Search in sources :

Example 51 with Stmt

use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.

the class DefUseVerifier method verify0.

public static void verify0(ControlFlowGraph cfg) {
    LocalsPool lp = cfg.getLocals();
    Map<Local, AbstractCopyStmt> defs = new HashMap<>();
    NullPermeableHashMap<VersionedLocal, Set<VarExpr>> uses = new NullPermeableHashMap<>(SetCreator.getInstance());
    for (BasicBlock b : cfg.vertices()) {
        for (Stmt stmt : b) {
            if (stmt.getOpcode() == Opcode.LOCAL_STORE || stmt.getOpcode() == Opcode.PHI_STORE) {
                AbstractCopyStmt copy = (AbstractCopyStmt) stmt;
                defs.put(copy.getVariable().getLocal(), copy);
            }
            for (Expr e : stmt.enumerateOnlyChildren()) {
                if (e.getOpcode() == Opcode.LOCAL_LOAD) {
                    VarExpr v = (VarExpr) e;
                    uses.getNonNull((VersionedLocal) v.getLocal()).add(v);
                }
            }
        }
    }
    {
        Set<Local> dlocals = new HashSet<>();
        dlocals.addAll(defs.keySet());
        dlocals.addAll(lp.defs.keySet());
        for (Local l : dlocals) {
            if (!defs.containsKey(l)) {
                throw new IllegalStateException("(other): def of " + l);
            }
            if (!lp.defs.containsKey(l)) {
                throw new IllegalStateException("(real): def of " + l);
            }
            AbstractCopyStmt copy1 = defs.get(l);
            AbstractCopyStmt copy2 = lp.defs.get(l);
            if (copy1 != copy2) {
                throw new IllegalStateException("dtest: " + copy1 + " :: " + copy2);
            }
        }
    }
    {
        Set<VersionedLocal> ulocals = new HashSet<>();
        ulocals.addAll(uses.keySet());
        ulocals.addAll(lp.uses.keySet());
        for (VersionedLocal l : ulocals) {
            /*if(!uses.containsKey(l)) {
					throw new IllegalStateException("(other): use of " + l);
				}
				
				if(!lp.uses.containsKey(l)) {
					throw new IllegalStateException("(real): use of " + l);
				}*/
            Set<VarExpr> uses1 = uses.get(l);
            Set<VarExpr> uses2 = lp.uses.get(l);
            if (uses1 == null) {
                if (uses2.size() != 0) {
                    throw new IllegalStateException(String.format("utest1: %s, u1:null :: u2:%d", l, uses2.size()));
                }
            } else if (uses2 == null) {
                if (uses1.size() == 0) {
                    throw new IllegalStateException(String.format("utest2: %s, u1:%d :: u2:null", l, uses1.size()));
                }
            } else {
                if (uses2.size() != uses1.size()) {
                    throw new IllegalStateException(String.format("utest3: %s, u1:%d :: u2:%d", l, uses1.size(), uses2.size()));
                }
            }
        }
    }
}
Also used : VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NullPermeableHashMap(org.mapleir.stdlib.collections.map.NullPermeableHashMap) BasicBlock(org.mapleir.ir.cfg.BasicBlock) Local(org.mapleir.ir.locals.Local) VersionedLocal(org.mapleir.ir.locals.impl.VersionedLocal) Stmt(org.mapleir.ir.code.Stmt) AbstractCopyStmt(org.mapleir.ir.code.stmt.copy.AbstractCopyStmt) LocalsPool(org.mapleir.ir.locals.LocalsPool) VarExpr(org.mapleir.ir.code.expr.VarExpr) Expr(org.mapleir.ir.code.Expr) NullPermeableHashMap(org.mapleir.stdlib.collections.map.NullPermeableHashMap) AbstractCopyStmt(org.mapleir.ir.code.stmt.copy.AbstractCopyStmt) VarExpr(org.mapleir.ir.code.expr.VarExpr)

Example 52 with Stmt

use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.

the class SSAGenPass method optimisePhis.

private void optimisePhis(BasicBlock b) {
    List<CopyPhiStmt> phis = new ArrayList<>();
    for (Stmt stmt : b) {
        if (stmt.getOpcode() == Opcode.PHI_STORE) {
            phis.add((CopyPhiStmt) stmt);
        } else {
            break;
        }
    }
    if (phis.size() > 1) {
        Set<Set<CopyPhiStmt>> ccs = findPhiClasses(phis);
        for (Set<CopyPhiStmt> cc : ccs) {
            CopyPhiStmt pref = chooseRealPhi(cc);
            // System.out.println("want to merge:");
            // for(CopyPhiStmt s : cc) {
            // System.out.println("  " + s);
            // }
            // System.out.println(" keeping " + pref);
            reduceClass(cc, pref);
        }
    }
}
Also used : CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt) SwitchStmt(org.mapleir.ir.code.stmt.SwitchStmt) CopyVarStmt(org.mapleir.ir.code.stmt.copy.CopyVarStmt) PopStmt(org.mapleir.ir.code.stmt.PopStmt) ThrowStmt(org.mapleir.ir.code.stmt.ThrowStmt) UnconditionalJumpStmt(org.mapleir.ir.code.stmt.UnconditionalJumpStmt) Stmt(org.mapleir.ir.code.Stmt) CopyPhiStmt(org.mapleir.ir.code.stmt.copy.CopyPhiStmt) ConditionalJumpStmt(org.mapleir.ir.code.stmt.ConditionalJumpStmt) AbstractCopyStmt(org.mapleir.ir.code.stmt.copy.AbstractCopyStmt)

Example 53 with Stmt

use of org.mapleir.ir.code.Stmt in project maple-ir by LLVM-but-worse.

the class MethodNodePrinter method emitBlock.

public void emitBlock(BasicBlock b) {
    this.sw.newline().print(b.getDisplayName()).print(": {").tab();
    for (Stmt stmt : b) {
        this.sw.newline();
        this.emitStmt(stmt);
    }
    this.sw.untab().newline().print("}");
}
Also used : SwitchStmt(org.mapleir.ir.code.stmt.SwitchStmt) FieldStoreStmt(org.mapleir.ir.code.stmt.FieldStoreStmt) MonitorStmt(org.mapleir.ir.code.stmt.MonitorStmt) PopStmt(org.mapleir.ir.code.stmt.PopStmt) ThrowStmt(org.mapleir.ir.code.stmt.ThrowStmt) UnconditionalJumpStmt(org.mapleir.ir.code.stmt.UnconditionalJumpStmt) Stmt(org.mapleir.ir.code.Stmt) ConditionalJumpStmt(org.mapleir.ir.code.stmt.ConditionalJumpStmt) AbstractCopyStmt(org.mapleir.ir.code.stmt.copy.AbstractCopyStmt) ArrayStoreStmt(org.mapleir.ir.code.stmt.ArrayStoreStmt) ReturnStmt(org.mapleir.ir.code.stmt.ReturnStmt)

Aggregations

Stmt (org.mapleir.ir.code.Stmt)53 BasicBlock (org.mapleir.ir.cfg.BasicBlock)35 Expr (org.mapleir.ir.code.Expr)29 AbstractCopyStmt (org.mapleir.ir.code.stmt.copy.AbstractCopyStmt)28 VarExpr (org.mapleir.ir.code.expr.VarExpr)26 CopyPhiStmt (org.mapleir.ir.code.stmt.copy.CopyPhiStmt)25 CopyVarStmt (org.mapleir.ir.code.stmt.copy.CopyVarStmt)24 Local (org.mapleir.ir.locals.Local)21 VersionedLocal (org.mapleir.ir.locals.impl.VersionedLocal)19 PhiExpr (org.mapleir.ir.code.expr.PhiExpr)15 ConditionalJumpStmt (org.mapleir.ir.code.stmt.ConditionalJumpStmt)13 UnconditionalJumpStmt (org.mapleir.ir.code.stmt.UnconditionalJumpStmt)13 ThrowStmt (org.mapleir.ir.code.stmt.ThrowStmt)12 PopStmt (org.mapleir.ir.code.stmt.PopStmt)11 SwitchStmt (org.mapleir.ir.code.stmt.SwitchStmt)11 HashSet (java.util.HashSet)10 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)9 ConstantExpr (org.mapleir.ir.code.expr.ConstantExpr)8 InvocationExpr (org.mapleir.ir.code.expr.invoke.InvocationExpr)8 BasicLocal (org.mapleir.ir.locals.impl.BasicLocal)7