vkd3d-shader: Add a hlsl_ namespace prefix to common functions.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-02-02 16:11:14 -06:00 committed by Alexandre Julliard
parent 0da1401d3d
commit 7c5bd7c776
4 changed files with 308 additions and 299 deletions

View File

@ -36,7 +36,7 @@ void hlsl_report_message(const struct source_location loc,
set_parse_status(&hlsl_ctx.status, PARSE_WARN); set_parse_status(&hlsl_ctx.status, PARSE_WARN);
} }
BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) BOOL hlsl_add_var(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var)
{ {
struct hlsl_ir_var *var; struct hlsl_ir_var *var;
@ -59,7 +59,7 @@ BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL lo
return TRUE; return TRUE;
} }
struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name)
{ {
struct hlsl_ir_var *var; struct hlsl_ir_var *var;
@ -70,10 +70,10 @@ struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name)
} }
if (!scope->upper) if (!scope->upper)
return NULL; return NULL;
return get_variable(scope->upper, name); return hlsl_get_var(scope->upper, name);
} }
void free_declaration(struct hlsl_ir_var *decl) void hlsl_free_var(struct hlsl_ir_var *decl)
{ {
vkd3d_free((void *)decl->name); vkd3d_free((void *)decl->name);
vkd3d_free((void *)decl->semantic); vkd3d_free((void *)decl->semantic);
@ -81,7 +81,7 @@ void free_declaration(struct hlsl_ir_var *decl)
vkd3d_free(decl); vkd3d_free(decl);
} }
struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_class, struct hlsl_type *hlsl_new_type(const char *name, enum hlsl_type_class type_class,
enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) enum hlsl_base_type base_type, unsigned dimx, unsigned dimy)
{ {
struct hlsl_type *type; struct hlsl_type *type;
@ -94,7 +94,7 @@ struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_clas
type->dimx = dimx; type->dimx = dimx;
type->dimy = dimy; type->dimy = dimy;
if (type_class == HLSL_CLASS_MATRIX) if (type_class == HLSL_CLASS_MATRIX)
type->reg_size = is_row_major(type) ? dimy : dimx; type->reg_size = hlsl_type_is_row_major(type) ? dimy : dimx;
else else
type->reg_size = 1; type->reg_size = 1;
@ -103,9 +103,9 @@ struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_clas
return type; return type;
} }
struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) struct hlsl_type *hlsl_new_array_type(struct hlsl_type *basic_type, unsigned int array_size)
{ {
struct hlsl_type *type = new_hlsl_type(NULL, HLSL_CLASS_ARRAY, HLSL_TYPE_FLOAT, 1, 1); struct hlsl_type *type = hlsl_new_type(NULL, HLSL_CLASS_ARRAY, HLSL_TYPE_FLOAT, 1, 1);
if (!type) if (!type)
return NULL; return NULL;
@ -126,7 +126,7 @@ static DWORD get_array_size(const struct hlsl_type *type)
return 1; return 1;
} }
struct hlsl_type *new_struct_type(const char *name, struct list *fields) struct hlsl_type *hlsl_new_struct_type(const char *name, struct list *fields)
{ {
struct hlsl_struct_field *field; struct hlsl_struct_field *field;
unsigned int reg_size = 0; unsigned int reg_size = 0;
@ -154,7 +154,7 @@ struct hlsl_type *new_struct_type(const char *name, struct list *fields)
return type; return type;
} }
struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, BOOL recursive)
{ {
struct rb_entry *entry = rb_get(&scope->types, name); struct rb_entry *entry = rb_get(&scope->types, name);
@ -162,16 +162,16 @@ struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recu
return RB_ENTRY_VALUE(entry, struct hlsl_type, scope_entry); return RB_ENTRY_VALUE(entry, struct hlsl_type, scope_entry);
if (recursive && scope->upper) if (recursive && scope->upper)
return get_type(scope->upper, name, recursive); return hlsl_get_type(scope->upper, name, recursive);
return NULL; return NULL;
} }
BOOL find_function(const char *name) BOOL hlsl_get_function(const char *name)
{ {
return rb_get(&hlsl_ctx.functions, name) != NULL; return rb_get(&hlsl_ctx.functions, name) != NULL;
} }
unsigned int components_count_type(struct hlsl_type *type) unsigned int hlsl_type_component_count(struct hlsl_type *type)
{ {
struct hlsl_struct_field *field; struct hlsl_struct_field *field;
unsigned int count = 0; unsigned int count = 0;
@ -182,7 +182,7 @@ unsigned int components_count_type(struct hlsl_type *type)
} }
if (type->type == HLSL_CLASS_ARRAY) if (type->type == HLSL_CLASS_ARRAY)
{ {
return components_count_type(type->e.array.type) * type->e.array.elements_count; return hlsl_type_component_count(type->e.array.type) * type->e.array.elements_count;
} }
if (type->type != HLSL_CLASS_STRUCT) if (type->type != HLSL_CLASS_STRUCT)
{ {
@ -192,12 +192,12 @@ unsigned int components_count_type(struct hlsl_type *type)
LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry)
{ {
count += components_count_type(field->type); count += hlsl_type_component_count(field->type);
} }
return count; return count;
} }
BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) BOOL hlsl_type_compare(const struct hlsl_type *t1, const struct hlsl_type *t2)
{ {
if (t1 == t2) if (t1 == t2)
return TRUE; return TRUE;
@ -226,7 +226,7 @@ BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2)
{ {
t1field = LIST_ENTRY(t1cur, struct hlsl_struct_field, entry); t1field = LIST_ENTRY(t1cur, struct hlsl_struct_field, entry);
t2field = LIST_ENTRY(t2cur, struct hlsl_struct_field, entry); t2field = LIST_ENTRY(t2cur, struct hlsl_struct_field, entry);
if (!compare_hlsl_types(t1field->type, t2field->type)) if (!hlsl_type_compare(t1field->type, t2field->type))
return FALSE; return FALSE;
if (strcmp(t1field->name, t2field->name)) if (strcmp(t1field->name, t2field->name))
return FALSE; return FALSE;
@ -238,12 +238,12 @@ BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2)
} }
if (t1->type == HLSL_CLASS_ARRAY) if (t1->type == HLSL_CLASS_ARRAY)
return t1->e.array.elements_count == t2->e.array.elements_count return t1->e.array.elements_count == t2->e.array.elements_count
&& compare_hlsl_types(t1->e.array.type, t2->e.array.type); && hlsl_type_compare(t1->e.array.type, t2->e.array.type);
return TRUE; return TRUE;
} }
struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_majority) struct hlsl_type *hlsl_type_clone(struct hlsl_type *old, unsigned int default_majority)
{ {
struct hlsl_struct_field *old_field, *field; struct hlsl_struct_field *old_field, *field;
struct hlsl_type *type; struct hlsl_type *type;
@ -271,7 +271,7 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_ma
switch (old->type) switch (old->type)
{ {
case HLSL_CLASS_ARRAY: case HLSL_CLASS_ARRAY:
type->e.array.type = clone_hlsl_type(old->e.array.type, default_majority); type->e.array.type = hlsl_type_clone(old->e.array.type, default_majority);
type->e.array.elements_count = old->e.array.elements_count; type->e.array.elements_count = old->e.array.elements_count;
type->reg_size = type->e.array.elements_count * type->e.array.type->reg_size; type->reg_size = type->e.array.elements_count * type->e.array.type->reg_size;
break; break;
@ -302,7 +302,7 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_ma
vkd3d_free(type); vkd3d_free(type);
return NULL; return NULL;
} }
field->type = clone_hlsl_type(old_field->type, default_majority); field->type = hlsl_type_clone(old_field->type, default_majority);
field->name = vkd3d_strdup(old_field->name); field->name = vkd3d_strdup(old_field->name);
if (old_field->semantic) if (old_field->semantic)
field->semantic = vkd3d_strdup(old_field->semantic); field->semantic = vkd3d_strdup(old_field->semantic);
@ -316,7 +316,7 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_ma
} }
case HLSL_CLASS_MATRIX: case HLSL_CLASS_MATRIX:
type->reg_size = is_row_major(type) ? type->dimy : type->dimx; type->reg_size = hlsl_type_is_row_major(type) ? type->dimy : type->dimx;
break; break;
default: default:
@ -328,19 +328,19 @@ struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_ma
return type; return type;
} }
struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ir_node *node, struct hlsl_type *type,
struct source_location *loc) struct source_location *loc)
{ {
struct hlsl_ir_node *cast; struct hlsl_ir_node *cast;
cast = new_unary_expr(HLSL_IR_UNOP_CAST, node, *loc); cast = hlsl_new_unary_expr(HLSL_IR_UNOP_CAST, node, *loc);
if (cast) if (cast)
cast->data_type = type; cast->data_type = type;
return expr_from_node(cast); return hlsl_ir_expr(cast);
} }
struct hlsl_ir_var *new_var(const char *name, struct hlsl_type *type, const struct source_location loc, struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct source_location loc,
const char *semantic, unsigned int modifiers, const struct reg_reservation *reg_reservation) const char *semantic, unsigned int modifiers, const struct hlsl_reg_reservation *reg_reservation)
{ {
struct hlsl_ir_var *var; struct hlsl_ir_var *var;
@ -359,9 +359,9 @@ struct hlsl_ir_var *new_var(const char *name, struct hlsl_type *type, const stru
return var; return var;
} }
struct hlsl_ir_var *new_synthetic_var(const char *name, struct hlsl_type *type, const struct source_location loc) struct hlsl_ir_var *hlsl_new_synthetic_var(const char *name, struct hlsl_type *type, const struct source_location loc)
{ {
struct hlsl_ir_var *var = new_var(vkd3d_strdup(name), type, loc, NULL, 0, NULL); struct hlsl_ir_var *var = hlsl_new_var(vkd3d_strdup(name), type, loc, NULL, 0, NULL);
if (var) if (var)
list_add_tail(&hlsl_ctx.globals->vars, &var->scope_entry); list_add_tail(&hlsl_ctx.globals->vars, &var->scope_entry);
@ -373,7 +373,7 @@ static BOOL type_is_single_reg(const struct hlsl_type *type)
return type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR; return type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR;
} }
struct hlsl_ir_assignment *new_assignment(struct hlsl_ir_var *var, struct hlsl_ir_node *offset, struct hlsl_ir_assignment *hlsl_new_assignment(struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
struct hlsl_ir_node *rhs, unsigned int writemask, struct source_location loc) struct hlsl_ir_node *rhs, unsigned int writemask, struct source_location loc)
{ {
struct hlsl_ir_assignment *assign; struct hlsl_ir_assignment *assign;
@ -392,12 +392,12 @@ struct hlsl_ir_assignment *new_assignment(struct hlsl_ir_var *var, struct hlsl_i
return assign; return assign;
} }
struct hlsl_ir_assignment *new_simple_assignment(struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs) struct hlsl_ir_assignment *hlsl_new_simple_assignment(struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs)
{ {
return new_assignment(lhs, NULL, rhs, 0, rhs->loc); return hlsl_new_assignment(lhs, NULL, rhs, 0, rhs->loc);
} }
struct hlsl_ir_constant *new_uint_constant(unsigned int n, const struct source_location loc) struct hlsl_ir_constant *hlsl_new_uint_constant(unsigned int n, const struct source_location loc)
{ {
struct hlsl_ir_constant *c; struct hlsl_ir_constant *c;
@ -408,7 +408,7 @@ struct hlsl_ir_constant *new_uint_constant(unsigned int n, const struct source_l
return c; return c;
} }
struct hlsl_ir_node *new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, struct source_location loc) struct hlsl_ir_node *hlsl_new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, struct source_location loc)
{ {
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
@ -420,12 +420,11 @@ struct hlsl_ir_node *new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node
return &expr->node; return &expr->node;
} }
struct hlsl_ir_node *new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *hlsl_new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2)
struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2)
{ {
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
assert(compare_hlsl_types(arg1->data_type, arg2->data_type)); assert(hlsl_type_compare(arg1->data_type, arg2->data_type));
if (!(expr = vkd3d_calloc(1, sizeof(*expr)))) if (!(expr = vkd3d_calloc(1, sizeof(*expr))))
return NULL; return NULL;
@ -436,7 +435,7 @@ struct hlsl_ir_node *new_binary_expr(enum hlsl_ir_expr_op op,
return &expr->node; return &expr->node;
} }
struct hlsl_ir_if *new_if(struct hlsl_ir_node *condition, struct source_location loc) struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct source_location loc)
{ {
struct hlsl_ir_if *iff; struct hlsl_ir_if *iff;
@ -449,7 +448,7 @@ struct hlsl_ir_if *new_if(struct hlsl_ir_node *condition, struct source_location
return iff; return iff;
} }
struct hlsl_ir_load *new_var_load(struct hlsl_ir_var *var, const struct source_location loc) struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct source_location loc)
{ {
struct hlsl_ir_load *load; struct hlsl_ir_load *load;
@ -460,7 +459,7 @@ struct hlsl_ir_load *new_var_load(struct hlsl_ir_var *var, const struct source_l
return load; return load;
} }
struct hlsl_ir_swizzle *new_swizzle(DWORD s, unsigned int components, struct hlsl_ir_swizzle *hlsl_new_swizzle(DWORD s, unsigned int components,
struct hlsl_ir_node *val, struct source_location *loc) struct hlsl_ir_node *val, struct source_location *loc)
{ {
struct hlsl_ir_swizzle *swizzle; struct hlsl_ir_swizzle *swizzle;
@ -468,18 +467,18 @@ struct hlsl_ir_swizzle *new_swizzle(DWORD s, unsigned int components,
if (!(swizzle = vkd3d_malloc(sizeof(*swizzle)))) if (!(swizzle = vkd3d_malloc(sizeof(*swizzle))))
return NULL; return NULL;
init_node(&swizzle->node, HLSL_IR_SWIZZLE, init_node(&swizzle->node, HLSL_IR_SWIZZLE,
new_hlsl_type(NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1), *loc); hlsl_new_type(NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1), *loc);
hlsl_src_from_node(&swizzle->val, val); hlsl_src_from_node(&swizzle->val, val);
swizzle->swizzle = s; swizzle->swizzle = s;
return swizzle; return swizzle;
} }
BOOL type_is_void(const struct hlsl_type *type) BOOL hlsl_type_is_void(const struct hlsl_type *type)
{ {
return type->type == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_VOID; return type->type == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_VOID;
} }
struct hlsl_ir_function_decl *new_func_decl(struct hlsl_type *return_type, struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_type *return_type,
struct list *parameters, const char *semantic, struct source_location loc) struct list *parameters, const char *semantic, struct source_location loc)
{ {
struct hlsl_ir_function_decl *decl; struct hlsl_ir_function_decl *decl;
@ -491,13 +490,13 @@ struct hlsl_ir_function_decl *new_func_decl(struct hlsl_type *return_type,
decl->semantic = semantic; decl->semantic = semantic;
decl->loc = loc; decl->loc = loc;
if (!type_is_void(return_type)) if (!hlsl_type_is_void(return_type))
{ {
struct hlsl_ir_var *return_var; struct hlsl_ir_var *return_var;
char name[28]; char name[28];
sprintf(name, "<retval-%p>", decl); sprintf(name, "<retval-%p>", decl);
if (!(return_var = new_synthetic_var(name, return_type, loc))) if (!(return_var = hlsl_new_synthetic_var(name, return_type, loc)))
{ {
vkd3d_free(decl); vkd3d_free(decl);
return NULL; return NULL;
@ -524,7 +523,7 @@ static int compare_hlsl_types_rb(const void *key, const struct rb_entry *entry)
return strcmp(name, type->name); return strcmp(name, type->name);
} }
void push_scope(struct hlsl_parse_ctx *ctx) void hlsl_push_scope(struct hlsl_parse_ctx *ctx)
{ {
struct hlsl_scope *new_scope; struct hlsl_scope *new_scope;
@ -538,7 +537,7 @@ void push_scope(struct hlsl_parse_ctx *ctx)
list_add_tail(&ctx->scopes, &new_scope->entry); list_add_tail(&ctx->scopes, &new_scope->entry);
} }
BOOL pop_scope(struct hlsl_parse_ctx *ctx) BOOL hlsl_pop_scope(struct hlsl_parse_ctx *ctx)
{ {
struct hlsl_scope *prev_scope = ctx->cur_scope->upper; struct hlsl_scope *prev_scope = ctx->cur_scope->upper;
@ -638,7 +637,7 @@ void init_functions_tree(struct rb_tree *funcs)
rb_init(&hlsl_ctx.functions, compare_function_rb); rb_init(&hlsl_ctx.functions, compare_function_rb);
} }
const char *debug_base_type(const struct hlsl_type *type) const char *hlsl_base_type_to_string(const struct hlsl_type *type)
{ {
const char *name = "(unknown)"; const char *name = "(unknown)";
@ -678,11 +677,11 @@ const char *debug_hlsl_type(const struct hlsl_type *type)
if (type->type == HLSL_CLASS_ARRAY) if (type->type == HLSL_CLASS_ARRAY)
{ {
name = debug_base_type(type->e.array.type); return vkd3d_dbg_sprintf("%s[%u]", hlsl_base_type_to_string(type->e.array.type),
return vkd3d_dbg_sprintf("%s[%u]", name, type->e.array.elements_count); type->e.array.elements_count);
} }
name = debug_base_type(type); name = hlsl_base_type_to_string(type);
if (type->type == HLSL_CLASS_SCALAR) if (type->type == HLSL_CLASS_SCALAR)
return vkd3d_dbg_sprintf("%s", name); return vkd3d_dbg_sprintf("%s", name);
@ -693,7 +692,7 @@ const char *debug_hlsl_type(const struct hlsl_type *type)
return "unexpected_type"; return "unexpected_type";
} }
const char *debug_modifiers(DWORD modifiers) const char *hlsl_debug_modifiers(DWORD modifiers)
{ {
char string[110]; char string[110];
@ -730,7 +729,7 @@ const char *debug_modifiers(DWORD modifiers)
return vkd3d_dbg_sprintf("%s", string[0] ? string + 1 : ""); return vkd3d_dbg_sprintf("%s", string[0] ? string + 1 : "");
} }
const char *debug_node_type(enum hlsl_ir_node_type type) const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type)
{ {
static const char * const names[] = static const char * const names[] =
{ {
@ -773,7 +772,7 @@ static void debug_dump_src(struct vkd3d_string_buffer *buffer, const struct hlsl
static void debug_dump_ir_var(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var) static void debug_dump_ir_var(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var)
{ {
if (var->modifiers) if (var->modifiers)
vkd3d_string_buffer_printf(buffer, "%s ", debug_modifiers(var->modifiers)); vkd3d_string_buffer_printf(buffer, "%s ", hlsl_debug_modifiers(var->modifiers));
vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(var->data_type), var->name); vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(var->data_type), var->name);
if (var->semantic) if (var->semantic)
vkd3d_string_buffer_printf(buffer, " : %s", var->semantic); vkd3d_string_buffer_printf(buffer, " : %s", var->semantic);
@ -856,7 +855,8 @@ static void debug_dump_ir_constant(struct vkd3d_string_buffer *buffer, const str
break; break;
default: default:
vkd3d_string_buffer_printf(buffer, "Constants of type %s not supported\n", debug_base_type(type)); vkd3d_string_buffer_printf(buffer, "Constants of type %s not supported\n",
hlsl_base_type_to_string(type));
} }
} }
if (type->dimx != 1) if (type->dimx != 1)
@ -1025,43 +1025,43 @@ static void debug_dump_instr(struct vkd3d_string_buffer *buffer, const struct hl
switch (instr->type) switch (instr->type)
{ {
case HLSL_IR_ASSIGNMENT: case HLSL_IR_ASSIGNMENT:
debug_dump_ir_assignment(buffer, assignment_from_node(instr)); debug_dump_ir_assignment(buffer, hlsl_ir_assignment(instr));
break; break;
case HLSL_IR_CONSTANT: case HLSL_IR_CONSTANT:
debug_dump_ir_constant(buffer, constant_from_node(instr)); debug_dump_ir_constant(buffer, hlsl_ir_constant(instr));
break; break;
case HLSL_IR_EXPR: case HLSL_IR_EXPR:
debug_dump_ir_expr(buffer, expr_from_node(instr)); debug_dump_ir_expr(buffer, hlsl_ir_expr(instr));
break; break;
case HLSL_IR_IF: case HLSL_IR_IF:
debug_dump_ir_if(buffer, if_from_node(instr)); debug_dump_ir_if(buffer, hlsl_ir_if(instr));
break; break;
case HLSL_IR_JUMP: case HLSL_IR_JUMP:
debug_dump_ir_jump(buffer, jump_from_node(instr)); debug_dump_ir_jump(buffer, hlsl_ir_jump(instr));
break; break;
case HLSL_IR_LOAD: case HLSL_IR_LOAD:
debug_dump_deref(buffer, &load_from_node(instr)->src); debug_dump_deref(buffer, &hlsl_ir_load(instr)->src);
break; break;
case HLSL_IR_LOOP: case HLSL_IR_LOOP:
debug_dump_ir_loop(buffer, loop_from_node(instr)); debug_dump_ir_loop(buffer, hlsl_ir_loop(instr));
break; break;
case HLSL_IR_SWIZZLE: case HLSL_IR_SWIZZLE:
debug_dump_ir_swizzle(buffer, swizzle_from_node(instr)); debug_dump_ir_swizzle(buffer, hlsl_ir_swizzle(instr));
break; break;
default: default:
vkd3d_string_buffer_printf(buffer, "<No dump function for %s>", debug_node_type(instr->type)); vkd3d_string_buffer_printf(buffer, "<No dump function for %s>", hlsl_node_type_to_string(instr->type));
} }
} }
void debug_dump_ir_function_decl(const struct hlsl_ir_function_decl *func) void hlsl_dump_function(const struct hlsl_ir_function_decl *func)
{ {
struct vkd3d_string_buffer buffer; struct vkd3d_string_buffer buffer;
struct hlsl_ir_var *param; struct hlsl_ir_var *param;
@ -1083,7 +1083,7 @@ void debug_dump_ir_function_decl(const struct hlsl_ir_function_decl *func)
vkd3d_string_buffer_cleanup(&buffer); vkd3d_string_buffer_cleanup(&buffer);
} }
void free_hlsl_type(struct hlsl_type *type) void hlsl_free_type(struct hlsl_type *type)
{ {
struct hlsl_struct_field *field, *next_field; struct hlsl_struct_field *field, *next_field;
@ -1100,7 +1100,7 @@ void free_hlsl_type(struct hlsl_type *type)
vkd3d_free(type); vkd3d_free(type);
} }
void free_instr_list(struct list *list) void hlsl_free_instr_list(struct list *list)
{ {
struct hlsl_ir_node *node, *next_node; struct hlsl_ir_node *node, *next_node;
@ -1109,7 +1109,7 @@ void free_instr_list(struct list *list)
/* Iterate in reverse, to avoid use-after-free when unlinking sources from /* Iterate in reverse, to avoid use-after-free when unlinking sources from
* the "uses" list. */ * the "uses" list. */
LIST_FOR_EACH_ENTRY_SAFE_REV(node, next_node, list, struct hlsl_ir_node, entry) LIST_FOR_EACH_ENTRY_SAFE_REV(node, next_node, list, struct hlsl_ir_node, entry)
free_instr(node); hlsl_free_instr(node);
vkd3d_free(list); vkd3d_free(list);
} }
@ -1139,9 +1139,9 @@ static void free_ir_if(struct hlsl_ir_if *if_node)
struct hlsl_ir_node *node, *next_node; struct hlsl_ir_node *node, *next_node;
LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &if_node->then_instrs, struct hlsl_ir_node, entry) LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &if_node->then_instrs, struct hlsl_ir_node, entry)
free_instr(node); hlsl_free_instr(node);
LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &if_node->else_instrs, struct hlsl_ir_node, entry) LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &if_node->else_instrs, struct hlsl_ir_node, entry)
free_instr(node); hlsl_free_instr(node);
hlsl_src_remove(&if_node->condition); hlsl_src_remove(&if_node->condition);
vkd3d_free(if_node); vkd3d_free(if_node);
} }
@ -1162,7 +1162,7 @@ static void free_ir_loop(struct hlsl_ir_loop *loop)
struct hlsl_ir_node *node, *next_node; struct hlsl_ir_node *node, *next_node;
LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &loop->body, struct hlsl_ir_node, entry) LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &loop->body, struct hlsl_ir_node, entry)
free_instr(node); hlsl_free_instr(node);
vkd3d_free(loop); vkd3d_free(loop);
} }
@ -1172,44 +1172,44 @@ static void free_ir_swizzle(struct hlsl_ir_swizzle *swizzle)
vkd3d_free(swizzle); vkd3d_free(swizzle);
} }
void free_instr(struct hlsl_ir_node *node) void hlsl_free_instr(struct hlsl_ir_node *node)
{ {
switch (node->type) switch (node->type)
{ {
case HLSL_IR_ASSIGNMENT: case HLSL_IR_ASSIGNMENT:
free_ir_assignment(assignment_from_node(node)); free_ir_assignment(hlsl_ir_assignment(node));
break; break;
case HLSL_IR_CONSTANT: case HLSL_IR_CONSTANT:
free_ir_constant(constant_from_node(node)); free_ir_constant(hlsl_ir_constant(node));
break; break;
case HLSL_IR_EXPR: case HLSL_IR_EXPR:
free_ir_expr(expr_from_node(node)); free_ir_expr(hlsl_ir_expr(node));
break; break;
case HLSL_IR_IF: case HLSL_IR_IF:
free_ir_if(if_from_node(node)); free_ir_if(hlsl_ir_if(node));
break; break;
case HLSL_IR_JUMP: case HLSL_IR_JUMP:
free_ir_jump(jump_from_node(node)); free_ir_jump(hlsl_ir_jump(node));
break; break;
case HLSL_IR_LOAD: case HLSL_IR_LOAD:
free_ir_load(load_from_node(node)); free_ir_load(hlsl_ir_load(node));
break; break;
case HLSL_IR_LOOP: case HLSL_IR_LOOP:
free_ir_loop(loop_from_node(node)); free_ir_loop(hlsl_ir_loop(node));
break; break;
case HLSL_IR_SWIZZLE: case HLSL_IR_SWIZZLE:
free_ir_swizzle(swizzle_from_node(node)); free_ir_swizzle(hlsl_ir_swizzle(node));
break; break;
default: default:
FIXME("Unsupported node type %s.\n", debug_node_type(node->type)); FIXME("Unsupported node type %s.\n", hlsl_node_type_to_string(node->type));
} }
} }
@ -1217,7 +1217,7 @@ static void free_function_decl(struct hlsl_ir_function_decl *decl)
{ {
vkd3d_free((void *)decl->semantic); vkd3d_free((void *)decl->semantic);
vkd3d_free(decl->parameters); vkd3d_free(decl->parameters);
free_instr_list(decl->body); hlsl_free_instr_list(decl->body);
vkd3d_free(decl); vkd3d_free(decl);
} }
@ -1233,12 +1233,12 @@ static void free_function(struct hlsl_ir_function *func)
vkd3d_free(func); vkd3d_free(func);
} }
void free_function_rb(struct rb_entry *entry, void *context) void hlsl_free_function_rb(struct rb_entry *entry, void *context)
{ {
free_function(RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry)); free_function(RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry));
} }
void add_function_decl(struct rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl, BOOL intrinsic) void hlsl_add_function(struct rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl, BOOL intrinsic)
{ {
struct hlsl_ir_function *func; struct hlsl_ir_function *func;
struct rb_entry *func_entry, *old_entry; struct rb_entry *func_entry, *old_entry;

View File

@ -206,7 +206,7 @@ struct hlsl_src
#define HLSL_MODIFIERS_MAJORITY_MASK (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR) #define HLSL_MODIFIERS_MAJORITY_MASK (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)
struct reg_reservation struct hlsl_reg_reservation
{ {
enum vkd3d_shader_register_type type; enum vkd3d_shader_register_type type;
DWORD regnum; DWORD regnum;
@ -219,7 +219,7 @@ struct hlsl_ir_var
const char *name; const char *name;
const char *semantic; const char *semantic;
unsigned int modifiers; unsigned int modifiers;
const struct reg_reservation *reg_reservation; const struct hlsl_reg_reservation *reg_reservation;
struct list scope_entry, param_entry; struct list scope_entry, param_entry;
unsigned int first_write, last_read; unsigned int first_write, last_read;
@ -404,14 +404,14 @@ struct parse_parameter
struct hlsl_type *type; struct hlsl_type *type;
const char *name; const char *name;
const char *semantic; const char *semantic;
const struct reg_reservation *reg_reservation; const struct hlsl_reg_reservation *reg_reservation;
unsigned int modifiers; unsigned int modifiers;
}; };
struct parse_colon_attribute struct parse_colon_attribute
{ {
const char *semantic; const char *semantic;
struct reg_reservation *reg_reservation; struct hlsl_reg_reservation *reg_reservation;
}; };
struct parse_initializer struct parse_initializer
@ -429,7 +429,7 @@ struct parse_variable_def
char *name; char *name;
unsigned int array_size; unsigned int array_size;
const char *semantic; const char *semantic;
struct reg_reservation *reg_reservation; struct hlsl_reg_reservation *reg_reservation;
struct parse_initializer initializer; struct parse_initializer initializer;
}; };
@ -508,53 +508,49 @@ enum hlsl_error_level
HLSL_LEVEL_NOTE, HLSL_LEVEL_NOTE,
}; };
void hlsl_message(const char *fmt, ...) VKD3D_PRINTF_FUNC(1,2) DECLSPEC_HIDDEN; static inline struct hlsl_ir_assignment *hlsl_ir_assignment(const struct hlsl_ir_node *node)
void hlsl_report_message(const struct source_location loc,
enum hlsl_error_level level, const char *fmt, ...) VKD3D_PRINTF_FUNC(3,4) DECLSPEC_HIDDEN;
static inline struct hlsl_ir_assignment *assignment_from_node(const struct hlsl_ir_node *node)
{ {
assert(node->type == HLSL_IR_ASSIGNMENT); assert(node->type == HLSL_IR_ASSIGNMENT);
return CONTAINING_RECORD(node, struct hlsl_ir_assignment, node); return CONTAINING_RECORD(node, struct hlsl_ir_assignment, node);
} }
static inline struct hlsl_ir_constant *constant_from_node(const struct hlsl_ir_node *node) static inline struct hlsl_ir_constant *hlsl_ir_constant(const struct hlsl_ir_node *node)
{ {
assert(node->type == HLSL_IR_CONSTANT); assert(node->type == HLSL_IR_CONSTANT);
return CONTAINING_RECORD(node, struct hlsl_ir_constant, node); return CONTAINING_RECORD(node, struct hlsl_ir_constant, node);
} }
static inline struct hlsl_ir_expr *expr_from_node(const struct hlsl_ir_node *node) static inline struct hlsl_ir_expr *hlsl_ir_expr(const struct hlsl_ir_node *node)
{ {
assert(node->type == HLSL_IR_EXPR); assert(node->type == HLSL_IR_EXPR);
return CONTAINING_RECORD(node, struct hlsl_ir_expr, node); return CONTAINING_RECORD(node, struct hlsl_ir_expr, node);
} }
static inline struct hlsl_ir_if *if_from_node(const struct hlsl_ir_node *node) static inline struct hlsl_ir_if *hlsl_ir_if(const struct hlsl_ir_node *node)
{ {
assert(node->type == HLSL_IR_IF); assert(node->type == HLSL_IR_IF);
return CONTAINING_RECORD(node, struct hlsl_ir_if, node); return CONTAINING_RECORD(node, struct hlsl_ir_if, node);
} }
static inline struct hlsl_ir_jump *jump_from_node(const struct hlsl_ir_node *node) static inline struct hlsl_ir_jump *hlsl_ir_jump(const struct hlsl_ir_node *node)
{ {
assert(node->type == HLSL_IR_JUMP); assert(node->type == HLSL_IR_JUMP);
return CONTAINING_RECORD(node, struct hlsl_ir_jump, node); return CONTAINING_RECORD(node, struct hlsl_ir_jump, node);
} }
static inline struct hlsl_ir_load *load_from_node(const struct hlsl_ir_node *node) static inline struct hlsl_ir_load *hlsl_ir_load(const struct hlsl_ir_node *node)
{ {
assert(node->type == HLSL_IR_LOAD); assert(node->type == HLSL_IR_LOAD);
return CONTAINING_RECORD(node, struct hlsl_ir_load, node); return CONTAINING_RECORD(node, struct hlsl_ir_load, node);
} }
static inline struct hlsl_ir_loop *loop_from_node(const struct hlsl_ir_node *node) static inline struct hlsl_ir_loop *hlsl_ir_loop(const struct hlsl_ir_node *node)
{ {
assert(node->type == HLSL_IR_LOOP); assert(node->type == HLSL_IR_LOOP);
return CONTAINING_RECORD(node, struct hlsl_ir_loop, node); return CONTAINING_RECORD(node, struct hlsl_ir_loop, node);
} }
static inline struct hlsl_ir_swizzle *swizzle_from_node(const struct hlsl_ir_node *node) static inline struct hlsl_ir_swizzle *hlsl_ir_swizzle(const struct hlsl_ir_node *node)
{ {
assert(node->type == HLSL_IR_SWIZZLE); assert(node->type == HLSL_IR_SWIZZLE);
return CONTAINING_RECORD(node, struct hlsl_ir_swizzle, node); return CONTAINING_RECORD(node, struct hlsl_ir_swizzle, node);
@ -592,61 +588,75 @@ static inline void set_parse_status(enum parse_status *current, enum parse_statu
*current = PARSE_WARN; *current = PARSE_WARN;
} }
struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN;
struct hlsl_ir_assignment *new_assignment(struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
struct hlsl_ir_node *rhs, unsigned int writemask, struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_node *new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1,
struct hlsl_ir_node *arg2) 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_function_decl *new_func_decl(struct hlsl_type *return_type,
struct list *parameters, const char *semantic, struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_if *new_if(struct hlsl_ir_node *condition, struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_assignment *new_simple_assignment(struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs) DECLSPEC_HIDDEN;
struct hlsl_type *new_struct_type(const char *name, struct list *fields) DECLSPEC_HIDDEN;
struct hlsl_ir_swizzle *new_swizzle(DWORD s, unsigned int components,
struct hlsl_ir_node *val, struct source_location *loc) DECLSPEC_HIDDEN;
struct hlsl_ir_var *new_synthetic_var(const char *name, struct hlsl_type *type,
const struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_constant *new_uint_constant(unsigned int n, const struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_node *new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg,
struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_var *new_var(const char *name, struct hlsl_type *type, const struct source_location loc,
const char *semantic, unsigned int modifiers, const struct reg_reservation *reg_reservation) DECLSPEC_HIDDEN;
struct hlsl_ir_load *new_var_load(struct hlsl_ir_var *var, const struct source_location loc) 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;
void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_class,
enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN;
struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_majority) DECLSPEC_HIDDEN;
struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN;
BOOL is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN;
BOOL find_function(const char *name) DECLSPEC_HIDDEN;
unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) DECLSPEC_HIDDEN;
void push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
BOOL pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
void init_functions_tree(struct rb_tree *funcs) DECLSPEC_HIDDEN; void init_functions_tree(struct rb_tree *funcs) DECLSPEC_HIDDEN;
void add_function_decl(struct rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl,
const char *hlsl_base_type_to_string(const struct hlsl_type *type) DECLSPEC_HIDDEN;
const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
const char *hlsl_debug_modifiers(DWORD 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,
BOOL intrinsic) DECLSPEC_HIDDEN; BOOL intrinsic) DECLSPEC_HIDDEN;
BOOL type_is_void(const struct hlsl_type *type) DECLSPEC_HIDDEN; BOOL hlsl_add_var(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN;
int hlsl_compile(enum vkd3d_shader_type type, DWORD major, DWORD minor, const char *entrypoint,
struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context) DECLSPEC_HIDDEN;
void hlsl_dump_function(const struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
void hlsl_free_instr(struct hlsl_ir_node *node) DECLSPEC_HIDDEN;
void hlsl_free_instr_list(struct list *list) DECLSPEC_HIDDEN;
void hlsl_free_function_rb(struct rb_entry *entry, void *context) DECLSPEC_HIDDEN;
void hlsl_free_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
void hlsl_free_var(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
BOOL hlsl_get_function(const char *name) DECLSPEC_HIDDEN;
struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN;
struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN;
struct hlsl_type *hlsl_new_array_type(struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN;
struct hlsl_ir_assignment *hlsl_new_assignment(struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
struct hlsl_ir_node *rhs, unsigned int writemask, struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_node *hlsl_new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1,
struct hlsl_ir_node *arg2) DECLSPEC_HIDDEN;
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ir_node *node, struct hlsl_type *type,
struct source_location *loc) DECLSPEC_HIDDEN;
struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_type *return_type,
struct list *parameters, const char *semantic, struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct source_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(const char *name, struct list *fields) DECLSPEC_HIDDEN;
struct hlsl_ir_swizzle *hlsl_new_swizzle(DWORD s, unsigned int components,
struct hlsl_ir_node *val, struct source_location *loc) DECLSPEC_HIDDEN;
struct hlsl_ir_var *hlsl_new_synthetic_var(const char *name, struct hlsl_type *type,
const struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_type *hlsl_new_type(const char *name, enum hlsl_type_class type_class,
enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN;
struct hlsl_ir_constant *hlsl_new_uint_constant(unsigned int n, const struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_node *hlsl_new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg,
struct source_location loc) DECLSPEC_HIDDEN;
struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct source_location loc,
const char *semantic, unsigned int modifiers,
const struct hlsl_reg_reservation *reg_reservation) DECLSPEC_HIDDEN;
struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct source_location loc) DECLSPEC_HIDDEN;
void hlsl_message(const char *fmt, ...) VKD3D_PRINTF_FUNC(1,2) DECLSPEC_HIDDEN;
void hlsl_report_message(const struct source_location loc,
enum hlsl_error_level level, const char *fmt, ...) VKD3D_PRINTF_FUNC(3,4) DECLSPEC_HIDDEN;
void hlsl_push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
BOOL hlsl_pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
struct hlsl_type *hlsl_type_clone(struct hlsl_type *old, unsigned int default_majority) DECLSPEC_HIDDEN;
BOOL hlsl_type_compare(const struct hlsl_type *t1, const struct hlsl_type *t2) DECLSPEC_HIDDEN;
unsigned int hlsl_type_component_count(struct hlsl_type *type) DECLSPEC_HIDDEN;
BOOL hlsl_type_is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN;
BOOL hlsl_type_is_void(const struct hlsl_type *type) DECLSPEC_HIDDEN;
int hlsl_lexer_compile(const char *text, enum vkd3d_shader_type type, DWORD major, DWORD minor, const char *entrypoint, int hlsl_lexer_compile(const char *text, enum vkd3d_shader_type type, DWORD major, DWORD minor, const char *entrypoint,
struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context) DECLSPEC_HIDDEN; struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context) DECLSPEC_HIDDEN;
int hlsl_parser_compile(enum vkd3d_shader_type type, DWORD major, DWORD minor, const char *entrypoint, int hlsl_parser_compile(enum vkd3d_shader_type type, DWORD major, DWORD minor, const char *entrypoint,
struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context) DECLSPEC_HIDDEN; struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context) DECLSPEC_HIDDEN;
const char *debug_base_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
const char *debug_modifiers(DWORD modifiers) DECLSPEC_HIDDEN;
const char *debug_node_type(enum hlsl_ir_node_type type) DECLSPEC_HIDDEN;
void debug_dump_ir_function_decl(const struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
void free_hlsl_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
void free_instr(struct hlsl_ir_node *node) DECLSPEC_HIDDEN;
void free_instr_list(struct list *list) DECLSPEC_HIDDEN;
void free_function_rb(struct rb_entry *entry, void *context) DECLSPEC_HIDDEN;
#endif #endif

View File

@ -172,10 +172,9 @@ row_major {return KW_ROW_MAJOR; }
{IDENTIFIER} { {IDENTIFIER} {
hlsl_lval.name = vkd3d_strdup(yytext); hlsl_lval.name = vkd3d_strdup(yytext);
if (get_variable(hlsl_ctx.cur_scope, yytext) if (hlsl_get_var(hlsl_ctx.cur_scope, yytext) || hlsl_get_function(yytext))
|| find_function(yytext))
return VAR_IDENTIFIER; return VAR_IDENTIFIER;
else if (get_type(hlsl_ctx.cur_scope, yytext, TRUE)) else if (hlsl_get_type(hlsl_ctx.cur_scope, yytext, TRUE))
return TYPE_IDENTIFIER; return TYPE_IDENTIFIER;
else else
return NEW_IDENTIFIER; return NEW_IDENTIFIER;

View File

@ -50,7 +50,7 @@ static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char
{ {
TRACE("Line %u: ", line_no); TRACE("Line %u: ", line_no);
if (modifiers) if (modifiers)
TRACE("%s ", debug_modifiers(modifiers)); TRACE("%s ", hlsl_debug_modifiers(modifiers));
TRACE("%s %s;\n", debug_hlsl_type(type), declname); TRACE("%s %s;\n", debug_hlsl_type(type), declname);
} }
@ -87,21 +87,21 @@ static BOOL compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2)
if (t1->type == HLSL_CLASS_ARRAY) if (t1->type == HLSL_CLASS_ARRAY)
{ {
if (compare_hlsl_types(t1->e.array.type, t2)) if (hlsl_type_compare(t1->e.array.type, t2))
/* e.g. float4[3] to float4 is allowed */ /* e.g. float4[3] to float4 is allowed */
return TRUE; return TRUE;
if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT) if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT)
return components_count_type(t1) >= components_count_type(t2); return hlsl_type_component_count(t1) >= hlsl_type_component_count(t2);
else else
return components_count_type(t1) == components_count_type(t2); return hlsl_type_component_count(t1) == hlsl_type_component_count(t2);
} }
if (t1->type == HLSL_CLASS_STRUCT) if (t1->type == HLSL_CLASS_STRUCT)
return components_count_type(t1) >= components_count_type(t2); return hlsl_type_component_count(t1) >= hlsl_type_component_count(t2);
if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT) if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT)
return components_count_type(t1) == components_count_type(t2); return hlsl_type_component_count(t1) == hlsl_type_component_count(t2);
if (t1->type == HLSL_CLASS_MATRIX || t2->type == HLSL_CLASS_MATRIX) if (t1->type == HLSL_CLASS_MATRIX || t2->type == HLSL_CLASS_MATRIX)
{ {
@ -110,12 +110,12 @@ static BOOL compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2)
/* Matrix-vector conversion is apparently allowed if they have the same components count */ /* Matrix-vector conversion is apparently allowed if they have the same components count */
if ((t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR) if ((t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR)
&& components_count_type(t1) == components_count_type(t2)) && hlsl_type_component_count(t1) == hlsl_type_component_count(t2))
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
if (components_count_type(t1) >= components_count_type(t2)) if (hlsl_type_component_count(t1) >= hlsl_type_component_count(t2))
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
@ -137,16 +137,16 @@ static BOOL implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ
if (t1->type == HLSL_CLASS_ARRAY && t2->type == HLSL_CLASS_ARRAY) if (t1->type == HLSL_CLASS_ARRAY && t2->type == HLSL_CLASS_ARRAY)
{ {
return components_count_type(t1) == components_count_type(t2); return hlsl_type_component_count(t1) == hlsl_type_component_count(t2);
} }
if ((t1->type == HLSL_CLASS_ARRAY && t2->type <= HLSL_CLASS_LAST_NUMERIC) if ((t1->type == HLSL_CLASS_ARRAY && t2->type <= HLSL_CLASS_LAST_NUMERIC)
|| (t1->type <= HLSL_CLASS_LAST_NUMERIC && t2->type == HLSL_CLASS_ARRAY)) || (t1->type <= HLSL_CLASS_LAST_NUMERIC && t2->type == HLSL_CLASS_ARRAY))
{ {
/* e.g. float4[3] to float4 is allowed */ /* e.g. float4[3] to float4 is allowed */
if (t1->type == HLSL_CLASS_ARRAY && compare_hlsl_types(t1->e.array.type, t2)) if (t1->type == HLSL_CLASS_ARRAY && hlsl_type_compare(t1->e.array.type, t2))
return TRUE; return TRUE;
if (components_count_type(t1) == components_count_type(t2)) if (hlsl_type_component_count(t1) == hlsl_type_component_count(t2))
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
@ -166,13 +166,13 @@ static BOOL implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ
/* Matrix-vector conversion is apparently allowed if they have the same components count */ /* Matrix-vector conversion is apparently allowed if they have the same components count */
if ((t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR) if ((t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR)
&& components_count_type(t1) == components_count_type(t2)) && hlsl_type_component_count(t1) == hlsl_type_component_count(t2))
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
if (t1->type == HLSL_CLASS_STRUCT && t2->type == HLSL_CLASS_STRUCT) if (t1->type == HLSL_CLASS_STRUCT && t2->type == HLSL_CLASS_STRUCT)
return compare_hlsl_types(t1, t2); return hlsl_type_compare(t1, t2);
return FALSE; return FALSE;
} }
@ -183,7 +183,7 @@ static struct hlsl_ir_node *add_implicit_conversion(struct list *instrs, struct
struct hlsl_type *src_type = node->data_type; struct hlsl_type *src_type = node->data_type;
struct hlsl_ir_expr *cast; struct hlsl_ir_expr *cast;
if (compare_hlsl_types(src_type, dst_type)) if (hlsl_type_compare(src_type, dst_type))
return node; return node;
if (!implicit_compatible_data_types(src_type, dst_type)) if (!implicit_compatible_data_types(src_type, dst_type))
@ -198,7 +198,7 @@ static struct hlsl_ir_node *add_implicit_conversion(struct list *instrs, struct
TRACE("Implicit conversion from %s to %s.\n", debug_hlsl_type(src_type), debug_hlsl_type(dst_type)); TRACE("Implicit conversion from %s to %s.\n", debug_hlsl_type(src_type), debug_hlsl_type(dst_type));
if (!(cast = new_cast(node, dst_type, loc))) if (!(cast = hlsl_new_cast(node, dst_type, loc)))
return NULL; return NULL;
list_add_tail(instrs, &cast->node.entry); list_add_tail(instrs, &cast->node.entry);
return &cast->node; return &cast->node;
@ -220,7 +220,7 @@ static BOOL declare_variable(struct hlsl_ir_var *decl, BOOL local)
if (invalid) if (invalid)
{ {
hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR, hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR,
"modifier '%s' invalid for local variables", debug_modifiers(invalid)); "modifier '%s' invalid for local variables", hlsl_debug_modifiers(invalid));
} }
if (decl->semantic) if (decl->semantic)
{ {
@ -231,16 +231,16 @@ static BOOL declare_variable(struct hlsl_ir_var *decl, BOOL local)
} }
else else
{ {
if (find_function(decl->name)) if (hlsl_get_function(decl->name))
{ {
hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR, "redefinition of '%s'", decl->name); hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR, "redefinition of '%s'", decl->name);
return FALSE; return FALSE;
} }
} }
ret = add_declaration(hlsl_ctx.cur_scope, decl, local); ret = hlsl_add_var(hlsl_ctx.cur_scope, decl, local);
if (!ret) if (!ret)
{ {
struct hlsl_ir_var *old = get_variable(hlsl_ctx.cur_scope, decl->name); struct hlsl_ir_var *old = hlsl_get_var(hlsl_ctx.cur_scope, decl->name);
hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR, "\"%s\" already declared", decl->name); hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR, "\"%s\" already declared", decl->name);
hlsl_report_message(old->loc, HLSL_LEVEL_NOTE, "\"%s\" was previously declared here", old->name); hlsl_report_message(old->loc, HLSL_LEVEL_NOTE, "\"%s\" was previously declared here", old->name);
@ -253,7 +253,7 @@ static DWORD add_modifiers(DWORD modifiers, DWORD mod, const struct source_locat
{ {
if (modifiers & mod) if (modifiers & mod)
{ {
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifier '%s' already specified", debug_modifiers(mod)); hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifier '%s' already specified", hlsl_debug_modifiers(mod));
return modifiers; return modifiers;
} }
if ((mod & HLSL_MODIFIERS_MAJORITY_MASK) && (modifiers & HLSL_MODIFIERS_MAJORITY_MASK)) if ((mod & HLSL_MODIFIERS_MAJORITY_MASK) && (modifiers & HLSL_MODIFIERS_MAJORITY_MASK))
@ -266,7 +266,7 @@ static DWORD add_modifiers(DWORD modifiers, DWORD mod, const struct source_locat
static BOOL add_type_to_scope(struct hlsl_scope *scope, struct hlsl_type *def) static BOOL add_type_to_scope(struct hlsl_scope *scope, struct hlsl_type *def)
{ {
if (get_type(scope, def->name, FALSE)) if (hlsl_get_type(scope, def->name, FALSE))
return FALSE; return FALSE;
rb_put(&scope->types, def->name, &def->scope_entry); rb_put(&scope->types, def->name, &def->scope_entry);
@ -304,20 +304,20 @@ static void declare_predefined_types(struct hlsl_scope *scope)
for (x = 1; x <= 4; ++x) for (x = 1; x <= 4; ++x)
{ {
sprintf(name, "%s%ux%u", names[bt], y, x); sprintf(name, "%s%ux%u", names[bt], y, x);
type = new_hlsl_type(vkd3d_strdup(name), HLSL_CLASS_MATRIX, bt, x, y); type = hlsl_new_type(vkd3d_strdup(name), HLSL_CLASS_MATRIX, bt, x, y);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
if (y == 1) if (y == 1)
{ {
sprintf(name, "%s%u", names[bt], x); sprintf(name, "%s%u", names[bt], x);
type = new_hlsl_type(vkd3d_strdup(name), HLSL_CLASS_VECTOR, bt, x, y); type = hlsl_new_type(vkd3d_strdup(name), HLSL_CLASS_VECTOR, bt, x, y);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
hlsl_ctx.builtin_types.vector[bt][x - 1] = type; hlsl_ctx.builtin_types.vector[bt][x - 1] = type;
if (x == 1) if (x == 1)
{ {
sprintf(name, "%s", names[bt]); sprintf(name, "%s", names[bt]);
type = new_hlsl_type(vkd3d_strdup(name), HLSL_CLASS_SCALAR, bt, x, y); type = hlsl_new_type(vkd3d_strdup(name), HLSL_CLASS_SCALAR, bt, x, y);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
hlsl_ctx.builtin_types.scalar[bt] = type; hlsl_ctx.builtin_types.scalar[bt] = type;
} }
@ -328,29 +328,29 @@ static void declare_predefined_types(struct hlsl_scope *scope)
for (bt = 0; bt <= HLSL_SAMPLER_DIM_MAX; ++bt) for (bt = 0; bt <= HLSL_SAMPLER_DIM_MAX; ++bt)
{ {
type = new_hlsl_type(vkd3d_strdup(sampler_names[bt]), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); type = hlsl_new_type(vkd3d_strdup(sampler_names[bt]), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
type->sampler_dim = bt; type->sampler_dim = bt;
hlsl_ctx.builtin_types.sampler[bt] = type; hlsl_ctx.builtin_types.sampler[bt] = type;
} }
hlsl_ctx.builtin_types.Void = new_hlsl_type(vkd3d_strdup("void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1); hlsl_ctx.builtin_types.Void = hlsl_new_type(vkd3d_strdup("void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1);
/* DX8 effects predefined types */ /* DX8 effects predefined types */
type = new_hlsl_type(vkd3d_strdup("DWORD"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1); type = hlsl_new_type(vkd3d_strdup("DWORD"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
type = new_hlsl_type(vkd3d_strdup("FLOAT"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1); type = hlsl_new_type(vkd3d_strdup("FLOAT"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
type = new_hlsl_type(vkd3d_strdup("VECTOR"), HLSL_CLASS_VECTOR, HLSL_TYPE_FLOAT, 4, 1); type = hlsl_new_type(vkd3d_strdup("VECTOR"), HLSL_CLASS_VECTOR, HLSL_TYPE_FLOAT, 4, 1);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
type = new_hlsl_type(vkd3d_strdup("MATRIX"), HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4); type = hlsl_new_type(vkd3d_strdup("MATRIX"), HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
type = new_hlsl_type(vkd3d_strdup("STRING"), HLSL_CLASS_OBJECT, HLSL_TYPE_STRING, 1, 1); type = hlsl_new_type(vkd3d_strdup("STRING"), HLSL_CLASS_OBJECT, HLSL_TYPE_STRING, 1, 1);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
type = new_hlsl_type(vkd3d_strdup("TEXTURE"), HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1); type = hlsl_new_type(vkd3d_strdup("TEXTURE"), HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
type = new_hlsl_type(vkd3d_strdup("PIXELSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1); type = hlsl_new_type(vkd3d_strdup("PIXELSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
type = new_hlsl_type(vkd3d_strdup("VERTEXSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1); type = hlsl_new_type(vkd3d_strdup("VERTEXSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1);
add_type_to_scope(scope, type); add_type_to_scope(scope, type);
} }
@ -365,11 +365,11 @@ static BOOL append_conditional_break(struct list *cond_list)
return TRUE; return TRUE;
condition = node_from_list(cond_list); condition = node_from_list(cond_list);
if (!(not = new_unary_expr(HLSL_IR_UNOP_LOGIC_NOT, condition, condition->loc))) if (!(not = hlsl_new_unary_expr(HLSL_IR_UNOP_LOGIC_NOT, condition, condition->loc)))
return FALSE; return FALSE;
list_add_tail(cond_list, &not->entry); list_add_tail(cond_list, &not->entry);
if (!(iff = new_if(not, condition->loc))) if (!(iff = hlsl_new_if(not, condition->loc)))
return FALSE; return FALSE;
list_add_tail(cond_list, &iff->node.entry); list_add_tail(cond_list, &iff->node.entry);
@ -431,10 +431,10 @@ oom:
vkd3d_free(loop); vkd3d_free(loop);
vkd3d_free(cond_jump); vkd3d_free(cond_jump);
vkd3d_free(list); vkd3d_free(list);
free_instr_list(init); hlsl_free_instr_list(init);
free_instr_list(cond); hlsl_free_instr_list(cond);
free_instr_list(iter); hlsl_free_instr_list(iter);
free_instr_list(body); hlsl_free_instr_list(body);
return NULL; return NULL;
} }
@ -444,7 +444,7 @@ static unsigned int initializer_size(const struct parse_initializer *initializer
for (i = 0; i < initializer->args_count; ++i) for (i = 0; i < initializer->args_count; ++i)
{ {
count += components_count_type(initializer->args[i]->data_type); count += hlsl_type_component_count(initializer->args[i]->data_type);
} }
TRACE("Initializer size = %u.\n", count); TRACE("Initializer size = %u.\n", count);
return count; return count;
@ -452,7 +452,7 @@ static unsigned int initializer_size(const struct parse_initializer *initializer
static void free_parse_initializer(struct parse_initializer *initializer) static void free_parse_initializer(struct parse_initializer *initializer)
{ {
free_instr_list(initializer->instrs); hlsl_free_instr_list(initializer->instrs);
vkd3d_free(initializer->args); vkd3d_free(initializer->args);
} }
@ -499,7 +499,7 @@ static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ir_node *value, const cha
swiz |= (y << 4 | x) << component * 8; swiz |= (y << 4 | x) << component * 8;
component++; component++;
} }
return new_swizzle(swiz, component, value, loc); return hlsl_new_swizzle(swiz, component, value, loc);
} }
/* Vector swizzle */ /* Vector swizzle */
@ -532,7 +532,7 @@ static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ir_node *value, const cha
component++; component++;
} }
if (valid) if (valid)
return new_swizzle(swiz, component, value, loc); return hlsl_new_swizzle(swiz, component, value, loc);
} }
return NULL; return NULL;
@ -551,11 +551,11 @@ static struct hlsl_ir_jump *add_return(struct list *instrs,
if (!(return_value = add_implicit_conversion(instrs, return_value, return_type, &loc))) if (!(return_value = add_implicit_conversion(instrs, return_value, return_type, &loc)))
return NULL; return NULL;
if (!(assignment = new_simple_assignment(hlsl_ctx.cur_function->return_var, return_value))) if (!(assignment = hlsl_new_simple_assignment(hlsl_ctx.cur_function->return_var, return_value)))
return NULL; return NULL;
list_add_after(&return_value->entry, &assignment->node.entry); list_add_after(&return_value->entry, &assignment->node.entry);
} }
else if (!type_is_void(return_type)) else if (!hlsl_type_is_void(return_type))
{ {
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "non-void function must return a value"); hlsl_report_message(loc, HLSL_LEVEL_ERROR, "non-void function must return a value");
return NULL; return NULL;
@ -579,12 +579,12 @@ static struct hlsl_ir_load *add_load(struct list *instrs, struct hlsl_ir_node *v
if (var_node->type == HLSL_IR_LOAD) if (var_node->type == HLSL_IR_LOAD)
{ {
const struct hlsl_deref *src = &load_from_node(var_node)->src; const struct hlsl_deref *src = &hlsl_ir_load(var_node)->src;
var = src->var; var = src->var;
if (src->offset.node) if (src->offset.node)
{ {
if (!(add = new_binary_expr(HLSL_IR_BINOP_ADD, src->offset.node, offset))) if (!(add = hlsl_new_binary_expr(HLSL_IR_BINOP_ADD, src->offset.node, offset)))
return NULL; return NULL;
list_add_tail(instrs, &add->entry); list_add_tail(instrs, &add->entry);
offset = add; offset = add;
@ -596,12 +596,12 @@ static struct hlsl_ir_load *add_load(struct list *instrs, struct hlsl_ir_node *v
char name[27]; char name[27];
sprintf(name, "<deref-%p>", var_node); sprintf(name, "<deref-%p>", var_node);
if (!(var = new_synthetic_var(name, var_node->data_type, var_node->loc))) if (!(var = hlsl_new_synthetic_var(name, var_node->data_type, var_node->loc)))
return NULL; return NULL;
TRACE("Synthesized variable %p for %s node.\n", var, debug_node_type(var_node->type)); TRACE("Synthesized variable %p for %s node.\n", var, hlsl_node_type_to_string(var_node->type));
if (!(assign = new_simple_assignment(var, var_node))) if (!(assign = hlsl_new_simple_assignment(var, var_node)))
return NULL; return NULL;
list_add_tail(instrs, &assign->node.entry); list_add_tail(instrs, &assign->node.entry);
@ -621,7 +621,7 @@ static struct hlsl_ir_load *add_record_load(struct list *instrs, struct hlsl_ir_
{ {
struct hlsl_ir_constant *c; struct hlsl_ir_constant *c;
if (!(c = new_uint_constant(field->reg_offset * 4, loc))) if (!(c = hlsl_new_uint_constant(field->reg_offset * 4, loc)))
return NULL; return NULL;
list_add_tail(instrs, &c->node.entry); list_add_tail(instrs, &c->node.entry);
@ -657,10 +657,10 @@ static struct hlsl_ir_load *add_array_load(struct list *instrs, struct hlsl_ir_n
return NULL; return NULL;
} }
if (!(c = new_uint_constant(data_type->reg_size * 4, loc))) if (!(c = hlsl_new_uint_constant(data_type->reg_size * 4, loc)))
return NULL; return NULL;
list_add_tail(instrs, &c->node.entry); list_add_tail(instrs, &c->node.entry);
if (!(mul = new_binary_expr(HLSL_IR_BINOP_MUL, index, &c->node))) if (!(mul = hlsl_new_binary_expr(HLSL_IR_BINOP_MUL, index, &c->node)))
return NULL; return NULL;
list_add_tail(instrs, &mul->entry); list_add_tail(instrs, &mul->entry);
index = mul; index = mul;
@ -681,7 +681,7 @@ static BOOL add_struct_field(struct list *fields, struct hlsl_struct_field *fiel
return TRUE; return TRUE;
} }
BOOL is_row_major(const struct hlsl_type *type) BOOL hlsl_type_is_row_major(const struct hlsl_type *type)
{ {
/* Default to column-major if the majority isn't explicitly set, which can /* Default to column-major if the majority isn't explicitly set, which can
* happen for anonymous nodes. */ * happen for anonymous nodes. */
@ -713,14 +713,14 @@ static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type,
if (!default_majority && !(*modifiers & HLSL_TYPE_MODIFIERS_MASK)) if (!default_majority && !(*modifiers & HLSL_TYPE_MODIFIERS_MASK))
return type; return type;
if (!(new_type = clone_hlsl_type(type, default_majority))) if (!(new_type = hlsl_type_clone(type, default_majority)))
return NULL; return NULL;
new_type->modifiers = add_modifiers(new_type->modifiers, *modifiers, loc); new_type->modifiers = add_modifiers(new_type->modifiers, *modifiers, loc);
*modifiers &= ~HLSL_TYPE_MODIFIERS_MASK; *modifiers &= ~HLSL_TYPE_MODIFIERS_MASK;
if (new_type->type == HLSL_CLASS_MATRIX) if (new_type->type == HLSL_CLASS_MATRIX)
new_type->reg_size = is_row_major(new_type) ? new_type->dimy : new_type->dimx; new_type->reg_size = hlsl_type_is_row_major(new_type) ? new_type->dimy : new_type->dimx;
return new_type; return new_type;
} }
@ -745,7 +745,7 @@ static struct list *gen_struct_fields(struct hlsl_type *type, DWORD modifiers, s
return list; return list;
} }
if (v->array_size) if (v->array_size)
field->type = new_array_type(type, v->array_size); field->type = hlsl_new_array_type(type, v->array_size);
else else
field->type = type; field->type = type;
field->name = v->name; field->name = v->name;
@ -772,9 +772,9 @@ static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct lis
LIST_FOR_EACH_ENTRY_SAFE(v, v_next, list, struct parse_variable_def, entry) LIST_FOR_EACH_ENTRY_SAFE(v, v_next, list, struct parse_variable_def, entry)
{ {
if (v->array_size) if (v->array_size)
type = new_array_type(orig_type, v->array_size); type = hlsl_new_array_type(orig_type, v->array_size);
else else
type = clone_hlsl_type(orig_type, 0); type = hlsl_type_clone(orig_type, 0);
if (!type) if (!type)
return FALSE; return FALSE;
vkd3d_free((void *)type->name); vkd3d_free((void *)type->name);
@ -784,7 +784,7 @@ static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct lis
if (type->type != HLSL_CLASS_MATRIX) if (type->type != HLSL_CLASS_MATRIX)
check_invalid_matrix_modifiers(type->modifiers, v->loc); check_invalid_matrix_modifiers(type->modifiers, v->loc);
else else
type->reg_size = is_row_major(type) ? type->dimy : type->dimx; type->reg_size = hlsl_type_is_row_major(type) ? type->dimy : type->dimx;
if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR) if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR)
&& (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)) && (type->modifiers & HLSL_MODIFIER_ROW_MAJOR))
@ -807,22 +807,22 @@ static BOOL add_func_parameter(struct list *list, struct parse_parameter *param,
if (param->type->type == HLSL_CLASS_MATRIX) if (param->type->type == HLSL_CLASS_MATRIX)
assert(param->type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK); assert(param->type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
if (!(var = new_var(param->name, param->type, loc, param->semantic, param->modifiers, param->reg_reservation))) if (!(var = hlsl_new_var(param->name, param->type, loc, param->semantic, param->modifiers, param->reg_reservation)))
return FALSE; return FALSE;
if (!add_declaration(hlsl_ctx.cur_scope, var, FALSE)) if (!hlsl_add_var(hlsl_ctx.cur_scope, var, FALSE))
{ {
free_declaration(var); hlsl_free_var(var);
return FALSE; return FALSE;
} }
list_add_tail(list, &var->param_entry); list_add_tail(list, &var->param_entry);
return TRUE; return TRUE;
} }
static struct reg_reservation *parse_reg_reservation(const char *reg_string) static struct hlsl_reg_reservation *parse_reg_reservation(const char *reg_string)
{ {
enum vkd3d_shader_register_type type; enum vkd3d_shader_register_type type;
struct reg_reservation *reg_res; struct hlsl_reg_reservation *reg_res;
DWORD regnum = 0; DWORD regnum = 0;
switch (reg_string[0]) switch (reg_string[0])
@ -902,7 +902,7 @@ static struct list *make_list(struct hlsl_ir_node *node)
if (!(list = vkd3d_malloc(sizeof(*list)))) if (!(list = vkd3d_malloc(sizeof(*list))))
{ {
free_instr(node); hlsl_free_instr(node);
return NULL; return NULL;
} }
list_init(list); list_init(list);
@ -919,7 +919,7 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
{ {
case HLSL_IR_CONSTANT: case HLSL_IR_CONSTANT:
{ {
struct hlsl_ir_constant *constant = constant_from_node(node); struct hlsl_ir_constant *constant = hlsl_ir_constant(node);
switch (constant->node.data_type->base_type) switch (constant->node.data_type->base_type)
{ {
@ -934,7 +934,7 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
case HLSL_TYPE_BOOL: case HLSL_TYPE_BOOL:
return constant->value.b[0]; return constant->value.b[0];
default: default:
WARN("Invalid type %s.\n", debug_base_type(constant->node.data_type)); WARN("Invalid type %s.\n", hlsl_base_type_to_string(constant->node.data_type));
return 0; return 0;
} }
} }
@ -942,12 +942,12 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
case HLSL_IR_EXPR: case HLSL_IR_EXPR:
case HLSL_IR_LOAD: case HLSL_IR_LOAD:
case HLSL_IR_SWIZZLE: case HLSL_IR_SWIZZLE:
FIXME("Unhandled type %s.\n", debug_node_type(node->type)); FIXME("Unhandled type %s.\n", hlsl_node_type_to_string(node->type));
return 0; return 0;
case HLSL_IR_ASSIGNMENT: case HLSL_IR_ASSIGNMENT:
default: default:
WARN("Invalid node type %s.\n", debug_node_type(node->type)); WARN("Invalid node type %s.\n", hlsl_node_type_to_string(node->type));
return 0; return 0;
} }
} }
@ -970,7 +970,7 @@ static BOOL expr_compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t
count or the matrix is nx1 or 1xn */ count or the matrix is nx1 or 1xn */
if (t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR) if (t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR)
{ {
if (components_count_type(t1) == components_count_type(t2)) if (hlsl_type_component_count(t1) == hlsl_type_component_count(t2))
return TRUE; return TRUE;
return (t1->type == HLSL_CLASS_MATRIX && (t1->dimx == 1 || t1->dimy == 1)) return (t1->type == HLSL_CLASS_MATRIX && (t1->dimx == 1 || t1->dimy == 1))
@ -1031,7 +1031,7 @@ static struct hlsl_type *expr_common_type(struct hlsl_type *t1, struct hlsl_type
return NULL; return NULL;
} }
if (compare_hlsl_types(t1, t2)) if (hlsl_type_compare(t1, t2))
return t1; return t1;
if (!expr_compatible_data_types(t1, t2)) if (!expr_compatible_data_types(t1, t2))
@ -1110,7 +1110,7 @@ static struct hlsl_type *expr_common_type(struct hlsl_type *t1, struct hlsl_type
return hlsl_ctx.builtin_types.scalar[base]; return hlsl_ctx.builtin_types.scalar[base];
if (type == HLSL_CLASS_VECTOR) if (type == HLSL_CLASS_VECTOR)
return hlsl_ctx.builtin_types.vector[base][dimx - 1]; return hlsl_ctx.builtin_types.vector[base][dimx - 1];
return new_hlsl_type(NULL, type, base, dimx, dimy); return hlsl_new_type(NULL, type, base, dimx, dimy);
} }
static struct hlsl_ir_expr *add_expr(struct list *instrs, enum hlsl_ir_expr_op op, static struct hlsl_ir_expr *add_expr(struct list *instrs, enum hlsl_ir_expr_op op,
@ -1135,7 +1135,7 @@ static struct hlsl_ir_expr *add_expr(struct list *instrs, enum hlsl_ir_expr_op o
if (!operands[i]) if (!operands[i])
break; break;
if (compare_hlsl_types(operands[i]->data_type, type)) if (hlsl_type_compare(operands[i]->data_type, type))
continue; continue;
TRACE("Implicitly converting %s into %s in an expression.\n", debug_hlsl_type(operands[i]->data_type), debug_hlsl_type(type)); TRACE("Implicitly converting %s into %s in an expression.\n", debug_hlsl_type(operands[i]->data_type), debug_hlsl_type(type));
if (operands[i]->data_type->dimx * operands[i]->data_type->dimy != 1 if (operands[i]->data_type->dimx * operands[i]->data_type->dimy != 1
@ -1144,7 +1144,7 @@ static struct hlsl_ir_expr *add_expr(struct list *instrs, enum hlsl_ir_expr_op o
hlsl_report_message(operands[i]->loc, HLSL_LEVEL_WARNING, "implicit truncation of vector/matrix type"); hlsl_report_message(operands[i]->loc, HLSL_LEVEL_WARNING, "implicit truncation of vector/matrix type");
} }
if (!(cast = new_cast(operands[i], type, &operands[i]->loc))) if (!(cast = hlsl_new_cast(operands[i], type, &operands[i]->loc)))
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;
@ -1257,7 +1257,7 @@ static struct hlsl_ir_node *add_assignment(struct list *instrs, struct hlsl_ir_n
{ {
struct hlsl_ir_node *lhs_inner; struct hlsl_ir_node *lhs_inner;
if (lhs->type == HLSL_IR_EXPR && expr_from_node(lhs)->op == HLSL_IR_UNOP_CAST) if (lhs->type == HLSL_IR_EXPR && hlsl_ir_expr(lhs)->op == HLSL_IR_UNOP_CAST)
{ {
FIXME("Cast on the lhs.\n"); FIXME("Cast on the lhs.\n");
vkd3d_free(assign); vkd3d_free(assign);
@ -1265,7 +1265,7 @@ static struct hlsl_ir_node *add_assignment(struct list *instrs, struct hlsl_ir_n
} }
else if (lhs->type == HLSL_IR_SWIZZLE) else if (lhs->type == HLSL_IR_SWIZZLE)
{ {
struct hlsl_ir_swizzle *swizzle = swizzle_from_node(lhs); struct hlsl_ir_swizzle *swizzle = hlsl_ir_swizzle(lhs);
const struct hlsl_type *swizzle_type = swizzle->node.data_type; const struct hlsl_type *swizzle_type = swizzle->node.data_type;
unsigned int width; unsigned int width;
@ -1301,15 +1301,15 @@ static struct hlsl_ir_node *add_assignment(struct list *instrs, struct hlsl_ir_n
init_node(&assign->node, HLSL_IR_ASSIGNMENT, lhs_type, lhs->loc); init_node(&assign->node, HLSL_IR_ASSIGNMENT, lhs_type, lhs->loc);
assign->writemask = writemask; assign->writemask = writemask;
assign->lhs.var = load_from_node(lhs)->src.var; assign->lhs.var = hlsl_ir_load(lhs)->src.var;
hlsl_src_from_node(&assign->lhs.offset, load_from_node(lhs)->src.offset.node); hlsl_src_from_node(&assign->lhs.offset, hlsl_ir_load(lhs)->src.offset.node);
if (assign_op != ASSIGN_OP_ASSIGN) if (assign_op != ASSIGN_OP_ASSIGN)
{ {
enum hlsl_ir_expr_op op = op_from_assignment(assign_op); enum hlsl_ir_expr_op op = op_from_assignment(assign_op);
struct hlsl_ir_node *expr; struct hlsl_ir_node *expr;
TRACE("Adding an expression for the compound assignment.\n"); TRACE("Adding an expression for the compound assignment.\n");
expr = new_binary_expr(op, lhs, rhs); expr = hlsl_new_binary_expr(op, lhs, rhs);
list_add_after(&rhs->entry, &expr->entry); list_add_after(&rhs->entry, &expr->entry);
rhs = expr; rhs = expr;
} }
@ -1326,7 +1326,7 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var,
struct hlsl_struct_field *field; struct hlsl_struct_field *field;
unsigned int i = 0; unsigned int i = 0;
if (initializer_size(initializer) != components_count_type(type)) if (initializer_size(initializer) != hlsl_type_component_count(type))
{ {
hlsl_report_message(var->loc, HLSL_LEVEL_ERROR, "structure initializer mismatch"); hlsl_report_message(var->loc, HLSL_LEVEL_ERROR, "structure initializer mismatch");
free_parse_initializer(initializer); free_parse_initializer(initializer);
@ -1345,13 +1345,13 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var,
if (i++ >= initializer->args_count) if (i++ >= initializer->args_count)
break; break;
if (components_count_type(field->type) == components_count_type(node->data_type)) if (hlsl_type_component_count(field->type) == hlsl_type_component_count(node->data_type))
{ {
if (!(c = new_uint_constant(field->reg_offset * 4, node->loc))) if (!(c = hlsl_new_uint_constant(field->reg_offset * 4, node->loc)))
break; break;
list_add_tail(list, &c->node.entry); list_add_tail(list, &c->node.entry);
if (!(assign = new_assignment(var, &c->node, node, 0, node->loc))) if (!(assign = hlsl_new_assignment(var, &c->node, node, 0, node->loc)))
break; break;
list_add_tail(list, &assign->node.entry); list_add_tail(list, &assign->node.entry);
} }
@ -1397,11 +1397,11 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers,
LIST_FOR_EACH_ENTRY_SAFE(v, v_next, var_list, struct parse_variable_def, entry) LIST_FOR_EACH_ENTRY_SAFE(v, v_next, var_list, struct parse_variable_def, entry)
{ {
if (v->array_size) if (v->array_size)
type = new_array_type(basic_type, v->array_size); type = hlsl_new_array_type(basic_type, v->array_size);
else else
type = basic_type; type = basic_type;
if (!(var = new_var(v->name, type, v->loc, v->semantic, modifiers, v->reg_reservation))) if (!(var = hlsl_new_var(v->name, type, v->loc, v->semantic, modifiers, v->reg_reservation)))
{ {
free_parse_variable_def(v); free_parse_variable_def(v);
continue; continue;
@ -1417,7 +1417,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers,
if (type->modifiers & HLSL_MODIFIER_CONST && !(var->modifiers & HLSL_STORAGE_UNIFORM) && !v->initializer.args_count) if (type->modifiers & HLSL_MODIFIER_CONST && !(var->modifiers & HLSL_STORAGE_UNIFORM) && !v->initializer.args_count)
{ {
hlsl_report_message(v->loc, HLSL_LEVEL_ERROR, "const variable without initializer"); hlsl_report_message(v->loc, HLSL_LEVEL_ERROR, "const variable without initializer");
free_declaration(var); hlsl_free_var(var);
vkd3d_free(v); vkd3d_free(v);
continue; continue;
} }
@ -1425,7 +1425,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers,
ret = declare_variable(var, local); ret = declare_variable(var, local);
if (!ret) if (!ret)
{ {
free_declaration(var); hlsl_free_var(var);
vkd3d_free(v); vkd3d_free(v);
continue; continue;
} }
@ -1450,7 +1450,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers,
} }
} }
if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY) if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY)
&& components_count_type(type) != size) && hlsl_type_component_count(type) != size)
{ {
hlsl_report_message(v->loc, HLSL_LEVEL_ERROR, hlsl_report_message(v->loc, HLSL_LEVEL_ERROR,
"'%s' initializer does not match", v->name); "'%s' initializer does not match", v->name);
@ -1487,7 +1487,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers,
continue; continue;
} }
load = new_var_load(var, var->loc); load = hlsl_new_var_load(var, var->loc);
list_add_tail(v->initializer.instrs, &load->node.entry); list_add_tail(v->initializer.instrs, &load->node.entry);
add_assignment(v->initializer.instrs, &load->node, ASSIGN_OP_ASSIGN, v->initializer.args[0]); add_assignment(v->initializer.instrs, &load->node, ASSIGN_OP_ASSIGN, v->initializer.args[0]);
vkd3d_free(v->initializer.args); vkd3d_free(v->initializer.args);
@ -1528,7 +1528,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers,
struct parse_if_body if_body; struct parse_if_body if_body;
enum parse_unary_op unary_op; enum parse_unary_op unary_op;
enum parse_assign_op assign_op; enum parse_assign_op assign_op;
struct reg_reservation *reg_reservation; struct hlsl_reg_reservation *reg_reservation;
struct parse_colon_attribute colon_attribute; struct parse_colon_attribute colon_attribute;
} }
@ -1732,7 +1732,7 @@ hlsl_prog:
"redefinition of function %s", debugstr_a($2.name)); "redefinition of function %s", debugstr_a($2.name));
YYABORT; YYABORT;
} }
else if (!compare_hlsl_types(decl->return_type, $2.decl->return_type)) else if (!hlsl_type_compare(decl->return_type, $2.decl->return_type))
{ {
hlsl_report_message($2.decl->loc, HLSL_LEVEL_ERROR, hlsl_report_message($2.decl->loc, HLSL_LEVEL_ERROR,
"redefining function %s with a different return type", "redefining function %s with a different return type",
@ -1744,14 +1744,14 @@ hlsl_prog:
} }
} }
if (type_is_void($2.decl->return_type) && $2.decl->semantic) if (hlsl_type_is_void($2.decl->return_type) && $2.decl->semantic)
{ {
hlsl_report_message($2.decl->loc, HLSL_LEVEL_ERROR, hlsl_report_message($2.decl->loc, HLSL_LEVEL_ERROR,
"void function with a semantic"); "void function with a semantic");
} }
TRACE("Adding function '%s' to the function list.\n", $2.name); TRACE("Adding function '%s' to the function list.\n", $2.name);
add_function_decl(&hlsl_ctx.functions, $2.name, $2.decl, FALSE); hlsl_add_function(&hlsl_ctx.functions, $2.name, $2.decl, FALSE);
} }
| hlsl_prog declaration_statement | hlsl_prog declaration_statement
{ {
@ -1759,7 +1759,7 @@ hlsl_prog:
if (!list_empty($2)) if (!list_empty($2))
FIXME("Uniform initializer.\n"); FIXME("Uniform initializer.\n");
free_instr_list($2); hlsl_free_instr_list($2);
} }
| hlsl_prog preproc_directive | hlsl_prog preproc_directive
| hlsl_prog ';' | hlsl_prog ';'
@ -1825,9 +1825,9 @@ named_struct_spec:
BOOL ret; BOOL ret;
TRACE("Structure %s declaration.\n", debugstr_a($2)); TRACE("Structure %s declaration.\n", debugstr_a($2));
$$ = new_struct_type($2, $4); $$ = hlsl_new_struct_type($2, $4);
if (get_variable(hlsl_ctx.cur_scope, $2)) if (hlsl_get_var(hlsl_ctx.cur_scope, $2))
{ {
hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR, "redefinition of '%s'", $2); hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR, "redefinition of '%s'", $2);
YYABORT; YYABORT;
@ -1845,7 +1845,7 @@ unnamed_struct_spec:
KW_STRUCT '{' fields_list '}' KW_STRUCT '{' fields_list '}'
{ {
TRACE("Anonymous structure declaration.\n"); TRACE("Anonymous structure declaration.\n");
$$ = new_struct_type(NULL, $3); $$ = hlsl_new_struct_type(NULL, $3);
} }
any_identifier: any_identifier:
@ -1899,13 +1899,13 @@ func_declaration:
TRACE("Function %s parsed.\n", $1.name); TRACE("Function %s parsed.\n", $1.name);
$$ = $1; $$ = $1;
$$.decl->body = $2; $$.decl->body = $2;
pop_scope(&hlsl_ctx); hlsl_pop_scope(&hlsl_ctx);
} }
| func_prototype ';' | func_prototype ';'
{ {
TRACE("Function prototype for %s.\n", $1.name); TRACE("Function prototype for %s.\n", $1.name);
$$ = $1; $$ = $1;
pop_scope(&hlsl_ctx); hlsl_pop_scope(&hlsl_ctx);
} }
func_prototype: func_prototype:
@ -1918,12 +1918,12 @@ func_prototype:
"unexpected modifiers on a function"); "unexpected modifiers on a function");
YYABORT; YYABORT;
} }
if (get_variable(hlsl_ctx.globals, $3)) if (hlsl_get_var(hlsl_ctx.globals, $3))
{ {
hlsl_report_message(get_location(&@3), HLSL_LEVEL_ERROR, "redefinition of '%s'\n", $3); hlsl_report_message(get_location(&@3), HLSL_LEVEL_ERROR, "redefinition of '%s'\n", $3);
YYABORT; YYABORT;
} }
if (type_is_void($2) && $7.semantic) if (hlsl_type_is_void($2) && $7.semantic)
{ {
hlsl_report_message(get_location(&@7), HLSL_LEVEL_ERROR, "void function with a semantic"); hlsl_report_message(get_location(&@7), HLSL_LEVEL_ERROR, "void function with a semantic");
} }
@ -1933,7 +1933,7 @@ func_prototype:
FIXME("Unexpected register reservation for a function.\n"); FIXME("Unexpected register reservation for a function.\n");
vkd3d_free($7.reg_reservation); vkd3d_free($7.reg_reservation);
} }
if (!($$.decl = new_func_decl($2, $5, $7.semantic, get_location(&@3)))) if (!($$.decl = hlsl_new_func_decl($2, $5, $7.semantic, get_location(&@3))))
YYABORT; YYABORT;
$$.name = $3; $$.name = $3;
hlsl_ctx.cur_function = $$.decl; hlsl_ctx.cur_function = $$.decl;
@ -1947,14 +1947,14 @@ compound_statement:
} }
| '{' scope_start statement_list '}' | '{' scope_start statement_list '}'
{ {
pop_scope(&hlsl_ctx); hlsl_pop_scope(&hlsl_ctx);
$$ = $3; $$ = $3;
} }
scope_start: scope_start:
/* empty */ /* empty */
{ {
push_scope(&hlsl_ctx); hlsl_push_scope(&hlsl_ctx);
} }
var_identifier: var_identifier:
@ -2100,7 +2100,7 @@ type:
YYABORT; YYABORT;
} }
$$ = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, $3->base_type, $5, 1); $$ = hlsl_new_type(NULL, HLSL_CLASS_VECTOR, $3->base_type, $5, 1);
} }
| KW_MATRIX '<' base_type ',' C_INTEGER ',' C_INTEGER '>' | KW_MATRIX '<' base_type ',' C_INTEGER ',' C_INTEGER '>'
{ {
@ -2123,7 +2123,7 @@ type:
YYABORT; YYABORT;
} }
$$ = new_hlsl_type(NULL, HLSL_CLASS_MATRIX, $3->base_type, $7, $5); $$ = hlsl_new_type(NULL, HLSL_CLASS_MATRIX, $3->base_type, $7, $5);
} }
base_type: base_type:
@ -2153,12 +2153,12 @@ base_type:
} }
| TYPE_IDENTIFIER | TYPE_IDENTIFIER
{ {
$$ = get_type(hlsl_ctx.cur_scope, $1, TRUE); $$ = hlsl_get_type(hlsl_ctx.cur_scope, $1, TRUE);
vkd3d_free($1); vkd3d_free($1);
} }
| KW_STRUCT TYPE_IDENTIFIER | KW_STRUCT TYPE_IDENTIFIER
{ {
$$ = get_type(hlsl_ctx.cur_scope, $2, TRUE); $$ = hlsl_get_type(hlsl_ctx.cur_scope, $2, TRUE);
if ($$->type != HLSL_CLASS_STRUCT) if ($$->type != HLSL_CLASS_STRUCT)
hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR, "'%s' redefined as a structure\n", $2); hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR, "'%s' redefined as a structure\n", $2);
vkd3d_free($2); vkd3d_free($2);
@ -2278,7 +2278,7 @@ array:
{ {
unsigned int size = evaluate_array_dimension(node_from_list($2)); unsigned int size = evaluate_array_dimension(node_from_list($2));
free_instr_list($2); hlsl_free_instr_list($2);
if (!size) if (!size)
{ {
@ -2436,7 +2436,7 @@ selection_statement:
struct hlsl_ir_node *condition = node_from_list($3); struct hlsl_ir_node *condition = node_from_list($3);
struct hlsl_ir_if *instr; struct hlsl_ir_if *instr;
if (!(instr = new_if(condition, get_location(&@1)))) if (!(instr = hlsl_new_if(condition, get_location(&@1))))
YYABORT; YYABORT;
list_move_tail(&instr->then_instrs, $5.then_instrs); list_move_tail(&instr->then_instrs, $5.then_instrs);
list_move_tail(&instr->else_instrs, $5.else_instrs); list_move_tail(&instr->else_instrs, $5.else_instrs);
@ -2473,7 +2473,7 @@ loop_statement:
| KW_FOR '(' scope_start expr_statement expr_statement expr ')' statement | KW_FOR '(' scope_start expr_statement expr_statement expr ')' statement
{ {
$$ = create_loop(LOOP_FOR, $4, $5, $6, $8, get_location(&@1)); $$ = create_loop(LOOP_FOR, $4, $5, $6, $8, get_location(&@1));
pop_scope(&hlsl_ctx); hlsl_pop_scope(&hlsl_ctx);
} }
| KW_FOR '(' scope_start declaration expr_statement expr ')' statement | KW_FOR '(' scope_start declaration expr_statement expr ')' statement
{ {
@ -2481,7 +2481,7 @@ loop_statement:
hlsl_report_message(get_location(&@4), HLSL_LEVEL_WARNING, hlsl_report_message(get_location(&@4), HLSL_LEVEL_WARNING,
"no expressions in for loop initializer"); "no expressions in for loop initializer");
$$ = create_loop(LOOP_FOR, $4, $5, $6, $8, get_location(&@1)); $$ = create_loop(LOOP_FOR, $4, $5, $6, $8, get_location(&@1));
pop_scope(&hlsl_ctx); hlsl_pop_scope(&hlsl_ctx);
} }
expr_statement: expr_statement:
@ -2534,12 +2534,12 @@ primary_expr:
struct hlsl_ir_load *load; struct hlsl_ir_load *load;
struct hlsl_ir_var *var; struct hlsl_ir_var *var;
if (!(var = get_variable(hlsl_ctx.cur_scope, $1))) if (!(var = hlsl_get_var(hlsl_ctx.cur_scope, $1)))
{ {
hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR, "variable '%s' is not declared\n", $1); hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR, "variable '%s' is not declared\n", $1);
YYABORT; YYABORT;
} }
if ((load = new_var_load(var, get_location(&@1)))) if ((load = hlsl_new_var_load(var, get_location(&@1))))
{ {
if (!($$ = make_list(&load->node))) if (!($$ = make_list(&load->node)))
YYABORT; YYABORT;
@ -2565,9 +2565,9 @@ postfix_expr:
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression"); hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression");
YYABORT; YYABORT;
} }
inc = new_unary_expr(HLSL_IR_UNOP_POSTINC, node_from_list($1), loc); inc = hlsl_new_unary_expr(HLSL_IR_UNOP_POSTINC, node_from_list($1), loc);
/* Post increment/decrement expressions are considered const */ /* Post increment/decrement expressions are considered const */
inc->data_type = clone_hlsl_type(inc->data_type, 0); inc->data_type = hlsl_type_clone(inc->data_type, 0);
inc->data_type->modifiers |= HLSL_MODIFIER_CONST; inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
$$ = append_unop($1, inc); $$ = append_unop($1, inc);
} }
@ -2582,9 +2582,9 @@ postfix_expr:
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression"); hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression");
YYABORT; YYABORT;
} }
inc = new_unary_expr(HLSL_IR_UNOP_POSTDEC, node_from_list($1), loc); inc = hlsl_new_unary_expr(HLSL_IR_UNOP_POSTDEC, node_from_list($1), loc);
/* Post increment/decrement expressions are considered const */ /* Post increment/decrement expressions are considered const */
inc->data_type = clone_hlsl_type(inc->data_type, 0); inc->data_type = hlsl_type_clone(inc->data_type, 0);
inc->data_type->modifiers |= HLSL_MODIFIER_CONST; inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
$$ = append_unop($1, inc); $$ = append_unop($1, inc);
} }
@ -2644,13 +2644,13 @@ postfix_expr:
if (index->data_type->type != HLSL_CLASS_SCALAR) if (index->data_type->type != HLSL_CLASS_SCALAR)
{ {
hlsl_report_message(get_location(&@3), HLSL_LEVEL_ERROR, "array index is not scalar"); hlsl_report_message(get_location(&@3), HLSL_LEVEL_ERROR, "array index is not scalar");
free_instr_list($1); hlsl_free_instr_list($1);
YYABORT; YYABORT;
} }
if (!add_array_load($1, array, index, get_location(&@2))) if (!add_array_load($1, array, index, get_location(&@2)))
{ {
free_instr_list($1); hlsl_free_instr_list($1);
YYABORT; YYABORT;
} }
$$ = $1; $$ = $1;
@ -2690,7 +2690,7 @@ postfix_expr:
FIXME("Matrix constructors are not supported yet.\n"); FIXME("Matrix constructors are not supported yet.\n");
sprintf(name, "<constructor-%x>", counter++); sprintf(name, "<constructor-%x>", counter++);
if (!(var = new_synthetic_var(name, $2, get_location(&@2)))) if (!(var = hlsl_new_synthetic_var(name, $2, get_location(&@2))))
YYABORT; YYABORT;
for (i = 0; i < $4.args_count; ++i) for (i = 0; i < $4.args_count; ++i)
{ {
@ -2702,7 +2702,7 @@ postfix_expr:
hlsl_report_message(arg->loc, HLSL_LEVEL_ERROR, "invalid constructor argument"); hlsl_report_message(arg->loc, HLSL_LEVEL_ERROR, "invalid constructor argument");
continue; continue;
} }
width = components_count_type(arg->data_type); width = hlsl_type_component_count(arg->data_type);
if (width > 4) if (width > 4)
{ {
@ -2714,14 +2714,14 @@ postfix_expr:
hlsl_ctx.builtin_types.vector[$2->base_type][width - 1], &arg->loc))) hlsl_ctx.builtin_types.vector[$2->base_type][width - 1], &arg->loc)))
continue; continue;
if (!(assignment = new_assignment(var, NULL, arg, if (!(assignment = hlsl_new_assignment(var, NULL, arg,
((1 << width) - 1) << writemask_offset, arg->loc))) ((1 << width) - 1) << writemask_offset, arg->loc)))
YYABORT; YYABORT;
writemask_offset += width; writemask_offset += width;
list_add_tail($4.instrs, &assignment->node.entry); list_add_tail($4.instrs, &assignment->node.entry);
} }
vkd3d_free($4.args); vkd3d_free($4.args);
if (!(load = new_var_load(var, get_location(&@2)))) if (!(load = hlsl_new_var_load(var, get_location(&@2))))
YYABORT; YYABORT;
$$ = append_unop($4.instrs, &load->node); $$ = append_unop($4.instrs, &load->node);
} }
@ -2738,7 +2738,7 @@ unary_expr:
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression"); hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression");
YYABORT; YYABORT;
} }
$$ = append_unop($2, new_unary_expr(HLSL_IR_UNOP_PREINC, node_from_list($2), loc)); $$ = append_unop($2, hlsl_new_unary_expr(HLSL_IR_UNOP_PREINC, node_from_list($2), loc));
} }
| OP_DEC unary_expr | OP_DEC unary_expr
{ {
@ -2750,7 +2750,7 @@ unary_expr:
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression"); hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression");
YYABORT; YYABORT;
} }
$$ = append_unop($2, new_unary_expr(HLSL_IR_UNOP_PREDEC, node_from_list($2), loc)); $$ = append_unop($2, hlsl_new_unary_expr(HLSL_IR_UNOP_PREDEC, node_from_list($2), loc));
} }
| unary_op unary_expr | unary_op unary_expr
{ {
@ -2760,7 +2760,7 @@ unary_expr:
if ($1 == UNARY_OP_PLUS) if ($1 == UNARY_OP_PLUS)
$$ = $2; $$ = $2;
else else
$$ = append_unop($2, new_unary_expr(ops[$1], node_from_list($2), get_location(&@1))); $$ = append_unop($2, hlsl_new_unary_expr(ops[$1], node_from_list($2), get_location(&@1)));
} }
/* var_modifiers is necessary to avoid shift/reduce conflicts. */ /* var_modifiers is necessary to avoid shift/reduce conflicts. */
@ -2778,7 +2778,7 @@ unary_expr:
} }
if ($4) if ($4)
dst_type = new_array_type($3, $4); dst_type = hlsl_new_array_type($3, $4);
else else
dst_type = $3; dst_type = $3;
@ -2789,7 +2789,7 @@ unary_expr:
YYABORT; YYABORT;
} }
$$ = append_unop($6, &new_cast(node_from_list($6), dst_type, &loc)->node); $$ = append_unop($6, &hlsl_new_cast(node_from_list($6), dst_type, &loc)->node);
} }
unary_op: unary_op:
@ -3011,7 +3011,7 @@ static void dump_function_decl(struct rb_entry *entry, void *context)
struct hlsl_ir_function_decl *func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry); struct hlsl_ir_function_decl *func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry);
if (func->body) if (func->body)
debug_dump_ir_function_decl(func); hlsl_dump_function(func);
} }
static void dump_function(struct rb_entry *entry, void *context) static void dump_function(struct rb_entry *entry, void *context)
@ -3032,14 +3032,14 @@ static unsigned int index_instructions(struct list *instrs, unsigned int index)
if (instr->type == HLSL_IR_IF) if (instr->type == HLSL_IR_IF)
{ {
struct hlsl_ir_if *iff = if_from_node(instr); struct hlsl_ir_if *iff = hlsl_ir_if(instr);
index = index_instructions(&iff->then_instrs, index); index = index_instructions(&iff->then_instrs, index);
index = index_instructions(&iff->else_instrs, index); index = index_instructions(&iff->else_instrs, index);
} }
else if (instr->type == HLSL_IR_LOOP) else if (instr->type == HLSL_IR_LOOP)
{ {
index = index_instructions(&loop_from_node(instr)->body, index); index = index_instructions(&hlsl_ir_loop(instr)->body, index);
loop_from_node(instr)->next_index = index; hlsl_ir_loop(instr)->next_index = index;
} }
} }
@ -3062,7 +3062,7 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
{ {
case HLSL_IR_ASSIGNMENT: case HLSL_IR_ASSIGNMENT:
{ {
struct hlsl_ir_assignment *assignment = assignment_from_node(instr); struct hlsl_ir_assignment *assignment = hlsl_ir_assignment(instr);
var = assignment->lhs.var; var = assignment->lhs.var;
if (!var->first_write) if (!var->first_write)
@ -3074,7 +3074,7 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
} }
case HLSL_IR_EXPR: case HLSL_IR_EXPR:
{ {
struct hlsl_ir_expr *expr = expr_from_node(instr); struct hlsl_ir_expr *expr = hlsl_ir_expr(instr);
unsigned int i; unsigned int i;
for (i = 0; i < ARRAY_SIZE(expr->operands) && expr->operands[i].node; ++i) for (i = 0; i < ARRAY_SIZE(expr->operands) && expr->operands[i].node; ++i)
@ -3083,7 +3083,7 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
} }
case HLSL_IR_IF: case HLSL_IR_IF:
{ {
struct hlsl_ir_if *iff = if_from_node(instr); struct hlsl_ir_if *iff = hlsl_ir_if(instr);
compute_liveness_recurse(&iff->then_instrs, loop_first, loop_last); compute_liveness_recurse(&iff->then_instrs, loop_first, loop_last);
compute_liveness_recurse(&iff->else_instrs, loop_first, loop_last); compute_liveness_recurse(&iff->else_instrs, loop_first, loop_last);
@ -3092,7 +3092,7 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
} }
case HLSL_IR_LOAD: case HLSL_IR_LOAD:
{ {
struct hlsl_ir_load *load = load_from_node(instr); struct hlsl_ir_load *load = hlsl_ir_load(instr);
var = load->src.var; var = load->src.var;
var->last_read = loop_last ? max(instr->index, loop_last) : instr->index; var->last_read = loop_last ? max(instr->index, loop_last) : instr->index;
@ -3102,7 +3102,7 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
} }
case HLSL_IR_LOOP: case HLSL_IR_LOOP:
{ {
struct hlsl_ir_loop *loop = loop_from_node(instr); struct hlsl_ir_loop *loop = hlsl_ir_loop(instr);
compute_liveness_recurse(&loop->body, loop_first ? loop_first : instr->index, compute_liveness_recurse(&loop->body, loop_first ? loop_first : instr->index,
loop_last ? loop_last : loop->next_index); loop_last ? loop_last : loop->next_index);
@ -3110,7 +3110,7 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
} }
case HLSL_IR_SWIZZLE: case HLSL_IR_SWIZZLE:
{ {
struct hlsl_ir_swizzle *swizzle = swizzle_from_node(instr); struct hlsl_ir_swizzle *swizzle = hlsl_ir_swizzle(instr);
swizzle->val.node->last_read = instr->index; swizzle->val.node->last_read = instr->index;
break; break;
@ -3170,7 +3170,7 @@ int hlsl_parser_compile(enum vkd3d_shader_type type, DWORD major, DWORD minor, c
init_functions_tree(&hlsl_ctx.functions); init_functions_tree(&hlsl_ctx.functions);
list_init(&hlsl_ctx.static_initializers); list_init(&hlsl_ctx.static_initializers);
push_scope(&hlsl_ctx); hlsl_push_scope(&hlsl_ctx);
hlsl_ctx.globals = hlsl_ctx.cur_scope; hlsl_ctx.globals = hlsl_ctx.cur_scope;
declare_predefined_types(hlsl_ctx.globals); declare_predefined_types(hlsl_ctx.globals);
@ -3185,7 +3185,7 @@ int hlsl_parser_compile(enum vkd3d_shader_type type, DWORD major, DWORD minor, c
goto out; goto out;
} }
if (!type_is_void(entry_func->return_type) if (!hlsl_type_is_void(entry_func->return_type)
&& entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic) && entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic)
{ {
hlsl_report_message(entry_func->loc, HLSL_LEVEL_ERROR, hlsl_report_message(entry_func->loc, HLSL_LEVEL_ERROR,
@ -3214,20 +3214,20 @@ out:
vkd3d_free(hlsl_ctx.source_files); vkd3d_free(hlsl_ctx.source_files);
TRACE("Freeing functions IR.\n"); TRACE("Freeing functions IR.\n");
rb_destroy(&hlsl_ctx.functions, free_function_rb, NULL); rb_destroy(&hlsl_ctx.functions, hlsl_free_function_rb, NULL);
TRACE("Freeing variables.\n"); TRACE("Freeing variables.\n");
LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &hlsl_ctx.scopes, struct hlsl_scope, entry) LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &hlsl_ctx.scopes, struct hlsl_scope, entry)
{ {
LIST_FOR_EACH_ENTRY_SAFE(var, next_var, &scope->vars, struct hlsl_ir_var, scope_entry) LIST_FOR_EACH_ENTRY_SAFE(var, next_var, &scope->vars, struct hlsl_ir_var, scope_entry)
free_declaration(var); hlsl_free_var(var);
rb_destroy(&scope->types, NULL, NULL); rb_destroy(&scope->types, NULL, NULL);
vkd3d_free(scope); vkd3d_free(scope);
} }
TRACE("Freeing types.\n"); TRACE("Freeing types.\n");
LIST_FOR_EACH_ENTRY_SAFE(hlsl_type, next_type, &hlsl_ctx.types, struct hlsl_type, entry) LIST_FOR_EACH_ENTRY_SAFE(hlsl_type, next_type, &hlsl_ctx.types, struct hlsl_type, entry)
free_hlsl_type(hlsl_type); hlsl_free_type(hlsl_type);
return ret; return ret;
} }