ir_constant *op[2];
unsigned int operand, c;
ir_constant_data data;
- const glsl_type *type = NULL;
for (operand = 0; operand < ir->get_num_operands(); operand++) {
op[operand] = ir->operands[operand]->constant_expression_value();
switch (ir->operation) {
case ir_unop_logic_not:
- type = ir->operands[0]->type;
- assert(type->base_type == GLSL_TYPE_BOOL);
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
for (c = 0; c < ir->operands[0]->type->components(); c++)
data.b[c] = !op[0]->value.b[c];
break;
case ir_unop_f2i:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.i[c] = op[0]->value.f[c];
}
case ir_unop_i2f:
assert(op[0]->type->base_type == GLSL_TYPE_UINT ||
op[0]->type->base_type == GLSL_TYPE_INT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
if (op[0]->type->base_type == GLSL_TYPE_INT)
data.f[c] = op[0]->value.i[c];
break;
case ir_unop_b2f:
assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.f[c] = op[0]->value.b[c] ? 1.0 : 0.0;
}
break;
case ir_unop_f2b:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.b[c] = bool(op[0]->value.f[c]);
}
break;
case ir_unop_b2i:
assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.u[c] = op[0]->value.b[c] ? 1 : 0;
}
break;
case ir_unop_i2b:
assert(op[0]->type->is_integer());
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.b[c] = bool(op[0]->value.u[c]);
}
break;
case ir_unop_neg:
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
- switch (type->base_type) {
+ switch (ir->type->base_type) {
case GLSL_TYPE_UINT:
data.u[c] = -op[0]->value.u[c];
break;
case ir_unop_abs:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
- switch (type->base_type) {
+ switch (ir->type->base_type) {
case GLSL_TYPE_UINT:
data.u[c] = op[0]->value.u[c];
break;
case ir_unop_rcp:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
- switch (type->base_type) {
+ switch (ir->type->base_type) {
case GLSL_TYPE_UINT:
if (op[0]->value.u[c] != 0.0)
data.u[c] = 1 / op[0]->value.u[c];
case ir_unop_rsq:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.f[c] = 1.0 / sqrtf(op[0]->value.f[c]);
}
case ir_unop_sqrt:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.f[c] = sqrtf(op[0]->value.f[c]);
}
case ir_unop_exp:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.f[c] = expf(op[0]->value.f[c]);
}
case ir_unop_log:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.f[c] = logf(op[0]->value.f[c]);
}
case ir_unop_dFdx:
case ir_unop_dFdy:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
- type = ir->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
data.f[c] = 0.0;
}
case ir_binop_add:
if (ir->operands[0]->type == ir->operands[1]->type) {
- type = ir->operands[0]->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
switch (ir->operands[0]->type->base_type) {
case GLSL_TYPE_UINT:
assert(0);
}
}
- }
+ } else
+ /* FINISHME: Support operations with non-equal types. */
+ return;
+
break;
case ir_binop_sub:
if (ir->operands[0]->type == ir->operands[1]->type) {
- type = ir->operands[0]->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
switch (ir->operands[0]->type->base_type) {
case GLSL_TYPE_UINT:
assert(0);
}
}
- }
+ } else
+ /* FINISHME: Support operations with non-equal types. */
+ return;
+
break;
case ir_binop_mul:
if (ir->operands[0]->type == ir->operands[1]->type &&
!ir->operands[0]->type->is_matrix()) {
- type = ir->operands[0]->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
switch (ir->operands[0]->type->base_type) {
case GLSL_TYPE_UINT:
assert(0);
}
}
- }
+ } else
+ /* FINISHME: Support operations with non-equal types. */
+ return;
+
break;
case ir_binop_div:
if (ir->operands[0]->type == ir->operands[1]->type) {
- type = ir->operands[0]->type;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
switch (ir->operands[0]->type->base_type) {
case GLSL_TYPE_UINT:
assert(0);
}
}
- }
+ } else
+ /* FINISHME: Support operations with non-equal types. */
+ return;
+
break;
case ir_binop_logic_and:
- type = ir->operands[0]->type;
- assert(type->base_type == GLSL_TYPE_BOOL);
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
for (c = 0; c < ir->operands[0]->type->components(); c++)
data.b[c] = op[0]->value.b[c] && op[1]->value.b[c];
break;
case ir_binop_logic_xor:
- type = ir->operands[0]->type;
- assert(type->base_type == GLSL_TYPE_BOOL);
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
for (c = 0; c < ir->operands[0]->type->components(); c++)
data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c];
break;
case ir_binop_logic_or:
- type = ir->operands[0]->type;
- assert(type->base_type == GLSL_TYPE_BOOL);
+ assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
for (c = 0; c < ir->operands[0]->type->components(); c++)
data.b[c] = op[0]->value.b[c] || op[1]->value.b[c];
break;
case ir_binop_less:
- type = glsl_type::bool_type;
switch (ir->operands[0]->type->base_type) {
case GLSL_TYPE_UINT:
data.b[0] = op[0]->value.u[0] < op[1]->value.u[0];
}
break;
case ir_binop_greater:
- type = glsl_type::bool_type;
switch (ir->operands[0]->type->base_type) {
case GLSL_TYPE_UINT:
data.b[0] = op[0]->value.u[0] > op[1]->value.u[0];
}
break;
case ir_binop_lequal:
- type = glsl_type::bool_type;
switch (ir->operands[0]->type->base_type) {
case GLSL_TYPE_UINT:
data.b[0] = op[0]->value.u[0] <= op[1]->value.u[0];
}
break;
case ir_binop_gequal:
- type = glsl_type::bool_type;
switch (ir->operands[0]->type->base_type) {
case GLSL_TYPE_UINT:
data.b[0] = op[0]->value.u[0] >= op[1]->value.u[0];
break;
case ir_binop_equal:
- type = glsl_type::bool_type;
data.b[0] = true;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
switch (ir->operands[0]->type->base_type) {
}
break;
case ir_binop_nequal:
- type = glsl_type::bool_type;
data.b[0] = false;
for (c = 0; c < ir->operands[0]->type->components(); c++) {
switch (ir->operands[0]->type->base_type) {
break;
default:
- break;
+ /* FINISHME: Should handle all expression types. */
+ return;
}
- if (type) {
- this->value = new ir_constant(type, &data);
- }
+ this->value = new ir_constant(ir->type, &data);
}