mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-27 14:12:36 +00:00
Same for ternary: reordered a bit, and fixing ontrue->onfalse at the jump back to the merge block
This commit is contained in:
parent
8a543bfae1
commit
a1a9fc797d
1 changed files with 41 additions and 40 deletions
43
ast.c
43
ast.c
|
@ -838,30 +838,18 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
|
|||
|
||||
/* In the following, contraty to ast_ifthen, we assume both paths exist. */
|
||||
|
||||
/* create on-true block */
|
||||
ontrue = ir_function_create_block(func->ir_func, ast_function_label(func, "tern_T"));
|
||||
if (!ontrue)
|
||||
return false;
|
||||
|
||||
/* create on-false block */
|
||||
onfalse = ir_function_create_block(func->ir_func, ast_function_label(func, "tern_F"));
|
||||
if (!onfalse)
|
||||
return false;
|
||||
|
||||
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))
|
||||
/* create on-true block */
|
||||
ontrue = ir_function_create_block(func->ir_func, ast_function_label(func, "tern_T"));
|
||||
if (!ontrue)
|
||||
return false;
|
||||
|
||||
/* on-true path */
|
||||
else
|
||||
{
|
||||
/* enter the block */
|
||||
func->curblock = ontrue;
|
||||
|
||||
|
@ -869,12 +857,14 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
|
|||
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))
|
||||
/* create on-false block */
|
||||
onfalse = ir_function_create_block(func->ir_func, ast_function_label(func, "tern_F"));
|
||||
if (!onfalse)
|
||||
return false;
|
||||
|
||||
/* on-false path */
|
||||
else
|
||||
{
|
||||
/* enter the block */
|
||||
func->curblock = onfalse;
|
||||
|
||||
|
@ -882,10 +872,21 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
|
|||
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;
|
||||
/* jump to merge block */
|
||||
if (!ir_block_create_jump(ontrue, merge))
|
||||
return false;
|
||||
if (!ir_block_create_jump(onfalse, merge))
|
||||
return false;
|
||||
|
||||
/* create if instruction */
|
||||
if (!ir_block_create_if(cond, condval, ontrue, onfalse))
|
||||
return false;
|
||||
|
||||
/* Now enter the merge block */
|
||||
func->curblock = merge;
|
||||
|
|
Loading…
Reference in a new issue