module ByteCode:sig
..end
Bytecode elements are low-level code elements,
high-level elements being provided by Instruction
module.
typeshort_offset =
Utils.s2
typelong_offset =
Utils.s4
type
instruction =
| |
AALOAD |
(* | load reference from array. | *) |
| |
AASTORE |
(* | store into reference array. | *) |
| |
ACONST_NULL |
(* | push null. | *) |
| |
ALOAD of |
(* | load reference from local variable. | *) |
| |
ALOAD_0 |
(* | load reference from local variable. | *) |
| |
ALOAD_1 |
(* | load reference from local variable. | *) |
| |
ALOAD_2 |
(* | load reference from local variable. | *) |
| |
ALOAD_3 |
(* | load reference from local variable. | *) |
| |
ANEWARRAY of |
(* | create new array of references. | *) |
| |
ARETURN |
(* | return reference from method. | *) |
| |
ARRAYLENGTH |
(* | get length of array. | *) |
| |
ASTORE of |
(* | store reference into local variable. | *) |
| |
ASTORE_0 |
(* | store reference into local variable. | *) |
| |
ASTORE_1 |
(* | store reference into local variable. | *) |
| |
ASTORE_2 |
(* | store reference into local variable. | *) |
| |
ASTORE_3 |
(* | store reference into local variable. | *) |
| |
ATHROW |
(* | throw exception or error. | *) |
| |
BALOAD |
(* | load byte or boolean from array. | *) |
| |
BASTORE |
(* | store into byte or boolean array. | *) |
| |
BIPUSH of |
(* | push byte. | *) |
| |
CALOAD |
(* | load char from array. | *) |
| |
CASTORE |
(* | store into char array. | *) |
| |
CHECKCAST of |
(* | check whether object is of given type. | *) |
| |
D2F |
(* | convert double to float. | *) |
| |
D2I |
(* | convert double to int. | *) |
| |
D2L |
(* | convert double to long. | *) |
| |
DADD |
(* | add double. | *) |
| |
DALOAD |
(* | load double from array. | *) |
| |
DASTORE |
(* | store into double array. | *) |
| |
DCMPG |
(* | compare double. | *) |
| |
DCMPL |
(* | compare double. | *) |
| |
DCONST_0 |
(* | push double. | *) |
| |
DCONST_1 |
(* | push double. | *) |
| |
DDIV |
(* | divide double. | *) |
| |
DLOAD of |
(* | load double from local variable. | *) |
| |
DLOAD_0 |
(* | load double from local variable. | *) |
| |
DLOAD_1 |
(* | load double from local variable. | *) |
| |
DLOAD_2 |
(* | load double from local variable. | *) |
| |
DLOAD_3 |
(* | load double from local variable. | *) |
| |
DMUL |
(* | multiply double. | *) |
| |
DNEG |
(* | negate double. | *) |
| |
DREM |
(* | remainder double. | *) |
| |
DRETURN |
(* | return double from method. | *) |
| |
DSTORE of |
(* | store double into local variable. | *) |
| |
DSTORE_0 |
(* | store double into local variable. | *) |
| |
DSTORE_1 |
(* | store double into local variable. | *) |
| |
DSTORE_2 |
(* | store double into local variable. | *) |
| |
DSTORE_3 |
(* | store double into local variable. | *) |
| |
DSUB |
(* | subtract double. | *) |
| |
DUP |
(* | duplicate the top operand stack value. | *) |
| |
DUP2 |
(* | duplicate the top one or two operand stack values. | *) |
| |
DUP2_X1 |
(* | duplicate the top one or two operand stack values and insert two or three values down. | *) |
| |
DUP2_X2 |
(* | duplicate the top one or two operand stack values and insert two, three, or four values down. | *) |
| |
DUP_X1 |
(* | duplicate the top operand stack value and insert two values down. | *) |
| |
DUP_X2 |
(* | duplicate the top operand stack value and insert two or threee values down. | *) |
| |
F2D |
(* | convert float to double. | *) |
| |
F2I |
(* | convert float to int. | *) |
| |
F2L |
(* | convert float to long. | *) |
| |
FADD |
(* | add float. | *) |
| |
FALOAD |
(* | load float from array. | *) |
| |
FASTORE |
(* | store into float array. | *) |
| |
FCMPG |
(* | compare float. | *) |
| |
FCMPL |
(* | compare float. | *) |
| |
FCONST_0 |
(* | push float. | *) |
| |
FCONST_1 |
(* | push float. | *) |
| |
FCONST_2 |
(* | push float. | *) |
| |
FDIV |
(* | divide float. | *) |
| |
FLOAD of |
(* | load float from local variable. | *) |
| |
FLOAD_0 |
(* | load float from local variable. | *) |
| |
FLOAD_1 |
(* | load float from local variable. | *) |
| |
FLOAD_2 |
(* | load float from local variable. | *) |
| |
FLOAD_3 |
(* | load float from local variable. | *) |
| |
FMUL |
(* | multiply float. | *) |
| |
FNEG |
(* | negate float. | *) |
| |
FREM |
(* | remainder float. | *) |
| |
FRETURN |
(* | return float from method. | *) |
| |
FSTORE of |
(* | store float into local variable. | *) |
| |
FSTORE_0 |
(* | store float into local variable. | *) |
| |
FSTORE_1 |
(* | store float into local variable. | *) |
| |
FSTORE_2 |
(* | store float into local variable. | *) |
| |
FSTORE_3 |
(* | store float into local variable. | *) |
| |
FSUB |
(* | subtract float. | *) |
| |
GETFIELD of |
(* | fetch field from object. | *) |
| |
GETSTATIC of |
(* | get static field from class. | *) |
| |
GOTO of |
(* | branch always. | *) |
| |
GOTO_W of |
(* | branch always. | *) |
| |
I2B |
(* | convert int to byte. | *) |
| |
I2C |
(* | convert int to char. | *) |
| |
I2D |
(* | convert int to double. | *) |
| |
I2F |
(* | convert int to float. | *) |
| |
I2L |
(* | convert int to long. | *) |
| |
I2S |
(* | convert int to short. | *) |
| |
IADD |
(* | add int. | *) |
| |
IALOAD |
(* | load int from array. | *) |
| |
IAND |
(* | boolean AND int. | *) |
| |
IASTORE |
(* | store into int array. | *) |
| |
ICONST_0 |
(* | push int constant. | *) |
| |
ICONST_1 |
(* | push int constant. | *) |
| |
ICONST_2 |
(* | push int constant. | *) |
| |
ICONST_3 |
(* | push int constant. | *) |
| |
ICONST_4 |
(* | push int constant. | *) |
| |
ICONST_5 |
(* | push int constant. | *) |
| |
ICONST_M1 |
(* | push int constant. | *) |
| |
IDIV |
(* | divide int. | *) |
| |
IF_ACMPEQ of |
(* | branch if reference comparison succeeds. | *) |
| |
IF_ACMPNE of |
(* | branch if reference comparison succeeds. | *) |
| |
IF_ICMPEQ of |
(* | branch if int comparison succeeds. | *) |
| |
IF_ICMPGE of |
(* | branch if int comparison succeeds. | *) |
| |
IF_ICMPGT of |
(* | branch if int comparison succeeds. | *) |
| |
IF_ICMPLE of |
(* | branch if int comparison succeeds. | *) |
| |
IF_ICMPLT of |
(* | branch if int comparison succeeds. | *) |
| |
IF_ICMPNE of |
(* | branch if int comparison succeeds. | *) |
| |
IFEQ of |
(* | branch if int comparison with zero succeeds. | *) |
| |
IFGE of |
(* | branch if int comparison with zero succeeds. | *) |
| |
IFGT of |
(* | branch if int comparison with zero succeeds. | *) |
| |
IFLE of |
(* | branch if int comparison with zero succeeds. | *) |
| |
IFLT of |
(* | branch if int comparison with zero succeeds. | *) |
| |
IFNE of |
(* | branch if int comparison with zero succeeds. | *) |
| |
IFNONNULL of |
(* | branch if reference not null. | *) |
| |
IFNULL of |
(* | branch if reference not null. | *) |
| |
IINC of |
(* | increment local variable by constant. | *) |
| |
ILOAD of |
(* | load int from local variable. | *) |
| |
ILOAD_0 |
(* | load int from local variable. | *) |
| |
ILOAD_1 |
(* | load int from local variable. | *) |
| |
ILOAD_2 |
(* | load int from local variable. | *) |
| |
ILOAD_3 |
(* | load int from local variable. | *) |
| |
IMUL |
(* | multiply int. | *) |
| |
INEG |
(* | negate int. | *) |
| |
INSTANCEOF of |
(* | determine if object is of given type. | *) |
| |
INVOKEDYNAMIC of |
(* | invoke instance method; resolve and dispatch based on class. | *) |
| |
INVOKEINTERFACE of |
(* | invoke interface method. | *) |
| |
INVOKESPECIAL of |
(* | invoke instance method; special handling for superclass, private, and instance initialization method invocations. | *) |
| |
INVOKESTATIC of |
(* | invoke a class (static) method. | *) |
| |
INVOKEVIRTUAL of |
(* | invoke instance method; dispatch based on class. | *) |
| |
IOR |
(* | boolean OR int. | *) |
| |
IREM |
(* | remainder int. | *) |
| |
IRETURN |
(* | return int from method. | *) |
| |
ISHL |
(* | shift left int. | *) |
| |
ISHR |
(* | arithmetic shift right int. | *) |
| |
ISTORE of |
(* | store int into local variable. | *) |
| |
ISTORE_0 |
(* | store int into local variable. | *) |
| |
ISTORE_1 |
(* | store int into local variable. | *) |
| |
ISTORE_2 |
(* | store int into local variable. | *) |
| |
ISTORE_3 |
(* | store int into local variable. | *) |
| |
ISUB |
(* | subtract int. | *) |
| |
IUSHR |
(* | logical shift right int. | *) |
| |
IXOR |
(* | boolean XOR int. | *) |
| |
JSR of |
(* | jump subroutine. | *) |
| |
JSR_W of |
(* | jump subroutine (wide index). | *) |
| |
L2D |
(* | convert long to double. | *) |
| |
L2F |
(* | convert long to float. | *) |
| |
L2I |
(* | convert long to int. | *) |
| |
LADD |
(* | add long. | *) |
| |
LALOAD |
(* | load long from array. | *) |
| |
LAND |
(* | boolean AND long. | *) |
| |
LASTORE |
(* | store into long array. | *) |
| |
LCMP |
(* | compare long. | *) |
| |
LCONST_0 |
(* | push long constant. | *) |
| |
LCONST_1 |
(* | push long constant. | *) |
| |
LDC of |
(* | push item from runtime constant pool. | *) |
| |
LDC2_W of |
(* | push long or double from runtime constant pool (wide index). | *) |
| |
LDC_W of |
(* | push item from runtime constant pool (wide index). | *) |
| |
LDIV |
(* | divide long. | *) |
| |
LLOAD of |
(* | load long from local variable. | *) |
| |
LLOAD_0 |
(* | load long from local variable. | *) |
| |
LLOAD_1 |
(* | load long from local variable. | *) |
| |
LLOAD_2 |
(* | load long from local variable. | *) |
| |
LLOAD_3 |
(* | load long from local variable. | *) |
| |
LMUL |
(* | multiply long. | *) |
| |
LNEG |
(* | negate long. | *) |
| |
LOOKUPSWITCH of |
(* | access jump table by key match and jump. | *) |
| |
LOR |
(* | boolean OR long. | *) |
| |
LREM |
(* | remainder long. | *) |
| |
LRETURN |
(* | return long from method. | *) |
| |
LSHL |
(* | shift left long. | *) |
| |
LSHR |
(* | arithmetic shift right long. | *) |
| |
LSTORE of |
(* | store long into local variable. | *) |
| |
LSTORE_0 |
(* | store long into local variable. | *) |
| |
LSTORE_1 |
(* | store long into local variable. | *) |
| |
LSTORE_2 |
(* | store long into local variable. | *) |
| |
LSTORE_3 |
(* | store long into local variable. | *) |
| |
LSUB |
(* | subtract long. | *) |
| |
LUSHR |
(* | logical shift right long. | *) |
| |
LXOR |
(* | boolean XOR long. | *) |
| |
MONITORENTER |
(* | enter monitor for object. | *) |
| |
MONITOREXIT |
(* | exit monitor for object. | *) |
| |
MULTIANEWARRAY of |
(* | create new multidimensional array. | *) |
| |
NEW of |
(* | create new object. | *) |
| |
NEWARRAY of |
(* | create new arrayhandler. | *) |
| |
NOP |
(* | do nothing. | *) |
| |
POP |
(* | pop the top operand stack value. | *) |
| |
POP2 |
(* | pop the top one or two operand stack values. | *) |
| |
PUTFIELD of |
(* | set field in object. | *) |
| |
PUTSTATIC of |
(* | set static field in class. | *) |
| |
RET of |
(* | return from subroutine. | *) |
| |
RETURN |
(* | return void from method. | *) |
| |
SALOAD |
(* | load short from array. | *) |
| |
SASTORE |
(* | store into short array. | *) |
| |
SIPUSH of |
(* | push short. | *) |
| |
SWAP |
(* | swap the top two operand stack values. | *) |
| |
TABLESWITCH of |
(* | access jump table by index and jump. | *) |
| |
WIDE_ALOAD of |
(* | load reference from local variable. | *) |
| |
WIDE_ASTORE of |
(* | store reference into local variable. | *) |
| |
WIDE_DLOAD of |
(* | load double from local variable. | *) |
| |
WIDE_DSTORE of |
(* | store double into local variable. | *) |
| |
WIDE_FLOAD of |
(* | load float from local variable. | *) |
| |
WIDE_FSTORE of |
(* | store float into local variable. | *) |
| |
WIDE_IINC of |
(* | increment local variable by constant. | *) |
| |
WIDE_ILOAD of |
(* | load int from local variable. | *) |
| |
WIDE_ISTORE of |
(* | store int into local variable. | *) |
| |
WIDE_LLOAD of |
(* | load long from local variable. | *) |
| |
WIDE_LSTORE of |
(* | store long into local variable. | *) |
| |
WIDE_RET of |
(* | return from subroutine. | *) |
type
error =
| |
Invalid_padding_byte |
| |
Unknown_opcode |
| |
Invalid_trailing_byte |
| |
Invalid_trailing_short |
| |
Internal |
| |
Invalid_switch_cases |
exception Exception of error
val string_of_error : error -> string
val read : InputStream.t -> int -> instruction list
read st ofs
reads an instruction list from st
using offset ofs
.
The offset is needed because some instructions include padding in
order to align data on given offsets.
Raises Exception
if an unknown opcode is encountered.
Raises Exception
if an invalid instruction is encountered.
Raises InputStream.Exception
if an i/o error occurs.val write : OutputStream.t -> int -> instruction list -> unit
write st ofs l
writes instruction list l
onto st
using offset
ofs
. The offset is needed because some instructions include padding
in order to align data on given offsets.
Raises OutputStream.Exception
if an i/o error occurs.