Skip to content

Commit

Permalink
Add utility to map variable insns to their respective accessed/writte…
Browse files Browse the repository at this point in the history
…n variable types
  • Loading branch information
Col-E committed Jan 13, 2025
1 parent 2431fc3 commit c7c6026
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.IntInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.VarInsnNode;

/**
* ASM instruction utilities.
Expand All @@ -31,6 +32,23 @@ public static AbstractInsnNode getDefaultValue(@Nonnull Type type) {
};
}

/**
* @param varInsn
* Variable instruction.
*
* @return Type that encompasses the variable being accessed/written to,
*/
@Nonnull
public static Type getTypeForVarInsn(@Nonnull VarInsnNode varInsn) {
return switch (varInsn.getOpcode()) {
case Opcodes.ISTORE, Opcodes.ILOAD -> Type.INT_TYPE;
case Opcodes.LSTORE, Opcodes.LLOAD -> Type.LONG_TYPE;
case Opcodes.FSTORE, Opcodes.FLOAD -> Type.FLOAT_TYPE;
case Opcodes.DSTORE, Opcodes.DLOAD -> Type.DOUBLE_TYPE;
default -> Types.OBJECT_TYPE;
};
}

/**
* Create an instruction to hold a given {@code int} value.
*
Expand Down

0 comments on commit c7c6026

Please sign in to comment.