Search in sources :

Example 1 with TarjanSCC

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);
}
Also used : BasicBlock(org.mapleir.ir.cfg.BasicBlock) ArrayList(java.util.ArrayList) TarjanSCC(org.mapleir.stdlib.collections.graph.algorithms.TarjanSCC)

Example 2 with TarjanSCC

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;
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) BasicBlock(org.mapleir.ir.cfg.BasicBlock) ArrayList(java.util.ArrayList) Stmt(org.mapleir.ir.code.Stmt) Type(org.objectweb.asm.Type) TarjanSCC(org.mapleir.stdlib.collections.graph.algorithms.TarjanSCC) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)2 BasicBlock (org.mapleir.ir.cfg.BasicBlock)2 TarjanSCC (org.mapleir.stdlib.collections.graph.algorithms.TarjanSCC)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Stmt (org.mapleir.ir.code.Stmt)1 Type (org.objectweb.asm.Type)1