diff options
Diffstat (limited to 'tools/llvmc/CompilerDriver.h')
-rw-r--r-- | tools/llvmc/CompilerDriver.h | 140 |
1 files changed, 124 insertions, 16 deletions
diff --git a/tools/llvmc/CompilerDriver.h b/tools/llvmc/CompilerDriver.h index d56c9b5..d6587b0 100644 --- a/tools/llvmc/CompilerDriver.h +++ b/tools/llvmc/CompilerDriver.h @@ -1,4 +1,4 @@ -//===- CompilerDriver.h - Compiler Driver ---------------------------------===// +//===- CompilerDriver.h - Compiler Driver -----------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -11,6 +11,11 @@ // LLVM Compiler Driver program (llvmc). // //===------------------------------------------------------------------------=== +#ifndef LLVM_TOOLS_LLVMC_COMPILERDRIVER_H +#define LLVM_TOOLS_LLVMC_COMPILERDRIVER_H + +#include <string> +#include <vector> namespace llvm { /// This class provides the high level interface to the LLVM Compiler Driver. @@ -24,7 +29,6 @@ namespace llvm { /// @name Types /// @{ public: - typedef unsigned OptimizationLevel; enum Phases { PREPROCESSING, ///< Source language combining, filtering, substitution TRANSLATION, ///< Translate source -> LLVM bytecode/assembly @@ -34,42 +38,146 @@ namespace llvm { }; enum OptimizationLevels { - OPT_NONE, - OPT_FAST_COMPILE, - OPT_SIMPLE, - OPT_AGGRESSIVE, - OPT_LINK_TIME, - OPT_AGGRESSIVE_LINK_TIME + OPT_NONE, ///< Zippo optimizations, nada, nil, none. + OPT_FAST_COMPILE, ///< Optimize to make >compile< go faster + OPT_SIMPLE, ///< Standard/simple optimizations + OPT_AGGRESSIVE, ///< Aggressive optimizations + OPT_LINK_TIME, ///< Aggressive + LinkTime optimizations + OPT_AGGRESSIVE_LINK_TIME ///< Make it go way fast! + }; + + /// This type is the input list to the CompilerDriver. It provides + /// a vector of filename/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; + + /// This type is read from configuration files or otherwise provided to + /// the CompilerDriver through a "ConfigDataProvider". It serves as both + /// the template of what to do and the actual Action to be executed. + /// @brief A structure to hold the action data for a given source + /// language. + struct Action { + std::string program; ///< The program to execve + std::vector<std::string> args; ///< Arguments to the program + size_t inputAt; ///< Argument index to insert input file + size_t outputAt; ///< Argument index to insert output file + }; + + struct ConfigData { + std::string langName; ///< The name of the source language + bool TranslatorPreprocesses;///< Translator program will pre-process + bool TranslatorOptimizes; ///< Translator program will optimize too + bool TranslatorGroksDashO; ///< Translator understands -O arguments + bool PreprocessorNeeded; ///< Preprocessor is needed for translation + Action PreProcessor; ///< PreProcessor command line + Action Translator; ///< Translator command line + Action Optimizer; ///< Optimizer command line + Action Assembler; ///< Assembler command line + Action Linker; ///< Linker command line + }; + + /// This pure virtual interface class defines the interface between the + /// CompilerDriver and other software that provides ConfigData objects to + /// it. The CompilerDriver must be configured to use an object of this + /// type so it can obtain the configuration data. + /// @see setConfigDataProvider + /// @brief Configuration Data Provider interface + class ConfigDataProvider { + public: + virtual ConfigData* ProvideConfigData(const std::string& filetype) = 0; + virtual void setConfigDir(const std::string& dirName) = 0; }; /// @} /// @name Constructors /// @{ public: - CompilerDriver(); + CompilerDriver(ConfigDataProvider& cdp ); + virtual ~CompilerDriver(); /// @} - /// @name Accessors + /// @name Methods /// @{ public: - void execute(); ///< Execute the actions requested + /// @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); /// @} /// @name Mutators /// @{ public: + /// @brief Set the final phase at which compilation terminates + void setFinalPhase( Phases phase ) { finalPhase = phase; } + /// @brief Set the optimization level for the compilation - void setOptimization( OptimizationLevel level ); - void setFinalPhase( Phases phase ); + 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 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; } + + /// @brief Set the output machine name. + void setOutputMachine( const std::string& machineName ) { + machine = machineName; + } + + /// @brief Set the list of library paths to be searched for + /// libraries. + void addLibraryPath( const std::string& libPath ) { + libPaths.push_back(libPath); + } + + /// @} + /// @name Functions + /// @{ + private: + Action* GetAction(ConfigData* cd, const std::string& input, + const std::string& output, Phases phase ); + void WriteAction(Action* a); + void DoAction(Action* a); /// @} /// @name Data /// @{ - public: - Phases finalPhase; - OptimizationLevel optLevel; + 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 emitRawCode; ///< Emit Raw (unoptimized) code? + bool emitNativeCode; ///< Emit native code instead of bytecode? + std::string machine; ///< Target machine name + std::vector<std::string> libPaths; ///< list of dirs to find libraries /// @} }; } + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab +#endif |