欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    (8.4.1)--第08章-代码生成4-一个简单的代码生成器_en.pdf

    • 资源ID:50072222       资源大小:220.45KB        全文页数:17页
    • 资源格式: PDF        下载积分:10金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    (8.4.1)--第08章-代码生成4-一个简单的代码生成器_en.pdf

    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 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 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 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 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 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 stored 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.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 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 place L where the y op z evaluation results will be placed.Look at the address description of y and determine the current place y with the y value.If the value of y is not yet in L,the instruction MOV y,L is generated.Generates the instruction op z,L,where z is one of the current places of z.If the current values of y and/or z are no longer referenced,are not active at the exit of the block,and are still in the register,then the register description is modified.A Simple Code GeneratorCode generation algorithmThe function getreg returns the place L where x=y op z is held.If the name y is in R,this R does not contain the value of other names,and y does not have the next reference after executing x=y op z,then this R is returned as L.Otherwise,if have,an idle register is returned.Otherwise,if x has the next reference in the block,or op is an operator that must use registers,then find an occupied register R(MOV R,M instructions may be generated,and the description of M may be modified).Otherwise,if X is no longer referenced in the basic block or the appropriate occupied register cannot be found,the memory unit of x is selected as L.A Simple Code GeneratorRegister select functionAssignment statement d=(a b)+(a c)+(a c)Compile to produce a three-address statement sequence:t1=a bt2=a ct3=t1+t2d=t3+t2 A Simple Code GeneratorStatemant Generated code Register descriptionaddress description of the nameEmpty register MOV R0,dd is in R0 and memoryd=t3+t2 ADD R1,R0 R0 contains dd is inR0t3=t1+t2 ADD R1,R0 R0 contains t3 R1 contains t2 t3 is in R0t2 is in R1 t2=a cMOV a,R1SUB c,R1R0 contains t1R1contains t2t1is in R0 t2 is in R1t1=a b MOV a,R0SUB b,R0 R0 contains t1 t1is in R0 Assignment statement:d=(a b)+(a c)+(a c)A Simple Code GeneratorThe first three instructions can be modified to reduce the execution costBefore modification After modificationMOV a,R0 MOV a,R0SUB b,R0 MOV R0,R1 MOV a,R1 SUB b,R0SUB c,R1 SUB c,R1A Simple Code GeneratorGenerate code for index and pointer statementsThe three address statements with index and pointer operations are treated the same as binary operatorsA Simple Code GeneratorThere are two ways to implement conditional transfer.Condition codes are used to indicate whether the calculated result or the value loaded into the register is negative,zero or positive.Branching depends on whether the register value is one of the following six conditions:negative,zero,positive,non-negative,non-zero,and non-positive.Conditional statementA Simple Code GeneratorBranching depends on whether the register value is one of the following six conditions:negative,zero,positive,non-negative,non-zero,and non-positive.e.g.if x y goto z The value of x minus y is stored in Register R.If the value of R is negative,it skips to z.1A Simple Code GeneratorIf the implementation of if x y goto z is:CMP x,y CJz 2.Examples of using conditional codesA Simple Code Generator|then the implementation of:|x=y+w|if x 0 goto z|is:|MOVy,R0|ADD w,R0|MOVR0,x|CJzCompilers TechniquesCode Generation

    注意事项

    本文((8.4.1)--第08章-代码生成4-一个简单的代码生成器_en.pdf)为本站会员(奉***)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开