X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=ast.h;h=d899fb1d090a831a98bc90e49f940066668af239;hb=8d3e59f1f399d7c1f7604779f1d62e876c609d9e;hp=fa84a915749c0dcf09b937c76f59696fffd7c6b4;hpb=0044e7edcea22d2456c051a1c4b744a26960ad27;p=mesa.git diff --git a/ast.h b/ast.h index fa84a915749..d899fb1d090 100644 --- a/ast.h +++ b/ast.h @@ -1,3 +1,4 @@ +/* -*- c++ -*- */ /* * Copyright © 2009 Intel Corporation * @@ -38,8 +39,8 @@ class ast_node : public simple_node { public: virtual ~ast_node(); virtual void print(void) const; - virtual ir_instruction *hir(exec_list *instructions, - struct _mesa_glsl_parse_state *state); + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); /** * Retrieve the source location of an AST node @@ -67,16 +68,13 @@ public: * * \sa ast_node::get_location */ - void set_location(const struct YYLTYPE *locp) + void set_location(const struct YYLTYPE &locp) { - this->location.source = locp->source; - this->location.line = locp->first_line; - this->location.column = locp->first_column; + this->location.source = locp.source; + this->location.line = locp.first_line; + this->location.column = locp.first_column; } - - int type; - struct { unsigned source; unsigned line; @@ -150,10 +148,19 @@ public: ast_expression(int oper, ast_expression *, ast_expression *, ast_expression *); + ast_expression(const char *identifier) : + oper(ast_identifier) + { + subexpressions[0] = NULL; + subexpressions[1] = NULL; + subexpressions[2] = NULL; + primary_expression.identifier = (char *) identifier; + } + static const char *operator_string(enum ast_operators op); - virtual ir_instruction *hir(exec_list *instructions, - struct _mesa_glsl_parse_state *state); + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); virtual void print(void) const; @@ -183,6 +190,42 @@ public: virtual void print(void) const; }; +/** + * Subclass of expressions for function calls + */ +class ast_function_expression : public ast_expression { +public: + ast_function_expression(ast_expression *callee) + : ast_expression(ast_function_call, callee, + NULL, NULL), + cons(false) + { + /* empty */ + } + + ast_function_expression(class ast_type_specifier *type) + : ast_expression(ast_function_call, (ast_expression *) type, + NULL, NULL), + cons(true) + { + /* empty */ + } + + bool is_constructor() const + { + return cons; + } + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + +private: + /** + * Is this function call actually a constructor? + */ + bool cons; +}; + /** * Number of possible operators for an ast_expression @@ -199,8 +242,8 @@ public: ast_compound_statement(int new_scope, ast_node *statements); virtual void print(void) const; - virtual ir_instruction *hir(exec_list *instructions, - struct _mesa_glsl_parse_state *state); + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); int new_scope; struct simple_node statements; @@ -280,10 +323,12 @@ enum ast_types { ast_mat4, ast_sampler1d, ast_sampler2d, + ast_sampler2drect, ast_sampler3d, ast_samplercube, ast_sampler1dshadow, ast_sampler2dshadow, + ast_sampler2drectshadow, ast_samplercubeshadow, ast_sampler1darray, ast_sampler2darray, @@ -311,11 +356,31 @@ class ast_type_specifier : public ast_node { public: ast_type_specifier(int specifier); + /** Construct a type specifier from a type name */ + ast_type_specifier(const char *name) + : type_specifier(ast_type_name), type_name(name), structure(NULL), + is_array(false), array_size(NULL), precision(ast_precision_high) + { + /* empty */ + } + + /** Construct a type specifier from a structure definition */ + ast_type_specifier(ast_struct_specifier *s) + : type_specifier(ast_struct), type_name(s->name), structure(s), + is_array(false), array_size(NULL), precision(ast_precision_high) + { + /* empty */ + } + + const struct glsl_type *glsl_type(const char **name, + struct _mesa_glsl_parse_state *state) + const; + virtual void print(void) const; enum ast_types type_specifier; - char *type_name; + const char *type_name; ast_struct_specifier *structure; int is_array; @@ -339,8 +404,8 @@ public: ast_declarator_list(ast_fully_specified_type *); virtual void print(void) const; - virtual ir_instruction *hir(exec_list *instructions, - struct _mesa_glsl_parse_state *state); + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); ast_fully_specified_type *type; struct simple_node declarations; @@ -360,13 +425,28 @@ class ast_parameter_declarator : public ast_node { public: virtual void print(void) const; - virtual ir_instruction *hir(exec_list *instructions, - struct _mesa_glsl_parse_state *state); + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); ast_fully_specified_type *type; char *identifier; int is_array; ast_expression *array_size; + + static void parameters_to_hir(simple_node *ast_parameters, + bool formal, exec_list *ir_parameters, + struct _mesa_glsl_parse_state *state); + +private: + /** Is this parameter declaration part of a formal parameter list? */ + bool formal_parameter; + + /** + * Is this parameter 'void' type? + * + * This field is set by \c ::hir. + */ + bool is_void; }; @@ -376,10 +456,36 @@ public: virtual void print(void) const; + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + ast_fully_specified_type *return_type; char *identifier; struct simple_node parameters; + +private: + /** + * Is this prototype part of the function definition? + * + * Used by ast_function_definition::hir to process the parameters, etc. + * of the function. + * + * \sa ::hir + */ + bool is_definition; + + /** + * Function signature corresponding to this function prototype instance + * + * Used by ast_function_definition::hir to process the parameters, etc. + * of the function. + * + * \sa ::hir + */ + class ir_function_signature *signature; + + friend class ast_function_definition; }; @@ -407,8 +513,8 @@ public: ast_expression_statement(ast_expression *); virtual void print(void) const; - virtual ir_instruction *hir(exec_list *instructions, - struct _mesa_glsl_parse_state *state); + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); ast_expression *expression; }; @@ -430,6 +536,9 @@ public: ast_node *else_statement); virtual void print(void) const; + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + ast_expression *condition; ast_node *then_statement; ast_node *else_statement; @@ -449,6 +558,8 @@ public: virtual void print(void) const; + virtual ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *); + enum ast_iteration_modes { ast_for, ast_while, @@ -461,6 +572,15 @@ public: ast_expression *rest_expression; ast_node *body; + +private: + /** + * Generate IR from the condition of a loop + * + * This is factored out of ::hir because some loops have the condition + * test at the top (for and while), and others have it at the end (do-while). + */ + void condition_to_hir(class ir_loop *, struct _mesa_glsl_parse_state *); }; @@ -469,6 +589,9 @@ public: ast_jump_statement(int mode, ast_expression *return_value); virtual void print(void) const; + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + enum ast_jump_modes { ast_continue, ast_break, @@ -484,15 +607,18 @@ class ast_function_definition : public ast_node { public: virtual void print(void) const; - virtual ir_instruction *hir(exec_list *instructions, - struct _mesa_glsl_parse_state *state); + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); ast_function *prototype; ast_compound_statement *body; }; -extern struct ir_instruction * +extern void +_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state); + +extern struct ir_rvalue * _mesa_ast_field_selection_to_hir(const struct ast_expression *expr, exec_list *instructions, struct _mesa_glsl_parse_state *state);