Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 2 -- libs/vkd3d-shader/hlsl.h | 2 -- libs/vkd3d-shader/hlsl.y | 28 ++++++++++++++++++++++------ 3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index e78f05c3..2312b9d3 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -983,8 +983,6 @@ static const char *debug_expr_op(const struct hlsl_ir_expr *expr)
"sat",
- "pre++", - "pre--", "post++", "post--",
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 76734401..b64ce2d5 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -276,8 +276,6 @@ enum hlsl_ir_expr_op
HLSL_IR_UNOP_SAT,
- HLSL_IR_UNOP_PREINC, - HLSL_IR_UNOP_PREDEC, HLSL_IR_UNOP_POSTINC, HLSL_IR_UNOP_POSTDEC,
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index a9c9dd02..95a2ed69 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1348,6 +1348,22 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in return ©->node; }
+static bool add_increment(struct hlsl_ctx *ctx, struct list *instrs, bool decrement, struct vkd3d_shader_location loc) +{ + struct hlsl_ir_node *lhs = node_from_list(instrs); + struct hlsl_ir_constant *one; + + if (lhs->data_type->modifiers & HLSL_MODIFIER_CONST) + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_MODIFIES_CONST, + "Argument to pre%screment operator is const.", decrement ? "de" : "in"); + + if (!(one = hlsl_new_uint_constant(ctx, 1, loc))) + return false; + list_add_tail(instrs, &one->node.entry); + + return !!add_assignment(ctx, instrs, lhs, decrement ? ASSIGN_OP_SUB : ASSIGN_OP_ADD, &one->node); +} + static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, struct hlsl_ir_var *var, struct parse_initializer *initializer) { @@ -2785,21 +2801,21 @@ unary_expr: postfix_expr | OP_INC unary_expr { - if (node_from_list($2)->data_type->modifiers & HLSL_MODIFIER_CONST) + if (!add_increment(ctx, $2, false, @1)) { - hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_MODIFIES_CONST, "Statement modifies a const expression."); + hlsl_free_instr_list($2); YYABORT; } - $$ = append_unop($2, hlsl_new_unary_expr(HLSL_IR_UNOP_PREINC, node_from_list($2), @1)); + $$ = $2; } | OP_DEC unary_expr { - if (node_from_list($2)->data_type->modifiers & HLSL_MODIFIER_CONST) + if (!add_increment(ctx, $2, true, @1)) { - hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_MODIFIES_CONST, "Statement modifies a const expression."); + hlsl_free_instr_list($2); YYABORT; } - $$ = append_unop($2, hlsl_new_unary_expr(HLSL_IR_UNOP_PREDEC, node_from_list($2), @1)); + $$ = $2; } | unary_op unary_expr {