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
.path
= this->location
.path
;
81 locp
.source
= this->location
.source
;
82 locp
.first_line
= this->location
.first_line
;
83 locp
.first_column
= this->location
.first_column
;
84 locp
.last_line
= this->location
.last_line
;
85 locp
.last_column
= this->location
.last_column
;
91 * Set the source location of an AST node from a parser location
93 * \sa ast_node::get_location
95 void set_location(const struct YYLTYPE
&locp
)
97 this->location
.path
= locp
.path
;
98 this->location
.source
= locp
.source
;
99 this->location
.first_line
= locp
.first_line
;
100 this->location
.first_column
= locp
.first_column
;
101 this->location
.last_line
= locp
.last_line
;
102 this->location
.last_column
= locp
.last_column
;
106 * Set the source location range of an AST node using two location nodes
108 * \sa ast_node::set_location
110 void set_location_range(const struct YYLTYPE
&begin
, const struct YYLTYPE
&end
)
112 this->location
.path
= begin
.path
;
113 this->location
.source
= begin
.source
;
114 this->location
.first_line
= begin
.first_line
;
115 this->location
.last_line
= end
.last_line
;
116 this->location
.first_column
= begin
.first_column
;
117 this->location
.last_column
= end
.last_column
;
121 * Source location of the AST node.
124 char *path
; /**< GLSL shader include path. */
125 unsigned source
; /**< GLSL source number. */
126 unsigned first_line
; /**< First line number within the source string. */
127 unsigned first_column
; /**< First column in the first line. */
128 unsigned last_line
; /**< Last line number within the source string. */
129 unsigned last_column
; /**< Last column in the last line. */
134 virtual void set_is_lhs(bool);
138 * The only constructor is protected so that only derived class objects can
146 * Operators for AST expression nodes.
150 ast_plus
, /**< Unary + operator. */
193 ast_unsized_array_dim
,
210 * Number of possible operators for an ast_expression
212 * This is done as a define instead of as an additional value in the enum so
213 * that the compiler won't generate spurious messages like "warning:
214 * enumeration value ‘ast_num_operators’ not handled in switch"
216 #define AST_NUM_OPERATORS (ast_aggregate + 1)
220 * Representation of any sort of expression.
222 class ast_expression
: public ast_node
{
224 ast_expression(int oper
, ast_expression
*,
225 ast_expression
*, ast_expression
*);
227 ast_expression(const char *identifier
) :
230 subexpressions
[0] = NULL
;
231 subexpressions
[1] = NULL
;
232 subexpressions
[2] = NULL
;
233 primary_expression
.identifier
= identifier
;
234 this->non_lvalue_description
= NULL
;
235 this->is_lhs
= false;
238 static const char *operator_string(enum ast_operators op
);
240 virtual ir_rvalue
*hir(exec_list
*instructions
,
241 struct _mesa_glsl_parse_state
*state
);
243 virtual void hir_no_rvalue(exec_list
*instructions
,
244 struct _mesa_glsl_parse_state
*state
);
246 virtual bool has_sequence_subexpression() const;
248 ir_rvalue
*do_hir(exec_list
*instructions
,
249 struct _mesa_glsl_parse_state
*state
,
252 virtual void print(void) const;
254 enum ast_operators oper
;
256 ast_expression
*subexpressions
[3];
259 const char *identifier
;
261 float float_constant
;
262 unsigned uint_constant
;
264 double double_constant
;
265 uint64_t uint64_constant
;
266 int64_t int64_constant
;
267 } primary_expression
;
271 * List of expressions for an \c ast_sequence or parameters for an
272 * \c ast_function_call
274 exec_list expressions
;
277 * For things that can't be l-values, this describes what it is.
279 * This text is used by the code that generates IR for assignments to
280 * detect and emit useful messages for assignments to some things that
281 * can't be l-values. For example, pre- or post-incerement expressions.
284 * This pointer may be \c NULL.
286 const char *non_lvalue_description
;
288 void set_is_lhs(bool new_value
);
294 class ast_expression_bin
: public ast_expression
{
296 ast_expression_bin(int oper
, ast_expression
*, ast_expression
*);
298 virtual void print(void) const;
302 * Subclass of expressions for function calls
304 class ast_function_expression
: public ast_expression
{
306 ast_function_expression(ast_expression
*callee
)
307 : ast_expression(ast_function_call
, callee
,
314 ast_function_expression(class ast_type_specifier
*type
)
315 : ast_expression(ast_function_call
, (ast_expression
*) type
,
322 bool is_constructor() const
327 virtual ir_rvalue
*hir(exec_list
*instructions
,
328 struct _mesa_glsl_parse_state
*state
);
330 virtual void hir_no_rvalue(exec_list
*instructions
,
331 struct _mesa_glsl_parse_state
*state
);
333 virtual bool has_sequence_subexpression() const;
337 * Is this function call actually a constructor?
341 handle_method(exec_list
*instructions
,
342 struct _mesa_glsl_parse_state
*state
);
345 class ast_subroutine_list
: public ast_node
348 virtual void print(void) const;
349 exec_list declarations
;
352 class ast_array_specifier
: public ast_node
{
354 ast_array_specifier(const struct YYLTYPE
&locp
, ast_expression
*dim
)
357 array_dimensions
.push_tail(&dim
->link
);
360 void add_dimension(ast_expression
*dim
)
362 array_dimensions
.push_tail(&dim
->link
);
365 bool is_single_dimension() const
367 return this->array_dimensions
.get_tail_raw()->prev
!= NULL
&&
368 this->array_dimensions
.get_tail_raw()->prev
->is_head_sentinel();
371 virtual void print(void) const;
373 /* This list contains objects of type ast_node containing the
374 * array dimensions in outermost-to-innermost order.
376 exec_list array_dimensions
;
379 class ast_layout_expression
: public ast_node
{
381 ast_layout_expression(const struct YYLTYPE
&locp
, ast_expression
*expr
)
384 layout_const_expressions
.push_tail(&expr
->link
);
387 bool process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
388 const char *qual_indentifier
,
389 unsigned *value
, bool can_be_zero
);
391 void merge_qualifier(ast_layout_expression
*l_expr
)
393 layout_const_expressions
.append_list(&l_expr
->layout_const_expressions
);
396 exec_list layout_const_expressions
;
400 * C-style aggregate initialization class
402 * Represents C-style initializers of vectors, matrices, arrays, and
403 * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to
404 * vec3 pos = vec3(1.0, 0.0, -1.0).
406 * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack.
408 * \sa _mesa_ast_set_aggregate_type
410 class ast_aggregate_initializer
: public ast_expression
{
412 ast_aggregate_initializer()
413 : ast_expression(ast_aggregate
, NULL
, NULL
, NULL
),
414 constructor_type(NULL
)
420 * glsl_type of the aggregate, which is inferred from the LHS of whatever
421 * the aggregate is being used to initialize. This can't be inferred at
422 * parse time (since the parser deals with ast_type_specifiers, not
423 * glsl_types), so the parser leaves it NULL. However, the ast-to-hir
424 * conversion code makes sure to fill it in with the appropriate type
425 * before hir() is called.
427 const glsl_type
*constructor_type
;
429 virtual ir_rvalue
*hir(exec_list
*instructions
,
430 struct _mesa_glsl_parse_state
*state
);
432 virtual void hir_no_rvalue(exec_list
*instructions
,
433 struct _mesa_glsl_parse_state
*state
);
437 class ast_compound_statement
: public ast_node
{
439 ast_compound_statement(int new_scope
, ast_node
*statements
);
440 virtual void print(void) const;
442 virtual ir_rvalue
*hir(exec_list
*instructions
,
443 struct _mesa_glsl_parse_state
*state
);
446 exec_list statements
;
449 class ast_declaration
: public ast_node
{
451 ast_declaration(const char *identifier
,
452 ast_array_specifier
*array_specifier
,
453 ast_expression
*initializer
);
454 virtual void print(void) const;
456 const char *identifier
;
458 ast_array_specifier
*array_specifier
;
460 ast_expression
*initializer
;
465 ast_precision_none
= 0, /**< Absence of precision qualifier. */
467 ast_precision_medium
,
472 ast_depth_none
= 0, /**< Absence of depth qualifier. */
479 struct ast_type_qualifier
{
480 DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier
);
481 /* Note: this bitset needs to have at least as many bits as the 'q'
482 * struct has flags, below. Previously, the size was 128 instead of 96.
483 * But an apparent bug in GCC 5.4.0 causes bad SSE code generation
484 * elsewhere, leading to a crash. 96 bits works around the issue.
485 * See https://bugs.freedesktop.org/show_bug.cgi?id=105497
487 DECLARE_BITSET_T(bitset_t
, 96);
491 unsigned invariant
:1;
494 unsigned attribute
:1;
503 unsigned shared_storage
:1;
506 unsigned noperspective
:1;
508 /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */
510 unsigned origin_upper_left
:1;
511 unsigned pixel_center_integer
:1;
515 * Flag set if GL_ARB_enhanced_layouts "align" layout qualifier is
518 unsigned explicit_align
:1;
521 * Flag set if GL_ARB_explicit_attrib_location "location" layout
524 unsigned explicit_location
:1;
526 * Flag set if GL_ARB_explicit_attrib_location "index" layout
529 unsigned explicit_index
:1;
532 * Flag set if GL_ARB_enhanced_layouts "component" layout
535 unsigned explicit_component
:1;
538 * Flag set if GL_ARB_shading_language_420pack "binding" layout
541 unsigned explicit_binding
:1;
544 * Flag set if GL_ARB_shader_atomic counter "offset" layout
547 unsigned explicit_offset
:1;
549 /** \name Layout qualifiers for GL_AMD_conservative_depth */
551 unsigned depth_type
:1;
554 /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
560 unsigned column_major
:1;
561 unsigned row_major
:1;
564 /** \name Layout qualifiers for GLSL 1.50 geometry shaders */
566 unsigned prim_type
:1;
567 unsigned max_vertices
:1;
571 * local_size_{x,y,z} flags for compute shaders. Bit 0 represents
572 * local_size_x, and so on.
574 unsigned local_size
:3;
576 /** \name Layout qualifiers for ARB_compute_variable_group_size. */
578 unsigned local_size_variable
:1;
581 /** \name Layout and memory qualifiers for ARB_shader_image_load_store. */
583 unsigned early_fragment_tests
:1;
584 unsigned explicit_image_format
:1;
586 unsigned _volatile
:1;
587 unsigned restrict_flag
:1;
588 unsigned read_only
:1; /**< "readonly" qualifier. */
589 unsigned write_only
:1; /**< "writeonly" qualifier. */
592 /** \name Layout qualifiers for GL_ARB_gpu_shader5 */
594 unsigned invocations
:1;
595 unsigned stream
:1; /**< Has stream value assigned */
596 unsigned explicit_stream
:1; /**< stream value assigned explicitly by shader code */
599 /** \name Layout qualifiers for GL_ARB_enhanced_layouts */
601 unsigned explicit_xfb_offset
:1; /**< xfb_offset value assigned explicitly by shader code */
602 unsigned xfb_buffer
:1; /**< Has xfb_buffer value assigned */
603 unsigned explicit_xfb_buffer
:1; /**< xfb_buffer value assigned explicitly by shader code */
604 unsigned xfb_stride
:1; /**< Is xfb_stride value yet to be merged with global values */
605 unsigned explicit_xfb_stride
:1; /**< xfb_stride value assigned explicitly by shader code */
608 /** \name Layout qualifiers for GL_ARB_tessellation_shader */
610 /* tess eval input layout */
611 /* gs prim_type reused for primitive mode */
612 unsigned vertex_spacing
:1;
614 unsigned point_mode
:1;
615 /* tess control output layout */
619 /** \name Qualifiers for GL_ARB_shader_subroutine */
621 unsigned subroutine
:1; /**< Is this marked 'subroutine' */
624 /** \name Qualifiers for GL_KHR_blend_equation_advanced */
626 unsigned blend_support
:1; /**< Are there any blend_support_ qualifiers */
630 * Flag set if GL_ARB_post_depth_coverage layout qualifier is used.
632 unsigned post_depth_coverage
:1;
635 * Flags for the layout qualifers added by ARB_fragment_shader_interlock
638 unsigned pixel_interlock_ordered
:1;
639 unsigned pixel_interlock_unordered
:1;
640 unsigned sample_interlock_ordered
:1;
641 unsigned sample_interlock_unordered
:1;
644 * Flag set if GL_INTEL_conservartive_rasterization layout qualifier
647 unsigned inner_coverage
:1;
649 /** \name Layout qualifiers for GL_ARB_bindless_texture */
651 unsigned bindless_sampler
:1;
652 unsigned bindless_image
:1;
653 unsigned bound_sampler
:1;
654 unsigned bound_image
:1;
657 /** \name Layout qualifiers for GL_EXT_shader_framebuffer_fetch_non_coherent */
659 unsigned non_coherent
:1;
662 /** \name Layout qualifiers for NV_compute_shader_derivatives */
664 unsigned derivative_group
:1;
668 * Flag set if GL_NV_viewport_array2 viewport_relative layout
671 unsigned viewport_relative
:1;
673 /** \brief Set of flags, accessed by name. */
676 /** \brief Set of flags, accessed as a bitmask. */
680 /** Precision of the type (highp/medium/lowp). */
681 unsigned precision
:2;
683 /** Type of layout qualifiers for GL_AMD_conservative_depth. */
684 unsigned depth_type
:3;
687 * Alignment specified via GL_ARB_enhanced_layouts "align" layout qualifier
689 ast_expression
*align
;
691 /** Geometry shader invocations for GL_ARB_gpu_shader5. */
692 ast_layout_expression
*invocations
;
695 * Location specified via GL_ARB_explicit_attrib_location layout
698 * This field is only valid if \c explicit_location is set.
700 ast_expression
*location
;
702 * Index specified via GL_ARB_explicit_attrib_location layout
705 * This field is only valid if \c explicit_index is set.
707 ast_expression
*index
;
710 * Component specified via GL_ARB_enhaced_layouts
713 * This field is only valid if \c explicit_component is set.
715 ast_expression
*component
;
717 /** Maximum output vertices in GLSL 1.50 geometry shaders. */
718 ast_layout_expression
*max_vertices
;
720 /** Stream in GLSL 1.50 geometry shaders. */
721 ast_expression
*stream
;
723 /** xfb_buffer specified via the GL_ARB_enhanced_layouts keyword. */
724 ast_expression
*xfb_buffer
;
726 /** xfb_stride specified via the GL_ARB_enhanced_layouts keyword. */
727 ast_expression
*xfb_stride
;
729 /** global xfb_stride values for each buffer */
730 ast_layout_expression
*out_xfb_stride
[MAX_FEEDBACK_BUFFERS
];
733 * Input or output primitive type in GLSL 1.50 geometry shaders
734 * and tessellation shaders.
739 * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword.
742 * This field is only valid if \c explicit_binding is set.
744 ast_expression
*binding
;
747 * Offset specified via GL_ARB_shader_atomic_counter's or
748 * GL_ARB_enhanced_layouts "offset" keyword, or by GL_ARB_enhanced_layouts
749 * "xfb_offset" keyword.
752 * This field is only valid if \c explicit_offset is set.
754 ast_expression
*offset
;
757 * Local size specified via GL_ARB_compute_shader's "local_size_{x,y,z}"
758 * layout qualifier. Element i of this array is only valid if
759 * flags.q.local_size & (1 << i) is set.
761 ast_layout_expression
*local_size
[3];
763 /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */
764 enum gl_tess_spacing vertex_spacing
;
766 /** Tessellation evaluation shader: vertex ordering (CW or CCW) */
769 /** Tessellation evaluation shader: point mode */
772 /** Tessellation control shader: number of output vertices */
773 ast_layout_expression
*vertices
;
776 * Image format specified with an ARB_shader_image_load_store
780 * This field is only valid if \c explicit_image_format is set.
782 enum pipe_format image_format
;
785 * Arrangement of invocations used to calculate derivatives in a compute
786 * shader. From NV_compute_shader_derivatives.
788 enum gl_derivative_group derivative_group
;
791 * Base type of the data read from or written to this image. Only
792 * the following enumerants are allowed: GLSL_TYPE_UINT,
793 * GLSL_TYPE_INT, GLSL_TYPE_FLOAT.
796 * This field is only valid if \c explicit_image_format is set.
798 glsl_base_type image_base_type
;
801 * Return true if and only if an interpolation qualifier is present.
803 bool has_interpolation() const;
806 * Return whether a layout qualifier is present.
808 bool has_layout() const;
811 * Return whether a storage qualifier is present.
813 bool has_storage() const;
816 * Return whether an auxiliary storage qualifier is present.
818 bool has_auxiliary_storage() const;
821 * Return true if and only if a memory qualifier is present.
823 bool has_memory() const;
826 * Return true if the qualifier is a subroutine declaration.
828 bool is_subroutine_decl() const;
830 bool merge_qualifier(YYLTYPE
*loc
,
831 _mesa_glsl_parse_state
*state
,
832 const ast_type_qualifier
&q
,
833 bool is_single_layout_merge
,
834 bool is_multiple_layouts_merge
= false);
837 * Validate current qualifier against the global out one.
839 bool validate_out_qualifier(YYLTYPE
*loc
,
840 _mesa_glsl_parse_state
*state
);
843 * Merge current qualifier into the global out one.
845 bool merge_into_out_qualifier(YYLTYPE
*loc
,
846 _mesa_glsl_parse_state
*state
,
850 * Validate current qualifier against the global in one.
852 bool validate_in_qualifier(YYLTYPE
*loc
,
853 _mesa_glsl_parse_state
*state
);
856 * Merge current qualifier into the global in one.
858 bool merge_into_in_qualifier(YYLTYPE
*loc
,
859 _mesa_glsl_parse_state
*state
,
863 * Push pending layout qualifiers to the global values.
865 bool push_to_global(YYLTYPE
*loc
,
866 _mesa_glsl_parse_state
*state
);
868 bool validate_flags(YYLTYPE
*loc
,
869 _mesa_glsl_parse_state
*state
,
870 const ast_type_qualifier
&allowed_flags
,
871 const char *message
, const char *name
);
873 ast_subroutine_list
*subroutine_list
;
876 class ast_declarator_list
;
878 class ast_struct_specifier
: public ast_node
{
880 ast_struct_specifier(const char *identifier
,
881 ast_declarator_list
*declarator_list
);
882 virtual void print(void) const;
884 virtual ir_rvalue
*hir(exec_list
*instructions
,
885 struct _mesa_glsl_parse_state
*state
);
888 ast_type_qualifier
*layout
;
889 /* List of ast_declarator_list * */
890 exec_list declarations
;
892 const glsl_type
*type
;
897 class ast_type_specifier
: public ast_node
{
899 /** Construct a type specifier from a type name */
900 ast_type_specifier(const char *name
)
901 : type(NULL
), type_name(name
), structure(NULL
), array_specifier(NULL
),
902 default_precision(ast_precision_none
)
907 /** Construct a type specifier from a structure definition */
908 ast_type_specifier(ast_struct_specifier
*s
)
909 : type(NULL
), type_name(s
->name
), structure(s
), array_specifier(NULL
),
910 default_precision(ast_precision_none
)
915 ast_type_specifier(const glsl_type
*t
)
916 : type(t
), type_name(t
->name
), structure(NULL
), array_specifier(NULL
),
917 default_precision(ast_precision_none
)
922 const struct glsl_type
*glsl_type(const char **name
,
923 struct _mesa_glsl_parse_state
*state
)
926 virtual void print(void) const;
928 ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
930 const struct glsl_type
*type
;
931 const char *type_name
;
932 ast_struct_specifier
*structure
;
934 ast_array_specifier
*array_specifier
;
936 /** For precision statements, this is the given precision; otherwise none. */
937 unsigned default_precision
:2;
941 class ast_fully_specified_type
: public ast_node
{
943 virtual void print(void) const;
944 bool has_qualifiers(_mesa_glsl_parse_state
*state
) const;
946 ast_fully_specified_type() : qualifier(), specifier(NULL
)
950 const struct glsl_type
*glsl_type(const char **name
,
951 struct _mesa_glsl_parse_state
*state
)
954 ast_type_qualifier qualifier
;
955 ast_type_specifier
*specifier
;
959 class ast_declarator_list
: public ast_node
{
961 ast_declarator_list(ast_fully_specified_type
*);
962 virtual void print(void) const;
964 virtual ir_rvalue
*hir(exec_list
*instructions
,
965 struct _mesa_glsl_parse_state
*state
);
967 ast_fully_specified_type
*type
;
968 /** List of 'ast_declaration *' */
969 exec_list declarations
;
972 * Flags for redeclarations. In these cases, no type is specified, to
973 * `type` is allowed to be NULL. In all other cases, this would be an error.
975 int invariant
; /** < `invariant` redeclaration */
976 int precise
; /** < `precise` redeclaration */
980 class ast_parameter_declarator
: public ast_node
{
982 ast_parameter_declarator() :
985 array_specifier(NULL
),
986 formal_parameter(false),
992 virtual void print(void) const;
994 virtual ir_rvalue
*hir(exec_list
*instructions
,
995 struct _mesa_glsl_parse_state
*state
);
997 ast_fully_specified_type
*type
;
998 const char *identifier
;
999 ast_array_specifier
*array_specifier
;
1001 static void parameters_to_hir(exec_list
*ast_parameters
,
1002 bool formal
, exec_list
*ir_parameters
,
1003 struct _mesa_glsl_parse_state
*state
);
1006 /** Is this parameter declaration part of a formal parameter list? */
1007 bool formal_parameter
;
1010 * Is this parameter 'void' type?
1012 * This field is set by \c ::hir.
1018 class ast_function
: public ast_node
{
1022 virtual void print(void) const;
1024 virtual ir_rvalue
*hir(exec_list
*instructions
,
1025 struct _mesa_glsl_parse_state
*state
);
1027 ast_fully_specified_type
*return_type
;
1028 const char *identifier
;
1030 exec_list parameters
;
1034 * Is this prototype part of the function definition?
1036 * Used by ast_function_definition::hir to process the parameters, etc.
1044 * Function signature corresponding to this function prototype instance
1046 * Used by ast_function_definition::hir to process the parameters, etc.
1051 class ir_function_signature
*signature
;
1053 friend class ast_function_definition
;
1057 class ast_expression_statement
: public ast_node
{
1059 ast_expression_statement(ast_expression
*);
1060 virtual void print(void) const;
1062 virtual ir_rvalue
*hir(exec_list
*instructions
,
1063 struct _mesa_glsl_parse_state
*state
);
1065 ast_expression
*expression
;
1069 class ast_case_label
: public ast_node
{
1071 ast_case_label(ast_expression
*test_value
);
1072 virtual void print(void) const;
1074 virtual ir_rvalue
*hir(exec_list
*instructions
,
1075 struct _mesa_glsl_parse_state
*state
);
1078 * An test value of NULL means 'default'.
1080 ast_expression
*test_value
;
1084 class ast_case_label_list
: public ast_node
{
1086 ast_case_label_list(void);
1087 virtual void print(void) const;
1089 virtual ir_rvalue
*hir(exec_list
*instructions
,
1090 struct _mesa_glsl_parse_state
*state
);
1093 * A list of case labels.
1099 class ast_case_statement
: public ast_node
{
1101 ast_case_statement(ast_case_label_list
*labels
);
1102 virtual void print(void) const;
1104 virtual ir_rvalue
*hir(exec_list
*instructions
,
1105 struct _mesa_glsl_parse_state
*state
);
1107 ast_case_label_list
*labels
;
1110 * A list of statements.
1116 class ast_case_statement_list
: public ast_node
{
1118 ast_case_statement_list(void);
1119 virtual void print(void) const;
1121 virtual ir_rvalue
*hir(exec_list
*instructions
,
1122 struct _mesa_glsl_parse_state
*state
);
1131 class ast_switch_body
: public ast_node
{
1133 ast_switch_body(ast_case_statement_list
*stmts
);
1134 virtual void print(void) const;
1136 virtual ir_rvalue
*hir(exec_list
*instructions
,
1137 struct _mesa_glsl_parse_state
*state
);
1139 ast_case_statement_list
*stmts
;
1143 class ast_selection_statement
: public ast_node
{
1145 ast_selection_statement(ast_expression
*condition
,
1146 ast_node
*then_statement
,
1147 ast_node
*else_statement
);
1148 virtual void print(void) const;
1150 virtual ir_rvalue
*hir(exec_list
*instructions
,
1151 struct _mesa_glsl_parse_state
*state
);
1153 ast_expression
*condition
;
1154 ast_node
*then_statement
;
1155 ast_node
*else_statement
;
1159 class ast_switch_statement
: public ast_node
{
1161 ast_switch_statement(ast_expression
*test_expression
,
1163 virtual void print(void) const;
1165 virtual ir_rvalue
*hir(exec_list
*instructions
,
1166 struct _mesa_glsl_parse_state
*state
);
1168 ast_expression
*test_expression
;
1172 void test_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1175 class ast_iteration_statement
: public ast_node
{
1177 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
1178 ast_expression
*rest_expression
, ast_node
*body
);
1180 virtual void print(void) const;
1182 virtual ir_rvalue
*hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1184 enum ast_iteration_modes
{
1191 ast_node
*init_statement
;
1192 ast_node
*condition
;
1193 ast_expression
*rest_expression
;
1198 * Generate IR from the condition of a loop
1200 * This is factored out of ::hir because some loops have the condition
1201 * test at the top (for and while), and others have it at the end (do-while).
1203 void condition_to_hir(exec_list
*, struct _mesa_glsl_parse_state
*);
1207 class ast_jump_statement
: public ast_node
{
1209 ast_jump_statement(int mode
, ast_expression
*return_value
);
1210 virtual void print(void) const;
1212 virtual ir_rvalue
*hir(exec_list
*instructions
,
1213 struct _mesa_glsl_parse_state
*state
);
1215 enum ast_jump_modes
{
1222 ast_expression
*opt_return_value
;
1226 class ast_demote_statement
: public ast_node
{
1228 ast_demote_statement(void) {}
1229 virtual void print(void) const;
1231 virtual ir_rvalue
*hir(exec_list
*instructions
,
1232 struct _mesa_glsl_parse_state
*state
);
1236 class ast_function_definition
: public ast_node
{
1238 ast_function_definition() : prototype(NULL
), body(NULL
)
1242 virtual void print(void) const;
1244 virtual ir_rvalue
*hir(exec_list
*instructions
,
1245 struct _mesa_glsl_parse_state
*state
);
1247 ast_function
*prototype
;
1248 ast_compound_statement
*body
;
1251 class ast_interface_block
: public ast_node
{
1253 ast_interface_block(const char *instance_name
,
1254 ast_array_specifier
*array_specifier
)
1255 : block_name(NULL
), instance_name(instance_name
),
1256 array_specifier(array_specifier
)
1260 virtual ir_rvalue
*hir(exec_list
*instructions
,
1261 struct _mesa_glsl_parse_state
*state
);
1263 ast_type_qualifier default_layout
;
1264 ast_type_qualifier layout
;
1265 const char *block_name
;
1268 * Declared name of the block instance, if specified.
1270 * If the block does not have an instance name, this field will be
1273 const char *instance_name
;
1275 /** List of ast_declarator_list * */
1276 exec_list declarations
;
1279 * Declared array size of the block instance
1281 * If the block is not declared as an array or if the block instance array
1282 * is unsized, this field will be \c NULL.
1284 ast_array_specifier
*array_specifier
;
1289 * AST node representing a declaration of the output layout for tessellation
1292 class ast_tcs_output_layout
: public ast_node
1295 ast_tcs_output_layout(const struct YYLTYPE
&locp
)
1300 virtual ir_rvalue
*hir(exec_list
*instructions
,
1301 struct _mesa_glsl_parse_state
*state
);
1306 * AST node representing a declaration of the input layout for geometry
1309 class ast_gs_input_layout
: public ast_node
1312 ast_gs_input_layout(const struct YYLTYPE
&locp
, GLenum prim_type
)
1313 : prim_type(prim_type
)
1318 virtual ir_rvalue
*hir(exec_list
*instructions
,
1319 struct _mesa_glsl_parse_state
*state
);
1322 const GLenum prim_type
;
1327 * AST node representing a decalaration of the input layout for compute
1330 class ast_cs_input_layout
: public ast_node
1333 ast_cs_input_layout(const struct YYLTYPE
&locp
,
1334 ast_layout_expression
*const *local_size
)
1336 for (int i
= 0; i
< 3; i
++) {
1337 this->local_size
[i
] = local_size
[i
];
1342 virtual ir_rvalue
*hir(exec_list
*instructions
,
1343 struct _mesa_glsl_parse_state
*state
);
1346 ast_layout_expression
*local_size
[3];
1349 class ast_warnings_toggle
: public ast_node
{
1351 ast_warnings_toggle(bool _enable
)
1357 virtual ir_rvalue
*hir(exec_list
*instructions
,
1358 struct _mesa_glsl_parse_state
*state
);
1366 _mesa_ast_to_hir(exec_list
*instructions
, struct _mesa_glsl_parse_state
*state
);
1369 _mesa_ast_field_selection_to_hir(const ast_expression
*expr
,
1370 exec_list
*instructions
,
1371 struct _mesa_glsl_parse_state
*state
);
1374 _mesa_ast_array_index_to_hir(void *mem_ctx
,
1375 struct _mesa_glsl_parse_state
*state
,
1376 ir_rvalue
*array
, ir_rvalue
*idx
,
1377 YYLTYPE
&loc
, YYLTYPE
&idx_loc
);
1380 _mesa_ast_set_aggregate_type(const glsl_type
*type
,
1381 ast_expression
*expr
);
1384 emit_function(_mesa_glsl_parse_state
*state
, ir_function
*f
);
1387 check_builtin_array_max_size(const char *name
, unsigned size
,
1388 YYLTYPE loc
, struct _mesa_glsl_parse_state
*state
);
1390 extern void _mesa_ast_process_interface_block(YYLTYPE
*locp
,
1391 _mesa_glsl_parse_state
*state
,
1392 ast_interface_block
*const block
,
1393 const struct ast_type_qualifier
&q
);
1396 process_qualifier_constant(struct _mesa_glsl_parse_state
*state
,
1398 const char *qual_indentifier
,
1399 ast_expression
*const_expression
,