[cfe-commits] r66844 - in /cfe/trunk: include/clang/Basic/DiagnosticDriverKinds.def include/clang/Driver/Driver.h include/clang/Driver/Options.def lib/Driver/Driver.cpp

Daniel Dunbar daniel at zuster.org
Thu Mar 12 16:55:14 PDT 2009


Author: ddunbar
Date: Thu Mar 12 18:55:14 2009
New Revision: 66844

URL: http://llvm.org/viewvc/llvm-project?rev=66844&view=rev
Log:
Driver: Determine which compilation stages to run.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/include/clang/Driver/Options.def
    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=66844&r1=66843&r2=66844&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.def Thu Mar 12 18:55:14 2009
@@ -24,3 +24,7 @@
      "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")
+DIAG(err_drv_no_input_files, ERROR,
+     "no input files")
+DIAG(err_drv_use_of_Z_option, ERROR,
+     "unsupported use of internal gcc -Z option '%0'")

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

==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Thu Mar 12 18:55:14 2009
@@ -29,6 +29,25 @@
 /// Driver - Encapsulate logic for constructing compilation processes
 /// from a set of gcc-driver-like command line arguments.
 class Driver {
+  /// PhaseOrder - Ordered values for successive stages in the
+  /// compilation process which interact with user options.
+  enum PhaseOrder {
+    /// Nothing.
+    NoPhaseOrder = 0,
+
+    /// Only run the preprocessor.
+    PreprocessPhaseOrder,
+
+    /// Only run the preprocessor and compiler.
+    CompilePhaseOrder,
+
+    /// Only run the preprocessor, compiler, and assembler.
+    AssemblePhaseOrder,
+
+    /// Run everything.
+    PostAssemblePhaseOrder
+  };
+
   OptTable *Opts;
 
   Diagnostic &Diags;

Modified: cfe/trunk/include/clang/Driver/Options.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.def?rev=66844&r1=66843&r2=66844&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Options.def (original)
+++ cfe/trunk/include/clang/Driver/Options.def Thu Mar 12 18:55:14 2009
@@ -111,7 +111,7 @@
 OPTION("--bootclasspath", _bootclasspath, Separate, INVALID, fbootclasspath_EQ, "J", 0)
 OPTION("--classpath=", _classpath_EQ, Joined, INVALID, fclasspath_EQ, "", 0)
 OPTION("--classpath", _classpath, Separate, INVALID, fclasspath_EQ, "J", 0)
-OPTION("--combine", _combine, Flag, INVALID, combine, "", 0)
+OPTION("--combine", _combine, Flag, INVALID, combine, "u", 0)
 OPTION("--comments-in-macros", _comments_in_macros, Flag, INVALID, CC, "", 0)
 OPTION("--comments", _comments, Flag, INVALID, C, "", 0)
 OPTION("--compile", _compile, Flag, INVALID, c, "", 0)

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

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Mar 12 18:55:14 2009
@@ -244,7 +244,9 @@
 void Driver::BuildActions(ArgList &Args, ActionList &Actions) {
   types::ID InputType = types::TY_INVALID;
   Arg *InputTypeArg = 0;
-  
+
+  // Start by constructing the list of inputs and their types.
+
   llvm::SmallVector<std::pair<types::ID, const Arg*>, 16> Inputs;
   for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); 
        it != ie; ++it) {
@@ -323,6 +325,46 @@
     }
   }
 
+  if (Inputs.empty()) {
+    Diag(clang::diag::err_drv_no_input_files);
+    return;
+  }
+
+  // Determine which compilation mode we are in. We look for options
+  // which affect the phase, starting with the earliest phases, and
+  // record which option we used to determine the final phase.
+  Arg *FinalPhaseOpt = 0;
+  PhaseOrder FinalPhase;
+
+  // -{E,M,MM} only run the preprocessor.
+  if ((FinalPhaseOpt = Args.getLastArg(options::OPT_E)) ||
+      (FinalPhaseOpt = Args.getLastArg(options::OPT_M)) ||
+      (FinalPhaseOpt = Args.getLastArg(options::OPT_MM))) {
+    FinalPhase = PreprocessPhaseOrder;
+    
+    // -{-analyze,fsyntax-only,S} only run up to the compiler.
+  } else if ((FinalPhaseOpt = Args.getLastArg(options::OPT__analyze)) ||
+             (FinalPhaseOpt = Args.getLastArg(options::OPT_fsyntax_only)) ||
+             (FinalPhaseOpt = Args.getLastArg(options::OPT_S))) {
+    FinalPhase = CompilePhaseOrder;
+
+    // -c only runs up to the assembler.
+  } else if ((FinalPhaseOpt = Args.getLastArg(options::OPT_c))) {
+    FinalPhase = AssemblePhaseOrder;
+    
+    // Otherwise do everything.
+  } else
+    FinalPhase = PostAssemblePhaseOrder;
+
+  if (FinalPhaseOpt)
+    FinalPhaseOpt->claim();
+
+  // Reject -Z* at the top level, these options should never have been
+  // exposed by gcc.
+  if (Arg *A = Args.getLastArg(options::OPT_Z))
+    Diag(clang::diag::err_drv_use_of_Z_option) << A->getValue(Args);
+
+  // FIXME: This is just debugging code.
   for (unsigned i = 0, e = Inputs.size(); i != e; ++i) {
     llvm::errs() << "input " << i << ": " 
                  << Inputs[i].second->getValue(Args) << "\n";





More information about the cfe-commits mailing list