Search in sources :

Example 21 with Expr

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

the class GenerationPass method can_succeed.

protected boolean can_succeed(ExpressionStack s, ExpressionStack succ) {
    // quick check stack heights
    if (s.height() != succ.height()) {
        return false;
    }
    ExpressionStack c0 = s.copy();
    ExpressionStack c1 = succ.copy();
    while (c0.height() > 0) {
        Expr e1 = c0.pop();
        Expr e2 = c1.pop();
        if (!(e1.getOpcode() == Opcode.LOCAL_LOAD) || !(e2.getOpcode() == Opcode.LOCAL_LOAD)) {
            return false;
        }
        if (((VarExpr) e1).getIndex() != ((VarExpr) e2).getIndex()) {
            return false;
        }
        if (e1.getType().getSize() != e2.getType().getSize()) {
            return false;
        }
    }
    return true;
}
Also used : InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) Expr(org.mapleir.ir.code.Expr) ExpressionStack(org.mapleir.ir.code.ExpressionStack)

Example 22 with Expr

use of org.mapleir.ir.code.Expr 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 23 with Expr

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

the class GenerationPass method save_stack.

protected void save_stack(boolean check) {
    // System.out.println("Saving " + currentBlock.getId());
    if (!currentBlock.isEmpty() && currentBlock.get(currentBlock.size() - 1).canChangeFlow()) {
        throw new IllegalStateException("Flow instruction already added to block; cannot save stack: " + currentBlock.getDisplayName());
    }
    // System.out.println("\n   Befor: " + currentStack);
    // System.out.println("     With size: " + currentStack.size());
    // System.out.println("     With height: " + currentStack.height());
    ExpressionStack copy = currentStack.copy();
    int len = currentStack.size();
    currentStack.clear();
    int height = 0;
    for (int i = len - 1; i >= 0; i--) {
        // peek(0) = top
        // peek(len-1) = btm
        int index = height;
        Expr expr = copy.peek(i);
        if (expr.getParent() != null) {
            expr = expr.copy();
        }
        // System.out.println("    Pop: " + expr + ":" + expr.getType());
        // System.out.println("    Idx: " + index);
        Type type = assign_stack(index, expr);
        Expr e = load_stack(index, type);
        // System.out.println("    Push " + e + ":" + e.getType());
        // System.out.println("    tlen: " + type.getSize());
        currentStack.push(e);
        height += type.getSize();
    }
    if (check) {
        saved = true;
    }
// System.out.println("   After: " + currentStack + "\n");
}
Also used : Type(org.objectweb.asm.Type) ComparisonType(org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType) ValueComparisonType(org.mapleir.ir.code.expr.ComparisonExpr.ValueComparisonType) ArrayType(org.mapleir.ir.TypeUtils.ArrayType) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) Expr(org.mapleir.ir.code.Expr) ExpressionStack(org.mapleir.ir.code.ExpressionStack)

Example 24 with Expr

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

the class GenerationPass method _store_field.

protected void _store_field(int opcode, String owner, String name, String desc) {
    save_stack(false);
    if (opcode == PUTFIELD) {
        Expr val = pop();
        Expr inst = pop();
        addStmt(new FieldStoreStmt(inst, val, owner, name, desc));
    } else if (opcode == PUTSTATIC) {
        Expr val = pop();
        addStmt(new FieldStoreStmt(null, val, owner, name, desc));
    } else {
        throw new UnsupportedOperationException(Printer.OPCODES[opcode] + " " + owner + "." + name + "   " + desc);
    }
}
Also used : InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) Expr(org.mapleir.ir.code.Expr)

Example 25 with Expr

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

the class GenerationPass method _jump_null.

protected void _jump_null(BasicBlock target, boolean invert) {
    save_stack(false);
    Expr left = pop();
    ConstantExpr right = new ConstantExpr(null, TypeUtils.OBJECT_TYPE);
    ComparisonType type = invert ? ComparisonType.NE : ComparisonType.EQ;
    _jump_cmp(target, type, left, right);
}
Also used : ComparisonType(org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType) ValueComparisonType(org.mapleir.ir.code.expr.ComparisonExpr.ValueComparisonType) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) Expr(org.mapleir.ir.code.Expr)

Aggregations

Expr (org.mapleir.ir.code.Expr)87 VarExpr (org.mapleir.ir.code.expr.VarExpr)46 InvocationExpr (org.mapleir.ir.code.expr.invoke.InvocationExpr)45 BasicBlock (org.mapleir.ir.cfg.BasicBlock)32 PhiExpr (org.mapleir.ir.code.expr.PhiExpr)31 Stmt (org.mapleir.ir.code.Stmt)29 ConstantExpr (org.mapleir.ir.code.expr.ConstantExpr)26 AbstractCopyStmt (org.mapleir.ir.code.stmt.copy.AbstractCopyStmt)26 Local (org.mapleir.ir.locals.Local)22 Type (org.objectweb.asm.Type)21 VersionedLocal (org.mapleir.ir.locals.impl.VersionedLocal)20 CopyPhiStmt (org.mapleir.ir.code.stmt.copy.CopyPhiStmt)19 InitialisedObjectExpr (org.mapleir.ir.code.expr.invoke.InitialisedObjectExpr)17 ComparisonType (org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType)14 CopyVarStmt (org.mapleir.ir.code.stmt.copy.CopyVarStmt)14 ValueComparisonType (org.mapleir.ir.code.expr.ComparisonExpr.ValueComparisonType)13 ArrayType (org.mapleir.ir.TypeUtils.ArrayType)12 HashSet (java.util.HashSet)11 ArithmeticExpr (org.mapleir.ir.code.expr.ArithmeticExpr)11 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)9