home *** CD-ROM | disk | FTP | other *** search
- --
- -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
- -- Author: Gilles Demailly
- --
- --
- -- Permission to use, copy, modify, and distribute this software and its
- -- documentation for any purpose and without fee is hereby granted,
- -- provided that the above copyright and authorship notice appear in all
- -- copies and that both that copyright notice and this permission notice
- -- appear in supporting documentation.
- --
- -- The ARA makes no representations about the suitability of this software
- -- for any purpose. It is provided "as is" without express
- -- or implied warranty.
- --
-
- --
- -- Package ByteCode provides the definition of the type ByteCode
- -- used to represent all operations in a Java method.
- -- basic functions on ByteCodes are provided.
- --
- -- For more information about ByteCode and the Java Class file format check :
- -- The Java Virtual Machine Specification
- -- (Release 1.0 Beta - Draft - August 21, 1995)
- --
-
- with Basic_Definitions;
- use Basic_Definitions;
-
- with Byte_Utilities;
-
- with CP;
-
- package ByteCode is
-
- E_Unkown_ByteCode : Exception;
-
- -- All Java bytecodes
- ---------------------
- type ByteCode is
- -- Pushing constants onto the Stack
- (Nop, -- Do nothing
- Aconst_null, -- push null object reference
- Iconst_m1, -- push integer constant -1
- Iconst_0, -- push integer constant 0
- Iconst_1, -- push integer constant 1
- Iconst_2, -- push integer constant 2
- Iconst_3, -- push integer constant 3
- Iconst_4, -- push integer constant 4
- Iconst_5, -- push integer constant 5
- Lconst_0, -- push long integer constant 0
- Lconst_1, -- push long integer constant 1
- Fconst_0, -- push single float 0.0
- Fconst_1, -- push single float 1.0
- Fconst_2, -- push single float 2.0
- Dconst_0, -- push double float 0.0
- Dconst_1, -- push double float 1.0
- Bipush, -- push one-byte signed integer
- Sipush, -- push two-byte signed integer
- Ldc1, -- push item from constant pool
- Ldc2, -- push item from constant pool
- Ldc2w, -- push long or double from constant pool
- -- Loading local variables onto the Stack
- Iload, -- Load integer from local variable
- Lload, -- Load long integer from local variable
- Fload, -- Load single float from local variable
- Dload, -- Load double float from local variable
- Aload, -- Load object reference from local variable
- Iload_0, -- Load integer from local variable 0
- Iload_1, -- Load integer from local variable 1
- Iload_2, -- Load integer from local variable 2
- Iload_3, -- Load integer from local variable 3
- Lload_0, -- Load long integer from local variable 0
- Lload_1, -- Load long integer from local variable 1
- Lload_2, -- Load long integer from local variable 2
- Lload_3, -- Load long integer from local variable 3
- Fload_0, -- Load single float from local variable 0
- Fload_1, -- Load single float from local variable 1
- Fload_2, -- Load single float from local variable 2
- Fload_3, -- Load single float from local variable 3
- Dload_0, -- Load double float from local variable 0
- Dload_1, -- Load double float from local variable 1
- Dload_2, -- Load double float from local variable 2
- Dload_3, -- Load double float from local variable 3
- Aload_0, -- Load object reference from local variable 0
- Aload_1, -- Load object reference from local variable 1
- Aload_2, -- Load object reference from local variable 2
- Aload_3, -- Load object reference from local variable 3
- Iaload, -- Load integer from array
- Laload, -- Load long integer from array
- Faload, -- Load signle float from array
- Daload, -- Load double float from array
- Aaload, -- Load object reference from array
- Baload, -- Load signed byte from array
- Caload, -- Load character from array
- Saload, -- Load short from array
- -- Storing stack values into local variables
- Istore, -- Store integer into local variable
- Lstore, -- Store long integer into local variable
- Fstore, -- Store single float into local variable
- Dstore, -- Store double float into local variable
- Astore, -- Store object reference into local variable
- Istore_0, -- Store integer into local variable 0
- Istore_1, -- Store integer into local variable 1
- Istore_2, -- Store integer into local variable 2
- Istore_3, -- Store integer into local variable 3
- Lstore_0, -- Store long integer into local variable 0
- Lstore_1, -- Store long integer into local variable 1
- Lstore_2, -- Store long integer into local variable 2
- Lstore_3, -- Store long integer into local variable 3
- Fstore_0, -- Store single float into local variable 0
- Fstore_1, -- Store single float into local variable 1
- Fstore_2, -- Store single float into local variable 2
- Fstore_3, -- Store single float into local variable 3
- Dstore_0, -- Store double float into local variable 0
- Dstore_1, -- Store double float into local variable 1
- Dstore_2, -- Store double float into local variable 2
- Dstore_3, -- Store double float into local variable 3
- Astore_0, -- Store object reference into local variable 0
- Astore_1, -- Store object reference into local variable 1
- Astore_2, -- Store object reference into local variable 2
- Astore_3, -- Store object reference into local variable 3
- -- Managing arrays
- Iastore, -- Store into integer array
- Lastore, -- Store into long integer array
- Fastore, -- Store into single float array
- Dastore, -- Store into double float array
- Aastore, -- Store into object reference array
- Bastore, -- Store into signed byte array
- Castore, -- Store into character array
- Sastore, -- Store into short array
- -- Stack instructions
- Pop, -- Pop top stack word
- Pop2, -- Pop top two stack words
- Dup, -- Duplicate top stack word
- Dup_x1, -- Duplicate top stack word and put two down
- Dup_x2, -- Duplicate top stack word and put three down
- Dup2, -- Duplicate top two stack words
- Dup2_x1, -- Duplicate top two stack words and put two down
- Dup2_x2, -- Duplicate top two stack words and put three down
- Swap, -- Swap top two stack words
- -- Arithmetic instructions
- Iadd, -- Integer add
- Ladd, -- Long integer add
- Fadd, -- Single floats add
- Dadd, -- Double floats add
- Isub, -- Integer substract
- Lsub, -- Long integer substract
- Fsub, -- Single float substract
- Dsub, -- Double float substract
- Imul, -- Integer multiply
- Lmul, -- Long integer multiply
- Fmul, -- Single float multiply
- Dmul, -- Double float multiply
- Idiv, -- Integer divide
- Ldiv, -- Long integer divide
- Fdiv, -- Single float divide
- Ddiv, -- Double float divide
- Irem, -- Integer remainder
- Lrem, -- Long integer remainder
- Frem, -- Single float remainder
- Drem, -- Double float remainder
- Ineg, -- Integer negate
- Lneg, -- Long integer negate
- Fneg, -- Single float negate
- Dneg, -- Double float negate
- -- Logical instructions
- Ishl, -- Integer shift left
- Lshl, -- Long integer shift left
- Ishr, -- Integer shift right
- Lshr, -- Long integer shift right
- Iushr, -- Integer logical shift right
- Lushr, -- Long integer logical shift right
- Iand, -- Integer boolean AND
- Land, -- Long integer boolean AND
- Ior, -- Integer boolean OR
- Lor, -- Long Integer boolean OR
- Ixor, -- Integer boolean XOR
- Lxor, -- Long integer boolean XOR
- Iinc, -- Increment local variable by constant
- -- Conversion operations
- I2l, -- Integer to long integer conversion
- I2f, -- Integer to single float
- I2d, -- Integer to double float
- L2i, -- Long integer to integer
- L2f, -- Long integer to float
- L2d, -- Long integer to double
- F2i, -- Single float to integer
- F2l, -- Single float to long integer
- F2d, -- Single float to double float
- D2i, -- Double float to integer
- D2l, -- Double float to long integer
- D2f, -- Double float to single float
- Int2byte, -- Integer to signed byte
- Int2char, -- Integer to char
- Int2short, -- Integer to short
- Lcmp, -- Long integer compare
- Fcmpl, -- Simple float compare (-1 on NaN)
- Fcmpg, -- Single float compare (1 on NaN)
- Dcmpl, -- Double float compare (-1 on NaN)
- Dcmpg, -- Double float compare (1 on NaN)
- -- Control transfert instructions
- Ifeq, -- Branch if equal to 0
- Ifne, -- Branch if not equal to 0
- Iflt, -- Branch if less than 0
- Ifge, -- Branch if greater than or equal to 0
- Ifgt, -- Branch if greater than 0
- Ifle, -- Branch if less than or equal to 0
- If_icmpeq, -- Branch if integers equal
- If_icmpne, -- Branch if integers not equal
- If_icmplt, -- Branch if integer less than
- If_icmpge, -- Branch if integer greater or equal to
- If_icmpgt, -- Branch if integer greater than
- If_icmple, -- Branch if integer less than or equal to
- If_acmpeq, -- Branch if object references are equal
- If_acmpne, -- Branch if object references not equal
- Gotoo, -- Branch always
- Jsr, -- Jump subroutine
- Ret, -- Return from subroutine
- -- Table jumping
- Tableswitch, -- Access jump table by index and jump
- Lookupswitch, -- Access jump table by key and jump
- -- Function return
- Ireturn, -- Return integer from function
- Lreturn, -- Return long Integer from function
- Freturn, -- Return single float from function
- Dreturn, -- Return double float from function
- Areturn, -- Return object reference from function
- Returnvoid, -- Return (void) from procedure
- -- Manipulating object fields
- Getstatic, -- Get static field from class
- Putstatic, -- Set static field in class
- Getfield, -- Fetch field from object
- Putfield, -- Set field in object
- -- Method invocation
- Invokevirtual, -- Invoke instance method, dispatch based on run-time type
- Invokenonvirtual, -- Invoke instance method, dispatching based on compile-time type
- Invokestatic, -- Invoke a class (static) method
- Invokeinterface, -- Invoke interface method
- New_object, -- Create new object
- Newarray, -- Allocate new array
- Anewarray, -- Allocate new array of references to objects
- Arraylength, -- Get length of array
- -- Exception handling
- Athrow, -- Throw exception or error
- -- Miscellaneous object operations
- Checkcast, -- Make sure object is of given type
- Instanceof, -- Determine if an object is of given type
- -- Monitors
- Monitorenter, -- Enter monitored region of code
- Monitorexit, -- Exit monitored region of code
- -- Wider index for loading, storing and incrementing
- Wide,
- Multianewarray, -- Allocate new multi-dimensional array
- Ifnull, -- Branch if null
- Ifnonnull, -- Branch if not null
- Goto_w, -- Branch always (wide index)
- Jsr_w, -- Jump subroutine (wide index)
- Breakpoint, -- Stop and pass control to breakpoint handler
- Ret_w); -- Return from subroutine (wide index)
-
-
- -- values used in Java Class files for bytecodes
- ------------------------------------------------
- for ByteCode use
- (0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
- 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- 20, 21, 22, 23, 24 ,25, 26, 27, 28, 29,
- 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
- 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
- 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
- 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
- 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
- 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
- 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
- 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
- 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
- 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
- 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
- 180, 181, 182, 183, 184, 185, 187, 188, 189,
- 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
- 200, 201, 202, 209);
-
- for Bytecode'Size use 8;
-
-
- -- returns a ByteCode from a Byte
- ---------------------------------
- function To_Bytecode
- (From : Byte_Utilities.Byte)
- return ByteCode;
-
- -- returns the operands number of a bytecode operation
- ------------------------------------------------------
- function Operands_Number
- (Code : ByteCode)
- return Unsigned_32;
-
- pragma Inline (Operands_Number);
-
-
- -- display an array of bytes as a bytecode array
- ------------------------------------------------
- procedure Display (Index : in out Unsigned_32;
- Bytes : in Byte_Utilities.Acc_Bytes;
- Context : in CP.Acc_CP_Infos);
-
- end ByteCode;
-