You can examine the structure of a program by using the print
method provided by the SUIF system to get a textual version of the
representation. Suppose you have a file called ex1.suif with
the programming code:
extern int i;
int l;
int j = 0;
static int a[3];
int proc(int *k,const int i)
a[i] = *k + j;
return j;
By running
suifdriver -e ``import basicnodes suifnodes; load ex1.suif; print -o ex1.out''
we get a print out in the file ex1.out, whose first 20
lines are shown in Figure 1.
|
The print function will traverse the ownership tree qin the representation and dump out all the information there is on the nodes. It prints out a node's class name (which includes the names of all the classes the node is derived from), its field names and their contents. If a field contains a SuifObjects the node owns, the printer will recursively print out the detailed information of the owned node. The output can be quite long as a result; for example, the textual representation of the short example above has over 500 lines.
The class names are shown in braces. The name of each class is output before the contents of that type's fields. When a class is derived, the name of the most derived class is printed, followed by the fields defined in that derivation, then the name of its parent, and its fields, and so on. So, in the above example, BooleanType is derived from NumericType which is derived from DataType which is derived from Type.
The print out is verbose but complete, making it a useful aid for understanding the structure of the representation. Once we are familiar with the structure, we would like to concentrate mainly on the contents. For that reason the SUIF system comes with an alternate printing style for all the basic nodes that display in the program in a more readable format. Simply import the suifprinter before printing the representation, and you will get the output shown in Figures 2 and 3.