this->operands[1] = op1;
}
+unsigned int
+ir_expression::get_num_operands(void)
+{
+/* Update ir_print_visitor.cpp when updating this list. */
+ const int num_operands[] = {
+ 1, /* ir_unop_bit_not */
+ 1, /* ir_unop_logic_not */
+ 1, /* ir_unop_neg */
+ 1, /* ir_unop_abs */
+ 1, /* ir_unop_rcp */
+ 1, /* ir_unop_rsq */
+ 1, /* ir_unop_sqrt */
+ 1, /* ir_unop_exp */
+ 1, /* ir_unop_log */
+ 1, /* ir_unop_exp2 */
+ 1, /* ir_unop_log2 */
+ 1, /* ir_unop_f2i */
+ 1, /* ir_unop_i2f */
+ 1, /* ir_unop_u2f */
+
+ 1, /* ir_unop_trunc */
+ 1, /* ir_unop_ceil */
+ 1, /* ir_unop_floor */
+
+ 2, /* ir_binop_add */
+ 2, /* ir_binop_sub */
+ 2, /* ir_binop_mul */
+ 2, /* ir_binop_div */
+ 2, /* ir_binop_mod */
+
+ 2, /* ir_binop_less */
+ 2, /* ir_binop_greater */
+ 2, /* ir_binop_lequal */
+ 2, /* ir_binop_gequal */
+ 2, /* ir_binop_equal */
+ 2, /* ir_binop_nequal */
+
+ 2, /* ir_binop_lshift */
+ 2, /* ir_binop_rshift */
+ 2, /* ir_binop_bit_and */
+ 2, /* ir_binop_bit_xor */
+ 2, /* ir_binop_bit_or */
+
+ 2, /* ir_binop_logic_and */
+ 2, /* ir_binop_logic_xor */
+ 2, /* ir_binop_logic_or */
+
+ 2, /* ir_binop_dot */
+ 2, /* ir_binop_min */
+ 2, /* ir_binop_max */
+
+ 2, /* ir_binop_pow */
+ };
+
+ assert(sizeof(num_operands) / sizeof(num_operands[0]) == ir_binop_pow + 1);
+
+ return num_operands[this->operation];
+}
ir_label::ir_label(const char *label)
: ir_instruction(), label(label)
ir_rvalue *condition;
};
-/* Update ir_print_visitor.cpp when updating this list. */
+/* Update ir_expression::num_operands() and ir_print_visitor.cpp when
+ * updating this list.
+*/
enum ir_expression_operation {
ir_unop_bit_not,
ir_unop_logic_not,
ir_expression(int op, const struct glsl_type *type,
ir_rvalue *, ir_rvalue *);
+ unsigned int get_num_operands(void);
+
virtual void accept(ir_visitor *v)
{
v->visit(this);
{
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;