Intermediate Code Generation. Chapter 6. Bac k -end and Fron t -end of A Com piler. Bac k -end and Fron t -end of A Com piler. Cl ose t o sou r c e lan g uage (e . g. s y n t a x t r e e ). Cl ose t o machine l an g uage.
An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
Advantagesof UsinganIntermediateLanguage Retargeting-Builda compilerforanewmachine by attaching anew codegeneratorto an existing front-end. Optimization-reuse intermediate code optimizers in compilers fordifferentlanguages and different machines. Note:the terms “intermediate code”,“intermediate language”, and “intermediate representation”are all used interchangeably.
IssuesinDesigninganIR • Whether touseanexisting IR • if targetmachine architecture is similar • if the new language is similar • Whether theIRis appropriate for the kind ofoptimizations tobeperformed • e.g. speculationandpredication • sometransformations maytake muchlongerthanthey wouldona different IR
IssuesinDesigninganIR • Designing anewIRneeds to consider • Level(how machine dependent it is) • Structure • Expressiveness • Appropriateness for general andspecial optimizations • Appropriateness forcodegeneration • Whethermultiple IRs should be used
Multiple-Level IR Target code High-level IR Low-level IR SourceProgram … Semantic Check High-level Optimization Low-level Optimization
UsingMultiple-levelIR • Translating from onelevelto another inthe compilationprocess • Preserving anexisting technology investment • Some representationsmaybe more appropriate foraparticular task.
Commonly UsedIR • :MPossibleIR forms • Graphical representations:such as syntaxtrees,AST (Abstract SyntaxTrees),DAG • Postfixnotation • Threeaddresscode • SSA(StaticSingle Assignment) form • :MIR should haveindividual components thatdescribe simplethings
SyntaxTree + + * a * - b c d a - b c Nodecan have morethan one parent • DirectedAcyclicGraph (DAG): • Morecompactrepresentation • Givescluesregardinggenerationofefficient code
TypesandDeclarations • Typechecking:to ensurethat typesof operands matchthe type expectedby operator • Determinethe storage needed • Calculate the address ofanarray reference • Insertexplicittypeconversion • Choose the writeversionofanoperator • …
StorageLayout • From thetype,we candetermine • amount of storage at runtime. • Atcompiletime, we will use thisamount • to assign its namea relativeaddress. • Typeandrelativeaddressare saved in • thesymboltable entry of thename. • Datawith lengthdeterminedonly at run timesavesa pointer inthe symboltable.
StorageLayout • Multibyteobjectsarestoredin consecutivebytesandgiven the address of thefirstbyte • Storageforaggregates(e.g. arrays and classes)isallocatedinonecontiguous block ofbytes.