[PATCH vkd3d 3/5] vkd3d-shader: Lower postincrement and postdecrement to assignment operations at parse time.

Matteo Bruni matteo.mystral at gmail.com
Thu Mar 11 15:35:19 CST 2021


On Wed, Mar 10, 2021 at 2:43 AM Zebediah Figura <zfigura at codeweavers.com> wrote:
>
> 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.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 &copy->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;

Now that we have two places where we clone an expression result it
might make sense to factor it out to a tiny helper. Mostly for clarity
(obvious function name -> no need to add a comment every time) and in
case in the future we decide to handle it differently.



More information about the wine-devel mailing list