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-2013, 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 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.          --
20--                                                                          --
21-- GNAT was originally developed  by the GNAT team at  New York University. --
22-- Extensive contributions were provided by Ada Core Technologies Inc.      --
23--                                                                          --
24------------------------------------------------------------------------------
25
26--  This package contains the routines for writing the library information
27
28package Lib.Writ is
29
30   -----------------------------------
31   -- Format of Library Information --
32   -----------------------------------
33
34   --  This section describes the format of the library information that is
35   --  associated with object files. The exact method of this association is
36   --  potentially implementation dependent and is described and implemented in
37   --  package ali. From the point of view of the description here, all we need
38   --  to know is that the information is represented as a string of characters
39   --  that is somehow associated with an object file, and can be retrieved. If
40   --  no library information exists for a given object file, then we take this
41   --  as equivalent to the non-existence of the object file, as if source file
42   --  has not been previously compiled.
43
44   --  The library information is written as a series of lines of the form:
45
46   --    Key_Character parameter parameter ...
47
48   --  The following sections describe the format of these lines in detail
49
50   --------------------------------------
51   -- Making Changes to the ALI Format --
52   --------------------------------------
53
54   --  A number of tools use ali.adb to parse ali files. This means that
55   --  changes to this format can cause old versions of these tools to be
56   --  incompatible with new versions of the compiler. Any changes to ali file
57   --  formats must be carefully evaluated to understand any such possible
58   --  conflicts, and in particular, it is very undesirable to create conflicts
59   --  between older versions of GPS and newer versions of the compiler.
60
61   --  If the following guidelines are respected, downward compatibility
62   --  problems (old tools reading new ali files) should be minimized:
63
64   --    The basic key character format must be kept
65
66   --    The V line must be the first line, this is checked by ali.adb even in
67   --    Ignore_Errors mode, and is used to verify that the file at hand is
68   --    indeed likely intended to be an ali file.
69
70   --    The P line must be present, though may be modified in contents
71   --    according to remaining guidelines. Again, ali.adb assumes the P
72   --    line is present even in Ignore_Errors mode.
73
74   --    New modifiers can generally be added (in particular adding new two
75   --    letter modifiers to the P or U lines is always safe)
76
77   --    Adding entirely new lines (with a new key letter) to the ali file is
78   --    always safe, at any point (other than before the V line), since such
79   --    lines will be ignored.
80
81   --  Following the guidelines in this section should ensure that this problem
82   --  is minimized and that old tools will be able to deal successfully with
83   --  new ali formats. Note that this does not apply to the compiler itself,
84   --  which always requires consistency between the ali files and the binder.
85   --  That is because one of the main functions of the binder is to ensure
86   --  consistency of the partition, and this can be compromised if the ali
87   --  files are inconsistent.
88
89   ------------------
90   -- Header Lines --
91   ------------------
92
93   --  The initial header lines in the file give information about the
94   --  compilation environment, and identify other special information such as
95   --  main program parameters.
96
97   --  ----------------
98   --  -- V  Version --
99   --  ----------------
100
101   --    V "xxxxxxxxxxxxxxxx"
102   --
103   --      This line indicates the library output version, as defined in
104   --      Gnatvsn. It ensures that separate object modules of a program are
105   --      consistent. It has to be changed if anything changes which would
106   --      affect successful binding of separately compiled modules. Examples
107   --      of such changes are modifications in the format of the library info
108   --      described in this package, or modifications to calling sequences, or
109   --      to the way that data is represented.
110
111   --    Note: the V line absolutely must be the first line, and no change
112   --    to the ALI format should change this, since even in Ignore_Errors
113   --    mode, Scan_ALI insists on finding a V line.
114
115   --  ---------------------
116   --  -- M  Main Program --
117   --  ---------------------
118
119   --    M type [priority] [T=time-slice] [AB] [C=cpu] W=?
120
121   --      This line appears only if the main unit for this file is suitable
122   --      for use as a main program. The parameters are:
123
124   --        type
125
126   --          P for a parameterless procedure
127   --          F for a function returning a value of integral type
128   --            (used for writing a main program returning an exit status)
129
130   --        priority
131
132   --          Present only if there was a valid pragma Priority in the
133   --          corresponding unit to set the main task priority. It is an
134   --          unsigned decimal integer.
135
136   --        T=time-slice
137
138   --          Present only if there was a valid pragma Time_Slice in the
139   --          corresponding unit. It is an unsigned decimal integer in the
140   --          range 0 .. 10**9 giving the time slice value in units of
141   --          milliseconds. The actual significance of this parameter is
142   --          target dependent.
143
144   --        AB
145
146   --          Present if there is an allocator in the body of the procedure
147   --          after the BEGIN. This will be a violation of the restriction
148   --          No_Allocators_After_Elaboration if it is present, and this
149   --          unit is used as a main program (only the binder can find the
150   --          violation, since only the binder knows the main program).
151
152   --        C=cpu
153
154   --          Present only if there was a valid pragma CPU in the
155   --          corresponding unit to set the main task affinity. It is an
156   --          unsigned decimal integer.
157
158   --        W=?
159
160   --          This parameter indicates the wide character encoding method used
161   --          when compiling the main program file. The ? character is the
162   --          single character used in the -gnatW? switch. This is used to
163   --          provide the default wide-character encoding for Wide_Text_IO
164   --          files.
165
166   --  -----------------
167   --  -- A  Argument --
168   --  -----------------
169
170   --    A argument
171
172   --      One of these lines appears for each of the arguments present in the
173   --      call to the gnat1 program. This can be used if it is necessary to
174   --      reconstruct this call (e.g. for fix and continue).
175
176   --  -------------------
177   --  -- P  Parameters --
178   --  -------------------
179
180   --    P <<parameters>>
181
182   --      Indicates various information that applies to the compilation of the
183   --      corresponding source file. Parameters is a sequence of zero or more
184   --      two letter codes that indicate configuration pragmas and other
185   --      parameters that apply:
186
187   --      The arguments are as follows:
188
189   --         CE   Compilation errors. If this is present it means that the ali
190   --              file resulted from a compilation with the -gnatQ switch set,
191   --              and illegalities were detected. The ali file contents may
192   --              not be completely reliable, but the format will be correct
193   --              and complete. Note that NO is always present if CE is
194   --              present.
195
196   --         DB   Detect_Blocking pragma is in effect for all units in this
197   --              file.
198
199   --         Ex   A valid Partition_Elaboration_Policy pragma applies to all
200   --              the units in this file, where x is the first character
201   --              (upper case) of the policy name (e.g. 'C' for Concurrent).
202
203   --         FD   Configuration pragmas apply to all the units in this file
204   --              specifying a possibly non-standard floating point format
205   --              (VAX float with Long_Float using D_Float).
206
207   --         FG   Configuration pragmas apply to all the units in this file
208   --              specifying a possibly non-standard floating point format
209   --              (VAX float with Long_Float using G_Float).
210
211   --         FI   Configuration pragmas apply to all the units in this file
212   --              specifying a possibly non-standard floating point format
213   --              (IEEE Float).
214
215   --         Lx   A valid Locking_Policy pragma applies to all the units in
216   --              this file, where x is the first character (upper case) of
217   --              the policy name (e.g. 'C' for Ceiling_Locking).
218
219   --         NO   No object. This flag indicates that the units in this file
220   --              were not compiled to produce an object. This can occur as a
221   --              result of the use of -gnatc, or if no object can be produced
222   --              (e.g. when a package spec is compiled instead of the body,
223   --              or a subunit on its own).
224
225   --         NR   No_Run_Time. Indicates that a pragma No_Run_Time applies
226   --              to all units in the file.
227
228   --         NS   Normalize_Scalars pragma in effect for all units in
229   --              this file.
230
231   --         Qx   A valid Queueing_Policy pragma applies to all the units
232   --              in this file, where x is the first character (upper case)
233   --              of the policy name (e.g. 'P' for Priority_Queueing).
234
235   --         SL   Indicates that the unit is an Interface to a Standalone
236   --              Library. Note that this indication is never given by the
237   --              compiler, but is added by the Project Manager in gnatmake
238   --              when an Interface ALI file is copied to the library
239   --              directory.
240
241   --         SS   This unit references System.Secondary_Stack (that is,
242   --              the unit makes use of the secondary stack facilities).
243
244   --         Tx   A valid Task_Dispatching_Policy pragma applies to all
245   --              the units in this file, where x is the first character
246   --              (upper case) of the corresponding policy name (e.g. 'F'
247   --              for FIFO_Within_Priorities).
248
249   --         UA  Unreserve_All_Interrupts pragma was processed in one or
250   --             more units in this file
251
252   --         ZX  Units in this file use zero-cost exceptions and have
253   --             generated exception tables. If ZX is not present, the
254   --             longjmp/setjmp exception scheme is in use.
255
256   --      Note that language defined units never output policy (Lx, Tx, Qx)
257   --      parameters. Language defined units must correctly handle all
258   --      possible cases. These values are checked for consistency by the
259   --      binder and then copied to the generated binder output file.
260
261   --    Note: The P line must be present. Even in Ignore_Errors mode, Scan_ALI
262   --    insists on finding a P line. So if changes are made to the ALI format,
263   --    they should not include removing the P line.
264
265   --  ---------------------
266   --  -- R  Restrictions --
267   --  ---------------------
268
269   --  There are two forms for R lines, positional and named. The positional
270   --  notation is now considered obsolescent, it is not generated by the most
271   --  recent versions of the compiler except under control of the debug switch
272   --  -gnatdR, but is still recognized by the binder.
273
274   --  The recognition by the binder is to ease the transition, and better deal
275   --  with some cases of inconsistent builds using incompatible versions of
276   --  the compiler and binder. The named notation is the current preferred
277   --  approach.
278
279   --  Note that R lines are generated using the information in unit Rident,
280   --  and intepreted by the binder using the information in System.Rident.
281   --  Normally these two units should be effectively identical. However in
282   --  some cases of inconsistent builds, they may be different. This may lead
283   --  to binder diagnostics, which can be suppressed using the -C switch for
284   --  the binder, which results in ignoring unrecognized restrictions in the
285   --  ali files.
286
287   --  ---------------------------------------
288   --  -- R  Restrictions (Positional Form) --
289   --  ---------------------------------------
290
291   --  The first R line records the status of restrictions generated by pragma
292   --  Restrictions encountered, as well as information on what the compiler
293   --  has been able to determine with respect to restrictions violations.
294   --  The format is:
295
296   --    R <<restriction-characters>> <<restriction-param-id-entries>>
297
298   --      The first parameter is a string of characters that records
299   --      information regarding restrictions that do not take parameter not
300   --      take parameter values. It is a string of characters, one character
301   --      for each value (in order) in All_Boolean_Restrictions. There are
302   --      three possible settings for each restriction:
303
304   --        r   Restricted. Unit was compiled under control of a pragma
305   --            Restrictions for the corresponding restriction. In this case
306   --            the unit certainly does not violate the Restriction, since
307   --            this would have been detected by the compiler.
308
309   --        n   Not used. The unit was not compiled under control of a pragma
310   --            Restrictions for the corresponding restriction, and does not
311   --            make any use of the referenced feature.
312
313   --        v   Violated. The unit was not compiled under control of a pragma
314   --            Restrictions for the corresponding restriction, and it does
315   --            indeed use the referenced feature.
316
317   --      This information is used in the binder to check consistency, i.e. to
318   --      detect cases where one unit has "r" and another unit has "v", which
319   --      is not permitted, since these restrictions are partition-wide.
320
321   --  The second parameter, which immediately follows the first (with no
322   --  separating space) gives restriction information for identifiers for
323   --  which a parameter is given.
324
325   --      The parameter is a string of entries, one for each value in
326   --      Restrict.All_Parameter_Restrictions. Each entry has two components
327   --      in sequence, the first indicating whether or not there is a
328   --      restriction, and the second indicating whether or not the compiler
329   --      detected violations. In the boolean case it is not necessary to
330   --      separate these, since if a restriction is set, and violated, that is
331   --      an error. But in the parameter case, this is not true. For example,
332   --      we can have a unit with a pragma Restrictions (Max_Tasks => 4),
333   --      where the compiler can detect that there are exactly three tasks
334   --      declared. Both of these pieces of information must be passed to the
335   --      binder. The parameter of 4 is important in case the total number of
336   --      tasks in the partition is greater than 4. The parameter of 3 is
337   --      important in case some other unit has a restrictions pragma with
338   --      Max_Tasks=>2.
339
340   --      The component for the presence of restriction has one of two
341   --      possible forms:
342
343   --         n   No pragma for this restriction is present in the set of units
344   --             for this ali file.
345
346   --         rN  At least one pragma for this restriction is present in the
347   --             set of units for this ali file. The value N is the minimum
348   --             parameter value encountered in any such pragma. N is in the
349   --             range of Integer (a value larger than N'Last causes the
350   --             pragma to be ignored).
351
352   --      The component for the violation detection has one of three
353   --      possible forms:
354
355   --         n   No violations were detected by the compiler
356
357   --         vN  A violation was detected. N is either the maximum or total
358   --             count of violations (depending on the checking type) in all
359   --             the units represented by the ali file). Note that this
360   --             setting is only allowed for restrictions that are in
361   --             Checked_[Max|Sum]_Parameter_Restrictions. The value here is
362   --             known to be exact by the compiler and is in the range of
363   --             Natural.
364
365   --         vN+ A violation was detected. The compiler cannot determine
366   --             the exact count of violations, but it is at least N.
367
368   --      There are no spaces within the parameter string, so the entry
369   --      described above in the header of this section for Max_Tasks would
370   --      appear as the string r4v3.
371
372   --      Note: The restrictions line is required to be present. Even in
373   --      Ignore_Errors mode, Scan_ALI expects to find an R line and will
374   --      signal a fatal error if it is missing. This means that future
375   --      changes to the ALI file format must retain the R line.
376
377   --  ----------------------------------
378   --  -- R  Restrictions (Named Form) --
379   --  ----------------------------------
380
381   --  The first R line for named form announces that named notation will be
382   --  used, and also assures that there is at least one R line present, which
383   --  makes parsing of ali files simpler. A blank line preceds the RN line.
384
385   --  RN
386
387   --  In named notation, the restrictions are given as a series of lines, one
388   --  per retrictions that is specified or violated (no information is present
389   --  for restrictions that are not specified or violated). In the following
390   --  name is the name of the restriction in all upper case.
391
392   --  For boolean restrictions, we have only two possibilities. A restrictions
393   --  pragma is present, or a violation is detected:
394
395   --  RR name
396
397   --    A restriction pragma is present for the named boolean restriction.
398   --    No violations were detected by the compiler (or the unit in question
399   --    would have been found to be illegal).
400
401   --  RV name
402
403   --    No restriction pragma is present for the named boolean restriction.
404   --    However, the compiler did detect one or more violations of this
405   --    restriction, which may require a binder consistency check. Note that
406   --    one case of a violation is the use of a Restriction_Set attribute for
407   --    the restriction that yielded False.
408
409   --  For the case of restrictions that take a parameter, we need both the
410   --  information from pragma if present, and the actual information about
411   --  what possible violations occur. For example, we can have a unit with
412   --  a pragma Restrictions (Max_Tasks => 4), where the compiler can detect
413   --  that there are exactly three tasks declared. Both of these pieces
414   --  of information must be passed to the binder. The parameter of 4 is
415   --  important in case the total number of tasks in the partition is greater
416   --  than 4. The parameter of 3 is important in case some other unit has a
417   --  restrictions pragma with Max_Tasks=>2.
418
419   --  RR name=N
420
421   --    A restriction pragma is present for the named restriction which is
422   --    one of the restrictions taking a parameter. The value N (a decimal
423   --    integer) is the value given in the restriction pragma.
424
425   --  RV name=N
426
427   --    A restriction pragma may or may not be present for the restriction
428   --    given by name (one of the restrictions taking a parameter). But in
429   --    either case, the compiler detected possible violations. N (a decimal
430   --    integer) is the maximum or total count of violations (depending
431   --    on the checking type) in all the units represented by the ali file).
432   --    The value here is known to be exact by the compiler and is in the
433   --    range of Natural. Note that if an RR line is present for the same
434   --    restriction, then the value in the RV line cannot exceed the value
435   --    in the RR line (since otherwise the compiler would have detected a
436   --    violation of the restriction).
437
438   --  RV name=N+
439
440   --    Similar to the above, but the compiler cannot determine the exact
441   --    count of violations, but it is at least N.
442
443   --  -------------------------------------------------
444   --  -- R  Restrictions (No_Dependence Information) --
445   --  -------------------------------------------------
446
447   --  Subsequent R lines are present only if pragma Restriction No_Dependence
448   --  is used. There is one such line for each such pragma appearing in the
449   --  extended main unit. The format is:
450
451   --    R unit_name
452
453   --      Here the unit name is in all lower case. The components of the unit
454   --      name are separated by periods. The names themselves are in encoded
455   --      form, as documented in Namet.
456
457   --  -------------------------
458   --  -- I  Interrupt States --
459   --  -------------------------
460
461   --    I interrupt-number interrupt-state line-number
462
463   --      This line records information from an Interrupt_State pragma. There
464   --      is one line for each separate pragma, and if no such pragmas are
465   --      used, then no I lines are present.
466
467   --      The interrupt-number is an unsigned positive integer giving the
468   --      value of the interrupt as defined in Ada.Interrupts.Names.
469
470   --      The interrupt-state is one of r/s/u for Runtime/System/User
471
472   --      The line number is an unsigned decimal integer giving the line
473   --      number of the corresponding Interrupt_State pragma. This is used
474   --      in consistency messages.
475
476   --  --------------------------------------
477   --  -- S  Priority Specific Dispatching --
478   --  --------------------------------------
479
480   --    S policy_identifier first_priority last_priority line-number
481
482   --      This line records information from a Priority_Specific_Dispatching
483   --      pragma. There is one line for each separate pragma, and if no such
484   --      pragmas are used, then no S lines are present.
485
486   --      The policy_identifier is the first character (upper case) of the
487   --      corresponding policy name (e.g. 'F' for FIFO_Within_Priorities).
488
489   --      The first_priority and last_priority fields define the range of
490   --      priorities to which the specified dispatching policy apply.
491
492   --      The line number is an unsigned decimal integer giving the line
493   --      number of the corresponding Priority_Specific_Dispatching pragma.
494   --      This is used in consistency messages.
495
496   ----------------------------
497   -- Compilation Unit Lines --
498   ----------------------------
499
500   --  Following these header lines, a set of information lines appears for
501   --  each compilation unit that appears in the corresponding object file. In
502   --  particular, when a package body or subprogram body is compiled, there
503   --  will be two sets of information, one for the spec and one for the body,
504   --  with the entry for the body appearing first. This is the only case in
505   --  which a single ALI file contains more than one unit (in particular note
506   --  that subunits do *not* count as compilation units for this purpose, and
507   --  generate no library information, since they are inlined).
508
509   --  --------------------
510   --  -- U  Unit Header --
511   --  --------------------
512
513   --  The lines for each compilation unit have the following form
514
515   --    U unit-name source-name version <<attributes>>
516
517   --      This line identifies the unit to which this section of the library
518   --      information file applies. The first three parameters are the unit
519   --      name in internal format, as described in package Uname, and the name
520   --      of the source file containing the unit.
521
522   --      Version is the version given as eight hexadecimal characters with
523   --      upper case letters. This value is the exclusive or of the source
524   --      checksums of the unit and all its semantically dependent units.
525
526   --      The <<attributes>> are a series of two letter codes indicating
527   --      information about the unit:
528
529   --         BD  Unit does not have pragma Elaborate_Body, but the elaboration
530   --             circuit has determined that it would be a good idea if this
531   --             pragma were present, since the body of the package contains
532   --             elaboration code that modifies one or more variables in the
533   --             visible part of the package. The binder will try, but does
534   --             not promise, to keep the elaboration of the body close to
535   --             the elaboration of the spec.
536
537   --         DE  Dynamic Elaboration. This unit was compiled with the dynamic
538   --             elaboration model, as set by either the -gnatE switch or
539   --             pragma Elaboration_Checks (Dynamic).
540   --
541   --         EB  Unit has pragma Elaborate_Body, or is a generic instance that
542   --             has a body. Set for instances because RM 12.3(20) requires
543   --             that the body be immediately elaborated after the spec (we
544   --             would normally do that anyway, because elaborate spec and
545   --             body together whenever possible, and for an instance it is
546   --             always possible; however setting EB ensures that this is done
547   --             even when using the -p gnatbind switch).
548
549   --         EE  Elaboration entity is present which must be set true when
550   --             the unit is elaborated. The name of the elaboration entity is
551   --             formed from the unit name in the usual way. If EE is present,
552   --             then this boolean must be set True as part of the elaboration
553   --             processing routine generated by the binder. Note that EE can
554   --             be set even if NE is set. This happens when the boolean is
555   --             needed solely for checking for the case of access before
556   --             elaboration.
557
558   --         GE  Unit is a generic declaration, or corresponding body
559   --
560   --         IL  Unit source uses a style with identifiers in all lower-case
561   --         IU  (IL) or all upper case (IU). If the standard mixed-case usage
562   --             is detected, or the compiler cannot determine the style, then
563   --             no I parameter will appear.
564
565   --         IS  Initialize_Scalars pragma applies to this unit, or else there
566   --             is at least one use of the Invalid_Value attribute.
567
568   --         KM  Unit source uses a style with keywords in mixed case (KM)
569   --         KU  or all upper case (KU). If the standard lower-case usage is
570   --             is detected, or the compiler cannot determine the style, then
571   --             no K parameter will appear.
572
573   --         NE  Unit has no elaboration routine. All subprogram bodies and
574   --             specs are in this category. Package bodies and specs may or
575   --             may not have NE set, depending on whether or not elaboration
576   --             code is required. Set if N_Compilation_Unit node has flag
577   --             Has_No_Elaboration_Code set.
578
579   --         OL   The units in this file are compiled with a local pragma
580   --              Optimize_Alignment, so no consistency requirement applies
581   --              to these units. All internal units have this status since
582   --              they have an automatic default of Optimize_Alignment (Off).
583   --
584   --         OO   Optimize_Alignment (Off) is the default setting for all
585   --              units in this file. All files in the partition that specify
586   --              a default must specify the same default.
587
588   --         OS   Optimize_Alignment (Space) is the default setting for all
589   --              units in this file. All files in the partition that specify
590   --              a default must specify the same default.
591
592   --         OT   Optimize_Alignment (Time) is the default setting for all
593   --              units in this file. All files in the partition that specify
594   --              a default must specify the same default.
595
596   --         PF  The unit has a library-level (package) finalizer
597
598   --         PK  Unit is package, rather than a subprogram
599
600   --         PU  Unit has pragma Pure
601
602   --         PR  Unit has pragma Preelaborate
603
604   --         RA  Unit declares a Remote Access to Class-Wide (RACW) type
605
606   --         RC  Unit has pragma Remote_Call_Interface
607
608   --         RT  Unit has pragma Remote_Types
609
610   --         SP  Unit has pragma Shared_Passive.
611
612   --         SU  Unit is a subprogram, rather than a package
613
614   --      The attributes may appear in any order, separated by spaces.
615
616   --  -----------------------------
617   --  -- W, Y and Z Withed Units --
618   --  -----------------------------
619
620   --  Following each U line, is a series of lines of the form
621
622   --    W unit-name [source-name lib-name] [E] [EA] [ED] [AD]
623   --      or
624   --    Y unit-name [source-name lib-name] [E] [EA] [ED] [AD]
625   --      or
626   --    Z unit-name [source-name lib-name] [E] [EA] [ED] [AD]
627
628   --      One W line is present for each unit that is mentioned in an explicit
629   --      non-limited with clause by the current unit. One Y line is present
630   --      for each unit that is mentioned in an explicit limited with clause
631   --      by the current unit. One Z line is present for each unit that is
632   --      only implicitly withed by the current unit. The first parameter is
633   --      the unit name in internal format. The second parameter is the file
634   --      name of the file that must be compiled to compile this unit. It is
635   --      usually the file for the body, except for packages which have no
636   --      body. For units that need a body, if the source file for the body
637   --      cannot be found, the file name of the spec is used instead. The
638   --      third parameter is the file name of the library information file
639   --      that contains the results of compiling this unit. The optional
640   --      modifiers are used as follows:
641
642   --        E   pragma Elaborate applies to this unit
643
644   --        EA  pragma Elaborate_All applies to this unit
645
646   --        ED  Elaborate_Desirable set for this unit, which means that there
647   --            is no Elaborate, but the analysis suggests that Program_Error
648   --            may be raised if the Elaborate conditions cannot be satisfied.
649   --            The binder will attempt to treat ED as E if it can.
650
651   --        AD  Elaborate_All_Desirable set for this unit, which means that
652   --            there is no Elaborate_All, but the analysis suggests that
653   --            Program_Error may be raised if the Elaborate_All conditions
654   --            cannot be satisfied. The binder will attempt to treat AD as
655   --            EA if it can.
656
657   --      The parameter source-name and lib-name are omitted for the case of a
658   --      generic unit compiled with earlier versions of GNAT which did not
659   --      generate object or ali files for generics. For compatibility in the
660   --      bootstrap path we continue to omit these entries for predefined
661   --      generic units, even though we do now generate object and ali files.
662
663   --      However, in SPARK mode, we always generate source-name and lib-name
664   --      parameters. Bootstrap issues do not apply there, and we need this
665   --      information to properly compute frame conditions of subprograms.
666
667   --      The parameter source-name and lib-name are also omitted for the W
668   --      lines that result from use of a Restriction_Set attribute which gets
669   --      a result of False from a No_Dependence check, in the case where the
670   --      unit is not in the semantic closure. In such a case, the bare W
671   --      line is generated, but no D (dependency) line. This will make the
672   --      binder do the consistency check, but not include the unit in the
673   --      partition closure (unless it is properly With'ed somewhere).
674
675   --  -----------------------
676   --  -- L  Linker_Options --
677   --  -----------------------
678
679   --  Following the W lines (if any, or the U line if not), are an optional
680   --  series of lines that indicates the usage of the pragma Linker_Options in
681   --  the associated unit. For each appearance of a pragma Linker_Options (or
682   --  Link_With) in the unit, a line is present with the form:
683
684   --    L "string"
685
686   --      where string is the string from the unit line enclosed in quotes.
687   --      Within the quotes the following can occur:
688
689   --        c    graphic characters in range 20-7E other than " or {
690   --        ""   indicating a single " character
691   --        {hh} indicating a character whose code is hex hh (0-9,A-F)
692   --        {00} [ASCII.NUL] is used as a separator character
693   --             to separate multiple arguments of a single
694   --             Linker_Options pragma.
695
696   --      For further details, see Stringt.Write_String_Table_Entry. Note that
697   --      wide characters in the form {hhhh} cannot be produced, since pragma
698   --      Linker_Option accepts only String, not Wide_String.
699
700   --      The L lines are required to appear in the same order as the
701   --      corresponding Linker_Options (or Link_With) pragmas appear in the
702   --      source file, so that this order is preserved by the binder in
703   --      constructing the set of linker arguments.
704
705   --  Note: Linker_Options lines never appear in the ALI file generated for
706   --  a predefined generic unit, and there is cicuitry in Sem_Prag to enforce
707   --  this restriction, which is needed because of not generating source name
708   --  and lib name parameters on the with lines for such files, as explained
709   --  above in the section on with lines.
710
711   --  --------------
712   --  -- N  Notes --
713   --  --------------
714
715   --  The final section of unit-specific lines contains notes which record
716   --  annotations inserted in source code for processing by external tools
717   --  using pragmas. For each occurrence of any of these pragmas, a line is
718   --  generated with the following syntax:
719
720   --    N x<sloc> [<arg_id>:]<arg> ...
721
722   --      x is one of:
723   --        A  pragma Annotate
724   --        C  pragma Comment
725   --        I  pragma Ident
726   --        T  pragma Title
727   --        S  pragma Subtitle
728
729   --      <sloc> is the source location of the pragma in line:col format
730
731   --      Successive entries record the pragma_argument_associations.
732
733   --        If a pragma argument identifier is present, the entry is prefixed
734   --        with the pragma argument identifier <arg_id> followed by a colon.
735
736   --        <arg> represents the pragma argument, and has the following
737   --        conventions:
738
739   --          - identifiers are output verbatim
740   --          - static string expressions are output as literals encoded as
741   --            for L lines
742   --          - static integer expressions are output as decimal literals
743   --          - any other expression is replaced by the placeholder "<expr>"
744
745   ---------------------
746   -- Reference Lines --
747   ---------------------
748
749   --  The reference lines contain information about references from any of the
750   --  units in the compilation (including body version and version attributes,
751   --  linker options pragmas and source dependencies).
752
753   --  ------------------------------------
754   --  -- E  External Version References --
755   --  ------------------------------------
756
757   --  One of these lines is present for each use of 'Body_Version or 'Version
758   --  in any of the units of the compilation. These are used by the linker to
759   --  determine which version symbols must be output. The format is simply:
760
761   --    E name
762
763   --  where name is the external name, i.e. the unit name with either a S or a
764   --  B for spec or body version referenced (Body_Version always references
765   --  the body, Version references the Spec, except in the case of a reference
766   --  to a subprogram with no separate spec). Upper half and wide character
767   --  codes are encoded using the same method as in Namet (Uhh for upper half,
768   --  Whhhh for wide character, where hh are hex digits).
769
770   --  ---------------------
771   --  -- D  Dependencies --
772   --  ---------------------
773
774   --  The dependency lines indicate the source files on which the compiled
775   --  units depend. This is used by the binder for consistency checking.
776   --  These lines are also referenced by the cross-reference information.
777
778   --    D source-name time-stamp checksum [subunit-name] line:file-name
779
780   --      source-name also includes preprocessing data file and preprocessing
781   --      definition file. These preprocessing files may be given as full
782   --      path names instead of simple file names. If a full path name
783   --      includes a directory with spaces, the path name is quoted (quote
784   --      characters (") added at start and end, and any internal quotes are
785   --      doubled).
786
787   --      The time-stamp field contains the time stamp of the corresponding
788   --      source file. See types.ads for details on time stamp representation.
789
790   --      The checksum is an 8-hex digit representation of the source file
791   --      checksum, with letters given in lower case.
792
793   --      The subunit name is present only if the dependency line is for a
794   --      subunit. It contains the fully qualified name of the subunit in all
795   --      lower case letters.
796
797   --      The line:file-name entry is present only if a Source_Reference
798   --      pragma appeared in the source file identified by source-name. In
799   --      this case, it gives the information from this pragma. Note that this
800   --      allows cross-reference information to be related back to the
801   --      original file. Note: the reason the line number comes first is that
802   --      a leading digit immediately identifies this as a Source_Reference
803   --      entry, rather than a subunit-name.
804
805   --      A line number of zero for line: in this entry indicates that there
806   --      is more than one source reference pragma. In this case, the line
807   --      numbers in the cross-reference are correct, and refer to the
808   --      original line number, but there is no information that allows a
809   --      reader of the ALI file to determine the exact mapping of physical
810   --      line numbers back to the original source.
811
812   --      Files with a zero checksum and a non-zero time stamp are in general
813   --      files on which the compilation depends but which are not Ada files
814   --      with further dependencies. This includes preprocessor data files
815   --      and preprocessor definition files.
816
817   --      Note: blank lines are ignored when the library information is read,
818   --      and separate sections of the file are separated by blank lines to
819   --      ease readability. Blanks between fields are also ignored.
820
821   --      For entries corresponding to files that were not present (and thus
822   --      resulted in error messages), or for files that are not part of the
823   --      dependency set, both the time stamp and checksum are set to all zero
824   --      characters. These dummy entries are ignored by the binder in
825   --      dependency checking, but must be present for proper interpretation
826   --      of the cross-reference data.
827
828   --------------------------
829   -- Cross-Reference Data --
830   --------------------------
831
832   --  The cross-reference data follows the dependency lines. See the spec of
833   --  Lib.Xref in file lib-xref.ads for details on the format of this data.
834
835   ---------------------------------
836   -- Source Coverage Obligations --
837   ---------------------------------
838
839   --  The Source Coverage Obligation (SCO) information follows the cross-
840   --  reference data. See the spec of Par_SCO in file par_sco.ads for full
841   --  details of the format.
842
843   ---------------------------------------
844   -- SPARK Cross-Reference Information --
845   ---------------------------------------
846
847   --  The SPARK cross-reference information follows the SCO information. See
848   --  the spec of SPARK_Xrefs in file spark_xrefs.ads for full details of the
849   --  format.
850
851   -------------------------------
852   -- ALI File Generation for C --
853   -------------------------------
854
855   --  The C compiler can also generate ALI files for use by the IDE's in
856   --  providing navigation services in C. These ALI files are a subset of
857   --  the specification above, lacking all Ada-specific output. Primarily
858   --  the IDE uses the cross-reference sections of such files.
859
860   ----------------------
861   -- Global Variables --
862   ----------------------
863
864   --  The table defined here stores one entry for each Interrupt_State pragma
865   --  encountered either in the main source or in an ancillary with'ed source.
866   --  Since interrupt state values have to be consistent across all units in a
867   --  partition, we detect inconsistencies at compile time when we can.
868
869   type Interrupt_State_Entry is record
870      Interrupt_Number : Pos;
871      --  Interrupt number value
872
873      Interrupt_State : Character;
874      --  Set to r/s/u for Runtime/System/User
875
876      Pragma_Loc : Source_Ptr;
877      --  Location of pragma setting this value in place
878   end record;
879
880   package Interrupt_States is new Table.Table (
881     Table_Component_Type => Interrupt_State_Entry,
882     Table_Index_Type     => Nat,
883     Table_Low_Bound      => 1,
884     Table_Initial        => 30,
885     Table_Increment      => 200,
886     Table_Name           => "Name_Interrupt_States");
887
888   --  The table structure defined here stores one entry for each
889   --  Priority_Specific_Dispatching pragma encountered either in the main
890   --  source or in an ancillary with'ed source. Since have to be consistent
891   --  across all units in a partition, we may as well detect inconsistencies
892   --  at compile time when we can.
893
894   type Specific_Dispatching_Entry is record
895      Dispatching_Policy : Character;
896      --  First character (upper case) of the corresponding policy name
897
898      First_Priority     : Nat;
899      --  Lower bound of the priority range to which the specified dispatching
900      --  policy applies.
901
902      Last_Priority      : Nat;
903      --  Upper bound of the priority range to which the specified dispatching
904      --  policy applies.
905
906      Pragma_Loc         : Source_Ptr;
907      --  Location of pragma setting this value in place
908   end record;
909
910   package Specific_Dispatching is new Table.Table (
911     Table_Component_Type => Specific_Dispatching_Entry,
912     Table_Index_Type     => Nat,
913     Table_Low_Bound      => 1,
914     Table_Initial        => 10,
915     Table_Increment      => 100,
916     Table_Name           => "Name_Priority_Specific_Dispatching");
917
918   -----------------
919   -- Subprograms --
920   -----------------
921
922   procedure Ensure_System_Dependency;
923   --  This procedure ensures that a dependency is created on system.ads. Even
924   --  if there is no semantic dependency, Targparm has read the file to
925   --  acquire target parameters, so we need a source dependency.
926
927   procedure Write_ALI (Object : Boolean);
928   --  This procedure writes the library information for the current main unit
929   --  The Object parameter is true if an object file is created, and false
930   --  otherwise.
931   --
932   --  Note: in the case where we are not generating code (-gnatc mode), this
933   --  routine only writes an ALI file if it cannot find an existing up to
934   --  date ALI file. If it *can* find an existing up to date ALI file, then
935   --  it reads this file and sets the Lib.Compilation_Arguments table from
936   --  the A lines in this file.
937
938   procedure Add_Preprocessing_Dependency (S : Source_File_Index);
939   --  Indicate that there is a dependency to be added on a preprocessing data
940   --  file or on a preprocessing definition file.
941
942end Lib.Writ;
943