unused variables are removed more aggressively (no longer checking asm blocks for their names)

This commit is contained in:
Irmen de Jong 2021-04-29 00:48:16 +02:00
parent ed7479c854
commit 4aba0c7405
5 changed files with 10 additions and 15 deletions

View File

@ -317,7 +317,7 @@ private fun writeAssembly(programAst: Program,
programAst.processAstBeforeAsmGeneration(errors, compilerOptions.compTarget)
errors.report()
printAst(programAst)
// printAst(programAst)
compilerOptions.compTarget.machine.initializeZeropage(compilerOptions)
val assembly = asmGeneratorFor(compilerOptions.compTarget,

View File

@ -182,7 +182,7 @@ class CallGraph(private val program: Program) : IAstVisitor {
return false
val allReferencedVardecls = allIdentifiersAndTargets.filter { it.value is VarDecl }.map { it.value }.toSet()
return decl !in allReferencedVardecls && !nameInAssemblyCode(decl.name)
return decl !in allReferencedVardecls // Don't check assembly just for occurrences of variables, if they're not used in prog8 itself, just kill them
}
private fun nameInAssemblyCode(name: String) = allAssemblyNodes.any { it.assembly.contains(name) }

View File

@ -104,12 +104,14 @@ internal class UnusedCodeRemover(private val program: Program,
}
override fun after(decl: VarDecl, parent: Node): Iterable<IAstModification> {
val forceOutput = "force_output" in decl.definingBlock().options()
if(!forceOutput && !decl.autogeneratedDontRemove && callgraph.unused(decl)) {
if(decl.type == VarDeclType.VAR && !decl.definingBlock().isInLibrary)
errors.warn("removing unused variable '${decl.name}'", decl.position)
return listOf(IAstModification.Remove(decl, decl.definingScope()))
if(decl.type==VarDeclType.VAR) {
val forceOutput = "force_output" in decl.definingBlock().options()
if (!forceOutput && !decl.autogeneratedDontRemove && !decl.definingBlock().isInLibrary) {
if (callgraph.unused(decl)) {
errors.warn("removing unused variable '${decl.name}'", decl.position)
return listOf(IAstModification.Remove(decl, decl.definingScope()))
}
}
}
return noModifications

View File

@ -2,7 +2,6 @@
TODO
====
- fix problem that unused vars are no longer properly removed
- BeforeAsmGenerationAstChanger no longer needs to move vardecls??
- simplify cx16.joystick_get2() once this cx16 rom issue is resolved: https://github.com/commanderx16/x16-rom/issues/203

View File

@ -3,12 +3,6 @@ main {
sub start() {
; TODO WHY AREN'T UNUSED VARS REMOVED ANY LONGER???
ubyte xx1
ubyte yy1=22
ubyte zz1=33
repeat {
ubyte xx
ubyte yy=xx