#ifndef AST_H
#define AST_H
-#include "main/simple_list.h"
#include "list.h"
#include "glsl_parser_extras.h"
struct YYLTYPE;
-class ast_node : public simple_node {
+class ast_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
*
* \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;
unsigned column;
} location;
+ exec_node link;
+
protected:
ast_node(void);
};
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;
/**
- * List of expressions for an \c ast_sequence.
+ * List of expressions for an \c ast_sequence or parameters for an
+ * \c ast_function_call
*/
- struct simple_node expressions;
+ exec_list expressions;
};
class ast_expression_bin : public ast_expression {
*/
class ast_function_expression : public ast_expression {
public:
- ast_function_expression(ast_node *callee)
- : ast_expression(ast_function_call, (ast_expression *) callee,
- NULL, NULL)
+ 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 */
+ }
- virtual ir_instruction *hir(exec_list *instructions,
- struct _mesa_glsl_parse_state *state);
+ 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;
};
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;
+ exec_list statements;
};
class ast_declaration : public ast_node {
ast_struct_specifier(char *identifier, ast_node *declarator_list);
virtual void print(void) const;
+ virtual ir_rvalue *hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state);
+
char *name;
- struct simple_node declarations;
+ exec_list declarations;
};
ast_mat4,
ast_sampler1d,
ast_sampler2d,
+ ast_sampler2drect,
ast_sampler3d,
ast_samplercube,
ast_sampler1dshadow,
ast_sampler2dshadow,
+ ast_sampler2drectshadow,
ast_samplercubeshadow,
ast_sampler1darray,
ast_sampler2darray,
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;
+ ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
+
enum ast_types type_specifier;
- char *type_name;
+ const char *type_name;
ast_struct_specifier *structure;
int is_array;
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;
+ exec_list declarations;
/**
* Special flag for vertex shader "invariant" declarations.
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(exec_list *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;
};
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;
+ exec_list 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;
};
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;
};
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;
class ast_switch_statement : public ast_node {
public:
ast_expression *expression;
- struct simple_node statements;
+ exec_list statements;
};
class ast_iteration_statement : public ast_node {
virtual void print(void) const;
+ virtual ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
+
enum ast_iteration_modes {
ast_for,
ast_while,
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 *);
};
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,
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 void
_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state);
-extern struct ir_instruction *
+extern struct ir_rvalue *
_mesa_ast_field_selection_to_hir(const struct ast_expression *expr,
exec_list *instructions,
struct _mesa_glsl_parse_state *state);