i965/nir: Validate that NIR passes call nir_metadata_preserve().
[mesa.git] / src / glsl / ast.h
1 /* -*- c++ -*- */
2 /*
3 * Copyright © 2009 Intel Corporation
4 *
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:
11 *
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
14 * Software.
15 *
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.
23 */
24
25 #pragma once
26 #ifndef AST_H
27 #define AST_H
28
29 #include "list.h"
30 #include "glsl_parser_extras.h"
31
32 struct _mesa_glsl_parse_state;
33
34 struct YYLTYPE;
35
36 /**
37 * \defgroup AST Abstract syntax tree node definitions
38 *
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.
44 *
45 *@{
46 */
47 /**
48 * Base class of all abstract syntax tree nodes
49 */
50 class ast_node {
51 public:
52 DECLARE_RALLOC_CXX_OPERATORS(ast_node);
53
54 /**
55 * Print an AST node in something approximating the original GLSL code
56 */
57 virtual void print(void) const;
58
59 /**
60 * Convert the AST node to the high-level intermediate representation
61 */
62 virtual ir_rvalue *hir(exec_list *instructions,
63 struct _mesa_glsl_parse_state *state);
64
65 virtual bool has_sequence_subexpression() const;
66
67 /**
68 * Retrieve the source location of an AST node
69 *
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.
72 *
73 * \sa _mesa_glsl_error, ast_node::set_location
74 */
75 struct YYLTYPE get_location(void) const
76 {
77 struct YYLTYPE locp;
78
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;
84
85 return locp;
86 }
87
88 /**
89 * Set the source location of an AST node from a parser location
90 *
91 * \sa ast_node::get_location
92 */
93 void set_location(const struct YYLTYPE &locp)
94 {
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;
100 }
101
102 /**
103 * Set the source location range of an AST node using two location nodes
104 *
105 * \sa ast_node::set_location
106 */
107 void set_location_range(const struct YYLTYPE &begin, const struct YYLTYPE &end)
108 {
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;
114 }
115
116 /**
117 * Source location of the AST node.
118 */
119 struct {
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. */
125 } location;
126
127 exec_node link;
128
129 protected:
130 /**
131 * The only constructor is protected so that only derived class objects can
132 * be created.
133 */
134 ast_node(void);
135 };
136
137
138 /**
139 * Operators for AST expression nodes.
140 */
141 enum ast_operators {
142 ast_assign,
143 ast_plus, /**< Unary + operator. */
144 ast_neg,
145 ast_add,
146 ast_sub,
147 ast_mul,
148 ast_div,
149 ast_mod,
150 ast_lshift,
151 ast_rshift,
152 ast_less,
153 ast_greater,
154 ast_lequal,
155 ast_gequal,
156 ast_equal,
157 ast_nequal,
158 ast_bit_and,
159 ast_bit_xor,
160 ast_bit_or,
161 ast_bit_not,
162 ast_logic_and,
163 ast_logic_xor,
164 ast_logic_or,
165 ast_logic_not,
166
167 ast_mul_assign,
168 ast_div_assign,
169 ast_mod_assign,
170 ast_add_assign,
171 ast_sub_assign,
172 ast_ls_assign,
173 ast_rs_assign,
174 ast_and_assign,
175 ast_xor_assign,
176 ast_or_assign,
177
178 ast_conditional,
179
180 ast_pre_inc,
181 ast_pre_dec,
182 ast_post_inc,
183 ast_post_dec,
184 ast_field_selection,
185 ast_array_index,
186 ast_unsized_array_dim,
187
188 ast_function_call,
189
190 ast_identifier,
191 ast_int_constant,
192 ast_uint_constant,
193 ast_float_constant,
194 ast_bool_constant,
195 ast_double_constant,
196
197 ast_sequence,
198 ast_aggregate
199 };
200
201 /**
202 * Representation of any sort of expression.
203 */
204 class ast_expression : public ast_node {
205 public:
206 ast_expression(int oper, ast_expression *,
207 ast_expression *, ast_expression *);
208
209 ast_expression(const char *identifier) :
210 oper(ast_identifier)
211 {
212 subexpressions[0] = NULL;
213 subexpressions[1] = NULL;
214 subexpressions[2] = NULL;
215 primary_expression.identifier = identifier;
216 this->non_lvalue_description = NULL;
217 }
218
219 static const char *operator_string(enum ast_operators op);
220
221 virtual ir_rvalue *hir(exec_list *instructions,
222 struct _mesa_glsl_parse_state *state);
223
224 virtual void hir_no_rvalue(exec_list *instructions,
225 struct _mesa_glsl_parse_state *state);
226
227 virtual bool has_sequence_subexpression() const;
228
229 ir_rvalue *do_hir(exec_list *instructions,
230 struct _mesa_glsl_parse_state *state,
231 bool needs_rvalue);
232
233 virtual void print(void) const;
234
235 enum ast_operators oper;
236
237 ast_expression *subexpressions[3];
238
239 union {
240 const char *identifier;
241 int int_constant;
242 float float_constant;
243 unsigned uint_constant;
244 int bool_constant;
245 double double_constant;
246 } primary_expression;
247
248
249 /**
250 * List of expressions for an \c ast_sequence or parameters for an
251 * \c ast_function_call
252 */
253 exec_list expressions;
254
255 /**
256 * For things that can't be l-values, this describes what it is.
257 *
258 * This text is used by the code that generates IR for assignments to
259 * detect and emit useful messages for assignments to some things that
260 * can't be l-values. For example, pre- or post-incerement expressions.
261 *
262 * \note
263 * This pointer may be \c NULL.
264 */
265 const char *non_lvalue_description;
266 };
267
268 class ast_expression_bin : public ast_expression {
269 public:
270 ast_expression_bin(int oper, ast_expression *, ast_expression *);
271
272 virtual void print(void) const;
273 };
274
275 /**
276 * Subclass of expressions for function calls
277 */
278 class ast_function_expression : public ast_expression {
279 public:
280 ast_function_expression(ast_expression *callee)
281 : ast_expression(ast_function_call, callee,
282 NULL, NULL),
283 cons(false)
284 {
285 /* empty */
286 }
287
288 ast_function_expression(class ast_type_specifier *type)
289 : ast_expression(ast_function_call, (ast_expression *) type,
290 NULL, NULL),
291 cons(true)
292 {
293 /* empty */
294 }
295
296 bool is_constructor() const
297 {
298 return cons;
299 }
300
301 virtual ir_rvalue *hir(exec_list *instructions,
302 struct _mesa_glsl_parse_state *state);
303
304 virtual void hir_no_rvalue(exec_list *instructions,
305 struct _mesa_glsl_parse_state *state);
306
307 virtual bool has_sequence_subexpression() const;
308
309 private:
310 /**
311 * Is this function call actually a constructor?
312 */
313 bool cons;
314 ir_rvalue *
315 handle_method(exec_list *instructions,
316 struct _mesa_glsl_parse_state *state);
317 };
318
319 class ast_subroutine_list : public ast_node
320 {
321 public:
322 virtual void print(void) const;
323 exec_list declarations;
324 };
325
326 class ast_array_specifier : public ast_node {
327 public:
328 ast_array_specifier(const struct YYLTYPE &locp, ast_expression *dim)
329 {
330 set_location(locp);
331 array_dimensions.push_tail(&dim->link);
332 }
333
334 void add_dimension(ast_expression *dim)
335 {
336 array_dimensions.push_tail(&dim->link);
337 }
338
339 const bool is_single_dimension()
340 {
341 return this->array_dimensions.tail_pred->prev != NULL &&
342 this->array_dimensions.tail_pred->prev->is_head_sentinel();
343 }
344
345 virtual void print(void) const;
346
347 /* This list contains objects of type ast_node containing the
348 * array dimensions in outermost-to-innermost order.
349 */
350 exec_list array_dimensions;
351 };
352
353 /**
354 * C-style aggregate initialization class
355 *
356 * Represents C-style initializers of vectors, matrices, arrays, and
357 * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to
358 * vec3 pos = vec3(1.0, 0.0, -1.0).
359 *
360 * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack.
361 *
362 * \sa _mesa_ast_set_aggregate_type
363 */
364 class ast_aggregate_initializer : public ast_expression {
365 public:
366 ast_aggregate_initializer()
367 : ast_expression(ast_aggregate, NULL, NULL, NULL),
368 constructor_type(NULL)
369 {
370 /* empty */
371 }
372
373 /**
374 * glsl_type of the aggregate, which is inferred from the LHS of whatever
375 * the aggregate is being used to initialize. This can't be inferred at
376 * parse time (since the parser deals with ast_type_specifiers, not
377 * glsl_types), so the parser leaves it NULL. However, the ast-to-hir
378 * conversion code makes sure to fill it in with the appropriate type
379 * before hir() is called.
380 */
381 const glsl_type *constructor_type;
382
383 virtual ir_rvalue *hir(exec_list *instructions,
384 struct _mesa_glsl_parse_state *state);
385
386 virtual void hir_no_rvalue(exec_list *instructions,
387 struct _mesa_glsl_parse_state *state);
388 };
389
390 /**
391 * Number of possible operators for an ast_expression
392 *
393 * This is done as a define instead of as an additional value in the enum so
394 * that the compiler won't generate spurious messages like "warning:
395 * enumeration value ‘ast_num_operators’ not handled in switch"
396 */
397 #define AST_NUM_OPERATORS (ast_sequence + 1)
398
399
400 class ast_compound_statement : public ast_node {
401 public:
402 ast_compound_statement(int new_scope, ast_node *statements);
403 virtual void print(void) const;
404
405 virtual ir_rvalue *hir(exec_list *instructions,
406 struct _mesa_glsl_parse_state *state);
407
408 int new_scope;
409 exec_list statements;
410 };
411
412 class ast_declaration : public ast_node {
413 public:
414 ast_declaration(const char *identifier,
415 ast_array_specifier *array_specifier,
416 ast_expression *initializer);
417 virtual void print(void) const;
418
419 const char *identifier;
420
421 ast_array_specifier *array_specifier;
422
423 ast_expression *initializer;
424 };
425
426
427 enum {
428 ast_precision_none = 0, /**< Absence of precision qualifier. */
429 ast_precision_high,
430 ast_precision_medium,
431 ast_precision_low
432 };
433
434 struct ast_type_qualifier {
435 DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier);
436
437 union {
438 struct {
439 unsigned invariant:1;
440 unsigned precise:1;
441 unsigned constant:1;
442 unsigned attribute:1;
443 unsigned varying:1;
444 unsigned in:1;
445 unsigned out:1;
446 unsigned centroid:1;
447 unsigned sample:1;
448 unsigned patch:1;
449 unsigned uniform:1;
450 unsigned buffer:1;
451 unsigned shared_storage:1;
452 unsigned smooth:1;
453 unsigned flat:1;
454 unsigned noperspective:1;
455
456 /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */
457 /*@{*/
458 unsigned origin_upper_left:1;
459 unsigned pixel_center_integer:1;
460 /*@}*/
461
462 /**
463 * Flag set if GL_ARB_explicit_attrib_location "location" layout
464 * qualifier is used.
465 */
466 unsigned explicit_location:1;
467 /**
468 * Flag set if GL_ARB_explicit_attrib_location "index" layout
469 * qualifier is used.
470 */
471 unsigned explicit_index:1;
472
473 /**
474 * Flag set if GL_ARB_shading_language_420pack "binding" layout
475 * qualifier is used.
476 */
477 unsigned explicit_binding:1;
478
479 /**
480 * Flag set if GL_ARB_shader_atomic counter "offset" layout
481 * qualifier is used.
482 */
483 unsigned explicit_offset:1;
484
485 /** \name Layout qualifiers for GL_AMD_conservative_depth */
486 /** \{ */
487 unsigned depth_any:1;
488 unsigned depth_greater:1;
489 unsigned depth_less:1;
490 unsigned depth_unchanged:1;
491 /** \} */
492
493 /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */
494 /** \{ */
495 unsigned std140:1;
496 unsigned std430:1;
497 unsigned shared:1;
498 unsigned packed:1;
499 unsigned column_major:1;
500 unsigned row_major:1;
501 /** \} */
502
503 /** \name Layout qualifiers for GLSL 1.50 geometry shaders */
504 /** \{ */
505 unsigned prim_type:1;
506 unsigned max_vertices:1;
507 /** \} */
508
509 /**
510 * local_size_{x,y,z} flags for compute shaders. Bit 0 represents
511 * local_size_x, and so on.
512 */
513 unsigned local_size:3;
514
515 /** \name Layout and memory qualifiers for ARB_shader_image_load_store. */
516 /** \{ */
517 unsigned early_fragment_tests:1;
518 unsigned explicit_image_format:1;
519 unsigned coherent:1;
520 unsigned _volatile:1;
521 unsigned restrict_flag:1;
522 unsigned read_only:1; /**< "readonly" qualifier. */
523 unsigned write_only:1; /**< "writeonly" qualifier. */
524 /** \} */
525
526 /** \name Layout qualifiers for GL_ARB_gpu_shader5 */
527 /** \{ */
528 unsigned invocations:1;
529 unsigned stream:1; /**< Has stream value assigned */
530 unsigned explicit_stream:1; /**< stream value assigned explicitly by shader code */
531 /** \} */
532
533 /** \name Layout qualifiers for GL_ARB_tessellation_shader */
534 /** \{ */
535 /* tess eval input layout */
536 /* gs prim_type reused for primitive mode */
537 unsigned vertex_spacing:1;
538 unsigned ordering:1;
539 unsigned point_mode:1;
540 /* tess control output layout */
541 unsigned vertices:1;
542 /** \} */
543
544 /** \name Qualifiers for GL_ARB_shader_subroutine */
545 /** \{ */
546 unsigned subroutine:1; /**< Is this marked 'subroutine' */
547 unsigned subroutine_def:1; /**< Is this marked 'subroutine' with a list of types */
548 /** \} */
549 }
550 /** \brief Set of flags, accessed by name. */
551 q;
552
553 /** \brief Set of flags, accessed as a bitmask. */
554 uint64_t i;
555 } flags;
556
557 /** Precision of the type (highp/medium/lowp). */
558 unsigned precision:2;
559
560 /** Geometry shader invocations for GL_ARB_gpu_shader5. */
561 int invocations;
562
563 /**
564 * Location specified via GL_ARB_explicit_attrib_location layout
565 *
566 * \note
567 * This field is only valid if \c explicit_location is set.
568 */
569 int location;
570 /**
571 * Index specified via GL_ARB_explicit_attrib_location layout
572 *
573 * \note
574 * This field is only valid if \c explicit_index is set.
575 */
576 int index;
577
578 /** Maximum output vertices in GLSL 1.50 geometry shaders. */
579 int max_vertices;
580
581 /** Stream in GLSL 1.50 geometry shaders. */
582 unsigned stream;
583
584 /**
585 * Input or output primitive type in GLSL 1.50 geometry shaders
586 * and tessellation shaders.
587 */
588 GLenum prim_type;
589
590 /**
591 * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword.
592 *
593 * \note
594 * This field is only valid if \c explicit_binding is set.
595 */
596 int binding;
597
598 /**
599 * Offset specified via GL_ARB_shader_atomic_counter's "offset"
600 * keyword.
601 *
602 * \note
603 * This field is only valid if \c explicit_offset is set.
604 */
605 int offset;
606
607 /**
608 * Local size specified via GL_ARB_compute_shader's "local_size_{x,y,z}"
609 * layout qualifier. Element i of this array is only valid if
610 * flags.q.local_size & (1 << i) is set.
611 */
612 int local_size[3];
613
614 /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */
615 GLenum vertex_spacing;
616
617 /** Tessellation evaluation shader: vertex ordering (CW or CCW) */
618 GLenum ordering;
619
620 /** Tessellation evaluation shader: point mode */
621 bool point_mode;
622
623 /** Tessellation control shader: number of output vertices */
624 int vertices;
625
626 /**
627 * Image format specified with an ARB_shader_image_load_store
628 * layout qualifier.
629 *
630 * \note
631 * This field is only valid if \c explicit_image_format is set.
632 */
633 GLenum image_format;
634
635 /**
636 * Base type of the data read from or written to this image. Only
637 * the following enumerants are allowed: GLSL_TYPE_UINT,
638 * GLSL_TYPE_INT, GLSL_TYPE_FLOAT.
639 *
640 * \note
641 * This field is only valid if \c explicit_image_format is set.
642 */
643 glsl_base_type image_base_type;
644
645 /** Flag to know if this represents a default value for a qualifier */
646 bool is_default_qualifier;
647
648 /**
649 * Return true if and only if an interpolation qualifier is present.
650 */
651 bool has_interpolation() const;
652
653 /**
654 * Return whether a layout qualifier is present.
655 */
656 bool has_layout() const;
657
658 /**
659 * Return whether a storage qualifier is present.
660 */
661 bool has_storage() const;
662
663 /**
664 * Return whether an auxiliary storage qualifier is present.
665 */
666 bool has_auxiliary_storage() const;
667
668 /**
669 * \brief Return string representation of interpolation qualifier.
670 *
671 * If an interpolation qualifier is present, then return that qualifier's
672 * string representation. Otherwise, return null. For example, if the
673 * noperspective bit is set, then this returns "noperspective".
674 *
675 * If multiple interpolation qualifiers are somehow present, then the
676 * returned string is undefined but not null.
677 */
678 const char *interpolation_string() const;
679
680 bool merge_qualifier(YYLTYPE *loc,
681 _mesa_glsl_parse_state *state,
682 ast_type_qualifier q);
683
684 bool merge_out_qualifier(YYLTYPE *loc,
685 _mesa_glsl_parse_state *state,
686 ast_type_qualifier q,
687 ast_node* &node);
688
689 bool merge_in_qualifier(YYLTYPE *loc,
690 _mesa_glsl_parse_state *state,
691 ast_type_qualifier q,
692 ast_node* &node);
693
694 ast_subroutine_list *subroutine_list;
695 };
696
697 class ast_declarator_list;
698
699 class ast_struct_specifier : public ast_node {
700 public:
701 ast_struct_specifier(const char *identifier,
702 ast_declarator_list *declarator_list);
703 virtual void print(void) const;
704
705 virtual ir_rvalue *hir(exec_list *instructions,
706 struct _mesa_glsl_parse_state *state);
707
708 const char *name;
709 /* List of ast_declarator_list * */
710 exec_list declarations;
711 bool is_declaration;
712 };
713
714
715
716 class ast_type_specifier : public ast_node {
717 public:
718 /** Construct a type specifier from a type name */
719 ast_type_specifier(const char *name)
720 : type_name(name), structure(NULL), array_specifier(NULL),
721 default_precision(ast_precision_none)
722 {
723 /* empty */
724 }
725
726 /** Construct a type specifier from a structure definition */
727 ast_type_specifier(ast_struct_specifier *s)
728 : type_name(s->name), structure(s), array_specifier(NULL),
729 default_precision(ast_precision_none)
730 {
731 /* empty */
732 }
733
734 const struct glsl_type *glsl_type(const char **name,
735 struct _mesa_glsl_parse_state *state)
736 const;
737
738 virtual void print(void) const;
739
740 ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
741
742 const char *type_name;
743 ast_struct_specifier *structure;
744
745 ast_array_specifier *array_specifier;
746
747 /** For precision statements, this is the given precision; otherwise none. */
748 unsigned default_precision:2;
749 };
750
751
752 class ast_fully_specified_type : public ast_node {
753 public:
754 virtual void print(void) const;
755 bool has_qualifiers() const;
756
757 ast_fully_specified_type() : qualifier(), specifier(NULL)
758 {
759 }
760
761 const struct glsl_type *glsl_type(const char **name,
762 struct _mesa_glsl_parse_state *state)
763 const;
764
765 ast_type_qualifier qualifier;
766 ast_type_specifier *specifier;
767 };
768
769
770 class ast_declarator_list : public ast_node {
771 public:
772 ast_declarator_list(ast_fully_specified_type *);
773 virtual void print(void) const;
774
775 virtual ir_rvalue *hir(exec_list *instructions,
776 struct _mesa_glsl_parse_state *state);
777
778 ast_fully_specified_type *type;
779 /** List of 'ast_declaration *' */
780 exec_list declarations;
781
782 /**
783 * Flags for redeclarations. In these cases, no type is specified, to
784 * `type` is allowed to be NULL. In all other cases, this would be an error.
785 */
786 int invariant; /** < `invariant` redeclaration */
787 int precise; /** < `precise` redeclaration */
788 };
789
790
791 class ast_parameter_declarator : public ast_node {
792 public:
793 ast_parameter_declarator() :
794 type(NULL),
795 identifier(NULL),
796 array_specifier(NULL),
797 formal_parameter(false),
798 is_void(false)
799 {
800 /* empty */
801 }
802
803 virtual void print(void) const;
804
805 virtual ir_rvalue *hir(exec_list *instructions,
806 struct _mesa_glsl_parse_state *state);
807
808 ast_fully_specified_type *type;
809 const char *identifier;
810 ast_array_specifier *array_specifier;
811
812 static void parameters_to_hir(exec_list *ast_parameters,
813 bool formal, exec_list *ir_parameters,
814 struct _mesa_glsl_parse_state *state);
815
816 private:
817 /** Is this parameter declaration part of a formal parameter list? */
818 bool formal_parameter;
819
820 /**
821 * Is this parameter 'void' type?
822 *
823 * This field is set by \c ::hir.
824 */
825 bool is_void;
826 };
827
828
829 class ast_function : public ast_node {
830 public:
831 ast_function(void);
832
833 virtual void print(void) const;
834
835 virtual ir_rvalue *hir(exec_list *instructions,
836 struct _mesa_glsl_parse_state *state);
837
838 ast_fully_specified_type *return_type;
839 const char *identifier;
840
841 exec_list parameters;
842
843 private:
844 /**
845 * Is this prototype part of the function definition?
846 *
847 * Used by ast_function_definition::hir to process the parameters, etc.
848 * of the function.
849 *
850 * \sa ::hir
851 */
852 bool is_definition;
853
854 /**
855 * Function signature corresponding to this function prototype instance
856 *
857 * Used by ast_function_definition::hir to process the parameters, etc.
858 * of the function.
859 *
860 * \sa ::hir
861 */
862 class ir_function_signature *signature;
863
864 friend class ast_function_definition;
865 };
866
867
868 class ast_expression_statement : public ast_node {
869 public:
870 ast_expression_statement(ast_expression *);
871 virtual void print(void) const;
872
873 virtual ir_rvalue *hir(exec_list *instructions,
874 struct _mesa_glsl_parse_state *state);
875
876 ast_expression *expression;
877 };
878
879
880 class ast_case_label : public ast_node {
881 public:
882 ast_case_label(ast_expression *test_value);
883 virtual void print(void) const;
884
885 virtual ir_rvalue *hir(exec_list *instructions,
886 struct _mesa_glsl_parse_state *state);
887
888 /**
889 * An test value of NULL means 'default'.
890 */
891 ast_expression *test_value;
892 };
893
894
895 class ast_case_label_list : public ast_node {
896 public:
897 ast_case_label_list(void);
898 virtual void print(void) const;
899
900 virtual ir_rvalue *hir(exec_list *instructions,
901 struct _mesa_glsl_parse_state *state);
902
903 /**
904 * A list of case labels.
905 */
906 exec_list labels;
907 };
908
909
910 class ast_case_statement : public ast_node {
911 public:
912 ast_case_statement(ast_case_label_list *labels);
913 virtual void print(void) const;
914
915 virtual ir_rvalue *hir(exec_list *instructions,
916 struct _mesa_glsl_parse_state *state);
917
918 ast_case_label_list *labels;
919
920 /**
921 * A list of statements.
922 */
923 exec_list stmts;
924 };
925
926
927 class ast_case_statement_list : public ast_node {
928 public:
929 ast_case_statement_list(void);
930 virtual void print(void) const;
931
932 virtual ir_rvalue *hir(exec_list *instructions,
933 struct _mesa_glsl_parse_state *state);
934
935 /**
936 * A list of cases.
937 */
938 exec_list cases;
939 };
940
941
942 class ast_switch_body : public ast_node {
943 public:
944 ast_switch_body(ast_case_statement_list *stmts);
945 virtual void print(void) const;
946
947 virtual ir_rvalue *hir(exec_list *instructions,
948 struct _mesa_glsl_parse_state *state);
949
950 ast_case_statement_list *stmts;
951 };
952
953
954 class ast_selection_statement : public ast_node {
955 public:
956 ast_selection_statement(ast_expression *condition,
957 ast_node *then_statement,
958 ast_node *else_statement);
959 virtual void print(void) const;
960
961 virtual ir_rvalue *hir(exec_list *instructions,
962 struct _mesa_glsl_parse_state *state);
963
964 ast_expression *condition;
965 ast_node *then_statement;
966 ast_node *else_statement;
967 };
968
969
970 class ast_switch_statement : public ast_node {
971 public:
972 ast_switch_statement(ast_expression *test_expression,
973 ast_node *body);
974 virtual void print(void) const;
975
976 virtual ir_rvalue *hir(exec_list *instructions,
977 struct _mesa_glsl_parse_state *state);
978
979 ast_expression *test_expression;
980 ast_node *body;
981
982 protected:
983 void test_to_hir(exec_list *, struct _mesa_glsl_parse_state *);
984 };
985
986 class ast_iteration_statement : public ast_node {
987 public:
988 ast_iteration_statement(int mode, ast_node *init, ast_node *condition,
989 ast_expression *rest_expression, ast_node *body);
990
991 virtual void print(void) const;
992
993 virtual ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
994
995 enum ast_iteration_modes {
996 ast_for,
997 ast_while,
998 ast_do_while
999 } mode;
1000
1001
1002 ast_node *init_statement;
1003 ast_node *condition;
1004 ast_expression *rest_expression;
1005
1006 ast_node *body;
1007
1008 /**
1009 * Generate IR from the condition of a loop
1010 *
1011 * This is factored out of ::hir because some loops have the condition
1012 * test at the top (for and while), and others have it at the end (do-while).
1013 */
1014 void condition_to_hir(exec_list *, struct _mesa_glsl_parse_state *);
1015 };
1016
1017
1018 class ast_jump_statement : public ast_node {
1019 public:
1020 ast_jump_statement(int mode, ast_expression *return_value);
1021 virtual void print(void) const;
1022
1023 virtual ir_rvalue *hir(exec_list *instructions,
1024 struct _mesa_glsl_parse_state *state);
1025
1026 enum ast_jump_modes {
1027 ast_continue,
1028 ast_break,
1029 ast_return,
1030 ast_discard
1031 } mode;
1032
1033 ast_expression *opt_return_value;
1034 };
1035
1036
1037 class ast_function_definition : public ast_node {
1038 public:
1039 ast_function_definition() : prototype(NULL), body(NULL)
1040 {
1041 }
1042
1043 virtual void print(void) const;
1044
1045 virtual ir_rvalue *hir(exec_list *instructions,
1046 struct _mesa_glsl_parse_state *state);
1047
1048 ast_function *prototype;
1049 ast_compound_statement *body;
1050 };
1051
1052 class ast_interface_block : public ast_node {
1053 public:
1054 ast_interface_block(ast_type_qualifier layout,
1055 const char *instance_name,
1056 ast_array_specifier *array_specifier)
1057 : layout(layout), block_name(NULL), instance_name(instance_name),
1058 array_specifier(array_specifier)
1059 {
1060 }
1061
1062 virtual ir_rvalue *hir(exec_list *instructions,
1063 struct _mesa_glsl_parse_state *state);
1064
1065 ast_type_qualifier layout;
1066 const char *block_name;
1067
1068 /**
1069 * Declared name of the block instance, if specified.
1070 *
1071 * If the block does not have an instance name, this field will be
1072 * \c NULL.
1073 */
1074 const char *instance_name;
1075
1076 /** List of ast_declarator_list * */
1077 exec_list declarations;
1078
1079 /**
1080 * Declared array size of the block instance
1081 *
1082 * If the block is not declared as an array or if the block instance array
1083 * is unsized, this field will be \c NULL.
1084 */
1085 ast_array_specifier *array_specifier;
1086 };
1087
1088
1089 /**
1090 * AST node representing a declaration of the output layout for tessellation
1091 * control shaders.
1092 */
1093 class ast_tcs_output_layout : public ast_node
1094 {
1095 public:
1096 ast_tcs_output_layout(const struct YYLTYPE &locp, int vertices)
1097 : vertices(vertices)
1098 {
1099 set_location(locp);
1100 }
1101
1102 virtual ir_rvalue *hir(exec_list *instructions,
1103 struct _mesa_glsl_parse_state *state);
1104
1105 private:
1106 const int vertices;
1107 };
1108
1109
1110 /**
1111 * AST node representing a declaration of the input layout for geometry
1112 * shaders.
1113 */
1114 class ast_gs_input_layout : public ast_node
1115 {
1116 public:
1117 ast_gs_input_layout(const struct YYLTYPE &locp, GLenum prim_type)
1118 : prim_type(prim_type)
1119 {
1120 set_location(locp);
1121 }
1122
1123 virtual ir_rvalue *hir(exec_list *instructions,
1124 struct _mesa_glsl_parse_state *state);
1125
1126 private:
1127 const GLenum prim_type;
1128 };
1129
1130
1131 /**
1132 * AST node representing a decalaration of the input layout for compute
1133 * shaders.
1134 */
1135 class ast_cs_input_layout : public ast_node
1136 {
1137 public:
1138 ast_cs_input_layout(const struct YYLTYPE &locp, const unsigned *local_size)
1139 {
1140 memcpy(this->local_size, local_size, sizeof(this->local_size));
1141 set_location(locp);
1142 }
1143
1144 virtual ir_rvalue *hir(exec_list *instructions,
1145 struct _mesa_glsl_parse_state *state);
1146
1147 private:
1148 unsigned local_size[3];
1149 };
1150
1151 /*@}*/
1152
1153 extern void
1154 _mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state);
1155
1156 extern ir_rvalue *
1157 _mesa_ast_field_selection_to_hir(const ast_expression *expr,
1158 exec_list *instructions,
1159 struct _mesa_glsl_parse_state *state);
1160
1161 extern ir_rvalue *
1162 _mesa_ast_array_index_to_hir(void *mem_ctx,
1163 struct _mesa_glsl_parse_state *state,
1164 ir_rvalue *array, ir_rvalue *idx,
1165 YYLTYPE &loc, YYLTYPE &idx_loc);
1166
1167 extern void
1168 _mesa_ast_set_aggregate_type(const glsl_type *type,
1169 ast_expression *expr);
1170
1171 void
1172 emit_function(_mesa_glsl_parse_state *state, ir_function *f);
1173
1174 extern void
1175 check_builtin_array_max_size(const char *name, unsigned size,
1176 YYLTYPE loc, struct _mesa_glsl_parse_state *state);
1177
1178 extern void _mesa_ast_process_interface_block(YYLTYPE *locp,
1179 _mesa_glsl_parse_state *state,
1180 ast_interface_block *const block,
1181 const struct ast_type_qualifier q);
1182
1183 #endif /* AST_H */