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