





























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
Some concept of Compilers - Code Generation are Activation Records, Basic Blocks, Instruction Selection, Intermediate Code, IR Optimisations, Semantic Analysis. Main points of this lecture are: Intermediate Code , Intermediate Representation, Machine-Independent, Instructions, Translate, Easier, Optimisations, Machine Code, Integer Constant, Symbolic Constant
Typology: Slides
1 / 37
This page cannot be seen from the preview
Don't miss anything!






























(^) IR is easier to apply optimisations to. (^) IR is simpler than real machine code. (^) Separation of front-end and back-end.
op (^) e1 e
e1 op e2 - Binary operator Evaluate e1, then e2, then apply op to e1 and e
CALL
f (e1….en)
Procedure call:evaluate f then the arguments in order, then call f
ESEQ
s e
Evaluate s for side effects then e for the result
t
e
Evaluate e then move the result to temporary t
MEM e e
Evaluate e1 giving address a, then evaluate e2 and move the move the result to address a
EXP
e
Evaluate e then discard the result
PLUS TEMP fp CONST k
TEMP fp CONST k
(^) simple variable v in the current procedure’s stack frame
(^) could be abbreviated to:
(^) Consider the statement: (^) A = (B + 23) * 4; (^) This would get translated into the statement: (^) MOVE ( MEM ( +(TEMP fp, CONST k_A) ),
(^) externalCall(”initArray”, [e1, e2])
General 1-Dimensional Arrays
(^) MEM(+(TEMP fp, +(CONST k-2w,x(CONST w, e)))) (^) where k is offset of static array from fp, w is word size
Equivalent to array [L 1 ..U 1 ] of array [L 2 ..U 2 ] of T
(^) Dj = Uj - Lj + 1
(^) Memory addr. of A[L 1 ,…, Ln] + sizeof(T) * [
(^) i 1 *D 2 …Dn + i 2 *D 3 …Dn + … + in-1 * Dn + in
(^) address(A) + ((variable part - constant part) * element size)
Variable part
Constant part
(^) ESEQ(SEQ(MOVE(TEMP r, externalCall(”allocRecord”,[CONST n])), SEQ(MOVE(MEM(TEMP r), e1)), SEQ(..., MOVE(MEM(+(TEMP r, CONST (n-1)w)),en))), TEMP r) (^) where w is the word size
(^) NAME( label)
(^) .word 11 (^) label: .ascii "hello world"
Source tree: (^) IF
a
b
c
IR tree:
fp
fp
t
f
t
LABEL f NULL
fp