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 BOOL declare_variable
(struct hlsl_ir_var
*decl
, BOOL local
)
116 TRACE
("Declaring variable %s.\n", decl
->name
);
117 if
(decl
->node.data_type
->type
== HLSL_CLASS_MATRIX
)
119 if
(!(decl
->modifiers
& (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR
)))
121 decl
->modifiers |
= hlsl_ctx.matrix_majority
== HLSL_ROW_MAJOR
122 ? HLSL_MODIFIER_ROW_MAJOR
: HLSL_MODIFIER_COLUMN_MAJOR
;
127 DWORD invalid
= decl
->modifiers
& (HLSL_STORAGE_EXTERN | HLSL_STORAGE_SHARED
128 | HLSL_STORAGE_GROUPSHARED | HLSL_STORAGE_UNIFORM
);
131 hlsl_report_message
(decl
->node.loc.file
, decl
->node.loc.line
, decl
->node.loc.col
, HLSL_LEVEL_ERROR
,
132 "modifier '%s' invalid for local variables", debug_modifiers
(invalid
));
135 ret
= add_declaration
(hlsl_ctx.cur_scope
, decl
, local
);
138 struct hlsl_ir_var
*old
= get_variable
(hlsl_ctx.cur_scope
, decl
->name
);
140 hlsl_report_message
(decl
->node.loc.file
, decl
->node.loc.line
, decl
->node.loc.col
, HLSL_LEVEL_ERROR
,
141 "\"%s\" already declared", decl
->name
);
142 hlsl_report_message
(old
->node.loc.file
, old
->node.loc.line
, old
->node.loc.col
, HLSL_LEVEL_NOTE
,
143 "\"%s\" was previously declared here", old
->name
);
149 static DWORD add_modifier
(DWORD modifiers
, DWORD mod
, const struct YYLTYPE *loc
);
151 static unsigned int components_count_expr_list
(struct list
*list
)
153 struct hlsl_ir_node
*node
;
154 unsigned int count
= 0;
156 LIST_FOR_EACH_ENTRY
(node
, list
, struct hlsl_ir_node
, entry
)
158 count
+= components_count_type
(node
->data_type
);
170 struct hlsl_type
*type
;
176 struct hlsl_ir_var
*var
;
177 struct hlsl_ir_node
*instr
;
179 struct hlsl_ir_function_decl
*function
;
180 struct parse_parameter parameter
;
181 struct parse_variable_def
*variable_def
;
188 %token KW_COLUMN_MAJOR
192 %token KW_DEPTHSTENCILSTATE
193 %token KW_DEPTHSTENCILVIEW
201 %token KW_GEOMETRYSHADER
202 %token KW_GROUPSHARED
209 %token KW_NOINTERPOLATION
212 %token KW_PIXELSHADER
214 %token KW_RASTERIZERSTATE
215 %token KW_RENDERTARGETVIEW
223 %token KW_SAMPLERCUBE
224 %token KW_SAMPLER_STATE
225 %token KW_SAMPLERCOMPARISONSTATE
228 %token KW_STATEBLOCK_STATE
235 %token KW_TECHNIQUE10
238 %token KW_TEXTURE1DARRAY
240 %token KW_TEXTURE2DARRAY
241 %token KW_TEXTURE2DMS
242 %token KW_TEXTURE2DMSARRAY
244 %token KW_TEXTURE3DARRAY
245 %token KW_TEXTURECUBE
250 %token KW_VERTEXSHADER
261 %token OP_LEFTSHIFTASSIGN
263 %token OP_RIGHTSHIFTASSIGN
281 %token
<intval
> PRE_LINE
283 %token
<name
> VAR_IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
284 %type
<name
> any_identifier var_identifier
286 %token
<floatval
> C_FLOAT
287 %token
<intval
> C_INTEGER
288 %type
<boolval
> boolean
289 %type
<type
> base_type
291 %type
<list
> declaration_statement
292 %type
<list
> complex_initializer
293 %type
<list
> initializer_expr_list
294 %type
<instr
> initializer_expr
295 %type
<modifiers
> var_modifiers
296 %type
<list
> parameters
297 %type
<list
> param_list
301 %type
<list
> statement
302 %type
<list
> statement_list
303 %type
<list
> compound_statement
304 %type
<function
> func_declaration
305 %type
<function
> func_prototype
306 %type
<parameter
> parameter
307 %type
<name
> semantic
308 %type
<variable_def
> variable_def
309 %type
<list
> variables_def
310 %type
<instr
> primary_expr
311 %type
<instr
> postfix_expr
312 %type
<instr
> unary_expr
313 %type
<instr
> mul_expr
314 %type
<instr
> add_expr
315 %type
<instr
> shift_expr
316 %type
<instr
> relational_expr
317 %type
<instr
> equality_expr
318 %type
<instr
> bitand_expr
319 %type
<instr
> bitxor_expr
320 %type
<instr
> bitor_expr
321 %type
<instr
> logicand_expr
322 %type
<instr
> logicor_expr
323 %type
<instr
> conditional_expr
324 %type
<instr
> assignment_expr
325 %type
<list
> expr_statement
326 %type
<modifiers
> input_mod
329 hlsl_prog: /* empty */
332 | hlsl_prog func_declaration
334 FIXME
("Check that the function doesn't conflict with an already declared one.\n");
335 list_add_tail
(&hlsl_ctx.functions
, &$2->node.entry
);
337 | hlsl_prog declaration_statement
339 TRACE
("Declaration statement parsed.\n");
341 | hlsl_prog preproc_directive
345 preproc_directive: PRE_LINE STRING
347 TRACE
("Updating line information to file %s, line %u\n", debugstr_a
($2), $1);
348 hlsl_ctx.line_no
= $1;
349 if
(strcmp
($2, hlsl_ctx.source_file
))
351 const char **new_array
;
353 hlsl_ctx.source_file
= $2;
354 new_array
= d3dcompiler_realloc
(hlsl_ctx.source_files
,
355 sizeof
(*hlsl_ctx.source_files
) * hlsl_ctx.source_files_count
+ 1);
358 hlsl_ctx.source_files
= new_array
;
359 hlsl_ctx.source_files
[hlsl_ctx.source_files_count
++] = $2;
364 any_identifier: VAR_IDENTIFIER
368 func_declaration: func_prototype compound_statement
370 TRACE
("Function %s parsed.\n", $1->name
);
373 pop_scope
(&hlsl_ctx
);
377 TRACE
("Function prototype for %s.\n", $1->name
);
379 pop_scope
(&hlsl_ctx
);
382 func_prototype: var_modifiers type var_identifier
'(' parameters
')' semantic
384 $$
= new_func_decl
($3, $2, $5);
387 ERR
("Out of memory.\n");
393 compound_statement: '{' '}'
395 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
398 |
'{' scope_start statement_list
'}'
400 pop_scope
(&hlsl_ctx
);
404 scope_start: /* Empty */
406 push_scope
(&hlsl_ctx
);
409 var_identifier: VAR_IDENTIFIER
412 semantic: /* Empty */
421 parameters: scope_start
423 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
426 | scope_start param_list
431 param_list: parameter
433 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
435 if
(!add_func_parameter
($$
, &$1, hlsl_ctx.line_no
))
437 ERR
("Error adding function parameter %s.\n", $1.name
);
438 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
442 | param_list
',' parameter
445 if
(!add_func_parameter
($$
, &$3, hlsl_ctx.line_no
))
447 hlsl_message
("Line %u: duplicate parameter %s.\n",
448 hlsl_ctx.line_no
, $3.name
);
449 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
454 parameter: input_mod var_modifiers type any_identifier semantic
463 input_mod: /* Empty */
465 $$
= HLSL_MODIFIER_IN
;
469 $$
= HLSL_MODIFIER_IN
;
473 $$
= HLSL_MODIFIER_OUT
;
477 $$
= HLSL_MODIFIER_IN | HLSL_MODIFIER_OUT
;
484 | KW_VECTOR
'<' base_type
',' C_INTEGER
'>'
486 if
($3->type
!= HLSL_CLASS_SCALAR
)
488 hlsl_message
("Line %u: vectors of non-scalar types are not allowed.\n",
490 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
493 if
($5 < 1 ||
$5 > 4)
495 hlsl_message
("Line %u: vector size must be between 1 and 4.\n",
497 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
501 $$
= new_hlsl_type
(NULL
, HLSL_CLASS_VECTOR
, $3->base_type
, $5, 1);
503 | KW_MATRIX
'<' base_type
',' C_INTEGER
',' C_INTEGER
'>'
505 if
($3->type
!= HLSL_CLASS_SCALAR
)
507 hlsl_message
("Line %u: matrices of non-scalar types are not allowed.\n",
509 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
512 if
($5 < 1 ||
$5 > 4 ||
$7 < 1 ||
$7 > 4)
514 hlsl_message
("Line %u: matrix dimensions must be between 1 and 4.\n",
516 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
520 $$
= new_hlsl_type
(NULL
, HLSL_CLASS_MATRIX
, $3->base_type
, $5, $7);
525 $$
= new_hlsl_type
(d3dcompiler_strdup
("void"), HLSL_CLASS_SCALAR
, HLSL_TYPE_VOID
, 1, 1);
529 $$
= new_hlsl_type
(d3dcompiler_strdup
("sampler"), HLSL_CLASS_OBJECT
, HLSL_TYPE_SAMPLER
, 1, 1);
530 $$
->sampler_dim
= HLSL_SAMPLER_DIM_GENERIC
;
534 $$
= new_hlsl_type
(d3dcompiler_strdup
("sampler1D"), HLSL_CLASS_OBJECT
, HLSL_TYPE_SAMPLER
, 1, 1);
535 $$
->sampler_dim
= HLSL_SAMPLER_DIM_1D
;
539 $$
= new_hlsl_type
(d3dcompiler_strdup
("sampler2D"), HLSL_CLASS_OBJECT
, HLSL_TYPE_SAMPLER
, 1, 1);
540 $$
->sampler_dim
= HLSL_SAMPLER_DIM_2D
;
544 $$
= new_hlsl_type
(d3dcompiler_strdup
("sampler3D"), HLSL_CLASS_OBJECT
, HLSL_TYPE_SAMPLER
, 1, 1);
545 $$
->sampler_dim
= HLSL_SAMPLER_DIM_3D
;
549 $$
= new_hlsl_type
(d3dcompiler_strdup
("samplerCUBE"), HLSL_CLASS_OBJECT
, HLSL_TYPE_SAMPLER
, 1, 1);
550 $$
->sampler_dim
= HLSL_SAMPLER_DIM_CUBE
;
554 struct hlsl_type
*type
;
556 TRACE
("Type %s.\n", $1);
557 type
= get_type
(hlsl_ctx.cur_scope
, $1, TRUE
);
559 d3dcompiler_free
($1);
561 | KW_STRUCT TYPE_IDENTIFIER
563 struct hlsl_type
*type
;
565 TRACE
("Struct type %s.\n", $2);
566 type
= get_type
(hlsl_ctx.cur_scope
, $2, TRUE
);
567 if
(type
->type
!= HLSL_CLASS_STRUCT
)
569 hlsl_message
("Line %u: redefining %s as a structure.\n",
570 hlsl_ctx.line_no
, $2);
571 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
577 d3dcompiler_free
($2);
580 declaration_statement: declaration
582 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
586 declaration: var_modifiers type variables_def
';'
588 struct parse_variable_def
*v
, *v_next
;
589 struct hlsl_ir_var
*var
;
590 BOOL ret
, local
= TRUE
;
592 LIST_FOR_EACH_ENTRY_SAFE
(v
, v_next
, $3, struct parse_variable_def
, entry
)
594 debug_dump_decl
($2, $1, v
->name
, hlsl_ctx.line_no
);
595 var
= d3dcompiler_alloc
(sizeof
(*var
));
596 var
->node.type
= HLSL_IR_VAR
;
598 var
->node.data_type
= new_array_type
($2, v
->array_size
);
600 var
->node.data_type
= $2;
601 var
->node.loc
= v
->loc
;
604 var
->semantic
= v
->semantic
;
607 FIXME
("Variable with an initializer.\n");
608 free_instr_list
(v
->initializer
);
611 if
(hlsl_ctx.cur_scope
== hlsl_ctx.globals
)
613 var
->modifiers |
= HLSL_STORAGE_UNIFORM
;
617 ret
= declare_variable
(var
, local
);
619 free_declaration
(var
);
621 TRACE
("Declared variable %s.\n", var
->name
);
624 d3dcompiler_free
($3);
627 variables_def: variable_def
629 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
631 list_add_head
($$
, &$1->entry
);
633 | variables_def
',' variable_def
636 list_add_tail
($$
, &$3->entry
);
639 /* FIXME: Local variables can't have semantics. */
640 variable_def: any_identifier array semantic
642 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
643 set_location
(&$$
->loc
, &@
1);
648 | any_identifier array semantic
'=' complex_initializer
650 TRACE
("Declaration with initializer.\n");
651 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
652 set_location
(&$$
->loc
, &@
1);
656 $$
->initializer
= $5;
670 var_modifiers: /* Empty */
674 | KW_EXTERN var_modifiers
676 $$
= add_modifier
($2, HLSL_STORAGE_EXTERN
, &@
1);
678 | KW_NOINTERPOLATION var_modifiers
680 $$
= add_modifier
($2, HLSL_STORAGE_NOINTERPOLATION
, &@
1);
682 | KW_PRECISE var_modifiers
684 $$
= add_modifier
($2, HLSL_MODIFIER_PRECISE
, &@
1);
686 | KW_SHARED var_modifiers
688 $$
= add_modifier
($2, HLSL_STORAGE_SHARED
, &@
1);
690 | KW_GROUPSHARED var_modifiers
692 $$
= add_modifier
($2, HLSL_STORAGE_GROUPSHARED
, &@
1);
694 | KW_STATIC var_modifiers
696 $$
= add_modifier
($2, HLSL_STORAGE_STATIC
, &@
1);
698 | KW_UNIFORM var_modifiers
700 $$
= add_modifier
($2, HLSL_STORAGE_UNIFORM
, &@
1);
702 | KW_VOLATILE var_modifiers
704 $$
= add_modifier
($2, HLSL_STORAGE_VOLATILE
, &@
1);
706 | KW_CONST var_modifiers
708 $$
= add_modifier
($2, HLSL_MODIFIER_CONST
, &@
1);
710 | KW_ROW_MAJOR var_modifiers
712 $$
= add_modifier
($2, HLSL_MODIFIER_ROW_MAJOR
, &@
1);
714 | KW_COLUMN_MAJOR var_modifiers
716 $$
= add_modifier
($2, HLSL_MODIFIER_COLUMN_MAJOR
, &@
1);
719 complex_initializer: initializer_expr
721 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
723 list_add_head
($$
, &$1->entry
);
725 |
'{' initializer_expr_list
'}'
730 initializer_expr: assignment_expr
735 initializer_expr_list: initializer_expr
737 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
739 list_add_head
($$
, &$1->entry
);
741 | initializer_expr_list
',' initializer_expr
744 list_add_tail
($$
, &$3->entry
);
756 statement_list: statement
760 | statement_list statement
763 list_move_tail
($$
, $2);
764 d3dcompiler_free
($2);
767 statement: declaration_statement
782 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
787 $$
= d3dcompiler_alloc
(sizeof
(*$$
));
790 list_add_head
($$
, &$1->entry
);
793 primary_expr: C_FLOAT
795 struct hlsl_ir_constant
*c
= d3dcompiler_alloc
(sizeof
(*c
));
798 ERR
("Out of memory.\n");
801 c
->node.type
= HLSL_IR_CONSTANT
;
802 c
->node.data_type
= new_hlsl_type
("float", HLSL_CLASS_SCALAR
, HLSL_TYPE_FLOAT
, 1, 1);
803 c
->v.value.f
[0] = $1;
808 struct hlsl_ir_constant
*c
= d3dcompiler_alloc
(sizeof
(*c
));
811 ERR
("Out of memory.\n");
814 c
->node.type
= HLSL_IR_CONSTANT
;
815 c
->node.data_type
= new_hlsl_type
("int", HLSL_CLASS_SCALAR
, HLSL_TYPE_INT
, 1, 1);
816 c
->v.value.i
[0] = $1;
821 struct hlsl_ir_constant
*c
= d3dcompiler_alloc
(sizeof
(*c
));
824 ERR
("Out of memory.\n");
827 c
->node.type
= HLSL_IR_CONSTANT
;
828 c
->node.data_type
= new_hlsl_type
("bool", HLSL_CLASS_SCALAR
, HLSL_TYPE_BOOL
, 1, 1);
829 c
->v.value.b
[0] = $1;
834 struct hlsl_ir_deref
*deref
= new_var_deref
($1);
835 $$
= deref ?
&deref
->node
: NULL
;
842 variable: VAR_IDENTIFIER
844 struct hlsl_ir_var
*var
;
845 var
= get_variable
(hlsl_ctx.cur_scope
, $1);
848 hlsl_message
("Line %d: variable '%s' not declared\n",
849 hlsl_ctx.line_no
, $1);
850 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
856 postfix_expr: primary_expr
860 /* "var_modifiers" doesn't make sense in this case, but it's needed
861 in the grammar to avoid shift/reduce conflicts. */
862 | var_modifiers type
'(' initializer_expr_list
')'
864 struct hlsl_ir_constructor
*constructor
;
866 TRACE
("%s constructor.\n", debug_hlsl_type
($2));
869 hlsl_message
("Line %u: unexpected modifier in a constructor.\n",
871 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
874 if
($2->type
> HLSL_CLASS_LAST_NUMERIC
)
876 hlsl_message
("Line %u: constructors are allowed only for numeric data types.\n",
878 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
881 if
($2->dimx
* $2->dimy
!= components_count_expr_list
($4))
883 hlsl_message
("Line %u: wrong number of components in constructor.\n",
885 set_parse_status
(&hlsl_ctx.status
, PARSE_ERR
);
889 constructor
= d3dcompiler_alloc
(sizeof
(*constructor
));
890 constructor
->node.type
= HLSL_IR_CONSTRUCTOR
;
891 constructor
->node.data_type
= $2;
892 constructor
->arguments
= $4;
894 $$
= &constructor
->node
;
897 unary_expr: postfix_expr
917 relational_expr: shift_expr
922 equality_expr: relational_expr
927 bitand_expr: equality_expr
932 bitxor_expr: bitand_expr
937 bitor_expr: bitxor_expr
942 logicand_expr: bitor_expr
947 logicor_expr: logicand_expr
952 conditional_expr: logicor_expr
957 assignment_expr: conditional_expr
962 expr: assignment_expr
966 | expr
',' assignment_expr
968 FIXME
("Comma expression\n");
973 static void set_location
(struct source_location
*loc
, const struct YYLTYPE *l
)
975 loc
->file
= hlsl_ctx.source_file
;
976 loc
->line
= l
->first_line
;
977 loc
->col
= l
->first_column
;
980 static DWORD add_modifier
(DWORD modifiers
, DWORD mod
, const struct YYLTYPE *loc
)
984 hlsl_report_message
(hlsl_ctx.source_file
, loc
->first_line
, loc
->first_column
, HLSL_LEVEL_ERROR
,
985 "modifier '%s' already specified", debug_modifiers
(mod
));
988 if
(mod
& (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR
)
989 && modifiers
& (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR
))
991 hlsl_report_message
(hlsl_ctx.source_file
, loc
->first_line
, loc
->first_column
, HLSL_LEVEL_ERROR
,
992 "more than one matrix majority keyword");
995 return modifiers | mod
;
998 struct bwriter_shader
*parse_hlsl
(enum shader_type type
, DWORD major
, DWORD minor
,
999 const char *entrypoint
, char **messages
)
1001 struct hlsl_ir_function_decl
*function
;
1002 struct hlsl_scope
*scope
, *next_scope
;
1003 struct hlsl_type
*hlsl_type
, *next_type
;
1004 struct hlsl_ir_var
*var
, *next_var
;
1007 hlsl_ctx.status
= PARSE_SUCCESS
;
1008 hlsl_ctx.messages.size
= hlsl_ctx.messages.capacity
= 0;
1009 hlsl_ctx.line_no
= hlsl_ctx.column
= 1;
1010 hlsl_ctx.source_file
= d3dcompiler_strdup
("");
1011 hlsl_ctx.source_files
= d3dcompiler_alloc
(sizeof
(*hlsl_ctx.source_files
));
1012 if
(hlsl_ctx.source_files
)
1013 hlsl_ctx.source_files
[0] = hlsl_ctx.source_file
;
1014 hlsl_ctx.source_files_count
= 1;
1015 hlsl_ctx.cur_scope
= NULL
;
1016 hlsl_ctx.matrix_majority
= HLSL_COLUMN_MAJOR
;
1017 list_init
(&hlsl_ctx.scopes
);
1018 list_init
(&hlsl_ctx.types
);
1019 list_init
(&hlsl_ctx.functions
);
1021 push_scope
(&hlsl_ctx
);
1022 hlsl_ctx.globals
= hlsl_ctx.cur_scope
;
1026 if
(TRACE_ON
(hlsl_parser
))
1028 struct hlsl_ir_function_decl
*func
;
1030 TRACE
("IR dump.\n");
1031 LIST_FOR_EACH_ENTRY
(func
, &hlsl_ctx.functions
, struct hlsl_ir_function_decl
, node.entry
)
1034 debug_dump_ir_function
(func
);
1038 TRACE
("Compilation status = %d\n", hlsl_ctx.status
);
1041 if
(hlsl_ctx.messages.size
)
1042 *messages
= hlsl_ctx.messages.
string;
1048 if
(hlsl_ctx.messages.capacity
)
1049 d3dcompiler_free
(hlsl_ctx.messages.
string);
1052 for
(i
= 0; i
< hlsl_ctx.source_files_count
; ++i
)
1053 d3dcompiler_free
((void *)hlsl_ctx.source_files
[i
]);
1054 d3dcompiler_free
(hlsl_ctx.source_files
);
1056 TRACE
("Freeing functions IR.\n");
1057 LIST_FOR_EACH_ENTRY
(function
, &hlsl_ctx.functions
, struct hlsl_ir_function_decl
, node.entry
)
1058 free_function
(function
);
1060 TRACE
("Freeing variables.\n");
1061 LIST_FOR_EACH_ENTRY_SAFE
(scope
, next_scope
, &hlsl_ctx.scopes
, struct hlsl_scope
, entry
)
1063 LIST_FOR_EACH_ENTRY_SAFE
(var
, next_var
, &scope
->vars
, struct hlsl_ir_var
, scope_entry
)
1065 free_declaration
(var
);
1067 d3dcompiler_free
(scope
);
1070 TRACE
("Freeing types.\n");
1071 LIST_FOR_EACH_ENTRY_SAFE
(hlsl_type
, next_type
, &hlsl_ctx.types
, struct hlsl_type
, entry
)
1073 free_hlsl_type
(hlsl_type
);