Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.l | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index b1090844..7e1fe14d 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -65,8 +65,8 @@ ANY (.) {RESERVED4} { struct hlsl_ctx *ctx = yyget_extra(yyscanner);
- hlsl_message("Line %u: Reserved keyword "%s" used.\n", ctx->line_no, yytext); - set_parse_status(&ctx->status, PARSE_ERR); + hlsl_report_message(ctx, *yylloc, HLSL_LEVEL_ERROR, + "Reserved keyword "%s" used.\n", yytext); }
BlendState {return KW_BLENDSTATE; }
So as to differentiate their API from our internal functions.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.l | 16 ++++++++-------- libs/vkd3d-shader/hlsl.y | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index 7e1fe14d..d9fd43d0 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -24,10 +24,10 @@ #include "hlsl.h" #include "hlsl.tab.h"
-#define YYSTYPE HLSL_STYPE -#define YYLTYPE HLSL_LTYPE +#define YYSTYPE HLSL_YYSTYPE +#define YYLTYPE HLSL_YYLTYPE
-static void update_location(struct hlsl_ctx *ctx, HLSL_LTYPE *loc); +static void update_location(struct hlsl_ctx *ctx, YYLTYPE *loc);
#define YY_USER_ACTION update_location(yyget_extra(yyscanner), yyget_lloc(yyscanner));
@@ -40,7 +40,7 @@ static void update_location(struct hlsl_ctx *ctx, HLSL_LTYPE *loc); %option noinput %option nounput %option noyywrap -%option prefix="hlsl_" +%option prefix="hlsl_yy" %option reentrant
%x pp pp_line pp_pragma pp_ignore @@ -278,7 +278,7 @@ row_major {return KW_ROW_MAJOR; }
%%
-static void update_location(struct hlsl_ctx *ctx, HLSL_LTYPE *lloc) +static void update_location(struct hlsl_ctx *ctx, YYLTYPE *lloc) { lloc->file = ctx->source_file; lloc->col = ctx->column; @@ -292,12 +292,12 @@ int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entry int ret;
yylex_init_extra(ctx, &ctx->scanner); - buffer = hlsl__scan_string(text, ctx->scanner); - hlsl__switch_to_buffer(buffer, ctx->scanner); + buffer = yy_scan_string(text, ctx->scanner); + yy_switch_to_buffer(buffer, ctx->scanner);
ret = hlsl_parser_compile(ctx, entrypoint);
- hlsl__delete_buffer(buffer, ctx->scanner); + yy_delete_buffer(buffer, ctx->scanner); yylex_destroy(ctx->scanner); return ret; } diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8fc7f825..f0280fcf 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -26,7 +26,7 @@ #include "hlsl.h" #include <stdio.h>
-#define HLSL_LTYPE struct source_location +#define HLSL_YYLTYPE struct source_location
struct parse_parameter { @@ -102,7 +102,7 @@ enum parse_assign_op %code provides {
-int hlsl_lex(HLSL_STYPE *yylval_param, HLSL_LTYPE *yylloc_param, void *yyscanner); +int yylex(HLSL_YYSTYPE *yylval_param, HLSL_YYLTYPE *yylloc_param, void *yyscanner);
}
@@ -1496,7 +1496,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
%locations %define parse.error verbose -%define api.prefix {hlsl_} +%define api.prefix {hlsl_yy} %define api.pure full %expect 1 %lex-param {yyscan_t scanner}
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 23 +++++-- libs/vkd3d-shader/hlsl.h | 9 ++- libs/vkd3d-shader/hlsl.l | 3 +- libs/vkd3d-shader/hlsl.y | 142 +++++++++++++++++++-------------------- 4 files changed, 93 insertions(+), 84 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 2b830a57..992e7062 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -25,15 +25,26 @@ void hlsl_message(const char *fmt, ...) /* FIXME */ }
-void hlsl_report_message(struct hlsl_ctx *ctx, const struct source_location loc, - enum hlsl_error_level level, const char *fmt, ...) +void hlsl_note(struct hlsl_ctx *ctx, const struct source_location loc, + enum vkd3d_shader_log_level level, const char *fmt, ...) { /* FIXME */
- if (level == HLSL_LEVEL_ERROR) - set_parse_status(&ctx->status, PARSE_ERR); - else if (level == HLSL_LEVEL_WARNING) - set_parse_status(&ctx->status, PARSE_WARN); + set_parse_status(&ctx->status, PARSE_WARN); +} + +void hlsl_error(struct hlsl_ctx *ctx, const struct source_location loc, const char *fmt, ...) +{ + /* FIXME */ + + set_parse_status(&ctx->status, PARSE_ERR); +} + +void hlsl_warning(struct hlsl_ctx *ctx, const struct source_location loc, const char *fmt, ...) +{ + /* FIXME */ + + set_parse_status(&ctx->status, PARSE_WARN); }
bool hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local_var) diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index d48ce79f..30c0215c 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -568,8 +568,13 @@ struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct source_location loc) DECLSPEC_HIDDEN;
void hlsl_message(const char *fmt, ...) VKD3D_PRINTF_FUNC(1,2) DECLSPEC_HIDDEN; -void hlsl_report_message(struct hlsl_ctx *ctx, const struct source_location loc, - enum hlsl_error_level level, const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5) DECLSPEC_HIDDEN; + +void hlsl_error(struct hlsl_ctx *ctx, const struct source_location loc, + const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4) DECLSPEC_HIDDEN; +void hlsl_warning(struct hlsl_ctx *ctx, const struct source_location loc, + const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4) DECLSPEC_HIDDEN; +void hlsl_note(struct hlsl_ctx *ctx, const struct source_location loc, enum vkd3d_shader_log_level level, + const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5) DECLSPEC_HIDDEN;
void hlsl_push_scope(struct hlsl_ctx *ctx) DECLSPEC_HIDDEN; void hlsl_pop_scope(struct hlsl_ctx *ctx) DECLSPEC_HIDDEN; diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index d9fd43d0..7a3737ac 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -65,8 +65,7 @@ ANY (.) {RESERVED4} { struct hlsl_ctx *ctx = yyget_extra(yyscanner);
- hlsl_report_message(ctx, *yylloc, HLSL_LEVEL_ERROR, - "Reserved keyword "%s" used.\n", yytext); + hlsl_error(ctx, *yylloc, "Reserved keyword "%s" used.\n", yytext); }
BlendState {return KW_BLENDSTATE; } diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index f0280fcf..d37f029e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -113,7 +113,7 @@ int yylex(HLSL_YYSTYPE *yylval_param, HLSL_YYLTYPE *yylloc_param, void *yyscanne
static void yyerror(YYLTYPE *loc, void *scanner, struct hlsl_ctx *ctx, const char *s) { - hlsl_report_message(ctx, *loc, HLSL_LEVEL_ERROR, "%s", s); + hlsl_error(ctx, *loc, "%s", s); }
static struct hlsl_ir_node *node_from_list(struct list *list) @@ -132,8 +132,7 @@ static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char static void check_invalid_matrix_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, struct source_location loc) { if (modifiers & HLSL_MODIFIERS_MAJORITY_MASK) - hlsl_report_message(ctx, loc, HLSL_LEVEL_ERROR, - "'row_major' or 'column_major' modifiers are only allowed for matrices."); + hlsl_error(ctx, loc, "'row_major' or 'column_major' modifiers are only allowed for matrices."); }
static bool convertible_data_type(struct hlsl_type *type) @@ -263,13 +262,13 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct
if (!implicit_compatible_data_types(src_type, dst_type)) { - hlsl_report_message(ctx, *loc, HLSL_LEVEL_ERROR, "can't implicitly convert %s to %s", + hlsl_error(ctx, *loc, "can't implicitly convert %s to %s", debug_hlsl_type(src_type), debug_hlsl_type(dst_type)); return NULL; }
if (dst_type->dimx * dst_type->dimy < src_type->dimx * src_type->dimy) - hlsl_report_message(ctx, *loc, HLSL_LEVEL_WARNING, "implicit truncation of vector type"); + hlsl_warning(ctx, *loc, "implicit truncation of vector type");
TRACE("Implicit conversion from %s to %s.\n", debug_hlsl_type(src_type), debug_hlsl_type(dst_type));
@@ -294,13 +293,11 @@ static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, boo
if (invalid) { - hlsl_report_message(ctx, decl->loc, HLSL_LEVEL_ERROR, - "modifier '%s' invalid for local variables", hlsl_debug_modifiers(invalid)); + hlsl_error(ctx, decl->loc, "modifier '%s' invalid for local variables", hlsl_debug_modifiers(invalid)); } if (decl->semantic) { - hlsl_report_message(ctx, decl->loc, HLSL_LEVEL_ERROR, - "semantics are not allowed on local variables"); + hlsl_error(ctx, decl->loc, "semantics are not allowed on local variables"); return false; } } @@ -308,7 +305,7 @@ static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, boo { if (hlsl_get_function(ctx, decl->name)) { - hlsl_report_message(ctx, decl->loc, HLSL_LEVEL_ERROR, "redefinition of '%s'", decl->name); + hlsl_error(ctx, decl->loc, "redefinition of '%s'", decl->name); return false; } } @@ -317,8 +314,8 @@ static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, boo { struct hlsl_ir_var *old = hlsl_get_var(ctx->cur_scope, decl->name);
- hlsl_report_message(ctx, decl->loc, HLSL_LEVEL_ERROR, ""%s" already declared", decl->name); - hlsl_report_message(ctx, old->loc, HLSL_LEVEL_NOTE, ""%s" was previously declared here", old->name); + hlsl_error(ctx, decl->loc, ""%s" already declared", decl->name); + hlsl_note(ctx, old->loc, VKD3D_SHADER_LOG_ERROR, ""%s" was previously declared here", old->name); return false; } return true; @@ -328,12 +325,12 @@ static DWORD add_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, DWORD mod, con { if (modifiers & mod) { - hlsl_report_message(ctx, loc, HLSL_LEVEL_ERROR, "modifier '%s' already specified", hlsl_debug_modifiers(mod)); + hlsl_error(ctx, loc, "modifier '%s' already specified", hlsl_debug_modifiers(mod)); return modifiers; } if ((mod & HLSL_MODIFIERS_MAJORITY_MASK) && (modifiers & HLSL_MODIFIERS_MAJORITY_MASK)) { - hlsl_report_message(ctx, loc, HLSL_LEVEL_ERROR, "more than one matrix majority keyword"); + hlsl_error(ctx, loc, "more than one matrix majority keyword"); return modifiers; } return modifiers | mod; @@ -542,7 +539,7 @@ static struct hlsl_ir_jump *add_return(struct hlsl_ctx *ctx, struct list *instrs } else if (!hlsl_type_is_void(return_type)) { - hlsl_report_message(ctx, loc, HLSL_LEVEL_ERROR, "non-void function must return a value"); + hlsl_error(ctx, loc, "non-void function must return a value"); return NULL; }
@@ -636,9 +633,9 @@ static struct hlsl_ir_load *add_array_load(struct hlsl_ctx *ctx, struct list *in else { if (expr_type->type == HLSL_CLASS_SCALAR) - hlsl_report_message(ctx, loc, HLSL_LEVEL_ERROR, "array-indexed expression is scalar"); + hlsl_error(ctx, loc, "array-indexed expression is scalar"); else - hlsl_report_message(ctx, loc, HLSL_LEVEL_ERROR, "expression is not array-indexable"); + hlsl_error(ctx, loc, "expression is not array-indexable"); return NULL; }
@@ -739,7 +736,7 @@ static struct list *gen_struct_fields(struct hlsl_ctx *ctx, struct hlsl_type *ty field->semantic = v->semantic; if (v->initializer.args_count) { - hlsl_report_message(ctx, v->loc, HLSL_LEVEL_ERROR, "struct field with an initializer.\n"); + hlsl_error(ctx, v->loc, "struct field with an initializer.\n"); free_parse_initializer(&v->initializer); } list_add_tail(list, &field->entry); @@ -774,11 +771,11 @@ static bool add_typedef(struct hlsl_ctx *ctx, DWORD modifiers, struct hlsl_type
if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR) && (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)) - hlsl_report_message(ctx, v->loc, HLSL_LEVEL_ERROR, "more than one matrix majority keyword"); + hlsl_error(ctx, v->loc, "more than one matrix majority keyword");
ret = hlsl_scope_add_type(ctx->cur_scope, type); if (!ret) - hlsl_report_message(ctx, v->loc, HLSL_LEVEL_ERROR, + hlsl_error(ctx, v->loc, "redefinition of custom type '%s'", v->name); vkd3d_free(v); } @@ -1014,7 +1011,7 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type
if (t1->type > HLSL_CLASS_LAST_NUMERIC || t2->type > HLSL_CLASS_LAST_NUMERIC) { - hlsl_report_message(ctx, *loc, HLSL_LEVEL_ERROR, "non scalar/vector/matrix data type in expression"); + hlsl_error(ctx, *loc, "non scalar/vector/matrix data type in expression"); return NULL; }
@@ -1023,7 +1020,7 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type
if (!expr_compatible_data_types(t1, t2)) { - hlsl_report_message(ctx, *loc, HLSL_LEVEL_ERROR, "expression data types are incompatible"); + hlsl_error(ctx, *loc, "expression data types are incompatible"); return NULL; }
@@ -1128,7 +1125,7 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, if (operands[i]->data_type->dimx * operands[i]->data_type->dimy != 1 && operands[i]->data_type->dimx * operands[i]->data_type->dimy != type->dimx * type->dimy) { - hlsl_report_message(ctx, operands[i]->loc, HLSL_LEVEL_WARNING, "implicit truncation of vector/matrix type"); + hlsl_warning(ctx, operands[i]->loc, "implicit truncation of vector/matrix type"); }
if (!(cast = hlsl_new_cast(operands[i], type, &operands[i]->loc))) @@ -1267,7 +1264,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in hlsl_src_from_node(&swizzle->val, rhs); if (!invert_swizzle(&swizzle->swizzle, &writemask, &width)) { - hlsl_report_message(ctx, lhs->loc, HLSL_LEVEL_ERROR, "invalid writemask"); + hlsl_error(ctx, lhs->loc, "invalid writemask"); vkd3d_free(assign); return NULL; } @@ -1278,7 +1275,7 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in } else { - hlsl_report_message(ctx, lhs->loc, HLSL_LEVEL_ERROR, "invalid lvalue"); + hlsl_error(ctx, lhs->loc, "invalid lvalue"); vkd3d_free(assign); return NULL; } @@ -1315,7 +1312,7 @@ static void struct_var_initializer(struct hlsl_ctx *ctx, struct list *list, stru
if (initializer_size(initializer) != hlsl_type_component_count(type)) { - hlsl_report_message(ctx, var->loc, HLSL_LEVEL_ERROR, "structure initializer mismatch"); + hlsl_error(ctx, var->loc, "structure initializer mismatch"); free_parse_initializer(initializer); return; } @@ -1404,7 +1401,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
if (type->modifiers & HLSL_MODIFIER_CONST && !(var->modifiers & HLSL_STORAGE_UNIFORM) && !v->initializer.args_count) { - hlsl_report_message(ctx, v->loc, HLSL_LEVEL_ERROR, "const variable without initializer"); + hlsl_error(ctx, v->loc, "const variable without initializer"); hlsl_free_var(var); vkd3d_free(v); continue; @@ -1430,7 +1427,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t { if (size < type->dimx * type->dimy) { - hlsl_report_message(ctx, v->loc, HLSL_LEVEL_ERROR, + hlsl_error(ctx, v->loc, "'%s' initializer does not match", v->name); free_parse_initializer(&v->initializer); vkd3d_free(v); @@ -1440,7 +1437,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY) && hlsl_type_component_count(type) != size) { - hlsl_report_message(ctx, v->loc, HLSL_LEVEL_ERROR, + hlsl_error(ctx, v->loc, "'%s' initializer does not match", v->name); free_parse_initializer(&v->initializer); vkd3d_free(v); @@ -1720,16 +1717,16 @@ hlsl_prog: { if (decl->body && $2.decl->body) { - hlsl_report_message(ctx, $2.decl->loc, HLSL_LEVEL_ERROR, + hlsl_error(ctx, $2.decl->loc, "redefinition of function %s", debugstr_a($2.name)); YYABORT; } else if (!hlsl_type_compare(decl->return_type, $2.decl->return_type)) { - hlsl_report_message(ctx, $2.decl->loc, HLSL_LEVEL_ERROR, + hlsl_error(ctx, $2.decl->loc, "redefining function %s with a different return type", debugstr_a($2.name)); - hlsl_report_message(ctx, decl->loc, HLSL_LEVEL_NOTE, + hlsl_note(ctx, decl->loc, VKD3D_SHADER_LOG_ERROR, "%s previously declared here", debugstr_a($2.name)); YYABORT; @@ -1738,7 +1735,7 @@ hlsl_prog:
if (hlsl_type_is_void($2.decl->return_type) && $2.decl->semantic) { - hlsl_report_message(ctx, $2.decl->loc, HLSL_LEVEL_ERROR, + hlsl_error(ctx, $2.decl->loc, "void function with a semantic"); }
@@ -1792,12 +1789,12 @@ struct_declaration: { if (!$2->name) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @2, "anonymous struct declaration with no variables"); } if (modifiers) { - hlsl_report_message(ctx, @1, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @1, "modifier not allowed on struct type declaration"); } } @@ -1821,14 +1818,14 @@ named_struct_spec:
if (hlsl_get_var(ctx->cur_scope, $2)) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, "redefinition of '%s'", $2); + hlsl_error(ctx, @2, "redefinition of '%s'", $2); YYABORT; }
ret = hlsl_scope_add_type(ctx->cur_scope, $$); if (!ret) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, "redefinition of struct '%s'", $2); + hlsl_error(ctx, @2, "redefinition of struct '%s'", $2); YYABORT; } } @@ -1862,8 +1859,7 @@ fields_list: ret = add_struct_field($$, field); if (ret == false) { - hlsl_report_message(ctx, @2, - HLSL_LEVEL_ERROR, "redefinition of '%s'", field->name); + hlsl_error(ctx, @2, "redefinition of '%s'", field->name); vkd3d_free(field); } } @@ -1906,18 +1902,17 @@ func_prototype: { if ($1) { - hlsl_report_message(ctx, @1, HLSL_LEVEL_ERROR, - "unexpected modifiers on a function"); + hlsl_error(ctx, @1, "unexpected modifiers on a function"); YYABORT; } if (hlsl_get_var(ctx->globals, $3)) { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, "redefinition of '%s'\n", $3); + hlsl_error(ctx, @3, "redefinition of '%s'\n", $3); YYABORT; } if (hlsl_type_is_void($2) && $7.semantic) { - hlsl_report_message(ctx, @7, HLSL_LEVEL_ERROR, "void function with a semantic"); + hlsl_error(ctx, @7, "void function with a semantic"); }
if ($7.reg_reservation) @@ -2020,7 +2015,7 @@ param_list: $$ = $1; if (!add_func_parameter(ctx, $$, &$3, @3)) { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, "duplicate parameter %s", $3.name); + hlsl_error(ctx, @3, "duplicate parameter %s", $3.name); YYABORT; } } @@ -2051,7 +2046,7 @@ input_mods: { if ($1 & $2) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @2, "duplicate input-output modifiers"); YYABORT; } @@ -2081,13 +2076,13 @@ type: { if ($3->type != HLSL_CLASS_SCALAR) { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @3, "vectors of non-scalar types are not allowed\n"); YYABORT; } if ($5 < 1 || $5 > 4) { - hlsl_report_message(ctx, @5, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @5, "vector size must be between 1 and 4\n"); YYABORT; } @@ -2098,19 +2093,19 @@ type: { if ($3->type != HLSL_CLASS_SCALAR) { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @3, "matrices of non-scalar types are not allowed\n"); YYABORT; } if ($5 < 1 || $5 > 4) { - hlsl_report_message(ctx, @5, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @5, "matrix row count must be between 1 and 4\n"); YYABORT; } if ($7 < 1 || $7 > 4) { - hlsl_report_message(ctx, @7, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @7, "matrix column count must be between 1 and 4\n"); YYABORT; } @@ -2152,7 +2147,7 @@ base_type: { $$ = hlsl_get_type(ctx->cur_scope, $2, true); if ($$->type != HLSL_CLASS_STRUCT) - hlsl_report_message(ctx, @1, HLSL_LEVEL_ERROR, "'%s' redefined as a structure\n", $2); + hlsl_error(ctx, @1, "'%s' redefined as a structure\n", $2); vkd3d_free($2); }
@@ -2176,7 +2171,7 @@ typedef: if ($2 & ~HLSL_TYPE_MODIFIERS_MASK) { struct parse_variable_def *v, *v_next; - hlsl_report_message(ctx, @1, HLSL_LEVEL_ERROR, "modifier not allowed on typedefs"); + hlsl_error(ctx, @1, "modifier not allowed on typedefs"); LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $4, struct parse_variable_def, entry) vkd3d_free(v); vkd3d_free($4); @@ -2274,7 +2269,7 @@ array:
if (!size) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @2, "array size is not a positive integer constant\n"); YYABORT; } @@ -2282,7 +2277,7 @@ array:
if (size > 65536) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @2, "array size must be between 1 and 65536"); YYABORT; } @@ -2435,7 +2430,7 @@ selection_statement: vkd3d_free($5.then_instrs); vkd3d_free($5.else_instrs); if (condition->data_type->dimx > 1 || condition->data_type->dimy > 1) - hlsl_report_message(ctx, instr->node.loc, HLSL_LEVEL_ERROR, + hlsl_error(ctx, instr->node.loc, "if condition requires a scalar"); $$ = $3; list_add_tail($$, &instr->node.entry); @@ -2470,8 +2465,7 @@ loop_statement: | KW_FOR '(' scope_start declaration expr_statement expr ')' statement { if (!$4) - hlsl_report_message(ctx, @4, HLSL_LEVEL_WARNING, - "no expressions in for loop initializer"); + hlsl_warning(ctx, @4, "no expressions in for loop initializer"); $$ = create_loop(LOOP_FOR, $4, $5, $6, $8, @1); hlsl_pop_scope(ctx); } @@ -2528,7 +2522,7 @@ primary_expr:
if (!(var = hlsl_get_var(ctx->cur_scope, $1))) { - hlsl_report_message(ctx, @1, HLSL_LEVEL_ERROR, "variable '%s' is not declared\n", $1); + hlsl_error(ctx, @1, "variable '%s' is not declared\n", $1); YYABORT; } if ((load = hlsl_new_var_load(var, @1))) @@ -2552,7 +2546,7 @@ postfix_expr:
if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, "modifying a const expression"); + hlsl_error(ctx, @2, "modifying a const expression"); YYABORT; } inc = hlsl_new_unary_expr(HLSL_IR_UNOP_POSTINC, node_from_list($1), @2); @@ -2567,7 +2561,7 @@ postfix_expr:
if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, "modifying a const expression"); + hlsl_error(ctx, @2, "modifying a const expression"); YYABORT; } inc = hlsl_new_unary_expr(HLSL_IR_UNOP_POSTDEC, node_from_list($1), @2); @@ -2598,7 +2592,7 @@ postfix_expr: } if (!$$) { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, "invalid subscript %s", debugstr_a($3)); + hlsl_error(ctx, @3, "invalid subscript %s", debugstr_a($3)); YYABORT; } } @@ -2608,14 +2602,14 @@ postfix_expr:
if (!(swizzle = get_swizzle(ctx, node, $3, &@3))) { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, "invalid swizzle %s", debugstr_a($3)); + hlsl_error(ctx, @3, "invalid swizzle %s", debugstr_a($3)); YYABORT; } $$ = append_unop($1, &swizzle->node); } else { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, "invalid subscript %s", debugstr_a($3)); + hlsl_error(ctx, @3, "invalid subscript %s", debugstr_a($3)); YYABORT; } } @@ -2628,7 +2622,7 @@ postfix_expr:
if (index->data_type->type != HLSL_CLASS_SCALAR) { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, "array index is not scalar"); + hlsl_error(ctx, @3, "array index is not scalar"); hlsl_free_instr_list($1); YYABORT; } @@ -2653,19 +2647,19 @@ postfix_expr:
if ($1) { - hlsl_report_message(ctx, @1, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @1, "unexpected modifier on a constructor\n"); YYABORT; } if ($2->type > HLSL_CLASS_LAST_NUMERIC) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @2, "constructors may only be used with numeric data types\n"); YYABORT; } if ($2->dimx * $2->dimy != initializer_size(&$4)) { - hlsl_report_message(ctx, @4, HLSL_LEVEL_ERROR, + hlsl_error(ctx, @4, "expected %u components in constructor, but got %u\n", $2->dimx * $2->dimy, initializer_size(&$4)); YYABORT; @@ -2684,7 +2678,7 @@ postfix_expr:
if (arg->data_type->type == HLSL_CLASS_OBJECT) { - hlsl_report_message(ctx, arg->loc, HLSL_LEVEL_ERROR, "invalid constructor argument"); + hlsl_error(ctx, arg->loc, "invalid constructor argument"); continue; } width = hlsl_type_component_count(arg->data_type); @@ -2717,7 +2711,7 @@ unary_expr: { if (node_from_list($2)->data_type->modifiers & HLSL_MODIFIER_CONST) { - hlsl_report_message(ctx, @1, HLSL_LEVEL_ERROR, "modifying a const expression"); + hlsl_error(ctx, @1, "modifying a const expression"); YYABORT; } $$ = append_unop($2, hlsl_new_unary_expr(HLSL_IR_UNOP_PREINC, node_from_list($2), @1)); @@ -2726,7 +2720,7 @@ unary_expr: { if (node_from_list($2)->data_type->modifiers & HLSL_MODIFIER_CONST) { - hlsl_report_message(ctx, @1, HLSL_LEVEL_ERROR, "modifying a const expression"); + hlsl_error(ctx, @1, "modifying a const expression"); YYABORT; } $$ = append_unop($2, hlsl_new_unary_expr(HLSL_IR_UNOP_PREDEC, node_from_list($2), @1)); @@ -2750,7 +2744,7 @@ unary_expr:
if ($2) { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, "unexpected modifier in a cast"); + hlsl_error(ctx, @3, "unexpected modifier in a cast"); YYABORT; }
@@ -2761,7 +2755,7 @@ unary_expr:
if (!compatible_data_types(src_type, dst_type)) { - hlsl_report_message(ctx, @3, HLSL_LEVEL_ERROR, "can't cast from %s to %s", + hlsl_error(ctx, @3, "can't cast from %s to %s", debug_hlsl_type(src_type), debug_hlsl_type(dst_type)); YYABORT; } @@ -2905,7 +2899,7 @@ assignment_expr:
if (lhs->data_type->modifiers & HLSL_MODIFIER_CONST) { - hlsl_report_message(ctx, @2, HLSL_LEVEL_ERROR, "l-value is const"); + hlsl_error(ctx, @2, "l-value is const"); YYABORT; } list_move_tail($3, $1); @@ -3129,7 +3123,7 @@ int hlsl_parser_compile(struct hlsl_ctx *ctx, const char *entrypoint) if (!hlsl_type_is_void(entry_func->return_type) && entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic) { - hlsl_report_message(ctx, entry_func->loc, HLSL_LEVEL_ERROR, + hlsl_error(ctx, entry_func->loc, "entry point "%s" is missing a return value semantic", entry_func->func->name); }
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
On Wed, Feb 10, 2021 at 10:43 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 23 +++++-- libs/vkd3d-shader/hlsl.h | 9 ++- libs/vkd3d-shader/hlsl.l | 3 +- libs/vkd3d-shader/hlsl.y | 142 +++++++++++++++++++-------------------- 4 files changed, 93 insertions(+), 84 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 2b830a57..992e7062 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -25,15 +25,26 @@ void hlsl_message(const char *fmt, ...) /* FIXME */ }
-void hlsl_report_message(struct hlsl_ctx *ctx, const struct source_location loc,
enum hlsl_error_level level, const char *fmt, ...)
+void hlsl_note(struct hlsl_ctx *ctx, const struct source_location loc,
enum vkd3d_shader_log_level level, const char *fmt, ...)
{ /* FIXME */
- if (level == HLSL_LEVEL_ERROR)
set_parse_status(&ctx->status, PARSE_ERR);
- else if (level == HLSL_LEVEL_WARNING)
set_parse_status(&ctx->status, PARSE_WARN);
- set_parse_status(&ctx->status, PARSE_WARN);
+}
Just for the records, it seems a bit surprising for hlsl_note() to set the error status.
On 2/12/21 10:40 AM, Matteo Bruni wrote:
On Wed, Feb 10, 2021 at 10:43 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 23 +++++-- libs/vkd3d-shader/hlsl.h | 9 ++- libs/vkd3d-shader/hlsl.l | 3 +- libs/vkd3d-shader/hlsl.y | 142 +++++++++++++++++++-------------------- 4 files changed, 93 insertions(+), 84 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 2b830a57..992e7062 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -25,15 +25,26 @@ void hlsl_message(const char *fmt, ...) /* FIXME */ }
-void hlsl_report_message(struct hlsl_ctx *ctx, const struct source_location loc,
enum hlsl_error_level level, const char *fmt, ...)
+void hlsl_note(struct hlsl_ctx *ctx, const struct source_location loc,
enum vkd3d_shader_log_level level, const char *fmt, ...)
{ /* FIXME */
- if (level == HLSL_LEVEL_ERROR)
set_parse_status(&ctx->status, PARSE_ERR);
- else if (level == HLSL_LEVEL_WARNING)
set_parse_status(&ctx->status, PARSE_WARN);
- set_parse_status(&ctx->status, PARSE_WARN);
+}
Just for the records, it seems a bit surprising for hlsl_note() to set the error status.
Yes, that seems to be a copy/paste error. I'll send a v2...
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 28 ++++++++++++++------------- libs/vkd3d-shader/hlsl.h | 41 +++++++++++++++++----------------------- libs/vkd3d-shader/hlsl.l | 4 ++-- libs/vkd3d-shader/hlsl.y | 32 +++++++++++++++---------------- 4 files changed, 50 insertions(+), 55 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 992e7062..6f19cbb3 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -25,7 +25,7 @@ void hlsl_message(const char *fmt, ...) /* FIXME */ }
-void hlsl_note(struct hlsl_ctx *ctx, const struct source_location loc, +void hlsl_note(struct hlsl_ctx *ctx, const struct vkd3d_shader_location loc, enum vkd3d_shader_log_level level, const char *fmt, ...) { /* FIXME */ @@ -33,14 +33,14 @@ void hlsl_note(struct hlsl_ctx *ctx, const struct source_location loc, set_parse_status(&ctx->status, PARSE_WARN); }
-void hlsl_error(struct hlsl_ctx *ctx, const struct source_location loc, const char *fmt, ...) +void hlsl_error(struct hlsl_ctx *ctx, const struct vkd3d_shader_location loc, const char *fmt, ...) { /* FIXME */
set_parse_status(&ctx->status, PARSE_ERR); }
-void hlsl_warning(struct hlsl_ctx *ctx, const struct source_location loc, const char *fmt, ...) +void hlsl_warning(struct hlsl_ctx *ctx, const struct vkd3d_shader_location loc, const char *fmt, ...) { /* FIXME */
@@ -350,7 +350,7 @@ bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type) }
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, - struct source_location *loc) + struct vkd3d_shader_location *loc) { struct hlsl_ir_node *cast;
@@ -360,7 +360,7 @@ struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ir_node *node, struct hlsl_type * return hlsl_ir_expr(cast); }
-struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct source_location loc, +struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc, const char *semantic, unsigned int modifiers, const struct hlsl_reg_reservation *reg_reservation) { struct hlsl_ir_var *var; @@ -378,7 +378,7 @@ struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const }
struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, - const struct source_location loc) + const struct vkd3d_shader_location loc) { struct hlsl_ir_var *var = hlsl_new_var(vkd3d_strdup(name), type, loc, NULL, 0, NULL);
@@ -393,7 +393,7 @@ static bool type_is_single_reg(const struct hlsl_type *type) }
struct hlsl_ir_assignment *hlsl_new_assignment(struct hlsl_ir_var *var, struct hlsl_ir_node *offset, - struct hlsl_ir_node *rhs, unsigned int writemask, struct source_location loc) + struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc) { struct hlsl_ir_assignment *assign;
@@ -416,7 +416,8 @@ struct hlsl_ir_assignment *hlsl_new_simple_assignment(struct hlsl_ir_var *lhs, s return hlsl_new_assignment(lhs, NULL, rhs, 0, rhs->loc); }
-struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct source_location loc) +struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, + const struct vkd3d_shader_location loc) { struct hlsl_ir_constant *c;
@@ -427,7 +428,8 @@ struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned i return c; }
-struct hlsl_ir_node *hlsl_new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, struct source_location loc) +struct hlsl_ir_node *hlsl_new_unary_expr(enum hlsl_ir_expr_op op, + struct hlsl_ir_node *arg, struct vkd3d_shader_location loc) { struct hlsl_ir_expr *expr;
@@ -454,7 +456,7 @@ struct hlsl_ir_node *hlsl_new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_i return &expr->node; }
-struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct source_location loc) +struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct vkd3d_shader_location loc) { struct hlsl_ir_if *iff;
@@ -467,7 +469,7 @@ struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct source_loc return iff; }
-struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct source_location loc) +struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct vkd3d_shader_location loc) { struct hlsl_ir_load *load;
@@ -479,7 +481,7 @@ struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct sou }
struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components, - struct hlsl_ir_node *val, struct source_location *loc) + struct hlsl_ir_node *val, struct vkd3d_shader_location *loc) { struct hlsl_ir_swizzle *swizzle;
@@ -498,7 +500,7 @@ bool hlsl_type_is_void(const struct hlsl_type *type) }
struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type, - struct list *parameters, const char *semantic, struct source_location loc) + struct list *parameters, const char *semantic, struct vkd3d_shader_location loc) { struct hlsl_ir_function_decl *decl;
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 30c0215c..59bf3140 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -144,13 +144,6 @@ struct hlsl_struct_field unsigned int reg_offset; };
-struct source_location -{ - const char *file; - unsigned int line; - unsigned int col; -}; - enum hlsl_ir_node_type { HLSL_IR_ASSIGNMENT = 0, @@ -171,7 +164,7 @@ struct hlsl_ir_node
struct list uses;
- struct source_location loc; + struct vkd3d_shader_location loc;
/* Liveness ranges. "index" is the index of this instruction. Since this is * essentially an SSA value, the earliest live point is the index. This is @@ -215,7 +208,7 @@ struct hlsl_reg_reservation struct hlsl_ir_var { struct hlsl_type *data_type; - struct source_location loc; + struct vkd3d_shader_location loc; const char *name; const char *semantic; unsigned int modifiers; @@ -237,7 +230,7 @@ struct hlsl_ir_function_decl { struct hlsl_type *return_type; struct hlsl_ir_var *return_var; - struct source_location loc; + struct vkd3d_shader_location loc; struct rb_entry entry; struct hlsl_ir_function *func; const char *semantic; @@ -487,7 +480,7 @@ static inline struct hlsl_ir_swizzle *hlsl_ir_swizzle(const struct hlsl_ir_node }
static inline void init_node(struct hlsl_ir_node *node, enum hlsl_ir_node_type type, - struct hlsl_type *data_type, struct source_location loc) + struct hlsl_type *data_type, struct vkd3d_shader_location loc) { memset(node, 0, sizeof(*node)); node->type = type; @@ -541,39 +534,39 @@ struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name) DEC struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN; struct hlsl_ir_assignment *hlsl_new_assignment(struct hlsl_ir_var *var, struct hlsl_ir_node *offset, - struct hlsl_ir_node *rhs, unsigned int writemask, struct source_location loc) DECLSPEC_HIDDEN; + struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN; struct hlsl_ir_node *hlsl_new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2) DECLSPEC_HIDDEN; struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, - struct source_location *loc) DECLSPEC_HIDDEN; + struct vkd3d_shader_location *loc) DECLSPEC_HIDDEN; struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type, - struct list *parameters, const char *semantic, struct source_location loc) DECLSPEC_HIDDEN; -struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct source_location loc) DECLSPEC_HIDDEN; + struct list *parameters, const char *semantic, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN; +struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN; struct hlsl_ir_assignment *hlsl_new_simple_assignment(struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs) DECLSPEC_HIDDEN; struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, struct list *fields) DECLSPEC_HIDDEN; struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components, - struct hlsl_ir_node *val, struct source_location *loc) DECLSPEC_HIDDEN; + struct hlsl_ir_node *val, struct vkd3d_shader_location *loc) DECLSPEC_HIDDEN; struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, - const struct source_location loc) DECLSPEC_HIDDEN; + const struct vkd3d_shader_location loc) DECLSPEC_HIDDEN; struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class, enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN; struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, - const struct source_location loc) DECLSPEC_HIDDEN; + const struct vkd3d_shader_location loc) DECLSPEC_HIDDEN; struct hlsl_ir_node *hlsl_new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, - struct source_location loc) DECLSPEC_HIDDEN; -struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct source_location loc, + struct vkd3d_shader_location loc) DECLSPEC_HIDDEN; +struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc, const char *semantic, unsigned int modifiers, const struct hlsl_reg_reservation *reg_reservation) DECLSPEC_HIDDEN; -struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct source_location loc) DECLSPEC_HIDDEN; +struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
void hlsl_message(const char *fmt, ...) VKD3D_PRINTF_FUNC(1,2) DECLSPEC_HIDDEN;
-void hlsl_error(struct hlsl_ctx *ctx, const struct source_location loc, +void hlsl_error(struct hlsl_ctx *ctx, const struct vkd3d_shader_location loc, const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4) DECLSPEC_HIDDEN; -void hlsl_warning(struct hlsl_ctx *ctx, const struct source_location loc, +void hlsl_warning(struct hlsl_ctx *ctx, const struct vkd3d_shader_location loc, const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4) DECLSPEC_HIDDEN; -void hlsl_note(struct hlsl_ctx *ctx, const struct source_location loc, enum vkd3d_shader_log_level level, +void hlsl_note(struct hlsl_ctx *ctx, const struct vkd3d_shader_location loc, enum vkd3d_shader_log_level level, const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5) DECLSPEC_HIDDEN;
void hlsl_push_scope(struct hlsl_ctx *ctx) DECLSPEC_HIDDEN; diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index 7a3737ac..38b4bf1f 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -279,9 +279,9 @@ row_major {return KW_ROW_MAJOR; }
static void update_location(struct hlsl_ctx *ctx, YYLTYPE *lloc) { - lloc->file = ctx->source_file; - lloc->col = ctx->column; + lloc->source_name = ctx->source_file; lloc->line = ctx->line_no; + lloc->column = ctx->column; ctx->column += yyget_leng(ctx->scanner); }
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index d37f029e..15c9c9cd 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -26,7 +26,7 @@ #include "hlsl.h" #include <stdio.h>
-#define HLSL_YYLTYPE struct source_location +#define HLSL_YYLTYPE struct vkd3d_shader_location
struct parse_parameter { @@ -53,7 +53,7 @@ struct parse_initializer struct parse_variable_def { struct list entry; - struct source_location loc; + struct vkd3d_shader_location loc;
char *name; uint32_t array_size; @@ -129,7 +129,7 @@ static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char TRACE("%s %s;\n", debug_hlsl_type(type), declname); }
-static void check_invalid_matrix_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, struct source_location loc) +static void check_invalid_matrix_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, struct vkd3d_shader_location loc) { if (modifiers & HLSL_MODIFIERS_MAJORITY_MASK) hlsl_error(ctx, loc, "'row_major' or 'column_major' modifiers are only allowed for matrices."); @@ -252,7 +252,7 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ }
static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct list *instrs, - struct hlsl_ir_node *node, struct hlsl_type *dst_type, struct source_location *loc) + struct hlsl_ir_node *node, struct hlsl_type *dst_type, struct vkd3d_shader_location *loc) { struct hlsl_type *src_type = node->data_type; struct hlsl_ir_expr *cast; @@ -321,7 +321,7 @@ static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, boo return true; }
-static DWORD add_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, DWORD mod, const struct source_location loc) +static DWORD add_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, DWORD mod, const struct vkd3d_shader_location loc) { if (modifiers & mod) { @@ -371,7 +371,7 @@ enum loop_type };
static struct list *create_loop(enum loop_type type, struct list *init, struct list *cond, - struct list *iter, struct list *body, struct source_location loc) + struct list *iter, struct list *body, struct vkd3d_shader_location loc) { struct list *list = NULL; struct hlsl_ir_loop *loop = NULL; @@ -439,7 +439,7 @@ static void free_parse_initializer(struct parse_initializer *initializer) }
static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ctx *ctx, struct hlsl_ir_node *value, const char *swizzle, - struct source_location *loc) + struct vkd3d_shader_location *loc) { unsigned int len = strlen(swizzle), component = 0; unsigned int i, set, swiz = 0; @@ -521,7 +521,7 @@ static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ctx *ctx, struct hlsl_ir_ }
static struct hlsl_ir_jump *add_return(struct hlsl_ctx *ctx, struct list *instrs, - struct hlsl_ir_node *return_value, struct source_location loc) + struct hlsl_ir_node *return_value, struct vkd3d_shader_location loc) { struct hlsl_type *return_type = ctx->cur_function->return_type; struct hlsl_ir_jump *jump; @@ -553,7 +553,7 @@ static struct hlsl_ir_jump *add_return(struct hlsl_ctx *ctx, struct list *instrs }
static struct hlsl_ir_load *add_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node, - struct hlsl_ir_node *offset, struct hlsl_type *data_type, const struct source_location loc) + struct hlsl_ir_node *offset, struct hlsl_type *data_type, const struct vkd3d_shader_location loc) { struct hlsl_ir_node *add = NULL; struct hlsl_ir_load *load; @@ -599,7 +599,7 @@ static struct hlsl_ir_load *add_load(struct hlsl_ctx *ctx, struct list *instrs, }
static struct hlsl_ir_load *add_record_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *record, - const struct hlsl_struct_field *field, const struct source_location loc) + const struct hlsl_struct_field *field, const struct vkd3d_shader_location loc) { struct hlsl_ir_constant *c;
@@ -611,7 +611,7 @@ static struct hlsl_ir_load *add_record_load(struct hlsl_ctx *ctx, struct list *i }
static struct hlsl_ir_load *add_array_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *array, - struct hlsl_ir_node *index, const struct source_location loc) + struct hlsl_ir_node *index, const struct vkd3d_shader_location loc) { const struct hlsl_type *expr_type = array->data_type; struct hlsl_type *data_type; @@ -671,7 +671,7 @@ bool hlsl_type_is_row_major(const struct hlsl_type *type) }
static struct hlsl_type *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_type *type, - unsigned int *modifiers, struct source_location loc) + unsigned int *modifiers, struct vkd3d_shader_location loc) { unsigned int default_majority = 0; struct hlsl_type *new_type; @@ -784,7 +784,7 @@ static bool add_typedef(struct hlsl_ctx *ctx, DWORD modifiers, struct hlsl_type }
static bool add_func_parameter(struct hlsl_ctx *ctx, struct list *list, - struct parse_parameter *param, const struct source_location loc) + struct parse_parameter *param, const struct vkd3d_shader_location loc) { struct hlsl_ir_var *var;
@@ -1003,7 +1003,7 @@ static enum hlsl_base_type expr_common_base_type(enum hlsl_base_type t1, enum hl }
static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type *t1, struct hlsl_type *t2, - struct source_location *loc) + struct vkd3d_shader_location *loc) { enum hlsl_type_class type; enum hlsl_base_type base; @@ -1098,7 +1098,7 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type }
static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs, - enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[3], struct source_location *loc) + enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[3], struct vkd3d_shader_location *loc) { struct hlsl_ir_expr *expr; struct hlsl_type *type; @@ -1152,7 +1152,7 @@ static struct list *append_unop(struct list *list, struct hlsl_ir_node *node) }
static struct list *add_binary_expr(struct hlsl_ctx *ctx, struct list *list1, struct list *list2, - enum hlsl_ir_expr_op op, struct source_location loc) + enum hlsl_ir_expr_op op, struct vkd3d_shader_location loc) { struct hlsl_ir_node *args[3] = {node_from_list(list1), node_from_list(list2)};
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 11 +++++------ libs/vkd3d-shader/hlsl.h | 4 +--- libs/vkd3d-shader/hlsl.l | 12 +++++------- libs/vkd3d-shader/hlsl.y | 6 +++--- 4 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6f19cbb3..2db9e85e 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1484,16 +1484,15 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, struct vkd3d_shader_message_cont
ctx->message_context = message_context;
- ctx->line_no = ctx->column = 1; - if (!(ctx->source_file = vkd3d_strdup(""))) - return false; if (!(ctx->source_files = vkd3d_malloc(sizeof(*ctx->source_files)))) + return false; + if (!(ctx->source_files[0] = vkd3d_strdup(""))) { - vkd3d_free((void *)ctx->source_file); + vkd3d_free(ctx->source_files); return false; } - ctx->source_files[0] = ctx->source_file; - ctx->source_files_count = 1; + ctx->location.source_name = ctx->source_files[0]; + ctx->location.line = ctx->location.column = 1;
ctx->matrix_majority = HLSL_COLUMN_MAJOR;
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 59bf3140..067aae86 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -395,9 +395,7 @@ struct hlsl_ctx { const char **source_files; unsigned int source_files_count; - const char *source_file; - unsigned int line_no; - unsigned int column; + struct vkd3d_shader_location location; enum parse_status status; struct vkd3d_shader_message_context *message_context;
diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index 38b4bf1f..a0e0beda 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -209,8 +209,8 @@ row_major {return KW_ROW_MAJOR; } {NEWLINE} { struct hlsl_ctx *ctx = yyget_extra(yyscanner);
- ctx->line_no++; - ctx->column = 1; + ++ctx->location.line; + ctx->location.column = 1; }
^# { @@ -238,7 +238,7 @@ row_major {return KW_ROW_MAJOR; } <pp_pragma>{NEWLINE} { struct hlsl_ctx *ctx = yyget_extra(yyscanner);
- FIXME("Unsupported preprocessor #pragma directive at line %u.\n", ctx->line_no); + FIXME("Unsupported preprocessor #pragma directive at line %u.\n", ctx->location.line); BEGIN(INITIAL); } <pp_pragma>{ANY} {} @@ -279,10 +279,8 @@ row_major {return KW_ROW_MAJOR; }
static void update_location(struct hlsl_ctx *ctx, YYLTYPE *lloc) { - lloc->source_name = ctx->source_file; - lloc->line = ctx->line_no; - lloc->column = ctx->column; - ctx->column += yyget_leng(ctx->scanner); + *lloc = ctx->location; + ctx->location.column += yyget_leng(ctx->scanner); }
int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entrypoint) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 15c9c9cd..d7201f58 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1762,8 +1762,8 @@ preproc_directive: const char **new_array = NULL;
TRACE("Updating line information to file %s, line %u.\n", debugstr_a($2), $1); - ctx->line_no = $1; - if (strcmp($2, ctx->source_file)) + ctx->location.line = $1; + if (strcmp($2, ctx->location.source_name)) new_array = vkd3d_realloc(ctx->source_files, sizeof(*ctx->source_files) * (ctx->source_files_count + 1));
@@ -1771,7 +1771,7 @@ preproc_directive: { ctx->source_files = new_array; ctx->source_files[ctx->source_files_count++] = $2; - ctx->source_file = $2; + ctx->location.source_name = $2; } else {
On Wed, Feb 10, 2021 at 10:43 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 11 +++++------ libs/vkd3d-shader/hlsl.h | 4 +--- libs/vkd3d-shader/hlsl.l | 12 +++++------- libs/vkd3d-shader/hlsl.y | 6 +++--- 4 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6f19cbb3..2db9e85e 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1484,16 +1484,15 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, struct vkd3d_shader_message_cont
ctx->message_context = message_context;
- ctx->line_no = ctx->column = 1;
- if (!(ctx->source_file = vkd3d_strdup("")))
if (!(ctx->source_files = vkd3d_malloc(sizeof(*ctx->source_files))))return false;
return false;
- if (!(ctx->source_files[0] = vkd3d_strdup(""))) {
vkd3d_free((void *)ctx->source_file);
}vkd3d_free(ctx->source_files); return false;
- ctx->source_files[0] = ctx->source_file;
- ctx->source_files_count = 1;
ctx->location.source_name = ctx->source_files[0];
ctx->location.line = ctx->location.column = 1;
ctx->matrix_majority = HLSL_COLUMN_MAJOR;
This doesn't initialize source_files_count to 1 anymore, isn't that still necessary?
On 2/12/21 10:40 AM, Matteo Bruni wrote:
On Wed, Feb 10, 2021 at 10:43 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 11 +++++------ libs/vkd3d-shader/hlsl.h | 4 +--- libs/vkd3d-shader/hlsl.l | 12 +++++------- libs/vkd3d-shader/hlsl.y | 6 +++--- 4 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6f19cbb3..2db9e85e 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1484,16 +1484,15 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, struct vkd3d_shader_message_cont
ctx->message_context = message_context;
- ctx->line_no = ctx->column = 1;
- if (!(ctx->source_file = vkd3d_strdup("")))
if (!(ctx->source_files = vkd3d_malloc(sizeof(*ctx->source_files))))return false;
return false;
- if (!(ctx->source_files[0] = vkd3d_strdup(""))) {
vkd3d_free((void *)ctx->source_file);
}vkd3d_free(ctx->source_files); return false;
- ctx->source_files[0] = ctx->source_file;
- ctx->source_files_count = 1;
ctx->location.source_name = ctx->source_files[0];
ctx->location.line = ctx->location.column = 1;
ctx->matrix_majority = HLSL_COLUMN_MAJOR;
This doesn't initialize source_files_count to 1 anymore, isn't that still necessary?
That is an error; thanks for catching it.