欢迎来到天天文库
浏览记录
ID:58699257
大小:3.65 MB
页数:65页
时间:2020-10-04
《第6章 中间代码生成ppt课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、中间代码生成1编译器的前端与后端2Methodusedfortranslationintointermediatecode:syntaxdirectedtranslation.Wewilltranslatetheconstructsofthelanguage:Declarations;AssignmentsFlow-of-controlstatementsIntermediaterepresentationintheliteratureinclude:syntaxtree(section5.2)postfix
2、(section2.3)threeaddresscode(chap.8)others(AST,DAG,ControlFlowGraphs(CFG),ProgramdependenceGraph(PDG),StaticSingleAssignmentForm,stackcode)3语法树,DAG后缀表达式可以看做语法树的一种线性表示abcuminus*bcuminus*+assign4语法树能通过语法制导定义(SDD)生成.E.g:56三地址代码形如:x:=yopz;Othertypesofthree-addr
3、essstatement7翻译时生成临时变量:x+y*zt1:=y*zt2:=x+t1DAG8生成三地址语句9表达式的三地址代码10newtemp()生成临时变量:t1,t2,…gen()生成中间代码11生成四元式ATASisanabstractformofintermediatecode.Incompiler,thesestatementscanbeimplementedasrecordshavingfieldsforoperatorandtheoperands.Recordrepresentationso
4、fthisformcomprisesquadruples,triplesandindirecttriplesTriplesareusedinordertoavoidtheenteringtemporarynamesintosymboltables.Wecanrefertoatemporaryvaluebythispositioninthestatement12E.g.Ternaryoperationx[i]:=yrequirestwoentriesinthetriplestructureandx:=y[i]r
5、equirestwooperations.13Otherrepresentations.IndirecttriplesusealistofpointerstotriplesinsteadoftriplethemselvesTheusageofdifferentrepresentationisamatterofhowmuchindirectionwewanttouseinourcompilerItcouldbeaproblemwhenweuseoptimizationinoutputcode.Movingate
6、mporarythatrepresentsastatementrequirestochangeallthereferencesinthetriples14过程声明AsymboltableentryiscreatedforeverydeclarednameInformationincludesname,type,relativeaddressofstorage,etc.Relativeaddressconsistsofanoffset:Offsetisfromthebaseofthestaticdataarea
7、forglobals,orOffsetisfromthefieldforlocaldatainanactivationrecordforlocalstoproceduresTypesareassignedattributestypeandwidthBecomesmorecomplexifweneedtodealwithnestedproceduresorrecords15Integershavewidth=4andrealshavethewidth=816KeepingTrackofscopeInformat
8、ionSomelanguageshavenestedproceduresspecification.Inthiscasewecanassignlocalnamesasinpreviousapproach.Whenisseeanestedprocedure,theprocessingofdeclarationistemporarilysuspendedPDDD;D
9、id:T
10、procid;D;SA
此文档下载收益归作者所有