ir_hierarchical_visitor: Add generic callback functionality
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 23 Jun 2010 01:37:12 +0000 (18:37 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 23 Jun 2010 16:25:28 +0000 (09:25 -0700)
ir_hierarchical_visitor.cpp
ir_hierarchical_visitor.h

index 11d30b4b6e7c273e9bc7a5e2f70babe763d3590b..63ce8784adbbf7bdcdc13b20f4b38d188290b9ec 100644 (file)
 #include "ir.h"
 #include "ir_hierarchical_visitor.h"
 
+ir_hierarchical_visitor::ir_hierarchical_visitor()
+{
+   this->callback = NULL;
+   this->data = NULL;
+}
+
 ir_visitor_status
 ir_hierarchical_visitor::visit(ir_variable *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
 ir_visitor_status
 ir_hierarchical_visitor::visit(ir_constant *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
 ir_visitor_status
 ir_hierarchical_visitor::visit(ir_loop_jump *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
 ir_visitor_status
 ir_hierarchical_visitor::visit(ir_dereference_variable *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_loop *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -69,7 +85,9 @@ ir_hierarchical_visitor::visit_leave(ir_loop *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_function_signature *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -83,7 +101,9 @@ ir_hierarchical_visitor::visit_leave(ir_function_signature *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_function *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -97,7 +117,9 @@ ir_hierarchical_visitor::visit_leave(ir_function *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_expression *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -111,7 +133,9 @@ ir_hierarchical_visitor::visit_leave(ir_expression *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_texture *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -125,7 +149,9 @@ ir_hierarchical_visitor::visit_leave(ir_texture *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_swizzle *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -139,7 +165,9 @@ ir_hierarchical_visitor::visit_leave(ir_swizzle *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_dereference_array *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -153,7 +181,9 @@ ir_hierarchical_visitor::visit_leave(ir_dereference_array *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_dereference_record *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -167,7 +197,9 @@ ir_hierarchical_visitor::visit_leave(ir_dereference_record *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_assignment *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -181,7 +213,9 @@ ir_hierarchical_visitor::visit_leave(ir_assignment *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_call *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -195,7 +229,9 @@ ir_hierarchical_visitor::visit_leave(ir_call *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_return *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
@@ -209,7 +245,9 @@ ir_hierarchical_visitor::visit_leave(ir_return *ir)
 ir_visitor_status
 ir_hierarchical_visitor::visit_enter(ir_if *ir)
 {
-   (void) ir;
+   if (this->callback != NULL)
+      this->callback(ir, this->data);
+
    return visit_continue;
 }
 
index 85bc5bb150ba0ce1fa21fdf9504f6bd0af35ec0f..af8f83cac560fb82133d039b8777d58c1ef2732a 100644 (file)
@@ -76,6 +76,8 @@ enum ir_visitor_status {
 
 class ir_hierarchical_visitor {
 public:
+   ir_hierarchical_visitor();
+
    /**
     * \name Visit methods for leaf-node classes
     */
@@ -136,6 +138,22 @@ public:
     * Utility function to process a linked list of instructions with a visitor
     */
    void run(struct exec_list *instructions);
+
+protected:
+   /**
+    * Callback function that is invoked on entry to each node visited.
+    *
+    * \warning
+    * Visitor classes derived from \c ir_hierarchical_visitor \b may \b not
+    * invoke this function.  This can be used, for example, to cause the
+    * callback to be invoked on every node type execpt one.
+    */
+   void (*callback)(class ir_instruction *ir, void *data);
+
+   /**
+    * Extra data parameter passed to the per-node callback function
+    */
+   void *data;
 };
 
 #endif /* IR_HIERARCHICAL_VISITOR_H */