
7.1 Suppose a certain compiler translates all statements and expressions into Tree.Exp trees, and does not use the Nx and Cx constructors to represent expressions in different ways. Draw a picture of the IR tree that results from each of the following MiniJava statements and expressions.

a+5
 b[i+1]
 a<b, which should be implemented by making an ESEQ whose lefthand side moves a 1 or 0 into some newly defined temporary, and whose righthand side is the temporary.
 a = x+y; which should be translated with an EXP node at the top.
 if (a<b) c=a; else c=b; translated using the a<b tree from part (c) above; the whole statement will therefore be rather clumsy and inefficient.
 if (a<b) c=a; else c=b; translated in a less clumsy way.
 7.2 Translate each of these MiniJava statements and expressions into IR trees, but using the Ex, Nx, and Cx constructors as appropriate. In each case, just draw pictures of the trees; an Ex tree will be a Tree Exp, an Nx tree will be a Tree Stm, anda Cx tree will be a Stm with holes labeled trueand falseinto which labels can later be placed.

a+5;
 b[i+1]=0;
 while (a<0) a=a+1;
 a<b moves a 1 or 0 into some newly defined temporary, and whose righthand side is the temporary.
 a = x+y;
 if (a<b) c=a; else c=b;
 7.3 Using the C compiler of your choice (or a compiler for another language), translate some functions to assembly language. On Unix this is done with the S option to the C compiler.
Then identify all the components of the calling sequence (items 111), and explain what each line of assembly language does (especially the pseudoinstructions that comprise items 1 and 11). Try one small function that returns without much computation (a leaffunction), and one that calls another function before eventually returning.
 7.4 The Tree intermediate language has no operators for floatingpoint variables. Show how the language would look with new binops for floatingpoint arithmetic, and new relops for floatingpoint comparisons. You may find it useful to introduce a variant of MEM nodes to describe fetching and storing floatingpoint values.
 *7.5 The Tree intermediate language has no provision for data values that are not exactly one word long. The C coding language has signed and unsigned integers of several sizes, with conversion operators among the different sizes. Augment the intermediate language to accommodate several sizes of integers, with conversions among them.
Hint: Do not distinguish signed values from unsigned values in the intermediate trees, but do distinguish between signed operators and unsigned operators. See also Fraser and Hanson [1995], Sections 5.5 and 9.1.