summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-23 02:35:57 +0000
committerChris Lattner <sabre@nondot.org>2001-07-23 02:35:57 +0000
commit8f367bd3c0f56b7b318c46cee04f77735f617777 (patch)
treeef00b00e2465f9168bbbd83fd2ebef8fa857146f
parenta28504313d4c3fe87173a71b511dd4c8e25c3312 (diff)
downloadllvm-8f367bd3c0f56b7b318c46cee04f77735f617777.tar.gz
llvm-8f367bd3c0f56b7b318c46cee04f77735f617777.tar.bz2
llvm-8f367bd3c0f56b7b318c46cee04f77735f617777.tar.xz
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
-rw-r--r--include/llvm/Assembly/Parser.h11
-rw-r--r--include/llvm/CodeGen/InstrSelection.h5
-rw-r--r--include/llvm/Support/ProgramOption.h142
-rw-r--r--include/llvm/Support/ProgramOptions.h145
-rw-r--r--include/llvm/Tools/CommandLine.h370
-rw-r--r--lib/CodeGen/InstrSelection/InstrSelection.cpp24
-rw-r--r--lib/Support/Makefile5
-rw-r--r--lib/Target/SparcV9/InstrSelection/InstrSelection.cpp24
-rw-r--r--support/lib/Support/Makefile5
-rw-r--r--support/lib/Support/ProgramOption.cpp114
-rw-r--r--support/lib/Support/ProgramOptions.cpp243
-rw-r--r--tools/analyze/Makefile3
-rw-r--r--tools/analyze/analyze.cpp95
-rw-r--r--tools/as/Makefile2
-rw-r--r--tools/as/as.cpp65
-rw-r--r--tools/dis/Makefile2
-rw-r--r--tools/dis/dis.cpp104
-rw-r--r--tools/llc/LLCOptions.cpp125
-rw-r--r--tools/llc/LLCOptions.h74
-rw-r--r--tools/llc/Makefile6
-rw-r--r--tools/llc/llc.cpp26
-rw-r--r--tools/llvm-as/Makefile2
-rw-r--r--tools/llvm-as/as.cpp65
-rw-r--r--tools/llvm-as/llvm-as.cpp65
-rw-r--r--tools/llvm-dis/Makefile2
-rw-r--r--tools/llvm-dis/dis.cpp104
-rw-r--r--tools/llvm-dis/llvm-dis.cpp104
-rw-r--r--tools/opt/Makefile2
-rw-r--r--tools/opt/opt.cpp93
-rwxr-xr-xtools/opt/test.sh4
-rwxr-xr-xtools/opt/testinline.sh3
-rwxr-xr-xtools/opt/teststrip.sh3
32 files changed, 671 insertions, 1366 deletions
diff --git a/include/llvm/Assembly/Parser.h b/include/llvm/Assembly/Parser.h
index 5ac6ec20fa..4dc2bfb059 100644
--- a/include/llvm/Assembly/Parser.h
+++ b/include/llvm/Assembly/Parser.h
@@ -10,14 +10,13 @@
#include <string>
class Module;
-class ToolCommandLine;
class ParseException;
// The useful interface defined by this file... Parse an ascii file, and return
// the internal representation in a nice slice'n'dice'able representation.
//
-Module *ParseAssemblyFile(const ToolCommandLine &Opts) throw (ParseException);
+Module *ParseAssemblyFile(const string &Filename) throw (ParseException);
//===------------------------------------------------------------------------===
// Helper Classes
@@ -28,7 +27,7 @@ Module *ParseAssemblyFile(const ToolCommandLine &Opts) throw (ParseException);
//
class ParseException {
public:
- ParseException(const ToolCommandLine &Opts, const string &message,
+ ParseException(const string &filename, const string &message,
int LineNo = -1, int ColNo = -1);
ParseException(const ParseException &E);
@@ -42,8 +41,8 @@ public:
return Message;
}
- inline const ToolCommandLine &getOptions() const {
- return Opts; // Get the options obj used to parse.
+ inline const string &getFilename() const {
+ return Filename;
}
// getErrorLocation - Return the line and column number of the error in the
@@ -56,7 +55,7 @@ public:
}
private :
- const ToolCommandLine &Opts;
+ string Filename;
string Message;
int LineNo, ColumnNo; // -1 if not relevant
diff --git a/include/llvm/CodeGen/InstrSelection.h b/include/llvm/CodeGen/InstrSelection.h
index 0873003baf..e5a93b4727 100644
--- a/include/llvm/CodeGen/InstrSelection.h
+++ b/include/llvm/CodeGen/InstrSelection.h
@@ -22,8 +22,6 @@ class InstructionNode;
class TmpInstruction;
class ConstPoolVal;
-enum { DEBUG_TREES_NONE = 0, DEBUG_INSTR_TREES = 1, DEBUG_BURG_TREES = 5 };
-
//---------------------------------------------------------------------------
// GLOBAL data and an external function that must be implemented
// for each architecture.
@@ -53,8 +51,7 @@ extern bool ThisIsAChainRule (int eruleno);
//---------------------------------------------------------------------------
bool SelectInstructionsForMethod (Method* method,
- CompileContext& ccontext,
- int DebugLevel);
+ CompileContext& ccontext);
// Debugging function to print the generated instructions
diff --git a/include/llvm/Support/ProgramOption.h b/include/llvm/Support/ProgramOption.h
deleted file mode 100644
index 83eeac60a8..0000000000
--- a/include/llvm/Support/ProgramOption.h
+++ /dev/null
@@ -1,142 +0,0 @@
-// $Id$ -*-c++-*-
-//***************************************************************************
-//
-// File:
-// ProgramOption.h
-//
-// Purpose:
-// General representations for a program option.
-//
-// History:
-// 08/08/95 - adve - created in the dHPF compiler
-// 11/26/96 - adve - EvalOpt now returns #args consumed, or -1 for error
-// 07/15/01 - vadve - Copied to LLVM system and modified
-//
-//**************************************************************************/
-
-#ifndef LLVM_SUPPORT_PROGRAMOPTION_H
-#define LLVM_SUPPORT_PROGRAMOPTION_H
-
-#include "llvm/Support/Unique.h"
-#include <string>
-
-
-class ProgramOption: public Unique {
-public:
- /*ctor*/ ProgramOption (const string &_argString,
- const string &_helpMesg,
- int _minExpectedArgs = 1)
- : optionSpecified(false),
- argString(_argString),
- helpMesg(_helpMesg),
- minExpectedArgs(_minExpectedArgs) {}
-
- /*dtor*/ virtual ~ProgramOption() {}
-
- // Pure virtual function for an option with 0 or more arguments.
- // `optarg' points to the start of the next word in argv[].
- // It will be NULL if there are no more words.
- // The return value indicates the number of words of argv[] that
- // were consumed by EvalOpt and should be discarded.
- // A return value of -1 indicates an error.
- //
- virtual int EvalOpt (const string &) = 0;
-
- // Returns the value associated with the option as a human-readable
- // string.
- virtual string GetTextValue () const = 0;
-
- // Inline accessor functions for common option information
- //
- bool OptionSpecified () const { return optionSpecified; }
- const string ArgString () const { return argString; }
- const string HelpMesg () const { return helpMesg; }
- int MinExpectedArgs () const { return minExpectedArgs; }
-
-protected:
- bool optionSpecified;
- string argString;
- string helpMesg;
- int minExpectedArgs;
-};
-
-//**************************************************************************/
-
-class StringOption : public ProgramOption {
-public:
- /*ctor*/ StringOption (const string &argString,
- const string &helpMesg,
- const string &initValue = "",
- bool append = false);
- // append = false: EvalOpt will overwrite preexisting value
- // append = true : EvalOpt will append <optArg> to value
-
- /*dtor*/ virtual ~StringOption () {}
-
- virtual int EvalOpt (const string &optarg);
-
- const string &Value() const { return value; }
- virtual string GetTextValue() const { return value; }
-
-protected:
- string value;
- bool append;
-};
-
-//**************************************************************************/
-
-// -<flag_opt> sets the flag to TRUE
-// -<flag_opt> 0 sets the flag to FALSE
-//
-// To provide an actual argument (not option) of "0", mark the
-// end of the options with "--" (see getopt(1)).
-
-class FlagOption : public ProgramOption {
-public:
- FlagOption(const string &argString, const string &helpMesg,
- bool initValue = false);
-
- virtual ~FlagOption() {}
-
- virtual int EvalOpt (const string &optarg);
-
- bool Value () const { return value; }
- virtual string GetTextValue() const { return value ? "true" : "false";}
-private:
- bool value;
-};
-
-//**************************************************************************/
-
-class RealValuedOption : public ProgramOption {
-public:
- /*ctor*/ RealValuedOption(const string &argString,
- const string &helpMesg,
- double initValue = 0.0);
- /*dtor*/ virtual ~RealValuedOption() {}
-
- virtual int EvalOpt (const string &optarg);
-
- double Value () const { return value; }
- virtual string GetTextValue() const;
-
-private:
- double value;
-};
-
-//**************************************************************************/
-
-class IntegerValuedOption : public RealValuedOption {
-public:
- /*ctor*/ IntegerValuedOption(const string &argString,
- const string &helpMesg,
- int initValue = 0);
- /*ctor*/ virtual ~IntegerValuedOption() {}
-
- int Value() const;
- virtual string GetTextValue() const;
-};
-
-//**************************************************************************/
-
-#endif
diff --git a/include/llvm/Support/ProgramOptions.h b/include/llvm/Support/ProgramOptions.h
deleted file mode 100644
index 9ebc975c46..0000000000
--- a/include/llvm/Support/ProgramOptions.h
+++ /dev/null
@@ -1,145 +0,0 @@
-// $Id$ -*-c++-*-
-//***************************************************************************
-//
-// File:
-// ProgramOptions.h
-//
-// Purpose:
-// A representation of options for any program.
-//
-// History:
-// 08/08/95 - adve - Created in the dHPF compiler
-// 10/10/96 - mpal, dbaker - converted to const member functions.
-// 10/19/96 - meven - slightly changed interface to accomodate
-// arguments other than -X type options
-// 07/15/01 - vadve - Copied to LLVM system and modified
-//
-//**************************************************************************/
-
-#ifndef LLVM_SUPPORT_PROGRAMOPTIONS_H
-#define LLVM_SUPPORT_PROGRAMOPTIONS_H
-
-#include "llvm/Support/Unique.h"
-#include <vector>
-#include <hash_map>
-#include <string>
-
-template <> struct hash<string> {
- size_t operator()(string const &str) const {
- return hash<char const *>()(str.c_str());
- }
-};
-
-class ProgramOption;
-
-//---------------------------------------------------------------------------
-//
-// Class: ProgramOptions
-//
-// Base Classes: none
-//
-// Class Data Members:
-// ProgramOptionsRepr* Internal representation of program options,
-// accessible to derived classes.
-// Purpose:
-// Base class for representing the set of options for a program.
-//
-//---------------------------------------------------------------------------
-
-class ProgramOptions: public Unique {
-public:
- /*ctor*/ ProgramOptions (int _argc,
- const char* _argv[],
- const char* _envp[]);
- /*dtor*/ ~ProgramOptions () {}
-
- //--------------------------------------------------------------------
- // Retrieving different kinds of arguments.
- // The required argument is specified by the optionString.
- //--------------------------------------------------------------------
-
- string StringOptionValue(const string &optionString) const;
- bool FlagOptionValue (const string &optionString) const;
- double RealOptionValue (const string &optionString) const;
- int IntOptionValue (const string &optionString) const;
-
- bool OptionSpecified (const string &optionString) const;
-
- //--------------------------------------------------------------------
- // The name used to invoke this program.
- //--------------------------------------------------------------------
- const char* ProgramName () const;
-
- //--------------------------------------------------------------------
- // Access to unparsed arguments
- //--------------------------------------------------------------------
- int NumberOfOtherOptions() const;
- const char* OtherOption(int i) const;
-
- //--------------------------------------------------------------------
- // Access to the original arguments
- //--------------------------------------------------------------------
- const char** GetOriginalArgs() const;
- void PrintArgs(ostream &out) const;
-
- //--------------------------------------------------------------------
- // Derived classes may use PrintOptions in their own PrintUsage() fct
- // to print information about optional, required, or additional
- // arguments
- //--------------------------------------------------------------------
- virtual void PrintOptions (ostream& stream) const;
- virtual void Usage () const;
-
- //--------------------------------------------------------------------
- // Generate a human-friendly description of the options actually set.
- // The vector returned contains a multiple of 3 of entries, entry 3n is
- // the name of the option, entry 3n + 1 contains the description of
- // the option and entry 3n + 2 contains the ascii value of the option.
- // All entries are allocated using malloc and can be freed with 'free'.
- //--------------------------------------------------------------------
- virtual vector<string> GetDescription () const;
-
-protected:
- //--------------------------------------------------------------------
- // Called by the subclass to register each possible option
- // used by the program. Assumes ownership of the ProgramOption.
- //--------------------------------------------------------------------
- void Register (ProgramOption* option);
-
- //--------------------------------------------------------------------
- // Parses the options.
- //--------------------------------------------------------------------
- void ParseArgs (int argc,
- const char* argv[],
- const char* envp[]);
-
- inline ProgramOption* OptionHandler(const string &optString) {
- hash_map<string, ProgramOption*>::iterator hp =
- optionRegistry.find(optString);
- return (hp != optionRegistry.end()) ? hp->second : 0;
- }
- inline const ProgramOption* OptionHandler(const string &optString) const {
- hash_map<string, ProgramOption*>::const_iterator hp =
- optionRegistry.find(optString);
- return (hp != optionRegistry.end()) ? hp->second : 0;
- }
-protected:
- //--------------------------------------------------------------------
- // Functions that must be overridden by the subclass.
- //--------------------------------------------------------------------
-
- virtual void ParseExtraArgs () = 0; // called after successful ParseArgs
-
- virtual void PrintUsage (ostream& stream) const = 0;
-
-protected:
- hash_map<string, ProgramOption*> optionRegistry;
- int argc;
- const char** argv;
- const char** envp;
- int argsConsumed;
-};
-
-//**************************************************************************/
-
-#endif
diff --git a/include/llvm/Tools/CommandLine.h b/include/llvm/Tools/CommandLine.h
index 76b4e97989..35d96d4922 100644
--- a/include/llvm/Tools/CommandLine.h
+++ b/include/llvm/Tools/CommandLine.h
@@ -1,12 +1,8 @@
//===-- llvm/Tools/CommandLine.h - Command line parser for tools -*- C++ -*--=//
//
// This class implements a command line argument processor that is useful when
-// creating a tool.
-//
-// This class is defined entirely inline so that you don't have to link to any
-// libraries to use this.
-//
-// TODO: make this extensible by passing in arguments to be read.
+// creating a tool. It provides a simple, minimalistic interface that is easily
+// extensible and supports nonlocal (library) command line options.
//
//===----------------------------------------------------------------------===//
@@ -14,113 +10,275 @@
#define LLVM_TOOLS_COMMANDLINE_H
#include <string>
+#include <vector>
+#include <utility>
+#include <stdarg.h>
+
+namespace cl { // Short namespace to make usage concise
+
+//===----------------------------------------------------------------------===//
+// ParseCommandLineOptions - Minimalistic command line option processing entry
+//
+void cl::ParseCommandLineOptions(int &argc, char **argv,
+ const char *Overview = 0);
+
+
+//===----------------------------------------------------------------------===//
+// Global flags permitted to be passed to command line arguments
+
+enum FlagsOptions {
+ NoFlags = 0x00, // Marker to make explicit that we have no flags
+
+ // Flags for the number of occurances allowed...
+ Optional = 0x00, // Zero or One occurance
+ ZeroOrMore = 0x01, // Zero or more occurances allowed
+ Required = 0x02, // One occurance required
+ OneOrMore = 0x03, // One or more occurances required
+ OccurancesMask = 0x07,
+
+ // Number of arguments to a value expected...
+ //Optional = 0x00, // The value can oppear... or not
+ ValueRequired = 0x08, // The value is required to appear!
+ ValueDisallowed = 0x10, // A value may not be specified (for flags)
+ ValueMask = 0x18,
+
+ // Control whether -help shows the command line option...
+ Hidden = 0x20, // -help doesn't -help-hidden does
+ ReallyHidden = 0x60, // Neither -help nor -help-hidden show this arg
+ HiddenMask = 0x60,
+};
+
+
+//===----------------------------------------------------------------------===//
+// Option Base class
+//
+class Option {
+ friend void cl::ParseCommandLineOptions(int &, char **, const char *Overview);
+
+ // handleOccurances - Overriden by subclasses to handle the value passed into
+ // an argument. Should return true if there was an error processing the
+ // argument and the program should exit.
+ //
+ virtual bool handleOccurance(const char *ArgName, const string &Arg) = 0;
+
+ int NumOccurances; // The number of times specified
+public:
+ const char * const ArgStr; // The argument string itself (ex: "help", "o")
+ const char * const HelpStr; // The descriptive text message for --help
+ const int Flags; // Flags for the argument
+
+protected:
+ Option(const char *ArgStr, const char *Message, int Flags);
+ Option(int flags) : ArgStr(""), HelpStr(""), Flags(flags) {}
+
+ // Prints option name followed by message. Always returns true.
+ bool error(string Message, const char *ArgName = 0);
+
+ // addOccurance - Wrapper around handleOccurance that enforces Flags
+ //
+ bool addOccurance(const char *ArgName, const string &Value);
+
+public:
+ // Return the width of the option tag for printing...
+ virtual unsigned getOptionWidth() const;
+
+ // printOptionInfo - Print out information about this option. The
+ // to-be-maintained width is specified.
+ //
+ virtual void printOptionInfo(unsigned GlobalWidth) const;
+
+public:
+ inline int getNumOccurances() const { return NumOccurances; }
+ virtual ~Option() {}
+};
+
+
+//===----------------------------------------------------------------------===//
+// Boolean/flag command line option
+//
+class Flag : public Option {
+ bool Value;
+ virtual bool handleOccurance(const char *ArgName, const string &Arg);
+public:
+ inline Flag(const char *ArgStr, const char *Message, int Flags = 0,
+ bool DefaultVal = 0) : Option(ArgStr, Message, Flags),
+ Value(DefaultVal) {}
+ operator bool() const { return Value; }
+ inline bool getValue() const { return Value; }
+ inline void setValue(bool Val) { Value = Val; }
+};
+
+
+
+//===----------------------------------------------------------------------===//
+// Integer valued command line option
+//
+class Int : public Option {
+ int Value;
+ virtual bool handleOccurance(const char *ArgName, const string &Arg);
+public:
+ inline Int(const char *ArgStr, const char *Help, int Flags = 0,
+ int DefaultVal = 0) : Option(ArgStr, Help, Flags | ValueRequired),
+ Value(DefaultVal) {}
+ inline operator int() const { return Value; }
+ inline int getValue() const { return Value; }
+ inline void setValue(int Val) { Value = Val; }
+};
+
-class ToolCommandLine {
+//===----------------------------------------------------------------------===//
+// String valued command line option
+//
+class String : public Option {
+ string Value;
+ virtual bool handleOccurance(const char *ArgName, const string &Arg);
+public:
+ inline String(const char *ArgStr, const char *Help, int Flags = 0,
+ const char *DefaultVal = "")
+ : Option(ArgStr, Help, Flags | ValueRequired), Value(DefaultVal) {}
+
+ inline const string &getValue() const { return Value; }
+ inline void setValue(const string &Val) { Value = Val; }
+};
+
+
+//===----------------------------------------------------------------------===//
+// Enum valued command line option
+//
+#define clEnumVal(ENUMVAL, DESC) #ENUMVAL, ENUMVAL, DESC
+#define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, ENUMVAL, DESC
+
+// EnumBase - Base class for all enum/varargs related argument types...
+class EnumBase : public Option {
+protected:
+ // Use a vector instead of a map, because the lists should be short,
+ // the overhead is less, and most importantly, it keeps them in the order
+ // inserted so we can print our option out nicely.
+ vector<pair<const char *, pair<int, const char *> > > ValueMap;
+
+ inline EnumBase(const char *ArgStr, const char *Help, int Flags)
+ : Option(ArgStr, Help, Flags) {}
+ inline EnumBase(int Flags) : Option(Flags) {}
+
+ // processValues - Incorporate the specifed varargs arglist into the
+ // ValueMap.
+ //
+ void processValues(va_list Vals);
+
+ // registerArgs - notify the system about these new arguments
+ void registerArgs();
+
+public:
+ // Turn an enum into the arg name that activates it
+ const char *getArgName(int ID) const;
+ const char *getArgDescription(int ID) const;
+};
+
+class EnumValueBase : public EnumBase {
+protected:
+ int Value;
+ inline EnumValueBase(const char *ArgStr, const char *Help, int Flags)
+ : EnumBase(ArgStr, Help, Flags) {}
+ inline EnumValueBase(int Flags) : EnumBase(Flags) {}
+
+ // handleOccurance - Set Value to the enum value specified by Arg
+ virtual bool handleOccurance(const char *ArgName, const string &Arg);
+
+ // Return the width of the option tag for printing...
+ virtual unsigned getOptionWidth() const;
+
+ // printOptionInfo - Print out information about this option. The
+ // to-be-maintained width is specified.
+ //
+ virtual void printOptionInfo(unsigned GlobalWidth) const;
+};
+
+template <class E> // The enum we are representing
+class Enum : public EnumValueBase {
public:
- inline ToolCommandLine(int &argc, char **argv, bool OutputBytecode = true);
- inline ToolCommandLine(const string &infn, const string &outfn = "-");
- inline ToolCommandLine(const ToolCommandLine &O);
- inline ToolCommandLine &operator=(const ToolCommandLine &O);
-
- inline bool getForce() const { return Force; }
- inline const string getInputFilename() const { return InputFilename; }
- inline const string getOutputFilename() const { return OutputFilename; }
-
-private:
- void calculateOutputFilename(bool OutputBytecode) {
- OutputFilename = InputFilename;
- unsigned Len = OutputFilename.length();
-
- if (Len <= 3) {
- OutputFilename += (OutputBytecode ? ".bc" : ".ll");
- return;
- }
-
- if (OutputBytecode) {
- if (OutputFilename[Len-3] == '.' &&
- OutputFilename[Len-2] == 'l' &&
- OutputFilename[Len-1] == 'l') { // .ll -> .bc
- OutputFilename[Len-2] = 'b';
- OutputFilename[Len-1] = 'c';
- } else {
- OutputFilename += ".bc";
- }
- } else {
- if (OutputFilename[Len-3] == '.' &&
- OutputFilename[Len-2] == 'b' &&
- OutputFilename[Len-1] == 'c') { // .ll -> .bc
- OutputFilename[Len-2] = 'l';
- OutputFilename[Len-1] = 'l';
- } else {
- OutputFilename += ".ll";
- }
- }
+ inline Enum(const char *ArgStr, int Flags, const char *Help, ...)
+ : EnumValueBase(ArgStr, Help, Flags | ValueRequired) {
+ va_list Values;
+ va_start(Values, Help);
+ processValues(Values);
+ va_end(Values);
+ Value = ValueMap.front().second.first; // Grab default value
}
-private:
- string InputFilename; // Filename to read from. If "-", use stdin.
- string OutputFilename; // Filename to write to. If "-", use stdout.
- bool Force; // Force output (-f argument)
+ inline E getValue() const { return (E)Value; }
+ inline void setValue(E Val) { Value = (E)Val; }
};
-inline ToolCommandLine::ToolCommandLine(int &argc, char **argv, bool OutBC)
- : InputFilename("-"), OutputFilename("-"), Force(false) {
- bool FoundInputFN = false;
- bool FoundOutputFN = false;
- bool FoundForce = false;
-
- for (int i = 1; i < argc; i++) {
- int RemoveArg = 0;
-
- if (argv[i][0] == '-') {
- if (!FoundInputFN && argv[i][1] == 0) { // Is the current argument '-'
- InputFilename = argv[i];
- FoundInputFN = true;
- RemoveArg = 1;
- } else if (!FoundOutputFN && (argv[i][1] == 'o' && argv[i][2] == 0)) {
- // Is the argument -o?
- if (i+1 < argc) { // Next arg is output fn
- OutputFilename = argv[i+1];
- FoundOutputFN = true;
- RemoveArg = 2;
- }
- } else if (!FoundForce && (argv[i][1] == 'f' && argv[i][2] == 0)) {
- Force = true;
- FoundForce = true;
- RemoveArg = 1;
- }
- } else if (!FoundInputFN) { // Is the current argument '[^-].*'?
- InputFilename = argv[i];
- FoundInputFN = true;
- RemoveArg = 1;
- }
-
- if (RemoveArg) {
- argc -= RemoveArg; // Shift args over...
- memmove(argv+i, argv+i+RemoveArg, (argc-i)*sizeof(char*));
- i--; // Reprocess this argument...
- }
+
+//===----------------------------------------------------------------------===//
+// Enum flags command line option
+//
+class EnumFlagsBase : public EnumValueBase {
+protected:
+ virtual bool handleOccurance(const char *ArgName, const string &Arg);
+ inline EnumFlagsBase(int Flags) : EnumValueBase(Flags | ValueDisallowed) {}
+
+ // Return the width of the option tag for printing...
+ virtual unsigned getOptionWidth() const;
+
+ // printOptionInfo - Print out information about this option. The
+ // to-be-maintained width is specified.
+ //
+ virtual void printOptionInfo(unsigned GlobalWidth) const;
+};
+
+template <class E> // The enum we are representing
+class EnumFlags : public EnumFlagsBase {
+public:
+ inline EnumFlags(int Flags, ...) : EnumFlagsBase(Flags) {
+ va_list Values;
+ va_start(Values, Flags);
+ processValues(Values);
+ va_end(Values);
+ registerArgs();
+ Value = ValueMap.front().second.first; // Grab default value
+ }
+ inline E getValue() const { return (E)Value; }
+ inline void setValue(E Val) { Value = (E)Val; }
+};
+
+
+//===----------------------------------------------------------------------===//
+// Enum list command line option
+//
+class EnumListBase : public EnumBase {
+protected:
+ vector<int> Values; // The options specified so far.
+
+ inline EnumListBase(int Flags)
+ : EnumBase(Flags | ValueDisallowed | ZeroOrMore) {}
+ virtual bool handleOccurance(const char *ArgName, const string &Arg);
+
+ // Return the width of the option tag for printing...
+ virtual unsigned getOptionWidth() const;
+
+ // printOptionInfo - Print out information about this option. The
+ // to-be-maintained width is specified.
+ //
+ virtual void printOptionInfo(unsigned GlobalWidth) const;
+public:
+ inline unsigned size() { return Values.size(); }
+};
+
+template <class E> // The enum we are representing
+class EnumList : public EnumListBase {
+public:
+ inline EnumList(int Flags, ...) : EnumListBase(Flags) {
+ va_list Values;
+ va_start(Values, Flags);
+ processValues(Values);
+ va_end(Values);
+ registerArgs();
}
+ inline E getValue(unsigned i) const { return (E)Values[i]; }
+ inline E operator[](unsigned i) const { return (E)Values[i]; }
+};
- if (!FoundOutputFN && InputFilename != "-")
- calculateOutputFilename(OutBC);
-}
-
-inline ToolCommandLine::ToolCommandLine(const string &inf,
- const string &outf)
- : InputFilename(inf), OutputFilename(outf), Force(false) {
-}
-
-inline ToolCommandLine::ToolCommandLine(const ToolCommandLine &Opts)
- : InputFilename(Opts.InputFilename), OutputFilename(Opts.OutputFilename),
- Force(Opts.Force) {
-}
-
-inline ToolCommandLine &ToolCommandLine::operator=(const ToolCommandLine &Opts){
- InputFilename = Opts.InputFilename;
- OutputFilename = Opts.OutputFilename;
- Force = Opts.Force;
- return *this;
-}
+} // End namespace cl
#endif
diff --git a/lib/CodeGen/InstrSelection/InstrSelection.cpp b/lib/CodeGen/InstrSelection/InstrSelection.cpp
index 4843a70dce..0ad1dbdb54 100644
--- a/lib/CodeGen/InstrSelection/InstrSelection.cpp
+++ b/lib/CodeGen/InstrSelection/InstrSelection.cpp
@@ -10,8 +10,6 @@
//***************************************************************************
-//*************************** User Include Files ***************************/
-
#include "llvm/CodeGen/InstrSelection.h"
#include "llvm/Method.h"
#include "llvm/BasicBlock.h"
@@ -20,7 +18,20 @@
#include "llvm/Instruction.h"
#include "llvm/LLC/CompileContext.h"
#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/Tools/CommandLine.h"
+
+enum DebugLev {
+ NoDebugInfo,
+ DebugInstTrees,
+ DebugBurgTrees,
+};
+// Enable Debug Options to be specified on the command line
+cl::Enum<enum DebugLev> DebugLevel("debug_select", cl::NoFlags, // cl::Hidden
+ "enable instruction selection debugging information",
+ clEnumVal(NoDebugInfo , "disable debug output"),
+ clEnumVal(DebugInstTrees, "print instruction trees"),
+ clEnumVal(DebugBurgTrees, "print burg trees"), 0);
//************************* Forward Declarations ***************************/
@@ -36,8 +47,7 @@ static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
// Returns true if instruction selection failed, false otherwise.
//---------------------------------------------------------------------------
-bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
- int DebugLevel) {
+bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext) {
bool failed = false;
InstrForest instrForest;
@@ -59,7 +69,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
// Invoke BURM to label each tree node with a state
(void) burm_label(basicNode);
- if (DebugLevel >= DEBUG_BURG_TREES)
+ if (DebugLevel.getValue() >= DebugBurgTrees)
{
printcover(basicNode, 1, 0);
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
@@ -76,7 +86,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
if (!failed)
{
- if (DebugLevel >= DEBUG_INSTR_TREES)
+ if (DebugLevel.getValue() >= DebugInstTrees)
{
cout << "\n\n*** Instruction trees for method "
<< (method->hasName()? method->getName() : "")
@@ -84,7 +94,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
instrForest.dump();
}
- if (DebugLevel >= DEBUG_TREES_NONE)
+ if (DebugLevel.getValue() > NoDebugInfo)
PrintMachineInstructions(method);
}
diff --git a/lib/Support/Makefile b/lib/Support/Makefile
index 7a41c62b04..c7eb8adcb1 100644
--- a/lib/Support/Makefile
+++ b/lib/Support/Makefile
@@ -4,9 +4,4 @@ DIRS =
LIBRARYNAME = support
-## List source files in link order
-Source = \
- ProgramOption.o \
- ProgramOptions.o
-
include $(LEVEL)/Makefile.common
diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
index 4843a70dce..0ad1dbdb54 100644
--- a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
+++ b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
@@ -10,8 +10,6 @@
//***************************************************************************
-//*************************** User Include Files ***************************/
-
#include "llvm/CodeGen/InstrSelection.h"
#include "llvm/Method.h"
#include "llvm/BasicBlock.h"
@@ -20,7 +18,20 @@
#include "llvm/Instruction.h"
#include "llvm/LLC/CompileContext.h"
#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/Tools/CommandLine.h"
+
+enum DebugLev {
+ NoDebugInfo,
+ DebugInstTrees,
+ DebugBurgTrees,
+};
+// Enable Debug Options to be specified on the command line
+cl::Enum<enum DebugLev> DebugLevel("debug_select", cl::NoFlags, // cl::Hidden
+ "enable instruction selection debugging information",
+ clEnumVal(NoDebugInfo , "disable debug output"),
+ clEnumVal(DebugInstTrees, "print instruction trees"),
+ clEnumVal(DebugBurgTrees, "print burg trees"), 0);
//************************* Forward Declarations ***************************/
@@ -36,8 +47,7 @@ static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
// Returns true if instruction selection failed, false otherwise.
//---------------------------------------------------------------------------
-bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
- int DebugLevel) {
+bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext) {
bool failed = false;
InstrForest instrForest;
@@ -59,7 +69,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
// Invoke BURM to label each tree node with a state
(void) burm_label(basicNode);
- if (DebugLevel >= DEBUG_BURG_TREES)
+ if (DebugLevel.getValue() >= DebugBurgTrees)
{
printcover(basicNode, 1, 0);
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
@@ -76,7 +86,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
if (!failed)
{
- if (DebugLevel >= DEBUG_INSTR_TREES)
+ if (DebugLevel.getValue() >= DebugInstTrees)
{
cout << "\n\n*** Instruction trees for method "
<< (method->hasName()? method->getName() : "")
@@ -84,7 +94,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
instrForest.dump();
}
- if (DebugLevel >= DEBUG_TREES_NONE)
+ if (DebugLevel.getValue() > NoDebugInfo)
PrintMachineInstructions(method);
}
diff --git a/support/lib/Support/Makefile b/support/lib/Support/Makefile
index 7a41c62b04..c7eb8adcb1 100644
--- a/support/lib/Support/Makefile
+++ b/support/lib/Support/Makefile
@@ -4,9 +4,4 @@ DIRS =
LIBRARYNAME = support
-## List source files in link order
-Source = \
- ProgramOption.o \
- ProgramOptions.o
-
include $(LEVEL)/Makefile.common
diff --git a/support/lib/Support/ProgramOption.cpp b/support/lib/Support/ProgramOption.cpp
deleted file mode 100644
index 6b391bc714..0000000000
--- a/support/lib/Support/ProgramOption.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-// $Id$
-//***************************************************************************
-//
-// File:
-// ProgramOption.C
-//
-// Purpose:
-// General representations for a program option.
-//
-// History:
-// 08/08/95 - adve - created in the dHPF compiler
-// 11/26/96 - adve - EvalOpt now returns #args consumed, or -1 for error
-// 07/15/01 - vadve - Copied to LLVM system and modified
-//
-//**************************************************************************/
-
-#include "llvm/Support/ProgramOption.h"
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-//**************************************************************************/
-
-StringOption::StringOption(const string &_argString,
- const string &_helpMesg,
- const string &_initValue,
- bool _append)
- : ProgramOption(_argString, _helpMesg),
- value(_initValue),
- append(_append)
-{}
-
-int StringOption::EvalOpt(const string &optarg) {
- if (optarg == (char*) NULL)
- return -1; // flag the error
-
- if (this->append)
- value += optarg;
- else
- value = optarg;
-
- optionSpecified = true;
- return 1; // one additional argument consumed
-}
-
-
-//**************************************************************************/
-
-FlagOption::FlagOption(const string &_argString,
- const string &_helpMesg,
- bool _initValue)
- : ProgramOption(_argString, _helpMesg, 0),
- value(_initValue)
-{}
-
-int FlagOption::EvalOpt(const string &optarg) {
- if (optarg == "0") {
- value = false;
- return 1; // one additional argument consumed
- }
- else {
- value = true;
- return 0; // zero ... consumed
- }
-}
-
-//**************************************************************************/
-
-RealValuedOption::RealValuedOption(const string &_argString,
- const string &_helpMesg,
- double _initValue)
- : ProgramOption(_argString, _helpMesg),
- value(_initValue)
-{}
-
-int RealValuedOption::EvalOpt(const string &optarg) {
- if (optarg == "") return -1;
-
- char* lastCharScanned = NULL;
- value = strtod(optarg.c_str(), &lastCharScanned);
- if (! (*lastCharScanned == '\0')) // look for incorrect or partially
- return -1; // correct numerical argument
-
- optionSpecified = true;
- return 1;
-}
-
-string RealValuedOption::GetTextValue() const {
- char buffer[40];
- sprintf(buffer, "%f", value);
- return buffer;
-}
-
-//**************************************************************************/
-
-IntegerValuedOption::IntegerValuedOption(const string &_argString,
- const string &_helpMesg,
- int _initValue)
- : RealValuedOption(_argString, _helpMesg, (double) _initValue)
-{}
-
-int IntegerValuedOption::Value() const {
- double realValue = RealValuedOption::Value();
- assert(realValue == (int) realValue);
- return (int) realValue;
-}
-
-string IntegerValuedOption::GetTextValue() const {
- char buffer[40];
- sprintf(buffer, "%d", Value());
- return buffer;
-}
-
-
diff --git a/support/lib/Support/ProgramOptions.cpp b/support/lib/Support/ProgramOptions.cpp
deleted file mode 100644
index fc50ddcbbb..0000000000
--- a/support/lib/Support/ProgramOptions.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-// $Id$
-//***************************************************************************
-//
-// File:
-// ProgramOptions.C
-//
-// Purpose:
-// General options processing for any program.
-//
-// History:
-// 08/08/95 - adve - created in the dHPF compiler
-// 10/10/96 - mpal, dbaker - converted to const member functions.
-// 11/26/96 - adve - fixed to handle options that consume 0+ arguments
-// 07/15/01 - vadve - Copied to LLVM system and modified
-//
-//**************************************************************************/
-
-//************************** System Include Files **************************/
-
-#include <iostream.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <math.h>
-#include <string>
-#ifndef MAXINT
-#define MAXINT ((1 << sizeof(int)-1) - 1)
-#endif
-
-//*************************** User Include Files ***************************/
-
-#include "llvm/Support/ProgramOptions.h"
-#include "llvm/Support/ProgramOption.h"
-
-
-//************************** Method Definitions ****************************/
-
-ProgramOptions::ProgramOptions(int _argc,
- const char* _argv[],
- const char* _envp[])
- : optionRegistry(),
- argc(_argc),
- argv(_argv),
- envp(_envp),
- argsConsumed(0)
-{}
-
-string ProgramOptions::StringOptionValue(const string &optString) const {
- const StringOption* handler = (const StringOption*)OptionHandler(optString);
- return (handler == NULL) ? string("") : handler->Value();
-}
-
-bool
-ProgramOptions::FlagOptionValue(const string &optString) const
-{
- const FlagOption* handler = (const FlagOption*) OptionHandler(optString);
- return (handler == NULL) ? false : handler->Value();
-}
-
-double
-ProgramOptions::RealOptionValue(const string &optString) const
-{
- const RealValuedOption* handler =
- (const RealValuedOption*) OptionHandler(optString);
- return (handler == NULL) ? MAXFLOAT : handler->Value();
-}
-
-int
-ProgramOptions::IntOptionValue(const string &optString) const
-{
- const IntegerValuedOption* handler =
- (const IntegerValuedOption*) OptionHandler(optString);
- return (handler == NULL) ? MAXINT : handler->Value();
-}
-
-bool
-ProgramOptions::OptionSpecified(const string &optString) const
-{
- const ProgramOption* handler = OptionHandler(optString);
- return handler->OptionSpecified();
-}
-
-const char*
-ProgramOptions::ProgramName() const
-{
- return argv[0];
-}
-
-int
-ProgramOptions::NumberOfOtherOptions() const
-{
- return argc - argsConsumed;
-}
-
-const char*
-ProgramOptions::OtherOption(int i) const
-{
- i += argsConsumed;
- assert(i >= 0 && i < argc);
- return argv[i];
-}
-
-const char**
-ProgramOptions::GetOriginalArgs() const
-{
- return argv;
-}
-
-vector<string>
-ProgramOptions::GetDescription() const
-{
- vector<string> optDesc;
-
- if (optDesc.size() < (unsigned) argc)
- {
- for (hash_map<string,ProgramOption*>::const_iterator iter=optionRegistry.begin();
- ! (iter == optionRegistry.end());
- ++iter)
- {
- const ProgramOption* handler = iter->second;
- optDesc.push_back(handler->ArgString()); // 1st
- optDesc.push_back(handler->HelpMesg()); // 2nd
- optDesc.push_back(handler->GetTextValue()); // 3rd
- }
- }
-
- return optDesc;
-}
-
-void
-ProgramOptions::Register(ProgramOption* option)
-{
- optionRegistry[option->ArgString()] = option;
-}
-
-//----------------------------------------------------------------------
-// function ProgramOptions::ParseArgs
-//
-// Parse command-line options until you run out of options or see
-// an unrecognized option. `getopt' is a standard package to do this,
-// but incredibly, it limited to single-letter options.
-//
-// -- Each option can consume zero or one additional arguments of argv
-// -- "--" can be used to mark the end of options
-// so that a program argument can also start with "-".
-//---------------------------------------------------------------------/
-
-void
-ProgramOptions::ParseArgs(int argc,
- const char* argv[],
- const char* envp[])
-{
- if (argc == 0) {
- Usage();
- }
- // consume the program name
- argsConsumed = 1;
-
- while (argsConsumed < argc)
- {
- const char* arg = argv[argsConsumed];
- if (arg[0] == '-')
- {
- if (strcmp(arg, "--") == 0) { // "--" marks end of options
- argsConsumed++; // consume and
- break; // discontinue the for loop
- }
- ProgramOption* handler = OptionHandler(arg+1);
- if (handler == NULL) {
- cerr << "Unrecognized option: " << arg+1 << endl;
- Usage();
- }
-
- if (argc - argsConsumed < handler->MinExpectedArgs()) {
- cerr << "Option " << (char*) arg+1 << " needs "
- << handler->MinExpectedArgs() << " arguments" << endl;
- Usage();
- }
-
- argsConsumed++; // consumed the option
-
- const char* nextArg = (argsConsumed < argc)? argv[argsConsumed]
- : "";
- int numAdditionalArgsConsumed = handler->EvalOpt(nextArg);
- if (numAdditionalArgsConsumed < 0)
- Usage();
- argsConsumed += numAdditionalArgsConsumed;
- }
- else
- {
- break; // quit the while loop
- }
- }
-
- ParseExtraArgs();
-}
-
-void
-ProgramOptions::PrintArgs(ostream& stream) const
-{
- for (int i = 0; i < argc; i++) {
- stream << argv[i] << " ";
- }
- stream << endl;
-}
-
-
-void
-ProgramOptions::PrintOptions(ostream& stream) const
-{
- stream << "OPTIONS:" << endl;
- stream << "\tUse argument 0 to turn OFF a flag option: "
- << "-<flag_opt> 0" << endl << endl;
-
- for (hash_map<string,ProgramOption*>::const_iterator iter = optionRegistry.begin();
- iter != optionRegistry.end(); ++iter) {
- const ProgramOption* handler = (*iter).second;
-
- stream << "\t-" << handler->ArgString();
-
- const char* const showarg = " <arg>";
- int i = 1;
- for (i=1; i <= handler->MinExpectedArgs(); i++)
- stream << showarg;
-
- int numCharsPrinted = 1 + handler->ArgString().length()
- + 6 * handler->MinExpectedArgs();
- for (i=1; i > numCharsPrinted / 8; i--)
- stream << "\t";
-
- stream << "\t" << handler->HelpMesg()
- << endl;
- }
-}
-
-void
-ProgramOptions::Usage() const
-{
- PrintUsage(cerr);
- exit(1);
-}
-
-
-//**************************************************************************/
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++) {
- 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-dis/Makefile b/tools/llvm-dis/Makefile
index e6624ab544..8ce3e2161c 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 deaf3a28fd..f243baadb0 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 <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/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index deaf3a28fd..f243baadb0 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 <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/opt/Makefile b/tools/opt/Makefile
index 4a14d372e5..658b2998ec 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 70c2efeff8..2b5b069106 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 <arg> 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<enum Opts> 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 b6d13f4467..0000000000
--- 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 ff16a666f5..0000000000
--- 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 2cff3bfd6a..0000000000
--- a/tools/opt/teststrip.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-../as/as < ../../test/$1 | ./opt -strip | dis