Top Banner
Intermediate-Code Generation Jin Tianxing 5110309085
17

Intermediate-Code Generation Jin Tianxing 5110309085.

Jan 20, 2018

Download

Documents

Karen Jefferson

Where is the data?
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Intermediate-Code Generation Jin Tianxing 5110309085.

Intermediate-Code Generation

Jin Tianxing5110309085

Page 2: Intermediate-Code Generation Jin Tianxing 5110309085.

Purpose Theoretically, we can directly generate the

MIPS assemble code after semantic analysis.

Intermediate-code give us opportunities to register allocation, code optimization and easiness when debugging.

After this, the input code and AST can be thrown away.

Page 3: Intermediate-Code Generation Jin Tianxing 5110309085.

Where is the data? There are only two possible place containing

data: and .

That means the intermediate-code get data only with and

For simplicity, we assume the number of is unlimited.

Page 4: Intermediate-Code Generation Jin Tianxing 5110309085.

Quadruple A quadruple consists of an , which can possibly be null. You should design your own IR package. Here is a viable example.

Page 5: Intermediate-Code Generation Jin Tianxing 5110309085.

Example in the Dragon Book

Page 6: Intermediate-Code Generation Jin Tianxing 5110309085.

Oprands

Page 7: Intermediate-Code Generation Jin Tianxing 5110309085.

Expression

Page 8: Intermediate-Code Generation Jin Tianxing 5110309085.

Memory Access

Page 9: Intermediate-Code Generation Jin Tianxing 5110309085.

Jump Statement

Page 10: Intermediate-Code Generation Jin Tianxing 5110309085.

Examples while () ;

;

for (;;);

Page 11: Intermediate-Code Generation Jin Tianxing 5110309085.

Example for jump stmt Maintain stacks of and of loops.

break Jump to the peek of

continue Jump to the peek of

Page 12: Intermediate-Code Generation Jin Tianxing 5110309085.

Function Call

Page 13: Intermediate-Code Generation Jin Tianxing 5110309085.

Register Use

Page 14: Intermediate-Code Generation Jin Tianxing 5110309085.

What to do when calling a function? Save in memory. Change , (jump and link) to the of the function. When from a function:

address(value) stores in a . (jump register)

Restore from memory.

Page 15: Intermediate-Code Generation Jin Tianxing 5110309085.

Stack Frame

Page 16: Intermediate-Code Generation Jin Tianxing 5110309085.

Single Static Assignment It is a intuitive approach in intermediate-code

generation.

One can be only assigned once.

Page 17: Intermediate-Code Generation Jin Tianxing 5110309085.

Example

Non-SSA Version: always represents (not store in memory)

SSA Version( is stored in memory):