Driver.h revision 0f99d2e57d8e3cf2508e7f9f868d41eccdc229c9
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 43public: 44 // Diag - Forwarding function for diagnostics. 45 DiagnosticBuilder Diag(unsigned DiagID) const { 46 return Diags.Report(FullSourceLoc(), DiagID); 47 } 48 49 // FIXME: Privatize once interface is stable. 50public: 51 /// The name the driver was invoked as. 52 std::string Name; 53 54 /// The path the driver executable was in, as invoked from the 55 /// command line. 56 std::string Dir; 57 58 /// Default host triple. 59 std::string DefaultHostTriple; 60 61 /// Default name for linked images (e.g., "a.out"). 62 std::string DefaultImageName; 63 64 /// Host information for the platform the driver is running as. This 65 /// will generally be the actual host platform, but not always. 66 const HostInfo *Host; 67 68 /// Information about the host which can be overriden by the user. 69 std::string HostBits, HostMachine, HostSystem, HostRelease; 70 71 /// Whether the driver should follow g++ like behavior. 72 bool CCCIsCXX : 1; 73 74 /// Echo commands while executing (in -v style). 75 bool CCCEcho : 1; 76 77 /// Only print tool bindings, don't build any jobs. 78 bool CCCPrintBindings : 1; 79 80private: 81 /// Use the clang compiler where possible. 82 bool CCCUseClang : 1; 83 84 /// Use clang for handling C++ and Objective-C++ inputs. 85 bool CCCUseClangCXX : 1; 86 87 /// Use clang as a preprocessor (clang's preprocessor will still be 88 /// used where an integrated CPP would). 89 bool CCCUseClangCPP : 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 const Diagnostic &getDiags() const { return Diags; } 114 115 /// @} 116 /// @name Primary Functionality 117 /// @{ 118 119 /// BuildCompilation - Construct a compilation object for a command 120 /// line argument vector. 121 /// 122 /// \return A compilation, or 0 if none was built for the given 123 /// argument vector. A null return value does not necessarily 124 /// indicate an error condition, the diagnostics should be queried 125 /// to determine if an error occurred. 126 Compilation *BuildCompilation(int argc, const char **argv); 127 128 /// @name Driver Steps 129 /// @{ 130 131 /// ParseArgStrings - Parse the given list of strings into an 132 /// ArgList. 133 ArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd); 134 135 /// BuildActions - Construct the list of actions to perform for the 136 /// given arguments, which are only done for a single architecture. 137 /// 138 /// \param Args - The input arguments. 139 /// \param Actions - The list to store the resulting actions onto. 140 void BuildActions(const ArgList &Args, ActionList &Actions) const; 141 142 /// BuildUniversalActions - Construct the list of actions to perform 143 /// for the given arguments, which may require a universal build. 144 /// 145 /// \param Args - The input arguments. 146 /// \param Actions - The list to store the resulting actions onto. 147 void BuildUniversalActions(const ArgList &Args, ActionList &Actions) const; 148 149 /// BuildJobs - Bind actions to concrete tools and translate 150 /// arguments to form the list of jobs to run. 151 /// 152 /// \arg C - The compilation that is being built. 153 void BuildJobs(Compilation &C) const; 154 155 /// @} 156 /// @name Helper Methods 157 /// @{ 158 159 /// PrintOptions - Print the list of arguments. 160 void PrintOptions(const ArgList &Args) const; 161 162 /// PrintVersion - Print the driver version. 163 void PrintVersion() const; 164 165 /// PrintActions - Print the list of actions. 166 void PrintActions(const Compilation &C) const; 167 168 /// GetFilePath - Lookup \arg Name in the list of file search paths. 169 /// 170 /// \arg TC - The tool chain for additional information on 171 /// directories to search. 172 // FIXME: This should be in CompilationInfo. 173 llvm::sys::Path GetFilePath(const char *Name, const ToolChain &TC) const; 174 175 /// GetProgramPath - Lookup \arg Name in the list of program search 176 /// paths. 177 /// 178 /// \arg TC - The provided tool chain for additional information on 179 /// directories to search. 180 // FIXME: This should be in CompilationInfo. 181 llvm::sys::Path GetProgramPath(const char *Name, const ToolChain &TC) 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 Compilation &C); 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 /// GetTemporaryPath - Return the pathname of a temporary file to 222 /// use as part of compilation; the file will have the given suffix. 223 /// 224 /// GCC goes to extra lengths here to be a bit more robust. 225 std::string GetTemporaryPath(const char *Suffix) const; 226 227 /// GetHostInfo - Construct a new host info object for the given 228 /// host triple. 229 const HostInfo *GetHostInfo(const char *HostTriple) const; 230 231 /// ShouldUseClangCompilar - Should the clang compiler be used to 232 /// handle this action. 233 bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, 234 const std::string &ArchName) const; 235 236 /// @} 237}; 238 239} // end namespace driver 240} // end namespace clang 241 242#endif 243