fix asm gen for loops when dealing with registers as loopvar

This commit is contained in:
Irmen de Jong
2019-07-10 08:51:05 +02:00
parent 9a3dab20dc
commit aaaab2cfcf
2 changed files with 16 additions and 7 deletions

View File

@@ -2066,7 +2066,20 @@ internal val patterns = listOf<AsmPattern>(
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_B), listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_UB)) { segment -> AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_B), listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_UB)) { segment ->
// this pattern is encountered as part of the loop bound condition in for loops (var + cmp + jz/jnz) // this pattern is encountered as part of the loop bound condition in for loops (var + cmp + jz/jnz)
val cmpval = segment[1].arg!!.integerValue() val cmpval = segment[1].arg!!.integerValue()
" lda ${segment[0].callLabel} | cmp #$cmpval " when(segment[0].callLabel) {
"A" -> {
" cmp #$cmpval "
}
"X" -> {
" cpx #$cmpval "
}
"Y" -> {
" cpy #$cmpval "
}
else -> {
" lda ${segment[0].callLabel} | cmp #$cmpval "
}
}
}, },
AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_W), listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_UW)) { segment -> AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_W), listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_UW)) { segment ->
// this pattern is encountered as part of the loop bound condition in for loops (var + cmp + jz/jnz) // this pattern is encountered as part of the loop bound condition in for loops (var + cmp + jz/jnz)

View File

@@ -4,17 +4,13 @@
~ main { ~ main {
sub start() { sub start() {
A=0
Y=0
ubyte aa =0
Y=10
for A in 0 to 4 { for A in 0 to 4 {
for Y in 0 to 3 { for Y in 0 to 3 {
rsave() rsave()
c64scr.print_ub(A) c64scr.print_ub(A)
c64.CHROUT(',') c64.CHROUT(',')
rrestore()
rsave()
c64scr.print_ub(Y) c64scr.print_ub(Y)
c64.CHROUT('\n') c64.CHROUT('\n')
rrestore() rrestore()