[cfe-commits] r67185 - in /cfe/trunk/lib/Driver: Tools.cpp Tools.h

Daniel Dunbar daniel at zuster.org
Wed Mar 18 01:07:30 PDT 2009


Author: ddunbar
Date: Wed Mar 18 03:07:30 2009
New Revision: 67185

URL: http://llvm.org/viewvc/llvm-project?rev=67185&view=rev
Log:
Driver: Lift out common GCC tool and implement generic GCC tool
argument translation.

Also, stub out clang tool implementation a bit more.

Modified:
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/lib/Driver/Tools.h

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Mar 18 03:07:30 2009
@@ -10,8 +10,12 @@
 #include "Tools.h"
 
 #include "clang/Driver/Arg.h"
+#include "clang/Driver/ArgList.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Job.h"
+#include "clang/Driver/HostInfo.h"
+#include "clang/Driver/Option.h"
+#include "clang/Driver/ToolChain.h"
 #include "clang/Driver/Util.h"
 
 #include "llvm/ADT/SmallVector.h"
@@ -27,49 +31,104 @@
                          const InputInfoList &Inputs,
                          const ArgList &TCArgs,
                          const char *LinkingOutput) const {
-}
-
-void gcc::Preprocess::ConstructJob(Compilation &C, const JobAction &JA,
-                                   Job &Dest,
-                                   const InputInfo &Output,
-                                   const InputInfoList &Inputs,
-                                   const ArgList &TCArgs,
-                                   const char *LinkingOutput) const {
+  ArgStringList CmdArgs;
 
+  for (InputInfoList::const_iterator
+         it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
+    const InputInfo &II = *it;
+    if (II.isPipe())
+      CmdArgs.push_back("-");
+    else
+      CmdArgs.push_back(II.getInputFilename());
+  }
+
+  if (Output.isPipe()) {
+    CmdArgs.push_back("-o");
+    CmdArgs.push_back("-");
+  } else if (const char *N = Output.getInputFilename()) {
+    CmdArgs.push_back("-o");
+    CmdArgs.push_back(N);
+  }
+
+  Dest.addCommand(new Command("clang", CmdArgs));
+}
+
+void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,
+                               Job &Dest,
+                               const InputInfo &Output,
+                               const InputInfoList &Inputs,
+                               const ArgList &TCArgs,
+                               const char *LinkingOutput) const {
+  ArgStringList CmdArgs;
+
+  for (ArgList::const_iterator 
+         it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it) {
+    Arg *A = *it;
+    if (A->getOption().hasForwardToGCC())
+      A->render(TCArgs, CmdArgs);
+  }
+  
+  RenderExtraToolArgs(CmdArgs);
+
+  // If using a driver driver, force the arch.
+  if (getToolChain().getHost().useDriverDriver()) {
+    CmdArgs.push_back("-arch");
+    CmdArgs.push_back(getToolChain().getArchName().c_str());
+  }
+
+  if (Output.isPipe()) {
+    CmdArgs.push_back("-o");
+    CmdArgs.push_back("-");
+  } else if (const char *N = Output.getInputFilename()) {
+    CmdArgs.push_back("-o");
+    CmdArgs.push_back(N);
+  } else
+    CmdArgs.push_back("-fsyntax-only");
+
+
+  // Only pass -x if gcc will understand it; otherwise hope gcc
+  // understands the suffix correctly. The main use case this would go
+  // wrong in is for linker inputs if they happened to have an odd
+  // suffix; really the only way to get this to happen is a command
+  // like '-x foobar a.c' which will treat a.c like a linker input.
+  //
+  // FIXME: For the linker case specifically, can we safely convert
+  // inputs into '-Wl,' options?
+  for (InputInfoList::const_iterator
+         it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
+    const InputInfo &II = *it;
+    if (types::canTypeBeUserSpecified(II.getType())) {
+      CmdArgs.push_back("-x");
+      CmdArgs.push_back(types::getTypeName(II.getType()));
+    }
+
+    if (II.isPipe())
+      CmdArgs.push_back("-");
+    else
+      // FIXME: Linker inputs
+      CmdArgs.push_back(II.getInputFilename());
+  }
+
+  Dest.addCommand(new Command("gcc", CmdArgs));
+}
+
+void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
+  CmdArgs.push_back("-E");
+}
+
+void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
+  // The type is good enough.
+}
+
+void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
+  CmdArgs.push_back("-S");
 }
 
-void gcc::Precompile::ConstructJob(Compilation &C, const JobAction &JA,
-                                   Job &Dest,
-                                   const InputInfo &Output,
-                                   const InputInfoList &Inputs,
-                                   const ArgList &TCArgs,
-                                   const char *LinkingOutput) const {
-
+void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
+  CmdArgs.push_back("-c");
 }
 
-void gcc::Compile::ConstructJob(Compilation &C, const JobAction &JA,
-                                Job &Dest,
-                                const InputInfo &Output,
-                                const InputInfoList &Inputs,
-                                const ArgList &TCArgs,
-                                const char *LinkingOutput) const {
-
+void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
+  // The types are (hopefully) good enough.
 }
 
-void gcc::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
-                                 Job &Dest,
-                                 const InputInfo &Output,
-                                 const InputInfoList &Inputs,
-                                 const ArgList &TCArgs,
-                                 const char *LinkingOutput) const {
-
-}
-
-void gcc::Link::ConstructJob(Compilation &C, const JobAction &JA,
-                             Job &Dest,
-                             const InputInfo &Output,
-                             const InputInfoList &Inputs,
-                             const ArgList &TCArgs,
-                             const char *LinkingOutput) const {
-
-}

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.h (original)
+++ cfe/trunk/lib/Driver/Tools.h Wed Mar 18 03:07:30 2009
@@ -11,6 +11,7 @@
 #define CLANG_LIB_DRIVER_TOOLS_H_
 
 #include "clang/Driver/Tool.h"
+#include "clang/Driver/Util.h"
 
 #include "llvm/Support/Compiler.h"
 
@@ -36,13 +37,9 @@
 
   /// gcc - Generic GCC tool implementations.
 namespace gcc {
-  class VISIBILITY_HIDDEN Preprocess : public Tool {
+  class VISIBILITY_HIDDEN Common : public Tool {
   public:
-    Preprocess(const ToolChain &TC) : Tool("gcc::Preprocess", TC) {}
-
-    virtual bool acceptsPipedInput() const { return true; }
-    virtual bool canPipeOutput() const { return true; }
-    virtual bool hasIntegratedCPP() const { return false; }
+    Common(const char *Name, const ToolChain &TC) : Tool(Name, TC) {}
 
     virtual void ConstructJob(Compilation &C, const JobAction &JA,
                               Job &Dest,
@@ -50,70 +47,66 @@
                               const InputInfoList &Inputs, 
                               const ArgList &TCArgs, 
                               const char *LinkingOutput) const;
+
+    /// RenderExtraToolArgs - Render any arguments necessary to force
+    /// the particular tool mode.
+    virtual void RenderExtraToolArgs(ArgStringList &CmdArgs) const = 0;
   };
 
-  class VISIBILITY_HIDDEN Precompile : public Tool  {
+  
+  class VISIBILITY_HIDDEN Preprocess : public Common {
   public:
-    Precompile(const ToolChain &TC) : Tool("gcc::Precompile", TC) {}
+    Preprocess(const ToolChain &TC) : Common("gcc::Preprocess", TC) {}
+
+    virtual bool acceptsPipedInput() const { return true; }
+    virtual bool canPipeOutput() const { return true; }
+    virtual bool hasIntegratedCPP() const { return false; }
+
+    virtual void RenderExtraToolArgs(ArgStringList &CmdArgs) const;
+  };
+
+  class VISIBILITY_HIDDEN Precompile : public Common  {
+  public:
+    Precompile(const ToolChain &TC) : Common("gcc::Precompile", TC) {}
 
     virtual bool acceptsPipedInput() const { return true; }
     virtual bool canPipeOutput() const { return false; }
     virtual bool hasIntegratedCPP() const { return true; }
 
-    virtual void ConstructJob(Compilation &C, const JobAction &JA,
-                              Job &Dest,
-                              const InputInfo &Output, 
-                              const InputInfoList &Inputs, 
-                              const ArgList &TCArgs, 
-                              const char *LinkingOutput) const;
+    virtual void RenderExtraToolArgs(ArgStringList &CmdArgs) const;
   };
 
-  class VISIBILITY_HIDDEN Compile : public Tool  {
+  class VISIBILITY_HIDDEN Compile : public Common  {
   public:
-    Compile(const ToolChain &TC) : Tool("gcc::Compile", TC) {}
+    Compile(const ToolChain &TC) : Common("gcc::Compile", TC) {}
 
     virtual bool acceptsPipedInput() const { return true; }
     virtual bool canPipeOutput() const { return true; }
     virtual bool hasIntegratedCPP() const { return true; }
 
-    virtual void ConstructJob(Compilation &C, const JobAction &JA,
-                              Job &Dest,
-                              const InputInfo &Output, 
-                              const InputInfoList &Inputs, 
-                              const ArgList &TCArgs, 
-                              const char *LinkingOutput) const;
+    virtual void RenderExtraToolArgs(ArgStringList &CmdArgs) const;
   };
 
-  class VISIBILITY_HIDDEN Assemble : public Tool  {
+  class VISIBILITY_HIDDEN Assemble : public Common  {
   public:
-    Assemble(const ToolChain &TC) : Tool("gcc::Assemble", TC) {}
+    Assemble(const ToolChain &TC) : Common("gcc::Assemble", TC) {}
 
     virtual bool acceptsPipedInput() const { return true; }
     virtual bool canPipeOutput() const { return false; }
     virtual bool hasIntegratedCPP() const { return false; }
 
-    virtual void ConstructJob(Compilation &C, const JobAction &JA,
-                              Job &Dest,
-                              const InputInfo &Output, 
-                              const InputInfoList &Inputs, 
-                              const ArgList &TCArgs, 
-                              const char *LinkingOutput) const;
+    virtual void RenderExtraToolArgs(ArgStringList &CmdArgs) const;
   };
 
-  class VISIBILITY_HIDDEN Link : public Tool  {
+  class VISIBILITY_HIDDEN Link : public Common  {
   public:
-    Link(const ToolChain &TC) : Tool("gcc::Link", TC) {}
+    Link(const ToolChain &TC) : Common("gcc::Link", TC) {}
 
     virtual bool acceptsPipedInput() const { return false; }
     virtual bool canPipeOutput() const { return false; }
     virtual bool hasIntegratedCPP() const { return false; }
 
-    virtual void ConstructJob(Compilation &C, const JobAction &JA,
-                              Job &Dest,
-                              const InputInfo &Output, 
-                              const InputInfoList &Inputs, 
-                              const ArgList &TCArgs, 
-                              const char *LinkingOutput) const;
+    virtual void RenderExtraToolArgs(ArgStringList &CmdArgs) const;
   };
 } // end namespace gcc
 





More information about the cfe-commits mailing list