From 64c132ee0a367b6cbbe5d3ddea91fda5de0cb0eb Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 22 Jan 2024 21:07:51 +0100 Subject: [PATCH] changed -breakinstr option so that you now specify the exact instruction to use for a %breakpoint. also fixed a IR issue with x=not x. --- .../src/prog8/code/core/CompilationOptions.kt | 2 +- .../src/prog8/codegen/cpu6502/AsmGen.kt | 10 ++----- .../codegen/intermediate/AssignmentGen.kt | 3 +- compiler/src/prog8/CompilerMain.kt | 8 +++-- compiler/src/prog8/compiler/Compiler.kt | 2 +- compiler/test/TestCompilerOnExamples.kt | 2 +- compiler/test/TestCompilerOptionLibdirs.kt | 2 +- compiler/test/helpers/compileXyz.kt | 2 +- docs/source/compiling.rst | 11 +++---- docs/source/todo.rst | 2 -- examples/test.p8 | 29 +++++-------------- .../src/prog8/http/TestHttp.kt | 2 +- 12 files changed, 28 insertions(+), 47 deletions(-) diff --git a/codeCore/src/prog8/code/core/CompilationOptions.kt b/codeCore/src/prog8/code/core/CompilationOptions.kt index a47deac2c..726dfb53e 100644 --- a/codeCore/src/prog8/code/core/CompilationOptions.kt +++ b/codeCore/src/prog8/code/core/CompilationOptions.kt @@ -25,7 +25,7 @@ class CompilationOptions(val output: OutputType, var slabsHighBank: Int? = null, var slabsGolden: Boolean = false, var splitWordArrays: Boolean = false, - var breakpointCpuInstruction: Boolean = false, + var breakpointCpuInstruction: String? = null, var outputDir: Path = Path(""), var symbolDefs: Map = emptyMap() ) { diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index 8d8e99f0e..078d9c389 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -1102,14 +1102,8 @@ $repeatLabel""") val label = "_prog8_breakpoint_${breakpointLabels.size+1}" breakpointLabels.add(label) out(label) - if(options.breakpointCpuInstruction) { - val instruction = - when(options.compTarget.machine.cpu) { - CpuType.CPU6502 -> "brk" - CpuType.CPU65c02 -> "stp" - else -> throw AssemblyError("invalid cpu type") - } - out(" $instruction") + if(options.breakpointCpuInstruction!=null) { + out(" ${options.breakpointCpuInstruction}") } } diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/AssignmentGen.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/AssignmentGen.kt index aa37315b2..642ad50e7 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/AssignmentGen.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/AssignmentGen.kt @@ -110,7 +110,8 @@ internal class AssignmentGen(private val codeGen: IRCodeGen, private val express value.add(origAssign.value) } else { require(origAssign.operator.endsWith('=')) - value = PtBinaryExpression(origAssign.operator.dropLast(1), origAssign.target.type, origAssign.value.position) + val operator = if(origAssign.operator=="==") "==" else origAssign.operator.dropLast(1) + value = PtBinaryExpression(operator, origAssign.target.type, origAssign.value.position) val left: PtExpression = origAssign.target.children.single() as PtExpression value.add(left) value.add(origAssign.value) diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index ef5145d95..6a0f9b8d8 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -52,7 +52,7 @@ private fun compileMain(args: Array): Boolean { val splitWordArrays by cli.option(ArgType.Boolean, fullName = "splitarrays", description = "treat all word arrays as tagged with @split to make them lsb/msb split in memory") val printAst1 by cli.option(ArgType.Boolean, fullName = "printast1", description = "print out the compiler AST") val printAst2 by cli.option(ArgType.Boolean, fullName = "printast2", description = "print out the intermediate AST that is used for code generation") - val breakpointCpuInstruction by cli.option(ArgType.Boolean, fullName = "breakinstr", description = "also use a CPU instruction for %breakpoint") + val breakpointCpuInstruction by cli.option(ArgType.Choice(listOf("brk", "stp"), { it }), fullName = "breakinstr", description = "the CPU instruction to use as well for %breakpoint") val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler (one of '${C64Target.NAME}', '${C128Target.NAME}', '${Cx16Target.NAME}', '${AtariTarget.NAME}', '${PETTarget.NAME}', '${VMTarget.NAME}') (required)") val startVm by cli.option(ArgType.Boolean, fullName = "vm", description = "load and run a .p8ir IR source file in the VM") val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watch for file changes)") @@ -69,6 +69,8 @@ private fun compileMain(args: Array): Boolean { return false } + println("BREAKPOINTINSTR=$breakpointCpuInstruction") + val outputPath = pathFrom(outputDir) if(!outputPath.toFile().isDirectory) { System.err.println("Output path doesn't exist") @@ -158,7 +160,7 @@ private fun compileMain(args: Array): Boolean { slabsGolden == true, compilationTarget!!, splitWordArrays == true, - breakpointCpuInstruction = false, + breakpointCpuInstruction, printAst1 == true, printAst2 == true, processedSymbols, @@ -236,7 +238,7 @@ private fun compileMain(args: Array): Boolean { slabsGolden == true, compilationTarget!!, splitWordArrays == true, - breakpointCpuInstruction == true, + breakpointCpuInstruction, printAst1 == true, printAst2 == true, processedSymbols, diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 758e5e257..ab346c272 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -44,7 +44,7 @@ class CompilerArguments(val filepath: Path, val slabsGolden: Boolean, val compilationTarget: String, val splitWordArrays: Boolean, - val breakpointCpuInstruction: Boolean, + val breakpointCpuInstruction: String?, val printAst1: Boolean, val printAst2: Boolean, val symbolDefs: Map, diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index 412b951f0..1b1037853 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -38,7 +38,7 @@ private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilat slabsGolden = false, compilationTarget = target.name, splitWordArrays = false, - breakpointCpuInstruction = false, + breakpointCpuInstruction = null, printAst1 = false, printAst2 = false, symbolDefs = emptyMap(), diff --git a/compiler/test/TestCompilerOptionLibdirs.kt b/compiler/test/TestCompilerOptionLibdirs.kt index 2ad5cdddd..e4dfbc9d2 100644 --- a/compiler/test/TestCompilerOptionLibdirs.kt +++ b/compiler/test/TestCompilerOptionLibdirs.kt @@ -36,7 +36,7 @@ class TestCompilerOptionSourcedirs: FunSpec({ slabsGolden = false, compilationTarget = Cx16Target.NAME, splitWordArrays = false, - breakpointCpuInstruction = false, + breakpointCpuInstruction = null, printAst1 = false, printAst2 = false, symbolDefs = emptyMap(), diff --git a/compiler/test/helpers/compileXyz.kt b/compiler/test/helpers/compileXyz.kt index f66878d5b..b6ce0bc62 100644 --- a/compiler/test/helpers/compileXyz.kt +++ b/compiler/test/helpers/compileXyz.kt @@ -38,7 +38,7 @@ internal fun compileFile( outputDir = outputDir, errors = errors ?: ErrorReporterForTests(), splitWordArrays = false, - breakpointCpuInstruction = false, + breakpointCpuInstruction = null, printAst1 = false, printAst2 = false ) diff --git a/docs/source/compiling.rst b/docs/source/compiling.rst index 364be0af9..df41cc83d 100644 --- a/docs/source/compiling.rst +++ b/docs/source/compiling.rst @@ -175,12 +175,13 @@ One or more .p8 module files ``-check`` Quickly check the program for errors. No output will be produced. -``-breakinstr`` - Also output a CPU instruction for a ``%breakpoint``, as well as the entry in the vice monitor list file. +``-breakinstr `` + Also output the specified CPU instruction for a ``%breakpoint``, as well as the entry in the vice monitor list file. This can be useful on emulators/systems that don't parse the breakpoint information in the list file, - such as the X16Emu emulator for the Commander X16. Prog8 then uses a STP instruction (65c02) to trigger a - breakpoint in the debugger (if enabled with -debug on the emulator). On a 6502 CPU, this option - will output a BRK instruction instead. + such as the X16Emu emulator for the Commander X16. + Useful instructions to consider are ``brk`` and ``stp``. + For example for the Commander X16 emulator, ``stp`` is useful because it can actually tyrigger + a breakpoint halt in the debugger when this is enabled by running the emulator with -debug. ``-expericodegen`` Use experimental code generation backend (*incomplete*). diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 341062536..6fc84a0a0 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -4,8 +4,6 @@ TODO maze: if cell & UP!=0 and @(celladdr(cx,cy-1)) & (WALKED|BACKTRACKED) ==0 ^^ adding this !=0 caused a weird beq + / lda #1 / + to appear in front of the shortcircuit beq... -make the breakpoint instruction selectable (BRK vs STP) - ... diff --git a/examples/test.p8 b/examples/test.p8 index 3bc70b255..edc297234 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,30 +1,15 @@ %import textio -%zeropage basicsafe +%zeropage dontuse main { sub start() { - const uword one = 1 - const uword two = 2 - uword @shared answer = one * two >> 8 - txt.print_uw(answer) - txt.spc() - txt.print_uw(one * two >> 8) - txt.nl() + ubyte @shared ubb = 99 + uword @shared uww = 12345 + ubyte[200] @shared barr + uword @shared ptr = memory("data", $2000, 0) - const uword uw1 = 99 - const uword uw2 = 22 - uword @shared answer2 = uw1 * uw2 >> 8 - txt.print_uw(answer2) - txt.spc() - txt.print_uw(uw1 * uw2 >> 8) - txt.nl() + %breakpoint - uword @shared uw3 = 99 - uword @shared uw4 = 22 - uword @shared answer3 = uw3 * uw4 >> 8 - txt.print_uw(answer3) - txt.spc() - txt.print_uw(uw3 * uw4 >> 8) - txt.nl() + txt.print_uwhex(sys.progend(), true) } } diff --git a/httpCompilerService/src/prog8/http/TestHttp.kt b/httpCompilerService/src/prog8/http/TestHttp.kt index 7de81f077..578a13d4a 100644 --- a/httpCompilerService/src/prog8/http/TestHttp.kt +++ b/httpCompilerService/src/prog8/http/TestHttp.kt @@ -42,7 +42,7 @@ class RequestParser : Take { asmListfile = false, experimentalCodegen = false, splitWordArrays = false, - breakpointCpuInstruction = false, + breakpointCpuInstruction = null, printAst1 = false, printAst2 = false, varsHighBank = null,