Code Generation: Intermediate Code and Data Structures, Summaries of Computer Science

The concepts of intermediate code and data structures in the context of code generation. It covers three-address code, P-code, and their respective implementations. The document also explains the process of translating P-code into three-address code and vice versa. Additionally, it touches upon the generation of code for address calculations and control statements.

Typology: Summaries

2021/2022

Uploaded on 02/02/2022

m-jamil
m-jamil 🇵🇰

3 documents

1 / 83

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COMPILER CONSTRUCTION
Principles and Practice
Kenneth C. Louden
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53

Partial preview of the text

Download Code Generation: Intermediate Code and Data Structures and more Summaries Computer Science in PDF only on Docsity!

COMPILER CONSTRUCTION

Principles and Practice

Kenneth C. Louden

8. Code Generation

8.1.1 Three-Address Code

8.1.2 Data Structures for the

Implementation of Three-Address Code

8.2 Basic Code Generation Techniques

8.2.1 Intermediate Code or Target Code as a Synthesized Attribute

8.2.3 Generation of Target Code from Intermediate Code

  • (^) Code generation from intermediate code involves either or both of two standard techniques: - (^) Macro expansion and Static simulation
  • (^) Macro expansion involves replacing each kind of intermediate code instruction with an equivalent sequence of target code instructions
  • (^) Static simulation involves a straight-line simulation of the effects of the intermediate code and generating target code to match these effects

< -- top of stack 3 X Address of x T1=x+ < -- top of stack T Addrss of x

X=t < -- top of stack T < -- top of stack 4 T T2=t1+ < -- top of stack T

  • (^) Then, the three-address code for the expression (x=x+3)+4: T1 = x + 3 X = t T2 = t1 + 4
  • (^) Can be translated into the following P-code: Lda t Lod x Ldc 3 Adi Sto Lad x Lod t Sto Lda t Lod t Ldc 4 Adi Sto

If we want to eliminate the extra temporaries, then a more sophisticated scheme than pure macro expansion must be used. T2 + X, t1 + 4 X 3

8.3 Code Generation of Data Structure References

8.3.1 Address Calculations