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