]> granicus.if.org Git - clang/commitdiff
Frontend: Add FrontendAction support for handling LLVM IR inputs.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 7 Jun 2010 23:26:47 +0000 (23:26 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 7 Jun 2010 23:26:47 +0000 (23:26 +0000)
 - These inputs follow an abbreviated execution path, but are still worth handling by FrontendAction so they reuse all the other clang -cc1 features.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105582 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/FrontendAction.h
lib/Frontend/ASTUnit.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Frontend/FrontendAction.cpp
lib/Frontend/FrontendOptions.cpp

index 3992c92874a6d9c4f8e2198456f57b1275203fc2..5a627ef960def589dc91dc367d94f6420311df1b 100644 (file)
@@ -32,7 +32,8 @@ enum InputKind {
   IK_PreprocessedObjC,
   IK_PreprocessedObjCXX,
   IK_OpenCL,
-  IK_AST
+  IK_AST,
+  IK_LLVM_IR
 };
 
 
@@ -153,6 +154,9 @@ public:
   /// 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; }
index 28000bbb67cee8ca78be261a07f31b0c27c5d1d3..68e7ac17eae02b3bb517e6b4a85bac2a83b1ad36 100644 (file)
@@ -334,6 +334,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI,
          "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));
index df2bb28c9b5adae9f83badba4eb3d368ace533f3..026a92c7f67927c1844f3efc67e0d4dd1caae5ec 100644 (file)
@@ -287,6 +287,7 @@ static const char *getInputKindName(InputKind Kind) {
   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 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
       .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 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
     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 @@ void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
   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);
index 56676e1ef93e3b49ce3b7c38bf6607e7fedc45a0..b761f30adf4f3c0b61a25bc10e71204cb8d0148b 100644 (file)
@@ -75,11 +75,28 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
     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.
index ef4c3fa23c2d3fe7a83a727669193f4e81ab693d..9dfee244ea36348dfb6afb4a7ec712439c8f0c83 100644 (file)
@@ -26,5 +26,6 @@ InputKind FrontendOptions::getInputKindForExtension(llvm::StringRef Extension) {
     .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);
 }