⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optimisation.txt

📁 一个编译器的例子,基于c语言,在linux下开发 现在了简单的c语言例子
💻 TXT
字号:
COMP510 04AID: 0130348name: Yinghao QinREPORT TWOOPTIMISATIOINFor the optimization part, actually, it is divided into two parts in my implementation. The first part is done during the type checking and the second part is in the code generation processing. During the type checking, if there are some constant values in the assignment calculations, the result will be calculated and the tree will be changed as well. for example, saya=3+4;after type checking, it will becomea=7;In the code generation, I try to eliminate the redundant loads and stores as much as possible. Because I use stack to save the temporary values, which is when meeting Id or numbers, they will be pushed in the stack, and when meeting the operation like "+","-" etc., pop the two operands out, calculate the result and then push back to stack, and so on until the statement finish, therefore, it is difficult to remove all redundant push and pop.  If there is only one assignment like a=5;b=a;the  assignment will be optimized by generating assignment directly, not pushing, pushing, and popping out then  calculating.The flow control optimization is done in code generation as well. Removing the useless label and "jmp" statements after optimization. That is based on analysis of the if statements.For common subexpression elimination, unfortunately, I have no time to do anything for this part. So, just leave it for the future.The test file is named "c-optimise.c-"use "c- c-optimise.c-"  to generate assembly code.The assembly code file, after optimized, is "c-opotimise.S", which contains 51 lines.The assembly code file, before optimized, is "c-bf-opotimise.S", which contains 86 lines.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -