101e04c3fSmrg/* -*- c++ -*- */ 201e04c3fSmrg/* 301e04c3fSmrg * Copyright © 2009 Intel Corporation 401e04c3fSmrg * 501e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 601e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 701e04c3fSmrg * to deal in the Software without restriction, including without limitation 801e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 901e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the 1001e04c3fSmrg * Software is furnished to do so, subject to the following conditions: 1101e04c3fSmrg * 1201e04c3fSmrg * The above copyright notice and this permission notice (including the next 1301e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1401e04c3fSmrg * Software. 1501e04c3fSmrg * 1601e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1701e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1801e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1901e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2001e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2101e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 2201e04c3fSmrg * DEALINGS IN THE SOFTWARE. 2301e04c3fSmrg */ 2401e04c3fSmrg 2501e04c3fSmrg#ifndef AST_H 2601e04c3fSmrg#define AST_H 2701e04c3fSmrg 2801e04c3fSmrg#include "list.h" 2901e04c3fSmrg#include "glsl_parser_extras.h" 3001e04c3fSmrg#include "compiler/glsl_types.h" 3101e04c3fSmrg#include "util/bitset.h" 3201e04c3fSmrg 3301e04c3fSmrgstruct _mesa_glsl_parse_state; 3401e04c3fSmrg 3501e04c3fSmrgstruct YYLTYPE; 3601e04c3fSmrg 3701e04c3fSmrg/** 3801e04c3fSmrg * \defgroup AST Abstract syntax tree node definitions 3901e04c3fSmrg * 4001e04c3fSmrg * An abstract syntax tree is generated by the parser. This is a fairly 4101e04c3fSmrg * direct representation of the gramma derivation for the source program. 4201e04c3fSmrg * No symantic checking is done during the generation of the AST. Only 4301e04c3fSmrg * syntactic checking is done. Symantic checking is performed by a later 4401e04c3fSmrg * stage that converts the AST to a more generic intermediate representation. 4501e04c3fSmrg * 4601e04c3fSmrg *@{ 4701e04c3fSmrg */ 4801e04c3fSmrg/** 4901e04c3fSmrg * Base class of all abstract syntax tree nodes 5001e04c3fSmrg */ 5101e04c3fSmrgclass ast_node { 5201e04c3fSmrgpublic: 5301e04c3fSmrg DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(ast_node); 5401e04c3fSmrg 5501e04c3fSmrg /** 5601e04c3fSmrg * Print an AST node in something approximating the original GLSL code 5701e04c3fSmrg */ 5801e04c3fSmrg virtual void print(void) const; 5901e04c3fSmrg 6001e04c3fSmrg /** 6101e04c3fSmrg * Convert the AST node to the high-level intermediate representation 6201e04c3fSmrg */ 6301e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 6401e04c3fSmrg struct _mesa_glsl_parse_state *state); 6501e04c3fSmrg 6601e04c3fSmrg virtual bool has_sequence_subexpression() const; 6701e04c3fSmrg 6801e04c3fSmrg /** 6901e04c3fSmrg * Retrieve the source location of an AST node 7001e04c3fSmrg * 7101e04c3fSmrg * This function is primarily used to get the source position of an AST node 7201e04c3fSmrg * into a form that can be passed to \c _mesa_glsl_error. 7301e04c3fSmrg * 7401e04c3fSmrg * \sa _mesa_glsl_error, ast_node::set_location 7501e04c3fSmrg */ 7601e04c3fSmrg struct YYLTYPE get_location(void) const 7701e04c3fSmrg { 7801e04c3fSmrg struct YYLTYPE locp; 7901e04c3fSmrg 807ec681f3Smrg locp.path = this->location.path; 8101e04c3fSmrg locp.source = this->location.source; 8201e04c3fSmrg locp.first_line = this->location.first_line; 8301e04c3fSmrg locp.first_column = this->location.first_column; 8401e04c3fSmrg locp.last_line = this->location.last_line; 8501e04c3fSmrg locp.last_column = this->location.last_column; 8601e04c3fSmrg 8701e04c3fSmrg return locp; 8801e04c3fSmrg } 8901e04c3fSmrg 9001e04c3fSmrg /** 9101e04c3fSmrg * Set the source location of an AST node from a parser location 9201e04c3fSmrg * 9301e04c3fSmrg * \sa ast_node::get_location 9401e04c3fSmrg */ 9501e04c3fSmrg void set_location(const struct YYLTYPE &locp) 9601e04c3fSmrg { 977ec681f3Smrg this->location.path = locp.path; 9801e04c3fSmrg this->location.source = locp.source; 9901e04c3fSmrg this->location.first_line = locp.first_line; 10001e04c3fSmrg this->location.first_column = locp.first_column; 10101e04c3fSmrg this->location.last_line = locp.last_line; 10201e04c3fSmrg this->location.last_column = locp.last_column; 10301e04c3fSmrg } 10401e04c3fSmrg 10501e04c3fSmrg /** 10601e04c3fSmrg * Set the source location range of an AST node using two location nodes 10701e04c3fSmrg * 10801e04c3fSmrg * \sa ast_node::set_location 10901e04c3fSmrg */ 11001e04c3fSmrg void set_location_range(const struct YYLTYPE &begin, const struct YYLTYPE &end) 11101e04c3fSmrg { 1127ec681f3Smrg this->location.path = begin.path; 11301e04c3fSmrg this->location.source = begin.source; 11401e04c3fSmrg this->location.first_line = begin.first_line; 11501e04c3fSmrg this->location.last_line = end.last_line; 11601e04c3fSmrg this->location.first_column = begin.first_column; 11701e04c3fSmrg this->location.last_column = end.last_column; 11801e04c3fSmrg } 11901e04c3fSmrg 12001e04c3fSmrg /** 12101e04c3fSmrg * Source location of the AST node. 12201e04c3fSmrg */ 12301e04c3fSmrg struct { 1247ec681f3Smrg char *path; /**< GLSL shader include path. */ 12501e04c3fSmrg unsigned source; /**< GLSL source number. */ 12601e04c3fSmrg unsigned first_line; /**< First line number within the source string. */ 12701e04c3fSmrg unsigned first_column; /**< First column in the first line. */ 12801e04c3fSmrg unsigned last_line; /**< Last line number within the source string. */ 12901e04c3fSmrg unsigned last_column; /**< Last column in the last line. */ 13001e04c3fSmrg } location; 13101e04c3fSmrg 13201e04c3fSmrg exec_node link; 13301e04c3fSmrg 13401e04c3fSmrg virtual void set_is_lhs(bool); 13501e04c3fSmrg 13601e04c3fSmrgprotected: 13701e04c3fSmrg /** 13801e04c3fSmrg * The only constructor is protected so that only derived class objects can 13901e04c3fSmrg * be created. 14001e04c3fSmrg */ 14101e04c3fSmrg ast_node(void); 14201e04c3fSmrg}; 14301e04c3fSmrg 14401e04c3fSmrg 14501e04c3fSmrg/** 14601e04c3fSmrg * Operators for AST expression nodes. 14701e04c3fSmrg */ 14801e04c3fSmrgenum ast_operators { 14901e04c3fSmrg ast_assign, 15001e04c3fSmrg ast_plus, /**< Unary + operator. */ 15101e04c3fSmrg ast_neg, 15201e04c3fSmrg ast_add, 15301e04c3fSmrg ast_sub, 15401e04c3fSmrg ast_mul, 15501e04c3fSmrg ast_div, 15601e04c3fSmrg ast_mod, 15701e04c3fSmrg ast_lshift, 15801e04c3fSmrg ast_rshift, 15901e04c3fSmrg ast_less, 16001e04c3fSmrg ast_greater, 16101e04c3fSmrg ast_lequal, 16201e04c3fSmrg ast_gequal, 16301e04c3fSmrg ast_equal, 16401e04c3fSmrg ast_nequal, 16501e04c3fSmrg ast_bit_and, 16601e04c3fSmrg ast_bit_xor, 16701e04c3fSmrg ast_bit_or, 16801e04c3fSmrg ast_bit_not, 16901e04c3fSmrg ast_logic_and, 17001e04c3fSmrg ast_logic_xor, 17101e04c3fSmrg ast_logic_or, 17201e04c3fSmrg ast_logic_not, 17301e04c3fSmrg 17401e04c3fSmrg ast_mul_assign, 17501e04c3fSmrg ast_div_assign, 17601e04c3fSmrg ast_mod_assign, 17701e04c3fSmrg ast_add_assign, 17801e04c3fSmrg ast_sub_assign, 17901e04c3fSmrg ast_ls_assign, 18001e04c3fSmrg ast_rs_assign, 18101e04c3fSmrg ast_and_assign, 18201e04c3fSmrg ast_xor_assign, 18301e04c3fSmrg ast_or_assign, 18401e04c3fSmrg 18501e04c3fSmrg ast_conditional, 18601e04c3fSmrg 18701e04c3fSmrg ast_pre_inc, 18801e04c3fSmrg ast_pre_dec, 18901e04c3fSmrg ast_post_inc, 19001e04c3fSmrg ast_post_dec, 19101e04c3fSmrg ast_field_selection, 19201e04c3fSmrg ast_array_index, 19301e04c3fSmrg ast_unsized_array_dim, 19401e04c3fSmrg 19501e04c3fSmrg ast_function_call, 19601e04c3fSmrg 19701e04c3fSmrg ast_identifier, 19801e04c3fSmrg ast_int_constant, 19901e04c3fSmrg ast_uint_constant, 20001e04c3fSmrg ast_float_constant, 20101e04c3fSmrg ast_bool_constant, 20201e04c3fSmrg ast_double_constant, 20301e04c3fSmrg ast_int64_constant, 20401e04c3fSmrg ast_uint64_constant, 20501e04c3fSmrg 20601e04c3fSmrg ast_sequence, 20701e04c3fSmrg ast_aggregate 20801e04c3fSmrg 20901e04c3fSmrg /** 21001e04c3fSmrg * Number of possible operators for an ast_expression 21101e04c3fSmrg * 21201e04c3fSmrg * This is done as a define instead of as an additional value in the enum so 21301e04c3fSmrg * that the compiler won't generate spurious messages like "warning: 21401e04c3fSmrg * enumeration value ‘ast_num_operators’ not handled in switch" 21501e04c3fSmrg */ 21601e04c3fSmrg #define AST_NUM_OPERATORS (ast_aggregate + 1) 21701e04c3fSmrg}; 21801e04c3fSmrg 21901e04c3fSmrg/** 22001e04c3fSmrg * Representation of any sort of expression. 22101e04c3fSmrg */ 22201e04c3fSmrgclass ast_expression : public ast_node { 22301e04c3fSmrgpublic: 22401e04c3fSmrg ast_expression(int oper, ast_expression *, 22501e04c3fSmrg ast_expression *, ast_expression *); 22601e04c3fSmrg 22701e04c3fSmrg ast_expression(const char *identifier) : 22801e04c3fSmrg oper(ast_identifier) 22901e04c3fSmrg { 23001e04c3fSmrg subexpressions[0] = NULL; 23101e04c3fSmrg subexpressions[1] = NULL; 23201e04c3fSmrg subexpressions[2] = NULL; 23301e04c3fSmrg primary_expression.identifier = identifier; 23401e04c3fSmrg this->non_lvalue_description = NULL; 23501e04c3fSmrg this->is_lhs = false; 23601e04c3fSmrg } 23701e04c3fSmrg 23801e04c3fSmrg static const char *operator_string(enum ast_operators op); 23901e04c3fSmrg 24001e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 24101e04c3fSmrg struct _mesa_glsl_parse_state *state); 24201e04c3fSmrg 24301e04c3fSmrg virtual void hir_no_rvalue(exec_list *instructions, 24401e04c3fSmrg struct _mesa_glsl_parse_state *state); 24501e04c3fSmrg 24601e04c3fSmrg virtual bool has_sequence_subexpression() const; 24701e04c3fSmrg 24801e04c3fSmrg ir_rvalue *do_hir(exec_list *instructions, 24901e04c3fSmrg struct _mesa_glsl_parse_state *state, 25001e04c3fSmrg bool needs_rvalue); 25101e04c3fSmrg 25201e04c3fSmrg virtual void print(void) const; 25301e04c3fSmrg 25401e04c3fSmrg enum ast_operators oper; 25501e04c3fSmrg 25601e04c3fSmrg ast_expression *subexpressions[3]; 25701e04c3fSmrg 25801e04c3fSmrg union { 25901e04c3fSmrg const char *identifier; 26001e04c3fSmrg int int_constant; 26101e04c3fSmrg float float_constant; 26201e04c3fSmrg unsigned uint_constant; 26301e04c3fSmrg int bool_constant; 26401e04c3fSmrg double double_constant; 26501e04c3fSmrg uint64_t uint64_constant; 26601e04c3fSmrg int64_t int64_constant; 26701e04c3fSmrg } primary_expression; 26801e04c3fSmrg 26901e04c3fSmrg 27001e04c3fSmrg /** 27101e04c3fSmrg * List of expressions for an \c ast_sequence or parameters for an 27201e04c3fSmrg * \c ast_function_call 27301e04c3fSmrg */ 27401e04c3fSmrg exec_list expressions; 27501e04c3fSmrg 27601e04c3fSmrg /** 27701e04c3fSmrg * For things that can't be l-values, this describes what it is. 27801e04c3fSmrg * 27901e04c3fSmrg * This text is used by the code that generates IR for assignments to 28001e04c3fSmrg * detect and emit useful messages for assignments to some things that 28101e04c3fSmrg * can't be l-values. For example, pre- or post-incerement expressions. 28201e04c3fSmrg * 28301e04c3fSmrg * \note 28401e04c3fSmrg * This pointer may be \c NULL. 28501e04c3fSmrg */ 28601e04c3fSmrg const char *non_lvalue_description; 28701e04c3fSmrg 28801e04c3fSmrg void set_is_lhs(bool new_value); 28901e04c3fSmrg 29001e04c3fSmrgprivate: 29101e04c3fSmrg bool is_lhs; 29201e04c3fSmrg}; 29301e04c3fSmrg 29401e04c3fSmrgclass ast_expression_bin : public ast_expression { 29501e04c3fSmrgpublic: 29601e04c3fSmrg ast_expression_bin(int oper, ast_expression *, ast_expression *); 29701e04c3fSmrg 29801e04c3fSmrg virtual void print(void) const; 29901e04c3fSmrg}; 30001e04c3fSmrg 30101e04c3fSmrg/** 30201e04c3fSmrg * Subclass of expressions for function calls 30301e04c3fSmrg */ 30401e04c3fSmrgclass ast_function_expression : public ast_expression { 30501e04c3fSmrgpublic: 30601e04c3fSmrg ast_function_expression(ast_expression *callee) 30701e04c3fSmrg : ast_expression(ast_function_call, callee, 30801e04c3fSmrg NULL, NULL), 30901e04c3fSmrg cons(false) 31001e04c3fSmrg { 31101e04c3fSmrg /* empty */ 31201e04c3fSmrg } 31301e04c3fSmrg 31401e04c3fSmrg ast_function_expression(class ast_type_specifier *type) 31501e04c3fSmrg : ast_expression(ast_function_call, (ast_expression *) type, 31601e04c3fSmrg NULL, NULL), 31701e04c3fSmrg cons(true) 31801e04c3fSmrg { 31901e04c3fSmrg /* empty */ 32001e04c3fSmrg } 32101e04c3fSmrg 32201e04c3fSmrg bool is_constructor() const 32301e04c3fSmrg { 32401e04c3fSmrg return cons; 32501e04c3fSmrg } 32601e04c3fSmrg 32701e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 32801e04c3fSmrg struct _mesa_glsl_parse_state *state); 32901e04c3fSmrg 33001e04c3fSmrg virtual void hir_no_rvalue(exec_list *instructions, 33101e04c3fSmrg struct _mesa_glsl_parse_state *state); 33201e04c3fSmrg 33301e04c3fSmrg virtual bool has_sequence_subexpression() const; 33401e04c3fSmrg 33501e04c3fSmrgprivate: 33601e04c3fSmrg /** 33701e04c3fSmrg * Is this function call actually a constructor? 33801e04c3fSmrg */ 33901e04c3fSmrg bool cons; 34001e04c3fSmrg ir_rvalue * 34101e04c3fSmrg handle_method(exec_list *instructions, 34201e04c3fSmrg struct _mesa_glsl_parse_state *state); 34301e04c3fSmrg}; 34401e04c3fSmrg 34501e04c3fSmrgclass ast_subroutine_list : public ast_node 34601e04c3fSmrg{ 34701e04c3fSmrgpublic: 34801e04c3fSmrg virtual void print(void) const; 34901e04c3fSmrg exec_list declarations; 35001e04c3fSmrg}; 35101e04c3fSmrg 35201e04c3fSmrgclass ast_array_specifier : public ast_node { 35301e04c3fSmrgpublic: 35401e04c3fSmrg ast_array_specifier(const struct YYLTYPE &locp, ast_expression *dim) 35501e04c3fSmrg { 35601e04c3fSmrg set_location(locp); 35701e04c3fSmrg array_dimensions.push_tail(&dim->link); 35801e04c3fSmrg } 35901e04c3fSmrg 36001e04c3fSmrg void add_dimension(ast_expression *dim) 36101e04c3fSmrg { 36201e04c3fSmrg array_dimensions.push_tail(&dim->link); 36301e04c3fSmrg } 36401e04c3fSmrg 36501e04c3fSmrg bool is_single_dimension() const 36601e04c3fSmrg { 36701e04c3fSmrg return this->array_dimensions.get_tail_raw()->prev != NULL && 36801e04c3fSmrg this->array_dimensions.get_tail_raw()->prev->is_head_sentinel(); 36901e04c3fSmrg } 37001e04c3fSmrg 37101e04c3fSmrg virtual void print(void) const; 37201e04c3fSmrg 37301e04c3fSmrg /* This list contains objects of type ast_node containing the 37401e04c3fSmrg * array dimensions in outermost-to-innermost order. 37501e04c3fSmrg */ 37601e04c3fSmrg exec_list array_dimensions; 37701e04c3fSmrg}; 37801e04c3fSmrg 37901e04c3fSmrgclass ast_layout_expression : public ast_node { 38001e04c3fSmrgpublic: 38101e04c3fSmrg ast_layout_expression(const struct YYLTYPE &locp, ast_expression *expr) 38201e04c3fSmrg { 38301e04c3fSmrg set_location(locp); 38401e04c3fSmrg layout_const_expressions.push_tail(&expr->link); 38501e04c3fSmrg } 38601e04c3fSmrg 38701e04c3fSmrg bool process_qualifier_constant(struct _mesa_glsl_parse_state *state, 38801e04c3fSmrg const char *qual_indentifier, 38901e04c3fSmrg unsigned *value, bool can_be_zero); 39001e04c3fSmrg 39101e04c3fSmrg void merge_qualifier(ast_layout_expression *l_expr) 39201e04c3fSmrg { 39301e04c3fSmrg layout_const_expressions.append_list(&l_expr->layout_const_expressions); 39401e04c3fSmrg } 39501e04c3fSmrg 39601e04c3fSmrg exec_list layout_const_expressions; 39701e04c3fSmrg}; 39801e04c3fSmrg 39901e04c3fSmrg/** 40001e04c3fSmrg * C-style aggregate initialization class 40101e04c3fSmrg * 40201e04c3fSmrg * Represents C-style initializers of vectors, matrices, arrays, and 40301e04c3fSmrg * structures. E.g., vec3 pos = {1.0, 0.0, -1.0} is equivalent to 40401e04c3fSmrg * vec3 pos = vec3(1.0, 0.0, -1.0). 40501e04c3fSmrg * 40601e04c3fSmrg * Specified in GLSL 4.20 and GL_ARB_shading_language_420pack. 40701e04c3fSmrg * 40801e04c3fSmrg * \sa _mesa_ast_set_aggregate_type 40901e04c3fSmrg */ 41001e04c3fSmrgclass ast_aggregate_initializer : public ast_expression { 41101e04c3fSmrgpublic: 41201e04c3fSmrg ast_aggregate_initializer() 41301e04c3fSmrg : ast_expression(ast_aggregate, NULL, NULL, NULL), 41401e04c3fSmrg constructor_type(NULL) 41501e04c3fSmrg { 41601e04c3fSmrg /* empty */ 41701e04c3fSmrg } 41801e04c3fSmrg 41901e04c3fSmrg /** 42001e04c3fSmrg * glsl_type of the aggregate, which is inferred from the LHS of whatever 42101e04c3fSmrg * the aggregate is being used to initialize. This can't be inferred at 42201e04c3fSmrg * parse time (since the parser deals with ast_type_specifiers, not 42301e04c3fSmrg * glsl_types), so the parser leaves it NULL. However, the ast-to-hir 42401e04c3fSmrg * conversion code makes sure to fill it in with the appropriate type 42501e04c3fSmrg * before hir() is called. 42601e04c3fSmrg */ 42701e04c3fSmrg const glsl_type *constructor_type; 42801e04c3fSmrg 42901e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 43001e04c3fSmrg struct _mesa_glsl_parse_state *state); 43101e04c3fSmrg 43201e04c3fSmrg virtual void hir_no_rvalue(exec_list *instructions, 43301e04c3fSmrg struct _mesa_glsl_parse_state *state); 43401e04c3fSmrg}; 43501e04c3fSmrg 43601e04c3fSmrg 43701e04c3fSmrgclass ast_compound_statement : public ast_node { 43801e04c3fSmrgpublic: 43901e04c3fSmrg ast_compound_statement(int new_scope, ast_node *statements); 44001e04c3fSmrg virtual void print(void) const; 44101e04c3fSmrg 44201e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 44301e04c3fSmrg struct _mesa_glsl_parse_state *state); 44401e04c3fSmrg 44501e04c3fSmrg int new_scope; 44601e04c3fSmrg exec_list statements; 44701e04c3fSmrg}; 44801e04c3fSmrg 44901e04c3fSmrgclass ast_declaration : public ast_node { 45001e04c3fSmrgpublic: 45101e04c3fSmrg ast_declaration(const char *identifier, 45201e04c3fSmrg ast_array_specifier *array_specifier, 45301e04c3fSmrg ast_expression *initializer); 45401e04c3fSmrg virtual void print(void) const; 45501e04c3fSmrg 45601e04c3fSmrg const char *identifier; 45701e04c3fSmrg 45801e04c3fSmrg ast_array_specifier *array_specifier; 45901e04c3fSmrg 46001e04c3fSmrg ast_expression *initializer; 46101e04c3fSmrg}; 46201e04c3fSmrg 46301e04c3fSmrg 46401e04c3fSmrgenum { 46501e04c3fSmrg ast_precision_none = 0, /**< Absence of precision qualifier. */ 46601e04c3fSmrg ast_precision_high, 46701e04c3fSmrg ast_precision_medium, 46801e04c3fSmrg ast_precision_low 46901e04c3fSmrg}; 47001e04c3fSmrg 47101e04c3fSmrgenum { 47201e04c3fSmrg ast_depth_none = 0, /**< Absence of depth qualifier. */ 47301e04c3fSmrg ast_depth_any, 47401e04c3fSmrg ast_depth_greater, 47501e04c3fSmrg ast_depth_less, 47601e04c3fSmrg ast_depth_unchanged 47701e04c3fSmrg}; 47801e04c3fSmrg 47901e04c3fSmrgstruct ast_type_qualifier { 48001e04c3fSmrg DECLARE_RALLOC_CXX_OPERATORS(ast_type_qualifier); 48101e04c3fSmrg /* Note: this bitset needs to have at least as many bits as the 'q' 48201e04c3fSmrg * struct has flags, below. Previously, the size was 128 instead of 96. 48301e04c3fSmrg * But an apparent bug in GCC 5.4.0 causes bad SSE code generation 48401e04c3fSmrg * elsewhere, leading to a crash. 96 bits works around the issue. 48501e04c3fSmrg * See https://bugs.freedesktop.org/show_bug.cgi?id=105497 48601e04c3fSmrg */ 48701e04c3fSmrg DECLARE_BITSET_T(bitset_t, 96); 48801e04c3fSmrg 48901e04c3fSmrg union flags { 49001e04c3fSmrg struct { 49101e04c3fSmrg unsigned invariant:1; 49201e04c3fSmrg unsigned precise:1; 49301e04c3fSmrg unsigned constant:1; 49401e04c3fSmrg unsigned attribute:1; 49501e04c3fSmrg unsigned varying:1; 49601e04c3fSmrg unsigned in:1; 49701e04c3fSmrg unsigned out:1; 49801e04c3fSmrg unsigned centroid:1; 49901e04c3fSmrg unsigned sample:1; 50001e04c3fSmrg unsigned patch:1; 50101e04c3fSmrg unsigned uniform:1; 50201e04c3fSmrg unsigned buffer:1; 50301e04c3fSmrg unsigned shared_storage:1; 50401e04c3fSmrg unsigned smooth:1; 50501e04c3fSmrg unsigned flat:1; 50601e04c3fSmrg unsigned noperspective:1; 50701e04c3fSmrg 50801e04c3fSmrg /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */ 50901e04c3fSmrg /*@{*/ 51001e04c3fSmrg unsigned origin_upper_left:1; 51101e04c3fSmrg unsigned pixel_center_integer:1; 51201e04c3fSmrg /*@}*/ 51301e04c3fSmrg 51401e04c3fSmrg /** 51501e04c3fSmrg * Flag set if GL_ARB_enhanced_layouts "align" layout qualifier is 51601e04c3fSmrg * used. 51701e04c3fSmrg */ 51801e04c3fSmrg unsigned explicit_align:1; 51901e04c3fSmrg 52001e04c3fSmrg /** 52101e04c3fSmrg * Flag set if GL_ARB_explicit_attrib_location "location" layout 52201e04c3fSmrg * qualifier is used. 52301e04c3fSmrg */ 52401e04c3fSmrg unsigned explicit_location:1; 52501e04c3fSmrg /** 52601e04c3fSmrg * Flag set if GL_ARB_explicit_attrib_location "index" layout 52701e04c3fSmrg * qualifier is used. 52801e04c3fSmrg */ 52901e04c3fSmrg unsigned explicit_index:1; 53001e04c3fSmrg 53101e04c3fSmrg /** 53201e04c3fSmrg * Flag set if GL_ARB_enhanced_layouts "component" layout 53301e04c3fSmrg * qualifier is used. 53401e04c3fSmrg */ 53501e04c3fSmrg unsigned explicit_component:1; 53601e04c3fSmrg 53701e04c3fSmrg /** 53801e04c3fSmrg * Flag set if GL_ARB_shading_language_420pack "binding" layout 53901e04c3fSmrg * qualifier is used. 54001e04c3fSmrg */ 54101e04c3fSmrg unsigned explicit_binding:1; 54201e04c3fSmrg 54301e04c3fSmrg /** 54401e04c3fSmrg * Flag set if GL_ARB_shader_atomic counter "offset" layout 54501e04c3fSmrg * qualifier is used. 54601e04c3fSmrg */ 54701e04c3fSmrg unsigned explicit_offset:1; 54801e04c3fSmrg 54901e04c3fSmrg /** \name Layout qualifiers for GL_AMD_conservative_depth */ 55001e04c3fSmrg /** \{ */ 55101e04c3fSmrg unsigned depth_type:1; 55201e04c3fSmrg /** \} */ 55301e04c3fSmrg 55401e04c3fSmrg /** \name Layout qualifiers for GL_ARB_uniform_buffer_object */ 55501e04c3fSmrg /** \{ */ 55601e04c3fSmrg unsigned std140:1; 55701e04c3fSmrg unsigned std430:1; 55801e04c3fSmrg unsigned shared:1; 55901e04c3fSmrg unsigned packed:1; 56001e04c3fSmrg unsigned column_major:1; 56101e04c3fSmrg unsigned row_major:1; 56201e04c3fSmrg /** \} */ 56301e04c3fSmrg 56401e04c3fSmrg /** \name Layout qualifiers for GLSL 1.50 geometry shaders */ 56501e04c3fSmrg /** \{ */ 56601e04c3fSmrg unsigned prim_type:1; 56701e04c3fSmrg unsigned max_vertices:1; 56801e04c3fSmrg /** \} */ 56901e04c3fSmrg 57001e04c3fSmrg /** 57101e04c3fSmrg * local_size_{x,y,z} flags for compute shaders. Bit 0 represents 57201e04c3fSmrg * local_size_x, and so on. 57301e04c3fSmrg */ 57401e04c3fSmrg unsigned local_size:3; 57501e04c3fSmrg 57601e04c3fSmrg /** \name Layout qualifiers for ARB_compute_variable_group_size. */ 57701e04c3fSmrg /** \{ */ 57801e04c3fSmrg unsigned local_size_variable:1; 57901e04c3fSmrg /** \} */ 58001e04c3fSmrg 58101e04c3fSmrg /** \name Layout and memory qualifiers for ARB_shader_image_load_store. */ 58201e04c3fSmrg /** \{ */ 58301e04c3fSmrg unsigned early_fragment_tests:1; 58401e04c3fSmrg unsigned explicit_image_format:1; 58501e04c3fSmrg unsigned coherent:1; 58601e04c3fSmrg unsigned _volatile:1; 58701e04c3fSmrg unsigned restrict_flag:1; 58801e04c3fSmrg unsigned read_only:1; /**< "readonly" qualifier. */ 58901e04c3fSmrg unsigned write_only:1; /**< "writeonly" qualifier. */ 59001e04c3fSmrg /** \} */ 59101e04c3fSmrg 59201e04c3fSmrg /** \name Layout qualifiers for GL_ARB_gpu_shader5 */ 59301e04c3fSmrg /** \{ */ 59401e04c3fSmrg unsigned invocations:1; 59501e04c3fSmrg unsigned stream:1; /**< Has stream value assigned */ 59601e04c3fSmrg unsigned explicit_stream:1; /**< stream value assigned explicitly by shader code */ 59701e04c3fSmrg /** \} */ 59801e04c3fSmrg 59901e04c3fSmrg /** \name Layout qualifiers for GL_ARB_enhanced_layouts */ 60001e04c3fSmrg /** \{ */ 60101e04c3fSmrg unsigned explicit_xfb_offset:1; /**< xfb_offset value assigned explicitly by shader code */ 60201e04c3fSmrg unsigned xfb_buffer:1; /**< Has xfb_buffer value assigned */ 60301e04c3fSmrg unsigned explicit_xfb_buffer:1; /**< xfb_buffer value assigned explicitly by shader code */ 60401e04c3fSmrg unsigned xfb_stride:1; /**< Is xfb_stride value yet to be merged with global values */ 60501e04c3fSmrg unsigned explicit_xfb_stride:1; /**< xfb_stride value assigned explicitly by shader code */ 60601e04c3fSmrg /** \} */ 60701e04c3fSmrg 60801e04c3fSmrg /** \name Layout qualifiers for GL_ARB_tessellation_shader */ 60901e04c3fSmrg /** \{ */ 61001e04c3fSmrg /* tess eval input layout */ 61101e04c3fSmrg /* gs prim_type reused for primitive mode */ 61201e04c3fSmrg unsigned vertex_spacing:1; 61301e04c3fSmrg unsigned ordering:1; 61401e04c3fSmrg unsigned point_mode:1; 61501e04c3fSmrg /* tess control output layout */ 61601e04c3fSmrg unsigned vertices:1; 61701e04c3fSmrg /** \} */ 61801e04c3fSmrg 61901e04c3fSmrg /** \name Qualifiers for GL_ARB_shader_subroutine */ 62001e04c3fSmrg /** \{ */ 62101e04c3fSmrg unsigned subroutine:1; /**< Is this marked 'subroutine' */ 62201e04c3fSmrg /** \} */ 62301e04c3fSmrg 62401e04c3fSmrg /** \name Qualifiers for GL_KHR_blend_equation_advanced */ 62501e04c3fSmrg /** \{ */ 62601e04c3fSmrg unsigned blend_support:1; /**< Are there any blend_support_ qualifiers */ 62701e04c3fSmrg /** \} */ 62801e04c3fSmrg 62901e04c3fSmrg /** 63001e04c3fSmrg * Flag set if GL_ARB_post_depth_coverage layout qualifier is used. 63101e04c3fSmrg */ 63201e04c3fSmrg unsigned post_depth_coverage:1; 63301e04c3fSmrg 63401e04c3fSmrg /** 63501e04c3fSmrg * Flags for the layout qualifers added by ARB_fragment_shader_interlock 63601e04c3fSmrg */ 63701e04c3fSmrg 63801e04c3fSmrg unsigned pixel_interlock_ordered:1; 63901e04c3fSmrg unsigned pixel_interlock_unordered:1; 64001e04c3fSmrg unsigned sample_interlock_ordered:1; 64101e04c3fSmrg unsigned sample_interlock_unordered:1; 64201e04c3fSmrg 64301e04c3fSmrg /** 64401e04c3fSmrg * Flag set if GL_INTEL_conservartive_rasterization layout qualifier 64501e04c3fSmrg * is used. 64601e04c3fSmrg */ 64701e04c3fSmrg unsigned inner_coverage:1; 64801e04c3fSmrg 64901e04c3fSmrg /** \name Layout qualifiers for GL_ARB_bindless_texture */ 65001e04c3fSmrg /** \{ */ 65101e04c3fSmrg unsigned bindless_sampler:1; 65201e04c3fSmrg unsigned bindless_image:1; 65301e04c3fSmrg unsigned bound_sampler:1; 65401e04c3fSmrg unsigned bound_image:1; 65501e04c3fSmrg /** \} */ 65601e04c3fSmrg 65701e04c3fSmrg /** \name Layout qualifiers for GL_EXT_shader_framebuffer_fetch_non_coherent */ 65801e04c3fSmrg /** \{ */ 65901e04c3fSmrg unsigned non_coherent:1; 66001e04c3fSmrg /** \} */ 661ed98bd31Smaya 662ed98bd31Smaya /** \name Layout qualifiers for NV_compute_shader_derivatives */ 663ed98bd31Smaya /** \{ */ 664ed98bd31Smaya unsigned derivative_group:1; 665ed98bd31Smaya /** \} */ 6667ec681f3Smrg 6677ec681f3Smrg /** 6687ec681f3Smrg * Flag set if GL_NV_viewport_array2 viewport_relative layout 6697ec681f3Smrg * qualifier is used. 6707ec681f3Smrg */ 6717ec681f3Smrg unsigned viewport_relative:1; 67201e04c3fSmrg } 67301e04c3fSmrg /** \brief Set of flags, accessed by name. */ 67401e04c3fSmrg q; 67501e04c3fSmrg 67601e04c3fSmrg /** \brief Set of flags, accessed as a bitmask. */ 67701e04c3fSmrg bitset_t i; 67801e04c3fSmrg } flags; 67901e04c3fSmrg 68001e04c3fSmrg /** Precision of the type (highp/medium/lowp). */ 68101e04c3fSmrg unsigned precision:2; 68201e04c3fSmrg 68301e04c3fSmrg /** Type of layout qualifiers for GL_AMD_conservative_depth. */ 68401e04c3fSmrg unsigned depth_type:3; 68501e04c3fSmrg 68601e04c3fSmrg /** 68701e04c3fSmrg * Alignment specified via GL_ARB_enhanced_layouts "align" layout qualifier 68801e04c3fSmrg */ 68901e04c3fSmrg ast_expression *align; 69001e04c3fSmrg 69101e04c3fSmrg /** Geometry shader invocations for GL_ARB_gpu_shader5. */ 69201e04c3fSmrg ast_layout_expression *invocations; 69301e04c3fSmrg 69401e04c3fSmrg /** 69501e04c3fSmrg * Location specified via GL_ARB_explicit_attrib_location layout 69601e04c3fSmrg * 69701e04c3fSmrg * \note 69801e04c3fSmrg * This field is only valid if \c explicit_location is set. 69901e04c3fSmrg */ 70001e04c3fSmrg ast_expression *location; 70101e04c3fSmrg /** 70201e04c3fSmrg * Index specified via GL_ARB_explicit_attrib_location layout 70301e04c3fSmrg * 70401e04c3fSmrg * \note 70501e04c3fSmrg * This field is only valid if \c explicit_index is set. 70601e04c3fSmrg */ 70701e04c3fSmrg ast_expression *index; 70801e04c3fSmrg 70901e04c3fSmrg /** 71001e04c3fSmrg * Component specified via GL_ARB_enhaced_layouts 71101e04c3fSmrg * 71201e04c3fSmrg * \note 71301e04c3fSmrg * This field is only valid if \c explicit_component is set. 71401e04c3fSmrg */ 71501e04c3fSmrg ast_expression *component; 71601e04c3fSmrg 71701e04c3fSmrg /** Maximum output vertices in GLSL 1.50 geometry shaders. */ 71801e04c3fSmrg ast_layout_expression *max_vertices; 71901e04c3fSmrg 72001e04c3fSmrg /** Stream in GLSL 1.50 geometry shaders. */ 72101e04c3fSmrg ast_expression *stream; 72201e04c3fSmrg 72301e04c3fSmrg /** xfb_buffer specified via the GL_ARB_enhanced_layouts keyword. */ 72401e04c3fSmrg ast_expression *xfb_buffer; 72501e04c3fSmrg 72601e04c3fSmrg /** xfb_stride specified via the GL_ARB_enhanced_layouts keyword. */ 72701e04c3fSmrg ast_expression *xfb_stride; 72801e04c3fSmrg 72901e04c3fSmrg /** global xfb_stride values for each buffer */ 73001e04c3fSmrg ast_layout_expression *out_xfb_stride[MAX_FEEDBACK_BUFFERS]; 73101e04c3fSmrg 73201e04c3fSmrg /** 73301e04c3fSmrg * Input or output primitive type in GLSL 1.50 geometry shaders 73401e04c3fSmrg * and tessellation shaders. 73501e04c3fSmrg */ 73601e04c3fSmrg GLenum prim_type; 73701e04c3fSmrg 73801e04c3fSmrg /** 73901e04c3fSmrg * Binding specified via GL_ARB_shading_language_420pack's "binding" keyword. 74001e04c3fSmrg * 74101e04c3fSmrg * \note 74201e04c3fSmrg * This field is only valid if \c explicit_binding is set. 74301e04c3fSmrg */ 74401e04c3fSmrg ast_expression *binding; 74501e04c3fSmrg 74601e04c3fSmrg /** 74701e04c3fSmrg * Offset specified via GL_ARB_shader_atomic_counter's or 74801e04c3fSmrg * GL_ARB_enhanced_layouts "offset" keyword, or by GL_ARB_enhanced_layouts 74901e04c3fSmrg * "xfb_offset" keyword. 75001e04c3fSmrg * 75101e04c3fSmrg * \note 75201e04c3fSmrg * This field is only valid if \c explicit_offset is set. 75301e04c3fSmrg */ 75401e04c3fSmrg ast_expression *offset; 75501e04c3fSmrg 75601e04c3fSmrg /** 75701e04c3fSmrg * Local size specified via GL_ARB_compute_shader's "local_size_{x,y,z}" 75801e04c3fSmrg * layout qualifier. Element i of this array is only valid if 75901e04c3fSmrg * flags.q.local_size & (1 << i) is set. 76001e04c3fSmrg */ 76101e04c3fSmrg ast_layout_expression *local_size[3]; 76201e04c3fSmrg 76301e04c3fSmrg /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */ 76401e04c3fSmrg enum gl_tess_spacing vertex_spacing; 76501e04c3fSmrg 76601e04c3fSmrg /** Tessellation evaluation shader: vertex ordering (CW or CCW) */ 76701e04c3fSmrg GLenum ordering; 76801e04c3fSmrg 76901e04c3fSmrg /** Tessellation evaluation shader: point mode */ 77001e04c3fSmrg bool point_mode; 77101e04c3fSmrg 77201e04c3fSmrg /** Tessellation control shader: number of output vertices */ 77301e04c3fSmrg ast_layout_expression *vertices; 77401e04c3fSmrg 77501e04c3fSmrg /** 77601e04c3fSmrg * Image format specified with an ARB_shader_image_load_store 77701e04c3fSmrg * layout qualifier. 77801e04c3fSmrg * 77901e04c3fSmrg * \note 78001e04c3fSmrg * This field is only valid if \c explicit_image_format is set. 78101e04c3fSmrg */ 7827ec681f3Smrg enum pipe_format image_format; 78301e04c3fSmrg 784ed98bd31Smaya /** 785ed98bd31Smaya * Arrangement of invocations used to calculate derivatives in a compute 786ed98bd31Smaya * shader. From NV_compute_shader_derivatives. 787ed98bd31Smaya */ 788ed98bd31Smaya enum gl_derivative_group derivative_group; 789ed98bd31Smaya 79001e04c3fSmrg /** 79101e04c3fSmrg * Base type of the data read from or written to this image. Only 79201e04c3fSmrg * the following enumerants are allowed: GLSL_TYPE_UINT, 79301e04c3fSmrg * GLSL_TYPE_INT, GLSL_TYPE_FLOAT. 79401e04c3fSmrg * 79501e04c3fSmrg * \note 79601e04c3fSmrg * This field is only valid if \c explicit_image_format is set. 79701e04c3fSmrg */ 79801e04c3fSmrg glsl_base_type image_base_type; 79901e04c3fSmrg 80001e04c3fSmrg /** 80101e04c3fSmrg * Return true if and only if an interpolation qualifier is present. 80201e04c3fSmrg */ 80301e04c3fSmrg bool has_interpolation() const; 80401e04c3fSmrg 80501e04c3fSmrg /** 80601e04c3fSmrg * Return whether a layout qualifier is present. 80701e04c3fSmrg */ 80801e04c3fSmrg bool has_layout() const; 80901e04c3fSmrg 81001e04c3fSmrg /** 81101e04c3fSmrg * Return whether a storage qualifier is present. 81201e04c3fSmrg */ 81301e04c3fSmrg bool has_storage() const; 81401e04c3fSmrg 81501e04c3fSmrg /** 81601e04c3fSmrg * Return whether an auxiliary storage qualifier is present. 81701e04c3fSmrg */ 81801e04c3fSmrg bool has_auxiliary_storage() const; 81901e04c3fSmrg 82001e04c3fSmrg /** 82101e04c3fSmrg * Return true if and only if a memory qualifier is present. 82201e04c3fSmrg */ 82301e04c3fSmrg bool has_memory() const; 82401e04c3fSmrg 82501e04c3fSmrg /** 82601e04c3fSmrg * Return true if the qualifier is a subroutine declaration. 82701e04c3fSmrg */ 82801e04c3fSmrg bool is_subroutine_decl() const; 82901e04c3fSmrg 83001e04c3fSmrg bool merge_qualifier(YYLTYPE *loc, 83101e04c3fSmrg _mesa_glsl_parse_state *state, 83201e04c3fSmrg const ast_type_qualifier &q, 83301e04c3fSmrg bool is_single_layout_merge, 83401e04c3fSmrg bool is_multiple_layouts_merge = false); 83501e04c3fSmrg 83601e04c3fSmrg /** 83701e04c3fSmrg * Validate current qualifier against the global out one. 83801e04c3fSmrg */ 83901e04c3fSmrg bool validate_out_qualifier(YYLTYPE *loc, 84001e04c3fSmrg _mesa_glsl_parse_state *state); 84101e04c3fSmrg 84201e04c3fSmrg /** 84301e04c3fSmrg * Merge current qualifier into the global out one. 84401e04c3fSmrg */ 84501e04c3fSmrg bool merge_into_out_qualifier(YYLTYPE *loc, 84601e04c3fSmrg _mesa_glsl_parse_state *state, 84701e04c3fSmrg ast_node* &node); 84801e04c3fSmrg 84901e04c3fSmrg /** 85001e04c3fSmrg * Validate current qualifier against the global in one. 85101e04c3fSmrg */ 85201e04c3fSmrg bool validate_in_qualifier(YYLTYPE *loc, 85301e04c3fSmrg _mesa_glsl_parse_state *state); 85401e04c3fSmrg 85501e04c3fSmrg /** 85601e04c3fSmrg * Merge current qualifier into the global in one. 85701e04c3fSmrg */ 85801e04c3fSmrg bool merge_into_in_qualifier(YYLTYPE *loc, 85901e04c3fSmrg _mesa_glsl_parse_state *state, 86001e04c3fSmrg ast_node* &node); 86101e04c3fSmrg 86201e04c3fSmrg /** 86301e04c3fSmrg * Push pending layout qualifiers to the global values. 86401e04c3fSmrg */ 86501e04c3fSmrg bool push_to_global(YYLTYPE *loc, 86601e04c3fSmrg _mesa_glsl_parse_state *state); 86701e04c3fSmrg 86801e04c3fSmrg bool validate_flags(YYLTYPE *loc, 86901e04c3fSmrg _mesa_glsl_parse_state *state, 87001e04c3fSmrg const ast_type_qualifier &allowed_flags, 87101e04c3fSmrg const char *message, const char *name); 87201e04c3fSmrg 87301e04c3fSmrg ast_subroutine_list *subroutine_list; 87401e04c3fSmrg}; 87501e04c3fSmrg 87601e04c3fSmrgclass ast_declarator_list; 87701e04c3fSmrg 87801e04c3fSmrgclass ast_struct_specifier : public ast_node { 87901e04c3fSmrgpublic: 88001e04c3fSmrg ast_struct_specifier(const char *identifier, 88101e04c3fSmrg ast_declarator_list *declarator_list); 88201e04c3fSmrg virtual void print(void) const; 88301e04c3fSmrg 88401e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 88501e04c3fSmrg struct _mesa_glsl_parse_state *state); 88601e04c3fSmrg 88701e04c3fSmrg const char *name; 88801e04c3fSmrg ast_type_qualifier *layout; 88901e04c3fSmrg /* List of ast_declarator_list * */ 89001e04c3fSmrg exec_list declarations; 89101e04c3fSmrg bool is_declaration; 89201e04c3fSmrg const glsl_type *type; 89301e04c3fSmrg}; 89401e04c3fSmrg 89501e04c3fSmrg 89601e04c3fSmrg 89701e04c3fSmrgclass ast_type_specifier : public ast_node { 89801e04c3fSmrgpublic: 89901e04c3fSmrg /** Construct a type specifier from a type name */ 90001e04c3fSmrg ast_type_specifier(const char *name) 90101e04c3fSmrg : type(NULL), type_name(name), structure(NULL), array_specifier(NULL), 90201e04c3fSmrg default_precision(ast_precision_none) 90301e04c3fSmrg { 90401e04c3fSmrg /* empty */ 90501e04c3fSmrg } 90601e04c3fSmrg 90701e04c3fSmrg /** Construct a type specifier from a structure definition */ 90801e04c3fSmrg ast_type_specifier(ast_struct_specifier *s) 90901e04c3fSmrg : type(NULL), type_name(s->name), structure(s), array_specifier(NULL), 91001e04c3fSmrg default_precision(ast_precision_none) 91101e04c3fSmrg { 91201e04c3fSmrg /* empty */ 91301e04c3fSmrg } 91401e04c3fSmrg 91501e04c3fSmrg ast_type_specifier(const glsl_type *t) 91601e04c3fSmrg : type(t), type_name(t->name), structure(NULL), array_specifier(NULL), 91701e04c3fSmrg default_precision(ast_precision_none) 91801e04c3fSmrg { 91901e04c3fSmrg /* empty */ 92001e04c3fSmrg } 92101e04c3fSmrg 92201e04c3fSmrg const struct glsl_type *glsl_type(const char **name, 92301e04c3fSmrg struct _mesa_glsl_parse_state *state) 92401e04c3fSmrg const; 92501e04c3fSmrg 92601e04c3fSmrg virtual void print(void) const; 92701e04c3fSmrg 92801e04c3fSmrg ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *); 92901e04c3fSmrg 93001e04c3fSmrg const struct glsl_type *type; 93101e04c3fSmrg const char *type_name; 93201e04c3fSmrg ast_struct_specifier *structure; 93301e04c3fSmrg 93401e04c3fSmrg ast_array_specifier *array_specifier; 93501e04c3fSmrg 93601e04c3fSmrg /** For precision statements, this is the given precision; otherwise none. */ 93701e04c3fSmrg unsigned default_precision:2; 93801e04c3fSmrg}; 93901e04c3fSmrg 94001e04c3fSmrg 94101e04c3fSmrgclass ast_fully_specified_type : public ast_node { 94201e04c3fSmrgpublic: 94301e04c3fSmrg virtual void print(void) const; 94401e04c3fSmrg bool has_qualifiers(_mesa_glsl_parse_state *state) const; 94501e04c3fSmrg 94601e04c3fSmrg ast_fully_specified_type() : qualifier(), specifier(NULL) 94701e04c3fSmrg { 94801e04c3fSmrg } 94901e04c3fSmrg 95001e04c3fSmrg const struct glsl_type *glsl_type(const char **name, 95101e04c3fSmrg struct _mesa_glsl_parse_state *state) 95201e04c3fSmrg const; 95301e04c3fSmrg 95401e04c3fSmrg ast_type_qualifier qualifier; 95501e04c3fSmrg ast_type_specifier *specifier; 95601e04c3fSmrg}; 95701e04c3fSmrg 95801e04c3fSmrg 95901e04c3fSmrgclass ast_declarator_list : public ast_node { 96001e04c3fSmrgpublic: 96101e04c3fSmrg ast_declarator_list(ast_fully_specified_type *); 96201e04c3fSmrg virtual void print(void) const; 96301e04c3fSmrg 96401e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 96501e04c3fSmrg struct _mesa_glsl_parse_state *state); 96601e04c3fSmrg 96701e04c3fSmrg ast_fully_specified_type *type; 96801e04c3fSmrg /** List of 'ast_declaration *' */ 96901e04c3fSmrg exec_list declarations; 97001e04c3fSmrg 97101e04c3fSmrg /** 97201e04c3fSmrg * Flags for redeclarations. In these cases, no type is specified, to 97301e04c3fSmrg * `type` is allowed to be NULL. In all other cases, this would be an error. 97401e04c3fSmrg */ 97501e04c3fSmrg int invariant; /** < `invariant` redeclaration */ 97601e04c3fSmrg int precise; /** < `precise` redeclaration */ 97701e04c3fSmrg}; 97801e04c3fSmrg 97901e04c3fSmrg 98001e04c3fSmrgclass ast_parameter_declarator : public ast_node { 98101e04c3fSmrgpublic: 98201e04c3fSmrg ast_parameter_declarator() : 98301e04c3fSmrg type(NULL), 98401e04c3fSmrg identifier(NULL), 98501e04c3fSmrg array_specifier(NULL), 98601e04c3fSmrg formal_parameter(false), 98701e04c3fSmrg is_void(false) 98801e04c3fSmrg { 98901e04c3fSmrg /* empty */ 99001e04c3fSmrg } 99101e04c3fSmrg 99201e04c3fSmrg virtual void print(void) const; 99301e04c3fSmrg 99401e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 99501e04c3fSmrg struct _mesa_glsl_parse_state *state); 99601e04c3fSmrg 99701e04c3fSmrg ast_fully_specified_type *type; 99801e04c3fSmrg const char *identifier; 99901e04c3fSmrg ast_array_specifier *array_specifier; 100001e04c3fSmrg 100101e04c3fSmrg static void parameters_to_hir(exec_list *ast_parameters, 100201e04c3fSmrg bool formal, exec_list *ir_parameters, 100301e04c3fSmrg struct _mesa_glsl_parse_state *state); 100401e04c3fSmrg 100501e04c3fSmrgprivate: 100601e04c3fSmrg /** Is this parameter declaration part of a formal parameter list? */ 100701e04c3fSmrg bool formal_parameter; 100801e04c3fSmrg 100901e04c3fSmrg /** 101001e04c3fSmrg * Is this parameter 'void' type? 101101e04c3fSmrg * 101201e04c3fSmrg * This field is set by \c ::hir. 101301e04c3fSmrg */ 101401e04c3fSmrg bool is_void; 101501e04c3fSmrg}; 101601e04c3fSmrg 101701e04c3fSmrg 101801e04c3fSmrgclass ast_function : public ast_node { 101901e04c3fSmrgpublic: 102001e04c3fSmrg ast_function(void); 102101e04c3fSmrg 102201e04c3fSmrg virtual void print(void) const; 102301e04c3fSmrg 102401e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 102501e04c3fSmrg struct _mesa_glsl_parse_state *state); 102601e04c3fSmrg 102701e04c3fSmrg ast_fully_specified_type *return_type; 102801e04c3fSmrg const char *identifier; 102901e04c3fSmrg 103001e04c3fSmrg exec_list parameters; 103101e04c3fSmrg 103201e04c3fSmrgprivate: 103301e04c3fSmrg /** 103401e04c3fSmrg * Is this prototype part of the function definition? 103501e04c3fSmrg * 103601e04c3fSmrg * Used by ast_function_definition::hir to process the parameters, etc. 103701e04c3fSmrg * of the function. 103801e04c3fSmrg * 103901e04c3fSmrg * \sa ::hir 104001e04c3fSmrg */ 104101e04c3fSmrg bool is_definition; 104201e04c3fSmrg 104301e04c3fSmrg /** 104401e04c3fSmrg * Function signature corresponding to this function prototype instance 104501e04c3fSmrg * 104601e04c3fSmrg * Used by ast_function_definition::hir to process the parameters, etc. 104701e04c3fSmrg * of the function. 104801e04c3fSmrg * 104901e04c3fSmrg * \sa ::hir 105001e04c3fSmrg */ 105101e04c3fSmrg class ir_function_signature *signature; 105201e04c3fSmrg 105301e04c3fSmrg friend class ast_function_definition; 105401e04c3fSmrg}; 105501e04c3fSmrg 105601e04c3fSmrg 105701e04c3fSmrgclass ast_expression_statement : public ast_node { 105801e04c3fSmrgpublic: 105901e04c3fSmrg ast_expression_statement(ast_expression *); 106001e04c3fSmrg virtual void print(void) const; 106101e04c3fSmrg 106201e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 106301e04c3fSmrg struct _mesa_glsl_parse_state *state); 106401e04c3fSmrg 106501e04c3fSmrg ast_expression *expression; 106601e04c3fSmrg}; 106701e04c3fSmrg 106801e04c3fSmrg 106901e04c3fSmrgclass ast_case_label : public ast_node { 107001e04c3fSmrgpublic: 107101e04c3fSmrg ast_case_label(ast_expression *test_value); 107201e04c3fSmrg virtual void print(void) const; 107301e04c3fSmrg 107401e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 107501e04c3fSmrg struct _mesa_glsl_parse_state *state); 107601e04c3fSmrg 107701e04c3fSmrg /** 107801e04c3fSmrg * An test value of NULL means 'default'. 107901e04c3fSmrg */ 108001e04c3fSmrg ast_expression *test_value; 108101e04c3fSmrg}; 108201e04c3fSmrg 108301e04c3fSmrg 108401e04c3fSmrgclass ast_case_label_list : public ast_node { 108501e04c3fSmrgpublic: 108601e04c3fSmrg ast_case_label_list(void); 108701e04c3fSmrg virtual void print(void) const; 108801e04c3fSmrg 108901e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 109001e04c3fSmrg struct _mesa_glsl_parse_state *state); 109101e04c3fSmrg 109201e04c3fSmrg /** 109301e04c3fSmrg * A list of case labels. 109401e04c3fSmrg */ 109501e04c3fSmrg exec_list labels; 109601e04c3fSmrg}; 109701e04c3fSmrg 109801e04c3fSmrg 109901e04c3fSmrgclass ast_case_statement : public ast_node { 110001e04c3fSmrgpublic: 110101e04c3fSmrg ast_case_statement(ast_case_label_list *labels); 110201e04c3fSmrg virtual void print(void) const; 110301e04c3fSmrg 110401e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 110501e04c3fSmrg struct _mesa_glsl_parse_state *state); 110601e04c3fSmrg 110701e04c3fSmrg ast_case_label_list *labels; 110801e04c3fSmrg 110901e04c3fSmrg /** 111001e04c3fSmrg * A list of statements. 111101e04c3fSmrg */ 111201e04c3fSmrg exec_list stmts; 111301e04c3fSmrg}; 111401e04c3fSmrg 111501e04c3fSmrg 111601e04c3fSmrgclass ast_case_statement_list : public ast_node { 111701e04c3fSmrgpublic: 111801e04c3fSmrg ast_case_statement_list(void); 111901e04c3fSmrg virtual void print(void) const; 112001e04c3fSmrg 112101e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 112201e04c3fSmrg struct _mesa_glsl_parse_state *state); 112301e04c3fSmrg 112401e04c3fSmrg /** 112501e04c3fSmrg * A list of cases. 112601e04c3fSmrg */ 112701e04c3fSmrg exec_list cases; 112801e04c3fSmrg}; 112901e04c3fSmrg 113001e04c3fSmrg 113101e04c3fSmrgclass ast_switch_body : public ast_node { 113201e04c3fSmrgpublic: 113301e04c3fSmrg ast_switch_body(ast_case_statement_list *stmts); 113401e04c3fSmrg virtual void print(void) const; 113501e04c3fSmrg 113601e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 113701e04c3fSmrg struct _mesa_glsl_parse_state *state); 113801e04c3fSmrg 113901e04c3fSmrg ast_case_statement_list *stmts; 114001e04c3fSmrg}; 114101e04c3fSmrg 114201e04c3fSmrg 114301e04c3fSmrgclass ast_selection_statement : public ast_node { 114401e04c3fSmrgpublic: 114501e04c3fSmrg ast_selection_statement(ast_expression *condition, 114601e04c3fSmrg ast_node *then_statement, 114701e04c3fSmrg ast_node *else_statement); 114801e04c3fSmrg virtual void print(void) const; 114901e04c3fSmrg 115001e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 115101e04c3fSmrg struct _mesa_glsl_parse_state *state); 115201e04c3fSmrg 115301e04c3fSmrg ast_expression *condition; 115401e04c3fSmrg ast_node *then_statement; 115501e04c3fSmrg ast_node *else_statement; 115601e04c3fSmrg}; 115701e04c3fSmrg 115801e04c3fSmrg 115901e04c3fSmrgclass ast_switch_statement : public ast_node { 116001e04c3fSmrgpublic: 116101e04c3fSmrg ast_switch_statement(ast_expression *test_expression, 116201e04c3fSmrg ast_node *body); 116301e04c3fSmrg virtual void print(void) const; 116401e04c3fSmrg 116501e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 116601e04c3fSmrg struct _mesa_glsl_parse_state *state); 116701e04c3fSmrg 116801e04c3fSmrg ast_expression *test_expression; 116901e04c3fSmrg ast_node *body; 117001e04c3fSmrg 117101e04c3fSmrgprotected: 117201e04c3fSmrg void test_to_hir(exec_list *, struct _mesa_glsl_parse_state *); 11737ec681f3Smrg void eval_test_expression(exec_list *instructions, 11747ec681f3Smrg struct _mesa_glsl_parse_state *state); 11757ec681f3Smrg ir_rvalue *test_val; 117601e04c3fSmrg}; 117701e04c3fSmrg 117801e04c3fSmrgclass ast_iteration_statement : public ast_node { 117901e04c3fSmrgpublic: 118001e04c3fSmrg ast_iteration_statement(int mode, ast_node *init, ast_node *condition, 118101e04c3fSmrg ast_expression *rest_expression, ast_node *body); 118201e04c3fSmrg 118301e04c3fSmrg virtual void print(void) const; 118401e04c3fSmrg 118501e04c3fSmrg virtual ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *); 118601e04c3fSmrg 118701e04c3fSmrg enum ast_iteration_modes { 118801e04c3fSmrg ast_for, 118901e04c3fSmrg ast_while, 119001e04c3fSmrg ast_do_while 119101e04c3fSmrg } mode; 119201e04c3fSmrg 119301e04c3fSmrg 119401e04c3fSmrg ast_node *init_statement; 119501e04c3fSmrg ast_node *condition; 119601e04c3fSmrg ast_expression *rest_expression; 119701e04c3fSmrg 11987ec681f3Smrg exec_list rest_instructions; 11997ec681f3Smrg 120001e04c3fSmrg ast_node *body; 120101e04c3fSmrg 120201e04c3fSmrg /** 120301e04c3fSmrg * Generate IR from the condition of a loop 120401e04c3fSmrg * 120501e04c3fSmrg * This is factored out of ::hir because some loops have the condition 120601e04c3fSmrg * test at the top (for and while), and others have it at the end (do-while). 120701e04c3fSmrg */ 120801e04c3fSmrg void condition_to_hir(exec_list *, struct _mesa_glsl_parse_state *); 120901e04c3fSmrg}; 121001e04c3fSmrg 121101e04c3fSmrg 121201e04c3fSmrgclass ast_jump_statement : public ast_node { 121301e04c3fSmrgpublic: 121401e04c3fSmrg ast_jump_statement(int mode, ast_expression *return_value); 121501e04c3fSmrg virtual void print(void) const; 121601e04c3fSmrg 121701e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 121801e04c3fSmrg struct _mesa_glsl_parse_state *state); 121901e04c3fSmrg 122001e04c3fSmrg enum ast_jump_modes { 122101e04c3fSmrg ast_continue, 122201e04c3fSmrg ast_break, 122301e04c3fSmrg ast_return, 122401e04c3fSmrg ast_discard 122501e04c3fSmrg } mode; 122601e04c3fSmrg 122701e04c3fSmrg ast_expression *opt_return_value; 122801e04c3fSmrg}; 122901e04c3fSmrg 123001e04c3fSmrg 12317ec681f3Smrgclass ast_demote_statement : public ast_node { 12327ec681f3Smrgpublic: 12337ec681f3Smrg ast_demote_statement(void) {} 12347ec681f3Smrg virtual void print(void) const; 12357ec681f3Smrg 12367ec681f3Smrg virtual ir_rvalue *hir(exec_list *instructions, 12377ec681f3Smrg struct _mesa_glsl_parse_state *state); 12387ec681f3Smrg}; 12397ec681f3Smrg 12407ec681f3Smrg 124101e04c3fSmrgclass ast_function_definition : public ast_node { 124201e04c3fSmrgpublic: 124301e04c3fSmrg ast_function_definition() : prototype(NULL), body(NULL) 124401e04c3fSmrg { 124501e04c3fSmrg } 124601e04c3fSmrg 124701e04c3fSmrg virtual void print(void) const; 124801e04c3fSmrg 124901e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 125001e04c3fSmrg struct _mesa_glsl_parse_state *state); 125101e04c3fSmrg 125201e04c3fSmrg ast_function *prototype; 125301e04c3fSmrg ast_compound_statement *body; 125401e04c3fSmrg}; 125501e04c3fSmrg 125601e04c3fSmrgclass ast_interface_block : public ast_node { 125701e04c3fSmrgpublic: 125801e04c3fSmrg ast_interface_block(const char *instance_name, 125901e04c3fSmrg ast_array_specifier *array_specifier) 126001e04c3fSmrg : block_name(NULL), instance_name(instance_name), 126101e04c3fSmrg array_specifier(array_specifier) 126201e04c3fSmrg { 126301e04c3fSmrg } 126401e04c3fSmrg 126501e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 126601e04c3fSmrg struct _mesa_glsl_parse_state *state); 126701e04c3fSmrg 126801e04c3fSmrg ast_type_qualifier default_layout; 126901e04c3fSmrg ast_type_qualifier layout; 127001e04c3fSmrg const char *block_name; 127101e04c3fSmrg 127201e04c3fSmrg /** 127301e04c3fSmrg * Declared name of the block instance, if specified. 127401e04c3fSmrg * 127501e04c3fSmrg * If the block does not have an instance name, this field will be 127601e04c3fSmrg * \c NULL. 127701e04c3fSmrg */ 127801e04c3fSmrg const char *instance_name; 127901e04c3fSmrg 128001e04c3fSmrg /** List of ast_declarator_list * */ 128101e04c3fSmrg exec_list declarations; 128201e04c3fSmrg 128301e04c3fSmrg /** 128401e04c3fSmrg * Declared array size of the block instance 128501e04c3fSmrg * 128601e04c3fSmrg * If the block is not declared as an array or if the block instance array 128701e04c3fSmrg * is unsized, this field will be \c NULL. 128801e04c3fSmrg */ 128901e04c3fSmrg ast_array_specifier *array_specifier; 129001e04c3fSmrg}; 129101e04c3fSmrg 129201e04c3fSmrg 129301e04c3fSmrg/** 129401e04c3fSmrg * AST node representing a declaration of the output layout for tessellation 129501e04c3fSmrg * control shaders. 129601e04c3fSmrg */ 129701e04c3fSmrgclass ast_tcs_output_layout : public ast_node 129801e04c3fSmrg{ 129901e04c3fSmrgpublic: 130001e04c3fSmrg ast_tcs_output_layout(const struct YYLTYPE &locp) 130101e04c3fSmrg { 130201e04c3fSmrg set_location(locp); 130301e04c3fSmrg } 130401e04c3fSmrg 130501e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 130601e04c3fSmrg struct _mesa_glsl_parse_state *state); 130701e04c3fSmrg}; 130801e04c3fSmrg 130901e04c3fSmrg 131001e04c3fSmrg/** 131101e04c3fSmrg * AST node representing a declaration of the input layout for geometry 131201e04c3fSmrg * shaders. 131301e04c3fSmrg */ 131401e04c3fSmrgclass ast_gs_input_layout : public ast_node 131501e04c3fSmrg{ 131601e04c3fSmrgpublic: 131701e04c3fSmrg ast_gs_input_layout(const struct YYLTYPE &locp, GLenum prim_type) 131801e04c3fSmrg : prim_type(prim_type) 131901e04c3fSmrg { 132001e04c3fSmrg set_location(locp); 132101e04c3fSmrg } 132201e04c3fSmrg 132301e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 132401e04c3fSmrg struct _mesa_glsl_parse_state *state); 132501e04c3fSmrg 132601e04c3fSmrgprivate: 132701e04c3fSmrg const GLenum prim_type; 132801e04c3fSmrg}; 132901e04c3fSmrg 133001e04c3fSmrg 133101e04c3fSmrg/** 133201e04c3fSmrg * AST node representing a decalaration of the input layout for compute 133301e04c3fSmrg * shaders. 133401e04c3fSmrg */ 133501e04c3fSmrgclass ast_cs_input_layout : public ast_node 133601e04c3fSmrg{ 133701e04c3fSmrgpublic: 133801e04c3fSmrg ast_cs_input_layout(const struct YYLTYPE &locp, 133901e04c3fSmrg ast_layout_expression *const *local_size) 134001e04c3fSmrg { 134101e04c3fSmrg for (int i = 0; i < 3; i++) { 134201e04c3fSmrg this->local_size[i] = local_size[i]; 134301e04c3fSmrg } 134401e04c3fSmrg set_location(locp); 134501e04c3fSmrg } 134601e04c3fSmrg 134701e04c3fSmrg virtual ir_rvalue *hir(exec_list *instructions, 134801e04c3fSmrg struct _mesa_glsl_parse_state *state); 134901e04c3fSmrg 135001e04c3fSmrgprivate: 135101e04c3fSmrg ast_layout_expression *local_size[3]; 135201e04c3fSmrg}; 135301e04c3fSmrg 1354ed98bd31Smayaclass ast_warnings_toggle : public ast_node { 1355ed98bd31Smayapublic: 1356ed98bd31Smaya ast_warnings_toggle(bool _enable) 1357ed98bd31Smaya : enable(_enable) 1358ed98bd31Smaya { 1359ed98bd31Smaya /* empty */ 1360ed98bd31Smaya } 1361ed98bd31Smaya 1362ed98bd31Smaya virtual ir_rvalue *hir(exec_list *instructions, 1363ed98bd31Smaya struct _mesa_glsl_parse_state *state); 1364ed98bd31Smaya 1365ed98bd31Smayaprivate: 1366ed98bd31Smaya bool enable; 1367ed98bd31Smaya}; 136801e04c3fSmrg/*@}*/ 136901e04c3fSmrg 137001e04c3fSmrgextern void 137101e04c3fSmrg_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state); 137201e04c3fSmrg 137301e04c3fSmrgextern ir_rvalue * 137401e04c3fSmrg_mesa_ast_field_selection_to_hir(const ast_expression *expr, 137501e04c3fSmrg exec_list *instructions, 137601e04c3fSmrg struct _mesa_glsl_parse_state *state); 137701e04c3fSmrg 137801e04c3fSmrgextern ir_rvalue * 137901e04c3fSmrg_mesa_ast_array_index_to_hir(void *mem_ctx, 138001e04c3fSmrg struct _mesa_glsl_parse_state *state, 138101e04c3fSmrg ir_rvalue *array, ir_rvalue *idx, 138201e04c3fSmrg YYLTYPE &loc, YYLTYPE &idx_loc); 138301e04c3fSmrg 138401e04c3fSmrgextern void 138501e04c3fSmrg_mesa_ast_set_aggregate_type(const glsl_type *type, 138601e04c3fSmrg ast_expression *expr); 138701e04c3fSmrg 138801e04c3fSmrgvoid 138901e04c3fSmrgemit_function(_mesa_glsl_parse_state *state, ir_function *f); 139001e04c3fSmrg 139101e04c3fSmrgextern void 139201e04c3fSmrgcheck_builtin_array_max_size(const char *name, unsigned size, 139301e04c3fSmrg YYLTYPE loc, struct _mesa_glsl_parse_state *state); 139401e04c3fSmrg 139501e04c3fSmrgextern void _mesa_ast_process_interface_block(YYLTYPE *locp, 139601e04c3fSmrg _mesa_glsl_parse_state *state, 139701e04c3fSmrg ast_interface_block *const block, 139801e04c3fSmrg const struct ast_type_qualifier &q); 139901e04c3fSmrg 140001e04c3fSmrgextern bool 140101e04c3fSmrgprocess_qualifier_constant(struct _mesa_glsl_parse_state *state, 140201e04c3fSmrg YYLTYPE *loc, 140301e04c3fSmrg const char *qual_indentifier, 140401e04c3fSmrg ast_expression *const_expression, 140501e04c3fSmrg unsigned *value); 140601e04c3fSmrg#endif /* AST_H */ 1407