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;
}
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));
}
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");
}
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);
}
}
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);
}
Aggregations