code for graph building is awful but works
This commit is contained in:
parent
d19481edca
commit
8b36443331
1 changed files with 16 additions and 6 deletions
|
@ -97,7 +97,7 @@ public class ControlFlowGraphBuilder {
|
|||
labels.add((LabelNode) instruction);
|
||||
}
|
||||
|
||||
if (isBranchingInstruction(type, isPointedLabel)) {
|
||||
if (isEndOfBlock(instruction, labelToIncomingEdges)) {
|
||||
final int nextI = i + 1;
|
||||
|
||||
// if we're not at the end
|
||||
|
@ -137,11 +137,21 @@ public class ControlFlowGraphBuilder {
|
|||
|| opcode == Opcodes.FRETURN;
|
||||
}
|
||||
|
||||
private static boolean isBranchingInstruction(int type, boolean isPointedLabel) {
|
||||
return type == AbstractInsnNode.JUMP_INSN
|
||||
private static boolean isEndOfBlock(AbstractInsnNode instruction, MultiMap<LabelNode, Edge> labelToInstruction) {
|
||||
final AbstractInsnNode nextInsn = instruction.getNext();
|
||||
if (nextInsn == null) {
|
||||
return false; // cannot start another bb at the end of the method with 0 instructions
|
||||
}
|
||||
|
||||
final int type = instruction.getType();
|
||||
if (type == AbstractInsnNode.JUMP_INSN
|
||||
|| type == AbstractInsnNode.LOOKUPSWITCH_INSN
|
||||
|| type == AbstractInsnNode.TABLESWITCH_INSN
|
||||
|| isPointedLabel;
|
||||
|| type == AbstractInsnNode.TABLESWITCH_INSN) {
|
||||
return true; // if we're branching or jumping after this instruction, we NEED to cut the current bb short
|
||||
}
|
||||
|
||||
// if the next instruction is a label some other bb may jump into then cut, otherwise continue
|
||||
return nextInsn instanceof LabelNode && labelToInstruction.containsKey((LabelNode) nextInsn);
|
||||
}
|
||||
|
||||
private record Edge(AbstractInsnNode instruction, String condition) {
|
||||
|
|
Reference in a new issue