]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Generate function global, take 2-op instruction operand ordering into account
authorWolfgang (Blub) Bumiller <blub@speed.at>
Mon, 25 Jun 2012 09:52:18 +0000 (11:52 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Mon, 25 Jun 2012 09:52:18 +0000 (11:52 +0200)
ir.c

diff --git a/ir.c b/ir.c
index 848e488e4d52e053b63fb33e6dbed1b11ce11685..df9e53eb551b16dcdbddefad1a40186df6085a42 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -1909,11 +1909,20 @@ tailcall:
         if (instr->_ops[2])
             stmt.o2.u1 = instr->_ops[2]->code.globaladdr;
 
-        if (stmt.opcode == INSTR_RETURN)
+        if (stmt.opcode == INSTR_RETURN || stmt.opcode == INSTR_DONE)
         {
             stmt.o1.u1 = stmt.o3.u1;
             stmt.o3.u1 = 0;
         }
+        else if ((stmt.opcode >= INSTR_STORE_F    &&
+                  stmt.opcode <= INSTR_STORE_FNC)    ||
+                 (stmt.opcode >= INSTR_NOT_F      &&
+                  stmt.opcode <= INSTR_NOT_FNC))
+        {
+            /* 2-operand instructions with A -> B */
+            stmt.o2.u1 = stmt.o3.u1;
+            stmt.o3.u1 = 0;
+        }
 
         if (code_statements_add(stmt) < 0)
             return false;
@@ -1997,7 +2006,7 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
     int32_t         *iptr;
     prog_section_def def;
 
-    def.type = global->vtype;
+    def.type   = global->vtype;
     def.offset = code_globals_elements;
     def.name   = global->code.name       = code_genstring(global->name);
 
@@ -2012,8 +2021,7 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
             return false;
         return gen_global_field(global);
     case TYPE_ENTITY:
-        if (code_defs_add(def) < 0)
-            return false;
+        /* fall through */
     case TYPE_FLOAT:
     {
         if (code_defs_add(def) < 0)
@@ -2057,6 +2065,7 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
     case TYPE_FUNCTION:
         if (code_defs_add(def) < 0)
             return false;
+        code_globals_add(code_functions_elements);
         return gen_global_function(self, global);
     case TYPE_VARIANT:
         /* assume biggest type */
@@ -2081,10 +2090,22 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
      * 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]))
+        if (!ir_builder_gen_global(self, self->globals[i])) {
             return false;
+        }
     }
 
     printf("writing '%s'...\n", filename);