diff --git a/deob/src/main/java/dev/openrs2/deob/analysis/LiveVariableAnalyzer.kt b/deob/src/main/java/dev/openrs2/deob/analysis/LiveVariableAnalyzer.kt new file mode 100644 index 00000000..924d154e --- /dev/null +++ b/deob/src/main/java/dev/openrs2/deob/analysis/LiveVariableAnalyzer.kt @@ -0,0 +1,30 @@ +package dev.openrs2.deob.analysis + +import org.objectweb.asm.Opcodes +import org.objectweb.asm.tree.AbstractInsnNode +import org.objectweb.asm.tree.IincInsnNode +import org.objectweb.asm.tree.MethodNode +import org.objectweb.asm.tree.VarInsnNode + +class LiveVariableAnalyzer(owner: String, method: MethodNode) : + DataFlowAnalyzer>(owner, method, backwards = true) { + override fun createInitialSet(): Set { + return emptySet() + } + + override fun join(set1: Set, set2: Set): Set { + return set1 union set2 + } + + override fun transfer(set: Set, insn: AbstractInsnNode): Set { + return when (insn) { + is VarInsnNode -> when (insn.opcode) { + Opcodes.ILOAD, Opcodes.LLOAD, Opcodes.FLOAD, Opcodes.DLOAD, Opcodes.ALOAD -> set.plus(insn.`var`) + Opcodes.ISTORE, Opcodes.LSTORE, Opcodes.FSTORE, Opcodes.DSTORE, Opcodes.ASTORE -> set.minus(insn.`var`) + else -> set + } + is IincInsnNode -> set.plus(insn.`var`) + else -> set + } + } +}