资源描述:
《03_12-03-_Code_Generation_II_18m08s》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、CompilersCodeGenerationIIAlexAikenCodeGenerationIIAlanguagewithintegersandintegeroperationsPD;P
2、DDdefid(ARGS)=E;ARGSid,ARGS
3、idEint
4、id
5、ifE=EthenEelseE1234
6、E+E
7、E–E
8、id(E,…,E)12121nAlexAikenCodeGenerationII•Codeforfunctioncallsandfunctiondefinitionsdep
9、endsonthelayoutoftheAR•AverysimpleARsufficesforthislanguage:–Theresultisalwaysintheaccumulator•NoneedtostoretheresultintheAR–Theactivationrecordholdsactualparameters•Forf(x,…,x)pushx,…,xonthestack1nn1•ThesearetheonlyvariablesinthislanguageAlexAikenCodeG
10、enerationII•Thestackdisciplineguaranteesthatonfunctionexit$spisthesameasitwasonfunctionentry–Noneedforacontrollink•Weneedthereturnaddress•Apointertothecurrentactivationisuseful–Thispointerlivesinregister$fp(framepointer)AlexAikenCodeGenerationII•Summary
11、:Forthislanguage,anARwiththecaller’sframepointer,theactualparameters,andthereturnaddresssuffices•Picture:Consideracalltof(x,y),theARis:FPoldfpyARoffxSPAlexAikenCodeGenerationII•Thecallingsequenceistheinstructions(ofbothcallerandcallee)tosetupafunctionin
12、vocation•Newinstruction:jallabel–Jumptolabel,saveaddressofnextinstructionin$ra–Onotherarchitecturesthereturnaddressisstoredonthestackbythe“call”instructionAlexAikenCodeGenerationIIcgen(f(e,…,e))=1n•Thecallersavesitsvalueoftheframesw$fp0($sp)pointeraddiu
13、$sp$sp-4•Thenitsavestheactualparametersincgen(e)nreverseordersw$a00($sp)addiu$sp$sp-4•Finallythecallersavesthereturn…addressinregister$racgen(e1)•TheARsofaris4*n+4byteslongsw$a00($sp)addiu$sp$sp-4jalf_entryAlexAikenCodeGenerationII•Newinstruction:jrreg–
14、Jumptoaddressinregisterregcgen(deff(x1,…,xn)=e)=•Note:Theframepointerpointstothemove$fp$sptop,notbottomoftheframesw$ra0($sp)•Thecalleepopsthereturnaddress,theaddiu$sp$sp-4actualargumentsandthesavedvalueoftheframepointercgen(e)•z=4*n+8lw$ra4($sp)addiu$sp
15、$spzlw$fp0($sp)jr$raAlexAikenCodeGenerationIIBeforecallOnentryBeforeexitAftercallFPFPFPSPoldfpoldfpSPyyxxSPFPreturnSPAlexAikenCodeGenerationII•Variablereferencesarethelastconstruct•The“variables”ofafunctionarejustitsparameters–Th