Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/d3dcompiler_private.h | 6 ++++ dlls/d3dcompiler_43/hlsl.y | 35 ++++++----------------- dlls/d3dcompiler_43/utils.c | 11 +++---- 3 files changed, 18 insertions(+), 34 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index b576c2401b6..7439e4aeebc 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -1186,6 +1186,12 @@ void free_instr(struct hlsl_ir_node *node) DECLSPEC_HIDDEN; void free_instr_list(struct list *list) DECLSPEC_HIDDEN; void free_function_rb(struct wine_rb_entry *entry, void *context) DECLSPEC_HIDDEN;
+static inline struct hlsl_ir_node *new_unary_expr(enum hlsl_ir_expr_op op, + struct hlsl_ir_node *op1, struct source_location loc) +{ + struct hlsl_ir_node *operands[3] = {op1}; + return &new_expr(op, operands, &loc)->node; +}
#define MAKE_TAG(ch0, ch1, ch2, ch3) \ ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \ diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index bbe8f15338b..5e74ec6d267 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -257,9 +257,8 @@ static void declare_predefined_types(struct hlsl_scope *scope)
static struct hlsl_ir_if *loop_condition(struct list *cond_list) { + struct hlsl_ir_node *cond, *not_cond; struct hlsl_ir_if *out_cond; - struct hlsl_ir_expr *not_cond; - struct hlsl_ir_node *cond, *operands[3]; struct hlsl_ir_jump *jump; unsigned int count = list_count(cond_list);
@@ -276,16 +275,13 @@ static struct hlsl_ir_if *loop_condition(struct list *cond_list) return NULL; } out_cond->node.type = HLSL_IR_IF; - operands[0] = cond; - operands[1] = operands[2] = NULL; - not_cond = new_expr(HLSL_IR_UNOP_LOGIC_NOT, operands, &cond->loc); - if (!not_cond) + if (!(not_cond = new_unary_expr(HLSL_IR_UNOP_LOGIC_NOT, cond, cond->loc))) { ERR("Out of memory.\n"); d3dcompiler_free(out_cond); return NULL; } - out_cond->condition = ¬_cond->node; + out_cond->condition = not_cond; jump = d3dcompiler_alloc(sizeof(*jump)); if (!jump) { @@ -1931,7 +1927,6 @@ postfix_expr: primary_expr } | postfix_expr OP_INC { - struct hlsl_ir_node *operands[3]; struct source_location loc;
set_location(&loc, &@2); @@ -1941,16 +1936,13 @@ postfix_expr: primary_expr "modifying a const expression"); YYABORT; } - operands[0] = $1; - operands[1] = operands[2] = NULL; - $$ = &new_expr(HLSL_IR_UNOP_POSTINC, operands, &loc)->node; + $$ = new_unary_expr(HLSL_IR_UNOP_POSTINC, $1, loc); /* Post increment/decrement expressions are considered const */ $$->data_type = clone_hlsl_type($$->data_type); $$->data_type->modifiers |= HLSL_MODIFIER_CONST; } | postfix_expr OP_DEC { - struct hlsl_ir_node *operands[3]; struct source_location loc;
set_location(&loc, &@2); @@ -1960,9 +1952,7 @@ postfix_expr: primary_expr "modifying a const expression"); YYABORT; } - operands[0] = $1; - operands[1] = operands[2] = NULL; - $$ = &new_expr(HLSL_IR_UNOP_POSTDEC, operands, &loc)->node; + $$ = new_unary_expr(HLSL_IR_UNOP_POSTDEC, $1, loc); /* Post increment/decrement expressions are considered const */ $$->data_type = clone_hlsl_type($$->data_type); $$->data_type->modifiers |= HLSL_MODIFIER_CONST; @@ -2125,7 +2115,6 @@ unary_expr: postfix_expr } | OP_INC unary_expr { - struct hlsl_ir_node *operands[3]; struct source_location loc;
set_location(&loc, &@1); @@ -2135,13 +2124,10 @@ unary_expr: postfix_expr "modifying a const expression"); YYABORT; } - operands[0] = $2; - operands[1] = operands[2] = NULL; - $$ = &new_expr(HLSL_IR_UNOP_PREINC, operands, &loc)->node; + $$ = new_unary_expr(HLSL_IR_UNOP_PREINC, $2, loc); } | OP_DEC unary_expr { - struct hlsl_ir_node *operands[3]; struct source_location loc;
set_location(&loc, &@1); @@ -2151,15 +2137,12 @@ unary_expr: postfix_expr "modifying a const expression"); YYABORT; } - operands[0] = $2; - operands[1] = operands[2] = NULL; - $$ = &new_expr(HLSL_IR_UNOP_PREDEC, operands, &loc)->node; + $$ = new_unary_expr(HLSL_IR_UNOP_PREDEC, $2, loc); } | unary_op unary_expr { enum hlsl_ir_expr_op ops[] = {0, HLSL_IR_UNOP_NEG, HLSL_IR_UNOP_LOGIC_NOT, HLSL_IR_UNOP_BIT_NOT}; - struct hlsl_ir_node *operands[3]; struct source_location loc;
if ($1 == UNARY_OP_PLUS) @@ -2168,10 +2151,8 @@ unary_expr: postfix_expr } else { - operands[0] = $2; - operands[1] = operands[2] = NULL; set_location(&loc, &@1); - $$ = &new_expr(ops[$1], operands, &loc)->node; + $$ = new_unary_expr(ops[$1], $2, loc); } } /* var_modifiers just to avoid shift/reduce conflicts */ diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 1dbb9152072..51042984906 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1343,15 +1343,12 @@ struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **ope struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, struct source_location *loc) { - struct hlsl_ir_expr *cast; - struct hlsl_ir_node *operands[3]; + struct hlsl_ir_node *cast;
- operands[0] = node; - operands[1] = operands[2] = NULL; - cast = new_expr(HLSL_IR_UNOP_CAST, operands, loc); + cast = new_unary_expr(HLSL_IR_UNOP_CAST, node, *loc); if (cast) - cast->node.data_type = type; - return cast; + cast->data_type = type; + return expr_from_node(cast); }
struct hlsl_ir_expr *hlsl_mul(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,