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.
- --
-
- with Ada.Text_Io;
- with ByteCode;
- with Unsigned_16_Io;
-
- package body Attribute.Code is
-
- use Byte_Utilities;
-
- procedure Decode (This : access Code_Attribute;
- From_File : in Byte_Utilities.File_Type;
- Context : in CP.Acc_CP_Infos) is
- begin
-
- -- reads stack size, number of local variables, code length
- Read (From_File, This.Max_Stack);
- Read (From_File, This.Max_Locals);
- Read (From_File, This.Code_Length);
-
- -- if the code length is not null then reads it
- if This.Code_Length > 0 then
-
- -- code allocation
- This.Code := new Bytes (1..This.Code_Length);
-
- -- reads the code
- for I in 1..This.Code_Length loop
- Read (From_File, This.Code (I));
- end loop;
- else
- This.Code := null;
- end if;
-
- -- reads the number of exception handlers
- Read (From_File, This.Exceptions_Count);
- if This.Exceptions_Count > 0 then
-
- -- exception handler table allocation
- This.Exception_Table := new Exception_Infos (1..This.Exceptions_Count);
-
- -- reads the exception handler table
- for I in 1..This.Exceptions_Count loop
- Read (From_File, This.Exception_Table (I).Start_Pc);
- Read (From_File, This.Exception_Table (I).End_Pc);
- Read (From_File, This.Exception_Table (I).Handler_Pc);
- Read (From_File, This.Exception_Table (I).Catch_Type);
- end loop;
- else
- This.Exception_Table := null;
- end if;
-
- -- reads the number of attributes attached to the code
- Read (From_File, This.Attributes_Count);
- if This.Attributes_Count > 0 then
-
- -- attributes array allocations
- This.Attributes := new Attributes (1 .. This.Attributes_Count);
-
- -- reads the attributes
- for J in 1 .. This.Attributes_Count loop
- This.Attributes (J) := Read_Attribute (From_File, Context);
- end loop;
- else
- This.Attributes := null;
- end if;
-
- end Decode;
-
- procedure Display (This : access Code_Attribute;
- Context : in CP.Acc_CP_Infos) is
- Index : Unsigned_32 := 1;
- begin
- -- displays stack size and local variables number
- Ada.Text_Io.Put_Line
- (" // Stack = " &
- Unsigned_16'Image (This.Max_Stack) &
- ", Locals = " &
- Unsigned_16'Image (This.Max_Locals));
-
- -- displays the method instructions
- if This.Code_Length > 0 then
- while Index <= This.Code_Length loop
- ByteCode.Display
- (Index => Index,
- Bytes => This.Code,
- Context => Context);
- end loop;
- end if;
-
- -- displays the exceptions handler table
- if This.Exceptions_Count > 0 then
- Ada.Text_Io.Put_Line
- (" Exception table:");
- Ada.Text_Io.Put_Line
- (" from to target type");
- for I in 1..This.Exceptions_Count loop
- Unsigned_16_Io.Put
- (Item => This.Exception_Table (I).Start_Pc, Width => 12);
- Unsigned_16_Io.Put
- (Item => This.Exception_Table (I).End_Pc, Width => 6);
- Unsigned_16_Io.Put
- (Item => This.Exception_Table (I).Handler_Pc, Width => 6);
- if This.Exception_Table (I).Catch_Type = 0 then
- Ada.Text_Io.Put (" any");
- else
- Ada.Text_Io.Put
- (" " &
- CP.Java_Decoded_String
- (Context (This.Exception_Table (I).Catch_Type),
- Context,
- CP.Class_Name));
- end if;
- Ada.Text_Io.New_Line;
- end loop;
- end if;
- end Display;
-
- end Attribute.Code;
-