Simplify removeDeadCode()

I think relying on just the isBodyEmpty() check is more correct too, as
the end label of a try/catch is exclusive. Furthermore, we don't want to
delete try/catch nodes where the middle of the body is not dead (even if
the start and end are dead).

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent 5c1e630cb8
commit 0395224000
  1. 15
      asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt

@ -108,25 +108,18 @@ fun MethodNode.removeDeadCode(owner: String) {
val analyzer = Analyzer(BasicInterpreter()) val analyzer = Analyzer(BasicInterpreter())
val frames = analyzer.analyze(owner, this) val frames = analyzer.analyze(owner, this)
val deadLabels = mutableSetOf<LabelNode>()
val it = instructions.iterator() val it = instructions.iterator()
var i = 0 var i = 0
for (insn in it) { for (insn in it) {
if (frames[i++] != null) { if (frames[i++] != null || insn is LabelNode) {
continue continue
} }
if (insn is LabelNode) { it.remove()
deadLabels.add(insn) changed = true
} else {
it.remove()
changed = true
}
} }
changed = changed or tryCatchBlocks.removeIf { changed = changed or tryCatchBlocks.removeIf { it.isBodyEmpty() }
it.start in deadLabels && it.end in deadLabels || it.isBodyEmpty()
}
} while (changed) } while (changed)
} }

Loading…
Cancel
Save