mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-17 09:02:25 +00:00
create the ir_function in ast_function_codegen, keep the current ir_block stored in ast_function so inner codegens can use it
This commit is contained in:
parent
1e9d02da14
commit
13082112b0
2 changed files with 11 additions and 2 deletions
12
ast.c
12
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))
|
||||
|
|
1
ast.h
1
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);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue