mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
Initial revision
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
5
tools/Makefile
Normal file
5
tools/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
LEVEL = ..
|
||||
DIRS = dis as opt
|
||||
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
9
tools/as/Makefile
Normal file
9
tools/as/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
LEVEL = ../..
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
||||
all:: as
|
||||
clean::
|
||||
rm -f as
|
||||
|
||||
as : $(ObjectsG)
|
||||
$(LinkG) -o as $(ObjectsG) -lvmcore -lasmparser -lbcwriter -lanalysis -lasmwriter
|
85
tools/as/as.cpp
Normal file
85
tools/as/as.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
//===------------------------------------------------------------------------===
|
||||
// LLVM 'AS' UTILITY
|
||||
//
|
||||
// This utility may be invoked in the following manner:
|
||||
// as --help - Output information about command line switches
|
||||
// as [options] - Read LLVM assembly from stdin, write bytecode to stdout
|
||||
// as [options] x.ll - Read LLVM assembly from the x.ll file, write bytecode
|
||||
// to the x.bc file.
|
||||
//
|
||||
//===------------------------------------------------------------------------===
|
||||
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include <string>
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Assembly/Parser.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Bytecode/Writer.h"
|
||||
#include "llvm/Tools/CommandLine.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ToolCommandLine Opts(argc, argv);
|
||||
bool DumpAsm = false;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (string(argv[i]) == string("-d")) {
|
||||
argv[i] = 0; DumpAsm = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool PrintMessage = false;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i] == 0) continue;
|
||||
|
||||
if (string(argv[i]) == string("--help")) {
|
||||
PrintMessage = true;
|
||||
} else {
|
||||
cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (PrintMessage) {
|
||||
cerr << argv[0] << " usage:\n"
|
||||
<< " " << argv[0] << " --help - Print this usage information\n"
|
||||
<< " " << argv[0] << " x.ll - Parse <x.ll> file and output "
|
||||
<< "bytecodes to x.bc\n"
|
||||
<< " " << argv[0] << " - Parse stdin and write to stdout.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
ostream *Out = &cout; // Default to output to stdout...
|
||||
try {
|
||||
// Parse the file now...
|
||||
Module *C = ParseAssemblyFile(Opts);
|
||||
if (C == 0) {
|
||||
cerr << "assembly didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (DumpAsm)
|
||||
cerr << "Here's the assembly:\n" << C;
|
||||
|
||||
if (Opts.getOutputFilename() != "-") {
|
||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
||||
if (!Out->good()) {
|
||||
cerr << "Error opening " << Opts.getOutputFilename() << "!\n";
|
||||
delete C;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
WriteBytecodeToFile(C, *Out);
|
||||
|
||||
delete C;
|
||||
} catch (const ParseException &E) {
|
||||
cerr << E.getMessage() << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Out != &cout) delete Out;
|
||||
return 0;
|
||||
}
|
||||
|
10
tools/dis/Makefile
Normal file
10
tools/dis/Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
LEVEL = ../..
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
||||
all:: dis
|
||||
clean ::
|
||||
rm -f dis
|
||||
|
||||
dis : $(ObjectsG)
|
||||
$(LinkG) -o $@ $(ObjectsG) -lvmcore -lasmwriter -lanalysis \
|
||||
-lbcreader
|
64
tools/dis/dis.cpp
Normal file
64
tools/dis/dis.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
//===------------------------------------------------------------------------===
|
||||
// LLVM 'DIS' UTILITY
|
||||
//
|
||||
// This utility may be invoked in the following manner:
|
||||
// dis --help - Output information about command line switches
|
||||
// dis [options] - Read LLVM bytecode from stdin, write assembly to stdout
|
||||
// dis [options] x.bc - Read LLVM bytecode from the x.bc file, write assembly
|
||||
// to the x.ll file.
|
||||
//
|
||||
//===------------------------------------------------------------------------===
|
||||
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Bytecode/Reader.h"
|
||||
#include "llvm/Tools/CommandLine.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ToolCommandLine Opts(argc, argv, false);
|
||||
|
||||
// We only support the options that the system parser does... if it left any
|
||||
// then we don't know what to do.
|
||||
//
|
||||
if (argc > 1) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (string(argv[i]) != string("--help"))
|
||||
cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
|
||||
}
|
||||
|
||||
cerr << argv[0] << " usage:\n"
|
||||
<< " " << argv[0] << " --help - Print this usage information\n"
|
||||
<< " " << argv[0] << " x.bc - Parse <x.bc> file and output "
|
||||
<< "assembly to x.ll\n"
|
||||
<< " " << argv[0] << " - Parse stdin and write to stdout.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
ostream *Out = &cout; // Default to printing to stdout...
|
||||
|
||||
Module *C = ParseBytecodeFile(Opts.getInputFilename());
|
||||
if (C == 0) {
|
||||
cerr << "bytecode didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Opts.getOutputFilename() != "-") {
|
||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
||||
if (!Out->good()) {
|
||||
cerr << "Error opening " << Opts.getOutputFilename()
|
||||
<< ": sending to stdout instead!\n";
|
||||
Out = &cout;
|
||||
}
|
||||
}
|
||||
|
||||
// All that dis does is write the assembly out to a file... which is exactly
|
||||
// what the writer library is supposed to do...
|
||||
(*Out) << C;
|
||||
delete C;
|
||||
|
||||
if (Out != &cout) delete Out;
|
||||
return 0;
|
||||
}
|
9
tools/llvm-as/Makefile
Normal file
9
tools/llvm-as/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
LEVEL = ../..
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
||||
all:: as
|
||||
clean::
|
||||
rm -f as
|
||||
|
||||
as : $(ObjectsG)
|
||||
$(LinkG) -o as $(ObjectsG) -lvmcore -lasmparser -lbcwriter -lanalysis -lasmwriter
|
85
tools/llvm-as/as.cpp
Normal file
85
tools/llvm-as/as.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
//===------------------------------------------------------------------------===
|
||||
// LLVM 'AS' UTILITY
|
||||
//
|
||||
// This utility may be invoked in the following manner:
|
||||
// as --help - Output information about command line switches
|
||||
// as [options] - Read LLVM assembly from stdin, write bytecode to stdout
|
||||
// as [options] x.ll - Read LLVM assembly from the x.ll file, write bytecode
|
||||
// to the x.bc file.
|
||||
//
|
||||
//===------------------------------------------------------------------------===
|
||||
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include <string>
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Assembly/Parser.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Bytecode/Writer.h"
|
||||
#include "llvm/Tools/CommandLine.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ToolCommandLine Opts(argc, argv);
|
||||
bool DumpAsm = false;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (string(argv[i]) == string("-d")) {
|
||||
argv[i] = 0; DumpAsm = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool PrintMessage = false;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i] == 0) continue;
|
||||
|
||||
if (string(argv[i]) == string("--help")) {
|
||||
PrintMessage = true;
|
||||
} else {
|
||||
cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (PrintMessage) {
|
||||
cerr << argv[0] << " usage:\n"
|
||||
<< " " << argv[0] << " --help - Print this usage information\n"
|
||||
<< " " << argv[0] << " x.ll - Parse <x.ll> file and output "
|
||||
<< "bytecodes to x.bc\n"
|
||||
<< " " << argv[0] << " - Parse stdin and write to stdout.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
ostream *Out = &cout; // Default to output to stdout...
|
||||
try {
|
||||
// Parse the file now...
|
||||
Module *C = ParseAssemblyFile(Opts);
|
||||
if (C == 0) {
|
||||
cerr << "assembly didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (DumpAsm)
|
||||
cerr << "Here's the assembly:\n" << C;
|
||||
|
||||
if (Opts.getOutputFilename() != "-") {
|
||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
||||
if (!Out->good()) {
|
||||
cerr << "Error opening " << Opts.getOutputFilename() << "!\n";
|
||||
delete C;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
WriteBytecodeToFile(C, *Out);
|
||||
|
||||
delete C;
|
||||
} catch (const ParseException &E) {
|
||||
cerr << E.getMessage() << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Out != &cout) delete Out;
|
||||
return 0;
|
||||
}
|
||||
|
85
tools/llvm-as/llvm-as.cpp
Normal file
85
tools/llvm-as/llvm-as.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
//===------------------------------------------------------------------------===
|
||||
// LLVM 'AS' UTILITY
|
||||
//
|
||||
// This utility may be invoked in the following manner:
|
||||
// as --help - Output information about command line switches
|
||||
// as [options] - Read LLVM assembly from stdin, write bytecode to stdout
|
||||
// as [options] x.ll - Read LLVM assembly from the x.ll file, write bytecode
|
||||
// to the x.bc file.
|
||||
//
|
||||
//===------------------------------------------------------------------------===
|
||||
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include <string>
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Assembly/Parser.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Bytecode/Writer.h"
|
||||
#include "llvm/Tools/CommandLine.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ToolCommandLine Opts(argc, argv);
|
||||
bool DumpAsm = false;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (string(argv[i]) == string("-d")) {
|
||||
argv[i] = 0; DumpAsm = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool PrintMessage = false;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i] == 0) continue;
|
||||
|
||||
if (string(argv[i]) == string("--help")) {
|
||||
PrintMessage = true;
|
||||
} else {
|
||||
cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (PrintMessage) {
|
||||
cerr << argv[0] << " usage:\n"
|
||||
<< " " << argv[0] << " --help - Print this usage information\n"
|
||||
<< " " << argv[0] << " x.ll - Parse <x.ll> file and output "
|
||||
<< "bytecodes to x.bc\n"
|
||||
<< " " << argv[0] << " - Parse stdin and write to stdout.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
ostream *Out = &cout; // Default to output to stdout...
|
||||
try {
|
||||
// Parse the file now...
|
||||
Module *C = ParseAssemblyFile(Opts);
|
||||
if (C == 0) {
|
||||
cerr << "assembly didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (DumpAsm)
|
||||
cerr << "Here's the assembly:\n" << C;
|
||||
|
||||
if (Opts.getOutputFilename() != "-") {
|
||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
||||
if (!Out->good()) {
|
||||
cerr << "Error opening " << Opts.getOutputFilename() << "!\n";
|
||||
delete C;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
WriteBytecodeToFile(C, *Out);
|
||||
|
||||
delete C;
|
||||
} catch (const ParseException &E) {
|
||||
cerr << E.getMessage() << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Out != &cout) delete Out;
|
||||
return 0;
|
||||
}
|
||||
|
10
tools/llvm-dis/Makefile
Normal file
10
tools/llvm-dis/Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
LEVEL = ../..
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
||||
all:: dis
|
||||
clean ::
|
||||
rm -f dis
|
||||
|
||||
dis : $(ObjectsG)
|
||||
$(LinkG) -o $@ $(ObjectsG) -lvmcore -lasmwriter -lanalysis \
|
||||
-lbcreader
|
64
tools/llvm-dis/dis.cpp
Normal file
64
tools/llvm-dis/dis.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
//===------------------------------------------------------------------------===
|
||||
// LLVM 'DIS' UTILITY
|
||||
//
|
||||
// This utility may be invoked in the following manner:
|
||||
// dis --help - Output information about command line switches
|
||||
// dis [options] - Read LLVM bytecode from stdin, write assembly to stdout
|
||||
// dis [options] x.bc - Read LLVM bytecode from the x.bc file, write assembly
|
||||
// to the x.ll file.
|
||||
//
|
||||
//===------------------------------------------------------------------------===
|
||||
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Bytecode/Reader.h"
|
||||
#include "llvm/Tools/CommandLine.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ToolCommandLine Opts(argc, argv, false);
|
||||
|
||||
// We only support the options that the system parser does... if it left any
|
||||
// then we don't know what to do.
|
||||
//
|
||||
if (argc > 1) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (string(argv[i]) != string("--help"))
|
||||
cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
|
||||
}
|
||||
|
||||
cerr << argv[0] << " usage:\n"
|
||||
<< " " << argv[0] << " --help - Print this usage information\n"
|
||||
<< " " << argv[0] << " x.bc - Parse <x.bc> file and output "
|
||||
<< "assembly to x.ll\n"
|
||||
<< " " << argv[0] << " - Parse stdin and write to stdout.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
ostream *Out = &cout; // Default to printing to stdout...
|
||||
|
||||
Module *C = ParseBytecodeFile(Opts.getInputFilename());
|
||||
if (C == 0) {
|
||||
cerr << "bytecode didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Opts.getOutputFilename() != "-") {
|
||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
||||
if (!Out->good()) {
|
||||
cerr << "Error opening " << Opts.getOutputFilename()
|
||||
<< ": sending to stdout instead!\n";
|
||||
Out = &cout;
|
||||
}
|
||||
}
|
||||
|
||||
// All that dis does is write the assembly out to a file... which is exactly
|
||||
// what the writer library is supposed to do...
|
||||
(*Out) << C;
|
||||
delete C;
|
||||
|
||||
if (Out != &cout) delete Out;
|
||||
return 0;
|
||||
}
|
64
tools/llvm-dis/llvm-dis.cpp
Normal file
64
tools/llvm-dis/llvm-dis.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
//===------------------------------------------------------------------------===
|
||||
// LLVM 'DIS' UTILITY
|
||||
//
|
||||
// This utility may be invoked in the following manner:
|
||||
// dis --help - Output information about command line switches
|
||||
// dis [options] - Read LLVM bytecode from stdin, write assembly to stdout
|
||||
// dis [options] x.bc - Read LLVM bytecode from the x.bc file, write assembly
|
||||
// to the x.ll file.
|
||||
//
|
||||
//===------------------------------------------------------------------------===
|
||||
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Bytecode/Reader.h"
|
||||
#include "llvm/Tools/CommandLine.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ToolCommandLine Opts(argc, argv, false);
|
||||
|
||||
// We only support the options that the system parser does... if it left any
|
||||
// then we don't know what to do.
|
||||
//
|
||||
if (argc > 1) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (string(argv[i]) != string("--help"))
|
||||
cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
|
||||
}
|
||||
|
||||
cerr << argv[0] << " usage:\n"
|
||||
<< " " << argv[0] << " --help - Print this usage information\n"
|
||||
<< " " << argv[0] << " x.bc - Parse <x.bc> file and output "
|
||||
<< "assembly to x.ll\n"
|
||||
<< " " << argv[0] << " - Parse stdin and write to stdout.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
ostream *Out = &cout; // Default to printing to stdout...
|
||||
|
||||
Module *C = ParseBytecodeFile(Opts.getInputFilename());
|
||||
if (C == 0) {
|
||||
cerr << "bytecode didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Opts.getOutputFilename() != "-") {
|
||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
||||
if (!Out->good()) {
|
||||
cerr << "Error opening " << Opts.getOutputFilename()
|
||||
<< ": sending to stdout instead!\n";
|
||||
Out = &cout;
|
||||
}
|
||||
}
|
||||
|
||||
// All that dis does is write the assembly out to a file... which is exactly
|
||||
// what the writer library is supposed to do...
|
||||
(*Out) << C;
|
||||
delete C;
|
||||
|
||||
if (Out != &cout) delete Out;
|
||||
return 0;
|
||||
}
|
10
tools/opt/Makefile
Normal file
10
tools/opt/Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
LEVEL = ../..
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
||||
all:: opt
|
||||
clean ::
|
||||
rm -f opt
|
||||
|
||||
opt : $(ObjectsG)
|
||||
$(LinkG) -o $@ $(ObjectsG) -lvmcore -lanalysis -lbcreader -lbcwriter \
|
||||
-lopt -lasmwriter
|
98
tools/opt/opt.cpp
Normal file
98
tools/opt/opt.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
//===------------------------------------------------------------------------===
|
||||
// LLVM 'OPT' UTILITY
|
||||
//
|
||||
// This utility may be invoked in the following manner:
|
||||
// opt --help - Output information about command line switches
|
||||
// opt [options] -dce - Run a dead code elimination pass on input
|
||||
// bytecodes
|
||||
// opt [options] -constprop - Run a constant propogation pass on input
|
||||
// bytecodes
|
||||
// opt [options] -inline - Run a method inlining pass on input bytecodes
|
||||
// opt [options] -strip - Strip symbol tables out of methods
|
||||
// opt [options] -mstrip - Strip module & method symbol tables
|
||||
//
|
||||
// Optimizations may be specified an arbitrary number of times on the command
|
||||
// line, they are run in the order specified.
|
||||
//
|
||||
// TODO: Add a -all option to keep applying all optimizations until the program
|
||||
// stops permuting.
|
||||
// TODO: Add a -h command line arg that prints all available optimizations
|
||||
// TODO: Add a -q command line arg that quiets "XXX pass made modifications"
|
||||
//
|
||||
//===------------------------------------------------------------------------===
|
||||
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Bytecode/Reader.h"
|
||||
#include "llvm/Bytecode/Writer.h"
|
||||
#include "llvm/Tools/CommandLine.h"
|
||||
#include "llvm/Opt/AllOpts.h"
|
||||
|
||||
struct {
|
||||
const string ArgName, Name;
|
||||
bool (*OptPtr)(Module *C);
|
||||
} OptTable[] = {
|
||||
{ "-dce", "Dead Code Elimination", DoDeadCodeElimination },
|
||||
{ "-constprop","Constant Propogation", DoConstantPropogation },
|
||||
{ "-inline" ,"Method Inlining", DoMethodInlining },
|
||||
{ "-strip" ,"Strip Symbols", DoSymbolStripping },
|
||||
{ "-mstrip" ,"Strip Module Symbols", DoFullSymbolStripping },
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ToolCommandLine Opts(argc, argv, false);
|
||||
bool Quiet = false;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (string(argv[i]) == string("--help")) {
|
||||
cerr << argv[0] << " usage:\n"
|
||||
<< " " << argv[0] << " --help - Print this usage information\n";
|
||||
return 1;
|
||||
} else if (string(argv[i]) == string("-q")) {
|
||||
Quiet = true; argv[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ostream *Out = &cout; // Default to printing to stdout...
|
||||
|
||||
Module *C = ParseBytecodeFile(Opts.getInputFilename());
|
||||
if (C == 0) {
|
||||
cerr << "bytecode didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i] == 0) continue;
|
||||
unsigned j;
|
||||
for (j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); j++) {
|
||||
if (string(argv[i]) == OptTable[j].ArgName) {
|
||||
if (OptTable[j].OptPtr(C) && !Quiet)
|
||||
cerr << OptTable[j].Name << " pass made modifications!\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == sizeof(OptTable)/sizeof(OptTable[0]))
|
||||
cerr << "'" << argv[i] << "' argument unrecognized: ignored\n";
|
||||
}
|
||||
|
||||
if (Opts.getOutputFilename() != "-") {
|
||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
||||
if (!Out->good()) {
|
||||
cerr << "Error opening " << Opts.getOutputFilename()
|
||||
<< "!\n";
|
||||
delete C;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Okay, we're done now... write out result...
|
||||
WriteBytecodeToFile(C, *Out);
|
||||
delete C;
|
||||
|
||||
if (Out != &cout) delete Out;
|
||||
return 0;
|
||||
}
|
4
tools/opt/test.sh
Executable file
4
tools/opt/test.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
../as/as < ../../test/$1 | ./opt -constprop -dce | ../dis/dis
|
||||
|
3
tools/opt/testinline.sh
Executable file
3
tools/opt/testinline.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
../as/as < ../../test/$1 | ./opt -inline -constprop -dce | dis
|
3
tools/opt/teststrip.sh
Executable file
3
tools/opt/teststrip.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
../as/as < ../../test/$1 | ./opt -strip | dis
|
5
tools/setup
Normal file
5
tools/setup
Normal file
@@ -0,0 +1,5 @@
|
||||
setenv LD_LIBRARY_PATH ../../lib/Assembly/Parser/Debug:../../lib/Assembly/Writer/Debug:../../lib/Analysis/Debug:../../lib/VMCore/Debug:../../lib/Bytecode/Writer/Debug:../../lib/Bytecode/Reader/Debug:../../lib/Optimizations/Debug
|
||||
|
||||
setenv PATH ../dis:../opt:../strip:${PATH}
|
||||
|
||||
alias as ../as/as
|
Reference in New Issue
Block a user