Driver.h revision 65f7165676854bf75494f5b73a620d7237db5d41
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 { 27793007242ba209b68ce14ec7547ac70ee981303aDaniel Dunbar class raw_ostream; 28793007242ba209b68ce14ec7547ac70ee981303aDaniel Dunbar} 293ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarnamespace clang { 301b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbarnamespace driver { 3153ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar class Action; 320648262df75d97b464c2be0ed867da3615659785Daniel Dunbar class ArgList; 333ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar class Compilation; 34279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar class DerivedArgList; 35365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar class HostInfo; 36f3cad36e59a41b5767fe662b5ac8911ee174b801Daniel Dunbar class InputArgList; 37f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar class InputInfo; 38441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar class JobAction; 391b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar class OptTable; 40cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar class ToolChain; 413ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 423ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar/// Driver - Encapsulate logic for constructing compilation processes 433ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar/// from a set of gcc-driver-like command line arguments. 443ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarclass Driver { 451b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar OptTable *Opts; 461b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar 474ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar Diagnostic &Diags; 484ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar 491d46033f760ba5fd266ce59fe391fac473f04f52Daniel Dunbarpublic: 504ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar // Diag - Forwarding function for diagnostics. 5157b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar DiagnosticBuilder Diag(unsigned DiagID) const { 520f9fed70cea107b3f79df554e38bd8e98d48fe47Daniel Dunbar return Diags.Report(DiagID); 534ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar } 544ad4b3ebbe5769143389dccfcfadb666a4ba5940Daniel Dunbar 55365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar // FIXME: Privatize once interface is stable. 56365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbarpublic: 57365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// The name the driver was invoked as. 58365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string Name; 591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// The path the driver executable was in, as invoked from the 61365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// command line. 62365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string Dir; 631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar /// The original path to the clang executable. 65b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar std::string ClangExecutable; 66b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar 67edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar /// The path to the installed clang directory, if any. 68edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar std::string InstalledDir; 69edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar 70225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar /// The path to the compiler resource directory. 71225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar std::string ResourceDir; 72225c41706dc0f3682236e351820d339e14390e00Daniel Dunbar 7348ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// A prefix directory used to emulated a limited subset of GCC's '-Bprefix' 7448ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// functionality. 7548ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// FIXME: This type of customization should be removed in favor of the 7648ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth /// universal driver when it is ready. 7709982cec0029bc495591067fa89967b6b4d1fa19Benjamin Kramer typedef llvm::SmallVector<std::string, 4> prefix_list; 7809982cec0029bc495591067fa89967b6b4d1fa19Benjamin Kramer prefix_list PrefixDirs; 7948ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth 80dd98e2cad165ca73c769e4f105a4e47c2216387aDaniel Dunbar /// Default host triple. 81dd98e2cad165ca73c769e4f105a4e47c2216387aDaniel Dunbar std::string DefaultHostTriple; 82365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 83f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// Default name for linked images (e.g., "a.out"). 84f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar std::string DefaultImageName; 85f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 8643302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar /// Driver title to use with help. 8743302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar std::string DriverTitle; 8843302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar 89365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Host information for the platform the driver is running as. This 90365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// will generally be the actual host platform, but not always. 911fd6c4b8abbbdcbae0e221f35100102112dabff2Daniel Dunbar const HostInfo *Host; 92365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 93365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Information about the host which can be overriden by the user. 94365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string HostBits, HostMachine, HostSystem, HostRelease; 95365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 964c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// The file to log CC_PRINT_OPTIONS output to, if enabled. 974c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar const char *CCPrintOptionsFilename; 984c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar 99322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar /// The file to log CC_PRINT_HEADERS output to, if enabled. 100322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar const char *CCPrintHeadersFilename; 101322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar 102365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Whether the driver should follow g++ like behavior. 1033bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCIsCXX : 1; 1041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1059ade4ae4fb7ed1fcbd63835d9f8f53052f0657a2Joerg Sonnenberger /// Whether the driver is just the preprocessor 1069ade4ae4fb7ed1fcbd63835d9f8f53052f0657a2Joerg Sonnenberger unsigned CCCIsCPP : 1; 1079ade4ae4fb7ed1fcbd63835d9f8f53052f0657a2Joerg Sonnenberger 108365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Echo commands while executing (in -v style). 1093bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCEcho : 1; 110365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1115c3c1d7b494660ba5e8983ee4584622750725ac2Daniel Dunbar /// Only print tool bindings, don't build any jobs. 1123bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCPrintBindings : 1; 11378d8a089c8f124ba6f47bb37e2c4a36986f60e23Daniel Dunbar 1144c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to 1154c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// CCPrintOptionsFilename or to stderr. 1164c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar unsigned CCPrintOptions : 1; 1174c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar 118322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar /// Set CC_PRINT_HEADERS mode, which causes the frontend to log header include 119322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar /// information to CCPrintHeadersFilename or to stderr. 120322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar unsigned CCPrintHeaders : 1; 121322c29fefe7fa33f03273136eb5f8b7f5b4df7c0Daniel Dunbar 122af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbarprivate: 12379e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola /// Name to use when calling the generic gcc. 12479e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola std::string CCCGenericGCCName; 12579e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 1263bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar /// Whether to check that input files exist when constructing compilation 1273bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar /// jobs. 1283bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CheckInputsExist : 1; 1293bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 1300f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Use the clang compiler where possible. 1313bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUseClang : 1; 132365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1330f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Use clang for handling C++ and Objective-C++ inputs. 1343bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUseClangCXX : 1; 135365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1360f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Use clang as a preprocessor (clang's preprocessor will still be 1370f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// used where an integrated CPP would). 1383bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUseClangCPP : 1; 139365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 140df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorpublic: 141df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor /// Use lazy precompiled headers for PCH support. 1423bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUsePCH : 1; 143df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor 144df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorprivate: 1450f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Only use clang for the given architectures (only used when 1460f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// non-empty). 147a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar std::set<llvm::Triple::ArchType> CCCClangArchs; 148365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 149365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Certain options suppress the 'no input files' warning. 150365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar bool SuppressMissingInputWarning : 1; 1511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 152365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::list<std::string> TempFiles; 153365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::list<std::string> ResultFiles; 154365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 155279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbarprivate: 156279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// TranslateInputArgs - Create a new derived argument list from the input 157279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// arguments, after applying the standard argument translations. 158279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar DerivedArgList *TranslateInputArgs(const InputArgList &Args) const; 159279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar 1603ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarpublic: 1610bbad519aa068206f1e158d5073f72a39fbe83c5Daniel Dunbar Driver(llvm::StringRef _ClangExecutable, 162e3fdca2ee0346a41d9cc5ee417a75e66274216f5Jeffrey Yasskin llvm::StringRef _DefaultHostTriple, 163e3fdca2ee0346a41d9cc5ee417a75e66274216f5Jeffrey Yasskin llvm::StringRef _DefaultImageName, 1645d93ed3c7a2dae0a8f422747e269963b3ef11d95Daniel Dunbar bool IsProduction, bool CXXIsProduction, 1655d93ed3c7a2dae0a8f422747e269963b3ef11d95Daniel Dunbar Diagnostic &_Diags); 1663ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar ~Driver(); 1673ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 168cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Accessors 169cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 170cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 17179e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola /// Name to use when calling the generic gcc. 17279e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; } 17379e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 17479e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 1751b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar const OptTable &getOpts() const { return *Opts; } 1761b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar 177af96def468042cfbed55a4cc12b1bb917ead4f33Daniel Dunbar const Diagnostic &getDiags() const { return Diags; } 178af96def468042cfbed55a4cc12b1bb917ead4f33Daniel Dunbar 1793bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar bool getCheckInputsExist() const { return CheckInputsExist; } 1803bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 1813bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar void setCheckInputsExist(bool Value) { CheckInputsExist = Value; } 1823bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 18343302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar const std::string &getTitle() { return DriverTitle; } 18443302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar void setTitle(std::string Value) { DriverTitle = Value; } 18543302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar 186b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar /// \brief Get the path to the main clang executable. 187a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar const char *getClangProgramPath() const { 188a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar return ClangExecutable.c_str(); 189b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar } 190b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar 191edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar /// \brief Get the path to where the clang executable was installed. 192edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar const char *getInstalledDir() const { 193edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar if (!InstalledDir.empty()) 194edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar return InstalledDir.c_str(); 195edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar return Dir.c_str(); 196edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar } 197edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar void setInstalledDir(llvm::StringRef Value) { 198edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar InstalledDir = Value; 199edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar } 200edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar 201cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 202cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Primary Functionality 203cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 204cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 2053ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar /// BuildCompilation - Construct a compilation object for a command 2063ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar /// line argument vector. 207cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// 208cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// \return A compilation, or 0 if none was built for the given 209cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// argument vector. A null return value does not necessarily 210cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// indicate an error condition, the diagnostics should be queried 211cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// to determine if an error occurred. 2123ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar Compilation *BuildCompilation(int argc, const char **argv); 213365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 214cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Driver Steps 215cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 21653ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar 21757b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// ParseArgStrings - Parse the given list of strings into an 21857b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// ArgList. 219f3cad36e59a41b5767fe662b5ac8911ee174b801Daniel Dunbar InputArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd); 22057b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar 22157b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildActions - Construct the list of actions to perform for the 22257b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// given arguments, which are only done for a single architecture. 22353ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// 22474edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar /// \param TC - The default host tool chain. 22553ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Args - The input arguments. 22653ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Actions - The list to store the resulting actions onto. 22765f7165676854bf75494f5b73a620d7237db5d41Joerg Sonnenberger void BuildActions(const ToolChain &TC, const DerivedArgList &Args, 22874edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar ActionList &Actions) const; 22953ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar 23057b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildUniversalActions - Construct the list of actions to perform 23157b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// for the given arguments, which may require a universal build. 23253ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// 23374edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar /// \param TC - The default host tool chain. 23453ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Args - The input arguments. 23553ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Actions - The list to store the resulting actions onto. 23665f7165676854bf75494f5b73a620d7237db5d41Joerg Sonnenberger void BuildUniversalActions(const ToolChain &TC, const DerivedArgList &Args, 23774edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar ActionList &Actions) const; 23857b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar 23957b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildJobs - Bind actions to concrete tools and translate 24057b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// arguments to form the list of jobs to run. 241586dc233bb88f2920c9f3638f69cef0ccd55dcedDaniel Dunbar /// 242586dc233bb88f2920c9f3638f69cef0ccd55dcedDaniel Dunbar /// \arg C - The compilation that is being built. 24321549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar void BuildJobs(Compilation &C) const; 244cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 245c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// ExecuteCompilation - Execute the compilation according to the command line 246c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// arguments and return an appropriate exit code. 247c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// 248c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// This routine handles additional processing that must be done in addition 249c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// to just running the subprocesses, for example reporting errors, removing 250c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// temporary files, etc. 251c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar int ExecuteCompilation(const Compilation &C) const; 252c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar 253cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 254cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Helper Methods 255cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 256cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 25791e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar /// PrintActions - Print the list of actions. 25891e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar void PrintActions(const Compilation &C) const; 25991e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar 260c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// PrintHelp - Print the help text. 261c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// 262c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// \param ShowHidden - Show hidden options. 263c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar void PrintHelp(bool ShowHidden) const; 26491e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar 265cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// PrintOptions - Print the list of arguments. 266cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar void PrintOptions(const ArgList &Args) const; 267cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 268cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// PrintVersion - Print the driver version. 269793007242ba209b68ce14ec7547ac70ee981303aDaniel Dunbar void PrintVersion(const Compilation &C, llvm::raw_ostream &OS) const; 270cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 271cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// GetFilePath - Lookup \arg Name in the list of file search paths. 2722ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// 27321549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// \arg TC - The tool chain for additional information on 27421549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// directories to search. 2755ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar // 276cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // FIXME: This should be in CompilationInfo. 2775ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar std::string GetFilePath(const char *Name, const ToolChain &TC) const; 278cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 279cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// GetProgramPath - Lookup \arg Name in the list of program search 280cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// paths. 2812ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// 28221549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// \arg TC - The provided tool chain for additional information on 28321549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// directories to search. 284950bedd8a9f00caabd2f1fc6812d70e08103f847Mike Stump /// 285950bedd8a9f00caabd2f1fc6812d70e08103f847Mike Stump /// \arg WantFile - False when searching for an executable file, otherwise 286950bedd8a9f00caabd2f1fc6812d70e08103f847Mike Stump /// true. Defaults to false. 2875ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar // 288cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // FIXME: This should be in CompilationInfo. 2895ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar std::string GetProgramPath(const char *Name, const ToolChain &TC, 2905ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar bool WantFile = false) const; 291cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 292cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// HandleImmediateArgs - Handle any arguments which should be 293cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// treated before building actions or binding tools. 294cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// 295cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// \return Whether any compilation should be built for this 296cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// invocation. 29721549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar bool HandleImmediateArgs(const Compilation &C); 298cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 299ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// ConstructAction - Construct the appropriate action to do for 300ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// \arg Phase on the \arg Input, taking in to account arguments 301ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// like -fsyntax-only or --analyze. 302ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase, 303ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar Action *Input) const; 304ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar 305f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 306f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// BuildJobsForAction - Construct the jobs to perform for the 307f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// action \arg A. 308f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar void BuildJobsForAction(Compilation &C, 309f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const Action *A, 310f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const ToolChain *TC, 3114954018954bbc97363eef02d0c83bea19ce9b329Daniel Dunbar const char *BoundArch, 312f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar bool AtTopLevel, 313f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const char *LinkingOutput, 314f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar InputInfo &Result) const; 315f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 316441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// GetNamedOutputPath - Return the name to use for the output of 317441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// the action \arg JA. The result is appended to the compilation's 318441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// list of temporary or result files, as appropriate. 319441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// 320441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param C - The compilation. 321441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param JA - The action of interest. 322441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param BaseInput - The original input file that this action was 323441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// triggered by. 324441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param AtTopLevel - Whether this is a "top-level" action. 3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const char *GetNamedOutputPath(Compilation &C, 326441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar const JobAction &JA, 327441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar const char *BaseInput, 328441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar bool AtTopLevel) const; 329441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar 330214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// GetTemporaryPath - Return the pathname of a temporary file to 331214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// use as part of compilation; the file will have the given suffix. 332214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// 333214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// GCC goes to extra lengths here to be a bit more robust. 334214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar std::string GetTemporaryPath(const char *Suffix) const; 3351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 336cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// GetHostInfo - Construct a new host info object for the given 337cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// host triple. 338e504952bc89f79fc9ff54d5641ab30bb07ec435eDaniel Dunbar const HostInfo *GetHostInfo(const char *HostTriple) const; 339cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 340af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar /// ShouldUseClangCompilar - Should the clang compiler be used to 341af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar /// handle this action. 3421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, 343a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar const llvm::Triple &ArchName) const; 344af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar 345cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 346d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar 347d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and 348d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// return the grouped values as integers. Numbers which are not 349d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// provided are set to 0. 350d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// 351d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// \return True if the entire string was parsed (9.2), or all 352d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// groups were parsed (10.3.5extrastuff). HadExtra is true if all 353d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// groups were parsed but extra characters remain at the end. 3541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool GetReleaseVersion(const char *Str, unsigned &Major, 355d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar unsigned &Minor, unsigned &Micro, 356d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar bool &HadExtra); 3573ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar}; 3583ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 3591b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar} // end namespace driver 3603ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar} // end namespace clang 3613ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 3623ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar#endif 363