use of org.mapleir.ir.code.Expr in project maple-ir by LLVM-but-worse.
the class SSAGenPass method processDeferredTranslations.
private int processDeferredTranslations() {
int i = 0;
Iterator<Entry<VersionedLocal, Set<VarExpr>>> it = pool.uses.entrySet().iterator();
while (it.hasNext()) {
Entry<VersionedLocal, Set<VarExpr>> e = it.next();
VersionedLocal vl = e.getKey();
if (deferred.contains(vl) || vl.isStack()) {
Set<VarExpr> useSet = e.getValue();
AbstractCopyStmt def = pool.defs.get(vl);
if (def != null && useSet.size() == 1) {
/* In this case, the only place that the value
* of this assignment will be used is at the use site.
* Since that value can not be spread until this one
* is, we can propagate it.*/
if (def.getOpcode() != Opcode.PHI_STORE) {
VarExpr use = useSet.iterator().next();
LatestValue val = latest.get(vl);
// System.out.println();
// System.out.println();
// System.out.println(def);
// System.out.println(use);
/* phi var*/
Expr rhs = def.getExpression();
if (use.getParent() != null) {
if (canTransferHandlers(def.getBlock(), use.getBlock()) && val.canPropagate(def, use.getRootParent(), use, false)) {
CodeUnit parent = use.getParent();
if (rhs.getOpcode() == Opcode.CATCH) {
// CodeUnit rp = use.getRootParent();
// System.out.println("DENIED NIGGA");
// System.out.println("replace " + vl + " with " + rhs);
// System.out.println(" in " + parent);
// System.out.println(" kill def: " + def);
// System.out.println();
deferred.remove(vl);
continue;
// check to see if we're moving it to the
// first expression in the block, if we aren't
// then deny, otherwise we can get rid of the local.
// if(rp.getBlock().indexOf(rp) != 1 || rp.enumerateExecutionOrder().indexOf(use) != 0) {
//
// }
}
rhs.unlink();
def.delete();
pool.defs.remove(vl);
useSet.clear();
parent.overwrite(rhs, parent.indexOf(use));
i++;
it.remove();
}
}
}
}
}
}
return i;
}
use of org.mapleir.ir.code.Expr in project maple-ir by LLVM-but-worse.
the class SSAGenPass method prune.
private boolean prune(AbstractCopyStmt def) {
if (def.isSynthetic()) {
return false;
}
Expr e = def.getExpression();
if (canPrune(e)) {
for (Expr s : e.enumerateWithSelf()) {
if (s.getOpcode() == Opcode.LOCAL_LOAD) {
VarExpr v = (VarExpr) s;
VersionedLocal vl = (VersionedLocal) v.getLocal();
pool.uses.get(vl).remove(v);
}
}
def.delete();
return true;
}
return false;
}
use of org.mapleir.ir.code.Expr in project maple-ir by LLVM-but-worse.
the class LatestValue method makeConstraints.
public void makeConstraints(Expr e) {
for (Expr s : e.enumerateWithSelf()) {
int op = s.getOpcode();
if (op == Opcode.FIELD_LOAD) {
FieldConstraint c = new FieldConstraint((FieldLoadExpr) s);
constraints.add(c);
} else if (ConstraintUtil.isInvoke(op)) {
constraints.add(new InvokeConstraint());
} else if (op == Opcode.ARRAY_LOAD) {
constraints.add(new ArrayConstraint());
}
}
}
use of org.mapleir.ir.code.Expr in project maple-ir by LLVM-but-worse.
the class GenerationPass method _call.
protected void _call(int op, String owner, String name, String desc) {
save_stack(false);
int argLen = Type.getArgumentTypes(desc).length + (op == INVOKESTATIC ? 0 : 1);
Expr[] args = new Expr[argLen];
for (int i = args.length - 1; i >= 0; i--) {
args[i] = pop();
}
InvocationExpr callExpr = new InvocationExpr(InvocationExpr.CallType.resolveCallType(op), args, owner, name, desc);
if (callExpr.getType() == Type.VOID_TYPE) {
addStmt(new PopStmt(callExpr));
} else {
int index = currentStack.height();
Type type = assign_stack(index, callExpr);
push(load_stack(index, type));
}
}
use of org.mapleir.ir.code.Expr in project maple-ir by LLVM-but-worse.
the class GenerationPass method _store_array.
protected void _store_array(ArrayType type) {
save_stack(false);
Expr value = pop();
Expr index = pop();
Expr array = pop();
addStmt(new ArrayStoreStmt(array, index, value, type));
}
Aggregations