added -slabshigh N and -slabsgolden for memory() slabs

This commit is contained in:
Irmen de Jong 2023-12-23 20:45:30 +01:00
parent 9b113c0cbb
commit 8ae435549d
10 changed files with 79 additions and 26 deletions

View File

@ -22,6 +22,8 @@ class CompilationOptions(val output: OutputType,
var experimentalCodegen: Boolean = false, var experimentalCodegen: Boolean = false,
var varsHighBank: Int? = null, var varsHighBank: Int? = null,
var varsGolden: Boolean = false, var varsGolden: Boolean = false,
var slabsHighBank: Int? = null,
var slabsGolden: Boolean = false,
var splitWordArrays: Boolean = false, var splitWordArrays: Boolean = false,
var breakpointCpuInstruction: Boolean = false, var breakpointCpuInstruction: Boolean = false,
var outputDir: Path = Path(""), var outputDir: Path = Path(""),

View File

@ -174,6 +174,7 @@ internal class ProgramAndVarsGen(
private fun footer() { private fun footer() {
var relocateBssVars = false var relocateBssVars = false
var relocateBssSlabs = false
var relocatedBssStart = 0u var relocatedBssStart = 0u
var relocatedBssEnd = 0u var relocatedBssEnd = 0u
@ -193,33 +194,61 @@ internal class ProgramAndVarsGen(
options.compTarget.machine.BSSHIGHRAM_END <= options.compTarget.machine.BSSHIGHRAM_START) { options.compTarget.machine.BSSHIGHRAM_END <= options.compTarget.machine.BSSHIGHRAM_START) {
throw AssemblyError("current compilation target hasn't got the high ram area properly defined or it is simply not available") throw AssemblyError("current compilation target hasn't got the high ram area properly defined or it is simply not available")
} }
if(options.slabsHighBank!=null && options.varsHighBank!=options.slabsHighBank)
throw AssemblyError("slabs and vars high bank must be the same")
relocateBssVars = true relocateBssVars = true
relocatedBssStart = options.compTarget.machine.BSSHIGHRAM_START relocatedBssStart = options.compTarget.machine.BSSHIGHRAM_START
relocatedBssEnd = options.compTarget.machine.BSSHIGHRAM_END relocatedBssEnd = options.compTarget.machine.BSSHIGHRAM_END
} }
if(options.slabsGolden) {
if(options.compTarget.machine.BSSGOLDENRAM_START == 0u ||
options.compTarget.machine.BSSGOLDENRAM_END == 0u ||
options.compTarget.machine.BSSGOLDENRAM_END <= options.compTarget.machine.BSSGOLDENRAM_START) {
throw AssemblyError("current compilation target hasn't got the golden ram area properly defined or it is simply not available")
}
relocateBssSlabs = true
relocatedBssStart = options.compTarget.machine.BSSGOLDENRAM_START
relocatedBssEnd = options.compTarget.machine.BSSGOLDENRAM_END
}
else if(options.slabsHighBank!=null) {
if(options.compTarget.machine.BSSHIGHRAM_START == 0u ||
options.compTarget.machine.BSSHIGHRAM_END == 0u ||
options.compTarget.machine.BSSHIGHRAM_END <= options.compTarget.machine.BSSHIGHRAM_START) {
throw AssemblyError("current compilation target hasn't got the high ram area properly defined or it is simply not available")
}
if(options.varsHighBank!=null && options.varsHighBank!=options.slabsHighBank)
throw AssemblyError("slabs and vars high bank must be the same")
relocateBssSlabs = true
relocatedBssStart = options.compTarget.machine.BSSHIGHRAM_START
relocatedBssEnd = options.compTarget.machine.BSSHIGHRAM_END
}
asmgen.out("; bss sections") asmgen.out("; bss sections")
asmgen.out("PROG8_VARSHIGH_RAMBANK = ${options.varsHighBank ?: 1}") asmgen.out("PROG8_VARSHIGH_RAMBANK = ${options.varsHighBank ?: 1}")
if(relocateBssVars) { if(relocateBssVars) {
// BSS vars in another ram area, memory() slabs just concatenated at the end of the program. if(!relocateBssSlabs)
if(symboltable.allMemorySlabs.isNotEmpty()) {
asmgen.out(" .dsection slabs_BSS") asmgen.out(" .dsection slabs_BSS")
}
asmgen.out("prog8_program_end\t; end of program label for progend()") asmgen.out("prog8_program_end\t; end of program label for progend()")
asmgen.out(" * = ${relocatedBssStart.toHex()}") asmgen.out(" * = ${relocatedBssStart.toHex()}")
asmgen.out("prog8_bss_section_start") asmgen.out("prog8_bss_section_start")
asmgen.out(" .dsection BSS") asmgen.out(" .dsection BSS")
asmgen.out(" .cerror * > ${relocatedBssEnd.toHex()}, \"too many variables for BSS section\"") if(relocateBssSlabs)
asmgen.out(" .dsection slabs_BSS")
asmgen.out(" .cerror * > ${relocatedBssEnd.toHex()}, \"too many variables/data for BSS section\"")
asmgen.out("prog8_bss_section_size = * - prog8_bss_section_start") asmgen.out("prog8_bss_section_size = * - prog8_bss_section_start")
} else { } else {
// just append BSS vars followed by memory() slabs, concatenated at the end of the program.
asmgen.out("prog8_bss_section_start") asmgen.out("prog8_bss_section_start")
asmgen.out(" .dsection BSS") asmgen.out(" .dsection BSS")
asmgen.out("prog8_bss_section_size = * - prog8_bss_section_start") asmgen.out("prog8_bss_section_size = * - prog8_bss_section_start")
if(symboltable.allMemorySlabs.isNotEmpty()) { if(!relocateBssSlabs)
asmgen.out(" .dsection slabs_BSS") asmgen.out(" .dsection slabs_BSS")
}
asmgen.out("prog8_program_end\t; end of program label for progend()") asmgen.out("prog8_program_end\t; end of program label for progend()")
if(relocateBssSlabs) {
asmgen.out(" * = ${relocatedBssStart.toHex()}")
asmgen.out(" .dsection slabs_BSS")
asmgen.out(" .cerror * > ${relocatedBssEnd.toHex()}, \"too many data for slabs_BSS section\"")
}
} }
} }

View File

@ -55,6 +55,8 @@ private fun compileMain(args: Array<String>): Boolean {
val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watch for file changes)") val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watch for file changes)")
val varsGolden by cli.option(ArgType.Boolean, fullName = "varsgolden", description = "put uninitialized variables in 'golden ram' memory area instead of at the end of the program. On the cx16 target this is $0400-07ff. This is unavailable on other systems.") val varsGolden by cli.option(ArgType.Boolean, fullName = "varsgolden", description = "put uninitialized variables in 'golden ram' memory area instead of at the end of the program. On the cx16 target this is $0400-07ff. This is unavailable on other systems.")
val varsHighBank by cli.option(ArgType.Int, fullName = "varshigh", description = "put uninitialized variables in high memory area instead of at the end of the program. On the cx16 target the value specifies the HiRAM bank to use, on other systems this value is ignored.") val varsHighBank by cli.option(ArgType.Int, fullName = "varshigh", description = "put uninitialized variables in high memory area instead of at the end of the program. On the cx16 target the value specifies the HiRAM bank to use, on other systems this value is ignored.")
val slabsGolden by cli.option(ArgType.Boolean, fullName = "slabsgolden", description = "put memory() slabs in 'golden ram' memory area instead of at the end of the program. On the cx16 target this is $0400-07ff. This is unavailable on other systems.")
val slabsHighBank by cli.option(ArgType.Int, fullName = "slabshigh", description = "put memory() slabs in high memory area instead of at the end of the program. On the cx16 target the value specifies the HiRAM bank to use, on other systems this value is ignored.")
val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999) val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999)
try { try {
@ -102,11 +104,26 @@ private fun compileMain(args: Array<String>): Boolean {
System.err.println("Golden Ram is only available on the Commander X16 target.") System.err.println("Golden Ram is only available on the Commander X16 target.")
return false return false
} }
if (varsHighBank!=null) { if (varsHighBank!=null || slabsHighBank!=null) {
System.err.println("Either use varsgolden or varshigh, not both.") System.err.println("Either use varsgolden or varshigh (and slabsgolden or slabshigh), not both or mixed.")
return false return false
} }
} }
if (slabsGolden==true) {
if (compilationTarget != Cx16Target.NAME) {
System.err.println("Golden Ram is only available on the Commander X16 target.")
return false
}
if (varsHighBank!=null || slabsHighBank!=null) {
System.err.println("Either use golden or high ram, not both.")
return false
}
}
if(varsHighBank!=null && slabsHighBank!=null && varsHighBank!=slabsHighBank) {
System.err.println("Vars and slabs high memory bank must be the same.")
return false
}
if(startVm==true) { if(startVm==true) {
return runVm(moduleFiles.first()) return runVm(moduleFiles.first())
@ -134,6 +151,8 @@ private fun compileMain(args: Array<String>): Boolean {
experimentalCodegen == true, experimentalCodegen == true,
varsHighBank, varsHighBank,
varsGolden == true, varsGolden == true,
slabsHighBank,
slabsGolden == true,
compilationTarget!!, compilationTarget!!,
splitWordArrays == true, splitWordArrays == true,
breakpointCpuInstruction = false, breakpointCpuInstruction = false,
@ -204,6 +223,8 @@ private fun compileMain(args: Array<String>): Boolean {
experimentalCodegen == true, experimentalCodegen == true,
varsHighBank, varsHighBank,
varsGolden == true, varsGolden == true,
slabsHighBank,
slabsGolden == true,
compilationTarget!!, compilationTarget!!,
splitWordArrays == true, splitWordArrays == true,
breakpointCpuInstruction == true, breakpointCpuInstruction == true,

View File

@ -37,6 +37,8 @@ class CompilerArguments(val filepath: Path,
val experimentalCodegen: Boolean, val experimentalCodegen: Boolean,
val varsHighBank: Int?, val varsHighBank: Int?,
val varsGolden: Boolean, val varsGolden: Boolean,
val slabsHighBank: Int?,
val slabsGolden: Boolean,
val compilationTarget: String, val compilationTarget: String,
val splitWordArrays: Boolean, val splitWordArrays: Boolean,
val breakpointCpuInstruction: Boolean, val breakpointCpuInstruction: Boolean,
@ -79,6 +81,8 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
breakpointCpuInstruction = args.breakpointCpuInstruction breakpointCpuInstruction = args.breakpointCpuInstruction
varsHighBank = args.varsHighBank varsHighBank = args.varsHighBank
varsGolden = args.varsGolden varsGolden = args.varsGolden
slabsHighBank = args.slabsHighBank
slabsGolden = args.slabsGolden
splitWordArrays = args.splitWordArrays splitWordArrays = args.splitWordArrays
outputDir = args.outputDir.normalize() outputDir = args.outputDir.normalize()
symbolDefs = args.symbolDefs symbolDefs = args.symbolDefs

View File

@ -34,6 +34,8 @@ private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilat
experimentalCodegen = false, experimentalCodegen = false,
varsHighBank = null, varsHighBank = null,
varsGolden = false, varsGolden = false,
slabsHighBank = null,
slabsGolden = false,
compilationTarget = target.name, compilationTarget = target.name,
splitWordArrays = false, splitWordArrays = false,
breakpointCpuInstruction = false, breakpointCpuInstruction = false,

View File

@ -32,6 +32,8 @@ class TestCompilerOptionSourcedirs: FunSpec({
experimentalCodegen = false, experimentalCodegen = false,
varsHighBank = null, varsHighBank = null,
varsGolden = false, varsGolden = false,
slabsHighBank = null,
slabsGolden = false,
compilationTarget = Cx16Target.NAME, compilationTarget = Cx16Target.NAME,
splitWordArrays = false, splitWordArrays = false,
breakpointCpuInstruction = false, breakpointCpuInstruction = false,

View File

@ -31,6 +31,8 @@ internal fun compileFile(
experimentalCodegen = false, experimentalCodegen = false,
varsHighBank = null, varsHighBank = null,
varsGolden = false, varsGolden = false,
slabsHighBank = null,
slabsGolden = false,
platform.name, platform.name,
symbolDefs = emptyMap(), symbolDefs = emptyMap(),
outputDir = outputDir, outputDir = outputDir,

View File

@ -2,7 +2,6 @@
TODO TODO
==== ====
- add -slabshigh and -slabsgold to also put the memory() slabs into these memory areas (they're now still always part of the prg itself)
- add -nowarnunused, or %option ignore_unused (module scope), to suppress all warnings about unused symbols. Useful in libraries. - add -nowarnunused, or %option ignore_unused (module scope), to suppress all warnings about unused symbols. Useful in libraries.
put this in all library code, like %option no_symbol_prefixing, and get rid of the "trick" it uses currently to suppress unused symbol warnings for library modules. put this in all library code, like %option no_symbol_prefixing, and get rid of the "trick" it uses currently to suppress unused symbol warnings for library modules.

View File

@ -1,24 +1,14 @@
%import textio %import textio
%zeropage basicsafe %zeropage dontuse
main { main {
sub start() { sub start() {
ubyte[] barr = [1,2,3,4,5,6,7,8,9] uword empty
uword[] warr = [111,222,333,444,555,666,777,888,999] uword block = memory("block", 500, 0)
uword pointer = &barr
byte index = 2
txt.print_ub(barr[7]) txt.print_uwhex(&empty, true)
txt.nl() txt.nl()
txt.print_ub(barr[-2]) txt.print_uwhex(block, true)
txt.nl()
txt.print_ub(pointer[7])
txt.nl()
txt.print_ub(pointer[index])
txt.nl()
txt.print_uw(warr[7])
txt.nl()
txt.print_uw(warr[-2])
txt.nl() txt.nl()
} }
} }

View File

@ -44,7 +44,9 @@ class RequestParser : Take {
splitWordArrays = false, splitWordArrays = false,
breakpointCpuInstruction = false, breakpointCpuInstruction = false,
varsHighBank = null, varsHighBank = null,
varsGolden = false varsGolden = false,
slabsHighBank = null,
slabsGolden = false
) )
compileProgram(args) compileProgram(args)
return RsJson(Jsonding()) return RsJson(Jsonding())