[Code generation]

This commit is contained in:
Philippe Tillet
2018-12-19 11:25:29 -05:00
parent 951e9733ea
commit 9247ed3714
2 changed files with 44 additions and 19 deletions

View File

@@ -31,7 +31,7 @@ llvm::IRBuilder<>& module::builder() {
namespace ast{
/* Translation unit */
void translation_unit::codegen(module *mod){
void translation_unit::codegen(module *mod) const{
decls_->codegen(mod);
}
@@ -78,8 +78,8 @@ Type* tile::type_impl(module*, Type *type) const{
}
// Initializer
Type* initializer::type_impl(module *, Type *type) const{
return type;
Type* initializer::type_impl(module *mod, Type *type) const{
return decl_->type(mod, type);
}
// Pointer
@@ -97,14 +97,31 @@ Type* function::type_impl(module*mod, Type *type) const{
}
/* Function definition */
void function_definition::codegen(module *mod){
llvm::FunctionType *prototype = (llvm::FunctionType *)header_->type(mod, spec_->type(mod));
void function_definition::codegen(module *mod) const{
FunctionType *prototype = (FunctionType *)header_->type(mod, spec_->type(mod));
const std::string &name = header_->id()->name();
llvm::Function *fn = llvm::Function::Create(prototype, llvm::Function::ExternalLinkage, name, mod->handle());
llvm::BasicBlock::Create(mod->handle()->getContext(), "entry", fn);
mod->builder().SetInsertPoint();
}
Function *fn = Function::Create(prototype, Function::ExternalLinkage, name, mod->handle());
BasicBlock *entry = BasicBlock::Create(mod->handle()->getContext(), "entry", fn);
mod->builder().SetInsertPoint(entry);
body_->codegen(mod);
}
/* Statements */
void compound_statement::codegen(module* mod) const{
decls_->codegen(mod);
statements_->codegen(mod);
}
/* Declaration */
void declaration::codegen(module* mod) const{
}
/* Initializat */
void initializer::codegen(module *) const{
}
}