}
return graphBuilder.build();
}
public static Graph buildControlFlowGraphWithTryCatch(Program program) {
GraphBuilder graphBuilder = new GraphBuilder(program.basicBlockCount());
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
for (int i = 0; i < program.basicBlockCount(); ++i) {
BasicBlock block = program.basicBlockAt(i);
Instruction insn = block.getLastInstruction();
if (insn != null) {
insn.acceptVisitor(transitionExtractor);
if (transitionExtractor.getTargets() != null) {
for (BasicBlock successor : transitionExtractor.getTargets()) {
graphBuilder.addEdge(i, successor.getIndex());
for (TryCatchBlock succTryCatch : successor.getTryCatchBlocks()) {
graphBuilder.addEdge(i, succTryCatch.getHandler().getIndex());
}
}
}
}
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
graphBuilder.addEdge(i, tryCatch.getHandler().getIndex());
}
}
return graphBuilder.build();
}