[cfe-commits] r105582 - in /cfe/trunk: include/clang/Frontend/FrontendAction.h lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInvocation.cpp lib/Frontend/FrontendAction.cpp lib/Frontend/FrontendOptions.cpp

Daniel Dunbar daniel at zuster.org
Mon Jun 7 16:26:47 PDT 2010


Author: ddunbar
Date: Mon Jun  7 18:26:47 2010
New Revision: 105582

URL: http://llvm.org/viewvc/llvm-project?rev=105582&view=rev
Log:
Frontend: Add FrontendAction support for handling LLVM IR inputs.
 - These inputs follow an abbreviated execution path, but are still worth handling by FrontendAction so they reuse all the other clang -cc1 features.

Modified:
    cfe/trunk/include/clang/Frontend/FrontendAction.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/FrontendAction.cpp
    cfe/trunk/lib/Frontend/FrontendOptions.cpp

Modified: cfe/trunk/include/clang/Frontend/FrontendAction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendAction.h?rev=105582&r1=105581&r2=105582&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendAction.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendAction.h Mon Jun  7 18:26:47 2010
@@ -32,7 +32,8 @@
   IK_PreprocessedObjC,
   IK_PreprocessedObjCXX,
   IK_OpenCL,
-  IK_AST
+  IK_AST,
+  IK_LLVM_IR
 };
 
 
@@ -153,6 +154,9 @@
   /// hasASTFileSupport - Does this action support use with AST files?
   virtual bool hasASTFileSupport() const { return !usesPreprocessorOnly(); }
 
+  /// hasIRSupport - Does this action support use with IR files?
+  virtual bool hasIRSupport() const { return false; }
+
   /// hasCodeCompletionSupport - Does this action support use with code
   /// completion?
   virtual bool hasCodeCompletionSupport() const { return false; }

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=105582&r1=105581&r2=105582&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Jun  7 18:26:47 2010
@@ -334,6 +334,8 @@
          "Invocation must have exactly one source file!");
   assert(Clang.getFrontendOpts().Inputs[0].first != IK_AST &&
          "FIXME: AST inputs not yet supported here!");
+  assert(Clang.getFrontendOpts().Inputs[0].first != IK_LLVM_IR &&
+         "IR inputs not support here!");
 
   // Create the AST unit.
   AST.reset(new ASTUnit(false));

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=105582&r1=105581&r2=105582&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Jun  7 18:26:47 2010
@@ -287,6 +287,7 @@
   case IK_Asm:               return "assembler-with-cpp";
   case IK_C:                 return "c";
   case IK_CXX:               return "c++";
+  case IK_LLVM_IR:           return "ir";
   case IK_ObjC:              return "objective-c";
   case IK_ObjCXX:            return "objective-c++";
   case IK_OpenCL:            return "cl";
@@ -1022,6 +1023,7 @@
       .Case("c++-header", IK_CXX)
       .Case("objective-c++-header", IK_ObjCXX)
       .Case("ast", IK_AST)
+      .Case("ir", IK_LLVM_IR)
       .Default(IK_None);
     if (DashX == IK_None)
       Diags.Report(diag::err_drv_invalid_value)
@@ -1141,6 +1143,7 @@
     switch (IK) {
     case IK_None:
     case IK_AST:
+    case IK_LLVM_IR:
       assert(0 && "Invalid input kind!");
     case IK_OpenCL:
       LangStd = LangStandard::lang_opencl;
@@ -1401,7 +1404,7 @@
   ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, Diags);
   InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags);
   ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
-  if (DashX != IK_AST)
+  if (DashX != IK_AST && DashX != IK_LLVM_IR)
     ParseLangArgs(Res.getLangOpts(), *Args, DashX, Diags);
   ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, Diags);
   ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args);

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=105582&r1=105581&r2=105582&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Mon Jun  7 18:26:47 2010
@@ -75,11 +75,28 @@
     return true;
   }
 
-  // Setup the file and source managers, if needed, and the preprocessor.
+  // Set up the file and source managers, if needed.
   if (!CI.hasFileManager())
     CI.createFileManager();
   if (!CI.hasSourceManager())
     CI.createSourceManager();
+
+  // IR files bypass the rest of initialization.
+  if (InputKind == IK_LLVM_IR) {
+    assert(hasIRSupport() &&
+           "This action does not have IR file support!");
+
+    // Inform the diagnostic client we are processing a source file.
+    CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), 0);
+
+    // Initialize the action.
+    if (!BeginSourceFileAction(CI, Filename))
+      goto failure;
+
+    return true;
+  }
+
+  // Set up the preprocessor.
   CI.createPreprocessor();
 
   // Inform the diagnostic client we are processing a source file.

Modified: cfe/trunk/lib/Frontend/FrontendOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendOptions.cpp?rev=105582&r1=105581&r2=105582&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendOptions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendOptions.cpp Mon Jun  7 18:26:47 2010
@@ -26,5 +26,6 @@
     .Cases("C", "cc", "cp", IK_CXX)
     .Cases("cpp", "CPP", "c++", "cxx", "hpp", IK_CXX)
     .Case("cl", IK_OpenCL)
+    .Cases("ll", "bc", IK_LLVM_IR)
     .Default(IK_C);
 }





More information about the cfe-commits mailing list