[cfe-commits] r95194 - in /cfe/trunk: include/clang/Driver/Options.td include/clang/Driver/Tool.h include/clang/Driver/ToolChain.h lib/Driver/Driver.cpp lib/Driver/Tools.cpp lib/Driver/Tools.h

Daniel Dunbar daniel at zuster.org
Tue Feb 2 19:07:57 PST 2010


Author: ddunbar
Date: Tue Feb  2 21:07:56 2010
New Revision: 95194

URL: http://llvm.org/viewvc/llvm-project?rev=95194&view=rev
Log:
Driver: Add -[no-]integrated-as for clang.
 - Requires backend support, which only exists for i386--darwin currently.

No 'as' required:
--
ddunbar at ozzy:tmp$ cat t.c
int main() { return 42; }
ddunbar at ozzy:tmp$ clang -m32 -integrated-as t.c


ddunbar at ozzy:tmp$ ./a.out; echo $?
42
ddunbar at ozzy:tmp$
--

The random extra whitespace is how you know its working! :)

Modified:
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/include/clang/Driver/Tool.h
    cfe/trunk/include/clang/Driver/ToolChain.h
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/lib/Driver/Tools.h

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

==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Feb  2 21:07:56 2010
@@ -377,6 +377,7 @@
 def include_ : JoinedOrSeparate<"-include">, Group<clang_i_Group>, EnumName<"include">;
 def init : Separate<"-init">;
 def install__name : Separate<"-install_name">;
+def integrated_as : Flag<"-integrated-as">, Flags<[DriverOption]>;
 def iprefix : JoinedOrSeparate<"-iprefix">, Group<clang_i_Group>;
 def iquote : JoinedOrSeparate<"-iquote">, Group<clang_i_Group>;
 def isysroot : JoinedOrSeparate<"-isysroot">, Group<clang_i_Group>;
@@ -444,6 +445,7 @@
 def no_canonical_prefixes : Flag<"-no-canonical-prefixes">, Flags<[DriverOption, HelpHidden]>,
   HelpText<"Use relative instead of canonical paths">;
 def no_cpp_precomp : Flag<"-no-cpp-precomp">;
+def no_integrated_as : Flag<"-no-integrated-as">, Flags<[DriverOption]>;
 def no_integrated_cpp : Flag<"-no-integrated-cpp">, Flags<[DriverOption]>;
 def no__dead__strip__inits__and__terms : Flag<"-no_dead_strip_inits_and_terms">;
 def nobuiltininc : Flag<"-nobuiltininc">;

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

==============================================================================
--- cfe/trunk/include/clang/Driver/Tool.h (original)
+++ cfe/trunk/include/clang/Driver/Tool.h Tue Feb  2 21:07:56 2010
@@ -45,6 +45,7 @@
 
   virtual bool acceptsPipedInput() const = 0;
   virtual bool canPipeOutput() const = 0;
+  virtual bool hasIntegratedAssembler() const { return false; }
   virtual bool hasIntegratedCPP() const = 0;
 
   /// ConstructJob - Construct jobs to perform the action \arg JA,

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

==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Tue Feb  2 21:07:56 2010
@@ -90,6 +90,10 @@
   /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
   virtual bool IsBlocksDefault() const { return false; }
 
+  /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
+  /// by default.
+  virtual bool IsIntegratedAssemblerDefault() const { return false; }
+
   /// IsObjCNonFragileABIDefault - Does this tool chain set
   /// -fobjc-nonfragile-abi by default.
   virtual bool IsObjCNonFragileABIDefault() const { return false; }

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

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Feb  2 21:07:56 2010
@@ -865,6 +865,44 @@
   }
 }
 
+static const Tool &SelectToolForJob(Compilation &C, const ToolChain *TC,
+                                    const JobAction *JA,
+                                    const ActionList *&Inputs) {
+  const Tool *ToolForJob = 0;
+
+  // See if we should look for a compiler with an integrated assembler. We match
+  // bottom up, so what we are actually looking for is an assembler job with a
+  // compiler input.
+  if (C.getArgs().hasArg(options::OPT_integrated_as,
+                         options::OPT_no_integrated_as,
+                         TC->IsIntegratedAssemblerDefault()) &&
+      !C.getArgs().hasArg(options::OPT_save_temps) &&
+      isa<AssembleJobAction>(JA) &&
+      Inputs->size() == 1 && isa<CompileJobAction>(*Inputs->begin())) {
+    const Tool &Compiler = TC->SelectTool(C,cast<JobAction>(**Inputs->begin()));
+    if (Compiler.hasIntegratedAssembler()) {
+      Inputs = &(*Inputs)[0]->getInputs();
+      ToolForJob = &Compiler;
+    }
+  }
+
+  // Otherwise use the tool for the current job.
+  if (!ToolForJob)
+    ToolForJob = &TC->SelectTool(C, *JA);
+
+  // See if we should use an integrated preprocessor. We do so when we have
+  // exactly one input, since this is the only use case we care about
+  // (irrelevant since we don't support combine yet).
+  if (Inputs->size() == 1 && isa<PreprocessJobAction>(*Inputs->begin()) &&
+      !C.getArgs().hasArg(options::OPT_no_integrated_cpp) &&
+      !C.getArgs().hasArg(options::OPT_traditional_cpp) &&
+      !C.getArgs().hasArg(options::OPT_save_temps) &&
+      ToolForJob->hasIntegratedCPP())
+    Inputs = &(*Inputs)[0]->getInputs();
+
+  return *ToolForJob;
+}
+
 void Driver::BuildJobsForAction(Compilation &C,
                                 const Action *A,
                                 const ToolChain *TC,
@@ -905,21 +943,10 @@
     return;
   }
 
-  const JobAction *JA = cast<JobAction>(A);
-  const Tool &T = TC->SelectTool(C, *JA);
-
-  // See if we should use an integrated preprocessor. We do so when we have
-  // exactly one input, since this is the only use case we care about
-  // (irrelevant since we don't support combine yet).
   const ActionList *Inputs = &A->getInputs();
-  if (Inputs->size() == 1 && isa<PreprocessJobAction>(*Inputs->begin())) {
-    if (!C.getArgs().hasArg(options::OPT_no_integrated_cpp) &&
-        !C.getArgs().hasArg(options::OPT_traditional_cpp) &&
-        !C.getArgs().hasArg(options::OPT_save_temps) &&
-        T.hasIntegratedCPP()) {
-      Inputs = &(*Inputs)[0]->getInputs();
-    }
-  }
+
+  const JobAction *JA = cast<JobAction>(A);
+  const Tool &T = SelectToolForJob(C, TC, JA, Inputs);
 
   // Only use pipes when there is exactly one input.
   bool TryToUsePipeInput = Inputs->size() == 1 && T.acceptsPipedInput();

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Feb  2 21:07:56 2010
@@ -651,6 +651,8 @@
       CmdArgs.push_back("-Eonly");
     else
       CmdArgs.push_back("-E");
+  } else if (isa<AssembleJobAction>(JA)) {
+    CmdArgs.push_back("-emit-obj");
   } else if (isa<PrecompileJobAction>(JA)) {
     // Use PCH if the user requested it, except for C++ (for now).
     bool UsePCH = D.CCCUsePCH;

Modified: cfe/trunk/lib/Driver/Tools.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.h?rev=95194&r1=95193&r2=95194&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Tools.h (original)
+++ cfe/trunk/lib/Driver/Tools.h Tue Feb  2 21:07:56 2010
@@ -41,6 +41,7 @@
 
     virtual bool acceptsPipedInput() const { return true; }
     virtual bool canPipeOutput() const { return true; }
+    virtual bool hasIntegratedAssembler() const { return true; }
     virtual bool hasIntegratedCPP() const { return true; }
 
     virtual void ConstructJob(Compilation &C, const JobAction &JA,





More information about the cfe-commits mailing list