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