Driver.h revision 21549237f14505cfc2a18a06416372a36229d0ce
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 /// Only print tool bindings, don't build any jobs. 82 bool CCCPrintBindings : 1; 83 84 /// Don't use clang for any tasks. 85 bool CCCNoClang : 1; 86 87 /// Don't use clang for handling C++ and Objective-C++ inputs. 88 bool CCCNoClangCXX : 1; 89 90 /// Don't use clang as a preprocessor (clang's preprocessor will 91 /// still be used where an integrated CPP would). 92 bool CCCNoClangCPP : 1; 93 94 /// Only use clang for the given architectures. Only used when 95 /// non-empty. 96 std::set<std::string> CCCClangArchs; 97 98 /// Certain options suppress the 'no input files' warning. 99 bool SuppressMissingInputWarning : 1; 100 101 std::list<std::string> TempFiles; 102 std::list<std::string> ResultFiles; 103 104public: 105 Driver(const char *_Name, const char *_Dir, 106 const char *_DefaultHostTriple, 107 const char *_DefaultImageName, 108 Diagnostic &_Diags); 109 ~Driver(); 110 111 /// @name Accessors 112 /// @{ 113 114 const OptTable &getOpts() const { return *Opts; } 115 116 /// @} 117 /// @name Primary Functionality 118 /// @{ 119 120 /// BuildCompilation - Construct a compilation object for a command 121 /// line argument vector. 122 /// 123 /// \return A compilation, or 0 if none was built for the given 124 /// argument vector. A null return value does not necessarily 125 /// indicate an error condition, the diagnostics should be queried 126 /// to determine if an error occurred. 127 Compilation *BuildCompilation(int argc, const char **argv); 128 129 /// @name Driver Steps 130 /// @{ 131 132 /// ParseArgStrings - Parse the given list of strings into an 133 /// ArgList. 134 ArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd); 135 136 /// BuildActions - Construct the list of actions to perform for the 137 /// given arguments, which are only done for a single architecture. 138 /// 139 /// \param Args - The input arguments. 140 /// \param Actions - The list to store the resulting actions onto. 141 void BuildActions(const ArgList &Args, ActionList &Actions) const; 142 143 /// BuildUniversalActions - Construct the list of actions to perform 144 /// for the given arguments, which may require a universal build. 145 /// 146 /// \param Args - The input arguments. 147 /// \param Actions - The list to store the resulting actions onto. 148 /// \param DefaultArchName - The default arch name (required to know 149 /// what architecture to bind if no -arch options are present). 150 151 void BuildUniversalActions(const ArgList &Args, ActionList &Actions, 152 const char *DefaultArchName) const; 153 154 /// BuildJobs - Bind actions to concrete tools and translate 155 /// arguments to form the list of jobs to run. 156 /// 157 /// \arg C - The compilation that is being built. 158 void BuildJobs(Compilation &C) const; 159 160 /// @} 161 /// @name Helper Methods 162 /// @{ 163 164 /// PrintOptions - Print the list of arguments. 165 void PrintOptions(const ArgList &Args) const; 166 167 /// PrintVersion - Print the driver version. 168 void PrintVersion() const; 169 170 /// PrintActions - Print the list of actions. 171 void PrintActions(const ArgList &Args, const ActionList &Actions) const; 172 173 /// GetFilePath - Lookup \arg Name in the list of file search paths. 174 /// 175 /// \arg TC - The tool chain for additional information on 176 /// directories to search. 177 // FIXME: This should be in CompilationInfo. 178 llvm::sys::Path GetFilePath(const char *Name, const ToolChain &TC) const; 179 180 /// GetProgramPath - Lookup \arg Name in the list of program search 181 /// paths. 182 /// 183 /// \arg TC - The provided tool chain for additional information on 184 /// directories to search. 185 // FIXME: This should be in CompilationInfo. 186 llvm::sys::Path GetProgramPath(const char *Name, const ToolChain &TC) const; 187 188 /// HandleImmediateArgs - Handle any arguments which should be 189 /// treated before building actions or binding tools. 190 /// 191 /// \return Whether any compilation should be built for this 192 /// invocation. 193 bool HandleImmediateArgs(const Compilation &C); 194 195 /// ConstructAction - Construct the appropriate action to do for 196 /// \arg Phase on the \arg Input, taking in to account arguments 197 /// like -fsyntax-only or --analyze. 198 Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase, 199 Action *Input) const; 200 201 202 /// BuildJobsForAction - Construct the jobs to perform for the 203 /// action \arg A. 204 void BuildJobsForAction(Compilation &C, 205 const Action *A, 206 const ToolChain *TC, 207 bool CanAcceptPipe, 208 bool AtTopLevel, 209 const char *LinkingOutput, 210 InputInfo &Result) const; 211 212 /// GetNamedOutputPath - Return the name to use for the output of 213 /// the action \arg JA. The result is appended to the compilation's 214 /// list of temporary or result files, as appropriate. 215 /// 216 /// \param C - The compilation. 217 /// \param JA - The action of interest. 218 /// \param BaseInput - The original input file that this action was 219 /// triggered by. 220 /// \param AtTopLevel - Whether this is a "top-level" action. 221 const char *GetNamedOutputPath(Compilation &C, 222 const JobAction &JA, 223 const char *BaseInput, 224 bool AtTopLevel) const; 225 226 /// GetHostInfo - Construct a new host info object for the given 227 /// host triple. 228 const HostInfo *GetHostInfo(const char *HostTriple) const; 229 230 /// @} 231}; 232 233} // end namespace driver 234} // end namespace clang 235 236#endif 237