diff --git a/asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt b/asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt index 0a50c7fa9f..2de6592912 100644 --- a/asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/InsnListUtils.kt @@ -4,7 +4,6 @@ import org.objectweb.asm.tree.AbstractInsnNode import org.objectweb.asm.tree.InsnList private val ANY_INSN = { _: AbstractInsnNode -> true } -private val JUMP_OR_LABEL = listOf(AbstractInsnNode.LABEL, AbstractInsnNode.JUMP_INSN) fun getExpression( last: AbstractInsnNode, @@ -27,7 +26,7 @@ fun getExpression( } insn = insn.previous - } while (insn != null && insn.type !in JUMP_OR_LABEL && filter(insn)) + } while (insn != null && insn.sequential && filter(insn)) return null } diff --git a/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt b/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt index 566fb4b58c..9b62685a2f 100644 --- a/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt @@ -4,7 +4,11 @@ import org.objectweb.asm.Opcodes import org.objectweb.asm.tree.AbstractInsnNode import org.objectweb.asm.tree.InsnNode import org.objectweb.asm.tree.IntInsnNode +import org.objectweb.asm.tree.JumpInsnNode +import org.objectweb.asm.tree.LabelNode import org.objectweb.asm.tree.LdcInsnNode +import org.objectweb.asm.tree.LookupSwitchInsnNode +import org.objectweb.asm.tree.TableSwitchInsnNode import org.objectweb.asm.util.Textifier import org.objectweb.asm.util.TraceMethodVisitor import java.io.PrintWriter @@ -184,6 +188,17 @@ private val IMPURE_OPCODES = setOf( Opcodes.IFNONNULL ) +private val THROW_RETURN_OPCODES = listOf( + Opcodes.IRETURN, + Opcodes.LRETURN, + Opcodes.FRETURN, + Opcodes.DRETURN, + Opcodes.ARETURN, + Opcodes.RETURN, + Opcodes.RET, + Opcodes.ATHROW +) + val AbstractInsnNode.nextReal: AbstractInsnNode? get() { var insn = next @@ -249,6 +264,15 @@ val AbstractInsnNode.intConstant: Int? } } +val AbstractInsnNode.sequential: Boolean + get() = when (this) { + is LabelNode -> false + is JumpInsnNode -> false + is TableSwitchInsnNode -> false + is LookupSwitchInsnNode -> false + else -> opcode !in THROW_RETURN_OPCODES + } + val AbstractInsnNode.pure: Boolean get() = when (opcode) { in PURE_OPCODES -> true