ir: making sure all names are scoped properly. textelite now runs in vm

This commit is contained in:
Irmen de Jong
2022-09-25 17:14:44 +02:00
parent dda19c29fe
commit 1d65d63bd9
14 changed files with 164 additions and 61 deletions
@@ -27,7 +27,7 @@ class IRCodeGen(
flattenLabelNames()
flattenNestedSubroutines()
val irProg = IRProgram(program.name, symbolTable, options, program.encoding)
val irProg = IRProgram(program.name, IRSymbolTable(symbolTable), options, program.encoding)
if(!options.dontReinitGlobals) {
// collect global variables initializers
@@ -996,7 +996,8 @@ class IRCodeGen(
private fun translate(parameters: List<PtSubroutineParameter>) =
parameters.map {
val flattenedName = (it.definingSub()!!.scopedName + it.name)
symbolTable.flat.getValue(flattenedName) as StStaticVariable
val orig = symbolTable.flat.getValue(flattenedName) as StStaticVariable
IRSubroutine.IRParam(flattenedName.joinToString("."), orig.dt, orig)
}
private fun translate(alignment: PtBlock.BlockAlignment): IRBlock.BlockAlignment {
@@ -1036,7 +1037,7 @@ class IRCodeGen(
fun addMemorySlab(name: String, size: UInt, align: UInt, position: Position): String {
val scopedName = "prog8_memoryslab_$name"
symbolTable.add(StMemorySlab(scopedName, size, align, null, position))
symbolTable.add(StMemorySlab(scopedName, size, align, position))
return scopedName
}
}
@@ -1,6 +1,5 @@
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import prog8.code.SymbolTable
import prog8.code.core.*
import prog8.code.target.VMTarget
import prog8.codegen.intermediate.IRPeepholeOptimizer
@@ -15,7 +14,6 @@ class TestIRPeepholeOpt: FunSpec({
chunk += line
sub += chunk
block += sub
val st = SymbolTable()
val target = VMTarget()
val options = CompilationOptions(
OutputType.RAW,
@@ -27,7 +25,7 @@ class TestIRPeepholeOpt: FunSpec({
compTarget = target,
loadAddress = target.machine.PROGRAM_LOAD_ADDRESS
)
val prog = IRProgram("test", st, options, target)
val prog = IRProgram("test", IRSymbolTable(null), options, target)
prog.addBlock(block)
return prog
}