diff --git a/compiler/res/version.txt b/compiler/res/version.txt index d456f7459..853262655 100644 --- a/compiler/res/version.txt +++ b/compiler/res/version.txt @@ -1 +1 @@ -1.80 +1.81-SNAPSHOT diff --git a/compiler/src/prog8/compiler/target/IAssemblyGenerator.kt b/compiler/src/prog8/compiler/target/IAssemblyGenerator.kt index e050d27fe..50992f2ce 100644 --- a/compiler/src/prog8/compiler/target/IAssemblyGenerator.kt +++ b/compiler/src/prog8/compiler/target/IAssemblyGenerator.kt @@ -6,6 +6,8 @@ internal interface IAssemblyGenerator { fun compileToAssembly(optimize: Boolean): IAssemblyProgram } +internal const val generatedLabelPrefix = "_prog8_label_" + internal interface IAssemblyProgram { val name: String fun assemble(options: CompilationOptions) diff --git a/compiler/src/prog8/compiler/target/c64/AssemblyProgram.kt b/compiler/src/prog8/compiler/target/c64/AssemblyProgram.kt index 08ce35de0..d4659d52a 100644 --- a/compiler/src/prog8/compiler/target/c64/AssemblyProgram.kt +++ b/compiler/src/prog8/compiler/target/c64/AssemblyProgram.kt @@ -3,10 +3,11 @@ package prog8.compiler.target.c64 import prog8.compiler.CompilationOptions import prog8.compiler.OutputType import prog8.compiler.target.IAssemblyProgram +import prog8.compiler.target.generatedLabelPrefix import java.nio.file.Path import kotlin.system.exitProcess -class AssemblyProgram(override val name: String, outputDir: Path): IAssemblyProgram { +class AssemblyProgram(override val name: String, outputDir: Path) : IAssemblyProgram { private val assemblyFile = outputDir.resolve("$name.asm") private val prgFile = outputDir.resolve("$name.prg") private val binFile = outputDir.resolve("$name.bin") @@ -18,7 +19,7 @@ class AssemblyProgram(override val name: String, outputDir: Path): IAssemblyProg "-Wall", "-Wno-strict-bool", "-Wno-shadow", "-Werror", "-Wno-error=long-branch", "--dump-labels", "--vice-labels", "-l", viceMonListFile.toString(), "--no-monitor") - val outFile = when(options.output) { + val outFile = when (options.output) { OutputType.PRG -> { command.add("--cbm-prg") println("\nCreating C-64 prg.") @@ -34,27 +35,39 @@ class AssemblyProgram(override val name: String, outputDir: Path): IAssemblyProg val proc = ProcessBuilder(command).inheritIO().start() val result = proc.waitFor() - if(result!=0) { + if (result != 0) { System.err.println("assembler failed with returncode $result") exitProcess(result) } + removeGeneratedLabelsFromMonlist() generateBreakpointList() } + private fun removeGeneratedLabelsFromMonlist() { + val pattern = Regex("""al (\w+) \S+${generatedLabelPrefix}.+?""") + val lines = viceMonListFile.toFile().readLines() + viceMonListFile.toFile().outputStream().bufferedWriter().use { + for (line in lines) { + if(pattern.matchEntire(line)==null) + it.write(line+"\n") + } + } + } + private fun generateBreakpointList() { // builds list of breakpoints, appends to monitor list file val breakpoints = mutableListOf() - val pattern = Regex("""al (\w+) \S+_prog8_breakpoint_\d+.?""") // gather breakpoints by the source label that"s generated for them - for(line in viceMonListFile.toFile().readLines()) { + val pattern = Regex("""al (\w+) \S+_prog8_breakpoint_\d+.?""") // gather breakpoints by the source label that's generated for them + for (line in viceMonListFile.toFile().readLines()) { val match = pattern.matchEntire(line) - if(match!=null) - breakpoints.add("break \$" + match.groupValues[1]) + if (match != null) + breakpoints.add("break \$" + match.groupValues[1]) } val num = breakpoints.size breakpoints.add(0, "; vice monitor breakpoint list now follows") breakpoints.add(1, "; $num breakpoints have been defined") breakpoints.add(2, "del") - viceMonListFile.toFile().appendText(breakpoints.joinToString("\n")+"\n") + viceMonListFile.toFile().appendText(breakpoints.joinToString("\n") + "\n") } } diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index 829c97ae7..5c9ba0e26 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -14,6 +14,7 @@ import prog8.compiler.target.c64.C64MachineDefinition import prog8.compiler.target.c64.C64MachineDefinition.ESTACK_LO_HEX import prog8.compiler.target.c64.C64MachineDefinition.ESTACK_HI_HEX import prog8.compiler.target.c64.Petscii +import prog8.compiler.target.generatedLabelPrefix import prog8.functions.BuiltinFunctions import prog8.functions.FunctionSignature import java.math.RoundingMode @@ -178,7 +179,7 @@ internal class AsmGen(private val program: Program, internal fun makeLabel(postfix: String): String { generatedLabelSequenceNumber++ - return "_prog8_label_${generatedLabelSequenceNumber}_$postfix" + return "${generatedLabelPrefix}${generatedLabelSequenceNumber}_$postfix" } private fun outputSourceLine(node: Node) {