]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
ast_local_codegen - similar structure to global_codegen obviously...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 2 May 2012 16:34:24 +0000 (18:34 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 2 May 2012 16:34:24 +0000 (18:34 +0200)
ast.c

diff --git a/ast.c b/ast.c
index af64e0847730f4d71111d0fe4223d9fb5aa17ecf..96e419de94cf12f6edad11e23190eb34d05dec7a 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -297,7 +297,10 @@ void ast_function_delete(ast_function *self)
 }
 
 /*********************************************************************/
-/* AST codegen aprt
+/* AST codegen part
+ * by convention you must never pass NULL to the 'ir_value **out'
+ * parameter. If you really don't care about the output, pass a dummy.
+ * But I can't imagine a pituation where the output is truly unnecessary.
  */
 
 bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_value **out)
@@ -368,6 +371,54 @@ error: /* clean up */
     return false;
 }
 
+bool ast_local_codegen(ast_value *self, ir_function *func)
+{
+    ir_value *v = NULL;
+    if (self->isconst && self->vtype == TYPE_FUNCTION)
+    {
+        /* Do we allow local functions? I think not...
+         * this is NOT a function pointer atm.
+         */
+        return false;
+    }
+
+    v = ir_function_create_local(func, self->name, self->vtype);
+    if (!v)
+        return false;
+
+    /* A constant local... hmmm...
+     * I suppose the IR will have to deal with this
+     */
+    if (self->isconst) {
+        switch (self->vtype)
+        {
+            case TYPE_FLOAT:
+                if (!ir_value_set_float(v, self->constval.vfloat))
+                    goto error;
+                break;
+            case TYPE_VECTOR:
+                if (!ir_value_set_vector(v, self->constval.vvec))
+                    goto error;
+                break;
+            case TYPE_STRING:
+                if (!ir_value_set_string(v, self->constval.vstring))
+                    goto error;
+                break;
+            default:
+                printf("TODO: global constant type %i\n", self->vtype);
+                break;
+        }
+    }
+
+    /* link us to the ir_value */
+    self->ir_v = v;
+    return true;
+
+error: /* clean up */
+    ir_value_delete(v);
+    return false;
+}
+
 bool ast_function_codegen(ast_function *self, ir_builder *ir)
 {
     if (!self->ir_func) {