From 00eb466e38733f386794b35ae5b0aab18b60b1d2 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 7 Jun 2010 15:08:04 -0700 Subject: [PATCH] Constant-fold constructor parameters after type conversion This causes the following tests to pass: glslparsertest/shaders/CorrectMatComma2.frag One of the incorrect errors in glslparsertest/shaders/CorrectComma.frag is also eliminated. --- ast_function.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ast_function.cpp b/ast_function.cpp index 6de72ab2d8a..07674ada741 100644 --- a/ast_function.cpp +++ b/ast_function.cpp @@ -137,6 +137,7 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type) { const unsigned a = desired_type->base_type; const unsigned b = src->type->base_type; + ir_expression *result = NULL; if (src->type->is_error()) return src; @@ -151,32 +152,37 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type) case GLSL_TYPE_UINT: case GLSL_TYPE_INT: if (b == GLSL_TYPE_FLOAT) - return new ir_expression(ir_unop_f2i, desired_type, src, NULL); + result = new ir_expression(ir_unop_f2i, desired_type, src, NULL); else { assert(b == GLSL_TYPE_BOOL); - return new ir_expression(ir_unop_b2i, desired_type, src, NULL); + result = new ir_expression(ir_unop_b2i, desired_type, src, NULL); } break; case GLSL_TYPE_FLOAT: switch (b) { case GLSL_TYPE_UINT: - return new ir_expression(ir_unop_u2f, desired_type, src, NULL); + result = new ir_expression(ir_unop_u2f, desired_type, src, NULL); + break; case GLSL_TYPE_INT: - return new ir_expression(ir_unop_i2f, desired_type, src, NULL); + result = new ir_expression(ir_unop_i2f, desired_type, src, NULL); + break; case GLSL_TYPE_BOOL: - return new ir_expression(ir_unop_b2f, desired_type, src, NULL); + result = new ir_expression(ir_unop_b2f, desired_type, src, NULL); + break; } break; case GLSL_TYPE_BOOL: { int z = 0; ir_constant *const zero = new ir_constant(src->type, &z); - return new ir_expression(ir_binop_nequal, desired_type, src, zero); + result = new ir_expression(ir_binop_nequal, desired_type, src, zero); } } - assert(!"Should not get here."); - return NULL; + assert(result != NULL); + + ir_constant *const constant = result->constant_expression_value(); + return (constant != NULL) ? (ir_rvalue *) constant : (ir_rvalue *) result; } -- 2.30.2