Intermediate-Code Generation
description
Transcript of Intermediate-Code Generation
Intermediate-Code Generation
Jin Tianxing5110309085
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.
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.
Quadruple A quadruple consists of an , which can possibly be null. You should design your own IR package. Here is a viable example.
Example in the Dragon Book
Oprands
Expression
Memory Access
Jump Statement
Examples while () ;
;
for (;;);
Example for jump stmt Maintain stacks of and of loops.
break Jump to the peek of
continue Jump to the peek of
Function Call
Register Use
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.
Stack Frame
Single Static Assignment It is a intuitive approach in intermediate-code
generation.
One can be only assigned once.
Example
Non-SSA Version: always represents (not store in memory)
SSA Version( is stored in memory):