Factor out assignment setup in ast_to_hir.
This commit is contained in:

committed by
Ian Romanick

parent
e65e12fdbc
commit
10a6852186
@@ -359,6 +359,33 @@ validate_assignment(const glsl_type *lhs_type, ir_rvalue *rhs)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ir_rvalue *
|
||||||
|
do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
|
||||||
|
ir_rvalue *lhs, ir_rvalue *rhs,
|
||||||
|
YYLTYPE lhs_loc)
|
||||||
|
{
|
||||||
|
bool error_emitted = (lhs->type->is_error() || rhs->type->is_error());
|
||||||
|
|
||||||
|
if (!error_emitted) {
|
||||||
|
/* FINISHME: This does not handle 'foo.bar.a.b.c[5].d = 5' */
|
||||||
|
if (!lhs->is_lvalue()) {
|
||||||
|
_mesa_glsl_error(& lhs_loc, state, "non-lvalue in assignment");
|
||||||
|
error_emitted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ir_rvalue *new_rhs = validate_assignment(lhs->type, rhs);
|
||||||
|
if (new_rhs == NULL) {
|
||||||
|
_mesa_glsl_error(& lhs_loc, state, "type mismatch");
|
||||||
|
} else {
|
||||||
|
rhs = new_rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
ir_instruction *tmp = new ir_assignment(lhs, rhs, NULL);
|
||||||
|
instructions->push_tail(tmp);
|
||||||
|
|
||||||
|
return rhs;
|
||||||
|
}
|
||||||
|
|
||||||
ir_rvalue *
|
ir_rvalue *
|
||||||
ast_node::hir(exec_list *instructions,
|
ast_node::hir(exec_list *instructions,
|
||||||
@@ -445,30 +472,10 @@ ast_expression::hir(exec_list *instructions,
|
|||||||
op[0] = this->subexpressions[0]->hir(instructions, state);
|
op[0] = this->subexpressions[0]->hir(instructions, state);
|
||||||
op[1] = this->subexpressions[1]->hir(instructions, state);
|
op[1] = this->subexpressions[1]->hir(instructions, state);
|
||||||
|
|
||||||
error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
|
result = do_assignment(instructions, state, op[0], op[1],
|
||||||
|
this->subexpressions[0]->get_location());
|
||||||
type = op[0]->type;
|
error_emitted = result->type->is_error();
|
||||||
if (!error_emitted) {
|
type = result->type;
|
||||||
YYLTYPE loc;
|
|
||||||
|
|
||||||
/* FINISHME: This does not handle 'foo.bar.a.b.c[5].d = 5' */
|
|
||||||
if (!op[0]->is_lvalue()) {
|
|
||||||
_mesa_glsl_error(& loc, state, "non-lvalue in assignment");
|
|
||||||
error_emitted = true;
|
|
||||||
type = glsl_type::error_type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ir_instruction *rhs = validate_assignment(op[0]->type, op[1]);
|
|
||||||
if (rhs == NULL) {
|
|
||||||
type = glsl_type::error_type;
|
|
||||||
rhs = op[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
ir_instruction *tmp = new ir_assignment(op[0], op[1], NULL);
|
|
||||||
instructions->push_tail(tmp);
|
|
||||||
|
|
||||||
result = op[0];
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,8 +582,6 @@ ast_expression::hir(exec_list *instructions,
|
|||||||
op[0] = this->subexpressions[0]->hir(instructions, state);
|
op[0] = this->subexpressions[0]->hir(instructions, state);
|
||||||
op[1] = this->subexpressions[1]->hir(instructions, state);
|
op[1] = this->subexpressions[1]->hir(instructions, state);
|
||||||
|
|
||||||
error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
|
|
||||||
|
|
||||||
type = arithmetic_result_type(op[0]->type, op[1]->type,
|
type = arithmetic_result_type(op[0]->type, op[1]->type,
|
||||||
(this->oper == ast_mul_assign),
|
(this->oper == ast_mul_assign),
|
||||||
state);
|
state);
|
||||||
@@ -584,37 +589,16 @@ ast_expression::hir(exec_list *instructions,
|
|||||||
ir_rvalue *temp_rhs = new ir_expression(operations[this->oper], type,
|
ir_rvalue *temp_rhs = new ir_expression(operations[this->oper], type,
|
||||||
op[0], op[1]);
|
op[0], op[1]);
|
||||||
|
|
||||||
/* FINISHME: This is copied from ast_assign above. It should
|
result = do_assignment(instructions, state, op[0], temp_rhs,
|
||||||
* FINISHME: probably be consolidated.
|
this->subexpressions[0]->get_location());
|
||||||
*/
|
type = result->type;
|
||||||
error_emitted = op[0]->type->is_error() || temp_rhs->type->is_error();
|
error_emitted = (op[0]->type->is_error());
|
||||||
|
|
||||||
type = op[0]->type;
|
|
||||||
if (!error_emitted) {
|
|
||||||
YYLTYPE loc;
|
|
||||||
|
|
||||||
if (!op[0]->is_lvalue()) {
|
|
||||||
_mesa_glsl_error(& loc, state, "non-lvalue in assignment");
|
|
||||||
error_emitted = true;
|
|
||||||
type = glsl_type::error_type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ir_rvalue *rhs = validate_assignment(op[0]->type, temp_rhs);
|
|
||||||
if (rhs == NULL) {
|
|
||||||
type = glsl_type::error_type;
|
|
||||||
rhs = temp_rhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
ir_instruction *tmp = new ir_assignment(op[0], rhs, NULL);
|
|
||||||
instructions->push_tail(tmp);
|
|
||||||
|
|
||||||
/* GLSL 1.10 does not allow array assignment. However, we don't have to
|
/* GLSL 1.10 does not allow array assignment. However, we don't have to
|
||||||
* explicitly test for this because none of the binary expression
|
* explicitly test for this because none of the binary expression
|
||||||
* operators allow array operands either.
|
* operators allow array operands either.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
result = op[0];
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user