summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/tools/InsnSequence.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ftbsc/lll/tools/InsnSequence.java')
-rw-r--r--src/main/java/ftbsc/lll/tools/InsnSequence.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/lll/tools/InsnSequence.java b/src/main/java/ftbsc/lll/tools/InsnSequence.java
new file mode 100644
index 0000000..fbd5f5c
--- /dev/null
+++ b/src/main/java/ftbsc/lll/tools/InsnSequence.java
@@ -0,0 +1,31 @@
+package ftbsc.lll.tools;
+
+import ftbsc.lll.exception.InstructionMismatchException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.InsnList;
+
+import java.util.Objects;
+
+/**
+ * Represents a sequence of instructions contained within two given nodes.
+ * Extends InsnList, but provides additional flexibility.
+ */
+public class InsnSequence extends InsnList implements Opcodes {
+ /**
+ * Public constructor.
+ * Must be given two non-null, connected nodes.
+ * @param startNode the starting node of the pattern
+ * @param endNode the first node of the pattern
+ */
+ public InsnSequence(AbstractInsnNode startNode, AbstractInsnNode endNode) {
+ Objects.requireNonNull(startNode);
+ Objects.requireNonNull(endNode);
+ for(; startNode != endNode && startNode != null; startNode = startNode.getNext())
+ super.add(startNode);
+ if (startNode == null)
+ throw new InstructionMismatchException("Nodes" + getFirst() + " and " + getLast() + " are not connected.");
+ }
+
+ //TODO replace
+}