Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 62 +++++++++++++----------- libs/vkd3d-shader/hlsl.h | 4 +- libs/vkd3d-shader/hlsl.y | 20 +++++--- libs/vkd3d-shader/vkd3d_shader_main.c | 60 +++++++++++++++++++++++ libs/vkd3d-shader/vkd3d_shader_private.h | 11 +++++ 5 files changed, 120 insertions(+), 37 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 52b3dd10..e2a77707 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -648,10 +648,10 @@ static int compare_function_decl_rb(const void *key, const struct rb_entry *entr return 0; }
-char *hlsl_type_to_string(const struct hlsl_type *type) +struct vkd3d_string_buffer *hlsl_type_to_string(struct vkd3d_string_buffer_cache *string_buffers, + const struct hlsl_type *type) { - const char *name; - char *string; + struct vkd3d_string_buffer *string;
static const char base_types[HLSL_TYPE_LAST_SCALAR + 1][7] = { @@ -663,66 +663,70 @@ char *hlsl_type_to_string(const struct hlsl_type *type) "bool", };
+ if (!(string = vkd3d_string_buffer_get(string_buffers))) + return NULL; + if (type->name) - return vkd3d_strdup(type->name); + { + vkd3d_string_buffer_printf(string, "%s", type->name); + return string; + }
switch (type->type) { case HLSL_CLASS_SCALAR: - return vkd3d_strdup(base_types[type->base_type]); + vkd3d_string_buffer_printf(string, "%s", base_types[type->base_type]); + return string;
case HLSL_CLASS_VECTOR: - name = base_types[type->base_type]; - if ((string = malloc(strlen(name) + 2))) - sprintf(string, "%s%u", name, type->dimx); + vkd3d_string_buffer_printf(string, "%s%u", base_types[type->base_type], type->dimx); return string;
case HLSL_CLASS_MATRIX: - name = base_types[type->base_type]; - if ((string = malloc(strlen(name) + 4))) - sprintf(string, "%s%ux%u", name, type->dimx, type->dimy); + vkd3d_string_buffer_printf(string, "%s%ux%u", base_types[type->base_type], type->dimx, type->dimy); return string;
case HLSL_CLASS_ARRAY: { + struct vkd3d_string_buffer *inner_string; const struct hlsl_type *t; - char *inner_string; - size_t len = 1;
for (t = type; t->type == HLSL_CLASS_ARRAY; t = t->e.array.type) - len += 14; - if (!(inner_string = hlsl_type_to_string(t))) - return NULL; - len += strlen(inner_string); + ;
- if ((string = malloc(len))) + if ((inner_string = hlsl_type_to_string(string_buffers, t))) { - strcpy(string, inner_string); - for (t = type; t->type == HLSL_CLASS_ARRAY; t = t->e.array.type) - sprintf(string + strlen(string), "[%u]", t->e.array.elements_count); + vkd3d_string_buffer_printf(string, "%s", inner_string->buffer); + vkd3d_string_buffer_release(string_buffers, inner_string); }
- vkd3d_free(inner_string); + for (t = type; t->type == HLSL_CLASS_ARRAY; t = t->e.array.type) + vkd3d_string_buffer_printf(string, "[%u]", t->e.array.elements_count); return string; }
case HLSL_CLASS_STRUCT: - return vkd3d_strdup("<anonymous struct>"); + vkd3d_string_buffer_printf(string, "<anonymous struct>"); + return string;
default: - return vkd3d_strdup("<unexpected type>"); + vkd3d_string_buffer_printf(string, "<unexpected type>"); + return string; } }
const char *debug_hlsl_type(const struct hlsl_type *type) { + struct vkd3d_string_buffer_cache string_buffers; + struct vkd3d_string_buffer *string; const char *ret; - char *string;
- if (!(string = hlsl_type_to_string(type))) + vkd3d_string_buffer_cache_init(&string_buffers); + if (!(string = hlsl_type_to_string(&string_buffers, type))) return NULL; - ret = vkd3d_dbg_sprintf("%s", string); - vkd3d_free(string); + ret = vkd3d_dbg_sprintf("%s", string->buffer); + vkd3d_string_buffer_release(&string_buffers, string); + vkd3d_string_buffer_cache_cleanup(&string_buffers); return ret; }
@@ -1526,6 +1530,7 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, struct vkd3d_shader_message_cont ctx->source_files_count = 1; ctx->location.source_name = ctx->source_files[0]; ctx->location.line = ctx->location.column = 1; + vkd3d_string_buffer_cache_init(&ctx->string_buffers);
ctx->matrix_majority = HLSL_COLUMN_MAJOR;
@@ -1553,6 +1558,7 @@ static void hlsl_ctx_cleanup(struct hlsl_ctx *ctx) for (i = 0; i < ctx->source_files_count; ++i) vkd3d_free((void *)ctx->source_files[i]); vkd3d_free(ctx->source_files); + vkd3d_string_buffer_cache_cleanup(&ctx->string_buffers);
rb_destroy(&ctx->functions, free_function_rb, NULL);
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index a374f54a..5a0470b9 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -390,6 +390,7 @@ struct hlsl_ctx unsigned int source_files_count; struct vkd3d_shader_location location; struct vkd3d_shader_message_context *message_context; + struct vkd3d_string_buffer_cache string_buffers; bool failed;
void *scanner; @@ -496,7 +497,8 @@ static inline void hlsl_src_remove(struct hlsl_src *src)
const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
-char *hlsl_type_to_string(const struct hlsl_type *type) DECLSPEC_HIDDEN; +struct vkd3d_string_buffer *hlsl_type_to_string(struct vkd3d_string_buffer_cache *string_buffers, + const struct hlsl_type *type) DECLSPEC_HIDDEN; char *hlsl_modifiers_to_string(unsigned int modifiers) DECLSPEC_HIDDEN; const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type) DECLSPEC_HIDDEN;
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index ea640b94..1fb1b7f3 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -255,13 +255,15 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct
if (!implicit_compatible_data_types(src_type, dst_type)) { - char *src_string = hlsl_type_to_string(src_type), *dst_string = hlsl_type_to_string(dst_type); + struct vkd3d_string_buffer *src_string, *dst_string;
+ src_string = hlsl_type_to_string(&ctx->string_buffers, src_type); + dst_string = hlsl_type_to_string(&ctx->string_buffers, dst_type); if (src_string && dst_string) hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, - "Can't implicitly convert from %s to %s.", src_string, dst_string); - vkd3d_free(src_string); - vkd3d_free(dst_string); + "Can't implicitly convert from %s to %s.", src_string->buffer, dst_string->buffer); + vkd3d_string_buffer_release(&ctx->string_buffers, src_string); + vkd3d_string_buffer_release(&ctx->string_buffers, dst_string); return NULL; }
@@ -2744,13 +2746,15 @@ unary_expr:
if (!compatible_data_types(src_type, dst_type)) { - char *src_string = hlsl_type_to_string(src_type), *dst_string = hlsl_type_to_string(dst_type); + struct vkd3d_string_buffer *src_string, *dst_string;
+ src_string = hlsl_type_to_string(&ctx->string_buffers, src_type); + dst_string = hlsl_type_to_string(&ctx->string_buffers, dst_type); if (src_string && dst_string) hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Can't cast from %s to %s.", - src_string, dst_string); - vkd3d_free(src_string); - vkd3d_free(dst_string); + src_string->buffer, dst_string->buffer); + vkd3d_string_buffer_release(&ctx->string_buffers, src_string); + vkd3d_string_buffer_release(&ctx->string_buffers, dst_string); YYABORT; }
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index bae2852a..51136243 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -33,6 +33,12 @@ void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer) vkd3d_free(buffer->buffer); }
+static void vkd3d_string_buffer_clear(struct vkd3d_string_buffer *buffer) +{ + buffer->buffer[0] = '\0'; + buffer->content_size = 0; +} + static bool vkd3d_string_buffer_resize(struct vkd3d_string_buffer *buffer, int rc) { unsigned int new_buffer_size = buffer->buffer_size * 2; @@ -107,6 +113,60 @@ void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const } }
+void vkd3d_string_buffer_cache_init(struct vkd3d_string_buffer_cache *cache) +{ + memset(cache, 0, sizeof(*cache)); +} + +void vkd3d_string_buffer_cache_cleanup(struct vkd3d_string_buffer_cache *cache) +{ + unsigned int i; + + for (i = 0; i < cache->count; ++i) + { + vkd3d_string_buffer_cleanup(cache->buffers[i]); + vkd3d_free(cache->buffers[i]); + } + vkd3d_free(cache->buffers); + vkd3d_string_buffer_cache_init(cache); +} + +struct vkd3d_string_buffer *vkd3d_string_buffer_get(struct vkd3d_string_buffer_cache *cache) +{ + struct vkd3d_string_buffer *buffer; + + if (!cache->count) + { + if (!vkd3d_array_reserve((void **)&cache->buffers, &cache->capacity, + cache->max_count + 1, sizeof(*cache->buffers))) + return NULL; + ++cache->max_count; + + if (!(buffer = vkd3d_malloc(sizeof(*buffer)))) + return NULL; + vkd3d_string_buffer_init(buffer); + if (!vkd3d_string_buffer_resize(buffer, 1)) + { + vkd3d_free(buffer); + return NULL; + } + } + else + { + buffer = cache->buffers[--cache->count]; + } + vkd3d_string_buffer_clear(buffer); + return buffer; +} + +void vkd3d_string_buffer_release(struct vkd3d_string_buffer_cache *cache, struct vkd3d_string_buffer *buffer) +{ + if (!buffer) + return; + assert(cache->count + 1 <= cache->max_count); + cache->buffers[cache->count++] = buffer; +} + void vkd3d_shader_message_context_init(struct vkd3d_shader_message_context *context, enum vkd3d_shader_log_level log_level) { diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index e837dbcd..cf66c67a 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -870,12 +870,23 @@ struct vkd3d_string_buffer unsigned int content_size; };
+struct vkd3d_string_buffer_cache +{ + struct vkd3d_string_buffer **buffers; + size_t count, max_count, capacity; +}; + enum vkd3d_result vkd3d_dxbc_binary_to_text(void *data, const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out) DECLSPEC_HIDDEN; void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN; +struct vkd3d_string_buffer *vkd3d_string_buffer_get(struct vkd3d_string_buffer_cache *list) DECLSPEC_HIDDEN; void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN; +void vkd3d_string_buffer_cache_cleanup(struct vkd3d_string_buffer_cache *list) DECLSPEC_HIDDEN; +void vkd3d_string_buffer_cache_init(struct vkd3d_string_buffer_cache *list) DECLSPEC_HIDDEN; int vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer, const char *format, ...) VKD3D_PRINTF_FUNC(2, 3) DECLSPEC_HIDDEN; +void vkd3d_string_buffer_release(struct vkd3d_string_buffer_cache *list, + struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN; #define vkd3d_string_buffer_trace(buffer) \ vkd3d_string_buffer_trace_(buffer, __FUNCTION__) void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function) DECLSPEC_HIDDEN;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 54 +++++++++++++++++++++------------------- libs/vkd3d-shader/hlsl.h | 3 ++- libs/vkd3d-shader/hlsl.y | 16 ++++++------ 3 files changed, 38 insertions(+), 35 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index e2a77707..fbbe001a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -730,46 +730,45 @@ const char *debug_hlsl_type(const struct hlsl_type *type) return ret; }
-char *hlsl_modifiers_to_string(unsigned int modifiers) +struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct vkd3d_string_buffer_cache *string_buffers, + unsigned int modifiers) { - char *string; - size_t len; + struct vkd3d_string_buffer *string;
- if (!(string = vkd3d_malloc(110))) + if (!(string = vkd3d_string_buffer_get(string_buffers))) return NULL;
- string[0] = 0; if (modifiers & HLSL_STORAGE_EXTERN) - strcat(string, "extern "); /* 7 */ + vkd3d_string_buffer_printf(string, "extern "); if (modifiers & HLSL_STORAGE_NOINTERPOLATION) - strcat(string, "nointerpolation "); /* 16 */ + vkd3d_string_buffer_printf(string, "nointerpolation "); if (modifiers & HLSL_MODIFIER_PRECISE) - strcat(string, "precise "); /* 8 */ + vkd3d_string_buffer_printf(string, "precise "); if (modifiers & HLSL_STORAGE_SHARED) - strcat(string, "shared "); /* 7 */ + vkd3d_string_buffer_printf(string, "shared "); if (modifiers & HLSL_STORAGE_GROUPSHARED) - strcat(string, "groupshared "); /* 12 */ + vkd3d_string_buffer_printf(string, "groupshared "); if (modifiers & HLSL_STORAGE_STATIC) - strcat(string, "static "); /* 7 */ + vkd3d_string_buffer_printf(string, "static "); if (modifiers & HLSL_STORAGE_UNIFORM) - strcat(string, "uniform "); /* 8 */ + vkd3d_string_buffer_printf(string, "uniform "); if (modifiers & HLSL_STORAGE_VOLATILE) - strcat(string, "volatile "); /* 9 */ + vkd3d_string_buffer_printf(string, "volatile "); if (modifiers & HLSL_MODIFIER_CONST) - strcat(string, "const "); /* 6 */ + vkd3d_string_buffer_printf(string, "const "); if (modifiers & HLSL_MODIFIER_ROW_MAJOR) - strcat(string, "row_major "); /* 10 */ + vkd3d_string_buffer_printf(string, "row_major "); if (modifiers & HLSL_MODIFIER_COLUMN_MAJOR) - strcat(string, "column_major "); /* 13 */ + vkd3d_string_buffer_printf(string, "column_major "); if ((modifiers & (HLSL_STORAGE_IN | HLSL_STORAGE_OUT)) == (HLSL_STORAGE_IN | HLSL_STORAGE_OUT)) - strcat(string, "inout "); /* 6 */ + vkd3d_string_buffer_printf(string, "inout "); else if (modifiers & HLSL_STORAGE_IN) - strcat(string, "in "); /* 3 */ + vkd3d_string_buffer_printf(string, "in "); else if (modifiers & HLSL_STORAGE_OUT) - strcat(string, "out "); /* 4 */ + vkd3d_string_buffer_printf(string, "out ");
- if ((len = strlen(string))) - string[len - 1] = 0; + if (string->content_size) + string->buffer[--string->content_size] = 0;
return string; } @@ -818,11 +817,14 @@ static void dump_ir_var(struct vkd3d_string_buffer *buffer, const struct hlsl_ir { if (var->modifiers) { - char *string; - - if ((string = hlsl_modifiers_to_string(var->modifiers))) - vkd3d_string_buffer_printf(buffer, "%s ", string); - vkd3d_free(string); + struct vkd3d_string_buffer_cache string_buffers; + struct vkd3d_string_buffer *string; + + vkd3d_string_buffer_cache_init(&string_buffers); + if ((string = hlsl_modifiers_to_string(&string_buffers, var->modifiers))) + vkd3d_string_buffer_printf(buffer, "%s ", string->buffer); + vkd3d_string_buffer_release(&string_buffers, string); + vkd3d_string_buffer_cache_cleanup(&string_buffers); } vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(var->data_type), var->name); if (var->semantic) diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 5a0470b9..8107b260 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -499,7 +499,8 @@ const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
struct vkd3d_string_buffer *hlsl_type_to_string(struct vkd3d_string_buffer_cache *string_buffers, const struct hlsl_type *type) DECLSPEC_HIDDEN; -char *hlsl_modifiers_to_string(unsigned int modifiers) DECLSPEC_HIDDEN; +struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct vkd3d_string_buffer_cache *string_buffers, + unsigned int modifiers) DECLSPEC_HIDDEN; const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type) DECLSPEC_HIDDEN;
void hlsl_add_function(struct rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 1fb1b7f3..dd15f627 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -291,12 +291,12 @@ static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, boo
if (invalid) { - char *string; + struct vkd3d_string_buffer *string;
- if ((string = hlsl_modifiers_to_string(invalid))) + if ((string = hlsl_modifiers_to_string(&ctx->string_buffers, invalid))) hlsl_error(ctx, decl->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, - "Modifiers '%s' are not allowed on local variables.", string); - vkd3d_free(string); + "Modifiers '%s' are not allowed on local variables.", string->buffer); + vkd3d_string_buffer_release(&ctx->string_buffers, string); }
if (decl->semantic) @@ -332,12 +332,12 @@ static DWORD add_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, DWORD mod, con { if (modifiers & mod) { - char *string; + struct vkd3d_string_buffer *string;
- if ((string = hlsl_modifiers_to_string(mod))) + if ((string = hlsl_modifiers_to_string(&ctx->string_buffers, mod))) hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, - "Modifier '%s' was already specified.", string); - vkd3d_free(string); + "Modifier '%s' was already specified.", string->buffer); + vkd3d_string_buffer_release(&ctx->string_buffers, string); return modifiers; } if ((mod & HLSL_MODIFIERS_MAJORITY_MASK) && (modifiers & HLSL_MODIFIERS_MAJORITY_MASK))
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index fbbe001a..1d767777 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -675,14 +675,17 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct vkd3d_string_buffer_cache switch (type->type) { case HLSL_CLASS_SCALAR: + assert(type->base_type < ARRAY_SIZE(base_types)); vkd3d_string_buffer_printf(string, "%s", base_types[type->base_type]); return string;
case HLSL_CLASS_VECTOR: + assert(type->base_type < ARRAY_SIZE(base_types)); vkd3d_string_buffer_printf(string, "%s%u", base_types[type->base_type], type->dimx); return string;
case HLSL_CLASS_MATRIX: + assert(type->base_type < ARRAY_SIZE(base_types)); vkd3d_string_buffer_printf(string, "%s%ux%u", base_types[type->base_type], type->dimx, type->dimy); return string;
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 55 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index dd15f627..5ad50b0c 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -121,6 +121,15 @@ static struct hlsl_ir_node *node_from_list(struct list *list) return LIST_ENTRY(list_tail(list), struct hlsl_ir_node, entry); }
+static struct list *make_empty_list(void) +{ + struct list *list; + + if ((list = vkd3d_malloc(sizeof(*list)))) + list_init(list); + return list; +} + static void check_invalid_matrix_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, struct vkd3d_shader_location loc) { if (modifiers & HLSL_MODIFIERS_MAJORITY_MASK) @@ -390,9 +399,8 @@ static struct list *create_loop(enum loop_type type, struct list *init, struct l struct hlsl_ir_loop *loop = NULL; struct hlsl_ir_if *cond_jump = NULL;
- if (!(list = vkd3d_malloc(sizeof(*list)))) + if (!(list = make_empty_list())) goto oom; - list_init(list);
if (init) list_move_head(list, init); @@ -724,9 +732,8 @@ static struct list *gen_struct_fields(struct hlsl_ctx *ctx, struct hlsl_type *ty if (type->type == HLSL_CLASS_MATRIX) assert(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
- if (!(list = vkd3d_malloc(sizeof(*list)))) + if (!(list = make_empty_list())) return NULL; - list_init(list); LIST_FOR_EACH_ENTRY_SAFE(v, v_next, fields, struct parse_variable_def, entry) { if (!(field = vkd3d_calloc(1, sizeof(*field)))) @@ -892,12 +899,11 @@ static struct list *make_list(struct hlsl_ir_node *node) { struct list *list;
- if (!(list = vkd3d_malloc(sizeof(*list)))) + if (!(list = make_empty_list())) { hlsl_free_instr(node); return NULL; } - list_init(list); list_add_tail(list, &node->entry); return list; } @@ -1377,14 +1383,13 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t if (basic_type->type == HLSL_CLASS_MATRIX) assert(basic_type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
- if (!(statements_list = vkd3d_malloc(sizeof(*statements_list)))) + if (!(statements_list = make_empty_list())) { LIST_FOR_EACH_ENTRY_SAFE(v, v_next, var_list, struct parse_variable_def, entry) free_parse_variable_def(v); vkd3d_free(var_list); return NULL; } - list_init(statements_list);
if (!var_list) return statements_list; @@ -1836,8 +1841,8 @@ any_identifier: fields_list: /* empty */ { - $$ = vkd3d_malloc(sizeof(*$$)); - list_init($$); + if (!($$ = make_empty_list())) + YYABORT; } | fields_list field { @@ -1921,8 +1926,8 @@ func_prototype: compound_statement: '{' '}' { - $$ = vkd3d_malloc(sizeof(*$$)); - list_init($$); + if (!($$ = make_empty_list())) + YYABORT; } | '{' scope_start statement_list '}' { @@ -1982,8 +1987,8 @@ register_opt: parameters: scope_start { - $$ = vkd3d_malloc(sizeof(*$$)); - list_init($$); + if (!($$ = make_empty_list())) + YYABORT; } | scope_start param_list { @@ -1993,8 +1998,8 @@ parameters: param_list: parameter { - $$ = vkd3d_malloc(sizeof(*$$)); - list_init($$); + if (!($$ = make_empty_list())) + YYABORT; if (!add_func_parameter(ctx, $$, &$1, @1)) { ERR("Error adding function parameter %s.\n", $1.name); @@ -2148,9 +2153,8 @@ declaration_statement: | struct_declaration | typedef { - if (!($$ = vkd3d_malloc(sizeof(*$$)))) + if (!($$ = make_empty_list())) YYABORT; - list_init($$); }
typedef_type: @@ -2177,8 +2181,8 @@ typedef: type_specs: type_spec { - $$ = vkd3d_malloc(sizeof(*$$)); - list_init($$); + if (!($$ = make_empty_list())) + YYABORT; list_add_head($$, &$1->entry); } | type_specs ',' type_spec @@ -2217,8 +2221,8 @@ variables_def_optional: variables_def: variable_def { - $$ = vkd3d_malloc(sizeof(*$$)); - list_init($$); + if (!($$ = make_empty_list())) + YYABORT; list_add_head($$, &$1->entry); } | variables_def ',' variable_def @@ -2401,9 +2405,8 @@ jump_statement: } | KW_RETURN ';' { - if (!($$ = vkd3d_malloc(sizeof(*$$)))) + if (!($$ = make_empty_list())) YYABORT; - list_init($$); if (!add_return(ctx, $$, NULL, @1)) YYABORT; } @@ -2462,8 +2465,8 @@ loop_statement: expr_statement: ';' { - $$ = vkd3d_malloc(sizeof(*$$)); - list_init($$); + if (!($$ = make_empty_list())) + YYABORT; } | expr ';' {
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- Very nice.
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 11 +++++++++++ libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 8 ++------ 3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 1d767777..1b388d5e 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -499,6 +499,17 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned return swizzle; }
+struct hlsl_ir_jump *hlsl_new_jump(enum hlsl_ir_jump_type type, struct vkd3d_shader_location loc) +{ + struct hlsl_ir_jump *jump; + + if (!(jump = vkd3d_malloc(sizeof(*jump)))) + return NULL; + init_node(&jump->node, HLSL_IR_JUMP, NULL, loc); + jump->type = type; + return jump; +} + bool hlsl_type_is_void(const struct hlsl_type *type) { return type->type == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_VOID; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 8107b260..c3b5d561 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -529,6 +529,7 @@ struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ir_node *node, struct hlsl_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 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_jump *hlsl_new_jump(enum hlsl_ir_jump_type type, 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; diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 5ad50b0c..45b97420 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -377,10 +377,8 @@ static bool append_conditional_break(struct list *cond_list) return false; list_add_tail(cond_list, &iff->node.entry);
- if (!(jump = vkd3d_malloc(sizeof(*jump)))) + if (!(jump = hlsl_new_jump(HLSL_IR_JUMP_BREAK, condition->loc))) return false; - init_node(&jump->node, HLSL_IR_JUMP, NULL, condition->loc); - jump->type = HLSL_IR_JUMP_BREAK; list_add_head(&iff->then_instrs, &jump->node.entry); return true; } @@ -563,10 +561,8 @@ static struct hlsl_ir_jump *add_return(struct hlsl_ctx *ctx, struct list *instrs return NULL; }
- if (!(jump = vkd3d_malloc(sizeof(*jump)))) + if (!(jump = hlsl_new_jump(HLSL_IR_JUMP_RETURN, loc))) return NULL; - init_node(&jump->node, HLSL_IR_JUMP, NULL, loc); - jump->type = HLSL_IR_JUMP_RETURN; list_add_tail(instrs, &jump->node.entry);
return jump;
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 11 +++++++++++ libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 4 +--- 3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 1b388d5e..4e73060a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -510,6 +510,17 @@ struct hlsl_ir_jump *hlsl_new_jump(enum hlsl_ir_jump_type type, struct vkd3d_sha return jump; }
+struct hlsl_ir_loop *hlsl_new_loop(struct vkd3d_shader_location loc) +{ + struct hlsl_ir_loop *loop; + + if (!(loop = vkd3d_calloc(1, sizeof(*loop)))) + return NULL; + init_node(&loop->node, HLSL_IR_LOOP, NULL, loc); + list_init(&loop->body); + return loop; +} + bool hlsl_type_is_void(const struct hlsl_type *type) { return type->type == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_VOID; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index c3b5d561..36e7dd0f 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -530,6 +530,7 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hl 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_jump *hlsl_new_jump(enum hlsl_ir_jump_type type, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN; +struct hlsl_ir_loop *hlsl_new_loop(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; diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 45b97420..1341de13 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -403,11 +403,9 @@ static struct list *create_loop(enum loop_type type, struct list *init, struct l if (init) list_move_head(list, init);
- if (!(loop = vkd3d_calloc(1, sizeof(*loop)))) + if (!(loop = hlsl_new_loop(loc))) goto oom; - init_node(&loop->node, HLSL_IR_LOOP, NULL, loc); list_add_tail(list, &loop->node.entry); - list_init(&loop->body);
if (!append_conditional_break(cond)) goto oom;
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com