1 Code Generation (cont’d.)
2 Save to Register A 1. 2 already in Register A, or 2. already in Register A, or 3. 2 and both are not in Register A
3 Code Generation (cont’d.) Node Specifier S( 1 ) save to rA
4
5 Code Generation (cont’d.)
6
7 Code Generation (cont’d.) 9 and 10 S( ) := S( ) = S(SUMSQ) REGA = S( ) <> rA =S(MEAN)
8 Code Generation (cont’d.) 10
9 S( 2 ) <> rA = S(MEAN) Call GETA( 2 ) GETA(SUMSQ) Generate [SUB S(MEAN)=T2] S( 1 ) := rA REGA := 1
10 Code Generation (cont’d.) 11 S( ) := S( ):= S(SUMSQ) S( ) <> rA S( ) := S(MEAN l )
11 Code Generation (cont’d.) 11 S( 2 ) <> rA S( ) <> rA Call GETA(MEAN) Generate [MUL MEAN] S(MEAN) := rA REGA:= MEAN
12 Code Generation (cont’d.) 11 S( 2 ) <> rA Call GETA(SUMSQ) Generate [DIV #100] S( 1 ) := rA REGA := 1
13 Code Generation (cont’d.) 12 S( ) := S(SUMSQ) S( ) := S(MEAN l ) S( ) := S(MEAN r ) S( ) := S(#100)
14
15 Code Generation (cont’d.) REGA = NULL Generate [LDA SUMSQ] S(SUMSQ) := rA REGA := SUMSQ REGA <> NULL = SUMSQ S(MEAN) <> rA = S(SUMSQ) Generate [STA T1] S(SUMSQ) = T1 Generate [LDA MEAN] S(MEAN) := rA REGA := MEAN REGA <> NULL = MEAN S(SUMSQ) <> rA = S(MEAN) Generate [STA T2] S(MEAN) = T2 Generate [LDA S(SUMSQ)=T1] S(SUMSQ) := rA REGA := SUMSQ
16 Code Generation (cont’d.) I
17 Code Generation (cont’d.) 1, 2, and 3
18 Code Generation (cont’d.) 4, 5, and 7
19 8, 14, 15
20 Code Generation (cont’d.) 16 and 17
21 Code Generation (cont’d.)
22 Code Generation (cont’d.)
23
24
25
26
27
28
29
30
31 LDASUMSQ DIV#100 STAT1 LDAMEAN MULMEAN STAT2 LDAT1 SUBT2 STAT3 LDAT3 STAVARIANCE
32 T2 LDAMEAN MULMEAN STAT2 LDASUMSQ DIV#100 STAT1 LDAT1 SUBT2 STAT3 LDAT3 STAVARIANCE
33 T2
34
35
36
37 3*(6-1)=3*5=15
38
39 3*(I-1) Content of Address of A A(3*(I-1))=5
40
41 3*((I-0)*(6-1+1)+(J-1))=5
42 3*((I-1)*(10-1+1)+(2J-1-1)) 3*(i1(i8)*10 3*(i2(i9) +i3(i10)-1-1 +i4(i11)-1 +i5 3*i6(i12) i7(i13)
43
44
45
46 Machine-Independent Compiler Features
47 Machine-Independent Compiler Features Storage Allocation Static Allocation: cannot be used for recursive call Dynamic Allocation: Activation Record
48
49
50
51
52
53
54
55 P-Code Compliers
56 Compiler-Compilers
57