[PATCH vkd3d v4 4/6] vkd3d-shader/hlsl: Parse bitwise AND.

Francisco Casas fcasas at codeweavers.com
Fri Jan 28 12:51:19 CST 2022


Signed-off-by: Francisco Casas <fcasas at codeweavers.com>

Seems good to me, just one detail:

January 28, 2022 5:03 AM, "Giovanni Mascellani" <gmascellani at codeweavers.com> wrote:

> Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
> ---
> v2:
> * Emit error messages.
> ---
> libs/vkd3d-shader/hlsl.y | 45 +++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 44 insertions(+), 1 deletion(-)
> 
> diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
> index 9476765f..13268617 100644
> --- a/libs/vkd3d-shader/hlsl.y
> +++ b/libs/vkd3d-shader/hlsl.y
> @@ -1057,6 +1057,49 @@ static struct list *add_binary_arithmetic_expr_merge(struct hlsl_ctx *ctx,
> struc
> return list1;
> }
> 
> +static struct hlsl_ir_expr *add_binary_bitwise_expr(struct hlsl_ctx *ctx, struct list *instrs,
> + enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
> + const struct vkd3d_shader_location *loc)
> +{
> + if (arg1->data_type->base_type == HLSL_TYPE_HALF || arg1->data_type->base_type ==
> HLSL_TYPE_FLOAT)
> + {

For now doubles aren't parsed but this maybe should also throw error on HLSL_TYPE_DOUBLE
to be future proof.
In that case it may be better to write the contrapositive:

---
if (arg1->data_type->base_type != HLSL_TYPE_INT && arg1->data_type->base_type != HLSL_TYPE_UINT &&
  arg1->data_type->base_type != HLSL_TYPE_BOOL)
---

> + struct vkd3d_string_buffer *type_str = hlsl_type_to_string(ctx, arg1->data_type);
> +
> + if (type_str)
> + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
> + "The first argument has type '%s', which is not integer.",
> + type_str->buffer);
> + hlsl_release_string_buffer(ctx, type_str);
> + return NULL;
> + }
> +
> + if (arg2->data_type->base_type == HLSL_TYPE_HALF || arg2->data_type->base_type ==
> HLSL_TYPE_FLOAT)

Same here.

> + {
> + struct vkd3d_string_buffer *type_str = hlsl_type_to_string(ctx, arg2->data_type);
> +
> + if (type_str)
> + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
> + "The second argument has type '%s', which is not integer.",
> + type_str->buffer);
> + hlsl_release_string_buffer(ctx, type_str);
> + return NULL;
> + }
> +
> + return add_binary_arithmetic_expr(ctx, instrs, op, arg1, arg2, loc);
> +}
> +
> +static struct list *add_binary_bitwise_expr_merge(struct hlsl_ctx *ctx, struct list *list1, struct
> list *list2,
> + enum hlsl_ir_expr_op op, const struct vkd3d_shader_location *loc)
> +{
> + struct hlsl_ir_node *arg1 = node_from_list(list1), *arg2 = node_from_list(list2);
> +
> + list_move_tail(list1, list2);
> + vkd3d_free(list2);
> + add_binary_bitwise_expr(ctx, list1, op, arg1, arg2, loc);
> +
> + return list1;
> +}
> +
> static struct hlsl_ir_expr *add_binary_comparison_expr(struct hlsl_ctx *ctx, struct list *instrs,
> enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
> struct vkd3d_shader_location *loc)
> @@ -3554,7 +3597,7 @@ bitand_expr:
> equality_expr
> | bitand_expr '&' equality_expr
> {
> - hlsl_fixme(ctx, &@$, "Bitwise AND.");
> + $$ = add_binary_bitwise_expr_merge(ctx, $1, $3, HLSL_OP2_BIT_AND, &@2);
> }
> 
> bitxor_expr:
> -- 
> 2.34.1



More information about the wine-devel mailing list