diff --git a/output/Operators.class b/output/Operators.class new file mode 100644 index 0000000..bf364f7 Binary files /dev/null and b/output/Operators.class differ diff --git a/pom.xml b/pom.xml index b3ad7f7..5ef0e2f 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,12 @@ RELEASE test + + junit + junit + 4.13.1 + test + commons-cli diff --git a/src/main/java/de/maishai/typedast/LoggingMethodVisitor.java b/src/main/java/de/maishai/typedast/LoggingMethodVisitor.java new file mode 100644 index 0000000..7d7870a --- /dev/null +++ b/src/main/java/de/maishai/typedast/LoggingMethodVisitor.java @@ -0,0 +1,103 @@ +package de.maishai.typedast; + +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +import java.util.HashMap; +import java.util.Map; + +public class LoggingMethodVisitor extends MethodVisitor { + private final Map labelNames = new HashMap<>(); + private int labelCounter = 0; + + public LoggingMethodVisitor(MethodVisitor methodVisitor) { + super(Opcodes.ASM9, methodVisitor); + System.out.println("\n--- Visiting Method ---"); + } + + private String getLabelName(Label label) { + return labelNames.computeIfAbsent(label, k -> "label" + labelCounter++); + } + + @Override + public void visitJumpInsn(int opcode, Label label) { + System.out.println("visitJumpInsn: " + opcodeToString(opcode) + ", " + getLabelName(label)); + super.visitJumpInsn(opcode, label); + } + + public static String opcodeToString(int opcode) { + for (java.lang.reflect.Field field : Opcodes.class.getDeclaredFields()) { + try { + if (field.getType() == int.class && field.getInt(null) == opcode) { + return field.getName(); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + return "UNKNOWN"; + } + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { + System.out.println("visitMethodInsn: " + opcodeToString(opcode) + ", " + owner + ", " + name + ", " + descriptor + ", " + isInterface); + super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); + } + + @Override + public void visitVarInsn(int opcode, int varIndex) { + System.out.println("visitVarInsn: " + opcodeToString(opcode) + ", " + varIndex); + super.visitVarInsn(opcode, varIndex); + } + + @Override + public void visitTypeInsn(int opcode, String type) { + System.out.println("visitTypeInsn: " + opcodeToString(opcode) + ", " + type); + super.visitTypeInsn(opcode, type); + } + + @Override + public void visitInsn(int opcode) { + System.out.println("visitInsn: " + opcodeToString(opcode)); + super.visitInsn(opcode); + } + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String descriptor) { + System.out.println("visitMethodInsn: " + opcodeToString(opcode) + ", " + owner + ", " + name + ", " + descriptor); + super.visitMethodInsn(opcode, owner, name, descriptor); + } + + @Override + public void visitFieldInsn(int opcode, String owner, String name, String descriptor) { + System.out.println("visitFieldInsn: " + opcodeToString(opcode) + ", " + owner + ", " + name + ", " + descriptor); + super.visitFieldInsn(opcode, owner, name, descriptor); + } + + @Override + public void visitMaxs(int maxStack, int maxLocals) { + System.out.println("visitMaxs: " + maxStack + ", " + maxLocals); + super.visitMaxs(maxStack, maxLocals); + } + + @Override + public void visitIntInsn(int opcode, int operand) { + String opcodeString = opcode == Opcodes.BIPUSH ? "BIPUSH" : "SIPUSH"; + System.out.println("visitIntInsn: " + opcodeString + ", " + operand); + super.visitIntInsn(opcode, operand); + } + + @Override + public void visitLabel(Label label) { + String labelName = getLabelName(label); + System.out.println("visitLabel: " + labelName); + super.visitLabel(label); + } + + @Override + public void visitLdcInsn(Object value) { + System.out.println("visitLdcInsn: " + value); + super.visitLdcInsn(value); + } +} diff --git a/src/main/java/de/maishai/typedast/MethodContext.java b/src/main/java/de/maishai/typedast/MethodContext.java index 9e741e1..41b4e3b 100644 --- a/src/main/java/de/maishai/typedast/MethodContext.java +++ b/src/main/java/de/maishai/typedast/MethodContext.java @@ -28,7 +28,12 @@ public class MethodContext { private final Deque