summaryrefslogtreecommitdiff
path: root/ir_constant_expression.cpp
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-03-31 16:25:12 -1000
committerIan Romanick <ian.d.romanick@intel.com>2010-04-02 11:05:16 -0700
commita576f9d84c35ecc8a797fea6e5e26e5320f7ac0c (patch)
tree017d0581ffb46c92683ff7d3c922e11798960cca /ir_constant_expression.cpp
parent307c71bf24a3c99409ccf4b8b10f161e4b032cba (diff)
Start trying to fill in a few bits of ir_constant_expression.cpp
This makes a little progress on CorrectParse2.frag.
Diffstat (limited to 'ir_constant_expression.cpp')
-rw-r--r--ir_constant_expression.cpp35
1 files changed, 33 insertions, 2 deletions
diff --git a/ir_constant_expression.cpp b/ir_constant_expression.cpp
index b8a9031fba..942bd8097e 100644
--- a/ir_constant_expression.cpp
+++ b/ir_constant_expression.cpp
@@ -36,6 +36,7 @@
#define NULL 0
#include "ir.h"
#include "ir_visitor.h"
+#include "glsl_types.h"
/**
* Visitor class for evaluating constant expressions
@@ -127,12 +128,42 @@ ir_constant_visitor::visit(ir_function *ir)
value = NULL;
}
-
void
ir_constant_visitor::visit(ir_expression *ir)
{
- (void) ir;
value = NULL;
+ ir_constant *op[2];
+
+ switch (ir->operation) {
+ 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[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;
+ }
+ }
+ 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;
+ }
+ 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;
+ }
+ break;
+ default:
+ break;
+ }
}