Search in sources :

Example 26 with BasicBlock

use of org.mapleir.ir.cfg.BasicBlock in project maple-ir by LLVM-but-worse.

the class GenerationPass method makeBlock.

protected BasicBlock makeBlock(LabelNode label) {
    BasicBlock b = new BasicBlock(builder.graph, ++builder.count, label);
    queue(label);
    builder.graph.addVertex(b);
    return b;
}
Also used : BasicBlock(org.mapleir.ir.cfg.BasicBlock)

Example 27 with BasicBlock

use of org.mapleir.ir.cfg.BasicBlock in project maple-ir by LLVM-but-worse.

the class GenerationPass method _switch.

protected void _switch(LinkedHashMap<Integer, BasicBlock> targets, BasicBlock dflt) {
    save_stack(false);
    Expr expr = pop();
    for (Entry<Integer, BasicBlock> e : targets.entrySet()) {
        update_target_stack(currentBlock, e.getValue(), currentStack);
    }
    update_target_stack(currentBlock, dflt, currentStack);
    addStmt(new SwitchStmt(expr, targets, dflt));
}
Also used : InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) Expr(org.mapleir.ir.code.Expr) BasicBlock(org.mapleir.ir.cfg.BasicBlock)

Example 28 with BasicBlock

use of org.mapleir.ir.cfg.BasicBlock in project maple-ir by LLVM-but-worse.

the class GenerationPass method makeRanges.

private void makeRanges(List<BasicBlock> order) {
    // System.out.println(builder.graph);
    // BasicDotConfiguration<ControlFlowGraph, BasicBlock, FlowEdge<BasicBlock>> config = new BasicDotConfiguration<>(DotConfiguration.GraphType.DIRECTED);
    // DotWriter<ControlFlowGraph, BasicBlock, FlowEdge<BasicBlock>> writer = new DotWriter<>(config, builder.graph);
    // writer.removeAll().add(new ControlFlowGraphDecorator().setFlags(ControlFlowGraphDecorator.OPT_DEEP)).setName("test9999").export();
    Map<String, ExceptionRange<BasicBlock>> ranges = new HashMap<>();
    for (TryCatchBlockNode tc : builder.method.tryCatchBlocks) {
        // System.out.printf("from %d to %d, handler:%d, type:%s.%n", insns.indexOf(tc.start), insns.indexOf(tc.end), insns.indexOf(tc.handler), tc.type);
        // System.out.println(String.format("%s:%s:%s", BasicBlock.createBlockName(insns.indexOf(tc.start)), BasicBlock.createBlockName(insns.indexOf(tc.end)), builder.graph.getBlock(tc.handler).getId()));
        int start = builder.graph.getBlock(tc.start).getNumericId();
        int end = builder.graph.getBlock(tc.end).getNumericId() - 1;
        List<BasicBlock> range = range(order, start, end);
        BasicBlock handler = builder.graph.getBlock(tc.handler);
        String key = String.format("%d:%d:%s", start, end, handler.getNumericId());
        ExceptionRange<BasicBlock> erange;
        if (ranges.containsKey(key)) {
            erange = ranges.get(key);
        } else {
            erange = new ExceptionRange<>(tc);
            erange.setHandler(handler);
            erange.addVertices(range);
            ranges.put(key, erange);
            if (!erange.isContiguous()) {
                System.out.println(erange + " not contiguous");
            }
            builder.graph.addRange(erange);
        }
        /* add L; so that the internal descriptor here matches the
			 * one provided by Type.getType(Class) and therefore
			 * ExceptionAnalysis.getType(Class). 
			 * 
			 * 26/08/17: changed Type.getType to return consistent
			 * object refs and to not create Types of sort METHOD
			 * if the given descriptor isn't intended for getType
			 * (getObjectType instead), shouldn't have this problem now.*/
        erange.addType(tc.type != null ? Type.getType("L" + tc.type + ";") : TypeUtils.THROWABLE);
        ListIterator<BasicBlock> lit = range.listIterator();
        while (lit.hasNext()) {
            BasicBlock block = lit.next();
            builder.graph.addEdge(block, new TryCatchEdge<>(block, erange));
        }
    }
}
Also used : ExceptionRange(org.mapleir.flowgraph.ExceptionRange) BasicBlock(org.mapleir.ir.cfg.BasicBlock)

Example 29 with BasicBlock

use of org.mapleir.ir.cfg.BasicBlock in project maple-ir by LLVM-but-worse.

the class GenerationPass method entry.

protected void entry(LabelNode firstLabel) {
    LabelNode l = new LabelNode();
    BasicBlock entry = new BasicBlock(builder.graph, ++builder.count, l);
    entry.setFlag(BasicBlock.FLAG_NO_MERGE, true);
    builder.graph.addVertex(entry);
    builder.graph.getEntries().add(entry);
    setInputStack(entry, new ExpressionStack(16));
    defineInputs(builder.method, entry);
    insns.insertBefore(firstLabel, l);
    BasicBlock b = makeBlock(firstLabel);
    setInputStack(b, new ExpressionStack(16));
    queue(firstLabel);
    builder.graph.addEdge(entry, new ImmediateEdge<>(entry, b));
}
Also used : BasicBlock(org.mapleir.ir.cfg.BasicBlock) ExpressionStack(org.mapleir.ir.code.ExpressionStack)

Example 30 with BasicBlock

use of org.mapleir.ir.cfg.BasicBlock 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)

Aggregations

BasicBlock (org.mapleir.ir.cfg.BasicBlock)70 Stmt (org.mapleir.ir.code.Stmt)37 Expr (org.mapleir.ir.code.Expr)34 Local (org.mapleir.ir.locals.Local)30 VarExpr (org.mapleir.ir.code.expr.VarExpr)29 CopyPhiStmt (org.mapleir.ir.code.stmt.copy.CopyPhiStmt)25 AbstractCopyStmt (org.mapleir.ir.code.stmt.copy.AbstractCopyStmt)24 CopyVarStmt (org.mapleir.ir.code.stmt.copy.CopyVarStmt)22 PhiExpr (org.mapleir.ir.code.expr.PhiExpr)19 VersionedLocal (org.mapleir.ir.locals.impl.VersionedLocal)19 HashSet (java.util.HashSet)12 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)11 UnconditionalJumpStmt (org.mapleir.ir.code.stmt.UnconditionalJumpStmt)10 InvocationExpr (org.mapleir.ir.code.expr.invoke.InvocationExpr)9 BasicLocal (org.mapleir.ir.locals.impl.BasicLocal)9 NullPermeableHashMap (org.mapleir.stdlib.collections.map.NullPermeableHashMap)9 ConditionalJumpStmt (org.mapleir.ir.code.stmt.ConditionalJumpStmt)8 Type (org.objectweb.asm.Type)7 ArrayList (java.util.ArrayList)6 ConstantExpr (org.mapleir.ir.code.expr.ConstantExpr)6