From: Nikolay Sivov nsivov@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 20 +++++++++++++++++++- libs/vkd3d-shader/hlsl.h | 3 +++ libs/vkd3d-shader/hlsl.l | 7 ++++++- libs/vkd3d-shader/hlsl.y | 16 +++++++++++++++- 4 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index a436e910..02c62a47 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -978,7 +978,8 @@ struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_typ { struct hlsl_ir_constant *c;
- assert(type->type <= HLSL_CLASS_VECTOR); + assert(type->type <= HLSL_CLASS_VECTOR + || (type->type == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_STRING));
if (!(c = hlsl_alloc(ctx, sizeof(*c)))) return NULL; @@ -1035,6 +1036,19 @@ struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned i return c; }
+struct hlsl_ir_constant *hlsl_new_string_constant(struct hlsl_ctx *ctx, const char *s, + const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_constant *c; + + c = hlsl_new_constant(ctx, hlsl_get_type(ctx->globals, "string", false), loc); + + if (c) + c->value[0].s = s; + + return c; +} + struct hlsl_ir_node *hlsl_new_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], struct hlsl_type *data_type, const struct vkd3d_shader_location *loc) @@ -2060,6 +2074,10 @@ static void dump_ir_constant(struct vkd3d_string_buffer *buffer, const struct hl vkd3d_string_buffer_printf(buffer, "%u ", value->u); break;
+ case HLSL_TYPE_STRING: + vkd3d_string_buffer_printf(buffer, "%s ", value->s); + break; + default: vkd3d_unreachable(); } diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 81b1a61d..b754a4c6 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -611,6 +611,7 @@ struct hlsl_ir_constant int32_t i; float f; double d; + const char *s; } value[4]; /* Constant register of type 'c' where the constant value is stored for SM1. */ struct hlsl_reg reg; @@ -1051,6 +1052,8 @@ struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, const struct hlsl_resource_load_params *params, const struct vkd3d_shader_location *loc); struct hlsl_ir_resource_store *hlsl_new_resource_store(struct hlsl_ctx *ctx, const struct hlsl_deref *resource, struct hlsl_ir_node *coords, struct hlsl_ir_node *value, const struct vkd3d_shader_location *loc); +struct hlsl_ir_constant *hlsl_new_string_constant(struct hlsl_ctx *ctx, const char *s, + const struct vkd3d_shader_location *loc); struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, struct hlsl_struct_field *fields, size_t field_count); struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components, diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index 69ed9d9d..00a33e8a 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -117,7 +117,6 @@ shared {return KW_SHARED; } stateblock {return KW_STATEBLOCK; } stateblock_state {return KW_STATEBLOCK_STATE; } static {return KW_STATIC; } -string {return KW_STRING; } struct {return KW_STRUCT; } switch {return KW_SWITCH; } tbuffer {return KW_TBUFFER; } @@ -212,6 +211,12 @@ row_major {return KW_ROW_MAJOR; } return C_INTEGER; }
+"([^\"]|\.)*" { + struct hlsl_ctx *ctx = yyget_extra(yyscanner); + yylval->strval = hlsl_strdup(ctx, yytext); + return C_STRING; + } + {DOUBLESLASHCOMMENT} {}
{WS}+ {} diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 76b0eae7..06fba41b 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3509,6 +3509,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl INT intval; FLOAT floatval; bool boolval; + char *strval; char *name; DWORD modifiers; struct hlsl_ir_node *instr; @@ -3580,7 +3581,6 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl %token KW_STATEBLOCK %token KW_STATEBLOCK_STATE %token KW_STATIC -%token KW_STRING %token KW_STRUCT %token KW_SWITCH %token KW_TBUFFER @@ -3636,6 +3636,8 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl %token <intval> C_INTEGER %token <intval> PRE_LINE
+%token <strval> C_STRING + %type <list> add_expr %type <list> assignment_expr %type <list> bitand_expr @@ -4952,6 +4954,18 @@ primary_expr: YYABORT; } } + | C_STRING + { + struct hlsl_ir_constant *c; + + if (!(c = hlsl_new_string_constant(ctx, $1, &@1))) + YYABORT; + if (!($$ = make_list(ctx, &c->node))) + { + hlsl_free_instr(&c->node); + YYABORT; + } + } | VAR_IDENTIFIER { struct hlsl_ir_load *load;