Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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