CH 06 CodeGeneration
CH 06 CodeGeneration
Intermediate Representations
A =
x = E x +
E + E * *
a * b a * b a b a b
= =
x + x +
* * *
a b a b a b
a+b ab+
a+b*c abc*+
if A then B else C ABC?
If A then if B then C else D else E ABCD?E?
x=a*b+a*b ab*ab*+x=
source 3AC
x = a+b*c t := b*c
x := a+t
Semantic Actions
and
Code Generation
subtree ASM
=
t1 = b*c L 3,b
M 3,c
x + ST 3,t1
t2 = a+t1 L 3,a
a * A 3,t1
ST 3,t2
b c x = t2 L 3,t2
ST 3,x