mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 01:18:03 +00:00
better Label-Logging-Support
This commit is contained in:
parent
3e2368d13c
commit
eac411972a
@ -1,15 +1,31 @@
|
|||||||
package de.maishai.typedast;
|
package de.maishai.typedast;
|
||||||
|
|
||||||
|
import org.objectweb.asm.Label;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class LoggingMethodVisitor extends MethodVisitor {
|
public class LoggingMethodVisitor extends MethodVisitor {
|
||||||
|
private final Map<Label, String> labelNames = new HashMap<>();
|
||||||
|
private int labelCounter = 0;
|
||||||
|
|
||||||
public LoggingMethodVisitor(MethodVisitor methodVisitor) {
|
public LoggingMethodVisitor(MethodVisitor methodVisitor) {
|
||||||
super(Opcodes.ASM9, methodVisitor);
|
super(Opcodes.ASM9, methodVisitor);
|
||||||
System.out.println("\n--- Visiting Method ---");
|
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) {
|
public static String opcodeToString(int opcode) {
|
||||||
for (java.lang.reflect.Field field : Opcodes.class.getDeclaredFields()) {
|
for (java.lang.reflect.Field field : Opcodes.class.getDeclaredFields()) {
|
||||||
try {
|
try {
|
||||||
@ -72,6 +88,13 @@ public class LoggingMethodVisitor extends MethodVisitor {
|
|||||||
super.visitIntInsn(opcode, operand);
|
super.visitIntInsn(opcode, operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitLabel(Label label) {
|
||||||
|
String labelName = getLabelName(label);
|
||||||
|
System.out.println("visitLabel: " + labelName);
|
||||||
|
super.visitLabel(label);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitLdcInsn(Object value) {
|
public void visitLdcInsn(Object value) {
|
||||||
System.out.println("visitLdcInsn: " + value);
|
System.out.println("visitLdcInsn: " + value);
|
||||||
|
Loading…
Reference in New Issue
Block a user