diff options
author | Chris Lattner <sabre@nondot.org> | 2001-07-23 02:35:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-07-23 02:35:57 +0000 |
commit | 8f367bd3c0f56b7b318c46cee04f77735f617777 (patch) | |
tree | ef00b00e2465f9168bbbd83fd2ebef8fa857146f /tools | |
parent | a28504313d4c3fe87173a71b511dd4c8e25c3312 (diff) |
Large scale changes to implement new command line argument facility
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/analyze/Makefile | 3 | ||||
-rw-r--r-- | tools/analyze/analyze.cpp | 95 | ||||
-rw-r--r-- | tools/as/Makefile | 2 | ||||
-rw-r--r-- | tools/as/as.cpp | 65 | ||||
-rw-r--r-- | tools/dis/Makefile | 2 | ||||
-rw-r--r-- | tools/dis/dis.cpp | 104 | ||||
-rw-r--r-- | tools/llc/LLCOptions.cpp | 125 | ||||
-rw-r--r-- | tools/llc/LLCOptions.h | 74 | ||||
-rw-r--r-- | tools/llc/Makefile | 6 | ||||
-rw-r--r-- | tools/llc/llc.cpp | 26 | ||||
-rw-r--r-- | tools/llvm-as/Makefile | 2 | ||||
-rw-r--r-- | tools/llvm-as/as.cpp | 65 | ||||
-rw-r--r-- | tools/llvm-as/llvm-as.cpp | 65 | ||||
-rw-r--r-- | tools/llvm-dis/Makefile | 2 | ||||
-rw-r--r-- | tools/llvm-dis/dis.cpp | 104 | ||||
-rw-r--r-- | tools/llvm-dis/llvm-dis.cpp | 104 | ||||
-rw-r--r-- | tools/opt/Makefile | 2 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 93 | ||||
-rwxr-xr-x | tools/opt/test.sh | 4 | ||||
-rwxr-xr-x | tools/opt/testinline.sh | 3 | ||||
-rwxr-xr-x | tools/opt/teststrip.sh | 3 |
21 files changed, 367 insertions, 582 deletions
diff --git a/tools/analyze/Makefile b/tools/analyze/Makefile index b33d40bd69..1ff0e53fd8 100644 --- a/tools/analyze/Makefile +++ b/tools/analyze/Makefile @@ -9,4 +9,5 @@ LIBDEPS = ../../lib/Optimizations/Debug/libopt.a ../../lib/Analysis/Debug/liba analyze : $(ObjectsG) Debug/.dir Depend/.dir $(LIBDEPS) $(LinkG) -o $@ $(ObjectsG) -lopt -lasmparser \ - -lbcreader -lvmcore -lasmwriter -lanalysis -lopt + -lbcreader -lvmcore -lasmwriter -lanalysis \ + -lopt -lsupport diff --git a/tools/analyze/analyze.cpp b/tools/analyze/analyze.cpp index cf93ea9d8e..4dc00b2c57 100644 --- a/tools/analyze/analyze.cpp +++ b/tools/analyze/analyze.cpp @@ -86,47 +86,54 @@ static void PrintPostDomFrontier(Method *M) { cout << cfg::DominanceFrontier(cfg::DominatorSet(M, true)); } +enum Ans { + print, intervals, exprclassify, + domset, idom, domtree, domfrontier, + postdomset, postidom, postdomtree, postdomfrontier, +}; + +cl::String InputFilename ("", "Load <arg> file to analyze", 0, "-"); +cl::Flag Quiet ("q", "Don't print analysis pass names", 0, false); +cl::EnumList<enum Ans> AnalysesList(cl::NoFlags, + clEnumVal(print , "Print each Method"), + clEnumVal(intervals , "Print Interval Partitions"), + clEnumVal(exprclassify , "Classify Expressions"), + + clEnumVal(domset , "Print Dominator Sets"), + clEnumVal(idom , "Print Immediate Dominators"), + clEnumVal(domtree , "Print Dominator Tree"), + clEnumVal(domfrontier , "Print Dominance Frontier"), + + clEnumVal(postdomset , "Print Postdominator Sets"), + clEnumVal(postidom , "Print Immediate Postdominators"), + clEnumVal(postdomtree , "Print Post Dominator Tree"), + clEnumVal(postdomfrontier, "Print Postdominance Frontier"), +0); + struct { - const string ArgName, Name; + enum Ans AnID; void (*AnPtr)(Method *M); } AnTable[] = { - { "-print" , "Print each Method" , PrintMethod }, - { "-intervals" , "Interval Partition" , PrintIntervalPartition }, - { "-exprclassify" , "Classify Expressions" , PrintClassifiedExprs }, - - { "-domset" , "Dominator Sets" , PrintDominatorSets }, - { "-idom" , "Immediate Dominators" , PrintImmediateDominators }, - { "-domtree" , "Dominator Tree" , PrintDominatorTree }, - { "-domfrontier" , "Dominance Frontier" , PrintDominanceFrontier }, - - { "-postdomset" , "Postdominator Sets" , PrintPostDominatorSets }, - { "-postidom" , "Immediate Postdominators", PrintImmediatePostDoms }, - { "-postdomtree" , "Post Dominator Tree" , PrintPostDomTree }, - { "-postdomfrontier", "Postdominance Frontier" , PrintPostDomFrontier }, + { print , PrintMethod }, + { intervals , PrintIntervalPartition }, + { exprclassify , PrintClassifiedExprs }, + + { domset , PrintDominatorSets }, + { idom , PrintImmediateDominators }, + { domtree , PrintDominatorTree }, + { domfrontier , PrintDominanceFrontier }, + + { postdomset , PrintPostDominatorSets }, + { postidom , PrintImmediatePostDoms }, + { postdomtree , PrintPostDomTree }, + { postdomfrontier, PrintPostDomFrontier }, }; int main(int argc, char **argv) { - ToolCommandLine Options(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\t - Print this usage information\n" - << "\t --quiet\t - Do not print analysis name before output\n"; - for (unsigned j = 0; j < sizeof(AnTable)/sizeof(AnTable[0]); ++j) { - cerr << "\t " << AnTable[j].ArgName << "\t - Print " - << AnTable[j].Name << endl; - } - return 1; - } else if (string(argv[i]) == string("-q") || - string(argv[i]) == string("--quiet")) { - Quiet = true; argv[i] = 0; - } - } - - Module *C = ParseBytecodeFile(Options.getInputFilename()); - if (!C && !(C = ParseAssemblyFile(Options))) { + cl::ParseCommandLineOptions(argc, argv, " llvm analysis printer tool\n"); + + Module *C = ParseBytecodeFile(InputFilename.getValue()); + if (!C && !(C = ParseAssemblyFile(InputFilename.getValue()))) { cerr << "Input file didn't read correctly.\n"; return 1; } @@ -136,22 +143,22 @@ int main(int argc, char **argv) { Method *M = *I; if (M->isExternal()) continue; - // Loop over all of the analyses to be run... - for (int i = 1; i < argc; i++) { - if (argv[i] == 0) continue; + for (unsigned i = 0; i < AnalysesList.size(); ++i) { + enum Ans AnalysisPass = AnalysesList[i]; + + // Loop over all of the analyses to be run... unsigned j; - for (j = 0; j < sizeof(AnTable)/sizeof(AnTable[0]); j++) { - if (string(argv[i]) == AnTable[j].ArgName) { + for (j = 0; j < sizeof(AnTable)/sizeof(AnTable[0]); ++j) { + if (AnalysisPass == AnTable[j].AnID) { if (!Quiet) - cerr << "Running: " << AnTable[j].Name << " analysis on '" - << ((Value*)M)->getName() << "'!\n"; + cerr << "Running: " << AnalysesList.getArgDescription(AnalysisPass) + << " analysis on '" << ((Value*)M)->getName() << "'!\n"; AnTable[j].AnPtr(M); break; } } - if (j == sizeof(AnTable)/sizeof(AnTable[0])) - cerr << "'" << argv[i] << "' argument unrecognized: ignored\n"; + cerr << "Analysis tables inconsistent!\n"; } } diff --git a/tools/as/Makefile b/tools/as/Makefile index 9d36cc1d00..fcb9293572 100644 --- a/tools/as/Makefile +++ b/tools/as/Makefile @@ -6,4 +6,4 @@ clean:: rm -f as as : $(ObjectsG) - $(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore + $(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore -lsupport diff --git a/tools/as/as.cpp b/tools/as/as.cpp index 2c319a0849..da05a36f7f 100644 --- a/tools/as/as.cpp +++ b/tools/as/as.cpp @@ -18,54 +18,49 @@ #include "llvm/Bytecode/Writer.h" #include "llvm/Tools/CommandLine.h" +cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-"); +cl::String OutputFilename("o", "Override output filename", 0, ""); +cl::Flag Force ("f", "Overwrite output files", 0, false); +cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false); int main(int argc, char **argv) { - ToolCommandLine Opts(argc, argv); - bool DumpAsm = false; + cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n"); - 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... + ostream *Out = 0; try { // Parse the file now... - Module *C = ParseAssemblyFile(Opts); + Module *C = ParseAssemblyFile(InputFilename.getValue()); if (C == 0) { cerr << "assembly didn't read correctly.\n"; return 1; } - if (DumpAsm) + if (DumpAsm.getValue()) cerr << "Here's the assembly:\n" << C; + + if (OutputFilename.getValue() != "") { // Specified an output filename? + Out = new ofstream(OutputFilename.getValue().c_str(), + (Force.getValue() ? 0 : ios::noreplace)|ios::out); + } else { + if (InputFilename.getValue() == "-") { + OutputFilename.setValue("-"); + Out = &cout; + } else { + string IFN = InputFilename.getValue(); + int Len = IFN.length(); + if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') { + // Source ends in .ll + OutputFilename.setValue(string(IFN.begin(), IFN.end()-3)); + } else { + OutputFilename.setValue(IFN); // Append a .bc to it + } + OutputFilename.setValue(OutputFilename.getValue() + ".bc"); + Out = new ofstream(OutputFilename.getValue().c_str(), + (Force.getValue() ? 0 : ios::noreplace)|ios::out); + } - 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"; + cerr << "Error opening " << OutputFilename.getValue() << "!\n"; delete C; return 1; } diff --git a/tools/dis/Makefile b/tools/dis/Makefile index e6624ab544..8ce3e2161c 100644 --- a/tools/dis/Makefile +++ b/tools/dis/Makefile @@ -6,5 +6,5 @@ clean :: rm -f dis dis : $(ObjectsG) - $(LinkG) -o $@ $(ObjectsG) -lbcreader -lasmwriter -lanalysis -lvmcore + $(LinkG) -o $@ $(ObjectsG) -lbcreader -lasmwriter -lanalysis -lvmcore -lsupport diff --git a/tools/dis/dis.cpp b/tools/dis/dis.cpp index deaf3a28fd..f243baadb0 100644 --- a/tools/dis/dis.cpp +++ b/tools/dis/dis.cpp @@ -25,69 +25,67 @@ #include "llvm/Method.h" #include "llvm/CFG.h" -int main(int argc, char **argv) { - // WriteMode - The different orderings to print basic blocks in... - enum { - Default = 0, // Method Order (list order) - DepthFirst, // Depth First ordering - ReverseDepthFirst, // Reverse Depth First ordering - PostOrder, // Post Order - ReversePostOrder // Reverse Post Order - } WriteMode = Default; +// OutputMode - The different orderings to print basic blocks in... +enum OutputMode { + Default = 0, // Method Order (list order) + dfo, // Depth First ordering + rdfo, // Reverse Depth First ordering + po, // Post Order + rpo, // Reverse Post Order +}; - ToolCommandLine Opts(argc, argv, false); +cl::String InputFilename ("", "Load <arg> file, print as assembly", 0, "-"); +cl::String OutputFilename("o", "Override output filename", 0, ""); +cl::Flag Force ("f", "Overwrite output files", 0, false); +cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags, + clEnumVal(Default, "Write bb's in bytecode order"), + clEnumVal(dfo , "Write bb's in depth first order"), + clEnumVal(rdfo , "Write bb's in reverse DFO"), + clEnumVal(po , "Write bb's in postorder"), + clEnumVal(rpo , "Write bb's in reverse postorder"), 0); - // 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] << " usage:\n" - << "\tx.bc - Parse <x.bc> file and output to x.ll\n" - << "\tno .bc file - Parse stdin and write to stdout.\n" - << "\t-dfo - Write basic blocks in depth first order.\n" - << "\t-rdfo - Write basic blocks in reverse DFO.\n" - << "\t-po - Write basic blocks in postorder.\n" - << "\t-rpo - Write basic blocks in reverse postorder.\n" - << "\t--help - Print this usage information\n\n"; - return 1; - } else if (string(argv[i]) == string("-dfo")) { - WriteMode = DepthFirst; - } else if (string(argv[i]) == string("-rdfo")) { - WriteMode = ReverseDepthFirst; - } else if (string(argv[i]) == string("-po")) { - WriteMode = PostOrder; - } else if (string(argv[i]) == string("-rpo")) { - WriteMode = ReversePostOrder; - } else { - cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n"; - } - } - } - +int main(int argc, char **argv) { + cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n"); ostream *Out = &cout; // Default to printing to stdout... - Module *C = ParseBytecodeFile(Opts.getInputFilename()); + Module *C = ParseBytecodeFile(InputFilename.getValue()); 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"; + if (OutputFilename.getValue() != "") { // Specified an output filename? + Out = new ofstream(OutputFilename.getValue().c_str(), + (Force.getValue() ? 0 : ios::noreplace)|ios::out); + } else { + if (InputFilename.getValue() == "-") { + OutputFilename.setValue("-"); Out = &cout; + } else { + string IFN = InputFilename.getValue(); + int Len = IFN.length(); + if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') { + // Source ends in .bc + OutputFilename.setValue(string(IFN.begin(), IFN.end()-3)); + } else { + OutputFilename.setValue(IFN); // Append a .ll to it } + OutputFilename.setValue(OutputFilename.getValue() + ".ll"); + Out = new ofstream(OutputFilename.getValue().c_str(), + (Force.getValue() ? 0 : ios::noreplace)|ios::out); + } } - + + if (!Out->good()) { + cerr << "Error opening " << OutputFilename.getValue() + << ": 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... // - if (WriteMode == Default) { + if (WriteMode.getValue() == Default) { (*Out) << C; // Print out in list order } else { // TODO: This does not print anything other than the basic blocks in the @@ -98,20 +96,20 @@ int main(int argc, char **argv) { Method *M = *I; (*Out) << "-------------- Method: " << M->getName() << " -------------\n"; - switch (WriteMode) { - case DepthFirst: // Depth First ordering + switch (WriteMode.getValue()) { + case dfo: // Depth First ordering copy(cfg::df_begin(M), cfg::df_end(M), ostream_iterator<BasicBlock*>(*Out, "\n")); break; - case ReverseDepthFirst: // Reverse Depth First ordering + case rdfo: // Reverse Depth First ordering copy(cfg::df_begin(M, true), cfg::df_end(M), ostream_iterator<BasicBlock*>(*Out, "\n")); break; - case PostOrder: // Post Order + case po: // Post Order copy(cfg::po_begin(M), cfg::po_end(M), ostream_iterator<BasicBlock*>(*Out, "\n")); break; - case ReversePostOrder: { // Reverse Post Order + case rpo: { // Reverse Post Order cfg::ReversePostOrderTraversal RPOT(M); copy(RPOT.begin(), RPOT.end(), ostream_iterator<BasicBlock*>(*Out, "\n")); diff --git a/tools/llc/LLCOptions.cpp b/tools/llc/LLCOptions.cpp deleted file mode 100644 index 1f367a2d18..0000000000 --- a/tools/llc/LLCOptions.cpp +++ /dev/null @@ -1,125 +0,0 @@ -// $Id$ -//**************************************************************************/ -// File: -// LLCOptions.cpp -// -// Purpose: -// Options for the llc compiler. -// -// History: -// 7/15/01 - Vikram Adve - Created -// -//**************************************************************************/ - -//************************** System Include Files **************************/ - -#include <iostream.h> -#include <unistd.h> - - -//*************************** User Include Files ***************************/ - -#include "llvm/Support/ProgramOptions.h" -#include "llvm/Support/ProgramOption.h" -#include "LLCOptions.h" - - -//--------------------------------------------------------------------------- -// class LLCOptions -//--------------------------------------------------------------------------- - -/*ctor*/ -LLCOptions::LLCOptions (int _argc, - const char* _argv[], - const char* _envp[]) - : ProgramOptions(_argc, _argv, _envp) -{ - InitializeOptions(); - ParseArgs(argc, argv, envp); - CheckParse(); -} - -/*dtor*/ -LLCOptions::~LLCOptions() -{} - -//-------------------------------------------------------------------- -// Initialize all our compiler options -//-------------------------------------------------------------------- - -void -LLCOptions::InitializeOptions() -{ - Register(new FlagOption(HELP_OPT, - "print usage message", - false /*initValue*/)); - - Register(new FlagOption(DEBUG_OPT, - "turn on default debugging options", - false /*initValue*/)); - - Register(new FlagOption(DEBUG_OPT, - "turn off all diagnostic messages", - false /*initValue*/)); - - Register(new StringOption(OUTFILENAME_OPT, - "output file name", - "" /*initValue*/)); - - Register(new IntegerValuedOption(DEBUG_INSTR_SELECT_OPT, - "control amount of debugging information for instruction selection", - 0 /*initValue*/)); -} - - -void -LLCOptions::ParseExtraArgs() -{ - if (argsConsumed != argc-1) - Usage(); - - // input file name should be the last argument - inputFileName = argv[argc-1]; - - // output file name may be specified with -o option; - // otherwise create it from the input file name by replace ".ll" with ".o" - const string &outfilenameOpt = StringOptionValue(OUTFILENAME_OPT); - if (outfilenameOpt.length()) - {// "-o" option was used - outputFileName = outfilenameOpt; - } - else - { - outputFileName = inputFileName; - unsigned int suffixPos = outputFileName.rfind(".bc"); - - if (suffixPos >= outputFileName.length()) - suffixPos = outputFileName.rfind(".ll"); - - if (suffixPos >= outputFileName.length()) - { - cerr << "Unrecognized suffix in file name " << inputFileName << endl; - Usage(); - } - - outputFileName.replace(suffixPos, 3, ".o"); - } -} - -//-------------------------------------------------------------------- -// Functions that must be overridden in subclass of ProgramOptions -//-------------------------------------------------------------------- - -void -LLCOptions::CheckParse() -{} - -void -LLCOptions::PrintUsage(ostream& stream) const -{ - stream << "\nUSAGE:\n\t" << ProgramName() << " [options] " - << "llvm-file" << endl << endl; - PrintOptions(stream); -} - - diff --git a/tools/llc/LLCOptions.h b/tools/llc/LLCOptions.h deleted file mode 100644 index cad1d4f935..0000000000 --- a/tools/llc/LLCOptions.h +++ /dev/null @@ -1,74 +0,0 @@ -// $Id$ -*-c++-*- -//**************************************************************************/ -// File: -// LLCOptions.h -// -// Purpose: -// Options for the llc compiler. -// -// History: -// 7/15/01 - Vikram Adve - Created -// -//**************************************************************************/ - -#ifndef LLVM_LLC_LLCOPTIONS_H -#define LLVM_LLC_LLCOPTIONS_H - -#include "llvm/Support/ProgramOptions.h" -#include "llvm/Support/ProgramOption.h" - -const char* const HELP_OPT = "help"; -const char* const DEBUG_OPT = "d"; -const char* const QUIET_OPT = "q"; -const char* const DEBUG_INSTR_SELECT_OPT= "debug_select"; -const char* const OUTFILENAME_OPT = "o"; - - -//--------------------------------------------------------------------------- -// class LLCOptions -//--------------------------------------------------------------------------- - -class LLCOptions : public ProgramOptions { -public: - /*ctor*/ LLCOptions (int _argc, - const char* _argv[], - const char* _envp[]); - /*dtor*/ virtual ~LLCOptions (); - - const string& getInputFileName() const { return inputFileName; } - - const string& getOutputFileName() const { return outputFileName; } - -protected: - - //-------------------------------------------------------------------- - // Initialize for all our compiler options (called by constructors). - //-------------------------------------------------------------------- - void InitializeOptions(); - - //-------------------------------------------------------------------- - // Make sure the parse went ok. - //-------------------------------------------------------------------- - void CheckParse(); - - //-------------------------------------------------------------------- - // Parse arguments after all options are consumed. - // This is called after a successful ParseArgs. - //-------------------------------------------------------------------- - virtual void ParseExtraArgs(); - - //-------------------------------------------------------------------- - // Print message describing which arguments and options are - // required, optional, mutually exclusive, ... - // called in ProgramOptions::Usage() method - //-------------------------------------------------------------------- - virtual void PrintUsage(ostream& stream) const; - -private: - string inputFileName; - string outputFileName; -}; - -//**************************************************************************/ - -#endif diff --git a/tools/llc/Makefile b/tools/llc/Makefile index a5b098c073..adfd9c822b 100644 --- a/tools/llc/Makefile +++ b/tools/llc/Makefile @@ -1,10 +1,4 @@ LEVEL = ../.. - -## List source files in link order -Source = \ - llc.o \ - LLCOptions.o - include $(LEVEL)/Makefile.common all:: llc diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 4bf26d5a16..1ebfb5037e 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -18,12 +18,15 @@ #include "llvm/CodeGen/InstrSelection.h" #include "llvm/LLC/CompileContext.h" #include "llvm/CodeGen/Sparc.h" -#include "LLCOptions.h" +#include "llvm/Tools/CommandLine.h" + +cl::String InputFilename ("", "Input filename", cl::NoFlags, ""); +cl::String OutputFilename("o", "Output filename", cl::NoFlags, ""); + CompileContext::~CompileContext() { delete targetMachine; } -static bool CompileModule(Module *module, CompileContext& ccontext, - LLCOptions &Options) { +static bool CompileModule(Module *module, CompileContext& ccontext) { bool failed = false; for (Module::MethodListType::const_iterator @@ -33,8 +36,7 @@ static bool CompileModule(Module *module, CompileContext& ccontext, { Method* method = *methodIter; - if (SelectInstructionsForMethod(method, ccontext, - Options.IntOptionValue(DEBUG_INSTR_SELECT_OPT))) + if (SelectInstructionsForMethod(method, ccontext)) { failed = true; cerr << "Instruction selection failed for method " @@ -52,28 +54,28 @@ static bool CompileModule(Module *module, CompileContext& ccontext, // Entry point for the driver. //--------------------------------------------------------------------------- -int main(int argc, const char** argv, const char** envp) { - LLCOptions Options(argc, argv, envp); +int main(int argc, char** argv) { + cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n"); CompileContext compileContext(new UltraSparc()); - - Module *module = ParseBytecodeFile(Options.getInputFileName()); + + Module *module = ParseBytecodeFile(InputFilename.getValue()); if (module == 0) { cerr << "bytecode didn't read correctly.\n"; return 1; } - bool failure = CompileModule(module, compileContext, Options); + bool failure = CompileModule(module, compileContext); if (failure) { cerr << "Error compiling " - << Options.getInputFileName() << "!\n"; + << InputFilename.getValue() << "!\n"; delete module; return 1; } // Okay, we're done now... write out result... // WriteBytecodeToFile(module, - // compileContext.getOptions().getOutputFileName); + // OutputFilename.getValue()); // Clean up and exit delete module; diff --git a/tools/llvm-as/Makefile b/tools/llvm-as/Makefile index 9d36cc1d00..fcb9293572 100644 --- a/tools/llvm-as/Makefile +++ b/tools/llvm-as/Makefile @@ -6,4 +6,4 @@ clean:: rm -f as as : $(ObjectsG) - $(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore + $(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore -lsupport diff --git a/tools/llvm-as/as.cpp b/tools/llvm-as/as.cpp index 2c319a0849..da05a36f7f 100644 --- a/tools/llvm-as/as.cpp +++ b/tools/llvm-as/as.cpp @@ -18,54 +18,49 @@ #include "llvm/Bytecode/Writer.h" #include "llvm/Tools/CommandLine.h" +cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-"); +cl::String OutputFilename("o", "Override output filename", 0, ""); +cl::Flag Force ("f", "Overwrite output files", 0, false); +cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false); int main(int argc, char **argv) { - ToolCommandLine Opts(argc, argv); - bool DumpAsm = false; + cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n"); - 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... + ostream *Out = 0; try { // Parse the file now... - Module *C = ParseAssemblyFile(Opts); + Module *C = ParseAssemblyFile(InputFilename.getValue()); if (C == 0) { cerr << "assembly didn't read correctly.\n"; return 1; } - if (DumpAsm) + if (DumpAsm.getValue()) cerr << "Here's the assembly:\n" << C; + + if (OutputFilename.getValue() != "") { // Specified an output filename? + Out = new ofstream(OutputFilename.getValue().c_str(), + (Force.getValue() ? 0 : ios::noreplace)|ios::out); + } else { + if (InputFilename.getValue() == "-") { + OutputFilename.setValue("-"); + Out = &cout; + } else { + string IFN = InputFilename.getValue(); + int Len = IFN.length(); + if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') { + // Source ends in .ll + OutputFilename.setValue(string(IFN.begin(), IFN.end()-3)); + } else { + OutputFilename.setValue(IFN); // Append a .bc to it + } + OutputFilename.setValue(OutputFilename.getValue() + ".bc"); + Out = new ofstream(OutputFilename.getValue().c_str(), + (Force.getValue() ? 0 : ios::noreplace)|ios::out); + } - 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"; + cerr << "Error opening " << OutputFilename.getValue() << "!\n"; delete C; return 1; } diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index 2c319a0849..da05a36f7f 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -18,54 +18,49 @@ #include "llvm/Bytecode/Writer.h" #include "llvm/Tools/CommandLine.h" +cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-"); +cl::String OutputFilename("o", "Override output filename", 0, ""); +cl::Flag Force ("f", "Overwrite output files", 0, false); +cl::Flag DumpAsm ("d", "Print assembly as parsed", cl::Hidden, false); int main(int argc, char **argv) { - ToolCommandLine Opts(argc, argv); - bool DumpAsm = false; + cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n"); - 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++) { |