blob: 09521c2bae3fe8834db5a451879f855a2435b3cd [file] [log] [blame]
Daniel Dunbar3ede8d02009-03-02 19:59:07 +00001//===--- 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 Hines176edba2014-12-01 14:53:08 -080010#ifndef LLVM_CLANG_DRIVER_DRIVER_H
11#define LLVM_CLANG_DRIVER_DRIVER_H
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000012
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000013#include "clang/Basic/Diagnostic.h"
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +000014#include "clang/Basic/LLVM.h"
Daniel Dunbarad2a9af2009-03-13 11:38:42 +000015#include "clang/Driver/Phases.h"
Chad Rosierbe69f602011-08-12 22:08:57 +000016#include "clang/Driver/Types.h"
Daniel Dunbard65bddc2009-03-12 18:24:49 +000017#include "clang/Driver/Util.h"
Chandler Carruth18d7f3a2012-01-25 11:01:57 +000018#include "llvm/ADT/StringMap.h"
Jeffrey Yasskine3fdca22009-12-08 01:46:24 +000019#include "llvm/ADT/StringRef.h"
Daniel Dunbara6046be2009-09-08 23:36:55 +000020#include "llvm/ADT/Triple.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000021#include "llvm/Support/Path.h" // FIXME: Kill when CompilationInfo
Stephen Hines651f13c2014-04-23 16:59:28 -070022#include <memory>
Daniel Dunbarcb881672009-03-13 00:51:18 +000023 // lands.
Daniel Dunbar365c02f2009-03-10 20:52:46 +000024#include <list>
25#include <set>
26#include <string>
27
Reid Klecknerb1e25a12013-06-14 17:17:23 +000028namespace llvm {
29namespace opt {
Chad Rosier1fc1de42011-07-27 23:36:45 +000030 class Arg;
Daniel Dunbar06482622009-03-05 06:38:47 +000031 class ArgList;
Daniel Dunbar279c1db2010-06-11 22:00:26 +000032 class DerivedArgList;
Daniel Dunbarf3cad362009-03-25 04:13:45 +000033 class InputArgList;
Reid Klecknerb1e25a12013-06-14 17:17:23 +000034 class OptTable;
35}
36}
37
38namespace clang {
39namespace driver {
Reid Klecknerb1e25a12013-06-14 17:17:23 +000040
41 class Action;
42 class Command;
43 class Compilation;
Daniel Dunbarf353c8c2009-03-16 06:56:51 +000044 class InputInfo;
Stephen Hines176edba2014-12-01 14:53:08 -080045 class Job;
Daniel Dunbar441d0602009-03-17 17:53:55 +000046 class JobAction;
Alexey Samsonov1b8f12d2013-08-19 09:14:21 +000047 class SanitizerArgs;
Daniel Dunbarcb881672009-03-13 00:51:18 +000048 class ToolChain;
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000049
50/// Driver - Encapsulate logic for constructing compilation processes
51/// from a set of gcc-driver-like command line arguments.
52class Driver {
Reid Klecknerdd0b3c42013-06-17 13:59:19 +000053 llvm::opt::OptTable *Opts;
Daniel Dunbar1b3bb6e2009-03-04 20:49:20 +000054
David Blaikied6471f72011-09-25 23:23:43 +000055 DiagnosticsEngine &Diags;
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000056
Hans Wennborg76b86c22013-07-18 20:29:38 +000057 enum DriverMode {
58 GCCMode,
59 GXXMode,
Hans Wennborgc2f531a2013-07-19 20:33:20 +000060 CPPMode,
61 CLMode
Hans Wennborg76b86c22013-07-18 20:29:38 +000062 } Mode;
63
Stephen Hines0e2c34f2015-03-23 12:09:02 -070064 enum SaveTempsMode {
65 SaveTempsNone,
66 SaveTempsCwd,
67 SaveTempsObj
68 } SaveTemps;
69
Daniel Dunbar1d460332009-03-18 10:01:51 +000070public:
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000071 // Diag - Forwarding function for diagnostics.
Daniel Dunbar57b704d2009-03-13 22:12:33 +000072 DiagnosticBuilder Diag(unsigned DiagID) const {
Daniel Dunbar0f9fed72009-11-10 23:55:23 +000073 return Diags.Report(DiagID);
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000074 }
75
Daniel Dunbar365c02f2009-03-10 20:52:46 +000076 // FIXME: Privatize once interface is stable.
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000077public:
Daniel Dunbar365c02f2009-03-10 20:52:46 +000078 /// The name the driver was invoked as.
79 std::string Name;
Mike Stump1eb44332009-09-09 15:08:12 +000080
Daniel Dunbar365c02f2009-03-10 20:52:46 +000081 /// The path the driver executable was in, as invoked from the
82 /// command line.
83 std::string Dir;
Mike Stump1eb44332009-09-09 15:08:12 +000084
Daniel Dunbarb9a82262010-07-14 18:46:27 +000085 /// The original path to the clang executable.
86 std::string ClangExecutable;
87
Daniel Dunbaredf29b02010-08-01 22:29:51 +000088 /// The path to the installed clang directory, if any.
89 std::string InstalledDir;
90
Daniel Dunbar225c4172010-01-20 02:35:16 +000091 /// The path to the compiler resource directory.
92 std::string ResourceDir;
93
Chandler Carruth48ad6092010-03-22 01:52:07 +000094 /// 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 Lattner686775d2011-07-20 06:58:45 +000098 typedef SmallVector<std::string, 4> prefix_list;
Benjamin Kramer09982ce2011-02-08 20:31:42 +000099 prefix_list PrefixDirs;
Chandler Carruth48ad6092010-03-22 01:52:07 +0000100
Joerg Sonnenberger8ab2bdc2011-03-21 13:51:29 +0000101 /// sysroot, if present
102 std::string SysRoot;
103
Peter Collingbournebdaa1342013-05-27 21:40:20 +0000104 /// Dynamic loader prefix, if present
105 std::string DyldPrefix;
106
Joerg Sonnenberger05e59302011-03-21 13:59:26 +0000107 /// If the standard library is used
108 bool UseStdLib;
109
Sebastian Pop9606a572012-01-13 20:36:46 +0000110 /// Default target triple.
111 std::string DefaultTargetTriple;
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000112
Daniel Dunbar43302d42010-02-25 03:31:53 +0000113 /// Driver title to use with help.
114 std::string DriverTitle;
115
Michael J. Spencer4c8acc92011-04-05 17:57:51 +0000116 /// Information about the host which can be overridden by the user.
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000117 std::string HostBits, HostMachine, HostSystem, HostRelease;
118
Daniel Dunbar4c00fcd2010-03-20 08:01:59 +0000119 /// The file to log CC_PRINT_OPTIONS output to, if enabled.
120 const char *CCPrintOptionsFilename;
121
Daniel Dunbar322c29f2011-02-02 21:11:35 +0000122 /// The file to log CC_PRINT_HEADERS output to, if enabled.
123 const char *CCPrintHeadersFilename;
124
Daniel Dunbarc8a22b02011-04-07 18:01:20 +0000125 /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
126 const char *CCLogDiagnosticsFilename;
127
Chad Rosierbe69f602011-08-12 22:08:57 +0000128 /// A list of inputs and their types for the given arguments.
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000129 typedef SmallVector<std::pair<types::ID, const llvm::opt::Arg *>, 16>
130 InputList;
Chad Rosierbe69f602011-08-12 22:08:57 +0000131
Daniel Dunbar3bd54cc2010-01-25 00:44:02 +0000132 /// Whether the driver should follow g++ like behavior.
Hans Wennborg76b86c22013-07-18 20:29:38 +0000133 bool CCCIsCXX() const { return Mode == GXXMode; }
Daniel Dunbar3bd54cc2010-01-25 00:44:02 +0000134
Chad Rosiere5de3762012-03-06 23:19:26 +0000135 /// Whether the driver is just the preprocessor.
Hans Wennborg76b86c22013-07-18 20:29:38 +0000136 bool CCCIsCPP() const { return Mode == CPPMode; }
Joerg Sonnenberger9ade4ae2011-03-06 23:31:01 +0000137
Hans Wennborg909930f2013-08-07 00:32:15 +0000138 /// Whether the driver should follow cl.exe like behavior.
139 bool IsCLMode() const { return Mode == CLMode; }
140
Daniel Dunbar3bd54cc2010-01-25 00:44:02 +0000141 /// Only print tool bindings, don't build any jobs.
142 unsigned CCCPrintBindings : 1;
143
Daniel Dunbar4c00fcd2010-03-20 08:01:59 +0000144 /// 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 Dunbar322c29f2011-02-02 21:11:35 +0000148 /// 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 Dunbarc8a22b02011-04-07 18:01:20 +0000152 /// 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 Rosier2b819102011-08-02 17:58:04 +0000157 /// Whether the driver is generating diagnostics for debugging purposes.
158 unsigned CCGenDiagnostics : 1;
159
Daniel Dunbaraf80e1f2009-03-24 18:57:02 +0000160private:
Dylan Noblesmithb8a3e812011-04-09 13:31:59 +0000161 /// Name to use when invoking gcc/g++.
Rafael Espindola79e9e9d2010-09-06 02:36:23 +0000162 std::string CCCGenericGCCName;
163
Daniel Dunbar3bd54cc2010-01-25 00:44:02 +0000164 /// Whether to check that input files exist when constructing compilation
165 /// jobs.
166 unsigned CheckInputsExist : 1;
167
Douglas Gregordf91ef32009-04-18 00:34:01 +0000168public:
169 /// Use lazy precompiled headers for PCH support.
Daniel Dunbar3bd54cc2010-01-25 00:44:02 +0000170 unsigned CCCUsePCH : 1;
Douglas Gregordf91ef32009-04-18 00:34:01 +0000171
172private:
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000173 /// Certain options suppress the 'no input files' warning.
174 bool SuppressMissingInputWarning : 1;
Mike Stump1eb44332009-09-09 15:08:12 +0000175
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000176 std::list<std::string> TempFiles;
177 std::list<std::string> ResultFiles;
178
Chandler Carruth18d7f3a2012-01-25 11:01:57 +0000179 /// \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 Kramer48d798c2012-06-02 10:20:41 +0000182 /// created targeting that triple. The driver owns all the ToolChain objects
Chandler Carruth18d7f3a2012-01-25 11:01:57 +0000183 /// stored in it, and will clean them up when torn down.
184 mutable llvm::StringMap<ToolChain *> ToolChains;
185
Daniel Dunbar279c1db2010-06-11 22:00:26 +0000186private:
187 /// TranslateInputArgs - Create a new derived argument list from the input
188 /// arguments, after applying the standard argument translations.
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000189 llvm::opt::DerivedArgList *
190 TranslateInputArgs(const llvm::opt::InputArgList &Args) const;
Daniel Dunbar279c1db2010-06-11 22:00:26 +0000191
Chad Rosier1fc1de42011-07-27 23:36:45 +0000192 // getFinalPhase - Determine which compilation mode we are in and record
193 // which option we used to determine the final phase.
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000194 phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL,
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700195 llvm::opt::Arg **FinalPhaseArg = nullptr) const;
Chad Rosier1fc1de42011-07-27 23:36:45 +0000196
Stephen Hines176edba2014-12-01 14:53:08 -0800197 // 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 Dunbar365c02f2009-03-10 20:52:46 +0000203public:
Chris Lattner686775d2011-07-20 06:58:45 +0000204 Driver(StringRef _ClangExecutable,
Sebastian Pop9606a572012-01-13 20:36:46 +0000205 StringRef _DefaultTargetTriple,
David Blaikied6471f72011-09-25 23:23:43 +0000206 DiagnosticsEngine &_Diags);
Daniel Dunbar3ede8d02009-03-02 19:59:07 +0000207 ~Driver();
208
Daniel Dunbarcb881672009-03-13 00:51:18 +0000209 /// @name Accessors
210 /// @{
211
Dylan Noblesmithb8a3e812011-04-09 13:31:59 +0000212 /// Name to use when invoking gcc/g++.
Rafael Espindola79e9e9d2010-09-06 02:36:23 +0000213 const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; }
214
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000215 const llvm::opt::OptTable &getOpts() const { return *Opts; }
Daniel Dunbar1b3bb6e2009-03-04 20:49:20 +0000216
David Blaikied6471f72011-09-25 23:23:43 +0000217 const DiagnosticsEngine &getDiags() const { return Diags; }
Daniel Dunbaraf96def2009-03-21 00:40:53 +0000218
Daniel Dunbar3bd54cc2010-01-25 00:44:02 +0000219 bool getCheckInputsExist() const { return CheckInputsExist; }
220
221 void setCheckInputsExist(bool Value) { CheckInputsExist = Value; }
222
Daniel Dunbar43302d42010-02-25 03:31:53 +0000223 const std::string &getTitle() { return DriverTitle; }
224 void setTitle(std::string Value) { DriverTitle = Value; }
225
Daniel Dunbarb9a82262010-07-14 18:46:27 +0000226 /// \brief Get the path to the main clang executable.
Daniel Dunbara001c1c2010-07-18 21:16:15 +0000227 const char *getClangProgramPath() const {
228 return ClangExecutable.c_str();
Daniel Dunbarb9a82262010-07-14 18:46:27 +0000229 }
230
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000231 /// \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 Lattner686775d2011-07-20 06:58:45 +0000237 void setInstalledDir(StringRef Value) {
Daniel Dunbaredf29b02010-08-01 22:29:51 +0000238 InstalledDir = Value;
239 }
240
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700241 bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
242 bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }
243
Daniel Dunbarcb881672009-03-13 00:51:18 +0000244 /// @}
245 /// @name Primary Functionality
246 /// @{
247
Daniel Dunbar3ede8d02009-03-02 19:59:07 +0000248 /// BuildCompilation - Construct a compilation object for a command
249 /// line argument vector.
Daniel Dunbarcb881672009-03-13 00:51:18 +0000250 ///
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 Lattner2d3ba4f2011-07-23 17:14:25 +0000255 Compilation *BuildCompilation(ArrayRef<const char *> Args);
Daniel Dunbar365c02f2009-03-10 20:52:46 +0000256
Daniel Dunbarcb881672009-03-13 00:51:18 +0000257 /// @name Driver Steps
258 /// @{
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000259
Hans Wennborg76b86c22013-07-18 20:29:38 +0000260 /// ParseDriverMode - Look for and handle the driver mode option in Args.
261 void ParseDriverMode(ArrayRef<const char *> Args);
262
Daniel Dunbar57b704d2009-03-13 22:12:33 +0000263 /// ParseArgStrings - Parse the given list of strings into an
264 /// ArgList.
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000265 llvm::opt::InputArgList *ParseArgStrings(ArrayRef<const char *> Args);
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000266
Chad Rosierbe69f602011-08-12 22:08:57 +0000267 /// 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 Hines6bcf27b2014-05-29 04:14:42 -0700274 void BuildInputs(const ToolChain &TC, llvm::opt::DerivedArgList &Args,
Chad Rosierbe69f602011-08-12 22:08:57 +0000275 InputList &Inputs) const;
276
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000277 /// BuildActions - Construct the list of actions to perform for the
278 /// given arguments, which are only done for a single architecture.
279 ///
Daniel Dunbar74edcea2010-08-02 05:43:51 +0000280 /// \param TC - The default host tool chain.
Daniel Dunbar53ec5522009-03-12 07:58:46 +0000281 /// \param Args - The input arguments.
282 /// \param Actions - The list to store the resulting actions onto.
Hans Wennborg9c0ed912013-08-12 23:26:25 +0000283 void BuildActions(const ToolChain &TC, llvm::opt::DerivedArgList &Args,
Chad Rosierbe69f602011-08-12 22:08:57 +0000284 const InputList &Inputs, ActionList &Actions) const;
Daniel Dunbar57b704d2009-03-13 22:12:33 +0000285
286 /// BuildUniversalActions - Construct the list of actions to perform
287 /// for the given arguments, which may require a universal build.
288 ///
Daniel Dunbar74edcea2010-08-02 05:43:51 +0000289 /// \param TC - The default host tool chain.
Daniel Dunbar57b704d2009-03-13 22:12:33 +0000290 /// \param Args - The input arguments.
291 /// \param Actions - The list to store the resulting actions onto.
Reid Klecknerdd0b3c42013-06-17 13:59:19 +0000292 void BuildUniversalActions(const ToolChain &TC,
Hans Wennborg9c0ed912013-08-12 23:26:25 +0000293 llvm::opt::DerivedArgList &Args,
Chad Rosierbe69f602011-08-12 22:08:57 +0000294 const InputList &BAInputs,
Daniel Dunbar74edcea2010-08-02 05:43:51 +0000295 ActionList &Actions) const;
Daniel Dunbar57b704d2009-03-13 22:12:33 +0000296
297 /// BuildJobs - Bind actions to concrete tools and translate
298 /// arguments to form the list of jobs to run.
Daniel Dunbar586dc232009-03-16 06:42:30 +0000299 ///
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000300 /// \param C - The compilation that is being built.
Daniel Dunbar21549232009-03-18 02:55:38 +0000301 void BuildJobs(Compilation &C) const;
Daniel Dunbarcb881672009-03-13 00:51:18 +0000302
Daniel Dunbarc88a88f2009-07-01 20:03:04 +0000303 /// 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 Hines176edba2014-12-01 14:53:08 -0800307 /// 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 Rosier2b819102011-08-02 17:58:04 +0000311
312 /// generateCompilationDiagnostics - Generate diagnostics information
313 /// including preprocessed source file(s).
314 ///
315 void generateCompilationDiagnostics(Compilation &C,
Stephen Hines176edba2014-12-01 14:53:08 -0800316 const Command &FailingCommand);
Daniel Dunbarc88a88f2009-07-01 20:03:04 +0000317
Daniel Dunbarcb881672009-03-13 00:51:18 +0000318 /// @}
319 /// @name Helper Methods
320 /// @{
321
Daniel Dunbar91e28af2009-03-31 21:38:17 +0000322 /// PrintActions - Print the list of actions.
323 void PrintActions(const Compilation &C) const;
324
Daniel Dunbarc35d71f2009-04-15 16:34:29 +0000325 /// PrintHelp - Print the help text.
326 ///
327 /// \param ShowHidden - Show hidden options.
328 void PrintHelp(bool ShowHidden) const;
Daniel Dunbar91e28af2009-03-31 21:38:17 +0000329
Daniel Dunbarcb881672009-03-13 00:51:18 +0000330 /// PrintVersion - Print the driver version.
Chris Lattner8cc488f2011-07-20 07:06:53 +0000331 void PrintVersion(const Compilation &C, raw_ostream &OS) const;
Daniel Dunbarcb881672009-03-13 00:51:18 +0000332
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000333 /// GetFilePath - Lookup \p Name in the list of file search paths.
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +0000334 ///
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000335 /// \param TC - The tool chain for additional information on
Daniel Dunbar21549232009-03-18 02:55:38 +0000336 /// directories to search.
Daniel Dunbar5ed34f42009-09-09 22:33:00 +0000337 //
Daniel Dunbarcb881672009-03-13 00:51:18 +0000338 // FIXME: This should be in CompilationInfo.
Daniel Dunbar5ed34f42009-09-09 22:33:00 +0000339 std::string GetFilePath(const char *Name, const ToolChain &TC) const;
Daniel Dunbarcb881672009-03-13 00:51:18 +0000340
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000341 /// GetProgramPath - Lookup \p Name in the list of program search paths.
Daniel Dunbar2ba38ba2009-03-16 05:25:36 +0000342 ///
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000343 /// \param TC - The provided tool chain for additional information on
Daniel Dunbar21549232009-03-18 02:55:38 +0000344 /// directories to search.
Daniel Dunbar5ed34f42009-09-09 22:33:00 +0000345 //
Daniel Dunbarcb881672009-03-13 00:51:18 +0000346 // FIXME: This should be in CompilationInfo.
Simon Atanasyanfc44e882012-10-03 19:52:37 +0000347 std::string GetProgramPath(const char *Name, const ToolChain &TC) const;
Daniel Dunbarcb881672009-03-13 00:51:18 +0000348
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 Dunbar21549232009-03-18 02:55:38 +0000354 bool HandleImmediateArgs(const Compilation &C);
Daniel Dunbarcb881672009-03-13 00:51:18 +0000355
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000356 /// ConstructAction - Construct the appropriate action to do for
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000357 /// \p Phase on the \p Input, taking in to account arguments
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000358 /// like -fsyntax-only or --analyze.
Stephen Hines176edba2014-12-01 14:53:08 -0800359 std::unique_ptr<Action>
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700360 ConstructPhaseAction(const ToolChain &TC, const llvm::opt::ArgList &Args,
361 phases::ID Phase, std::unique_ptr<Action> Input) const;
Daniel Dunbarad2a9af2009-03-13 11:38:42 +0000362
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000363 /// BuildJobsForAction - Construct the jobs to perform for the
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000364 /// action \p A.
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000365 void BuildJobsForAction(Compilation &C,
366 const Action *A,
367 const ToolChain *TC,
Daniel Dunbar49540182009-09-09 18:36:01 +0000368 const char *BoundArch,
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000369 bool AtTopLevel,
Chad Rosier1c187592013-04-30 22:01:21 +0000370 bool MultipleArchs,
Daniel Dunbarf353c8c2009-03-16 06:56:51 +0000371 const char *LinkingOutput,
372 InputInfo &Result) const;
373
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700374 /// Returns the default name for linked images (e.g., "a.out").
375 const char *getDefaultImageName() const;
376
Daniel Dunbar441d0602009-03-17 17:53:55 +0000377 /// GetNamedOutputPath - Return the name to use for the output of
Dmitri Gribenko1824d542012-09-13 13:11:20 +0000378 /// the action \p JA. The result is appended to the compilation's
Daniel Dunbar441d0602009-03-17 17:53:55 +0000379 /// 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 Rosier1c187592013-04-30 22:01:21 +0000385 /// \param BoundArch - The bound architecture.
Daniel Dunbar441d0602009-03-17 17:53:55 +0000386 /// \param AtTopLevel - Whether this is a "top-level" action.
Chad Rosier1c187592013-04-30 22:01:21 +0000387 /// \param MultipleArchs - Whether multiple -arch options were supplied.
Mike Stump1eb44332009-09-09 15:08:12 +0000388 const char *GetNamedOutputPath(Compilation &C,
Daniel Dunbar441d0602009-03-17 17:53:55 +0000389 const JobAction &JA,
390 const char *BaseInput,
Chad Rosier1c187592013-04-30 22:01:21 +0000391 const char *BoundArch,
392 bool AtTopLevel,
393 bool MultipleArchs) const;
Daniel Dunbar441d0602009-03-17 17:53:55 +0000394
Chad Rosierfe87fc72011-08-26 21:28:44 +0000395 /// 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 Dunbar214399e2009-03-18 19:34:39 +0000397 ///
398 /// GCC goes to extra lengths here to be a bit more robust.
Chad Rosierf43b5e82011-08-26 22:27:02 +0000399 std::string GetTemporaryPath(StringRef Prefix, const char *Suffix) const;
Mike Stump1eb44332009-09-09 15:08:12 +0000400
Chad Rosier7db16db2012-11-16 23:41:41 +0000401 /// ShouldUseClangCompiler - Should the clang compiler be used to
Nick Lewycky5bab9ae2012-11-15 05:36:36 +0000402 /// handle this action.
Rafael Espindolad5320182013-03-18 15:33:26 +0000403 bool ShouldUseClangCompiler(const JobAction &JA) const;
Nick Lewycky5bab9ae2012-11-15 05:36:36 +0000404
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700405 bool IsUsingLTO(const ToolChain &TC, const llvm::opt::ArgList &Args) const;
Daniel Dunbared798952011-06-21 20:55:08 +0000406
Chandler Carruth18d7f3a2012-01-25 11:01:57 +0000407private:
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 Klecknerdd0b3c42013-06-17 13:59:19 +0000412 const ToolChain &getToolChain(const llvm::opt::ArgList &Args,
Chandler Carruth18d7f3a2012-01-25 11:01:57 +0000413 StringRef DarwinArchName = "") const;
414
Daniel Dunbarcb881672009-03-13 00:51:18 +0000415 /// @}
Daniel Dunbard73fe9b2009-03-26 15:58:36 +0000416
Hans Wennborg69813302013-07-27 00:23:45 +0000417 /// \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 Carruth18d7f3a2012-01-25 11:01:57 +0000421public:
Daniel Dunbard73fe9b2009-03-26 15:58:36 +0000422 /// 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 Stump1eb44332009-09-09 15:08:12 +0000429 static bool GetReleaseVersion(const char *Str, unsigned &Major,
Daniel Dunbard73fe9b2009-03-26 15:58:36 +0000430 unsigned &Minor, unsigned &Micro,
431 bool &HadExtra);
Daniel Dunbar3ede8d02009-03-02 19:59:07 +0000432};
433
Stephen Hines651f13c2014-04-23 16:59:28 -0700434/// \return True if the last defined optimization level is -Ofast.
435/// And False otherwise.
436bool isOptimizationLevelFast(const llvm::opt::ArgList &Args);
437
Daniel Dunbar1b3bb6e2009-03-04 20:49:20 +0000438} // end namespace driver
Daniel Dunbar3ede8d02009-03-02 19:59:07 +0000439} // end namespace clang
440
441#endif