summaryrefslogtreecommitdiffstats
path: root/src/glsl/ir_validate.cpp
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2010-07-12 13:55:32 -0700
committerIan Romanick <[email protected]>2010-07-12 15:43:50 -0700
commit8baf21b1a4d50efca086679cc43bb0cfc3fee03a (patch)
treedb3b5ceb124a5880777cb2c074bed0b469e9d52c /src/glsl/ir_validate.cpp
parent3fb878722ed53d79eedb9fe68972ef32b79575d4 (diff)
ir_validate: Validate that varibles are declared before used in IR
Diffstat (limited to 'src/glsl/ir_validate.cpp')
-rw-r--r--src/glsl/ir_validate.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
index 8c86748d26a..74b4826e355 100644
--- a/src/glsl/ir_validate.cpp
+++ b/src/glsl/ir_validate.cpp
@@ -58,6 +58,7 @@ public:
}
virtual ir_visitor_status visit(ir_variable *v);
+ virtual ir_visitor_status visit(ir_dereference_variable *ir);
virtual ir_visitor_status visit_enter(ir_function *ir);
virtual ir_visitor_status visit_leave(ir_function *ir);
@@ -70,6 +71,27 @@ public:
struct hash_table *ht;
};
+
+ir_visitor_status
+ir_validate::visit(ir_dereference_variable *ir)
+{
+ if ((ir->var == NULL) || (ir->var->as_variable() == NULL)) {
+ printf("ir_dereference_variable @ %p does not specify a variable %p\n",
+ ir, ir->var);
+ abort();
+ }
+
+ if (hash_table_find(ht, ir->var) == NULL) {
+ printf("ir_dereference_variable @ %p specifies undeclared variable "
+ "`%s' @ %p\n",
+ ir, ir->var->name, ir->var);
+ abort();
+ }
+
+ return visit_continue;
+}
+
+
ir_visitor_status
ir_validate::visit_enter(ir_function *ir)
{
@@ -126,9 +148,11 @@ ir_visitor_status
ir_validate::visit(ir_variable *ir)
{
/* An ir_variable is the one thing that can (and will) appear multiple times
- * in an IR tree.
+ * in an IR tree. It is added to the hashtable so that it can be used
+ * in the ir_dereference_variable handler to ensure that a variable is
+ * declared before it is dereferenced.
*/
- (void) ir;
+ hash_table_insert(ht, ir, ir);
return visit_continue;
}