1 / 17

Intermediate-Code Generation

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.

gezana
Download Presentation

Intermediate-Code Generation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intermediate-Code Generation Jin Tianxing 5110309085

  2. 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.

  3. 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.

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

  5. Example in the Dragon Book

  6. Oprands

  7. Expression

  8. Memory Access

  9. Jump Statement

  10. Examples • while () ; • ; • for (;;);

  11. Example for jump stmt • Maintain stacks of and of loops. • break • Jump to the peek of • continue • Jump to the peek of

  12. Function Call

  13. Register Use

  14. 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.

  15. Stack Frame

  16. Single Static Assignment • It is a intuitive approach in intermediate-code generation. • One can be only assigned once.

  17. Example • Non-SSA Version: • always represents (not store in memory) • SSA Version( is stored in memory):

More Related