[cfe-commits] r67108 - in /cfe/trunk: include/clang/Driver/Tool.h lib/Driver/Tool.cpp lib/Driver/ToolChains.h

Daniel Dunbar daniel at zuster.org
Tue Mar 17 15:07:31 PDT 2009


Author: ddunbar
Date: Tue Mar 17 17:07:31 2009
New Revision: 67108

URL: http://llvm.org/viewvc/llvm-project?rev=67108&view=rev
Log:
Driver: Stub out generic GCC tool selection.

Modified:
    cfe/trunk/include/clang/Driver/Tool.h
    cfe/trunk/lib/Driver/Tool.cpp
    cfe/trunk/lib/Driver/ToolChains.h

Modified: cfe/trunk/include/clang/Driver/Tool.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Tool.h?rev=67108&r1=67107&r2=67108&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Tool.h (original)
+++ cfe/trunk/include/clang/Driver/Tool.h Tue Mar 17 17:07:31 2009
@@ -12,15 +12,20 @@
 
 namespace clang {
 namespace driver {
-
+  class ToolChain;
+  
 /// Tool - Information on a specific compilation tool.
 class Tool {
-protected:
-  Tool();
+  const ToolChain &TheToolChain;
+
+public:
+  Tool(const ToolChain &TC);
 
 public:
   virtual ~Tool();
 
+  const ToolChain &getToolChain() const { return TheToolChain; }
+
   virtual bool acceptsPipedInput() const = 0;
   virtual bool canPipeOutput() const = 0;
   virtual bool hasIntegratedCPP() const = 0;

Modified: cfe/trunk/lib/Driver/Tool.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tool.cpp?rev=67108&r1=67107&r2=67108&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Tool.cpp (original)
+++ cfe/trunk/lib/Driver/Tool.cpp Tue Mar 17 17:07:31 2009
@@ -11,5 +11,8 @@
 
 using namespace clang::driver;
 
+Tool::Tool(const ToolChain &TC) : TheToolChain(TC) {
+}
+
 Tool::~Tool() {
 }

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=67108&r1=67107&r2=67108&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Tue Mar 17 17:07:31 2009
@@ -10,24 +10,58 @@
 #ifndef CLANG_LIB_DRIVER_TOOLCHAINS_H_
 #define CLANG_LIB_DRIVER_TOOLCHAINS_H_
 
+#include "clang/Driver/Action.h"
 #include "clang/Driver/ToolChain.h"
 
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/Compiler.h"
 
+#include "Tools.h"
+
 namespace clang {
 namespace driver {
 namespace toolchains VISIBILITY_HIDDEN {
 
+  /// Generic_GCC - A tool chain using the 'gcc' command to perform
+  /// all subcommands; this relies on gcc translating the majority of
+  /// command line options.
 class Generic_GCC : public ToolChain {
+  mutable llvm::DenseMap<unsigned, Tool*> Tools;
+
 public:
   Generic_GCC(const HostInfo &Host, const char *Arch, const char *Platform, 
-              const char *OS) : ToolChain(Host, Arch, Platform, OS) {
-  }
+              const char *OS) : ToolChain(Host, Arch, Platform, OS) {}
 
   virtual ArgList *TranslateArgs(ArgList &Args) const { return &Args; }
 
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const {
-    return *((Tool*) 0);
+    Action::ActionClass Key;
+    if (ShouldUseClangCompiler(C, JA))
+      Key = Action::AnalyzeJobClass;
+    else
+      Key = JA.getKind();
+
+    Tool *&T = Tools[Key];
+    if (!T) {
+      switch (Key) {
+      default:
+        assert(0 && "Invalid tool kind.");
+      case Action::PreprocessJobClass: 
+        T = new tools::GCC_Preprocess(*this); break;
+      case Action::PrecompileJobClass: 
+        T = new tools::GCC_Precompile(*this); break;
+      case Action::AnalyzeJobClass: 
+        T = new tools::Clang(*this); break;
+      case Action::CompileJobClass: 
+        T = new tools::GCC_Compile(*this); break;
+      case Action::AssembleJobClass: 
+        T = new tools::GCC_Assemble(*this); break;
+      case Action::LinkJobClass: 
+        T = new tools::GCC_Assemble(*this); break;
+      }
+    }
+
+    return *T;
   }
 
   virtual bool IsMathErrnoDefault() const { return true; }





More information about the cfe-commits mailing list