Compiler fortolker struktur
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

Compiler/fortolker struktur PowerPoint PPT Presentation


  • 96 Views
  • Uploaded on
  • Presentation posted in: General

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.

Download Presentation

Compiler/fortolker struktur

An Image/Link below is provided (as is) to download presentation

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 - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Compiler fortolker struktur

Lexikalsk-

analyse

Syntax-

analyse

Semantik-

analyse

Mellemk.-

optimering

Kode-

generering

Kode-

optimering

Compiler/fortolker struktur

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

Mellem-

kode

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


Mellemkode

Mellemkode.

Tree-based repræsentation.

Mellemkode som et parsertræ.

Three-address koder:

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--;

}

}


Three address kodeoptimering

Three-address kodeoptimering.

  • Find basic blokke.

  • Optimer hver basic blok:

    • Commom sub-expression

    • Copy propagation

    • Dead-code elimination

    • Arithmetic transform

      • Constant folding

      • Algebraic transform

      • Reduction in strength

    • Packing af mellemvariable.

  • Loop optimering.


Basic blokke

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

Basic blok optimering.

  • Commom sub-expression

    Samme beregning flere gange.

  • Copy propagation

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

  • Dead-code elimination

    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

    Frigiv overflødig plads til mellemvariable.


Commom sub expression

Commom sub-expression

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


Copy propagation

Copy propagation

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


Dead code elimination

Dead-code elimination

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


Arithmetic transform

Arithmetic transform

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


Loop optimering

1

2a

2b

3

4

5

6

Loop optimering.

1

2

3

4

5

6


Kodegenerering

Kodegenerering.

Globale og static variable:

Når navn indsættes i symboltabellen

så SymAdr= Nextstatic;

Nextstatic=+ VarSize;

Lokal variable:

Hvis første: NextLokal= 0;

Ellers: SymAdr= NextLokal;

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,

så sæt referencer til LabelAdr.


  • Login