Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 1 | //===- CompilerDriver.h - Compiler Driver -----------------------*- C++ -*-===// |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 5 | // This file was developed by Reid Spencer and is distributed under the |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares the CompilerDriver class which implements the bulk of the |
| 11 | // LLVM Compiler Driver program (llvmc). |
| 12 | // |
| 13 | //===------------------------------------------------------------------------=== |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 14 | #ifndef LLVM_TOOLS_LLVMC_COMPILERDRIVER_H |
| 15 | #define LLVM_TOOLS_LLVMC_COMPILERDRIVER_H |
| 16 | |
| 17 | #include <string> |
| 18 | #include <vector> |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 19 | #include "llvm/System/Program.h" |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | /// This class provides the high level interface to the LLVM Compiler Driver. |
| 23 | /// The driver's purpose is to make it easier for compiler writers and users |
| 24 | /// of LLVM to utilize the compiler toolkits and LLVM toolset by learning only |
| 25 | /// the interface of one program (llvmc). |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 26 | /// |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 27 | /// @see llvmc.cpp |
| 28 | /// @brief The interface to the LLVM Compiler Driver. |
| 29 | class CompilerDriver { |
| 30 | /// @name Types |
| 31 | /// @{ |
| 32 | public: |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 33 | /// @brief A vector of strings, used for argument lists |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 34 | typedef std::vector<std::string> StringVector; |
| 35 | |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 36 | /// @brief A vector of sys::Path, used for path lists |
| 37 | typedef std::vector<sys::Path> PathVector; |
| 38 | |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 39 | /// @brief A table of strings, indexed typically by Phases |
| 40 | typedef std::vector<StringVector> StringTable; |
| 41 | |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 42 | /// @brief The phases of processing that llvmc understands |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 43 | enum Phases { |
| 44 | PREPROCESSING, ///< Source language combining, filtering, substitution |
| 45 | TRANSLATION, ///< Translate source -> LLVM bytecode/assembly |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 46 | OPTIMIZATION, ///< Optimize translation result |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 47 | ASSEMBLY, ///< Convert program to executable |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 48 | LINKING, ///< Link bytecode and native code |
| 49 | NUM_PHASES ///< Always last! |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 52 | /// @brief The levels of optimization llvmc understands |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 53 | enum OptimizationLevels { |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 54 | OPT_FAST_COMPILE, ///< Optimize to make >compile< go faster |
| 55 | OPT_SIMPLE, ///< Standard/simple optimizations |
| 56 | OPT_AGGRESSIVE, ///< Aggressive optimizations |
| 57 | OPT_LINK_TIME, ///< Aggressive + LinkTime optimizations |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 58 | OPT_AGGRESSIVE_LINK_TIME, ///< Make it go way fast! |
| 59 | OPT_NONE ///< No optimizations. Keep this at the end! |
| 60 | }; |
| 61 | |
| 62 | /// @brief Action specific flags |
| 63 | enum ConfigurationFlags { |
| 64 | REQUIRED_FLAG = 0x0001, ///< Should the action always be run? |
Reid Spencer | fd2f728 | 2004-08-24 13:49:57 +0000 | [diff] [blame] | 65 | PREPROCESSES_FLAG = 0x0002, ///< Does this action preprocess? |
| 66 | TRANSLATES_FLAG = 0x0004, ///< Does this action translate? |
| 67 | OUTPUT_IS_ASM_FLAG = 0x0008, ///< Action produces .ll files? |
| 68 | FLAGS_MASK = 0x000F, ///< Union of all flags |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /// This type is the input list to the CompilerDriver. It provides |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 72 | /// a vector of pathname/filetype pairs. The filetype is used to look up |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 73 | /// the configuration of the actions to be taken by the driver. |
| 74 | /// @brief The Input Data to the execute method |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 75 | typedef std::vector<std::pair<sys::Path,std::string> > InputList; |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 76 | |
| 77 | /// This type is read from configuration files or otherwise provided to |
| 78 | /// the CompilerDriver through a "ConfigDataProvider". It serves as both |
| 79 | /// the template of what to do and the actual Action to be executed. |
| 80 | /// @brief A structure to hold the action data for a given source |
| 81 | /// language. |
| 82 | struct Action { |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 83 | Action() : flags(0) {} |
Reid Spencer | f6358c7 | 2004-12-19 18:00:56 +0000 | [diff] [blame] | 84 | sys::Path program; ///< The program to execve |
| 85 | StringVector args; ///< Arguments to the program |
| 86 | unsigned flags; ///< Action specific flags |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 87 | void set(unsigned fl ) { flags |= fl; } |
| 88 | void clear(unsigned fl) { flags &= (FLAGS_MASK ^ fl); } |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 89 | bool isSet(unsigned fl) { return (flags&fl) != 0; } |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | struct ConfigData { |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 93 | ConfigData(); |
Reid Spencer | 59a745a | 2004-08-22 18:03:25 +0000 | [diff] [blame] | 94 | std::string version; ///< The version number. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 95 | std::string langName; ///< The name of the source language |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 96 | StringTable opts; ///< The o10n options for each level |
Reid Spencer | 2d3ee4e | 2004-11-23 23:40:06 +0000 | [diff] [blame] | 97 | StringVector libpaths; ///< The library paths |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 98 | Action PreProcessor; ///< PreProcessor command line |
| 99 | Action Translator; ///< Translator command line |
| 100 | Action Optimizer; ///< Optimizer command line |
| 101 | Action Assembler; ///< Assembler command line |
| 102 | Action Linker; ///< Linker command line |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | /// This pure virtual interface class defines the interface between the |
| 106 | /// CompilerDriver and other software that provides ConfigData objects to |
| 107 | /// it. The CompilerDriver must be configured to use an object of this |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 108 | /// type so it can obtain the configuration data. |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 109 | /// @see setConfigDataProvider |
| 110 | /// @brief Configuration Data Provider interface |
| 111 | class ConfigDataProvider { |
| 112 | public: |
| 113 | virtual ConfigData* ProvideConfigData(const std::string& filetype) = 0; |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 114 | virtual void setConfigDir(const sys::Path& dirName) = 0; |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
Reid Spencer | 54fafe4 | 2004-09-14 01:58:45 +0000 | [diff] [blame] | 117 | /// These flags control various actions of the compiler driver. They are |
| 118 | /// used by adding the needed flag values together and passing them to the |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 119 | /// compiler driver's setDriverFlags method. |
Reid Spencer | 54fafe4 | 2004-09-14 01:58:45 +0000 | [diff] [blame] | 120 | /// @see setDriverFlags |
| 121 | /// @brief Driver specific flags |
| 122 | enum DriverFlags { |
| 123 | DRY_RUN_FLAG = 0x0001, ///< Do everything but execute actions |
Reid Spencer | 3a9b222 | 2004-10-28 04:04:38 +0000 | [diff] [blame] | 124 | VERBOSE_FLAG = 0x0002, ///< Print each action |
| 125 | DEBUG_FLAG = 0x0004, ///< Print debug information |
| 126 | TIME_PASSES_FLAG = 0x0008, ///< Time the passes as they execute |
| 127 | TIME_ACTIONS_FLAG = 0x0010, ///< Time the actions as they execute |
| 128 | SHOW_STATS_FLAG = 0x0020, ///< Show pass statistics |
| 129 | EMIT_NATIVE_FLAG = 0x0040, ///< Emit native code instead of bc |
| 130 | EMIT_RAW_FLAG = 0x0080, ///< Emit raw, unoptimized bytecode |
| 131 | KEEP_TEMPS_FLAG = 0x0100, ///< Don't delete temporary files |
| 132 | STRIP_OUTPUT_FLAG = 0x0200, ///< Strip symbols from linked output |
| 133 | DRIVER_FLAGS_MASK = 0x03FF, ///< Union of the above flags |
Reid Spencer | 54fafe4 | 2004-09-14 01:58:45 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 136 | /// @} |
| 137 | /// @name Constructors |
| 138 | /// @{ |
| 139 | public: |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 140 | /// @brief Static Constructor |
| 141 | static CompilerDriver* Get(ConfigDataProvider& CDP); |
| 142 | |
| 143 | /// @brief Virtual destructor |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 144 | virtual ~CompilerDriver(); |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 145 | |
| 146 | /// @} |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 147 | /// @name Methods |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 148 | /// @{ |
| 149 | public: |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 150 | /// @brief Execute the actions requested for the given input list. |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 151 | virtual int execute(const InputList& list, const sys::Path& output) = 0; |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 152 | |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 153 | /// @brief Set the final phase at which compilation terminates |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 154 | virtual void setFinalPhase(Phases phase) = 0; |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 155 | |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 156 | /// @brief Set the optimization level for the compilation |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 157 | virtual void setOptimization(OptimizationLevels level) = 0; |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 158 | |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 159 | /// @brief Set the driver flags. |
| 160 | virtual void setDriverFlags(unsigned flags) = 0; |
Reid Spencer | bae6825 | 2004-08-19 04:49:47 +0000 | [diff] [blame] | 161 | |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 162 | /// @brief Set the output machine name. |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 163 | virtual void setOutputMachine(const std::string& machineName) = 0; |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 164 | |
Reid Spencer | 07adb28 | 2004-11-05 22:15:36 +0000 | [diff] [blame] | 165 | /// @brief Set the options for a given phase. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 166 | virtual void setPhaseArgs(Phases phase, const StringVector& opts) = 0; |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 167 | |
| 168 | /// @brief Set Library Paths |
Reid Spencer | ca01f9b | 2004-08-30 06:29:06 +0000 | [diff] [blame] | 169 | virtual void setIncludePaths(const StringVector& paths) = 0; |
| 170 | |
| 171 | /// @brief Set Library Paths |
| 172 | virtual void setSymbolDefines(const StringVector& paths) = 0; |
| 173 | |
| 174 | /// @brief Set Library Paths |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 175 | virtual void setLibraryPaths(const StringVector& paths) = 0; |
Reid Spencer | bf43772 | 2004-08-15 08:19:46 +0000 | [diff] [blame] | 176 | |
Reid Spencer | 07adb28 | 2004-11-05 22:15:36 +0000 | [diff] [blame] | 177 | /// @brief Add a path to the list of library paths |
Reid Spencer | 52c2dc1 | 2004-08-29 19:26:56 +0000 | [diff] [blame] | 178 | virtual void addLibraryPath( const sys::Path& libPath ) = 0; |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 179 | |
Reid Spencer | 07adb28 | 2004-11-05 22:15:36 +0000 | [diff] [blame] | 180 | /// @brief Add a path to the list of paths in which to find tools |
| 181 | virtual void addToolPath( const sys::Path& toolPath) = 0; |
| 182 | |
Reid Spencer | 54fafe4 | 2004-09-14 01:58:45 +0000 | [diff] [blame] | 183 | /// @brief Set the list of -f options to be passed through |
| 184 | virtual void setfPassThrough(const StringVector& fOpts) = 0; |
| 185 | |
| 186 | /// @brief Set the list of -M options to be passed through |
| 187 | virtual void setMPassThrough(const StringVector& fOpts) = 0; |
| 188 | |
| 189 | /// @brief Set the list of -W options to be passed through |
| 190 | virtual void setWPassThrough(const StringVector& fOpts) = 0; |
| 191 | |
Reid Spencer | 2d3ee4e | 2004-11-23 23:40:06 +0000 | [diff] [blame] | 192 | /// @brief Determine where a linkage file is located in the file system |
| 193 | virtual sys::Path GetPathForLinkageItem( |
| 194 | const std::string& link_item, ///< Item to be sought |
| 195 | bool native = false ///< Looking for native? |
| 196 | ) = 0; |
| 197 | |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 198 | /// @} |
Reid Spencer | abf1ce3 | 2004-08-10 16:29:18 +0000 | [diff] [blame] | 199 | }; |
| 200 | } |
Reid Spencer | 5c56dc1 | 2004-08-13 20:22:43 +0000 | [diff] [blame] | 201 | |
| 202 | // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab |
| 203 | #endif |