Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/hlsl.y | 84 +++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 42 deletions(-)
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index c18efcc1350..f87df072c26 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -1091,7 +1091,7 @@ hlsl_prog: /* empty */ hlsl_report_message($2.decl->node.loc.file, $2.decl->node.loc.line, $2.decl->node.loc.col, HLSL_LEVEL_ERROR, "redefinition of function %s", debugstr_a($2.name)); - return 1; + YYABORT; } else if (!compare_hlsl_types(decl->node.data_type, $2.decl->node.data_type)) { @@ -1102,7 +1102,7 @@ hlsl_prog: /* empty */ hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_NOTE, "%s previously declared here", debugstr_a($2.name)); - return 1; + YYABORT; } }
@@ -1184,7 +1184,7 @@ named_struct_spec: var_modifiers KW_STRUCT any_identifier '{' fields_list { hlsl_report_message(hlsl_ctx.source_file, @3.first_line, @3.first_column, HLSL_LEVEL_ERROR, "redefinition of '%s'", $3); - return 1; + YYABORT; }
ret = add_type_to_scope(hlsl_ctx.cur_scope, $$); @@ -1192,7 +1192,7 @@ named_struct_spec: var_modifiers KW_STRUCT any_identifier '{' fields_list { hlsl_report_message(hlsl_ctx.source_file, @3.first_line, @3.first_column, HLSL_LEVEL_ERROR, "redefinition of struct '%s'", $3); - return 1; + YYABORT; } }
@@ -1263,7 +1263,7 @@ func_prototype: var_modifiers type var_identifier '(' parameters ')' c { hlsl_report_message(hlsl_ctx.source_file, @3.first_line, @3.first_column, HLSL_LEVEL_ERROR, "redefinition of '%s'\n", $3); - return 1; + YYABORT; } if ($2->base_type == HLSL_TYPE_VOID && $7.semantic) { @@ -1280,7 +1280,7 @@ func_prototype: var_modifiers type var_identifier '(' parameters ')' c if (!$$.decl) { ERR("Out of memory.\n"); - return -1; + YYABORT; } $$.name = $3; $$.decl->semantic = $7.semantic; @@ -1363,7 +1363,7 @@ param_list: parameter { ERR("Error adding function parameter %s.\n", $1.name); set_parse_status(&hlsl_ctx.status, PARSE_ERR); - return -1; + YYABORT; } } | param_list ',' parameter @@ -1376,7 +1376,7 @@ param_list: parameter { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "duplicate parameter %s", $3.name); - return 1; + YYABORT; } }
@@ -1400,7 +1400,7 @@ input_mods: /* Empty */ { hlsl_report_message(hlsl_ctx.source_file, @2.first_line, @2.first_column, HLSL_LEVEL_ERROR, "duplicate input-output modifiers"); - return 1; + YYABORT; } $$ = $1 | $2; } @@ -1429,14 +1429,14 @@ type: base_type hlsl_message("Line %u: vectors of non-scalar types are not allowed.\n", hlsl_ctx.line_no); set_parse_status(&hlsl_ctx.status, PARSE_ERR); - return 1; + YYABORT; } if ($5 < 1 || $5 > 4) { hlsl_message("Line %u: vector size must be between 1 and 4.\n", hlsl_ctx.line_no); set_parse_status(&hlsl_ctx.status, PARSE_ERR); - return 1; + YYABORT; }
$$ = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, $3->base_type, $5, 1); @@ -1448,14 +1448,14 @@ type: base_type hlsl_message("Line %u: matrices of non-scalar types are not allowed.\n", hlsl_ctx.line_no); set_parse_status(&hlsl_ctx.status, PARSE_ERR); - return 1; + YYABORT; } if ($5 < 1 || $5 > 4 || $7 < 1 || $7 > 4) { hlsl_message("Line %u: matrix dimensions must be between 1 and 4.\n", hlsl_ctx.line_no); set_parse_status(&hlsl_ctx.status, PARSE_ERR); - return 1; + YYABORT; }
$$ = new_hlsl_type(NULL, HLSL_CLASS_MATRIX, $3->base_type, $5, $7); @@ -1524,7 +1524,7 @@ declaration_statement: declaration if (!$$) { ERR("Out of memory\n"); - return -1; + YYABORT; } list_init($$); } @@ -1535,7 +1535,7 @@ typedef: KW_TYPEDEF var_modifiers type type_specs ';'
set_location(&loc, &@1); if (!add_typedef($2, $3, $4, &loc)) - return 1; + YYABORT; } | KW_TYPEDEF struct_spec type_specs ';' { @@ -1543,7 +1543,7 @@ typedef: KW_TYPEDEF var_modifiers type type_specs ';'
set_location(&loc, &@1); if (!add_typedef(0, $2, $3, &loc)) - return 1; + YYABORT; }
type_specs: type_spec @@ -1739,7 +1739,7 @@ jump_statement: KW_RETURN expr ';' if (!jump) { ERR("Out of memory\n"); - return -1; + YYABORT; } jump->node.type = HLSL_IR_JUMP; set_location(&jump->node.loc, &@1); @@ -1762,7 +1762,7 @@ selection_statement: KW_IF '(' expr ')' if_body if (!instr) { ERR("Out of memory\n"); - return -1; + YYABORT; } instr->node.type = HLSL_IR_IF; set_location(&instr->node.loc, &@1); @@ -1799,7 +1799,7 @@ loop_statement: KW_WHILE '(' expr ')' statement if (!cond) { ERR("Out of memory.\n"); - return -1; + YYABORT; } list_init(cond); list_add_head(cond, &$3->entry); @@ -1814,7 +1814,7 @@ loop_statement: KW_WHILE '(' expr ')' statement if (!cond) { ERR("Out of memory.\n"); - return -1; + YYABORT; } list_init(cond); list_add_head(cond, &$5->entry); @@ -1860,7 +1860,7 @@ primary_expr: C_FLOAT if (!c) { ERR("Out of memory.\n"); - return -1; + YYABORT; } c->node.type = HLSL_IR_CONSTANT; set_location(&c->node.loc, &yylloc); @@ -1874,7 +1874,7 @@ primary_expr: C_FLOAT if (!c) { ERR("Out of memory.\n"); - return -1; + YYABORT; } c->node.type = HLSL_IR_CONSTANT; set_location(&c->node.loc, &yylloc); @@ -1888,7 +1888,7 @@ primary_expr: C_FLOAT if (!c) { ERR("Out of memory.\n"); - return -1; + YYABORT; } c->node.type = HLSL_IR_CONSTANT; set_location(&c->node.loc, &yylloc); @@ -1906,7 +1906,7 @@ primary_expr: C_FLOAT hlsl_message("Line %d: variable '%s' not declared\n", hlsl_ctx.line_no, $1); set_parse_status(&hlsl_ctx.status, PARSE_ERR); - return 1; + YYABORT; } if ((deref = new_var_deref(var))) { @@ -1935,7 +1935,7 @@ postfix_expr: primary_expr { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); - return 1; + YYABORT; } operands[0] = $1; operands[1] = operands[2] = NULL; @@ -1954,7 +1954,7 @@ postfix_expr: primary_expr { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); - return 1; + YYABORT; } operands[0] = $1; operands[1] = operands[2] = NULL; @@ -1983,7 +1983,7 @@ postfix_expr: primary_expr if (!deref) { ERR("Out of memory\n"); - return -1; + YYABORT; } deref->node.loc = loc; $$ = &deref->node; @@ -1994,7 +1994,7 @@ postfix_expr: primary_expr { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "invalid subscript %s", debugstr_a($3)); - return 1; + YYABORT; } } else if ($1->data_type->type <= HLSL_CLASS_LAST_NUMERIC) @@ -2006,7 +2006,7 @@ postfix_expr: primary_expr { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "invalid swizzle %s", debugstr_a($3)); - return 1; + YYABORT; } $$ = &swizzle->node; } @@ -2014,7 +2014,7 @@ postfix_expr: primary_expr { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "invalid subscript %s", debugstr_a($3)); - return 1; + YYABORT; } } | postfix_expr '[' expr ']' @@ -2030,7 +2030,7 @@ postfix_expr: primary_expr if (!deref) { ERR("Out of memory\n"); - return -1; + YYABORT; } deref->node.type = HLSL_IR_DEREF; set_location(&loc, &@2); @@ -2058,7 +2058,7 @@ postfix_expr: primary_expr d3dcompiler_free(deref); free_instr($1); free_instr($3); - return 1; + YYABORT; } if ($3->data_type->type != HLSL_CLASS_SCALAR) { @@ -2067,7 +2067,7 @@ postfix_expr: primary_expr d3dcompiler_free(deref); free_instr($1); free_instr($3); - return 1; + YYABORT; } deref->type = HLSL_IR_DEREF_ARRAY; deref->v.array.array = $1; @@ -2088,21 +2088,21 @@ postfix_expr: primary_expr hlsl_message("Line %u: unexpected modifier in a constructor.\n", hlsl_ctx.line_no); set_parse_status(&hlsl_ctx.status, PARSE_ERR); - return -1; + YYABORT; } if ($2->type > HLSL_CLASS_LAST_NUMERIC) { hlsl_message("Line %u: constructors are allowed only for numeric data types.\n", hlsl_ctx.line_no); set_parse_status(&hlsl_ctx.status, PARSE_ERR); - return -1; + YYABORT; } if ($2->dimx * $2->dimy != initializer_size($4)) { hlsl_message("Line %u: wrong number of components in constructor.\n", hlsl_ctx.line_no); set_parse_status(&hlsl_ctx.status, PARSE_ERR); - return -1; + YYABORT; }
constructor = d3dcompiler_alloc(sizeof(*constructor)); @@ -2133,7 +2133,7 @@ unary_expr: postfix_expr { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); - return 1; + YYABORT; } operands[0] = $2; operands[1] = operands[2] = NULL; @@ -2149,7 +2149,7 @@ unary_expr: postfix_expr { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); - return 1; + YYABORT; } operands[0] = $2; operands[1] = operands[2] = NULL; @@ -2187,7 +2187,7 @@ unary_expr: postfix_expr { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "unexpected modifier in a cast"); - return 1; + YYABORT; }
if ($4) @@ -2200,7 +2200,7 @@ unary_expr: postfix_expr hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "can't cast from %s to %s", debug_hlsl_type(src_type), debug_hlsl_type(dst_type)); - return 1; + YYABORT; }
expr = new_cast($6, dst_type, &loc); @@ -2401,11 +2401,11 @@ assignment_expr: conditional_expr { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "l-value is const"); - return 1; + YYABORT; } $$ = make_assignment($1, $2, BWRITERSP_WRITEMASK_ALL, $3); if (!$$) - return 1; + YYABORT; $$->loc = loc; }
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/d3dcompiler_private.h | 8 +- dlls/d3dcompiler_43/hlsl.y | 116 +++++++++++----------- 2 files changed, 65 insertions(+), 59 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index d6db46b4536..b576c2401b6 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -980,6 +980,12 @@ struct parse_colon_attribute struct reg_reservation *reg_reservation; };
+struct parse_initializer +{ + struct hlsl_ir_node **args; + unsigned int args_count; +}; + struct parse_variable_def { struct list entry; @@ -989,7 +995,7 @@ struct parse_variable_def unsigned int array_size; const char *semantic; struct reg_reservation *reg_reservation; - struct list *initializer; + struct parse_initializer initializer; };
struct parse_function diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index f87df072c26..bbe8f15338b 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -378,19 +378,26 @@ oom: return NULL; }
-static unsigned int initializer_size(struct list *initializer) +static unsigned int initializer_size(const struct parse_initializer *initializer) { - unsigned int count = 0; - struct hlsl_ir_node *node; + unsigned int count = 0, i;
- LIST_FOR_EACH_ENTRY(node, initializer, struct hlsl_ir_node, entry) + for (i = 0; i < initializer->args_count; ++i) { - count += components_count_type(node->data_type); + count += components_count_type(initializer->args[i]->data_type); } TRACE("Initializer size = %u.\n", count); return count; }
+static void free_parse_initializer(struct parse_initializer *initializer) +{ + unsigned int i; + for (i = 0; i < initializer->args_count; ++i) + free_instr(initializer->args[i]); + d3dcompiler_free(initializer->args); +} + static struct hlsl_ir_swizzle *new_swizzle(DWORD s, unsigned int components, struct hlsl_ir_node *val, struct source_location *loc) { @@ -488,30 +495,30 @@ static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ir_node *value, const cha return NULL; }
-static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, struct list *initializer) +static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, + struct parse_initializer *initializer) { struct hlsl_type *type = var->node.data_type; - struct hlsl_ir_node *node; struct hlsl_struct_field *field; - struct list *cur_node; struct hlsl_ir_node *assignment; struct hlsl_ir_deref *deref; + unsigned int i = 0;
if (initializer_size(initializer) != components_count_type(type)) { hlsl_report_message(var->node.loc.file, var->node.loc.line, var->node.loc.col, HLSL_LEVEL_ERROR, "structure initializer mismatch"); - free_instr_list(initializer); + free_parse_initializer(initializer); return; } - cur_node = list_head(initializer); - assert(cur_node); - node = LIST_ENTRY(cur_node, struct hlsl_ir_node, entry); + LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) { - if (!cur_node) + struct hlsl_ir_node *node = initializer->args[i]; + + if (i++ >= initializer->args_count) { - d3dcompiler_free(initializer); + d3dcompiler_free(initializer->args); return; } if (components_count_type(field->type) == components_count_type(node->data_type)) @@ -528,19 +535,12 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, s } else FIXME("Initializing with "mismatched" fields is not supported yet.\n"); - cur_node = list_next(initializer, cur_node); - node = LIST_ENTRY(cur_node, struct hlsl_ir_node, entry); }
/* Free initializer elements in excess. */ - while (cur_node) - { - struct list *next = list_next(initializer, cur_node); - free_instr(node); - cur_node = next; - node = LIST_ENTRY(cur_node, struct hlsl_ir_node, entry); - } - d3dcompiler_free(initializer); + for (; i < initializer->args_count; ++i) + free_instr(initializer->args[i]); + d3dcompiler_free(initializer->args); }
static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, struct list *var_list) @@ -593,7 +593,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, local = FALSE; }
- if (var->modifiers & HLSL_MODIFIER_CONST && !(var->modifiers & HLSL_STORAGE_UNIFORM) && !v->initializer) + if (var->modifiers & HLSL_MODIFIER_CONST && !(var->modifiers & HLSL_STORAGE_UNIFORM) && !v->initializer.args_count) { hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, "const variable without initializer"); @@ -611,10 +611,9 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, } TRACE("Declared variable %s.\n", var->name);
- if (v->initializer) + if (v->initializer.args_count) { - unsigned int size = initializer_size(v->initializer); - struct hlsl_ir_node *node; + unsigned int size = initializer_size(&v->initializer);
TRACE("Variable with initializer.\n"); if (type->type <= HLSL_CLASS_LAST_NUMERIC @@ -624,7 +623,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, { hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, "'%s' initializer does not match", v->name); - free_instr_list(v->initializer); + free_parse_initializer(&v->initializer); d3dcompiler_free(v); continue; } @@ -634,43 +633,43 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, { hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, "'%s' initializer does not match", v->name); - free_instr_list(v->initializer); + free_parse_initializer(&v->initializer); d3dcompiler_free(v); continue; }
if (type->type == HLSL_CLASS_STRUCT) { - struct_var_initializer(statements_list, var, v->initializer); + struct_var_initializer(statements_list, var, &v->initializer); d3dcompiler_free(v); continue; } if (type->type > HLSL_CLASS_LAST_NUMERIC) { FIXME("Initializers for non scalar/struct variables not supported yet.\n"); - free_instr_list(v->initializer); + free_parse_initializer(&v->initializer); d3dcompiler_free(v); continue; } if (v->array_size > 0) { FIXME("Initializing arrays is not supported yet.\n"); - free_instr_list(v->initializer); + free_parse_initializer(&v->initializer); d3dcompiler_free(v); continue; } - if (list_count(v->initializer) > 1) + if (v->initializer.args_count > 1) { FIXME("Complex initializers are not supported yet.\n"); - free_instr_list(v->initializer); + free_parse_initializer(&v->initializer); d3dcompiler_free(v); continue; } - node = LIST_ENTRY(list_head(v->initializer), struct hlsl_ir_node, entry); + assignment = make_assignment(&var->node, ASSIGN_OP_ASSIGN, - BWRITERSP_WRITEMASK_ALL, node); + BWRITERSP_WRITEMASK_ALL, v->initializer.args[0]); + d3dcompiler_free(v->initializer.args); list_add_tail(statements_list, &assignment->entry); - d3dcompiler_free(v->initializer); } d3dcompiler_free(v); } @@ -718,11 +717,11 @@ static struct list *gen_struct_fields(struct hlsl_type *type, DWORD modifiers, s field->name = v->name; field->modifiers = modifiers; field->semantic = v->semantic; - if (v->initializer) + if (v->initializer.args_count) { hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, "struct field with an initializer.\n"); - free_instr_list(v->initializer); + free_parse_initializer(&v->initializer); } list_add_tail(list, &field->entry); d3dcompiler_free(v); @@ -905,6 +904,7 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr struct list *list; struct parse_function function; struct parse_parameter parameter; + struct parse_initializer initializer; struct parse_variable_def *variable_def; struct parse_if_body if_body; enum parse_unary_op unary_op; @@ -1028,8 +1028,8 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr %type <type> unnamed_struct_spec %type <list> type_specs %type <variable_def> type_spec -%type <list> complex_initializer -%type <list> initializer_expr_list +%type <initializer> complex_initializer +%type <initializer> initializer_expr_list %type <instr> initializer_expr %type <modifiers> var_modifiers %type <list> field @@ -1675,9 +1675,10 @@ var_modifiers: /* Empty */
complex_initializer: initializer_expr { - $$ = d3dcompiler_alloc(sizeof(*$$)); - list_init($$); - list_add_head($$, &$1->entry); + $$.args_count = 1; + if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args)))) + YYABORT; + $$.args[0] = $1; } | '{' initializer_expr_list '}' { @@ -1695,14 +1696,17 @@ initializer_expr: assignment_expr
initializer_expr_list: initializer_expr { - $$ = d3dcompiler_alloc(sizeof(*$$)); - list_init($$); - list_add_head($$, &$1->entry); + $$.args_count = 1; + if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args)))) + YYABORT; + $$.args[0] = $1; } | initializer_expr_list ',' initializer_expr { $$ = $1; - list_add_tail($$, &$3->entry); + if (!($$.args = d3dcompiler_realloc($$.args, ($$.args_count + 1) * sizeof(*$$.args)))) + YYABORT; + $$.args[$$.args_count++] = $3; }
boolean: KW_TRUE @@ -2080,7 +2084,6 @@ postfix_expr: primary_expr | var_modifiers type '(' initializer_expr_list ')' { struct hlsl_ir_constructor *constructor; - struct hlsl_ir_node *instr;
TRACE("%s constructor.\n", debug_hlsl_type($2)); if ($1) @@ -2097,25 +2100,22 @@ postfix_expr: primary_expr set_parse_status(&hlsl_ctx.status, PARSE_ERR); YYABORT; } - if ($2->dimx * $2->dimy != initializer_size($4)) + if ($2->dimx * $2->dimy != initializer_size(&$4)) { hlsl_message("Line %u: wrong number of components in constructor.\n", hlsl_ctx.line_no); set_parse_status(&hlsl_ctx.status, PARSE_ERR); YYABORT; } + assert($4.args_count <= ARRAY_SIZE(constructor->args));
constructor = d3dcompiler_alloc(sizeof(*constructor)); constructor->node.type = HLSL_IR_CONSTRUCTOR; set_location(&constructor->node.loc, &@3); constructor->node.data_type = $2; - constructor->args_count = 0; - LIST_FOR_EACH_ENTRY(instr, $4, struct hlsl_ir_node, entry) - { - constructor->args[constructor->args_count++] = instr; - } - d3dcompiler_free($4); - + constructor->args_count = $4.args_count; + memcpy(constructor->args, $4.args, $4.args_count * sizeof(*$4.args)); + d3dcompiler_free($4.args); $$ = &constructor->node; }
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/utils.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 742b2623ddb..1dbb9152072 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1277,19 +1277,10 @@ static struct hlsl_type *expr_common_type(struct hlsl_type *t1, struct hlsl_type static struct hlsl_ir_node *implicit_conversion(struct hlsl_ir_node *node, struct hlsl_type *type, struct source_location *loc) { - struct hlsl_ir_expr *cast; - struct hlsl_ir_node *operands[3]; - if (compare_hlsl_types(node->data_type, type)) return node; TRACE("Implicit conversion of expression to %s\n", debug_hlsl_type(type)); - operands[0] = node; - operands[1] = operands[2] = NULL; - cast = new_expr(HLSL_IR_UNOP_CAST, operands, loc); - if (!cast) - return NULL; - cast->node.data_type = type; - return &cast->node; + return &new_cast(node, type, loc)->node; }
struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **operands,
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
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,
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/d3dcompiler_private.h | 29 +--- dlls/d3dcompiler_43/hlsl.y | 22 ++-- dlls/d3dcompiler_43/utils.c | 153 +--------------------- 3 files changed, 21 insertions(+), 183 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 7439e4aeebc..0506b16b3a2 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -1142,28 +1142,6 @@ struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **ope struct source_location *loc) DECLSPEC_HIDDEN; struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_mul(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_div(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_mod(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_add(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_sub(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_lt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_gt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_le(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_ge(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_eq(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; -struct hlsl_ir_expr *hlsl_ne(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) DECLSPEC_HIDDEN; struct hlsl_ir_deref *new_var_deref(struct hlsl_ir_var *var) DECLSPEC_HIDDEN; struct hlsl_ir_deref *new_record_deref(struct hlsl_ir_node *record, struct hlsl_struct_field *field) DECLSPEC_HIDDEN; struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assign_op assign_op, @@ -1193,6 +1171,13 @@ static inline struct hlsl_ir_node *new_unary_expr(enum hlsl_ir_expr_op op, return &new_expr(op, operands, &loc)->node; }
+static inline struct hlsl_ir_node *new_binary_expr(enum hlsl_ir_expr_op op, + struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, struct source_location loc) +{ + struct hlsl_ir_node *operands[3] = {op1, op2}; + return &new_expr(op, operands, &loc)->node; +} + #define MAKE_TAG(ch0, ch1, ch2, ch3) \ ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \ ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 )) diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 5e74ec6d267..5585b899463 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -2214,21 +2214,21 @@ mul_expr: unary_expr struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_mul($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_MUL, $1, $3, loc); } | mul_expr '/' unary_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_div($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_DIV, $1, $3, loc); } | mul_expr '%' unary_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_mod($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_MOD, $1, $3, loc); }
add_expr: mul_expr @@ -2240,14 +2240,14 @@ add_expr: mul_expr struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_add($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_ADD, $1, $3, loc); } | add_expr '-' mul_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_sub($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_SUB, $1, $3, loc); }
shift_expr: add_expr @@ -2272,28 +2272,28 @@ relational_expr: shift_expr struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_lt($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_LESS, $1, $3, loc); } | relational_expr '>' shift_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_gt($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_GREATER, $1, $3, loc); } | relational_expr OP_LE shift_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_le($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_LEQUAL, $1, $3, loc); } | relational_expr OP_GE shift_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_ge($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_GEQUAL, $1, $3, loc); }
equality_expr: relational_expr @@ -2305,14 +2305,14 @@ equality_expr: relational_expr struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_eq($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_EQUAL, $1, $3, loc); } | equality_expr OP_NE relational_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = &hlsl_ne($1, $3, &loc)->node; + $$ = new_binary_expr(HLSL_IR_BINOP_NEQUAL, $1, $3, loc); }
bitand_expr: equality_expr diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 51042984906..d2275da97a6 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1351,149 +1351,6 @@ struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, return expr_from_node(cast); }
-struct hlsl_ir_expr *hlsl_mul(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_MUL, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_div(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_DIV, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_mod(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_MOD, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_add(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_ADD, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_sub(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_SUB, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_lt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_LESS, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_gt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_GREATER, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_le(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_LEQUAL, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_ge(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_GEQUAL, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_eq(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_EQUAL, ops, loc); - return expr; -} - -struct hlsl_ir_expr *hlsl_ne(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, - struct source_location *loc) -{ - struct hlsl_ir_expr *expr; - struct hlsl_ir_node *ops[3]; - - ops[0] = op1; - ops[1] = op2; - ops[2] = NULL; - expr = new_expr(HLSL_IR_BINOP_NEQUAL, ops, loc); - return expr; -} - struct hlsl_ir_deref *new_var_deref(struct hlsl_ir_var *var) { struct hlsl_ir_deref *deref = d3dcompiler_alloc(sizeof(*deref)); @@ -1553,7 +1410,6 @@ static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op) struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assign_op assign_op, DWORD writemask, struct hlsl_ir_node *right) { - struct hlsl_ir_expr *expr; struct hlsl_ir_assignment *assign = d3dcompiler_alloc(sizeof(*assign)); struct hlsl_type *type; struct hlsl_ir_node *lhs, *rhs; @@ -1643,8 +1499,8 @@ struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assig assign->lhs = lhs; if (assign_op != ASSIGN_OP_ASSIGN) { - struct hlsl_ir_node *operands[3]; enum hlsl_ir_expr_op op = op_from_assignment(assign_op); + struct hlsl_ir_node *expr;
if (lhs->type != HLSL_IR_DEREF || deref_from_node(lhs)->type != HLSL_IR_DEREF_VAR) { @@ -1657,11 +1513,8 @@ struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assig
TRACE("Adding an expression for the compound assignment.\n"); new_deref = new_var_deref(lhs_deref->v.var); - operands[0] = &new_deref->node; - operands[1] = rhs; - operands[2] = NULL; - expr = new_expr(op, operands, &left->loc); - assign->rhs = &expr->node; + expr = new_binary_expr(op, &new_deref->node, rhs, left->loc); + assign->rhs = expr; } } else
Signed-off-by: Matteo Bruni mbruni@codeweavers.com