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_RALLOC_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
,
204 * Representation of any sort of expression.
206 class ast_expression
: public ast_node
{
208 ast_expression(int oper
, ast_expression
*,
209 ast_expression
*, ast_expression
*);
211 ast_expression(const char *identifier
) :
214 subexpressions
[0] = NULL
;
215 subexpressions
[1] = NULL
;
216 subexpressions
[2] = NULL
;
217 primary_expression
.identifier
= identifier
;
218 this->non_lvalue_description
= NULL
;
219 this->is_lhs
= false;
222 static const char *operator_string(enum ast_operators op
);
224 virtual ir_rvalue
*hir(exec_list
*instructions
,
225 struct _mesa_glsl_parse_state
*state
);
227 virtual void hir_no_rvalue(exec_list
*instructions
,
228 struct _mesa_glsl_parse_state
*state
);
230 virtual bool has_sequence_subexpression() const;
232 ir_rvalue
*do_hir(exec_list
*instructions
,
233 struct _mesa_glsl_parse_state
*state
,
236 virtual void print(void) const;
238 enum ast_operators oper
;
240 ast_expression
*subexpressions
[3];
243 const char *identifier
;
245 float float_constant
;
246 unsigned uint_constant
;
248 double double_constant
;
249 } primary_expression
;
253 * List of expressions for an \c ast_sequence or parameters for an
254 * \c ast_function_call
256 exec_list expressions
;
259 * For things that can't be l-values, this describes what it is.
261 * This text is used by the code that generates IR for assignments to
262 * detect and emit useful messages for assignments to some things that
263 * can't be l-values. For example, pre- or post-incerement expressions.
266 * This pointer may be \c NULL.
268 const char *non_lvalue_description
;
270 void set_is_lhs(bool new_value
);
276 class ast_expression_bin
: public ast_expression
{
278 ast_expression_bin(int oper
, ast_expression
*, ast_expression
*);
280 virtual void print(void) const;
284 * Subclass of expressions for function calls
286 class ast_function_expression
: public ast_expression
{
288 ast_function_expression(ast_expression
*callee
)
289 : ast_expression(ast_function_call
, callee
,
296 ast_function_expression(class ast_type_specifier
*type
)
297 : ast_expression(ast_function_call
, (ast_expression
*) type
,
304 bool is_constructor() const
309 virtual ir_rvalue
*hir(exec_list
*instructions
,
310 struct _mesa_glsl_parse_state
*state
);
312 virtual void hir_no_rvalue(exec_list
*instructions
,
313 struct _mesa_glsl_parse_state
*state
);
315 virtual bool has_sequence_subexpression() const;
319 * Is this function call actually a constructor?
323 handle_method(exec_list
*instructions
,
324 struct _mesa_glsl_parse_state
*state
);
327 class ast_subroutine_list
: public ast_node
330 virtual void print(void) const;
331 exec_list declarations
;
334 class ast_array_specifier
: public ast_node
{
336 ast_array_specifier(const struct YYLTYPE
&locp
, ast_expression
*dim
)
339 array_dimensions
.push_tail(&dim
->link
);
342 void add_dimension(ast_expression
*dim
)
344 array_dimensions
.push_tail(&dim
->link
);
347 bool is_single_dimension() const
349 return this->array_dimensions
.get_tail_raw()->prev
!= NULL
&&
350 this->array_dimensions
.get_tail_raw()->prev
->is_head_sentinel();
353 virtual void print(void) const;
355 /* This list contains objects of type ast_node containing the
356 * array dimensions in outermost-to-innermost order.
358 exec_list array_dimensions
;
361 class ast_layout_expression
: public ast_node
{
363 ast_layout_expression(const struct YYLTYPE
&locp
, ast_expression
*expr
)
366 layout_const_expressions
.push_tail(&expr
->link
);
369 bool process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
370 const char *qual_indentifier
,
371 unsigned *value
, bool can_be_zero
,
372 bool must_match
= false);
374 void merge_qualifier(ast_layout_expression
*l_expr
)
376 layout_const_expressions
.append_list(&l_expr
->layout_const_expressions
);
379 exec_list layout_const_expressions
;
383 * C-style aggregate initialization class
385 * Represents C-style initializers of vectors, matrices, arrays, and
386 * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to
387 * vec3 pos = vec3(1.0, 0.0, -1.0).
389 * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack.
391 * \sa _mesa_ast_set_aggregate_type
393 class ast_aggregate_initializer
: public ast_expression
{
395 ast_aggregate_initializer()
396 : ast_expression(ast_aggregate
, NULL
, NULL
, NULL
),
397 constructor_type(NULL
)
403 * glsl_type of the aggregate, which is inferred from the LHS of whatever
404 * the aggregate is being used to initialize. This can't be inferred at
405 * parse time (since the parser deals with ast_type_specifiers, not
406 * glsl_types), so the parser leaves it NULL. However, the ast-to-hir
407 * conversion code makes sure to fill it in with the appropriate type
408 * before hir() is called.
410 const glsl_type
*constructor_type
;
412 virtual ir_rvalue
*hir(exec_list
*instructions
,
413 struct _mesa_glsl_parse_state
*state
);
415 virtual void hir_no_rvalue(exec_list
*instructions
,
416 struct _mesa_glsl_parse_state
*state
);
420 * Number of possible operators for an ast_expression
422 * This is done as a define instead of as an additional value in the enum so
423 * that the compiler won't generate spurious messages like "warning:
424 * enumeration value ‘ast_num_operators’ not handled in switch"
426 #define AST_NUM_OPERATORS (ast_sequence + 1)
429 class ast_compound_statement
: public ast_node
{
431 ast_compound_statement(int new_scope
, ast_node
*statements
);
432 virtual void print(void) const;
434 virtual ir_rvalue
*hir(exec_list
*instructions
,
435 struct _mesa_glsl_parse_state
*state
);
438 exec_list statements
;
441 class ast_declaration
: public ast_node
{
443 ast_declaration(const char *identifier
,
444 ast_array_specifier
*array_specifier
,
445 ast_expression
*initializer
);
446 virtual void print(void) const;
448 const char *identifier
;
450 ast_array_specifier
*array_specifier
;
452 ast_expression
*initializer
;
457 ast_precision_none
= 0, /**< Absence of precision qualifier. */
459 ast_precision_medium
,
463 struct ast_type_qualifier
{
464 DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier
);
468 unsigned invariant
:1;
471 unsigned attribute
:1;
480 unsigned shared_storage
:1;
483 unsigned noperspective
:1;
485 /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */
487 unsigned origin_upper_left
:1;
488 unsigned pixel_center_integer
:1;
492 * Flag set if GL_ARB_enhanced_layouts "align" layout qualifier is
495 unsigned explicit_align
:1;
498 * Flag set if GL_ARB_explicit_attrib_location "location" layout
501 unsigned explicit_location
:1;
503 * Flag set if GL_ARB_explicit_attrib_location "index" layout
506 unsigned explicit_index
:1;
509 * Flag set if GL_ARB_enhanced_layouts "component" layout
512 unsigned explicit_component
:1;
515 * Flag set if GL_ARB_shading_language_420pack "binding" layout
518 unsigned explicit_binding
:1;
521 * Flag set if GL_ARB_shader_atomic counter "offset" layout
524 unsigned explicit_offset
:1;
526 /** \name Layout qualifiers for GL_AMD_conservative_depth */
528 unsigned depth_any
:1;
529 unsigned depth_greater
:1;
530 unsigned depth_less
:1;
531 unsigned depth_unchanged
:1;
534 /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
540 unsigned column_major
:1;
541 unsigned row_major
:1;
544 /** \name Layout qualifiers for GLSL 1.50 geometry shaders */
546 unsigned prim_type
:1;
547 unsigned max_vertices
:1;
551 * local_size_{x,y,z} flags for compute shaders. Bit 0 represents
552 * local_size_x, and so on.
554 unsigned local_size
:3;
556 /** \name Layout and memory qualifiers for ARB_shader_image_load_store. */
558 unsigned early_fragment_tests
:1;
559 unsigned explicit_image_format
:1;
561 unsigned _volatile
:1;
562 unsigned restrict_flag
:1;
563 unsigned read_only
:1; /**< "readonly" qualifier. */
564 unsigned write_only
:1; /**< "writeonly" qualifier. */
567 /** \name Layout qualifiers for GL_ARB_gpu_shader5 */
569 unsigned invocations
:1;
570 unsigned stream
:1; /**< Has stream value assigned */
571 unsigned explicit_stream
:1; /**< stream value assigned explicitly by shader code */
574 /** \name Layout qualifiers for GL_ARB_enhanced_layouts */
576 unsigned explicit_xfb_offset
:1; /**< xfb_offset value assigned explicitly by shader code */
577 unsigned xfb_buffer
:1; /**< Has xfb_buffer value assigned */
578 unsigned explicit_xfb_buffer
:1; /**< xfb_buffer value assigned explicitly by shader code */
579 unsigned xfb_stride
:1; /**< Is xfb_stride value yet to be merged with global values */
580 unsigned explicit_xfb_stride
:1; /**< xfb_stride value assigned explicitly by shader code */
583 /** \name Layout qualifiers for GL_ARB_tessellation_shader */
585 /* tess eval input layout */
586 /* gs prim_type reused for primitive mode */
587 unsigned vertex_spacing
:1;
589 unsigned point_mode
:1;
590 /* tess control output layout */
594 /** \name Qualifiers for GL_ARB_shader_subroutine */
596 unsigned subroutine
:1; /**< Is this marked 'subroutine' */
597 unsigned subroutine_def
:1; /**< Is this marked 'subroutine' with a list of types */
600 /** \brief Set of flags, accessed by name. */
603 /** \brief Set of flags, accessed as a bitmask. */
607 /** Precision of the type (highp/medium/lowp). */
608 unsigned precision
:2;
611 * Alignment specified via GL_ARB_enhanced_layouts "align" layout qualifier
613 ast_expression
*align
;
615 /** Geometry shader invocations for GL_ARB_gpu_shader5. */
616 ast_layout_expression
*invocations
;
619 * Location specified via GL_ARB_explicit_attrib_location layout
622 * This field is only valid if \c explicit_location is set.
624 ast_expression
*location
;
626 * Index specified via GL_ARB_explicit_attrib_location layout
629 * This field is only valid if \c explicit_index is set.
631 ast_expression
*index
;
634 * Component specified via GL_ARB_enhaced_layouts
637 * This field is only valid if \c explicit_component is set.
639 ast_expression
*component
;
641 /** Maximum output vertices in GLSL 1.50 geometry shaders. */
642 ast_layout_expression
*max_vertices
;
644 /** Stream in GLSL 1.50 geometry shaders. */
645 ast_expression
*stream
;
647 /** xfb_buffer specified via the GL_ARB_enhanced_layouts keyword. */
648 ast_expression
*xfb_buffer
;
650 /** xfb_stride specified via the GL_ARB_enhanced_layouts keyword. */
651 ast_expression
*xfb_stride
;
653 /** global xfb_stride values for each buffer */
654 ast_layout_expression
*out_xfb_stride
[MAX_FEEDBACK_BUFFERS
];
657 * Input or output primitive type in GLSL 1.50 geometry shaders
658 * and tessellation shaders.
663 * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword.
666 * This field is only valid if \c explicit_binding is set.
668 ast_expression
*binding
;
671 * Offset specified via GL_ARB_shader_atomic_counter's or
672 * GL_ARB_enhanced_layouts "offset" keyword, or by GL_ARB_enhanced_layouts
673 * "xfb_offset" keyword.
676 * This field is only valid if \c explicit_offset is set.
678 ast_expression
*offset
;
681 * Local size specified via GL_ARB_compute_shader's "local_size_{x,y,z}"
682 * layout qualifier. Element i of this array is only valid if
683 * flags.q.local_size & (1 << i) is set.
685 ast_layout_expression
*local_size
[3];
687 /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */
688 GLenum vertex_spacing
;
690 /** Tessellation evaluation shader: vertex ordering (CW or CCW) */
693 /** Tessellation evaluation shader: point mode */
696 /** Tessellation control shader: number of output vertices */
697 ast_layout_expression
*vertices
;
700 * Image format specified with an ARB_shader_image_load_store
704 * This field is only valid if \c explicit_image_format is set.
709 * Base type of the data read from or written to this image. Only
710 * the following enumerants are allowed: GLSL_TYPE_UINT,
711 * GLSL_TYPE_INT, GLSL_TYPE_FLOAT.
714 * This field is only valid if \c explicit_image_format is set.
716 glsl_base_type image_base_type
;
718 /** Flag to know if this represents a default value for a qualifier */
719 bool is_default_qualifier
;
722 * Return true if and only if an interpolation qualifier is present.
724 bool has_interpolation() const;
727 * Return whether a layout qualifier is present.
729 bool has_layout() const;
732 * Return whether a storage qualifier is present.
734 bool has_storage() const;
737 * Return whether an auxiliary storage qualifier is present.
739 bool has_auxiliary_storage() const;
741 bool merge_qualifier(YYLTYPE
*loc
,
742 _mesa_glsl_parse_state
*state
,
743 const ast_type_qualifier
&q
,
744 bool is_single_layout_merge
);
746 bool merge_out_qualifier(YYLTYPE
*loc
,
747 _mesa_glsl_parse_state
*state
,
748 const ast_type_qualifier
&q
,
749 ast_node
* &node
, bool create_node
);
751 bool merge_in_qualifier(YYLTYPE
*loc
,
752 _mesa_glsl_parse_state
*state
,
753 const ast_type_qualifier
&q
,
754 ast_node
* &node
, bool create_node
);
756 bool validate_flags(YYLTYPE
*loc
,
757 _mesa_glsl_parse_state
*state
,
758 const ast_type_qualifier
&allowed_flags
,
759 const char *message
, const char *name
);
761 ast_subroutine_list
*subroutine_list
;
764 class ast_declarator_list
;
766 class ast_struct_specifier
: public ast_node
{
768 ast_struct_specifier(const char *identifier
,
769 ast_declarator_list
*declarator_list
);
770 virtual void print(void) const;
772 virtual ir_rvalue
*hir(exec_list
*instructions
,
773 struct _mesa_glsl_parse_state
*state
);
776 ast_type_qualifier
*layout
;
777 /* List of ast_declarator_list * */
778 exec_list declarations
;
784 class ast_type_specifier
: public ast_node
{
786 /** Construct a type specifier from a type name */
787 ast_type_specifier(const char *name
)
788 : type_name(name
), structure(NULL
), array_specifier(NULL
),
789 default_precision(ast_precision_none
)
794 /** Construct a type specifier from a structure definition */
795 ast_type_specifier(ast_struct_specifier
*s
)
796 : type_name(s
->name
), structure(s
), array_specifier(NULL
),
797 default_precision(ast_precision_none
)
802 const struct glsl_type
*glsl_type(const char **name
,
803 struct _mesa_glsl_parse_state
*state
)
806 virtual void print(void) const;
808 ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
810 const char *type_name
;
811 ast_struct_specifier
*structure
;
813 ast_array_specifier
*array_specifier
;
815 /** For precision statements, this is the given precision; otherwise none. */
816 unsigned default_precision
:2;
820 class ast_fully_specified_type
: public ast_node
{
822 virtual void print(void) const;
823 bool has_qualifiers(_mesa_glsl_parse_state
*state
) const;
825 ast_fully_specified_type() : qualifier(), specifier(NULL
)
829 const struct glsl_type
*glsl_type(const char **name
,
830 struct _mesa_glsl_parse_state
*state
)
833 ast_type_qualifier qualifier
;
834 ast_type_specifier
*specifier
;
838 class ast_declarator_list
: public ast_node
{
840 ast_declarator_list(ast_fully_specified_type
*);
841 virtual void print(void) const;
843 virtual ir_rvalue
*hir(exec_list
*instructions
,
844 struct _mesa_glsl_parse_state
*state
);
846 ast_fully_specified_type
*type
;
847 /** List of 'ast_declaration *' */
848 exec_list declarations
;
851 * Flags for redeclarations. In these cases, no type is specified, to
852 * `type` is allowed to be NULL. In all other cases, this would be an error.
854 int invariant
; /** < `invariant` redeclaration */
855 int precise
; /** < `precise` redeclaration */
859 class ast_parameter_declarator
: public ast_node
{
861 ast_parameter_declarator() :
864 array_specifier(NULL
),
865 formal_parameter(false),
871 virtual void print(void) const;
873 virtual ir_rvalue
*hir(exec_list
*instructions
,
874 struct _mesa_glsl_parse_state
*state
);
876 ast_fully_specified_type
*type
;
877 const char *identifier
;
878 ast_array_specifier
*array_specifier
;
880 static void parameters_to_hir(exec_list
*ast_parameters
,
881 bool formal
, exec_list
*ir_parameters
,
882 struct _mesa_glsl_parse_state
*state
);
885 /** Is this parameter declaration part of a formal parameter list? */
886 bool formal_parameter
;
889 * Is this parameter 'void' type?
891 * This field is set by \c ::hir.
897 class ast_function
: public ast_node
{
901 virtual void print(void) const;
903 virtual ir_rvalue
*hir(exec_list
*instructions
,
904 struct _mesa_glsl_parse_state
*state
);
906 ast_fully_specified_type
*return_type
;
907 const char *identifier
;
909 exec_list parameters
;
913 * Is this prototype part of the function definition?
915 * Used by ast_function_definition::hir to process the parameters, etc.
923 * Function signature corresponding to this function prototype instance
925 * Used by ast_function_definition::hir to process the parameters, etc.
930 class ir_function_signature
*signature
;
932 friend class ast_function_definition
;
936 class ast_expression_statement
: public ast_node
{
938 ast_expression_statement(ast_expression
*);
939 virtual void print(void) const;
941 virtual ir_rvalue
*hir(exec_list
*instructions
,
942 struct _mesa_glsl_parse_state
*state
);
944 ast_expression
*expression
;
948 class ast_case_label
: public ast_node
{
950 ast_case_label(ast_expression
*test_value
);
951 virtual void print(void) const;
953 virtual ir_rvalue
*hir(exec_list
*instructions
,
954 struct _mesa_glsl_parse_state
*state
);
957 * An test value of NULL means 'default'.
959 ast_expression
*test_value
;
963 class ast_case_label_list
: public ast_node
{
965 ast_case_label_list(void);
966 virtual void print(void) const;
968 virtual ir_rvalue
*hir(exec_list
*instructions
,
969 struct _mesa_glsl_parse_state
*state
);
972 * A list of case labels.
978 class ast_case_statement
: public ast_node
{
980 ast_case_statement(ast_case_label_list
*labels
);
981 virtual void print(void) const;
983 virtual ir_rvalue
*hir(exec_list
*instructions
,
984 struct _mesa_glsl_parse_state
*state
);
986 ast_case_label_list
*labels
;
989 * A list of statements.
995 class ast_case_statement_list
: public ast_node
{
997 ast_case_statement_list(void);
998 virtual void print(void) const;
1000 virtual ir_rvalue
*hir(exec_list
*instructions
,
1001 struct _mesa_glsl_parse_state
*state
);
1010 class ast_switch_body
: public ast_node
{
1012 ast_switch_body(ast_case_statement_list
*stmts
);
1013 virtual void print(void) const;
1015 virtual ir_rvalue
*hir(exec_list
*instructions
,
1016 struct _mesa_glsl_parse_state
*state
);
1018 ast_case_statement_list
*stmts
;
1022 class ast_selection_statement
: public ast_node
{
1024 ast_selection_statement(ast_expression
*condition
,
1025 ast_node
*then_statement
,
1026 ast_node
*else_statement
);
1027 virtual void print(void) const;
1029 virtual ir_rvalue
*hir(exec_list
*instructions
,
1030 struct _mesa_glsl_parse_state
*state
);
1032 ast_expression
*condition
;
1033 ast_node
*then_statement
;
1034 ast_node
*else_statement
;
1038 class ast_switch_statement
: public ast_node
{
1040 ast_switch_statement(ast_expression
*test_expression
,
1042 virtual void print(void) const;
1044 virtual ir_rvalue
*hir(exec_list
*instructions
,
1045 struct _mesa_glsl_parse_state
*state
);
1047 ast_expression
*test_expression
;
1051 void test_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1054 class ast_iteration_statement
: public ast_node
{
1056 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
1057 ast_expression
*rest_expression
, ast_node
*body
);
1059 virtual void print(void) const;
1061 virtual ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1063 enum ast_iteration_modes
{
1070 ast_node
*init_statement
;
1071 ast_node
*condition
;
1072 ast_expression
*rest_expression
;
1077 * Generate IR from the condition of a loop
1079 * This is factored out of ::hir because some loops have the condition
1080 * test at the top (for and while), and others have it at the end (do-while).
1082 void condition_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1086 class ast_jump_statement
: public ast_node
{
1088 ast_jump_statement(int mode
, ast_expression
*return_value
);
1089 virtual void print(void) const;
1091 virtual ir_rvalue
*hir(exec_list
*instructions
,
1092 struct _mesa_glsl_parse_state
*state
);
1094 enum ast_jump_modes
{
1101 ast_expression
*opt_return_value
;
1105 class ast_function_definition
: public ast_node
{
1107 ast_function_definition() : prototype(NULL
), body(NULL
)
1111 virtual void print(void) const;
1113 virtual ir_rvalue
*hir(exec_list
*instructions
,
1114 struct _mesa_glsl_parse_state
*state
);
1116 ast_function
*prototype
;
1117 ast_compound_statement
*body
;
1120 class ast_interface_block
: public ast_node
{
1122 ast_interface_block(const char *instance_name
,
1123 ast_array_specifier
*array_specifier
)
1124 : block_name(NULL
), instance_name(instance_name
),
1125 array_specifier(array_specifier
)
1129 virtual ir_rvalue
*hir(exec_list
*instructions
,
1130 struct _mesa_glsl_parse_state
*state
);
1132 ast_type_qualifier layout
;
1133 const char *block_name
;
1136 * Declared name of the block instance, if specified.
1138 * If the block does not have an instance name, this field will be
1141 const char *instance_name
;
1143 /** List of ast_declarator_list * */
1144 exec_list declarations
;
1147 * Declared array size of the block instance
1149 * If the block is not declared as an array or if the block instance array
1150 * is unsized, this field will be \c NULL.
1152 ast_array_specifier
*array_specifier
;
1157 * AST node representing a declaration of the output layout for tessellation
1160 class ast_tcs_output_layout
: public ast_node
1163 ast_tcs_output_layout(const struct YYLTYPE
&locp
)
1168 virtual ir_rvalue
*hir(exec_list
*instructions
,
1169 struct _mesa_glsl_parse_state
*state
);
1174 * AST node representing a declaration of the input layout for geometry
1177 class ast_gs_input_layout
: public ast_node
1180 ast_gs_input_layout(const struct YYLTYPE
&locp
, GLenum prim_type
)
1181 : prim_type(prim_type
)
1186 virtual ir_rvalue
*hir(exec_list
*instructions
,
1187 struct _mesa_glsl_parse_state
*state
);
1190 const GLenum prim_type
;
1195 * AST node representing a decalaration of the input layout for compute
1198 class ast_cs_input_layout
: public ast_node
1201 ast_cs_input_layout(const struct YYLTYPE
&locp
,
1202 ast_layout_expression
*const *local_size
)
1204 for (int i
= 0; i
< 3; i
++) {
1205 this->local_size
[i
] = local_size
[i
];
1210 virtual ir_rvalue
*hir(exec_list
*instructions
,
1211 struct _mesa_glsl_parse_state
*state
);
1214 ast_layout_expression
*local_size
[3];
1220 _mesa_ast_to_hir(exec_list
*instructions
, struct _mesa_glsl_parse_state
*state
);
1223 _mesa_ast_field_selection_to_hir(const ast_expression
*expr
,
1224 exec_list
*instructions
,
1225 struct _mesa_glsl_parse_state
*state
);
1228 _mesa_ast_array_index_to_hir(void *mem_ctx
,
1229 struct _mesa_glsl_parse_state
*state
,
1230 ir_rvalue
*array
, ir_rvalue
*idx
,
1231 YYLTYPE
&loc
, YYLTYPE
&idx_loc
);
1234 _mesa_ast_set_aggregate_type(const glsl_type
*type
,
1235 ast_expression
*expr
);
1238 emit_function(_mesa_glsl_parse_state
*state
, ir_function
*f
);
1241 check_builtin_array_max_size(const char *name
, unsigned size
,
1242 YYLTYPE loc
, struct _mesa_glsl_parse_state
*state
);
1244 extern void _mesa_ast_process_interface_block(YYLTYPE
*locp
,
1245 _mesa_glsl_parse_state
*state
,
1246 ast_interface_block
*const block
,
1247 const struct ast_type_qualifier
&q
);
1250 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
1252 const char *qual_indentifier
,
1253 ast_expression
*const_expression
,