Go to the previous, next section.

FOR Loops

A simple FOR loop corresponding to the for structure in C and the do structure in FORTRAN can be constructed using the builder. The builder's FOR() function gets translated to a SUIF FOR tree node.
        for(int i=0; i<=10; i++)

can be generated using builder by:

        block i(block::new_sym(cst_int, i));
        block code(block::FOR(i, block(0), block(10), block(...)));

The fields of the builder FOR() function are
The index variable.

The lower bound.

Optional: The loop test. Any builder enum of a test operator can be used. The default is bop_leq (<=).

The upper bound.

Optional: The step size. The default is 1.

The body of the loop.

Go to the previous, next section.