diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index d23665e01..c71d19860 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -157,7 +157,7 @@ internal class AsmGen(private val program: Program, pha""") } - out(" jmp main.start ; start program / force start proc to be included") + jmp("main.start") } private fun slaballocations() { @@ -695,7 +695,7 @@ internal class AsmGen(private val program: Program, is Break -> { if(loopEndLabels.isEmpty()) throw AssemblyError("break statement out of context ${stmt.position}") - out(" jmp ${loopEndLabels.peek()}") + jmp(loopEndLabels.peek()) } is WhileLoop -> translate(stmt) is RepeatLoop -> translate(stmt) @@ -930,7 +930,7 @@ internal class AsmGen(private val program: Program, val endLabel = makeLabel("if_end") expressionsAsmGen.translateComparisonExpressionWithJumpIfFalse(booleanCondition, elseLabel) translate(stmt.truepart) - out(" jmp $endLabel") + jmp(endLabel) out(elseLabel) translate(stmt.elsepart) out(endLabel) @@ -952,7 +952,7 @@ internal class AsmGen(private val program: Program, // endless loop out(repeatLabel) translate(stmt.body) - out(" jmp $repeatLabel") + jmp(repeatLabel) out(endLabel) } is NumericLiteralValue -> { @@ -1104,7 +1104,7 @@ $counterVar .word 0""") out(whileLabel) expressionsAsmGen.translateComparisonExpressionWithJumpIfFalse(booleanCondition, endLabel) translate(stmt.body) - out(" jmp $whileLabel") + jmp(whileLabel) out(endLabel) loopEndLabels.pop() } @@ -1138,7 +1138,7 @@ $counterVar .word 0""") if(choice.values==null) { // the else choice translate(choice.statements) - out(" jmp $endLabel") + jmp(endLabel) } else { choiceBlocks.add(choiceLabel to choice.statements) for (cv in choice.values!!) { @@ -1157,11 +1157,11 @@ $counterVar .word 0""") } } } - out(" jmp $endLabel") + jmp(endLabel) for(choiceBlock in choiceBlocks) { out(choiceBlock.first) translate(choiceBlock.second) - out(" jmp $endLabel") + jmp(endLabel) } out(endLabel) } @@ -1220,7 +1220,7 @@ $counterVar .word 0""") val endLabel = makeLabel("branch_end") out(" $instruction $elseLabel") translate(stmt.truepart) - out(" jmp $endLabel") + jmp(endLabel) out(elseLabel) translate(stmt.elsepart) out(endLabel) @@ -1277,14 +1277,12 @@ $label nop""") } } - private fun translate(jmp: Jump) { - out(" jmp ${getJumpTarget(jmp)}") - } + private fun translate(jump: Jump) = jmp(getJumpTarget(jump)) - private fun getJumpTarget(jmp: Jump): String { - val ident = jmp.identifier - val label = jmp.generatedLabel - val addr = jmp.address + private fun getJumpTarget(jump: Jump): String { + val ident = jump.identifier + val label = jump.generatedLabel + val addr = jump.address return when { ident!=null -> { val target = ident.targetStatement(program) diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt b/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt index aebb92491..1cefd62f5 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt @@ -370,7 +370,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal>=leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -381,7 +381,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge cmp #${rightConstVal.number} bcs $jumpIfFalseLabel""") else - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else if (left is DirectMemoryRead) { @@ -390,7 +390,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge asmgen.out(" cmp #${rightConstVal.number} | bcs $jumpIfFalseLabel") } else - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } } @@ -405,7 +405,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal>=leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -439,7 +439,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal>=leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -455,7 +455,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge bcs $jumpIfFalseLabel +""") else - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } } @@ -470,7 +470,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal>=leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -500,7 +500,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal<=leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -538,7 +538,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal<=leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -576,7 +576,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal<=leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -611,7 +611,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal<=leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -647,7 +647,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal>leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -693,7 +693,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal>leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -731,7 +731,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal>leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -765,7 +765,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal>leftConstVal) - asmgen.out(" jmp $jumpIfFalseLabel") + asmgen.jmp(jumpIfFalseLabel) return } else { if (left is IdentifierReference) { @@ -801,7 +801,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal memcopy) - hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine) - optimize swap of two memread values with index, using the same pointer expression/variable, like swap(@(ptr+1), @(ptr+2))