[cfe-commits] r46792 - in /cfe/trunk: 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

Chris Lattner sabre at nondot.org
Tue Feb 5 18:01:47 PST 2008


Author: lattner
Date: Tue Feb  5 20:01:47 2008
New Revision: 46792

URL: http://llvm.org/viewvc/llvm-project?rev=46792&view=rev
Log:
move the codegen ASTConsumer out of the driver into libcodegen,
eliminating a bunch of forwarding methods and generally 
simplifying things.

Modified:
    cfe/trunk/AST/ASTConsumer.cpp
    cfe/trunk/CodeGen/CodeGenModule.h
    cfe/trunk/CodeGen/ModuleBuilder.cpp
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/ASTConsumers.h
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/Sema/ParseAST.cpp
    cfe/trunk/include/clang/CodeGen/ModuleBuilder.h

Modified: cfe/trunk/AST/ASTConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTConsumer.cpp?rev=46792&r1=46791&r2=46792&view=diff

==============================================================================
--- cfe/trunk/AST/ASTConsumer.cpp (original)
+++ cfe/trunk/AST/ASTConsumer.cpp Tue Feb  5 20:01:47 2008
@@ -13,9 +13,10 @@
 
 #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) {

Modified: cfe/trunk/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.h?rev=46792&r1=46791&r2=46792&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/CodeGen/CodeGenModule.h Tue Feb  5 20:01:47 2008
@@ -92,8 +92,6 @@
   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.
     

Modified: cfe/trunk/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/ModuleBuilder.cpp?rev=46792&r1=46791&r2=46792&view=diff

==============================================================================
--- cfe/trunk/CodeGen/ModuleBuilder.cpp (original)
+++ cfe/trunk/CodeGen/ModuleBuilder.cpp Tue Feb  5 20:01:47 2008
@@ -13,51 +13,73 @@
 
 #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.
-}
-
-/// CodeGenGlobalVar - Emit the specified global variable to LLVM.
-void clang::CodeGen::CodeGenGlobalVar(CodeGenModule *Builder, FileVarDecl *D) {
-  Builder->EmitGlobalVarDeclarator(D);
-}
-
-/// CodeGenTypeDecl - Compile a type.
-void clang::CodeGen::CodeGenTypeDecl(CodeGenModule *Builder, TypeDecl *D) {
-  Builder->EmitType(D);
+#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"
+
+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));
+      }
+    }
+  };
+}
+
+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();
-}

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=46792&r1=46791&r2=46792&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Tue Feb  5 20:01:47 2008
@@ -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"
@@ -588,69 +589,6 @@
 }
 
 //===----------------------------------------------------------------------===//
-// 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
 
 namespace {

Modified: cfe/trunk/Driver/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=46792&r1=46791&r2=46792&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Tue Feb  5 20:01:47 2008
@@ -43,10 +43,6 @@
   
 ASTConsumer *CreateGRConstants();
 
-  
-ASTConsumer *CreateLLVMCodeGen(Diagnostic &Diags, const LangOptions &Features,
-                               llvm::Module *&DestModule);
-
 ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
                                     Diagnostic &Diags);
 

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=46792&r1=46791&r2=46792&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Tue Feb  5 20:01:47 2008
@@ -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"

Modified: cfe/trunk/Sema/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/ParseAST.cpp?rev=46792&r1=46791&r2=46792&view=diff

==============================================================================
--- cfe/trunk/Sema/ParseAST.cpp (original)
+++ cfe/trunk/Sema/ParseAST.cpp Tue Feb  5 20:01:47 2008
@@ -19,8 +19,6 @@
 #include "clang/Parse/Parser.h"
 using namespace clang;
 
-ASTConsumer::~ASTConsumer() {}
-
 //===----------------------------------------------------------------------===//
 // Public interface to the file
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/include/clang/CodeGen/ModuleBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h?rev=46792&r1=46791&r2=46792&view=diff

==============================================================================
--- cfe/trunk/include/clang/CodeGen/ModuleBuilder.h (original)
+++ cfe/trunk/include/clang/CodeGen/ModuleBuilder.h Tue Feb  5 20:01:47 2008
@@ -16,46 +16,15 @@
 
 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





More information about the cfe-commits mailing list