Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 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 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 10 | #ifndef LLVM_CLANG_DRIVER_DRIVER_H |
| 11 | #define LLVM_CLANG_DRIVER_DRIVER_H |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 12 | |
Daniel Dunbar | 4ad4b3e | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 13 | #include "clang/Basic/Diagnostic.h" |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 14 | #include "clang/Basic/LLVM.h" |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Phases.h" |
Chad Rosier | be69f60 | 2011-08-12 22:08:57 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Types.h" |
Daniel Dunbar | d65bddc | 2009-03-12 18:24:49 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Util.h" |
Chandler Carruth | 18d7f3a | 2012-01-25 11:01:57 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringMap.h" |
Jeffrey Yasskin | e3fdca2 | 2009-12-08 01:46:24 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringRef.h" |
Daniel Dunbar | a6046be | 2009-09-08 23:36:55 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Triple.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Path.h" // FIXME: Kill when CompilationInfo |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 22 | #include <memory> |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 23 | // lands. |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 24 | #include <list> |
| 25 | #include <set> |
| 26 | #include <string> |
| 27 | |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 28 | namespace llvm { |
| 29 | namespace opt { |
Chad Rosier | 1fc1de4 | 2011-07-27 23:36:45 +0000 | [diff] [blame] | 30 | class Arg; |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame] | 31 | class ArgList; |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 32 | class DerivedArgList; |
Daniel Dunbar | f3cad36 | 2009-03-25 04:13:45 +0000 | [diff] [blame] | 33 | class InputArgList; |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 34 | class OptTable; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | namespace clang { |
| 39 | namespace driver { |
Reid Kleckner | b1e25a1 | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 40 | |
| 41 | class Action; |
| 42 | class Command; |
| 43 | class Compilation; |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 44 | class InputInfo; |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 45 | class Job; |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 46 | class JobAction; |
Alexey Samsonov | 1b8f12d | 2013-08-19 09:14:21 +0000 | [diff] [blame] | 47 | class SanitizerArgs; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 48 | class ToolChain; |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 49 | |
| 50 | /// Driver - Encapsulate logic for constructing compilation processes |
| 51 | /// from a set of gcc-driver-like command line arguments. |
| 52 | class Driver { |
Reid Kleckner | dd0b3c4 | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 53 | llvm::opt::OptTable *Opts; |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 54 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 55 | DiagnosticsEngine &Diags; |
Daniel Dunbar | 4ad4b3e | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 56 | |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 57 | enum DriverMode { |
| 58 | GCCMode, |
| 59 | GXXMode, |
Hans Wennborg | c2f531a | 2013-07-19 20:33:20 +0000 | [diff] [blame] | 60 | CPPMode, |
| 61 | CLMode |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 62 | } Mode; |
| 63 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 64 | enum SaveTempsMode { |
| 65 | SaveTempsNone, |
| 66 | SaveTempsCwd, |
| 67 | SaveTempsObj |
| 68 | } SaveTemps; |
| 69 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 70 | public: |
Daniel Dunbar | 4ad4b3e | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 71 | // Diag - Forwarding function for diagnostics. |
Daniel Dunbar | 57b704d | 2009-03-13 22:12:33 +0000 | [diff] [blame] | 72 | DiagnosticBuilder Diag(unsigned DiagID) const { |
Daniel Dunbar | 0f9fed7 | 2009-11-10 23:55:23 +0000 | [diff] [blame] | 73 | return Diags.Report(DiagID); |
Daniel Dunbar | 4ad4b3e | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 76 | // FIXME: Privatize once interface is stable. |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 77 | public: |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 78 | /// The name the driver was invoked as. |
| 79 | std::string Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 81 | /// The path the driver executable was in, as invoked from the |
| 82 | /// command line. |
| 83 | std::string Dir; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | |
Daniel Dunbar | b9a8226 | 2010-07-14 18:46:27 +0000 | [diff] [blame] | 85 | /// The original path to the clang executable. |
| 86 | std::string ClangExecutable; |
| 87 | |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 88 | /// The path to the installed clang directory, if any. |
| 89 | std::string InstalledDir; |
| 90 | |
Daniel Dunbar | 225c417 | 2010-01-20 02:35:16 +0000 | [diff] [blame] | 91 | /// The path to the compiler resource directory. |
| 92 | std::string ResourceDir; |
| 93 | |
Chandler Carruth | 48ad609 | 2010-03-22 01:52:07 +0000 | [diff] [blame] | 94 | /// A prefix directory used to emulated a limited subset of GCC's '-Bprefix' |
| 95 | /// functionality. |
| 96 | /// FIXME: This type of customization should be removed in favor of the |
| 97 | /// universal driver when it is ready. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 98 | typedef SmallVector<std::string, 4> prefix_list; |
Benjamin Kramer | 09982ce | 2011-02-08 20:31:42 +0000 | [diff] [blame] | 99 | prefix_list PrefixDirs; |
Chandler Carruth | 48ad609 | 2010-03-22 01:52:07 +0000 | [diff] [blame] | 100 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 101 | /// sysroot, if present |
| 102 | std::string SysRoot; |
| 103 | |
Peter Collingbourne | bdaa134 | 2013-05-27 21:40:20 +0000 | [diff] [blame] | 104 | /// Dynamic loader prefix, if present |
| 105 | std::string DyldPrefix; |
| 106 | |
Joerg Sonnenberger | 05e5930 | 2011-03-21 13:59:26 +0000 | [diff] [blame] | 107 | /// If the standard library is used |
| 108 | bool UseStdLib; |
| 109 | |
Sebastian Pop | 9606a57 | 2012-01-13 20:36:46 +0000 | [diff] [blame] | 110 | /// Default target triple. |
| 111 | std::string DefaultTargetTriple; |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 112 | |
Daniel Dunbar | 43302d4 | 2010-02-25 03:31:53 +0000 | [diff] [blame] | 113 | /// Driver title to use with help. |
| 114 | std::string DriverTitle; |
| 115 | |
Michael J. Spencer | 4c8acc9 | 2011-04-05 17:57:51 +0000 | [diff] [blame] | 116 | /// Information about the host which can be overridden by the user. |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 117 | std::string HostBits, HostMachine, HostSystem, HostRelease; |
| 118 | |
Daniel Dunbar | 4c00fcd | 2010-03-20 08:01:59 +0000 | [diff] [blame] | 119 | /// The file to log CC_PRINT_OPTIONS output to, if enabled. |
| 120 | const char *CCPrintOptionsFilename; |
| 121 | |
Daniel Dunbar | 322c29f | 2011-02-02 21:11:35 +0000 | [diff] [blame] | 122 | /// The file to log CC_PRINT_HEADERS output to, if enabled. |
| 123 | const char *CCPrintHeadersFilename; |
| 124 | |
Daniel Dunbar | c8a22b0 | 2011-04-07 18:01:20 +0000 | [diff] [blame] | 125 | /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled. |
| 126 | const char *CCLogDiagnosticsFilename; |
| 127 | |
Chad Rosier | be69f60 | 2011-08-12 22:08:57 +0000 | [diff] [blame] | 128 | /// A list of inputs and their types for the given arguments. |
Reid Kleckner | dd0b3c4 | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 129 | typedef SmallVector<std::pair<types::ID, const llvm::opt::Arg *>, 16> |
| 130 | InputList; |
Chad Rosier | be69f60 | 2011-08-12 22:08:57 +0000 | [diff] [blame] | 131 | |
Daniel Dunbar | 3bd54cc | 2010-01-25 00:44:02 +0000 | [diff] [blame] | 132 | /// Whether the driver should follow g++ like behavior. |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 133 | bool CCCIsCXX() const { return Mode == GXXMode; } |
Daniel Dunbar | 3bd54cc | 2010-01-25 00:44:02 +0000 | [diff] [blame] | 134 | |
Chad Rosier | e5de376 | 2012-03-06 23:19:26 +0000 | [diff] [blame] | 135 | /// Whether the driver is just the preprocessor. |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 136 | bool CCCIsCPP() const { return Mode == CPPMode; } |
Joerg Sonnenberger | 9ade4ae | 2011-03-06 23:31:01 +0000 | [diff] [blame] | 137 | |
Hans Wennborg | 909930f | 2013-08-07 00:32:15 +0000 | [diff] [blame] | 138 | /// Whether the driver should follow cl.exe like behavior. |
| 139 | bool IsCLMode() const { return Mode == CLMode; } |
| 140 | |
Daniel Dunbar | 3bd54cc | 2010-01-25 00:44:02 +0000 | [diff] [blame] | 141 | /// Only print tool bindings, don't build any jobs. |
| 142 | unsigned CCCPrintBindings : 1; |
| 143 | |
Daniel Dunbar | 4c00fcd | 2010-03-20 08:01:59 +0000 | [diff] [blame] | 144 | /// Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to |
| 145 | /// CCPrintOptionsFilename or to stderr. |
| 146 | unsigned CCPrintOptions : 1; |
| 147 | |
Daniel Dunbar | 322c29f | 2011-02-02 21:11:35 +0000 | [diff] [blame] | 148 | /// Set CC_PRINT_HEADERS mode, which causes the frontend to log header include |
| 149 | /// information to CCPrintHeadersFilename or to stderr. |
| 150 | unsigned CCPrintHeaders : 1; |
| 151 | |
Daniel Dunbar | c8a22b0 | 2011-04-07 18:01:20 +0000 | [diff] [blame] | 152 | /// Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics |
| 153 | /// to CCLogDiagnosticsFilename or to stderr, in a stable machine readable |
| 154 | /// format. |
| 155 | unsigned CCLogDiagnostics : 1; |
| 156 | |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 157 | /// Whether the driver is generating diagnostics for debugging purposes. |
| 158 | unsigned CCGenDiagnostics : 1; |
| 159 | |
Daniel Dunbar | af80e1f | 2009-03-24 18:57:02 +0000 | [diff] [blame] | 160 | private: |
Dylan Noblesmith | b8a3e81 | 2011-04-09 13:31:59 +0000 | [diff] [blame] | 161 | /// Name to use when invoking gcc/g++. |
Rafael Espindola | 79e9e9d | 2010-09-06 02:36:23 +0000 | [diff] [blame] | 162 | std::string CCCGenericGCCName; |
| 163 | |
Daniel Dunbar | 3bd54cc | 2010-01-25 00:44:02 +0000 | [diff] [blame] | 164 | /// Whether to check that input files exist when constructing compilation |
| 165 | /// jobs. |
| 166 | unsigned CheckInputsExist : 1; |
| 167 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 168 | public: |
| 169 | /// Use lazy precompiled headers for PCH support. |
Daniel Dunbar | 3bd54cc | 2010-01-25 00:44:02 +0000 | [diff] [blame] | 170 | unsigned CCCUsePCH : 1; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 171 | |
| 172 | private: |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 173 | /// Certain options suppress the 'no input files' warning. |
| 174 | bool SuppressMissingInputWarning : 1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 176 | std::list<std::string> TempFiles; |
| 177 | std::list<std::string> ResultFiles; |
| 178 | |
Chandler Carruth | 18d7f3a | 2012-01-25 11:01:57 +0000 | [diff] [blame] | 179 | /// \brief Cache of all the ToolChains in use by the driver. |
| 180 | /// |
| 181 | /// This maps from the string representation of a triple to a ToolChain |
Benjamin Kramer | 48d798c | 2012-06-02 10:20:41 +0000 | [diff] [blame] | 182 | /// created targeting that triple. The driver owns all the ToolChain objects |
Chandler Carruth | 18d7f3a | 2012-01-25 11:01:57 +0000 | [diff] [blame] | 183 | /// stored in it, and will clean them up when torn down. |
| 184 | mutable llvm::StringMap<ToolChain *> ToolChains; |
| 185 | |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 186 | private: |
| 187 | /// TranslateInputArgs - Create a new derived argument list from the input |
| 188 | /// arguments, after applying the standard argument translations. |
Reid Kleckner | dd0b3c4 | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 189 | llvm::opt::DerivedArgList * |
| 190 | TranslateInputArgs(const llvm::opt::InputArgList &Args) const; |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 191 | |
Chad Rosier | 1fc1de4 | 2011-07-27 23:36:45 +0000 | [diff] [blame] | 192 | // getFinalPhase - Determine which compilation mode we are in and record |
| 193 | // which option we used to determine the final phase. |
Reid Kleckner | dd0b3c4 | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 194 | phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL, |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 195 | llvm::opt::Arg **FinalPhaseArg = nullptr) const; |
Chad Rosier | 1fc1de4 | 2011-07-27 23:36:45 +0000 | [diff] [blame] | 196 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 197 | // Before executing jobs, sets up response files for commands that need them. |
| 198 | void setUpResponseFiles(Compilation &C, Job &J); |
| 199 | |
| 200 | void generatePrefixedToolNames(const char *Tool, const ToolChain &TC, |
| 201 | SmallVectorImpl<std::string> &Names) const; |
| 202 | |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 203 | public: |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 204 | Driver(StringRef _ClangExecutable, |
Sebastian Pop | 9606a57 | 2012-01-13 20:36:46 +0000 | [diff] [blame] | 205 | StringRef _DefaultTargetTriple, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 206 | DiagnosticsEngine &_Diags); |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 207 | ~Driver(); |
| 208 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 209 | /// @name Accessors |
| 210 | /// @{ |
| 211 | |
Dylan Noblesmith | b8a3e81 | 2011-04-09 13:31:59 +0000 | [diff] [blame] | 212 | /// Name to use when invoking gcc/g++. |
Rafael Espindola | 79e9e9d | 2010-09-06 02:36:23 +0000 | [diff] [blame] | 213 | const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; } |
| 214 | |
Reid Kleckner | dd0b3c4 | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 215 | const llvm::opt::OptTable &getOpts() const { return *Opts; } |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 216 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 217 | const DiagnosticsEngine &getDiags() const { return Diags; } |
Daniel Dunbar | af96def | 2009-03-21 00:40:53 +0000 | [diff] [blame] | 218 | |
Daniel Dunbar | 3bd54cc | 2010-01-25 00:44:02 +0000 | [diff] [blame] | 219 | bool getCheckInputsExist() const { return CheckInputsExist; } |
| 220 | |
| 221 | void setCheckInputsExist(bool Value) { CheckInputsExist = Value; } |
| 222 | |
Daniel Dunbar | 43302d4 | 2010-02-25 03:31:53 +0000 | [diff] [blame] | 223 | const std::string &getTitle() { return DriverTitle; } |
| 224 | void setTitle(std::string Value) { DriverTitle = Value; } |
| 225 | |
Daniel Dunbar | b9a8226 | 2010-07-14 18:46:27 +0000 | [diff] [blame] | 226 | /// \brief Get the path to the main clang executable. |
Daniel Dunbar | a001c1c | 2010-07-18 21:16:15 +0000 | [diff] [blame] | 227 | const char *getClangProgramPath() const { |
| 228 | return ClangExecutable.c_str(); |
Daniel Dunbar | b9a8226 | 2010-07-14 18:46:27 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 231 | /// \brief Get the path to where the clang executable was installed. |
| 232 | const char *getInstalledDir() const { |
| 233 | if (!InstalledDir.empty()) |
| 234 | return InstalledDir.c_str(); |
| 235 | return Dir.c_str(); |
| 236 | } |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 237 | void setInstalledDir(StringRef Value) { |
Daniel Dunbar | edf29b0 | 2010-08-01 22:29:51 +0000 | [diff] [blame] | 238 | InstalledDir = Value; |
| 239 | } |
| 240 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 241 | bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; } |
| 242 | bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; } |
| 243 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 244 | /// @} |
| 245 | /// @name Primary Functionality |
| 246 | /// @{ |
| 247 | |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 248 | /// BuildCompilation - Construct a compilation object for a command |
| 249 | /// line argument vector. |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 250 | /// |
| 251 | /// \return A compilation, or 0 if none was built for the given |
| 252 | /// argument vector. A null return value does not necessarily |
| 253 | /// indicate an error condition, the diagnostics should be queried |
| 254 | /// to determine if an error occurred. |
Chris Lattner | 2d3ba4f | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 255 | Compilation *BuildCompilation(ArrayRef<const char *> Args); |
Daniel Dunbar | 365c02f | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 256 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 257 | /// @name Driver Steps |
| 258 | /// @{ |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 259 | |
Hans Wennborg | 76b86c2 | 2013-07-18 20:29:38 +0000 | [diff] [blame] | 260 | /// ParseDriverMode - Look for and handle the driver mode option in Args. |
| 261 | void ParseDriverMode(ArrayRef<const char *> Args); |
| 262 | |
Daniel Dunbar | 57b704d | 2009-03-13 22:12:33 +0000 | [diff] [blame] | 263 | /// ParseArgStrings - Parse the given list of strings into an |
| 264 | /// ArgList. |
Reid Kleckner | dd0b3c4 | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 265 | llvm::opt::InputArgList *ParseArgStrings(ArrayRef<const char *> Args); |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 266 | |
Chad Rosier | be69f60 | 2011-08-12 22:08:57 +0000 | [diff] [blame] | 267 | /// BuildInputs - Construct the list of inputs and their types from |
| 268 | /// the given arguments. |
| 269 | /// |
| 270 | /// \param TC - The default host tool chain. |
| 271 | /// \param Args - The input arguments. |
| 272 | /// \param Inputs - The list to store the resulting compilation |
| 273 | /// inputs onto. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 274 | void BuildInputs(const ToolChain &TC, llvm::opt::DerivedArgList &Args, |
Chad Rosier | be69f60 | 2011-08-12 22:08:57 +0000 | [diff] [blame] | 275 | InputList &Inputs) const; |
| 276 | |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 277 | /// BuildActions - Construct the list of actions to perform for the |
| 278 | /// given arguments, which are only done for a single architecture. |
| 279 | /// |
Daniel Dunbar | 74edcea | 2010-08-02 05:43:51 +0000 | [diff] [blame] | 280 | /// \param TC - The default host tool chain. |
Daniel Dunbar | 53ec552 | 2009-03-12 07:58:46 +0000 | [diff] [blame] | 281 | /// \param Args - The input arguments. |
| 282 | /// \param Actions - The list to store the resulting actions onto. |
Hans Wennborg | 9c0ed91 | 2013-08-12 23:26:25 +0000 | [diff] [blame] | 283 | void BuildActions(const ToolChain &TC, llvm::opt::DerivedArgList &Args, |
Chad Rosier | be69f60 | 2011-08-12 22:08:57 +0000 | [diff] [blame] | 284 | const InputList &Inputs, ActionList &Actions) const; |
Daniel Dunbar | 57b704d | 2009-03-13 22:12:33 +0000 | [diff] [blame] | 285 | |
| 286 | /// BuildUniversalActions - Construct the list of actions to perform |
| 287 | /// for the given arguments, which may require a universal build. |
| 288 | /// |
Daniel Dunbar | 74edcea | 2010-08-02 05:43:51 +0000 | [diff] [blame] | 289 | /// \param TC - The default host tool chain. |
Daniel Dunbar | 57b704d | 2009-03-13 22:12:33 +0000 | [diff] [blame] | 290 | /// \param Args - The input arguments. |
| 291 | /// \param Actions - The list to store the resulting actions onto. |
Reid Kleckner | dd0b3c4 | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 292 | void BuildUniversalActions(const ToolChain &TC, |
Hans Wennborg | 9c0ed91 | 2013-08-12 23:26:25 +0000 | [diff] [blame] | 293 | llvm::opt::DerivedArgList &Args, |
Chad Rosier | be69f60 | 2011-08-12 22:08:57 +0000 | [diff] [blame] | 294 | const InputList &BAInputs, |
Daniel Dunbar | 74edcea | 2010-08-02 05:43:51 +0000 | [diff] [blame] | 295 | ActionList &Actions) const; |
Daniel Dunbar | 57b704d | 2009-03-13 22:12:33 +0000 | [diff] [blame] | 296 | |
| 297 | /// BuildJobs - Bind actions to concrete tools and translate |
| 298 | /// arguments to form the list of jobs to run. |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 299 | /// |
Dmitri Gribenko | 1824d54 | 2012-09-13 13:11:20 +0000 | [diff] [blame] | 300 | /// \param C - The compilation that is being built. |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 301 | void BuildJobs(Compilation &C) const; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 302 | |
Daniel Dunbar | c88a88f | 2009-07-01 20:03:04 +0000 | [diff] [blame] | 303 | /// ExecuteCompilation - Execute the compilation according to the command line |
| 304 | /// arguments and return an appropriate exit code. |
| 305 | /// |
| 306 | /// This routine handles additional processing that must be done in addition |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 307 | /// to just running the subprocesses, for example reporting errors, setting |
| 308 | /// up response files, removing temporary files, etc. |
| 309 | int ExecuteCompilation(Compilation &C, |
| 310 | SmallVectorImpl< std::pair<int, const Command *> > &FailingCommands); |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 311 | |
| 312 | /// generateCompilationDiagnostics - Generate diagnostics information |
| 313 | /// including preprocessed source file(s). |
| 314 | /// |
| 315 | void generateCompilationDiagnostics(Compilation &C, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 316 | const Command &FailingCommand); |
Daniel Dunbar | c88a88f | 2009-07-01 20:03:04 +0000 | [diff] [blame] | 317 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 318 | /// @} |
| 319 | /// @name Helper Methods |
| 320 | /// @{ |
| 321 | |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 322 | /// PrintActions - Print the list of actions. |
| 323 | void PrintActions(const Compilation &C) const; |
| 324 | |
Daniel Dunbar | c35d71f | 2009-04-15 16:34:29 +0000 | [diff] [blame] | 325 | /// PrintHelp - Print the help text. |
| 326 | /// |
| 327 | /// \param ShowHidden - Show hidden options. |
| 328 | void PrintHelp(bool ShowHidden) const; |
Daniel Dunbar | 91e28af | 2009-03-31 21:38:17 +0000 | [diff] [blame] | 329 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 330 | /// PrintVersion - Print the driver version. |
Chris Lattner | 8cc488f | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 331 | void PrintVersion(const Compilation &C, raw_ostream &OS) const; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 332 | |
Dmitri Gribenko | 1824d54 | 2012-09-13 13:11:20 +0000 | [diff] [blame] | 333 | /// GetFilePath - Lookup \p Name in the list of file search paths. |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 334 | /// |
Dmitri Gribenko | 1824d54 | 2012-09-13 13:11:20 +0000 | [diff] [blame] | 335 | /// \param TC - The tool chain for additional information on |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 336 | /// directories to search. |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 337 | // |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 338 | // FIXME: This should be in CompilationInfo. |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 339 | std::string GetFilePath(const char *Name, const ToolChain &TC) const; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 340 | |
Dmitri Gribenko | 1824d54 | 2012-09-13 13:11:20 +0000 | [diff] [blame] | 341 | /// GetProgramPath - Lookup \p Name in the list of program search paths. |
Daniel Dunbar | 2ba38ba | 2009-03-16 05:25:36 +0000 | [diff] [blame] | 342 | /// |
Dmitri Gribenko | 1824d54 | 2012-09-13 13:11:20 +0000 | [diff] [blame] | 343 | /// \param TC - The provided tool chain for additional information on |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 344 | /// directories to search. |
Daniel Dunbar | 5ed34f4 | 2009-09-09 22:33:00 +0000 | [diff] [blame] | 345 | // |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 346 | // FIXME: This should be in CompilationInfo. |
Simon Atanasyan | fc44e88 | 2012-10-03 19:52:37 +0000 | [diff] [blame] | 347 | std::string GetProgramPath(const char *Name, const ToolChain &TC) const; |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 348 | |
| 349 | /// HandleImmediateArgs - Handle any arguments which should be |
| 350 | /// treated before building actions or binding tools. |
| 351 | /// |
| 352 | /// \return Whether any compilation should be built for this |
| 353 | /// invocation. |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 354 | bool HandleImmediateArgs(const Compilation &C); |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 355 | |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 356 | /// ConstructAction - Construct the appropriate action to do for |
Dmitri Gribenko | 1824d54 | 2012-09-13 13:11:20 +0000 | [diff] [blame] | 357 | /// \p Phase on the \p Input, taking in to account arguments |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 358 | /// like -fsyntax-only or --analyze. |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 359 | std::unique_ptr<Action> |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 360 | ConstructPhaseAction(const ToolChain &TC, const llvm::opt::ArgList &Args, |
| 361 | phases::ID Phase, std::unique_ptr<Action> Input) const; |
Daniel Dunbar | ad2a9af | 2009-03-13 11:38:42 +0000 | [diff] [blame] | 362 | |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 363 | /// BuildJobsForAction - Construct the jobs to perform for the |
Dmitri Gribenko | 1824d54 | 2012-09-13 13:11:20 +0000 | [diff] [blame] | 364 | /// action \p A. |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 365 | void BuildJobsForAction(Compilation &C, |
| 366 | const Action *A, |
| 367 | const ToolChain *TC, |
Daniel Dunbar | 4954018 | 2009-09-09 18:36:01 +0000 | [diff] [blame] | 368 | const char *BoundArch, |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 369 | bool AtTopLevel, |
Chad Rosier | 1c18759 | 2013-04-30 22:01:21 +0000 | [diff] [blame] | 370 | bool MultipleArchs, |
Daniel Dunbar | f353c8c | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 371 | const char *LinkingOutput, |
| 372 | InputInfo &Result) const; |
| 373 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 374 | /// Returns the default name for linked images (e.g., "a.out"). |
| 375 | const char *getDefaultImageName() const; |
| 376 | |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 377 | /// GetNamedOutputPath - Return the name to use for the output of |
Dmitri Gribenko | 1824d54 | 2012-09-13 13:11:20 +0000 | [diff] [blame] | 378 | /// the action \p JA. The result is appended to the compilation's |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 379 | /// list of temporary or result files, as appropriate. |
| 380 | /// |
| 381 | /// \param C - The compilation. |
| 382 | /// \param JA - The action of interest. |
| 383 | /// \param BaseInput - The original input file that this action was |
| 384 | /// triggered by. |
Chad Rosier | 1c18759 | 2013-04-30 22:01:21 +0000 | [diff] [blame] | 385 | /// \param BoundArch - The bound architecture. |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 386 | /// \param AtTopLevel - Whether this is a "top-level" action. |
Chad Rosier | 1c18759 | 2013-04-30 22:01:21 +0000 | [diff] [blame] | 387 | /// \param MultipleArchs - Whether multiple -arch options were supplied. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | const char *GetNamedOutputPath(Compilation &C, |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 389 | const JobAction &JA, |
| 390 | const char *BaseInput, |
Chad Rosier | 1c18759 | 2013-04-30 22:01:21 +0000 | [diff] [blame] | 391 | const char *BoundArch, |
| 392 | bool AtTopLevel, |
| 393 | bool MultipleArchs) const; |
Daniel Dunbar | 441d060 | 2009-03-17 17:53:55 +0000 | [diff] [blame] | 394 | |
Chad Rosier | fe87fc7 | 2011-08-26 21:28:44 +0000 | [diff] [blame] | 395 | /// GetTemporaryPath - Return the pathname of a temporary file to use |
| 396 | /// as part of compilation; the file will have the given prefix and suffix. |
Daniel Dunbar | 214399e | 2009-03-18 19:34:39 +0000 | [diff] [blame] | 397 | /// |
| 398 | /// GCC goes to extra lengths here to be a bit more robust. |
Chad Rosier | f43b5e8 | 2011-08-26 22:27:02 +0000 | [diff] [blame] | 399 | std::string GetTemporaryPath(StringRef Prefix, const char *Suffix) const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | |
Chad Rosier | 7db16db | 2012-11-16 23:41:41 +0000 | [diff] [blame] | 401 | /// ShouldUseClangCompiler - Should the clang compiler be used to |
Nick Lewycky | 5bab9ae | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 402 | /// handle this action. |
Rafael Espindola | d532018 | 2013-03-18 15:33:26 +0000 | [diff] [blame] | 403 | bool ShouldUseClangCompiler(const JobAction &JA) const; |
Nick Lewycky | 5bab9ae | 2012-11-15 05:36:36 +0000 | [diff] [blame] | 404 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 405 | bool IsUsingLTO(const ToolChain &TC, const llvm::opt::ArgList &Args) const; |
Daniel Dunbar | ed79895 | 2011-06-21 20:55:08 +0000 | [diff] [blame] | 406 | |
Chandler Carruth | 18d7f3a | 2012-01-25 11:01:57 +0000 | [diff] [blame] | 407 | private: |
| 408 | /// \brief Retrieves a ToolChain for a particular target triple. |
| 409 | /// |
| 410 | /// Will cache ToolChains for the life of the driver object, and create them |
| 411 | /// on-demand. |
Reid Kleckner | dd0b3c4 | 2013-06-17 13:59:19 +0000 | [diff] [blame] | 412 | const ToolChain &getToolChain(const llvm::opt::ArgList &Args, |
Chandler Carruth | 18d7f3a | 2012-01-25 11:01:57 +0000 | [diff] [blame] | 413 | StringRef DarwinArchName = "") const; |
| 414 | |
Daniel Dunbar | cb88167 | 2009-03-13 00:51:18 +0000 | [diff] [blame] | 415 | /// @} |
Daniel Dunbar | d73fe9b | 2009-03-26 15:58:36 +0000 | [diff] [blame] | 416 | |
Hans Wennborg | 6981330 | 2013-07-27 00:23:45 +0000 | [diff] [blame] | 417 | /// \brief Get bitmasks for which option flags to include and exclude based on |
| 418 | /// the driver mode. |
| 419 | std::pair<unsigned, unsigned> getIncludeExcludeOptionFlagMasks() const; |
| 420 | |
Chandler Carruth | 18d7f3a | 2012-01-25 11:01:57 +0000 | [diff] [blame] | 421 | public: |
Daniel Dunbar | d73fe9b | 2009-03-26 15:58:36 +0000 | [diff] [blame] | 422 | /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and |
| 423 | /// return the grouped values as integers. Numbers which are not |
| 424 | /// provided are set to 0. |
| 425 | /// |
| 426 | /// \return True if the entire string was parsed (9.2), or all |
| 427 | /// groups were parsed (10.3.5extrastuff). HadExtra is true if all |
| 428 | /// groups were parsed but extra characters remain at the end. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 429 | static bool GetReleaseVersion(const char *Str, unsigned &Major, |
Daniel Dunbar | d73fe9b | 2009-03-26 15:58:36 +0000 | [diff] [blame] | 430 | unsigned &Minor, unsigned &Micro, |
| 431 | bool &HadExtra); |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 432 | }; |
| 433 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 434 | /// \return True if the last defined optimization level is -Ofast. |
| 435 | /// And False otherwise. |
| 436 | bool isOptimizationLevelFast(const llvm::opt::ArgList &Args); |
| 437 | |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 438 | } // end namespace driver |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 439 | } // end namespace clang |
| 440 | |
| 441 | #endif |