From 308f431017429c94728ea0f719ae3fa6cd00e275 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 29 May 2007 23:50:05 +0000 Subject: Add codegen support for NullStmt and CompoundStmt. {;;{};;} is now ours! llvm-svn: 39522 --- clang/CodeGen/CodeGenFunction.cpp | 42 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'clang/CodeGen/CodeGenFunction.cpp') diff --git a/clang/CodeGen/CodeGenFunction.cpp b/clang/CodeGen/CodeGenFunction.cpp index cfe5d9d9521..ff31a835ce9 100644 --- a/clang/CodeGen/CodeGenFunction.cpp +++ b/clang/CodeGen/CodeGenFunction.cpp @@ -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 @@ const llvm::Type *CodeGenFunction::ConvertType(QualType T, SourceLocation Loc) { } -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(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(*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); +} + -- cgit v1.2.3