diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index b90aa27736af..3a07a325bd47 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -17,18 +17,17 @@ namespace clang { namespace driver { class ArgList; class Compilation; - class Driver; + class HostInfo; class JobAction; class Tool; /// ToolChain - Access to tools for a single platform. class ToolChain { - Driver &TheDriver; - + const HostInfo &Host; std::string Arch, Platform, OS; protected: - ToolChain(Driver &D, const char *_Arch, const char *_Platform, + ToolChain(const HostInfo &Host, const char *_Arch, const char *_Platform, const char *_OS); public: @@ -36,6 +35,7 @@ public: // Accessors + const HostInfo &getHost() const { return Host; } const std::string &getArchName() const { return Arch; } const std::string &getPlatform() const { return Platform; } const std::string &getOS() const { return OS; } @@ -44,7 +44,10 @@ public: /// TranslateArgs - Create a new derived argument list for any /// argument translations this ToolChain may wish to perform. - virtual ArgList *TranslateArgs(const ArgList &Args) const = 0; + /// + /// The client implementation is free to return Args directly if no + /// translations need to be performed. + virtual ArgList *TranslateArgs(ArgList &Args) const = 0; /// SelectTool - Choose a tool to use to handle the action \arg JA. virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const = 0; diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index ff4e97b1d458..ea2528bfffc1 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -11,12 +11,13 @@ #include "clang/Driver/Action.h" #include "clang/Driver/Driver.h" +#include "clang/Driver/HostInfo.h" using namespace clang::driver; -ToolChain::ToolChain(Driver &_TheDriver, const char *_Arch, +ToolChain::ToolChain(const HostInfo &_Host, const char *_Arch, const char *_Platform, const char *_OS) - : TheDriver(_TheDriver), Arch(_Arch), Platform(_Platform), OS(_OS) { + : Host(_Host), Arch(_Arch), Platform(_Platform), OS(_OS) { } ToolChain::~ToolChain() { @@ -24,38 +25,38 @@ ToolChain::~ToolChain() { llvm::sys::Path ToolChain::GetFilePath(const Compilation &C, const char *Name) const { - return TheDriver.GetFilePath(Name, this); + return Host.getDriver().GetFilePath(Name, this); } llvm::sys::Path ToolChain::GetProgramPath(const Compilation &C, const char *Name) const { - return TheDriver.GetProgramPath(Name, this); + return Host.getDriver().GetProgramPath(Name, this); } bool ToolChain::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA) const { // Check if user requested no clang, or clang doesn't understand // this type (we only handle single inputs for now). - if (TheDriver.CCCNoClang || JA.size() != 1 || + if (Host.getDriver().CCCNoClang || JA.size() != 1 || !types::isAcceptedByClang((*JA.begin())->getType())) return false; // Otherwise make sure this is an action clang undertands. if (isa(JA)) { - if (TheDriver.CCCNoClangCPP) + if (Host.getDriver().CCCNoClangCPP) return false; } else if (!isa(JA) && !isa(JA)) return false; // Avoid CXX if the user requested. - if (TheDriver.CCCNoClangCXX && types::isCXX((*JA.begin())->getType())) + if (Host.getDriver().CCCNoClangCXX && types::isCXX((*JA.begin())->getType())) return false; // Finally, don't use clang if this isn't one of the user specified // archs to build. - if (!TheDriver.CCCClangArchs.empty() && - TheDriver.CCCClangArchs.count(getArchName())) + if (!Host.getDriver().CCCClangArchs.empty() && + Host.getDriver().CCCClangArchs.count(getArchName())) return false; return true;