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.
30 #include "glsl_parser_extras.h"
32 struct _mesa_glsl_parse_state
;
37 * \defgroup AST Abstract syntax tree node definitions
39 * An abstract syntax tree is generated by the parser. This is a fairly
40 * direct representation of the gramma derivation for the source program.
41 * No symantic checking is done during the generation of the AST. Only
42 * syntactic checking is done. Symantic checking is performed by a later
43 * stage that converts the AST to a more generic intermediate representation.
48 * Base class of all abstract syntax tree nodes
52 DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(ast_node
);
55 * Print an AST node in something approximating the original GLSL code
57 virtual void print(void) const;
60 * Convert the AST node to the high-level intermediate representation
62 virtual ir_rvalue
*hir(exec_list
*instructions
,
63 struct _mesa_glsl_parse_state
*state
);
65 virtual bool has_sequence_subexpression() const;
68 * Retrieve the source location of an AST node
70 * This function is primarily used to get the source position of an AST node
71 * into a form that can be passed to \c _mesa_glsl_error.
73 * \sa _mesa_glsl_error, ast_node::set_location
75 struct YYLTYPE
get_location(void) const
79 locp
.source
= this->location
.source
;
80 locp
.first_line
= this->location
.first_line
;
81 locp
.first_column
= this->location
.first_column
;
82 locp
.last_line
= this->location
.last_line
;
83 locp
.last_column
= this->location
.last_column
;
89 * Set the source location of an AST node from a parser location
91 * \sa ast_node::get_location
93 void set_location(const struct YYLTYPE
&locp
)
95 this->location
.source
= locp
.source
;
96 this->location
.first_line
= locp
.first_line
;
97 this->location
.first_column
= locp
.first_column
;
98 this->location
.last_line
= locp
.last_line
;
99 this->location
.last_column
= locp
.last_column
;
103 * Set the source location range of an AST node using two location nodes
105 * \sa ast_node::set_location
107 void set_location_range(const struct YYLTYPE
&begin
, const struct YYLTYPE
&end
)
109 this->location
.source
= begin
.source
;
110 this->location
.first_line
= begin
.first_line
;
111 this->location
.last_line
= end
.last_line
;
112 this->location
.first_column
= begin
.first_column
;
113 this->location
.last_column
= end
.last_column
;
117 * Source location of the AST node.
120 unsigned source
; /**< GLSL source number. */
121 unsigned first_line
; /**< First line number within the source string. */
122 unsigned first_column
; /**< First column in the first line. */
123 unsigned last_line
; /**< Last line number within the source string. */
124 unsigned last_column
; /**< Last column in the last line. */
129 virtual void set_is_lhs(bool);
133 * The only constructor is protected so that only derived class objects can
141 * Operators for AST expression nodes.
145 ast_plus
, /**< Unary + operator. */
188 ast_unsized_array_dim
,
205 * Number of possible operators for an ast_expression
207 * This is done as a define instead of as an additional value in the enum so
208 * that the compiler won't generate spurious messages like "warning:
209 * enumeration value ‘ast_num_operators’ not handled in switch"
211 #define AST_NUM_OPERATORS (ast_aggregate + 1)
215 * Representation of any sort of expression.
217 class ast_expression
: public ast_node
{
219 ast_expression(int oper
, ast_expression
*,
220 ast_expression
*, ast_expression
*);
222 ast_expression(const char *identifier
) :
225 subexpressions
[0] = NULL
;
226 subexpressions
[1] = NULL
;
227 subexpressions
[2] = NULL
;
228 primary_expression
.identifier
= identifier
;
229 this->non_lvalue_description
= NULL
;
230 this->is_lhs
= false;
233 static const char *operator_string(enum ast_operators op
);
235 virtual ir_rvalue
*hir(exec_list
*instructions
,
236 struct _mesa_glsl_parse_state
*state
);
238 virtual void hir_no_rvalue(exec_list
*instructions
,
239 struct _mesa_glsl_parse_state
*state
);
241 virtual bool has_sequence_subexpression() const;
243 ir_rvalue
*do_hir(exec_list
*instructions
,
244 struct _mesa_glsl_parse_state
*state
,
247 virtual void print(void) const;
249 enum ast_operators oper
;
251 ast_expression
*subexpressions
[3];
254 const char *identifier
;
256 float float_constant
;
257 unsigned uint_constant
;
259 double double_constant
;
260 uint64_t uint64_constant
;
261 int64_t int64_constant
;
262 } primary_expression
;
266 * List of expressions for an \c ast_sequence or parameters for an
267 * \c ast_function_call
269 exec_list expressions
;
272 * For things that can't be l-values, this describes what it is.
274 * This text is used by the code that generates IR for assignments to
275 * detect and emit useful messages for assignments to some things that
276 * can't be l-values. For example, pre- or post-incerement expressions.
279 * This pointer may be \c NULL.
281 const char *non_lvalue_description
;
283 void set_is_lhs(bool new_value
);
289 class ast_expression_bin
: public ast_expression
{
291 ast_expression_bin(int oper
, ast_expression
*, ast_expression
*);
293 virtual void print(void) const;
297 * Subclass of expressions for function calls
299 class ast_function_expression
: public ast_expression
{
301 ast_function_expression(ast_expression
*callee
)
302 : ast_expression(ast_function_call
, callee
,
309 ast_function_expression(class ast_type_specifier
*type
)
310 : ast_expression(ast_function_call
, (ast_expression
*) type
,
317 bool is_constructor() const
322 virtual ir_rvalue
*hir(exec_list
*instructions
,
323 struct _mesa_glsl_parse_state
*state
);
325 virtual void hir_no_rvalue(exec_list
*instructions
,
326 struct _mesa_glsl_parse_state
*state
);
328 virtual bool has_sequence_subexpression() const;
332 * Is this function call actually a constructor?
336 handle_method(exec_list
*instructions
,
337 struct _mesa_glsl_parse_state
*state
);
340 class ast_subroutine_list
: public ast_node
343 virtual void print(void) const;
344 exec_list declarations
;
347 class ast_array_specifier
: public ast_node
{
349 ast_array_specifier(const struct YYLTYPE
&locp
, ast_expression
*dim
)
352 array_dimensions
.push_tail(&dim
->link
);
355 void add_dimension(ast_expression
*dim
)
357 array_dimensions
.push_tail(&dim
->link
);
360 bool is_single_dimension() const
362 return this->array_dimensions
.get_tail_raw()->prev
!= NULL
&&
363 this->array_dimensions
.get_tail_raw()->prev
->is_head_sentinel();
366 virtual void print(void) const;
368 /* This list contains objects of type ast_node containing the
369 * array dimensions in outermost-to-innermost order.
371 exec_list array_dimensions
;
374 class ast_layout_expression
: public ast_node
{
376 ast_layout_expression(const struct YYLTYPE
&locp
, ast_expression
*expr
)
379 layout_const_expressions
.push_tail(&expr
->link
);
382 bool process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
383 const char *qual_indentifier
,
384 unsigned *value
, bool can_be_zero
);
386 void merge_qualifier(ast_layout_expression
*l_expr
)
388 layout_const_expressions
.append_list(&l_expr
->layout_const_expressions
);
391 exec_list layout_const_expressions
;
395 * C-style aggregate initialization class
397 * Represents C-style initializers of vectors, matrices, arrays, and
398 * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to
399 * vec3 pos = vec3(1.0, 0.0, -1.0).
401 * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack.
403 * \sa _mesa_ast_set_aggregate_type
405 class ast_aggregate_initializer
: public ast_expression
{
407 ast_aggregate_initializer()
408 : ast_expression(ast_aggregate
, NULL
, NULL
, NULL
),
409 constructor_type(NULL
)
415 * glsl_type of the aggregate, which is inferred from the LHS of whatever
416 * the aggregate is being used to initialize. This can't be inferred at
417 * parse time (since the parser deals with ast_type_specifiers, not
418 * glsl_types), so the parser leaves it NULL. However, the ast-to-hir
419 * conversion code makes sure to fill it in with the appropriate type
420 * before hir() is called.
422 const glsl_type
*constructor_type
;
424 virtual ir_rvalue
*hir(exec_list
*instructions
,
425 struct _mesa_glsl_parse_state
*state
);
427 virtual void hir_no_rvalue(exec_list
*instructions
,
428 struct _mesa_glsl_parse_state
*state
);
432 class ast_compound_statement
: public ast_node
{
434 ast_compound_statement(int new_scope
, ast_node
*statements
);
435 virtual void print(void) const;
437 virtual ir_rvalue
*hir(exec_list
*instructions
,
438 struct _mesa_glsl_parse_state
*state
);
441 exec_list statements
;
444 class ast_declaration
: public ast_node
{
446 ast_declaration(const char *identifier
,
447 ast_array_specifier
*array_specifier
,
448 ast_expression
*initializer
);
449 virtual void print(void) const;
451 const char *identifier
;
453 ast_array_specifier
*array_specifier
;
455 ast_expression
*initializer
;
460 ast_precision_none
= 0, /**< Absence of precision qualifier. */
462 ast_precision_medium
,
466 struct ast_type_qualifier
{
467 DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier
);
471 unsigned invariant
:1;
474 unsigned attribute
:1;
483 unsigned shared_storage
:1;
486 unsigned noperspective
:1;
488 /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */
490 unsigned origin_upper_left
:1;
491 unsigned pixel_center_integer
:1;
495 * Flag set if GL_ARB_enhanced_layouts "align" layout qualifier is
498 unsigned explicit_align
:1;
501 * Flag set if GL_ARB_explicit_attrib_location "location" layout
504 unsigned explicit_location
:1;
506 * Flag set if GL_ARB_explicit_attrib_location "index" layout
509 unsigned explicit_index
:1;
512 * Flag set if GL_ARB_enhanced_layouts "component" layout
515 unsigned explicit_component
:1;
518 * Flag set if GL_ARB_shading_language_420pack "binding" layout
521 unsigned explicit_binding
:1;
524 * Flag set if GL_ARB_shader_atomic counter "offset" layout
527 unsigned explicit_offset
:1;
529 /** \name Layout qualifiers for GL_AMD_conservative_depth */
531 unsigned depth_any
:1;
532 unsigned depth_greater
:1;
533 unsigned depth_less
:1;
534 unsigned depth_unchanged
:1;
537 /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
543 unsigned column_major
:1;
544 unsigned row_major
:1;
547 /** \name Layout qualifiers for GLSL 1.50 geometry shaders */
549 unsigned prim_type
:1;
550 unsigned max_vertices
:1;
554 * local_size_{x,y,z} flags for compute shaders. Bit 0 represents
555 * local_size_x, and so on.
557 unsigned local_size
:3;
559 /** \name Layout qualifiers for ARB_compute_variable_group_size. */
561 unsigned local_size_variable
:1;
564 /** \name Layout and memory qualifiers for ARB_shader_image_load_store. */
566 unsigned early_fragment_tests
:1;
567 unsigned explicit_image_format
:1;
569 unsigned _volatile
:1;
570 unsigned restrict_flag
:1;
571 unsigned read_only
:1; /**< "readonly" qualifier. */
572 unsigned write_only
:1; /**< "writeonly" qualifier. */
575 /** \name Layout qualifiers for GL_ARB_gpu_shader5 */
577 unsigned invocations
:1;
578 unsigned stream
:1; /**< Has stream value assigned */
579 unsigned explicit_stream
:1; /**< stream value assigned explicitly by shader code */
582 /** \name Layout qualifiers for GL_ARB_enhanced_layouts */
584 unsigned explicit_xfb_offset
:1; /**< xfb_offset value assigned explicitly by shader code */
585 unsigned xfb_buffer
:1; /**< Has xfb_buffer value assigned */
586 unsigned explicit_xfb_buffer
:1; /**< xfb_buffer value assigned explicitly by shader code */
587 unsigned xfb_stride
:1; /**< Is xfb_stride value yet to be merged with global values */
588 unsigned explicit_xfb_stride
:1; /**< xfb_stride value assigned explicitly by shader code */
591 /** \name Layout qualifiers for GL_ARB_tessellation_shader */
593 /* tess eval input layout */
594 /* gs prim_type reused for primitive mode */
595 unsigned vertex_spacing
:1;
597 unsigned point_mode
:1;
598 /* tess control output layout */
602 /** \name Qualifiers for GL_ARB_shader_subroutine */
604 unsigned subroutine
:1; /**< Is this marked 'subroutine' */
605 unsigned subroutine_def
:1; /**< Is this marked 'subroutine' with a list of types */
608 /** \name Qualifiers for GL_KHR_blend_equation_advanced */
610 unsigned blend_support
:1; /**< Are there any blend_support_ qualifiers */
614 * Flag set if GL_ARB_post_depth_coverage layout qualifier is used.
616 unsigned post_depth_coverage
:1;
618 * Flag set if GL_INTEL_conservartive_rasterization layout qualifier
621 unsigned inner_coverage
:1;
623 /** \brief Set of flags, accessed by name. */
626 /** \brief Set of flags, accessed as a bitmask. */
630 /** Precision of the type (highp/medium/lowp). */
631 unsigned precision
:2;
634 * Alignment specified via GL_ARB_enhanced_layouts "align" layout qualifier
636 ast_expression
*align
;
638 /** Geometry shader invocations for GL_ARB_gpu_shader5. */
639 ast_layout_expression
*invocations
;
642 * Location specified via GL_ARB_explicit_attrib_location layout
645 * This field is only valid if \c explicit_location is set.
647 ast_expression
*location
;
649 * Index specified via GL_ARB_explicit_attrib_location layout
652 * This field is only valid if \c explicit_index is set.
654 ast_expression
*index
;
657 * Component specified via GL_ARB_enhaced_layouts
660 * This field is only valid if \c explicit_component is set.
662 ast_expression
*component
;
664 /** Maximum output vertices in GLSL 1.50 geometry shaders. */
665 ast_layout_expression
*max_vertices
;
667 /** Stream in GLSL 1.50 geometry shaders. */
668 ast_expression
*stream
;
670 /** xfb_buffer specified via the GL_ARB_enhanced_layouts keyword. */
671 ast_expression
*xfb_buffer
;
673 /** xfb_stride specified via the GL_ARB_enhanced_layouts keyword. */
674 ast_expression
*xfb_stride
;
676 /** global xfb_stride values for each buffer */
677 ast_layout_expression
*out_xfb_stride
[MAX_FEEDBACK_BUFFERS
];
680 * Input or output primitive type in GLSL 1.50 geometry shaders
681 * and tessellation shaders.
686 * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword.
689 * This field is only valid if \c explicit_binding is set.
691 ast_expression
*binding
;
694 * Offset specified via GL_ARB_shader_atomic_counter's or
695 * GL_ARB_enhanced_layouts "offset" keyword, or by GL_ARB_enhanced_layouts
696 * "xfb_offset" keyword.
699 * This field is only valid if \c explicit_offset is set.
701 ast_expression
*offset
;
704 * Local size specified via GL_ARB_compute_shader's "local_size_{x,y,z}"
705 * layout qualifier. Element i of this array is only valid if
706 * flags.q.local_size & (1 << i) is set.
708 ast_layout_expression
*local_size
[3];
710 /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */
711 enum gl_tess_spacing vertex_spacing
;
713 /** Tessellation evaluation shader: vertex ordering (CW or CCW) */
716 /** Tessellation evaluation shader: point mode */
719 /** Tessellation control shader: number of output vertices */
720 ast_layout_expression
*vertices
;
723 * Image format specified with an ARB_shader_image_load_store
727 * This field is only valid if \c explicit_image_format is set.
732 * Base type of the data read from or written to this image. Only
733 * the following enumerants are allowed: GLSL_TYPE_UINT,
734 * GLSL_TYPE_INT, GLSL_TYPE_FLOAT.
737 * This field is only valid if \c explicit_image_format is set.
739 glsl_base_type image_base_type
;
742 * Return true if and only if an interpolation qualifier is present.
744 bool has_interpolation() const;
747 * Return whether a layout qualifier is present.
749 bool has_layout() const;
752 * Return whether a storage qualifier is present.
754 bool has_storage() const;
757 * Return whether an auxiliary storage qualifier is present.
759 bool has_auxiliary_storage() const;
762 * Return true if and only if a memory qualifier is present.
764 bool has_memory() const;
766 bool merge_qualifier(YYLTYPE
*loc
,
767 _mesa_glsl_parse_state
*state
,
768 const ast_type_qualifier
&q
,
769 bool is_single_layout_merge
,
770 bool is_multiple_layouts_merge
= false);
773 * Validate current qualifier against the global out one.
775 bool validate_out_qualifier(YYLTYPE
*loc
,
776 _mesa_glsl_parse_state
*state
);
779 * Merge current qualifier into the global out one.
781 bool merge_into_out_qualifier(YYLTYPE
*loc
,
782 _mesa_glsl_parse_state
*state
,
786 * Validate current qualifier against the global in one.
788 bool validate_in_qualifier(YYLTYPE
*loc
,
789 _mesa_glsl_parse_state
*state
);
792 * Merge current qualifier into the global in one.
794 bool merge_into_in_qualifier(YYLTYPE
*loc
,
795 _mesa_glsl_parse_state
*state
,
799 * Push pending layout qualifiers to the global values.
801 bool push_to_global(YYLTYPE
*loc
,
802 _mesa_glsl_parse_state
*state
);
804 bool validate_flags(YYLTYPE
*loc
,
805 _mesa_glsl_parse_state
*state
,
806 const ast_type_qualifier
&allowed_flags
,
807 const char *message
, const char *name
);
809 ast_subroutine_list
*subroutine_list
;
812 class ast_declarator_list
;
814 class ast_struct_specifier
: public ast_node
{
816 ast_struct_specifier(void *lin_ctx
, const char *identifier
,
817 ast_declarator_list
*declarator_list
);
818 virtual void print(void) const;
820 virtual ir_rvalue
*hir(exec_list
*instructions
,
821 struct _mesa_glsl_parse_state
*state
);
824 ast_type_qualifier
*layout
;
825 /* List of ast_declarator_list * */
826 exec_list declarations
;
832 class ast_type_specifier
: public ast_node
{
834 /** Construct a type specifier from a type name */
835 ast_type_specifier(const char *name
)
836 : type_name(name
), structure(NULL
), array_specifier(NULL
),
837 default_precision(ast_precision_none
)
842 /** Construct a type specifier from a structure definition */
843 ast_type_specifier(ast_struct_specifier
*s
)
844 : type_name(s
->name
), structure(s
), array_specifier(NULL
),
845 default_precision(ast_precision_none
)
850 const struct glsl_type
*glsl_type(const char **name
,
851 struct _mesa_glsl_parse_state
*state
)
854 virtual void print(void) const;
856 ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
858 const char *type_name
;
859 ast_struct_specifier
*structure
;
861 ast_array_specifier
*array_specifier
;
863 /** For precision statements, this is the given precision; otherwise none. */
864 unsigned default_precision
:2;
868 class ast_fully_specified_type
: public ast_node
{
870 virtual void print(void) const;
871 bool has_qualifiers(_mesa_glsl_parse_state
*state
) const;
873 ast_fully_specified_type() : qualifier(), specifier(NULL
)
877 const struct glsl_type
*glsl_type(const char **name
,
878 struct _mesa_glsl_parse_state
*state
)
881 ast_type_qualifier qualifier
;
882 ast_type_specifier
*specifier
;
886 class ast_declarator_list
: public ast_node
{
888 ast_declarator_list(ast_fully_specified_type
*);
889 virtual void print(void) const;
891 virtual ir_rvalue
*hir(exec_list
*instructions
,
892 struct _mesa_glsl_parse_state
*state
);
894 ast_fully_specified_type
*type
;
895 /** List of 'ast_declaration *' */
896 exec_list declarations
;
899 * Flags for redeclarations. In these cases, no type is specified, to
900 * `type` is allowed to be NULL. In all other cases, this would be an error.
902 int invariant
; /** < `invariant` redeclaration */
903 int precise
; /** < `precise` redeclaration */
907 class ast_parameter_declarator
: public ast_node
{
909 ast_parameter_declarator() :
912 array_specifier(NULL
),
913 formal_parameter(false),
919 virtual void print(void) const;
921 virtual ir_rvalue
*hir(exec_list
*instructions
,
922 struct _mesa_glsl_parse_state
*state
);
924 ast_fully_specified_type
*type
;
925 const char *identifier
;
926 ast_array_specifier
*array_specifier
;
928 static void parameters_to_hir(exec_list
*ast_parameters
,
929 bool formal
, exec_list
*ir_parameters
,
930 struct _mesa_glsl_parse_state
*state
);
933 /** Is this parameter declaration part of a formal parameter list? */
934 bool formal_parameter
;
937 * Is this parameter 'void' type?
939 * This field is set by \c ::hir.
945 class ast_function
: public ast_node
{
949 virtual void print(void) const;
951 virtual ir_rvalue
*hir(exec_list
*instructions
,
952 struct _mesa_glsl_parse_state
*state
);
954 ast_fully_specified_type
*return_type
;
955 const char *identifier
;
957 exec_list parameters
;
961 * Is this prototype part of the function definition?
963 * Used by ast_function_definition::hir to process the parameters, etc.
971 * Function signature corresponding to this function prototype instance
973 * Used by ast_function_definition::hir to process the parameters, etc.
978 class ir_function_signature
*signature
;
980 friend class ast_function_definition
;
984 class ast_expression_statement
: public ast_node
{
986 ast_expression_statement(ast_expression
*);
987 virtual void print(void) const;
989 virtual ir_rvalue
*hir(exec_list
*instructions
,
990 struct _mesa_glsl_parse_state
*state
);
992 ast_expression
*expression
;
996 class ast_case_label
: public ast_node
{
998 ast_case_label(ast_expression
*test_value
);
999 virtual void print(void) const;
1001 virtual ir_rvalue
*hir(exec_list
*instructions
,
1002 struct _mesa_glsl_parse_state
*state
);
1005 * An test value of NULL means 'default'.
1007 ast_expression
*test_value
;
1011 class ast_case_label_list
: public ast_node
{
1013 ast_case_label_list(void);
1014 virtual void print(void) const;
1016 virtual ir_rvalue
*hir(exec_list
*instructions
,
1017 struct _mesa_glsl_parse_state
*state
);
1020 * A list of case labels.
1026 class ast_case_statement
: public ast_node
{
1028 ast_case_statement(ast_case_label_list
*labels
);
1029 virtual void print(void) const;
1031 virtual ir_rvalue
*hir(exec_list
*instructions
,
1032 struct _mesa_glsl_parse_state
*state
);
1034 ast_case_label_list
*labels
;
1037 * A list of statements.
1043 class ast_case_statement_list
: public ast_node
{
1045 ast_case_statement_list(void);
1046 virtual void print(void) const;
1048 virtual ir_rvalue
*hir(exec_list
*instructions
,
1049 struct _mesa_glsl_parse_state
*state
);
1058 class ast_switch_body
: public ast_node
{
1060 ast_switch_body(ast_case_statement_list
*stmts
);
1061 virtual void print(void) const;
1063 virtual ir_rvalue
*hir(exec_list
*instructions
,
1064 struct _mesa_glsl_parse_state
*state
);
1066 ast_case_statement_list
*stmts
;
1070 class ast_selection_statement
: public ast_node
{
1072 ast_selection_statement(ast_expression
*condition
,
1073 ast_node
*then_statement
,
1074 ast_node
*else_statement
);
1075 virtual void print(void) const;
1077 virtual ir_rvalue
*hir(exec_list
*instructions
,
1078 struct _mesa_glsl_parse_state
*state
);
1080 ast_expression
*condition
;
1081 ast_node
*then_statement
;
1082 ast_node
*else_statement
;
1086 class ast_switch_statement
: public ast_node
{
1088 ast_switch_statement(ast_expression
*test_expression
,
1090 virtual void print(void) const;
1092 virtual ir_rvalue
*hir(exec_list
*instructions
,
1093 struct _mesa_glsl_parse_state
*state
);
1095 ast_expression
*test_expression
;
1099 void test_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1102 class ast_iteration_statement
: public ast_node
{
1104 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
1105 ast_expression
*rest_expression
, ast_node
*body
);
1107 virtual void print(void) const;
1109 virtual ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1111 enum ast_iteration_modes
{
1118 ast_node
*init_statement
;
1119 ast_node
*condition
;
1120 ast_expression
*rest_expression
;
1125 * Generate IR from the condition of a loop
1127 * This is factored out of ::hir because some loops have the condition
1128 * test at the top (for and while), and others have it at the end (do-while).
1130 void condition_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1134 class ast_jump_statement
: public ast_node
{
1136 ast_jump_statement(int mode
, ast_expression
*return_value
);
1137 virtual void print(void) const;
1139 virtual ir_rvalue
*hir(exec_list
*instructions
,
1140 struct _mesa_glsl_parse_state
*state
);
1142 enum ast_jump_modes
{
1149 ast_expression
*opt_return_value
;
1153 class ast_function_definition
: public ast_node
{
1155 ast_function_definition() : prototype(NULL
), body(NULL
)
1159 virtual void print(void) const;
1161 virtual ir_rvalue
*hir(exec_list
*instructions
,
1162 struct _mesa_glsl_parse_state
*state
);
1164 ast_function
*prototype
;
1165 ast_compound_statement
*body
;
1168 class ast_interface_block
: public ast_node
{
1170 ast_interface_block(const char *instance_name
,
1171 ast_array_specifier
*array_specifier
)
1172 : block_name(NULL
), instance_name(instance_name
),
1173 array_specifier(array_specifier
)
1177 virtual ir_rvalue
*hir(exec_list
*instructions
,
1178 struct _mesa_glsl_parse_state
*state
);
1180 ast_type_qualifier default_layout
;
1181 ast_type_qualifier layout
;
1182 const char *block_name
;
1185 * Declared name of the block instance, if specified.
1187 * If the block does not have an instance name, this field will be
1190 const char *instance_name
;
1192 /** List of ast_declarator_list * */
1193 exec_list declarations
;
1196 * Declared array size of the block instance
1198 * If the block is not declared as an array or if the block instance array
1199 * is unsized, this field will be \c NULL.
1201 ast_array_specifier
*array_specifier
;
1206 * AST node representing a declaration of the output layout for tessellation
1209 class ast_tcs_output_layout
: public ast_node
1212 ast_tcs_output_layout(const struct YYLTYPE
&locp
)
1217 virtual ir_rvalue
*hir(exec_list
*instructions
,
1218 struct _mesa_glsl_parse_state
*state
);
1223 * AST node representing a declaration of the input layout for geometry
1226 class ast_gs_input_layout
: public ast_node
1229 ast_gs_input_layout(const struct YYLTYPE
&locp
, GLenum prim_type
)
1230 : prim_type(prim_type
)
1235 virtual ir_rvalue
*hir(exec_list
*instructions
,
1236 struct _mesa_glsl_parse_state
*state
);
1239 const GLenum prim_type
;
1244 * AST node representing a decalaration of the input layout for compute
1247 class ast_cs_input_layout
: public ast_node
1250 ast_cs_input_layout(const struct YYLTYPE
&locp
,
1251 ast_layout_expression
*const *local_size
)
1253 for (int i
= 0; i
< 3; i
++) {
1254 this->local_size
[i
] = local_size
[i
];
1259 virtual ir_rvalue
*hir(exec_list
*instructions
,
1260 struct _mesa_glsl_parse_state
*state
);
1263 ast_layout_expression
*local_size
[3];
1269 _mesa_ast_to_hir(exec_list
*instructions
, struct _mesa_glsl_parse_state
*state
);
1272 _mesa_ast_field_selection_to_hir(const ast_expression
*expr
,
1273 exec_list
*instructions
,
1274 struct _mesa_glsl_parse_state
*state
);
1277 _mesa_ast_array_index_to_hir(void *mem_ctx
,
1278 struct _mesa_glsl_parse_state
*state
,
1279 ir_rvalue
*array
, ir_rvalue
*idx
,
1280 YYLTYPE
&loc
, YYLTYPE
&idx_loc
);
1283 _mesa_ast_set_aggregate_type(const glsl_type
*type
,
1284 ast_expression
*expr
);
1287 emit_function(_mesa_glsl_parse_state
*state
, ir_function
*f
);
1290 check_builtin_array_max_size(const char *name
, unsigned size
,
1291 YYLTYPE loc
, struct _mesa_glsl_parse_state
*state
);
1293 extern void _mesa_ast_process_interface_block(YYLTYPE
*locp
,
1294 _mesa_glsl_parse_state
*state
,
1295 ast_interface_block
*const block
,
1296 const struct ast_type_qualifier
&q
);
1299 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
1301 const char *qual_indentifier
,
1302 ast_expression
*const_expression
,