Browse Source

Rearrange code in HIR conversion of ?: operator

There are no functional changes.  Code is just moved arround.  This
prepares for the next set of changes that do change the functionality.
tags/mesa-7.9-rc1
Ian Romanick 16 years ago
parent
commit
0ad76c6767
1 changed files with 24 additions and 18 deletions
  1. 24
    18
      ast_to_hir.cpp

+ 24
- 18
ast_to_hir.cpp View File

@@ -1000,23 +1000,11 @@ ast_expression::hir(exec_list *instructions,
* the if-statement assigns a value to the anonymous temporary. This
* temporary is the r-value of the expression.
*/
ir_variable *const tmp = generate_temporary(glsl_type::error_type,
instructions, state);

ir_if *const stmt = new ir_if(op[0]);
instructions->push_tail(stmt);

op[1] = this->subexpressions[1]->hir(& stmt->then_instructions, state);
ir_dereference *const then_deref = new ir_dereference_variable(tmp);
ir_assignment *const then_assign =
new ir_assignment(then_deref, op[1], NULL);
stmt->then_instructions.push_tail(then_assign);
exec_list then_instructions;
exec_list else_instructions;

op[2] = this->subexpressions[2]->hir(& stmt->else_instructions, state);
ir_dereference *const else_deref = new ir_dereference_variable(tmp);
ir_assignment *const else_assign =
new ir_assignment(else_deref, op[2], NULL);
stmt->else_instructions.push_tail(else_assign);
op[1] = this->subexpressions[1]->hir(&then_instructions, state);
op[2] = this->subexpressions[2]->hir(&else_instructions, state);

/* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec:
*
@@ -1035,12 +1023,30 @@ ast_expression::hir(exec_list *instructions,
_mesa_glsl_error(& loc, state, "Second and third operands of ?: "
"operator must have matching types.");
error_emitted = true;
type = glsl_type::error_type;
} else {
tmp->type = op[1]->type;
type = op[1]->type;
}

ir_variable *const tmp = generate_temporary(type,
instructions, state);

ir_if *const stmt = new ir_if(op[0]);
instructions->push_tail(stmt);

then_instructions.move_nodes_to(& stmt->then_instructions);
ir_dereference *const then_deref = new ir_dereference_variable(tmp);
ir_assignment *const then_assign =
new ir_assignment(then_deref, op[1], NULL);
stmt->then_instructions.push_tail(then_assign);

else_instructions.move_nodes_to(& stmt->else_instructions);
ir_dereference *const else_deref = new ir_dereference_variable(tmp);
ir_assignment *const else_assign =
new ir_assignment(else_deref, op[2], NULL);
stmt->else_instructions.push_tail(else_assign);

result = new ir_dereference_variable(tmp);
type = tmp->type;
break;
}


Loading…
Cancel
Save