# Compiler/fortolker struktur - PowerPoint PPT Presentation

1 / 11

Lexikalsk- analyse. Syntax- analyse. Semantik- analyse. Mellemk.- optimering. Kode- generering. Kode- optimering. Compiler/fortolker struktur. - - - - - - - Front end - - - - - - - - -. Mellem- kode. - - - - - - - Back end - - - - - - - - -. Mellemkode. Tree-based repræsentation.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Compiler/fortolker struktur

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Lexikalsk-

analyse

Syntax-

analyse

Semantik-

analyse

Mellemk.-

optimering

Kode-

generering

Kode-

optimering

### Compiler/fortolker struktur

- - - - - - - Front end - - - - - - - - -

Mellem-

kode

- - - - - - - Back end - - - - - - - - -

### Mellemkode.

Tree-based repræsentation.

Mellemkode som et parsertræ.

A:= b + c

a= 0

b= 2

l1:

ifz b goto l2

a= a + b

b= b – 1

goto l1

l2:

int main ()

{ int a=0,b=2;

while (b) {

a= a+b;

b--;

}

}

• Find basic blokke.

• Optimer hver basic blok:

• Commom sub-expression

• Copy propagation

• Arithmetic transform

• Constant folding

• Algebraic transform

• Reduction in strength

• Packing af mellemvariable.

• Loop optimering.

### Basic blokke

• Blok start:

• Første statement

• Label, der hoppes til

• Statement efter et branch

a= 0

b= 2

l1:

ifz b goto l2

a= a + b

b= b – 1

goto l1

l2:

### Basic blok optimering.

• Commom sub-expression

Samme beregning flere gange.

• Copy propagation

Samme værdi i flere variable. Erstat alle med en.

Variable, der ikke bruges, slettes.

• Arithmetic transform

• Constant folding

Beregn konstanter

• Algebraic transform

+ 0, - 0, * 1 og /1

• Reduction in strength

Fx: 2*x -> x+x

• Packing af mellemvariable

b := 4 - 2

t1 := b / 2

t2 := a * t1

t3 := t2 * b

t4 := t3 + c

t5 := t2 * b

t6 := t5 + c

d := t4 * t6

b := 4 - 2

t1 := b / 2

t2 := a * t1

t3 := t2 * b

t4 := t3 + c

t5 := t3

t6 := t5 + c

d := t4 * t6

b := 4 - 2

t1 := b / 2

t2 := a * t1

t3 := t2 * b

t4 := t3 + c

t5 := t3

t6 := t5 + c

d := t4 * t6

b := 4 - 2

t1 := b / 2

t2 := a * t1

t3 := t2 * b

t4 := t3 + c

t5 := t3

t6 := t3 + c

d := t4 * t6

b := 4 - 2

t1 := b / 2

t2 := a * t1

t3 := t2 * b

t4 := t3 + c

t5 := t3

t6 := t4

d := t4 * t4

b := 4 - 2

t1 := b / 2

t2 := a * t1

t3 := t2 * b

t4 := t3 + c

t5 := t3

t6 := t4

d := t4 * t4

b := 4 - 2

t1 := b / 2

t2 := a * t1

t3 := t2 * b

t4 := t3 + c

d := t4 * t4

b := 4 - 2

t1 := b / 2

t2 := a * t1

t3 := t2 * b

t4 := t3 + c

d := t4 * t4

b := 2

t1 := b / 2

t2 := a * t1

t3 := t2 * b

t4 := t3 + c

d := t4 * t4

t1 := 1

t2 := a * t1

t3 := t2 * 2

t4 := t3 + c

d := t4 * t4

t2 := a

t3 := t2 * 2

t4 := t3 + c

d := t4 * t4

1

2a

2b

3

4

5

6

1

2

3

4

5

6

### Kodegenerering.

Globale og static variable:

Når navn indsættes i symboltabellen

Nextstatic=+ VarSize;

Lokal variable:

Hvis første: NextLokal= 0;

NextLokal=+ VarSize;

a= 0

b= 2

l1:

ifz b goto l2

a= a + b

b= b – 1

goto l1

l2:

For hver linie i mellemkode:

Generer koden vha informationer fra symboltabellen.

Labels:

Anvendelse: Kik i symboltabellen om den er

defineret ellers gem i tabellen, hvor den bruges.

Oprettelse: Labeladr= LC. Hvis gemte anvendelser,