use of org.jetbrains.org.objectweb.asm.tree.LineNumberNode in project kotlin by JetBrains.
the class ControlFlowGraph method dotDescribe.
private static String dotDescribe(Node node) {
AbstractInsnNode instruction = node.instruction;
if (instruction instanceof LabelNode) {
return "Label";
} else if (instruction instanceof LineNumberNode) {
LineNumberNode lineNode = (LineNumberNode) instruction;
return "Line " + lineNode.line;
} else if (instruction instanceof FrameNode) {
return "Stack Frame";
} else if (instruction instanceof MethodInsnNode) {
MethodInsnNode method = (MethodInsnNode) instruction;
String cls = method.owner.substring(method.owner.lastIndexOf('/') + 1);
cls = cls.replace('$', '.');
return "Call " + cls + "#" + method.name;
} else if (instruction instanceof FieldInsnNode) {
FieldInsnNode field = (FieldInsnNode) instruction;
String cls = field.owner.substring(field.owner.lastIndexOf('/') + 1);
cls = cls.replace('$', '.');
return "Field " + cls + "#" + field.name;
} else if (instruction instanceof TypeInsnNode && instruction.getOpcode() == Opcodes.NEW) {
return "New " + ((TypeInsnNode) instruction).desc;
}
StringBuilder sb = new StringBuilder();
String opcodeName = getOpcodeName(instruction.getOpcode());
sb.append(opcodeName);
if (instruction instanceof IntInsnNode) {
IntInsnNode in = (IntInsnNode) instruction;
sb.append(" ").append(Integer.toString(in.operand));
} else if (instruction instanceof LdcInsnNode) {
LdcInsnNode ldc = (LdcInsnNode) instruction;
sb.append(" ");
if (ldc.cst instanceof String) {
sb.append("\\\"");
}
sb.append(ldc.cst);
if (ldc.cst instanceof String) {
sb.append("\\\"");
}
}
return sb.toString();
}
use of org.jetbrains.org.objectweb.asm.tree.LineNumberNode in project kotlin by JetBrains.
the class ControlFlowGraph method toDot.
/**
* Generates dot output of the graph. This can be used with
* graphwiz to visualize the graph. For example, if you
* save the output as graph1.gv you can run
* <pre>
* $ dot -Tps graph1.gv -o graph1.ps
* </pre>
* to generate a postscript file, which you can then view
* with "gv graph1.ps".
*
* (There are also some online web sites where you can
* paste in dot graphs and see the visualization right
* there in the browser.)
*
* @return a dot description of this control flow graph,
* useful for debugging
*/
@SuppressWarnings("unused")
public String toDot(@Nullable Set<Node> highlight) {
StringBuilder sb = new StringBuilder();
sb.append("digraph G {\n");
AbstractInsnNode instruction = mMethod.instructions.getFirst();
// Special start node
sb.append(" start -> ").append(getId(mNodeMap.get(instruction))).append(";\n");
sb.append(" start [shape=plaintext];\n");
while (instruction != null) {
Node node = mNodeMap.get(instruction);
if (node != null) {
if (node.successors != null) {
for (Node to : node.successors) {
sb.append(" ").append(getId(node)).append(" -> ").append(getId(to));
if (node.instruction instanceof JumpInsnNode) {
sb.append(" [label=\"");
if (((JumpInsnNode) node.instruction).label == to.instruction) {
sb.append("yes");
} else {
sb.append("no");
}
sb.append("\"]");
}
sb.append(";\n");
}
}
if (node.exceptions != null) {
for (Node to : node.exceptions) {
sb.append(getId(node)).append(" -> ").append(getId(to));
sb.append(" [label=\"exception\"];\n");
}
}
}
instruction = instruction.getNext();
}
// Labels
sb.append("\n");
for (Node node : mNodeMap.values()) {
instruction = node.instruction;
sb.append(" ").append(getId(node)).append(" ");
sb.append("[label=\"").append(dotDescribe(node)).append("\"");
if (highlight != null && highlight.contains(node)) {
sb.append(",shape=box,style=filled");
} else if (instruction instanceof LineNumberNode || instruction instanceof LabelNode || instruction instanceof FrameNode) {
sb.append(",shape=oval,style=dotted");
} else {
sb.append(",shape=box");
}
sb.append("];\n");
}
sb.append("}");
return sb.toString();
}
use of org.jetbrains.org.objectweb.asm.tree.LineNumberNode in project kotlin by JetBrains.
the class ClassContext method findLineNumber.
/**
* Finds the line number closest to the given node
*
* @param node the instruction node to get a line number for
* @return the closest line number, or -1 if not known
*/
public static int findLineNumber(@NonNull AbstractInsnNode node) {
AbstractInsnNode curr = node;
// First search backwards
while (curr != null) {
if (curr.getType() == AbstractInsnNode.LINE) {
return ((LineNumberNode) curr).line;
}
curr = curr.getPrevious();
}
// Then search forwards
curr = node;
while (curr != null) {
if (curr.getType() == AbstractInsnNode.LINE) {
return ((LineNumberNode) curr).line;
}
curr = curr.getNext();
}
return -1;
}
Aggregations