mirror of
https://github.com/irmen/prog8.git
synced 2024-10-19 07:23:56 +00:00
optimized code for branches containing just a goto or break statement
This commit is contained in:
parent
63332c0530
commit
b7694686c2
@ -124,10 +124,8 @@ io_error:
|
|||||||
; read the filename
|
; read the filename
|
||||||
repeat {
|
repeat {
|
||||||
ubyte char = c64.CHRIN()
|
ubyte char = c64.CHRIN()
|
||||||
if char==0
|
if_z
|
||||||
break
|
break
|
||||||
; if_z
|
|
||||||
; break ; TODO fix generated code for this jump
|
|
||||||
if char=='\"'
|
if char=='\"'
|
||||||
break
|
break
|
||||||
@(nameptr) = char
|
@(nameptr) = char
|
||||||
|
@ -1076,21 +1076,43 @@ $counterVar .byte 0""")
|
|||||||
out(" $instruction ${getJumpTarget(jump)}")
|
out(" $instruction ${getJumpTarget(jump)}")
|
||||||
translate(stmt.elsepart)
|
translate(stmt.elsepart)
|
||||||
} else {
|
} else {
|
||||||
|
val truePartIsJustBreak = stmt.truepart.statements.firstOrNull() is Break
|
||||||
|
val elsePartIsJustBreak = stmt.elsepart.statements.firstOrNull() is Break
|
||||||
if(stmt.elsepart.containsNoCodeNorVars()) {
|
if(stmt.elsepart.containsNoCodeNorVars()) {
|
||||||
|
if(truePartIsJustBreak) {
|
||||||
|
// branch with just a break (jump out of loop)
|
||||||
|
val instruction = branchInstruction(stmt.condition, false)
|
||||||
|
val loopEndLabel = loopEndLabels.peek()
|
||||||
|
out(" $instruction $loopEndLabel")
|
||||||
|
} else {
|
||||||
val instruction = branchInstruction(stmt.condition, true)
|
val instruction = branchInstruction(stmt.condition, true)
|
||||||
val elseLabel = makeLabel("branch_else")
|
val elseLabel = makeLabel("branch_else")
|
||||||
out(" $instruction $elseLabel")
|
out(" $instruction $elseLabel")
|
||||||
translate(stmt.truepart)
|
translate(stmt.truepart)
|
||||||
out(elseLabel)
|
out(elseLabel)
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
else if(truePartIsJustBreak) {
|
||||||
|
// branch with just a break (jump out of loop)
|
||||||
val instruction = branchInstruction(stmt.condition, false)
|
val instruction = branchInstruction(stmt.condition, false)
|
||||||
val trueLabel = makeLabel("branch_true")
|
val loopEndLabel = loopEndLabels.peek()
|
||||||
val endLabel = makeLabel("branch_end")
|
out(" $instruction $loopEndLabel")
|
||||||
out(" $instruction $trueLabel")
|
|
||||||
translate(stmt.elsepart)
|
translate(stmt.elsepart)
|
||||||
out(" jmp $endLabel")
|
} else if(elsePartIsJustBreak) {
|
||||||
out(trueLabel)
|
// branch with just a break (jump out of loop) but true/false inverted
|
||||||
|
val instruction = branchInstruction(stmt.condition, true)
|
||||||
|
val loopEndLabel = loopEndLabels.peek()
|
||||||
|
out(" $instruction $loopEndLabel")
|
||||||
translate(stmt.truepart)
|
translate(stmt.truepart)
|
||||||
|
} else {
|
||||||
|
val instruction = branchInstruction(stmt.condition, true)
|
||||||
|
val elseLabel = makeLabel("branch_else")
|
||||||
|
val endLabel = makeLabel("branch_end")
|
||||||
|
out(" $instruction $elseLabel")
|
||||||
|
translate(stmt.truepart)
|
||||||
|
out(" jmp $endLabel")
|
||||||
|
out(elseLabel)
|
||||||
|
translate(stmt.elsepart)
|
||||||
out(endLabel)
|
out(endLabel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,15 @@ errors {
|
|||||||
|
|
||||||
repeat {
|
repeat {
|
||||||
ubyte char3 = c64.CHRIN()
|
ubyte char3 = c64.CHRIN()
|
||||||
|
if_cc
|
||||||
|
break
|
||||||
|
|
||||||
if_z
|
if_z
|
||||||
goto labeltje
|
char3 ++
|
||||||
if_z
|
else
|
||||||
break ; TODO wrong jump asm generated, works fine if you use a label instead to jump to
|
break
|
||||||
|
|
||||||
|
char3--
|
||||||
}
|
}
|
||||||
labeltje:
|
labeltje:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user