[cfe-commits] r39522 - in /cfe/cfe/trunk/CodeGen: CodeGenFunction.cpp CodeGenFunction.h CodeGenModule.h

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:45:15 PDT 2007


Author: clattner
Date: Wed Jul 11 11:45:15 2007
New Revision: 39522

URL: http://llvm.org/viewvc/llvm-project?rev=39522&view=rev
Log:
Add codegen support for NullStmt and CompoundStmt.  {;;{};;} is now ours!

Modified:
    cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp
    cfe/cfe/trunk/CodeGen/CodeGenFunction.h
    cfe/cfe/trunk/CodeGen/CodeGenModule.h

Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp?rev=39522&r1=39521&r2=39522&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp Wed Jul 11 11:45:15 2007
@@ -16,7 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/AST/AST.h"
 #include "llvm/DerivedTypes.h"
-#include "llvm/Support/LLVMBuilder.h"
+#include "llvm/Function.h"
 using namespace llvm;
 using namespace clang;
 using namespace CodeGen;
@@ -101,9 +101,45 @@
 }
 
 
-void CodeGenFunction::GenerateCode(FunctionDecl *FD) {
+void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
   const llvm::Type *Ty = ConvertType(FD->getType(), FD->getLocation());
   
-  Ty->dump();
+  llvm::Function *F = new Function(cast<llvm::FunctionType>(Ty),
+                                   Function::ExternalLinkage,
+                                   FD->getName(), &CGM.getModule());
   
+  BasicBlock *EntryBB = new BasicBlock("entry", F);
+  
+  // TODO: Walk the decls, creating allocas etc.
+  
+  Builder.SetInsertPoint(EntryBB);
+  
+  EmitStmt(FD->getBody());
+}
+
+
+//===----------------------------------------------------------------------===//
+//                              Statement Emission
+//===----------------------------------------------------------------------===//
+
+void CodeGenFunction::EmitStmt(const Stmt *S) {
+  assert(S && "Null statement?");
+  
+  switch (S->getStmtClass()) {
+  default:
+    printf("Unimplemented stmt!\n");
+    S->dump();
+    break;
+  case Stmt::NullStmtClass: break;
+  case Stmt::CompoundStmtClass: EmitCompoundStmt(cast<CompoundStmt>(*S)); break;
+  }
 }
+
+void CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S) {
+  // FIXME: handle vla's etc.
+  
+  for (CompoundStmt::const_body_iterator I = S.body_begin(), E = S.body_end();
+       I != E; ++I)
+    EmitStmt(*I);
+}
+

Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.h?rev=39522&r1=39521&r2=39522&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:45:15 2007
@@ -14,15 +14,18 @@
 #ifndef CODEGEN_CODEGENFUNCTION_H
 #define CODEGEN_CODEGENFUNCTION_H
 
+#include "llvm/Support/LLVMBuilder.h"
+
 namespace llvm {
   class Module;
-  class Type;
 namespace clang {
   class ASTContext;
   class FunctionDecl;
   class QualType;
   class SourceLocation;
   class TargetInfo;
+  class Stmt;
+  class CompoundStmt;
   
 namespace CodeGen {
   class CodeGenModule;
@@ -32,12 +35,20 @@
 class CodeGenFunction {
   CodeGenModule &CGM;  // Per-module state.
   TargetInfo &Target;
+  LLVMBuilder Builder;
 public:
   CodeGenFunction(CodeGenModule &cgm);
   
   const llvm::Type *ConvertType(QualType T, SourceLocation Loc);
   
-  void GenerateCode(FunctionDecl *FD);
+  void GenerateCode(const FunctionDecl *FD);
+  
+  //===--------------------------------------------------------------------===//
+  //                             Statement Emission
+  //===--------------------------------------------------------------------===//
+
+  void EmitStmt(const Stmt *S);
+  void EmitCompoundStmt(const CompoundStmt &S);
 };
 }  // end namespace CodeGen
 }  // end namespace clang

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

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenModule.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenModule.h Wed Jul 11 11:45:15 2007
@@ -31,6 +31,7 @@
   CodeGenModule(ASTContext &C, Module &M) : Context(C), TheModule(M) {}
   
   ASTContext &getContext() const { return Context; }
+  Module &getModule() const { return TheModule; }
   
   void EmitFunction(FunctionDecl *FD);
   





More information about the cfe-commits mailing list