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