Zebediah Figura : vkd3d-shader: Lower preincrement and predecrement to assignment operations at parse time.
Alexandre Julliard
julliard at winehq.org
Mon Mar 15 16:58:42 CDT 2021
Module: vkd3d
Branch: master
Commit: 1cd208fb32ccf928873db8a3517f131fb49ec583
URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=1cd208fb32ccf928873db8a3517f131fb49ec583
Author: Zebediah Figura <zfigura at codeweavers.com>
Date: Tue Mar 9 19:42:47 2021 -0600
vkd3d-shader: Lower preincrement and predecrement to assignment operations at parse time.
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
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 e78f05c..2312b9d 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 7673440..b64ce2d 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 a9c9dd0..95a2ed6 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
{
More information about the wine-cvs
mailing list