3 * Copyright © 2009 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
29 #include "glsl_parser_extras.h"
31 struct _mesa_glsl_parse_state
;
36 * \defgroup AST Abstract syntax tree node definitions
38 * An abstract syntax tree is generated by the parser. This is a fairly
39 * direct representation of the gramma derivation for the source program.
40 * No symantic checking is done during the generation of the AST. Only
41 * syntactic checking is done. Symantic checking is performed by a later
42 * stage that converts the AST to a more generic intermediate representation.
47 * Base class of all abstract syntax tree nodes
51 DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(ast_node
);
54 * Print an AST node in something approximating the original GLSL code
56 virtual void print(void) const;
59 * Convert the AST node to the high-level intermediate representation
61 virtual ir_rvalue
*hir(exec_list
*instructions
,
62 struct _mesa_glsl_parse_state
*state
);
64 virtual bool has_sequence_subexpression() const;
67 * Retrieve the source location of an AST node
69 * This function is primarily used to get the source position of an AST node
70 * into a form that can be passed to \c _mesa_glsl_error.
72 * \sa _mesa_glsl_error, ast_node::set_location
74 struct YYLTYPE
get_location(void) const
78 locp
.source
= this->location
.source
;
79 locp
.first_line
= this->location
.first_line
;
80 locp
.first_column
= this->location
.first_column
;
81 locp
.last_line
= this->location
.last_line
;
82 locp
.last_column
= this->location
.last_column
;
88 * Set the source location of an AST node from a parser location
90 * \sa ast_node::get_location
92 void set_location(const struct YYLTYPE
&locp
)
94 this->location
.source
= locp
.source
;
95 this->location
.first_line
= locp
.first_line
;
96 this->location
.first_column
= locp
.first_column
;
97 this->location
.last_line
= locp
.last_line
;
98 this->location
.last_column
= locp
.last_column
;
102 * Set the source location range of an AST node using two location nodes
104 * \sa ast_node::set_location
106 void set_location_range(const struct YYLTYPE
&begin
, const struct YYLTYPE
&end
)
108 this->location
.source
= begin
.source
;
109 this->location
.first_line
= begin
.first_line
;
110 this->location
.last_line
= end
.last_line
;
111 this->location
.first_column
= begin
.first_column
;
112 this->location
.last_column
= end
.last_column
;
116 * Source location of the AST node.
119 unsigned source
; /**< GLSL source number. */
120 unsigned first_line
; /**< First line number within the source string. */
121 unsigned first_column
; /**< First column in the first line. */
122 unsigned last_line
; /**< Last line number within the source string. */
123 unsigned last_column
; /**< Last column in the last line. */
128 virtual void set_is_lhs(bool);
132 * The only constructor is protected so that only derived class objects can
140 * Operators for AST expression nodes.
144 ast_plus
, /**< Unary + operator. */
187 ast_unsized_array_dim
,
204 * Number of possible operators for an ast_expression
206 * This is done as a define instead of as an additional value in the enum so
207 * that the compiler won't generate spurious messages like "warning:
208 * enumeration value ‘ast_num_operators’ not handled in switch"
210 #define AST_NUM_OPERATORS (ast_aggregate + 1)
214 * Representation of any sort of expression.
216 class ast_expression
: public ast_node
{
218 ast_expression(int oper
, ast_expression
*,
219 ast_expression
*, ast_expression
*);
221 ast_expression(const char *identifier
) :
224 subexpressions
[0] = NULL
;
225 subexpressions
[1] = NULL
;
226 subexpressions
[2] = NULL
;
227 primary_expression
.identifier
= identifier
;
228 this->non_lvalue_description
= NULL
;
229 this->is_lhs
= false;
232 static const char *operator_string(enum ast_operators op
);
234 virtual ir_rvalue
*hir(exec_list
*instructions
,
235 struct _mesa_glsl_parse_state
*state
);
237 virtual void hir_no_rvalue(exec_list
*instructions
,
238 struct _mesa_glsl_parse_state
*state
);
240 virtual bool has_sequence_subexpression() const;
242 ir_rvalue
*do_hir(exec_list
*instructions
,
243 struct _mesa_glsl_parse_state
*state
,
246 virtual void print(void) const;
248 enum ast_operators oper
;
250 ast_expression
*subexpressions
[3];
253 const char *identifier
;
255 float float_constant
;
256 unsigned uint_constant
;
258 double double_constant
;
259 uint64_t uint64_constant
;
260 int64_t int64_constant
;
261 } primary_expression
;
265 * List of expressions for an \c ast_sequence or parameters for an
266 * \c ast_function_call
268 exec_list expressions
;
271 * For things that can't be l-values, this describes what it is.
273 * This text is used by the code that generates IR for assignments to
274 * detect and emit useful messages for assignments to some things that
275 * can't be l-values. For example, pre- or post-incerement expressions.
278 * This pointer may be \c NULL.
280 const char *non_lvalue_description
;
282 void set_is_lhs(bool new_value
);
288 class ast_expression_bin
: public ast_expression
{
290 ast_expression_bin(int oper
, ast_expression
*, ast_expression
*);
292 virtual void print(void) const;
296 * Subclass of expressions for function calls
298 class ast_function_expression
: public ast_expression
{
300 ast_function_expression(ast_expression
*callee
)
301 : ast_expression(ast_function_call
, callee
,
308 ast_function_expression(class ast_type_specifier
*type
)
309 : ast_expression(ast_function_call
, (ast_expression
*) type
,
316 bool is_constructor() const
321 virtual ir_rvalue
*hir(exec_list
*instructions
,
322 struct _mesa_glsl_parse_state
*state
);
324 virtual void hir_no_rvalue(exec_list
*instructions
,
325 struct _mesa_glsl_parse_state
*state
);
327 virtual bool has_sequence_subexpression() const;
331 * Is this function call actually a constructor?
335 handle_method(exec_list
*instructions
,
336 struct _mesa_glsl_parse_state
*state
);
339 class ast_subroutine_list
: public ast_node
342 virtual void print(void) const;
343 exec_list declarations
;
346 class ast_array_specifier
: public ast_node
{
348 ast_array_specifier(const struct YYLTYPE
&locp
, ast_expression
*dim
)
351 array_dimensions
.push_tail(&dim
->link
);
354 void add_dimension(ast_expression
*dim
)
356 array_dimensions
.push_tail(&dim
->link
);
359 bool is_single_dimension() const
361 return this->array_dimensions
.get_tail_raw()->prev
!= NULL
&&
362 this->array_dimensions
.get_tail_raw()->prev
->is_head_sentinel();
365 virtual void print(void) const;
367 /* This list contains objects of type ast_node containing the
368 * array dimensions in outermost-to-innermost order.
370 exec_list array_dimensions
;
373 class ast_layout_expression
: public ast_node
{
375 ast_layout_expression(const struct YYLTYPE
&locp
, ast_expression
*expr
)
378 layout_const_expressions
.push_tail(&expr
->link
);
381 bool process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
382 const char *qual_indentifier
,
383 unsigned *value
, bool can_be_zero
);
385 void merge_qualifier(ast_layout_expression
*l_expr
)
387 layout_const_expressions
.append_list(&l_expr
->layout_const_expressions
);
390 exec_list layout_const_expressions
;
394 * C-style aggregate initialization class
396 * Represents C-style initializers of vectors, matrices, arrays, and
397 * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to
398 * vec3 pos = vec3(1.0, 0.0, -1.0).
400 * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack.
402 * \sa _mesa_ast_set_aggregate_type
404 class ast_aggregate_initializer
: public ast_expression
{
406 ast_aggregate_initializer()
407 : ast_expression(ast_aggregate
, NULL
, NULL
, NULL
),
408 constructor_type(NULL
)
414 * glsl_type of the aggregate, which is inferred from the LHS of whatever
415 * the aggregate is being used to initialize. This can't be inferred at
416 * parse time (since the parser deals with ast_type_specifiers, not
417 * glsl_types), so the parser leaves it NULL. However, the ast-to-hir
418 * conversion code makes sure to fill it in with the appropriate type
419 * before hir() is called.
421 const glsl_type
*constructor_type
;
423 virtual ir_rvalue
*hir(exec_list
*instructions
,
424 struct _mesa_glsl_parse_state
*state
);
426 virtual void hir_no_rvalue(exec_list
*instructions
,
427 struct _mesa_glsl_parse_state
*state
);
431 class ast_compound_statement
: public ast_node
{
433 ast_compound_statement(int new_scope
, ast_node
*statements
);
434 virtual void print(void) const;
436 virtual ir_rvalue
*hir(exec_list
*instructions
,
437 struct _mesa_glsl_parse_state
*state
);
440 exec_list statements
;
443 class ast_declaration
: public ast_node
{
445 ast_declaration(const char *identifier
,
446 ast_array_specifier
*array_specifier
,
447 ast_expression
*initializer
);
448 virtual void print(void) const;
450 const char *identifier
;
452 ast_array_specifier
*array_specifier
;
454 ast_expression
*initializer
;
459 ast_precision_none
= 0, /**< Absence of precision qualifier. */
461 ast_precision_medium
,
466 ast_depth_none
= 0, /**< Absence of depth qualifier. */
473 struct ast_type_qualifier
{
474 DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier
);
478 unsigned invariant
:1;
481 unsigned attribute
:1;
490 unsigned shared_storage
:1;
493 unsigned noperspective
:1;
495 /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */
497 unsigned origin_upper_left
:1;
498 unsigned pixel_center_integer
:1;
502 * Flag set if GL_ARB_enhanced_layouts "align" layout qualifier is
505 unsigned explicit_align
:1;
508 * Flag set if GL_ARB_explicit_attrib_location "location" layout
511 unsigned explicit_location
:1;
513 * Flag set if GL_ARB_explicit_attrib_location "index" layout
516 unsigned explicit_index
:1;
519 * Flag set if GL_ARB_enhanced_layouts "component" layout
522 unsigned explicit_component
:1;
525 * Flag set if GL_ARB_shading_language_420pack "binding" layout
528 unsigned explicit_binding
:1;
531 * Flag set if GL_ARB_shader_atomic counter "offset" layout
534 unsigned explicit_offset
:1;
536 /** \name Layout qualifiers for GL_AMD_conservative_depth */
538 unsigned depth_type
:1;
541 /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
547 unsigned column_major
:1;
548 unsigned row_major
:1;
551 /** \name Layout qualifiers for GLSL 1.50 geometry shaders */
553 unsigned prim_type
:1;
554 unsigned max_vertices
:1;
558 * local_size_{x,y,z} flags for compute shaders. Bit 0 represents
559 * local_size_x, and so on.
561 unsigned local_size
:3;
563 /** \name Layout qualifiers for ARB_compute_variable_group_size. */
565 unsigned local_size_variable
:1;
568 /** \name Layout and memory qualifiers for ARB_shader_image_load_store. */
570 unsigned early_fragment_tests
:1;
571 unsigned explicit_image_format
:1;
573 unsigned _volatile
:1;
574 unsigned restrict_flag
:1;
575 unsigned read_only
:1; /**< "readonly" qualifier. */
576 unsigned write_only
:1; /**< "writeonly" qualifier. */
579 /** \name Layout qualifiers for GL_ARB_gpu_shader5 */
581 unsigned invocations
:1;
582 unsigned stream
:1; /**< Has stream value assigned */
583 unsigned explicit_stream
:1; /**< stream value assigned explicitly by shader code */
586 /** \name Layout qualifiers for GL_ARB_enhanced_layouts */
588 unsigned explicit_xfb_offset
:1; /**< xfb_offset value assigned explicitly by shader code */
589 unsigned xfb_buffer
:1; /**< Has xfb_buffer value assigned */
590 unsigned explicit_xfb_buffer
:1; /**< xfb_buffer value assigned explicitly by shader code */
591 unsigned xfb_stride
:1; /**< Is xfb_stride value yet to be merged with global values */
592 unsigned explicit_xfb_stride
:1; /**< xfb_stride value assigned explicitly by shader code */
595 /** \name Layout qualifiers for GL_ARB_tessellation_shader */
597 /* tess eval input layout */
598 /* gs prim_type reused for primitive mode */
599 unsigned vertex_spacing
:1;
601 unsigned point_mode
:1;
602 /* tess control output layout */
606 /** \name Qualifiers for GL_ARB_shader_subroutine */
608 unsigned subroutine
:1; /**< Is this marked 'subroutine' */
611 /** \name Qualifiers for GL_KHR_blend_equation_advanced */
613 unsigned blend_support
:1; /**< Are there any blend_support_ qualifiers */
617 * Flag set if GL_ARB_post_depth_coverage layout qualifier is used.
619 unsigned post_depth_coverage
:1;
621 * Flag set if GL_INTEL_conservartive_rasterization layout qualifier
624 unsigned inner_coverage
:1;
626 /** \name Layout qualifiers for GL_ARB_bindless_texture */
628 unsigned bindless_sampler
:1;
629 unsigned bindless_image
:1;
630 unsigned bound_sampler
:1;
631 unsigned bound_image
:1;
634 /** \brief Set of flags, accessed by name. */
637 /** \brief Set of flags, accessed as a bitmask. */
641 /** Precision of the type (highp/medium/lowp). */
642 unsigned precision
:2;
644 /** Type of layout qualifiers for GL_AMD_conservative_depth. */
645 unsigned depth_type
:3;
648 * Alignment specified via GL_ARB_enhanced_layouts "align" layout qualifier
650 ast_expression
*align
;
652 /** Geometry shader invocations for GL_ARB_gpu_shader5. */
653 ast_layout_expression
*invocations
;
656 * Location specified via GL_ARB_explicit_attrib_location layout
659 * This field is only valid if \c explicit_location is set.
661 ast_expression
*location
;
663 * Index specified via GL_ARB_explicit_attrib_location layout
666 * This field is only valid if \c explicit_index is set.
668 ast_expression
*index
;
671 * Component specified via GL_ARB_enhaced_layouts
674 * This field is only valid if \c explicit_component is set.
676 ast_expression
*component
;
678 /** Maximum output vertices in GLSL 1.50 geometry shaders. */
679 ast_layout_expression
*max_vertices
;
681 /** Stream in GLSL 1.50 geometry shaders. */
682 ast_expression
*stream
;
684 /** xfb_buffer specified via the GL_ARB_enhanced_layouts keyword. */
685 ast_expression
*xfb_buffer
;
687 /** xfb_stride specified via the GL_ARB_enhanced_layouts keyword. */
688 ast_expression
*xfb_stride
;
690 /** global xfb_stride values for each buffer */
691 ast_layout_expression
*out_xfb_stride
[MAX_FEEDBACK_BUFFERS
];
694 * Input or output primitive type in GLSL 1.50 geometry shaders
695 * and tessellation shaders.
700 * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword.
703 * This field is only valid if \c explicit_binding is set.
705 ast_expression
*binding
;
708 * Offset specified via GL_ARB_shader_atomic_counter's or
709 * GL_ARB_enhanced_layouts "offset" keyword, or by GL_ARB_enhanced_layouts
710 * "xfb_offset" keyword.
713 * This field is only valid if \c explicit_offset is set.
715 ast_expression
*offset
;
718 * Local size specified via GL_ARB_compute_shader's "local_size_{x,y,z}"
719 * layout qualifier. Element i of this array is only valid if
720 * flags.q.local_size & (1 << i) is set.
722 ast_layout_expression
*local_size
[3];
724 /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */
725 enum gl_tess_spacing vertex_spacing
;
727 /** Tessellation evaluation shader: vertex ordering (CW or CCW) */
730 /** Tessellation evaluation shader: point mode */
733 /** Tessellation control shader: number of output vertices */
734 ast_layout_expression
*vertices
;
737 * Image format specified with an ARB_shader_image_load_store
741 * This field is only valid if \c explicit_image_format is set.
746 * Base type of the data read from or written to this image. Only
747 * the following enumerants are allowed: GLSL_TYPE_UINT,
748 * GLSL_TYPE_INT, GLSL_TYPE_FLOAT.
751 * This field is only valid if \c explicit_image_format is set.
753 glsl_base_type image_base_type
;
756 * Return true if and only if an interpolation qualifier is present.
758 bool has_interpolation() const;
761 * Return whether a layout qualifier is present.
763 bool has_layout() const;
766 * Return whether a storage qualifier is present.
768 bool has_storage() const;
771 * Return whether an auxiliary storage qualifier is present.
773 bool has_auxiliary_storage() const;
776 * Return true if and only if a memory qualifier is present.
778 bool has_memory() const;
781 * Return true if the qualifier is a subroutine declaration.
783 bool is_subroutine_decl() const;
785 bool merge_qualifier(YYLTYPE
*loc
,
786 _mesa_glsl_parse_state
*state
,
787 const ast_type_qualifier
&q
,
788 bool is_single_layout_merge
,
789 bool is_multiple_layouts_merge
= false);
792 * Validate current qualifier against the global out one.
794 bool validate_out_qualifier(YYLTYPE
*loc
,
795 _mesa_glsl_parse_state
*state
);
798 * Merge current qualifier into the global out one.
800 bool merge_into_out_qualifier(YYLTYPE
*loc
,
801 _mesa_glsl_parse_state
*state
,
805 * Validate current qualifier against the global in one.
807 bool validate_in_qualifier(YYLTYPE
*loc
,
808 _mesa_glsl_parse_state
*state
);
811 * Merge current qualifier into the global in one.
813 bool merge_into_in_qualifier(YYLTYPE
*loc
,
814 _mesa_glsl_parse_state
*state
,
818 * Push pending layout qualifiers to the global values.
820 bool push_to_global(YYLTYPE
*loc
,
821 _mesa_glsl_parse_state
*state
);
823 bool validate_flags(YYLTYPE
*loc
,
824 _mesa_glsl_parse_state
*state
,
825 const ast_type_qualifier
&allowed_flags
,
826 const char *message
, const char *name
);
828 ast_subroutine_list
*subroutine_list
;
831 class ast_declarator_list
;
833 class ast_struct_specifier
: public ast_node
{
835 ast_struct_specifier(void *lin_ctx
, const char *identifier
,
836 ast_declarator_list
*declarator_list
);
837 virtual void print(void) const;
839 virtual ir_rvalue
*hir(exec_list
*instructions
,
840 struct _mesa_glsl_parse_state
*state
);
843 ast_type_qualifier
*layout
;
844 /* List of ast_declarator_list * */
845 exec_list declarations
;
851 class ast_type_specifier
: public ast_node
{
853 /** Construct a type specifier from a type name */
854 ast_type_specifier(const char *name
)
855 : type_name(name
), structure(NULL
), array_specifier(NULL
),
856 default_precision(ast_precision_none
)
861 /** Construct a type specifier from a structure definition */
862 ast_type_specifier(ast_struct_specifier
*s
)
863 : type_name(s
->name
), structure(s
), array_specifier(NULL
),
864 default_precision(ast_precision_none
)
869 const struct glsl_type
*glsl_type(const char **name
,
870 struct _mesa_glsl_parse_state
*state
)
873 virtual void print(void) const;
875 ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
877 const char *type_name
;
878 ast_struct_specifier
*structure
;
880 ast_array_specifier
*array_specifier
;
882 /** For precision statements, this is the given precision; otherwise none. */
883 unsigned default_precision
:2;
887 class ast_fully_specified_type
: public ast_node
{
889 virtual void print(void) const;
890 bool has_qualifiers(_mesa_glsl_parse_state
*state
) const;
892 ast_fully_specified_type() : qualifier(), specifier(NULL
)
896 const struct glsl_type
*glsl_type(const char **name
,
897 struct _mesa_glsl_parse_state
*state
)
900 ast_type_qualifier qualifier
;
901 ast_type_specifier
*specifier
;
905 class ast_declarator_list
: public ast_node
{
907 ast_declarator_list(ast_fully_specified_type
*);
908 virtual void print(void) const;
910 virtual ir_rvalue
*hir(exec_list
*instructions
,
911 struct _mesa_glsl_parse_state
*state
);
913 ast_fully_specified_type
*type
;
914 /** List of 'ast_declaration *' */
915 exec_list declarations
;
918 * Flags for redeclarations. In these cases, no type is specified, to
919 * `type` is allowed to be NULL. In all other cases, this would be an error.
921 int invariant
; /** < `invariant` redeclaration */
922 int precise
; /** < `precise` redeclaration */
926 class ast_parameter_declarator
: public ast_node
{
928 ast_parameter_declarator() :
931 array_specifier(NULL
),
932 formal_parameter(false),
938 virtual void print(void) const;
940 virtual ir_rvalue
*hir(exec_list
*instructions
,
941 struct _mesa_glsl_parse_state
*state
);
943 ast_fully_specified_type
*type
;
944 const char *identifier
;
945 ast_array_specifier
*array_specifier
;
947 static void parameters_to_hir(exec_list
*ast_parameters
,
948 bool formal
, exec_list
*ir_parameters
,
949 struct _mesa_glsl_parse_state
*state
);
952 /** Is this parameter declaration part of a formal parameter list? */
953 bool formal_parameter
;
956 * Is this parameter 'void' type?
958 * This field is set by \c ::hir.
964 class ast_function
: public ast_node
{
968 virtual void print(void) const;
970 virtual ir_rvalue
*hir(exec_list
*instructions
,
971 struct _mesa_glsl_parse_state
*state
);
973 ast_fully_specified_type
*return_type
;
974 const char *identifier
;
976 exec_list parameters
;
980 * Is this prototype part of the function definition?
982 * Used by ast_function_definition::hir to process the parameters, etc.
990 * Function signature corresponding to this function prototype instance
992 * Used by ast_function_definition::hir to process the parameters, etc.
997 class ir_function_signature
*signature
;
999 friend class ast_function_definition
;
1003 class ast_expression_statement
: public ast_node
{
1005 ast_expression_statement(ast_expression
*);
1006 virtual void print(void) const;
1008 virtual ir_rvalue
*hir(exec_list
*instructions
,
1009 struct _mesa_glsl_parse_state
*state
);
1011 ast_expression
*expression
;
1015 class ast_case_label
: public ast_node
{
1017 ast_case_label(ast_expression
*test_value
);
1018 virtual void print(void) const;
1020 virtual ir_rvalue
*hir(exec_list
*instructions
,
1021 struct _mesa_glsl_parse_state
*state
);
1024 * An test value of NULL means 'default'.
1026 ast_expression
*test_value
;
1030 class ast_case_label_list
: public ast_node
{
1032 ast_case_label_list(void);
1033 virtual void print(void) const;
1035 virtual ir_rvalue
*hir(exec_list
*instructions
,
1036 struct _mesa_glsl_parse_state
*state
);
1039 * A list of case labels.
1045 class ast_case_statement
: public ast_node
{
1047 ast_case_statement(ast_case_label_list
*labels
);
1048 virtual void print(void) const;
1050 virtual ir_rvalue
*hir(exec_list
*instructions
,
1051 struct _mesa_glsl_parse_state
*state
);
1053 ast_case_label_list
*labels
;
1056 * A list of statements.
1062 class ast_case_statement_list
: public ast_node
{
1064 ast_case_statement_list(void);
1065 virtual void print(void) const;
1067 virtual ir_rvalue
*hir(exec_list
*instructions
,
1068 struct _mesa_glsl_parse_state
*state
);
1077 class ast_switch_body
: public ast_node
{
1079 ast_switch_body(ast_case_statement_list
*stmts
);
1080 virtual void print(void) const;
1082 virtual ir_rvalue
*hir(exec_list
*instructions
,
1083 struct _mesa_glsl_parse_state
*state
);
1085 ast_case_statement_list
*stmts
;
1089 class ast_selection_statement
: public ast_node
{
1091 ast_selection_statement(ast_expression
*condition
,
1092 ast_node
*then_statement
,
1093 ast_node
*else_statement
);
1094 virtual void print(void) const;
1096 virtual ir_rvalue
*hir(exec_list
*instructions
,
1097 struct _mesa_glsl_parse_state
*state
);
1099 ast_expression
*condition
;
1100 ast_node
*then_statement
;
1101 ast_node
*else_statement
;
1105 class ast_switch_statement
: public ast_node
{
1107 ast_switch_statement(ast_expression
*test_expression
,
1109 virtual void print(void) const;
1111 virtual ir_rvalue
*hir(exec_list
*instructions
,
1112 struct _mesa_glsl_parse_state
*state
);
1114 ast_expression
*test_expression
;
1118 void test_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1121 class ast_iteration_statement
: public ast_node
{
1123 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
1124 ast_expression
*rest_expression
, ast_node
*body
);
1126 virtual void print(void) const;
1128 virtual ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1130 enum ast_iteration_modes
{
1137 ast_node
*init_statement
;
1138 ast_node
*condition
;
1139 ast_expression
*rest_expression
;
1144 * Generate IR from the condition of a loop
1146 * This is factored out of ::hir because some loops have the condition
1147 * test at the top (for and while), and others have it at the end (do-while).
1149 void condition_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1153 class ast_jump_statement
: public ast_node
{
1155 ast_jump_statement(int mode
, ast_expression
*return_value
);
1156 virtual void print(void) const;
1158 virtual ir_rvalue
*hir(exec_list
*instructions
,
1159 struct _mesa_glsl_parse_state
*state
);
1161 enum ast_jump_modes
{
1168 ast_expression
*opt_return_value
;
1172 class ast_function_definition
: public ast_node
{
1174 ast_function_definition() : prototype(NULL
), body(NULL
)
1178 virtual void print(void) const;
1180 virtual ir_rvalue
*hir(exec_list
*instructions
,
1181 struct _mesa_glsl_parse_state
*state
);
1183 ast_function
*prototype
;
1184 ast_compound_statement
*body
;
1187 class ast_interface_block
: public ast_node
{
1189 ast_interface_block(const char *instance_name
,
1190 ast_array_specifier
*array_specifier
)
1191 : block_name(NULL
), instance_name(instance_name
),
1192 array_specifier(array_specifier
)
1196 virtual ir_rvalue
*hir(exec_list
*instructions
,
1197 struct _mesa_glsl_parse_state
*state
);
1199 ast_type_qualifier default_layout
;
1200 ast_type_qualifier layout
;
1201 const char *block_name
;
1204 * Declared name of the block instance, if specified.
1206 * If the block does not have an instance name, this field will be
1209 const char *instance_name
;
1211 /** List of ast_declarator_list * */
1212 exec_list declarations
;
1215 * Declared array size of the block instance
1217 * If the block is not declared as an array or if the block instance array
1218 * is unsized, this field will be \c NULL.
1220 ast_array_specifier
*array_specifier
;
1225 * AST node representing a declaration of the output layout for tessellation
1228 class ast_tcs_output_layout
: public ast_node
1231 ast_tcs_output_layout(const struct YYLTYPE
&locp
)
1236 virtual ir_rvalue
*hir(exec_list
*instructions
,
1237 struct _mesa_glsl_parse_state
*state
);
1242 * AST node representing a declaration of the input layout for geometry
1245 class ast_gs_input_layout
: public ast_node
1248 ast_gs_input_layout(const struct YYLTYPE
&locp
, GLenum prim_type
)
1249 : prim_type(prim_type
)
1254 virtual ir_rvalue
*hir(exec_list
*instructions
,
1255 struct _mesa_glsl_parse_state
*state
);
1258 const GLenum prim_type
;
1263 * AST node representing a decalaration of the input layout for compute
1266 class ast_cs_input_layout
: public ast_node
1269 ast_cs_input_layout(const struct YYLTYPE
&locp
,
1270 ast_layout_expression
*const *local_size
)
1272 for (int i
= 0; i
< 3; i
++) {
1273 this->local_size
[i
] = local_size
[i
];
1278 virtual ir_rvalue
*hir(exec_list
*instructions
,
1279 struct _mesa_glsl_parse_state
*state
);
1282 ast_layout_expression
*local_size
[3];
1288 _mesa_ast_to_hir(exec_list
*instructions
, struct _mesa_glsl_parse_state
*state
);
1291 _mesa_ast_field_selection_to_hir(const ast_expression
*expr
,
1292 exec_list
*instructions
,
1293 struct _mesa_glsl_parse_state
*state
);
1296 _mesa_ast_array_index_to_hir(void *mem_ctx
,
1297 struct _mesa_glsl_parse_state
*state
,
1298 ir_rvalue
*array
, ir_rvalue
*idx
,
1299 YYLTYPE
&loc
, YYLTYPE
&idx_loc
);
1302 _mesa_ast_set_aggregate_type(const glsl_type
*type
,
1303 ast_expression
*expr
);
1306 emit_function(_mesa_glsl_parse_state
*state
, ir_function
*f
);
1309 check_builtin_array_max_size(const char *name
, unsigned size
,
1310 YYLTYPE loc
, struct _mesa_glsl_parse_state
*state
);
1312 extern void _mesa_ast_process_interface_block(YYLTYPE
*locp
,
1313 _mesa_glsl_parse_state
*state
,
1314 ast_interface_block
*const block
,
1315 const struct ast_type_qualifier
&q
);
1318 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
1320 const char *qual_indentifier
,
1321 ast_expression
*const_expression
,