Docsity

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

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