]> granicus.if.org Git - clang/commitdiff
Frontend: Pull CodeGenAction out more, and eliminate CreateBackendConsumer.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 25 Feb 2010 04:37:45 +0000 (04:37 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 25 Feb 2010 04:37:45 +0000 (04:37 +0000)
This is the way I would like to move the frontend function towards -- distinct
pieces of functionality should be exposed only via FrontendAction
implementations which have clean and relatively-stable APIs.

This also isolates the surface area in clang which depends on LLVM CodeGen.

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

include/clang/Frontend/ASTConsumers.h
include/clang/Frontend/CodeGenAction.h [new file with mode: 0644]
include/clang/Frontend/FrontendActions.h
lib/Frontend/CodeGenAction.cpp [moved from lib/Frontend/Backend.cpp with 87% similarity]
lib/Frontend/FrontendActions.cpp
tools/driver/cc1_main.cpp

index 7ec5063b5334d58f60ba1a370fa9da2a94010779..b5b09f536d6ea7363490aa87eac1059846c38cd1 100644 (file)
@@ -69,26 +69,6 @@ ASTConsumer *CreateObjCRewriter(const std::string &InFile,
                                 const LangOptions &LOpts,
                                 bool SilenceRewriteMacroWarning);
 
-// LLVM code generator: uses the code generation backend to generate LLVM
-// assembly. This runs optimizations depending on the CodeGenOptions
-// parameter. The output depends on the Action parameter.
-enum BackendAction {
-  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_EmitObj        // Emit native object files
-};
-ASTConsumer *CreateBackendConsumer(BackendAction Action,
-                                   Diagnostic &Diags,
-                                   const LangOptions &Features,
-                                   const CodeGenOptions &CodeGenOpts,
-                                   const TargetOptions &TargetOpts,
-                                   bool TimePasses,
-                                   const std::string &ModuleID,
-                                   llvm::raw_ostream *OS,
-                                   llvm::LLVMContext& C);
-
 /// CreateHTMLPrinter - Create an AST consumer which rewrites source code to
 /// HTML with syntax highlighting suitable for viewing in a web-browser.
 ASTConsumer *CreateHTMLPrinter(llvm::raw_ostream *OS, Preprocessor &PP,
diff --git a/include/clang/Frontend/CodeGenAction.h b/include/clang/Frontend/CodeGenAction.h
new file mode 100644 (file)
index 0000000..f782e12
--- /dev/null
@@ -0,0 +1,50 @@
+//===--- CodeGenAction.h - LLVM Code Generation Frontend Action -*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/FrontendAction.h"
+
+namespace clang {
+
+class CodeGenAction : public ASTFrontendAction {
+private:
+  unsigned Act;
+
+protected:
+  CodeGenAction(unsigned _Act);
+
+  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
+                                         llvm::StringRef InFile);
+};
+
+class EmitAssemblyAction : public CodeGenAction {
+public:
+  EmitAssemblyAction();
+};
+
+class EmitBCAction : public CodeGenAction {
+public:
+  EmitBCAction();
+};
+
+class EmitLLVMAction : public CodeGenAction {
+public:
+  EmitLLVMAction();
+};
+
+class EmitLLVMOnlyAction : public CodeGenAction {
+public:
+  EmitLLVMOnlyAction();
+};
+
+class EmitObjAction : public CodeGenAction {
+public:
+  EmitObjAction();
+};
+
+}
index cbb3508c8a76b22b89f74be1fd40987967fd978f..5348e6b1ee9c62bf17eeed86bc6e5acb8036985b 100644 (file)
@@ -158,46 +158,6 @@ public:
   virtual bool hasCodeCompletionSupport() const;
 };
 
-//===----------------------------------------------------------------------===//
-// Code Gen AST Actions
-//===----------------------------------------------------------------------===//
-
-class CodeGenAction : public ASTFrontendAction {
-private:
-  unsigned Act;
-
-protected:
-  CodeGenAction(unsigned _Act);
-
-  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
-                                         llvm::StringRef InFile);
-};
-
-class EmitAssemblyAction : public CodeGenAction {
-public:
-  EmitAssemblyAction();
-};
-
-class EmitBCAction : public CodeGenAction {
-public:
-  EmitBCAction();
-};
-
-class EmitLLVMAction : public CodeGenAction {
-public:
-  EmitLLVMAction();
-};
-
-class EmitLLVMOnlyAction : public CodeGenAction {
-public:
-  EmitLLVMOnlyAction();
-};
-
-class EmitObjAction : public CodeGenAction {
-public:
-  EmitObjAction();
-};
-
 //===----------------------------------------------------------------------===//
 // Preprocessor Actions
 //===----------------------------------------------------------------------===//
similarity index 87%
rename from lib/Frontend/Backend.cpp
rename to lib/Frontend/CodeGenAction.cpp
index f5291a9525e716305fc92e2bc313af0487ab63b4..7800d1534eeae89f9a87d06d2557720918c4fed4 100644 (file)
@@ -1,4 +1,4 @@
-//===--- Backend.cpp - Interface to LLVM backend technologies -------------===//
+//===--- CodeGenAction.cpp - LLVM Code Generation Frontend Action ---------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Frontend/ASTConsumers.h"
+#include "clang/Frontend/CodeGenAction.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclGroup.h"
@@ -15,6 +15,8 @@
 #include "clang/Basic/TargetOptions.h"
 #include "clang/CodeGen/CodeGenOptions.h"
 #include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/ASTConsumers.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
@@ -37,6 +39,14 @@ using namespace clang;
 using namespace llvm;
 
 namespace {
+  enum BackendAction {
+    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_EmitObj        ///< Emit native object files
+  };
+
   class BackendConsumer : public ASTConsumer {
     Diagnostic &Diags;
     BackendAction Action;
@@ -419,15 +429,46 @@ void BackendConsumer::EmitAssembly() {
   }
 }
 
-ASTConsumer *clang::CreateBackendConsumer(BackendAction Action,
-                                          Diagnostic &Diags,
-                                          const LangOptions &LangOpts,
-                                          const CodeGenOptions &CodeGenOpts,
-                                          const TargetOptions &TargetOpts,
-                                          bool TimePasses,
-                                          const std::string& InFile,
-                                          llvm::raw_ostream* OS,
-                                          LLVMContext& C) {
-  return new BackendConsumer(Action, Diags, LangOpts, CodeGenOpts,
-                             TargetOpts, TimePasses, InFile, OS, C);
+//
+
+CodeGenAction::CodeGenAction(unsigned _Act) : Act(_Act) {}
+
+ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI,
+                                              llvm::StringRef InFile) {
+  BackendAction BA = static_cast<BackendAction>(Act);
+  llvm::OwningPtr<llvm::raw_ostream> OS;
+  switch (BA) {
+  case Backend_EmitAssembly:
+    OS.reset(CI.createDefaultOutputFile(false, InFile, "s"));
+    break;
+  case Backend_EmitLL:
+    OS.reset(CI.createDefaultOutputFile(false, InFile, "ll"));
+    break;
+  case Backend_EmitBC:
+    OS.reset(CI.createDefaultOutputFile(true, InFile, "bc"));
+    break;
+  case Backend_EmitNothing:
+    break;
+  case Backend_EmitObj:
+    OS.reset(CI.createDefaultOutputFile(true, InFile, "o"));
+    break;
+  }
+  if (BA != Backend_EmitNothing && !OS)
+    return 0;
+
+  return new BackendConsumer(BA, CI.getDiagnostics(), CI.getLangOpts(),
+                             CI.getCodeGenOpts(), CI.getTargetOpts(),
+                             CI.getFrontendOpts().ShowTimers, InFile, OS.take(),
+                             CI.getLLVMContext());
 }
+
+EmitAssemblyAction::EmitAssemblyAction()
+  : CodeGenAction(Backend_EmitAssembly) {}
+
+EmitBCAction::EmitBCAction() : CodeGenAction(Backend_EmitBC) {}
+
+EmitLLVMAction::EmitLLVMAction() : CodeGenAction(Backend_EmitLL) {}
+
+EmitLLVMOnlyAction::EmitLLVMOnlyAction() : CodeGenAction(Backend_EmitNothing) {}
+
+EmitObjAction::EmitObjAction() : CodeGenAction(Backend_EmitObj) {}
index 1c958a7087a91cc3daaacee7f4c0f985af9ab9c4..1e210b42e6d16dc3d1b422ac23ec075e86b461f7 100644 (file)
@@ -159,48 +159,6 @@ ASTConsumer *SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI,
   return new ASTConsumer();
 }
 
-CodeGenAction::CodeGenAction(unsigned _Act) : Act(_Act) {}
-
-ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI,
-                                              llvm::StringRef InFile) {
-  BackendAction BA = static_cast<BackendAction>(Act);
-  llvm::OwningPtr<llvm::raw_ostream> OS;
-  switch (BA) {
-  case Backend_EmitAssembly:
-    OS.reset(CI.createDefaultOutputFile(false, InFile, "s"));
-    break;
-  case Backend_EmitLL:
-    OS.reset(CI.createDefaultOutputFile(false, InFile, "ll"));
-    break;
-  case Backend_EmitBC:
-    OS.reset(CI.createDefaultOutputFile(true, InFile, "bc"));
-    break;
-  case Backend_EmitNothing:
-    break;
-  case Backend_EmitObj:
-    OS.reset(CI.createDefaultOutputFile(true, InFile, "o"));
-    break;
-  }
-  if (BA != Backend_EmitNothing && !OS)
-    return 0;
-
-  return CreateBackendConsumer(BA, CI.getDiagnostics(), CI.getLangOpts(),
-                               CI.getCodeGenOpts(), CI.getTargetOpts(),
-                               CI.getFrontendOpts().ShowTimers, InFile,
-                               OS.take(), CI.getLLVMContext());
-}
-
-EmitAssemblyAction::EmitAssemblyAction()
-  : CodeGenAction(Backend_EmitAssembly) {}
-
-EmitBCAction::EmitBCAction() : CodeGenAction(Backend_EmitBC) {}
-
-EmitLLVMAction::EmitLLVMAction() : CodeGenAction(Backend_EmitLL) {}
-
-EmitLLVMOnlyAction::EmitLLVMOnlyAction() : CodeGenAction(Backend_EmitNothing) {}
-
-EmitObjAction::EmitObjAction() : CodeGenAction(Backend_EmitObj) {}
-
 //===----------------------------------------------------------------------===//
 // Preprocessor Actions
 //===----------------------------------------------------------------------===//
index 2dfe2d3caef18af9374728a9d8b449e10d1478e9..294a68015f4e671c1693ee8d31688272477f770b 100644 (file)
@@ -19,6 +19,7 @@
 #include "clang/Driver/CC1Options.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/OptTable.h"
+#include "clang/Frontend/CodeGenAction.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"