diff options
author | Eric Anholt <[email protected]> | 2010-07-19 09:05:42 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2010-07-19 09:50:29 -0700 |
commit | d16044ad4d6176fec6164f96450a25f76b7677f1 (patch) | |
tree | 1e2eff035142a680d4996791cb24d0f6f75037cc /src/glsl | |
parent | ee7b2b3f44d09c2311887d3524e197b9738580a9 (diff) |
glsl2: Give IR nodes a type field.
This is a big deal for debugging if nothing else ("what class is this
ir_instruction, really?"), but is also nice for avoiding building a
whole visitor or an if (node->as_whatever() || node->as_other_thing())
chain.
Diffstat (limited to 'src/glsl')
-rw-r--r-- | src/glsl/ir.cpp | 23 | ||||
-rw-r--r-- | src/glsl/ir.h | 42 | ||||
-rw-r--r-- | src/glsl/ir_validate.cpp | 15 |
3 files changed, 70 insertions, 10 deletions
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 70905ddb80f..1648848ecb6 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -29,6 +29,7 @@ ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition) { + this->ir_type = ir_type_assignment; this->lhs = lhs; this->rhs = rhs; this->condition = condition; @@ -38,6 +39,7 @@ ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_expression::ir_expression(int op, const struct glsl_type *type, ir_rvalue *op0, ir_rvalue *op1) { + this->ir_type = ir_type_expression; this->type = type; this->operation = ir_expression_operation(op); this->operands[0] = op0; @@ -190,7 +192,7 @@ ir_expression::get_operator(const char *str) ir_constant::ir_constant() { - /* empty */ + this->ir_type = ir_type_constant; } ir_constant::ir_constant(const struct glsl_type *type, @@ -199,36 +201,42 @@ ir_constant::ir_constant(const struct glsl_type *type, assert((type->base_type >= GLSL_TYPE_UINT) && (type->base_type <= GLSL_TYPE_BOOL)); + this->ir_type = ir_type_constant; this->type = type; memcpy(& this->value, data, sizeof(this->value)); } ir_constant::ir_constant(float f) { + this->ir_type = ir_type_constant; this->type = glsl_type::float_type; this->value.f[0] = f; } ir_constant::ir_constant(unsigned int u) { + this->ir_type = ir_type_constant; this->type = glsl_type::uint_type; this->value.u[0] = u; } ir_constant::ir_constant(int i) { + this->ir_type = ir_type_constant; this->type = glsl_type::int_type; this->value.i[0] = i; } ir_constant::ir_constant(bool b) { + this->ir_type = ir_type_constant; this->type = glsl_type::bool_type; this->value.b[0] = b; } ir_constant::ir_constant(const ir_constant *c, unsigned i) { + this->ir_type = ir_type_constant; this->type = c->type->get_base_type(); switch (this->type->base_type) { @@ -242,6 +250,7 @@ ir_constant::ir_constant(const ir_constant *c, unsigned i) ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list) { + this->ir_type = ir_type_constant; this->type = type; /* FINISHME: Support array types. */ @@ -454,6 +463,7 @@ ir_constant::has_value(const ir_constant *c) const ir_dereference_variable::ir_dereference_variable(ir_variable *var) { + this->ir_type = ir_type_dereference_variable; this->var = var; this->type = (var != NULL) ? var->type : glsl_type::error_type; } @@ -462,6 +472,7 @@ ir_dereference_variable::ir_dereference_variable(ir_variable *var) ir_dereference_array::ir_dereference_array(ir_rvalue *value, ir_rvalue *array_index) { + this->ir_type = ir_type_dereference_array; this->array_index = array_index; this->set_array(value); } @@ -472,6 +483,7 @@ ir_dereference_array::ir_dereference_array(ir_variable *var, { void *ctx = talloc_parent(var); + this->ir_type = ir_type_dereference_array; this->array_index = array_index; this->set_array(new(ctx) ir_dereference_variable(var)); } @@ -500,6 +512,7 @@ ir_dereference_array::set_array(ir_rvalue *value) ir_dereference_record::ir_dereference_record(ir_rvalue *value, const char *field) { + this->ir_type = ir_type_dereference_record; this->record = value; this->field = field; this->type = (this->record != NULL) @@ -512,6 +525,7 @@ ir_dereference_record::ir_dereference_record(ir_variable *var, { void *ctx = talloc_parent(var); + this->ir_type = ir_type_dereference_record; this->record = new(ctx) ir_dereference_variable(var); this->field = field; this->type = (this->record != NULL) @@ -624,6 +638,7 @@ ir_swizzle::ir_swizzle(ir_rvalue *val, unsigned x, unsigned y, unsigned z, : val(val) { const unsigned components[4] = { x, y, z, w }; + this->ir_type = ir_type_swizzle; this->init_mask(components, count); } @@ -631,11 +646,13 @@ ir_swizzle::ir_swizzle(ir_rvalue *val, const unsigned *comp, unsigned count) : val(val) { + this->ir_type = ir_type_swizzle; this->init_mask(comp, count); } ir_swizzle::ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask) { + this->ir_type = ir_type_swizzle; this->val = val; this->mask = mask; this->type = glsl_type::get_instance(val->type->base_type, @@ -736,6 +753,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name) shader_in(false), shader_out(false), mode(ir_var_auto), interpolation(ir_var_smooth), array_lvalue(false) { + this->ir_type = ir_type_variable; this->type = type; this->name = talloc_strdup(this, name); this->location = -1; @@ -775,7 +793,7 @@ ir_variable::component_slots() const ir_function_signature::ir_function_signature(const glsl_type *return_type) : return_type(return_type), is_defined(false), _function(NULL) { - /* empty */ + this->ir_type = ir_type_function_signature; } @@ -825,6 +843,7 @@ ir_function_signature::replace_parameters(exec_list *new_params) ir_function::ir_function(const char *name) { + this->ir_type = ir_type_function; this->name = talloc_strdup(this, name); } diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 042da94d853..389fe243262 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -41,11 +41,34 @@ extern "C" { #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #endif +enum ir_node_type { + ir_type_unset, + ir_type_variable, + ir_type_assignment, + ir_type_call, + ir_type_constant, + ir_type_dereference_array, + ir_type_dereference_record, + ir_type_dereference_variable, + ir_type_discard, + ir_type_expression, + ir_type_function, + ir_type_function_signature, + ir_type_if, + ir_type_loop, + ir_type_loop_jump, + ir_type_return, + ir_type_swizzle, + ir_type_texture, + ir_type_max, /**< maximum ir_type enum number, for validation */ +}; + /** * Base class of all IR instructions */ class ir_instruction : public exec_node { public: + enum ir_node_type ir_type; const struct glsl_type *type; class ir_constant *constant_expression_value(); @@ -84,7 +107,7 @@ public: protected: ir_instruction() { - /* empty */ + ir_type = ir_type_unset; } }; @@ -410,7 +433,7 @@ public: ir_if(ir_rvalue *condition) : condition(condition) { - /* empty */ + ir_type = ir_type_if; } virtual ir_if *clone(struct hash_table *ht) const; @@ -442,7 +465,7 @@ class ir_loop : public ir_instruction { public: ir_loop() : from(NULL), to(NULL), increment(NULL), counter(NULL) { - /* empty */ + ir_type = ir_type_loop; } virtual ir_loop *clone(struct hash_table *ht) const; @@ -664,6 +687,7 @@ public: ir_call(ir_function_signature *callee, exec_list *actual_parameters) : callee(callee) { + ir_type = ir_type_call; assert(callee->return_type != NULL); type = callee->return_type; actual_parameters->move_nodes_to(& this->actual_parameters); @@ -726,7 +750,7 @@ private: ir_call() : callee(NULL) { - /* empty */ + this->ir_type = ir_type_call; } ir_function_signature *callee; @@ -746,7 +770,7 @@ class ir_jump : public ir_instruction { protected: ir_jump() { - /* empty */ + ir_type = ir_type_unset; } }; @@ -755,13 +779,13 @@ public: ir_return() : value(NULL) { - /* empty */ + this->ir_type = ir_type_return; } ir_return(ir_rvalue *value) : value(value) { - /* empty */ + this->ir_type = ir_type_return; } virtual ir_return *clone(struct hash_table *) const; @@ -804,6 +828,7 @@ public: ir_loop_jump(jump_mode mode) { + this->ir_type = ir_type_loop_jump; this->mode = mode; this->loop = loop; } @@ -841,6 +866,7 @@ class ir_discard : public ir_jump { public: ir_discard() { + this->ir_type = ir_type_discard; this->condition = NULL; } @@ -898,7 +924,7 @@ public: ir_texture(enum ir_texture_opcode op) : op(op), projector(NULL), shadow_comparitor(NULL) { - /* empty */ + this->ir_type = ir_type_texture; } virtual ir_texture *clone(struct hash_table *) const; diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp index 4284f6b1201..8a567954a1f 100644 --- a/src/glsl/ir_validate.cpp +++ b/src/glsl/ir_validate.cpp @@ -173,9 +173,24 @@ ir_validate::validate_ir(ir_instruction *ir, void *data) } void +check_node_type(ir_instruction *ir, void *data) +{ + if (ir->ir_type <= ir_type_unset || ir->ir_type >= ir_type_max) { + printf("Instruction node with unset type\n"); + ir->print(); printf("\n"); + } +} + +void validate_ir_tree(exec_list *instructions) { ir_validate v; v.run(instructions); + + foreach_iter(exec_list_iterator, iter, *instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + + visit_tree(ir, check_node_type, NULL); + } } |