summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-06-11 12:56:26 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-06-11 15:43:59 -0700
commit0ad76c67675c35a65a79752058f53eee74947ba5 (patch)
tree719c8470623998c1dd4ab6addac8e357a9dd4ab5
parentc2ba6190921be014fecaca0a5627ecc72fa7b2a1 (diff)
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.
-rw-r--r--ast_to_hir.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp
index 307e448..b8375b3 100644
--- a/ast_to_hir.cpp
+++ b/ast_to_hir.cpp
@@ -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;
}