Title | Project 3 |
---|---|
Author | Anonymous User |
Course | Compilers: Principles And Practice |
Institution | Purdue University |
Pages | 5 |
File Size | 170.7 KB |
File Type | |
Total Downloads | 49 |
Total Views | 143 |
Project 3 of Compilers. Assembly...
CS 352 Spring 2019 Compiler Project 3 Posted March 30, 2019, Due April 27, 2019, 11:59pm 1. Introduction Thisprojectistobedonebyeachstudentindividually.ReviewtheAcademicHonestyPolicypostedon Piazzacarefully.Theduedate/timeisfirm,exceptforthegracedaysallottedtoeachstudent(seethe beginningnoteinProject1handoutaboutthegracedays). Thisisasubstantialprojectconsistingofseveralcomponents.Studentsarestronglyadvisedtostart early,followingthesuggestedtimeline. Studentsareremindedthat,withthescaleof100,Project3counts45. ThesourcecodeinMinijava+followsthesamegrammar (https://piazza.com/class_profile/get_resource/jqkfvqi3m1v1gq/js9ufjf6pp86cz)andthesametype rulesimplementedinProject2.Alltestcasesareassumedtobesyntacticallycorrectwithouttype violations. Youmayfindthedocument“ARM_Assembly_Tutorial.html”postedonPiazza (https://piazza.com/class_profile/get_resource/jqkfvqi3m1v1gq/jtoro1oqk046qz)usefulforthisproject, especiallyifyouarenewtoARMassembly.
2. Project Requirement ThissectiongivesanoverviewofthetasksinProject3.MinutedetailswillbeclarifiedonPiazzaas variousquestionsmaybeposedbystudents. ThemaintaskofProject3istoreplacetheinterpreterwrittenforProject2byanewASTtraversal schemethatconvertsaMiniJava+programintoanequivalentARMassemblycode,withtheadditional goaltomakethegeneratedcodeefficientbyusingregisterallocationschemestobediscussedinclass. Itisassumedthatthetestcaseswillnotcauserun‐timeexceptions.Hencenoerrorsaretobereported. Someofthetypecheckingcodeisstillneededforallocatingvariablesinthememoryandforgenerating address‐computinginstructions. Thecriteriatodeterminethecorrectnessofthegeneratedassemblycodeistorunitthroughsample inputs.TheoutputproducedbytheassemblycodemustagreewiththeexpectedresultoftheMiniJava+ program.(Whenindoubt,testtheMiniJava+programusingthestandardJavacompilation/execution tools.)
AsstatedinMiniJava+specpostedforProject1,thesemanticsofaMiniJava+followsthatinJava standard.StudentsshouldcarefullyreviewrelevantJavatyperulesandexecutionrulesasinProject2. Asdescribedinthelectureslides,thetargethardwareisaRaspberryPivirtualmachineimage.Please refertoLecture29andthepostedmini‐tutorialonPiazzafordetails.
3. The Grading Scheme RecallthatProject2handoutdividedMiniJava+programsintothreecategories.Project3continuesto usethatdivision.Part1constitutethebasiccases,constituting80%ofthetotalpoints.Ofthose,70%of thetotalpointsisattributedtothecorrectnessoftheoutputand10%ofthetotalpointsisattributedto theefficiencyofthegeneratedcode.Themetricofefficiencyistobeannouncedlater,dependingonthe successofinstallingaperformancecounterintheRaspberryPivirtualmachineimage.Themost importantfactorthatimpactstheefficiencyisexpectedtobehowwellregisterallocation isperformed. Part2ofthecasesaddsreferencestoarrayvariablesandclassinstancevariables.Themainworkfor Part2istogenerateaddress‐computationinstructionsforaccessingarrayelementsandinstance variables.Part2counts10%ofthetotalpoints. Part3,whichcounts10%ofthetotalpoints,addsmethodinvocation(whichmayberecursive).Grading willbebasedonbothcorrectnessandefficiency,whereefficiencyisprimarilyaffectedbyhowregister savingandrestoresareoptimized.Theweightofcorrectnessandefficiencyiscurrentlysetto5%eachof thetotalpoints,butwemayreviseitasweunderstandtheeffortinvolvedbetter.
4. A Suggested Implementation Plan 4.1Part1 RecallthatprogramsinPart1fallsintotwosetofcases,onewiththemainclassbutnootherclasses, andtheotherwithboththemainclassandoneotherclass.Thepurposeofhavinganadditionalclassis toallowthefullvarietyofstatementsintheprogram,exceptthegeneralcasesofmethodinvocation. Iftheprogramcontainsthemainclassalone,theonlystatementstobeimplementedwillineffectbe justtheprintingstatements.Eachinvocationoftheprintingmethodhasonlyoneargument,whichis eithertheresultofanintegerconstantexpressionorastringliteral.Instructionstoprintastringliteral followstheexamplegiveninLecture29,byinvokingtheprintfstandardfunction.Theassemblycodeto printtheresultofanintegerconstantexpressionwillbesimilar,exceptthatALUinstructionsthat evaluatetheconstantexpressionsshouldbegeneratedbytraversingtheASTsubtreeforthatexpression. Suchinstructionsareemittedfollowingapost‐ordertraversaloftheASTsubtree. IfaprograminPart1containsanotherclass,C1,besidesthemainclass,thentheargumentinaprinting method(invokedfromthemainmethod)maybethereturnvalueofyetanothermethod,saym1, declaredandimplementedinC1.Themethodm1willhavenoformalparametersinthetestcasesandit willnotmakeanymethodinvocation.Wesuggestthatcodegenerationforsuchaprogrambe
implementedfollowsapost‐ordertraversaloftheASTsubtreeofthemethodbodyofm1.Thus,the instructionstoloadtheoperandsaregeneratedfirst,whichisfollowedbythenextinstructionoperating ontheoperands,andsoon. Wesuggestthat,forPart1,allmethod‐localvariablesarefirstallocatedstatically,usingsymboliclabels asintheARMcodeexampleshowninclass.Similarly,thereturnedvaluefromm1canbestoredina staticlocationknowntothemainmethod.Thisallocationscheme,althoughnotageneralschemeforall MiniJava+programs,makesimplementationforPart1morestraightforwardthanallocatingthe variablestothestack.Thissimplerallocationschemeallowsstudentstofocusontheinstruction selectionforvariouskindsofstatements.AsstudentslaterproceedtoPart3,onlythememory referencinginstructions(includingthoseinPart1)needtobereplacedbytheconventionalstack‐based scheme.
4.2Part2 WhatisnewinPart2isthatarrayandinstancevariablesaredynamicallyconstructedbyinvokingthe standardlibraryfunctionmalloc()intheARMassemblycode.ThemainworkforPart2istodetermine thesizeoftherequestedblockfortheconstructedarrayorobjectandtogenerateaddress‐computation instructionstoaccessarrayelementsandinstancevariables.Therestofcodegenerationisthesameas inPart1.
4.3Part3 Generatingcodeforgeneralmethodinvocation(asdefinedinProject2)isthemainworkforPart3. Differentclassesmayhavenamesakemethods.Thesymboliclabelsintheassemblycodeforsuch methodscanbegeneratedbyconcatenatingtheclassnameandthemethodname. Methodinvocationinvolvesparameterpassingandregistersaving/restoring.Thisshouldfollowan applicationbinaryinterface(ABI).Wewillpostamini‐tutorialontheABIlater. Cross‐classreferencesofinstancevariablesinPart3requirescompile‐timedeterminationofoffsetsto beaddedtothebaseaddressofanobject.Theseissuesandhandlingmethodshavebeendiscussedin previouslectures. TheefficiencyofthecodegeneratedinPart3isprimarilyimpactedbyhowwellthecodeavoids unnecessarysavingandrestoringofregistersasonemethodinvokesanother.Thiswillbediscussedin thelectures.
5. Estimated Timeline
Part1withoutefficiencyconcern(oneweek)
Part2(3days)
Registerallocationschemeforscalarvariables(oneweek)
Part3(oneweek+)
6. Submission instruction 1)Noofflinesubmission(suchasemail)isaccepted. 2)UsethefollowingcommandonCSlabmachinesthatrunanyLinuxOS,e.g.theXINUmachines(i.e., xinu01.cs~xinu20.cs)tosubmityourhomework. turnin–ccs352–pp3[yourworkingdirectory] Priortoexecutingtheturnincommand,itisveryimportantthatyouremoveallfilesinthesubmitted folderexceptthemakefile,theyaccprogram(.y),thelexprogram(.l),andthe.hand.cfilesyouwrite fortheproject.IfyouimplementinC++,similarcaremustbetaken. (YourhomedirectoriesaredirectlyaccessibletoyouonallCSlabmachines.) 3)YouarefreetowriteyourownMakefile,aslongasthefollowingrequirementsaremet. ThegraderwillrunyourMakefilebyexecutingthecommand“makemjavac”toproducetheexecutable programnameedmjavac.Hence,itisimportantthatyourMakefileproducessuchanexecutablewhen invoked. YoumustalsowriteyourMakefilesuchthatwhen“makeclean”isrun,allfiles,excepttheMakefile, yourYaccandlexprograms,andthe.hand.cfiles(ortheC++equivalents),areallremoved.Thisisto ensurethatthesystemdoesnotexceedthestoragelimitsetbythesystemstaff. 4)YourprogramMUSTcompileandrunwithoutanyerroronCSlab’sLinuxmachines.Pleasedoafinal testofthisbeforesubmission,especiallyifyoudoyourprojectonothercomputers. 5)Yourcodewillbetestedforgradinginthefollowingsteps: Step1:Werunthefollowingcommand >./mjavacprogram_name.java where“program_name.java”isthefilenamecontainingtheinputprogram.Yourcodemustproducethe ARMassemblycodeprogram_name.s.Notethefileextension“.s”. Step2:program_name.swillbeassembledandlinkedontheRaspberryPivirtualmachineimage,using command“gcc–oprogram_nameprogram_name.s” Step3:program_nameisexecutedandtheprint‐outexaminedforcorrectness.Efficiencyismeasured.
NOTE:Deviationfromtheaboverequirementwillgeta5pointofpenalty.(Forexample,ifyourcode receives90points,thefinalscoreontheBlackboardforthisassignmentwillbe85points.)
7. Discussion Online [ThissectionisessentiallycopiedfromProject1.] Theteachingstaffwillprovideasetoftestcasesandexpectedresults.Thesetestcasesareintendedas astartingpointforstudentstoformafullunderstandingoftheentiresetofvalidinput.Oneshouldfully expectthat,althoughsomeofthetestcasesmaybeverysimilartothepostones,therestmaywellbe quitedifferentandlikelygobeyondthescopenarrowlydefinedbythepostedtestcases. Studentsareencouragedtoshareanddiscusstestcasesonourcourse’spiazzasite.(Buildingtest casesingroupsisactuallyagoodpracticeusefulforyourcareer.)However,nopartofthesolutionis allowedtobeposted.Theteachingstaffwilldiligentlychecksubmissionsagainsteachotherandagainst submissionsfromprevioussemesters(ifapplicable). PleasedonotpostanycodesegmentonPiazza(noteveninprivatemessages)orinemailforTAsto debugforyou,becausemostofthetimeitisimpossibletolocateerrorswithoutactuallyrunningyour code.Onlyifyoutrulybelieveafewlinesofcodeexplainsyourquestionperfectlywellareyouallowed topostitinaprivatemessageonPiazzaalongwithaclearandspecifictechnicalquestion.Inallother cases,cometoanyPSOtofindhelpfromtheTAor,ifnoPSObesidesyoursiswithoutaschedule conflict,arrangeaspecialtimewithaTAforhelp.IftheTAsarenotabletofindtheproblemafteran effort,emailinstructortoexplainyourdifficulty. ...