Added a flag to both ast and ir which enforces the generation of a globaldef for...
authorWolfgang Bumiller <blub@speed.at>
Fri, 11 Jan 2013 18:15:59 +0000 (19:15 +0100)
committerWolfgang Bumiller <blub@speed.at>
Fri, 11 Jan 2013 18:15:59 +0000 (19:15 +0100)
ast.c
ast.h
ir.c
ir.h

diff --git a/ast.c b/ast.c
index 2b4a456ebb08e5e388d79bbe9a910d49c51d1a9e..995ba094efa04432e655135b489e7e61fb3b7148 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1164,6 +1164,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
 
         self->constval.vfunc->ir_func = func;
         self->ir_v = func->value;
+        if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
+            self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
         /* The function is filled later on ast_function_codegen... */
         return true;
     }
@@ -1206,6 +1208,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
             v->unique_life = true;
             v->locked      = true;
             array->ir_v = self->ir_v = v;
+            if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
+                self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
 
             namelen = strlen(self->name);
             name    = (char*)mem_a(namelen + 16);
@@ -1224,6 +1228,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
                 array->ir_values[ai]->context = ast_ctx(self);
                 array->ir_values[ai]->unique_life = true;
                 array->ir_values[ai]->locked      = true;
+                if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
+                    self->ir_values[ai]->flags |= IR_FLAG_INCLUDE_DEF;
             }
             mem_d(name);
         }
@@ -1234,6 +1240,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
                 return false;
             v->context = ast_ctx(self);
             self->ir_v = v;
+            if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
+                self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
         }
         return true;
     }
@@ -1258,6 +1266,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
         v->context = ast_ctx(self);
         v->unique_life = true;
         v->locked      = true;
+        if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
+            v->flags |= IR_FLAG_INCLUDE_DEF;
 
         namelen = strlen(self->name);
         name    = (char*)mem_a(namelen + 16);
@@ -1276,6 +1286,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
             self->ir_values[ai]->context = ast_ctx(self);
             self->ir_values[ai]->unique_life = true;
             self->ir_values[ai]->locked      = true;
+            if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
+                self->ir_values[ai]->flags |= IR_FLAG_INCLUDE_DEF;
         }
         mem_d(name);
     }
@@ -1338,6 +1350,8 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
     /* link us to the ir_value */
     v->cvq = self->cvq;
     self->ir_v = v;
+    if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
+        self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
     return true;
 
 error: /* clean up */
diff --git a/ast.h b/ast.h
index ce69810e152fbc7ea8e338ed0fe0e00bc89b3cf0..37bbf0266aab0d332e79b6302f2fd9d397eb34a7 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -145,6 +145,7 @@ typedef struct
 #define AST_FLAG_INLINE       (1<<2)
 #define AST_FLAG_INITIALIZED  (1<<3)
 #define AST_FLAG_DEPRECATED   (1<<4)
+#define AST_FLAG_INCLUDE_DEF  (1<<5)
 #define AST_FLAG_TYPE_MASK (AST_FLAG_VARIADIC | AST_FLAG_NORETURN)
 
 /* Value
diff --git a/ir.c b/ir.c
index 420ef93069531cfbdb9385e1d66d6b342ace3bde..5461b44cfabdb65bf60297eb1a4912cd6e32334b 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -1018,6 +1018,7 @@ ir_value* ir_value_var(const char *name, int storetype, int vtype)
     self->fieldtype = TYPE_VOID;
     self->outtype = TYPE_VOID;
     self->store = storetype;
+    self->flags = 0;
 
     self->reads  = NULL;
     self->writes = NULL;
@@ -3323,6 +3324,7 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc
         pushdef = true;
 
         if (OPTS_OPTIMIZATION(OPTIM_STRIP_CONSTANT_NAMES) &&
+            !(global->flags & IR_FLAG_INCLUDE_DEF) &&
             (global->name[0] == '#' || global->cvq == CV_CONST))
         {
             pushdef = false;
diff --git a/ir.h b/ir.h
index a241ad5cad6d3601ed76eb5270a502c5dcd5946c..9a953a6187fbd2a12245c88b59728812cd5f2ea9 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -44,6 +44,7 @@ typedef struct ir_value_s {
     int       outtype;
     /* 'const' vs 'var' qualifier */
     int       cvq;
+    uint32_t  flags;
 
     struct ir_instr_s **reads;
     struct ir_instr_s **writes;
@@ -276,6 +277,7 @@ typedef struct ir_function_s
 #define IR_FLAG_HAS_ARRAYS        (1<<1)
 #define IR_FLAG_HAS_UNINITIALIZED (1<<2)
 #define IR_FLAG_HAS_GOTO          (1<<3)
+#define IR_FLAG_INCLUDE_DEF       (1<<4)
 #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);