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