d3dcompiler: Parse "return" statement.
[wine.git] / dlls / d3dcompiler_43 / hlsl.y
blob75b57412821d85127bd291653a0962496e3f49cb
1 /*
2 * HLSL parser
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
22 #include "config.h"
23 #include "wine/debug.h"
25 #include <stdio.h>
27 #include "d3dcompiler_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
31 int hlsl_lex(void);
33 struct hlsl_parse_ctx hlsl_ctx;
35 struct YYLTYPE;
36 static void set_location(struct source_location *loc, const struct YYLTYPE *l);
38 void hlsl_message(const char *fmt, ...)
40 va_list args;
42 va_start(args, fmt);
43 compilation_message(&hlsl_ctx.messages, fmt, args);
44 va_end(args);
47 static const char *hlsl_get_error_level_name(enum hlsl_error_level level)
49 const char *names[] =
51 "error",
52 "warning",
53 "note",
55 return names[level];
58 void hlsl_report_message(const char *filename, DWORD line, DWORD column,
59 enum hlsl_error_level level, const char *fmt, ...)
61 va_list args;
62 char *string = NULL;
63 int rc, size = 0;
65 while (1)
67 va_start(args, fmt);
68 rc = vsnprintf(string, size, fmt, args);
69 va_end(args);
71 if (rc >= 0 && rc < size)
72 break;
74 if (rc >= size)
75 size = rc + 1;
76 else
77 size = size ? size * 2 : 32;
79 if (!string)
80 string = d3dcompiler_alloc(size);
81 else
82 string = d3dcompiler_realloc(string, size);
83 if (!string)
85 ERR("Error reallocating memory for a string.\n");
86 return;
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);
107 if (modifiers)
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)
123 BOOL ret;
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;
134 else
135 check_invalid_matrix_modifiers(decl->modifiers, &decl->node.loc);
137 if (local)
139 DWORD invalid = decl->modifiers & (HLSL_STORAGE_EXTERN | HLSL_STORAGE_SHARED
140 | HLSL_STORAGE_GROUPSHARED | HLSL_STORAGE_UNIFORM);
141 if (invalid)
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));
146 if (decl->semantic)
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");
150 return FALSE;
153 else
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);
159 return FALSE;
162 ret = add_declaration(hlsl_ctx.cur_scope, decl, local);
163 if (!ret)
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);
171 return FALSE;
173 return TRUE;
176 static DWORD add_modifier(DWORD modifiers, DWORD mod, const struct YYLTYPE *loc);
178 BOOL add_type_to_scope(struct hlsl_scope *scope, struct hlsl_type *def)
180 if (get_type(scope, def->name, FALSE))
181 return FALSE;
183 list_add_tail(&scope->types, &def->scope_entry);
184 return TRUE;
187 static void declare_predefined_types(struct hlsl_scope *scope)
189 struct hlsl_type *type;
190 unsigned int x, y, bt;
191 static const char *names[] =
193 "float",
194 "half",
195 "double",
196 "int",
197 "uint",
198 "bool",
200 char name[10];
202 for (bt = 0; bt <= HLSL_TYPE_LAST_SCALAR; ++bt)
204 for (y = 1; y <= 4; ++y)
206 for (x = 1; x <= 4; ++x)
208 sprintf(name, "%s%ux%u", names[bt], x, y);
209 type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_MATRIX, bt, x, y);
210 add_type_to_scope(scope, type);
212 if (y == 1)
214 sprintf(name, "%s%u", names[bt], x);
215 type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_VECTOR, bt, x, y);
216 add_type_to_scope(scope, type);
218 if (x == 1)
220 sprintf(name, "%s", names[bt]);
221 type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_SCALAR, bt, x, y);
222 add_type_to_scope(scope, type);
229 /* DX8 effects predefined types */
230 type = new_hlsl_type(d3dcompiler_strdup("DWORD"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1);
231 add_type_to_scope(scope, type);
232 type = new_hlsl_type(d3dcompiler_strdup("FLOAT"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1);
233 add_type_to_scope(scope, type);
234 type = new_hlsl_type(d3dcompiler_strdup("VECTOR"), HLSL_CLASS_VECTOR, HLSL_TYPE_FLOAT, 4, 1);
235 add_type_to_scope(scope, type);
236 type = new_hlsl_type(d3dcompiler_strdup("MATRIX"), HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4);
237 add_type_to_scope(scope, type);
238 type = new_hlsl_type(d3dcompiler_strdup("STRING"), HLSL_CLASS_OBJECT, HLSL_TYPE_STRING, 1, 1);
239 add_type_to_scope(scope, type);
240 type = new_hlsl_type(d3dcompiler_strdup("TEXTURE"), HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1);
241 add_type_to_scope(scope, type);
242 type = new_hlsl_type(d3dcompiler_strdup("PIXELSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1);
243 add_type_to_scope(scope, type);
244 type = new_hlsl_type(d3dcompiler_strdup("VERTEXSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1);
245 add_type_to_scope(scope, type);
248 static unsigned int components_count_expr_list(struct list *list)
250 struct hlsl_ir_node *node;
251 unsigned int count = 0;
253 LIST_FOR_EACH_ENTRY(node, list, struct hlsl_ir_node, entry)
255 count += components_count_type(node->data_type);
257 return count;
260 static struct hlsl_ir_swizzle *new_swizzle(DWORD s, unsigned int components,
261 struct hlsl_ir_node *val, struct source_location *loc)
263 struct hlsl_ir_swizzle *swizzle = d3dcompiler_alloc(sizeof(*swizzle));
265 if (!swizzle)
266 return NULL;
267 swizzle->node.type = HLSL_IR_SWIZZLE;
268 swizzle->node.loc = *loc;
269 swizzle->node.data_type = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1);
270 swizzle->val = val;
271 swizzle->swizzle = s;
272 return swizzle;
275 static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ir_node *value, const char *swizzle,
276 struct source_location *loc)
278 unsigned int len = strlen(swizzle), component = 0;
279 unsigned int i, set, swiz = 0;
280 BOOL valid;
282 if (value->data_type->type == HLSL_CLASS_MATRIX)
284 /* Matrix swizzle */
285 BOOL m_swizzle;
286 unsigned int inc, x, y;
288 if (len < 3 || swizzle[0] != '_')
289 return NULL;
290 m_swizzle = swizzle[1] == 'm';
291 inc = m_swizzle ? 4 : 3;
293 if (len % inc || len > inc * 4)
294 return NULL;
296 for (i = 0; i < len; i += inc)
298 if (swizzle[i] != '_')
299 return NULL;
300 if (m_swizzle)
302 if (swizzle[i + 1] != 'm')
303 return NULL;
304 x = swizzle[i + 2] - '0';
305 y = swizzle[i + 3] - '0';
307 else
309 x = swizzle[i + 1] - '1';
310 y = swizzle[i + 2] - '1';
313 if (x >= value->data_type->dimx || y >= value->data_type->dimy)
314 return NULL;
315 swiz |= (y << 4 | x) << component * 8;
316 component++;
318 return new_swizzle(swiz, component, value, loc);
321 /* Vector swizzle */
322 if (len > 4)
323 return NULL;
325 for (set = 0; set < 2; ++set)
327 valid = TRUE;
328 component = 0;
329 for (i = 0; i < len; ++i)
331 char c[2][4] = {{'x', 'y', 'z', 'w'}, {'r', 'g', 'b', 'a'}};
332 unsigned int s = 0;
334 for (s = 0; s < 4; ++s)
336 if (swizzle[i] == c[set][s])
337 break;
339 if (s == 4)
341 valid = FALSE;
342 break;
345 if (s >= value->data_type->dimx)
346 return NULL;
347 swiz |= s << component * 2;
348 component++;
350 if (valid)
351 return new_swizzle(swiz, component, value, loc);
354 return NULL;
359 %locations
360 %error-verbose
362 %union
364 struct hlsl_type *type;
365 INT intval;
366 FLOAT floatval;
367 BOOL boolval;
368 char *name;
369 DWORD modifiers;
370 struct hlsl_ir_var *var;
371 struct hlsl_ir_node *instr;
372 struct list *list;
373 struct hlsl_ir_function_decl *function;
374 struct parse_parameter parameter;
375 struct parse_variable_def *variable_def;
376 enum parse_unary_op unary_op;
377 enum parse_assign_op assign_op;
380 %token KW_BLENDSTATE
381 %token KW_BREAK
382 %token KW_BUFFER
383 %token KW_CBUFFER
384 %token KW_COLUMN_MAJOR
385 %token KW_COMPILE
386 %token KW_CONST
387 %token KW_CONTINUE
388 %token KW_DEPTHSTENCILSTATE
389 %token KW_DEPTHSTENCILVIEW
390 %token KW_DISCARD
391 %token KW_DO
392 %token KW_DOUBLE
393 %token KW_ELSE
394 %token KW_EXTERN
395 %token KW_FALSE
396 %token KW_FOR
397 %token KW_GEOMETRYSHADER
398 %token KW_GROUPSHARED
399 %token KW_IF
400 %token KW_IN
401 %token KW_INLINE
402 %token KW_INOUT
403 %token KW_MATRIX
404 %token KW_NAMESPACE
405 %token KW_NOINTERPOLATION
406 %token KW_OUT
407 %token KW_PASS
408 %token KW_PIXELSHADER
409 %token KW_PRECISE
410 %token KW_RASTERIZERSTATE
411 %token KW_RENDERTARGETVIEW
412 %token KW_RETURN
413 %token KW_REGISTER
414 %token KW_ROW_MAJOR
415 %token KW_SAMPLER
416 %token KW_SAMPLER1D
417 %token KW_SAMPLER2D
418 %token KW_SAMPLER3D
419 %token KW_SAMPLERCUBE
420 %token KW_SAMPLER_STATE
421 %token KW_SAMPLERCOMPARISONSTATE
422 %token KW_SHARED
423 %token KW_STATEBLOCK
424 %token KW_STATEBLOCK_STATE
425 %token KW_STATIC
426 %token KW_STRING
427 %token KW_STRUCT
428 %token KW_SWITCH
429 %token KW_TBUFFER
430 %token KW_TECHNIQUE
431 %token KW_TECHNIQUE10
432 %token KW_TEXTURE
433 %token KW_TEXTURE1D
434 %token KW_TEXTURE1DARRAY
435 %token KW_TEXTURE2D
436 %token KW_TEXTURE2DARRAY
437 %token KW_TEXTURE2DMS
438 %token KW_TEXTURE2DMSARRAY
439 %token KW_TEXTURE3D
440 %token KW_TEXTURE3DARRAY
441 %token KW_TEXTURECUBE
442 %token KW_TRUE
443 %token KW_TYPEDEF
444 %token KW_UNIFORM
445 %token KW_VECTOR
446 %token KW_VERTEXSHADER
447 %token KW_VOID
448 %token KW_VOLATILE
449 %token KW_WHILE
451 %token OP_INC
452 %token OP_DEC
453 %token OP_AND
454 %token OP_OR
455 %token OP_EQ
456 %token OP_LEFTSHIFT
457 %token OP_LEFTSHIFTASSIGN
458 %token OP_RIGHTSHIFT
459 %token OP_RIGHTSHIFTASSIGN
460 %token OP_ELLIPSIS
461 %token OP_LE
462 %token OP_GE
463 %token OP_NE
464 %token OP_ADDASSIGN
465 %token OP_SUBASSIGN
466 %token OP_MULASSIGN
467 %token OP_DIVASSIGN
468 %token OP_MODASSIGN
469 %token OP_ANDASSIGN
470 %token OP_ORASSIGN
471 %token OP_XORASSIGN
472 %token OP_UNKNOWN1
473 %token OP_UNKNOWN2
474 %token OP_UNKNOWN3
475 %token OP_UNKNOWN4
477 %token <intval> PRE_LINE
479 %token <name> VAR_IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
480 %type <name> any_identifier var_identifier
481 %token <name> STRING
482 %token <floatval> C_FLOAT
483 %token <intval> C_INTEGER
484 %type <boolval> boolean
485 %type <type> base_type
486 %type <type> type
487 %type <list> declaration_statement
488 %type <list> complex_initializer
489 %type <list> initializer_expr_list
490 %type <instr> initializer_expr
491 %type <modifiers> var_modifiers
492 %type <list> parameters
493 %type <list> param_list
494 %type <instr> expr
495 %type <var> variable
496 %type <intval> array
497 %type <list> statement
498 %type <list> statement_list
499 %type <list> compound_statement
500 %type <list> jump_statement
501 %type <function> func_declaration
502 %type <function> func_prototype
503 %type <parameter> parameter
504 %type <name> semantic
505 %type <variable_def> variable_def
506 %type <list> variables_def
507 %type <instr> primary_expr
508 %type <instr> postfix_expr
509 %type <instr> unary_expr
510 %type <instr> mul_expr
511 %type <instr> add_expr
512 %type <instr> shift_expr
513 %type <instr> relational_expr
514 %type <instr> equality_expr
515 %type <instr> bitand_expr
516 %type <instr> bitxor_expr
517 %type <instr> bitor_expr
518 %type <instr> logicand_expr
519 %type <instr> logicor_expr
520 %type <instr> conditional_expr
521 %type <instr> assignment_expr
522 %type <list> expr_statement
523 %type <unary_op> unary_op
524 %type <assign_op> assign_op
525 %type <modifiers> input_mod
528 hlsl_prog: /* empty */
531 | hlsl_prog func_declaration
533 FIXME("Check that the function doesn't conflict with an already declared one.\n");
534 list_add_tail(&hlsl_ctx.functions, &$2->node.entry);
536 | hlsl_prog declaration_statement
538 TRACE("Declaration statement parsed.\n");
540 | hlsl_prog preproc_directive
544 preproc_directive: PRE_LINE STRING
546 TRACE("Updating line information to file %s, line %u\n", debugstr_a($2), $1);
547 hlsl_ctx.line_no = $1;
548 if (strcmp($2, hlsl_ctx.source_file))
550 const char **new_array;
552 hlsl_ctx.source_file = $2;
553 new_array = d3dcompiler_realloc(hlsl_ctx.source_files,
554 sizeof(*hlsl_ctx.source_files) * hlsl_ctx.source_files_count + 1);
555 if (new_array)
557 hlsl_ctx.source_files = new_array;
558 hlsl_ctx.source_files[hlsl_ctx.source_files_count++] = $2;
563 any_identifier: VAR_IDENTIFIER
564 | TYPE_IDENTIFIER
565 | NEW_IDENTIFIER
567 func_declaration: func_prototype compound_statement
569 TRACE("Function %s parsed.\n", $1->name);
570 $$ = $1;
571 $$->body = $2;
572 pop_scope(&hlsl_ctx);
574 | func_prototype ';'
576 TRACE("Function prototype for %s.\n", $1->name);
577 $$ = $1;
578 pop_scope(&hlsl_ctx);
581 func_prototype: var_modifiers type var_identifier '(' parameters ')' semantic
583 if (get_variable(hlsl_ctx.globals, $3))
585 hlsl_report_message(hlsl_ctx.source_file, @3.first_line, @3.first_column,
586 HLSL_LEVEL_ERROR, "redefinition of '%s'\n", $3);
587 return 1;
589 if ($2->base_type == HLSL_TYPE_VOID && $7)
591 hlsl_report_message(hlsl_ctx.source_file, @7.first_line, @7.first_column,
592 HLSL_LEVEL_ERROR, "void function with a semantic");
595 $$ = new_func_decl($3, $2, $5);
596 if (!$$)
598 ERR("Out of memory.\n");
599 return -1;
601 $$->semantic = $7;
604 compound_statement: '{' '}'
606 $$ = d3dcompiler_alloc(sizeof(*$$));
607 list_init($$);
609 | '{' scope_start statement_list '}'
611 pop_scope(&hlsl_ctx);
612 $$ = $3;
615 scope_start: /* Empty */
617 push_scope(&hlsl_ctx);
620 var_identifier: VAR_IDENTIFIER
621 | NEW_IDENTIFIER
623 semantic: /* Empty */
625 $$ = NULL;
627 | ':' any_identifier
629 $$ = $2;
632 parameters: scope_start
634 $$ = d3dcompiler_alloc(sizeof(*$$));
635 list_init($$);
637 | scope_start param_list
639 $$ = $2;
642 param_list: parameter
644 struct source_location loc;
646 $$ = d3dcompiler_alloc(sizeof(*$$));
647 list_init($$);
648 set_location(&loc, &@1);
649 if (!add_func_parameter($$, &$1, &loc))
651 ERR("Error adding function parameter %s.\n", $1.name);
652 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
653 return -1;
656 | param_list ',' parameter
658 struct source_location loc;
660 $$ = $1;
661 set_location(&loc, &@3);
662 if (!add_func_parameter($$, &$3, &loc))
664 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
665 "duplicate parameter %s", $3.name);
666 return 1;
670 parameter: input_mod var_modifiers type any_identifier semantic
672 $$.modifiers = $1;
673 $$.modifiers |= $2;
674 $$.type = $3;
675 $$.name = $4;
676 $$.semantic = $5;
679 input_mod: /* Empty */
681 $$ = HLSL_MODIFIER_IN;
683 | KW_IN
685 $$ = HLSL_MODIFIER_IN;
687 | KW_OUT
689 $$ = HLSL_MODIFIER_OUT;
691 | KW_INOUT
693 $$ = HLSL_MODIFIER_IN | HLSL_MODIFIER_OUT;
696 type: base_type
698 $$ = $1;
700 | KW_VECTOR '<' base_type ',' C_INTEGER '>'
702 if ($3->type != HLSL_CLASS_SCALAR)
704 hlsl_message("Line %u: vectors of non-scalar types are not allowed.\n",
705 hlsl_ctx.line_no);
706 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
707 return 1;
709 if ($5 < 1 || $5 > 4)
711 hlsl_message("Line %u: vector size must be between 1 and 4.\n",
712 hlsl_ctx.line_no);
713 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
714 return 1;
717 $$ = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, $3->base_type, $5, 1);
719 | KW_MATRIX '<' base_type ',' C_INTEGER ',' C_INTEGER '>'
721 if ($3->type != HLSL_CLASS_SCALAR)
723 hlsl_message("Line %u: matrices of non-scalar types are not allowed.\n",
724 hlsl_ctx.line_no);
725 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
726 return 1;
728 if ($5 < 1 || $5 > 4 || $7 < 1 || $7 > 4)
730 hlsl_message("Line %u: matrix dimensions must be between 1 and 4.\n",
731 hlsl_ctx.line_no);
732 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
733 return 1;
736 $$ = new_hlsl_type(NULL, HLSL_CLASS_MATRIX, $3->base_type, $5, $7);
739 base_type: KW_VOID
741 $$ = new_hlsl_type(d3dcompiler_strdup("void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1);
743 | KW_SAMPLER
745 $$ = new_hlsl_type(d3dcompiler_strdup("sampler"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
746 $$->sampler_dim = HLSL_SAMPLER_DIM_GENERIC;
748 | KW_SAMPLER1D
750 $$ = new_hlsl_type(d3dcompiler_strdup("sampler1D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
751 $$->sampler_dim = HLSL_SAMPLER_DIM_1D;
753 | KW_SAMPLER2D
755 $$ = new_hlsl_type(d3dcompiler_strdup("sampler2D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
756 $$->sampler_dim = HLSL_SAMPLER_DIM_2D;
758 | KW_SAMPLER3D
760 $$ = new_hlsl_type(d3dcompiler_strdup("sampler3D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
761 $$->sampler_dim = HLSL_SAMPLER_DIM_3D;
763 | KW_SAMPLERCUBE
765 $$ = new_hlsl_type(d3dcompiler_strdup("samplerCUBE"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
766 $$->sampler_dim = HLSL_SAMPLER_DIM_CUBE;
768 | TYPE_IDENTIFIER
770 struct hlsl_type *type;
772 TRACE("Type %s.\n", $1);
773 type = get_type(hlsl_ctx.cur_scope, $1, TRUE);
774 $$ = type;
775 d3dcompiler_free($1);
777 | KW_STRUCT TYPE_IDENTIFIER
779 struct hlsl_type *type;
781 TRACE("Struct type %s.\n", $2);
782 type = get_type(hlsl_ctx.cur_scope, $2, TRUE);
783 if (type->type != HLSL_CLASS_STRUCT)
785 hlsl_message("Line %u: redefining %s as a structure.\n",
786 hlsl_ctx.line_no, $2);
787 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
789 else
791 $$ = type;
793 d3dcompiler_free($2);
796 declaration_statement: declaration
798 $$ = d3dcompiler_alloc(sizeof(*$$));
799 list_init($$);
802 declaration: var_modifiers type variables_def ';'
804 struct parse_variable_def *v, *v_next;
805 struct hlsl_ir_var *var;
806 BOOL ret, local = TRUE;
808 LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $3, struct parse_variable_def, entry)
810 debug_dump_decl($2, $1, v->name, hlsl_ctx.line_no);
811 var = d3dcompiler_alloc(sizeof(*var));
812 var->node.type = HLSL_IR_VAR;
813 if (v->array_size)
814 var->node.data_type = new_array_type($2, v->array_size);
815 else
816 var->node.data_type = $2;
817 var->node.loc = v->loc;
818 var->name = v->name;
819 var->modifiers = $1;
820 var->semantic = v->semantic;
822 if (hlsl_ctx.cur_scope == hlsl_ctx.globals)
824 var->modifiers |= HLSL_STORAGE_UNIFORM;
825 local = FALSE;
828 if (var->modifiers & HLSL_MODIFIER_CONST && !v->initializer)
830 hlsl_report_message(v->loc.file, v->loc.line, v->loc.col,
831 HLSL_LEVEL_ERROR, "const variable without initializer");
832 free_declaration(var);
833 d3dcompiler_free(v);
834 continue;
837 ret = declare_variable(var, local);
838 if (!ret)
839 free_declaration(var);
840 else
841 TRACE("Declared variable %s.\n", var->name);
843 if (v->initializer)
845 FIXME("Variable with an initializer.\n");
846 free_instr_list(v->initializer);
849 d3dcompiler_free(v);
851 d3dcompiler_free($3);
854 variables_def: variable_def
856 $$ = d3dcompiler_alloc(sizeof(*$$));
857 list_init($$);
858 list_add_head($$, &$1->entry);
860 | variables_def ',' variable_def
862 $$ = $1;
863 list_add_tail($$, &$3->entry);
866 variable_def: any_identifier array semantic
868 $$ = d3dcompiler_alloc(sizeof(*$$));
869 set_location(&$$->loc, &@1);
870 $$->name = $1;
871 $$->array_size = $2;
872 $$->semantic = $3;
874 | any_identifier array semantic '=' complex_initializer
876 TRACE("Declaration with initializer.\n");
877 $$ = d3dcompiler_alloc(sizeof(*$$));
878 set_location(&$$->loc, &@1);
879 $$->name = $1;
880 $$->array_size = $2;
881 $$->semantic = $3;
882 $$->initializer = $5;
885 array: /* Empty */
887 $$ = 0;
889 | '[' expr ']'
891 FIXME("Array.\n");
892 $$ = 0;
893 free_instr($2);
896 var_modifiers: /* Empty */
898 $$ = 0;
900 | KW_EXTERN var_modifiers
902 $$ = add_modifier($2, HLSL_STORAGE_EXTERN, &@1);
904 | KW_NOINTERPOLATION var_modifiers
906 $$ = add_modifier($2, HLSL_STORAGE_NOINTERPOLATION, &@1);
908 | KW_PRECISE var_modifiers
910 $$ = add_modifier($2, HLSL_MODIFIER_PRECISE, &@1);
912 | KW_SHARED var_modifiers
914 $$ = add_modifier($2, HLSL_STORAGE_SHARED, &@1);
916 | KW_GROUPSHARED var_modifiers
918 $$ = add_modifier($2, HLSL_STORAGE_GROUPSHARED, &@1);
920 | KW_STATIC var_modifiers
922 $$ = add_modifier($2, HLSL_STORAGE_STATIC, &@1);
924 | KW_UNIFORM var_modifiers
926 $$ = add_modifier($2, HLSL_STORAGE_UNIFORM, &@1);
928 | KW_VOLATILE var_modifiers
930 $$ = add_modifier($2, HLSL_STORAGE_VOLATILE, &@1);
932 | KW_CONST var_modifiers
934 $$ = add_modifier($2, HLSL_MODIFIER_CONST, &@1);
936 | KW_ROW_MAJOR var_modifiers
938 $$ = add_modifier($2, HLSL_MODIFIER_ROW_MAJOR, &@1);
940 | KW_COLUMN_MAJOR var_modifiers
942 $$ = add_modifier($2, HLSL_MODIFIER_COLUMN_MAJOR, &@1);
945 complex_initializer: initializer_expr
947 $$ = d3dcompiler_alloc(sizeof(*$$));
948 list_init($$);
949 list_add_head($$, &$1->entry);
951 | '{' initializer_expr_list '}'
953 $$ = $2;
956 initializer_expr: assignment_expr
958 $$ = $1;
961 initializer_expr_list: initializer_expr
963 $$ = d3dcompiler_alloc(sizeof(*$$));
964 list_init($$);
965 list_add_head($$, &$1->entry);
967 | initializer_expr_list ',' initializer_expr
969 $$ = $1;
970 list_add_tail($$, &$3->entry);
973 boolean: KW_TRUE
975 $$ = TRUE;
977 | KW_FALSE
979 $$ = FALSE;
982 statement_list: statement
984 $$ = $1;
986 | statement_list statement
988 $$ = $1;
989 list_move_tail($$, $2);
990 d3dcompiler_free($2);
993 statement: declaration_statement
994 | expr_statement
995 | compound_statement
996 | jump_statement
998 /* FIXME: add rule for return with no value */
999 jump_statement: KW_RETURN expr ';'
1001 struct hlsl_ir_jump *jump = d3dcompiler_alloc(sizeof(*jump));
1002 if (!jump)
1004 ERR("Out of memory\n");
1005 return -1;
1007 jump->node.type = HLSL_IR_JUMP;
1008 set_location(&jump->node.loc, &@1);
1009 jump->type = HLSL_IR_JUMP_RETURN;
1010 jump->node.data_type = $2->data_type;
1011 jump->return_value = $2;
1013 FIXME("Check for valued return on void function.\n");
1014 FIXME("Implicit conversion to the return type if needed, "
1015 "error out if conversion not possible.\n");
1017 $$ = d3dcompiler_alloc(sizeof(*$$));
1018 list_init($$);
1019 list_add_tail($$, &jump->node.entry);
1022 expr_statement: ';'
1024 $$ = d3dcompiler_alloc(sizeof(*$$));
1025 list_init($$);
1027 | expr ';'
1029 $$ = d3dcompiler_alloc(sizeof(*$$));
1030 list_init($$);
1031 if ($1)
1032 list_add_head($$, &$1->entry);
1035 primary_expr: C_FLOAT
1037 struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c));
1038 if (!c)
1040 ERR("Out of memory.\n");
1041 return -1;
1043 c->node.type = HLSL_IR_CONSTANT;
1044 set_location(&c->node.loc, &yylloc);
1045 c->node.data_type = new_hlsl_type("float", HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1);
1046 c->v.value.f[0] = $1;
1047 $$ = &c->node;
1049 | C_INTEGER
1051 struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c));
1052 if (!c)
1054 ERR("Out of memory.\n");
1055 return -1;
1057 c->node.type = HLSL_IR_CONSTANT;
1058 set_location(&c->node.loc, &yylloc);
1059 c->node.data_type = new_hlsl_type("int", HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1);
1060 c->v.value.i[0] = $1;
1061 $$ = &c->node;
1063 | boolean
1065 struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c));
1066 if (!c)
1068 ERR("Out of memory.\n");
1069 return -1;
1071 c->node.type = HLSL_IR_CONSTANT;
1072 set_location(&c->node.loc, &yylloc);
1073 c->node.data_type = new_hlsl_type("bool", HLSL_CLASS_SCALAR, HLSL_TYPE_BOOL, 1, 1);
1074 c->v.value.b[0] = $1;
1075 $$ = &c->node;
1077 | variable
1079 struct hlsl_ir_deref *deref = new_var_deref($1);
1080 if (deref)
1082 $$ = &deref->node;
1083 set_location(&$$->loc, &@1);
1085 else
1086 $$ = NULL;
1088 | '(' expr ')'
1090 $$ = $2;
1093 variable: VAR_IDENTIFIER
1095 struct hlsl_ir_var *var;
1096 var = get_variable(hlsl_ctx.cur_scope, $1);
1097 if (!var)
1099 hlsl_message("Line %d: variable '%s' not declared\n",
1100 hlsl_ctx.line_no, $1);
1101 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
1102 return 1;
1104 $$ = var;
1107 postfix_expr: primary_expr
1109 $$ = $1;
1111 | postfix_expr OP_INC
1113 struct hlsl_ir_node *operands[3];
1114 struct source_location loc;
1116 set_location(&loc, &@2);
1117 if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
1119 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1120 "modifying a const expression");
1121 return 1;
1123 operands[0] = $1;
1124 operands[1] = operands[2] = NULL;
1125 $$ = &new_expr(HLSL_IR_BINOP_POSTINC, operands, &loc)->node;
1126 /* Post increment/decrement expressions are considered const */
1127 $$->data_type = clone_hlsl_type($$->data_type);
1128 $$->data_type->modifiers |= HLSL_MODIFIER_CONST;
1130 | postfix_expr OP_DEC
1132 struct hlsl_ir_node *operands[3];
1133 struct source_location loc;
1135 set_location(&loc, &@2);
1136 if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
1138 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1139 "modifying a const expression");
1140 return 1;
1142 operands[0] = $1;
1143 operands[1] = operands[2] = NULL;
1144 $$ = &new_expr(HLSL_IR_BINOP_POSTDEC, operands, &loc)->node;
1145 /* Post increment/decrement expressions are considered const */
1146 $$->data_type = clone_hlsl_type($$->data_type);
1147 $$->data_type->modifiers |= HLSL_MODIFIER_CONST;
1149 | postfix_expr '.' any_identifier
1151 struct source_location loc;
1153 set_location(&loc, &@2);
1154 if ($1->data_type->type <= HLSL_CLASS_LAST_NUMERIC)
1156 struct hlsl_ir_swizzle *swizzle;
1158 swizzle = get_swizzle($1, $3, &loc);
1159 if (!swizzle)
1161 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1162 "invalid swizzle %s", debugstr_a($3));
1163 return 1;
1165 $$ = &swizzle->node;
1167 else
1169 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1170 "invalid subscript %s", debugstr_a($3));
1171 return 1;
1174 /* "var_modifiers" doesn't make sense in this case, but it's needed
1175 in the grammar to avoid shift/reduce conflicts. */
1176 | var_modifiers type '(' initializer_expr_list ')'
1178 struct hlsl_ir_constructor *constructor;
1180 TRACE("%s constructor.\n", debug_hlsl_type($2));
1181 if ($1)
1183 hlsl_message("Line %u: unexpected modifier in a constructor.\n",
1184 hlsl_ctx.line_no);
1185 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
1186 return -1;
1188 if ($2->type > HLSL_CLASS_LAST_NUMERIC)
1190 hlsl_message("Line %u: constructors are allowed only for numeric data types.\n",
1191 hlsl_ctx.line_no);
1192 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
1193 return -1;
1195 if ($2->dimx * $2->dimy != components_count_expr_list($4))
1197 hlsl_message("Line %u: wrong number of components in constructor.\n",
1198 hlsl_ctx.line_no);
1199 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
1200 return -1;
1203 constructor = d3dcompiler_alloc(sizeof(*constructor));
1204 constructor->node.type = HLSL_IR_CONSTRUCTOR;
1205 set_location(&constructor->node.loc, &@3);
1206 constructor->node.data_type = $2;
1207 constructor->arguments = $4;
1209 $$ = &constructor->node;
1212 unary_expr: postfix_expr
1214 $$ = $1;
1216 | OP_INC unary_expr
1218 struct hlsl_ir_node *operands[3];
1219 struct source_location loc;
1221 set_location(&loc, &@1);
1222 if ($2->data_type->modifiers & HLSL_MODIFIER_CONST)
1224 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1225 "modifying a const expression");
1226 return 1;
1228 operands[0] = $2;
1229 operands[1] = operands[2] = NULL;
1230 $$ = &new_expr(HLSL_IR_BINOP_PREINC, operands, &loc)->node;
1232 | OP_DEC unary_expr
1234 struct hlsl_ir_node *operands[3];
1235 struct source_location loc;
1237 set_location(&loc, &@1);
1238 if ($2->data_type->modifiers & HLSL_MODIFIER_CONST)
1240 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1241 "modifying a const expression");
1242 return 1;
1244 operands[0] = $2;
1245 operands[1] = operands[2] = NULL;
1246 $$ = &new_expr(HLSL_IR_BINOP_PREDEC, operands, &loc)->node;
1248 | unary_op unary_expr
1250 enum hlsl_ir_expr_op ops[] = {0, HLSL_IR_UNOP_NEG,
1251 HLSL_IR_UNOP_LOGIC_NOT, HLSL_IR_UNOP_BIT_NOT};
1252 struct hlsl_ir_node *operands[3];
1253 struct source_location loc;
1255 if ($1 == UNARY_OP_PLUS)
1257 $$ = $2;
1259 else
1261 operands[0] = $2;
1262 operands[1] = operands[2] = NULL;
1263 set_location(&loc, &@1);
1264 $$ = &new_expr(ops[$1], operands, &loc)->node;
1268 unary_op: '+'
1270 $$ = UNARY_OP_PLUS;
1272 | '-'
1274 $$ = UNARY_OP_MINUS;
1276 | '!'
1278 $$ = UNARY_OP_LOGICNOT;
1280 | '~'
1282 $$ = UNARY_OP_BITNOT;
1285 mul_expr: unary_expr
1287 $$ = $1;
1289 | mul_expr '*' unary_expr
1291 struct source_location loc;
1293 set_location(&loc, &@2);
1294 $$ = &hlsl_mul($1, $3, &loc)->node;
1296 | mul_expr '/' unary_expr
1298 struct source_location loc;
1300 set_location(&loc, &@2);
1301 $$ = &hlsl_div($1, $3, &loc)->node;
1303 | mul_expr '%' unary_expr
1305 struct source_location loc;
1307 set_location(&loc, &@2);
1308 $$ = &hlsl_mod($1, $3, &loc)->node;
1311 add_expr: mul_expr
1313 $$ = $1;
1315 | add_expr '+' mul_expr
1317 struct source_location loc;
1319 set_location(&loc, &@2);
1320 $$ = &hlsl_add($1, $3, &loc)->node;
1322 | add_expr '-' mul_expr
1324 struct source_location loc;
1326 set_location(&loc, &@2);
1327 $$ = &hlsl_sub($1, $3, &loc)->node;
1330 shift_expr: add_expr
1332 $$ = $1;
1334 | shift_expr OP_LEFTSHIFT add_expr
1336 FIXME("Left shift\n");
1338 | shift_expr OP_RIGHTSHIFT add_expr
1340 FIXME("Right shift\n");
1343 relational_expr: shift_expr
1345 $$ = $1;
1347 | relational_expr '<' shift_expr
1349 struct source_location loc;
1351 set_location(&loc, &@2);
1352 $$ = &hlsl_lt($1, $3, &loc)->node;
1354 | relational_expr '>' shift_expr
1356 struct source_location loc;
1358 set_location(&loc, &@2);
1359 $$ = &hlsl_gt($1, $3, &loc)->node;
1361 | relational_expr OP_LE shift_expr
1363 struct source_location loc;
1365 set_location(&loc, &@2);
1366 $$ = &hlsl_le($1, $3, &loc)->node;
1368 | relational_expr OP_GE shift_expr
1370 struct source_location loc;
1372 set_location(&loc, &@2);
1373 $$ = &hlsl_ge($1, $3, &loc)->node;
1376 equality_expr: relational_expr
1378 $$ = $1;
1380 | equality_expr OP_EQ relational_expr
1382 struct source_location loc;
1384 set_location(&loc, &@2);
1385 $$ = &hlsl_eq($1, $3, &loc)->node;
1387 | equality_expr OP_NE relational_expr
1389 struct source_location loc;
1391 set_location(&loc, &@2);
1392 $$ = &hlsl_ne($1, $3, &loc)->node;
1395 bitand_expr: equality_expr
1397 $$ = $1;
1399 | bitand_expr '&' equality_expr
1401 FIXME("bitwise AND\n");
1404 bitxor_expr: bitand_expr
1406 $$ = $1;
1408 | bitxor_expr '^' bitand_expr
1410 FIXME("bitwise XOR\n");
1413 bitor_expr: bitxor_expr
1415 $$ = $1;
1417 | bitor_expr '|' bitxor_expr
1419 FIXME("bitwise OR\n");
1422 logicand_expr: bitor_expr
1424 $$ = $1;
1426 | logicand_expr OP_AND bitor_expr
1428 FIXME("logic AND\n");
1431 logicor_expr: logicand_expr
1433 $$ = $1;
1435 | logicor_expr OP_OR logicand_expr
1437 FIXME("logic OR\n");
1440 conditional_expr: logicor_expr
1442 $$ = $1;
1444 | logicor_expr '?' expr ':' assignment_expr
1446 FIXME("ternary operator\n");
1449 assignment_expr: conditional_expr
1451 $$ = $1;
1453 | unary_expr assign_op assignment_expr
1455 struct source_location loc;
1457 set_location(&loc, &@2);
1458 if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
1460 hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR,
1461 "l-value is const");
1462 return 1;
1464 $$ = make_assignment($1, $2, BWRITERSP_WRITEMASK_ALL, $3);
1465 if (!$$)
1466 return 1;
1467 $$->loc = loc;
1470 assign_op: '='
1472 $$ = ASSIGN_OP_ASSIGN;
1474 | OP_ADDASSIGN
1476 $$ = ASSIGN_OP_ADD;
1478 | OP_SUBASSIGN
1480 $$ = ASSIGN_OP_SUB;
1482 | OP_MULASSIGN
1484 $$ = ASSIGN_OP_MUL;
1486 | OP_DIVASSIGN
1488 $$ = ASSIGN_OP_DIV;
1490 | OP_MODASSIGN
1492 $$ = ASSIGN_OP_MOD;
1494 | OP_LEFTSHIFTASSIGN
1496 $$ = ASSIGN_OP_LSHIFT;
1498 | OP_RIGHTSHIFTASSIGN
1500 $$ = ASSIGN_OP_RSHIFT;
1502 | OP_ANDASSIGN
1504 $$ = ASSIGN_OP_AND;
1506 | OP_ORASSIGN
1508 $$ = ASSIGN_OP_OR;
1510 | OP_XORASSIGN
1512 $$ = ASSIGN_OP_XOR;
1515 expr: assignment_expr
1517 $$ = $1;
1519 | expr ',' assignment_expr
1521 FIXME("Comma expression\n");
1526 static void set_location(struct source_location *loc, const struct YYLTYPE *l)
1528 loc->file = hlsl_ctx.source_file;
1529 loc->line = l->first_line;
1530 loc->col = l->first_column;
1533 static DWORD add_modifier(DWORD modifiers, DWORD mod, const struct YYLTYPE *loc)
1535 if (modifiers & mod)
1537 hlsl_report_message(hlsl_ctx.source_file, loc->first_line, loc->first_column, HLSL_LEVEL_ERROR,
1538 "modifier '%s' already specified", debug_modifiers(mod));
1539 return modifiers;
1541 if (mod & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)
1542 && modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR))
1544 hlsl_report_message(hlsl_ctx.source_file, loc->first_line, loc->first_column, HLSL_LEVEL_ERROR,
1545 "more than one matrix majority keyword");
1546 return modifiers;
1548 return modifiers | mod;
1551 struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
1552 const char *entrypoint, char **messages)
1554 struct hlsl_ir_function_decl *function;
1555 struct hlsl_scope *scope, *next_scope;
1556 struct hlsl_type *hlsl_type, *next_type;
1557 struct hlsl_ir_var *var, *next_var;
1558 unsigned int i;
1560 hlsl_ctx.status = PARSE_SUCCESS;
1561 hlsl_ctx.messages.size = hlsl_ctx.messages.capacity = 0;
1562 hlsl_ctx.line_no = hlsl_ctx.column = 1;
1563 hlsl_ctx.source_file = d3dcompiler_strdup("");
1564 hlsl_ctx.source_files = d3dcompiler_alloc(sizeof(*hlsl_ctx.source_files));
1565 if (hlsl_ctx.source_files)
1566 hlsl_ctx.source_files[0] = hlsl_ctx.source_file;
1567 hlsl_ctx.source_files_count = 1;
1568 hlsl_ctx.cur_scope = NULL;
1569 hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
1570 list_init(&hlsl_ctx.scopes);
1571 list_init(&hlsl_ctx.types);
1572 list_init(&hlsl_ctx.functions);
1574 push_scope(&hlsl_ctx);
1575 hlsl_ctx.globals = hlsl_ctx.cur_scope;
1576 declare_predefined_types(hlsl_ctx.globals);
1578 hlsl_parse();
1580 if (TRACE_ON(hlsl_parser))
1582 struct hlsl_ir_function_decl *func;
1584 TRACE("IR dump.\n");
1585 LIST_FOR_EACH_ENTRY(func, &hlsl_ctx.functions, struct hlsl_ir_function_decl, node.entry)
1587 if (func->body)
1588 debug_dump_ir_function(func);
1592 TRACE("Compilation status = %d\n", hlsl_ctx.status);
1593 if (messages)
1595 if (hlsl_ctx.messages.size)
1596 *messages = hlsl_ctx.messages.string;
1597 else
1598 *messages = NULL;
1600 else
1602 if (hlsl_ctx.messages.capacity)
1603 d3dcompiler_free(hlsl_ctx.messages.string);
1606 for (i = 0; i < hlsl_ctx.source_files_count; ++i)
1607 d3dcompiler_free((void *)hlsl_ctx.source_files[i]);
1608 d3dcompiler_free(hlsl_ctx.source_files);
1610 TRACE("Freeing functions IR.\n");
1611 LIST_FOR_EACH_ENTRY(function, &hlsl_ctx.functions, struct hlsl_ir_function_decl, node.entry)
1612 free_function(function);
1614 TRACE("Freeing variables.\n");
1615 LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &hlsl_ctx.scopes, struct hlsl_scope, entry)
1617 LIST_FOR_EACH_ENTRY_SAFE(var, next_var, &scope->vars, struct hlsl_ir_var, scope_entry)
1619 free_declaration(var);
1621 d3dcompiler_free(scope);
1624 TRACE("Freeing types.\n");
1625 LIST_FOR_EACH_ENTRY_SAFE(hlsl_type, next_type, &hlsl_ctx.types, struct hlsl_type, entry)
1627 free_hlsl_type(hlsl_type);
1630 return NULL;