Driver.h revision fc44e88cbdf013d285f2e4e3962fb80dcad56770
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" 144ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar 15ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar#include "clang/Driver/Phases.h" 16be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier#include "clang/Driver/Types.h" 17d65bddcbe1385a4de212ecbbdc8919c54b3efeb0Daniel Dunbar#include "clang/Driver/Util.h" 18d65bddcbe1385a4de212ecbbdc8919c54b3efeb0Daniel Dunbar 1918d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth#include "llvm/ADT/StringMap.h" 20e3fdca2ee0346a41d9cc5ee417a75e66274216f5Jeffrey Yasskin#include "llvm/ADT/StringRef.h" 21a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar#include "llvm/ADT/Triple.h" 2203013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/Path.h" // FIXME: Kill when CompilationInfo 23cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // lands. 24365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar#include <list> 25365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar#include <set> 26365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar#include <string> 27365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 28793007242ba209b68ce14ec7547ac70ee981303aDaniel Dunbarnamespace llvm { 297f9fc3f7ce076645cb6aefc99c64d9446caf13d6Chris Lattner template<typename T> class ArrayRef; 30793007242ba209b68ce14ec7547ac70ee981303aDaniel Dunbar} 313ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarnamespace clang { 321b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbarnamespace driver { 3353ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar class Action; 341fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier class Arg; 350648262df75d97b464c2be0ed867da3615659785Daniel Dunbar class ArgList; 362b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier class Command; 373ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar class Compilation; 38279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar class DerivedArgList; 39f3cad36e59a41b5767fe662b5ac8911ee174b801Daniel Dunbar class InputArgList; 40f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar class InputInfo; 41441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar class JobAction; 421b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar class OptTable; 43cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar class ToolChain; 443ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 453ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar/// Driver - Encapsulate logic for constructing compilation processes 463ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar/// from a set of gcc-driver-like command line arguments. 473ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarclass Driver { 481b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar OptTable *Opts; 491b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar 50d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine &Diags; 514ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar 521d46033f760ba5fd266ce59fe391fac473f04f52Daniel Dunbarpublic: 534ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar // Diag - Forwarding function for diagnostics. 5457b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar DiagnosticBuilder Diag(unsigned DiagID) const { 550f9fed70cea107b3f79df554e38bd8e98d48fe47Daniel Dunbar return Diags.Report(DiagID); 564ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar } 574ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar 58365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar // FIXME: Privatize once interface is stable. 59365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbarpublic: 60365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// The name the driver was invoked as. 61365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string Name; 621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// The path the driver executable was in, as invoked from the 64365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// command line. 65365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string Dir; 661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar /// The original path to the clang executable. 68b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar std::string ClangExecutable; 69b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar 70edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar /// The path to the installed clang directory, if any. 71edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar std::string InstalledDir; 72edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar 73225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar /// The path to the compiler resource directory. 74225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar std::string ResourceDir; 75225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar 7648ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// A prefix directory used to emulated a limited subset of GCC's '-Bprefix' 7748ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// functionality. 7848ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// FIXME: This type of customization should be removed in favor of the 7948ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// universal driver when it is ready. 80686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<std::string, 4> prefix_list; 8109982cec0029bc495591067fa89967b6b4d1fa19Benjamin Kramer prefix_list PrefixDirs; 8248ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth 838ab2bdcc4f397e100c684ede8e8ca6e226e1380aJoerg Sonnenberger /// sysroot, if present 848ab2bdcc4f397e100c684ede8e8ca6e226e1380aJoerg Sonnenberger std::string SysRoot; 858ab2bdcc4f397e100c684ede8e8ca6e226e1380aJoerg Sonnenberger 8605e5930166333e382522b942f00d08abc6c0a28eJoerg Sonnenberger /// If the standard library is used 8705e5930166333e382522b942f00d08abc6c0a28eJoerg Sonnenberger bool UseStdLib; 8805e5930166333e382522b942f00d08abc6c0a28eJoerg Sonnenberger 899606a57b6f2c43bf438a958fdffea1de60f6b2b7Sebastian Pop /// Default target triple. 909606a57b6f2c43bf438a958fdffea1de60f6b2b7Sebastian Pop std::string DefaultTargetTriple; 91365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 92f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// Default name for linked images (e.g., "a.out"). 93f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar std::string DefaultImageName; 94f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 9543302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar /// Driver title to use with help. 9643302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar std::string DriverTitle; 9743302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar 984c8acc9b0158081635e1dabd49304377ae67ca98Michael J. Spencer /// Information about the host which can be overridden by the user. 99365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string HostBits, HostMachine, HostSystem, HostRelease; 100365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1014c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// The file to log CC_PRINT_OPTIONS output to, if enabled. 1024c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar const char *CCPrintOptionsFilename; 1034c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar 104322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar /// The file to log CC_PRINT_HEADERS output to, if enabled. 105322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar const char *CCPrintHeadersFilename; 106322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar 107c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled. 108c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar const char *CCLogDiagnosticsFilename; 109c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar 110be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier /// A list of inputs and their types for the given arguments. 111be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier typedef SmallVector<std::pair<types::ID, const Arg*>, 16> InputList; 112be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier 113365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Whether the driver should follow g++ like behavior. 1143bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCIsCXX : 1; 1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 116e5de3767186e2a31659c91c55a9665eff077eae6Chad Rosier /// Whether the driver is just the preprocessor. 1179ade4ae4fb7ed1fcbd63835d9f8f53052f0657a2Joerg Sonnenberger unsigned CCCIsCPP : 1; 1189ade4ae4fb7ed1fcbd63835d9f8f53052f0657a2Joerg Sonnenberger 119365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Echo commands while executing (in -v style). 1203bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCEcho : 1; 121365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1225c3c1d7b494660ba5e8983ee4584622750725ac2Daniel Dunbar /// Only print tool bindings, don't build any jobs. 1233bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCPrintBindings : 1; 12478d8a089c8f124ba6f47bb37e2c4a36986f60e23Daniel Dunbar 1254c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to 1264c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// CCPrintOptionsFilename or to stderr. 1274c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar unsigned CCPrintOptions : 1; 1284c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar 129322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar /// Set CC_PRINT_HEADERS mode, which causes the frontend to log header include 130322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar /// information to CCPrintHeadersFilename or to stderr. 131322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar unsigned CCPrintHeaders : 1; 132322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar 133c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar /// Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics 134c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar /// to CCLogDiagnosticsFilename or to stderr, in a stable machine readable 135c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar /// format. 136c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar unsigned CCLogDiagnostics : 1; 137c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar 1382b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier /// Whether the driver is generating diagnostics for debugging purposes. 1392b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier unsigned CCGenDiagnostics : 1; 1402b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier 141af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbarprivate: 142b8a3e8139b9fe513500c89bbcd9133415654a689Dylan Noblesmith /// Name to use when invoking gcc/g++. 14379e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola std::string CCCGenericGCCName; 14479e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 1453bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar /// Whether to check that input files exist when constructing compilation 1463bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar /// jobs. 1473bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CheckInputsExist : 1; 1483bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 1490f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Use the clang compiler where possible. 1503bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUseClang : 1; 151365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1520f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Use clang for handling C++ and Objective-C++ inputs. 1533bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUseClangCXX : 1; 154365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1550f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Use clang as a preprocessor (clang's preprocessor will still be 1560f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// used where an integrated CPP would). 1573bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUseClangCPP : 1; 158365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 159d6277fb9e0353edffc0d6c8655a65542c08cf6f1Argyrios Kyrtzidis /// \brief Force use of clang frontend. 160d6277fb9e0353edffc0d6c8655a65542c08cf6f1Argyrios Kyrtzidis unsigned ForcedClangUse : 1; 161d6277fb9e0353edffc0d6c8655a65542c08cf6f1Argyrios Kyrtzidis 162df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorpublic: 163df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor /// Use lazy precompiled headers for PCH support. 1643bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUsePCH : 1; 165df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor 166df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorprivate: 1670f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Only use clang for the given architectures (only used when 1680f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// non-empty). 169a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar std::set<llvm::Triple::ArchType> CCCClangArchs; 170365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 171365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Certain options suppress the 'no input files' warning. 172365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar bool SuppressMissingInputWarning : 1; 1731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 174365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::list<std::string> TempFiles; 175365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::list<std::string> ResultFiles; 176365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 17718d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth /// \brief Cache of all the ToolChains in use by the driver. 17818d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth /// 17918d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth /// This maps from the string representation of a triple to a ToolChain 18048d798ce32447607144db70a484cdb99c1180663Benjamin Kramer /// created targeting that triple. The driver owns all the ToolChain objects 18118d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth /// stored in it, and will clean them up when torn down. 18218d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth mutable llvm::StringMap<ToolChain *> ToolChains; 18318d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth 184279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbarprivate: 185279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// TranslateInputArgs - Create a new derived argument list from the input 186279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// arguments, after applying the standard argument translations. 187279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar DerivedArgList *TranslateInputArgs(const InputArgList &Args) const; 188279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar 1891fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier // getFinalPhase - Determine which compilation mode we are in and record 1901fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier // which option we used to determine the final phase. 1911fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier phases::ID getFinalPhase(const DerivedArgList &DAL, Arg **FinalPhaseArg = 0) 1921fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier const; 1931fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier 1943ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarpublic: 195686775deca8b8685eb90801495880e3abdd844c2Chris Lattner Driver(StringRef _ClangExecutable, 1969606a57b6f2c43bf438a958fdffea1de60f6b2b7Sebastian Pop StringRef _DefaultTargetTriple, 197686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef _DefaultImageName, 19810a82cde7c317c5dd41dc3faf17f503c52ce2a3dBob Wilson bool IsProduction, 199d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine &_Diags); 2003ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar ~Driver(); 2013ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 202cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Accessors 203cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 204cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 205b8a3e8139b9fe513500c89bbcd9133415654a689Dylan Noblesmith /// Name to use when invoking gcc/g++. 20679e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; } 20779e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 20879e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 2091b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar const OptTable &getOpts() const { return *Opts; } 2101b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar 211d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie const DiagnosticsEngine &getDiags() const { return Diags; } 212af96def468042cfbed55a4cc12b1bb917ead4f33Daniel Dunbar 2133bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar bool getCheckInputsExist() const { return CheckInputsExist; } 2143bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 2153bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar void setCheckInputsExist(bool Value) { CheckInputsExist = Value; } 2163bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 21743302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar const std::string &getTitle() { return DriverTitle; } 21843302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar void setTitle(std::string Value) { DriverTitle = Value; } 21943302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar 220b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar /// \brief Get the path to the main clang executable. 221a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar const char *getClangProgramPath() const { 222a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar return ClangExecutable.c_str(); 223b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar } 224b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar 225edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar /// \brief Get the path to where the clang executable was installed. 226edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar const char *getInstalledDir() const { 227edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar if (!InstalledDir.empty()) 228edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar return InstalledDir.c_str(); 229edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar return Dir.c_str(); 230edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar } 231686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void setInstalledDir(StringRef Value) { 232edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar InstalledDir = Value; 233edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar } 234edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar 235d6277fb9e0353edffc0d6c8655a65542c08cf6f1Argyrios Kyrtzidis bool shouldForceClangUse() const { return ForcedClangUse; } 236d6277fb9e0353edffc0d6c8655a65542c08cf6f1Argyrios Kyrtzidis void setForcedClangUse(bool V = true) { ForcedClangUse = V; } 237d6277fb9e0353edffc0d6c8655a65542c08cf6f1Argyrios Kyrtzidis 238cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 239cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Primary Functionality 240cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 241cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 2423ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar /// BuildCompilation - Construct a compilation object for a command 2433ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar /// line argument vector. 244cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// 245cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// \return A compilation, or 0 if none was built for the given 246cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// argument vector. A null return value does not necessarily 247cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// indicate an error condition, the diagnostics should be queried 248cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// to determine if an error occurred. 2492d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner Compilation *BuildCompilation(ArrayRef<const char *> Args); 250365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 251cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Driver Steps 252cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 25353ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar 25457b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// ParseArgStrings - Parse the given list of strings into an 25557b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// ArgList. 2562d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner InputArgList *ParseArgStrings(ArrayRef<const char *> Args); 25757b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar 258be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier /// BuildInputs - Construct the list of inputs and their types from 259be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier /// the given arguments. 260be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier /// 261be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier /// \param TC - The default host tool chain. 262be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier /// \param Args - The input arguments. 263be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier /// \param Inputs - The list to store the resulting compilation 264be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier /// inputs onto. 265be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier void BuildInputs(const ToolChain &TC, const DerivedArgList &Args, 266be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier InputList &Inputs) const; 267be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier 26857b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildActions - Construct the list of actions to perform for the 26957b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// given arguments, which are only done for a single architecture. 27053ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// 27174edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar /// \param TC - The default host tool chain. 27253ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Args - The input arguments. 27353ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Actions - The list to store the resulting actions onto. 27465f7165676854bf75494f5b73a620d7237db5d41Joerg Sonnenberger void BuildActions(const ToolChain &TC, const DerivedArgList &Args, 275be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier const InputList &Inputs, ActionList &Actions) const; 27653ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar 27757b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildUniversalActions - Construct the list of actions to perform 27857b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// for the given arguments, which may require a universal build. 27953ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// 28074edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar /// \param TC - The default host tool chain. 28153ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Args - The input arguments. 28253ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Actions - The list to store the resulting actions onto. 28365f7165676854bf75494f5b73a620d7237db5d41Joerg Sonnenberger void BuildUniversalActions(const ToolChain &TC, const DerivedArgList &Args, 284be69f6092668b0586c8729855c01ca2eea22e6feChad Rosier const InputList &BAInputs, 28574edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar ActionList &Actions) const; 28657b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar 28757b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildJobs - Bind actions to concrete tools and translate 28857b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// arguments to form the list of jobs to run. 289586dc233bb88f2920c9f3638f69cef0ccd55dcedDaniel Dunbar /// 2901824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// \param C - The compilation that is being built. 29121549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar void BuildJobs(Compilation &C) const; 292cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 293c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// ExecuteCompilation - Execute the compilation according to the command line 294c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// arguments and return an appropriate exit code. 295c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// 296c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// This routine handles additional processing that must be done in addition 297c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// to just running the subprocesses, for example reporting errors, removing 298c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// temporary files, etc. 2992b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier int ExecuteCompilation(const Compilation &C, 3002b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier const Command *&FailingCommand) const; 3012b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier 3022b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier /// generateCompilationDiagnostics - Generate diagnostics information 3032b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier /// including preprocessed source file(s). 3042b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier /// 3052b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier void generateCompilationDiagnostics(Compilation &C, 3062b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier const Command *FailingCommand); 307c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar 308cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 309cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Helper Methods 310cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 311cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 31291e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar /// PrintActions - Print the list of actions. 31391e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar void PrintActions(const Compilation &C) const; 31491e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar 315c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// PrintHelp - Print the help text. 316c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// 317c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// \param ShowHidden - Show hidden options. 318c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar void PrintHelp(bool ShowHidden) const; 31991e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar 320cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// PrintOptions - Print the list of arguments. 321cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar void PrintOptions(const ArgList &Args) const; 322cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 323cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// PrintVersion - Print the driver version. 3248cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void PrintVersion(const Compilation &C, raw_ostream &OS) const; 325cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 3261824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// GetFilePath - Lookup \p Name in the list of file search paths. 3272ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// 3281824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// \param TC - The tool chain for additional information on 32921549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// directories to search. 3305ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar // 331cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // FIXME: This should be in CompilationInfo. 3325ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar std::string GetFilePath(const char *Name, const ToolChain &TC) const; 333cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 3341824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// GetProgramPath - Lookup \p Name in the list of program search paths. 3352ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// 3361824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// \param TC - The provided tool chain for additional information on 33721549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// directories to search. 3385ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar // 339cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // FIXME: This should be in CompilationInfo. 340fc44e88cbdf013d285f2e4e3962fb80dcad56770Simon Atanasyan std::string GetProgramPath(const char *Name, const ToolChain &TC) const; 341cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 342cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// HandleImmediateArgs - Handle any arguments which should be 343cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// treated before building actions or binding tools. 344cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// 345cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// \return Whether any compilation should be built for this 346cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// invocation. 34721549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar bool HandleImmediateArgs(const Compilation &C); 348cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 349ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// ConstructAction - Construct the appropriate action to do for 3501824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// \p Phase on the \p Input, taking in to account arguments 351ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// like -fsyntax-only or --analyze. 352ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase, 353ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar Action *Input) const; 354ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar 355f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 356f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// BuildJobsForAction - Construct the jobs to perform for the 3571824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// action \p A. 358f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar void BuildJobsForAction(Compilation &C, 359f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const Action *A, 360f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const ToolChain *TC, 3614954018954bbc97363eef02d0c83bea19ce9b329Daniel Dunbar const char *BoundArch, 362f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar bool AtTopLevel, 363f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const char *LinkingOutput, 364f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar InputInfo &Result) const; 365f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 366441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// GetNamedOutputPath - Return the name to use for the output of 3671824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// the action \p JA. The result is appended to the compilation's 368441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// list of temporary or result files, as appropriate. 369441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// 370441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param C - The compilation. 371441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param JA - The action of interest. 372441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param BaseInput - The original input file that this action was 373441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// triggered by. 374441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param AtTopLevel - Whether this is a "top-level" action. 3751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const char *GetNamedOutputPath(Compilation &C, 376441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar const JobAction &JA, 377441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar const char *BaseInput, 378441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar bool AtTopLevel) const; 379441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar 380fe87fc73c0091a8d6ba04b7e3b5f144d4a0517a3Chad Rosier /// GetTemporaryPath - Return the pathname of a temporary file to use 381fe87fc73c0091a8d6ba04b7e3b5f144d4a0517a3Chad Rosier /// as part of compilation; the file will have the given prefix and suffix. 382214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// 383214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// GCC goes to extra lengths here to be a bit more robust. 384f43b5e84aa982afacd87a225440ec88a9b66c1a0Chad Rosier std::string GetTemporaryPath(StringRef Prefix, const char *Suffix) const; 3851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 386af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar /// ShouldUseClangCompilar - Should the clang compiler be used to 387af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar /// handle this action. 3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, 389a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar const llvm::Triple &ArchName) const; 390af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar 391ed798951b46555946c95cb76568ea3cf0b16c9abDaniel Dunbar bool IsUsingLTO(const ArgList &Args) const; 392ed798951b46555946c95cb76568ea3cf0b16c9abDaniel Dunbar 39318d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruthprivate: 39418d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth /// \brief Retrieves a ToolChain for a particular target triple. 39518d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth /// 39618d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth /// Will cache ToolChains for the life of the driver object, and create them 39718d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth /// on-demand. 39818d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth const ToolChain &getToolChain(const ArgList &Args, 39918d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth StringRef DarwinArchName = "") const; 40018d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruth 401cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 402d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar 40318d7f3af752c41a197552a1ff25ddd639224b4bbChandler Carruthpublic: 404d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and 405d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// return the grouped values as integers. Numbers which are not 406d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// provided are set to 0. 407d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// 408d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// \return True if the entire string was parsed (9.2), or all 409d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// groups were parsed (10.3.5extrastuff). HadExtra is true if all 410d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// groups were parsed but extra characters remain at the end. 4111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool GetReleaseVersion(const char *Str, unsigned &Major, 412d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar unsigned &Minor, unsigned &Micro, 413d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar bool &HadExtra); 4143ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar}; 4153ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 4161b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar} // end namespace driver 4173ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar} // end namespace clang 4183ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 4193ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar#endif 420