]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
generating an ir_value for an ir_function at creation now
authorWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 29 Jun 2012 11:25:31 +0000 (13:25 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 29 Jun 2012 11:25:31 +0000 (13:25 +0200)
ir.c
ir.h

diff --git a/ir.c b/ir.c
index 28169da2113c14f8c9272d3e9f6c76e36789d8e7..3621359e64c73f1d8a39a9f7c2542fd606d569f0 100644 (file)
--- 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 c93971eac4e357e70d15860881845127b070977e..171c185f049b34a1c9ccda933624d023fe30b918 100644 (file)
--- 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.