fix symbol table issue

This commit is contained in:
Irmen de Jong 2024-04-06 12:47:04 +02:00
parent 66a6659a6e
commit cfe3fcc9e7
3 changed files with 22 additions and 8 deletions

View File

@ -8,7 +8,6 @@ import prog8.ast.expressions.Expression
import prog8.ast.expressions.NumericLiteral import prog8.ast.expressions.NumericLiteral
import prog8.ast.printProgram import prog8.ast.printProgram
import prog8.ast.statements.Directive import prog8.ast.statements.Directive
import prog8.code.SymbolTable
import prog8.code.SymbolTableMaker import prog8.code.SymbolTableMaker
import prog8.code.ast.PtProgram import prog8.code.ast.PtProgram
import prog8.code.ast.printAst import prog8.code.ast.printAst
@ -148,7 +147,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
println("*********** INTERMEDIATE AST END *************\n") println("*********** INTERMEDIATE AST END *************\n")
} }
if(!createAssemblyAndAssemble(intermediateAst, symbolTable, args.errors, compilationOptions)) { if(!createAssemblyAndAssemble(intermediateAst, args.errors, compilationOptions)) {
System.err.println("Error in codegeneration or assembler") System.err.println("Error in codegeneration or assembler")
return null return null
} }
@ -469,7 +468,6 @@ private fun postprocessAst(program: Program, errors: IErrorReporter, compilerOpt
} }
private fun createAssemblyAndAssemble(program: PtProgram, private fun createAssemblyAndAssemble(program: PtProgram,
symbolTable: SymbolTable,
errors: IErrorReporter, errors: IErrorReporter,
compilerOptions: CompilationOptions compilerOptions: CompilationOptions
): Boolean { ): Boolean {
@ -483,6 +481,10 @@ private fun createAssemblyAndAssemble(program: PtProgram,
else else
throw NotImplementedError("no code generator for cpu ${compilerOptions.compTarget.machine.cpu}") throw NotImplementedError("no code generator for cpu ${compilerOptions.compTarget.machine.cpu}")
// need to make a new symboltable here to capture possible changes made by optimization steps performed earlier!
val stMaker = SymbolTableMaker(program, compilerOptions)
val symbolTable = stMaker.make()
val assembly = asmgen.generate(program, symbolTable, compilerOptions, errors) val assembly = asmgen.generate(program, symbolTable, compilerOptions, errors)
errors.report() errors.report()

View File

@ -1030,4 +1030,21 @@ main {
(a3.children[0] as PtAssignTarget).void shouldBe false (a3.children[0] as PtAssignTarget).void shouldBe false
(a3.children[0] as PtAssignTarget).identifier!!.name shouldBe "cx16.r0H" (a3.children[0] as PtAssignTarget).identifier!!.name shouldBe "cx16.r0H"
} }
test("symbol table correct in asmgen after earlier optimization steps") {
val src="""
main {
sub start() {
uword @shared bulletRef, enemyRef
const ubyte BD_Y = 10
const ubyte EN_Y = 11
if bulletRef[BD_Y] == enemyRef[EN_Y] or bulletRef[BD_Y] == enemyRef[EN_Y] + 1 {
cx16.r0++
}
}
}"""
compileText(VMTarget(), true, src, writeAssembly = true) shouldNotBe null
compileText(C64Target(), true, src, writeAssembly = true) shouldNotBe null
}
}) })

View File

@ -1,11 +1,6 @@
TODO TODO
==== ====
imageviewer is a lot larger now?
fix compiler crash for assembler: unknown identifier [PtIdentifier:parser.proces_directive_str.prog8_subexprvar_1 UBYTE [src/assembler.p8: line 875 col 29-29]]
fix similar crash for petaxian
check docs on assign about status register in assignment (can no longer be ignored, use void to not assign it) check docs on assign about status register in assignment (can no longer be ignored, use void to not assign it)
... ...