1b8e80941Smrg/* -*- c++ -*- */ 2b8e80941Smrg/* 3b8e80941Smrg * Copyright © 2009 Intel Corporation 4b8e80941Smrg * 5b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 7b8e80941Smrg * to deal in the Software without restriction, including without limitation 8b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 10b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 11b8e80941Smrg * 12b8e80941Smrg * The above copyright notice and this permission notice (including the next 13b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 14b8e80941Smrg * Software. 15b8e80941Smrg * 16b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22b8e80941Smrg * DEALINGS IN THE SOFTWARE. 23b8e80941Smrg */ 24b8e80941Smrg 25b8e80941Smrg#ifndef AST_H 26b8e80941Smrg#define AST_H 27b8e80941Smrg 28b8e80941Smrg#include "list.h" 29b8e80941Smrg#include "glsl_parser_extras.h" 30b8e80941Smrg#include "compiler/glsl_types.h" 31b8e80941Smrg#include "util/bitset.h" 32b8e80941Smrg 33b8e80941Smrgstruct _mesa_glsl_parse_state; 34b8e80941Smrg 35b8e80941Smrgstruct YYLTYPE; 36b8e80941Smrg 37b8e80941Smrg/** 38b8e80941Smrg * \defgroup AST Abstract syntax tree node definitions 39b8e80941Smrg * 40b8e80941Smrg * An abstract syntax tree is generated by the parser. This is a fairly 41b8e80941Smrg * direct representation of the gramma derivation for the source program. 42b8e80941Smrg * No symantic checking is done during the generation of the AST. Only 43b8e80941Smrg * syntactic checking is done. Symantic checking is performed by a later 44b8e80941Smrg * stage that converts the AST to a more generic intermediate representation. 45b8e80941Smrg * 46b8e80941Smrg *@{ 47b8e80941Smrg */ 48b8e80941Smrg/** 49b8e80941Smrg * Base class of all abstract syntax tree nodes 50b8e80941Smrg */ 51b8e80941Smrgclass ast_node { 52b8e80941Smrgpublic: 53b8e80941Smrg DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(ast_node); 54b8e80941Smrg 55b8e80941Smrg /** 56b8e80941Smrg * Print an AST node in something approximating the original GLSL code 57b8e80941Smrg */ 58b8e80941Smrg virtual void print(void) const; 59b8e80941Smrg 60b8e80941Smrg /** 61b8e80941Smrg * Convert the AST node to the high-level intermediate representation 62b8e80941Smrg */ 63b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 64b8e80941Smrg struct _mesa_glsl_parse_state *state); 65b8e80941Smrg 66b8e80941Smrg virtual bool has_sequence_subexpression() const; 67b8e80941Smrg 68b8e80941Smrg /** 69b8e80941Smrg * Retrieve the source location of an AST node 70b8e80941Smrg * 71b8e80941Smrg * This function is primarily used to get the source position of an AST node 72b8e80941Smrg * into a form that can be passed to \c _mesa_glsl_error. 73b8e80941Smrg * 74b8e80941Smrg * \sa _mesa_glsl_error, ast_node::set_location 75b8e80941Smrg */ 76b8e80941Smrg struct YYLTYPE get_location(void) const 77b8e80941Smrg { 78b8e80941Smrg struct YYLTYPE locp; 79b8e80941Smrg 80b8e80941Smrg locp.source = this->location.source; 81b8e80941Smrg locp.first_line = this->location.first_line; 82b8e80941Smrg locp.first_column = this->location.first_column; 83b8e80941Smrg locp.last_line = this->location.last_line; 84b8e80941Smrg locp.last_column = this->location.last_column; 85b8e80941Smrg 86b8e80941Smrg return locp; 87b8e80941Smrg } 88b8e80941Smrg 89b8e80941Smrg /** 90b8e80941Smrg * Set the source location of an AST node from a parser location 91b8e80941Smrg * 92b8e80941Smrg * \sa ast_node::get_location 93b8e80941Smrg */ 94b8e80941Smrg void set_location(const struct YYLTYPE &locp) 95b8e80941Smrg { 96b8e80941Smrg this->location.source = locp.source; 97b8e80941Smrg this->location.first_line = locp.first_line; 98b8e80941Smrg this->location.first_column = locp.first_column; 99b8e80941Smrg this->location.last_line = locp.last_line; 100b8e80941Smrg this->location.last_column = locp.last_column; 101b8e80941Smrg } 102b8e80941Smrg 103b8e80941Smrg /** 104b8e80941Smrg * Set the source location range of an AST node using two location nodes 105b8e80941Smrg * 106b8e80941Smrg * \sa ast_node::set_location 107b8e80941Smrg */ 108b8e80941Smrg void set_location_range(const struct YYLTYPE &begin, const struct YYLTYPE &end) 109b8e80941Smrg { 110b8e80941Smrg this->location.source = begin.source; 111b8e80941Smrg this->location.first_line = begin.first_line; 112b8e80941Smrg this->location.last_line = end.last_line; 113b8e80941Smrg this->location.first_column = begin.first_column; 114b8e80941Smrg this->location.last_column = end.last_column; 115b8e80941Smrg } 116b8e80941Smrg 117b8e80941Smrg /** 118b8e80941Smrg * Source location of the AST node. 119b8e80941Smrg */ 120b8e80941Smrg struct { 121b8e80941Smrg unsigned source; /**< GLSL source number. */ 122b8e80941Smrg unsigned first_line; /**< First line number within the source string. */ 123b8e80941Smrg unsigned first_column; /**< First column in the first line. */ 124b8e80941Smrg unsigned last_line; /**< Last line number within the source string. */ 125b8e80941Smrg unsigned last_column; /**< Last column in the last line. */ 126b8e80941Smrg } location; 127b8e80941Smrg 128b8e80941Smrg exec_node link; 129b8e80941Smrg 130b8e80941Smrg virtual void set_is_lhs(bool); 131b8e80941Smrg 132b8e80941Smrgprotected: 133b8e80941Smrg /** 134b8e80941Smrg * The only constructor is protected so that only derived class objects can 135b8e80941Smrg * be created. 136b8e80941Smrg */ 137b8e80941Smrg ast_node(void); 138b8e80941Smrg}; 139b8e80941Smrg 140b8e80941Smrg 141b8e80941Smrg/** 142b8e80941Smrg * Operators for AST expression nodes. 143b8e80941Smrg */ 144b8e80941Smrgenum ast_operators { 145b8e80941Smrg ast_assign, 146b8e80941Smrg ast_plus, /**< Unary + operator. */ 147b8e80941Smrg ast_neg, 148b8e80941Smrg ast_add, 149b8e80941Smrg ast_sub, 150b8e80941Smrg ast_mul, 151b8e80941Smrg ast_div, 152b8e80941Smrg ast_mod, 153b8e80941Smrg ast_lshift, 154b8e80941Smrg ast_rshift, 155b8e80941Smrg ast_less, 156b8e80941Smrg ast_greater, 157b8e80941Smrg ast_lequal, 158b8e80941Smrg ast_gequal, 159b8e80941Smrg ast_equal, 160b8e80941Smrg ast_nequal, 161b8e80941Smrg ast_bit_and, 162b8e80941Smrg ast_bit_xor, 163b8e80941Smrg ast_bit_or, 164b8e80941Smrg ast_bit_not, 165b8e80941Smrg ast_logic_and, 166b8e80941Smrg ast_logic_xor, 167b8e80941Smrg ast_logic_or, 168b8e80941Smrg ast_logic_not, 169b8e80941Smrg 170b8e80941Smrg ast_mul_assign, 171b8e80941Smrg ast_div_assign, 172b8e80941Smrg ast_mod_assign, 173b8e80941Smrg ast_add_assign, 174b8e80941Smrg ast_sub_assign, 175b8e80941Smrg ast_ls_assign, 176b8e80941Smrg ast_rs_assign, 177b8e80941Smrg ast_and_assign, 178b8e80941Smrg ast_xor_assign, 179b8e80941Smrg ast_or_assign, 180b8e80941Smrg 181b8e80941Smrg ast_conditional, 182b8e80941Smrg 183b8e80941Smrg ast_pre_inc, 184b8e80941Smrg ast_pre_dec, 185b8e80941Smrg ast_post_inc, 186b8e80941Smrg ast_post_dec, 187b8e80941Smrg ast_field_selection, 188b8e80941Smrg ast_array_index, 189b8e80941Smrg ast_unsized_array_dim, 190b8e80941Smrg 191b8e80941Smrg ast_function_call, 192b8e80941Smrg 193b8e80941Smrg ast_identifier, 194b8e80941Smrg ast_int_constant, 195b8e80941Smrg ast_uint_constant, 196b8e80941Smrg ast_float_constant, 197b8e80941Smrg ast_bool_constant, 198b8e80941Smrg ast_double_constant, 199b8e80941Smrg ast_int64_constant, 200b8e80941Smrg ast_uint64_constant, 201b8e80941Smrg 202b8e80941Smrg ast_sequence, 203b8e80941Smrg ast_aggregate 204b8e80941Smrg 205b8e80941Smrg /** 206b8e80941Smrg * Number of possible operators for an ast_expression 207b8e80941Smrg * 208b8e80941Smrg * This is done as a define instead of as an additional value in the enum so 209b8e80941Smrg * that the compiler won't generate spurious messages like "warning: 210b8e80941Smrg * enumeration value ‘ast_num_operators’ not handled in switch" 211b8e80941Smrg */ 212b8e80941Smrg #define AST_NUM_OPERATORS (ast_aggregate + 1) 213b8e80941Smrg}; 214b8e80941Smrg 215b8e80941Smrg/** 216b8e80941Smrg * Representation of any sort of expression. 217b8e80941Smrg */ 218b8e80941Smrgclass ast_expression : public ast_node { 219b8e80941Smrgpublic: 220b8e80941Smrg ast_expression(int oper, ast_expression *, 221b8e80941Smrg ast_expression *, ast_expression *); 222b8e80941Smrg 223b8e80941Smrg ast_expression(const char *identifier) : 224b8e80941Smrg oper(ast_identifier) 225b8e80941Smrg { 226b8e80941Smrg subexpressions[0] = NULL; 227b8e80941Smrg subexpressions[1] = NULL; 228b8e80941Smrg subexpressions[2] = NULL; 229b8e80941Smrg primary_expression.identifier = identifier; 230b8e80941Smrg this->non_lvalue_description = NULL; 231b8e80941Smrg this->is_lhs = false; 232b8e80941Smrg } 233b8e80941Smrg 234b8e80941Smrg static const char *operator_string(enum ast_operators op); 235b8e80941Smrg 236b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 237b8e80941Smrg struct _mesa_glsl_parse_state *state); 238b8e80941Smrg 239b8e80941Smrg virtual void hir_no_rvalue(exec_list *instructions, 240b8e80941Smrg struct _mesa_glsl_parse_state *state); 241b8e80941Smrg 242b8e80941Smrg virtual bool has_sequence_subexpression() const; 243b8e80941Smrg 244b8e80941Smrg ir_rvalue *do_hir(exec_list *instructions, 245b8e80941Smrg struct _mesa_glsl_parse_state *state, 246b8e80941Smrg bool needs_rvalue); 247b8e80941Smrg 248b8e80941Smrg virtual void print(void) const; 249b8e80941Smrg 250b8e80941Smrg enum ast_operators oper; 251b8e80941Smrg 252b8e80941Smrg ast_expression *subexpressions[3]; 253b8e80941Smrg 254b8e80941Smrg union { 255b8e80941Smrg const char *identifier; 256b8e80941Smrg int int_constant; 257b8e80941Smrg float float_constant; 258b8e80941Smrg unsigned uint_constant; 259b8e80941Smrg int bool_constant; 260b8e80941Smrg double double_constant; 261b8e80941Smrg uint64_t uint64_constant; 262b8e80941Smrg int64_t int64_constant; 263b8e80941Smrg } primary_expression; 264b8e80941Smrg 265b8e80941Smrg 266b8e80941Smrg /** 267b8e80941Smrg * List of expressions for an \c ast_sequence or parameters for an 268b8e80941Smrg * \c ast_function_call 269b8e80941Smrg */ 270b8e80941Smrg exec_list expressions; 271b8e80941Smrg 272b8e80941Smrg /** 273b8e80941Smrg * For things that can't be l-values, this describes what it is. 274b8e80941Smrg * 275b8e80941Smrg * This text is used by the code that generates IR for assignments to 276b8e80941Smrg * detect and emit useful messages for assignments to some things that 277b8e80941Smrg * can't be l-values. For example, pre- or post-incerement expressions. 278b8e80941Smrg * 279b8e80941Smrg * \note 280b8e80941Smrg * This pointer may be \c NULL. 281b8e80941Smrg */ 282b8e80941Smrg const char *non_lvalue_description; 283b8e80941Smrg 284b8e80941Smrg void set_is_lhs(bool new_value); 285b8e80941Smrg 286b8e80941Smrgprivate: 287b8e80941Smrg bool is_lhs; 288b8e80941Smrg}; 289b8e80941Smrg 290b8e80941Smrgclass ast_expression_bin : public ast_expression { 291b8e80941Smrgpublic: 292b8e80941Smrg ast_expression_bin(int oper, ast_expression *, ast_expression *); 293b8e80941Smrg 294b8e80941Smrg virtual void print(void) const; 295b8e80941Smrg}; 296b8e80941Smrg 297b8e80941Smrg/** 298b8e80941Smrg * Subclass of expressions for function calls 299b8e80941Smrg */ 300b8e80941Smrgclass ast_function_expression : public ast_expression { 301b8e80941Smrgpublic: 302b8e80941Smrg ast_function_expression(ast_expression *callee) 303b8e80941Smrg : ast_expression(ast_function_call, callee, 304b8e80941Smrg NULL, NULL), 305b8e80941Smrg cons(false) 306b8e80941Smrg { 307b8e80941Smrg /* empty */ 308b8e80941Smrg } 309b8e80941Smrg 310b8e80941Smrg ast_function_expression(class ast_type_specifier *type) 311b8e80941Smrg : ast_expression(ast_function_call, (ast_expression *) type, 312b8e80941Smrg NULL, NULL), 313b8e80941Smrg cons(true) 314b8e80941Smrg { 315b8e80941Smrg /* empty */ 316b8e80941Smrg } 317b8e80941Smrg 318b8e80941Smrg bool is_constructor() const 319b8e80941Smrg { 320b8e80941Smrg return cons; 321b8e80941Smrg } 322b8e80941Smrg 323b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 324b8e80941Smrg struct _mesa_glsl_parse_state *state); 325b8e80941Smrg 326b8e80941Smrg virtual void hir_no_rvalue(exec_list *instructions, 327b8e80941Smrg struct _mesa_glsl_parse_state *state); 328b8e80941Smrg 329b8e80941Smrg virtual bool has_sequence_subexpression() const; 330b8e80941Smrg 331b8e80941Smrgprivate: 332b8e80941Smrg /** 333b8e80941Smrg * Is this function call actually a constructor? 334b8e80941Smrg */ 335b8e80941Smrg bool cons; 336b8e80941Smrg ir_rvalue * 337b8e80941Smrg handle_method(exec_list *instructions, 338b8e80941Smrg struct _mesa_glsl_parse_state *state); 339b8e80941Smrg}; 340b8e80941Smrg 341b8e80941Smrgclass ast_subroutine_list : public ast_node 342b8e80941Smrg{ 343b8e80941Smrgpublic: 344b8e80941Smrg virtual void print(void) const; 345b8e80941Smrg exec_list declarations; 346b8e80941Smrg}; 347b8e80941Smrg 348b8e80941Smrgclass ast_array_specifier : public ast_node { 349b8e80941Smrgpublic: 350b8e80941Smrg ast_array_specifier(const struct YYLTYPE &locp, ast_expression *dim) 351b8e80941Smrg { 352b8e80941Smrg set_location(locp); 353b8e80941Smrg array_dimensions.push_tail(&dim->link); 354b8e80941Smrg } 355b8e80941Smrg 356b8e80941Smrg void add_dimension(ast_expression *dim) 357b8e80941Smrg { 358b8e80941Smrg array_dimensions.push_tail(&dim->link); 359b8e80941Smrg } 360b8e80941Smrg 361b8e80941Smrg bool is_single_dimension() const 362b8e80941Smrg { 363b8e80941Smrg return this->array_dimensions.get_tail_raw()->prev != NULL && 364b8e80941Smrg this->array_dimensions.get_tail_raw()->prev->is_head_sentinel(); 365b8e80941Smrg } 366b8e80941Smrg 367b8e80941Smrg virtual void print(void) const; 368b8e80941Smrg 369b8e80941Smrg /* This list contains objects of type ast_node containing the 370b8e80941Smrg * array dimensions in outermost-to-innermost order. 371b8e80941Smrg */ 372b8e80941Smrg exec_list array_dimensions; 373b8e80941Smrg}; 374b8e80941Smrg 375b8e80941Smrgclass ast_layout_expression : public ast_node { 376b8e80941Smrgpublic: 377b8e80941Smrg ast_layout_expression(const struct YYLTYPE &locp, ast_expression *expr) 378b8e80941Smrg { 379b8e80941Smrg set_location(locp); 380b8e80941Smrg layout_const_expressions.push_tail(&expr->link); 381b8e80941Smrg } 382b8e80941Smrg 383b8e80941Smrg bool process_qualifier_constant(struct _mesa_glsl_parse_state *state, 384b8e80941Smrg const char *qual_indentifier, 385b8e80941Smrg unsigned *value, bool can_be_zero); 386b8e80941Smrg 387b8e80941Smrg void merge_qualifier(ast_layout_expression *l_expr) 388b8e80941Smrg { 389b8e80941Smrg layout_const_expressions.append_list(&l_expr->layout_const_expressions); 390b8e80941Smrg } 391b8e80941Smrg 392b8e80941Smrg exec_list layout_const_expressions; 393b8e80941Smrg}; 394b8e80941Smrg 395b8e80941Smrg/** 396b8e80941Smrg * C-style aggregate initialization class 397b8e80941Smrg * 398b8e80941Smrg * Represents C-style initializers of vectors, matrices, arrays, and 399b8e80941Smrg * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to 400b8e80941Smrg * vec3 pos = vec3(1.0, 0.0, -1.0). 401b8e80941Smrg * 402b8e80941Smrg * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack. 403b8e80941Smrg * 404b8e80941Smrg * \sa _mesa_ast_set_aggregate_type 405b8e80941Smrg */ 406b8e80941Smrgclass ast_aggregate_initializer : public ast_expression { 407b8e80941Smrgpublic: 408b8e80941Smrg ast_aggregate_initializer() 409b8e80941Smrg : ast_expression(ast_aggregate, NULL, NULL, NULL), 410b8e80941Smrg constructor_type(NULL) 411b8e80941Smrg { 412b8e80941Smrg /* empty */ 413b8e80941Smrg } 414b8e80941Smrg 415b8e80941Smrg /** 416b8e80941Smrg * glsl_type of the aggregate, which is inferred from the LHS of whatever 417b8e80941Smrg * the aggregate is being used to initialize. This can't be inferred at 418b8e80941Smrg * parse time (since the parser deals with ast_type_specifiers, not 419b8e80941Smrg * glsl_types), so the parser leaves it NULL. However, the ast-to-hir 420b8e80941Smrg * conversion code makes sure to fill it in with the appropriate type 421b8e80941Smrg * before hir() is called. 422b8e80941Smrg */ 423b8e80941Smrg const glsl_type *constructor_type; 424b8e80941Smrg 425b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 426b8e80941Smrg struct _mesa_glsl_parse_state *state); 427b8e80941Smrg 428b8e80941Smrg virtual void hir_no_rvalue(exec_list *instructions, 429b8e80941Smrg struct _mesa_glsl_parse_state *state); 430b8e80941Smrg}; 431b8e80941Smrg 432b8e80941Smrg 433b8e80941Smrgclass ast_compound_statement : public ast_node { 434b8e80941Smrgpublic: 435b8e80941Smrg ast_compound_statement(int new_scope, ast_node *statements); 436b8e80941Smrg virtual void print(void) const; 437b8e80941Smrg 438b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 439b8e80941Smrg struct _mesa_glsl_parse_state *state); 440b8e80941Smrg 441b8e80941Smrg int new_scope; 442b8e80941Smrg exec_list statements; 443b8e80941Smrg}; 444b8e80941Smrg 445b8e80941Smrgclass ast_declaration : public ast_node { 446b8e80941Smrgpublic: 447b8e80941Smrg ast_declaration(const char *identifier, 448b8e80941Smrg ast_array_specifier *array_specifier, 449b8e80941Smrg ast_expression *initializer); 450b8e80941Smrg virtual void print(void) const; 451b8e80941Smrg 452b8e80941Smrg const char *identifier; 453b8e80941Smrg 454b8e80941Smrg ast_array_specifier *array_specifier; 455b8e80941Smrg 456b8e80941Smrg ast_expression *initializer; 457b8e80941Smrg}; 458b8e80941Smrg 459b8e80941Smrg 460b8e80941Smrgenum { 461b8e80941Smrg ast_precision_none = 0, /**< Absence of precision qualifier. */ 462b8e80941Smrg ast_precision_high, 463b8e80941Smrg ast_precision_medium, 464b8e80941Smrg ast_precision_low 465b8e80941Smrg}; 466b8e80941Smrg 467b8e80941Smrgenum { 468b8e80941Smrg ast_depth_none = 0, /**< Absence of depth qualifier. */ 469b8e80941Smrg ast_depth_any, 470b8e80941Smrg ast_depth_greater, 471b8e80941Smrg ast_depth_less, 472b8e80941Smrg ast_depth_unchanged 473b8e80941Smrg}; 474b8e80941Smrg 475b8e80941Smrgstruct ast_type_qualifier { 476b8e80941Smrg DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier); 477b8e80941Smrg /* Note: this bitset needs to have at least as many bits as the 'q' 478b8e80941Smrg * struct has flags, below. Previously, the size was 128 instead of 96. 479b8e80941Smrg * But an apparent bug in GCC 5.4.0 causes bad SSE code generation 480b8e80941Smrg * elsewhere, leading to a crash. 96 bits works around the issue. 481b8e80941Smrg * See https://bugs.freedesktop.org/show_bug.cgi?id=105497 482b8e80941Smrg */ 483b8e80941Smrg DECLARE_BITSET_T(bitset_t, 96); 484b8e80941Smrg 485b8e80941Smrg union flags { 486b8e80941Smrg struct { 487b8e80941Smrg unsigned invariant:1; 488b8e80941Smrg unsigned precise:1; 489b8e80941Smrg unsigned constant:1; 490b8e80941Smrg unsigned attribute:1; 491b8e80941Smrg unsigned varying:1; 492b8e80941Smrg unsigned in:1; 493b8e80941Smrg unsigned out:1; 494b8e80941Smrg unsigned centroid:1; 495b8e80941Smrg unsigned sample:1; 496b8e80941Smrg unsigned patch:1; 497b8e80941Smrg unsigned uniform:1; 498b8e80941Smrg unsigned buffer:1; 499b8e80941Smrg unsigned shared_storage:1; 500b8e80941Smrg unsigned smooth:1; 501b8e80941Smrg unsigned flat:1; 502b8e80941Smrg unsigned noperspective:1; 503b8e80941Smrg 504b8e80941Smrg /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */ 505b8e80941Smrg /*@{*/ 506b8e80941Smrg unsigned origin_upper_left:1; 507b8e80941Smrg unsigned pixel_center_integer:1; 508b8e80941Smrg /*@}*/ 509b8e80941Smrg 510b8e80941Smrg /** 511b8e80941Smrg * Flag set if GL_ARB_enhanced_layouts "align" layout qualifier is 512b8e80941Smrg * used. 513b8e80941Smrg */ 514b8e80941Smrg unsigned explicit_align:1; 515b8e80941Smrg 516b8e80941Smrg /** 517b8e80941Smrg * Flag set if GL_ARB_explicit_attrib_location "location" layout 518b8e80941Smrg * qualifier is used. 519b8e80941Smrg */ 520b8e80941Smrg unsigned explicit_location:1; 521b8e80941Smrg /** 522b8e80941Smrg * Flag set if GL_ARB_explicit_attrib_location "index" layout 523b8e80941Smrg * qualifier is used. 524b8e80941Smrg */ 525b8e80941Smrg unsigned explicit_index:1; 526b8e80941Smrg 527b8e80941Smrg /** 528b8e80941Smrg * Flag set if GL_ARB_enhanced_layouts "component" layout 529b8e80941Smrg * qualifier is used. 530b8e80941Smrg */ 531b8e80941Smrg unsigned explicit_component:1; 532b8e80941Smrg 533b8e80941Smrg /** 534b8e80941Smrg * Flag set if GL_ARB_shading_language_420pack "binding" layout 535b8e80941Smrg * qualifier is used. 536b8e80941Smrg */ 537b8e80941Smrg unsigned explicit_binding:1; 538b8e80941Smrg 539b8e80941Smrg /** 540b8e80941Smrg * Flag set if GL_ARB_shader_atomic counter "offset" layout 541b8e80941Smrg * qualifier is used. 542b8e80941Smrg */ 543b8e80941Smrg unsigned explicit_offset:1; 544b8e80941Smrg 545b8e80941Smrg /** \name Layout qualifiers for GL_AMD_conservative_depth */ 546b8e80941Smrg /** \{ */ 547b8e80941Smrg unsigned depth_type:1; 548b8e80941Smrg /** \} */ 549b8e80941Smrg 550b8e80941Smrg /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */ 551b8e80941Smrg /** \{ */ 552b8e80941Smrg unsigned std140:1; 553b8e80941Smrg unsigned std430:1; 554b8e80941Smrg unsigned shared:1; 555b8e80941Smrg unsigned packed:1; 556b8e80941Smrg unsigned column_major:1; 557b8e80941Smrg unsigned row_major:1; 558b8e80941Smrg /** \} */ 559b8e80941Smrg 560b8e80941Smrg /** \name Layout qualifiers for GLSL 1.50 geometry shaders */ 561b8e80941Smrg /** \{ */ 562b8e80941Smrg unsigned prim_type:1; 563b8e80941Smrg unsigned max_vertices:1; 564b8e80941Smrg /** \} */ 565b8e80941Smrg 566b8e80941Smrg /** 567b8e80941Smrg * local_size_{x,y,z} flags for compute shaders. Bit 0 represents 568b8e80941Smrg * local_size_x, and so on. 569b8e80941Smrg */ 570b8e80941Smrg unsigned local_size:3; 571b8e80941Smrg 572b8e80941Smrg /** \name Layout qualifiers for ARB_compute_variable_group_size. */ 573b8e80941Smrg /** \{ */ 574b8e80941Smrg unsigned local_size_variable:1; 575b8e80941Smrg /** \} */ 576b8e80941Smrg 577b8e80941Smrg /** \name Layout and memory qualifiers for ARB_shader_image_load_store. */ 578b8e80941Smrg /** \{ */ 579b8e80941Smrg unsigned early_fragment_tests:1; 580b8e80941Smrg unsigned explicit_image_format:1; 581b8e80941Smrg unsigned coherent:1; 582b8e80941Smrg unsigned _volatile:1; 583b8e80941Smrg unsigned restrict_flag:1; 584b8e80941Smrg unsigned read_only:1; /**< "readonly" qualifier. */ 585b8e80941Smrg unsigned write_only:1; /**< "writeonly" qualifier. */ 586b8e80941Smrg /** \} */ 587b8e80941Smrg 588b8e80941Smrg /** \name Layout qualifiers for GL_ARB_gpu_shader5 */ 589b8e80941Smrg /** \{ */ 590b8e80941Smrg unsigned invocations:1; 591b8e80941Smrg unsigned stream:1; /**< Has stream value assigned */ 592b8e80941Smrg unsigned explicit_stream:1; /**< stream value assigned explicitly by shader code */ 593b8e80941Smrg /** \} */ 594b8e80941Smrg 595b8e80941Smrg /** \name Layout qualifiers for GL_ARB_enhanced_layouts */ 596b8e80941Smrg /** \{ */ 597b8e80941Smrg unsigned explicit_xfb_offset:1; /**< xfb_offset value assigned explicitly by shader code */ 598b8e80941Smrg unsigned xfb_buffer:1; /**< Has xfb_buffer value assigned */ 599b8e80941Smrg unsigned explicit_xfb_buffer:1; /**< xfb_buffer value assigned explicitly by shader code */ 600b8e80941Smrg unsigned xfb_stride:1; /**< Is xfb_stride value yet to be merged with global values */ 601b8e80941Smrg unsigned explicit_xfb_stride:1; /**< xfb_stride value assigned explicitly by shader code */ 602b8e80941Smrg /** \} */ 603b8e80941Smrg 604b8e80941Smrg /** \name Layout qualifiers for GL_ARB_tessellation_shader */ 605b8e80941Smrg /** \{ */ 606b8e80941Smrg /* tess eval input layout */ 607b8e80941Smrg /* gs prim_type reused for primitive mode */ 608b8e80941Smrg unsigned vertex_spacing:1; 609b8e80941Smrg unsigned ordering:1; 610b8e80941Smrg unsigned point_mode:1; 611b8e80941Smrg /* tess control output layout */ 612b8e80941Smrg unsigned vertices:1; 613b8e80941Smrg /** \} */ 614b8e80941Smrg 615b8e80941Smrg /** \name Qualifiers for GL_ARB_shader_subroutine */ 616b8e80941Smrg /** \{ */ 617b8e80941Smrg unsigned subroutine:1; /**< Is this marked 'subroutine' */ 618b8e80941Smrg /** \} */ 619b8e80941Smrg 620b8e80941Smrg /** \name Qualifiers for GL_KHR_blend_equation_advanced */ 621b8e80941Smrg /** \{ */ 622b8e80941Smrg unsigned blend_support:1; /**< Are there any blend_support_ qualifiers */ 623b8e80941Smrg /** \} */ 624b8e80941Smrg 625b8e80941Smrg /** 626b8e80941Smrg * Flag set if GL_ARB_post_depth_coverage layout qualifier is used. 627b8e80941Smrg */ 628b8e80941Smrg unsigned post_depth_coverage:1; 629b8e80941Smrg 630b8e80941Smrg /** 631b8e80941Smrg * Flags for the layout qualifers added by ARB_fragment_shader_interlock 632b8e80941Smrg */ 633b8e80941Smrg 634b8e80941Smrg unsigned pixel_interlock_ordered:1; 635b8e80941Smrg unsigned pixel_interlock_unordered:1; 636b8e80941Smrg unsigned sample_interlock_ordered:1; 637b8e80941Smrg unsigned sample_interlock_unordered:1; 638b8e80941Smrg 639b8e80941Smrg /** 640b8e80941Smrg * Flag set if GL_INTEL_conservartive_rasterization layout qualifier 641b8e80941Smrg * is used. 642b8e80941Smrg */ 643b8e80941Smrg unsigned inner_coverage:1; 644b8e80941Smrg 645b8e80941Smrg /** \name Layout qualifiers for GL_ARB_bindless_texture */ 646b8e80941Smrg /** \{ */ 647b8e80941Smrg unsigned bindless_sampler:1; 648b8e80941Smrg unsigned bindless_image:1; 649b8e80941Smrg unsigned bound_sampler:1; 650b8e80941Smrg unsigned bound_image:1; 651b8e80941Smrg /** \} */ 652b8e80941Smrg 653b8e80941Smrg /** \name Layout qualifiers for GL_EXT_shader_framebuffer_fetch_non_coherent */ 654b8e80941Smrg /** \{ */ 655b8e80941Smrg unsigned non_coherent:1; 656b8e80941Smrg /** \} */ 657b8e80941Smrg 658b8e80941Smrg /** \name Layout qualifiers for NV_compute_shader_derivatives */ 659b8e80941Smrg /** \{ */ 660b8e80941Smrg unsigned derivative_group:1; 661b8e80941Smrg /** \} */ 662b8e80941Smrg } 663b8e80941Smrg /** \brief Set of flags, accessed by name. */ 664b8e80941Smrg q; 665b8e80941Smrg 666b8e80941Smrg /** \brief Set of flags, accessed as a bitmask. */ 667b8e80941Smrg bitset_t i; 668b8e80941Smrg } flags; 669b8e80941Smrg 670b8e80941Smrg /** Precision of the type (highp/medium/lowp). */ 671b8e80941Smrg unsigned precision:2; 672b8e80941Smrg 673b8e80941Smrg /** Type of layout qualifiers for GL_AMD_conservative_depth. */ 674b8e80941Smrg unsigned depth_type:3; 675b8e80941Smrg 676b8e80941Smrg /** 677b8e80941Smrg * Alignment specified via GL_ARB_enhanced_layouts "align" layout qualifier 678b8e80941Smrg */ 679b8e80941Smrg ast_expression *align; 680b8e80941Smrg 681b8e80941Smrg /** Geometry shader invocations for GL_ARB_gpu_shader5. */ 682b8e80941Smrg ast_layout_expression *invocations; 683b8e80941Smrg 684b8e80941Smrg /** 685b8e80941Smrg * Location specified via GL_ARB_explicit_attrib_location layout 686b8e80941Smrg * 687b8e80941Smrg * \note 688b8e80941Smrg * This field is only valid if \c explicit_location is set. 689b8e80941Smrg */ 690b8e80941Smrg ast_expression *location; 691b8e80941Smrg /** 692b8e80941Smrg * Index specified via GL_ARB_explicit_attrib_location layout 693b8e80941Smrg * 694b8e80941Smrg * \note 695b8e80941Smrg * This field is only valid if \c explicit_index is set. 696b8e80941Smrg */ 697b8e80941Smrg ast_expression *index; 698b8e80941Smrg 699b8e80941Smrg /** 700b8e80941Smrg * Component specified via GL_ARB_enhaced_layouts 701b8e80941Smrg * 702b8e80941Smrg * \note 703b8e80941Smrg * This field is only valid if \c explicit_component is set. 704b8e80941Smrg */ 705b8e80941Smrg ast_expression *component; 706b8e80941Smrg 707b8e80941Smrg /** Maximum output vertices in GLSL 1.50 geometry shaders. */ 708b8e80941Smrg ast_layout_expression *max_vertices; 709b8e80941Smrg 710b8e80941Smrg /** Stream in GLSL 1.50 geometry shaders. */ 711b8e80941Smrg ast_expression *stream; 712b8e80941Smrg 713b8e80941Smrg /** xfb_buffer specified via the GL_ARB_enhanced_layouts keyword. */ 714b8e80941Smrg ast_expression *xfb_buffer; 715b8e80941Smrg 716b8e80941Smrg /** xfb_stride specified via the GL_ARB_enhanced_layouts keyword. */ 717b8e80941Smrg ast_expression *xfb_stride; 718b8e80941Smrg 719b8e80941Smrg /** global xfb_stride values for each buffer */ 720b8e80941Smrg ast_layout_expression *out_xfb_stride[MAX_FEEDBACK_BUFFERS]; 721b8e80941Smrg 722b8e80941Smrg /** 723b8e80941Smrg * Input or output primitive type in GLSL 1.50 geometry shaders 724b8e80941Smrg * and tessellation shaders. 725b8e80941Smrg */ 726b8e80941Smrg GLenum prim_type; 727b8e80941Smrg 728b8e80941Smrg /** 729b8e80941Smrg * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword. 730b8e80941Smrg * 731b8e80941Smrg * \note 732b8e80941Smrg * This field is only valid if \c explicit_binding is set. 733b8e80941Smrg */ 734b8e80941Smrg ast_expression *binding; 735b8e80941Smrg 736b8e80941Smrg /** 737b8e80941Smrg * Offset specified via GL_ARB_shader_atomic_counter's or 738b8e80941Smrg * GL_ARB_enhanced_layouts "offset" keyword, or by GL_ARB_enhanced_layouts 739b8e80941Smrg * "xfb_offset" keyword. 740b8e80941Smrg * 741b8e80941Smrg * \note 742b8e80941Smrg * This field is only valid if \c explicit_offset is set. 743b8e80941Smrg */ 744b8e80941Smrg ast_expression *offset; 745b8e80941Smrg 746b8e80941Smrg /** 747b8e80941Smrg * Local size specified via GL_ARB_compute_shader's "local_size_{x,y,z}" 748b8e80941Smrg * layout qualifier. Element i of this array is only valid if 749b8e80941Smrg * flags.q.local_size & (1 << i) is set. 750b8e80941Smrg */ 751b8e80941Smrg ast_layout_expression *local_size[3]; 752b8e80941Smrg 753b8e80941Smrg /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */ 754b8e80941Smrg enum gl_tess_spacing vertex_spacing; 755b8e80941Smrg 756b8e80941Smrg /** Tessellation evaluation shader: vertex ordering (CW or CCW) */ 757b8e80941Smrg GLenum ordering; 758b8e80941Smrg 759b8e80941Smrg /** Tessellation evaluation shader: point mode */ 760b8e80941Smrg bool point_mode; 761b8e80941Smrg 762b8e80941Smrg /** Tessellation control shader: number of output vertices */ 763b8e80941Smrg ast_layout_expression *vertices; 764b8e80941Smrg 765b8e80941Smrg /** 766b8e80941Smrg * Image format specified with an ARB_shader_image_load_store 767b8e80941Smrg * layout qualifier. 768b8e80941Smrg * 769b8e80941Smrg * \note 770b8e80941Smrg * This field is only valid if \c explicit_image_format is set. 771b8e80941Smrg */ 772b8e80941Smrg GLenum image_format; 773b8e80941Smrg 774b8e80941Smrg /** 775b8e80941Smrg * Arrangement of invocations used to calculate derivatives in a compute 776b8e80941Smrg * shader. From NV_compute_shader_derivatives. 777b8e80941Smrg */ 778b8e80941Smrg enum gl_derivative_group derivative_group; 779b8e80941Smrg 780b8e80941Smrg /** 781b8e80941Smrg * Base type of the data read from or written to this image. Only 782b8e80941Smrg * the following enumerants are allowed: GLSL_TYPE_UINT, 783b8e80941Smrg * GLSL_TYPE_INT, GLSL_TYPE_FLOAT. 784b8e80941Smrg * 785b8e80941Smrg * \note 786b8e80941Smrg * This field is only valid if \c explicit_image_format is set. 787b8e80941Smrg */ 788b8e80941Smrg glsl_base_type image_base_type; 789b8e80941Smrg 790b8e80941Smrg /** 791b8e80941Smrg * Return true if and only if an interpolation qualifier is present. 792b8e80941Smrg */ 793b8e80941Smrg bool has_interpolation() const; 794b8e80941Smrg 795b8e80941Smrg /** 796b8e80941Smrg * Return whether a layout qualifier is present. 797b8e80941Smrg */ 798b8e80941Smrg bool has_layout() const; 799b8e80941Smrg 800b8e80941Smrg /** 801b8e80941Smrg * Return whether a storage qualifier is present. 802b8e80941Smrg */ 803b8e80941Smrg bool has_storage() const; 804b8e80941Smrg 805b8e80941Smrg /** 806b8e80941Smrg * Return whether an auxiliary storage qualifier is present. 807b8e80941Smrg */ 808b8e80941Smrg bool has_auxiliary_storage() const; 809b8e80941Smrg 810b8e80941Smrg /** 811b8e80941Smrg * Return true if and only if a memory qualifier is present. 812b8e80941Smrg */ 813b8e80941Smrg bool has_memory() const; 814b8e80941Smrg 815b8e80941Smrg /** 816b8e80941Smrg * Return true if the qualifier is a subroutine declaration. 817b8e80941Smrg */ 818b8e80941Smrg bool is_subroutine_decl() const; 819b8e80941Smrg 820b8e80941Smrg bool merge_qualifier(YYLTYPE *loc, 821b8e80941Smrg _mesa_glsl_parse_state *state, 822b8e80941Smrg const ast_type_qualifier &q, 823b8e80941Smrg bool is_single_layout_merge, 824b8e80941Smrg bool is_multiple_layouts_merge = false); 825b8e80941Smrg 826b8e80941Smrg /** 827b8e80941Smrg * Validate current qualifier against the global out one. 828b8e80941Smrg */ 829b8e80941Smrg bool validate_out_qualifier(YYLTYPE *loc, 830b8e80941Smrg _mesa_glsl_parse_state *state); 831b8e80941Smrg 832b8e80941Smrg /** 833b8e80941Smrg * Merge current qualifier into the global out one. 834b8e80941Smrg */ 835b8e80941Smrg bool merge_into_out_qualifier(YYLTYPE *loc, 836b8e80941Smrg _mesa_glsl_parse_state *state, 837b8e80941Smrg ast_node* &node); 838b8e80941Smrg 839b8e80941Smrg /** 840b8e80941Smrg * Validate current qualifier against the global in one. 841b8e80941Smrg */ 842b8e80941Smrg bool validate_in_qualifier(YYLTYPE *loc, 843b8e80941Smrg _mesa_glsl_parse_state *state); 844b8e80941Smrg 845b8e80941Smrg /** 846b8e80941Smrg * Merge current qualifier into the global in one. 847b8e80941Smrg */ 848b8e80941Smrg bool merge_into_in_qualifier(YYLTYPE *loc, 849b8e80941Smrg _mesa_glsl_parse_state *state, 850b8e80941Smrg ast_node* &node); 851b8e80941Smrg 852b8e80941Smrg /** 853b8e80941Smrg * Push pending layout qualifiers to the global values. 854b8e80941Smrg */ 855b8e80941Smrg bool push_to_global(YYLTYPE *loc, 856b8e80941Smrg _mesa_glsl_parse_state *state); 857b8e80941Smrg 858b8e80941Smrg bool validate_flags(YYLTYPE *loc, 859b8e80941Smrg _mesa_glsl_parse_state *state, 860b8e80941Smrg const ast_type_qualifier &allowed_flags, 861b8e80941Smrg const char *message, const char *name); 862b8e80941Smrg 863b8e80941Smrg ast_subroutine_list *subroutine_list; 864b8e80941Smrg}; 865b8e80941Smrg 866b8e80941Smrgclass ast_declarator_list; 867b8e80941Smrg 868b8e80941Smrgclass ast_struct_specifier : public ast_node { 869b8e80941Smrgpublic: 870b8e80941Smrg ast_struct_specifier(const char *identifier, 871b8e80941Smrg ast_declarator_list *declarator_list); 872b8e80941Smrg virtual void print(void) const; 873b8e80941Smrg 874b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 875b8e80941Smrg struct _mesa_glsl_parse_state *state); 876b8e80941Smrg 877b8e80941Smrg const char *name; 878b8e80941Smrg ast_type_qualifier *layout; 879b8e80941Smrg /* List of ast_declarator_list * */ 880b8e80941Smrg exec_list declarations; 881b8e80941Smrg bool is_declaration; 882b8e80941Smrg const glsl_type *type; 883b8e80941Smrg}; 884b8e80941Smrg 885b8e80941Smrg 886b8e80941Smrg 887b8e80941Smrgclass ast_type_specifier : public ast_node { 888b8e80941Smrgpublic: 889b8e80941Smrg /** Construct a type specifier from a type name */ 890b8e80941Smrg ast_type_specifier(const char *name) 891b8e80941Smrg : type(NULL), type_name(name), structure(NULL), array_specifier(NULL), 892b8e80941Smrg default_precision(ast_precision_none) 893b8e80941Smrg { 894b8e80941Smrg /* empty */ 895b8e80941Smrg } 896b8e80941Smrg 897b8e80941Smrg /** Construct a type specifier from a structure definition */ 898b8e80941Smrg ast_type_specifier(ast_struct_specifier *s) 899b8e80941Smrg : type(NULL), type_name(s->name), structure(s), array_specifier(NULL), 900b8e80941Smrg default_precision(ast_precision_none) 901b8e80941Smrg { 902b8e80941Smrg /* empty */ 903b8e80941Smrg } 904b8e80941Smrg 905b8e80941Smrg ast_type_specifier(const glsl_type *t) 906b8e80941Smrg : type(t), type_name(t->name), structure(NULL), array_specifier(NULL), 907b8e80941Smrg default_precision(ast_precision_none) 908b8e80941Smrg { 909b8e80941Smrg /* empty */ 910b8e80941Smrg } 911b8e80941Smrg 912b8e80941Smrg const struct glsl_type *glsl_type(const char **name, 913b8e80941Smrg struct _mesa_glsl_parse_state *state) 914b8e80941Smrg const; 915b8e80941Smrg 916b8e80941Smrg virtual void print(void) const; 917b8e80941Smrg 918b8e80941Smrg ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *); 919b8e80941Smrg 920b8e80941Smrg const struct glsl_type *type; 921b8e80941Smrg const char *type_name; 922b8e80941Smrg ast_struct_specifier *structure; 923b8e80941Smrg 924b8e80941Smrg ast_array_specifier *array_specifier; 925b8e80941Smrg 926b8e80941Smrg /** For precision statements, this is the given precision; otherwise none. */ 927b8e80941Smrg unsigned default_precision:2; 928b8e80941Smrg}; 929b8e80941Smrg 930b8e80941Smrg 931b8e80941Smrgclass ast_fully_specified_type : public ast_node { 932b8e80941Smrgpublic: 933b8e80941Smrg virtual void print(void) const; 934b8e80941Smrg bool has_qualifiers(_mesa_glsl_parse_state *state) const; 935b8e80941Smrg 936b8e80941Smrg ast_fully_specified_type() : qualifier(), specifier(NULL) 937b8e80941Smrg { 938b8e80941Smrg } 939b8e80941Smrg 940b8e80941Smrg const struct glsl_type *glsl_type(const char **name, 941b8e80941Smrg struct _mesa_glsl_parse_state *state) 942b8e80941Smrg const; 943b8e80941Smrg 944b8e80941Smrg ast_type_qualifier qualifier; 945b8e80941Smrg ast_type_specifier *specifier; 946b8e80941Smrg}; 947b8e80941Smrg 948b8e80941Smrg 949b8e80941Smrgclass ast_declarator_list : public ast_node { 950b8e80941Smrgpublic: 951b8e80941Smrg ast_declarator_list(ast_fully_specified_type *); 952b8e80941Smrg virtual void print(void) const; 953b8e80941Smrg 954b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 955b8e80941Smrg struct _mesa_glsl_parse_state *state); 956b8e80941Smrg 957b8e80941Smrg ast_fully_specified_type *type; 958b8e80941Smrg /** List of 'ast_declaration *' */ 959b8e80941Smrg exec_list declarations; 960b8e80941Smrg 961b8e80941Smrg /** 962b8e80941Smrg * Flags for redeclarations. In these cases, no type is specified, to 963b8e80941Smrg * `type` is allowed to be NULL. In all other cases, this would be an error. 964b8e80941Smrg */ 965b8e80941Smrg int invariant; /** < `invariant` redeclaration */ 966b8e80941Smrg int precise; /** < `precise` redeclaration */ 967b8e80941Smrg}; 968b8e80941Smrg 969b8e80941Smrg 970b8e80941Smrgclass ast_parameter_declarator : public ast_node { 971b8e80941Smrgpublic: 972b8e80941Smrg ast_parameter_declarator() : 973b8e80941Smrg type(NULL), 974b8e80941Smrg identifier(NULL), 975b8e80941Smrg array_specifier(NULL), 976b8e80941Smrg formal_parameter(false), 977b8e80941Smrg is_void(false) 978b8e80941Smrg { 979b8e80941Smrg /* empty */ 980b8e80941Smrg } 981b8e80941Smrg 982b8e80941Smrg virtual void print(void) const; 983b8e80941Smrg 984b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 985b8e80941Smrg struct _mesa_glsl_parse_state *state); 986b8e80941Smrg 987b8e80941Smrg ast_fully_specified_type *type; 988b8e80941Smrg const char *identifier; 989b8e80941Smrg ast_array_specifier *array_specifier; 990b8e80941Smrg 991b8e80941Smrg static void parameters_to_hir(exec_list *ast_parameters, 992b8e80941Smrg bool formal, exec_list *ir_parameters, 993b8e80941Smrg struct _mesa_glsl_parse_state *state); 994b8e80941Smrg 995b8e80941Smrgprivate: 996b8e80941Smrg /** Is this parameter declaration part of a formal parameter list? */ 997b8e80941Smrg bool formal_parameter; 998b8e80941Smrg 999b8e80941Smrg /** 1000b8e80941Smrg * Is this parameter 'void' type? 1001b8e80941Smrg * 1002b8e80941Smrg * This field is set by \c ::hir. 1003b8e80941Smrg */ 1004b8e80941Smrg bool is_void; 1005b8e80941Smrg}; 1006b8e80941Smrg 1007b8e80941Smrg 1008b8e80941Smrgclass ast_function : public ast_node { 1009b8e80941Smrgpublic: 1010b8e80941Smrg ast_function(void); 1011b8e80941Smrg 1012b8e80941Smrg virtual void print(void) const; 1013b8e80941Smrg 1014b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1015b8e80941Smrg struct _mesa_glsl_parse_state *state); 1016b8e80941Smrg 1017b8e80941Smrg ast_fully_specified_type *return_type; 1018b8e80941Smrg const char *identifier; 1019b8e80941Smrg 1020b8e80941Smrg exec_list parameters; 1021b8e80941Smrg 1022b8e80941Smrgprivate: 1023b8e80941Smrg /** 1024b8e80941Smrg * Is this prototype part of the function definition? 1025b8e80941Smrg * 1026b8e80941Smrg * Used by ast_function_definition::hir to process the parameters, etc. 1027b8e80941Smrg * of the function. 1028b8e80941Smrg * 1029b8e80941Smrg * \sa ::hir 1030b8e80941Smrg */ 1031b8e80941Smrg bool is_definition; 1032b8e80941Smrg 1033b8e80941Smrg /** 1034b8e80941Smrg * Function signature corresponding to this function prototype instance 1035b8e80941Smrg * 1036b8e80941Smrg * Used by ast_function_definition::hir to process the parameters, etc. 1037b8e80941Smrg * of the function. 1038b8e80941Smrg * 1039b8e80941Smrg * \sa ::hir 1040b8e80941Smrg */ 1041b8e80941Smrg class ir_function_signature *signature; 1042b8e80941Smrg 1043b8e80941Smrg friend class ast_function_definition; 1044b8e80941Smrg}; 1045b8e80941Smrg 1046b8e80941Smrg 1047b8e80941Smrgclass ast_expression_statement : public ast_node { 1048b8e80941Smrgpublic: 1049b8e80941Smrg ast_expression_statement(ast_expression *); 1050b8e80941Smrg virtual void print(void) const; 1051b8e80941Smrg 1052b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1053b8e80941Smrg struct _mesa_glsl_parse_state *state); 1054b8e80941Smrg 1055b8e80941Smrg ast_expression *expression; 1056b8e80941Smrg}; 1057b8e80941Smrg 1058b8e80941Smrg 1059b8e80941Smrgclass ast_case_label : public ast_node { 1060b8e80941Smrgpublic: 1061b8e80941Smrg ast_case_label(ast_expression *test_value); 1062b8e80941Smrg virtual void print(void) const; 1063b8e80941Smrg 1064b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1065b8e80941Smrg struct _mesa_glsl_parse_state *state); 1066b8e80941Smrg 1067b8e80941Smrg /** 1068b8e80941Smrg * An test value of NULL means 'default'. 1069b8e80941Smrg */ 1070b8e80941Smrg ast_expression *test_value; 1071b8e80941Smrg}; 1072b8e80941Smrg 1073b8e80941Smrg 1074b8e80941Smrgclass ast_case_label_list : public ast_node { 1075b8e80941Smrgpublic: 1076b8e80941Smrg ast_case_label_list(void); 1077b8e80941Smrg virtual void print(void) const; 1078b8e80941Smrg 1079b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1080b8e80941Smrg struct _mesa_glsl_parse_state *state); 1081b8e80941Smrg 1082b8e80941Smrg /** 1083b8e80941Smrg * A list of case labels. 1084b8e80941Smrg */ 1085b8e80941Smrg exec_list labels; 1086b8e80941Smrg}; 1087b8e80941Smrg 1088b8e80941Smrg 1089b8e80941Smrgclass ast_case_statement : public ast_node { 1090b8e80941Smrgpublic: 1091b8e80941Smrg ast_case_statement(ast_case_label_list *labels); 1092b8e80941Smrg virtual void print(void) const; 1093b8e80941Smrg 1094b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1095b8e80941Smrg struct _mesa_glsl_parse_state *state); 1096b8e80941Smrg 1097b8e80941Smrg ast_case_label_list *labels; 1098b8e80941Smrg 1099b8e80941Smrg /** 1100b8e80941Smrg * A list of statements. 1101b8e80941Smrg */ 1102b8e80941Smrg exec_list stmts; 1103b8e80941Smrg}; 1104b8e80941Smrg 1105b8e80941Smrg 1106b8e80941Smrgclass ast_case_statement_list : public ast_node { 1107b8e80941Smrgpublic: 1108b8e80941Smrg ast_case_statement_list(void); 1109b8e80941Smrg virtual void print(void) const; 1110b8e80941Smrg 1111b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1112b8e80941Smrg struct _mesa_glsl_parse_state *state); 1113b8e80941Smrg 1114b8e80941Smrg /** 1115b8e80941Smrg * A list of cases. 1116b8e80941Smrg */ 1117b8e80941Smrg exec_list cases; 1118b8e80941Smrg}; 1119b8e80941Smrg 1120b8e80941Smrg 1121b8e80941Smrgclass ast_switch_body : public ast_node { 1122b8e80941Smrgpublic: 1123b8e80941Smrg ast_switch_body(ast_case_statement_list *stmts); 1124b8e80941Smrg virtual void print(void) const; 1125b8e80941Smrg 1126b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1127b8e80941Smrg struct _mesa_glsl_parse_state *state); 1128b8e80941Smrg 1129b8e80941Smrg ast_case_statement_list *stmts; 1130b8e80941Smrg}; 1131b8e80941Smrg 1132b8e80941Smrg 1133b8e80941Smrgclass ast_selection_statement : public ast_node { 1134b8e80941Smrgpublic: 1135b8e80941Smrg ast_selection_statement(ast_expression *condition, 1136b8e80941Smrg ast_node *then_statement, 1137b8e80941Smrg ast_node *else_statement); 1138b8e80941Smrg virtual void print(void) const; 1139b8e80941Smrg 1140b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1141b8e80941Smrg struct _mesa_glsl_parse_state *state); 1142b8e80941Smrg 1143b8e80941Smrg ast_expression *condition; 1144b8e80941Smrg ast_node *then_statement; 1145b8e80941Smrg ast_node *else_statement; 1146b8e80941Smrg}; 1147b8e80941Smrg 1148b8e80941Smrg 1149b8e80941Smrgclass ast_switch_statement : public ast_node { 1150b8e80941Smrgpublic: 1151b8e80941Smrg ast_switch_statement(ast_expression *test_expression, 1152b8e80941Smrg ast_node *body); 1153b8e80941Smrg virtual void print(void) const; 1154b8e80941Smrg 1155b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1156b8e80941Smrg struct _mesa_glsl_parse_state *state); 1157b8e80941Smrg 1158b8e80941Smrg ast_expression *test_expression; 1159b8e80941Smrg ast_node *body; 1160b8e80941Smrg 1161b8e80941Smrgprotected: 1162b8e80941Smrg void test_to_hir(exec_list *, struct _mesa_glsl_parse_state *); 1163b8e80941Smrg}; 1164b8e80941Smrg 1165b8e80941Smrgclass ast_iteration_statement : public ast_node { 1166b8e80941Smrgpublic: 1167b8e80941Smrg ast_iteration_statement(int mode, ast_node *init, ast_node *condition, 1168b8e80941Smrg ast_expression *rest_expression, ast_node *body); 1169b8e80941Smrg 1170b8e80941Smrg virtual void print(void) const; 1171b8e80941Smrg 1172b8e80941Smrg virtual ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *); 1173b8e80941Smrg 1174b8e80941Smrg enum ast_iteration_modes { 1175b8e80941Smrg ast_for, 1176b8e80941Smrg ast_while, 1177b8e80941Smrg ast_do_while 1178b8e80941Smrg } mode; 1179b8e80941Smrg 1180b8e80941Smrg 1181b8e80941Smrg ast_node *init_statement; 1182b8e80941Smrg ast_node *condition; 1183b8e80941Smrg ast_expression *rest_expression; 1184b8e80941Smrg 1185b8e80941Smrg ast_node *body; 1186b8e80941Smrg 1187b8e80941Smrg /** 1188b8e80941Smrg * Generate IR from the condition of a loop 1189b8e80941Smrg * 1190b8e80941Smrg * This is factored out of ::hir because some loops have the condition 1191b8e80941Smrg * test at the top (for and while), and others have it at the end (do-while). 1192b8e80941Smrg */ 1193b8e80941Smrg void condition_to_hir(exec_list *, struct _mesa_glsl_parse_state *); 1194b8e80941Smrg}; 1195b8e80941Smrg 1196b8e80941Smrg 1197b8e80941Smrgclass ast_jump_statement : public ast_node { 1198b8e80941Smrgpublic: 1199b8e80941Smrg ast_jump_statement(int mode, ast_expression *return_value); 1200b8e80941Smrg virtual void print(void) const; 1201b8e80941Smrg 1202b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1203b8e80941Smrg struct _mesa_glsl_parse_state *state); 1204b8e80941Smrg 1205b8e80941Smrg enum ast_jump_modes { 1206b8e80941Smrg ast_continue, 1207b8e80941Smrg ast_break, 1208b8e80941Smrg ast_return, 1209b8e80941Smrg ast_discard 1210b8e80941Smrg } mode; 1211b8e80941Smrg 1212b8e80941Smrg ast_expression *opt_return_value; 1213b8e80941Smrg}; 1214b8e80941Smrg 1215b8e80941Smrg 1216b8e80941Smrgclass ast_function_definition : public ast_node { 1217b8e80941Smrgpublic: 1218b8e80941Smrg ast_function_definition() : prototype(NULL), body(NULL) 1219b8e80941Smrg { 1220b8e80941Smrg } 1221b8e80941Smrg 1222b8e80941Smrg virtual void print(void) const; 1223b8e80941Smrg 1224b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1225b8e80941Smrg struct _mesa_glsl_parse_state *state); 1226b8e80941Smrg 1227b8e80941Smrg ast_function *prototype; 1228b8e80941Smrg ast_compound_statement *body; 1229b8e80941Smrg}; 1230b8e80941Smrg 1231b8e80941Smrgclass ast_interface_block : public ast_node { 1232b8e80941Smrgpublic: 1233b8e80941Smrg ast_interface_block(const char *instance_name, 1234b8e80941Smrg ast_array_specifier *array_specifier) 1235b8e80941Smrg : block_name(NULL), instance_name(instance_name), 1236b8e80941Smrg array_specifier(array_specifier) 1237b8e80941Smrg { 1238b8e80941Smrg } 1239b8e80941Smrg 1240b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1241b8e80941Smrg struct _mesa_glsl_parse_state *state); 1242b8e80941Smrg 1243b8e80941Smrg ast_type_qualifier default_layout; 1244b8e80941Smrg ast_type_qualifier layout; 1245b8e80941Smrg const char *block_name; 1246b8e80941Smrg 1247b8e80941Smrg /** 1248b8e80941Smrg * Declared name of the block instance, if specified. 1249b8e80941Smrg * 1250b8e80941Smrg * If the block does not have an instance name, this field will be 1251b8e80941Smrg * \c NULL. 1252b8e80941Smrg */ 1253b8e80941Smrg const char *instance_name; 1254b8e80941Smrg 1255b8e80941Smrg /** List of ast_declarator_list * */ 1256b8e80941Smrg exec_list declarations; 1257b8e80941Smrg 1258b8e80941Smrg /** 1259b8e80941Smrg * Declared array size of the block instance 1260b8e80941Smrg * 1261b8e80941Smrg * If the block is not declared as an array or if the block instance array 1262b8e80941Smrg * is unsized, this field will be \c NULL. 1263b8e80941Smrg */ 1264b8e80941Smrg ast_array_specifier *array_specifier; 1265b8e80941Smrg}; 1266b8e80941Smrg 1267b8e80941Smrg 1268b8e80941Smrg/** 1269b8e80941Smrg * AST node representing a declaration of the output layout for tessellation 1270b8e80941Smrg * control shaders. 1271b8e80941Smrg */ 1272b8e80941Smrgclass ast_tcs_output_layout : public ast_node 1273b8e80941Smrg{ 1274b8e80941Smrgpublic: 1275b8e80941Smrg ast_tcs_output_layout(const struct YYLTYPE &locp) 1276b8e80941Smrg { 1277b8e80941Smrg set_location(locp); 1278b8e80941Smrg } 1279b8e80941Smrg 1280b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1281b8e80941Smrg struct _mesa_glsl_parse_state *state); 1282b8e80941Smrg}; 1283b8e80941Smrg 1284b8e80941Smrg 1285b8e80941Smrg/** 1286b8e80941Smrg * AST node representing a declaration of the input layout for geometry 1287b8e80941Smrg * shaders. 1288b8e80941Smrg */ 1289b8e80941Smrgclass ast_gs_input_layout : public ast_node 1290b8e80941Smrg{ 1291b8e80941Smrgpublic: 1292b8e80941Smrg ast_gs_input_layout(const struct YYLTYPE &locp, GLenum prim_type) 1293b8e80941Smrg : prim_type(prim_type) 1294b8e80941Smrg { 1295b8e80941Smrg set_location(locp); 1296b8e80941Smrg } 1297b8e80941Smrg 1298b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1299b8e80941Smrg struct _mesa_glsl_parse_state *state); 1300b8e80941Smrg 1301b8e80941Smrgprivate: 1302b8e80941Smrg const GLenum prim_type; 1303b8e80941Smrg}; 1304b8e80941Smrg 1305b8e80941Smrg 1306b8e80941Smrg/** 1307b8e80941Smrg * AST node representing a decalaration of the input layout for compute 1308b8e80941Smrg * shaders. 1309b8e80941Smrg */ 1310b8e80941Smrgclass ast_cs_input_layout : public ast_node 1311b8e80941Smrg{ 1312b8e80941Smrgpublic: 1313b8e80941Smrg ast_cs_input_layout(const struct YYLTYPE &locp, 1314b8e80941Smrg ast_layout_expression *const *local_size) 1315b8e80941Smrg { 1316b8e80941Smrg for (int i = 0; i < 3; i++) { 1317b8e80941Smrg this->local_size[i] = local_size[i]; 1318b8e80941Smrg } 1319b8e80941Smrg set_location(locp); 1320b8e80941Smrg } 1321b8e80941Smrg 1322b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1323b8e80941Smrg struct _mesa_glsl_parse_state *state); 1324b8e80941Smrg 1325b8e80941Smrgprivate: 1326b8e80941Smrg ast_layout_expression *local_size[3]; 1327b8e80941Smrg}; 1328b8e80941Smrg 1329b8e80941Smrgclass ast_warnings_toggle : public ast_node { 1330b8e80941Smrgpublic: 1331b8e80941Smrg ast_warnings_toggle(bool _enable) 1332b8e80941Smrg : enable(_enable) 1333b8e80941Smrg { 1334b8e80941Smrg /* empty */ 1335b8e80941Smrg } 1336b8e80941Smrg 1337b8e80941Smrg virtual ir_rvalue *hir(exec_list *instructions, 1338b8e80941Smrg struct _mesa_glsl_parse_state *state); 1339b8e80941Smrg 1340b8e80941Smrgprivate: 1341b8e80941Smrg bool enable; 1342b8e80941Smrg}; 1343b8e80941Smrg/*@}*/ 1344b8e80941Smrg 1345b8e80941Smrgextern void 1346b8e80941Smrg_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state); 1347b8e80941Smrg 1348b8e80941Smrgextern ir_rvalue * 1349b8e80941Smrg_mesa_ast_field_selection_to_hir(const ast_expression *expr, 1350b8e80941Smrg exec_list *instructions, 1351b8e80941Smrg struct _mesa_glsl_parse_state *state); 1352b8e80941Smrg 1353b8e80941Smrgextern ir_rvalue * 1354b8e80941Smrg_mesa_ast_array_index_to_hir(void *mem_ctx, 1355b8e80941Smrg struct _mesa_glsl_parse_state *state, 1356b8e80941Smrg ir_rvalue *array, ir_rvalue *idx, 1357b8e80941Smrg YYLTYPE &loc, YYLTYPE &idx_loc); 1358b8e80941Smrg 1359b8e80941Smrgextern void 1360b8e80941Smrg_mesa_ast_set_aggregate_type(const glsl_type *type, 1361b8e80941Smrg ast_expression *expr); 1362b8e80941Smrg 1363b8e80941Smrgvoid 1364b8e80941Smrgemit_function(_mesa_glsl_parse_state *state, ir_function *f); 1365b8e80941Smrg 1366b8e80941Smrgextern void 1367b8e80941Smrgcheck_builtin_array_max_size(const char *name, unsigned size, 1368b8e80941Smrg YYLTYPE loc, struct _mesa_glsl_parse_state *state); 1369b8e80941Smrg 1370b8e80941Smrgextern void _mesa_ast_process_interface_block(YYLTYPE *locp, 1371b8e80941Smrg _mesa_glsl_parse_state *state, 1372b8e80941Smrg ast_interface_block *const block, 1373b8e80941Smrg const struct ast_type_qualifier &q); 1374b8e80941Smrg 1375b8e80941Smrgextern bool 1376b8e80941Smrgprocess_qualifier_constant(struct _mesa_glsl_parse_state *state, 1377b8e80941Smrg YYLTYPE *loc, 1378b8e80941Smrg const char *qual_indentifier, 1379b8e80941Smrg ast_expression *const_expression, 1380b8e80941Smrg unsigned *value); 1381b8e80941Smrg#endif /* AST_H */ 1382