Search in sources :

Example 46 with LabelNode

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

the class SynchronizedFilterTest method javac.

@Test
public void javac() {
    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, "Fun", "lock", "Ljava/lang/Object;");
    m.visitInsn(Opcodes.DUP);
    m.visitVarInsn(Opcodes.ASTORE, 1);
    m.visitInsn(Opcodes.MONITORENTER);
    m.visitLabel(start);
    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.ASTORE, 2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitInsn(Opcodes.MONITOREXIT);
    m.visitLabel(handlerEnd);
    m.visitVarInsn(Opcodes.ALOAD, 2);
    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)

Example 47 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project jphp by jphp-compiler.

the class StmtCompiler method writeLabel.

public LabelNode writeLabel(MethodNode mv, int lineNumber) {
    LabelNode node = new LabelNode(new Label());
    mv.instructions.add(node);
    if (lineNumber != -1)
        mv.instructions.add(new LineNumberNode(lineNumber, node));
    return node;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) Label(org.objectweb.asm.Label) LineNumberNode(org.objectweb.asm.tree.LineNumberNode)

Example 48 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project jphp by jphp-compiler.

the class ForCompiler method write.

@Override
public void write(ForStmtToken token) {
    expr.writeDefineVariables(token.getInitLocal());
    for (ExprStmtToken expr : token.getInitExpr()) {
        this.expr.writeExpression(expr, false, false);
    }
    expr.writeUndefineVariables(token.getInitLocal());
    expr.writeDefineVariables(token.getLocal());
    for (VariableExprToken variable : token.getIterationLocal()) {
        // TODO optimize this for Dynamic Values of variables
        LocalVariable local = method.getLocalVariable(variable.getName());
        local.setValue(null);
    }
    LabelNode start = expr.writeLabel(node, token.getMeta().getStartLine());
    LabelNode iter = new LabelNode();
    LabelNode end = new LabelNode();
    for (Iterator<ExprStmtToken> i = token.getConditionExpr().iterator(); i.hasNext(); ) {
        ExprStmtToken expr = i.next();
        if (i.hasNext()) {
            this.expr.writeExpression(expr, false, false);
        } else {
            this.expr.writeExpression(expr, true, false);
            this.expr.writePopBoolean();
            add(new JumpInsnNode(IFEQ, end));
            this.expr.stackPop();
        }
    }
    method.pushJump(end, iter);
    expr.write(BodyStmtToken.class, token.getBody());
    method.popJump();
    add(iter);
    for (ExprStmtToken expr : token.getIterationExpr()) {
        this.expr.writeExpression(expr, false, false);
    }
    add(new JumpInsnNode(GOTO, start));
    add(end);
    add(new LineNumberNode(token.getMeta().getEndLine(), end));
    expr.writeUndefineVariables(token.getLocal());
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) LocalVariable(org.develnext.jphp.core.compiler.jvm.misc.LocalVariable) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) VariableExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken) LineNumberNode(org.objectweb.asm.tree.LineNumberNode)

Example 49 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project jphp by jphp-compiler.

the class GotoCompiler method write.

@Override
public void write(GotoStmtToken token) {
    LabelNode labelNode = method.getOrCreateGotoLabel(token.getLabel().getName());
    LabelStmtToken labelStmtToken = method.statement.findLabel(token.getLabel().getName());
    if (labelStmtToken == null) {
        compiler.getEnvironment().error(token.getLabel().toTraceInfo(compiler.getContext()), "'goto' to undefined label '%s'", token.getLabel().getName());
        return;
    }
    if (labelStmtToken.getLevel() > token.getLevel()) {
        compiler.getEnvironment().error(token.toTraceInfo(compiler.getContext()), "'goto' into loop, switch or finally statement is disallowed");
    }
    add(new JumpInsnNode(GOTO, labelNode));
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LabelStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.LabelStmtToken) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode)

Example 50 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project Bookshelf by Darkhax-Minecraft.

the class InstructionComparator method getImportantList.

// TODO: Add documentation
public static InsnList getImportantList(InsnList list) {
    if (list.size() == 0) {
        return list;
    }
    final HashMap<LabelNode, LabelNode> labels = new HashMap<>();
    for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
        if (insn instanceof LabelNode) {
            labels.put((LabelNode) insn, (LabelNode) insn);
        }
    }
    final InsnList importantNodeList = new InsnList();
    for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
        if (insn instanceof LabelNode || insn instanceof LineNumberNode) {
            continue;
        }
        importantNodeList.add(insn.clone(labels));
    }
    return importantNodeList;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) HashMap(java.util.HashMap) LineNumberNode(org.objectweb.asm.tree.LineNumberNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList)

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