ir_function now has a flags field - flags are: IR_FLAG_HAS_{ARRAYS,UNINITIALIZED...
authorWolfgang Bumiller <blub@speed.at>
Sun, 23 Dec 2012 15:21:38 +0000 (16:21 +0100)
committerWolfgang Bumiller <blub@speed.at>
Sun, 23 Dec 2012 15:21:38 +0000 (16:21 +0100)
ast.c
ir.c
ir.h

diff --git a/ast.c b/ast.c
index 09c12a4c6957ce0efbe963a2083a389c9181002c..3894cdefaad6e8fe4fb5ff6a38154e320fee2784 100644 (file)
--- 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 bb15d1963bbdcd7370a3ff001c87bb2d53da2900..38effd70ee6513eddecd2cc4e9554449c113285f 100644 (file)
--- 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 6532a5ea3a9c0cec236bd5f96f93ba1be6636ef8..75946959a900ed0914dd21b2072359c2594f34d4 100644 (file)
--- 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*);