use of org.mapleir.stdlib.collections.graph.algorithms.TarjanSCC in project maple-ir by LLVM-but-worse.
the class NaturalisationPass2 method run.
@Override
public void run() {
TarjanSCC<BasicBlock> scc = new TarjanSCC<>(builder.graph);
for (BasicBlock b : builder.graph.vertices()) {
if (scc.low(b) == -1) {
scc.search(b);
}
}
List<BasicBlock> order = new ArrayList<>();
for (List<BasicBlock> c : scc.getComponents()) {
order.addAll(c);
}
builder.graph.naturalise(order);
}
use of org.mapleir.stdlib.collections.graph.algorithms.TarjanSCC in project maple-ir by LLVM-but-worse.
the class DemoteRangesPass method process.
private void process(ApplicationClassSource app, ControlFlowGraph cfg, ExceptionAnalysis analysis) {
TarjanSCC<BasicBlock> sccComputor = new TarjanSCC<>(cfg);
for (BasicBlock b : cfg.vertices()) {
if (sccComputor.low(b) == -1) {
sccComputor.search(b);
}
}
Map<BasicBlock, List<BasicBlock>> sccs = new HashMap<>();
for (List<BasicBlock> l : sccComputor.getComponents()) {
for (BasicBlock e : l) {
if (sccs.containsKey(e)) {
throw new IllegalStateException();
} else {
sccs.put(e, l);
}
}
}
for (ExceptionRange<BasicBlock> er : cfg.getRanges()) {
/* if the handler catches */
for (BasicBlock b : er.get()) {
Set<Type> canThrow = new HashSet<>();
List<BasicBlock> comp = new ArrayList<>();
if (sccs.containsKey(b)) {
comp.addAll(sccs.get(b));
} else {
comp.add(b);
}
for (BasicBlock e : comp) {
for (Stmt stmt : e) {
canThrow.addAll(analysis.getPossibleUserThrowables(stmt));
}
}
if (!catchesAny(app, er.getTypes(), canThrow)) {
if (comp.size() > 1) {
System.out.println("promote: " + GraphUtils.toNodeArray(comp));
for (BasicBlock e : comp) {
System.out.println(ControlFlowGraph.printBlock(e));
}
System.out.println(" canThrow: " + canThrow);
System.out.println(" catching: " + er.getTypes());
System.out.println();
System.out.println();
System.out.println();
return;
}
} else {
break;
}
}
}
}
Aggregations