d3dcompiler: Add hlsl_report_message function to standardize error messages.
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h
index ccac936..aa02eb9 100644
--- a/dlls/d3dcompiler_43/d3dcompiler_private.h
+++ b/dlls/d3dcompiler_43/d3dcompiler_private.h
@@ -840,7 +840,16 @@
extern struct hlsl_parse_ctx hlsl_ctx DECLSPEC_HIDDEN;
+enum hlsl_error_level
+{
+ HLSL_LEVEL_ERROR = 0,
+ HLSL_LEVEL_WARNING,
+ HLSL_LEVEL_NOTE,
+};
+
void hlsl_message(const char *fmt, ...) PRINTF_ATTR(1,2) DECLSPEC_HIDDEN;
+void hlsl_report_message(const char *filename, DWORD line, DWORD column,
+ enum hlsl_error_level level, const char *fmt, ...) PRINTF_ATTR(5,6) DECLSPEC_HIDDEN;
static inline struct hlsl_ir_deref *deref_from_node(const struct hlsl_ir_node *node)
{
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index 03aa4eb..240eaaf 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -41,10 +41,61 @@
va_end(args);
}
+static const char *hlsl_get_error_level_name(enum hlsl_error_level level)
+{
+ const char *names[] =
+ {
+ "error",
+ "warning",
+ "note",
+ };
+ return names[level];
+}
+
+void hlsl_report_message(const char *filename, DWORD line, DWORD column,
+ enum hlsl_error_level level, const char *fmt, ...)
+{
+ va_list args;
+ char *string = NULL;
+ int rc, size = 0;
+
+ while (1)
+ {
+ va_start(args, fmt);
+ rc = vsnprintf(string, size, fmt, args);
+ va_end(args);
+
+ if (rc >= 0 && rc < size)
+ break;
+
+ if (rc >= size)
+ size = rc + 1;
+ else
+ size = size ? size * 2 : 32;
+
+ if (!string)
+ string = d3dcompiler_alloc(size);
+ else
+ string = d3dcompiler_realloc(string, size);
+ if (!string)
+ {
+ ERR("Error reallocating memory for a string.\n");
+ return;
+ }
+ }
+
+ hlsl_message("%s:%u:%u: %s: %s\n", filename, line, column, hlsl_get_error_level_name(level), string);
+ d3dcompiler_free(string);
+
+ if (level == HLSL_LEVEL_ERROR)
+ set_parse_status(&hlsl_ctx.status, PARSE_ERR);
+ else if (level == HLSL_LEVEL_WARNING)
+ set_parse_status(&hlsl_ctx.status, PARSE_WARN);
+}
+
static void hlsl_error(const char *s)
{
- hlsl_message("Line %u: %s\n", hlsl_ctx.line_no, s);
- set_parse_status(&hlsl_ctx.status, PARSE_ERR);
+ hlsl_report_message(hlsl_ctx.source_file, hlsl_ctx.line_no, 1, HLSL_LEVEL_ERROR, "%s", s);
}
static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char *declname, unsigned int line_no)