Driver.h revision e504952bc89f79fc9ff54d5641ab30bb07ec435e
1//===--- Driver.h - Clang GCC Compatible Driver -----------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef CLANG_DRIVER_DRIVER_H_ 11#define CLANG_DRIVER_DRIVER_H_ 12 13#include "clang/Basic/Diagnostic.h" 14 15#include "clang/Driver/Phases.h" 16#include "clang/Driver/Util.h" 17 18#include "llvm/System/Path.h" // FIXME: Kill when CompilationInfo 19 // lands. 20#include <list> 21#include <set> 22#include <string> 23 24namespace clang { 25namespace driver { 26 class Action; 27 class ArgList; 28 class Compilation; 29 class HostInfo; 30 class InputInfo; 31 class JobAction; 32 class OptTable; 33 class PipedJob; 34 class ToolChain; 35 36/// Driver - Encapsulate logic for constructing compilation processes 37/// from a set of gcc-driver-like command line arguments. 38class Driver { 39 OptTable *Opts; 40 41 Diagnostic &Diags; 42 43 // Diag - Forwarding function for diagnostics. 44 DiagnosticBuilder Diag(unsigned DiagID) const { 45 return Diags.Report(FullSourceLoc(), DiagID); 46 } 47 48 // FIXME: Privatize once interface is stable. 49public: 50 /// The name the driver was invoked as. 51 std::string Name; 52 53 /// The path the driver executable was in, as invoked from the 54 /// command line. 55 std::string Dir; 56 57 /// Default host triple. 58 std::string DefaultHostTriple; 59 60 /// Default name for linked images (e.g., "a.out"). 61 std::string DefaultImageName; 62 63 /// Host information for the platform the driver is running as. This 64 /// will generally be the actual host platform, but not always. 65 const HostInfo *Host; 66 67 /// The default tool chain for this host. 68 // FIXME: This shouldn't be here; this should be in a 69 // CompilationInfo structure. 70 ToolChain *DefaultToolChain; 71 72 /// Information about the host which can be overriden by the user. 73 std::string HostBits, HostMachine, HostSystem, HostRelease; 74 75 /// Whether the driver should follow g++ like behavior. 76 bool CCCIsCXX : 1; 77 78 /// Echo commands while executing (in -v style). 79 bool CCCEcho : 1; 80 81 /// Don't use clang for any tasks. 82 bool CCCNoClang : 1; 83 84 /// Don't use clang for handling C++ and Objective-C++ inputs. 85 bool CCCNoClangCXX : 1; 86 87 /// Don't use clang as a preprocessor (clang's preprocessor will 88 /// still be used where an integrated CPP would). 89 bool CCCNoClangCPP : 1; 90 91 /// Only use clang for the given architectures. Only used when 92 /// non-empty. 93 std::set<std::string> CCCClangArchs; 94 95 /// Certain options suppress the 'no input files' warning. 96 bool SuppressMissingInputWarning : 1; 97 98 std::list<std::string> TempFiles; 99 std::list<std::string> ResultFiles; 100 101public: 102 Driver(const char *_Name, const char *_Dir, 103 const char *_DefaultHostTriple, 104 const char *_DefaultImageName, 105 Diagnostic &_Diags); 106 ~Driver(); 107 108 /// @name Accessors 109 /// @{ 110 111 const OptTable &getOpts() const { return *Opts; } 112 113 /// @} 114 /// @name Primary Functionality 115 /// @{ 116 117 /// BuildCompilation - Construct a compilation object for a command 118 /// line argument vector. 119 /// 120 /// \return A compilation, or 0 if none was built for the given 121 /// argument vector. A null return value does not necessarily 122 /// indicate an error condition, the diagnostics should be queried 123 /// to determine if an error occurred. 124 Compilation *BuildCompilation(int argc, const char **argv); 125 126 /// @name Driver Steps 127 /// @{ 128 129 /// ParseArgStrings - Parse the given list of strings into an 130 /// ArgList. 131 ArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd); 132 133 /// BuildActions - Construct the list of actions to perform for the 134 /// given arguments, which are only done for a single architecture. 135 /// 136 /// \param Args - The input arguments. 137 /// \param Actions - The list to store the resulting actions onto. 138 void BuildActions(ArgList &Args, ActionList &Actions) const; 139 140 /// BuildUniversalActions - Construct the list of actions to perform 141 /// for the given arguments, which may require a universal build. 142 /// 143 /// \param Args - The input arguments. 144 /// \param Actions - The list to store the resulting actions onto. 145 void BuildUniversalActions(ArgList &Args, ActionList &Actions) const; 146 147 /// BuildJobs - Bind actions to concrete tools and translate 148 /// arguments to form the list of jobs to run. 149 /// 150 /// \arg C - The compilation that is being built. 151 void BuildJobs(Compilation &C, const ActionList &Actions) const; 152 153 /// @} 154 /// @name Helper Methods 155 /// @{ 156 157 /// PrintOptions - Print the list of arguments. 158 void PrintOptions(const ArgList &Args) const; 159 160 /// PrintVersion - Print the driver version. 161 void PrintVersion() const; 162 163 /// PrintActions - Print the list of actions. 164 void PrintActions(const ArgList &Args, const ActionList &Actions) const; 165 166 /// GetFilePath - Lookup \arg Name in the list of file search paths. 167 /// 168 /// \arg TC - Use the provided tool chain for additional information 169 /// on directories to search, or the DefaultToolChain if not 170 /// provided. 171 // FIXME: This should be in CompilationInfo. 172 llvm::sys::Path GetFilePath(const char *Name, const ToolChain *TC=0) const; 173 174 /// GetProgramPath - Lookup \arg Name in the list of program search 175 /// paths. 176 /// 177 /// \arg TC - Use the provided tool chain for additional information 178 /// on directories to search, or the DefaultToolChain if not 179 /// provided. 180 // FIXME: This should be in CompilationInfo. 181 llvm::sys::Path GetProgramPath(const char *Name, const ToolChain *TC=0) const; 182 183 /// HandleImmediateArgs - Handle any arguments which should be 184 /// treated before building actions or binding tools. 185 /// 186 /// \return Whether any compilation should be built for this 187 /// invocation. 188 bool HandleImmediateArgs(const ArgList &Args); 189 190 /// ConstructAction - Construct the appropriate action to do for 191 /// \arg Phase on the \arg Input, taking in to account arguments 192 /// like -fsyntax-only or --analyze. 193 Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase, 194 Action *Input) const; 195 196 197 /// BuildJobsForAction - Construct the jobs to perform for the 198 /// action \arg A. 199 void BuildJobsForAction(Compilation &C, 200 const Action *A, 201 const ToolChain *TC, 202 bool CanAcceptPipe, 203 bool AtTopLevel, 204 const char *LinkingOutput, 205 InputInfo &Result) const; 206 207 /// GetNamedOutputPath - Return the name to use for the output of 208 /// the action \arg JA. The result is appended to the compilation's 209 /// list of temporary or result files, as appropriate. 210 /// 211 /// \param C - The compilation. 212 /// \param JA - The action of interest. 213 /// \param BaseInput - The original input file that this action was 214 /// triggered by. 215 /// \param AtTopLevel - Whether this is a "top-level" action. 216 const char *GetNamedOutputPath(Compilation &C, 217 const JobAction &JA, 218 const char *BaseInput, 219 bool AtTopLevel) const; 220 221 /// GetHostInfo - Construct a new host info object for the given 222 /// host triple. 223 const HostInfo *GetHostInfo(const char *HostTriple) const; 224 225 /// @} 226}; 227 228} // end namespace driver 229} // end namespace clang 230 231#endif 232