[PATCH vkd3d 3/5] vkd3d-shader: Lower postincrement and postdecrement to assignment operations at parse time.
Zebediah Figura
zfigura at codeweavers.com
Tue Mar 9 19:42:48 CST 2021
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
libs/vkd3d-shader/hlsl.c | 3 ---
libs/vkd3d-shader/hlsl.h | 3 ---
libs/vkd3d-shader/hlsl.y | 53 +++++++++++++++++++++++-----------------
3 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 2312b9d3..19c0e2e4 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -983,9 +983,6 @@ static const char *debug_expr_op(const struct hlsl_ir_expr *expr)
"sat",
- "post++",
- "post--",
-
"+",
"-",
"*",
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index b64ce2d5..5a2f6af1 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -276,9 +276,6 @@ enum hlsl_ir_expr_op
HLSL_IR_UNOP_SAT,
- HLSL_IR_UNOP_POSTINC,
- HLSL_IR_UNOP_POSTDEC,
-
HLSL_IR_BINOP_ADD,
HLSL_IR_BINOP_SUB,
HLSL_IR_BINOP_MUL,
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 95a2ed69..815aac9b 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1348,20 +1348,39 @@ 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)
+static bool add_increment(struct hlsl_ctx *ctx, struct list *instrs, bool decrement, bool post,
+ 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");
+ "Argument to %s%screment operator is const.", post ? "post" : "pre", 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);
+ if (!add_assignment(ctx, instrs, lhs, decrement ? ASSIGN_OP_SUB : ASSIGN_OP_ADD, &one->node))
+ return false;
+
+ if (post)
+ {
+ struct hlsl_ir_expr *copy;
+
+ /* Use a cast to the same type as a makeshift identity expression. */
+ if (!(copy = hlsl_new_cast(lhs, lhs->data_type, &lhs->loc)))
+ return false;
+ list_add_tail(instrs, ©->node.entry);
+
+ /* Post increment/decrement expressions are considered const. */
+ if (!(copy->node.data_type = hlsl_type_clone(ctx, copy->node.data_type, 0)))
+ return false;
+ copy->node.data_type->modifiers |= HLSL_MODIFIER_CONST;
+ }
+
+ return true;
}
static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, struct hlsl_ir_var *var,
@@ -2624,33 +2643,21 @@ postfix_expr:
primary_expr
| postfix_expr OP_INC
{
- struct hlsl_ir_node *inc;
-
- if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST)
+ if (!add_increment(ctx, $1, false, true, @2))
{
- hlsl_error(ctx, @2, VKD3D_SHADER_ERROR_HLSL_MODIFIES_CONST, "Statement modifies a const expression.");
+ hlsl_free_instr_list($1);
YYABORT;
}
- inc = hlsl_new_unary_expr(HLSL_IR_UNOP_POSTINC, node_from_list($1), @2);
- /* Post increment/decrement expressions are considered const */
- inc->data_type = hlsl_type_clone(ctx, inc->data_type, 0);
- inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
- $$ = append_unop($1, inc);
+ $$ = $1;
}
| postfix_expr OP_DEC
{
- struct hlsl_ir_node *inc;
-
- if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST)
+ if (!add_increment(ctx, $1, true, true, @2))
{
- hlsl_error(ctx, @2, VKD3D_SHADER_ERROR_HLSL_MODIFIES_CONST, "Statement modifies a const expression.");
+ hlsl_free_instr_list($1);
YYABORT;
}
- inc = hlsl_new_unary_expr(HLSL_IR_UNOP_POSTDEC, node_from_list($1), @2);
- /* Post increment/decrement expressions are considered const */
- inc->data_type = hlsl_type_clone(ctx, inc->data_type, 0);
- inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
- $$ = append_unop($1, inc);
+ $$ = $1;
}
| postfix_expr '.' any_identifier
{
@@ -2801,7 +2808,7 @@ unary_expr:
postfix_expr
| OP_INC unary_expr
{
- if (!add_increment(ctx, $2, false, @1))
+ if (!add_increment(ctx, $2, false, false, @1))
{
hlsl_free_instr_list($2);
YYABORT;
@@ -2810,7 +2817,7 @@ unary_expr:
}
| OP_DEC unary_expr
{
- if (!add_increment(ctx, $2, true, @1))
+ if (!add_increment(ctx, $2, true, false, @1))
{
hlsl_free_instr_list($2);
YYABORT;
--
2.30.1
More information about the wine-devel
mailing list