]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Starting ir_builder_generate - TYPE_FUNCTION still TODO
authorWolfgang Bumiller <wolfgang.linux@bumiller.com>
Fri, 4 May 2012 22:28:51 +0000 (00:28 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 9 May 2012 13:03:19 +0000 (15:03 +0200)
ir.c

diff --git a/ir.c b/ir.c
index e70c22c64bd89e324e229eb0ab8f75abc824a35c..75ea4aa05eea36c79b40b8be0193b119a552b0a8 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -1671,10 +1671,97 @@ on_error:
  * Breaking conventions is annoying...
  */
 
+static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
+{
+    int              nelems;
+    uint32_t        *elems;
+    prog_section_def def;
+
+    def.type = 0;
+    switch (global->vtype)
+    {
+    case TYPE_POINTER:
+        def.type++;
+        def.type++;
+    case TYPE_FIELD:
+        def.type++;
+    case TYPE_ENTITY:
+        def.type++;
+        def.type++;
+    case TYPE_FLOAT:
+        def.type++;
+    case TYPE_STRING:
+        def.type++;
+        nelems = 1;
+        break;
+    case TYPE_VECTOR:
+        def.type = 3;
+        nelems = 3;
+        break;
+    case TYPE_FUNCTION:
+        def.type = 6;
+        nelems = 1;
+        break;
+    default:
+        /* refuse to create 'void' type or any other fancy business. */
+        return false;
+    }
+
+    def.offset = code_globals_allocated;
+    def.name   = code_genstring(global->name);
+
+    if (code_defs_add(def) < 0)
+        return false;
+
+    if (!global->isconst) {
+        int i;
+        for (i = 0; i < nelems; ++i) {
+            if (code_globals_add(0) < 0)
+                return false;
+        }
+    } else {
+        if (global->vtype == TYPE_STRING) {
+            if (code_globals_add(code_genstring(global->constval.vstring)) < 0)
+                return false;
+        } else if (global->vtype == TYPE_FUNCTION) {
+            prog_section_function fun;
+            int i;
+
+            fun.profile    = 0;
+            fun.file = code_cachedstring(global->context.file);
+            fun.name = def.name;
+            for (i = 0; i < 8; ++i)
+                fun.argsize[i] = 0;
+            fun.nargs      = 0;
+            fun.entry      = 0;
+            fun.firstlocal = 0;
+            fun.locals     = 0;
+            code_functions_add(fun);
+        } else {
+            int i;
+            elems = (uint32_t*)&global->constval;
+            for (i = 0; i < nelems; ++i) {
+                if (code_globals_add(elems[i]) < 0)
+                    return false;
+            }
+        }
+    }
+
+    return true;
+}
+
 bool ir_builder_generate(ir_builder *self, const char *filename)
 {
+    size_t i;
+
     code_init();
 
+    for (i = 0; i < self->globals_count; ++i)
+    {
+        if (!ir_builder_gen_global(self, self->globals[i]))
+            return false;
+    }
+
     code_write(filename);
     return false;
 }