r177368 - Finish refactoring the tool selection logic.
Rafael Espindola
rafael.espindola at gmail.com
Mon Mar 18 17:36:58 PDT 2013
Author: rafael
Date: Mon Mar 18 19:36:57 2013
New Revision: 177368
URL: http://llvm.org/viewvc/llvm-project?rev=177368&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/WindowsToolChain.cpp
Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=177368&r1=177367&r2=177368&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Mon Mar 18 19:36:57 2013
@@ -63,7 +63,7 @@ private:
protected:
ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args);
- virtual Tool *constructTool(Action::ActionClass AC) const = 0;
+ virtual Tool *constructTool(Action::ActionClass AC) const;
/// \name Utilities for implementing subclasses.
///@{
Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=177368&r1=177367&r2=177368&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Mon Mar 18 19:36:57 2013
@@ -63,6 +63,26 @@ bool ToolChain::IsUnwindTablesDefault()
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))
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=177368&r1=177367&r2=177368&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Mar 18 19:36:57 2013
@@ -174,15 +174,6 @@ void Generic_ELF::anchor() {}
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 @@ Tool *Darwin::constructTool(Action::Acti
return new tools::darwin::Dsymutil(*this);
case Action::VerifyJobClass:
return new tools::darwin::VerifyDebug(*this);
+ default:
+ return ToolChain::constructTool(AC);
}
}
@@ -1359,31 +1352,18 @@ Generic_GCC::~Generic_GCC() {
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 @@ Tool *Hexagon_TC::constructTool(Action::
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 @@ bool TCEToolChain::isPICDefaultForced()
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)
Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=177368&r1=177367&r2=177368&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Mon Mar 18 19:36:57 2013
@@ -528,7 +528,6 @@ public:
const ArgList &Args);
~TCEToolChain();
- virtual Tool *constructTool(Action::ActionClass AC) const;
bool IsMathErrnoDefault() const;
bool isPICDefault() const;
bool isPICDefaultForced() const;
Modified: cfe/trunk/lib/Driver/WindowsToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/WindowsToolChain.cpp?rev=177368&r1=177367&r2=177368&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/WindowsToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/WindowsToolChain.cpp Mon Mar 18 19:36:57 2013
@@ -38,17 +38,6 @@ Windows::Windows(const Driver &D, const
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 @@ Tool *Windows::constructTool(Action::Act
break;
case Action::LinkJobClass:
return new tools::visualstudio::Link(*this);
+ default:
+ return ToolChain::constructTool(AC);
}
}
More information about the cfe-commits
mailing list