From: Wolfgang (Blub) Bumiller Date: Fri, 29 Jun 2012 11:25:31 +0000 (+0200) Subject: generating an ir_value for an ir_function at creation now X-Git-Tag: 0.1-rc1~464 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=856c9d16a5dfd309ff2a65c5a8c051b161679799 generating an ir_value for an ir_function at creation now --- diff --git a/ir.c b/ir.c index 28169da..3621359 100644 --- a/ir.c +++ b/ir.c @@ -124,6 +124,18 @@ ir_function* ir_builder_create_function(ir_builder *self, const char *name, int ir_function_delete(fn); return NULL; } + + fn->value = ir_builder_create_global(self, fn->name, TYPE_FUNCTION); + if (!fn->value) { + ir_function_delete(fn); + return NULL; + } + + fn->value->isconst = true; + fn->value->outtype = outtype; + fn->value->constval.vfunc = fn; + fn->value->context = fn->context; + return fn; } @@ -178,6 +190,7 @@ ir_function* ir_function_new(ir_builder* owner, int outtype) self->context.file = "<@no context>"; self->context.line = 0; self->outtype = outtype; + self->value = NULL; MEM_VECTOR_INIT(self, params); MEM_VECTOR_INIT(self, blocks); MEM_VECTOR_INIT(self, values); @@ -217,6 +230,8 @@ void ir_function_delete(ir_function *self) ir_value_delete(self->locals[i]); MEM_VECTOR_CLEAR(self, locals); + /* self->value is deleted by the builder */ + mem_d(self); } @@ -2397,21 +2412,6 @@ bool ir_builder_generate(ir_builder *self, const char *filename) code_init(); - /* FIXME: generate TYPE_FUNCTION globals and link them - * to their ir_function. - */ - - for (i = 0; i < self->functions_count; ++i) - { - ir_value *funval; - ir_function *fun = self->functions[i]; - - funval = ir_builder_create_global(self, fun->name, TYPE_FUNCTION); - funval->isconst = true; - funval->constval.vfunc = fun; - funval->context = fun->context; - } - for (i = 0; i < self->globals_count; ++i) { if (!ir_builder_gen_global(self, self->globals[i])) { diff --git a/ir.h b/ir.h index c93971e..171c185 100644 --- a/ir.h +++ b/ir.h @@ -228,6 +228,8 @@ typedef struct ir_function_s MEM_VECTOR_MAKE(int, params); MEM_VECTOR_MAKE(ir_block*, blocks); + ir_value *value; + /* values generated from operations * which might get optimized away, so anything * in there needs to be deleted in the dtor.