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 - Loop Nodes
</TITLE>
7 <link href=
"suif1_17.html" rel=Next
>
8 <link href=
"suif1_15.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_15.html">previous
</A>,
<A HREF=
"suif1_17.html">next
</A>,
<A HREF=
"suif1_113.html">last
</A> section,
<A HREF=
"suif1_toc.html">table of contents
</A>.
17 <H3><A NAME=
"SEC16" HREF=
"suif1_toc.html#TOC16">Loop Nodes
</A></H3>
29 A
<CODE>tree_loop
</CODE> node represents a
"do-while" loop. It contains two
30 tree node lists: the
<CODE>body
</CODE> and the
<CODE>test
</CODE>. The
<CODE>body
</CODE>
31 list comes first and holds the loop body. The
<CODE>test
</CODE> list contains
32 code to evaluate the
"while" expression and conditionally branch back
33 to the beginning of the body.
43 There are three labels associated with a
<CODE>tree_loop
</CODE> node:
44 <CODE>toplab
</CODE>,
<CODE>contlab
</CODE>, and
<CODE>brklab
</CODE>. The
<CODE>toplab
</CODE>
45 label marks the beginning of the loop
<CODE>body
</CODE>; the
<CODE>test
</CODE> list
46 typically contains a conditional branch back to
<CODE>toplab
</CODE>. A
47 "continue" statement in the loop body requires a jump over the rest of
48 the body to the beginning of the test code. The
<CODE>contlab
</CODE> label is
49 positioned at the beginning of the
<CODE>test
</CODE> list for this purpose.
50 Similarly, a
"break" statement in the loop is translated to a jump to
51 the
<CODE>brklab
</CODE> label which is located immediately after the loop.
52 These
<CODE>tree_loop
</CODE> labels must be defined in the scope of the loop
53 node, but the label positions are implicit rather than being marked by
54 label instructions. When the
<CODE>tree_loop
</CODE> is expanded to low-SUIF
55 form, the label instructions are inserted into the tree node lists.
59 Because the loop nodes are only intended for use with structured control
60 flow, certain restrictions on the contents of the
<CODE>tree_loop
</CODE>
61 lists are required. The
<CODE>test
</CODE> part has exactly the same
62 restrictions as the
<CODE>header
</CODE> of a
<CODE>tree_if
</CODE> except that it
63 is the
<CODE>toplab
</CODE> label instead of the
<CODE>jumpto
</CODE> label to which
64 jumps and branches are allowed and expected. See section
<A HREF=
"suif1_15.html#SEC15">If Nodes
</A>. Note
65 in particular that use of the
<CODE>brklab
</CODE> and
<CODE>contlab
</CODE> labels
66 is not allowed in the
<CODE>test
</CODE> list.
70 The
<CODE>body
</CODE> list has restrictions analogous to the restriction on
71 <CODE>then_part
</CODE> and
<CODE>else_part
</CODE> lists of a
<CODE>tree_if
</CODE>:
72 arbitrary nesting of other
<CODE>tree_node
</CODE>s is allowed, but control
73 flow into or out of the
<CODE>body
</CODE> is not allowed. The
<CODE>body
</CODE>
74 list is allowed slightly more leeway, though: jumps or branches are
75 allowed from anywhere in the
<CODE>body
</CODE> to the
<CODE>brklab
</CODE> or the
76 <CODE>contlab
</CODE> labels. This is the only place where the
<CODE>brklab
</CODE>
77 or
<CODE>contlab
</CODE> labels can be used--they cannot be used outside the
78 <CODE>tree_loop
</CODE> or in the
<CODE>test
</CODE> list.
82 Note that either or both of the
<CODE>test
</CODE> and
<CODE>body
</CODE> parts may
83 be empty lists, but if the
<CODE>test
</CODE> part is empty, the loop is
84 degenerate--it will always execute exactly once.
88 For example, the following C code could be translated into the SUIF code
89 shown in a simplified form below. Note that because the
<CODE>test
</CODE>
90 code is at the
<EM>bottom
</EM> of the loop, the
"while" loop must be
91 converted to a
"do-while" loop guarded by an
"if" node. See section
<A HREF=
"suif1_15.html#SEC15">If Nodes
</A>.
99 if (k
< 10) continue;
112 LOOP (Top=L:__L2 Cont=L:__L3 Brk=L:__L4)
134 <p>Go to the
<A HREF=
"suif1_1.html">first
</A>,
<A HREF=
"suif1_15.html">previous
</A>,
<A HREF=
"suif1_17.html">next
</A>,
<A HREF=
"suif1_113.html">last
</A> section,
<A HREF=
"suif1_toc.html">table of contents
</A>.