add -dumpvars option to dump all allocated variables (zp, normal ram, etc)

This commit is contained in:
Irmen de Jong 2024-02-10 18:42:31 +01:00
parent d7f72056fc
commit 5522a305ab
9 changed files with 57 additions and 3 deletions

View File

@ -19,6 +19,7 @@ class CompilationOptions(val output: OutputType,
var asmQuiet: Boolean = false,
var asmListfile: Boolean = false,
var includeSourcelines: Boolean = false,
var dumpVariables: Boolean = false,
var experimentalCodegen: Boolean = false,
var varsHighBank: Int? = null,
var varsGolden: Boolean = false,

View File

@ -262,6 +262,10 @@ class AsmGen6502Internal (
// write the unmodified code
output.writeLines(assembly)
}
if(options.dumpVariables)
dumpVariables()
return AssemblyProgram(program.name, options.outputDir, options.compTarget)
} else {
errors.report()
@ -269,6 +273,48 @@ class AsmGen6502Internal (
}
}
private fun dumpVariables() {
println("---- VARIABLES DUMP ----")
if(allocator.globalFloatConsts.isNotEmpty()) {
println("Floats:")
allocator.globalFloatConsts.forEach { (value, name) ->
println(" $name = $value")
}
}
if(symbolTable.allMemorySlabs.isNotEmpty()) {
println("Memory slabs:")
symbolTable.allMemorySlabs.sortedBy { it.name }.forEach { slab ->
println(" ${slab.name} ${slab.size} align ${slab.align}")
}
}
if(symbolTable.allMemMappedVariables.isNotEmpty()) {
println("Memory mapped:")
symbolTable.allMemMappedVariables
.sortedWith( compareBy( {it.address}, {it.scopedName} ))
.forEach { mvar ->
println(" ${'$'}${mvar.address.toString(16).padStart(4, '0')}\t${mvar.dt}\t${mvar.scopedName}")
}
}
if(allocator.zeropageVars.isNotEmpty()) {
println("ZeroPage:")
allocator.zeropageVars
.asSequence()
.sortedWith( compareBy( {it.value.address}, {it.key} ))
.forEach { (name, alloc) ->
println(" ${'$'}${alloc.address.toString(16).padStart(2, '0')}\t${alloc.dt}\t$name")
}
}
if(symbolTable.allVariables.isNotEmpty()) {
println("Static variables (not in ZeroPage):")
symbolTable.allVariables
.filterNot { allocator.isZpVar(it.scopedName) }
.sortedBy { it.scopedName }.forEach {
println(" ${it.dt}\t${it.scopedName}\t")
}
}
println("---- VARIABLES DUMP END ----")
}
private fun scanInvalid65816instructions(asmLines: MutableList<String>) {
// The CommanderX16 ships with a WDC 65C02 CPU or a WDC 65816 CPU
// The latter is compatible with the 65C02 except for 4 instructions: RMB, SMB, BBS, BBR.

View File

@ -42,6 +42,7 @@ private fun compileMain(args: Array<String>): Boolean {
val startEmulator1 by cli.option(ArgType.Boolean, fullName = "emu", description = "auto-start emulator after successful compilation")
val startEmulator2 by cli.option(ArgType.Boolean, fullName = "emu2", description = "auto-start alternative emulator after successful compilation")
val experimentalCodegen by cli.option(ArgType.Boolean, fullName = "expericodegen", description = "use experimental/alternative codegen")
val dumpVariables by cli.option(ArgType.Boolean, fullName = "dumpvars", description = "print a dump of the variables in the program")
val dontWriteAssembly by cli.option(ArgType.Boolean, fullName = "noasm", description="don't create assembly code")
val dontOptimize by cli.option(ArgType.Boolean, fullName = "noopt", description = "don't perform code optimizations")
val outputDir by cli.option(ArgType.String, fullName = "out", description = "directory for output files instead of current directory").default(".")
@ -152,6 +153,7 @@ private fun compileMain(args: Array<String>): Boolean {
asmListfile == true,
includeSourcelines == true,
experimentalCodegen == true,
dumpVariables == true,
varsHighBank,
varsGolden == true,
slabsHighBank,
@ -230,6 +232,7 @@ private fun compileMain(args: Array<String>): Boolean {
asmListfile == true,
includeSourcelines == true,
experimentalCodegen == true,
dumpVariables == true,
varsHighBank,
varsGolden == true,
slabsHighBank,

View File

@ -38,6 +38,7 @@ class CompilerArguments(val filepath: Path,
val asmListfile: Boolean,
val includeSourcelines: Boolean,
val experimentalCodegen: Boolean,
val dumpVariables: Boolean,
val varsHighBank: Int?,
val varsGolden: Boolean,
val slabsHighBank: Int?,
@ -83,6 +84,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
asmListfile = args.asmListfile
includeSourcelines = args.includeSourcelines
experimentalCodegen = args.experimentalCodegen
dumpVariables = args.dumpVariables
breakpointCpuInstruction = args.breakpointCpuInstruction
varsHighBank = args.varsHighBank
varsGolden = args.varsGolden

View File

@ -32,6 +32,7 @@ private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilat
asmListfile = false,
includeSourcelines = false,
experimentalCodegen = false,
dumpVariables = false,
varsHighBank = null,
varsGolden = false,
slabsHighBank = null,

View File

@ -30,6 +30,7 @@ class TestCompilerOptionSourcedirs: FunSpec({
asmListfile = false,
includeSourcelines = false,
experimentalCodegen = false,
dumpVariables = false,
varsHighBank = null,
varsGolden = false,
slabsHighBank = null,

View File

@ -29,6 +29,7 @@ internal fun compileFile(
asmListfile = false,
includeSourcelines = false,
experimentalCodegen = false,
dumpVariables = false,
varsHighBank = null,
varsGolden = false,
slabsHighBank = null,

View File

@ -1,8 +1,6 @@
TODO
====
add an option to dump what variables ended up where (zp, normal ram, etc)
chess is larger than on 10.1 (other variables ended up in zeropage)
rockrunner is larger than on 10.1
medemo is quite a bit larger than on 10.1

View File

@ -48,7 +48,8 @@ class RequestParser : Take {
varsHighBank = null,
varsGolden = false,
slabsHighBank = null,
slabsGolden = false
slabsGolden = false,
dumpVariables = false
)
compileProgram(args)
return RsJson(Jsonding())