Add codegen support for NullStmt and CompoundStmt. {;;{};;} is now ours!

llvm-svn: 39522
This commit is contained in:
Chris Lattner 2007-05-29 23:50:05 +00:00
parent d5322cd27e
commit 308f431017
3 changed files with 53 additions and 5 deletions

View File

@ -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<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);
}

View File

@ -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 @@ namespace CodeGen {
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

View File

@ -31,6 +31,7 @@ public:
CodeGenModule(ASTContext &C, Module &M) : Context(C), TheModule(M) {}
ASTContext &getContext() const { return Context; }
Module &getModule() const { return TheModule; }
void EmitFunction(FunctionDecl *FD);