Search in sources :

Example 1 with ExpressionStack

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

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

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

the class GenerationPass method preprocess.

protected void preprocess(BasicBlock b) {
    ExpressionStack stack = getInputStackFor(b).copy();
    stacks.set(b.getNumericId());
    currentBlock = b;
    currentStack = stack;
    saved = false;
}
Also used : ExpressionStack(org.mapleir.ir.code.ExpressionStack)

Example 4 with ExpressionStack

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

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

the class GenerationVerifier method confirm_rules.

void confirm_rules(List<VerifierRule> rules) {
    throwNoContext();
    int opcode = currentContext.insn.opcode();
    ExpressionStack stack = currentContext.stack;
    List<VerifierRule> vr = vrules.get(opcode);
    if (vr.size() > 0) {
        for (VerifierRule r : rules) {
            if (r.match_attempt(stack, false)) {
                return;
            }
        }
        throw new VerifyException(ExceptionStage.POST, currentContext);
    }
}
Also used : ExpressionStack(org.mapleir.ir.code.ExpressionStack)

Aggregations

ExpressionStack (org.mapleir.ir.code.ExpressionStack)7 ArrayType (org.mapleir.ir.TypeUtils.ArrayType)2 BasicBlock (org.mapleir.ir.cfg.BasicBlock)2 Expr (org.mapleir.ir.code.Expr)2 ValueComparisonType (org.mapleir.ir.code.expr.ComparisonExpr.ValueComparisonType)2 InvocationExpr (org.mapleir.ir.code.expr.invoke.InvocationExpr)2 ComparisonType (org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType)2 Type (org.objectweb.asm.Type)2 ArrayList (java.util.ArrayList)1 CopyVarStmt (org.mapleir.ir.code.stmt.copy.CopyVarStmt)1