From daca87c6d04f26ef62ea4d60d3ae0e44a8806857 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 15 Oct 2023 21:55:09 +0200 Subject: [PATCH] added -breakinstr compiler option --- codeCore/src/prog8/code/core/CompilationOptions.kt | 1 + codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt | 9 +++++++++ compiler/src/prog8/CompilerMain.kt | 3 +++ compiler/src/prog8/buildversion/BuildVersion.kt | 12 ++++++------ compiler/src/prog8/compiler/Compiler.kt | 2 ++ compiler/test/TestCompilerOnExamples.kt | 1 + compiler/test/TestCompilerOptionLibdirs.kt | 1 + compiler/test/helpers/compileXyz.kt | 3 ++- docs/source/compiling.rst | 7 +++++++ examples/test.p8 | 1 + httpCompilerService/src/prog8/http/TestHttp.kt | 1 + 11 files changed, 34 insertions(+), 7 deletions(-) diff --git a/codeCore/src/prog8/code/core/CompilationOptions.kt b/codeCore/src/prog8/code/core/CompilationOptions.kt index b7e7e20a0..3b5e5c026 100644 --- a/codeCore/src/prog8/code/core/CompilationOptions.kt +++ b/codeCore/src/prog8/code/core/CompilationOptions.kt @@ -21,6 +21,7 @@ class CompilationOptions(val output: OutputType, var experimentalCodegen: Boolean = false, var varsHighBank: Int? = null, var splitWordArrays: Boolean = false, + var breakpointCpuInstruction: Boolean = false, 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 87c9f1e44..e90e59cef 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -1026,6 +1026,15 @@ $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") + } } internal fun signExtendAYlsb(valueDt: DataType) { diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index 67ae32b42..b44cf8f7f 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -49,6 +49,7 @@ private fun compileMain(args: Array): Boolean { val sourceDirs by cli.option(ArgType.String, fullName="srcdirs", description = "list of extra paths, separated with ${File.pathSeparator}, to search in for imported modules").multiple().delimiter(File.pathSeparator) val includeSourcelines by cli.option(ArgType.Boolean, fullName = "sourcelines", description = "include original Prog8 source lines in generated asm code") 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 breakpointCpuInstruction by cli.option(ArgType.Boolean, fullName = "breakinstr", description = "also use a CPU instruction 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)") @@ -122,6 +123,7 @@ private fun compileMain(args: Array): Boolean { varsHighBank, compilationTarget!!, splitWordArrays == true, + breakpointCpuInstruction = false, processedSymbols, srcdirs, outputPath @@ -190,6 +192,7 @@ private fun compileMain(args: Array): Boolean { varsHighBank, compilationTarget!!, splitWordArrays == true, + breakpointCpuInstruction == true, processedSymbols, srcdirs, outputPath diff --git a/compiler/src/prog8/buildversion/BuildVersion.kt b/compiler/src/prog8/buildversion/BuildVersion.kt index fec9cac3d..ab9f2d6d7 100644 --- a/compiler/src/prog8/buildversion/BuildVersion.kt +++ b/compiler/src/prog8/buildversion/BuildVersion.kt @@ -5,11 +5,11 @@ package prog8.buildversion */ const val MAVEN_GROUP = "prog8" const val MAVEN_NAME = "compiler" -const val VERSION = "9.5-SNAPSHOT" -const val GIT_REVISION = 4108 -const val GIT_SHA = "c319233ddc7f43a05e2090e293abbed8d80ce8cf" -const val GIT_DATE = "2023-09-18T21:22:03Z" +const val VERSION = "9.5" +const val GIT_REVISION = 4149 +const val GIT_SHA = "203ec5fa46f883885b7e66526f18770aa1717785" +const val GIT_DATE = "2023-10-15T18:24:48Z" const val GIT_BRANCH = "master" -const val BUILD_DATE = "2023-09-18T21:27:55Z" -const val BUILD_UNIX_TIME = 1695072475414L +const val BUILD_DATE = "2023-10-15T19:52:30Z" +const val BUILD_UNIX_TIME = 1697399550365L const val DIRTY = 1 diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 54ab99b45..c3880ff18 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -38,6 +38,7 @@ class CompilerArguments(val filepath: Path, val varsHighBank: Int?, val compilationTarget: String, val splitWordArrays: Boolean, + val breakpointCpuInstruction: Boolean, val symbolDefs: Map, val sourceDirs: List = emptyList(), val outputDir: Path = Path(""), @@ -74,6 +75,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? { asmListfile = args.asmListfile includeSourcelines = args.includeSourcelines experimentalCodegen = args.experimentalCodegen + breakpointCpuInstruction = args.breakpointCpuInstruction varsHighBank = args.varsHighBank splitWordArrays = args.splitWordArrays outputDir = args.outputDir.normalize() diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index 10e4fafaf..2b8811765 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -35,6 +35,7 @@ private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilat varsHighBank = null, compilationTarget = target.name, splitWordArrays = false, + breakpointCpuInstruction = false, symbolDefs = emptyMap(), outputDir = outputDir ) diff --git a/compiler/test/TestCompilerOptionLibdirs.kt b/compiler/test/TestCompilerOptionLibdirs.kt index 0a2ec7645..9c2d32860 100644 --- a/compiler/test/TestCompilerOptionLibdirs.kt +++ b/compiler/test/TestCompilerOptionLibdirs.kt @@ -52,6 +52,7 @@ class TestCompilerOptionSourcedirs: FunSpec({ varsHighBank = null, compilationTarget = Cx16Target.NAME, splitWordArrays = false, + breakpointCpuInstruction = false, symbolDefs = emptyMap(), sourceDirs, outputDir diff --git a/compiler/test/helpers/compileXyz.kt b/compiler/test/helpers/compileXyz.kt index 831e3cbba..f55f39e02 100644 --- a/compiler/test/helpers/compileXyz.kt +++ b/compiler/test/helpers/compileXyz.kt @@ -34,7 +34,8 @@ internal fun compileFile( symbolDefs = emptyMap(), outputDir = outputDir, errors = errors ?: ErrorReporterForTests(), - splitWordArrays = false + splitWordArrays = false, + breakpointCpuInstruction = false ) return compileProgram(args) } diff --git a/docs/source/compiling.rst b/docs/source/compiling.rst index d3c53011d..42334d60f 100644 --- a/docs/source/compiling.rst +++ b/docs/source/compiling.rst @@ -166,6 +166,13 @@ One or more .p8 module files ``-asmlist`` Generate an assembler listing file as well. +``-breakinstr`` + Also output a 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. + ``-expericodegen`` Use experimental code generation backend (*incomplete*). diff --git a/examples/test.p8 b/examples/test.p8 index de569c8e9..cb6f55a48 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -27,6 +27,7 @@ main { txt.spc() txt.print_uwhex(ptr, true) txt.nl() + %breakpoint ptr = &split_array txt.print_uw(peekw(ptr)) txt.nl() diff --git a/httpCompilerService/src/prog8/http/TestHttp.kt b/httpCompilerService/src/prog8/http/TestHttp.kt index 5dbe44760..a70908c3f 100644 --- a/httpCompilerService/src/prog8/http/TestHttp.kt +++ b/httpCompilerService/src/prog8/http/TestHttp.kt @@ -42,6 +42,7 @@ class RequestParser : Take { asmListfile = false, experimentalCodegen = false, splitWordArrays = false, + breakpointCpuInstruction = false, varsHighBank = null, ) compileProgram(args)