From 13082112b071c0e6c0a5f9bd408c2afa7613b75b Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Wed, 2 May 2012 19:25:25 +0200 Subject: [PATCH] create the ir_function in ast_function_codegen, keep the current ir_block stored in ast_function so inner codegens can use it --- ast.c | 12 ++++++++++-- ast.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ast.c b/ast.c index 5f8025c..7a2b7a5 100644 --- a/ast.c +++ b/ast.c @@ -267,6 +267,7 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) MEM_VECTOR_INIT(self, blocks); self->ir_func = NULL; + self->curblock = NULL; vtype->isconst = true; vtype->constval.vfunc = self; @@ -421,13 +422,20 @@ error: /* clean up */ bool ast_function_codegen(ast_function *self, ir_builder *ir) { - ir_value *dummy; + ir_function *irf; + ir_value *dummy; size_t i; - if (!self->ir_func) { + + irf = self->ir_func; + if (!irf) { printf("ast_function's related ast_value was not generated yet\n"); return false; } + self->curblock = ir_function_create_block(irf, "entry"); + if (!self->curblock) + return false; + for (i = 0; i < self->blocks_count; ++i) { ast_expression_codegen *gen = self->blocks[i]->expression.codegen; if (!(*gen)((ast_expression*)self->blocks[i], self, false, &dummy)) diff --git a/ast.h b/ast.h index bea59d5..9609a08 100644 --- a/ast.h +++ b/ast.h @@ -274,6 +274,7 @@ struct ast_function_s const char *name; ir_function *ir_func; + ir_block *curblock; MEM_VECTOR_MAKE(ast_block*, blocks); }; -- 2.39.2