资源描述:
《编译程序构造原理和实现技术.ppt》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、ChapterCodeGeneration代码生成88.1IntermediateCodeandDataStructuresforCodeGeneration中间代码和用于代码生成的数据结构8.2BasicCodeGenerationTechniques基本的代码生成技术8.3CodeGenerationofDataStructureReferences数据结构应用的代码生成8.4CodeGenerationofControlStatementsandLogicalExpressions控制语句和逻辑表达式的代码生成8.5CodeGenerationofPro
2、cedureandFunctionCalls过程和函数调用的代码生成8.6CodeGenerationinCommercialCompilers:TwoCaseStudies商用编译器中的代码生成:两个案例研究8.7TM:ASimpleTargetMachineTM:简单的目标机器8.8CodeGenerationfortheTinyLanguageTINY语言的代码生成器8.9ASurveyofCodeOptimizationsTechniques代码优化技术考察8.10SimpleOptimizationsfortheTINYCodeGeneratorTI
3、NY代码生成器的简单优化8.1IntermediateCodeandDataStructuresforCodeGeneration中间代码和用于代码生成的数据结构●intermediaterepresentation(IR)Adatastructurethatrepresentsthesourceprogramduringtranslationiscalledanintermediaterepresentation,orIR,forshort.源程序的一种内部表示,不依赖目标机的结构,易于生成目标代码的中间表示。●twopopularformsofinterm
4、ediatecodeThree-AddressCode三地址码波兰式P-code.P-代码●Three-AddressCode例1请写出算术表达式2*a+(b-3)的三地址码解:2*a+(b-3)withsyntaxtree2*a+(b-3)的语法树+b*-32aT1=2*aT2=b–3T3=t1+t2(2)Thecorrespondingthree-addresscodeis三地址码●example例2请写出SampleTINYprogram的三地址码readx;{inputaninteger}if05、t:=1;repeatfact:=fact*x;x:=x-1untilx=0;writefact{outputfactorialofx}ends解:Three-addresscodefortheTINYprogramreadxt1=x>0if_falset1gotoL1fact=1labelL2t2=fact*xfact=t2t3=x-1x=t3t4=x==0if_falset4gotoL2writefactlabelL1halt●DataStructuresfortheImplementationofThree-AddressCode实现三地址码的数据结
6、构Quadruple四元式Triple三元式例1请写出TINYprogram三地址码的四元式表示。readxt1=x>0if_falset1gotoL1fact=1labelL2t2=fact*xfact=t2t3=x-1x=t3t4=x==0if_falset4gotoL2writefactlabelL1halt●example例1请写出TINYprogram三地址码的四元式表示。readxt1=x>0if_falset1gotoL1fact=1labelL2t2=fact*xfact=t2t3=x-1x=t3t4=x==0if_falset4gotoL
7、2writefactlabelL1halt解:Quadrupleimplementationforthethree-addresscode(sub,x,1,t3)(asn,t3,x,_)(eq,x,0,t4)(if_f,t4,L2,_)(wri,fact,_,_)(lab,L1,_,_)halt,_,_,_)(rd,x,_,_)(gt,x,0,t1)(if_f,t1,L1,_)(asn,1,fact,_)(lab,L2,_,_)(mul,fact,x,t2)(asn,t2,fact,_)●example例2请写出TINYprogram三地址码的三元式表示。re
8、adxt1=x>0if_falset