mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 08: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;
|
||||
|
||||
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<Label, String> 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 {
|
||||
@ -72,6 +88,13 @@ public class LoggingMethodVisitor extends MethodVisitor {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user