]> granicus.if.org Git - clang/commitdiff
Driver: Add an explicit argument translation phase to the driver itself. We are going...
authorDaniel Dunbar <daniel@zuster.org>
Fri, 11 Jun 2010 22:00:26 +0000 (22:00 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 11 Jun 2010 22:00:26 +0000 (22:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105842 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/ArgList.h
include/clang/Driver/Compilation.h
include/clang/Driver/Driver.h
include/clang/Driver/ToolChain.h
lib/Driver/ArgList.cpp
lib/Driver/Compilation.cpp
lib/Driver/Driver.cpp
lib/Driver/ToolChains.cpp
lib/Driver/ToolChains.h

index 40f6805e7d190393840d86dacd607daca89f2d49..3e28cc7dfd2ce6b614a29f47bc77c20e81b17b7e 100644 (file)
@@ -96,6 +96,10 @@ namespace driver {
   /// check for the presence of Arg instances for a particular Option
   /// and to iterate over groups of arguments.
   class ArgList {
+  private:
+    ArgList(const ArgList &); // DO NOT IMPLEMENT
+    void operator=(const ArgList &); // DO NOT IMPLEMENT
+
   public:
     typedef llvm::SmallVector<Arg*, 16> arglist_type;
     typedef arglist_type::iterator iterator;
@@ -263,9 +267,6 @@ namespace driver {
   };
 
   class InputArgList : public ArgList  {
-    InputArgList(const ArgList &); // DO NOT IMPLEMENT
-    void operator=(const ArgList &); // DO NOT IMPLEMENT
-
   private:
     /// List of argument strings used by the contained Args.
     ///
@@ -312,17 +313,14 @@ namespace driver {
   /// DerivedArgList - An ordered collection of driver arguments,
   /// whose storage may be in another argument list.
   class DerivedArgList : public ArgList {
-    InputArgList &BaseArgs;
+    const InputArgList &BaseArgs;
 
     /// The list of arguments we synthesized.
     mutable arglist_type SynthesizedArgs;
 
   public:
     /// Construct a new derived arg list from \arg BaseArgs.
-    ///
-    /// \param OnlyProxy - If true, this is only a proxy for the base
-    /// list (to adapt the type), and it's Args list is unused.
-    DerivedArgList(InputArgList &BaseArgs, bool OnlyProxy);
+    DerivedArgList(const InputArgList &BaseArgs);
     ~DerivedArgList();
 
     virtual const char *getArgString(unsigned Index) const {
@@ -333,6 +331,10 @@ namespace driver {
       return BaseArgs.getNumInputArgStrings();
     }
 
+    const InputArgList &getBaseArgs() const {
+      return BaseArgs;
+    }
+
     /// @name Arg Synthesis
     /// @{
 
index 56786a7ae2a39eb1b9d233247626b6ce7f9fe393..d9faa64103c35185fe04d6053ce49977fc65e6e9 100644 (file)
@@ -40,6 +40,10 @@ class Compilation {
   /// The original (untranslated) input argument list.
   InputArgList *Args;
 
+  /// The driver translated arguments. Note that toolchains may perform their
+  /// own argument translation.
+  DerivedArgList *TranslatedArgs;
+
   /// The list of actions.
   ActionList Actions;
 
@@ -58,7 +62,7 @@ class Compilation {
 
 public:
   Compilation(const Driver &D, const ToolChain &DefaultToolChain,
-              InputArgList *Args);
+              InputArgList *Args, DerivedArgList *TranslatedArgs);
   ~Compilation();
 
   const Driver &getDriver() const { return TheDriver; }
@@ -67,6 +71,8 @@ public:
 
   const InputArgList &getArgs() const { return *Args; }
 
+  const DerivedArgList &getTranslatedArgs() const { return *TranslatedArgs; }
+
   ActionList &getActions() { return Actions; }
   const ActionList &getActions() const { return Actions; }
 
index 90c3a0dcdc1897d1022862c5d7f5b3ee832886e9..153981f842d3ba7ded4f4d227634985c1f8164bc 100644 (file)
@@ -31,6 +31,7 @@ namespace driver {
   class Action;
   class ArgList;
   class Compilation;
+  class DerivedArgList;
   class HostInfo;
   class InputArgList;
   class InputInfo;
@@ -135,6 +136,11 @@ private:
   std::list<std::string> TempFiles;
   std::list<std::string> ResultFiles;
 
+private:
+  /// TranslateInputArgs - Create a new derived argument list from the input
+  /// arguments, after applying the standard argument translations.
+  DerivedArgList *TranslateInputArgs(const InputArgList &Args) const;
+
 public:
   Driver(llvm::StringRef _Name, llvm::StringRef _Dir,
          llvm::StringRef _DefaultHostTriple,
index 1a8ae7749143e512f9dffdf2890d4cf17172b3f6..2cec22a09d8bfb4c0c2ec38047426fed9aa0dbef 100644 (file)
@@ -70,11 +70,14 @@ public:
   // Tool access.
 
   /// TranslateArgs - Create a new derived argument list for any argument
-  /// translations this ToolChain may wish to perform.
+  /// translations this ToolChain may wish to perform, or 0 if no tool chain
+  /// specific translations are needed.
   ///
   /// \param BoundArch - The bound architecture name, or 0.
-  virtual DerivedArgList *TranslateArgs(InputArgList &Args,
-                                        const char *BoundArch) const = 0;
+  virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
+                                        const char *BoundArch) const {
+    return 0;
+  }
 
   /// SelectTool - Choose a tool to use to handle the action \arg JA.
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const = 0;
index 63f1deec7f5834866e89cd97203fbfe62f55cfb8..46573022c566eaa88c800bb78a2fd36410e11213 100644 (file)
@@ -240,10 +240,8 @@ const char *InputArgList::MakeArgString(llvm::StringRef Str) const {
 
 //
 
-DerivedArgList::DerivedArgList(InputArgList &_BaseArgs, bool OnlyProxy)
+DerivedArgList::DerivedArgList(const InputArgList &_BaseArgs)
   : BaseArgs(_BaseArgs) {
-  if (OnlyProxy)
-    getArgs() = _BaseArgs.getArgs();
 }
 
 DerivedArgList::~DerivedArgList() {
index 227f79a75b7184a8431db06b00df116321c94a03..282e9fe82e4136b80e86b478d85da457d1a9d34a 100644 (file)
 #include <errno.h>
 using namespace clang::driver;
 
-Compilation::Compilation(const Driver &D,
-                         const ToolChain &_DefaultToolChain,
-                         InputArgList *_Args)
-  : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args) {
+Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain,
+                         InputArgList *_Args, DerivedArgList *_TranslatedArgs)
+  : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args),
+    TranslatedArgs(_TranslatedArgs) {
 }
 
 Compilation::~Compilation() {
+  delete TranslatedArgs;
   delete Args;
 
   // Free any derived arg lists.
   for (llvm::DenseMap<std::pair<const ToolChain*, const char*>,
                       DerivedArgList*>::iterator it = TCArgs.begin(),
          ie = TCArgs.end(); it != ie; ++it)
-    delete it->second;
+    if (it->second != TranslatedArgs)
+      delete it->second;
 
   // Free the actions, if built.
   for (ActionList::iterator it = Actions.begin(), ie = Actions.end();
@@ -49,8 +51,11 @@ const DerivedArgList &Compilation::getArgsForToolChain(const ToolChain *TC,
     TC = &DefaultToolChain;
 
   DerivedArgList *&Entry = TCArgs[std::make_pair(TC, BoundArch)];
-  if (!Entry)
-    Entry = TC->TranslateArgs(*Args, BoundArch);
+  if (!Entry) {
+    Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch);
+    if (!Entry)
+      Entry = TranslatedArgs;
+  }
 
   return *Entry;
 }
index 7b4507091207f5f437a6dd7805af39802e1d93e6..4663fb9502b35c05f09d3eeb5abb84fd44e04f00 100644 (file)
@@ -110,6 +110,16 @@ InputArgList *Driver::ParseArgStrings(const char **ArgBegin,
   return Args;
 }
 
+DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
+  DerivedArgList *DAL = new DerivedArgList(Args);
+
+  for (ArgList::const_iterator it = Args.begin(),
+         ie = Args.end(); it != ie; ++it)
+    DAL->append(*it);
+
+  return DAL;
+}
+
 Compilation *Driver::BuildCompilation(int argc, const char **argv) {
   llvm::PrettyStackTraceString CrashInfo("Compilation construction");
 
@@ -179,8 +189,12 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
 
   Host = GetHostInfo(HostTriple);
 
+  // Perform the default argument translations.
+  DerivedArgList *TranslatedArgs = TranslateInputArgs(*Args);
+
   // The compilation takes ownership of Args.
-  Compilation *C = new Compilation(*this, *Host->CreateToolChain(*Args), Args);
+  Compilation *C = new Compilation(*this, *Host->CreateToolChain(*Args), Args,
+                                   TranslatedArgs);
 
   // FIXME: This behavior shouldn't be here.
   if (CCCPrintOptions) {
index 92c7d793f9abf6c893854bfcac76676b9622d1db..ba329e3855a2c2276d8d970a3ba6934d3fd2714d 100644 (file)
@@ -388,9 +388,9 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
   }
 }
 
-DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
+DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
                                       const char *BoundArch) const {
-  DerivedArgList *DAL = new DerivedArgList(Args, false);
+  DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
   const OptTable &Opts = getDriver().getOpts();
 
   // FIXME: We really want to get out of the tool chain level argument
@@ -478,7 +478,8 @@ DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
   }
   setTarget(iPhoneVersion, Major, Minor, Micro);
 
-  for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
+  for (ArgList::const_iterator it = Args.begin(),
+         ie = Args.end(); it != ie; ++it) {
     Arg *A = *it;
 
     if (A->getOption().matches(options::OPT_Xarch__)) {
@@ -764,12 +765,6 @@ const char *Generic_GCC::GetForcedPicModel() const {
   return 0;
 }
 
-DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
-                                           const char *BoundArch) const {
-  return new DerivedArgList(Args, true);
-}
-
-
 /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
 /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
 /// Currently does not support anything else but compilation.
@@ -824,11 +819,6 @@ Tool &TCEToolChain::SelectTool(const Compilation &C,
   return *T;
 }
 
-DerivedArgList *TCEToolChain::TranslateArgs(InputArgList &Args,
-                                            const char *BoundArch) const {
-  return new DerivedArgList(Args, true);
-}
-
 /// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
 
 OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
index ad975bfe6dee3c4ec76d596d9ec68c9a694679e8..f561016ebe30f2ea003c089fb185ce16bea6e757 100644 (file)
@@ -33,9 +33,6 @@ public:
   Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple);
   ~Generic_GCC();
 
-  virtual DerivedArgList *TranslateArgs(InputArgList &Args,
-                                        const char *BoundArch) const;
-
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
 
   virtual bool IsUnwindTablesDefault() const;
@@ -147,7 +144,7 @@ public:
   /// @name ToolChain Implementation
   /// {
 
-  virtual DerivedArgList *TranslateArgs(InputArgList &Args,
+  virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args,
                                         const char *BoundArch) const;
 
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
@@ -290,8 +287,6 @@ public:
   TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple);
   ~TCEToolChain();
 
-  virtual DerivedArgList *TranslateArgs(InputArgList &Args,
-                                        const char *BoundArch) const;
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
   bool IsMathErrnoDefault() const;
   bool IsUnwindTablesDefault() const;