diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 8a533a26e..a5b2a9e83 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -8,7 +8,6 @@ import prog8.ast.expressions.Expression import prog8.ast.expressions.NumericLiteral import prog8.ast.printProgram import prog8.ast.statements.Directive -import prog8.code.SymbolTable import prog8.code.SymbolTableMaker import prog8.code.ast.PtProgram import prog8.code.ast.printAst @@ -148,7 +147,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? { 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") return null } @@ -469,7 +468,6 @@ private fun postprocessAst(program: Program, errors: IErrorReporter, compilerOpt } private fun createAssemblyAndAssemble(program: PtProgram, - symbolTable: SymbolTable, errors: IErrorReporter, compilerOptions: CompilationOptions ): Boolean { @@ -483,6 +481,10 @@ private fun createAssemblyAndAssemble(program: PtProgram, else 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) errors.report() diff --git a/compiler/test/TestOptimization.kt b/compiler/test/TestOptimization.kt index 0af8d15dd..83b361dd6 100644 --- a/compiler/test/TestOptimization.kt +++ b/compiler/test/TestOptimization.kt @@ -1030,4 +1030,21 @@ main { (a3.children[0] as PtAssignTarget).void shouldBe false (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 + } }) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 0d7dbd1c6..9523fbbb5 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,11 +1,6 @@ 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) ...