Finish refactoring the tool selection logic.
The general pattern now is that Foobar::constructTool only creates tools
defined in the tools::foobar namespace and then delegates to the parent.
The remaining duplicated code is now in the tools themselves.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177368 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index 5322a6d..def3b3d 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -63,6 +63,26 @@
return false;
}
+Tool *ToolChain::constructTool(Action::ActionClass AC) const {
+ switch (AC) {
+ case Action::InputClass:
+ case Action::BindArchClass:
+ case Action::AssembleJobClass:
+ case Action::LinkJobClass:
+ 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 new tools::Clang(*this);
+ }
+}
+
Tool &ToolChain::SelectTool(const JobAction &JA) const {
Action::ActionClass Key;
if (getDriver().ShouldUseClangCompiler(JA))
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 802d0ce..0e29ba0 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -174,15 +174,6 @@
Tool *Darwin::constructTool(Action::ActionClass AC) const {
switch (AC) {
- case Action::InputClass:
- case Action::BindArchClass:
- llvm_unreachable("Invalid tool kind.");
- case Action::PreprocessJobClass:
- case Action::AnalyzeJobClass:
- case Action::MigrateJobClass:
- case Action::PrecompileJobClass:
- case Action::CompileJobClass:
- return new tools::Clang(*this);
case Action::AssembleJobClass:
return new tools::darwin::Assemble(*this);
case Action::LinkJobClass:
@@ -193,6 +184,8 @@
return new tools::darwin::Dsymutil(*this);
case Action::VerifyJobClass:
return new tools::darwin::VerifyDebug(*this);
+ default:
+ return ToolChain::constructTool(AC);
}
}
@@ -1359,31 +1352,18 @@
Tool *Generic_GCC::constructTool(Action::ActionClass AC) const {
switch (AC) {
- case Action::InputClass:
- case Action::BindArchClass:
- llvm_unreachable("Invalid tool kind.");
case Action::PreprocessJobClass:
return new tools::gcc::Preprocess(*this);
case Action::PrecompileJobClass:
return new tools::gcc::Precompile(*this);
- case Action::AnalyzeJobClass:
- case Action::MigrateJobClass:
- return new tools::Clang(*this);
case Action::CompileJobClass:
return new tools::gcc::Compile(*this);
case Action::AssembleJobClass:
return new tools::gcc::Assemble(*this);
case Action::LinkJobClass:
return new tools::gcc::Link(*this);
-
- // This is a bit ungeneric, but the only platform using a driver
- // driver is Darwin.
- case Action::LipoJobClass:
- return new tools::darwin::Lipo(*this);
- case Action::DsymutilJobClass:
- return new tools::darwin::Dsymutil(*this);
- case Action::VerifyJobClass:
- return new tools::darwin::VerifyDebug(*this);
+ default:
+ return ToolChain::constructTool(AC);
}
}
@@ -1518,7 +1498,6 @@
case Action::LinkJobClass:
return new tools::hexagon::Link(*this);
default:
- assert(false && "Unsupported action for Hexagon target.");
return Linux::constructTool(AC);
}
}
@@ -1637,17 +1616,6 @@
return false;
}
-Tool *TCEToolChain::constructTool(Action::ActionClass AC) const {
- switch (AC) {
- case Action::PreprocessJobClass:
- return new tools::gcc::Preprocess(*this);
- case Action::AnalyzeJobClass:
- return new tools::Clang(*this);
- default:
- llvm_unreachable("Unsupported action for TCE target.");
- }
-}
-
/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
OpenBSD::OpenBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args)
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index a2b84c9..fb40a61 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -528,7 +528,6 @@
const ArgList &Args);
~TCEToolChain();
- virtual Tool *constructTool(Action::ActionClass AC) const;
bool IsMathErrnoDefault() const;
bool isPICDefault() const;
bool isPICDefaultForced() const;
diff --git a/lib/Driver/WindowsToolChain.cpp b/lib/Driver/WindowsToolChain.cpp
index 0909c4c..b3fdb35 100644
--- a/lib/Driver/WindowsToolChain.cpp
+++ b/lib/Driver/WindowsToolChain.cpp
@@ -38,17 +38,6 @@
Tool *Windows::constructTool(Action::ActionClass AC) const {
switch (AC) {
- case Action::InputClass:
- case Action::BindArchClass:
- case Action::LipoJobClass:
- case Action::DsymutilJobClass:
- case Action::VerifyJobClass:
- case Action::PreprocessJobClass:
- case Action::PrecompileJobClass:
- case Action::AnalyzeJobClass:
- case Action::MigrateJobClass:
- case Action::CompileJobClass:
- return new tools::Clang(*this);
case Action::AssembleJobClass:
if (getTriple().getEnvironment() == llvm::Triple::MachO)
return new tools::darwin::Assemble(*this);
@@ -56,6 +45,8 @@
break;
case Action::LinkJobClass:
return new tools::visualstudio::Link(*this);
+ default:
+ return ToolChain::constructTool(AC);
}
}