3 <!-- This HTML file has been created by texi2html 1.54
4 from suif1.texi on 28 April 1999 -->
6 <TITLE>The SUIF Version
1 Library - Instruction Nodes
</TITLE>
7 <link href=
"suif1_15.html" rel=Next
>
8 <link href=
"suif1_13.html" rel=Previous
>
9 <link href=
"suif1_toc.html" rel=ToC
>
13 <p>Go to the
<A HREF=
"suif1_1.html">first
</A>,
<A HREF=
"suif1_13.html">previous
</A>,
<A HREF=
"suif1_15.html">next
</A>,
<A HREF=
"suif1_113.html">last
</A> section,
<A HREF=
"suif1_toc.html">table of contents
</A>.
17 <H3><A NAME=
"SEC14" HREF=
"suif1_toc.html#TOC14">Instruction Nodes
</A></H3>
29 Instruction nodes, implemented by the
<CODE>tree_instr
</CODE> class, are the
30 leaves of the abstract syntax trees. Each instruction node contains a
31 single instruction or expression tree which can be accessed using the
32 <CODE>instr
</CODE> method. The
<CODE>set_instr
</CODE> method attaches an
33 instruction to a
<CODE>tree_instr
</CODE>, and the
<CODE>remove_instr
</CODE> method
34 detaches an instruction. Note that
<CODE>remove_instr
</CODE> does not free
35 the storage for the instruction, and unlike the
<CODE>remove
</CODE> method in
36 the
<CODE>instruction
</CODE> class (see section
<A HREF=
"suif1_28.html#SEC28">Source Operands
</A>), it does not
37 remove the instruction from its expression tree. Conversely, removing
38 an instruction from an expression tree with the
<CODE>remove
</CODE> method
39 will automatically call
<CODE>remove_instr
</CODE> if necessary.
43 The SUIF library automatically maintains back-pointers from instructions
44 to their parent
<CODE>tree_instr
</CODE> nodes. As a result, the
45 <CODE>set_instr
</CODE> and
<CODE>remove_instr
</CODE> methods must always be used to
46 attach and detach instructions to
<CODE>tree_instr
</CODE> nodes. Never use
47 the instruction in a
<CODE>tree_instr
</CODE> elsewhere without first calling
48 <CODE>remove_instr
</CODE>, and never use
<CODE>set_instr
</CODE> with a
49 <CODE>tree_instr
</CODE> that already contains an instruction.
53 Unlike other tree nodes, instruction nodes are considered temporary
54 objects. They are destroyed and created automatically by the SUIF
55 library when switching between expression trees and flat lists, and
56 their annotations and ID numbers are not written to the output files.
57 Consequently, annotations should generally not be attached to them but
58 should instead be placed directly on the instructions.
62 The destructor for the
<CODE>tree_instr
</CODE> class also deletes the
63 instruction or expression tree contained in the node. This is the
64 desired behavior for most cases. However, if you only want to delete
65 the
<CODE>tree_instr
</CODE> node, simply call
<CODE>remove_instr
</CODE> first and
66 save a pointer to the instruction.
72 Often in SUIF one needs to perform some operation on all the
73 instructions in a procedure. The
<CODE>map
</CODE> methods in the
74 <CODE>tree_node
</CODE> and
<CODE>tree_node_list
</CODE> classes (see section
<A HREF=
"suif1_21.html#SEC21">Mapping Functions Over Subtrees
</A>) make it easy to visit all of the instruction nodes. Once an
75 instruction node is reached, its
<CODE>instr_map
</CODE> method may be used to
76 apply a function to every instruction in the associated expression tree.
77 Given a function of type
<CODE>instr_map_f
</CODE>,
<CODE>instr_map
</CODE> will
78 traverse the expression tree and apply the function to every
79 instruction. The
<CODE>preorder
</CODE> parameter is used to select either
80 preorder or postorder traversals; the default is preorder. The
81 <CODE>instr_map_f
</CODE> function takes two arguments: the instruction pointer
82 and a
<CODE>void*
</CODE> value that you provide to
<CODE>instr_map
</CODE>.
87 <p>Go to the
<A HREF=
"suif1_1.html">first
</A>,
<A HREF=
"suif1_13.html">previous
</A>,
<A HREF=
"suif1_15.html">next
</A>,
<A HREF=
"suif1_113.html">last
</A> section,
<A HREF=
"suif1_toc.html">table of contents
</A>.