Commit 2dc666c9 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

d3dcompiler: Add a helper to initialize the hlsl_ir_node structure.

parent 1028a5c1
...@@ -1077,6 +1077,14 @@ static inline struct hlsl_ir_node *node_from_list(struct list *list) ...@@ -1077,6 +1077,14 @@ static inline struct hlsl_ir_node *node_from_list(struct list *list)
return LIST_ENTRY(list_tail(list), struct hlsl_ir_node, entry); return LIST_ENTRY(list_tail(list), struct hlsl_ir_node, entry);
} }
static inline void init_node(struct hlsl_ir_node *node, enum hlsl_ir_node_type type,
struct hlsl_type *data_type, struct source_location loc)
{
node->type = type;
node->data_type = data_type;
node->loc = loc;
}
BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN; BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN;
struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN; struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN;
void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN; void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
...@@ -1096,8 +1104,6 @@ struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, ...@@ -1096,8 +1104,6 @@ struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type,
struct source_location *loc) DECLSPEC_HIDDEN; struct source_location *loc) DECLSPEC_HIDDEN;
struct hlsl_ir_node *implicit_conversion(struct hlsl_ir_node *node, struct hlsl_type *type, struct hlsl_ir_node *implicit_conversion(struct hlsl_ir_node *node, struct hlsl_type *type,
struct source_location *loc) DECLSPEC_HIDDEN; 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, struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assign_op assign_op,
struct hlsl_ir_node *right) DECLSPEC_HIDDEN; struct hlsl_ir_node *right) DECLSPEC_HIDDEN;
void push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN; void push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
......
...@@ -1327,17 +1327,10 @@ struct hlsl_ir_node *implicit_conversion(struct hlsl_ir_node *node, struct hlsl_ ...@@ -1327,17 +1327,10 @@ struct hlsl_ir_node *implicit_conversion(struct hlsl_ir_node *node, struct hlsl_
struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **operands, struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **operands,
struct source_location *loc) struct source_location *loc)
{ {
struct hlsl_ir_expr *expr = d3dcompiler_alloc(sizeof(*expr)); struct hlsl_ir_expr *expr;
struct hlsl_type *type; struct hlsl_type *type;
unsigned int i; unsigned int i;
if (!expr)
{
ERR("Out of memory\n");
return NULL;
}
expr->node.type = HLSL_IR_EXPR;
expr->node.loc = *loc;
type = operands[0]->data_type; type = operands[0]->data_type;
for (i = 1; i <= 2; ++i) for (i = 1; i <= 2; ++i)
{ {
...@@ -1345,10 +1338,7 @@ struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **ope ...@@ -1345,10 +1338,7 @@ struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **ope
break; break;
type = expr_common_type(type, operands[i]->data_type, loc); type = expr_common_type(type, operands[i]->data_type, loc);
if (!type) if (!type)
{
d3dcompiler_free(expr);
return NULL; return NULL;
}
} }
for (i = 0; i <= 2; ++i) for (i = 0; i <= 2; ++i)
{ {
...@@ -1366,14 +1356,14 @@ struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **ope ...@@ -1366,14 +1356,14 @@ struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **ope
} }
if (!(cast = new_cast(operands[i], type, &operands[i]->loc))) if (!(cast = new_cast(operands[i], type, &operands[i]->loc)))
{
d3dcompiler_free(expr);
return NULL; return NULL;
}
list_add_after(&operands[i]->entry, &cast->node.entry); list_add_after(&operands[i]->entry, &cast->node.entry);
operands[i] = &cast->node; operands[i] = &cast->node;
} }
expr->node.data_type = type;
if (!(expr = d3dcompiler_alloc(sizeof(*expr))))
return NULL;
init_node(&expr->node, HLSL_IR_EXPR, type, *loc);
expr->op = op; expr->op = op;
expr->operands[0] = operands[0]; expr->operands[0] = operands[0];
expr->operands[1] = operands[1]; expr->operands[1] = operands[1];
...@@ -1393,39 +1383,6 @@ struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, ...@@ -1393,39 +1383,6 @@ struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type,
return expr_from_node(cast); return expr_from_node(cast);
} }
struct hlsl_ir_deref *new_var_deref(struct hlsl_ir_var *var)
{
struct hlsl_ir_deref *deref = d3dcompiler_alloc(sizeof(*deref));
if (!deref)
{
ERR("Out of memory.\n");
return NULL;
}
deref->node.type = HLSL_IR_DEREF;
deref->node.data_type = var->data_type;
deref->src.type = HLSL_IR_DEREF_VAR;
deref->src.v.var = var;
return deref;
}
struct hlsl_ir_deref *new_record_deref(struct hlsl_ir_node *record, struct hlsl_struct_field *field)
{
struct hlsl_ir_deref *deref = d3dcompiler_alloc(sizeof(*deref));
if (!deref)
{
ERR("Out of memory.\n");
return NULL;
}
deref->node.type = HLSL_IR_DEREF;
deref->node.data_type = field->type;
deref->src.type = HLSL_IR_DEREF_RECORD;
deref->src.v.record.record = record;
deref->src.v.record.field = field;
return deref;
}
static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op) static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op)
{ {
static const enum hlsl_ir_expr_op ops[] = static const enum hlsl_ir_expr_op ops[] =
...@@ -1593,9 +1550,8 @@ struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *lhs, enum parse_assign ...@@ -1593,9 +1550,8 @@ struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *lhs, enum parse_assign
type_class = lhs->data_type->type; type_class = lhs->data_type->type;
type = new_hlsl_type(NULL, type_class, lhs->data_type->base_type, dimx, 1); type = new_hlsl_type(NULL, type_class, lhs->data_type->base_type, dimx, 1);
} }
assign->node.type = HLSL_IR_ASSIGNMENT;
assign->node.loc = lhs->loc; init_node(&assign->node, HLSL_IR_ASSIGNMENT, type, lhs->loc);
assign->node.data_type = type;
assign->writemask = writemask; assign->writemask = writemask;
rhs = implicit_conversion(rhs, type, &rhs->loc); rhs = implicit_conversion(rhs, type, &rhs->loc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment