devoured elysium
devoured elysium

Reputation: 105057

Utility methods in ASM bytecode library for opcode nature determination?

Are there any utils classes in ASM that allows me to infer from the opcode whether the instruction is some kind of store, load, or whatever?

For instance, and considering the following code (from ASM)

/**
 * Visits a zero operand instruction.
 *
 * @param opcode the opcode of the instruction to be visited. This opcode is
 *        either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
 *        ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0,
 *        FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD,
 *        DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE,
 *        DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP,
 *        DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD,
 *        DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV,
 *        FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL,
 *        LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR,
 *        I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B,
 *        I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
 *        FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW,
 *        MONITORENTER, or MONITOREXIT.
 */
public void visitInsn(int opcode) {
    if (mv != null) {
        mv.visitInsn(opcode);
    }
}

it would be handy to have methods such as Utils.isConst(opcode) or Utils.isLoad(opcode) or Utils.isStore(opcode).

Is there anything like it in ASM?

Upvotes: 0

Views: 264

Answers (1)

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340733

Have a look at InstructionAdapter. It translates opcodes into more coarse-grained method calls.

Upvotes: 1

Related Questions