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