summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/tools/InsnSequence.java
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-02-07 14:20:26 +0100
committer zaaarf <zaaarf@proton.me>2023-02-07 14:20:26 +0100
commit764ff58eaa6fbfbf3e3809e67c23fcccacfa68eb (patch)
treecff32928c0b36b7b899fe44d549478007e16daf6 /src/main/java/ftbsc/lll/tools/InsnSequence.java
parent809939c50264758ec4f30d58c2557f4f876f9b46 (diff)
feat: implemented ASM pattern matcher
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
+}