Previous    Next

INTERMEDIATE REPRESENTATION TREES

The intermediate representation tree language is defined by the package Tree, containing abstract classes Stm and Exp and their subclasses, as shown in Image 7.2.

Java Start Image
package Tree;
abstract class Exp
CONST(int value)
NAME(Label label)
TEMP(Temp.Temp temp)
BINOP(int binop, Exp left, Exp right)
MEM(Exp exp)
CALL(Exp func, ExpList args)
ESEQ(Stm stm, Exp exp)
abstract class Stm
MOVE(Exp dst, Exp src)
EXP(Exp exp)
JUMP(Exp exp, Temp.LabelList targets)
CJUMP(int relop, Exp left, Exp right, Label iftrue, Label iffalse)
SEQ(Stm left, Stm right)
LABEL(Label label)
other classes:
ExpList(Exp head, ExpList tail)
StmList(Stm head, StmList tail)
other constants:
final static int BINOP.PLUS, BINOP.MINUS, BINOP.MUL, BINOP.DIV, BINOP.AND,
 BINOP.OR, BINOP.LSHIFT, BINOP.RSHIFT, BINOP.ARSHIFT, BINOP.XOR;
final static int CJUMP.EQ, CJUMP.NE, CJUMP.LT, CJUMP.GT, CJUMP.LE,
 CJUMP.GE, CJUMP.ULT, CJUMP.ULE, CJUMP.UGT, CJUMP.UGE;


Java End Image

Image 7.2: Intermediate representation trees.

A good intermediate representation has several qualities:

Individual pieces of abstract syntax can be complicated things, such as array subscripts, procedure calls, and so on. And individual "real machine" instructions can also have a complicated effect (though this is less true of modern RISC machines than of earlier architectures). Unfortunately, it is not always the case that complex pieces of the abstract syntax correspond exactly to the complex instructions that a machine can execute. Therefore, the intermediate representation should have individual components that describe only extremely simple things: a single fetch, store, add, move, or jump. Then any "chunky" piece of abstract syntax can be translated into just the right set of abstract machine instructions; and groups of abstract machine instructions can be clumped together (perhaps in quite different clumps) to form "real" machine instructions. Here is a description of the meaning of each tree operator. First, the expressions (Exp), which stand for the computation of some value (possibly with side effects):

The statements (stm) of the tree language perform side effects and control flow:

It is almost possible to give a formal semantics to the Tree language. However, there is no provision in this language for procedure and function definitions - we can specify only the body of each function. The procedure entry and exit sequences will be added later as special "glue" that is different for each target machine.


JaVaScreenshot Previous    Next
Comments