aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/ast_to_hir.cpp
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-04-27 15:56:59 +0000
committermarha <marha@users.sourceforge.net>2011-04-27 15:56:59 +0000
commit100633b3e7619842f345cb7603b0db6b5761dd11 (patch)
tree3c3af754c7e801c07263269837d6a05072ff834c /mesalib/src/glsl/ast_to_hir.cpp
parent205a4bdae76f287126db9f45a4f0ba631e3efca1 (diff)
parent96d6df5da9cddedf4931bf8e17f96e242467c661 (diff)
downloadvcxsrv-100633b3e7619842f345cb7603b0db6b5761dd11.tar.gz
vcxsrv-100633b3e7619842f345cb7603b0db6b5761dd11.tar.bz2
vcxsrv-100633b3e7619842f345cb7603b0db6b5761dd11.zip
svn merge ^/branches/released .
Diffstat (limited to 'mesalib/src/glsl/ast_to_hir.cpp')
-rw-r--r--mesalib/src/glsl/ast_to_hir.cpp60
1 files changed, 39 insertions, 21 deletions
diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp
index d7e54d823..b5cffcd47 100644
--- a/mesalib/src/glsl/ast_to_hir.cpp
+++ b/mesalib/src/glsl/ast_to_hir.cpp
@@ -940,7 +940,7 @@ ast_expression::hir(exec_list *instructions,
};
ir_rvalue *result = NULL;
ir_rvalue *op[3];
- const struct glsl_type *type = glsl_type::error_type;
+ const struct glsl_type *type; /* a temporary variable for switch cases */
bool error_emitted = false;
YYLTYPE loc;
@@ -954,7 +954,6 @@ ast_expression::hir(exec_list *instructions,
result = do_assignment(instructions, state, op[0], op[1], false,
this->subexpressions[0]->get_location());
error_emitted = result->type->is_error();
- type = result->type;
break;
}
@@ -1078,9 +1077,7 @@ ast_expression::hir(exec_list *instructions,
} else {
result = do_comparison(ctx, operations[this->oper], op[0], op[1]);
assert(result->type == glsl_type::bool_type);
- type = glsl_type::bool_type;
}
-
break;
case ast_bit_and:
@@ -1209,7 +1206,6 @@ ast_expression::hir(exec_list *instructions,
result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
op[0], op[1]);
- type = glsl_type::bool_type;
break;
case ast_logic_not:
@@ -1218,7 +1214,6 @@ ast_expression::hir(exec_list *instructions,
result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
op[0], NULL);
- type = glsl_type::bool_type;
break;
case ast_mul_assign:
@@ -1238,7 +1233,6 @@ ast_expression::hir(exec_list *instructions,
result = do_assignment(instructions, state,
op[0]->clone(ctx, NULL), temp_rhs, false,
this->subexpressions[0]->get_location());
- type = result->type;
error_emitted = (op[0]->type->is_error());
/* GLSL 1.10 does not allow array assignment. However, we don't have to
@@ -1264,7 +1258,6 @@ ast_expression::hir(exec_list *instructions,
result = do_assignment(instructions, state,
op[0]->clone(ctx, NULL), temp_rhs, false,
this->subexpressions[0]->get_location());
- type = result->type;
error_emitted = type->is_error();
break;
}
@@ -1406,7 +1399,6 @@ ast_expression::hir(exec_list *instructions,
result = do_assignment(instructions, state,
op[0]->clone(ctx, NULL), temp_rhs, false,
this->subexpressions[0]->get_location());
- type = result->type;
error_emitted = op[0]->type->is_error();
break;
}
@@ -1436,14 +1428,12 @@ ast_expression::hir(exec_list *instructions,
op[0]->clone(ctx, NULL), temp_rhs, false,
this->subexpressions[0]->get_location());
- type = result->type;
error_emitted = op[0]->type->is_error();
break;
}
case ast_field_selection:
result = _mesa_ast_field_selection_to_hir(this, instructions, state);
- type = result->type;
break;
case ast_array_index: {
@@ -1600,7 +1590,6 @@ ast_expression::hir(exec_list *instructions,
if (error_emitted)
result->type = glsl_type::error_type;
- type = result->type;
break;
}
@@ -1623,7 +1612,6 @@ ast_expression::hir(exec_list *instructions,
if (var != NULL) {
var->used = true;
- type = result->type;
} else {
_mesa_glsl_error(& loc, state, "`%s' undeclared",
this->primary_expression.identifier);
@@ -1634,22 +1622,18 @@ ast_expression::hir(exec_list *instructions,
}
case ast_int_constant:
- type = glsl_type::int_type;
result = new(ctx) ir_constant(this->primary_expression.int_constant);
break;
case ast_uint_constant:
- type = glsl_type::uint_type;
result = new(ctx) ir_constant(this->primary_expression.uint_constant);
break;
case ast_float_constant:
- type = glsl_type::float_type;
result = new(ctx) ir_constant(this->primary_expression.float_constant);
break;
case ast_bool_constant:
- type = glsl_type::bool_type;
result = new(ctx) ir_constant(bool(this->primary_expression.bool_constant));
break;
@@ -1664,10 +1648,42 @@ ast_expression::hir(exec_list *instructions,
* therefore add instructions to the instruction list), they get dropped
* on the floor.
*/
- foreach_list_typed (ast_node, ast, link, &this->expressions)
- result = ast->hir(instructions, state);
+ exec_node *previous_tail_pred = NULL;
+ YYLTYPE previous_operand_loc = loc;
+
+ foreach_list_typed (ast_node, ast, link, &this->expressions) {
+ /* If one of the operands of comma operator does not generate any
+ * code, we want to emit a warning. At each pass through the loop
+ * previous_tail_pred will point to the last instruction in the
+ * stream *before* processing the previous operand. Naturally,
+ * instructions->tail_pred will point to the last instruction in the
+ * stream *after* processing the previous operand. If the two
+ * pointers match, then the previous operand had no effect.
+ *
+ * The warning behavior here differs slightly from GCC. GCC will
+ * only emit a warning if none of the left-hand operands have an
+ * effect. However, it will emit a warning for each. I believe that
+ * there are some cases in C (especially with GCC extensions) where
+ * it is useful to have an intermediate step in a sequence have no
+ * effect, but I don't think these cases exist in GLSL. Either way,
+ * it would be a giant hassle to replicate that behavior.
+ */
+ if (previous_tail_pred == instructions->tail_pred) {
+ _mesa_glsl_warning(&previous_operand_loc, state,
+ "left-hand operand of comma expression has "
+ "no effect");
+ }
+
+ /* tail_pred is directly accessed instead of using the get_tail()
+ * method for performance reasons. get_tail() has extra code to
+ * return NULL when the list is empty. We don't care about that
+ * here, so using tail_pred directly is fine.
+ */
+ previous_tail_pred = instructions->tail_pred;
+ previous_operand_loc = ast->get_location();
- type = result->type;
+ result = ast->hir(instructions, state);
+ }
/* Any errors should have already been emitted in the loop above.
*/
@@ -1675,8 +1691,10 @@ ast_expression::hir(exec_list *instructions,
break;
}
}
+ type = NULL; /* use result->type, not type. */
+ assert(result != NULL);
- if (type->is_error() && !error_emitted)
+ if (result->type->is_error() && !error_emitted)
_mesa_glsl_error(& loc, state, "type mismatch");
return result;