From c6921fba9df242c2d40f52ac0e207466f26c4caf Mon Sep 17 00:00:00 2001 From: Graham Date: Mon, 29 Jul 2019 13:52:30 +0100 Subject: [PATCH] Add InsnNodeUtils This commit introduces four methods: two for finding the next/previous AbstractInsnNode that contains a real JVM opcode and two for finding the next/previous AbstractInsnNode that is virtual (e.g. a label). --- .../java/dev/openrs2/asm/InsnNodeUtils.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.java diff --git a/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.java b/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.java new file mode 100644 index 00000000..7c517a4d --- /dev/null +++ b/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.java @@ -0,0 +1,29 @@ +package dev.openrs2.asm; + +import org.objectweb.asm.tree.AbstractInsnNode; + +public final class InsnNodeUtils { + public static AbstractInsnNode nextReal(AbstractInsnNode insn) { + while ((insn = insn.getNext()) != null && insn.getOpcode() == -1); + return insn; + } + + public static AbstractInsnNode previousReal(AbstractInsnNode insn) { + while ((insn = insn.getPrevious()) != null && insn.getOpcode() == -1); + return insn; + } + + public static AbstractInsnNode nextVirtual(AbstractInsnNode insn) { + while ((insn = insn.getNext()) != null && insn.getOpcode() != -1); + return insn; + } + + public static AbstractInsnNode previousVirtual(AbstractInsnNode insn) { + while ((insn = insn.getPrevious()) != null && insn.getOpcode() != -1); + return insn; + } + + private InsnNodeUtils() { + /* empty */ + } +}