OSDN Git Service

6aa8dcf97ef1901244668e1efee52194b9388365
[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-2004 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    --         SS   This unit references System.Secondary_Stack (that is,
181    --              the unit makes use of the secondary stack facilities).
182    --
183    --         Tx   A valid Task_Dispatching_Policy pragma applies to all
184    --              the units in this file, where x is the first character
185    --              (upper case) of the corresponding policy name (e.g. 'F'
186    --              for FIFO_Within_Priorities).
187    --
188    --         UA  Unreserve_All_Interrupts pragma was processed in one or
189    --             more units in this file
190    --
191    --         UX  Generated code contains unit exception table pointer
192    --             (i.e. it uses zero-cost exceptions, and there is at
193    --             least one subprogram present).
194    --
195    --         ZX  Units in this file use zero-cost exceptions and have
196    --             generated exception tables. If ZX is not present, the
197    --             longjmp/setjmp exception scheme is in use.
198    --
199    --      Note that language defined units never output policy (Lx,Tx,Qx)
200    --      parameters. Language defined units must correctly handle all
201    --      possible cases. These values are checked for consistency by the
202    --      binder and then copied to the generated binder output file.
203
204    --  ---------------------
205    --  -- R  Restrictions --
206    --  ---------------------
207
208    --  Two lines are generated to record the status of restrictions that can
209    --  be specified by pragma Restrictions. The first of these lines refers
210    --  to Restriction_Id values:
211
212    --    R <<restriction-characters>>
213
214    --      This line records information regarding restrictions that do
215    --      not take parameter values. Here "restriction-characters is a
216    --      string of characters, one for each value (in order) defined
217    --      in Restrict.All_Boolean_Restrictions. There are three possible
218    --      settings for each restriction:
219
220    --        r   Restricted. Unit was compiled under control of a pragma
221    --            Restrictions for the corresponding restriction. In
222    --            this case the unit certainly does not violate the
223    --            Restriction, since this would have been detected by
224    --            the compiler.
225
226    --        n   Not used. The unit was not compiled under control of a
227    --            pragma Restrictions for the corresponding restriction,
228    --            and does not make any use of the referenced feature.
229
230    --        v   Violated. The unit was not compiled under control of a
231    --            pragma Restrictions for the corresponding restriction,
232    --            and it does indeed use the referenced feature.
233
234    --      This information is used in the binder to check consistency,
235    --      i.e. to detect cases where one unit has "r" and another unit
236    --      has "v", which is not permitted, since these restrictions
237    --      are partition-wide.
238
239    --  The second R line refers to parameter restrictions:
240
241    --    R <<restriction-parameter-id-entries>>
242
243    --      The parameter is a string of entries, one for each value in
244    --      Restrict.All_Parameter_Restrictions. Each entry has two
245    --      components in sequence, the first indicating whether or not
246    --      there is a restriction, and the second indicating whether
247    --      or not the compiler detected violations. In the boolean case
248    --      it is not necessary to separate these, since if a restriction
249    --      is set, and violated, that is an error. But in the parameter
250    --      case, this is not true. For example, we can have a unit with
251    --      a pragma Restrictions (Max_Tasks => 4), where the compiler
252    --      can detect that there are exactly three tasks declared. Both
253    --      of these pieces of information must be passed to the binder.
254    --      The parameter of 4 is important in case the total number of
255    --      tasks in the partition is greater than 4. The parameter of
256    --      3 is important in case some other unit has a restrictions
257    --      pragma with Max_Tasks=>2.
258
259    --      The component for the presence of restriction has one of two
260    --      possible forms:
261
262    --         n   No pragma for this restriction is present in the
263    --             set of units for this ali file.
264
265    --         rN  At least one pragma for this restriction is present
266    --             in the set of units for this ali file. The value N
267    --             is the minimum parameter value encountered in any
268    --             such pragma. N is in the range of Integer (a value
269    --             larger than N'Last causes the pragma to be ignored).
270
271    --      The component for the violation detection has one of three
272    --      possible forms:
273
274    --         n   No violations were detected by the compiler
275
276    --         vN  A violation was detected. N is either the maximum or total
277    --             count of violations (depending on the checking type) in
278    --             all the units represented by the ali file). Note that
279    --             this setting is only allowed for restrictions that are
280    --             in Checked_[Max|Sum]_Parameter_Restrictions. The value
281    --             here is known to be exact by the compiler and is in the
282    --             range of Natural.
283
284    --         vN+ A violation was detected. The compiler cannot determine
285    --             the exact count of violations, but it is at least N.
286
287    --      There are no spaces in the line, so the entry for the example
288    --      in the header of this section for Max_Tasks would appear as
289    --      the string r4v3.
290
291    --  ------------------------
292    --  -- I Interrupt States --
293    --  ------------------------
294
295    --    I interrupt-number interrupt-state line-number
296
297    --      This line records information from an Interrupt_State pragma.
298    --      There is one line for each separate pragma, and if no such
299    --      pragmas are used, then no I lines are present.
300
301    --      The interrupt-number is an unsigned positive integer giving
302    --      the value of the interrupt as defined in Ada.Interrupts.Names.
303
304    --      The interrupt-state is one of r/s/u for Runtime/System/User
305
306    --      The line number is an unsigned decimal integer giving the
307    --      line number of the corresponding Interrupt_State pragma.
308    --      This is used in consistency messages.
309
310    ----------------------------
311    -- Compilation Unit Lines --
312    ----------------------------
313
314    --  Following these header lines, a set of information lines appears for
315    --  each compilation unit that appears in the corresponding object file.
316    --  In particular, when a package body or subprogram body is compiled,
317    --  there will be two sets of information, one for the spec and one for
318    --  the body. with the entry for the body appearing first. This is the
319    --  only case in which a single ALI file contains more than one unit (in
320    --  particular note that subunits do *not* count as compilation units for
321    --  this purpose, and generate no library information, since they are
322    --  inlined).
323
324    --  --------------------
325    --  -- U  Unit Header --
326    --  --------------------
327
328    --  The lines for each compilation unit have the following form.
329
330    --    U unit-name source-name version <<attributes>>
331    --
332    --      This line identifies the unit to which this section of the
333    --      library information file applies. The first three parameters are
334    --      the unit name in internal format, as described in package Uname,
335    --      and the name of the source file containing the unit.
336    --
337    --      Version is the version given as eight hexadecimal characters
338    --      with upper case letters. This value is the exclusive or of the
339    --      source checksums of the unit and all its semantically dependent
340    --      units.
341    --
342    --      The <<attributes>> are a series of two letter codes indicating
343    --      information about the unit:
344    --
345    --         DE  Dynamic Elaboration. This unit was compiled with the
346    --             dynamic elaboration model, as set by either the -gnatE
347    --             switch or pragma Elaboration_Checks (Dynamic).
348    --
349    --         EB  Unit has pragma Elaborate_Body
350    --
351    --         EE  Elaboration entity is present which must be set true when
352    --             the unit is elaborated. The name of the elaboration entity
353    --             is formed from the unit name in the usual way. If EE is
354    --             present, then this boolean must be set True as part of the
355    --             elaboration processing routine generated by the binder.
356    --             Note that EE can be set even if NE is set. This happens
357    --             when the boolean is needed solely for checking for the
358    --             case of access before elaboration.
359    --
360    --         GE  Unit is a generic declaration, or corresponding body
361    --
362    --         IL  Unit source uses a style with identifiers in all lower
363    --         IU  case (IL) or all upper case (IU). If the standard mixed-
364    --             case usage is detected, or the compiler cannot determine
365    --             the style, then no I parameter will appear.
366    --
367    --         IS  Initialize_Scalars pragma applies to this unit
368    --
369    --         KM  Unit source uses a style with keywords in mixed case
370    --         KU  (KM) or all upper case (KU). If the standard lower-case
371    --             usage is detected, or the compiler cannot determine the
372    --             style, then no K parameter will appear.
373    --
374    --         NE  Unit has no elaboration routine. All subprogram bodies
375    --             and specs are in this category. Package bodies and specs
376    --             may or may not have NE set, depending on whether or not
377    --             elaboration code is required. Set if N_Compilation_Unit
378    --             node has flag Has_No_Elaboration_Code set.
379    --
380    --         PK  Unit is package, rather than a subprogram
381    --
382    --         PU  Unit has pragma Pure
383    --
384    --         PR  Unit has pragma Preelaborate
385    --
386    --         RA  Unit declares a Remote Access to Class-Wide (RACW) type
387    --
388    --         RC  Unit has pragma Remote_Call_Interface
389    --
390    --         RT  Unit has pragma Remote_Types
391    --
392    --         SP  Unit has pragma Shared_Passive.
393    --
394    --         SU  Unit is a subprogram, rather than a package
395    --
396    --      The attributes may appear in any order, separated by spaces.
397
398    --  ---------------------
399    --  -- W  Withed Units --
400    --  ---------------------
401
402    --  Following each U line, is a series of lines of the form
403
404    --    W unit-name [source-name lib-name] [E] [EA] [ED]
405    --
406    --      One of these lines is present for each unit that is mentioned in
407    --      an explicit with clause by the current unit. The first parameter
408    --      is the unit name in internal format. The second parameter is the
409    --      file name of the file that must be compiled to compile this unit.
410    --      It is usually the file for the body, except for packages
411    --      which have no body; for units that need a body, if the source file
412    --      for the body cannot be found, the file name of the spec is used
413    --      instead. The third parameter is the file name of the library
414    --      information file that contains the results of compiling this unit.
415    --      The optional modifiers are used as follows:
416    --
417    --        E   pragma Elaborate applies to this unit
418    --
419    --        EA  pragma Elaborate_All applies to this unit
420    --
421    --        ED  Elaborate_All_Desirable set for this unit, which means
422    --            that there is no Elaborate_All, but the analysis suggests
423    --            that Program_Error may be raised if the Elaborate_All
424    --            conditions cannot be satisfied. The binder will attempt
425    --            to treat ED as EA if it can.
426    --
427    --      The parameter source-name and lib-name are omitted for the case
428    --      of a generic unit compiled with earlier versions of GNAT which
429    --      did not generate object or ali files for generics.
430
431    --  -----------------------
432    --  -- L  Linker_Options --
433    --  -----------------------
434
435    --  Following the W lines (if any, or the U line if not), are an
436    --  optional series of lines that indicates the usage of the pragma
437    --  Linker_Options in the associated unit. For each appearence of a
438    --  pragma Linker_Options (or Link_With) in the unit, a line is
439    --  present with the form:
440
441    --    L "string"
442
443    --      where string is the string from the unit line enclosed in quotes.
444    --      Within the quotes the following can occur:
445
446    --        c    graphic characters in range 20-7E other than " or {
447    --        ""   indicating a single " character
448    --        {hh} indicating a character whose code is hex hh (0-9,A-F)
449    --        {00} [ASCII.NUL] is used as a separator character
450    --             to separate multiple arguments of a single
451    --             Linker_Options pragma.
452
453    --      For further details, see Stringt.Write_String_Table_Entry. Note
454    --      that wide characters in the form {hhhh} cannot be produced, since
455    --      pragma Linker_Option accepts only String, not Wide_String.
456
457    --      The L lines are required to appear in the same order as the
458    --      corresponding Linker_Options (or Link_With) pragmas appear in
459    --      the source file, so that this order is preserved by the binder
460    --      in constructing the set of linker arguments.
461
462    ---------------------
463    -- Reference Lines --
464    ---------------------
465
466    --  The reference lines contain information about references from
467    --  any of the units in the compilation (including, body version
468    --  and version attributes, linker options pragmas and source
469    --  dependencies.
470
471    --  ------------------------------------
472    --  -- E  External Version References --
473    --  ------------------------------------
474
475    --  One of these lines is present for each use of 'Body_Version or
476    --  'Version in any of the units of the compilation. These are used
477    --  by the linker to determine which version symbols must be output.
478    --  The format is simply:
479
480    --    E name
481
482    --  where name is the external name, i.e. the unit name with either
483    --  a S or a B for spec or body version referenced (Body_Version
484    --  always references the body, Version references the Spec, except
485    --  in the case of a reference to a subprogram with no separate spec).
486    --  Upper half and wide character codes are encoded using the same
487    --  method as in Namet (Uhh for upper half, Whhhh for wide character,
488    --  where hh are hex digits).
489
490    --  ---------------------
491    --  -- D  Dependencies --
492    --  ---------------------
493
494    --  The dependency lines indicate the source files on which the compiled
495    --  units depend. This is used by the binder for consistency checking.
496    --  These lines are also referenced by the cross-reference information.
497
498    --    D source-name time-stamp checksum [subunit-name] line:file-name
499
500    --      The time-stamp field contains the time stamp of the
501    --      corresponding source file. See types.ads for details on
502    --      time stamp representation.
503
504    --      The checksum is an 8-hex digit representation of the source
505    --      file checksum, with letters given in lower case.
506
507    --      The subunit name is present only if the dependency line is for
508    --      a subunit. It contains the fully qualified name of the subunit
509    --      in all lower case letters.
510
511    --      The line:file-name entry is present only if a Source_Reference
512    --      pragma appeared in the source file identified by source-name.
513    --      In this case, it gives the information from this pragma. Note
514    --      that this allows cross-reference information to be related back
515    --      to the original file. Note: the reason the line number comes
516    --      first is that a leading digit immediately identifies this as
517    --      a Source_Reference entry, rather than a subunit-name.
518
519    --      A line number of zero for line: in this entry indicates that
520    --      there is more than one source reference pragma. In this case,
521    --      the line numbers in the cross-reference are correct, and refer
522    --      to the original line number, but there is no information that
523    --      allows a reader of the ALI file to determine the exact mapping
524    --      of physical line numbers back to the original source.
525
526    --      Files with a zero checksum and a non-zero time stamp are in general
527    --      files on which the compilation depends but which are not Ada files
528    --      with further dependencies. This includes preprocessor data files
529    --      and preprocessor definition files.
530
531    --      Note: blank lines are ignored when the library information is
532    --      read, and separate sections of the file are separated by blank
533    --      lines to ease readability. Blanks between fields are also
534    --      ignored.
535
536    --      For entries corresponding to files that were not present (and
537    --      thus resulted in error messages), or for files that are not
538    --      part of the dependency set, both the time stamp and checksum
539    --      are set to all zero characters. These dummy entries are ignored
540    --      by the binder in dependency checking, but must be present for
541    --      proper interpretation of the cross-reference data.
542
543    --------------------------
544    -- Cross-Reference Data --
545    --------------------------
546
547    --  The cross-reference data follows the dependency lines. See
548    --  the spec of Lib.Xref for details on the format of this data.
549
550    ----------------------
551    -- Global_Variables --
552    ----------------------
553
554    --  The table structure defined here stores one entry for each
555    --  Interrupt_State pragma encountered either in the main source or
556    --  in an ancillary with'ed source. Since interrupt state values
557    --  have to be consistent across all units in a partition, we may
558    --  as well detect inconsistencies at compile time when we can.
559
560    type Interrupt_State_Entry is record
561       Interrupt_Number : Pos;
562       --  Interrupt number value
563
564       Interrupt_State : Character;
565       --  Set to r/s/u for Runtime/System/User
566
567       Pragma_Loc : Source_Ptr;
568       --  Location of pragma setting this value in place
569    end record;
570
571    package Interrupt_States is new Table.Table (
572      Table_Component_Type => Interrupt_State_Entry,
573      Table_Index_Type     => Nat,
574      Table_Low_Bound      => 1,
575      Table_Initial        => 30,
576      Table_Increment      => 200,
577      Table_Name           => "Name_Interrupt_States");
578
579    -----------------
580    -- Subprograms --
581    -----------------
582
583    procedure Ensure_System_Dependency;
584    --  This procedure ensures that a dependency is created on system.ads.
585    --  Even if there is no semantic dependency, Targparm has read the
586    --  file to acquire target parameters, so we need a source dependency.
587
588    procedure Write_ALI (Object : Boolean);
589    --  This procedure writes the library information for the current main unit
590    --  The Object parameter is true if an object file is created, and false
591    --  otherwise.
592    --
593    --  Note: in the case where we are not generating code (-gnatc mode), this
594    --  routine only writes an ALI file if it cannot find an existing up to
595    --  date ALI file. If it *can* find an existing up to date ALI file, then
596    --  it reads this file and sets the Lib.Compilation_Arguments table from
597    --  the A lines in this file.
598
599    procedure Add_Preprocessing_Dependency (S : Source_File_Index);
600    --  Indicate that there is a dependency to be added on a preprocessing
601    --  data file or on a preprocessing definition file.
602
603 end Lib.Writ;