Go to the previous, next section.
Assume that a copmiler pass needs to create a statement that adds two given variables. Builder will perform this task in a simple and elegant manner.
tree_node_list * b_gets_a_plus_b(tree_proc * proc,
var_sym * a,
var_sym * b)
{
block::set_proc(proc)
block A(a);
block B(b);
block result(B = A + B);
return result.make_tree_node_list()
}
The function b_gets_a_plus_b() takes the current SUIF
procedure and two variables and produce a tree_node_list
containing the resulting statement.
Before using any builder commands, the current procedure must be
set using set_proc(). Two blocks were created for the
variables and a result block was obtained by composing these two
blocks. Overloaded = and + operators were used to
perform the composition. Finally, the tree_node_list was
generated for the result block.
There are many possible ways to calculate the block with the
correct statement. Following are a few possibilities.
block result(block(b) = block(a) + block(b));
Since a complete set of operator overloading is given, any C++ syntax and semantics will work.
block A(a);
block B(b);
block add2(A + B);
block result(B = add2);
block A(a);
block B(b);
block add2(block::op(A, bop_add, B));
block result(block::op(B, aop_eq, add2));
block A(a);
block B(b);
block add2(block::op(A, "+", B));
block result(block::op(B, "=", add2));
block A(a);
block B(b);
block add2(A.dobinop(bop_add, B));
block result(B.doasignop(aop_eq, add2));
There are many different possibilities for creating expressions and statements (see section Creating Expressions and Statements).
Go to the previous, next section.