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"
30 #include "compiler/glsl_types.h"
31 #include "util/bitset.h"
33 struct _mesa_glsl_parse_state
;
38 * \defgroup AST Abstract syntax tree node definitions
40 * An abstract syntax tree is generated by the parser. This is a fairly
41 * direct representation of the gramma derivation for the source program.
42 * No symantic checking is done during the generation of the AST. Only
43 * syntactic checking is done. Symantic checking is performed by a later
44 * stage that converts the AST to a more generic intermediate representation.
49 * Base class of all abstract syntax tree nodes
53 DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(ast_node
);
56 * Print an AST node in something approximating the original GLSL code
58 virtual void print(void) const;
61 * Convert the AST node to the high-level intermediate representation
63 virtual ir_rvalue
*hir(exec_list
*instructions
,
64 struct _mesa_glsl_parse_state
*state
);
66 virtual bool has_sequence_subexpression() const;
69 * Retrieve the source location of an AST node
71 * This function is primarily used to get the source position of an AST node
72 * into a form that can be passed to \c _mesa_glsl_error.
74 * \sa _mesa_glsl_error, ast_node::set_location
76 struct YYLTYPE
get_location(void) const
80 locp
.source
= this->location
.source
;
81 locp
.first_line
= this->location
.first_line
;
82 locp
.first_column
= this->location
.first_column
;
83 locp
.last_line
= this->location
.last_line
;
84 locp
.last_column
= this->location
.last_column
;
90 * Set the source location of an AST node from a parser location
92 * \sa ast_node::get_location
94 void set_location(const struct YYLTYPE
&locp
)
96 this->location
.source
= locp
.source
;
97 this->location
.first_line
= locp
.first_line
;
98 this->location
.first_column
= locp
.first_column
;
99 this->location
.last_line
= locp
.last_line
;
100 this->location
.last_column
= locp
.last_column
;
104 * Set the source location range of an AST node using two location nodes
106 * \sa ast_node::set_location
108 void set_location_range(const struct YYLTYPE
&begin
, const struct YYLTYPE
&end
)
110 this->location
.source
= begin
.source
;
111 this->location
.first_line
= begin
.first_line
;
112 this->location
.last_line
= end
.last_line
;
113 this->location
.first_column
= begin
.first_column
;
114 this->location
.last_column
= end
.last_column
;
118 * Source location of the AST node.
121 unsigned source
; /**< GLSL source number. */
122 unsigned first_line
; /**< First line number within the source string. */
123 unsigned first_column
; /**< First column in the first line. */
124 unsigned last_line
; /**< Last line number within the source string. */
125 unsigned last_column
; /**< Last column in the last line. */
130 virtual void set_is_lhs(bool);
134 * The only constructor is protected so that only derived class objects can
142 * Operators for AST expression nodes.
146 ast_plus
, /**< Unary + operator. */
189 ast_unsized_array_dim
,
206 * Number of possible operators for an ast_expression
208 * This is done as a define instead of as an additional value in the enum so
209 * that the compiler won't generate spurious messages like "warning:
210 * enumeration value ‘ast_num_operators’ not handled in switch"
212 #define AST_NUM_OPERATORS (ast_aggregate + 1)
216 * Representation of any sort of expression.
218 class ast_expression
: public ast_node
{
220 ast_expression(int oper
, ast_expression
*,
221 ast_expression
*, ast_expression
*);
223 ast_expression(const char *identifier
) :
226 subexpressions
[0] = NULL
;
227 subexpressions
[1] = NULL
;
228 subexpressions
[2] = NULL
;
229 primary_expression
.identifier
= identifier
;
230 this->non_lvalue_description
= NULL
;
231 this->is_lhs
= false;
234 static const char *operator_string(enum ast_operators op
);
236 virtual ir_rvalue
*hir(exec_list
*instructions
,
237 struct _mesa_glsl_parse_state
*state
);
239 virtual void hir_no_rvalue(exec_list
*instructions
,
240 struct _mesa_glsl_parse_state
*state
);
242 virtual bool has_sequence_subexpression() const;
244 ir_rvalue
*do_hir(exec_list
*instructions
,
245 struct _mesa_glsl_parse_state
*state
,
248 virtual void print(void) const;
250 enum ast_operators oper
;
252 ast_expression
*subexpressions
[3];
255 const char *identifier
;
257 float float_constant
;
258 unsigned uint_constant
;
260 double double_constant
;
261 uint64_t uint64_constant
;
262 int64_t int64_constant
;
263 } primary_expression
;
267 * List of expressions for an \c ast_sequence or parameters for an
268 * \c ast_function_call
270 exec_list expressions
;
273 * For things that can't be l-values, this describes what it is.
275 * This text is used by the code that generates IR for assignments to
276 * detect and emit useful messages for assignments to some things that
277 * can't be l-values. For example, pre- or post-incerement expressions.
280 * This pointer may be \c NULL.
282 const char *non_lvalue_description
;
284 void set_is_lhs(bool new_value
);
290 class ast_expression_bin
: public ast_expression
{
292 ast_expression_bin(int oper
, ast_expression
*, ast_expression
*);
294 virtual void print(void) const;
298 * Subclass of expressions for function calls
300 class ast_function_expression
: public ast_expression
{
302 ast_function_expression(ast_expression
*callee
)
303 : ast_expression(ast_function_call
, callee
,
310 ast_function_expression(class ast_type_specifier
*type
)
311 : ast_expression(ast_function_call
, (ast_expression
*) type
,
318 bool is_constructor() const
323 virtual ir_rvalue
*hir(exec_list
*instructions
,
324 struct _mesa_glsl_parse_state
*state
);
326 virtual void hir_no_rvalue(exec_list
*instructions
,
327 struct _mesa_glsl_parse_state
*state
);
329 virtual bool has_sequence_subexpression() const;
333 * Is this function call actually a constructor?
337 handle_method(exec_list
*instructions
,
338 struct _mesa_glsl_parse_state
*state
);
341 class ast_subroutine_list
: public ast_node
344 virtual void print(void) const;
345 exec_list declarations
;
348 class ast_array_specifier
: public ast_node
{
350 ast_array_specifier(const struct YYLTYPE
&locp
, ast_expression
*dim
)
353 array_dimensions
.push_tail(&dim
->link
);
356 void add_dimension(ast_expression
*dim
)
358 array_dimensions
.push_tail(&dim
->link
);
361 bool is_single_dimension() const
363 return this->array_dimensions
.get_tail_raw()->prev
!= NULL
&&
364 this->array_dimensions
.get_tail_raw()->prev
->is_head_sentinel();
367 virtual void print(void) const;
369 /* This list contains objects of type ast_node containing the
370 * array dimensions in outermost-to-innermost order.
372 exec_list array_dimensions
;
375 class ast_layout_expression
: public ast_node
{
377 ast_layout_expression(const struct YYLTYPE
&locp
, ast_expression
*expr
)
380 layout_const_expressions
.push_tail(&expr
->link
);
383 bool process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
384 const char *qual_indentifier
,
385 unsigned *value
, bool can_be_zero
);
387 void merge_qualifier(ast_layout_expression
*l_expr
)
389 layout_const_expressions
.append_list(&l_expr
->layout_const_expressions
);
392 exec_list layout_const_expressions
;
396 * C-style aggregate initialization class
398 * Represents C-style initializers of vectors, matrices, arrays, and
399 * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to
400 * vec3 pos = vec3(1.0, 0.0, -1.0).
402 * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack.
404 * \sa _mesa_ast_set_aggregate_type
406 class ast_aggregate_initializer
: public ast_expression
{
408 ast_aggregate_initializer()
409 : ast_expression(ast_aggregate
, NULL
, NULL
, NULL
),
410 constructor_type(NULL
)
416 * glsl_type of the aggregate, which is inferred from the LHS of whatever
417 * the aggregate is being used to initialize. This can't be inferred at
418 * parse time (since the parser deals with ast_type_specifiers, not
419 * glsl_types), so the parser leaves it NULL. However, the ast-to-hir
420 * conversion code makes sure to fill it in with the appropriate type
421 * before hir() is called.
423 const glsl_type
*constructor_type
;
425 virtual ir_rvalue
*hir(exec_list
*instructions
,
426 struct _mesa_glsl_parse_state
*state
);
428 virtual void hir_no_rvalue(exec_list
*instructions
,
429 struct _mesa_glsl_parse_state
*state
);
433 class ast_compound_statement
: public ast_node
{
435 ast_compound_statement(int new_scope
, ast_node
*statements
);
436 virtual void print(void) const;
438 virtual ir_rvalue
*hir(exec_list
*instructions
,
439 struct _mesa_glsl_parse_state
*state
);
442 exec_list statements
;
445 class ast_declaration
: public ast_node
{
447 ast_declaration(const char *identifier
,
448 ast_array_specifier
*array_specifier
,
449 ast_expression
*initializer
);
450 virtual void print(void) const;
452 const char *identifier
;
454 ast_array_specifier
*array_specifier
;
456 ast_expression
*initializer
;
461 ast_precision_none
= 0, /**< Absence of precision qualifier. */
463 ast_precision_medium
,
468 ast_depth_none
= 0, /**< Absence of depth qualifier. */
475 struct ast_type_qualifier
{
476 DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier
);
477 /* Note: this bitset needs to have at least as many bits as the 'q'
478 * struct has flags, below. Previously, the size was 128 instead of 96.
479 * But an apparent bug in GCC 5.4.0 causes bad SSE code generation
480 * elsewhere, leading to a crash. 96 bits works around the issue.
481 * See https://bugs.freedesktop.org/show_bug.cgi?id=105497
483 DECLARE_BITSET_T(bitset_t
, 96);
487 unsigned invariant
:1;
490 unsigned attribute
:1;
499 unsigned shared_storage
:1;
502 unsigned noperspective
:1;
504 /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */
506 unsigned origin_upper_left
:1;
507 unsigned pixel_center_integer
:1;
511 * Flag set if GL_ARB_enhanced_layouts "align" layout qualifier is
514 unsigned explicit_align
:1;
517 * Flag set if GL_ARB_explicit_attrib_location "location" layout
520 unsigned explicit_location
:1;
522 * Flag set if GL_ARB_explicit_attrib_location "index" layout
525 unsigned explicit_index
:1;
528 * Flag set if GL_ARB_enhanced_layouts "component" layout
531 unsigned explicit_component
:1;
534 * Flag set if GL_ARB_shading_language_420pack "binding" layout
537 unsigned explicit_binding
:1;
540 * Flag set if GL_ARB_shader_atomic counter "offset" layout
543 unsigned explicit_offset
:1;
545 /** \name Layout qualifiers for GL_AMD_conservative_depth */
547 unsigned depth_type
:1;
550 /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
556 unsigned column_major
:1;
557 unsigned row_major
:1;
560 /** \name Layout qualifiers for GLSL 1.50 geometry shaders */
562 unsigned prim_type
:1;
563 unsigned max_vertices
:1;
567 * local_size_{x,y,z} flags for compute shaders. Bit 0 represents
568 * local_size_x, and so on.
570 unsigned local_size
:3;
572 /** \name Layout qualifiers for ARB_compute_variable_group_size. */
574 unsigned local_size_variable
:1;
577 /** \name Layout and memory qualifiers for ARB_shader_image_load_store. */
579 unsigned early_fragment_tests
:1;
580 unsigned explicit_image_format
:1;
582 unsigned _volatile
:1;
583 unsigned restrict_flag
:1;
584 unsigned read_only
:1; /**< "readonly" qualifier. */
585 unsigned write_only
:1; /**< "writeonly" qualifier. */
588 /** \name Layout qualifiers for GL_ARB_gpu_shader5 */
590 unsigned invocations
:1;
591 unsigned stream
:1; /**< Has stream value assigned */
592 unsigned explicit_stream
:1; /**< stream value assigned explicitly by shader code */
595 /** \name Layout qualifiers for GL_ARB_enhanced_layouts */
597 unsigned explicit_xfb_offset
:1; /**< xfb_offset value assigned explicitly by shader code */
598 unsigned xfb_buffer
:1; /**< Has xfb_buffer value assigned */
599 unsigned explicit_xfb_buffer
:1; /**< xfb_buffer value assigned explicitly by shader code */
600 unsigned xfb_stride
:1; /**< Is xfb_stride value yet to be merged with global values */
601 unsigned explicit_xfb_stride
:1; /**< xfb_stride value assigned explicitly by shader code */
604 /** \name Layout qualifiers for GL_ARB_tessellation_shader */
606 /* tess eval input layout */
607 /* gs prim_type reused for primitive mode */
608 unsigned vertex_spacing
:1;
610 unsigned point_mode
:1;
611 /* tess control output layout */
615 /** \name Qualifiers for GL_ARB_shader_subroutine */
617 unsigned subroutine
:1; /**< Is this marked 'subroutine' */
620 /** \name Qualifiers for GL_KHR_blend_equation_advanced */
622 unsigned blend_support
:1; /**< Are there any blend_support_ qualifiers */
626 * Flag set if GL_ARB_post_depth_coverage layout qualifier is used.
628 unsigned post_depth_coverage
:1;
631 * Flags for the layout qualifers added by ARB_fragment_shader_interlock
634 unsigned pixel_interlock_ordered
:1;
635 unsigned pixel_interlock_unordered
:1;
636 unsigned sample_interlock_ordered
:1;
637 unsigned sample_interlock_unordered
:1;
640 * Flag set if GL_INTEL_conservartive_rasterization layout qualifier
643 unsigned inner_coverage
:1;
645 /** \name Layout qualifiers for GL_ARB_bindless_texture */
647 unsigned bindless_sampler
:1;
648 unsigned bindless_image
:1;
649 unsigned bound_sampler
:1;
650 unsigned bound_image
:1;
653 /** \name Layout qualifiers for GL_EXT_shader_framebuffer_fetch_non_coherent */
655 unsigned non_coherent
:1;
658 /** \name Layout qualifiers for NV_compute_shader_derivatives */
660 unsigned derivative_group
:1;
663 /** \brief Set of flags, accessed by name. */
666 /** \brief Set of flags, accessed as a bitmask. */
670 /** Precision of the type (highp/medium/lowp). */
671 unsigned precision
:2;
673 /** Type of layout qualifiers for GL_AMD_conservative_depth. */
674 unsigned depth_type
:3;
677 * Alignment specified via GL_ARB_enhanced_layouts "align" layout qualifier
679 ast_expression
*align
;
681 /** Geometry shader invocations for GL_ARB_gpu_shader5. */
682 ast_layout_expression
*invocations
;
685 * Location specified via GL_ARB_explicit_attrib_location layout
688 * This field is only valid if \c explicit_location is set.
690 ast_expression
*location
;
692 * Index specified via GL_ARB_explicit_attrib_location layout
695 * This field is only valid if \c explicit_index is set.
697 ast_expression
*index
;
700 * Component specified via GL_ARB_enhaced_layouts
703 * This field is only valid if \c explicit_component is set.
705 ast_expression
*component
;
707 /** Maximum output vertices in GLSL 1.50 geometry shaders. */
708 ast_layout_expression
*max_vertices
;
710 /** Stream in GLSL 1.50 geometry shaders. */
711 ast_expression
*stream
;
713 /** xfb_buffer specified via the GL_ARB_enhanced_layouts keyword. */
714 ast_expression
*xfb_buffer
;
716 /** xfb_stride specified via the GL_ARB_enhanced_layouts keyword. */
717 ast_expression
*xfb_stride
;
719 /** global xfb_stride values for each buffer */
720 ast_layout_expression
*out_xfb_stride
[MAX_FEEDBACK_BUFFERS
];
723 * Input or output primitive type in GLSL 1.50 geometry shaders
724 * and tessellation shaders.
729 * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword.
732 * This field is only valid if \c explicit_binding is set.
734 ast_expression
*binding
;
737 * Offset specified via GL_ARB_shader_atomic_counter's or
738 * GL_ARB_enhanced_layouts "offset" keyword, or by GL_ARB_enhanced_layouts
739 * "xfb_offset" keyword.
742 * This field is only valid if \c explicit_offset is set.
744 ast_expression
*offset
;
747 * Local size specified via GL_ARB_compute_shader's "local_size_{x,y,z}"
748 * layout qualifier. Element i of this array is only valid if
749 * flags.q.local_size & (1 << i) is set.
751 ast_layout_expression
*local_size
[3];
753 /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */
754 enum gl_tess_spacing vertex_spacing
;
756 /** Tessellation evaluation shader: vertex ordering (CW or CCW) */
759 /** Tessellation evaluation shader: point mode */
762 /** Tessellation control shader: number of output vertices */
763 ast_layout_expression
*vertices
;
766 * Image format specified with an ARB_shader_image_load_store
770 * This field is only valid if \c explicit_image_format is set.
775 * Arrangement of invocations used to calculate derivatives in a compute
776 * shader. From NV_compute_shader_derivatives.
778 enum gl_derivative_group derivative_group
;
781 * Base type of the data read from or written to this image. Only
782 * the following enumerants are allowed: GLSL_TYPE_UINT,
783 * GLSL_TYPE_INT, GLSL_TYPE_FLOAT.
786 * This field is only valid if \c explicit_image_format is set.
788 glsl_base_type image_base_type
;
791 * Return true if and only if an interpolation qualifier is present.
793 bool has_interpolation() const;
796 * Return whether a layout qualifier is present.
798 bool has_layout() const;
801 * Return whether a storage qualifier is present.
803 bool has_storage() const;
806 * Return whether an auxiliary storage qualifier is present.
808 bool has_auxiliary_storage() const;
811 * Return true if and only if a memory qualifier is present.
813 bool has_memory() const;
816 * Return true if the qualifier is a subroutine declaration.
818 bool is_subroutine_decl() const;
820 bool merge_qualifier(YYLTYPE
*loc
,
821 _mesa_glsl_parse_state
*state
,
822 const ast_type_qualifier
&q
,
823 bool is_single_layout_merge
,
824 bool is_multiple_layouts_merge
= false);
827 * Validate current qualifier against the global out one.
829 bool validate_out_qualifier(YYLTYPE
*loc
,
830 _mesa_glsl_parse_state
*state
);
833 * Merge current qualifier into the global out one.
835 bool merge_into_out_qualifier(YYLTYPE
*loc
,
836 _mesa_glsl_parse_state
*state
,
840 * Validate current qualifier against the global in one.
842 bool validate_in_qualifier(YYLTYPE
*loc
,
843 _mesa_glsl_parse_state
*state
);
846 * Merge current qualifier into the global in one.
848 bool merge_into_in_qualifier(YYLTYPE
*loc
,
849 _mesa_glsl_parse_state
*state
,
853 * Push pending layout qualifiers to the global values.
855 bool push_to_global(YYLTYPE
*loc
,
856 _mesa_glsl_parse_state
*state
);
858 bool validate_flags(YYLTYPE
*loc
,
859 _mesa_glsl_parse_state
*state
,
860 const ast_type_qualifier
&allowed_flags
,
861 const char *message
, const char *name
);
863 ast_subroutine_list
*subroutine_list
;
866 class ast_declarator_list
;
868 class ast_struct_specifier
: public ast_node
{
870 ast_struct_specifier(const char *identifier
,
871 ast_declarator_list
*declarator_list
);
872 virtual void print(void) const;
874 virtual ir_rvalue
*hir(exec_list
*instructions
,
875 struct _mesa_glsl_parse_state
*state
);
878 ast_type_qualifier
*layout
;
879 /* List of ast_declarator_list * */
880 exec_list declarations
;
882 const glsl_type
*type
;
887 class ast_type_specifier
: public ast_node
{
889 /** Construct a type specifier from a type name */
890 ast_type_specifier(const char *name
)
891 : type(NULL
), type_name(name
), structure(NULL
), array_specifier(NULL
),
892 default_precision(ast_precision_none
)
897 /** Construct a type specifier from a structure definition */
898 ast_type_specifier(ast_struct_specifier
*s
)
899 : type(NULL
), type_name(s
->name
), structure(s
), array_specifier(NULL
),
900 default_precision(ast_precision_none
)
905 ast_type_specifier(const glsl_type
*t
)
906 : type(t
), type_name(t
->name
), structure(NULL
), array_specifier(NULL
),
907 default_precision(ast_precision_none
)
912 const struct glsl_type
*glsl_type(const char **name
,
913 struct _mesa_glsl_parse_state
*state
)
916 virtual void print(void) const;
918 ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
920 const struct glsl_type
*type
;
921 const char *type_name
;
922 ast_struct_specifier
*structure
;
924 ast_array_specifier
*array_specifier
;
926 /** For precision statements, this is the given precision; otherwise none. */
927 unsigned default_precision
:2;
931 class ast_fully_specified_type
: public ast_node
{
933 virtual void print(void) const;
934 bool has_qualifiers(_mesa_glsl_parse_state
*state
) const;
936 ast_fully_specified_type() : qualifier(), specifier(NULL
)
940 const struct glsl_type
*glsl_type(const char **name
,
941 struct _mesa_glsl_parse_state
*state
)
944 ast_type_qualifier qualifier
;
945 ast_type_specifier
*specifier
;
949 class ast_declarator_list
: public ast_node
{
951 ast_declarator_list(ast_fully_specified_type
*);
952 virtual void print(void) const;
954 virtual ir_rvalue
*hir(exec_list
*instructions
,
955 struct _mesa_glsl_parse_state
*state
);
957 ast_fully_specified_type
*type
;
958 /** List of 'ast_declaration *' */
959 exec_list declarations
;
962 * Flags for redeclarations. In these cases, no type is specified, to
963 * `type` is allowed to be NULL. In all other cases, this would be an error.
965 int invariant
; /** < `invariant` redeclaration */
966 int precise
; /** < `precise` redeclaration */
970 class ast_parameter_declarator
: public ast_node
{
972 ast_parameter_declarator() :
975 array_specifier(NULL
),
976 formal_parameter(false),
982 virtual void print(void) const;
984 virtual ir_rvalue
*hir(exec_list
*instructions
,
985 struct _mesa_glsl_parse_state
*state
);
987 ast_fully_specified_type
*type
;
988 const char *identifier
;
989 ast_array_specifier
*array_specifier
;
991 static void parameters_to_hir(exec_list
*ast_parameters
,
992 bool formal
, exec_list
*ir_parameters
,
993 struct _mesa_glsl_parse_state
*state
);
996 /** Is this parameter declaration part of a formal parameter list? */
997 bool formal_parameter
;
1000 * Is this parameter 'void' type?
1002 * This field is set by \c ::hir.
1008 class ast_function
: public ast_node
{
1012 virtual void print(void) const;
1014 virtual ir_rvalue
*hir(exec_list
*instructions
,
1015 struct _mesa_glsl_parse_state
*state
);
1017 ast_fully_specified_type
*return_type
;
1018 const char *identifier
;
1020 exec_list parameters
;
1024 * Is this prototype part of the function definition?
1026 * Used by ast_function_definition::hir to process the parameters, etc.
1034 * Function signature corresponding to this function prototype instance
1036 * Used by ast_function_definition::hir to process the parameters, etc.
1041 class ir_function_signature
*signature
;
1043 friend class ast_function_definition
;
1047 class ast_expression_statement
: public ast_node
{
1049 ast_expression_statement(ast_expression
*);
1050 virtual void print(void) const;
1052 virtual ir_rvalue
*hir(exec_list
*instructions
,
1053 struct _mesa_glsl_parse_state
*state
);
1055 ast_expression
*expression
;
1059 class ast_case_label
: public ast_node
{
1061 ast_case_label(ast_expression
*test_value
);
1062 virtual void print(void) const;
1064 virtual ir_rvalue
*hir(exec_list
*instructions
,
1065 struct _mesa_glsl_parse_state
*state
);
1068 * An test value of NULL means 'default'.
1070 ast_expression
*test_value
;
1074 class ast_case_label_list
: public ast_node
{
1076 ast_case_label_list(void);
1077 virtual void print(void) const;
1079 virtual ir_rvalue
*hir(exec_list
*instructions
,
1080 struct _mesa_glsl_parse_state
*state
);
1083 * A list of case labels.
1089 class ast_case_statement
: public ast_node
{
1091 ast_case_statement(ast_case_label_list
*labels
);
1092 virtual void print(void) const;
1094 virtual ir_rvalue
*hir(exec_list
*instructions
,
1095 struct _mesa_glsl_parse_state
*state
);
1097 ast_case_label_list
*labels
;
1100 * A list of statements.
1106 class ast_case_statement_list
: public ast_node
{
1108 ast_case_statement_list(void);
1109 virtual void print(void) const;
1111 virtual ir_rvalue
*hir(exec_list
*instructions
,
1112 struct _mesa_glsl_parse_state
*state
);
1121 class ast_switch_body
: public ast_node
{
1123 ast_switch_body(ast_case_statement_list
*stmts
);
1124 virtual void print(void) const;
1126 virtual ir_rvalue
*hir(exec_list
*instructions
,
1127 struct _mesa_glsl_parse_state
*state
);
1129 ast_case_statement_list
*stmts
;
1133 class ast_selection_statement
: public ast_node
{
1135 ast_selection_statement(ast_expression
*condition
,
1136 ast_node
*then_statement
,
1137 ast_node
*else_statement
);
1138 virtual void print(void) const;
1140 virtual ir_rvalue
*hir(exec_list
*instructions
,
1141 struct _mesa_glsl_parse_state
*state
);
1143 ast_expression
*condition
;
1144 ast_node
*then_statement
;
1145 ast_node
*else_statement
;
1149 class ast_switch_statement
: public ast_node
{
1151 ast_switch_statement(ast_expression
*test_expression
,
1153 virtual void print(void) const;
1155 virtual ir_rvalue
*hir(exec_list
*instructions
,
1156 struct _mesa_glsl_parse_state
*state
);
1158 ast_expression
*test_expression
;
1162 void test_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1165 class ast_iteration_statement
: public ast_node
{
1167 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
1168 ast_expression
*rest_expression
, ast_node
*body
);
1170 virtual void print(void) const;
1172 virtual ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1174 enum ast_iteration_modes
{
1181 ast_node
*init_statement
;
1182 ast_node
*condition
;
1183 ast_expression
*rest_expression
;
1188 * Generate IR from the condition of a loop
1190 * This is factored out of ::hir because some loops have the condition
1191 * test at the top (for and while), and others have it at the end (do-while).
1193 void condition_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1197 class ast_jump_statement
: public ast_node
{
1199 ast_jump_statement(int mode
, ast_expression
*return_value
);
1200 virtual void print(void) const;
1202 virtual ir_rvalue
*hir(exec_list
*instructions
,
1203 struct _mesa_glsl_parse_state
*state
);
1205 enum ast_jump_modes
{
1212 ast_expression
*opt_return_value
;
1216 class ast_demote_statement
: public ast_node
{
1218 ast_demote_statement(void) {}
1219 virtual void print(void) const;
1221 virtual ir_rvalue
*hir(exec_list
*instructions
,
1222 struct _mesa_glsl_parse_state
*state
);
1226 class ast_function_definition
: public ast_node
{
1228 ast_function_definition() : prototype(NULL
), body(NULL
)
1232 virtual void print(void) const;
1234 virtual ir_rvalue
*hir(exec_list
*instructions
,
1235 struct _mesa_glsl_parse_state
*state
);
1237 ast_function
*prototype
;
1238 ast_compound_statement
*body
;
1241 class ast_interface_block
: public ast_node
{
1243 ast_interface_block(const char *instance_name
,
1244 ast_array_specifier
*array_specifier
)
1245 : block_name(NULL
), instance_name(instance_name
),
1246 array_specifier(array_specifier
)
1250 virtual ir_rvalue
*hir(exec_list
*instructions
,
1251 struct _mesa_glsl_parse_state
*state
);
1253 ast_type_qualifier default_layout
;
1254 ast_type_qualifier layout
;
1255 const char *block_name
;
1258 * Declared name of the block instance, if specified.
1260 * If the block does not have an instance name, this field will be
1263 const char *instance_name
;
1265 /** List of ast_declarator_list * */
1266 exec_list declarations
;
1269 * Declared array size of the block instance
1271 * If the block is not declared as an array or if the block instance array
1272 * is unsized, this field will be \c NULL.
1274 ast_array_specifier
*array_specifier
;
1279 * AST node representing a declaration of the output layout for tessellation
1282 class ast_tcs_output_layout
: public ast_node
1285 ast_tcs_output_layout(const struct YYLTYPE
&locp
)
1290 virtual ir_rvalue
*hir(exec_list
*instructions
,
1291 struct _mesa_glsl_parse_state
*state
);
1296 * AST node representing a declaration of the input layout for geometry
1299 class ast_gs_input_layout
: public ast_node
1302 ast_gs_input_layout(const struct YYLTYPE
&locp
, GLenum prim_type
)
1303 : prim_type(prim_type
)
1308 virtual ir_rvalue
*hir(exec_list
*instructions
,
1309 struct _mesa_glsl_parse_state
*state
);
1312 const GLenum prim_type
;
1317 * AST node representing a decalaration of the input layout for compute
1320 class ast_cs_input_layout
: public ast_node
1323 ast_cs_input_layout(const struct YYLTYPE
&locp
,
1324 ast_layout_expression
*const *local_size
)
1326 for (int i
= 0; i
< 3; i
++) {
1327 this->local_size
[i
] = local_size
[i
];
1332 virtual ir_rvalue
*hir(exec_list
*instructions
,
1333 struct _mesa_glsl_parse_state
*state
);
1336 ast_layout_expression
*local_size
[3];
1339 class ast_warnings_toggle
: public ast_node
{
1341 ast_warnings_toggle(bool _enable
)
1347 virtual ir_rvalue
*hir(exec_list
*instructions
,
1348 struct _mesa_glsl_parse_state
*state
);
1356 _mesa_ast_to_hir(exec_list
*instructions
, struct _mesa_glsl_parse_state
*state
);
1359 _mesa_ast_field_selection_to_hir(const ast_expression
*expr
,
1360 exec_list
*instructions
,
1361 struct _mesa_glsl_parse_state
*state
);
1364 _mesa_ast_array_index_to_hir(void *mem_ctx
,
1365 struct _mesa_glsl_parse_state
*state
,
1366 ir_rvalue
*array
, ir_rvalue
*idx
,
1367 YYLTYPE
&loc
, YYLTYPE
&idx_loc
);
1370 _mesa_ast_set_aggregate_type(const glsl_type
*type
,
1371 ast_expression
*expr
);
1374 emit_function(_mesa_glsl_parse_state
*state
, ir_function
*f
);
1377 check_builtin_array_max_size(const char *name
, unsigned size
,
1378 YYLTYPE loc
, struct _mesa_glsl_parse_state
*state
);
1380 extern void _mesa_ast_process_interface_block(YYLTYPE
*locp
,
1381 _mesa_glsl_parse_state
*state
,
1382 ast_interface_block
*const block
,
1383 const struct ast_type_qualifier
&q
);
1386 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
1388 const char *qual_indentifier
,
1389 ast_expression
*const_expression
,