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

Chad Rosier mcrosier at apple.com
Fri Aug 12 15:08:57 PDT 2011


Author: mcrosier
Date: Fri Aug 12 17:08:57 2011
New Revision: 137524

URL: http://llvm.org/viewvc/llvm-project?rev=137524&view=rev
Log:
[driver] Refactor a bit to enable a few fixes when generating diagnostics.  No functional change intended.

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

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=137524&r1=137523&r2=137524&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Fri Aug 12 17:08:57 2011
@@ -13,6 +13,7 @@
 #include "clang/Basic/Diagnostic.h"
 
 #include "clang/Driver/Phases.h"
+#include "clang/Driver/Types.h"
 #include "clang/Driver/Util.h"
 
 #include "llvm/ADT/StringRef.h"
@@ -110,6 +111,9 @@
   /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
   const char *CCLogDiagnosticsFilename;
 
+  /// A list of inputs and their types for the given arguments.
+  typedef SmallVector<std::pair<types::ID, const Arg*>, 16> InputList;
+
   /// Whether the driver should follow g++ like behavior.
   unsigned CCCIsCXX : 1;
 
@@ -242,6 +246,16 @@
   /// ArgList.
   InputArgList *ParseArgStrings(ArrayRef<const char *> Args);
 
+  /// BuildInputs - Construct the list of inputs and their types from 
+  /// the given arguments.
+  ///
+  /// \param TC - The default host tool chain.
+  /// \param Args - The input arguments.
+  /// \param Inputs - The list to store the resulting compilation 
+  /// inputs onto.
+  void BuildInputs(const ToolChain &TC, const DerivedArgList &Args,
+                   InputList &Inputs) const;
+
   /// BuildActions - Construct the list of actions to perform for the
   /// given arguments, which are only done for a single architecture.
   ///
@@ -249,7 +263,7 @@
   /// \param Args - The input arguments.
   /// \param Actions - The list to store the resulting actions onto.
   void BuildActions(const ToolChain &TC, const DerivedArgList &Args,
-                    ActionList &Actions) const;
+                    const InputList &Inputs, ActionList &Actions) const;
 
   /// BuildUniversalActions - Construct the list of actions to perform
   /// for the given arguments, which may require a universal build.
@@ -258,6 +272,7 @@
   /// \param Args - The input arguments.
   /// \param Actions - The list to store the resulting actions onto.
   void BuildUniversalActions(const ToolChain &TC, const DerivedArgList &Args,
+                             const InputList &BAInputs,
                              ActionList &Actions) const;
 
   /// BuildJobs - Bind actions to concrete tools and translate

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=137524&r1=137523&r2=137524&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Aug 12 17:08:57 2011
@@ -25,7 +25,6 @@
 #include "clang/Driver/Options.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
-#include "clang/Driver/Types.h"
 
 #include "clang/Basic/Version.h"
 
@@ -350,12 +349,17 @@
   if (!HandleImmediateArgs(*C))
     return C;
 
+  // Construct the list of inputs.
+  InputList Inputs;
+  BuildInputs(C->getDefaultToolChain(), C->getArgs(), Inputs);
+
   // Construct the list of abstract actions to perform for this compilation.
   if (Host->useDriverDriver())
     BuildUniversalActions(C->getDefaultToolChain(), C->getArgs(),
-                          C->getActions());
+                          Inputs, C->getActions());
   else
-    BuildActions(C->getDefaultToolChain(), C->getArgs(), C->getActions());
+    BuildActions(C->getDefaultToolChain(), C->getArgs(), Inputs,
+                 C->getActions());
 
   if (CCCPrintActions) {
     PrintActions(*C);
@@ -382,14 +386,19 @@
 
   // Clear stale state and suppress tool output.
   C.initCompilationForDiagnostics();
+  Diags.Reset();
+
+  // Construct the list of inputs.
+  InputList Inputs;
+  BuildInputs(C.getDefaultToolChain(), C.getArgs(), Inputs);
 
   // Construct the list of abstract actions to perform for this compilation.
-  Diags.Reset();
   if (Host->useDriverDriver())
     BuildUniversalActions(C.getDefaultToolChain(), C.getArgs(),
-                          C.getActions());
+                          Inputs, C.getActions());
   else
-    BuildActions(C.getDefaultToolChain(), C.getArgs(), C.getActions());
+    BuildActions(C.getDefaultToolChain(), C.getArgs(), Inputs,
+                 C.getActions());
 
   BuildJobs(C);
 
@@ -703,6 +712,7 @@
 
 void Driver::BuildUniversalActions(const ToolChain &TC,
                                    const DerivedArgList &Args,
+                                   const InputList &BAInputs,
                                    ActionList &Actions) const {
   llvm::PrettyStackTraceString CrashInfo("Building universal build actions");
   // Collect the list of architectures. Duplicates are allowed, but should only
@@ -747,7 +757,7 @@
   }
 
   ActionList SingleActions;
-  BuildActions(TC, Args, SingleActions);
+  BuildActions(TC, Args, BAInputs, SingleActions);
 
   // Add in arch bindings for every top level action, as well as lipo and
   // dsymutil steps if needed.
@@ -797,18 +807,15 @@
   }
 }
 
-void Driver::BuildActions(const ToolChain &TC, const DerivedArgList &Args,
-                          ActionList &Actions) const {
-  llvm::PrettyStackTraceString CrashInfo("Building compilation actions");
-  // Start by constructing the list of inputs and their types.
-
+// Construct a the list of inputs and their types.
+void Driver::BuildInputs(const ToolChain &TC, const DerivedArgList &Args,
+                         InputList &Inputs) const {
   // Track the current user specified (-x) input. We also explicitly track the
   // argument used to set the type; we only want to claim the type when we
   // actually use it, so we warn about unused -x arguments.
   types::ID InputType = types::TY_Nothing;
   Arg *InputTypeArg = 0;
 
-  SmallVector<std::pair<types::ID, const Arg*>, 16> Inputs;
   for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
        it != ie; ++it) {
     Arg *A = *it;
@@ -912,7 +919,6 @@
       }
     }
   }
-
   if (CCCIsCPP && Inputs.empty()) {
     // If called as standalone preprocessor, stdin is processed
     // if no other input is present.
@@ -921,6 +927,11 @@
     A->claim();
     Inputs.push_back(std::make_pair(types::TY_C, A));
   }
+}
+
+void Driver::BuildActions(const ToolChain &TC, const DerivedArgList &Args,
+                          const InputList &Inputs, ActionList &Actions) const {
+  llvm::PrettyStackTraceString CrashInfo("Building compilation actions");
 
   if (!SuppressMissingInputWarning && Inputs.empty()) {
     Diag(clang::diag::err_drv_no_input_files);





More information about the cfe-commits mailing list