









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Paper; Class: Compiler Design; Subject: Computer & Info Science; University: Syracuse University; Term: Unknown 1989;
Typology: Papers
1 / 15
This page cannot be seen from the preview
Don't miss anything!










Annotated abstract syntax trees
-^
Directed acyclic graphs (common subexpressions are coalesced)
Each instruction has, at most, one binary operation
-^
More abstract than machine instructions
Lower level than syntax trees
Suitable for many types of code optimization
A name. Each name is a symbol table index. For convenience, wewrite the names as the identifier.
-^
A constant.
-^
A compiler-generated temporary. Each time a temporary address isneeded, the compiler generates another name from the stream t1, t2,t3, etc.
instructions
registers or to memory.
L is a symbolic label of an instruction
Left: If x is true, execute instruction L next
-^
Right: If x is false, execute instruction L next
Left: sets x to the value in the location i memory units beyond y
-^
Right: sets the contents of the location i memory units beyond y to x
x = &y sets the r value of x to be the location (l value) of y.
-^
x = *y, presumably y is a pointer or temporary whose r value is alocation. The r value of x is set to the contents of that location.
-^
*x = y sets the r value of the object pointed to by x to the r value of y.
Instead of using an attribute to keep the generated code, we assumethat we can generate instructions into a stream of instructions
topmost (innermost) lexical level
Uses the attribute addr to keep the addr of the instruction for thatnonterminal symbol.
E.addr = lookup(top, id.text)
| id
E.addr = E1.addr
E.addr = new Temp()Gen(E.addr = minus E1.addr)
E.addr = new Temp()Gen(E.addr = E1.addr plus E2.addr)
Gen(lookup(top, id.text) = E.addr)
id = E ;
In this case, computing boolean operations may also have flow-of-controlExample:
if ( x < 100 || x > 200 && x != y ) x = 0; Translation:
if x < 100 goto L2ifFalse x >200 goto L1ifFalse x != y goto L L2: x = 0L1: …
B.CodeS1.Code
B.trueB.false
to B.trueto B.false
B.CodeS1.Code Goto S.next
S2.code
B.true B.FalseS.Next
to B.trueto B.false
B.Code = gen(goto B.false)
false
B.Code = gen(goto B.true)
true
B.Code = E1.code || E2.code
|| gen( if E1.addr relop E2.addr goto B.true)|| gen( goto B.false)
E1 rel E
B1.True = B.false; B1.false = B.true;B.Code = B1.code
B1.true = newlabel(); B1.false = B.falseB2.true = B.true; B2.false = B.falseB.Code = B1.code || label(B1.true) || B2.code
B1.true = B.true; B1.false = newlabel();B2.true = B.true; B2.false = B.false;B.Code = B1.code || label(B1.false) || B2.code