diff options
Diffstat (limited to 'tools/llvmc/CompilerDriver.h')
-rw-r--r-- | tools/llvmc/CompilerDriver.h | 134 |
1 files changed, 37 insertions, 97 deletions
diff --git a/tools/llvmc/CompilerDriver.h b/tools/llvmc/CompilerDriver.h index a6d0be0..ea999b4 100644 --- a/tools/llvmc/CompilerDriver.h +++ b/tools/llvmc/CompilerDriver.h @@ -16,7 +16,7 @@ #include <string> #include <vector> -#include "Support/SetVector.h" +#include "llvm/System/Program.h" namespace llvm { /// This class provides the high level interface to the LLVM Compiler Driver. @@ -30,9 +30,12 @@ namespace llvm { /// @name Types /// @{ public: - /// @brief A vector of strings, commonly used + /// @brief A vector of strings, used for argument lists typedef std::vector<std::string> StringVector; + /// @brief A vector of sys::Path, used for path lists + typedef std::vector<sys::Path> PathVector; + /// @brief A table of strings, indexed typically by Phases typedef std::vector<StringVector> StringTable; @@ -65,11 +68,26 @@ namespace llvm { FLAGS_MASK = 0x000F, ///< Union of all flags }; + /// @brief Driver specific flags + enum DriverFlags { + DRY_RUN_FLAG = 0x0001, ///< Do everything but execute actions + FORCE_FLAG = 0x0002, ///< Force overwrite of output files + VERBOSE_FLAG = 0x0004, ///< Print each action + DEBUG_FLAG = 0x0008, ///< Print debug information + TIME_PASSES_FLAG = 0x0010, ///< Time the passes as they execute + TIME_ACTIONS_FLAG = 0x0020, ///< Time the actions as they execute + SHOW_STATS_FLAG = 0x0040, ///< Show pass statistics + EMIT_NATIVE_FLAG = 0x0080, ///< Emit native code instead of bc + EMIT_RAW_FLAG = 0x0100, ///< Emit raw, unoptimized bytecode + KEEP_TEMPS_FLAG = 0x0200, ///< Don't delete temporary files + DRIVER_FLAGS_MASK = 0x02FF, ///< Union of the above flags + }; + /// This type is the input list to the CompilerDriver. It provides - /// a vector of filename/filetype pairs. The filetype is used to look up + /// a vector of pathname/filetype pairs. The filetype is used to look up /// the configuration of the actions to be taken by the driver. /// @brief The Input Data to the execute method - typedef std::vector<std::pair<std::string,std::string> > InputList; + typedef std::vector<std::pair<sys::Path,std::string> > InputList; /// This type is read from configuration files or otherwise provided to /// the CompilerDriver through a "ConfigDataProvider". It serves as both @@ -78,7 +96,7 @@ namespace llvm { /// language. struct Action { Action() : flags(0) {} - std::string program; ///< The program to execve + sys::Program program; ///< The program to execve StringVector args; ///< Arguments to the program unsigned flags; ///< Action specific flags void set(unsigned fl ) { flags |= fl; } @@ -107,127 +125,49 @@ namespace llvm { class ConfigDataProvider { public: virtual ConfigData* ProvideConfigData(const std::string& filetype) = 0; - virtual void setConfigDir(const std::string& dirName) = 0; + virtual void setConfigDir(const sys::Path& dirName) = 0; }; /// @} /// @name Constructors /// @{ public: - CompilerDriver(ConfigDataProvider& cdp ); + /// @brief Static Constructor + static CompilerDriver* Get(ConfigDataProvider& CDP); + + /// @brief Virtual destructor virtual ~CompilerDriver(); /// @} /// @name Methods /// @{ public: - /// @brief Handle an error - virtual void error(const std::string& errmsg); - /// @brief Execute the actions requested for the given input list. - virtual int execute(const InputList& list, const std::string& output); + virtual int execute(const InputList& list, const sys::Path& output) = 0; - /// @} - /// @name Mutators - /// @{ - public: /// @brief Set the final phase at which compilation terminates - void setFinalPhase( Phases phase ) { finalPhase = phase; } + virtual void setFinalPhase(Phases phase) = 0; /// @brief Set the optimization level for the compilation - void setOptimization( OptimizationLevels level ) { optLevel = level; } - - /// @brief Prevent the CompilerDriver from taking any actions - void setDryRun( bool TF ) { isDryRun = TF; } - - /// @brief Cause the CompilerDriver to print to stderr all the - /// actions it is taking. - void setVerbose( bool TF ) { isVerbose = TF; } - - /// @brief Cause the CompilerDriver to print to stderr very verbose - /// information that might be useful in debugging the driver's actions - void setDebug( bool TF ) { isDebug = TF; } - - /// @brief Cause the CompilerDriver to print to stderr the - /// execution time of each action taken. - void setTimeActions( bool TF ) { timeActions = TF; } - - /// @brief Cause the CompilerDriver to print timings for each pass. - void setTimePasses( bool TF ) { timePasses = TF; } + virtual void setOptimization(OptimizationLevels level) = 0; - /// @brief Cause the CompilerDriver to show statistics gathered - void setShowStats( bool TF ) { showStats = TF; } - - /// @brief Indicate that native code is to be generated instead - /// of LLVM bytecode. - void setEmitNativeCode( bool TF ) { emitNativeCode = TF; } - - /// @brief Indicate that raw, unoptimized code is to be generated. - void setEmitRawCode(bool TF ) { emitRawCode = TF; } - - void setKeepTemporaries(bool TF) { keepTemps = TF; } + /// @brief Set the driver flags. + virtual void setDriverFlags(unsigned flags) = 0; /// @brief Set the output machine name. - void setOutputMachine( const std::string& machineName ) { - machine = machineName; - } + virtual void setOutputMachine(const std::string& machineName) = 0; /// @brief Set Preprocessor specific options - void setPhaseArgs(Phases phase, const std::vector<std::string>& opts) { - assert(phase <= LINKING && phase >= PREPROCESSING); - AdditionalArgs[phase] = opts; - } + virtual void setPhaseArgs(Phases phase, const StringVector& opts) = 0; /// @brief Set Library Paths - void setLibraryPaths(const std::vector<std::string>& paths) { - LibraryPaths = paths; - } + virtual void setLibraryPaths(const StringVector& paths) = 0; /// @brief Set the list of library paths to be searched for /// libraries. - void addLibraryPath( const std::string& libPath ) { - LibraryPaths.push_back(libPath); - } + virtual void addLibraryPath( const sys::Path& libPath ) = 0; /// @} - /// @name Functions - /// @{ - private: - Action* GetAction(ConfigData* cd, const std::string& input, - const std::string& output, Phases phase ); - - bool DoAction(Action* a); - - std::string GetPathForLinkageItem(const std::string& link_item, - const std::string& dir); - - bool ProcessLinkageItem(const std::string& link_item, - SetVector<std::string>& set, - std::string& err); - - /// @} - /// @name Data - /// @{ - private: - ConfigDataProvider* cdp; ///< Where we get configuration data from - Phases finalPhase; ///< The final phase of compilation - OptimizationLevels optLevel; ///< The optimization level to apply - bool isDryRun; ///< Prevent actions ? - bool isVerbose; ///< Print actions? - bool isDebug; ///< Print lotsa debug info? - bool timeActions; ///< Time the actions executed ? - bool timePasses; ///< Time each pass and print timing ? - bool showStats; ///< Show gathered statistics ? - bool emitRawCode; ///< Emit Raw (unoptimized) code? - bool emitNativeCode; ///< Emit native code instead of bytecode? - bool keepTemps; ///< Keep temporary files? - std::string machine; ///< Target machine name - StringVector LibraryPaths; ///< -L options - StringTable AdditionalArgs; ///< The -Txyz options - std::string TempDir; ///< Name of the temporary directory. - - /// @} - }; } |