1 //===- CompilerDriver.h - Compiler Driver -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source 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 //===------------------------------------------------------------------------===
14 #ifndef LLVM_TOOLS_LLVMC_COMPILERDRIVER_H
15 #define LLVM_TOOLS_LLVMC_COMPILERDRIVER_H
21 /// This class provides the high level interface to the LLVM Compiler Driver.
22 /// The driver's purpose is to make it easier for compiler writers and users
23 /// of LLVM to utilize the compiler toolkits and LLVM toolset by learning only
24 /// the interface of one program (llvmc).
27 /// @brief The interface to the LLVM Compiler Driver.
28 class CompilerDriver {
33 PREPROCESSING, ///< Source language combining, filtering, substitution
34 TRANSLATION, ///< Translate source -> LLVM bytecode/assembly
35 OPTIMIZATION, ///< Optimize translation result
36 LINKING, ///< Link bytecode and native code
37 ASSEMBLY, ///< Convert program to executable
40 enum OptimizationLevels {
41 OPT_NONE, ///< Zippo optimizations, nada, nil, none.
42 OPT_FAST_COMPILE, ///< Optimize to make >compile< go faster
43 OPT_SIMPLE, ///< Standard/simple optimizations
44 OPT_AGGRESSIVE, ///< Aggressive optimizations
45 OPT_LINK_TIME, ///< Aggressive + LinkTime optimizations
46 OPT_AGGRESSIVE_LINK_TIME ///< Make it go way fast!
49 /// This type is the input list to the CompilerDriver. It provides
50 /// a vector of filename/filetype pairs. The filetype is used to look up
51 /// the configuration of the actions to be taken by the driver.
52 /// @brief The Input Data to the execute method
53 typedef std::vector<std::pair<std::string,std::string> > InputList;
55 /// This type is read from configuration files or otherwise provided to
56 /// the CompilerDriver through a "ConfigDataProvider". It serves as both
57 /// the template of what to do and the actual Action to be executed.
58 /// @brief A structure to hold the action data for a given source
61 Action() : inputAt(0) , outputAt(0) {}
62 std::string program; ///< The program to execve
63 std::vector<std::string> args; ///< Arguments to the program
64 size_t inputAt; ///< Argument index to insert input file
65 size_t outputAt; ///< Argument index to insert output file
69 ConfigData() : TranslatorPreprocesses(false),
70 TranslatorOptimizes(false),
71 TranslatorGroksDashO(false),
72 PreprocessorNeeded(false) {}
73 std::string langName; ///< The name of the source language
74 bool TranslatorPreprocesses;///< Translator program will pre-process
75 bool TranslatorOptimizes; ///< Translator program will optimize too
76 bool TranslatorGroksDashO; ///< Translator understands -O arguments
77 bool PreprocessorNeeded; ///< Preprocessor is needed for translation
78 Action PreProcessor; ///< PreProcessor command line
79 Action Translator; ///< Translator command line
80 Action Optimizer; ///< Optimizer command line
81 Action Assembler; ///< Assembler command line
82 Action Linker; ///< Linker command line
85 /// This pure virtual interface class defines the interface between the
86 /// CompilerDriver and other software that provides ConfigData objects to
87 /// it. The CompilerDriver must be configured to use an object of this
88 /// type so it can obtain the configuration data.
89 /// @see setConfigDataProvider
90 /// @brief Configuration Data Provider interface
91 class ConfigDataProvider {
93 virtual ConfigData* ProvideConfigData(const std::string& filetype) = 0;
94 virtual void setConfigDir(const std::string& dirName) = 0;
98 /// @name Constructors
101 CompilerDriver(ConfigDataProvider& cdp );
102 virtual ~CompilerDriver();
108 /// @brief Handle an error
109 virtual void error(const std::string& errmsg);
111 /// @brief Execute the actions requested for the given input list.
112 virtual int execute(const InputList& list, const std::string& output);
118 /// @brief Set the final phase at which compilation terminates
119 void setFinalPhase( Phases phase ) { finalPhase = phase; }
121 /// @brief Set the optimization level for the compilation
122 void setOptimization( OptimizationLevels level ) { optLevel = level; }
124 /// @brief Prevent the CompilerDriver from taking any actions
125 void setDryRun( bool TF ) { isDryRun = TF; }
127 /// @brief Cause the CompilerDriver to print to stderr all the
128 /// actions it is taking.
129 void setVerbose( bool TF ) { isVerbose = TF; }
131 /// @brief Cause the CompilerDriver to print to stderr very verbose
132 /// information that might be useful in debugging the driver's actions
133 void setDebug( bool TF ) { isDebug = TF; }
135 /// @brief Cause the CompilerDriver to print to stderr the
136 /// execution time of each action taken.
137 void setTimeActions( bool TF ) { timeActions = TF; }
139 /// @brief Indicate that native code is to be generated instead
140 /// of LLVM bytecode.
141 void setEmitNativeCode( bool TF ) { emitNativeCode = TF; }
143 /// @brief Indicate that raw, unoptimized code is to be generated.
144 void setEmitRawCode(bool TF ) { emitRawCode = TF; }
146 /// @brief Set the output machine name.
147 void setOutputMachine( const std::string& machineName ) {
148 machine = machineName;
151 /// @brief Set the list of library paths to be searched for
153 void addLibraryPath( const std::string& libPath ) {
154 libPaths.push_back(libPath);
161 Action* GetAction(ConfigData* cd, const std::string& input,
162 const std::string& output, Phases phase );
163 void DoAction(Action* a);
169 ConfigDataProvider* cdp; ///< Where we get configuration data from
170 Phases finalPhase; ///< The final phase of compilation
171 OptimizationLevels optLevel; ///< The optimization level to apply
172 bool isDryRun; ///< Prevent actions ?
173 bool isVerbose; ///< Print actions?
174 bool isDebug; ///< Print lotsa debug info?
175 bool timeActions; ///< Time the actions executed ?
176 bool emitRawCode; ///< Emit Raw (unoptimized) code?
177 bool emitNativeCode; ///< Emit native code instead of bytecode?
178 std::string machine; ///< Target machine name
179 std::vector<std::string> libPaths; ///< list of dirs to find libraries
186 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab