OSDN Git Service

2003-12-11 Ed Falis <falis@gnat.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / lib-writ.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             L I B . W R I T                              --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2003 Free Software Foundation, Inc.          --
10 --                                                                          --
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 2,  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 COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  This package contains the routines for writing the library information
28
29 package Lib.Writ is
30
31    -----------------------------------
32    -- Format of Library Information --
33    -----------------------------------
34
35    --  Note: the contents of the ali file are summarized in the GNAT
36    --  user's guide, so if any non-trivial changes are made to this
37    --  section, they should be reflected in the user's guide.
38
39    --  This section  describes the format of the library information that is
40    --  associated with object files. The exact method of this association is
41    --  potentially implementation dependent and is described and implemented
42    --  in package ali. From the point of view of the description here, all we
43    --  need to know is that the information is represented as a string of
44    --  characters that is somehow associated with an object file, and can be
45    --  retrieved. If no library information exists for a given object file,
46    --  then we take this as equivalent to the non-existence of the object
47    --  file, as if source file has not been previously compiled.
48
49    --  The library information is written as a series of lines of the form:
50
51    --    Key_Character parameter parameter ...
52
53    ------------------
54    -- Header Lines --
55    ------------------
56
57    --  The initial header lines in the file give information about the
58    --  compilation environment, and identify other special information
59    --  such as main program parameters.
60
61    --  ----------------
62    --  -- V  Version --
63    --  ----------------
64
65    --    V "xxxxxxxxxxxxxxxx"
66    --
67    --      This line indicates the library output version, as defined in
68    --      Gnatvsn. It ensures that separate object modules of a program are
69    --      consistent. It has to be changed if anything changes which would
70    --      affect successful binding of separately compiled modules.
71    --      Examples of such changes are modifications in the format of the
72    --      library info described in this package, or modifications to
73    --      calling sequences, or to the way that data is represented.
74
75    --  ---------------------
76    --  -- M  Main Program --
77    --  ---------------------
78
79    --    M type [priority] [T=time-slice] W=?
80
81    --      This line appears only if the main unit for this file is
82    --      suitable for use as a main program. The parameters are:
83
84    --        type
85
86    --          P for a parameterless procedure
87    --          F for a function returning a value of integral type
88    --            (used for writing a main program returning an exit status)
89
90    --        priority
91
92    --          Present only if there was a valid pragma Priority in the
93    --          corresponding unit to set the main task priority. It is
94    --          an unsigned decimal integer.
95
96    --        T=time-slice
97
98    --          Present only if there was a valid pragma Time_Slice in the
99    --          corresponding unit. It is an unsigned decimal integer in
100    --          the range 0 .. 10**9 giving the time slice value in units
101    --          of milliseconds. The actual significance of this parameter
102    --          is target dependent.
103
104    --        W=?
105
106    --          This parameter indicates the wide character encoding
107    --          method used when compiling the main program file. The ?
108    --          character is the single character used in the -gnatW?
109    --          switch. This is used to provide the default wide-character
110    --          encoding for Wide_Text_IO files.
111
112    --  -----------------
113    --  -- A  Argument --
114    --  -----------------
115
116    --    A argument
117
118    --      One of these lines appears for each of the arguments present
119    --      in the call to the gnat1 program. This can be used if it is
120    --      necessary to reconstruct this call (e.g. for fix and continue)
121
122    --  -------------------
123    --  -- P  Parameters --
124    --  -------------------
125
126    --    P <<parameters>>
127
128    --      Indicates various information that applies to the compilation
129    --      of the corresponding source unit. Parameters is a sequence of
130    --      zero or more two letter codes that indicate configuration
131    --      pragmas and other parameters that apply:
132    --
133    --      The arguments are as follows:
134    --
135    --         CE   Compilation errors. If this is present it means that the
136    --              ali file resulted from a compilation with the -gnatQ
137    --              switch set, and illegalities were detected. The ali
138    --              file contents may not be completely reliable, but the
139    --              format will be correct and complete. Note that NO is
140    --              always present if CE is present.
141    --
142    --         FD   Configuration pragmas apply to all the units in this
143    --              file specifying a possibly non-standard floating point
144    --              format (VAX float with Long_Float using D_Float)
145    --
146    --         FG   Configuration pragmas apply to all the units in this
147    --              file specifying a possibly non-standard floating point
148    --              format (VAX float with Long_Float using G_Float)
149    --
150    --         FI   Configuration pragmas apply to all the units in this
151    --              file specifying a possibly non-standard floating point
152    --              format (IEEE Float)
153    --
154    --         Lx   A valid Locking_Policy pragma applies to all the units
155    --              in this file, where x is the first character (upper case)
156    --              of the policy name (e.g. 'C' for Ceiling_Locking)
157    --
158    --         NO   No object. This flag indicates that the units in this
159    --              file were not compiled to produce an object. This can
160    --              occur as a result of the use of -gnatc, or if no object
161    --              can be produced (e.g. when a package spec is compiled
162    --              instead of the body, or a subunit on its own).
163    --
164    --         NR   No_Run_Time. Indicates that a pragma No_Run_Time applies
165    --              to all units in the file.
166    --
167    --         NS   Normalize_Scalars pragma in effect for all units in
168    --              this file
169    --
170    --         Qx   A valid Queueing_Policy pragma applies to all the units
171    --              in this file, where x is the first character (upper case)
172    --              of the policy name (e.g. 'P' for Priority_Queueing).
173    --
174    --         SL   Indicates that the unit is an Interface to a Standalone
175    --              Library. Note that this indication is never given by the
176    --              compiler, but is added by the Project Manager in gnatmake
177    --              when an Interface ALI file is copied to the library
178    --              directory.
179    --
180    --         Tx   A valid Task_Dispatching_Policy pragma applies to all
181    --              the units in this file, where x is the first character
182    --              (upper case) of the corresponding policy name (e.g. 'F'
183    --              for FIFO_Within_Priorities).
184    --
185    --         UA  Unreserve_All_Interrupts pragma was processed in one or
186    --             more units in this file
187    --
188    --         UX  Generated code contains unit exception table pointer
189    --             (i.e. it uses zero-cost exceptions, and there is at
190    --             least one subprogram present).
191    --
192    --         ZX  Units in this file use zero-cost exceptions and have
193    --             generated exception tables. If ZX is not present, the
194    --             longjmp/setjmp exception scheme is in use.
195    --
196    --      Note that language defined units never output policy (Lx,Tx,Qx)
197    --      parameters. Language defined units must correctly handle all
198    --      possible cases. These values are checked for consistency by the
199    --      binder and then copied to the generated binder output file.
200
201    --  ---------------------
202    --  -- R  Restrictions --
203    --  ---------------------
204
205    --    R <<restriction-characters>>
206
207    --      This line records information regarding restrictions. The
208    --      parameter is a string of characters, one for each entry in
209    --      Restrict.Compilation_Unit_Restrictions, in order. There are
210    --      three settings possible settings for each restriction:
211
212    --        r   Restricted. Unit was compiled under control of a pragma
213    --            Restrictions for the corresponding restriction. In
214    --            this case the unit certainly does not violate the
215    --            Restriction, since this would have been detected by
216    --            the compiler.
217
218    --        n   Not used. The unit was not compiled under control of a
219    --            pragma Restrictions for the corresponding restriction,
220    --            and does not make any use of the referenced feature.
221
222    --        v   Violated. The unit was not compiled under control of a
223    --            pragma Restrictions for the corresponding restriction,
224    --            and it does indeed use the referenced feature.
225
226    --      This information is used in the binder to check consistency,
227    --      i.e. to detect cases where one unit has "r" and another unit
228    --      has "v", which is not permitted, since these restrictions
229    --      are partition-wide.
230
231    --  ------------------------
232    --  -- I Interrupt States --
233    --  ------------------------
234
235    --    I interrupt-number interrupt-state line-number
236
237    --      This line records information from an Interrupt_State pragma.
238    --      There is one line for each separate pragma, and if no such
239    --      pragmas are used, then no I lines are present.
240
241    --      The interrupt-number is an unsigned positive integer giving
242    --      the value of the interrupt as defined in Ada.Interrupts.Names.
243
244    --      The interrupt-state is one of r/s/u for Runtime/System/User
245
246    --      The line number is an unsigned decimal integer giving the
247    --      line number of the corresponding Interrupt_State pragma.
248    --      This is used in consistency messages.
249
250    ----------------------------
251    -- Compilation Unit Lines --
252    ----------------------------
253
254    --  Following these header lines, a set of information lines appears for
255    --  each compilation unit that appears in the corresponding object file.
256    --  In particular, when a package body or subprogram body is compiled,
257    --  there will be two sets of information, one for the spec and one for
258    --  the body. with the entry for the body appearing first. This is the
259    --  only case in which a single ALI file contains more than one unit (in
260    --  particular note that subunits do *not* count as compilation units for
261    --  this purpose, and generate no library information, since they are
262    --  inlined).
263
264    --  --------------------
265    --  -- U  Unit Header --
266    --  --------------------
267
268    --  The lines for each compilation unit have the following form.
269
270    --    U unit-name source-name version <<attributes>>
271    --
272    --      This line identifies the unit to which this section of the
273    --      library information file applies. The first three parameters are
274    --      the unit name in internal format, as described in package Uname,
275    --      and the name of the source file containing the unit.
276    --
277    --      Version is the version given as eight hexadecimal characters
278    --      with upper case letters. This value is the exclusive or of the
279    --      source checksums of the unit and all its semantically dependent
280    --      units.
281    --
282    --      The <<attributes>> are a series of two letter codes indicating
283    --      information about the unit:
284    --
285    --         DE  Dynamic Elaboration. This unit was compiled with the
286    --             dynamic elaboration model, as set by either the -gnatE
287    --             switch or pragma Elaboration_Checks (Dynamic).
288    --
289    --         EB  Unit has pragma Elaborate_Body
290    --
291    --         EE  Elaboration entity is present which must be set true when
292    --             the unit is elaborated. The name of the elaboration entity
293    --             is formed from the unit name in the usual way. If EE is
294    --             present, then this boolean must be set True as part of the
295    --             elaboration processing routine generated by the binder.
296    --             Note that EE can be set even if NE is set. This happens
297    --             when the boolean is needed solely for checking for the
298    --             case of access before elaboration.
299    --
300    --         GE  Unit is a generic declaration, or corresponding body
301    --
302    --         IL  Unit source uses a style with identifiers in all lower
303    --         IU  case (IL) or all upper case (IU). If the standard mixed-
304    --             case usage is detected, or the compiler cannot determine
305    --             the style, then no I parameter will appear.
306    --
307    --         IS  Initialize_Scalars pragma applies to this unit
308    --
309    --         KM  Unit source uses a style with keywords in mixed case
310    --         KU  (KM) or all upper case (KU). If the standard lower-case
311    --             usage is detected, or the compiler cannot determine the
312    --             style, then no K parameter will appear.
313    --
314    --         NE  Unit has no elaboration routine. All subprogram bodies
315    --             and specs are in this category. Package bodies and specs
316    --             may or may not have NE set, depending on whether or not
317    --             elaboration code is required. Set if N_Compilation_Unit
318    --             node has flag Has_No_Elaboration_Code set.
319    --
320    --         PK  Unit is package, rather than a subprogram
321    --
322    --         PU  Unit has pragma Pure
323    --
324    --         PR  Unit has pragma Preelaborate
325    --
326    --         RA  Unit declares a Remote Access to Class-Wide (RACW) type
327    --
328    --         RC  Unit has pragma Remote_Call_Interface
329    --
330    --         RT  Unit has pragma Remote_Types
331    --
332    --         SP  Unit has pragma Shared_Passive.
333    --
334    --         SU  Unit is a subprogram, rather than a package
335    --
336    --      The attributes may appear in any order, separated by spaces.
337
338    --  ---------------------
339    --  -- W  Withed Units --
340    --  ---------------------
341
342    --  Following each U line, is a series of lines of the form
343
344    --    W unit-name [source-name lib-name] [E] [EA] [ED]
345    --
346    --      One of these lines is present for each unit that is mentioned in
347    --      an explicit with clause by the current unit. The first parameter
348    --      is the unit name in internal format. The second parameter is the
349    --      file name of the file that must be compiled to compile this unit
350    --      (which is usually the file for the body, except for packages
351    --      which have no body). The third parameter is the file name of the
352    --      library information file that contains the results of compiling
353    --      this unit. The optional modifiers are used as follows:
354    --
355    --        E   pragma Elaborate applies to this unit
356    --
357    --        EA  pragma Elaborate_All applies to this unit
358    --
359    --        ED  Elaborate_All_Desirable set for this unit, which means
360    --            that there is no Elaborate_All, but the analysis suggests
361    --            that Program_Error may be raised if the Elaborate_All
362    --            conditions cannot be satisfied. The binder will attempt
363    --            to treat ED as EA if it can.
364    --
365    --      The parameter source-name and lib-name are omitted for the case
366    --      of a generic unit compiled with earlier versions of GNAT which
367    --      did not generate object or ali files for generics.
368
369    --  -----------------------
370    --  -- L  Linker_Options --
371    --  -----------------------
372
373    --  Following the W lines (if any, or the U line if not), are an
374    --  optional series of lines that indicates the usage of the pragma
375    --  Linker_Options in the associated unit. For each appearence of a
376    --  pragma Linker_Options (or Link_With) in the unit, a line is
377    --  present with the form:
378
379    --    L "string"
380
381    --      where string is the string from the unit line enclosed in quotes.
382    --      Within the quotes the following can occur:
383
384    --        c    graphic characters in range 20-7E other than " or {
385    --        ""   indicating a single " character
386    --        {hh} indicating a character whose code is hex hh (0-9,A-F)
387    --        {00} [ASCII.NUL] is used as a separator character
388    --             to separate multiple arguments of a single
389    --             Linker_Options pragma.
390
391    --      For further details, see Stringt.Write_String_Table_Entry. Note
392    --      that wide characters in the form {hhhh} cannot be produced, since
393    --      pragma Linker_Option accepts only String, not Wide_String.
394
395    --      The L lines are required to appear in the same order as the
396    --      corresponding Linker_Options (or Link_With) pragmas appear in
397    --      the source file, so that this order is preserved by the binder
398    --      in constructing the set of linker arguments.
399
400    ---------------------
401    -- Reference Lines --
402    ---------------------
403
404    --  The reference lines contain information about references from
405    --  any of the units in the compilation (including, body version
406    --  and version attributes, linker options pragmas and source
407    --  dependencies.
408
409    --  ------------------------------------
410    --  -- E  External Version References --
411    --  ------------------------------------
412
413    --  One of these lines is present for each use of 'Body_Version or
414    --  'Version in any of the units of the compilation. These are used
415    --  by the linker to determine which version symbols must be output.
416    --  The format is simply:
417
418    --    E name
419
420    --  where name is the external name, i.e. the unit name with either
421    --  a S or a B for spec or body version referenced (Body_Version
422    --  always references the body, Version references the Spec, except
423    --  in the case of a reference to a subprogram with no separate spec).
424    --  Upper half and wide character codes are encoded using the same
425    --  method as in Namet (Uhh for upper half, Whhhh for wide character,
426    --  where hh are hex digits).
427
428    --  ---------------------
429    --  -- D  Dependencies --
430    --  ---------------------
431
432    --  The dependency lines indicate the source files on which the compiled
433    --  units depend. This is used by the binder for consistency checking.
434    --  These lines are also referenced by the cross-reference information.
435
436    --    D source-name time-stamp checksum [subunit-name] line:file-name
437
438    --      The time-stamp field contains the time stamp of the
439    --      corresponding source file. See types.ads for details on
440    --      time stamp representation.
441
442    --      The checksum is an 8-hex digit representation of the source
443    --      file checksum, with letters given in lower case.
444
445    --      The subunit name is present only if the dependency line is for
446    --      a subunit. It contains the fully qualified name of the subunit
447    --      in all lower case letters.
448
449    --      The line:file-name entry is present only if a Source_Reference
450    --      pragma appeared in the source file identified by source-name.
451    --      In this case, it gives the information from this pragma. Note
452    --      that this allows cross-reference information to be related back
453    --      to the original file. Note: the reason the line number comes
454    --      first is that a leading digit immediately identifies this as
455    --      a Source_Reference entry, rather than a subunit-name.
456
457    --      A line number of zero for line: in this entry indicates that
458    --      there is more than one source reference pragma. In this case,
459    --      the line numbers in the cross-reference are correct, and refer
460    --      to the original line number, but there is no information that
461    --      allows a reader of the ALI file to determine the exact mapping
462    --      of physical line numbers back to the original source.
463
464    --      Files with a zero checksum and a non-zero time stamp are in general
465    --      files on which the compilation depends but which are not Ada files
466    --      with further dependencies. This includes preprocessor data files
467    --      and preprocessor definition files.
468
469    --      Note: blank lines are ignored when the library information is
470    --      read, and separate sections of the file are separated by blank
471    --      lines to ease readability. Blanks between fields are also
472    --      ignored.
473
474    --      For entries corresponding to files that were not present (and
475    --      thus resulted in error messages), or for files that are not
476    --      part of the dependency set, both the time stamp and checksum
477    --      are set to all zero characters. These dummy entries are ignored
478    --      by the binder in dependency checking, but must be present for
479    --      proper interpretation of the cross-reference data.
480
481    --------------------------
482    -- Cross-Reference Data --
483    --------------------------
484
485    --  The cross-reference data follows the dependency lines. See
486    --  the spec of Lib.Xref for details on the format of this data.
487
488    ----------------------
489    -- Global_Variables --
490    ----------------------
491
492    --  The table structure defined here stores one entry for each
493    --  Interrupt_State pragma encountered either in the main source or
494    --  in an ancillary with'ed source. Since interrupt state values
495    --  have to be consistent across all units in a partition, we may
496    --  as well detect inconsistencies at compile time when we can.
497
498    type Interrupt_State_Entry is record
499       Interrupt_Number : Pos;
500       --  Interrupt number value
501
502       Interrupt_State : Character;
503       --  Set to r/s/u for Runtime/System/User
504
505       Pragma_Loc : Source_Ptr;
506       --  Location of pragma setting this value in place
507    end record;
508
509    package Interrupt_States is new Table.Table (
510      Table_Component_Type => Interrupt_State_Entry,
511      Table_Index_Type     => Nat,
512      Table_Low_Bound      => 1,
513      Table_Initial        => 30,
514      Table_Increment      => 200,
515      Table_Name           => "Name_Interrupt_States");
516
517    -----------------
518    -- Subprograms --
519    -----------------
520
521    procedure Ensure_System_Dependency;
522    --  This procedure ensures that a dependency is created on system.ads.
523    --  Even if there is no semantic dependency, Targparm has read the
524    --  file to acquire target parameters, so we need a source dependency.
525
526    procedure Write_ALI (Object : Boolean);
527    --  This procedure writes the library information for the current main unit
528    --  The Object parameter is true if an object file is created, and false
529    --  otherwise.
530    --
531    --  Note: in the case where we are not generating code (-gnatc mode), this
532    --  routine only writes an ALI file if it cannot find an existing up to
533    --  date ALI file. If it *can* find an existing up to date ALI file, then
534    --  it reads this file and sets the Lib.Compilation_Arguments table from
535    --  the A lines in this file.
536
537    procedure Add_Preprocessing_Dependency (S : Source_File_Index);
538    --  Indicate that there is a dependency to be added on a preprocessing
539    --  data file or on a preprocessing definition file.
540
541 end Lib.Writ;