ir_function now has a flags field - flags are: IR_FLAG_HAS_{ARRAYS,UNINITIALIZED,GOTO}

This commit is contained in:
Wolfgang Bumiller 2012-12-23 16:21:38 +01:00
parent 2382fdee50
commit 7998a98818
3 changed files with 15 additions and 16 deletions

6
ast.c
View file

@ -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;
}

19
ir.c
View file

@ -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))
{

6
ir.h
View file

@ -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*);