]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
ast_function generates parameter locals, ir_function_create_local now allows adding...
authorWolfgang Bumiller <wolfgang.linux@bumiller.com>
Sun, 22 Jul 2012 10:15:48 +0000 (12:15 +0200)
committerWolfgang Bumiller <wolfgang.linux@bumiller.com>
Sun, 22 Jul 2012 10:15:48 +0000 (12:15 +0200)
ast.c
ast.h
ir.c
ir.h

diff --git a/ast.c b/ast.c
index 767dde92badaf54f15bc3e196d42ba38a2ba4270..f0fba0f99a6d3db764e8f1e51ba3d30f1b4e8e5e 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -557,7 +557,7 @@ error: /* clean up */
     return false;
 }
 
-bool ast_local_codegen(ast_value *self, ir_function *func)
+bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
 {
     ir_value *v = NULL;
     if (self->isconst && self->expression.vtype == TYPE_FUNCTION)
@@ -568,7 +568,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func)
         return false;
     }
 
-    v = ir_function_create_local(func, self->name, self->expression.vtype);
+    v = ir_function_create_local(func, self->name, self->expression.vtype, param);
     if (!v)
         return false;
 
@@ -617,11 +617,23 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
         return false;
     }
 
+    if (!self->builtin && self->vtype->params_count != self->params_count) {
+        printf("ast_function's parameter variables doesn't match the declared parameter count\n");
+        printf("%i != %i\n", self->vtype->params_count, self->params_count);
+        return false;
+    }
+
+    /* fill the parameter list */
     for (i = 0; i < self->vtype->params_count; ++i)
     {
         if (!ir_function_params_add(irf, self->vtype->params[i]->expression.vtype))
             return false;
     }
+    /* generate the parameter locals */
+    for (i = 0; i < self->params_count; ++i) {
+        if (!ast_local_codegen(self->params[i], self->ir_func, true))
+            return false;
+    }
 
     if (self->builtin) {
         irf->builtin = self->builtin;
@@ -682,7 +694,7 @@ bool ast_block_codegen(ast_block *self, ast_function *func, bool lvalue, ir_valu
     /* generate locals */
     for (i = 0; i < self->locals_count; ++i)
     {
-        if (!ast_local_codegen(self->locals[i], func->ir_func))
+        if (!ast_local_codegen(self->locals[i], func->ir_func, false))
             return false;
     }
 
diff --git a/ast.h b/ast.h
index ecc2498b3356ba10f535f5bdbc9c140a1b0f7e81..26edec91e791c5a3577316c99151d18eb696ad8d 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -125,7 +125,7 @@ void ast_value_delete(ast_value*);
 bool ast_value_set_name(ast_value*, const char *name);
 
 bool ast_value_codegen(ast_value*, ast_function*, bool lvalue, ir_value**);
-bool ast_local_codegen(ast_value *self, ir_function *func);
+bool ast_local_codegen(ast_value *self, ir_function *func, bool isparam);
 bool ast_global_codegen(ast_value *self, ir_builder *ir);
 
 /* Binary
diff --git a/ir.c b/ir.c
index 22119495f7fa83c45983985696c2bbb01c5e479c..0c0517a54d791cfdd248efcd98d8b4433fa8e9f4 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -311,14 +311,21 @@ ir_value* ir_function_get_local(ir_function *self, const char *name)
     return NULL;
 }
 
-ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype)
+ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype, bool param)
 {
     ir_value *ve = ir_function_get_local(self, name);
     if (ve) {
         return NULL;
     }
 
-    ve = ir_value_var(name, store_local, vtype);
+    if (param &&
+        self->locals_count &&
+        self->locals[self->locals_count-1]->store != store_param) {
+        printf("cannot add parameters after adding locals\n");
+        return NULL;
+    }
+
+    ve = ir_value_var(name, (param ? store_param : store_local), vtype);
     if (!ir_function_locals_add(self, ve)) {
         ir_value_delete(ve);
         return NULL;
diff --git a/ir.h b/ir.h
index 7aa889bae7e25ab3ca822c8a562a9d9e90e4447b..fb0f699283dc9036aa16111359c184af6835875b 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -265,7 +265,7 @@ MEM_VECTOR_PROTO(ir_function, int, params);
 MEM_VECTOR_PROTO(ir_function, ir_block*, blocks);
 
 ir_value* ir_function_get_local(ir_function *self, const char *name);
-ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype);
+ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype, bool param);
 
 bool GMQCC_WARN ir_function_finalize(ir_function*);
 /*