Driver.h revision 2b81910618f63e4ce2373c926a26e76b4b91373f
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" 16d65bddcbe1385a4de212ecbbdc8919c54b3efeb0Daniel Dunbar#include "clang/Driver/Util.h" 17d65bddcbe1385a4de212ecbbdc8919c54b3efeb0Daniel Dunbar 18e3fdca2ee0346a41d9cc5ee417a75e66274216f5Jeffrey Yasskin#include "llvm/ADT/StringRef.h" 19a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar#include "llvm/ADT/Triple.h" 2003013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/Path.h" // FIXME: Kill when CompilationInfo 21cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // lands. 22365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar#include <list> 23365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar#include <set> 24365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar#include <string> 25365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 26793007242ba209b68ce14ec7547ac70ee981303aDaniel Dunbarnamespace llvm { 277f9fc3f7ce076645cb6aefc99c64d9446caf13d6Chris Lattner template<typename T> class ArrayRef; 28793007242ba209b68ce14ec7547ac70ee981303aDaniel Dunbar} 293ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarnamespace clang { 301b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbarnamespace driver { 3153ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar class Action; 321fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier class Arg; 330648262df75d97b464c2be0ed867da3615659785Daniel Dunbar class ArgList; 342b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier class Command; 353ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar class Compilation; 36279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar class DerivedArgList; 37365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar class HostInfo; 38f3cad36e59a41b5767fe662b5ac8911ee174b801Daniel Dunbar class InputArgList; 39f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar class InputInfo; 40441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar class JobAction; 411b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar class OptTable; 42cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar class ToolChain; 433ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 443ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar/// Driver - Encapsulate logic for constructing compilation processes 453ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar/// from a set of gcc-driver-like command line arguments. 463ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarclass Driver { 471b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar OptTable *Opts; 481b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar 494ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar Diagnostic &Diags; 504ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar 511d46033f760ba5fd266ce59fe391fac473f04f52Daniel Dunbarpublic: 524ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar // Diag - Forwarding function for diagnostics. 5357b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar DiagnosticBuilder Diag(unsigned DiagID) const { 540f9fed70cea107b3f79df554e38bd8e98d48fe47Daniel Dunbar return Diags.Report(DiagID); 554ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar } 564ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar 57365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar // FIXME: Privatize once interface is stable. 58365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbarpublic: 59365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// The name the driver was invoked as. 60365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string Name; 611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// The path the driver executable was in, as invoked from the 63365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// command line. 64365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string Dir; 651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar /// The original path to the clang executable. 67b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar std::string ClangExecutable; 68b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar 69edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar /// The path to the installed clang directory, if any. 70edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar std::string InstalledDir; 71edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar 72225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar /// The path to the compiler resource directory. 73225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar std::string ResourceDir; 74225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar 7548ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// A prefix directory used to emulated a limited subset of GCC's '-Bprefix' 7648ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// functionality. 7748ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// FIXME: This type of customization should be removed in favor of the 7848ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// universal driver when it is ready. 79686775deca8b8685eb90801495880e3abdd844c2Chris Lattner typedef SmallVector<std::string, 4> prefix_list; 8009982cec0029bc495591067fa89967b6b4d1fa19Benjamin Kramer prefix_list PrefixDirs; 8148ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth 828ab2bdcc4f397e100c684ede8e8ca6e226e1380aJoerg Sonnenberger /// sysroot, if present 838ab2bdcc4f397e100c684ede8e8ca6e226e1380aJoerg Sonnenberger std::string SysRoot; 848ab2bdcc4f397e100c684ede8e8ca6e226e1380aJoerg Sonnenberger 8505e5930166333e382522b942f00d08abc6c0a28eJoerg Sonnenberger /// If the standard library is used 8605e5930166333e382522b942f00d08abc6c0a28eJoerg Sonnenberger bool UseStdLib; 8705e5930166333e382522b942f00d08abc6c0a28eJoerg Sonnenberger 88dd98e2cad165ca73c769e4f105a4e47c2216387aDaniel Dunbar /// Default host triple. 89dd98e2cad165ca73c769e4f105a4e47c2216387aDaniel Dunbar std::string DefaultHostTriple; 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 97365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Host information for the platform the driver is running as. This 98365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// will generally be the actual host platform, but not always. 991fd6c4b8abbbdcbae0e221f35100102112dabff2Daniel Dunbar const HostInfo *Host; 100365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1014c8acc9b0158081635e1dabd49304377ae67ca98Michael J. Spencer /// Information about the host which can be overridden by the user. 102365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string HostBits, HostMachine, HostSystem, HostRelease; 103365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1044c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// The file to log CC_PRINT_OPTIONS output to, if enabled. 1054c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar const char *CCPrintOptionsFilename; 1064c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar 107322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar /// The file to log CC_PRINT_HEADERS output to, if enabled. 108322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar const char *CCPrintHeadersFilename; 109322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar 110c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled. 111c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar const char *CCLogDiagnosticsFilename; 112c8a22b091677c02003880166e5d5767ca8d74b70Daniel Dunbar 113365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Whether the driver should follow g++ like behavior. 1143bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCIsCXX : 1; 1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1169ade4ae4fb7ed1fcbd63835d9f8f53052f0657a2Joerg Sonnenberger /// 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 159df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorpublic: 160df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor /// Use lazy precompiled headers for PCH support. 1613bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUsePCH : 1; 162df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor 163df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorprivate: 1640f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Only use clang for the given architectures (only used when 1650f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// non-empty). 166a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar std::set<llvm::Triple::ArchType> CCCClangArchs; 167365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 168365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Certain options suppress the 'no input files' warning. 169365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar bool SuppressMissingInputWarning : 1; 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 171365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::list<std::string> TempFiles; 172365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::list<std::string> ResultFiles; 173365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 174279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbarprivate: 175279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// TranslateInputArgs - Create a new derived argument list from the input 176279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// arguments, after applying the standard argument translations. 177279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar DerivedArgList *TranslateInputArgs(const InputArgList &Args) const; 178279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar 1791fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier // getFinalPhase - Determine which compilation mode we are in and record 1801fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier // which option we used to determine the final phase. 1811fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier phases::ID getFinalPhase(const DerivedArgList &DAL, Arg **FinalPhaseArg = 0) 1821fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier const; 1831fc1de48cdf9a2f241e0f2c7b9e9db2322f1b794Chad Rosier 1843ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarpublic: 185686775deca8b8685eb90801495880e3abdd844c2Chris Lattner Driver(StringRef _ClangExecutable, 186686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef _DefaultHostTriple, 187686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef _DefaultImageName, 1885d93ed3c7a2dae0a8f422747e269963b3ef11d95Daniel Dunbar bool IsProduction, bool CXXIsProduction, 1895d93ed3c7a2dae0a8f422747e269963b3ef11d95Daniel Dunbar Diagnostic &_Diags); 1903ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar ~Driver(); 1913ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 192cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Accessors 193cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 194cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 195b8a3e8139b9fe513500c89bbcd9133415654a689Dylan Noblesmith /// Name to use when invoking gcc/g++. 19679e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; } 19779e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 19879e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 1991b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar const OptTable &getOpts() const { return *Opts; } 2001b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar 201af96def468042cfbed55a4cc12b1bb917ead4f33Daniel Dunbar const Diagnostic &getDiags() const { return Diags; } 202af96def468042cfbed55a4cc12b1bb917ead4f33Daniel Dunbar 2033bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar bool getCheckInputsExist() const { return CheckInputsExist; } 2043bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 2053bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar void setCheckInputsExist(bool Value) { CheckInputsExist = Value; } 2063bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 20743302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar const std::string &getTitle() { return DriverTitle; } 20843302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar void setTitle(std::string Value) { DriverTitle = Value; } 20943302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar 210b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar /// \brief Get the path to the main clang executable. 211a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar const char *getClangProgramPath() const { 212a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar return ClangExecutable.c_str(); 213b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar } 214b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar 215edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar /// \brief Get the path to where the clang executable was installed. 216edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar const char *getInstalledDir() const { 217edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar if (!InstalledDir.empty()) 218edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar return InstalledDir.c_str(); 219edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar return Dir.c_str(); 220edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar } 221686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void setInstalledDir(StringRef Value) { 222edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar InstalledDir = Value; 223edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar } 224edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar 225cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 226cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Primary Functionality 227cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 228cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 2293ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar /// BuildCompilation - Construct a compilation object for a command 2303ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar /// line argument vector. 231cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// 232cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// \return A compilation, or 0 if none was built for the given 233cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// argument vector. A null return value does not necessarily 234cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// indicate an error condition, the diagnostics should be queried 235cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// to determine if an error occurred. 2362d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner Compilation *BuildCompilation(ArrayRef<const char *> Args); 237365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 238cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Driver Steps 239cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 24053ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar 24157b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// ParseArgStrings - Parse the given list of strings into an 24257b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// ArgList. 2432d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner InputArgList *ParseArgStrings(ArrayRef<const char *> Args); 24457b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar 24557b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildActions - Construct the list of actions to perform for the 24657b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// given arguments, which are only done for a single architecture. 24753ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// 24874edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar /// \param TC - The default host tool chain. 24953ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Args - The input arguments. 25053ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Actions - The list to store the resulting actions onto. 25165f7165676854bf75494f5b73a620d7237db5d41Joerg Sonnenberger void BuildActions(const ToolChain &TC, const DerivedArgList &Args, 25274edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar ActionList &Actions) const; 25353ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar 25457b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildUniversalActions - Construct the list of actions to perform 25557b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// for the given arguments, which may require a universal build. 25653ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// 25774edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar /// \param TC - The default host tool chain. 25853ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Args - The input arguments. 25953ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Actions - The list to store the resulting actions onto. 26065f7165676854bf75494f5b73a620d7237db5d41Joerg Sonnenberger void BuildUniversalActions(const ToolChain &TC, const DerivedArgList &Args, 26174edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar ActionList &Actions) const; 26257b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar 26357b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildJobs - Bind actions to concrete tools and translate 26457b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// arguments to form the list of jobs to run. 265586dc233bb88f2920c9f3638f69cef0ccd55dcedDaniel Dunbar /// 266586dc233bb88f2920c9f3638f69cef0ccd55dcedDaniel Dunbar /// \arg C - The compilation that is being built. 26721549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar void BuildJobs(Compilation &C) const; 268cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 269c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// ExecuteCompilation - Execute the compilation according to the command line 270c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// arguments and return an appropriate exit code. 271c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// 272c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// This routine handles additional processing that must be done in addition 273c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// to just running the subprocesses, for example reporting errors, removing 274c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// temporary files, etc. 2752b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier int ExecuteCompilation(const Compilation &C, 2762b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier const Command *&FailingCommand) const; 2772b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier 2782b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier /// generateCompilationDiagnostics - Generate diagnostics information 2792b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier /// including preprocessed source file(s). 2802b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier /// 2812b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier void generateCompilationDiagnostics(Compilation &C, 2822b81910618f63e4ce2373c926a26e76b4b91373fChad Rosier const Command *FailingCommand); 283c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar 284cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 285cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Helper Methods 286cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 287cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 28891e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar /// PrintActions - Print the list of actions. 28991e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar void PrintActions(const Compilation &C) const; 29091e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar 291c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// PrintHelp - Print the help text. 292c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// 293c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// \param ShowHidden - Show hidden options. 294c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar void PrintHelp(bool ShowHidden) const; 29591e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar 296cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// PrintOptions - Print the list of arguments. 297cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar void PrintOptions(const ArgList &Args) const; 298cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 299cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// PrintVersion - Print the driver version. 3008cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void PrintVersion(const Compilation &C, raw_ostream &OS) const; 301cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 302cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// GetFilePath - Lookup \arg Name in the list of file search paths. 3032ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// 30421549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// \arg TC - The tool chain for additional information on 30521549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// directories to search. 3065ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar // 307cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // FIXME: This should be in CompilationInfo. 3085ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar std::string GetFilePath(const char *Name, const ToolChain &TC) const; 309cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 310cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// GetProgramPath - Lookup \arg Name in the list of program search 311cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// paths. 3122ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// 31321549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// \arg TC - The provided tool chain for additional information on 31421549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// directories to search. 315950bedd8a9f00caabd2f1fc6812d70e08103f847Mike Stump /// 316950bedd8a9f00caabd2f1fc6812d70e08103f847Mike Stump /// \arg WantFile - False when searching for an executable file, otherwise 317950bedd8a9f00caabd2f1fc6812d70e08103f847Mike Stump /// true. Defaults to false. 3185ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar // 319cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // FIXME: This should be in CompilationInfo. 3205ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar std::string GetProgramPath(const char *Name, const ToolChain &TC, 3215ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar bool WantFile = false) const; 322cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 323cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// HandleImmediateArgs - Handle any arguments which should be 324cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// treated before building actions or binding tools. 325cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// 326cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// \return Whether any compilation should be built for this 327cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// invocation. 32821549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar bool HandleImmediateArgs(const Compilation &C); 329cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 330ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// ConstructAction - Construct the appropriate action to do for 331ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// \arg Phase on the \arg Input, taking in to account arguments 332ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// like -fsyntax-only or --analyze. 333ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase, 334ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar Action *Input) const; 335ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar 336f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 337f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// BuildJobsForAction - Construct the jobs to perform for the 338f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// action \arg A. 339f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar void BuildJobsForAction(Compilation &C, 340f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const Action *A, 341f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const ToolChain *TC, 3424954018954bbc97363eef02d0c83bea19ce9b329Daniel Dunbar const char *BoundArch, 343f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar bool AtTopLevel, 344f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const char *LinkingOutput, 345f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar InputInfo &Result) const; 346f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 347441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// GetNamedOutputPath - Return the name to use for the output of 348441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// the action \arg JA. The result is appended to the compilation's 349441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// list of temporary or result files, as appropriate. 350441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// 351441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param C - The compilation. 352441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param JA - The action of interest. 353441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param BaseInput - The original input file that this action was 354441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// triggered by. 355441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param AtTopLevel - Whether this is a "top-level" action. 3561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const char *GetNamedOutputPath(Compilation &C, 357441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar const JobAction &JA, 358441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar const char *BaseInput, 359441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar bool AtTopLevel) const; 360441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar 361214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// GetTemporaryPath - Return the pathname of a temporary file to 362214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// use as part of compilation; the file will have the given suffix. 363214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// 364214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// GCC goes to extra lengths here to be a bit more robust. 365214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar std::string GetTemporaryPath(const char *Suffix) const; 3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 367cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// GetHostInfo - Construct a new host info object for the given 368cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// host triple. 369e504952bc89f79fc9ff54d5641ab30bb07ec435eDaniel Dunbar const HostInfo *GetHostInfo(const char *HostTriple) const; 370cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 371af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar /// ShouldUseClangCompilar - Should the clang compiler be used to 372af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar /// handle this action. 3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, 374a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar const llvm::Triple &ArchName) const; 375af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar 376ed798951b46555946c95cb76568ea3cf0b16c9abDaniel Dunbar bool IsUsingLTO(const ArgList &Args) const; 377ed798951b46555946c95cb76568ea3cf0b16c9abDaniel Dunbar 378cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 379d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar 380d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and 381d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// return the grouped values as integers. Numbers which are not 382d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// provided are set to 0. 383d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// 384d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// \return True if the entire string was parsed (9.2), or all 385d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// groups were parsed (10.3.5extrastuff). HadExtra is true if all 386d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// groups were parsed but extra characters remain at the end. 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool GetReleaseVersion(const char *Str, unsigned &Major, 388d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar unsigned &Minor, unsigned &Micro, 389d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar bool &HadExtra); 3903ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar}; 3913ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 3921b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar} // end namespace driver 3933ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar} // end namespace clang 3943ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 3953ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar#endif 396