next up previous contents
Next: Walkers Up: Programming with the SUIF Previous: VisitorMap   Contents


Iterators

There are two common ways of traversing the SUIF IR representation: iterators and walkers. We discuss iterators here and walkers in the next section. The interface of an iterator can be found in suifkernel/iter.h. An iterator is an ordered collection of objects and an interface that allows one to traverse the objects. It has the notion of a current index, which is initialized to the first position of the collection, and provides methods to move the index up and down. The following example shows the use of an iterator:

       for (Iter<Expression*> iter = st->get_expression_iterator(); 
            iter.is_valid(); iter.next()) {
           Expression *e = iter.current();
       }

The important methods in its interface are:

Method Meaning
length Returns the number of elements in the whole collection.
current Returns the current element.
next Advances the current position.
previous Sets back the current position.
is_valid Returns T if more elements exist beyond the current index.
set_to Sets the current index to a particular value.

The SUIF system provides a set of useful templates for constructing iterators and sets of SuifObjects in the suifkernel/utilities.h file.


next up previous contents
Next: Walkers Up: Programming with the SUIF Previous: VisitorMap   Contents
David Heine
1999-11-22