Search in sources :

Example 1 with JumpInsnNode

use of org.jetbrains.org.objectweb.asm.tree.JumpInsnNode in project intellij-community by JetBrains.

the class Subroutine method merge.

public boolean merge(final Subroutine subroutine) throws AnalyzerException {
    boolean changes = false;
    for (int i = 0; i < access.length; ++i) {
        if (subroutine.access[i] && !access[i]) {
            access[i] = true;
            changes = true;
        }
    }
    if (subroutine.start == start) {
        for (int i = 0; i < subroutine.callers.size(); ++i) {
            JumpInsnNode caller = subroutine.callers.get(i);
            if (!callers.contains(caller)) {
                callers.add(caller);
                changes = true;
            }
        }
    }
    return changes;
}
Also used : JumpInsnNode(org.jetbrains.org.objectweb.asm.tree.JumpInsnNode)

Example 2 with JumpInsnNode

use of org.jetbrains.org.objectweb.asm.tree.JumpInsnNode 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();
}
Also used : LabelNode(org.jetbrains.org.objectweb.asm.tree.LabelNode) FrameNode(org.jetbrains.org.objectweb.asm.tree.FrameNode) FieldInsnNode(org.jetbrains.org.objectweb.asm.tree.FieldInsnNode) FrameNode(org.jetbrains.org.objectweb.asm.tree.FrameNode) JumpInsnNode(org.jetbrains.org.objectweb.asm.tree.JumpInsnNode) MethodInsnNode(org.jetbrains.org.objectweb.asm.tree.MethodInsnNode) TryCatchBlockNode(org.jetbrains.org.objectweb.asm.tree.TryCatchBlockNode) AbstractInsnNode(org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode) LineNumberNode(org.jetbrains.org.objectweb.asm.tree.LineNumberNode) TypeInsnNode(org.jetbrains.org.objectweb.asm.tree.TypeInsnNode) ClassNode(org.jetbrains.org.objectweb.asm.tree.ClassNode) IntInsnNode(org.jetbrains.org.objectweb.asm.tree.IntInsnNode) LabelNode(org.jetbrains.org.objectweb.asm.tree.LabelNode) LdcInsnNode(org.jetbrains.org.objectweb.asm.tree.LdcInsnNode) MethodNode(org.jetbrains.org.objectweb.asm.tree.MethodNode) JumpInsnNode(org.jetbrains.org.objectweb.asm.tree.JumpInsnNode) LineNumberNode(org.jetbrains.org.objectweb.asm.tree.LineNumberNode) AbstractInsnNode(org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)

Aggregations

JumpInsnNode (org.jetbrains.org.objectweb.asm.tree.JumpInsnNode)2 AbstractInsnNode (org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)1 ClassNode (org.jetbrains.org.objectweb.asm.tree.ClassNode)1 FieldInsnNode (org.jetbrains.org.objectweb.asm.tree.FieldInsnNode)1 FrameNode (org.jetbrains.org.objectweb.asm.tree.FrameNode)1 IntInsnNode (org.jetbrains.org.objectweb.asm.tree.IntInsnNode)1 LabelNode (org.jetbrains.org.objectweb.asm.tree.LabelNode)1 LdcInsnNode (org.jetbrains.org.objectweb.asm.tree.LdcInsnNode)1 LineNumberNode (org.jetbrains.org.objectweb.asm.tree.LineNumberNode)1 MethodInsnNode (org.jetbrains.org.objectweb.asm.tree.MethodInsnNode)1 MethodNode (org.jetbrains.org.objectweb.asm.tree.MethodNode)1 TryCatchBlockNode (org.jetbrains.org.objectweb.asm.tree.TryCatchBlockNode)1 TypeInsnNode (org.jetbrains.org.objectweb.asm.tree.TypeInsnNode)1