home *** CD-ROM | disk | FTP | other *** search
/ Hacker / Hacker.iso / HACKER / DECOMP / DECAF / bytecode.ads < prev    next >
Encoding:
Text File  |  1996-09-19  |  15.1 KB  |  313 lines

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