]> granicus.if.org Git - clang/commitdiff
move the codegen ASTConsumer out of the driver into libcodegen,
authorChris Lattner <sabre@nondot.org>
Wed, 6 Feb 2008 02:01:47 +0000 (02:01 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 6 Feb 2008 02:01:47 +0000 (02:01 +0000)
eliminating a bunch of forwarding methods and generally
simplifying things.

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

AST/ASTConsumer.cpp
CodeGen/CodeGenModule.h
CodeGen/ModuleBuilder.cpp
Driver/ASTConsumers.cpp
Driver/ASTConsumers.h
Driver/clang.cpp
Sema/ParseAST.cpp
include/clang/CodeGen/ModuleBuilder.h

index dd839752eec81577f99b4adba16659c545d1ff3f..b3d12710927a8014754b094ae94edbcb3610f297 100644 (file)
 
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/Decl.h"
-
 using namespace clang;
 
+ASTConsumer::~ASTConsumer() {}
+
 void ASTConsumer::HandleTopLevelDeclaration(Decl* d) {
   if (ScopedDecl* sd = dyn_cast<ScopedDecl>(d))
     while (sd) {
index 5135c1b598a6d173b7d1982c4af88c65e9892dcd..900ddf46bbb79fbd2b85c504ac9c32d79237406a 100644 (file)
@@ -92,8 +92,6 @@ public:
   llvm::Constant *EmitGlobalInit(const Expr *E);
   llvm::Constant *EmitConstantExpr(const Expr *E);
     
-  void PrintStats() {}
-  
   /// WarnUnsupported - Print out a warning that codegen doesn't support the
   /// specified stmt yet.
     
index b626c45272c4729dbc1a598cdaab8b81378b3401..c59ef447e660c6a4201c0a41c217cd356352d141 100644 (file)
 
 #include "clang/CodeGen/ModuleBuilder.h"
 #include "CodeGenModule.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 using namespace clang;
 
+//===----------------------------------------------------------------------===//
+// LLVM Emitter
 
-/// Init - Create an ModuleBuilder with the specified ASTContext.
-clang::CodeGen::CodeGenModule *
-clang::CodeGen::Init(ASTContext &Context, const LangOptions &Features, 
-                     llvm::Module &M, const llvm::TargetData &TD, 
-                     Diagnostic &Diags) {
-  return new CodeGenModule(Context, Features, M, TD, Diags);
-}
-
-void clang::CodeGen::Terminate(CodeGenModule *B) {
-  delete B;
-}
-
-/// CodeGenFunction - Convert the AST node for a FunctionDecl into LLVM.
-///
-void clang::CodeGen::CodeGenFunction(CodeGenModule *B, FunctionDecl *D) {
-  B->EmitFunction(D);
-}
-
-/// CodeGenLinkageSpec - Emit the specified linkage space to LLVM.
-void clang::CodeGen::CodeGenLinkageSpec(CodeGenModule *Builder,
-                                       LinkageSpecDecl *LS) {
-  if (LS->getLanguage() == LinkageSpecDecl::lang_cxx)
-    Builder->WarnUnsupported(LS, "linkage spec");
-
-  // FIXME: implement C++ linkage, C linkage works mostly by C
-  // language reuse already.
-}
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "llvm/Module.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetMachine.h"
 
-/// CodeGenGlobalVar - Emit the specified global variable to LLVM.
-void clang::CodeGen::CodeGenGlobalVar(CodeGenModule *Builder, FileVarDecl *D) {
-  Builder->EmitGlobalVarDeclarator(D);
+namespace {
+  class CodeGenerator : public ASTConsumer {
+    Diagnostic &Diags;
+    const llvm::TargetData *TD;
+    ASTContext *Ctx;
+    const LangOptions &Features;
+  protected:
+    llvm::Module *&M;
+    CodeGen::CodeGenModule *Builder;
+  public:
+    CodeGenerator(Diagnostic &diags, const LangOptions &LO,
+                  llvm::Module *&DestModule)
+    : Diags(diags), Features(LO), M(DestModule) {}
+    
+    ~CodeGenerator() {
+      delete Builder;
+    }
+    
+    virtual void Initialize(ASTContext &Context) {
+      Ctx = &Context;
+      
+      M->setTargetTriple(Ctx->Target.getTargetTriple());
+      M->setDataLayout(Ctx->Target.getTargetDescription());
+      TD = new llvm::TargetData(Ctx->Target.getTargetDescription());
+      Builder = new CodeGen::CodeGenModule(Context, Features, *M, *TD, Diags);
+    }
+    
+    virtual void HandleTopLevelDecl(Decl *D) {
+      // If an error occurred, stop code generation, but continue parsing and
+      // semantic analysis (to ensure all warnings and errors are emitted).
+      if (Diags.hasErrorOccurred())
+        return;
+      
+      if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+        Builder->EmitFunction(FD);
+      } else if (FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
+        Builder->EmitGlobalVarDeclarator(FVD);
+      } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
+        if (LSD->getLanguage() == LinkageSpecDecl::lang_cxx)
+          Builder->WarnUnsupported(LSD, "linkage spec");
+        // FIXME: implement C++ linkage, C linkage works mostly by C
+        // language reuse already.
+      } else {
+        Builder->EmitType(cast<TypeDecl>(D));
+      }
+    }
+  };
 }
 
-/// CodeGenTypeDecl - Compile a type.
-void clang::CodeGen::CodeGenTypeDecl(CodeGenModule *Builder, TypeDecl *D) {
-  Builder->EmitType(D);
+ASTConsumer *clang::CreateLLVMCodeGen(Diagnostic &Diags, 
+                                      const LangOptions &Features,
+                                      llvm::Module *&DestModule) {
+  return new CodeGenerator(Diags, Features, DestModule);
 }
 
-
-/// PrintStats - Emit statistic information to stderr.
-///
-void clang::CodeGen::PrintStats(CodeGenModule *B) {
-  B->PrintStats();
-}
index 4dba24bdcea7fd4147c4748bbc66e081ce086888..7b96a6c13868e4483a2a0403ceb1e79ba858fc25 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "ASTConsumers.h"
 #include "clang/AST/TranslationUnit.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/AST/AST.h"
@@ -587,69 +588,6 @@ void GRConstantsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
   RunGRConstants(C, FD, *Ctx);
 }
 
-//===----------------------------------------------------------------------===//
-// LLVM Emitter
-
-#include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/TargetInfo.h"
-#include "clang/CodeGen/ModuleBuilder.h"
-#include "llvm/Module.h"
-#include "llvm/Target/TargetData.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/Bitcode/ReaderWriter.h"
-
-namespace {
-  class CodeGenerator : public ASTConsumer {
-    Diagnostic &Diags;
-    const llvm::TargetData *TD;
-    ASTContext *Ctx;
-    const LangOptions &Features;
-  protected:
-    llvm::Module *&M;
-    CodeGen::CodeGenModule *Builder;
-  public:
-    CodeGenerator(Diagnostic &diags, const LangOptions &LO,
-                  llvm::Module *&DestModule)
-      : Diags(diags), Features(LO), M(DestModule) {}
-    
-    ~CodeGenerator() {
-      CodeGen::Terminate(Builder);
-    }
-    
-    virtual void Initialize(ASTContext &Context) {
-      Ctx = &Context;
-      
-      M->setTargetTriple(Ctx->Target.getTargetTriple());
-      M->setDataLayout(Ctx->Target.getTargetDescription());
-      TD = new llvm::TargetData(Ctx->Target.getTargetDescription());
-      Builder = CodeGen::Init(Context, Features, *M, *TD, Diags);
-    }
-    
-    virtual void HandleTopLevelDecl(Decl *D) {
-      // If an error occurred, stop code generation, but continue parsing and
-      // semantic analysis (to ensure all warnings and errors are emitted).
-      if (Diags.hasErrorOccurred())
-        return;
-      
-      if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-        CodeGen::CodeGenFunction(Builder, FD);
-      } else if (FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
-        CodeGen::CodeGenGlobalVar(Builder, FVD);
-      } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
-        CodeGen::CodeGenLinkageSpec(Builder, LSD);
-      } else {
-        CodeGen::CodeGenTypeDecl(Builder, cast<TypeDecl>(D));
-      }
-    }
-  };
-}
-
-ASTConsumer *clang::CreateLLVMCodeGen(Diagnostic &Diags, 
-                                      const LangOptions &Features,
-                                      llvm::Module *&DestModule) {
-  return new CodeGenerator(Diags, Features, DestModule);
-}
-
 //===----------------------------------------------------------------------===//
 // AST Serializer
 
index 3c7589b4fdbc55e4e04673716c361a5572154fc7..10ab1eb83c4dc5910054f7e432c96cf0003cc1a0 100644 (file)
@@ -43,10 +43,6 @@ ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
   
 ASTConsumer *CreateGRConstants();
 
-  
-ASTConsumer *CreateLLVMCodeGen(Diagnostic &Diags, const LangOptions &Features,
-                               llvm::Module *&DestModule);
-
 ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
                                     Diagnostic &Diags);
 
index 6e76a4a0cd272bdca69394e26c048d0dc7a3af60..01ef28ff38e18507ca9582d927962703d3a24107 100644 (file)
@@ -27,6 +27,7 @@
 #include "TextDiagnosticBuffer.h"
 #include "TextDiagnosticPrinter.h"
 #include "clang/AST/TranslationUnit.h"
+#include "clang/CodeGen/ModuleBuilder.h"
 #include "clang/Sema/ParseAST.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/Parse/Parser.h"
index 8fd14d17d1a64e99d1d28786722c537ad02dc14b..364b07291006d877ca6af22e8d74a5159ccc7854 100644 (file)
@@ -19,8 +19,6 @@
 #include "clang/Parse/Parser.h"
 using namespace clang;
 
-ASTConsumer::~ASTConsumer() {}
-
 //===----------------------------------------------------------------------===//
 // Public interface to the file
 //===----------------------------------------------------------------------===//
index ab08c4abc671e3f78d1496e186f33c822f6a8f8a..8abb377f80411c72b66cbb796b1c920ffa0ba604 100644 (file)
 
 namespace llvm {
   class Module;
-  class TargetData;
 }
 
 namespace clang {
-  class ASTContext;
-  class FunctionDecl;
-  class LinkageSpecDecl;
-  class FileVarDecl;
-  class TypeDecl;
-  struct LangOptions;
   class Diagnostic;
-
-namespace CodeGen {
-  class CodeGenModule;
-  
-  /// Init - Create an ModuleBuilder with the specified ASTContext.
-  CodeGenModule *Init(ASTContext &Context, const LangOptions &Features,
-                      llvm::Module &M, const llvm::TargetData &TD,
-                      Diagnostic &Diags);
-  
-  /// CodeGenFunction - Convert the AST node for a FunctionDecl into LLVM.
-  ///
-  void CodeGenFunction(CodeGenModule *Builder, FunctionDecl *D);
-
-  void CodeGenLinkageSpec(CodeGenModule *Builder, LinkageSpecDecl *LS);
-  
-  /// CodeGenGlobalVar - Emit the specified global variable to LLVM.
-  void CodeGenGlobalVar(CodeGenModule *Builder, FileVarDecl *D);
-  
-  /// CodeGenTypeDecl - Compile a type.
-  void CodeGenTypeDecl(CodeGenModule *Builder, TypeDecl *D);
-
-  /// PrintStats - Emit statistic information to stderr.
-  ///
-  void PrintStats(CodeGenModule *Builder);
+  struct LangOptions;
+  class ASTConsumer;
   
-  /// Terminate - Gracefully shut down the builder.
-  ///
-  void Terminate(CodeGenModule *Builder);
-}  // end namespace CodeGen
-}  // end namespace clang
+  ASTConsumer *CreateLLVMCodeGen(Diagnostic &Diags, const LangOptions &Features,
+                                 llvm::Module *&DestModule);
+}
 
 #endif