mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
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
This commit is contained in:
@@ -10,14 +10,13 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Module;
|
class Module;
|
||||||
class ToolCommandLine;
|
|
||||||
class ParseException;
|
class ParseException;
|
||||||
|
|
||||||
|
|
||||||
// The useful interface defined by this file... Parse an ascii file, and return
|
// The useful interface defined by this file... Parse an ascii file, and return
|
||||||
// the internal representation in a nice slice'n'dice'able representation.
|
// 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
|
// Helper Classes
|
||||||
@@ -28,7 +27,7 @@ Module *ParseAssemblyFile(const ToolCommandLine &Opts) throw (ParseException);
|
|||||||
//
|
//
|
||||||
class ParseException {
|
class ParseException {
|
||||||
public:
|
public:
|
||||||
ParseException(const ToolCommandLine &Opts, const string &message,
|
ParseException(const string &filename, const string &message,
|
||||||
int LineNo = -1, int ColNo = -1);
|
int LineNo = -1, int ColNo = -1);
|
||||||
|
|
||||||
ParseException(const ParseException &E);
|
ParseException(const ParseException &E);
|
||||||
@@ -42,8 +41,8 @@ public:
|
|||||||
return Message;
|
return Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const ToolCommandLine &getOptions() const {
|
inline const string &getFilename() const {
|
||||||
return Opts; // Get the options obj used to parse.
|
return Filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
// getErrorLocation - Return the line and column number of the error in the
|
// getErrorLocation - Return the line and column number of the error in the
|
||||||
@@ -56,7 +55,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private :
|
private :
|
||||||
const ToolCommandLine &Opts;
|
string Filename;
|
||||||
string Message;
|
string Message;
|
||||||
int LineNo, ColumnNo; // -1 if not relevant
|
int LineNo, ColumnNo; // -1 if not relevant
|
||||||
|
|
||||||
|
@@ -22,8 +22,6 @@ class InstructionNode;
|
|||||||
class TmpInstruction;
|
class TmpInstruction;
|
||||||
class ConstPoolVal;
|
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
|
// GLOBAL data and an external function that must be implemented
|
||||||
// for each architecture.
|
// for each architecture.
|
||||||
@@ -53,8 +51,7 @@ extern bool ThisIsAChainRule (int eruleno);
|
|||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool SelectInstructionsForMethod (Method* method,
|
bool SelectInstructionsForMethod (Method* method,
|
||||||
CompileContext& ccontext,
|
CompileContext& ccontext);
|
||||||
int DebugLevel);
|
|
||||||
|
|
||||||
|
|
||||||
// Debugging function to print the generated instructions
|
// Debugging function to print the generated instructions
|
||||||
|
@@ -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
|
|
@@ -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
|
|
@@ -1,12 +1,8 @@
|
|||||||
//===-- llvm/Tools/CommandLine.h - Command line parser for tools -*- C++ -*--=//
|
//===-- llvm/Tools/CommandLine.h - Command line parser for tools -*- C++ -*--=//
|
||||||
//
|
//
|
||||||
// This class implements a command line argument processor that is useful when
|
// This class implements a command line argument processor that is useful when
|
||||||
// creating a tool.
|
// creating a tool. It provides a simple, minimalistic interface that is easily
|
||||||
//
|
// extensible and supports nonlocal (library) command line options.
|
||||||
// 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.
|
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
@@ -14,113 +10,275 @@
|
|||||||
#define LLVM_TOOLS_COMMANDLINE_H
|
#define LLVM_TOOLS_COMMANDLINE_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
class ToolCommandLine {
|
namespace cl { // Short namespace to make usage concise
|
||||||
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; }
|
// ParseCommandLineOptions - Minimalistic command line option processing entry
|
||||||
inline const string getOutputFilename() const { return OutputFilename; }
|
//
|
||||||
|
void cl::ParseCommandLineOptions(int &argc, char **argv,
|
||||||
|
const char *Overview = 0);
|
||||||
|
|
||||||
private:
|
|
||||||
void calculateOutputFilename(bool OutputBytecode) {
|
|
||||||
OutputFilename = InputFilename;
|
|
||||||
unsigned Len = OutputFilename.length();
|
|
||||||
|
|
||||||
if (Len <= 3) {
|
//===----------------------------------------------------------------------===//
|
||||||
OutputFilename += (OutputBytecode ? ".bc" : ".ll");
|
// Global flags permitted to be passed to command line arguments
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OutputBytecode) {
|
enum FlagsOptions {
|
||||||
if (OutputFilename[Len-3] == '.' &&
|
NoFlags = 0x00, // Marker to make explicit that we have no flags
|
||||||
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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
// Flags for the number of occurances allowed...
|
||||||
string InputFilename; // Filename to read from. If "-", use stdin.
|
Optional = 0x00, // Zero or One occurance
|
||||||
string OutputFilename; // Filename to write to. If "-", use stdout.
|
ZeroOrMore = 0x01, // Zero or more occurances allowed
|
||||||
bool Force; // Force output (-f argument)
|
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,
|
||||||
};
|
};
|
||||||
|
|
||||||
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;
|
// Option Base class
|
||||||
|
//
|
||||||
if (argv[i][0] == '-') {
|
class Option {
|
||||||
if (!FoundInputFN && argv[i][1] == 0) { // Is the current argument '-'
|
friend void cl::ParseCommandLineOptions(int &, char **, const char *Overview);
|
||||||
InputFilename = argv[i];
|
|
||||||
FoundInputFN = true;
|
// handleOccurances - Overriden by subclasses to handle the value passed into
|
||||||
RemoveArg = 1;
|
// an argument. Should return true if there was an error processing the
|
||||||
} else if (!FoundOutputFN && (argv[i][1] == 'o' && argv[i][2] == 0)) {
|
// argument and the program should exit.
|
||||||
// Is the argument -o?
|
//
|
||||||
if (i+1 < argc) { // Next arg is output fn
|
virtual bool handleOccurance(const char *ArgName, const string &Arg) = 0;
|
||||||
OutputFilename = argv[i+1];
|
|
||||||
FoundOutputFN = true;
|
int NumOccurances; // The number of times specified
|
||||||
RemoveArg = 2;
|
public:
|
||||||
}
|
const char * const ArgStr; // The argument string itself (ex: "help", "o")
|
||||||
} else if (!FoundForce && (argv[i][1] == 'f' && argv[i][2] == 0)) {
|
const char * const HelpStr; // The descriptive text message for --help
|
||||||
Force = true;
|
const int Flags; // Flags for the argument
|
||||||
FoundForce = true;
|
|
||||||
RemoveArg = 1;
|
protected:
|
||||||
}
|
Option(const char *ArgStr, const char *Message, int Flags);
|
||||||
} else if (!FoundInputFN) { // Is the current argument '[^-].*'?
|
Option(int flags) : ArgStr(""), HelpStr(""), Flags(flags) {}
|
||||||
InputFilename = argv[i];
|
|
||||||
FoundInputFN = true;
|
// Prints option name followed by message. Always returns true.
|
||||||
RemoveArg = 1;
|
bool error(string Message, const char *ArgName = 0);
|
||||||
}
|
|
||||||
|
// addOccurance - Wrapper around handleOccurance that enforces Flags
|
||||||
if (RemoveArg) {
|
//
|
||||||
argc -= RemoveArg; // Shift args over...
|
bool addOccurance(const char *ArgName, const string &Value);
|
||||||
memmove(argv+i, argv+i+RemoveArg, (argc-i)*sizeof(char*));
|
|
||||||
i--; // Reprocess this argument...
|
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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// 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 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
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FoundOutputFN && InputFilename != "-")
|
inline E getValue() const { return (E)Value; }
|
||||||
calculateOutputFilename(OutBC);
|
inline void setValue(E Val) { Value = (E)Val; }
|
||||||
}
|
};
|
||||||
|
|
||||||
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),
|
// Enum flags command line option
|
||||||
Force(Opts.Force) {
|
//
|
||||||
}
|
class EnumFlagsBase : public EnumValueBase {
|
||||||
|
protected:
|
||||||
|
virtual bool handleOccurance(const char *ArgName, const string &Arg);
|
||||||
|
inline EnumFlagsBase(int Flags) : EnumValueBase(Flags | ValueDisallowed) {}
|
||||||
|
|
||||||
inline ToolCommandLine &ToolCommandLine::operator=(const ToolCommandLine &Opts){
|
// Return the width of the option tag for printing...
|
||||||
InputFilename = Opts.InputFilename;
|
virtual unsigned getOptionWidth() const;
|
||||||
OutputFilename = Opts.OutputFilename;
|
|
||||||
Force = Opts.Force;
|
// printOptionInfo - Print out information about this option. The
|
||||||
return *this;
|
// 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]; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End namespace cl
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -10,8 +10,6 @@
|
|||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
//*************************** User Include Files ***************************/
|
|
||||||
|
|
||||||
#include "llvm/CodeGen/InstrSelection.h"
|
#include "llvm/CodeGen/InstrSelection.h"
|
||||||
#include "llvm/Method.h"
|
#include "llvm/Method.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
@@ -20,7 +18,20 @@
|
|||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
#include "llvm/LLC/CompileContext.h"
|
#include "llvm/LLC/CompileContext.h"
|
||||||
#include "llvm/CodeGen/MachineInstr.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 ***************************/
|
//************************* Forward Declarations ***************************/
|
||||||
|
|
||||||
@@ -36,8 +47,7 @@ static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
|
|||||||
// Returns true if instruction selection failed, false otherwise.
|
// Returns true if instruction selection failed, false otherwise.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext) {
|
||||||
int DebugLevel) {
|
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
|
|
||||||
InstrForest instrForest;
|
InstrForest instrForest;
|
||||||
@@ -59,7 +69,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
|||||||
// Invoke BURM to label each tree node with a state
|
// Invoke BURM to label each tree node with a state
|
||||||
(void) burm_label(basicNode);
|
(void) burm_label(basicNode);
|
||||||
|
|
||||||
if (DebugLevel >= DEBUG_BURG_TREES)
|
if (DebugLevel.getValue() >= DebugBurgTrees)
|
||||||
{
|
{
|
||||||
printcover(basicNode, 1, 0);
|
printcover(basicNode, 1, 0);
|
||||||
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
||||||
@@ -76,7 +86,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
|||||||
|
|
||||||
if (!failed)
|
if (!failed)
|
||||||
{
|
{
|
||||||
if (DebugLevel >= DEBUG_INSTR_TREES)
|
if (DebugLevel.getValue() >= DebugInstTrees)
|
||||||
{
|
{
|
||||||
cout << "\n\n*** Instruction trees for method "
|
cout << "\n\n*** Instruction trees for method "
|
||||||
<< (method->hasName()? method->getName() : "")
|
<< (method->hasName()? method->getName() : "")
|
||||||
@@ -84,7 +94,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
|||||||
instrForest.dump();
|
instrForest.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DebugLevel >= DEBUG_TREES_NONE)
|
if (DebugLevel.getValue() > NoDebugInfo)
|
||||||
PrintMachineInstructions(method);
|
PrintMachineInstructions(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,9 +4,4 @@ DIRS =
|
|||||||
|
|
||||||
LIBRARYNAME = support
|
LIBRARYNAME = support
|
||||||
|
|
||||||
## List source files in link order
|
|
||||||
Source = \
|
|
||||||
ProgramOption.o \
|
|
||||||
ProgramOptions.o
|
|
||||||
|
|
||||||
include $(LEVEL)/Makefile.common
|
include $(LEVEL)/Makefile.common
|
||||||
|
@@ -10,8 +10,6 @@
|
|||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
//*************************** User Include Files ***************************/
|
|
||||||
|
|
||||||
#include "llvm/CodeGen/InstrSelection.h"
|
#include "llvm/CodeGen/InstrSelection.h"
|
||||||
#include "llvm/Method.h"
|
#include "llvm/Method.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
@@ -20,7 +18,20 @@
|
|||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
#include "llvm/LLC/CompileContext.h"
|
#include "llvm/LLC/CompileContext.h"
|
||||||
#include "llvm/CodeGen/MachineInstr.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 ***************************/
|
//************************* Forward Declarations ***************************/
|
||||||
|
|
||||||
@@ -36,8 +47,7 @@ static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
|
|||||||
// Returns true if instruction selection failed, false otherwise.
|
// Returns true if instruction selection failed, false otherwise.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext) {
|
||||||
int DebugLevel) {
|
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
|
|
||||||
InstrForest instrForest;
|
InstrForest instrForest;
|
||||||
@@ -59,7 +69,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
|||||||
// Invoke BURM to label each tree node with a state
|
// Invoke BURM to label each tree node with a state
|
||||||
(void) burm_label(basicNode);
|
(void) burm_label(basicNode);
|
||||||
|
|
||||||
if (DebugLevel >= DEBUG_BURG_TREES)
|
if (DebugLevel.getValue() >= DebugBurgTrees)
|
||||||
{
|
{
|
||||||
printcover(basicNode, 1, 0);
|
printcover(basicNode, 1, 0);
|
||||||
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
||||||
@@ -76,7 +86,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
|||||||
|
|
||||||
if (!failed)
|
if (!failed)
|
||||||
{
|
{
|
||||||
if (DebugLevel >= DEBUG_INSTR_TREES)
|
if (DebugLevel.getValue() >= DebugInstTrees)
|
||||||
{
|
{
|
||||||
cout << "\n\n*** Instruction trees for method "
|
cout << "\n\n*** Instruction trees for method "
|
||||||
<< (method->hasName()? method->getName() : "")
|
<< (method->hasName()? method->getName() : "")
|
||||||
@@ -84,7 +94,7 @@ bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
|||||||
instrForest.dump();
|
instrForest.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DebugLevel >= DEBUG_TREES_NONE)
|
if (DebugLevel.getValue() > NoDebugInfo)
|
||||||
PrintMachineInstructions(method);
|
PrintMachineInstructions(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,9 +4,4 @@ DIRS =
|
|||||||
|
|
||||||
LIBRARYNAME = support
|
LIBRARYNAME = support
|
||||||
|
|
||||||
## List source files in link order
|
|
||||||
Source = \
|
|
||||||
ProgramOption.o \
|
|
||||||
ProgramOptions.o
|
|
||||||
|
|
||||||
include $(LEVEL)/Makefile.common
|
include $(LEVEL)/Makefile.common
|
||||||
|
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//**************************************************************************/
|
|
@@ -9,4 +9,5 @@ LIBDEPS = ../../lib/Optimizations/Debug/libopt.a ../../lib/Analysis/Debug/liba
|
|||||||
|
|
||||||
analyze : $(ObjectsG) Debug/.dir Depend/.dir $(LIBDEPS)
|
analyze : $(ObjectsG) Debug/.dir Depend/.dir $(LIBDEPS)
|
||||||
$(LinkG) -o $@ $(ObjectsG) -lopt -lasmparser \
|
$(LinkG) -o $@ $(ObjectsG) -lopt -lasmparser \
|
||||||
-lbcreader -lvmcore -lasmwriter -lanalysis -lopt
|
-lbcreader -lvmcore -lasmwriter -lanalysis \
|
||||||
|
-lopt -lsupport
|
||||||
|
@@ -86,47 +86,54 @@ static void PrintPostDomFrontier(Method *M) {
|
|||||||
cout << cfg::DominanceFrontier(cfg::DominatorSet(M, true));
|
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 {
|
struct {
|
||||||
const string ArgName, Name;
|
enum Ans AnID;
|
||||||
void (*AnPtr)(Method *M);
|
void (*AnPtr)(Method *M);
|
||||||
} AnTable[] = {
|
} AnTable[] = {
|
||||||
{ "-print" , "Print each Method" , PrintMethod },
|
{ print , PrintMethod },
|
||||||
{ "-intervals" , "Interval Partition" , PrintIntervalPartition },
|
{ intervals , PrintIntervalPartition },
|
||||||
{ "-exprclassify" , "Classify Expressions" , PrintClassifiedExprs },
|
{ exprclassify , PrintClassifiedExprs },
|
||||||
|
|
||||||
{ "-domset" , "Dominator Sets" , PrintDominatorSets },
|
{ domset , PrintDominatorSets },
|
||||||
{ "-idom" , "Immediate Dominators" , PrintImmediateDominators },
|
{ idom , PrintImmediateDominators },
|
||||||
{ "-domtree" , "Dominator Tree" , PrintDominatorTree },
|
{ domtree , PrintDominatorTree },
|
||||||
{ "-domfrontier" , "Dominance Frontier" , PrintDominanceFrontier },
|
{ domfrontier , PrintDominanceFrontier },
|
||||||
|
|
||||||
{ "-postdomset" , "Postdominator Sets" , PrintPostDominatorSets },
|
{ postdomset , PrintPostDominatorSets },
|
||||||
{ "-postidom" , "Immediate Postdominators", PrintImmediatePostDoms },
|
{ postidom , PrintImmediatePostDoms },
|
||||||
{ "-postdomtree" , "Post Dominator Tree" , PrintPostDomTree },
|
{ postdomtree , PrintPostDomTree },
|
||||||
{ "-postdomfrontier", "Postdominance Frontier" , PrintPostDomFrontier },
|
{ postdomfrontier, PrintPostDomFrontier },
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
ToolCommandLine Options(argc, argv, false);
|
cl::ParseCommandLineOptions(argc, argv, " llvm analysis printer tool\n");
|
||||||
bool Quiet = false;
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
||||||
if (string(argv[i]) == string("--help")) {
|
if (!C && !(C = ParseAssemblyFile(InputFilename.getValue()))) {
|
||||||
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))) {
|
|
||||||
cerr << "Input file didn't read correctly.\n";
|
cerr << "Input file didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -136,22 +143,22 @@ int main(int argc, char **argv) {
|
|||||||
Method *M = *I;
|
Method *M = *I;
|
||||||
if (M->isExternal()) continue;
|
if (M->isExternal()) continue;
|
||||||
|
|
||||||
// Loop over all of the analyses to be run...
|
for (unsigned i = 0; i < AnalysesList.size(); ++i) {
|
||||||
for (int i = 1; i < argc; i++) {
|
enum Ans AnalysisPass = AnalysesList[i];
|
||||||
if (argv[i] == 0) continue;
|
|
||||||
|
// Loop over all of the analyses to be run...
|
||||||
unsigned j;
|
unsigned j;
|
||||||
for (j = 0; j < sizeof(AnTable)/sizeof(AnTable[0]); j++) {
|
for (j = 0; j < sizeof(AnTable)/sizeof(AnTable[0]); ++j) {
|
||||||
if (string(argv[i]) == AnTable[j].ArgName) {
|
if (AnalysisPass == AnTable[j].AnID) {
|
||||||
if (!Quiet)
|
if (!Quiet)
|
||||||
cerr << "Running: " << AnTable[j].Name << " analysis on '"
|
cerr << "Running: " << AnalysesList.getArgDescription(AnalysisPass)
|
||||||
<< ((Value*)M)->getName() << "'!\n";
|
<< " analysis on '" << ((Value*)M)->getName() << "'!\n";
|
||||||
AnTable[j].AnPtr(M);
|
AnTable[j].AnPtr(M);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j == sizeof(AnTable)/sizeof(AnTable[0]))
|
if (j == sizeof(AnTable)/sizeof(AnTable[0]))
|
||||||
cerr << "'" << argv[i] << "' argument unrecognized: ignored\n";
|
cerr << "Analysis tables inconsistent!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,4 +6,4 @@ clean::
|
|||||||
rm -f as
|
rm -f as
|
||||||
|
|
||||||
as : $(ObjectsG)
|
as : $(ObjectsG)
|
||||||
$(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore
|
$(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore -lsupport
|
||||||
|
@@ -18,54 +18,49 @@
|
|||||||
#include "llvm/Bytecode/Writer.h"
|
#include "llvm/Bytecode/Writer.h"
|
||||||
#include "llvm/Tools/CommandLine.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) {
|
int main(int argc, char **argv) {
|
||||||
ToolCommandLine Opts(argc, argv);
|
cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n");
|
||||||
bool DumpAsm = false;
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
ostream *Out = 0;
|
||||||
if (string(argv[i]) == string("-d")) {
|
|
||||||
argv[i] = 0; DumpAsm = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PrintMessage = false;
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
if (argv[i] == 0) continue;
|
|
||||||
|
|
||||||
if (string(argv[i]) == string("--help")) {
|
|
||||||
PrintMessage = true;
|
|
||||||
} else {
|
|
||||||
cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PrintMessage) {
|
|
||||||
cerr << argv[0] << " usage:\n"
|
|
||||||
<< " " << argv[0] << " --help - Print this usage information\n"
|
|
||||||
<< " " << argv[0] << " x.ll - Parse <x.ll> file and output "
|
|
||||||
<< "bytecodes to x.bc\n"
|
|
||||||
<< " " << argv[0] << " - Parse stdin and write to stdout.\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream *Out = &cout; // Default to output to stdout...
|
|
||||||
try {
|
try {
|
||||||
// Parse the file now...
|
// Parse the file now...
|
||||||
Module *C = ParseAssemblyFile(Opts);
|
Module *C = ParseAssemblyFile(InputFilename.getValue());
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "assembly didn't read correctly.\n";
|
cerr << "assembly didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DumpAsm)
|
if (DumpAsm.getValue())
|
||||||
cerr << "Here's the assembly:\n" << C;
|
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()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << Opts.getOutputFilename() << "!\n";
|
cerr << "Error opening " << OutputFilename.getValue() << "!\n";
|
||||||
delete C;
|
delete C;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@@ -6,5 +6,5 @@ clean ::
|
|||||||
rm -f dis
|
rm -f dis
|
||||||
|
|
||||||
dis : $(ObjectsG)
|
dis : $(ObjectsG)
|
||||||
$(LinkG) -o $@ $(ObjectsG) -lbcreader -lasmwriter -lanalysis -lvmcore
|
$(LinkG) -o $@ $(ObjectsG) -lbcreader -lasmwriter -lanalysis -lvmcore -lsupport
|
||||||
|
|
||||||
|
@@ -25,69 +25,67 @@
|
|||||||
#include "llvm/Method.h"
|
#include "llvm/Method.h"
|
||||||
#include "llvm/CFG.h"
|
#include "llvm/CFG.h"
|
||||||
|
|
||||||
|
// 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
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// WriteMode - The different orderings to print basic blocks in...
|
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
|
||||||
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;
|
|
||||||
|
|
||||||
ToolCommandLine Opts(argc, argv, false);
|
|
||||||
|
|
||||||
// We only support the options that the system parser does... if it left any
|
|
||||||
// then we don't know what to do.
|
|
||||||
//
|
|
||||||
if (argc > 1) {
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
if (string(argv[i]) == string("--help")) {
|
|
||||||
cerr << argv[0] << " 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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream *Out = &cout; // Default to printing to stdout...
|
ostream *Out = &cout; // Default to printing to stdout...
|
||||||
|
|
||||||
Module *C = ParseBytecodeFile(Opts.getInputFilename());
|
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Opts.getOutputFilename() != "-") {
|
if (OutputFilename.getValue() != "") { // Specified an output filename?
|
||||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
Out = new ofstream(OutputFilename.getValue().c_str(),
|
||||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
||||||
if (!Out->good()) {
|
} else {
|
||||||
cerr << "Error opening " << Opts.getOutputFilename()
|
if (InputFilename.getValue() == "-") {
|
||||||
<< ": sending to stdout instead!\n";
|
OutputFilename.setValue("-");
|
||||||
Out = &cout;
|
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
|
// All that dis does is write the assembly out to a file... which is exactly
|
||||||
// what the writer library is supposed to do...
|
// what the writer library is supposed to do...
|
||||||
//
|
//
|
||||||
if (WriteMode == Default) {
|
if (WriteMode.getValue() == Default) {
|
||||||
(*Out) << C; // Print out in list order
|
(*Out) << C; // Print out in list order
|
||||||
} else {
|
} else {
|
||||||
// TODO: This does not print anything other than the basic blocks in the
|
// TODO: This does not print anything other than the basic blocks in the
|
||||||
@@ -98,20 +96,20 @@ int main(int argc, char **argv) {
|
|||||||
Method *M = *I;
|
Method *M = *I;
|
||||||
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
||||||
|
|
||||||
switch (WriteMode) {
|
switch (WriteMode.getValue()) {
|
||||||
case DepthFirst: // Depth First ordering
|
case dfo: // Depth First ordering
|
||||||
copy(cfg::df_begin(M), cfg::df_end(M),
|
copy(cfg::df_begin(M), cfg::df_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
break;
|
break;
|
||||||
case ReverseDepthFirst: // Reverse Depth First ordering
|
case rdfo: // Reverse Depth First ordering
|
||||||
copy(cfg::df_begin(M, true), cfg::df_end(M),
|
copy(cfg::df_begin(M, true), cfg::df_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
break;
|
break;
|
||||||
case PostOrder: // Post Order
|
case po: // Post Order
|
||||||
copy(cfg::po_begin(M), cfg::po_end(M),
|
copy(cfg::po_begin(M), cfg::po_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
break;
|
break;
|
||||||
case ReversePostOrder: { // Reverse Post Order
|
case rpo: { // Reverse Post Order
|
||||||
cfg::ReversePostOrderTraversal RPOT(M);
|
cfg::ReversePostOrderTraversal RPOT(M);
|
||||||
copy(RPOT.begin(), RPOT.end(),
|
copy(RPOT.begin(), RPOT.end(),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@@ -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
|
|
@@ -1,10 +1,4 @@
|
|||||||
LEVEL = ../..
|
LEVEL = ../..
|
||||||
|
|
||||||
## List source files in link order
|
|
||||||
Source = \
|
|
||||||
llc.o \
|
|
||||||
LLCOptions.o
|
|
||||||
|
|
||||||
include $(LEVEL)/Makefile.common
|
include $(LEVEL)/Makefile.common
|
||||||
|
|
||||||
all:: llc
|
all:: llc
|
||||||
|
@@ -18,12 +18,15 @@
|
|||||||
#include "llvm/CodeGen/InstrSelection.h"
|
#include "llvm/CodeGen/InstrSelection.h"
|
||||||
#include "llvm/LLC/CompileContext.h"
|
#include "llvm/LLC/CompileContext.h"
|
||||||
#include "llvm/CodeGen/Sparc.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; }
|
CompileContext::~CompileContext() { delete targetMachine; }
|
||||||
|
|
||||||
static bool CompileModule(Module *module, CompileContext& ccontext,
|
static bool CompileModule(Module *module, CompileContext& ccontext) {
|
||||||
LLCOptions &Options) {
|
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
|
|
||||||
for (Module::MethodListType::const_iterator
|
for (Module::MethodListType::const_iterator
|
||||||
@@ -33,8 +36,7 @@ static bool CompileModule(Module *module, CompileContext& ccontext,
|
|||||||
{
|
{
|
||||||
Method* method = *methodIter;
|
Method* method = *methodIter;
|
||||||
|
|
||||||
if (SelectInstructionsForMethod(method, ccontext,
|
if (SelectInstructionsForMethod(method, ccontext))
|
||||||
Options.IntOptionValue(DEBUG_INSTR_SELECT_OPT)))
|
|
||||||
{
|
{
|
||||||
failed = true;
|
failed = true;
|
||||||
cerr << "Instruction selection failed for method "
|
cerr << "Instruction selection failed for method "
|
||||||
@@ -52,28 +54,28 @@ static bool CompileModule(Module *module, CompileContext& ccontext,
|
|||||||
// Entry point for the driver.
|
// Entry point for the driver.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
int main(int argc, const char** argv, const char** envp) {
|
int main(int argc, char** argv) {
|
||||||
LLCOptions Options(argc, argv, envp);
|
cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
|
||||||
CompileContext compileContext(new UltraSparc());
|
CompileContext compileContext(new UltraSparc());
|
||||||
|
|
||||||
Module *module = ParseBytecodeFile(Options.getInputFileName());
|
Module *module = ParseBytecodeFile(InputFilename.getValue());
|
||||||
if (module == 0) {
|
if (module == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool failure = CompileModule(module, compileContext, Options);
|
bool failure = CompileModule(module, compileContext);
|
||||||
|
|
||||||
if (failure) {
|
if (failure) {
|
||||||
cerr << "Error compiling "
|
cerr << "Error compiling "
|
||||||
<< Options.getInputFileName() << "!\n";
|
<< InputFilename.getValue() << "!\n";
|
||||||
delete module;
|
delete module;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Okay, we're done now... write out result...
|
// Okay, we're done now... write out result...
|
||||||
// WriteBytecodeToFile(module,
|
// WriteBytecodeToFile(module,
|
||||||
// compileContext.getOptions().getOutputFileName);
|
// OutputFilename.getValue());
|
||||||
|
|
||||||
// Clean up and exit
|
// Clean up and exit
|
||||||
delete module;
|
delete module;
|
||||||
|
@@ -6,4 +6,4 @@ clean::
|
|||||||
rm -f as
|
rm -f as
|
||||||
|
|
||||||
as : $(ObjectsG)
|
as : $(ObjectsG)
|
||||||
$(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore
|
$(LinkG) -o as $(ObjectsG) -lasmparser -lbcwriter -lasmwriter -lanalysis -lvmcore -lsupport
|
||||||
|
@@ -18,54 +18,49 @@
|
|||||||
#include "llvm/Bytecode/Writer.h"
|
#include "llvm/Bytecode/Writer.h"
|
||||||
#include "llvm/Tools/CommandLine.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) {
|
int main(int argc, char **argv) {
|
||||||
ToolCommandLine Opts(argc, argv);
|
cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n");
|
||||||
bool DumpAsm = false;
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
ostream *Out = 0;
|
||||||
if (string(argv[i]) == string("-d")) {
|
|
||||||
argv[i] = 0; DumpAsm = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PrintMessage = false;
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
if (argv[i] == 0) continue;
|
|
||||||
|
|
||||||
if (string(argv[i]) == string("--help")) {
|
|
||||||
PrintMessage = true;
|
|
||||||
} else {
|
|
||||||
cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PrintMessage) {
|
|
||||||
cerr << argv[0] << " usage:\n"
|
|
||||||
<< " " << argv[0] << " --help - Print this usage information\n"
|
|
||||||
<< " " << argv[0] << " x.ll - Parse <x.ll> file and output "
|
|
||||||
<< "bytecodes to x.bc\n"
|
|
||||||
<< " " << argv[0] << " - Parse stdin and write to stdout.\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream *Out = &cout; // Default to output to stdout...
|
|
||||||
try {
|
try {
|
||||||
// Parse the file now...
|
// Parse the file now...
|
||||||
Module *C = ParseAssemblyFile(Opts);
|
Module *C = ParseAssemblyFile(InputFilename.getValue());
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "assembly didn't read correctly.\n";
|
cerr << "assembly didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DumpAsm)
|
if (DumpAsm.getValue())
|
||||||
cerr << "Here's the assembly:\n" << C;
|
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()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << Opts.getOutputFilename() << "!\n";
|
cerr << "Error opening " << OutputFilename.getValue() << "!\n";
|
||||||
delete C;
|
delete C;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@@ -18,54 +18,49 @@
|
|||||||
#include "llvm/Bytecode/Writer.h"
|
#include "llvm/Bytecode/Writer.h"
|
||||||
#include "llvm/Tools/CommandLine.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) {
|
int main(int argc, char **argv) {
|
||||||
ToolCommandLine Opts(argc, argv);
|
cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n");
|
||||||
bool DumpAsm = false;
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
ostream *Out = 0;
|
||||||
if (string(argv[i]) == string("-d")) {
|
|
||||||
argv[i] = 0; DumpAsm = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PrintMessage = false;
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
if (argv[i] == 0) continue;
|
|
||||||
|
|
||||||
if (string(argv[i]) == string("--help")) {
|
|
||||||
PrintMessage = true;
|
|
||||||
} else {
|
|
||||||
cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PrintMessage) {
|
|
||||||
cerr << argv[0] << " usage:\n"
|
|
||||||
<< " " << argv[0] << " --help - Print this usage information\n"
|
|
||||||
<< " " << argv[0] << " x.ll - Parse <x.ll> file and output "
|
|
||||||
<< "bytecodes to x.bc\n"
|
|
||||||
<< " " << argv[0] << " - Parse stdin and write to stdout.\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream *Out = &cout; // Default to output to stdout...
|
|
||||||
try {
|
try {
|
||||||
// Parse the file now...
|
// Parse the file now...
|
||||||
Module *C = ParseAssemblyFile(Opts);
|
Module *C = ParseAssemblyFile(InputFilename.getValue());
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "assembly didn't read correctly.\n";
|
cerr << "assembly didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DumpAsm)
|
if (DumpAsm.getValue())
|
||||||
cerr << "Here's the assembly:\n" << C;
|
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()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << Opts.getOutputFilename() << "!\n";
|
cerr << "Error opening " << OutputFilename.getValue() << "!\n";
|
||||||
delete C;
|
delete C;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@@ -6,5 +6,5 @@ clean ::
|
|||||||
rm -f dis
|
rm -f dis
|
||||||
|
|
||||||
dis : $(ObjectsG)
|
dis : $(ObjectsG)
|
||||||
$(LinkG) -o $@ $(ObjectsG) -lbcreader -lasmwriter -lanalysis -lvmcore
|
$(LinkG) -o $@ $(ObjectsG) -lbcreader -lasmwriter -lanalysis -lvmcore -lsupport
|
||||||
|
|
||||||
|
@@ -25,69 +25,67 @@
|
|||||||
#include "llvm/Method.h"
|
#include "llvm/Method.h"
|
||||||
#include "llvm/CFG.h"
|
#include "llvm/CFG.h"
|
||||||
|
|
||||||
|
// 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
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// WriteMode - The different orderings to print basic blocks in...
|
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
|
||||||
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;
|
|
||||||
|
|
||||||
ToolCommandLine Opts(argc, argv, false);
|
|
||||||
|
|
||||||
// We only support the options that the system parser does... if it left any
|
|
||||||
// then we don't know what to do.
|
|
||||||
//
|
|
||||||
if (argc > 1) {
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
if (string(argv[i]) == string("--help")) {
|
|
||||||
cerr << argv[0] << " 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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream *Out = &cout; // Default to printing to stdout...
|
ostream *Out = &cout; // Default to printing to stdout...
|
||||||
|
|
||||||
Module *C = ParseBytecodeFile(Opts.getInputFilename());
|
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Opts.getOutputFilename() != "-") {
|
if (OutputFilename.getValue() != "") { // Specified an output filename?
|
||||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
Out = new ofstream(OutputFilename.getValue().c_str(),
|
||||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
||||||
if (!Out->good()) {
|
} else {
|
||||||
cerr << "Error opening " << Opts.getOutputFilename()
|
if (InputFilename.getValue() == "-") {
|
||||||
<< ": sending to stdout instead!\n";
|
OutputFilename.setValue("-");
|
||||||
Out = &cout;
|
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
|
// All that dis does is write the assembly out to a file... which is exactly
|
||||||
// what the writer library is supposed to do...
|
// what the writer library is supposed to do...
|
||||||
//
|
//
|
||||||
if (WriteMode == Default) {
|
if (WriteMode.getValue() == Default) {
|
||||||
(*Out) << C; // Print out in list order
|
(*Out) << C; // Print out in list order
|
||||||
} else {
|
} else {
|
||||||
// TODO: This does not print anything other than the basic blocks in the
|
// TODO: This does not print anything other than the basic blocks in the
|
||||||
@@ -98,20 +96,20 @@ int main(int argc, char **argv) {
|
|||||||
Method *M = *I;
|
Method *M = *I;
|
||||||
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
||||||
|
|
||||||
switch (WriteMode) {
|
switch (WriteMode.getValue()) {
|
||||||
case DepthFirst: // Depth First ordering
|
case dfo: // Depth First ordering
|
||||||
copy(cfg::df_begin(M), cfg::df_end(M),
|
copy(cfg::df_begin(M), cfg::df_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
break;
|
break;
|
||||||
case ReverseDepthFirst: // Reverse Depth First ordering
|
case rdfo: // Reverse Depth First ordering
|
||||||
copy(cfg::df_begin(M, true), cfg::df_end(M),
|
copy(cfg::df_begin(M, true), cfg::df_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
break;
|
break;
|
||||||
case PostOrder: // Post Order
|
case po: // Post Order
|
||||||
copy(cfg::po_begin(M), cfg::po_end(M),
|
copy(cfg::po_begin(M), cfg::po_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
break;
|
break;
|
||||||
case ReversePostOrder: { // Reverse Post Order
|
case rpo: { // Reverse Post Order
|
||||||
cfg::ReversePostOrderTraversal RPOT(M);
|
cfg::ReversePostOrderTraversal RPOT(M);
|
||||||
copy(RPOT.begin(), RPOT.end(),
|
copy(RPOT.begin(), RPOT.end(),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
|
@@ -25,69 +25,67 @@
|
|||||||
#include "llvm/Method.h"
|
#include "llvm/Method.h"
|
||||||
#include "llvm/CFG.h"
|
#include "llvm/CFG.h"
|
||||||
|
|
||||||
|
// 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
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// WriteMode - The different orderings to print basic blocks in...
|
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
|
||||||
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;
|
|
||||||
|
|
||||||
ToolCommandLine Opts(argc, argv, false);
|
|
||||||
|
|
||||||
// We only support the options that the system parser does... if it left any
|
|
||||||
// then we don't know what to do.
|
|
||||||
//
|
|
||||||
if (argc > 1) {
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
if (string(argv[i]) == string("--help")) {
|
|
||||||
cerr << argv[0] << " 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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream *Out = &cout; // Default to printing to stdout...
|
ostream *Out = &cout; // Default to printing to stdout...
|
||||||
|
|
||||||
Module *C = ParseBytecodeFile(Opts.getInputFilename());
|
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Opts.getOutputFilename() != "-") {
|
if (OutputFilename.getValue() != "") { // Specified an output filename?
|
||||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
Out = new ofstream(OutputFilename.getValue().c_str(),
|
||||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
||||||
if (!Out->good()) {
|
} else {
|
||||||
cerr << "Error opening " << Opts.getOutputFilename()
|
if (InputFilename.getValue() == "-") {
|
||||||
<< ": sending to stdout instead!\n";
|
OutputFilename.setValue("-");
|
||||||
Out = &cout;
|
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
|
// All that dis does is write the assembly out to a file... which is exactly
|
||||||
// what the writer library is supposed to do...
|
// what the writer library is supposed to do...
|
||||||
//
|
//
|
||||||
if (WriteMode == Default) {
|
if (WriteMode.getValue() == Default) {
|
||||||
(*Out) << C; // Print out in list order
|
(*Out) << C; // Print out in list order
|
||||||
} else {
|
} else {
|
||||||
// TODO: This does not print anything other than the basic blocks in the
|
// TODO: This does not print anything other than the basic blocks in the
|
||||||
@@ -98,20 +96,20 @@ int main(int argc, char **argv) {
|
|||||||
Method *M = *I;
|
Method *M = *I;
|
||||||
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
(*Out) << "-------------- Method: " << M->getName() << " -------------\n";
|
||||||
|
|
||||||
switch (WriteMode) {
|
switch (WriteMode.getValue()) {
|
||||||
case DepthFirst: // Depth First ordering
|
case dfo: // Depth First ordering
|
||||||
copy(cfg::df_begin(M), cfg::df_end(M),
|
copy(cfg::df_begin(M), cfg::df_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
break;
|
break;
|
||||||
case ReverseDepthFirst: // Reverse Depth First ordering
|
case rdfo: // Reverse Depth First ordering
|
||||||
copy(cfg::df_begin(M, true), cfg::df_end(M),
|
copy(cfg::df_begin(M, true), cfg::df_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
break;
|
break;
|
||||||
case PostOrder: // Post Order
|
case po: // Post Order
|
||||||
copy(cfg::po_begin(M), cfg::po_end(M),
|
copy(cfg::po_begin(M), cfg::po_end(M),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
break;
|
break;
|
||||||
case ReversePostOrder: { // Reverse Post Order
|
case rpo: { // Reverse Post Order
|
||||||
cfg::ReversePostOrderTraversal RPOT(M);
|
cfg::ReversePostOrderTraversal RPOT(M);
|
||||||
copy(RPOT.begin(), RPOT.end(),
|
copy(RPOT.begin(), RPOT.end(),
|
||||||
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
ostream_iterator<BasicBlock*>(*Out, "\n"));
|
||||||
|
@@ -7,4 +7,4 @@ clean ::
|
|||||||
|
|
||||||
opt : $(ObjectsG) ../../lib/Optimizations/Debug/libopt.a
|
opt : $(ObjectsG) ../../lib/Optimizations/Debug/libopt.a
|
||||||
$(LinkG) -o $@ $(ObjectsG) -lopt -lbcreader -lbcwriter \
|
$(LinkG) -o $@ $(ObjectsG) -lopt -lbcreader -lbcwriter \
|
||||||
-lasmwriter -lanalysis -lvmcore
|
-lasmwriter -lanalysis -lvmcore -lsupport
|
||||||
|
@@ -29,70 +29,81 @@
|
|||||||
|
|
||||||
using namespace opt;
|
using namespace opt;
|
||||||
|
|
||||||
struct {
|
enum Opts {
|
||||||
const string ArgName, Name;
|
// Basic optimizations
|
||||||
bool (*OptPtr)(Module *C);
|
dce, constprop, inlining, strip, mstrip,
|
||||||
} OptTable[] = {
|
|
||||||
{ "-dce" , "Dead Code Elimination", DoDeadCodeElimination },
|
// More powerful optimizations
|
||||||
{ "-constprop" , "Constant Propogation", DoConstantPropogation },
|
indvars, sccp, cpm, adce, raise,
|
||||||
{ "-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 },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
enum Opts OptID;
|
||||||
|
bool (*OptPtr)(Module *C);
|
||||||
|
} OptTable[] = {
|
||||||
|
{ dce , DoDeadCodeElimination },
|
||||||
|
{ constprop, DoConstantPropogation },
|
||||||
|
{ inlining , DoMethodInlining },
|
||||||
|
{ strip , DoSymbolStripping },
|
||||||
|
{ mstrip , DoFullSymbolStripping },
|
||||||
|
{ indvars , DoInductionVariableCannonicalize },
|
||||||
|
{ sccp , DoSCCP },
|
||||||
|
{ cpm , DoConstantPoolMerging },
|
||||||
|
{ adce , DoADCE },
|
||||||
|
{ raise , DoRaiseRepresentation },
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
ToolCommandLine Opts(argc, argv, false);
|
cl::ParseCommandLineOptions(argc, argv,
|
||||||
bool Quiet = false;
|
" llvm .bc -> .bc modular optimizer\n");
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
Module *C = ParseBytecodeFile(InputFilename.getValue());
|
||||||
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());
|
|
||||||
if (C == 0) {
|
if (C == 0) {
|
||||||
cerr << "bytecode didn't read correctly.\n";
|
cerr << "bytecode didn't read correctly.\n";
|
||||||
return 1;
|
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;
|
unsigned j;
|
||||||
for (j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); j++) {
|
for (j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); ++j) {
|
||||||
if (string(argv[i]) == OptTable[j].ArgName) {
|
if (Opt == OptTable[j].OptID) {
|
||||||
if (OptTable[j].OptPtr(C) && !Quiet)
|
if (OptTable[j].OptPtr(C) && !Quiet)
|
||||||
cerr << OptTable[j].Name << " pass made modifications!\n";
|
cerr << OptimizationList.getArgName(Opt)
|
||||||
|
<< " pass made modifications!\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j == sizeof(OptTable)/sizeof(OptTable[0]))
|
if (j == sizeof(OptTable)/sizeof(OptTable[0]))
|
||||||
cerr << "'" << argv[i] << "' argument unrecognized: ignored\n";
|
cerr << "Optimization tables inconsistent!!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Opts.getOutputFilename() != "-") {
|
ostream *Out = &cout; // Default to printing to stdout...
|
||||||
Out = new ofstream(Opts.getOutputFilename().c_str(),
|
if (OutputFilename.getValue() != "") {
|
||||||
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
|
Out = new ofstream(OutputFilename.getValue().c_str(),
|
||||||
|
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
cerr << "Error opening " << Opts.getOutputFilename()
|
cerr << "Error opening " << OutputFilename.getValue() << "!\n";
|
||||||
<< "!\n";
|
|
||||||
delete C;
|
delete C;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
../as/as < ../../test/$1 | ./opt -constprop -dce | ../dis/dis
|
|
||||||
|
|
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
../as/as < ../../test/$1 | ./opt -inline -constprop -dce | dis
|
|
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
../as/as < ../../test/$1 | ./opt -strip | dis
|
|
Reference in New Issue
Block a user