-- v3: vkd3d-shader/hlsl: Free the "iter" block pointer on success in create_loop(). vkd3d-shader/hlsl: Return a hlsl_block from the "expr_statement" and "expr" rules. vkd3d-shader/hlsl: Return a hlsl_block from the "jump_statement" rule. vkd3d-shader/hlsl: Return a hlsl_block from the "selection_statement" rule. vkd3d-shader/hlsl: Return a hlsl_block from the "loop_statement" rule. vkd3d-shader/hlsl: Return a hlsl_block from the "statement" rule.
From: Zebediah Figura zfigura@codeweavers.com
As well as from the "statement_list" and "compound_statement" rules, which trivially pass through from "statement". --- libs/vkd3d-shader/hlsl.y | 63 +++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 26 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 82dd19eb..c8b7e255 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -487,9 +487,8 @@ static bool attribute_list_has_duplicates(const struct parse_attribute_list *att }
static struct list *create_loop(struct hlsl_ctx *ctx, enum loop_type type, const struct parse_attribute_list *attributes, struct list *init, struct list *cond, - struct list *iter, struct list *body, const struct vkd3d_shader_location *loc) + struct list *iter, struct hlsl_block *body, const struct vkd3d_shader_location *loc) { - struct hlsl_block body_block; struct hlsl_ir_node *loop; unsigned int i;
@@ -529,32 +528,27 @@ static struct list *create_loop(struct hlsl_ctx *ctx, enum loop_type type, const if (!append_conditional_break(ctx, cond)) goto oom;
- hlsl_block_init(&body_block); - - if (type != LOOP_DO_WHILE) - list_move_tail(&body_block.instrs, cond); - - list_move_tail(&body_block.instrs, body); - if (iter) - list_move_tail(&body_block.instrs, iter); + list_move_tail(&body->instrs, iter);
if (type == LOOP_DO_WHILE) - list_move_tail(&body_block.instrs, cond); + list_move_tail(&body->instrs, cond); + else + list_move_head(&body->instrs, cond);
- if (!(loop = hlsl_new_loop(ctx, &body_block, loc))) + if (!(loop = hlsl_new_loop(ctx, body, loc))) goto oom; list_add_tail(init, &loop->entry);
vkd3d_free(cond); - vkd3d_free(body); + destroy_block(body); return init;
oom: destroy_instr_list(init); destroy_instr_list(cond); destroy_instr_list(iter); - destroy_instr_list(body); + destroy_block(body); return NULL; }
@@ -4433,6 +4427,7 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type char *name; DWORD modifiers; struct hlsl_ir_node *instr; + struct hlsl_block *block; struct list *list; struct parse_fields fields; struct parse_function function; @@ -4565,7 +4560,6 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <list> bitand_expr %type <list> bitor_expr %type <list> bitxor_expr -%type <list> compound_statement %type <list> conditional_expr %type <list> declaration %type <list> declaration_statement @@ -4584,8 +4578,6 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <list> relational_expr %type <list> selection_statement %type <list> shift_expr -%type <list> statement -%type <list> statement_list %type <list> struct_declaration_without_vars %type <list> type_specs %type <list> unary_expr @@ -4606,6 +4598,10 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <attr_list> attribute_list %type <attr_list> attribute_list_optional
+%type <block> compound_statement +%type <block> statement +%type <block> statement_list + %type <boolval> boolean
%type <buffer_type> buffer_type @@ -4913,15 +4909,15 @@ func_declaration: "Function "%s" is already defined.", decl->func->name); hlsl_note(ctx, &decl->loc, VKD3D_SHADER_LOG_ERROR, ""%s" was previously defined here.", decl->func->name); - hlsl_free_instr_list($2); + destroy_block($2); } else { size_t i;
decl->has_body = true; - list_move_tail(&decl->body.instrs, $2); - vkd3d_free($2); + hlsl_block_add_block(&decl->body, $2); + destroy_block($2);
/* Semantics are taken from whichever definition has a body. * We can't just replace the hlsl_ir_var pointers, though: if @@ -5098,7 +5094,7 @@ func_prototype: compound_statement: '{' '}' { - if (!($$ = make_empty_list(ctx))) + if (!($$ = make_empty_block(ctx))) YYABORT; } | '{' scope_start statement_list '}' @@ -5913,17 +5909,32 @@ statement_list: | statement_list statement { $$ = $1; - list_move_tail($$, $2); - vkd3d_free($2); + hlsl_block_add_block($$, $2); + destroy_block($2); }
statement: declaration_statement + { + $$ = list_to_block($1); + } | expr_statement + { + $$ = list_to_block($1); + } | compound_statement | jump_statement + { + $$ = list_to_block($1); + } | selection_statement + { + $$ = list_to_block($1); + } | loop_statement + { + $$ = list_to_block($1); + }
jump_statement: KW_RETURN expr ';' @@ -5985,13 +5996,13 @@ selection_statement: if_body: statement { - $$.then_block = list_to_block($1); + $$.then_block = $1; $$.else_block = NULL; } | statement KW_ELSE statement { - $$.then_block = list_to_block($1); - $$.else_block = list_to_block($3); + $$.then_block = $1; + $$.else_block = $3; }
loop_statement:
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.y | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index c8b7e255..a2f2f373 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -486,7 +486,8 @@ static bool attribute_list_has_duplicates(const struct parse_attribute_list *att return false; }
-static struct list *create_loop(struct hlsl_ctx *ctx, enum loop_type type, const struct parse_attribute_list *attributes, struct list *init, struct list *cond, +static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum loop_type type, + const struct parse_attribute_list *attributes, struct list *init, struct list *cond, struct list *iter, struct hlsl_block *body, const struct vkd3d_shader_location *loc) { struct hlsl_ir_node *loop; @@ -542,7 +543,7 @@ static struct list *create_loop(struct hlsl_ctx *ctx, enum loop_type type, const
vkd3d_free(cond); destroy_block(body); - return init; + return list_to_block(init);
oom: destroy_instr_list(init); @@ -4571,7 +4572,6 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <list> jump_statement %type <list> logicand_expr %type <list> logicor_expr -%type <list> loop_statement %type <list> mul_expr %type <list> postfix_expr %type <list> primary_expr @@ -4599,6 +4599,7 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <attr_list> attribute_list_optional
%type <block> compound_statement +%type <block> loop_statement %type <block> statement %type <block> statement_list
@@ -5932,9 +5933,6 @@ statement: $$ = list_to_block($1); } | loop_statement - { - $$ = list_to_block($1); - }
jump_statement: KW_RETURN expr ';'
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.y | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index a2f2f373..bf72117a 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -4576,7 +4576,6 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <list> postfix_expr %type <list> primary_expr %type <list> relational_expr -%type <list> selection_statement %type <list> shift_expr %type <list> struct_declaration_without_vars %type <list> type_specs @@ -4600,6 +4599,7 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type
%type <block> compound_statement %type <block> loop_statement +%type <block> selection_statement %type <block> statement %type <block> statement_list
@@ -5929,9 +5929,6 @@ statement: $$ = list_to_block($1); } | selection_statement - { - $$ = list_to_block($1); - } | loop_statement
jump_statement: @@ -5987,8 +5984,8 @@ selection_statement: "if condition type %s is not scalar.", string->buffer); hlsl_release_string_buffer(ctx, string); } - $$ = $3; - list_add_tail($$, &instr->entry); + $$ = list_to_block($3); + hlsl_block_add_instr($$, instr); }
if_body:
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.y | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index bf72117a..00179664 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -138,6 +138,11 @@ static struct hlsl_ir_node *node_from_list(struct list *list) return LIST_ENTRY(list_tail(list), struct hlsl_ir_node, entry); }
+static struct hlsl_ir_node *node_from_block(struct hlsl_block *block) +{ + return LIST_ENTRY(list_tail(&block->instrs), struct hlsl_ir_node, entry); +} + static struct list *block_to_list(struct hlsl_block *block) { /* This is a temporary hack to ease the transition from lists to blocks. @@ -652,7 +657,7 @@ static struct hlsl_ir_node *get_swizzle(struct hlsl_ctx *ctx, struct hlsl_ir_nod return NULL; }
-static bool add_return(struct hlsl_ctx *ctx, struct list *instrs, +static bool add_return(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *return_value, const struct vkd3d_shader_location *loc) { struct hlsl_type *return_type = ctx->cur_function->return_type; @@ -664,7 +669,7 @@ static bool add_return(struct hlsl_ctx *ctx, struct list *instrs, { struct hlsl_ir_node *store;
- if (!(return_value = add_implicit_conversion(ctx, instrs, return_value, return_type, loc))) + if (!(return_value = add_implicit_conversion(ctx, block_to_list(block), return_value, return_type, loc))) return false;
if (!(store = hlsl_new_simple_store(ctx, ctx->cur_function->return_var, return_value))) @@ -685,7 +690,7 @@ static bool add_return(struct hlsl_ctx *ctx, struct list *instrs,
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_RETURN, NULL, loc))) return false; - list_add_tail(instrs, &jump->entry); + hlsl_block_add_instr(block, jump);
return true; } @@ -4569,7 +4574,6 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <list> expr_optional %type <list> expr_statement %type <list> initializer_expr -%type <list> jump_statement %type <list> logicand_expr %type <list> logicor_expr %type <list> mul_expr @@ -4598,6 +4602,7 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <attr_list> attribute_list_optional
%type <block> compound_statement +%type <block> jump_statement %type <block> loop_statement %type <block> selection_statement %type <block> statement @@ -5925,22 +5930,19 @@ statement: } | compound_statement | jump_statement - { - $$ = list_to_block($1); - } | selection_statement | loop_statement
jump_statement: KW_RETURN expr ';' { - if (!add_return(ctx, $2, node_from_list($2), &@1)) + $$ = list_to_block($2); + if (!add_return(ctx, $$, node_from_block($$), &@1)) YYABORT; - $$ = $2; } | KW_RETURN ';' { - if (!($$ = make_empty_list(ctx))) + if (!($$ = make_empty_block(ctx))) YYABORT; if (!add_return(ctx, $$, NULL, &@1)) YYABORT; @@ -5949,16 +5951,16 @@ jump_statement: { struct hlsl_ir_node *discard, *c;
- if (!($$ = make_empty_list(ctx))) + if (!($$ = make_empty_block(ctx))) YYABORT;
if (!(c = hlsl_new_uint_constant(ctx, ~0u, &@1))) return false; - list_add_tail($$, &c->entry); + hlsl_block_add_instr($$, c);
if (!(discard = hlsl_new_jump(ctx, HLSL_IR_JUMP_DISCARD_NZ, c, &@1))) return false; - list_add_tail($$, &discard->entry); + hlsl_block_add_instr($$, discard); }
selection_statement:
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.y | 83 +++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 44 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 00179664..a888ec76 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -442,19 +442,19 @@ static DWORD add_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, DWORD mod, return modifiers | mod; }
-static bool append_conditional_break(struct hlsl_ctx *ctx, struct list *cond_list) +static bool append_conditional_break(struct hlsl_ctx *ctx, struct hlsl_block *cond_block) { struct hlsl_ir_node *condition, *not, *iff, *jump; struct hlsl_block then_block;
/* E.g. "for (i = 0; ; ++i)". */ - if (list_empty(cond_list)) + if (list_empty(&cond_block->instrs)) return true;
- condition = node_from_list(cond_list); + condition = node_from_block(cond_block); if (!(not = hlsl_new_unary_expr(ctx, HLSL_OP1_LOGIC_NOT, condition, &condition->loc))) return false; - list_add_tail(cond_list, ¬->entry); + hlsl_block_add_instr(cond_block, not);
hlsl_block_init(&then_block);
@@ -464,7 +464,7 @@ static bool append_conditional_break(struct hlsl_ctx *ctx, struct list *cond_lis
if (!(iff = hlsl_new_if(ctx, not, &then_block, NULL, &condition->loc))) return false; - list_add_tail(cond_list, &iff->entry); + hlsl_block_add_instr(cond_block, iff); return true; }
@@ -492,8 +492,8 @@ static bool attribute_list_has_duplicates(const struct parse_attribute_list *att }
static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum loop_type type, - const struct parse_attribute_list *attributes, struct list *init, struct list *cond, - struct list *iter, struct hlsl_block *body, const struct vkd3d_shader_location *loc) + const struct parse_attribute_list *attributes, struct hlsl_block *init, struct hlsl_block *cond, + struct hlsl_block *iter, struct hlsl_block *body, const struct vkd3d_shader_location *loc) { struct hlsl_ir_node *loop; unsigned int i; @@ -528,32 +528,32 @@ static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum loop_type type, } }
- if (!init && !(init = make_empty_list(ctx))) + if (!init && !(init = make_empty_block(ctx))) goto oom;
if (!append_conditional_break(ctx, cond)) goto oom;
if (iter) - list_move_tail(&body->instrs, iter); + hlsl_block_add_block(body, iter);
if (type == LOOP_DO_WHILE) - list_move_tail(&body->instrs, cond); + list_move_tail(&body->instrs, &cond->instrs); else - list_move_head(&body->instrs, cond); + list_move_head(&body->instrs, &cond->instrs);
if (!(loop = hlsl_new_loop(ctx, body, loc))) goto oom; - list_add_tail(init, &loop->entry); + hlsl_block_add_instr(init, loop);
- vkd3d_free(cond); + destroy_block(cond); destroy_block(body); - return list_to_block(init); + return init;
oom: - destroy_instr_list(init); - destroy_instr_list(cond); - destroy_instr_list(iter); + destroy_block(init); + destroy_block(cond); + destroy_block(iter); destroy_block(body); return NULL; } @@ -4570,9 +4570,6 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <list> declaration %type <list> declaration_statement %type <list> equality_expr -%type <list> expr -%type <list> expr_optional -%type <list> expr_statement %type <list> initializer_expr %type <list> logicand_expr %type <list> logicor_expr @@ -4602,6 +4599,9 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <attr_list> attribute_list_optional
%type <block> compound_statement +%type <block> expr +%type <block> expr_optional +%type <block> expr_statement %type <block> jump_statement %type <block> loop_statement %type <block> selection_statement @@ -5639,7 +5639,7 @@ state: any_identifier '=' expr ';' { vkd3d_free($1); - hlsl_free_instr_list($3); + destroy_block($3); }
state_block_start: @@ -5705,17 +5705,12 @@ arrays: } | '[' expr ']' arrays { - struct hlsl_block block; uint32_t *new_array; unsigned int size;
- hlsl_block_init(&block); - list_move_tail(&block.instrs, $2); - - size = evaluate_static_expression_as_uint(ctx, &block, &@2); + size = evaluate_static_expression_as_uint(ctx, $2, &@2);
- hlsl_block_cleanup(&block); - vkd3d_free($2); + destroy_block($2);
$$ = $4;
@@ -5925,9 +5920,6 @@ statement: $$ = list_to_block($1); } | expr_statement - { - $$ = list_to_block($1); - } | compound_statement | jump_statement | selection_statement @@ -5936,7 +5928,7 @@ statement: jump_statement: KW_RETURN expr ';' { - $$ = list_to_block($2); + $$ = $2; if (!add_return(ctx, $$, node_from_block($$), &@1)) YYABORT; } @@ -5966,7 +5958,7 @@ jump_statement: selection_statement: KW_IF '(' expr ')' if_body { - struct hlsl_ir_node *condition = node_from_list($3); + struct hlsl_ir_node *condition = node_from_block($3); struct hlsl_ir_node *instr;
if (!(instr = hlsl_new_if(ctx, condition, $5.then_block, $5.else_block, &@1))) @@ -5986,7 +5978,7 @@ selection_statement: "if condition type %s is not scalar.", string->buffer); hlsl_release_string_buffer(ctx, string); } - $$ = list_to_block($3); + $$ = $3; hlsl_block_add_instr($$, instr); }
@@ -6018,14 +6010,14 @@ loop_statement: } | attribute_list_optional KW_FOR '(' scope_start declaration expr_statement expr_optional ')' statement { - $$ = create_loop(ctx, LOOP_FOR, &$1, $5, $6, $7, $9, &@2); + $$ = create_loop(ctx, LOOP_FOR, &$1, list_to_block($5), $6, $7, $9, &@2); hlsl_pop_scope(ctx); }
expr_optional: %empty { - if (!($$ = make_empty_list(ctx))) + if (!($$ = make_empty_block(ctx))) YYABORT; } | expr @@ -6095,7 +6087,7 @@ primary_expr: } | '(' expr ')' { - $$ = $2; + $$ = block_to_list($2); } | var_identifier '(' func_arguments ')' { @@ -6189,10 +6181,10 @@ postfix_expr: } | postfix_expr '[' expr ']' { - struct hlsl_ir_node *array = node_from_list($1), *index = node_from_list($3); + struct hlsl_ir_node *array = node_from_list($1), *index = node_from_block($3);
- list_move_head($1, $3); - vkd3d_free($3); + list_move_head($1, &$3->instrs); + destroy_block($3);
if (!add_array_access(ctx, $1, array, index, &@2)) { @@ -6451,12 +6443,12 @@ conditional_expr: logicor_expr | logicor_expr '?' expr ':' assignment_expr { - struct hlsl_ir_node *cond = node_from_list($1), *first = node_from_list($3), *second = node_from_list($5); + struct hlsl_ir_node *cond = node_from_list($1), *first = node_from_block($3), *second = node_from_list($5); struct hlsl_type *common_type;
- list_move_tail($1, $3); + list_move_tail($1, &$3->instrs); list_move_tail($1, $5); - vkd3d_free($3); + destroy_block($3); vkd3d_free($5);
if (!(common_type = get_common_numeric_type(ctx, first, second, &@3))) @@ -6540,9 +6532,12 @@ assign_op:
expr: assignment_expr + { + $$ = list_to_block($1); + } | expr ',' assignment_expr { $$ = $1; - list_move_tail($$, $3); + list_move_tail(&$$->instrs, $3); vkd3d_free($3); }
From: Zebediah Figura zfigura@codeweavers.com
Spotted by Giovanni Mascellani. --- libs/vkd3d-shader/hlsl.y | 1 + 1 file changed, 1 insertion(+)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index a888ec76..42fa2129 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -548,6 +548,7 @@ static struct hlsl_block *create_loop(struct hlsl_ctx *ctx, enum loop_type type,
destroy_block(cond); destroy_block(body); + destroy_block(iter); return init;
oom:
This merge request was approved by Henri Verbeet.