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
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;
return cons;
}
- 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);
private:
/**
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;
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;
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;
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_jump_statement(int mode, ast_expression *return_value);
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);
enum ast_jump_modes {
ast_continue,
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);
#include "glsl_types.h"
#include "ir.h"
-static ir_instruction *
+static ir_rvalue *
match_function_by_name(exec_list *instructions, const char *name,
YYLTYPE *loc, simple_node *parameters,
struct _mesa_glsl_parse_state *state)
}
-ir_instruction *
+ir_rvalue *
ast_function_expression::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
* In addition to being used for assignments, this function is used to
* type-check return values.
*/
-ir_instruction *
-validate_assignment(const glsl_type *lhs_type, ir_instruction *rhs)
+ir_rvalue *
+validate_assignment(const glsl_type *lhs_type, ir_rvalue *rhs)
{
const glsl_type *const rhs_type = rhs->type;
}
-ir_instruction *
+ir_rvalue *
ast_node::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
}
-ir_instruction *
+ir_rvalue *
ast_expression::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
-1, /* ast_bool_constant doesn't conv to ir_expression. */
-1, /* ast_sequence doesn't convert to ir_expression. */
};
- ir_instruction *result = NULL;
- ir_instruction *op[2];
+ ir_rvalue *result = NULL;
+ ir_rvalue *op[2];
struct simple_node op_list;
const struct glsl_type *type = glsl_error_type;
bool error_emitted = false;
case ast_div_assign:
case ast_add_assign:
case ast_sub_assign: {
- struct ir_instruction *temp_rhs;
-
op[0] = this->subexpressions[0]->hir(instructions, state);
op[1] = this->subexpressions[1]->hir(instructions, state);
(this->oper == ast_mul_assign),
state);
- temp_rhs = new ir_expression(operations[this->oper], type,
- op[0], op[1]);
+ ir_rvalue *temp_rhs = new ir_expression(operations[this->oper], type,
+ op[0], op[1]);
/* FINISHME: This is copied from ast_assign above. It should
* FINISHME: probably be consolidated.
}
}
- ir_instruction *rhs = validate_assignment(op[0]->type, temp_rhs);
+ ir_rvalue *rhs = validate_assignment(op[0]->type, temp_rhs);
if (rhs == NULL) {
type = glsl_error_type;
rhs = temp_rhs;
}
-ir_instruction *
+ir_rvalue *
ast_expression_statement::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
}
-ir_instruction *
+ir_rvalue *
ast_compound_statement::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
}
-ir_instruction *
+ir_rvalue *
ast_declarator_list::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
}
-ir_instruction *
+ir_rvalue *
ast_parameter_declarator::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
}
-ir_instruction *
+ir_rvalue *
ast_function_definition::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
}
-ir_instruction *
+ir_rvalue *
ast_jump_statement::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
retval->set_swizzle(0, 0, 0, 0, declarations[16]->type->vector_elements);
- inst = new ir_return((ir_expression *) retval);
+ inst = new ir_return(retval);
instructions->push_tail(inst);
}
ir_dereference *retval = new ir_dereference(declarations[16]);
- inst = new ir_return((ir_expression *) retval);
+ inst = new ir_return(retval);
instructions->push_tail(inst);
}
}
ir_dereference *const retval = new ir_dereference(declarations[16]);
- inst = new ir_return((ir_expression *) retval);
+ inst = new ir_return(retval);
instructions->push_tail(inst);
}
ir_dereference *retval = new ir_dereference(declarations[16]);
- inst = new ir_return((ir_expression *) retval);
+ inst = new ir_return(retval);
instructions->push_tail(inst);
}
}
-struct ir_instruction *
+struct ir_rvalue *
_mesa_ast_field_selection_to_hir(const ast_expression *expr,
exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
- ir_instruction *op;
+ ir_rvalue *op;
ir_dereference *deref;
YYLTYPE loc;
* now. Doing so prevents spurious error messages from being logged below.
*/
if (is_error_type(op->type))
- return (struct ir_instruction *) deref;
+ return deref;
/* There are two kinds of field selection. There is the selection of a
* specific field from a structure, and there is the selection of a
expr->primary_expression.identifier);
}
- return (struct ir_instruction *) deref;
+ return deref;
}
#include "ir.h"
#include "glsl_types.h"
-ir_assignment::ir_assignment(ir_instruction *lhs, ir_instruction *rhs,
- ir_expression *condition)
- : ir_instruction()
+ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs,
+ ir_rvalue *condition)
+ : ir_rvalue()
{
- this->lhs = (ir_dereference *) lhs;
+ this->lhs = lhs;
this->rhs = rhs;
this->condition = condition;
}
ir_expression::ir_expression(int op, const struct glsl_type *type,
- ir_instruction *op0, ir_instruction *op1)
- : ir_instruction()
+ ir_rvalue *op0, ir_rvalue *op1)
+ : ir_rvalue()
{
this->type = type;
this->operation = ir_expression_operation(op);
ir_constant::ir_constant(const struct glsl_type *type, const void *data)
- : ir_instruction()
+ : ir_rvalue()
{
const unsigned elements =
((type->vector_elements == 0) ? 1 : type->vector_elements)
ir_dereference::ir_dereference(ir_instruction *var)
- : ir_instruction()
+ : ir_rvalue()
{
this->mode = ir_reference_variable;
this->var = var;
ir_dereference::ir_dereference(ir_instruction *var,
- ir_instruction *array_index)
- : ir_instruction(), mode(ir_reference_array),
+ ir_rvalue *array_index)
+ : ir_rvalue(), mode(ir_reference_array),
var(var)
{
this->type = (var != NULL) ? var->type : glsl_error_type;
/*@{*/
virtual class ir_variable * as_variable() { return NULL; }
virtual class ir_dereference * as_dereference() { return NULL; }
+ virtual class ir_rvalue * as_rvalue() { return NULL; }
/*@}*/
protected:
};
+class ir_rvalue : public ir_instruction {
+public:
+ virtual ir_rvalue * as_rvalue()
+ {
+ return this;
+ }
+
+ virtual bool is_lvalue()
+ {
+ return false;
+ }
+
+protected:
+ ir_rvalue() : ir_instruction() { }
+};
+
+
enum ir_variable_mode {
ir_var_auto = 0,
ir_var_uniform,
ir_var_noperspective
};
+
class ir_variable : public ir_instruction {
public:
ir_variable(const struct glsl_type *, const char *);
/*@}*/
-class ir_assignment : public ir_instruction {
+class ir_assignment : public ir_rvalue {
public:
- ir_assignment(ir_instruction *lhs, ir_instruction *rhs,
- ir_expression *condition);
+ ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition);
virtual void accept(ir_visitor *v)
{
/**
* Left-hand side of the assignment.
*/
- ir_dereference *lhs;
+ ir_rvalue *lhs;
/**
* Value being assigned
- *
- * This should be either \c ir_op_expression or \c ir_op_dereference.
*/
- ir_instruction *rhs;
+ ir_rvalue *rhs;
/**
* Optional condition for the assignment.
*/
- ir_expression *condition;
+ ir_rvalue *condition;
};
ir_binop_pow
};
-class ir_expression : public ir_instruction {
+class ir_expression : public ir_rvalue {
public:
ir_expression(int op, const struct glsl_type *type,
- ir_instruction *, ir_instruction *);
+ ir_rvalue *, ir_rvalue *);
virtual void accept(ir_visitor *v)
{
}
ir_expression_operation operation;
- ir_instruction *operands[2];
+ ir_rvalue *operands[2];
};
/**
* IR instruction representing a function call
*/
-class ir_call : public ir_instruction {
+class ir_call : public ir_rvalue {
public:
ir_call(const ir_function_signature *callee, exec_list *actual_parameters)
- : ir_instruction(), callee(callee)
+ : ir_rvalue(), callee(callee)
{
assert(callee->return_type != NULL);
type = callee->return_type;
private:
ir_call()
- : ir_instruction(), callee(NULL)
+ : ir_rvalue(), callee(NULL)
{
/* empty */
}
/* empty */
}
- ir_return(ir_expression *value)
+ ir_return(ir_rvalue *value)
: value(value)
{
/* empty */
}
- ir_expression *get_value() const
+ ir_rvalue *get_value() const
{
return value;
}
}
private:
- ir_expression *value;
+ ir_rvalue *value;
};
/*@}*/
unsigned has_duplicates:1;
};
-class ir_dereference : public ir_instruction {
+class ir_dereference : public ir_rvalue {
public:
ir_dereference(struct ir_instruction *);
- ir_dereference(ir_instruction *variable, ir_instruction *array_index);
+ ir_dereference(ir_instruction *variable, ir_rvalue *array_index);
virtual ir_dereference *as_dereference()
{
v->visit(this);
}
+ bool is_lvalue()
+ {
+ return var != NULL;
+ }
+
/**
* Setting the swizzle of a derefernce
*/
/**
* Object being dereferenced.
*
- * Must be either an \c ir_variable or an \c ir_dereference.
+ * Must be either an \c ir_variable or an \c ir_rvalue.
*/
ir_instruction *var;
union {
- ir_instruction *array_index;
+ ir_rvalue *array_index;
const char *field;
struct ir_swizzle_mask swizzle;
} selector;
};
-class ir_constant : public ir_instruction {
+class ir_constant : public ir_rvalue {
public:
ir_constant(const struct glsl_type *type, const void *data);
{
printf("(return");
- ir_expression *const value = ir->get_value();
+ ir_rvalue *const value = ir->get_value();
if (value) {
printf(" ");
value->accept(this);