[cfe-commits] r95182 - in /cfe/trunk: include/clang/Driver/CC1Options.td include/clang/Frontend/ASTConsumers.h include/clang/Frontend/FrontendActions.h include/clang/Frontend/FrontendOptions.h lib/Frontend/Backend.cpp lib/Frontend/CompilerInvocation.cpp lib/Frontend/FrontendActions.cpp tools/driver/cc1_main.cpp

Daniel Dunbar daniel at zuster.org
Tue Feb 2 17:18:43 PST 2010


Author: ddunbar
Date: Tue Feb  2 19:18:43 2010
New Revision: 95182

URL: http://llvm.org/viewvc/llvm-project?rev=95182&view=rev
Log:
clang -cc1: Wire up -emit-obj, for emitting object files.

Modified:
    cfe/trunk/include/clang/Driver/CC1Options.td
    cfe/trunk/include/clang/Frontend/ASTConsumers.h
    cfe/trunk/include/clang/Frontend/FrontendActions.h
    cfe/trunk/include/clang/Frontend/FrontendOptions.h
    cfe/trunk/lib/Frontend/Backend.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/tools/driver/cc1_main.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Feb  2 19:18:43 2010
@@ -281,6 +281,8 @@
   HelpText<"Build ASTs then convert to LLVM, emit .bc file">;
 def emit_llvm_only : Flag<"-emit-llvm-only">,
   HelpText<"Build ASTs and convert to LLVM, discarding output">;
+def emit_obj : Flag<"-emit-obj">,
+  HelpText<"Emit native object files">;
 def rewrite_test : Flag<"-rewrite-test">,
   HelpText<"Rewriter playground">;
 def rewrite_objc : Flag<"-rewrite-objc">,

Modified: cfe/trunk/include/clang/Frontend/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTConsumers.h?rev=95182&r1=95181&r2=95182&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTConsumers.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTConsumers.h Tue Feb  2 19:18:43 2010
@@ -73,10 +73,11 @@
 // assembly. This runs optimizations depending on the CodeGenOptions
 // parameter. The output depends on the Action parameter.
 enum BackendAction {
-  Backend_EmitAssembly,  // Emit native assembly
-  Backend_EmitBC,        // Emit LLVM bitcode file
+  Backend_EmitAssembly,  // Emit native assembly files
+  Backend_EmitBC,        // Emit LLVM bitcode files
   Backend_EmitLL,        // Emit human-readable LLVM assembly
-  Backend_EmitNothing    // Don't emit anything (benchmarking mode)
+  Backend_EmitNothing,   // Don't emit anything (benchmarking mode)
+  Backend_EmitObj        // Emit native object files
 };
 ASTConsumer *CreateBackendConsumer(BackendAction Action,
                                    Diagnostic &Diags,

Modified: cfe/trunk/include/clang/Frontend/FrontendActions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendActions.h?rev=95182&r1=95181&r2=95182&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendActions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendActions.h Tue Feb  2 19:18:43 2010
@@ -154,6 +154,11 @@
   EmitLLVMOnlyAction();
 };
 
+class EmitObjAction : public CodeGenAction {
+public:
+  EmitObjAction();
+};
+
 //===----------------------------------------------------------------------===//
 // Preprocessor Actions
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=95182&r1=95181&r2=95182&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Tue Feb  2 19:18:43 2010
@@ -31,6 +31,7 @@
     EmitHTML,               ///< Translate input source into HTML.
     EmitLLVM,               ///< Emit a .ll file.
     EmitLLVMOnly,           ///< Generate LLVM IR, but do not
+    EmitObj,                ///< Emit a .o file.
     FixIt,                  ///< Parse and apply any fixits to the source.
     GeneratePCH,            ///< Generate pre-compiled header.
     GeneratePTH,            ///< Generate pre-tokenized header.

Modified: cfe/trunk/lib/Frontend/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Backend.cpp?rev=95182&r1=95181&r2=95182&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/Backend.cpp (original)
+++ cfe/trunk/lib/Frontend/Backend.cpp Tue Feb  2 19:18:43 2010
@@ -303,16 +303,15 @@
     case 3: OptLevel = CodeGenOpt::Aggressive; break;
     }
 
-    // Normal mode, emit a .s file by running the code generator.
-    // Note, this also adds codegenerator level optimization passes.
-    switch (TM->addPassesToEmitFile(*PM, FormattedOutStream,
-                                    TargetMachine::CGFT_AssemblyFile,
-                                    OptLevel)) {
-    default:
+    // Normal mode, emit a .s or .o file by running the code generator. Note,
+    // this also adds codegenerator level optimization passes.
+    TargetMachine::CodeGenFileType CGFT = TargetMachine::CGFT_AssemblyFile;
+    if (Action == Backend_EmitObj)
+      CGFT = TargetMachine::CGFT_ObjectFile;
+    if (TM->addPassesToEmitFile(*PM, FormattedOutStream,
+                                CGFT, OptLevel) != CGFT) {
       Diags.Report(diag::err_fe_unable_to_interface_with_target);
       return false;
-    case TargetMachine::CGFT_AssemblyFile:
-      break;
     }
   }
 

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=95182&r1=95181&r2=95182&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Feb  2 19:18:43 2010
@@ -280,6 +280,7 @@
   case frontend::EmitHTML:               return "-emit-html";
   case frontend::EmitLLVM:               return "-emit-llvm";
   case frontend::EmitLLVMOnly:           return "-emit-llvm-only";
+  case frontend::EmitObj:                return "-emit-obj";
   case frontend::FixIt:                  return "-fixit";
   case frontend::GeneratePCH:            return "-emit-pch";
   case frontend::GeneratePTH:            return "-emit-pth";
@@ -858,6 +859,8 @@
       Opts.ProgramAction = frontend::EmitLLVM; break;
     case OPT_emit_llvm_only:
       Opts.ProgramAction = frontend::EmitLLVMOnly; break;
+    case OPT_emit_obj:
+      Opts.ProgramAction = frontend::EmitObj; break;
     case OPT_fixit:
       Opts.ProgramAction = frontend::FixIt; break;
     case OPT_emit_pch:

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=95182&r1=95181&r2=95182&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Tue Feb  2 19:18:43 2010
@@ -177,6 +177,9 @@
     break;
   case Backend_EmitNothing:
     break;
+  case Backend_EmitObj:
+    OS.reset(CI.createDefaultOutputFile(true, InFile, "o"));
+    break;
   }
   if (BA != Backend_EmitNothing && !OS)
     return 0;
@@ -196,6 +199,8 @@
 
 EmitLLVMOnlyAction::EmitLLVMOnlyAction() : CodeGenAction(Backend_EmitNothing) {}
 
+EmitObjAction::EmitObjAction() : CodeGenAction(Backend_EmitObj) {}
+
 //===----------------------------------------------------------------------===//
 // Preprocessor Actions
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Tue Feb  2 19:18:43 2010
@@ -70,6 +70,7 @@
   case EmitHTML:               return new HTMLPrintAction();
   case EmitLLVM:               return new EmitLLVMAction();
   case EmitLLVMOnly:           return new EmitLLVMOnlyAction();
+  case EmitObj:                return new EmitObjAction();
   case FixIt:                  return new FixItAction();
   case GeneratePCH:            return new GeneratePCHAction();
   case GeneratePTH:            return new GeneratePTHAction();





More information about the cfe-commits mailing list