From 7998a98818d38858405698a9c7029d3bea8e4e7b Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Sun, 23 Dec 2012 16:21:38 +0100 Subject: [PATCH] ir_function now has a flags field - flags are: IR_FLAG_HAS_{ARRAYS,UNINITIALIZED,GOTO} --- ast.c | 6 ++++-- ir.c | 19 +++++-------------- ir.h | 6 ++++++ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ast.c b/ast.c index 09c12a4..3894cde 100644 --- a/ast.c +++ b/ast.c @@ -1317,6 +1317,8 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param) ast_expression_common *elemtype = &self->expression.next->expression; int vtype = elemtype->vtype; + func->flags |= IR_FLAG_HAS_ARRAYS; + if (param) { compile_error(ast_ctx(self), "array-parameters are not supported"); return false; @@ -2856,14 +2858,14 @@ bool ast_goto_codegen(ast_goto *self, ast_function *func, bool lvalue, ir_value if (self->irblock_from) { /* we already tried once, this is the callback */ self->irblock_from->final = false; - if (!ir_block_create_jump(self->irblock_from, ast_ctx(self), self->target->irblock)) { + if (!ir_block_create_goto(self->irblock_from, ast_ctx(self), self->target->irblock)) { compile_error(ast_ctx(self), "failed to generate goto to `%s`", self->name); return false; } } else { - if (!ir_block_create_jump(func->curblock, ast_ctx(self), self->target->irblock)) { + if (!ir_block_create_goto(func->curblock, ast_ctx(self), self->target->irblock)) { compile_error(ast_ctx(self), "failed to generate goto to `%s`", self->name); return false; } diff --git a/ir.c b/ir.c index bb15d19..38effd7 100644 --- a/ir.c +++ b/ir.c @@ -433,6 +433,8 @@ ir_function* ir_function_new(ir_builder* owner, int outtype) mem_d(self); return NULL; } + self->flags = 0; + self->owner = owner; self->context.file = "<@no context>"; self->context.line = 0; @@ -1529,20 +1531,8 @@ bool ir_block_create_jump(ir_block *self, lex_ctx ctx, ir_block *to) bool ir_block_create_goto(ir_block *self, lex_ctx ctx, ir_block *to) { - ir_instr *in; - if (!ir_check_unreachable(self)) - return false; - self->final = true; - in = ir_instr_new(ctx, self, INSTR_GOTO); - if (!in) - return false; - - in->bops[0] = to; - vec_push(self->instr, in); - - vec_push(self->exits, to); - vec_push(to->entries, self); - return true; + self->owner->flags |= IR_FLAG_HAS_GOTO; + return ir_block_create_jump(self, ctx, to); } ir_instr* ir_block_create_phi(ir_block *self, lex_ctx ctx, const char *label, int ot) @@ -2232,6 +2222,7 @@ bool ir_function_calculate_liferanges(ir_function *self) if (!vec_ir_value_find(block->living, v->memberof, NULL)) continue; } + self->flags |= IR_FLAG_HAS_UNINITIALIZED; if (irwarning(v->context, WARN_USED_UNINITIALIZED, "variable `%s` may be used uninitialized in this function", v->name)) { diff --git a/ir.h b/ir.h index 6532a5e..7594695 100644 --- a/ir.h +++ b/ir.h @@ -237,6 +237,8 @@ typedef struct ir_function_s int *params; ir_block **blocks; + uint32_t flags; + int builtin; ir_value *value; @@ -270,6 +272,10 @@ typedef struct ir_function_s struct ir_builder_s *owner; } ir_function; +#define IR_FLAG_HAS_ARRAYS (1<<1) +#define IR_FLAG_HAS_UNINITIALIZED (1<<2) +#define IR_FLAG_HAS_GOTO (1<<3) +#define IR_FLAG_MASK_NO_OVERLAP (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED) ir_function* ir_function_new(struct ir_builder_s *owner, int returntype); void ir_function_delete(ir_function*); -- 2.39.2