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