From 7c09576a97be3490fe36fff9241b9c148ba558cb Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 22 Jun 2010 18:37:12 -0700 Subject: [PATCH] ir_hierarchical_visitor: Add generic callback functionality --- ir_hierarchical_visitor.cpp | 70 ++++++++++++++++++++++++++++++++++----------- ir_hierarchical_visitor.h | 18 ++++++++++++ 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/ir_hierarchical_visitor.cpp b/ir_hierarchical_visitor.cpp index 11d30b4..63ce878 100644 --- a/ir_hierarchical_visitor.cpp +++ b/ir_hierarchical_visitor.cpp @@ -24,38 +24,54 @@ #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; } diff --git a/ir_hierarchical_visitor.h b/ir_hierarchical_visitor.h index 85bc5bb..af8f83c 100644 --- a/ir_hierarchical_visitor.h +++ b/ir_hierarchical_visitor.h @@ -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 */ -- 2.7.4