Professional Documents
Culture Documents
Code Generation
MACHINE - DEPENDENT CODE
OPTIMIZATION
Machine Independent Compiler
Features
MACHINE - INDEPENDENT CODE
OPTIMIZATION
Solution
<EXP>
<EXP>
<TERM> <TERM>
<Term> <Term>
<Factor> <Factor> <Factor> <Factor>
Id
:= -
Id DIV Int Id * Id
{VARIANCE} {SUMQ} {100} {MEAN} {MEAN}
LDA SUMSQ
DIV # 100
STA TMP1
LDA MEAN
MUL MEAN
STA TMP2
LDA TMP1
SUB TMP2
STA VARIABLE
The first three phases are called as the front end of the
compiler because they are machine independent.
N.K. Srinath srinath_nk@yahoo.com 1 RVCE
The code generation and related
phase is called as the back end.
The intermediate code generation is neither consider
to be the back end nor front end.
Next slide shows three languages producing a
common intermediate code. From the intermediate
code the object code for the two M/C are obtained.
PROGRAM STATS
VAR
SUM, SUMSQ, I, VALUE, MEAN, VARIANCE :
INTEGER
BEGIN
SUM :=0;
SUMSQ : = 0 ;
2. := #0 SUMSQ SUMSQ : = 0
3. := #1 I FOR I : = 1 to 100
4. JGT I #100 (15)
6. PARA VALUE
11.: = i3 SUMSQ
13.: = i4 I
N.K. Srinath srinath_nk@yahoo.com 36 RVCE
14. J (4)
15. DIV SUM #100 i5 {MEAN:= SUM DIV 100}
16. : = i5 MEAN
Block -- A Quadruples 1 - 3
Block -- B Quadruples 4
2) * MEAN MEAN i2
3) - i1 i2 i3
4) : = i3 VARIANCE
* MEAN MEAN i2
- i1 i2 i3
:= i3 VARIANCE
N.K. Srinath srinath_nk@yahoo.com 27 RVCE
LDA MEAN
MUL MEAN
STA i1
LDA SUMSQ
DIV # 100
SUB i1
STA VARIANCE
ARRAY [ i .. u ] OF INTEGER
Main objective:
Maximize the utilization of the CPU registers
Minimize references to memory locations
» Importance
Efficiency
Speed