Example usage for org.objectweb.asm.tree InsnList insertBefore

List of usage examples for org.objectweb.asm.tree InsnList insertBefore

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList insertBefore.

Prototype

public void insertBefore(final AbstractInsnNode nextInsn, final InsnList insnList) 

Source Link

Document

Inserts the given instructions before the specified instruction.

Usage

From source file:br.usp.each.saeg.badua.core.internal.instr.LabelFrameNode.java

License:Open Source License

public static void insertBefore(final AbstractInsnNode location, final InsnList insns, final InsnList insert) {

    final LabelFrameNode lfn = create(location);
    if (lfn != null) {
        insert.add(lfn);//from w  w w . ja va 2  s  .com
    }
    insns.insertBefore(location, insert);
}

From source file:br.usp.each.saeg.badua.core.internal.instr.LabelFrameNode.java

License:Open Source License

public static void insertBefore(final AbstractInsnNode location, final InsnList insns,
        final AbstractInsnNode insert) {

    final LabelFrameNode lfn = create(location);
    insns.insertBefore(location, insert);
    if (lfn != null) {
        insns.insertBefore(location, lfn);
    }/*from   w w w . j  a v a2s . c  o  m*/
}

From source file:cl.inria.stiq.instrumenter.LocationsManager.java

License:Open Source License

/**
 * Creates a new location before the given node in the given list.
 *///from  ww  w  .j a  va2  s.  c o  m
public int createLocation(InsnList aInsns, AbstractInsnNode aNode) {
    int theId = itsStructureDatabase.addProbe(-1, -1, null, -1);
    Label theLabel = new Label();
    aInsns.insertBefore(aNode, new LabelNode(theLabel));
    itsLocations.add(new TmpLocationInfo(theId, theLabel));
    return theId;
}

From source file:com.github.fge.grappa.transform.process.GroupClassGenerator.java

License:Apache License

protected static void insertSetContextCalls(InstructionGroup group, int localVarIx) {
    InsnList instructions = group.getInstructions();
    CodeBlock block = CodeBlock.newCodeBlock();

    for (InstructionGraphNode node : group.getNodes()) {
        if (!node.isCallOnContextAware())
            continue;

        AbstractInsnNode insn = node.getInstruction();

        if (node.getPredecessors().size() > 1) {
            // store the target of the call in a new local variable
            AbstractInsnNode loadTarget = node.getPredecessors().get(0).getInstruction();

            block.clear().dup().astore(++localVarIx);
            instructions.insert(loadTarget, block.getInstructionList());

            // immediately before the call get the target from the local var
            // and set the context on it
            instructions.insertBefore(insn, new VarInsnNode(ALOAD, localVarIx));
        } else {/*from  w ww. j  a  v a2  s . c o  m*/
            // if we have only one predecessor the call does not take any
            // parameters and we can skip the storing and loading of the
            // invocation target
            instructions.insertBefore(insn, new InsnNode(DUP));
        }

        block.clear().aload(1).invokeinterface(CodegenUtils.p(ContextAware.class), "setContext",
                CodegenUtils.sig(void.class, Context.class));

        instructions.insertBefore(insn, block.getInstructionList());
    }
}

From source file:com.github.fge.grappa.transform.process.LabellingGenerator.java

License:Apache License

@Override
public void process(@Nonnull ParserClassNode classNode, @Nonnull RuleMethod method) throws Exception {
    Objects.requireNonNull(classNode, "classNode");
    Objects.requireNonNull(method, "method");
    // super methods have flag moved to the overriding method
    Preconditions.checkState(!method.isSuperMethod());

    InsnList instructions = method.instructions;

    AbstractInsnNode retInsn = instructions.getLast();
    while (retInsn.getOpcode() != ARETURN)
        retInsn = retInsn.getPrevious();

    LabelNode label = new LabelNode();
    CodeBlock block = CodeBlock.newCodeBlock().dup().ifnull(label).ldc(getLabelText(method))
            .invokeinterface(CodegenUtils.p(Rule.class), "label", CodegenUtils.sig(Rule.class, String.class))
            .label(label);//  ww w .j a  va2s .com

    instructions.insertBefore(retInsn, block.getInstructionList());
}

From source file:com.github.fge.grappa.transform.process.RuleMethodRewriter.java

License:Open Source License

private void createNewGroupClassInstance(InstructionGroup group) {
    String internalName = group.getGroupClassType().getInternalName();
    InstructionGraphNode root = group.getRoot();
    AbstractInsnNode rootInsn = root.getInstruction();
    InsnList insnList = method.instructions;
    String constant = method.name + (root.isActionRoot() ? "_Action" + ++actionNr : "_VarInit" + ++varInitNr);

    CodeBlock block = CodeBlock.newCodeBlock();

    block.newobj(internalName).dup().ldc(constant).invokespecial(internalName, "<init>",
            CodegenUtils.sig(void.class, String.class));

    if (root.isActionRoot() && method.hasSkipActionsInPredicatesAnnotation())
        block.dup().invokevirtual(internalName, "setSkipInPredicates", CodegenUtils.sig(void.class));

    insnList.insertBefore(rootInsn, block.getInstructionList());
}

From source file:com.github.fge.grappa.transform.process.RuleMethodRewriter.java

License:Open Source License

private void initializeFields(InstructionGroup group) {
    String internalName = group.getGroupClassType().getInternalName();

    InsnList insnList;
    AbstractInsnNode rootInsn;//from w  w w .j  a  v  a  2s .  com
    int opcode;
    VarInsnNode varNode;
    FieldInsnNode fieldNode;

    for (FieldNode field : group.getFields()) {
        insnList = method.instructions;
        rootInsn = group.getRoot().getInstruction();
        // TODO: replace with method in CodeBlock?
        opcode = LoadingOpcode.forType((Type) field.value);
        varNode = new VarInsnNode(opcode, field.access);
        fieldNode = new FieldInsnNode(PUTFIELD, internalName, field.name, field.desc);

        insnList.insertBefore(rootInsn, new InsnNode(DUP));
        // the FieldNodes access and value members have been reused for the
        // var index / Type respectively!
        insnList.insertBefore(rootInsn, varNode);
        insnList.insertBefore(rootInsn, fieldNode);
    }
}

From source file:com.github.fge.grappa.transform.process.VarFramingGenerator.java

License:Apache License

@Override
public void process(@Nonnull ParserClassNode classNode, @Nonnull RuleMethod method) throws Exception {
    Objects.requireNonNull(classNode, "classNode");
    Objects.requireNonNull(method, "method");
    InsnList instructions = method.instructions;

    AbstractInsnNode ret = instructions.getLast();
    while (ret.getOpcode() != ARETURN)
        ret = ret.getPrevious();/*w w  w.j  a va2  s .c om*/

    CodeBlock block = CodeBlock.newCodeBlock();

    block.newobj(CodegenUtils.p(VarFramingMatcher.class)).dup_x1().swap();

    createVarFieldArray(block, method);

    block.invokespecial(CodegenUtils.p(VarFramingMatcher.class), "<init>",
            CodegenUtils.sig(void.class, Rule.class, Var[].class));

    instructions.insertBefore(ret, block.getInstructionList());

    method.setBodyRewritten();
}

From source file:com.lodgon.parboiled.transform.FlagMarkingGenerator.java

License:Apache License

public void process(ParserClassNode classNode, RuleMethod method) throws Exception {
    checkArgNotNull(classNode, "classNode");
    checkArgNotNull(method, "method");
    checkState(!method.isSuperMethod()); // super methods have flag moved to the overriding method

    InsnList instructions = method.instructions;

    AbstractInsnNode ret = instructions.getLast();
    while (ret.getOpcode() != ARETURN) {
        ret = ret.getPrevious();//  w  w  w .  j  ava2  s .  c o m
    }

    // stack: <rule>
    instructions.insertBefore(ret, new InsnNode(DUP));
    // stack: <rule> :: <rule>
    LabelNode isNullLabel = new LabelNode();
    instructions.insertBefore(ret, new JumpInsnNode(IFNULL, isNullLabel));
    // stack: <rule>

    if (method.hasSuppressNodeAnnotation())
        generateMarkerCall(instructions, ret, "suppressNode");
    if (method.hasSuppressSubnodesAnnotation())
        generateMarkerCall(instructions, ret, "suppressSubnodes");
    if (method.hasSkipNodeAnnotation())
        generateMarkerCall(instructions, ret, "skipNode");
    if (method.hasMemoMismatchesAnnotation())
        generateMarkerCall(instructions, ret, "memoMismatches");

    // stack: <rule>
    instructions.insertBefore(ret, isNullLabel);
    // stack: <rule>
}

From source file:com.lodgon.parboiled.transform.FlagMarkingGenerator.java

License:Apache License

private void generateMarkerCall(InsnList instructions, AbstractInsnNode ret, String call) {
    instructions.insertBefore(ret, new MethodInsnNode(INVOKEINTERFACE, Types.RULE.getInternalName(), call,
            "()" + Types.RULE.getDescriptor()));
}