next up previous contents
Next: Cloning Up: Programming with the SUIF Previous: The IR Tree   Contents


Casting and Type Identification

SUIF is designed so that a compiler pass can operate on a SUIF program with IR nodes whose declarations were not included at the time the pass was compiled. For example, a pass that is defined for the base SUIF representation can be applied to program representations that include new IR subclasses that a programmer defines. Information specific to these new classes are stored away and will be written out when the representation is saved to disk. The system keeps track of the type of each SUIF object internally, and you should not use standard C++ techniques such as dynamic casts to determine the types of these objects. Instead, SUIF objects, which are all descended from the class SuifObject, provide their own type identification and object casting methods. Table 1 shows the correct methods of casting and identifying types. To use these, you must include the header file iokernel/cast.h.


Table 1: Casting and Type Identification
Method Meaning
bool is_a< suifclass>(Object $\ast$) returns true if the object is exactly of type suifclass, which must be descended from Object
bool is_kind_of< suifclass>(Object $\ast$) returns true if the object's class is type suifclass or derived from it.
suifclass $\ast$ to< suifclass>(Object $\ast$) A dynamic cast to type suifclass. Asserts if the cast is illegal. Returns NULL if the object is NULL.


next up previous contents
Next: Cloning Up: Programming with the SUIF Previous: The IR Tree   Contents
David Heine
1999-11-22