next up previous contents
Next: Using A Selective Walker Up: Programming with the SUIF Previous: Iterators   Contents


Walkers

A Walker is a class that provides support for walking trees and visiting certain nodes. The classes from which you will normally derive are SelectiveWalker and GroupWalker, both found in the file suifkernel/group_walker.h. SelectiveWalker allows you to walk one class of object (including its derived classes), while GroupWalker allows you to register a list of walkers for a variety of classes of object. This is a much better way of performing different actions on differing classes of objects than using a giant if statement because it is easy to add new cases.

The ProcedureWalker in the file basepasses/transforms/procedure_walker_utilities.h is useful if you want to apply a SelectiveWalker to each procedure. If you want to visit all SUIF objects, without selecting by class, you can derive instead from the class SuifWalker, found in suifkernel/suif_walker.h.

The work for all walkers is performed by the function operator:

        Walker::ApplyStatus operator () (SuifObject *x)

which is called for every object matching your selection criteria. The returned status, drawn from the enum ApplyStatus, controls the further progress of the walk:

ApplyStatus Meaning
Continue Normal completion
Stop Terminate the walk successfully
Abort Terminate the walk with error
Truncate Do not walk sub-trees of this node (only useable in pre-order walks)
Replaced This subtree has been replaced. The set_address walker method must have been called before returning this status with the pointer to the new sub-tree. In pre-order, this new subtree will be walked instead of the old.




next up previous contents
Next: Using A Selective Walker Up: Programming with the SUIF Previous: Iterators   Contents
David Heine
1999-11-22