]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
MUL_VF and MUL_FV get their special life-range handling
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 7c349b4638657b2cfa52dbe8866479dcf4e65199..dda26ab7d047ae1ae0f12a2e6e733362e5446f28 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -788,6 +788,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir)
         v = ir_builder_create_field(ir, self->name, self->expression.next->expression.vtype);
         if (!v)
             return false;
+        v->context = ast_ctx(self);
         if (self->isconst) {
             asterror(ast_ctx(self), "TODO: constant field pointers with value\n");
             goto error;
@@ -801,6 +802,7 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir)
         asterror(ast_ctx(self), "ir_builder_create_global failed\n");
         return false;
     }
+    v->context = ast_ctx(self);
 
     if (self->isconst) {
         switch (self->expression.vtype)
@@ -852,6 +854,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
     v = ir_function_create_local(func, self->name, self->expression.vtype, param);
     if (!v)
         return false;
+    v->context = ast_ctx(self);
 
     /* A constant local... hmmm...
      * I suppose the IR will have to deal with this
@@ -934,6 +937,9 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
     /* TODO: check return types */
     if (!self->curblock->is_return)
     {
+        return ir_block_create_return(self->curblock, NULL);
+        /* From now on the parser has to handle this situation */
+#if 0
         if (!self->vtype->expression.next ||
             self->vtype->expression.next->expression.vtype == TYPE_VOID)
         {
@@ -945,6 +951,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
             asterror(ast_ctx(self), "function `%s` missing return value", self->name);
             return false;
         }
+#endif
     }
     return true;
 }
@@ -1274,6 +1281,8 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
     ir_block *cond = func->curblock;
     ir_block *ontrue;
     ir_block *onfalse;
+    ir_block *ontrue_endblock;
+    ir_block *onfalse_endblock;
     ir_block *merge;
 
     /* We don't output any value, thus also don't care about r/lvalue */
@@ -1307,6 +1316,9 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
         cgen = self->on_true->expression.codegen;
         if (!(*cgen)((ast_expression*)(self->on_true), func, false, &dummy))
             return false;
+
+        /* we now need to work from the current endpoint */
+        ontrue_endblock = func->curblock;
     } else
         ontrue = NULL;
 
@@ -1324,6 +1336,9 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
         cgen = self->on_false->expression.codegen;
         if (!(*cgen)((ast_expression*)(self->on_false), func, false, &dummy))
             return false;
+
+        /* we now need to work from the current endpoint */
+        onfalse_endblock = func->curblock;
     } else
         onfalse = NULL;
 
@@ -1333,9 +1348,9 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
         return false;
 
     /* add jumps ot the merge block */
-    if (ontrue && !ontrue->final && !ir_block_create_jump(ontrue, merge))
+    if (ontrue && !ontrue_endblock->final && !ir_block_create_jump(ontrue_endblock, merge))
         return false;
-    if (onfalse && !onfalse->final && !ir_block_create_jump(onfalse, merge))
+    if (onfalse && !onfalse_endblock->final && !ir_block_create_jump(onfalse_endblock, merge))
         return false;
 
     /* we create the if here, that way all blocks are ordered :)