[cfe-commits] r74634 - in /cfe/trunk: include/clang/Driver/Compilation.h include/clang/Driver/Driver.h lib/Driver/Compilation.cpp lib/Driver/Driver.cpp tools/driver/driver.cpp

Daniel Dunbar daniel at zuster.org
Wed Jul 1 13:03:06 PDT 2009


Author: ddunbar
Date: Wed Jul  1 15:03:04 2009
New Revision: 74634

URL: http://llvm.org/viewvc/llvm-project?rev=74634&view=rev
Log:
Driver: Move Compilation::Execute to Driver::ExecuteCompilation.
 - The Compilation is just a helper class, it shouldn't have that amount of
   logic in it.

 - No functionality change.

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

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

==============================================================================
--- cfe/trunk/include/clang/Driver/Compilation.h (original)
+++ cfe/trunk/include/clang/Driver/Compilation.h Wed Jul  1 15:03:04 2009
@@ -69,6 +69,11 @@
   const ActionList &getActions() const { return Actions; }
 
   JobList &getJobs() { return Jobs; }
+  const JobList &getJobs() const { return Jobs; }
+
+  const ArgStringList &getTempFiles() const { return TempFiles; }
+
+  const ArgStringList &getResultFiles() const { return ResultFiles; }
 
   /// getArgsForToolChain - Return the derived argument list for the
   /// tool chain \arg TC (or the default tool chain, if TC is not
@@ -89,11 +94,6 @@
     return Name;
   }
 
-  /// Execute - Execute the compilation jobs and return an
-  /// appropriate exit code.
-  int Execute() const;
-
-private:
   /// CleanupFileList - Remove the files in the given list.
   ///
   /// \param IssueErrors - Report failures as errors.
@@ -120,7 +120,7 @@
   /// ExecuteJob - Execute a single job.
   ///
   /// \param FailingCommand - For non-zero results, this will be set to the
-  /// Command which failed, if any.
+  /// Command which failed.
   /// \return The accumulated result code of the job.
   int ExecuteJob(const Job &J, const Command *&FailingCommand) const;
 };

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

==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Wed Jul  1 15:03:04 2009
@@ -161,6 +161,14 @@
   /// \arg C - The compilation that is being built.
   void BuildJobs(Compilation &C) const;
 
+  /// ExecuteCompilation - Execute the compilation according to the command line
+  /// arguments and return an appropriate exit code.
+  ///
+  /// This routine handles additional processing that must be done in addition
+  /// to just running the subprocesses, for example reporting errors, removing
+  /// temporary files, etc.
+  int ExecuteCompilation(const Compilation &C) const;
+
   /// @}
   /// @name Helper Methods
   /// @{

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

==============================================================================
--- cfe/trunk/lib/Driver/Compilation.cpp (original)
+++ cfe/trunk/lib/Driver/Compilation.cpp Wed Jul  1 15:03:04 2009
@@ -155,51 +155,3 @@
     return 0;
   }
 }
-
-int Compilation::Execute() const {
-  // Just print if -### was present.
-  if (getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
-    PrintJob(llvm::errs(), Jobs, "\n", true);
-    return 0;
-  }
-
-  // If there were errors building the compilation, quit now.
-  if (getDriver().getDiags().getNumErrors())
-    return 1;
-
-  const Command *FailingCommand = 0;
-  int Res = ExecuteJob(Jobs, FailingCommand);
-  
-  // Remove temp files.
-  CleanupFileList(TempFiles);
-
-  // If the compilation failed, remove result files as well.
-  if (Res != 0 && !getArgs().hasArg(options::OPT_save_temps))
-    CleanupFileList(ResultFiles, true);
-
-  // Print extra information about abnormal failures, if possible.
-  if (Res) {
-    // This is ad-hoc, but we don't want to be excessively noisy. If the result
-    // status was 1, assume the command failed normally. In particular, if it
-    // was the compiler then assume it gave a reasonable error code. Failures in
-    // other tools are less common, and they generally have worse diagnostics,
-    // so always print the diagnostic there.
-    const Action &Source = FailingCommand->getSource();
-    bool IsFriendlyTool = (isa<PreprocessJobAction>(Source) ||
-                           isa<PrecompileJobAction>(Source) ||
-                           isa<AnalyzeJobAction>(Source) ||
-                           isa<CompileJobAction>(Source));
-
-    if (!IsFriendlyTool || Res != 1) {
-      // FIXME: See FIXME above regarding result code interpretation.
-      if (Res < 0)
-        getDriver().Diag(clang::diag::err_drv_command_signalled) 
-          << Source.getClassName() << -Res;
-      else
-        getDriver().Diag(clang::diag::err_drv_command_failed) 
-          << Source.getClassName() << Res;
-    }
-  }
-
-  return Res;
-}

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

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Jul  1 15:03:04 2009
@@ -217,6 +217,54 @@
   return C;
 }
 
+int Driver::ExecuteCompilation(const Compilation &C) const {
+  // Just print if -### was present.
+  if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
+    C.PrintJob(llvm::errs(), C.getJobs(), "\n", true);
+    return 0;
+  }
+
+  // If there were errors building the compilation, quit now.
+  if (getDiags().getNumErrors())
+    return 1;
+
+  const Command *FailingCommand = 0;
+  int Res = C.ExecuteJob(C.getJobs(), FailingCommand);
+  
+  // Remove temp files.
+  C.CleanupFileList(C.getTempFiles());
+
+  // If the compilation failed, remove result files as well.
+  if (Res != 0 && !C.getArgs().hasArg(options::OPT_save_temps))
+    C.CleanupFileList(C.getResultFiles(), true);
+
+  // Print extra information about abnormal failures, if possible.
+  if (Res) {
+    // This is ad-hoc, but we don't want to be excessively noisy. If the result
+    // status was 1, assume the command failed normally. In particular, if it
+    // was the compiler then assume it gave a reasonable error code. Failures in
+    // other tools are less common, and they generally have worse diagnostics,
+    // so always print the diagnostic there.
+    const Action &Source = FailingCommand->getSource();
+    bool IsFriendlyTool = (isa<PreprocessJobAction>(Source) ||
+                           isa<PrecompileJobAction>(Source) ||
+                           isa<AnalyzeJobAction>(Source) ||
+                           isa<CompileJobAction>(Source));
+
+    if (!IsFriendlyTool || Res != 1) {
+      // FIXME: See FIXME above regarding result code interpretation.
+      if (Res < 0)
+        Diag(clang::diag::err_drv_command_signalled) 
+          << Source.getClassName() << -Res;
+      else
+        Diag(clang::diag::err_drv_command_failed) 
+          << Source.getClassName() << Res;
+    }
+  }
+
+  return Res;
+}
+
 void Driver::PrintOptions(const ArgList &Args) const {
   unsigned i = 0;
   for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); 

Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=74634&r1=74633&r2=74634&view=diff

==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Wed Jul  1 15:03:04 2009
@@ -219,7 +219,7 @@
 
   int Res = 0;
   if (C.get())
-    Res = C->Execute();
+    Res = TheDriver.ExecuteCompilation(*C);
 
   llvm::llvm_shutdown();
 





More information about the cfe-commits mailing list