diff options
Diffstat (limited to 'lib/Driver/ToolChain.cpp')
-rw-r--r-- | lib/Driver/ToolChain.cpp | 87 |
1 files changed, 85 insertions, 2 deletions
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 21015a6c84..71f53933e2 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "Tools.h" #include "clang/Driver/ToolChain.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Driver/Action.h" @@ -18,11 +19,13 @@ #include "clang/Driver/Options.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FileSystem.h" using namespace clang::driver; using namespace clang; -ToolChain::ToolChain(const Driver &D, const llvm::Triple &T) - : D(D), Triple(T) { +ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, + const ArgList &A) + : D(D), Triple(T), Args(A) { } ToolChain::~ToolChain() { @@ -32,6 +35,12 @@ const Driver &ToolChain::getDriver() const { return D; } +bool ToolChain::useIntegratedAs() const { + return Args.hasFlag(options::OPT_integrated_as, + options::OPT_no_integrated_as, + IsIntegratedAssemblerDefault()); +} + std::string ToolChain::getDefaultUniversalArchName() const { // In universal driver terms, the arch name accepted by -arch isn't exactly // the same as the ones that appear in the triple. Roughly speaking, this is @@ -51,6 +60,73 @@ bool ToolChain::IsUnwindTablesDefault() const { return false; } +Tool *ToolChain::getClang() const { + if (!Clang) + Clang.reset(new tools::Clang(*this)); + return Clang.get(); +} + +Tool *ToolChain::buildAssembler() const { + return new tools::ClangAs(*this); +} + +Tool *ToolChain::buildLinker() const { + llvm_unreachable("Linking is not supported by this toolchain"); +} + +Tool *ToolChain::getAssemble() const { + if (!Assemble) + Assemble.reset(buildAssembler()); + return Assemble.get(); +} + +Tool *ToolChain::getClangAs() const { + if (!Assemble) + Assemble.reset(new tools::ClangAs(*this)); + return Assemble.get(); +} + +Tool *ToolChain::getLink() const { + if (!Link) + Link.reset(buildLinker()); + return Link.get(); +} + +Tool *ToolChain::getTool(Action::ActionClass AC) const { + switch (AC) { + case Action::AssembleJobClass: + return getAssemble(); + + case Action::LinkJobClass: + return getLink(); + + case Action::InputClass: + case Action::BindArchClass: + case Action::LipoJobClass: + case Action::DsymutilJobClass: + case Action::VerifyJobClass: + llvm_unreachable("Invalid tool kind."); + + case Action::CompileJobClass: + case Action::PrecompileJobClass: + case Action::PreprocessJobClass: + case Action::AnalyzeJobClass: + case Action::MigrateJobClass: + return getClang(); + } + + llvm_unreachable("Invalid tool kind."); +} + +Tool *ToolChain::SelectTool(const JobAction &JA) const { + if (getDriver().ShouldUseClangCompiler(JA)) + return getClang(); + Action::ActionClass AC = JA.getKind(); + if (AC == Action::AssembleJobClass && useIntegratedAs()) + return getClangAs(); + return getTool(AC); +} + std::string ToolChain::GetFilePath(const char *Name) const { return D.GetFilePath(Name, *this); @@ -258,6 +334,13 @@ ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ CC1Args.push_back(DriverArgs.MakeArgString(Path)); } +void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs, + ArgStringList &CC1Args, + const Twine &Path) { + if (llvm::sys::fs::exists(Path)) + addExternCSystemInclude(DriverArgs, CC1Args, Path); +} + /// \brief Utility function to add a list of system include directories to CC1. /*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs, ArgStringList &CC1Args, |