]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
reorder ifthen codegen and fix a jump generation where I used ontrue instead of onfalse
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 20:05:20 +0000 (22:05 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 20:05:20 +0000 (22:05 +0200)
ast.c

diff --git a/ast.c b/ast.c
index 7a68ba352bca72bfeb869d80c63740accf8c5a59..6a6abe5d83a4658464ce95b7e5bde3a47d1405db 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -742,34 +742,60 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
     (void)out;
     (void)lvalue;
 
-    /* create blocks first, it's nicer if they're ordered */
+    /* generate the condition */
+    func->curblock = cond;
+    cgen = self->cond->expression.codegen;
+    if (!(*cgen)((ast_expression*)(self->cond), func, false, &condval))
+        return false;
+
+    /* on-true path */
 
     if (self->on_true) {
         /* create on-true block */
         ontrue = ir_function_create_block(func->ir_func, ast_function_label(func, "ontrue"));
         if (!ontrue)
             return false;
+
+        /* enter the block */
+        func->curblock = ontrue;
+
+        /* generate */
+        cgen = self->on_true->expression.codegen;
+        if (!(*cgen)((ast_expression*)(self->on_true), func, false, &dummy))
+            return false;
     } else
         ontrue = NULL;
     
+    /* on-false path */
     if (self->on_false) {
         /* create on-false block */
         onfalse = ir_function_create_block(func->ir_func, ast_function_label(func, "onfalse"));
         if (!onfalse)
             return false;
+
+        /* enter the block */
+        func->curblock = onfalse;
+
+        /* generate */
+        cgen = self->on_false->expression.codegen;
+        if (!(*cgen)((ast_expression*)(self->on_false), func, false, &dummy))
+            return false;
     } else
         onfalse = NULL;
 
+    /* Merge block were they all merge in to */
     merge = ir_function_create_block(func->ir_func, ast_function_label(func, "endif"));
     if (!merge)
         return NULL;
 
-    /* generate the condition */
-    func->curblock = cond;
-    cgen = self->cond->expression.codegen;
-    if (!(*cgen)((ast_expression*)(self->cond), func, false, &condval))
+    /* add jumps ot the merge block */
+    if (ontrue && !ir_block_create_jump(ontrue, merge))
+        return false;
+    if (onfalse && !ir_block_create_jump(onfalse, merge))
         return false;
 
+    /* we create the if here, that way all blocks are ordered :)
+     */
     if (!ir_block_create_if(cond, condval,
                             (ontrue  ? ontrue  : merge),
                             (onfalse ? onfalse : merge)))
@@ -777,36 +803,6 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
         return false;
     }
 
-    /* on-true path */
-    if (ontrue) {
-        /* enter the block */
-        func->curblock = ontrue;
-
-        /* generate */
-        cgen = self->on_true->expression.codegen;
-        if (!(*cgen)((ast_expression*)(self->on_true), func, false, &dummy))
-            return false;
-
-        /* jump to merge block */
-        if (!ir_block_create_jump(ontrue, merge))
-            return false;
-    }
-
-    /* on-false path */
-    if (onfalse) {
-        /* enter the block */
-        func->curblock = onfalse;
-
-        /* generate */
-        cgen = self->on_false->expression.codegen;
-        if (!(*cgen)((ast_expression*)(self->on_false), func, false, &dummy))
-            return false;
-
-        /* jump to merge block */
-        if (!ir_block_create_jump(ontrue, merge))
-            return false;
-    }
-
     /* Now enter the merge block */
     func->curblock = merge;
 
@@ -919,5 +915,17 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
 
 bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value **out)
 {
+    ast_expression_codegen *cgen;
+
+    ir_value *precond;
+    ir_value *postcond;
+
+    ir_block *binit;
+    ir_block *bprecond;
+    ir_block *bpostcond;
+    ir_block *bincrement;
+
+    (void)lvalue;
+
     return false;
 }