Backpatching in Compiler Construction

708 views 4 slides Sep 24, 2021
Slide 1
Slide 1 of 4
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4

About This Presentation

Backpatching in Compiler Construction


Slide Content

m-Haeoon |
BACK PA TCH ING Lecturer [ese IT) V06 Lahore. \ |
hasoon. voguieat (O gmail. com |

A Key problem when guesahng an inteomedaaté
x ps 0
d 4 ad Greie)

Code For bonlem expressions nd How of cont

Shdements is that of maldigo jump instancias

with the Hogar of the jump.

% Wher we gmende An intesmedunk codé fo¥ Some
Code Giron dra bulemm eapoessions and Haw-oflentat
Shdemecda tamnet Le coude into intesmedaate
code wa single-pass

why? .
~~ Becang the hanfer ef nl of à

Complete. Program Camnet be olgliminad th

A Sal ge
KA Separate pass is needed o bind Labels
(id sexe Jel Man ini) adresse,

% Ts Approach is called “Badkp sng”?

4
Input Cade Shi C Cet om)

Y a<cr1b>3 82 atb
ASL 1 (673 92 ah)
\ntemediats code using Back patchrog

Pr Fer
AS el ase es Logical peurs (08 ,ano)
Precoeding fo precadince wie , And wit be seled first

ae Fue Pass (Vene adhes space bark)

Mares Teee pales Inshuchris

fe der qa ——

fées
1081
to | Jo —

| if 63 pP ——

Ieo3
| Er
ms | ab qe —

lees | Get? ——

los? | tue

1008 | False

x Second Pass (FU blk addieses space )

Three Addeess stich ng

dés if ac is true Hen comptulz
tel Hf ac 2 got [ol Lépine 50 ohn? Coe)
Des to 1003 Lif aca. isfalic then check bya
a Se gphe In3
[if b23 ger 2S — Li pa ie me Me ates
must be tout te Je comple

we goto ns OP. tne, So, guto 1005

ms | if al=b geo de + Dihäansie Complete Pur is Salle
es a. ond copio is Fake
bo 100

| ¿pto Lee
to | tune |
108 | False

O) beckpaichig fo FE he

2
of- Contoo Expression’

. Tf-Else
+ Switch

Input Code (Cre Pas)

if (fall-maaks > Spring-masks)

{

3
aye

1

improvement =

improvemet = 6 ;

Cout << à

Yovemest_;

iale Code using Gackpedchig

x First Rs

tel if ( fall-masks > spring-masks ) goto

102 | improvement = O

ko 3 | gto
Heo | improvement = 4

195 | cout << imprvemet

x Second Pass

lo! | if (fallo masks > spving-mosks) gut ot
102 | improvement =

lo03 | goto los

Vor | Impovemect <4
loos | code Inprovemeut;

Incase of Switch Shaemed pit cowest dd in

Freie then Jere intesmedists code. if ee
switch (vat)

cose 1

3)
«esalt= 300;