lecture 13 intermediate code generation 2.pptx
TRANSCRIPT
![Page 1: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/1.jpg)
CSE 420Intermediate Code Generation
Lecture 13
![Page 2: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/2.jpg)
Conversions between primitive Conversions between primitive types in Javatypes in Java
![Page 3: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/3.jpg)
Introducing type conversions into Introducing type conversions into expression evaluationexpression evaluation
![Page 4: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/4.jpg)
Abstract syntax tree for the Abstract syntax tree for the function definitionfunction definitionfun length(x) = if null(x) then 0 else length(tl(x)+1)
This is a polymorphic function in ML language
![Page 5: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/5.jpg)
Control FlowControl Flow
Boolean expressions are often used to:
•Alter the flow of control.•Compute logical values.
![Page 6: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/6.jpg)
Short-Circuit Code
![Page 7: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/7.jpg)
Flow-of-Control Flow-of-Control StatementsStatements
![Page 8: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/8.jpg)
Syntax-directed definitionSyntax-directed definition
![Page 9: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/9.jpg)
Generating three-address code for Generating three-address code for booleansbooleans
![Page 10: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/10.jpg)
translation of a simple if-translation of a simple if-statementstatement
•
•
![Page 11: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/11.jpg)
BackpatchingBackpatching• Previous codes for Boolean expressions insert
symbolic labels for jumps• It therefore needs a separate pass to set them to
appropriate addresses• We can use a technique named backpatching to avoid
this• We assume we save instructions into an array and
labels will be indices in the array• For non-terminal B we use two attributes B.truelist
and B.falselist together with following functions:▫ makelist(i): create a new list containing only I, an index into
the array of instructions▫ Merge(p1,p2): concatenates the lists pointed by p1 and p2 and
returns a pointer to the concatenated list▫ Backpatch(p,i): inserts i as the target label for each of the
instruction on the list pointed to by p
![Page 12: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/12.jpg)
Backpatching for Boolean Backpatching for Boolean ExpressionsExpressions
• •
![Page 13: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/13.jpg)
Backpatching for Boolean Backpatching for Boolean ExpressionsExpressions•Annotated parse tree for x < 100 || x > 200 &&
x ! = y
![Page 14: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/14.jpg)
Flow-of-Control Flow-of-Control StatementsStatements
![Page 15: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/15.jpg)
Translation of a switch-Translation of a switch-statementstatement
![Page 16: Lecture 13 intermediate code generation 2.pptx](https://reader033.vdocuments.mx/reader033/viewer/2022052514/587f16d01a28ab350c8b4dab/html5/thumbnails/16.jpg)
Any Question?