]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Adding DEF_SAVEGLOBAL, marking globals as to-be-saved now, for real support of quicks...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 23 Aug 2012 16:28:05 +0000 (18:28 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 23 Aug 2012 16:28:05 +0000 (18:28 +0200)
exec.c
gmqcc.h
ir.c

diff --git a/exec.c b/exec.c
index 666468a3f3bfa33ff519c357331313f9e5791143..bb35ee9e3ac1fc30a375ec6539523ac099efe335 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -903,7 +903,7 @@ int main(int argc, char **argv)
     if (opts_printdefs) {
         for (i = 0; i < prog->defs_count; ++i) {
             printf("Global: %8s %-16s at %u\n",
-                   type_name[prog->defs[i].type],
+                   type_name[prog->defs[i].type & DEF_TYPEMASK],
                    prog_getstring(prog, prog->defs[i].name),
                    (unsigned int)prog->defs[i].offset);
         }
diff --git a/gmqcc.h b/gmqcc.h
index f150cf186f918e924ff4d843ec428eef7e4ffc8a..158463332e78a31ca40ab91d91f67336c2d574c0 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -390,6 +390,10 @@ typedef struct {
 typedef prog_section_both prog_section_def;
 typedef prog_section_both prog_section_field;
 
+/* this is ORed to the type */
+#define DEF_SAVEGLOBAL (1<<15)
+#define DEF_TYPEMASK   ((1<<15)-1)
+
 typedef struct {
     int32_t   entry;      /* in statement table for instructions  */
     uint32_t  firstlocal; /* First local in local table           */
diff --git a/ir.c b/ir.c
index 4dc791410f415908cca89cdd21e79d6b93c3bd5b..0313fd9345c1fd8a6d37a818c76eda9cb1738492 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -2667,8 +2667,9 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
         /* I'd argue setting it to 0 is sufficient, but maybe some depend on knowing how far
          * the system fields actually go? Though the engine knows this anyway...
          * Maybe this could be an -foption
+         * fteqcc creates data for end_sys_* - of size 1, so let's do the same
          */
-        ir_value_code_setaddr(global, def.offset);
+        ir_value_code_setaddr(global, code_globals_add(0));
         /* Add the def */
         if (code_defs_add(def) < 0)
             return false;
@@ -2685,33 +2686,33 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
         /* fall through */
     case TYPE_FLOAT:
     {
-        if (code_defs_add(def) < 0)
-            return false;
-
         if (global->isconst) {
             iptr = (int32_t*)&global->constval.vfloat;
             ir_value_code_setaddr(global, code_globals_add(*iptr));
-        } else
+        } else {
             ir_value_code_setaddr(global, code_globals_add(0));
+            def.type |= DEF_SAVEGLOBAL;
+        }
+        if (code_defs_add(def) < 0)
+            return false;
 
         return global->code.globaladdr >= 0;
     }
     case TYPE_STRING:
     {
-        if (code_defs_add(def) < 0)
-            return false;
         if (global->isconst)
             ir_value_code_setaddr(global, code_globals_add(code_cachedstring(global->constval.vstring)));
-        else
+        else {
             ir_value_code_setaddr(global, code_globals_add(0));
+            def.type |= DEF_SAVEGLOBAL;
+        }
+        if (code_defs_add(def) < 0)
+            return false;
         return global->code.globaladdr >= 0;
     }
     case TYPE_VECTOR:
     {
         size_t d;
-        if (code_defs_add(def) < 0)
-            return false;
-
         if (global->isconst) {
             iptr = (int32_t*)&global->constval.vvec;
             ir_value_code_setaddr(global, code_globals_add(iptr[0]));
@@ -2731,20 +2732,28 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
                 if (code_globals_add(0) < 0)
                     return false;
             }
+            def.type |= DEF_SAVEGLOBAL;
         }
+
+        if (code_defs_add(def) < 0)
+            return false;
         return global->code.globaladdr >= 0;
     }
     case TYPE_FUNCTION:
-        if (code_defs_add(def) < 0)
-            return false;
         if (!global->isconst) {
             ir_value_code_setaddr(global, code_globals_add(0));
-            return global->code.globaladdr >= 0;
+            if (global->code.globaladdr < 0)
+                return false;
         } else {
             ir_value_code_setaddr(global, code_globals_elements);
             code_globals_add(code_functions_elements);
-            return gen_global_function(self, global);
+            if (!gen_global_function(self, global))
+                return false;
+            def.type |= DEF_SAVEGLOBAL;
         }
+        if (code_defs_add(def) < 0)
+            return false;
+        return true;
     case TYPE_VARIANT:
         /* assume biggest type */
             ir_value_code_setaddr(global, code_globals_add(0));