diff options
author | Eric Anholt <eric@anholt.net> | 2010-04-01 18:07:08 -1000 |
---|---|---|
committer | Ian Romanick <ian.d.romanick@intel.com> | 2010-04-02 11:22:41 -0700 |
commit | 160d092507c1ca341b7c5c88e5ba94b4cf5fb7d0 (patch) | |
tree | 2cb33458b814deded2b4b767cf9c2d1ce977afba /ir_constant_expression.cpp | |
parent | 90b7825b0e92375dbe721d2dca1a4a3f1093f4ab (diff) |
Simplify ir_constant_expression.cpp by factoring operand computation out.
Diffstat (limited to 'ir_constant_expression.cpp')
-rw-r--r-- | ir_constant_expression.cpp | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/ir_constant_expression.cpp b/ir_constant_expression.cpp index c7c4d7b244..476afe8b87 100644 --- a/ir_constant_expression.cpp +++ b/ir_constant_expression.cpp @@ -133,40 +133,36 @@ ir_constant_visitor::visit(ir_expression *ir) { value = NULL; ir_constant *op[2]; + unsigned int i; + + for (i = 0; i < ir->get_num_operands(); i++) { + op[i] = ir->operands[i]->constant_expression_value(); + if (!op[i]) + return; + } switch (ir->operation) { case ir_unop_logic_not: - op[0] = ir->operands[0]->constant_expression_value(); - if (op[0]) { - value = new ir_constant(!op[0]->value.b[0]); - value->type = glsl_type::bool_type; - } + value = new ir_constant(!op[0]->value.b[0]); + value->type = glsl_type::bool_type; break; case ir_binop_mul: - op[0] = ir->operands[0]->constant_expression_value(); - op[1] = ir->operands[1]->constant_expression_value(); - if (op[0] && op[1] && ir->operands[0]->type == ir->operands[1]->type) { + if (ir->operands[0]->type == ir->operands[1]->type) { if (ir->operands[1]->type == glsl_type::float_type) { value = new ir_constant(op[0]->value.f[0] * op[1]->value.f[0]); value->type = glsl_type::float_type; } } + if (value) + value->type = ir->operands[1]->type; break; case ir_binop_logic_and: - op[0] = ir->operands[0]->constant_expression_value(); - op[1] = ir->operands[1]->constant_expression_value(); - if (op[0] && op[1]) { - value = new ir_constant(op[0]->value.b[0] && op[1]->value.b[0]); - value->type = glsl_type::bool_type; - } + value = new ir_constant(op[0]->value.b[0] && op[1]->value.b[0]); + value->type = glsl_type::bool_type; break; case ir_binop_logic_or: - op[0] = ir->operands[0]->constant_expression_value(); - op[1] = ir->operands[1]->constant_expression_value(); - if (op[0] && op[1]) { - value = new ir_constant(op[0]->value.b[0] || op[1]->value.b[0]); - value->type = glsl_type::bool_type; - } + value = new ir_constant(op[0]->value.b[0] || op[1]->value.b[0]); + value->type = glsl_type::bool_type; break; default: break; |