Driver.h revision bdaa13418851be5cc1ca3be88fbd82b15efecde7
13ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar//===--- Driver.h - Clang GCC Compatible Driver -----------------*- C++ -*-===//
23ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar//
33ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar//                     The LLVM Compiler Infrastructure
43ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar//
53ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar// This file is distributed under the University of Illinois Open Source
63ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar// License. See LICENSE.TXT for details.
73ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar//
83ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar//===----------------------------------------------------------------------===//
93ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar
103ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar#ifndef CLANG_DRIVER_DRIVER_H_
113ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar#define CLANG_DRIVER_DRIVER_H_
123ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar
134ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar#include "clang/Basic/Diagnostic.h"
14cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko#include "clang/Basic/LLVM.h"
15ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar#include "clang/Driver/Phases.h"
16be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier#include "clang/Driver/Types.h"
17d65bddcbe1385a4de212ecbbdc8919c54b3efeb0Daniel Dunbar#include "clang/Driver/Util.h"
1818d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth#include "llvm/ADT/StringMap.h"
19e3fdca2ee0346a41d9cc5ee417a75e66274216f5Jeffrey Yasskin#include "llvm/ADT/StringRef.h"
20a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar#include "llvm/ADT/Triple.h"
2103013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/Path.h" // FIXME: Kill when CompilationInfo
22cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar                              // lands.
23365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar#include <list>
24365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar#include <set>
25365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar#include <string>
26365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar
273ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarnamespace clang {
281b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbarnamespace driver {
2953ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar  class Action;
301fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier  class Arg;
310648262df75d97b464c2be0ed867da3615659785Daniel Dunbar  class ArgList;
322b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier  class Command;
333ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar  class Compilation;
34279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar  class DerivedArgList;
35f3cad36e59a41b5767fe662b5ac8911ee174b801Daniel Dunbar  class InputArgList;
36f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar  class InputInfo;
37441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar  class JobAction;
381b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar  class OptTable;
39cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  class ToolChain;
403ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar
413ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar/// Driver - Encapsulate logic for constructing compilation processes
423ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar/// from a set of gcc-driver-like command line arguments.
433ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarclass Driver {
441b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar  OptTable *Opts;
451b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar
46d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine &Diags;
474ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar
481d46033f760ba5fd266ce59fe391fac473f04f52Daniel Dunbarpublic:
494ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar  // Diag - Forwarding function for diagnostics.
5057b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar  DiagnosticBuilder Diag(unsigned DiagID) const {
510f9fed70cea107b3f79df554e38bd8e98d48fe47Daniel Dunbar    return Diags.Report(DiagID);
524ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar  }
534ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar
54365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  // FIXME: Privatize once interface is stable.
55365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbarpublic:
56365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  /// The name the driver was invoked as.
57365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  std::string Name;
581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  /// The path the driver executable was in, as invoked from the
60365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  /// command line.
61365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  std::string Dir;
621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar  /// The original path to the clang executable.
64b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar  std::string ClangExecutable;
65b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar
66edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar  /// The path to the installed clang directory, if any.
67edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar  std::string InstalledDir;
68edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar
69225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar  /// The path to the compiler resource directory.
70225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar  std::string ResourceDir;
71225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar
7248ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth  /// A prefix directory used to emulated a limited subset of GCC's '-Bprefix'
7348ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth  /// functionality.
7448ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth  /// FIXME: This type of customization should be removed in favor of the
7548ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth  /// universal driver when it is ready.
76686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<std::string, 4> prefix_list;
7709982cec0029bc495591067fa89967b6b4d1fa19Benjamin Kramer  prefix_list PrefixDirs;
7848ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth
798ab2bdcc4f397e100c684ede8e8ca6e226e1380aJoerg Sonnenberger  /// sysroot, if present
808ab2bdcc4f397e100c684ede8e8ca6e226e1380aJoerg Sonnenberger  std::string SysRoot;
818ab2bdcc4f397e100c684ede8e8ca6e226e1380aJoerg Sonnenberger
82bdaa13418851be5cc1ca3be88fbd82b15efecde7Peter Collingbourne  /// Dynamic loader prefix, if present
83bdaa13418851be5cc1ca3be88fbd82b15efecde7Peter Collingbourne  std::string DyldPrefix;
84bdaa13418851be5cc1ca3be88fbd82b15efecde7Peter Collingbourne
8505e5930166333e382522b942f00d08abc6c0a28eJoerg Sonnenberger  /// If the standard library is used
8605e5930166333e382522b942f00d08abc6c0a28eJoerg Sonnenberger  bool UseStdLib;
8705e5930166333e382522b942f00d08abc6c0a28eJoerg Sonnenberger
889606a57b6f2c43bf438a958fdffea1de60f6b2b7Sebastian Pop  /// Default target triple.
899606a57b6f2c43bf438a958fdffea1de60f6b2b7Sebastian Pop  std::string DefaultTargetTriple;
90365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar
91f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar  /// Default name for linked images (e.g., "a.out").
92f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar  std::string DefaultImageName;
93f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar
9443302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar  /// Driver title to use with help.
9543302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar  std::string DriverTitle;
9643302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar
974c8acc9b0158081635e1dabd49304377ae67ca98Michael J. Spencer  /// Information about the host which can be overridden by the user.
98365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  std::string HostBits, HostMachine, HostSystem, HostRelease;
99365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar
1004c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar  /// The file to log CC_PRINT_OPTIONS output to, if enabled.
1014c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar  const char *CCPrintOptionsFilename;
1024c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar
103322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar  /// The file to log CC_PRINT_HEADERS output to, if enabled.
104322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar  const char *CCPrintHeadersFilename;
105322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar
106c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar  /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
107c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar  const char *CCLogDiagnosticsFilename;
108c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar
109be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  /// A list of inputs and their types for the given arguments.
110be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  typedef SmallVector<std::pair<types::ID, const Arg*>, 16> InputList;
111be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier
112365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  /// Whether the driver should follow g++ like behavior.
1133bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar  unsigned CCCIsCXX : 1;
1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
115e5de3767186e2a31659c91c55a9665eff077eae6Chad Rosier  /// Whether the driver is just the preprocessor.
1169ade4ae4fb7ed1fcbd63835d9f8f53052f0657a2Joerg Sonnenberger  unsigned CCCIsCPP : 1;
1179ade4ae4fb7ed1fcbd63835d9f8f53052f0657a2Joerg Sonnenberger
118365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  /// Echo commands while executing (in -v style).
1193bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar  unsigned CCCEcho : 1;
120365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar
1215c3c1d7b494660ba5e8983ee4584622750725ac2Daniel Dunbar  /// Only print tool bindings, don't build any jobs.
1223bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar  unsigned CCCPrintBindings : 1;
12378d8a089c8f124ba6f47bb37e2c4a36986f60e23Daniel Dunbar
1244c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar  /// Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to
1254c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar  /// CCPrintOptionsFilename or to stderr.
1264c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar  unsigned CCPrintOptions : 1;
1274c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar
128322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar  /// Set CC_PRINT_HEADERS mode, which causes the frontend to log header include
129322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar  /// information to CCPrintHeadersFilename or to stderr.
130322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar  unsigned CCPrintHeaders : 1;
131322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar
132c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar  /// Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics
133c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar  /// to CCLogDiagnosticsFilename or to stderr, in a stable machine readable
134c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar  /// format.
135c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar  unsigned CCLogDiagnostics : 1;
136c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar
1372b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier  /// Whether the driver is generating diagnostics for debugging purposes.
1382b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier  unsigned CCGenDiagnostics : 1;
1392b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier
140af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbarprivate:
141b8a3e8139b9fe513500c89bbcd9133415654a689Dylan Noblesmith  /// Name to use when invoking gcc/g++.
14279e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola  std::string CCCGenericGCCName;
14379e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola
1443bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar  /// Whether to check that input files exist when constructing compilation
1453bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar  /// jobs.
1463bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar  unsigned CheckInputsExist : 1;
1473bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar
148df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorpublic:
149df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor  /// Use lazy precompiled headers for PCH support.
1503bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar  unsigned CCCUsePCH : 1;
151df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor
152df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorprivate:
153365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  /// Certain options suppress the 'no input files' warning.
154365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  bool SuppressMissingInputWarning : 1;
1551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
156365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  std::list<std::string> TempFiles;
157365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar  std::list<std::string> ResultFiles;
158365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar
15918d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  /// \brief Cache of all the ToolChains in use by the driver.
16018d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  ///
16118d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  /// This maps from the string representation of a triple to a ToolChain
16248d798ce32447607144db70a484cdb99c1180663Benjamin Kramer  /// created targeting that triple. The driver owns all the ToolChain objects
16318d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  /// stored in it, and will clean them up when torn down.
16418d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  mutable llvm::StringMap<ToolChain *> ToolChains;
16518d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth
166279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbarprivate:
167279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar  /// TranslateInputArgs - Create a new derived argument list from the input
168279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar  /// arguments, after applying the standard argument translations.
169279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar  DerivedArgList *TranslateInputArgs(const InputArgList &Args) const;
170279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar
1711fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier  // getFinalPhase - Determine which compilation mode we are in and record
1721fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier  // which option we used to determine the final phase.
1731fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier  phases::ID getFinalPhase(const DerivedArgList &DAL, Arg **FinalPhaseArg = 0)
1741fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier    const;
1751fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier
1763ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarpublic:
177686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  Driver(StringRef _ClangExecutable,
1789606a57b6f2c43bf438a958fdffea1de60f6b2b7Sebastian Pop         StringRef _DefaultTargetTriple,
179686775deca8b8685eb90801495880e3abdd844c2Chris Lattner         StringRef _DefaultImageName,
180d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie         DiagnosticsEngine &_Diags);
1813ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar  ~Driver();
1823ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar
183cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @name Accessors
184cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @{
185cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar
186b8a3e8139b9fe513500c89bbcd9133415654a689Dylan Noblesmith  /// Name to use when invoking gcc/g++.
18779e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola  const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; }
18879e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola
18979e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola
1901b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar  const OptTable &getOpts() const { return *Opts; }
1911b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar
192d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  const DiagnosticsEngine &getDiags() const { return Diags; }
193af96def468042cfbed55a4cc12b1bb917ead4f33Daniel Dunbar
1943bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar  bool getCheckInputsExist() const { return CheckInputsExist; }
1953bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar
1963bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar  void setCheckInputsExist(bool Value) { CheckInputsExist = Value; }
1973bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar
19843302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar  const std::string &getTitle() { return DriverTitle; }
19943302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar  void setTitle(std::string Value) { DriverTitle = Value; }
20043302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar
201b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar  /// \brief Get the path to the main clang executable.
202a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar  const char *getClangProgramPath() const {
203a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar    return ClangExecutable.c_str();
204b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar  }
205b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar
206edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar  /// \brief Get the path to where the clang executable was installed.
207edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar  const char *getInstalledDir() const {
208edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar    if (!InstalledDir.empty())
209edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar      return InstalledDir.c_str();
210edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar    return Dir.c_str();
211edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar  }
212686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void setInstalledDir(StringRef Value) {
213edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar    InstalledDir = Value;
214edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar  }
215edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar
216cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @}
217cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @name Primary Functionality
218cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @{
219cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar
2203ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar  /// BuildCompilation - Construct a compilation object for a command
2213ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar  /// line argument vector.
222cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  ///
223cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// \return A compilation, or 0 if none was built for the given
224cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// argument vector. A null return value does not necessarily
225cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// indicate an error condition, the diagnostics should be queried
226cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// to determine if an error occurred.
2272d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner  Compilation *BuildCompilation(ArrayRef<const char *> Args);
228365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar
229cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @name Driver Steps
230cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @{
23153ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar
23257b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar  /// ParseArgStrings - Parse the given list of strings into an
23357b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar  /// ArgList.
2342d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner  InputArgList *ParseArgStrings(ArrayRef<const char *> Args);
23557b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar
236be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  /// BuildInputs - Construct the list of inputs and their types from
237be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  /// the given arguments.
238be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  ///
239be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  /// \param TC - The default host tool chain.
240be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  /// \param Args - The input arguments.
241be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  /// \param Inputs - The list to store the resulting compilation
242be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  /// inputs onto.
243be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier  void BuildInputs(const ToolChain &TC, const DerivedArgList &Args,
244be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier                   InputList &Inputs) const;
245be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier
24657b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar  /// BuildActions - Construct the list of actions to perform for the
24757b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar  /// given arguments, which are only done for a single architecture.
24853ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar  ///
24974edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar  /// \param TC - The default host tool chain.
25053ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar  /// \param Args - The input arguments.
25153ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar  /// \param Actions - The list to store the resulting actions onto.
25265f7165676854bf75494f5b73a620d7237db5d41Joerg Sonnenberger  void BuildActions(const ToolChain &TC, const DerivedArgList &Args,
253be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier                    const InputList &Inputs, ActionList &Actions) const;
25453ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar
25557b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar  /// BuildUniversalActions - Construct the list of actions to perform
25657b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar  /// for the given arguments, which may require a universal build.
25753ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar  ///
25874edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar  /// \param TC - The default host tool chain.
25953ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar  /// \param Args - The input arguments.
26053ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar  /// \param Actions - The list to store the resulting actions onto.
26165f7165676854bf75494f5b73a620d7237db5d41Joerg Sonnenberger  void BuildUniversalActions(const ToolChain &TC, const DerivedArgList &Args,
262be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier                             const InputList &BAInputs,
26374edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar                             ActionList &Actions) const;
26457b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar
26557b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar  /// BuildJobs - Bind actions to concrete tools and translate
26657b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar  /// arguments to form the list of jobs to run.
267586dc233bb88f2920c9f3638f69cef0ccd55dcedDaniel Dunbar  ///
2681824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \param C - The compilation that is being built.
26921549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar  void BuildJobs(Compilation &C) const;
270cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar
271c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar  /// ExecuteCompilation - Execute the compilation according to the command line
272c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar  /// arguments and return an appropriate exit code.
273c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar  ///
274c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar  /// This routine handles additional processing that must be done in addition
275c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar  /// to just running the subprocesses, for example reporting errors, removing
276c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar  /// temporary files, etc.
2772b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier  int ExecuteCompilation(const Compilation &C,
278a16355c31878403443f99077cc8df8318457faf5Chad Rosier     SmallVectorImpl< std::pair<int, const Command *> > &FailingCommands) const;
2792b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier
2802b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier  /// generateCompilationDiagnostics - Generate diagnostics information
2812b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier  /// including preprocessed source file(s).
2822b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier  ///
2832b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier  void generateCompilationDiagnostics(Compilation &C,
2842b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier                                      const Command *FailingCommand);
285c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar
286cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @}
287cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @name Helper Methods
288cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @{
289cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar
29091e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar  /// PrintActions - Print the list of actions.
29191e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar  void PrintActions(const Compilation &C) const;
29291e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar
293c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar  /// PrintHelp - Print the help text.
294c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar  ///
295c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar  /// \param ShowHidden - Show hidden options.
296c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar  void PrintHelp(bool ShowHidden) const;
29791e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar
298cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// PrintOptions - Print the list of arguments.
299cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  void PrintOptions(const ArgList &Args) const;
300cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar
301cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// PrintVersion - Print the driver version.
3028cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void PrintVersion(const Compilation &C, raw_ostream &OS) const;
303cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar
3041824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// GetFilePath - Lookup \p Name in the list of file search paths.
3052ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar  ///
3061824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \param TC - The tool chain for additional information on
30721549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar  /// directories to search.
3085ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar  //
309cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  // FIXME: This should be in CompilationInfo.
3105ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar  std::string GetFilePath(const char *Name, const ToolChain &TC) const;
311cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar
3121824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// GetProgramPath - Lookup \p Name in the list of program search paths.
3132ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar  ///
3141824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \param TC - The provided tool chain for additional information on
31521549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar  /// directories to search.
3165ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar  //
317cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  // FIXME: This should be in CompilationInfo.
318fc44e88cbdf013d285f2e4e3962fb80dcad56770Simon Atanasyan  std::string GetProgramPath(const char *Name, const ToolChain &TC) const;
319cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar
320cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// HandleImmediateArgs - Handle any arguments which should be
321cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// treated before building actions or binding tools.
322cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  ///
323cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// \return Whether any compilation should be built for this
324cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// invocation.
32521549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar  bool HandleImmediateArgs(const Compilation &C);
326cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar
327ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar  /// ConstructAction - Construct the appropriate action to do for
3281824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// \p Phase on the \p Input, taking in to account arguments
329ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar  /// like -fsyntax-only or --analyze.
330ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar  Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase,
331ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar                               Action *Input) const;
332ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar
333f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar
334f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar  /// BuildJobsForAction - Construct the jobs to perform for the
3351824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// action \p A.
336f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar  void BuildJobsForAction(Compilation &C,
337f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar                          const Action *A,
338f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar                          const ToolChain *TC,
3394954018954bbc97363eef02d0c83bea19ce9b329Daniel Dunbar                          const char *BoundArch,
340f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar                          bool AtTopLevel,
3411c18759b45140c85e62ac6367fbee51f363e3c81Chad Rosier                          bool MultipleArchs,
342f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar                          const char *LinkingOutput,
343f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar                          InputInfo &Result) const;
344f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar
345441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar  /// GetNamedOutputPath - Return the name to use for the output of
3461824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// the action \p JA. The result is appended to the compilation's
347441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar  /// list of temporary or result files, as appropriate.
348441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar  ///
349441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar  /// \param C - The compilation.
350441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar  /// \param JA - The action of interest.
351441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar  /// \param BaseInput - The original input file that this action was
352441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar  /// triggered by.
3531c18759b45140c85e62ac6367fbee51f363e3c81Chad Rosier  /// \param BoundArch - The bound architecture.
354441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar  /// \param AtTopLevel - Whether this is a "top-level" action.
3551c18759b45140c85e62ac6367fbee51f363e3c81Chad Rosier  /// \param MultipleArchs - Whether multiple -arch options were supplied.
3561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const char *GetNamedOutputPath(Compilation &C,
357441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar                                 const JobAction &JA,
358441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar                                 const char *BaseInput,
3591c18759b45140c85e62ac6367fbee51f363e3c81Chad Rosier                                 const char *BoundArch,
3601c18759b45140c85e62ac6367fbee51f363e3c81Chad Rosier                                 bool AtTopLevel,
3611c18759b45140c85e62ac6367fbee51f363e3c81Chad Rosier                                 bool MultipleArchs) const;
362441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar
363fe87fc73c0091a8d6ba04b7e3b5f144d4a0517a3Chad Rosier  /// GetTemporaryPath - Return the pathname of a temporary file to use
364fe87fc73c0091a8d6ba04b7e3b5f144d4a0517a3Chad Rosier  /// as part of compilation; the file will have the given prefix and suffix.
365214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar  ///
366214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar  /// GCC goes to extra lengths here to be a bit more robust.
367f43b5e84aa982afacd87a225440ec88a9b66c1a0Chad Rosier  std::string GetTemporaryPath(StringRef Prefix, const char *Suffix) const;
3681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3697db16db1ad37a77d45de26bd26725a296025981aChad Rosier  /// ShouldUseClangCompiler - Should the clang compiler be used to
3705bab9ae87c41148ee2f92d312945c1e9303222e8Nick Lewycky  /// handle this action.
371d5320184367b681087e9ff74fc57ed2c5954c8ecRafael Espindola  bool ShouldUseClangCompiler(const JobAction &JA) const;
3725bab9ae87c41148ee2f92d312945c1e9303222e8Nick Lewycky
373ed798951b46555946c95cb76568ea3cf0b16c9abDaniel Dunbar  bool IsUsingLTO(const ArgList &Args) const;
374ed798951b46555946c95cb76568ea3cf0b16c9abDaniel Dunbar
37518d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruthprivate:
37618d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  /// \brief Retrieves a ToolChain for a particular target triple.
37718d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  ///
37818d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  /// Will cache ToolChains for the life of the driver object, and create them
37918d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  /// on-demand.
38018d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth  const ToolChain &getToolChain(const ArgList &Args,
38118d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth                                StringRef DarwinArchName = "") const;
38218d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth
383cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar  /// @}
384d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar
38518d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruthpublic:
386d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar  /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
387d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar  /// return the grouped values as integers. Numbers which are not
388d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar  /// provided are set to 0.
389d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar  ///
390d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar  /// \return True if the entire string was parsed (9.2), or all
391d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar  /// groups were parsed (10.3.5extrastuff). HadExtra is true if all
392d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar  /// groups were parsed but extra characters remain at the end.
3931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool GetReleaseVersion(const char *Str, unsigned &Major,
394d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar                                unsigned &Minor, unsigned &Micro,
395d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar                                bool &HadExtra);
3963ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar};
3973ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar
3981b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar} // end namespace driver
3993ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar} // end namespace clang
4003ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar
4013ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar#endif
402