From 8f367bd3c0f56b7b318c46cee04f77735f617777 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 23 Jul 2001 02:35:57 +0000 Subject: 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 --- tools/analyze/Makefile | 3 +- tools/analyze/analyze.cpp | 95 +++++++++++++++++---------------- tools/as/Makefile | 2 +- tools/as/as.cpp | 65 +++++++++++------------ tools/dis/Makefile | 2 +- tools/dis/dis.cpp | 104 ++++++++++++++++++------------------ tools/llc/LLCOptions.cpp | 125 -------------------------------------------- tools/llc/LLCOptions.h | 74 -------------------------- tools/llc/Makefile | 6 --- tools/llc/llc.cpp | 26 ++++----- tools/llvm-as/Makefile | 2 +- tools/llvm-as/as.cpp | 65 +++++++++++------------ tools/llvm-as/llvm-as.cpp | 65 +++++++++++------------ tools/llvm-dis/Makefile | 2 +- tools/llvm-dis/dis.cpp | 104 ++++++++++++++++++------------------ tools/llvm-dis/llvm-dis.cpp | 104 ++++++++++++++++++------------------ tools/opt/Makefile | 2 +- tools/opt/opt.cpp | 93 +++++++++++++++++--------------- tools/opt/test.sh | 4 -- tools/opt/testinline.sh | 3 -- tools/opt/teststrip.sh | 3 -- 21 files changed, 367 insertions(+), 582 deletions(-) delete mode 100644 tools/llc/LLCOptions.cpp delete mode 100644 tools/llc/LLCOptions.h delete mode 100755 tools/opt/test.sh delete mode 100755 tools/opt/testinline.sh delete mode 100755 tools/opt/teststrip.sh (limited to 'tools') diff --git a/tools/analyze/Makefile b/tools/analyze/Makefile index b33d40b..1ff0e53 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 cf93ea9..4dc00b2 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 file to analyze", 0, "-"); +cl::Flag Quiet ("q", "Don't print analysis pass names", 0, false); +cl::EnumList 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 9d36cc1..fcb9293 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 2c319a0..da05a36 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 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 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 e6624ab..8ce3e21 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 deaf3a2..f243baa 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 file, print as assembly", 0, "-"); +cl::String OutputFilename("o", "Override output filename", 0, ""); +cl::Flag Force ("f", "Overwrite output files", 0, false); +cl::EnumFlags 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 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(*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(*Out, "\n")); break; - case PostOrder: // Post Order + case po: // Post Order copy(cfg::po_begin(M), cfg::po_end(M), ostream_iterator(*Out, "\n")); break; - case ReversePostOrder: { // Reverse Post Order + case rpo: { // Reverse Post Order cfg::ReversePostOrderTraversal RPOT(M); copy(RPOT.begin(), RPOT.end(), ostream_iterator(*Out, "\n")); diff --git a/tools/llc/LLCOptions.cpp b/tools/llc/LLCOptions.cpp deleted file mode 100644 index 1f367a2..0000000 --- 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 -#include - - -//*************************** 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 cad1d4f..0000000 --- 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 a5b098c..adfd9c8 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 4bf26d5..1ebfb50 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 9d36cc1..fcb9293 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 2c319a0..da05a36 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 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 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 2c319a0..da05a36 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 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 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-dis/Makefile b/tools/llvm-dis/Makefile index e6624ab..8ce3e21 100644 --- a/tools/llvm-dis/Makefile +++ b/tools/llvm-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/llvm-dis/dis.cpp b/tools/llvm-dis/dis.cpp index deaf3a2..f243baa 100644 --- a/tools/llvm-dis/dis.cpp +++ b/tools/llvm-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 file, print as assembly", 0, "-"); +cl::String OutputFilename("o", "Override output filename", 0, ""); +cl::Flag Force ("f", "Overwrite output files", 0, false); +cl::EnumFlags 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 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(*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(*Out, "\n")); break; - case PostOrder: // Post Order + case po: // Post Order copy(cfg::po_begin(M), cfg::po_end(M), ostream_iterator(*Out, "\n")); break; - case ReversePostOrder: { // Reverse Post Order + case rpo: { // Reverse Post Order cfg::ReversePostOrderTraversal RPOT(M); copy(RPOT.begin(), RPOT.end(), ostream_iterator(*Out, "\n")); diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index deaf3a2..f243baa 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-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 file, print as assembly", 0, "-"); +cl::String OutputFilename("o", "Override output filename", 0, ""); +cl::Flag Force ("f", "Overwrite output files", 0, false); +cl::EnumFlags 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 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(*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(*Out, "\n")); break; - case PostOrder: // Post Order + case po: // Post Order copy(cfg::po_begin(M), cfg::po_end(M), ostream_iterator(*Out, "\n")); break; - case ReversePostOrder: { // Reverse Post Order + case rpo: { // Reverse Post Order cfg::ReversePostOrderTraversal RPOT(M); copy(RPOT.begin(), RPOT.end(), ostream_iterator(*Out, "\n")); diff --git a/tools/opt/Makefile b/tools/opt/Makefile index 4a14d37..658b299 100644 --- a/tools/opt/Makefile +++ b/tools/opt/Makefile @@ -7,4 +7,4 @@ clean :: opt : $(ObjectsG) ../../lib/Optimizations/Debug/libopt.a $(LinkG) -o $@ $(ObjectsG) -lopt -lbcreader -lbcwriter \ - -lasmwriter -lanalysis -lvmcore + -lasmwriter -lanalysis -lvmcore -lsupport diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 70c2efe..2b5b069 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -29,70 +29,81 @@ using namespace opt; +enum Opts { + // Basic optimizations + dce, constprop, inlining, strip, mstrip, + + // More powerful optimizations + indvars, sccp, cpm, adce, raise, +}; + struct { - const string ArgName, Name; + enum Opts OptID; 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 }, - { "-indvars" , "Simplify Induction Vars",DoInductionVariableCannonicalize }, - { "-sccp" , "Sparse Conditional Constant Prop", DoSCCP }, - { "-cpm" , "Constant Pool Merging", DoConstantPoolMerging }, - { "-adce" , "Agressive DCE", DoADCE }, - { "-raise" , "Raise to Higher Level", DoRaiseRepresentation }, + { dce , DoDeadCodeElimination }, + { constprop, DoConstantPropogation }, + { inlining , DoMethodInlining }, + { strip , DoSymbolStripping }, + { mstrip , DoFullSymbolStripping }, + { indvars , DoInductionVariableCannonicalize }, + { sccp , DoSCCP }, + { cpm , DoConstantPoolMerging }, + { adce , DoADCE }, + { raise , DoRaiseRepresentation }, }; -int main(int argc, char **argv) { - ToolCommandLine Opts(argc, argv, false); - bool Quiet = false; +cl::String InputFilename ("", "Load file to optimize", 0, "-"); +cl::String OutputFilename("o", "Override output filename", 0, ""); +cl::Flag Force ("f", "Overwrite output files", 0, false); +cl::Flag Quiet ("q", "Don't print modifying pass names", 0, false); +cl::EnumList OptimizationList(cl::NoFlags, + clEnumVal(dce , "Dead Code Elimination"), + clEnumVal(constprop, "Simple Constant Propogation"), + clEnumValN(inlining , "inline", "Method Inlining"), + clEnumVal(strip , "Strip Symbols"), + clEnumVal(mstrip , "Strip Module Symbols"), + clEnumVal(indvars , "Simplify Induction Variables"), + clEnumVal(sccp , "Sparse Conditional Constant Propogation"), + clEnumVal(cpm , "Constant Pool Merging"), + clEnumVal(adce , "Agressive DCE"), + clEnumVal(raise , "Raise to Higher Level"), +0); - 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"; - for (unsigned j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); ++j) { - cerr << "\t" << OptTable[j].ArgName << "\t - Enable " - << OptTable[j].Name << endl; - } - 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()); +int main(int argc, char **argv) { + cl::ParseCommandLineOptions(argc, argv, + " llvm .bc -> .bc modular optimizer\n"); + + Module *C = ParseBytecodeFile(InputFilename.getValue()); if (C == 0) { cerr << "bytecode didn't read correctly.\n"; return 1; } + for (unsigned i = 0; i < OptimizationList.size(); ++i) { + enum Opts Opt = OptimizationList[i]; - 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) { + for (j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); ++j) { + if (Opt == OptTable[j].OptID) { if (OptTable[j].OptPtr(C) && !Quiet) - cerr << OptTable[j].Name << " pass made modifications!\n"; + cerr << OptimizationList.getArgName(Opt) + << " pass made modifications!\n"; break; } } if (j == sizeof(OptTable)/sizeof(OptTable[0])) - cerr << "'" << argv[i] << "' argument unrecognized: ignored\n"; + cerr << "Optimization tables inconsistent!!\n"; } - if (Opts.getOutputFilename() != "-") { - Out = new ofstream(Opts.getOutputFilename().c_str(), - (Opts.getForce() ? 0 : ios::noreplace)|ios::out); + ostream *Out = &cout; // Default to printing to stdout... + if (OutputFilename.getValue() != "") { + Out = new ofstream(OutputFilename.getValue().c_str(), + (Force.getValue() ? 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/opt/test.sh b/tools/opt/test.sh deleted file mode 100755 index b6d13f4..0000000 --- a/tools/opt/test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -../as/as < ../../test/$1 | ./opt -constprop -dce | ../dis/dis - diff --git a/tools/opt/testinline.sh b/tools/opt/testinline.sh deleted file mode 100755 index ff16a66..0000000 --- a/tools/opt/testinline.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -../as/as < ../../test/$1 | ./opt -inline -constprop -dce | dis diff --git a/tools/opt/teststrip.sh b/tools/opt/teststrip.sh deleted file mode 100755 index 2cff3bf..0000000 --- a/tools/opt/teststrip.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -../as/as < ../../test/$1 | ./opt -strip | dis -- cgit v1.1