





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






(^) is false go to 4.
(^) thenPart
.
(^) elsePart
.
condition
thenPartIfNode
elsePart
Exp
Stmts
Stmts
if (b) a=1;
will result in code with an extra jump:
iload
(^2) ; Push local #2 (B) onto the stack
ifeq
L1 ; Goto L1 if B is 0 (false)
iconst_
; Push 1
istore
(^1) ; Store stack top into local #1 (a)
goto
L2 ; Skip around else statements
L2:L1:
ElseLabel
(^) CreateUniqueLabel()
condition.Result
(^) AddressNode(JumpIfFalse, ElseLabel)
condition.CodeGen()
thenPart.CodeGen()
if elsePart = null
then GenLabel(ElseLabel)
else OutLabel
(^) CreateUniqueLabel()
GenGoTo(OutLabel)
GenLabel(ElseLabel)
elsePart.CodeGen()
GenLabel(OutLabel)
(^) is false go to 4.
(^) loopBody
.
(^) loopBody
.
(^) is true go to 2.
1.Execute
(^) initializer
(^) code.
3.Execute statements in2.Go to 5.
(^) loopBody
4.Execute
(^) increment
(^) code.
5.If (^) condition
(^) is true go to 3.
condition
forNode
increment
Exp
StmtExpr
Stmts
initializer
loopBody
StmtExpr
initializer.CodeGen()
SkipLabel
(^) CreateUniqueLabel()
GenGoTo(SkipLabel)
TopLabel
(^) CreateUniqueLabel()
GenLabel(TopLabel)
loopBody.CodeGen()
ContinueLabel
(^) getContinueLabel()
GenLabel(ContinueLabel)
increment.CodeGen()
12.11. if condition = null10. GenLabel(SkipLabel)
then GenGoTo(TopLabel)
else condition.Result
(^) AddressNode(JumpIfTrue, TopLabel)
condition.CodeGen()
The special case of
for (;;) {}
generates:
goto
L
L1: L2: L3:
goto
L