4 * Copyright 2008 Stefan Dösinger
5 * Copyright 2012 Matteo Bruni for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/debug.h"
27 #include "d3dcompiler_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
33 struct hlsl_parse_ctx hlsl_ctx;
36 static void set_location(struct source_location *loc, const struct YYLTYPE *l);
38 void hlsl_message(const char *fmt, ...)
43 compilation_message(&hlsl_ctx.messages, fmt, args);
47 static const char *hlsl_get_error_level_name(enum hlsl_error_level level)
58 void hlsl_report_message(const char *filename, DWORD line, DWORD column,
59 enum hlsl_error_level level, const char *fmt, ...)
68 rc = vsnprintf(string, size, fmt, args);
71 if (rc >= 0 && rc < size)
77 size = size ? size * 2 : 32;
80 string = d3dcompiler_alloc(size);
82 string = d3dcompiler_realloc(string, size);
85 ERR("Error reallocating memory for a string.\n");
90 hlsl_message("%s:%u:%u: %s: %s\n", filename, line, column, hlsl_get_error_level_name(level), string);
91 d3dcompiler_free(string);
93 if (level == HLSL_LEVEL_ERROR)
94 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
95 else if (level == HLSL_LEVEL_WARNING)
96 set_parse_status(&hlsl_ctx.status, PARSE_WARN);
99 static void hlsl_error(const char *s)
101 hlsl_report_message(hlsl_ctx.source_file, hlsl_ctx.line_no, hlsl_ctx.column, HLSL_LEVEL_ERROR, "%s", s);
104 static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char *declname, unsigned int line_no)
106 TRACE("Line %u: ", line_no);
108 TRACE("%s ", debug_modifiers(modifiers));
109 TRACE("%s %s;\n", debug_hlsl_type(type), declname);
112 static void check_invalid_matrix_modifiers(DWORD modifiers, struct source_location *loc)
114 if (modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR))
116 hlsl_report_message(loc->file, loc->line, loc->col, HLSL_LEVEL_ERROR,
117 "'row_major' or 'column_major' modifiers are only allowed for matrices");
121 static BOOL declare_variable(struct hlsl_ir_var *decl, BOOL local)
125 TRACE("Declaring variable %s.\n", decl->name);
126 if (decl->node.data_type->type == HLSL_CLASS_MATRIX)
128 if (!(decl->modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)))
130 decl->modifiers |= hlsl_ctx.matrix_majority == HLSL_ROW_MAJOR
131 ? HLSL_MODIFIER_ROW_MAJOR : HLSL_MODIFIER_COLUMN_MAJOR;
135 check_invalid_matrix_modifiers(decl->modifiers, &decl->node.loc);
139 DWORD invalid = decl->modifiers & (HLSL_STORAGE_EXTERN | HLSL_STORAGE_SHARED
140 | HLSL_STORAGE_GROUPSHARED | HLSL_STORAGE_UNIFORM);
143 hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR,
144 "modifier '%s' invalid for local variables", debug_modifiers(invalid));
148 hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR,
149 "semantics are not allowed on local variables");
155 if (find_function(decl->name))
157 hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR,
158 "redefinition of '%s'", decl->name);
162 ret = add_declaration(hlsl_ctx.cur_scope, decl, local);
165 struct hlsl_ir_var *old = get_variable(hlsl_ctx.cur_scope, decl->name);
167 hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR,
168 "\"%s\" already declared", decl->name);
169 hlsl_report_message(old->node.loc.file, old->node.loc.line, old->node.loc.col, HLSL_LEVEL_NOTE,
170 "\"%s\" was previously declared here", old->name);
176 static DWORD add_modifier(DWORD modifiers, DWORD mod, const struct YYLTYPE *loc);
178 static BOOL check_type_modifiers(DWORD modifiers, struct source_location *loc)
180 if (modifiers & ~HLSL_TYPE_MODIFIERS_MASK)
182 hlsl_report_message(loc->file, loc->line, loc->col, HLSL_LEVEL_ERROR,
183 "modifier not allowed on typedefs");
189 static BOOL add_type_to_scope(struct hlsl_scope *scope, struct hlsl_type *def)
191 if (get_type(scope, def->name, FALSE))
194 wine_rb_put(&scope->types, def->name, &def->scope_entry);
198 static void declare_predefined_types(struct hlsl_scope *scope)
200 struct hlsl_type *type;
201 unsigned int x, y, bt;
202 static const char *names[] =
213 for (bt = 0; bt <= HLSL_TYPE_LAST_SCALAR; ++bt)
215 for (y = 1; y <= 4; ++y)
217 for (x = 1; x <= 4; ++x)
219 sprintf(name, "%s%ux%u", names[bt], x, y);
220 type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_MATRIX, bt, x, y);
221 add_type_to_scope(scope, type);
225 sprintf(name, "%s%u", names[bt], x);
226 type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_VECTOR, bt, x, y);
227 add_type_to_scope(scope, type);
231 sprintf(name, "%s", names[bt]);
232 type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_SCALAR, bt, x, y);
233 add_type_to_scope(scope, type);
240 /* DX8 effects predefined types */
241 type = new_hlsl_type(d3dcompiler_strdup("DWORD"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1);
242 add_type_to_scope(scope, type);
243 type = new_hlsl_type(d3dcompiler_strdup("FLOAT"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1);
244 add_type_to_scope(scope, type);
245 type = new_hlsl_type(d3dcompiler_strdup("VECTOR"), HLSL_CLASS_VECTOR, HLSL_TYPE_FLOAT, 4, 1);
246 add_type_to_scope(scope, type);
247 type = new_hlsl_type(d3dcompiler_strdup("MATRIX"), HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4);
248 add_type_to_scope(scope, type);
249 type = new_hlsl_type(d3dcompiler_strdup("STRING"), HLSL_CLASS_OBJECT, HLSL_TYPE_STRING, 1, 1);
250 add_type_to_scope(scope, type);
251 type = new_hlsl_type(d3dcompiler_strdup("TEXTURE"), HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1);
252 add_type_to_scope(scope, type);
253 type = new_hlsl_type(d3dcompiler_strdup("PIXELSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1);
254 add_type_to_scope(scope, type);
255 type = new_hlsl_type(d3dcompiler_strdup("VERTEXSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1);
256 add_type_to_scope(scope, type);
259 static struct hlsl_ir_if *loop_condition(struct list *cond_list)
261 struct hlsl_ir_if *out_cond;
262 struct hlsl_ir_expr *not_cond;
263 struct hlsl_ir_node *cond, *operands[3];
264 struct hlsl_ir_jump *jump;
265 unsigned int count = list_count(cond_list);
270 ERR("Got multiple expressions in a for condition.\n");
272 cond = LIST_ENTRY(list_head(cond_list), struct hlsl_ir_node, entry);
273 out_cond = d3dcompiler_alloc(sizeof(*out_cond));
276 ERR("Out of memory.\n");
279 out_cond->node.type = HLSL_IR_IF;
281 operands[1] = operands[2] = NULL;
282 not_cond = new_expr(HLSL_IR_UNOP_LOGIC_NOT, operands, &cond->loc);
285 ERR("Out of memory.\n");
286 d3dcompiler_free(out_cond);
289 out_cond->condition = ¬_cond->node;
290 jump = d3dcompiler_alloc(sizeof(*jump));
293 ERR("Out of memory.\n");
294 d3dcompiler_free(out_cond);
295 d3dcompiler_free(not_cond);
298 jump->node.type = HLSL_IR_JUMP;
299 jump->type = HLSL_IR_JUMP_BREAK;
300 out_cond->then_instrs = d3dcompiler_alloc(sizeof(*out_cond->then_instrs));
301 if (!out_cond->then_instrs)
303 ERR("Out of memory.\n");
304 d3dcompiler_free(out_cond);
305 d3dcompiler_free(not_cond);
306 d3dcompiler_free(jump);
309 list_init(out_cond->then_instrs);
310 list_add_head(out_cond->then_instrs, &jump->node.entry);
322 static struct list *create_loop(enum loop_type type, struct list *init, struct list *cond,
323 struct list *iter, struct list *body, struct source_location *loc)
325 struct list *list = NULL;
326 struct hlsl_ir_loop *loop = NULL;
327 struct hlsl_ir_if *cond_jump = NULL;
329 list = d3dcompiler_alloc(sizeof(*list));
335 list_move_head(list, init);
337 loop = d3dcompiler_alloc(sizeof(*loop));
340 loop->node.type = HLSL_IR_LOOP;
341 loop->node.loc = *loc;
342 list_add_tail(list, &loop->node.entry);
343 loop->body = d3dcompiler_alloc(sizeof(*loop->body));
346 list_init(loop->body);
348 cond_jump = loop_condition(cond);
352 if (type != LOOP_DO_WHILE)
353 list_add_tail(loop->body, &cond_jump->node.entry);
355 list_move_tail(loop->body, body);
358 list_move_tail(loop->body, iter);
360 if (type == LOOP_DO_WHILE)
361 list_add_tail(loop->body, &cond_jump->node.entry);
363 d3dcompiler_free(init);
364 d3dcompiler_free(cond);
365 d3dcompiler_free(iter);
366 d3dcompiler_free(body);
370 ERR("Out of memory.\n");
372 d3dcompiler_free(loop->body);
373 d3dcompiler_free(loop);
374 d3dcompiler_free(cond_jump);
375 d3dcompiler_free(list);
376 free_instr_list(init);
377 free_instr_list(cond);
378 free_instr_list(iter);
379 free_instr_list(body);
383 static unsigned int initializer_size(struct list *initializer)
385 unsigned int count = 0;
386 struct hlsl_ir_node *node;
388 LIST_FOR_EACH_ENTRY(node, initializer, struct hlsl_ir_node, entry)
390 count += components_count_type(node->data_type);
392 TRACE("Initializer size = %u\n", count);
396 static unsigned int components_count_expr_list(struct list *list)
398 struct hlsl_ir_node *node;
399 unsigned int count = 0;
401 LIST_FOR_EACH_ENTRY(node, list, struct hlsl_ir_node, entry)
403 count += components_count_type(node->data_type);
408 static struct hlsl_ir_swizzle *new_swizzle(DWORD s, unsigned int components,
409 struct hlsl_ir_node *val, struct source_location *loc)
411 struct hlsl_ir_swizzle *swizzle = d3dcompiler_alloc(sizeof(*swizzle));
415 swizzle->node.type = HLSL_IR_SWIZZLE;
416 swizzle->node.loc = *loc;
417 swizzle->node.data_type = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1);
419 swizzle->swizzle = s;
423 static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ir_node *value, const char *swizzle,
424 struct source_location *loc)
426 unsigned int len = strlen(swizzle), component = 0;
427 unsigned int i, set, swiz = 0;
430 if (value->data_type->type == HLSL_CLASS_MATRIX)
434 unsigned int inc, x, y;
436 if (len < 3 || swizzle[0] != '_')
438 m_swizzle = swizzle[1] == 'm';
439 inc = m_swizzle ? 4 : 3;
441 if (len % inc || len > inc * 4)
444 for (i = 0; i < len; i += inc)
446 if (swizzle[i] != '_')
450 if (swizzle[i + 1] != 'm')
452 x = swizzle[i + 2] - '0';
453 y = swizzle[i + 3] - '0';
457 x = swizzle[i + 1] - '1';
458 y = swizzle[i + 2] - '1';
461 if (x >= value->data_type->dimx || y >= value->data_type->dimy)
463 swiz |= (y << 4 | x) << component * 8;
466 return new_swizzle(swiz, component, value, loc);
473 for (set = 0; set < 2; ++set)
477 for (i = 0; i < len; ++i)
479 char c[2][4] = {{'x', 'y', 'z', 'w'}, {'r', 'g', 'b', 'a'}};
482 for (s = 0; s < 4; ++s)
484 if (swizzle[i] == c[set][s])
493 if (s >= value->data_type->dimx)
495 swiz |= s << component * 2;
499 return new_swizzle(swiz, component, value, loc);
505 static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct list *list,
506 struct source_location *loc)
509 struct hlsl_type *type;
510 struct parse_variable_def *v, *v_next;
512 if (!check_type_modifiers(modifiers, loc))
514 LIST_FOR_EACH_ENTRY_SAFE(v, v_next, list, struct parse_variable_def, entry)
516 d3dcompiler_free(list);
520 LIST_FOR_EACH_ENTRY_SAFE(v, v_next, list, struct parse_variable_def, entry)
523 type = new_array_type(orig_type, v->array_size);
525 type = clone_hlsl_type(orig_type);
528 ERR("Out of memory\n");
531 d3dcompiler_free((void *)type->name);
532 type->name = v->name;
533 type->modifiers |= modifiers;
535 if (type->type != HLSL_CLASS_MATRIX)
536 check_invalid_matrix_modifiers(type->modifiers, &v->loc);
538 ret = add_type_to_scope(hlsl_ctx.cur_scope, type);
541 hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR,
542 "redefinition of custom type '%s'", v->name);
546 d3dcompiler_free(list);
558 struct hlsl_type *type;
564 struct hlsl_ir_var *var;
565 struct hlsl_ir_node *instr;
567 struct hlsl_ir_function_decl *function;
568 struct parse_parameter parameter;
569 struct parse_variable_def *variable_def;
570 struct parse_if_body if_body;
571 enum parse_unary_op unary_op;
572 enum parse_assign_op assign_op;
579 %token KW_COLUMN_MAJOR
583 %token KW_DEPTHSTENCILSTATE
584 %token KW_DEPTHSTENCILVIEW
592 %token KW_GEOMETRYSHADER
593 %token KW_GROUPSHARED
600 %token KW_NOINTERPOLATION
603 %token KW_PIXELSHADER
605 %token KW_RASTERIZERSTATE
606 %token KW_RENDERTARGETVIEW
614 %token KW_SAMPLERCUBE
615 %token KW_SAMPLER_STATE
616 %token KW_SAMPLERCOMPARISONSTATE
619 %token KW_STATEBLOCK_STATE
626 %token KW_TECHNIQUE10
629 %token KW_TEXTURE1DARRAY
631 %token KW_TEXTURE2DARRAY
632 %token KW_TEXTURE2DMS
633 %token KW_TEXTURE2DMSARRAY
635 %token KW_TEXTURE3DARRAY
636 %token KW_TEXTURECUBE
641 %token KW_VERTEXSHADER
652 %token OP_LEFTSHIFTASSIGN
654 %token OP_RIGHTSHIFTASSIGN
672 %token <intval> PRE_LINE
674 %token <name> VAR_IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
675 %type <name> any_identifier var_identifier
677 %token <floatval> C_FLOAT
678 %token <intval> C_INTEGER
679 %type <boolval> boolean
680 %type <type> base_type
682 %type <list> declaration_statement
683 %type <list> declaration
684 %type <list> type_specs
685 %type <variable_def> type_spec
686 %type <list> complex_initializer
687 %type <list> initializer_expr_list
688 %type <instr> initializer_expr
689 %type <modifiers> var_modifiers
690 %type <list> parameters
691 %type <list> param_list
695 %type <list> statement
696 %type <list> statement_list
697 %type <list> compound_statement
698 %type <list> jump_statement
699 %type <list> selection_statement
700 %type <list> loop_statement
701 %type <function> func_declaration
702 %type <function> func_prototype
703 %type <parameter> parameter
704 %type <name> semantic
705 %type <variable_def> variable_def
706 %type <list> variables_def
707 %type <if_body> if_body
708 %type <instr> primary_expr
709 %type <instr> postfix_expr
710 %type <instr> unary_expr
711 %type <instr> mul_expr
712 %type <instr> add_expr
713 %type <instr> shift_expr
714 %type <instr> relational_expr
715 %type <instr> equality_expr
716 %type <instr> bitand_expr
717 %type <instr> bitxor_expr
718 %type <instr> bitor_expr
719 %type <instr> logicand_expr
720 %type <instr> logicor_expr
721 %type <instr> conditional_expr
722 %type <instr> assignment_expr
723 %type <list> expr_statement
724 %type <unary_op> unary_op
725 %type <assign_op> assign_op
726 %type <modifiers> input_mod
729 hlsl_prog: /* empty */
732 | hlsl_prog func_declaration
734 FIXME("Check that the function doesn't conflict with an already declared one.\n");
735 list_add_tail(&hlsl_ctx.functions, &$2->node.entry);
737 | hlsl_prog declaration_statement
739 TRACE("Declaration statement parsed.\n");
741 | hlsl_prog preproc_directive
745 preproc_directive: PRE_LINE STRING
747 TRACE("Updating line information to file %s, line %u\n", debugstr_a($2), $1);
748 hlsl_ctx.line_no = $1;
749 if (strcmp($2, hlsl_ctx.source_file))
751 const char **new_array;
753 hlsl_ctx.source_file = $2;
754 new_array = d3dcompiler_realloc(hlsl_ctx.source_files,
755 sizeof(*hlsl_ctx.source_files) * hlsl_ctx.source_files_count + 1);
758 hlsl_ctx.source_files = new_array;
759 hlsl_ctx.source_files[hlsl_ctx.source_files_count++] = $2;
764 any_identifier: VAR_IDENTIFIER
768 func_declaration: func_prototype compound_statement
770 TRACE("Function %s parsed.\n", $1->name);
773 pop_scope(&hlsl_ctx);
777 TRACE("Function prototype for %s.\n", $1->name);
779 pop_scope(&hlsl_ctx);
782 func_prototype: var_modifiers type var_identifier '(' parameters ')' semantic
784 if (get_variable(hlsl_ctx.globals, $3))
786 hlsl_report_message(hlsl_ctx.source_file, @3.first_line, @3.first_column,
787 HLSL_LEVEL_ERROR, "redefinition of '%s'\n", $3);
790 if ($2->base_type == HLSL_TYPE_VOID && $7)
792 hlsl_report_message(hlsl_ctx.source_file, @7.first_line, @7.first_column,
793 HLSL_LEVEL_ERROR, "void function with a semantic");
796 $$ = new_func_decl($3, $2, $5);
799 ERR("Out of memory.\n");
805 compound_statement: '{' '}'
807 $$ = d3dcompiler_alloc(sizeof(*$$));
810 | '{' scope_start statement_list '}'
812 pop_scope(&hlsl_ctx);
816 scope_start: /* Empty */
818 push_scope(&hlsl_ctx);
821 var_identifier: VAR_IDENTIFIER
824 semantic: /* Empty */
833 parameters: scope_start
835 $$ = d3dcompiler_alloc(sizeof(*$$));
838 | scope_start param_list
843 param_list: parameter
845 struct source_location loc;
847 $$ = d3dcompiler_alloc(sizeof(*$$));
849 set_location(&loc, &@1);
850 if (!add_func_parameter($$, &$1, &loc))
852 ERR("Error adding function parameter %s.\n", $1.name);
853 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
857 | param_list ',' parameter
859 struct source_location loc;
862 set_location(&loc, &@3);
863 if (!add_func_parameter($$, &$3, &loc))
865 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
866 "duplicate parameter %s", $3.name);
871 parameter: input_mod var_modifiers type any_identifier semantic
880 input_mod: /* Empty */
882 $$ = HLSL_MODIFIER_IN;
886 $$ = HLSL_MODIFIER_IN;
890 $$ = HLSL_MODIFIER_OUT;
894 $$ = HLSL_MODIFIER_IN | HLSL_MODIFIER_OUT;
901 | KW_VECTOR '<' base_type ',' C_INTEGER '>'
903 if ($3->type != HLSL_CLASS_SCALAR)
905 hlsl_message("Line %u: vectors of non-scalar types are not allowed.\n",
907 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
910 if ($5 < 1 || $5 > 4)
912 hlsl_message("Line %u: vector size must be between 1 and 4.\n",
914 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
918 $$ = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, $3->base_type, $5, 1);
920 | KW_MATRIX '<' base_type ',' C_INTEGER ',' C_INTEGER '>'
922 if ($3->type != HLSL_CLASS_SCALAR)
924 hlsl_message("Line %u: matrices of non-scalar types are not allowed.\n",
926 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
929 if ($5 < 1 || $5 > 4 || $7 < 1 || $7 > 4)
931 hlsl_message("Line %u: matrix dimensions must be between 1 and 4.\n",
933 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
937 $$ = new_hlsl_type(NULL, HLSL_CLASS_MATRIX, $3->base_type, $5, $7);
942 $$ = new_hlsl_type(d3dcompiler_strdup("void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1);
946 $$ = new_hlsl_type(d3dcompiler_strdup("sampler"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
947 $$->sampler_dim = HLSL_SAMPLER_DIM_GENERIC;
951 $$ = new_hlsl_type(d3dcompiler_strdup("sampler1D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
952 $$->sampler_dim = HLSL_SAMPLER_DIM_1D;
956 $$ = new_hlsl_type(d3dcompiler_strdup("sampler2D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
957 $$->sampler_dim = HLSL_SAMPLER_DIM_2D;
961 $$ = new_hlsl_type(d3dcompiler_strdup("sampler3D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
962 $$->sampler_dim = HLSL_SAMPLER_DIM_3D;
966 $$ = new_hlsl_type(d3dcompiler_strdup("samplerCUBE"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
967 $$->sampler_dim = HLSL_SAMPLER_DIM_CUBE;
971 struct hlsl_type *type;
973 TRACE("Type %s.\n", $1);
974 type = get_type(hlsl_ctx.cur_scope, $1, TRUE);
976 d3dcompiler_free($1);
978 | KW_STRUCT TYPE_IDENTIFIER
980 struct hlsl_type *type;
982 TRACE("Struct type %s.\n", $2);
983 type = get_type(hlsl_ctx.cur_scope, $2, TRUE);
984 if (type->type != HLSL_CLASS_STRUCT)
986 hlsl_message("Line %u: redefining %s as a structure.\n",
987 hlsl_ctx.line_no, $2);
988 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
994 d3dcompiler_free($2);
997 declaration_statement: declaration
1003 $$ = d3dcompiler_alloc(sizeof(*$$));
1006 ERR("Out of memory\n");
1012 typedef: KW_TYPEDEF var_modifiers type type_specs ';'
1014 struct source_location loc;
1016 set_location(&loc, &@1);
1017 if (!add_typedef($2, $3, $4, &loc))
1021 type_specs: type_spec
1023 $$ = d3dcompiler_alloc(sizeof(*$$));
1025 list_add_head($$, &$1->entry);
1027 | type_specs ',' type_spec
1030 list_add_tail($$, &$3->entry);
1033 type_spec: any_identifier array
1035 $$ = d3dcompiler_alloc(sizeof(*$$));
1036 set_location(&$$->loc, &@1);
1038 $$->array_size = $2;
1041 declaration: var_modifiers type variables_def ';'
1043 struct hlsl_type *type;
1044 struct parse_variable_def *v, *v_next;
1045 struct hlsl_ir_var *var;
1046 struct hlsl_ir_node *assignment;
1047 BOOL ret, local = TRUE;
1049 $$ = d3dcompiler_alloc(sizeof(*$$));
1051 LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $3, struct parse_variable_def, entry)
1053 debug_dump_decl($2, $1, v->name, hlsl_ctx.line_no);
1054 var = d3dcompiler_alloc(sizeof(*var));
1055 var->node.type = HLSL_IR_VAR;
1057 type = new_array_type($2, v->array_size);
1060 var->node.data_type = type;
1061 var->node.loc = v->loc;
1062 var->name = v->name;
1063 var->modifiers = $1;
1064 var->semantic = v->semantic;
1066 if (hlsl_ctx.cur_scope == hlsl_ctx.globals)
1068 var->modifiers |= HLSL_STORAGE_UNIFORM;
1072 if (var->modifiers & HLSL_MODIFIER_CONST && !v->initializer)
1074 hlsl_report_message(v->loc.file, v->loc.line, v->loc.col,
1075 HLSL_LEVEL_ERROR, "const variable without initializer");
1076 free_declaration(var);
1077 d3dcompiler_free(v);
1081 ret = declare_variable(var, local);
1083 free_declaration(var);
1085 TRACE("Declared variable %s.\n", var->name);
1089 unsigned int size = initializer_size(v->initializer);
1090 struct hlsl_ir_node *node;
1092 TRACE("Variable with initializer\n");
1093 if (type->type <= HLSL_CLASS_LAST_NUMERIC
1094 && type->dimx * type->dimy != size
1097 if (size < type->dimx * type->dimy)
1099 hlsl_report_message(v->loc.file,
1100 v->loc.line, v->loc.col, HLSL_LEVEL_ERROR,
1101 "'%s' initializer does not match", v->name);
1102 free_instr_list(v->initializer);
1103 d3dcompiler_free(v);
1108 if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY)
1109 && components_count_type(type) != size)
1111 hlsl_report_message(v->loc.file,
1112 v->loc.line, v->loc.col, HLSL_LEVEL_ERROR,
1113 "'%s' initializer does not match", v->name);
1114 free_instr_list(v->initializer);
1115 d3dcompiler_free(v);
1119 if (type->type > HLSL_CLASS_LAST_NUMERIC)
1121 FIXME("Initializers for non scalar/struct variables not supported yet\n");
1122 free_instr_list(v->initializer);
1123 d3dcompiler_free(v);
1126 if (v->array_size > 0)
1128 FIXME("Initializing arrays is not supported yet\n");
1129 free_instr_list(v->initializer);
1130 d3dcompiler_free(v);
1134 if (list_count(v->initializer) > 1)
1136 FIXME("Complex initializers are not supported yet.\n");
1137 free_instr_list(v->initializer);
1138 d3dcompiler_free(v);
1141 node = LIST_ENTRY(list_head(v->initializer), struct hlsl_ir_node, entry);
1142 assignment = make_assignment(&var->node, ASSIGN_OP_ASSIGN,
1143 BWRITERSP_WRITEMASK_ALL, node);
1144 list_add_tail($$, &assignment->entry);
1146 d3dcompiler_free(v);
1148 d3dcompiler_free($3);
1151 variables_def: variable_def
1153 $$ = d3dcompiler_alloc(sizeof(*$$));
1155 list_add_head($$, &$1->entry);
1157 | variables_def ',' variable_def
1160 list_add_tail($$, &$3->entry);
1163 variable_def: any_identifier array semantic
1165 $$ = d3dcompiler_alloc(sizeof(*$$));
1166 set_location(&$$->loc, &@1);
1168 $$->array_size = $2;
1171 | any_identifier array semantic '=' complex_initializer
1173 TRACE("Declaration with initializer.\n");
1174 $$ = d3dcompiler_alloc(sizeof(*$$));
1175 set_location(&$$->loc, &@1);
1177 $$->array_size = $2;
1179 $$->initializer = $5;
1193 var_modifiers: /* Empty */
1197 | KW_EXTERN var_modifiers
1199 $$ = add_modifier($2, HLSL_STORAGE_EXTERN, &@1);
1201 | KW_NOINTERPOLATION var_modifiers
1203 $$ = add_modifier($2, HLSL_STORAGE_NOINTERPOLATION, &@1);
1205 | KW_PRECISE var_modifiers
1207 $$ = add_modifier($2, HLSL_MODIFIER_PRECISE, &@1);
1209 | KW_SHARED var_modifiers
1211 $$ = add_modifier($2, HLSL_STORAGE_SHARED, &@1);
1213 | KW_GROUPSHARED var_modifiers
1215 $$ = add_modifier($2, HLSL_STORAGE_GROUPSHARED, &@1);
1217 | KW_STATIC var_modifiers
1219 $$ = add_modifier($2, HLSL_STORAGE_STATIC, &@1);
1221 | KW_UNIFORM var_modifiers
1223 $$ = add_modifier($2, HLSL_STORAGE_UNIFORM, &@1);
1225 | KW_VOLATILE var_modifiers
1227 $$ = add_modifier($2, HLSL_STORAGE_VOLATILE, &@1);
1229 | KW_CONST var_modifiers
1231 $$ = add_modifier($2, HLSL_MODIFIER_CONST, &@1);
1233 | KW_ROW_MAJOR var_modifiers
1235 $$ = add_modifier($2, HLSL_MODIFIER_ROW_MAJOR, &@1);
1237 | KW_COLUMN_MAJOR var_modifiers
1239 $$ = add_modifier($2, HLSL_MODIFIER_COLUMN_MAJOR, &@1);
1242 complex_initializer: initializer_expr
1244 $$ = d3dcompiler_alloc(sizeof(*$$));
1246 list_add_head($$, &$1->entry);
1248 | '{' initializer_expr_list '}'
1253 initializer_expr: assignment_expr
1258 initializer_expr_list: initializer_expr
1260 $$ = d3dcompiler_alloc(sizeof(*$$));
1262 list_add_head($$, &$1->entry);
1264 | initializer_expr_list ',' initializer_expr
1267 list_add_tail($$, &$3->entry);
1279 statement_list: statement
1283 | statement_list statement
1286 list_move_tail($$, $2);
1287 d3dcompiler_free($2);
1290 statement: declaration_statement
1292 | compound_statement
1294 | selection_statement
1297 /* FIXME: add rule for return with no value */
1298 jump_statement: KW_RETURN expr ';'
1300 struct hlsl_ir_jump *jump = d3dcompiler_alloc(sizeof(*jump));
1303 ERR("Out of memory\n");
1306 jump->node.type = HLSL_IR_JUMP;
1307 set_location(&jump->node.loc, &@1);
1308 jump->type = HLSL_IR_JUMP_RETURN;
1309 jump->node.data_type = $2->data_type;
1310 jump->return_value = $2;
1312 FIXME("Check for valued return on void function.\n");
1313 FIXME("Implicit conversion to the return type if needed, "
1314 "error out if conversion not possible.\n");
1316 $$ = d3dcompiler_alloc(sizeof(*$$));
1318 list_add_tail($$, &jump->node.entry);
1321 selection_statement: KW_IF '(' expr ')' if_body
1323 struct hlsl_ir_if *instr = d3dcompiler_alloc(sizeof(*instr));
1326 ERR("Out of memory\n");
1329 instr->node.type = HLSL_IR_IF;
1330 set_location(&instr->node.loc, &@1);
1331 instr->condition = $3;
1332 instr->then_instrs = $5.then_instrs;
1333 instr->else_instrs = $5.else_instrs;
1334 if ($3->data_type->dimx > 1 || $3->data_type->dimy > 1)
1336 hlsl_report_message(instr->node.loc.file, instr->node.loc.line,
1337 instr->node.loc.col, HLSL_LEVEL_ERROR,
1338 "if condition requires a scalar");
1340 $$ = d3dcompiler_alloc(sizeof(*$$));
1342 list_add_head($$, &instr->node.entry);
1347 $$.then_instrs = $1;
1348 $$.else_instrs = NULL;
1350 | statement KW_ELSE statement
1352 $$.then_instrs = $1;
1353 $$.else_instrs = $3;
1356 loop_statement: KW_WHILE '(' expr ')' statement
1358 struct source_location loc;
1359 struct list *cond = d3dcompiler_alloc(sizeof(*cond));
1363 ERR("Out of memory.\n");
1367 list_add_head(cond, &$3->entry);
1368 set_location(&loc, &@1);
1369 $$ = create_loop(LOOP_WHILE, NULL, cond, NULL, $5, &loc);
1374 $$ = d3dcompiler_alloc(sizeof(*$$));
1379 $$ = d3dcompiler_alloc(sizeof(*$$));
1382 list_add_head($$, &$1->entry);
1385 primary_expr: C_FLOAT
1387 struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c));
1390 ERR("Out of memory.\n");
1393 c->node.type = HLSL_IR_CONSTANT;
1394 set_location(&c->node.loc, &yylloc);
1395 c->node.data_type = new_hlsl_type("float", HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1);
1396 c->v.value.f[0] = $1;
1401 struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c));
1404 ERR("Out of memory.\n");
1407 c->node.type = HLSL_IR_CONSTANT;
1408 set_location(&c->node.loc, &yylloc);
1409 c->node.data_type = new_hlsl_type("int", HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1);
1410 c->v.value.i[0] = $1;
1415 struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c));
1418 ERR("Out of memory.\n");
1421 c->node.type = HLSL_IR_CONSTANT;
1422 set_location(&c->node.loc, &yylloc);
1423 c->node.data_type = new_hlsl_type("bool", HLSL_CLASS_SCALAR, HLSL_TYPE_BOOL, 1, 1);
1424 c->v.value.b[0] = $1;
1429 struct hlsl_ir_deref *deref = new_var_deref($1);
1433 set_location(&$$->loc, &@1);
1443 variable: VAR_IDENTIFIER
1445 struct hlsl_ir_var *var;
1446 var = get_variable(hlsl_ctx.cur_scope, $1);
1449 hlsl_message("Line %d: variable '%s' not declared\n",
1450 hlsl_ctx.line_no, $1);
1451 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
1457 postfix_expr: primary_expr
1461 | postfix_expr OP_INC
1463 struct hlsl_ir_node *operands[3];
1464 struct source_location loc;
1466 set_location(&loc, &@2);
1467 if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
1469 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1470 "modifying a const expression");
1474 operands[1] = operands[2] = NULL;
1475 $$ = &new_expr(HLSL_IR_BINOP_POSTINC, operands, &loc)->node;
1476 /* Post increment/decrement expressions are considered const */
1477 $$->data_type = clone_hlsl_type($$->data_type);
1478 $$->data_type->modifiers |= HLSL_MODIFIER_CONST;
1480 | postfix_expr OP_DEC
1482 struct hlsl_ir_node *operands[3];
1483 struct source_location loc;
1485 set_location(&loc, &@2);
1486 if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
1488 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1489 "modifying a const expression");
1493 operands[1] = operands[2] = NULL;
1494 $$ = &new_expr(HLSL_IR_BINOP_POSTDEC, operands, &loc)->node;
1495 /* Post increment/decrement expressions are considered const */
1496 $$->data_type = clone_hlsl_type($$->data_type);
1497 $$->data_type->modifiers |= HLSL_MODIFIER_CONST;
1499 | postfix_expr '.' any_identifier
1501 struct source_location loc;
1503 set_location(&loc, &@2);
1504 if ($1->data_type->type <= HLSL_CLASS_LAST_NUMERIC)
1506 struct hlsl_ir_swizzle *swizzle;
1508 swizzle = get_swizzle($1, $3, &loc);
1511 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1512 "invalid swizzle %s", debugstr_a($3));
1515 $$ = &swizzle->node;
1519 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1520 "invalid subscript %s", debugstr_a($3));
1524 /* "var_modifiers" doesn't make sense in this case, but it's needed
1525 in the grammar to avoid shift/reduce conflicts. */
1526 | var_modifiers type '(' initializer_expr_list ')'
1528 struct hlsl_ir_constructor *constructor;
1530 TRACE("%s constructor.\n", debug_hlsl_type($2));
1533 hlsl_message("Line %u: unexpected modifier in a constructor.\n",
1535 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
1538 if ($2->type > HLSL_CLASS_LAST_NUMERIC)
1540 hlsl_message("Line %u: constructors are allowed only for numeric data types.\n",
1542 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
1545 if ($2->dimx * $2->dimy != components_count_expr_list($4))
1547 hlsl_message("Line %u: wrong number of components in constructor.\n",
1549 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
1553 constructor = d3dcompiler_alloc(sizeof(*constructor));
1554 constructor->node.type = HLSL_IR_CONSTRUCTOR;
1555 set_location(&constructor->node.loc, &@3);
1556 constructor->node.data_type = $2;
1557 constructor->arguments = $4;
1559 $$ = &constructor->node;
1562 unary_expr: postfix_expr
1568 struct hlsl_ir_node *operands[3];
1569 struct source_location loc;
1571 set_location(&loc, &@1);
1572 if ($2->data_type->modifiers & HLSL_MODIFIER_CONST)
1574 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1575 "modifying a const expression");
1579 operands[1] = operands[2] = NULL;
1580 $$ = &new_expr(HLSL_IR_BINOP_PREINC, operands, &loc)->node;
1584 struct hlsl_ir_node *operands[3];
1585 struct source_location loc;
1587 set_location(&loc, &@1);
1588 if ($2->data_type->modifiers & HLSL_MODIFIER_CONST)
1590 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1591 "modifying a const expression");
1595 operands[1] = operands[2] = NULL;
1596 $$ = &new_expr(HLSL_IR_BINOP_PREDEC, operands, &loc)->node;
1598 | unary_op unary_expr
1600 enum hlsl_ir_expr_op ops[] = {0, HLSL_IR_UNOP_NEG,
1601 HLSL_IR_UNOP_LOGIC_NOT, HLSL_IR_UNOP_BIT_NOT};
1602 struct hlsl_ir_node *operands[3];
1603 struct source_location loc;
1605 if ($1 == UNARY_OP_PLUS)
1612 operands[1] = operands[2] = NULL;
1613 set_location(&loc, &@1);
1614 $$ = &new_expr(ops[$1], operands, &loc)->node;
1617 /* var_modifiers just to avoid shift/reduce conflicts */
1618 | '(' var_modifiers type array ')' unary_expr
1620 struct hlsl_ir_expr *expr;
1621 struct hlsl_type *src_type = $6->data_type;
1622 struct hlsl_type *dst_type;
1623 struct source_location loc;
1625 set_location(&loc, &@3);
1628 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1629 "unexpected modifier in a cast");
1634 dst_type = new_array_type($3, $4);
1638 if (!compatible_data_types(src_type, dst_type))
1640 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1641 "can't cast from %s to %s",
1642 debug_hlsl_type(src_type), debug_hlsl_type(dst_type));
1646 expr = new_cast($6, dst_type, &loc);
1647 $$ = expr ? &expr->node : NULL;
1656 $$ = UNARY_OP_MINUS;
1660 $$ = UNARY_OP_LOGICNOT;
1664 $$ = UNARY_OP_BITNOT;
1667 mul_expr: unary_expr
1671 | mul_expr '*' unary_expr
1673 struct source_location loc;
1675 set_location(&loc, &@2);
1676 $$ = &hlsl_mul($1, $3, &loc)->node;
1678 | mul_expr '/' unary_expr
1680 struct source_location loc;
1682 set_location(&loc, &@2);
1683 $$ = &hlsl_div($1, $3, &loc)->node;
1685 | mul_expr '%' unary_expr
1687 struct source_location loc;
1689 set_location(&loc, &@2);
1690 $$ = &hlsl_mod($1, $3, &loc)->node;
1697 | add_expr '+' mul_expr
1699 struct source_location loc;
1701 set_location(&loc, &@2);
1702 $$ = &hlsl_add($1, $3, &loc)->node;
1704 | add_expr '-' mul_expr
1706 struct source_location loc;
1708 set_location(&loc, &@2);
1709 $$ = &hlsl_sub($1, $3, &loc)->node;
1712 shift_expr: add_expr
1716 | shift_expr OP_LEFTSHIFT add_expr
1718 FIXME("Left shift\n");
1720 | shift_expr OP_RIGHTSHIFT add_expr
1722 FIXME("Right shift\n");
1725 relational_expr: shift_expr
1729 | relational_expr '<' shift_expr
1731 struct source_location loc;
1733 set_location(&loc, &@2);
1734 $$ = &hlsl_lt($1, $3, &loc)->node;
1736 | relational_expr '>' shift_expr
1738 struct source_location loc;
1740 set_location(&loc, &@2);
1741 $$ = &hlsl_gt($1, $3, &loc)->node;
1743 | relational_expr OP_LE shift_expr
1745 struct source_location loc;
1747 set_location(&loc, &@2);
1748 $$ = &hlsl_le($1, $3, &loc)->node;
1750 | relational_expr OP_GE shift_expr
1752 struct source_location loc;
1754 set_location(&loc, &@2);
1755 $$ = &hlsl_ge($1, $3, &loc)->node;
1758 equality_expr: relational_expr
1762 | equality_expr OP_EQ relational_expr
1764 struct source_location loc;
1766 set_location(&loc, &@2);
1767 $$ = &hlsl_eq($1, $3, &loc)->node;
1769 | equality_expr OP_NE relational_expr
1771 struct source_location loc;
1773 set_location(&loc, &@2);
1774 $$ = &hlsl_ne($1, $3, &loc)->node;
1777 bitand_expr: equality_expr
1781 | bitand_expr '&' equality_expr
1783 FIXME("bitwise AND\n");
1786 bitxor_expr: bitand_expr
1790 | bitxor_expr '^' bitand_expr
1792 FIXME("bitwise XOR\n");
1795 bitor_expr: bitxor_expr
1799 | bitor_expr '|' bitxor_expr
1801 FIXME("bitwise OR\n");
1804 logicand_expr: bitor_expr
1808 | logicand_expr OP_AND bitor_expr
1810 FIXME("logic AND\n");
1813 logicor_expr: logicand_expr
1817 | logicor_expr OP_OR logicand_expr
1819 FIXME("logic OR\n");
1822 conditional_expr: logicor_expr
1826 | logicor_expr '?' expr ':' assignment_expr
1828 FIXME("ternary operator\n");
1831 assignment_expr: conditional_expr
1835 | unary_expr assign_op assignment_expr
1837 struct source_location loc;
1839 set_location(&loc, &@2);
1840 if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
1842 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1843 "l-value is const");
1846 $$ = make_assignment($1, $2, BWRITERSP_WRITEMASK_ALL, $3);
1854 $$ = ASSIGN_OP_ASSIGN;
1876 | OP_LEFTSHIFTASSIGN
1878 $$ = ASSIGN_OP_LSHIFT;
1880 | OP_RIGHTSHIFTASSIGN
1882 $$ = ASSIGN_OP_RSHIFT;
1897 expr: assignment_expr
1901 | expr ',' assignment_expr
1903 FIXME("Comma expression\n");
1908 static void set_location(struct source_location *loc, const struct YYLTYPE *l)
1910 loc->file = hlsl_ctx.source_file;
1911 loc->line = l->first_line;
1912 loc->col = l->first_column;
1915 static DWORD add_modifier(DWORD modifiers, DWORD mod, const struct YYLTYPE *loc)
1917 if (modifiers & mod)
1919 hlsl_report_message(hlsl_ctx.source_file, loc->first_line, loc->first_column, HLSL_LEVEL_ERROR,
1920 "modifier '%s' already specified", debug_modifiers(mod));
1923 if (mod & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)
1924 && modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR))
1926 hlsl_report_message(hlsl_ctx.source_file, loc->first_line, loc->first_column, HLSL_LEVEL_ERROR,
1927 "more than one matrix majority keyword");
1930 return modifiers | mod;
1933 struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
1934 const char *entrypoint, char **messages)
1936 struct hlsl_ir_function_decl *function;
1937 struct hlsl_scope *scope, *next_scope;
1938 struct hlsl_type *hlsl_type, *next_type;
1939 struct hlsl_ir_var *var, *next_var;
1942 hlsl_ctx.status = PARSE_SUCCESS;
1943 hlsl_ctx.messages.size = hlsl_ctx.messages.capacity = 0;
1944 hlsl_ctx.line_no = hlsl_ctx.column = 1;
1945 hlsl_ctx.source_file = d3dcompiler_strdup("");
1946 hlsl_ctx.source_files = d3dcompiler_alloc(sizeof(*hlsl_ctx.source_files));
1947 if (hlsl_ctx.source_files)
1948 hlsl_ctx.source_files[0] = hlsl_ctx.source_file;
1949 hlsl_ctx.source_files_count = 1;
1950 hlsl_ctx.cur_scope = NULL;
1951 hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
1952 list_init(&hlsl_ctx.scopes);
1953 list_init(&hlsl_ctx.types);
1954 list_init(&hlsl_ctx.functions);
1956 push_scope(&hlsl_ctx);
1957 hlsl_ctx.globals = hlsl_ctx.cur_scope;
1958 declare_predefined_types(hlsl_ctx.globals);
1962 if (TRACE_ON(hlsl_parser))
1964 struct hlsl_ir_function_decl *func;
1966 TRACE("IR dump.\n");
1967 LIST_FOR_EACH_ENTRY(func, &hlsl_ctx.functions, struct hlsl_ir_function_decl, node.entry)
1970 debug_dump_ir_function(func);
1974 TRACE("Compilation status = %d\n", hlsl_ctx.status);
1977 if (hlsl_ctx.messages.size)
1978 *messages = hlsl_ctx.messages.string;
1984 if (hlsl_ctx.messages.capacity)
1985 d3dcompiler_free(hlsl_ctx.messages.string);
1988 for (i = 0; i < hlsl_ctx.source_files_count; ++i)
1989 d3dcompiler_free((void *)hlsl_ctx.source_files[i]);
1990 d3dcompiler_free(hlsl_ctx.source_files);
1992 TRACE("Freeing functions IR.\n");
1993 LIST_FOR_EACH_ENTRY(function, &hlsl_ctx.functions, struct hlsl_ir_function_decl, node.entry)
1994 free_function(function);
1996 TRACE("Freeing variables.\n");
1997 LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &hlsl_ctx.scopes, struct hlsl_scope, entry)
1999 LIST_FOR_EACH_ENTRY_SAFE(var, next_var, &scope->vars, struct hlsl_ir_var, scope_entry)
2001 free_declaration(var);
2003 wine_rb_destroy(&scope->types, NULL, NULL);
2004 d3dcompiler_free(scope);
2007 TRACE("Freeing types.\n");
2008 LIST_FOR_EACH_ENTRY_SAFE(hlsl_type, next_type, &hlsl_ctx.types, struct hlsl_type, entry)
2010 free_hlsl_type(hlsl_type);