(8.4.1)--第08章-代码生成4-一个简单的代码生成器_en.pdf
《(8.4.1)--第08章-代码生成4-一个简单的代码生成器_en.pdf》由会员分享,可在线阅读,更多相关《(8.4.1)--第08章-代码生成4-一个简单的代码生成器_en.pdf(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Compilers TechniquesCode GenerationBefore collecting global information,code is generated temporarily in basic blocks.A Simple Code Generatorprod:=0prod:=0i:=1i:=1t t1 1:=4*i:=4*it t2 2:=at:=at1 1 t t3 3:=4*I:=4*It t4 4:=bt:=bt3 3 t t5 5:=t:=t2 2*t*t4 4t t6 6:=prod+t:=prod+t5 5prod:=tprod:=t6 6t t7
2、7:=i+1:=i+1i:=ti:=t7 7if i=20 if i=20 goto goto B B2 2B B1 1B B2 2Consider each statement of the basic blocks in turn to generate code for it.Basic considerations:Assume that each operator of the three-address statement has a corresponding target machine operator.Assume that the calculation results
3、remain in the register as long as possible unless:.This register is to be used for other calculations,orAt the end of the basic block.So some information needs to be recorded during code generation.A Simple Code Generatore.g.a=b+c.If register Ri contains b,Rj contains c,and b no longer active after
4、that ADD Rj,Ri are generated,and result a is in Ri.If Ri contains b,but c is in the memory unit,b is still no longer active.Generate ADD c,Ri,or generate.MOV c,Rj.ADD Rj,Ri.If the value of c is used later,the second code is more attractive.A Simple Code GeneratorIn the process of code generation,it
5、is necessary to track the contents of the registers and the addresses of the names.e.g.b=aRegister description record what is currently stored in each register?At any point,each register holds the values of several(including zero)names.A Simple Code Generator/Before the statement,R0 holds the value
6、of variable a./does not generate any instructions for this statement./After the statement,R0 holds the values of variables a and b.In the process of code generation,it is necessary to track the contents of the registers and the addresses of the names.Register description record what is currently sto
7、red in each register?Address description of name(variable)record where the current value of each name can be found at runtime.This place can be a register,stack unit,memory address,or even a set of them.For example,after generating MOV c,R0,the value of c can be found in the memory units of R0 and c
8、.A Simple Code GeneratorIn the process of code generation,it is necessary to track the contents of the registers and the addresses of the names.The address information of the name is stored in the symbol table,and a register description table is built separately.These two descriptions change during
9、code generation.A Simple Code GeneratorRegister description record what is currently stored in each register?Address description of name(variable)record where the current value of each name can be found at runtime.For each three-address statement x=y op zCall the function getreg to determine the pla
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 8.4 08 代码 生成 一个 简单 生成器 _en
限制150内