Example usage for org.objectweb.asm.tree AbstractInsnNode getOpcode

List of usage examples for org.objectweb.asm.tree AbstractInsnNode getOpcode

Introduction

In this page you can find the example usage for org.objectweb.asm.tree AbstractInsnNode getOpcode.

Prototype

public int getOpcode() 

Source Link

Document

Returns the opcode of this instruction.

Usage

From source file:com.friz.instruction.utility.InstructionUtil.java

License:Open Source License

/**
 * Finds the previous psuedo node following the specified node.
 * //from   w w  w .j ava 2  s  .  c o m
 * @param node
 *            The node.
 * @return The previous psuedo node, or {@code null} if the start of the
 *         instruction list is reached.
 */
public static AbstractInsnNode previousPsuedoNode(AbstractInsnNode node) {
    while ((node = node.getPrevious()) != null && node.getOpcode() != -1)
        ;
    return node;
}

From source file:com.friz.instruction.utility.InstructionUtil.java

License:Open Source License

/**
 * Finds the previous psuedo node following the specified node.
 * //from  w ww  .  j av  a 2s . c o m
 * @param node
 *            The node.
 * @return The previous psuedo node, or {@code null} if the start of the
 *         instruction list is reached.
 */
public static AbstractInsnNode previousPsuedoNode(AbstractInsnNode node, int opcode) {
    while ((node = node.getPrevious()) != null && node.getOpcode() != opcode)
        ;
    return node;
}

From source file:com.github.fge.grappa.misc.AsmUtils.java

License:Open Source License

public static boolean isBooleanValueOfZ(AbstractInsnNode insn) {
    Objects.requireNonNull(insn, "insn");
    boolean r = false;
    if (insn.getOpcode() == Opcodes.INVOKESTATIC) {
        MethodInsnNode mi = (MethodInsnNode) insn;
        r = isBooleanValueOfZ(mi.owner, mi.name, mi.desc);
    }//  ww  w  .j  a v a  2s  .  com
    return r;
}

From source file:com.github.fge.grappa.misc.AsmUtils.java

License:Open Source License

public static boolean isActionRoot(AbstractInsnNode insn) {
    Objects.requireNonNull(insn, "insn");
    boolean r = false;
    if (insn.getOpcode() == Opcodes.INVOKESTATIC) {
        MethodInsnNode mi = (MethodInsnNode) insn;
        r = isActionRoot(mi.owner, mi.name);
    }/*from   w w  w  .ja  v  a2  s.c  om*/
    return r;
}

From source file:com.github.fge.grappa.misc.AsmUtils.java

License:Open Source License

public static boolean isVarRoot(AbstractInsnNode insn) {
    Objects.requireNonNull(insn, "insn");
    boolean r = false;
    if (insn.getOpcode() == Opcodes.INVOKESPECIAL) {
        MethodInsnNode mi = (MethodInsnNode) insn;
        r = isVarRoot(mi.owner, mi.name, mi.desc);
    }/* w w  w.  j a  va  2s  . com*/
    return r;
}

From source file:com.github.fge.grappa.misc.AsmUtils.java

License:Open Source License

public static boolean isCallOnContextAware(AbstractInsnNode insn) {
    Objects.requireNonNull(insn, "insn");
    return (insn.getOpcode() == Opcodes.INVOKEVIRTUAL //
            || insn.getOpcode() == Opcodes.INVOKEINTERFACE) //
            && isAssignableTo(((MethodInsnNode) insn).owner, ContextAware.class);//
}

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

License:Apache License

private boolean isStoredIntoObjectArray(InstructionGraphNode node) {
    // is the single dependent an AASTORE instruction ?
    AbstractInsnNode insn = node.getInstruction();
    if (insn.getOpcode() != AASTORE)
        return false;

    // Does this instruction store into an array of Object ?
    List<InstructionGraphNode> dependents = getDependents(node);

    // an AASTORE instruction should have exactly one dependent
    Preconditions.checkState(dependents.size() == 1);

    AbstractInsnNode newArrayInsn = dependents.get(0).getInstruction();
    // which should be a n ANEWARRAY instruction
    Preconditions.checkState(newArrayInsn.getOpcode() == ANEWARRAY);

    String desc = ((TypeInsnNode) newArrayInsn).desc;
    return CodegenUtils.p(Object.class).equals(desc);
}

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);/*from   w ww.  j av  a2 s  .c o m*/

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

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

License:Apache License

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

    AbstractInsnNode current = method.instructions.getLast();

    // find last return
    while (current.getOpcode() != ARETURN)
        current = current.getPrevious();

    LabelNode lastReturnLabel = new LabelNode();
    method.instructions.insertBefore(current, lastReturnLabel);

    // iterate backwards up to first instructions
    while ((current = current.getPrevious()) != null) {

        // replace returns with gotos
        if (current.getOpcode() != ARETURN)
            continue;

        JumpInsnNode insn = new JumpInsnNode(GOTO, lastReturnLabel);
        method.instructions.set(current, insn);
        current = insn;//from w  w  w  .  j a v a2 s .  co m
    }
}

From source file:com.github.fge.grappa.transform.process.SuperCallRewriter.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 insn = instructions.getFirst();
    while (insn.getOpcode() != ARETURN) {
        if (insn.getOpcode() == INVOKESPECIAL)
            process(classNode, method, (MethodInsnNode) insn);
        insn = insn.getNext();/*from  ww  w . java 2s.  c  o m*/
    }
}