Compiler Designs and Constructions - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Compiler Designs and Constructions

Description:

Intermediate Language (Code) Why Intermediate Language and not the Target Language? ... Generate Intermediate Code into an output file ( .obj) Gen ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 20
Provided by: scie6
Category:

less

Transcript and Presenter's Notes

Title: Compiler Designs and Constructions


1
Compiler Designs and Constructions
  • Chapter 10 Intermediate Code Generation (part I)
  • Objectives
  • Dr. Mohsen Chitsaz

2
Intermediate Language (Code)
  • Why Intermediate Language and not the Target
    Language?
  • Advantages of Intermediate Code

Pascal
Back-End
Fortran
Inter. Code
---gt 68000 ---gt 8086
C
My Compiler
Front-End
3
  • Definition
  • Back-End
  • Intermediate ---gt Machine Code
  • Front-End
  • Programming Languages ---gt Intermediate

4
Intermediate Code Generation
  • C AB
  • What are the values of A and B?
  • A.Place
  • B.Place
  • C.Place
  • Translate
  • Gen(Temp1 A.Place B.Place)
  • Gen(C.Place Temp1)

5
Notation and Definition
6
Notation and Definition
7
1-Assignment Statement
  • A ---gt id E
  • E ---gt E E
  • E ---gt E E
  • E ---gt - E
  • E ---gt ( E )
  • E ---gt id

8
Code Generation for Assignment Statement
9
Mixed Mode Translation (Type)
  • E.Mode to pass the Type
  • C A B

10
  • E ---gt E1 E2
  • E.Place NewTemp()
  • If E1.ModeInt and E2.Mode Int THEN
  • E.Mode Int
  • Gen(E.Place E1.Place E2.Place)
  • ELSE
  • If E1.Mode Real and E2.Mode Real THEN
  • E.Mode Real
  • Gen(E.Place E1.Place E2.Place)
  • ELSE

11
  • If E1.Mode Int THEN
  • TNewTemp()
  • Gen(T Int_To_Real E1.Place)
  • Gen(E.Place T E2.Place)
  • E.Mode Real
  • ELSE
  • T NewTemp()
  • Gen(T Int_To_Real E2.Place)
  • Gen(E.Place E2.Place T)
  • E.Mode Real

12
2-Translation of Boolean Expression
  • Logical Values
  • Conditional Expression
  • 1- E ---gt E OR E
  • 2- E ---gt E AND E
  • 3- E ---gt NOT E
  • 4- E ---gt (E)
  • 5- E ---gt id Rel.op id
  • 6- E ---gt TRUE
  • 7- E ---gt FALSE

13
Method1 Using Quadruples
  • Assumption
  • Left association
  • True1
  • False0
  • Example
  • a OR b AND NOT c
  • t1 NOT c
  • t2 b AND t1
  • t3 a OR t2

14
Translation of Boolean Expression con.
  • Example a lt b
  • 0 IF altb GOTO ( )
  • 1 t1 0
  • 2 GOTO ( )
  • 3 t1 1
  • 4
  • IF altb THEN 1 ELSE 0

15
Translation of Boolean Expression con.
  • Example
  • A lt b OR c
  • 0 IF a lt b GOTO ( 3 )
  • 1 t1 0
  • 2 GOTO ( 4 )
  • 3 t1 1
  • 4 t2 t1 OR c
  • 5

16
Translation of Boolean Expression con.
  • 7- E ---gt FALSE
  • E.Place NewTemp()
  • Gen(E.Place 0)
  • 6- E ---gt TRUE
  • E.Place NewTemp()
  • Gen(E.Place 1)

17
Translation of Boolean Expression con.
  • 5- E ---gt id1 Rel.op id2
  • E.Place NewTemp()
  • Gen(IF id1.Place Rel.op id2.Place GOTO
    nextQuad2)
  • Gen(E.Place 0)
  • Gen(GOTO nextQuad1)
  • Gen(E.Place 1)

18
Translation of Boolean Expression con.
  • 4- E ---gt (E1)
  • E.Place E1.Place
  • 3- E ---gt NOT E1
  • E.Place NewTemp()
  • Gen(E.Place NOT E1.Place)
  • 2- E ---gt E1 AND E2
  • E.Place NewTemp()
  • Gen(E.Place E1.Place AND E2.Place)
  • 1- E ---gt E1 OR E2

19
Example
  • altb OR cltd AND eltf
Write a Comment
User Comments (0)
About PowerShow.com