mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 16:29:21 +00:00
fix subroutine inline problem with strings
This commit is contained in:
parent
a77fde577c
commit
a521982576
@ -16,7 +16,7 @@ class IRUnusedCodeRemover(
|
||||
irprog.blocks.reversed().forEach { block ->
|
||||
if(block.isEmpty()) {
|
||||
irprog.blocks.remove(block)
|
||||
irprog.st.removeTree(block.label)
|
||||
pruneSymboltable(block.label)
|
||||
numRemoved++
|
||||
}
|
||||
}
|
||||
@ -24,6 +24,22 @@ class IRUnusedCodeRemover(
|
||||
return numRemoved
|
||||
}
|
||||
|
||||
private fun pruneSymboltable(blockLabel: String) {
|
||||
// we could clean up the SymbolTable as well, but ONLY if these symbols aren't referenced somewhere still in an instruction
|
||||
val prefix = "$blockLabel."
|
||||
val blockVars = irprog.st.allVariables().filter { it.name.startsWith(prefix) }
|
||||
blockVars.forEach { stVar ->
|
||||
irprog. allSubs().flatMap { it.chunks }.forEach { chunk ->
|
||||
chunk.instructions.forEach { ins ->
|
||||
if(ins.labelSymbol == stVar.name) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
irprog.st.removeTree(blockLabel)
|
||||
}
|
||||
|
||||
private fun removeUnusedSubroutines(): Int {
|
||||
val allLabeledChunks = mutableMapOf<String, IRCodeChunkBase>()
|
||||
irprog.foreachCodeChunk { chunk ->
|
||||
|
@ -75,7 +75,9 @@ class UnusedCodeRemover(private val program: Program,
|
||||
if(!block.statements.any { it is Subroutine && it.hasBeenInlined })
|
||||
errors.warn("removing unused block '${block.name}'", block.position)
|
||||
}
|
||||
program.removeInternedStringsFromRemovedBlock(block)
|
||||
if(!block.statements.any { it is Subroutine && it.hasBeenInlined }) {
|
||||
program.removeInternedStringsFromRemovedBlock(block)
|
||||
}
|
||||
return listOf(IAstModification.Remove(block, parent as IStatementContainer))
|
||||
}
|
||||
}
|
||||
|
@ -178,4 +178,28 @@ main {
|
||||
}"""
|
||||
compileText(C64Target(), false, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("string vars in inlined subroutines are ok") {
|
||||
val src="""
|
||||
main {
|
||||
sub start() {
|
||||
void block2.curdir()
|
||||
void block2.other()
|
||||
}
|
||||
}
|
||||
|
||||
block2 {
|
||||
str result="zzzz"
|
||||
sub curdir() -> str {
|
||||
return result
|
||||
}
|
||||
|
||||
sub other() -> str {
|
||||
return "other"
|
||||
}
|
||||
}"""
|
||||
|
||||
compileText(C64Target(), true, src, writeAssembly = true) shouldNotBe null
|
||||
compileText(VMTarget(), true, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
})
|
@ -1,10 +1,6 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- fix undefined symbol error for sub curdir() -> str { return "todo" }
|
||||
- fix placeholder error for
|
||||
str result = "todo" , sub curdir() -> str { return result }
|
||||
|
||||
- document some library modules better (diskio, etc)
|
||||
|
||||
...
|
||||
|
Loading…
Reference in New Issue
Block a user