1 //===- CompilerDriver.h - Compiler Driver -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the CompilerDriver class which implements the bulk of the
11 // LLVM Compiler Driver program (llvmc).
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TOOLS_LLVMC_COMPILERDRIVER_H
16 #define LLVM_TOOLS_LLVMC_COMPILERDRIVER_H
20 #include "llvm/System/Program.h"
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).
29 /// @brief The interface to the LLVM Compiler Driver.
30 class CompilerDriver {
34 /// @brief A vector of strings, used for argument lists
35 typedef std::vector<std::string> StringVector;
37 /// @brief A vector of sys::Path, used for path lists
38 typedef std::vector<sys::Path> PathVector;
40 /// @brief A table of strings, indexed typically by Phases
41 typedef std::vector<StringVector> StringTable;
43 /// @brief The phases of processing that llvmc understands
45 PREPROCESSING, ///< Source language combining, filtering, substitution
46 TRANSLATION, ///< Translate source -> LLVM bitcode/assembly
47 OPTIMIZATION, ///< Optimize translation result
48 ASSEMBLY, ///< Convert program to executable
49 LINKING, ///< Link bitcode and native code
50 NUM_PHASES ///< Always last!
53 /// @brief The levels of optimization llvmc understands
54 enum OptimizationLevels {
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
59 OPT_AGGRESSIVE_LINK_TIME, ///< Make it go way fast!
60 OPT_NONE ///< No optimizations. Keep this at the end!
63 /// @brief Action specific flags
64 enum ConfigurationFlags {
65 REQUIRED_FLAG = 0x0001, ///< Should the action always be run?
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?
69 FLAGS_MASK = 0x000F ///< Union of all flags
72 /// This type is the input list to the CompilerDriver. It provides
73 /// a vector of pathname/filetype pairs. The filetype is used to look up
74 /// the configuration of the actions to be taken by the driver.
75 /// @brief The Input Data to the execute method
76 typedef std::vector<std::pair<sys::Path,std::string> > InputList;
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
84 Action() : flags(0) {}
85 sys::Path program; ///< The program to execve
86 StringVector args; ///< Arguments to the program
87 unsigned flags; ///< Action specific flags
88 void set(unsigned fl ) { flags |= fl; }
89 void clear(unsigned fl) { flags &= (FLAGS_MASK ^ fl); }
90 bool isSet(unsigned fl) { return (flags&fl) != 0; }
95 std::string version; ///< The version number.
96 std::string langName; ///< The name of the source language
97 StringTable opts; ///< The o10n options for each level
98 StringVector libpaths; ///< The library paths
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
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
109 /// type so it can obtain the configuration data.
110 /// @see setConfigDataProvider
111 /// @brief Configuration Data Provider interface
112 class ConfigDataProvider {
114 virtual ~ConfigDataProvider();
115 virtual ConfigData* ProvideConfigData(const std::string& filetype) = 0;
116 virtual void setConfigDir(const sys::Path& dirName) = 0;
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
121 /// compiler driver's setDriverFlags method.
122 /// @see setDriverFlags
123 /// @brief Driver specific flags
125 DRY_RUN_FLAG = 0x0001, ///< Do everything but execute actions
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
132 EMIT_RAW_FLAG = 0x0080, ///< Emit raw, unoptimized bitcode
133 KEEP_TEMPS_FLAG = 0x0100, ///< Don't delete temporary files
134 STRIP_OUTPUT_FLAG = 0x0200, ///< Strip symbols from linked output
135 DRIVER_FLAGS_MASK = 0x03FF ///< Union of the above flags
139 /// @name Constructors
142 /// @brief Static Constructor
143 static CompilerDriver* Get(ConfigDataProvider& CDP);
145 /// @brief Virtual destructor
146 virtual ~CompilerDriver();
152 /// @brief Execute the actions requested for the given input list.
154 const InputList& list, const sys::Path& output, std::string& ErrMsg) =0;
156 /// @brief Set the final phase at which compilation terminates
157 virtual void setFinalPhase(Phases phase) = 0;
159 /// @brief Set the optimization level for the compilation
160 virtual void setOptimization(OptimizationLevels level) = 0;
162 /// @brief Set the driver flags.
163 virtual void setDriverFlags(unsigned flags) = 0;
165 /// @brief Set the output machine name.
166 virtual void setOutputMachine(const std::string& machineName) = 0;
168 /// @brief Set the options for a given phase.
169 virtual void setPhaseArgs(Phases phase, const StringVector& opts) = 0;
171 /// @brief Set Library Paths
172 virtual void setIncludePaths(const StringVector& paths) = 0;
174 /// @brief Set Library Paths
175 virtual void setSymbolDefines(const StringVector& paths) = 0;
177 /// @brief Set Library Paths
178 virtual void setLibraryPaths(const StringVector& paths) = 0;
180 /// @brief Add a path to the list of library paths
181 virtual void addLibraryPath( const sys::Path& libPath ) = 0;
183 /// @brief Add a path to the list of paths in which to find tools
184 virtual void addToolPath( const sys::Path& toolPath) = 0;
186 /// @brief Set the list of -f options to be passed through
187 virtual void setfPassThrough(const StringVector& fOpts) = 0;
189 /// @brief Set the list of -M options to be passed through
190 virtual void setMPassThrough(const StringVector& fOpts) = 0;
192 /// @brief Set the list of -W options to be passed through
193 virtual void setWPassThrough(const StringVector& fOpts) = 0;
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?
205 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab