Intermediate-Code Generation

17
Intermediate-Code Generation Jin Tianxing 5110309085

description

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. - PowerPoint PPT Presentation

Transcript of Intermediate-Code Generation

Page 1: Intermediate-Code Generation

Intermediate-Code Generation

Jin Tianxing5110309085

Page 2: Intermediate-Code Generation

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

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

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

Example in the Dragon Book

Page 6: Intermediate-Code Generation

Oprands

Page 7: Intermediate-Code Generation

Expression

Page 8: Intermediate-Code Generation

Memory Access

Page 9: Intermediate-Code Generation

Jump Statement

Page 10: Intermediate-Code Generation

Examples while () ;

;

for (;;);

Page 11: Intermediate-Code Generation

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

Function Call

Page 13: Intermediate-Code Generation

Register Use

Page 14: Intermediate-Code Generation

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

Stack Frame

Page 16: Intermediate-Code Generation

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

generation.

One can be only assigned once.

Page 17: Intermediate-Code Generation

Example

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

SSA Version( is stored in memory):