Centralize the recording of which tools have been constructed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177319 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index 83c1646..e5ddfd1 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"
@@ -27,6 +28,10 @@
}
ToolChain::~ToolChain() {
+ // Free tool implementations.
+ for (llvm::DenseMap<unsigned, Tool*>::iterator
+ it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
+ delete it->second;
}
const Driver &ToolChain::getDriver() const {
@@ -58,6 +63,25 @@
return false;
}
+Tool &ToolChain::SelectTool(const JobAction &JA) const {
+ Action::ActionClass Key;
+ if (getDriver().ShouldUseClangCompiler(JA))
+ Key = Action::AnalyzeJobClass;
+ else
+ Key = JA.getKind();
+
+ Tool *&T = Tools[Key];
+ if (T)
+ return *T;
+
+ if (getDriver().ShouldUseClangCompiler(JA))
+ T = new tools::Clang(*this);
+ else
+ T = constructTool(Key);
+
+ return *T;
+}
+
std::string ToolChain::GetFilePath(const char *Name) const {
return D.GetFilePath(Name, *this);