Search in sources :

Example 36 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project maple-ir by LLVM-but-worse.

the class ReflectiveFunctorFactory method branch.

@Override
public EvaluationFunctor<Boolean> branch(Type lt, Type rt, ConditionalJumpStmt.ComparisonType type) {
    Type opType = TypeUtils.resolveBinOpType(lt, rt);
    String name = lt.getClassName() + type.name() + rt.getClassName() + "OPTYPE" + opType.getClassName() + "RETbool";
    String desc = "(" + lt.getDescriptor() + rt.getDescriptor() + ")Z";
    if (cache.containsKey(name)) {
        return _get(name);
    }
    MethodNode m = makeBase(name, desc);
    {
        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);
        LabelNode trueSuccessor = new LabelNode();
        if (opType == Type.INT_TYPE) {
            insns.add(new JumpInsnNode(Opcodes.IF_ICMPEQ + type.ordinal(), trueSuccessor));
        } else if (opType == Type.LONG_TYPE) {
            insns.add(new InsnNode(Opcodes.LCMP));
            insns.add(new JumpInsnNode(Opcodes.IFEQ + type.ordinal(), trueSuccessor));
        } else if (opType == Type.FLOAT_TYPE) {
            insns.add(new InsnNode((type == ConditionalJumpStmt.ComparisonType.LT || type == ConditionalJumpStmt.ComparisonType.LE) ? Opcodes.FCMPL : Opcodes.FCMPG));
            insns.add(new JumpInsnNode(Opcodes.IFEQ + type.ordinal(), trueSuccessor));
        } else if (opType == Type.DOUBLE_TYPE) {
            insns.add(new InsnNode((type == ConditionalJumpStmt.ComparisonType.LT || type == ConditionalJumpStmt.ComparisonType.LE) ? Opcodes.DCMPL : Opcodes.DCMPG));
            insns.add(new JumpInsnNode(Opcodes.IFEQ + type.ordinal(), trueSuccessor));
        } else {
            throw new IllegalArgumentException(opType.toString());
        }
        branchReturn(insns, trueSuccessor);
        m.instructions = insns;
    }
    return buildBridge(m);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) MethodNode(org.objectweb.asm.tree.MethodNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 37 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project maple-ir by LLVM-but-worse.

the class LiftConstructorCallsPass method split.

private void split(ControlFlowGraph cfg, BasicBlock b, Stmt at) {
    BasicBlock newBlock = new BasicBlock(cfg, cfg.vertices().size() + 1, new LabelNode());
    cfg.addVertex(newBlock);
    System.out.println(ControlFlowGraph.printBlock(b));
    System.out.println("  to " + at);
    int index = b.indexOf(at) + 1;
    int size = b.size();
    for (int i = index; i < size; i++) {
        Stmt stmt = b.remove(index);
        stmt.setBlock(newBlock);
        newBlock.add(stmt);
    }
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) BasicBlock(org.mapleir.ir.cfg.BasicBlock) Stmt(org.mapleir.ir.code.Stmt)

Example 38 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project maple-ir by LLVM-but-worse.

the class LineNumberNodeSerializer method deserialize.

@Override
public LineNumberNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = (JsonObject) json;
    int line = jsonObject.get("line").getAsInt();
    LabelNode start = context.deserialize(jsonObject.get("start"), LabelNode.class);
    return new LineNumberNode(line, start);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) JsonObject(com.google.gson.JsonObject) LineNumberNode(org.objectweb.asm.tree.LineNumberNode)

Example 39 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project maple-ir by LLVM-but-worse.

the class TableSwitchInsnNodeSerializer method deserialize.

@Override
public TableSwitchInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = (JsonObject) json;
    int min = jsonObject.get("min").getAsInt();
    int max = jsonObject.get("max").getAsInt();
    LabelNode dflt = context.deserialize(jsonObject.get("dflt"), LabelNode.class);
    List<LabelNode> labelList = context.deserialize(jsonObject.get("labels"), List.class);
    LabelNode[] labels = new LabelNode[labelList.size()];
    for (int i = 0; i < labels.length; i++) {
        labels[i] = labelList.get(i);
    }
    return new TableSwitchInsnNode(min, max, dflt, labels);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode) JsonObject(com.google.gson.JsonObject)

Example 40 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project jacoco by jacoco.

the class SynchronizedFilterTest method ecj.

@Test
public void ecj() {
    final Label start = new Label();
    final Label end = new Label();
    final Label handler = new Label();
    final Label handlerEnd = new Label();
    m.visitTryCatchBlock(start, end, handler, null);
    m.visitTryCatchBlock(handler, handlerEnd, handler, null);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitFieldInsn(Opcodes.GETFIELD, "Target", "lock", "Ljava/lang/Object;");
    m.visitInsn(Opcodes.DUP);
    m.visitVarInsn(Opcodes.ASTORE, 1);
    m.visitInsn(Opcodes.MONITORENTER);
    m.visitLabel(start);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitInsn(Opcodes.NOP);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitInsn(Opcodes.MONITOREXIT);
    m.visitLabel(end);
    final Label exit = new Label();
    m.visitJumpInsn(Opcodes.GOTO, exit);
    m.visitLabel(handler);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitInsn(Opcodes.MONITOREXIT);
    m.visitLabel(handlerEnd);
    m.visitInsn(Opcodes.ATHROW);
    m.visitLabel(exit);
    m.visitInsn(Opcodes.RETURN);
    filter.filter(m, context, output);
    assertIgnored(new Range((LabelNode) handler.info, ((LabelNode) exit.info).getPrevious()));
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) Label(org.objectweb.asm.Label) Test(org.junit.Test)

Aggregations

LabelNode (org.objectweb.asm.tree.LabelNode)89 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)37 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)32 Label (org.objectweb.asm.Label)28 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)23 InsnList (org.objectweb.asm.tree.InsnList)22 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)21 InsnNode (org.objectweb.asm.tree.InsnNode)20 MethodNode (org.objectweb.asm.tree.MethodNode)19 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)17 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)16 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)15 ClassNode (org.objectweb.asm.tree.ClassNode)14 ClassReader (org.objectweb.asm.ClassReader)12 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)10 Type (org.objectweb.asm.Type)8 LocalVariableNode (org.objectweb.asm.tree.LocalVariableNode)8 LinkedList (java.util.LinkedList)6 ArrayList (java.util.ArrayList)5 LookupSwitchInsnNode (org.objectweb.asm.tree.LookupSwitchInsnNode)5