[cfe-commits] r66817 - in /cfe/trunk: include/clang/Basic/DiagnosticDriverKinds.def include/clang/Basic/DiagnosticDriverKinds.td include/clang/Driver/Action.h lib/Driver/Action.cpp lib/Driver/Driver.cpp

Daniel Dunbar daniel at zuster.org
Thu Mar 12 11:40:20 PDT 2009


Author: ddunbar
Date: Thu Mar 12 13:40:18 2009
New Revision: 66817

URL: http://llvm.org/viewvc/llvm-project?rev=66817&view=rev
Log:
Driver: Add majority of driver-driver implementation.
 - Compare to driverdriver.c if bored; not completely fair since the
   driver gets a bit more code in other places to handle binding archs
   (for Xarch) but not completely unfair either.

Fear not, extra Action classes will have a happy home for their
vtables soon.

Added:
    cfe/trunk/lib/Driver/Action.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
    cfe/trunk/include/clang/Driver/Action.h
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def?rev=66817&r1=66816&r2=66817&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def Thu Mar 12 13:40:18 2009
@@ -20,3 +20,7 @@
      "-E or -x required when input is from standard input")
 DIAG(err_drv_unknown_language, ERROR,
      "language not recognized: '%0'")
+DIAG(err_drv_invalid_opt_with_multiple_archs, ERROR,
+     "option '%0' cannot be used with multiple -arch options")
+DIAG(err_drv_invalid_output_with_multiple_archs, ERROR,
+     "cannot use '%0' output with multiple -arch options")

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=66817&r1=66816&r2=66817&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Mar 12 13:40:18 2009
@@ -14,5 +14,9 @@
 def err_drv_unknown_stdin_type : Error<
     "-E or -x required when input is from standard input">
 def err_drv_unknown_language : Error<"language not recognized: '%0'">
+def err_drv_invalid_opt_with_multiple_archs : Error<
+     "option '%0' cannot be used with multiple -arch options">
+def err_drv_invalid_output_with_multiple_archs : Error<
+     "cannot use '%0' output with multiple -arch options">
 
 }

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

==============================================================================
--- cfe/trunk/include/clang/Driver/Action.h (original)
+++ cfe/trunk/include/clang/Driver/Action.h Thu Mar 12 13:40:18 2009
@@ -10,6 +10,11 @@
 #ifndef CLANG_DRIVER_ACTION_H_
 #define CLANG_DRIVER_ACTION_H_
 
+#include "llvm/ADT/SmallVector.h"
+
+#include "clang/Driver/Types.h"
+#include "clang/Driver/Util.h"
+
 namespace clang {
 namespace driver {
 
@@ -17,9 +22,49 @@
 ///
 /// An action represents an edge in the compilation graph; typically
 /// it is a job to transform an input using some tool.
+///
+/// The current driver is hard wired to expect actions which produce a
+/// single primary output, at least in terms of controlling the
+/// compilation. Actions can produce auxiliary files, but can only
+/// produce a single output to feed into subsequent actions.
 class Action {
+  /// The output type of this action.
+  types::ID Type;
+  
+  ActionList Inputs;
+
+protected:
+  Action(const ActionList &_Inputs, types::ID _Type) : Type(_Type),
+                                                       Inputs(_Inputs) {}  
 public:
+  virtual ~Action();
   
+  types::ID getType() { return Type; }
+};
+
+class InputAction : public Action {
+};
+
+class BindArchAction : public Action {
+  const char *ArchName;
+
+public:
+  BindArchAction(Action *Input, const char *_ArchName) 
+    : Action(ActionList(&Input, &Input + 1), Input->getType()),
+      ArchName(_ArchName) {
+  }
+};
+
+class JobAction : public Action {
+protected:
+  JobAction(ActionList &Inputs, types::ID Type) 
+    : Action(Inputs, Type) {}
+};
+
+class LipoJobAction : public JobAction {
+public:
+  LipoJobAction(ActionList &Inputs, types::ID Type) 
+    : JobAction(Inputs, Type) {}
 };
 
 } // end namespace driver

Added: cfe/trunk/lib/Driver/Action.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Action.cpp?rev=66817&view=auto

==============================================================================
--- cfe/trunk/lib/Driver/Action.cpp (added)
+++ cfe/trunk/lib/Driver/Action.cpp Thu Mar 12 13:40:18 2009
@@ -0,0 +1,15 @@
+//===--- Action.cpp - Abstract compilation steps ------------------------*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Driver/Action.h"
+
+#include <cassert>
+using namespace clang::driver;
+
+Action::~Action() {}

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

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Mar 12 13:40:18 2009
@@ -19,6 +19,7 @@
 #include "clang/Driver/Options.h"
 #include "clang/Driver/Types.h"
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Path.h"
 using namespace clang::driver;
@@ -171,8 +172,73 @@
 }
 
 void Driver::BuildUniversalActions(ArgList &Args, ActionList &Actions) {
-  // FIXME: Implement
-  BuildActions(Args, Actions);
+  llvm::StringMap<Arg *> Archs;
+  for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); 
+       it != ie; ++it) {
+    Arg *A = *it;
+
+    if (A->getOption().getId() == options::OPT_arch) {
+      // FIXME: We need to handle canonicalization of the specified
+      // arch?
+
+      Archs[A->getValue(Args)] = A;
+    }
+  }
+
+  // When there is no explicit arch for this platform, get one from
+  // the host so that -Xarch_ is handled correctly.
+  if (!Archs.size()) {
+    const char *Arch = Host->getArchName().c_str();
+    Archs[Arch] = Args.MakeSeparateArg(getOpts().getOption(options::OPT_arch),
+                                       Arch);
+  }
+
+  // FIXME: We killed off some others but these aren't yet detected in
+  // a functional manner. If we added information to jobs about which
+  // "auxiliary" files they wrote then we could detect the conflict
+  // these cause downstream.
+  if (Archs.size() > 1) {
+    // No recovery needed, the point of this is just to prevent
+    // overwriting the same files.
+    if (const Arg *A = Args.getLastArg(options::OPT_M_Group))
+      Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) 
+        << A->getOption().getName();
+    if (const Arg *A = Args.getLastArg(options::OPT_save_temps))
+      Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) 
+        << A->getOption().getName();
+  }
+
+  ActionList SingleActions;
+  BuildActions(Args, SingleActions);
+
+  // Add in arch binding and lipo (if necessary) for every top level
+  // action.
+  for (unsigned i = 0, e = SingleActions.size(); i != e; ++i) {
+    Action *Act = SingleActions[i];
+
+    // Make sure we can lipo this kind of output. If not (and it is an
+    // actual output) then we disallow, since we can't create an
+    // output file with the right name without overwriting it. We
+    // could remove this oddity by just changing the output names to
+    // include the arch, which would also fix
+    // -save-temps. Compatibility wins for now.
+
+    if (Archs.size() > 1 && types::canLipoType(Act->getType()))
+      Diag(clang::diag::err_drv_invalid_output_with_multiple_archs)
+        << types::getTypeName(Act->getType());
+
+    ActionList Inputs;
+    for (llvm::StringMap<Arg*>::iterator it = Archs.begin(), ie = Archs.end();
+         it != ie; ++it)
+      Inputs.push_back(new BindArchAction(Act, it->second->getValue(Args)));
+
+    // Lipo if necessary, We do it this way because we need to set the
+    // arch flag so that -Xarch_ gets overwritten.
+    if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing)
+      Actions.append(Inputs.begin(), Inputs.end());
+    else
+      Actions.push_back(new LipoJobAction(Inputs, Act->getType()));
+  }
 }
 
 void Driver::BuildActions(ArgList &Args, ActionList &Actions) {





More information about the cfe-commits mailing list