Search in sources :

Example 1 with ComparisonType

use of org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType 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)

Example 2 with ComparisonType

use of org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType in project maple-ir by LLVM-but-worse.

the class ConstantExpressionReorderPass method transform.

private int transform(ControlFlowGraph ir) {
    int i = 0;
    for (BasicBlock b : ir.vertices()) {
        for (Stmt stmt : b) {
            if (stmt.getOpcode() == COND_JUMP) {
                ConditionalJumpStmt cjs = (ConditionalJumpStmt) stmt;
                Expr r = cjs.getRight();
                Expr l = cjs.getLeft();
                ComparisonType type = cjs.getComparisonType();
                if (type == ComparisonType.EQ || type == ComparisonType.NE) {
                    if (shouldReorder(r, l)) {
                        cjs.setRight(null);
                        cjs.setLeft(null);
                        cjs.setLeft(r);
                        cjs.setRight(l);
                        i++;
                    }
                }
            }
            for (Expr e : stmt.enumerateOnlyChildren()) {
                if (e.getOpcode() == ARITHMETIC) {
                    ArithmeticExpr arith = (ArithmeticExpr) e;
                    Expr r = arith.getRight();
                    Expr l = arith.getLeft();
                    Operator op = arith.getOperator();
                    if (!op.doesOrderMatter()) {
                        if (shouldReorder(r, l)) {
                            arith.setRight(null);
                            arith.setLeft(null);
                            arith.setLeft(r);
                            arith.setRight(l);
                            i++;
                        }
                    }
                }
            }
        }
    }
    return i;
}
Also used : ConditionalJumpStmt(org.mapleir.ir.code.stmt.ConditionalJumpStmt) Operator(org.mapleir.ir.code.expr.ArithmeticExpr.Operator) ComparisonType(org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType) ArithmeticExpr(org.mapleir.ir.code.expr.ArithmeticExpr) Expr(org.mapleir.ir.code.Expr) ArithmeticExpr(org.mapleir.ir.code.expr.ArithmeticExpr) BasicBlock(org.mapleir.ir.cfg.BasicBlock) Stmt(org.mapleir.ir.code.Stmt) ConditionalJumpStmt(org.mapleir.ir.code.stmt.ConditionalJumpStmt)

Aggregations

Expr (org.mapleir.ir.code.Expr)2 ComparisonType (org.mapleir.ir.code.stmt.ConditionalJumpStmt.ComparisonType)2 BasicBlock (org.mapleir.ir.cfg.BasicBlock)1 Stmt (org.mapleir.ir.code.Stmt)1 ArithmeticExpr (org.mapleir.ir.code.expr.ArithmeticExpr)1 Operator (org.mapleir.ir.code.expr.ArithmeticExpr.Operator)1 ValueComparisonType (org.mapleir.ir.code.expr.ComparisonExpr.ValueComparisonType)1 InvocationExpr (org.mapleir.ir.code.expr.invoke.InvocationExpr)1 ConditionalJumpStmt (org.mapleir.ir.code.stmt.ConditionalJumpStmt)1