use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.
the class ReflectiveFunctorFactory method compare.
@Override
public EvaluationFunctor<Number> compare(Type lt, Type rt, ComparisonExpr.ValueComparisonType type) {
String name = lt.getClassName() + type.name() + rt.getClassName() + "RETint";
if (cache.containsKey(name)) {
return _get(name);
}
String desc = "(" + lt.getDescriptor() + rt.getDescriptor() + ")I";
MethodNode m = makeBase(name, desc);
{
Type opType = TypeUtils.resolveBinOpType(lt, rt);
InsnList insns = new InsnList();
insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(lt), 0));
cast(insns, lt, opType);
insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(rt), lt.getSize()));
cast(insns, rt, opType);
int op;
if (opType == Type.DOUBLE_TYPE) {
op = type == ComparisonExpr.ValueComparisonType.GT ? Opcodes.DCMPG : Opcodes.DCMPL;
} else if (opType == Type.FLOAT_TYPE) {
op = type == ComparisonExpr.ValueComparisonType.GT ? Opcodes.FCMPG : Opcodes.FCMPL;
} else if (opType == Type.LONG_TYPE) {
op = Opcodes.LCMP;
} else {
throw new IllegalArgumentException();
}
insns.add(new InsnNode(op));
insns.add(new InsnNode(Opcodes.IRETURN));
m.node.instructions = insns;
}
return buildBridge(m);
}
use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.
the class ConcreteStaticInvocationPass method accept.
@Override
public PassResult accept(PassContext pcxt) {
AnalysisContext cxt = pcxt.getAnalysis();
int fixed = 0;
InvocationResolver resolver = cxt.getInvocationResolver();
for (ClassNode cn : cxt.getApplication().iterate()) {
for (MethodNode mn : cn.getMethods()) {
ControlFlowGraph cfg = cxt.getIRCache().getFor(mn);
for (BasicBlock b : cfg.vertices()) {
for (Stmt stmt : b) {
for (Expr e : stmt.enumerateOnlyChildren()) {
if (e.getOpcode() == Opcode.INVOKE) {
InvocationExpr invoke = (InvocationExpr) e;
if (invoke.getCallType() == InvocationExpr.CallType.STATIC) {
MethodNode invoked = resolver.resolveStaticCall(invoke.getOwner(), invoke.getName(), invoke.getDesc());
if (invoked != null) {
if (!invoked.getOwner().equals(invoke.getOwner())) {
invoke.setOwner(invoked.getOwner());
fixed++;
}
}
}
}
}
}
}
}
}
System.out.printf(" corrected %d dodgy static calls.%n", fixed);
return PassResult.with(pcxt, this).finished().make();
}
use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.
the class DeadCodeEliminationPass method accept.
@Override
public PassResult accept(PassContext pcxt) {
AnalysisContext cxt = pcxt.getAnalysis();
deadBlocks = 0;
immediateJumps = 0;
deadLocals = 0;
for (ClassNode cn : cxt.getApplication().iterate()) {
for (MethodNode m : cn.getMethods()) {
ControlFlowGraph cfg = cxt.getIRCache().getFor(m);
/* dead blocks */
process(cfg);
}
}
System.out.printf(" removed %d dead blocks.%n", deadBlocks);
System.out.printf(" converted %d immediate jumps.%n", immediateJumps);
System.out.printf(" eliminated %d dead locals.%n", deadLocals);
return PassResult.with(pcxt, this).finished(deadBlocks + immediateJumps).make();
}
use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.
the class IRCallTracer method traceInvocation.
private void traceInvocation(MethodNode m, Invocation invoke) {
Set<MethodNode> targets;
try {
targets = invoke.resolveTargets(resolver);
} catch (Throwable e) {
LOGGER.warn(String.format("can't resolve call to %s.%s %s%s%s", invoke.getOwner(), invoke.getName(), invoke.getDesc(), invoke.isStatic() ? "(static)" : "", invoke.isDynamic() ? "(dynamic)" : ""));
LOGGER.warn(String.format(" call from %s", m));
return;
}
if (targets.size() != 0) {
for (MethodNode vtarg : targets) {
trace(vtarg);
processedInvocation(m, vtarg, invoke);
}
} else {
LOGGER.error(String.format("can't resolve call to %s.%s %s%s%s", invoke.getOwner(), invoke.getName(), invoke.getDesc(), invoke.isStatic() ? "(static)" : "", invoke.isDynamic() ? "(dynamic)" : ""));
LOGGER.error(String.format(" call from %s", m));
}
}
use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.
the class CallgraphPruningPass method accept.
@Override
public PassResult accept(PassContext cxt) {
int delta = 0;
Set<MethodNode> active = cxt.getAnalysis().getIRCache().getActiveMethods();
for (ClassNode cn : cxt.getAnalysis().getApplication().iterate()) {
ListIterator<MethodNode> lit = cn.getMethods().listIterator();
while (lit.hasNext()) {
MethodNode m = lit.next();
if (!active.contains(m)) {
lit.remove();
delta++;
}
}
}
System.out.println("Removed " + delta + " dead methods.");
return PassResult.with(cxt, this).finished().make();
}
Aggregations