From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/hlsl.l | 18 +++++-- libs/vkd3d-shader/hlsl.y | 55 +++++++++++++++++----- tests/hlsl/initializer-numeric.shader_test | 4 +- 3 files changed, 59 insertions(+), 18 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index c35709903..401fba604 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -203,18 +203,30 @@ while {return KW_WHILE; } yylval->floatval = atof(yytext); return C_FLOAT; } -0x[0-9a-fA-F]+[uU]? { +0x[0-9a-fA-F]+[lL]? { yylval->intval = vkd3d_parse_integer(yytext); return C_INTEGER; } -0[0-7]+[uU]? { +0[0-7]+[lL]? { yylval->intval = vkd3d_parse_integer(yytext); return C_INTEGER; } -[0-9]+[uU]? { +[0-9]+[lL]? { yylval->intval = vkd3d_parse_integer(yytext); return C_INTEGER; } +0x[0-9a-fA-F]+([uU]|[uU][lL]|[lL][uU]) { + yylval->intval = vkd3d_parse_integer(yytext); + return C_UNSIGNED; + } +0[0-7]+([uU]|[uU][lL]|[lL][uU]) { + yylval->intval = vkd3d_parse_integer(yytext); + return C_UNSIGNED; + } +[0-9]+([uU]|[uU][lL]|[lL][uU]) { + yylval->intval = vkd3d_parse_integer(yytext); + return C_UNSIGNED; + }
{WS}+ {} {NEWLINE} { diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 5e0d48d3c..fb6520bc6 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -28,6 +28,12 @@
#define HLSL_YYLTYPE struct vkd3d_shader_location
+struct parse_integer +{ + uint32_t u; + bool is_unsigned; +}; + struct parse_fields { struct hlsl_struct_field *fields; @@ -4809,6 +4815,7 @@ static void check_duplicated_switch_cases(struct hlsl_ctx *ctx, const struct hls bool boolval; char *name; DWORD modifiers; + struct parse_integer integer; struct hlsl_ir_node *instr; struct hlsl_block *block; struct list *list; @@ -4939,6 +4946,7 @@ static void check_duplicated_switch_cases(struct hlsl_ctx *ctx, const struct hls %token <floatval> C_FLOAT
%token <intval> C_INTEGER +%token <intval> C_UNSIGNED %token <intval> PRE_LINE
%type <list> type_specs @@ -4991,6 +4999,7 @@ static void check_duplicated_switch_cases(struct hlsl_ctx *ctx, const struct hls %type <block> unary_expr
%type <boolval> boolean +%type <integer> integer
%type <buffer_type> buffer_type
@@ -5769,7 +5778,7 @@ uav_type: }
type_no_void: - KW_VECTOR '<' type ',' C_INTEGER '>' + KW_VECTOR '<' type ',' integer '>' { if ($3->class != HLSL_CLASS_SCALAR) { @@ -5782,21 +5791,21 @@ type_no_void: hlsl_release_string_buffer(ctx, string); YYABORT; } - if ($5 < 1 || $5 > 4) + if ($5.u < 1 || $5.u > 4) { hlsl_error(ctx, &@5, VKD3D_SHADER_ERROR_HLSL_INVALID_SIZE, - "Vector size %d is not between 1 and 4.", $5); + "Vector size %d is not between 1 and 4.", $5.u); YYABORT; }
- $$ = hlsl_type_clone(ctx, hlsl_get_vector_type(ctx, $3->base_type, $5), 0, 0); + $$ = hlsl_type_clone(ctx, hlsl_get_vector_type(ctx, $3->base_type, $5.u), 0, 0); $$->is_minimum_precision = $3->is_minimum_precision; } | KW_VECTOR { $$ = hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, 4); } - | KW_MATRIX '<' type ',' C_INTEGER ',' C_INTEGER '>' + | KW_MATRIX '<' type ',' integer ',' integer '>' { if ($3->class != HLSL_CLASS_SCALAR) { @@ -5809,20 +5818,20 @@ type_no_void: hlsl_release_string_buffer(ctx, string); YYABORT; } - if ($5 < 1 || $5 > 4) + if ($5.u < 1 || $5.u > 4) { hlsl_error(ctx, &@5, VKD3D_SHADER_ERROR_HLSL_INVALID_SIZE, - "Matrix row count %d is not between 1 and 4.", $5); + "Matrix row count %d is not between 1 and 4.", $5.u); YYABORT; } - if ($7 < 1 || $7 > 4) + if ($7.u < 1 || $7.u > 4) { hlsl_error(ctx, &@7, VKD3D_SHADER_ERROR_HLSL_INVALID_SIZE, - "Matrix column count %d is not between 1 and 4.", $7); + "Matrix column count %d is not between 1 and 4.", $7.u); YYABORT; }
- $$ = hlsl_type_clone(ctx, hlsl_get_matrix_type(ctx, $3->base_type, $7, $5), 0, 0); + $$ = hlsl_type_clone(ctx, hlsl_get_matrix_type(ctx, $3->base_type, $7.u, $5.u), 0, 0); $$->is_minimum_precision = $3->is_minimum_precision; } | KW_MATRIX @@ -6371,6 +6380,18 @@ boolean: $$ = false; }
+integer: + C_UNSIGNED + { + $$.u = $1; + $$.is_unsigned = true; + } + | C_INTEGER + { + $$.u = $1; + $$.is_unsigned = false; + } + statement_list: statement | statement_list statement @@ -6664,12 +6685,20 @@ primary_expr: if (!($$ = make_block(ctx, c))) YYABORT; } - | C_INTEGER + | integer { struct hlsl_ir_node *c;
- if (!(c = hlsl_new_int_constant(ctx, $1, &@1))) - YYABORT; + if ($1.is_unsigned) + { + if (!(c = hlsl_new_uint_constant(ctx, $1.u, &@1))) + YYABORT; + } + else + { + if (!(c = hlsl_new_int_constant(ctx, $1.u, &@1))) + YYABORT; + } if (!($$ = make_block(ctx, c))) YYABORT; } diff --git a/tests/hlsl/initializer-numeric.shader_test b/tests/hlsl/initializer-numeric.shader_test index 81d19d06c..617b67405 100644 --- a/tests/hlsl/initializer-numeric.shader_test +++ b/tests/hlsl/initializer-numeric.shader_test @@ -57,7 +57,7 @@ float4 main() : sv_target
[test] draw quad -todo(sm<6) probe all rgba (3.0, 250.0, 16.0, 4.2949673e+009) 4 +probe all rgba (3.0, 250.0, 16.0, 4.2949673e+009) 4
[require] @@ -73,4 +73,4 @@ float4 main() : sv_target
[test] draw quad -todo probe all rgba (-1294967296.0, 3000000000.0, 0.0, 0.0) 4 +probe all rgba (-1294967296.0, 3000000000.0, 0.0, 0.0) 4