Driver.h revision 03013fa9a0bf1ef4b907f5fec006c8f4000fdd21
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. 7748ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth std::string PrefixDir; 7848ad6094679ca2bf4f3593068e02e7a208c1a73cChandler Carruth 79dd98e2cad165ca73c769e4f105a4e47c2216387aDaniel Dunbar /// Default host triple. 80dd98e2cad165ca73c769e4f105a4e47c2216387aDaniel Dunbar std::string DefaultHostTriple; 81365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 82f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// Default name for linked images (e.g., "a.out"). 83f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar std::string DefaultImageName; 84f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 8543302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar /// Driver title to use with help. 8643302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar std::string DriverTitle; 8743302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar 88365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Host information for the platform the driver is running as. This 89365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// will generally be the actual host platform, but not always. 901fd6c4b8abbbdcbae0e221f35100102112dabff2Daniel Dunbar const HostInfo *Host; 91365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 92365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Information about the host which can be overriden by the user. 93365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::string HostBits, HostMachine, HostSystem, HostRelease; 94365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 954c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// The file to log CC_PRINT_OPTIONS output to, if enabled. 964c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar const char *CCPrintOptionsFilename; 974c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar 98365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Whether the driver should follow g++ like behavior. 993bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCIsCXX : 1; 1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Echo commands while executing (in -v style). 1023bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCEcho : 1; 103365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1045c3c1d7b494660ba5e8983ee4584622750725ac2Daniel Dunbar /// Only print tool bindings, don't build any jobs. 1053bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCPrintBindings : 1; 10678d8a089c8f124ba6f47bb37e2c4a36986f60e23Daniel Dunbar 1074c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to 1084c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar /// CCPrintOptionsFilename or to stderr. 1094c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar unsigned CCPrintOptions : 1; 1104c00fcdf98d3d7c4cb47b64f8b770f8f4bff1357Daniel Dunbar 111af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbarprivate: 11279e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola /// Name to use when calling the generic gcc. 11379e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola std::string CCCGenericGCCName; 11479e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 1153bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar /// Whether to check that input files exist when constructing compilation 1163bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar /// jobs. 1173bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CheckInputsExist : 1; 1183bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 1190f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Use the clang compiler where possible. 1203bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUseClang : 1; 121365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1220f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Use clang for handling C++ and Objective-C++ inputs. 1233bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUseClangCXX : 1; 124365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 1250f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Use clang as a preprocessor (clang's preprocessor will still be 1260f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// used where an integrated CPP would). 1273bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUseClangCPP : 1; 128365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 129df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorpublic: 130df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor /// Use lazy precompiled headers for PCH support. 1313bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar unsigned CCCUsePCH : 1; 132df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregor 133df91ef3d6c55692a0236f67b6c6b134a3bf84098Douglas Gregorprivate: 1340f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// Only use clang for the given architectures (only used when 1350f99d2e57d8e3cf2508e7f9f868d41eccdc229c9Daniel Dunbar /// non-empty). 136a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar std::set<llvm::Triple::ArchType> CCCClangArchs; 137365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 138365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar /// Certain options suppress the 'no input files' warning. 139365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar bool SuppressMissingInputWarning : 1; 1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::list<std::string> TempFiles; 142365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar std::list<std::string> ResultFiles; 143365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 144279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbarprivate: 145279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// TranslateInputArgs - Create a new derived argument list from the input 146279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar /// arguments, after applying the standard argument translations. 147279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar DerivedArgList *TranslateInputArgs(const InputArgList &Args) const; 148279c1dbebf37cd128f3c73c70741a6b8c35ad025Daniel Dunbar 1493ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbarpublic: 1500bbad519aa068206f1e158d5073f72a39fbe83c5Daniel Dunbar Driver(llvm::StringRef _ClangExecutable, 151e3fdca2ee0346a41d9cc5ee417a75e66274216f5Jeffrey Yasskin llvm::StringRef _DefaultHostTriple, 152e3fdca2ee0346a41d9cc5ee417a75e66274216f5Jeffrey Yasskin llvm::StringRef _DefaultImageName, 1535d93ed3c7a2dae0a8f422747e269963b3ef11d95Daniel Dunbar bool IsProduction, bool CXXIsProduction, 1545d93ed3c7a2dae0a8f422747e269963b3ef11d95Daniel Dunbar Diagnostic &_Diags); 1553ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar ~Driver(); 1563ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 157cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Accessors 158cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 159cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 16079e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola /// Name to use when calling the generic gcc. 16179e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; } 16279e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 16379e9e9dd533de9609ef141449bf50e705fa68fd0Rafael Espindola 1641b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar const OptTable &getOpts() const { return *Opts; } 1651b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar 166af96def468042cfbed55a4cc12b1bb917ead4f33Daniel Dunbar const Diagnostic &getDiags() const { return Diags; } 167af96def468042cfbed55a4cc12b1bb917ead4f33Daniel Dunbar 1683bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar bool getCheckInputsExist() const { return CheckInputsExist; } 1693bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 1703bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar void setCheckInputsExist(bool Value) { CheckInputsExist = Value; } 1713bd54cc56276c386f4d50940a9fbfcad7a69cb75Daniel Dunbar 17243302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar const std::string &getTitle() { return DriverTitle; } 17343302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar void setTitle(std::string Value) { DriverTitle = Value; } 17443302d4144b5291961aa160d2fe191c09a9d8ad1Daniel Dunbar 175b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar /// \brief Get the path to the main clang executable. 176a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar const char *getClangProgramPath() const { 177a001c1ce5fcb669624a5b8e50d0a629d673da901Daniel Dunbar return ClangExecutable.c_str(); 178b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar } 179b9a822639c570b1853c75c235e9d6bad485f9e01Daniel Dunbar 180edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar /// \brief Get the path to where the clang executable was installed. 181edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar const char *getInstalledDir() const { 182edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar if (!InstalledDir.empty()) 183edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar return InstalledDir.c_str(); 184edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar return Dir.c_str(); 185edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar } 186edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar void setInstalledDir(llvm::StringRef Value) { 187edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar InstalledDir = Value; 188edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar } 189edf29b00bc1641034b38be92146e15f0625a45d2Daniel Dunbar 190cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 191cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Primary Functionality 192cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 193cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 1943ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar /// BuildCompilation - Construct a compilation object for a command 1953ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar /// line argument vector. 196cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// 197cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// \return A compilation, or 0 if none was built for the given 198cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// argument vector. A null return value does not necessarily 199cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// indicate an error condition, the diagnostics should be queried 200cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// to determine if an error occurred. 2013ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar Compilation *BuildCompilation(int argc, const char **argv); 202365c02f65be026f90e67a8e00e7b827cee60e228Daniel Dunbar 203cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Driver Steps 204cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 20553ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar 20657b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// ParseArgStrings - Parse the given list of strings into an 20757b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// ArgList. 208f3cad36e59a41b5767fe662b5ac8911ee174b801Daniel Dunbar InputArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd); 20957b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar 21057b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildActions - Construct the list of actions to perform for the 21157b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// given arguments, which are only done for a single architecture. 21253ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// 21374edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar /// \param TC - The default host tool chain. 21453ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Args - The input arguments. 21553ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Actions - The list to store the resulting actions onto. 21674edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar void BuildActions(const ToolChain &TC, const ArgList &Args, 21774edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar ActionList &Actions) const; 21853ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar 21957b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildUniversalActions - Construct the list of actions to perform 22057b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// for the given arguments, which may require a universal build. 22153ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// 22274edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar /// \param TC - The default host tool chain. 22353ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Args - The input arguments. 22453ec55215075c8f4ddd47ca6ed7d382f16beb670Daniel Dunbar /// \param Actions - The list to store the resulting actions onto. 22574edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar void BuildUniversalActions(const ToolChain &TC, const ArgList &Args, 22674edcea3db1f85ba73ad0fede2ed5e2f096cac4bDaniel Dunbar ActionList &Actions) const; 22757b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar 22857b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// BuildJobs - Bind actions to concrete tools and translate 22957b704d8d8f49bcaf856a3e37941d5ac6456eb50Daniel Dunbar /// arguments to form the list of jobs to run. 230586dc233bb88f2920c9f3638f69cef0ccd55dcedDaniel Dunbar /// 231586dc233bb88f2920c9f3638f69cef0ccd55dcedDaniel Dunbar /// \arg C - The compilation that is being built. 23221549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar void BuildJobs(Compilation &C) const; 233cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 234c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// ExecuteCompilation - Execute the compilation according to the command line 235c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// arguments and return an appropriate exit code. 236c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// 237c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// This routine handles additional processing that must be done in addition 238c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// to just running the subprocesses, for example reporting errors, removing 239c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar /// temporary files, etc. 240c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar int ExecuteCompilation(const Compilation &C) const; 241c88a88f6f7672b6bb831dce9da4acfa0c846975fDaniel Dunbar 242cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 243cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @name Helper Methods 244cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @{ 245cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 24691e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar /// PrintActions - Print the list of actions. 24791e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar void PrintActions(const Compilation &C) const; 24891e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar 249c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// PrintHelp - Print the help text. 250c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// 251c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar /// \param ShowHidden - Show hidden options. 252c35d71f1e0a0c72fd43a73ddecd408bf43d501deDaniel Dunbar void PrintHelp(bool ShowHidden) const; 25391e28afe3503893c69afd71877f11e3bf03fa4ceDaniel Dunbar 254cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// PrintOptions - Print the list of arguments. 255cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar void PrintOptions(const ArgList &Args) const; 256cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 257cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// PrintVersion - Print the driver version. 258793007242ba209b68ce14ec7547ac70ee981303aDaniel Dunbar void PrintVersion(const Compilation &C, llvm::raw_ostream &OS) const; 259cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 260cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// GetFilePath - Lookup \arg Name in the list of file search paths. 2612ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// 26221549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// \arg TC - The tool chain for additional information on 26321549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// directories to search. 2645ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar // 265cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // FIXME: This should be in CompilationInfo. 2665ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar std::string GetFilePath(const char *Name, const ToolChain &TC) const; 267cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 268cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// GetProgramPath - Lookup \arg Name in the list of program search 269cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// paths. 2702ba38ba9a18b8ec88e2509fad622eeec01562769Daniel Dunbar /// 27121549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// \arg TC - The provided tool chain for additional information on 27221549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar /// directories to search. 273950bedd8a9f00caabd2f1fc6812d70e08103f847Mike Stump /// 274950bedd8a9f00caabd2f1fc6812d70e08103f847Mike Stump /// \arg WantFile - False when searching for an executable file, otherwise 275950bedd8a9f00caabd2f1fc6812d70e08103f847Mike Stump /// true. Defaults to false. 2765ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar // 277cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar // FIXME: This should be in CompilationInfo. 2785ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar std::string GetProgramPath(const char *Name, const ToolChain &TC, 2795ed34f4c58b6ad4e21038d713c1fae31a6146ff5Daniel Dunbar bool WantFile = false) const; 280cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 281cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// HandleImmediateArgs - Handle any arguments which should be 282cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// treated before building actions or binding tools. 283cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// 284cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// \return Whether any compilation should be built for this 285cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// invocation. 28621549237f14505cfc2a18a06416372a36229d0ceDaniel Dunbar bool HandleImmediateArgs(const Compilation &C); 287cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 288ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// ConstructAction - Construct the appropriate action to do for 289ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// \arg Phase on the \arg Input, taking in to account arguments 290ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar /// like -fsyntax-only or --analyze. 291ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase, 292ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar Action *Input) const; 293ad2a9af666efdd9afe3bb5f886bcb0d1c9a0f0c3Daniel Dunbar 294f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 295f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// BuildJobsForAction - Construct the jobs to perform for the 296f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar /// action \arg A. 297f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar void BuildJobsForAction(Compilation &C, 298f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const Action *A, 299f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const ToolChain *TC, 3004954018954bbc97363eef02d0c83bea19ce9b329Daniel Dunbar const char *BoundArch, 301f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar bool AtTopLevel, 302f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar const char *LinkingOutput, 303f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar InputInfo &Result) const; 304f353c8cc2ee1cc16ff194b399a8d951f707fb129Daniel Dunbar 305441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// GetNamedOutputPath - Return the name to use for the output of 306441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// the action \arg JA. The result is appended to the compilation's 307441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// list of temporary or result files, as appropriate. 308441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// 309441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param C - The compilation. 310441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param JA - The action of interest. 311441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param BaseInput - The original input file that this action was 312441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// triggered by. 313441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar /// \param AtTopLevel - Whether this is a "top-level" action. 3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const char *GetNamedOutputPath(Compilation &C, 315441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar const JobAction &JA, 316441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar const char *BaseInput, 317441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar bool AtTopLevel) const; 318441d060838a5797691777dfcc992ff836b73dcd1Daniel Dunbar 319214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// GetTemporaryPath - Return the pathname of a temporary file to 320214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// use as part of compilation; the file will have the given suffix. 321214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// 322214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar /// GCC goes to extra lengths here to be a bit more robust. 323214399ebd73545dde02b4a45872e7ca9e1d9e742Daniel Dunbar std::string GetTemporaryPath(const char *Suffix) const; 3241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 325cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// GetHostInfo - Construct a new host info object for the given 326cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// host triple. 327e504952bc89f79fc9ff54d5641ab30bb07ec435eDaniel Dunbar const HostInfo *GetHostInfo(const char *HostTriple) const; 328cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar 329af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar /// ShouldUseClangCompilar - Should the clang compiler be used to 330af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar /// handle this action. 3311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, 332a6046bec7fc835186dde134fb81aa1b7d45cd9f0Daniel Dunbar const llvm::Triple &ArchName) const; 333af80e1ffafeb77929cc0b9ba8940a7f1c0b80d51Daniel Dunbar 334cb881672c2c46142ec1bdfa401c9818ae805db0fDaniel Dunbar /// @} 335d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar 336d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and 337d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// return the grouped values as integers. Numbers which are not 338d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// provided are set to 0. 339d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// 340d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// \return True if the entire string was parsed (9.2), or all 341d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// groups were parsed (10.3.5extrastuff). HadExtra is true if all 342d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar /// groups were parsed but extra characters remain at the end. 3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool GetReleaseVersion(const char *Str, unsigned &Major, 344d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar unsigned &Minor, unsigned &Micro, 345d73fe9b70c5f6738d004744562287a62831f39bfDaniel Dunbar bool &HadExtra); 3463ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar}; 3473ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 3481b3bb6efc59a21f794b534078f9ae7e95393f510Daniel Dunbar} // end namespace driver 3493ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar} // end namespace clang 3503ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar 3513ede8d0a7d1813f678ccc6011a99a0834b1b6116Daniel Dunbar#endif 352