1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y M B O L S . P R O C E S S I N G --
9 -- Copyright (C) 2003-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This is the VMS Alpha version of this package
29 package body Processing
is
31 type Number
is mod 2**16;
32 -- 16 bits unsigned number for number of characters
34 GSD
: constant Number
:= 10;
35 -- Code for the Global Symbol Definition section
37 C_SYM
: constant Number
:= 1;
38 -- Code for a Symbol subsection
40 V_DEF_Mask
: constant Number
:= 2**1;
41 V_NORM_Mask
: constant Number
:= 2**6;
45 Number_Of_Characters
: Natural := 0;
46 -- The number of characters of each section
48 -- The following variables are used by procedure Process when reading an
52 Length
: Natural := 0;
56 Nchars
: Natural := 0;
59 Symbol
: String (1 .. 255);
62 procedure Get
(N
: out Number
);
63 -- Read two bytes from the object file LSB first as unsigned 16 bit number
65 procedure Get
(N
: out Natural);
66 -- Read two bytes from the object file, LSByte first, as a Natural
72 procedure Get
(N
: out Number
) is
77 LSByte
:= Byte
'Pos (C
);
79 N
:= LSByte
+ (256 * Byte
'Pos (C
));
82 procedure Get
(N
: out Natural) is
86 N
:= Natural (Result
);
94 (Object_File
: String;
95 Success
: out Boolean)
100 -- Open the object file with Byte_IO. Return with Success = False if
104 Open
(File
, In_File
, Object_File
);
108 ("*** Unable to open object file """ & Object_File
& """");
113 -- Assume that the object file has a correct format
117 -- Get the different sections one by one from the object file
119 while not End_Of_File
(File
) loop
122 Get
(Number_Of_Characters
);
123 Number_Of_Characters
:= Number_Of_Characters
- 4;
125 -- If this is not a Global Symbol Definition section, skip to the
130 for J
in 1 .. Number_Of_Characters
loop
136 -- Skip over the next 4 bytes
140 Number_Of_Characters
:= Number_Of_Characters
- 4;
142 -- Get each subsection in turn
149 Number_Of_Characters
:= Number_Of_Characters
- 8;
150 Nchars
:= Nchars
- 8;
152 -- If this is a symbol and the V_DEF flag is set, get the
155 if Code
= C_SYM
and then ((Flags
and V_DEF_Mask
) /= 0) then
156 -- First, reach the symbol length
158 for J
in 1 .. 25 loop
160 Nchars
:= Nchars
- 1;
161 Number_Of_Characters
:= Number_Of_Characters
- 1;
164 Length
:= Byte
'Pos (B
);
167 -- Get the symbol characters
169 for J
in 1 .. Nchars
loop
171 Number_Of_Characters
:= Number_Of_Characters
- 1;
175 Length
:= Length
- 1;
179 -- Check if it is a symbol from a generic body
183 for J
in 1 .. LSymb
- 2 loop
184 if Symbol
(J
) = 'G' and then Symbol
(J
+ 1) = 'P'
185 and then Symbol
(J
+ 2) in '0' .. '9'
194 -- Create the new Symbol
197 S_Data
: Symbol_Data
;
200 S_Data
.Name
:= new String'(Symbol (1 .. LSymb));
202 -- The symbol kind (Data or Procedure) depends on the
205 if (Flags and V_NORM_Mask) = 0 then
212 -- Put the new symbol in the table
214 Symbol_Table.Append (Complete_Symbols, S_Data);
219 -- As it is not a symbol subsection, skip to the next
222 for J in 1 .. Nchars loop
224 Number_Of_Characters := Number_Of_Characters - 1;
228 -- Exit the GSD section when number of characters reaches 0
230 exit when Number_Of_Characters = 0;
235 -- The object file has been processed, close it
240 -- For any exception, output an error message, close the object file
241 -- and return with Success = False.
244 Put_Line ("unexpected exception raised while processing """
245 & Object_File & """");
246 Put_Line (Exception_Information (X));