mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-20 12:31:40 +00:00
CommandLine library cleanup. No longer use getValue/setValue, instead, just treat the commandline
args as the objects they represent and the "right thing" will happen git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b49ff5c5ee
commit
1e78f36127
@ -67,7 +67,7 @@ bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
|
|||||||
// Invoke BURM to label each tree node with a state
|
// Invoke BURM to label each tree node with a state
|
||||||
(void) burm_label(basicNode);
|
(void) burm_label(basicNode);
|
||||||
|
|
||||||
if (DebugLevel.getValue() >= DebugBurgTrees)
|
if (DebugLevel >= DebugBurgTrees)
|
||||||
{
|
{
|
||||||
printcover(basicNode, 1, 0);
|
printcover(basicNode, 1, 0);
|
||||||
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
||||||
@ -84,7 +84,7 @@ bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
|
|||||||
|
|
||||||
if (!failed)
|
if (!failed)
|
||||||
{
|
{
|
||||||
if (DebugLevel.getValue() >= DebugInstTrees)
|
if (DebugLevel >= DebugInstTrees)
|
||||||
{
|
{
|
||||||
cout << "\n\n*** Instruction trees for method "
|
cout << "\n\n*** Instruction trees for method "
|
||||||
<< (method->hasName()? method->getName() : "")
|
<< (method->hasName()? method->getName() : "")
|
||||||
@ -92,7 +92,7 @@ bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
|
|||||||
instrForest.dump();
|
instrForest.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DebugLevel.getValue() > NoDebugInfo)
|
if (DebugLevel > NoDebugInfo)
|
||||||
PrintMachineInstructions(method);
|
PrintMachineInstructions(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ bool Int::handleOccurance(const char *ArgName, const string &Arg) {
|
|||||||
// String valued command line option implementation
|
// String valued command line option implementation
|
||||||
//
|
//
|
||||||
bool String::handleOccurance(const char *ArgName, const string &Arg) {
|
bool String::handleOccurance(const char *ArgName, const string &Arg) {
|
||||||
Value = Arg;
|
*this = Arg;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
|
|||||||
// Invoke BURM to label each tree node with a state
|
// Invoke BURM to label each tree node with a state
|
||||||
(void) burm_label(basicNode);
|
(void) burm_label(basicNode);
|
||||||
|
|
||||||
if (DebugLevel.getValue() >= DebugBurgTrees)
|
if (DebugLevel >= DebugBurgTrees)
|
||||||
{
|
{
|
||||||
printcover(basicNode, 1, 0);
|
printcover(basicNode, 1, 0);
|
||||||
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
||||||
@ -84,7 +84,7 @@ bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
|
|||||||
|
|
||||||
if (!failed)
|
if (!failed)
|
||||||
{
|
{
|
||||||
if (DebugLevel.getValue() >= DebugInstTrees)
|
if (DebugLevel >= DebugInstTrees)
|
||||||
{
|
{
|
||||||
cout << "\n\n*** Instruction trees for method "
|
cout << "\n\n*** Instruction trees for method "
|
||||||
<< (method->hasName()? method->getName() : "")
|
<< (method->hasName()? method->getName() : "")
|
||||||
@ -92,7 +92,7 @@ bool SelectInstructionsForMethod(Method* method, TargetMachine &Target) {
|
|||||||
instrForest.dump();
|
instrForest.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DebugLevel.getValue() > NoDebugInfo)
|
if (DebugLevel > NoDebugInfo)
|
||||||
PrintMachineInstructions(method);
|
PrintMachineInstructions(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ bool Int::handleOccurance(const char *ArgName, const string &Arg) {
|
|||||||
// String valued command line option implementation
|
// String valued command line option implementation
|
||||||
//
|
//
|
||||||
bool String::handleOccurance(const char *ArgName, const string &Arg) {
|
bool String::handleOccurance(const char *ArgName, const string &Arg) {
|
||||||
Value = Arg;
|
*this = Arg;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ enum Ans {
|
|||||||
postdomset, postidom, postdomtree, postdomfrontier,
|
postdomset, postidom, postdomtree, postdomfrontier,
|
||||||
};
|
};
|
||||||
|
|
||||||
cl::String InputFilename ("", "Load <arg> file to analyze", 0, "-");
|
cl::String InputFilename ("", "Load <arg> file to analyze", cl::NoFlags, "-");
|
||||||
cl::Flag Quiet ("q", "Don't print analysis pass names", 0, false);
|
cl::Flag Quiet ("q", "Don't print analysis pass names", 0, false);
|
||||||
cl::EnumList<enum Ans> AnalysesList(cl::NoFlags,
|
cl::EnumList<enum Ans> AnalysesList(cl::NoFlags,
|
||||||
clEnumVal(print , "Print each Method"),
|
clEnumVal(print , "Print each Method"),
|
||||||
@ -132,8 +132,8 @@ struct {
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
cl::ParseCommandLineOptions(argc, argv, " llvm analysis printer tool\n");
|
cl::ParseCommandLineOptions(argc, argv, " llvm analysis printer tool\n");
|
||||||
|
|
||||||
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
Module *C = ParseBytecodeFile(InputFilename);
|
||||||
if (!C && !(C = ParseAssemblyFile(InputFilename.getValue()))) {
|
if (!C && !(C = ParseAssemblyFile(InputFilename))) {
|
||||||
cerr << "Input file didn't read correctly.\n";
|
cerr << "Input file didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
|
||||||
cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
|
cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
|
||||||
cl::String OutputFilename("o", "Override output filename", 0, "");
|
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
||||||
cl::Flag Force ("f", "Overwrite output files", 0, false);
|
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
||||||
cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false);
|
cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -29,38 +29,38 @@ int main(int argc, char **argv) {
|
|||||||
ostream *Out = 0;
|
ostream *Out = 0;
|
||||||
try {
|
try {
|
||||||
// Parse the file now...
|
// Parse the file now...
|
||||||
Module *C = ParseAssemblyFile(InputFilename.getValue());
|
Module *C = ParseAssemblyFile(InputFilename);
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "assembly didn't read correctly.\n";
|
cerr << "assembly didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DumpAsm.getValue())
|
if (DumpAsm)
|
||||||
cerr << "Here's the assembly:\n" << C;
|
cerr << "Here's the assembly:\n" << C;
|
||||||
|
|
||||||
if (OutputFilename.getValue() != "") { // Specified an output filename?
|
if (OutputFilename != "") { // Specified an output filename?
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
} else {
|
} else {
|
||||||
if (InputFilename.getValue() == "-") {
|
if (InputFilename == "-") {
|
||||||
OutputFilename.setValue("-");
|
OutputFilename = "-";
|
||||||
Out = &cout;
|
Out = &cout;
|
||||||
} else {
|
} else {
|
||||||
string IFN = InputFilename.getValue();
|
string IFN = InputFilename;
|
||||||
int Len = IFN.length();
|
int Len = IFN.length();
|
||||||
if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
|
if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
|
||||||
// Source ends in .ll
|
// Source ends in .ll
|
||||||
OutputFilename.setValue(string(IFN.begin(), IFN.end()-3));
|
OutputFilename = string(IFN.begin(), IFN.end()-3);
|
||||||
} else {
|
} else {
|
||||||
OutputFilename.setValue(IFN); // Append a .bc to it
|
OutputFilename = IFN; // Append a .bc to it
|
||||||
}
|
}
|
||||||
OutputFilename.setValue(OutputFilename.getValue() + ".bc");
|
OutputFilename += ".bc";
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << OutputFilename.getValue() << "!\n";
|
cerr << "Error opening " << OutputFilename << "!\n";
|
||||||
delete C;
|
delete C;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,8 @@ enum OutputMode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
||||||
cl::String OutputFilename("o", "Override output filename", 0, "");
|
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
||||||
cl::Flag Force ("f", "Overwrite output files", 0, false);
|
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
||||||
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
||||||
clEnumVal(Default, "Write basic blocks in bytecode order"),
|
clEnumVal(Default, "Write basic blocks in bytecode order"),
|
||||||
clEnumVal(dfo , "Write basic blocks in depth first order"),
|
clEnumVal(dfo , "Write basic blocks in depth first order"),
|
||||||
@ -49,36 +49,36 @@ int main(int argc, char **argv) {
|
|||||||
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
|
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
|
||||||
ostream *Out = &cout; // Default to printing to stdout...
|
ostream *Out = &cout; // Default to printing to stdout...
|
||||||
|
|
||||||
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
Module *C = ParseBytecodeFile(InputFilename);
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OutputFilename.getValue() != "") { // Specified an output filename?
|
if (OutputFilename != "") { // Specified an output filename?
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
} else {
|
} else {
|
||||||
if (InputFilename.getValue() == "-") {
|
if (InputFilename == "-") {
|
||||||
OutputFilename.setValue("-");
|
OutputFilename = "-";
|
||||||
Out = &cout;
|
Out = &cout;
|
||||||
} else {
|
} else {
|
||||||
string IFN = InputFilename.getValue();
|
string IFN = InputFilename;
|
||||||
int Len = IFN.length();
|
int Len = IFN.length();
|
||||||
if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
|
if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
|
||||||
// Source ends in .bc
|
// Source ends in .bc
|
||||||
OutputFilename.setValue(string(IFN.begin(), IFN.end()-3));
|
OutputFilename = string(IFN.begin(), IFN.end()-3);
|
||||||
} else {
|
} else {
|
||||||
OutputFilename.setValue(IFN); // Append a .ll to it
|
OutputFilename = IFN; // Append a .ll to it
|
||||||
}
|
}
|
||||||
OutputFilename.setValue(OutputFilename.getValue() + ".ll");
|
OutputFilename += ".ll";
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << OutputFilename.getValue()
|
cerr << "Error opening " << OutputFilename
|
||||||
<< ": sending to stdout instead!\n";
|
<< ": sending to stdout instead!\n";
|
||||||
Out = &cout;
|
Out = &cout;
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ int main(int argc, char **argv) {
|
|||||||
// All that dis does is write the assembly out to a file... which is exactly
|
// All that dis does is write the assembly out to a file... which is exactly
|
||||||
// what the writer library is supposed to do...
|
// what the writer library is supposed to do...
|
||||||
//
|
//
|
||||||
if (WriteMode.getValue() == Default) {
|
if (WriteMode == Default) {
|
||||||
(*Out) << C; // Print out in list order
|
(*Out) << C; // Print out in list order
|
||||||
} else {
|
} else {
|
||||||
// TODO: This does not print anything other than the basic blocks in the
|
// TODO: This does not print anything other than the basic blocks in the
|
||||||
@ -97,7 +97,7 @@ int main(int argc, char **argv) {
|
|||||||
Method *M = *I;
|
Method *M = *I;
|
||||||
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
||||||
|
|
||||||
switch (WriteMode.getValue()) {
|
switch (WriteMode) {
|
||||||
case dfo: // Depth First ordering
|
case dfo: // Depth First ordering
|
||||||
copy(cfg::df_begin(M), cfg::df_end(M),
|
copy(cfg::df_begin(M), cfg::df_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
|
@ -14,31 +14,25 @@
|
|||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Method.h"
|
#include "llvm/Method.h"
|
||||||
#include "llvm/Bytecode/Reader.h"
|
#include "llvm/Bytecode/Reader.h"
|
||||||
#include "llvm/Bytecode/Writer.h"
|
|
||||||
#include "llvm/CodeGen/InstrSelection.h"
|
#include "llvm/CodeGen/InstrSelection.h"
|
||||||
#include "llvm/CodeGen/Sparc.h"
|
#include "llvm/CodeGen/Sparc.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
|
||||||
cl::String InputFilename ("", "Input filename", cl::NoFlags, "");
|
cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
|
||||||
cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
|
cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
|
||||||
|
|
||||||
static bool CompileModule(Module *module, TargetMachine &Target) {
|
static bool CompileModule(Module *M, TargetMachine &Target) {
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
|
|
||||||
for (Module::MethodListType::const_iterator
|
for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
|
||||||
methodIter = module->getMethodList().begin();
|
Method * method = *MI;
|
||||||
methodIter != module->getMethodList().end();
|
|
||||||
++methodIter)
|
|
||||||
{
|
|
||||||
Method* method = *methodIter;
|
|
||||||
|
|
||||||
if (SelectInstructionsForMethod(method, Target))
|
if (SelectInstructionsForMethod(method, Target)) {
|
||||||
{
|
failed = true;
|
||||||
failed = true;
|
cerr << "Instruction selection failed for method "
|
||||||
cerr << "Instruction selection failed for method "
|
<< method->getName() << "\n\n";
|
||||||
<< method->getName() << "\n\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return failed;
|
return failed;
|
||||||
}
|
}
|
||||||
@ -54,24 +48,17 @@ int main(int argc, char** argv) {
|
|||||||
cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
|
cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
|
||||||
UltraSparc Target;
|
UltraSparc Target;
|
||||||
|
|
||||||
Module *module = ParseBytecodeFile(InputFilename.getValue());
|
Module *module = ParseBytecodeFile(InputFilename);
|
||||||
if (module == 0) {
|
if (module == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool failure = CompileModule(module, Target);
|
if (CompileModule(module, Target)) {
|
||||||
|
cerr << "Error compiling " << InputFilename << "!\n";
|
||||||
if (failure) {
|
delete module;
|
||||||
cerr << "Error compiling "
|
return 1;
|
||||||
<< InputFilename.getValue() << "!\n";
|
}
|
||||||
delete module;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Okay, we're done now... write out result...
|
|
||||||
// WriteBytecodeToFile(module,
|
|
||||||
// OutputFilename.getValue());
|
|
||||||
|
|
||||||
// Clean up and exit
|
// Clean up and exit
|
||||||
delete module;
|
delete module;
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
|
||||||
cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
|
cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
|
||||||
cl::String OutputFilename("o", "Override output filename", 0, "");
|
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
||||||
cl::Flag Force ("f", "Overwrite output files", 0, false);
|
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
||||||
cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false);
|
cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -29,38 +29,38 @@ int main(int argc, char **argv) {
|
|||||||
ostream *Out = 0;
|
ostream *Out = 0;
|
||||||
try {
|
try {
|
||||||
// Parse the file now...
|
// Parse the file now...
|
||||||
Module *C = ParseAssemblyFile(InputFilename.getValue());
|
Module *C = ParseAssemblyFile(InputFilename);
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "assembly didn't read correctly.\n";
|
cerr << "assembly didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DumpAsm.getValue())
|
if (DumpAsm)
|
||||||
cerr << "Here's the assembly:\n" << C;
|
cerr << "Here's the assembly:\n" << C;
|
||||||
|
|
||||||
if (OutputFilename.getValue() != "") { // Specified an output filename?
|
if (OutputFilename != "") { // Specified an output filename?
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
} else {
|
} else {
|
||||||
if (InputFilename.getValue() == "-") {
|
if (InputFilename == "-") {
|
||||||
OutputFilename.setValue("-");
|
OutputFilename = "-";
|
||||||
Out = &cout;
|
Out = &cout;
|
||||||
} else {
|
} else {
|
||||||
string IFN = InputFilename.getValue();
|
string IFN = InputFilename;
|
||||||
int Len = IFN.length();
|
int Len = IFN.length();
|
||||||
if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
|
if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
|
||||||
// Source ends in .ll
|
// Source ends in .ll
|
||||||
OutputFilename.setValue(string(IFN.begin(), IFN.end()-3));
|
OutputFilename = string(IFN.begin(), IFN.end()-3);
|
||||||
} else {
|
} else {
|
||||||
OutputFilename.setValue(IFN); // Append a .bc to it
|
OutputFilename = IFN; // Append a .bc to it
|
||||||
}
|
}
|
||||||
OutputFilename.setValue(OutputFilename.getValue() + ".bc");
|
OutputFilename += ".bc";
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << OutputFilename.getValue() << "!\n";
|
cerr << "Error opening " << OutputFilename << "!\n";
|
||||||
delete C;
|
delete C;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
|
||||||
cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
|
cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
|
||||||
cl::String OutputFilename("o", "Override output filename", 0, "");
|
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
||||||
cl::Flag Force ("f", "Overwrite output files", 0, false);
|
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
||||||
cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false);
|
cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -29,38 +29,38 @@ int main(int argc, char **argv) {
|
|||||||
ostream *Out = 0;
|
ostream *Out = 0;
|
||||||
try {
|
try {
|
||||||
// Parse the file now...
|
// Parse the file now...
|
||||||
Module *C = ParseAssemblyFile(InputFilename.getValue());
|
Module *C = ParseAssemblyFile(InputFilename);
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "assembly didn't read correctly.\n";
|
cerr << "assembly didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DumpAsm.getValue())
|
if (DumpAsm)
|
||||||
cerr << "Here's the assembly:\n" << C;
|
cerr << "Here's the assembly:\n" << C;
|
||||||
|
|
||||||
if (OutputFilename.getValue() != "") { // Specified an output filename?
|
if (OutputFilename != "") { // Specified an output filename?
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
} else {
|
} else {
|
||||||
if (InputFilename.getValue() == "-") {
|
if (InputFilename == "-") {
|
||||||
OutputFilename.setValue("-");
|
OutputFilename = "-";
|
||||||
Out = &cout;
|
Out = &cout;
|
||||||
} else {
|
} else {
|
||||||
string IFN = InputFilename.getValue();
|
string IFN = InputFilename;
|
||||||
int Len = IFN.length();
|
int Len = IFN.length();
|
||||||
if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
|
if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
|
||||||
// Source ends in .ll
|
// Source ends in .ll
|
||||||
OutputFilename.setValue(string(IFN.begin(), IFN.end()-3));
|
OutputFilename = string(IFN.begin(), IFN.end()-3);
|
||||||
} else {
|
} else {
|
||||||
OutputFilename.setValue(IFN); // Append a .bc to it
|
OutputFilename = IFN; // Append a .bc to it
|
||||||
}
|
}
|
||||||
OutputFilename.setValue(OutputFilename.getValue() + ".bc");
|
OutputFilename += ".bc";
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << OutputFilename.getValue() << "!\n";
|
cerr << "Error opening " << OutputFilename << "!\n";
|
||||||
delete C;
|
delete C;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,8 @@ enum OutputMode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
||||||
cl::String OutputFilename("o", "Override output filename", 0, "");
|
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
||||||
cl::Flag Force ("f", "Overwrite output files", 0, false);
|
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
||||||
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
||||||
clEnumVal(Default, "Write basic blocks in bytecode order"),
|
clEnumVal(Default, "Write basic blocks in bytecode order"),
|
||||||
clEnumVal(dfo , "Write basic blocks in depth first order"),
|
clEnumVal(dfo , "Write basic blocks in depth first order"),
|
||||||
@ -49,36 +49,36 @@ int main(int argc, char **argv) {
|
|||||||
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
|
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
|
||||||
ostream *Out = &cout; // Default to printing to stdout...
|
ostream *Out = &cout; // Default to printing to stdout...
|
||||||
|
|
||||||
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
Module *C = ParseBytecodeFile(InputFilename);
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OutputFilename.getValue() != "") { // Specified an output filename?
|
if (OutputFilename != "") { // Specified an output filename?
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
} else {
|
} else {
|
||||||
if (InputFilename.getValue() == "-") {
|
if (InputFilename == "-") {
|
||||||
OutputFilename.setValue("-");
|
OutputFilename = "-";
|
||||||
Out = &cout;
|
Out = &cout;
|
||||||
} else {
|
} else {
|
||||||
string IFN = InputFilename.getValue();
|
string IFN = InputFilename;
|
||||||
int Len = IFN.length();
|
int Len = IFN.length();
|
||||||
if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
|
if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
|
||||||
// Source ends in .bc
|
// Source ends in .bc
|
||||||
OutputFilename.setValue(string(IFN.begin(), IFN.end()-3));
|
OutputFilename = string(IFN.begin(), IFN.end()-3);
|
||||||
} else {
|
} else {
|
||||||
OutputFilename.setValue(IFN); // Append a .ll to it
|
OutputFilename = IFN; // Append a .ll to it
|
||||||
}
|
}
|
||||||
OutputFilename.setValue(OutputFilename.getValue() + ".ll");
|
OutputFilename += ".ll";
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << OutputFilename.getValue()
|
cerr << "Error opening " << OutputFilename
|
||||||
<< ": sending to stdout instead!\n";
|
<< ": sending to stdout instead!\n";
|
||||||
Out = &cout;
|
Out = &cout;
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ int main(int argc, char **argv) {
|
|||||||
// All that dis does is write the assembly out to a file... which is exactly
|
// All that dis does is write the assembly out to a file... which is exactly
|
||||||
// what the writer library is supposed to do...
|
// what the writer library is supposed to do...
|
||||||
//
|
//
|
||||||
if (WriteMode.getValue() == Default) {
|
if (WriteMode == Default) {
|
||||||
(*Out) << C; // Print out in list order
|
(*Out) << C; // Print out in list order
|
||||||
} else {
|
} else {
|
||||||
// TODO: This does not print anything other than the basic blocks in the
|
// TODO: This does not print anything other than the basic blocks in the
|
||||||
@ -97,7 +97,7 @@ int main(int argc, char **argv) {
|
|||||||
Method *M = *I;
|
Method *M = *I;
|
||||||
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
||||||
|
|
||||||
switch (WriteMode.getValue()) {
|
switch (WriteMode) {
|
||||||
case dfo: // Depth First ordering
|
case dfo: // Depth First ordering
|
||||||
copy(cfg::df_begin(M), cfg::df_end(M),
|
copy(cfg::df_begin(M), cfg::df_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
|
@ -35,8 +35,8 @@ enum OutputMode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-");
|
||||||
cl::String OutputFilename("o", "Override output filename", 0, "");
|
cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
|
||||||
cl::Flag Force ("f", "Overwrite output files", 0, false);
|
cl::Flag Force ("f", "Overwrite output files", cl::NoFlags, false);
|
||||||
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
|
||||||
clEnumVal(Default, "Write basic blocks in bytecode order"),
|
clEnumVal(Default, "Write basic blocks in bytecode order"),
|
||||||
clEnumVal(dfo , "Write basic blocks in depth first order"),
|
clEnumVal(dfo , "Write basic blocks in depth first order"),
|
||||||
@ -49,36 +49,36 @@ int main(int argc, char **argv) {
|
|||||||
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
|
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
|
||||||
ostream *Out = &cout; // Default to printing to stdout...
|
ostream *Out = &cout; // Default to printing to stdout...
|
||||||
|
|
||||||
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
Module *C = ParseBytecodeFile(InputFilename);
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OutputFilename.getValue() != "") { // Specified an output filename?
|
if (OutputFilename != "") { // Specified an output filename?
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
} else {
|
} else {
|
||||||
if (InputFilename.getValue() == "-") {
|
if (InputFilename == "-") {
|
||||||
OutputFilename.setValue("-");
|
OutputFilename = "-";
|
||||||
Out = &cout;
|
Out = &cout;
|
||||||
} else {
|
} else {
|
||||||
string IFN = InputFilename.getValue();
|
string IFN = InputFilename;
|
||||||
int Len = IFN.length();
|
int Len = IFN.length();
|
||||||
if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
|
if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
|
||||||
// Source ends in .bc
|
// Source ends in .bc
|
||||||
OutputFilename.setValue(string(IFN.begin(), IFN.end()-3));
|
OutputFilename = string(IFN.begin(), IFN.end()-3);
|
||||||
} else {
|
} else {
|
||||||
OutputFilename.setValue(IFN); // Append a .ll to it
|
OutputFilename = IFN; // Append a .ll to it
|
||||||
}
|
}
|
||||||
OutputFilename.setValue(OutputFilename.getValue() + ".ll");
|
OutputFilename += ".ll";
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << OutputFilename.getValue()
|
cerr << "Error opening " << OutputFilename
|
||||||
<< ": sending to stdout instead!\n";
|
<< ": sending to stdout instead!\n";
|
||||||
Out = &cout;
|
Out = &cout;
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ int main(int argc, char **argv) {
|
|||||||
// All that dis does is write the assembly out to a file... which is exactly
|
// All that dis does is write the assembly out to a file... which is exactly
|
||||||
// what the writer library is supposed to do...
|
// what the writer library is supposed to do...
|
||||||
//
|
//
|
||||||
if (WriteMode.getValue() == Default) {
|
if (WriteMode == Default) {
|
||||||
(*Out) << C; // Print out in list order
|
(*Out) << C; // Print out in list order
|
||||||
} else {
|
} else {
|
||||||
// TODO: This does not print anything other than the basic blocks in the
|
// TODO: This does not print anything other than the basic blocks in the
|
||||||
@ -97,7 +97,7 @@ int main(int argc, char **argv) {
|
|||||||
Method *M = *I;
|
Method *M = *I;
|
||||||
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
||||||
|
|
||||||
switch (WriteMode.getValue()) {
|
switch (WriteMode) {
|
||||||
case dfo: // Depth First ordering
|
case dfo: // Depth First ordering
|
||||||
copy(cfg::df_begin(M), cfg::df_end(M),
|
copy(cfg::df_begin(M), cfg::df_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
|
@ -75,7 +75,7 @@ int main(int argc, char **argv) {
|
|||||||
cl::ParseCommandLineOptions(argc, argv,
|
cl::ParseCommandLineOptions(argc, argv,
|
||||||
" llvm .bc -> .bc modular optimizer\n");
|
" llvm .bc -> .bc modular optimizer\n");
|
||||||
|
|
||||||
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
Module *C = ParseBytecodeFile(InputFilename);
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
@ -99,11 +99,11 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ostream *Out = &cout; // Default to printing to stdout...
|
ostream *Out = &cout; // Default to printing to stdout...
|
||||||
if (OutputFilename.getValue() != "") {
|
if (OutputFilename != "") {
|
||||||
Out = new ofstream(OutputFilename.getValue().c_str(),
|
Out = new ofstream(OutputFilename.c_str(),
|
||||||
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
(Force ? 0 : ios::noreplace)|ios::out);
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << OutputFilename.getValue() << "!\n";
|
cerr << "Error opening " << OutputFilename << "!\n";
|
||||||
delete C;
|
delete C;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user