]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Same for ternary: reordered a bit, and fixing ontrue->onfalse at the jump back to...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 20:07:58 +0000 (22:07 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 3 May 2012 20:07:58 +0000 (22:07 +0200)
ast.c

diff --git a/ast.c b/ast.c
index 6a6abe5d83a4658464ce95b7e5bde3a47d1405db..de2c3156f7bcdf7140eedc5cc1dcbc1309bfac07 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -837,54 +837,55 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
         return false;
 
     /* In the following, contraty to ast_ifthen, we assume both paths exist. */
+    
+    /* generate the condition */
+    func->curblock = cond;
+    cgen = self->cond->expression.codegen;
+    if (!(*cgen)((ast_expression*)(self->cond), func, false, &condval))
+        return false;
 
     /* create on-true block */
     ontrue = ir_function_create_block(func->ir_func, ast_function_label(func, "tern_T"));
     if (!ontrue)
         return false;
+    else
+    {
+        /* enter the block */
+        func->curblock = ontrue;
+
+        /* generate */
+        cgen = self->on_true->expression.codegen;
+        if (!(*cgen)((ast_expression*)(self->on_true), func, false, &trueval))
+            return false;
+    }
     
     /* create on-false block */
     onfalse = ir_function_create_block(func->ir_func, ast_function_label(func, "tern_F"));
     if (!onfalse)
         return false;
+    else
+    {
+        /* enter the block */
+        func->curblock = onfalse;
+
+        /* generate */
+        cgen = self->on_false->expression.codegen;
+        if (!(*cgen)((ast_expression*)(self->on_false), func, false, &falseval))
+            return false;
+    }
 
+    /* create merge block */
     merge = ir_function_create_block(func->ir_func, ast_function_label(func, "tern_out"));
     if (!merge)
         return NULL;
-
-    /* generate the condition */
-    func->curblock = cond;
-    cgen = self->cond->expression.codegen;
-    if (!(*cgen)((ast_expression*)(self->cond), func, false, &condval))
-        return false;
-
-    if (!ir_block_create_if(cond, condval, ontrue, onfalse))
-        return false;
-
-    /* on-true path */
-    /* enter the block */
-    func->curblock = ontrue;
-
-    /* generate */
-    cgen = self->on_true->expression.codegen;
-    if (!(*cgen)((ast_expression*)(self->on_true), func, false, &trueval))
-        return false;
-
     /* jump to merge block */
     if (!ir_block_create_jump(ontrue, merge))
         return false;
-
-    /* on-false path */
-    /* enter the block */
-    func->curblock = onfalse;
-
-    /* generate */
-    cgen = self->on_false->expression.codegen;
-    if (!(*cgen)((ast_expression*)(self->on_false), func, false, &falseval))
+    if (!ir_block_create_jump(onfalse, merge))
         return false;
 
-    /* jump to merge block */
-    if (!ir_block_create_jump(ontrue, merge))
+    /* create if instruction */
+    if (!ir_block_create_if(cond, condval, ontrue, onfalse))
         return false;
 
     /* Now enter the merge block */