Driver.h revision 586dc233bb88f2920c9f3638f69cef0ccd55dced
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 OptTable; 31 class ToolChain; 32 33/// Driver - Encapsulate logic for constructing compilation processes 34/// from a set of gcc-driver-like command line arguments. 35class Driver { 36 OptTable *Opts; 37 38 Diagnostic &Diags; 39 40 // Diag - Forwarding function for diagnostics. 41 DiagnosticBuilder Diag(unsigned DiagID) const { 42 return Diags.Report(FullSourceLoc(), DiagID); 43 } 44 45 // FIXME: Privatize once interface is stable. 46public: 47 /// The name the driver was invoked as. 48 std::string Name; 49 50 /// The path the driver executable was in, as invoked from the 51 /// command line. 52 std::string Dir; 53 54 /// Default host triple. 55 std::string DefaultHostTriple; 56 57 /// Host information for the platform the driver is running as. This 58 /// will generally be the actual host platform, but not always. 59 HostInfo *Host; 60 61 /// The default tool chain for this host. 62 // FIXME: This shouldn't be here; this should be in a 63 // CompilationInfo structure. 64 ToolChain *DefaultToolChain; 65 66 /// Information about the host which can be overriden by the user. 67 std::string HostBits, HostMachine, HostSystem, HostRelease; 68 69 /// Whether the driver should follow g++ like behavior. 70 bool CCCIsCXX : 1; 71 72 /// Echo commands while executing (in -v style). 73 bool CCCEcho : 1; 74 75 /// Don't use clang for any tasks. 76 bool CCCNoClang : 1; 77 78 /// Don't use clang for handling C++ and Objective-C++ inputs. 79 bool CCCNoClangCXX : 1; 80 81 /// Don't use clang as a preprocessor (clang's preprocessor will 82 /// still be used where an integrated CPP would). 83 bool CCCNoClangCPP : 1; 84 85 /// Only use clang for the given architectures. Only used when 86 /// non-empty. 87 std::set<std::string> CCCClangArchs; 88 89 /// Certain options suppress the 'no input files' warning. 90 bool SuppressMissingInputWarning : 1; 91 92 std::list<std::string> TempFiles; 93 std::list<std::string> ResultFiles; 94 95public: 96 Driver(const char *_Name, const char *_Dir, 97 const char *_DefaultHostTriple, 98 Diagnostic &_Diags); 99 ~Driver(); 100 101 /// @name Accessors 102 /// @{ 103 104 const OptTable &getOpts() const { return *Opts; } 105 106 /// @} 107 /// @name Primary Functionality 108 /// @{ 109 110 /// BuildCompilation - Construct a compilation object for a command 111 /// line argument vector. 112 /// 113 /// \return A compilation, or 0 if none was built for the given 114 /// argument vector. A null return value does not necessarily 115 /// indicate an error condition, the diagnostics should be queried 116 /// to determine if an error occurred. 117 Compilation *BuildCompilation(int argc, const char **argv); 118 119 /// @name Driver Steps 120 /// @{ 121 122 /// ParseArgStrings - Parse the given list of strings into an 123 /// ArgList. 124 ArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd); 125 126 /// BuildActions - Construct the list of actions to perform for the 127 /// given arguments, which are only done for a single architecture. 128 /// 129 /// \param Args - The input arguments. 130 /// \param Actions - The list to store the resulting actions onto. 131 void BuildActions(ArgList &Args, ActionList &Actions) const; 132 133 /// BuildUniversalActions - Construct the list of actions to perform 134 /// for the given arguments, which may require a universal build. 135 /// 136 /// \param Args - The input arguments. 137 /// \param Actions - The list to store the resulting actions onto. 138 void BuildUniversalActions(ArgList &Args, ActionList &Actions) const; 139 140 /// BuildJobs - Bind actions to concrete tools and translate 141 /// arguments to form the list of jobs to run. 142 /// 143 /// \arg C - The compilation that is being built. 144 void BuildJobs(Compilation &C, const ActionList &Actions) const; 145 146 /// @} 147 /// @name Helper Methods 148 /// @{ 149 150 /// PrintOptions - Print the list of arguments. 151 void PrintOptions(const ArgList &Args) const; 152 153 /// PrintVersion - Print the driver version. 154 void PrintVersion() const; 155 156 /// PrintActions - Print the list of actions. 157 void PrintActions(const ArgList &Args, const ActionList &Actions) const; 158 159 /// GetFilePath - Lookup \arg Name in the list of file search paths. 160 /// 161 /// \arg TC - Use the provided tool chain for additional information 162 /// on directories to search, or the DefaultToolChain if not 163 /// provided. 164 // FIXME: This should be in CompilationInfo. 165 llvm::sys::Path GetFilePath(const char *Name, const ToolChain *TC=0) const; 166 167 /// GetProgramPath - Lookup \arg Name in the list of program search 168 /// paths. 169 /// 170 /// \arg TC - Use the provided tool chain for additional information 171 /// on directories to search, or the DefaultToolChain if not 172 /// provided. 173 // FIXME: This should be in CompilationInfo. 174 llvm::sys::Path GetProgramPath(const char *Name, const ToolChain *TC=0) const; 175 176 /// HandleImmediateArgs - Handle any arguments which should be 177 /// treated before building actions or binding tools. 178 /// 179 /// \return Whether any compilation should be built for this 180 /// invocation. 181 bool HandleImmediateArgs(const ArgList &Args); 182 183 /// ConstructAction - Construct the appropriate action to do for 184 /// \arg Phase on the \arg Input, taking in to account arguments 185 /// like -fsyntax-only or --analyze. 186 Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase, 187 Action *Input) const; 188 189 /// GetHostInfo - Construct a new host info object for the given 190 /// host triple. 191 static HostInfo *GetHostInfo(const char *HostTriple); 192 193 /// @} 194}; 195 196} // end namespace driver 197} // end namespace clang 198 199#endif 200