code for graph building is awful but works

This commit is contained in:
Claudio Maggioni 2023-10-10 17:13:02 +02:00
parent d19481edca
commit 8b36443331

View file

@ -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
|| type == AbstractInsnNode.LOOKUPSWITCH_INSN
|| type == AbstractInsnNode.TABLESWITCH_INSN
|| isPointedLabel;
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) {
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) {