1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Errout
; use Errout
;
32 with Fname
; use Fname
;
33 with Fname
.UF
; use Fname
.UF
;
34 with Lib
.Util
; use Lib
.Util
;
35 with Lib
.Xref
; use Lib
.Xref
;
36 with Nlists
; use Nlists
;
37 with Gnatvsn
; use Gnatvsn
;
39 with Osint
; use Osint
;
40 with Osint
.C
; use Osint
.C
;
42 with Par_SCO
; use Par_SCO
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
46 with Sinfo
; use Sinfo
;
47 with Sinput
; use Sinput
;
48 with Snames
; use Snames
;
49 with Stringt
; use Stringt
;
50 with Tbuild
; use Tbuild
;
51 with Uname
; use Uname
;
53 with System
.Case_Util
; use System
.Case_Util
;
54 with System
.WCh_Con
; use System
.WCh_Con
;
56 package body Lib
.Writ
is
58 -----------------------
59 -- Local Subprograms --
60 -----------------------
62 procedure Write_Unit_Name
(N
: Node_Id
);
63 -- Used to write out the unit name for R (pragma Restriction) lines
64 -- for uses of Restriction (No_Dependence => unit-name).
66 ----------------------------------
67 -- Add_Preprocessing_Dependency --
68 ----------------------------------
70 procedure Add_Preprocessing_Dependency
(S
: Source_File_Index
) is
73 Units
.Table
(Units
.Last
) :=
74 (Unit_File_Name
=> File_Name
(S
),
75 Unit_Name
=> No_Unit_Name
,
76 Expected_Unit
=> No_Unit_Name
,
79 Cunit_Entity
=> Empty
,
81 Dynamic_Elab
=> False,
83 Generate_Code
=> False,
84 Has_Allocator
=> False,
86 Is_Compiler_Unit
=> False,
87 Ident_String
=> Empty
,
94 Error_Location
=> No_Location
,
96 SPARK_Mode_Pragma
=> Empty
);
97 end Add_Preprocessing_Dependency
;
99 ------------------------------
100 -- Ensure_System_Dependency --
101 ------------------------------
103 procedure Ensure_System_Dependency
is
104 System_Uname
: Unit_Name_Type
;
105 -- Unit name for system spec if needed for dummy entry
107 System_Fname
: File_Name_Type
;
108 -- File name for system spec if needed for dummy entry
111 -- Nothing to do if we already compiled System
113 for Unum
in Units
.First
.. Last_Unit
loop
114 if Units
.Table
(Unum
).Source_Index
= System_Source_File_Index
then
119 -- If no entry for system.ads in the units table, then add a entry
120 -- to the units table for system.ads, which will be referenced when
121 -- the ali file is generated. We need this because every unit depends
122 -- on system as a result of Targparm scanning the system.ads file to
123 -- determine the target dependent parameters for the compilation.
126 Name_Buffer
(1 .. 6) := "system";
127 System_Uname
:= Name_To_Unit_Name
(Name_Enter
);
128 System_Fname
:= File_Name
(System_Source_File_Index
);
130 Units
.Increment_Last
;
131 Units
.Table
(Units
.Last
) := (
132 Unit_File_Name
=> System_Fname
,
133 Unit_Name
=> System_Uname
,
134 Expected_Unit
=> System_Uname
,
135 Source_Index
=> System_Source_File_Index
,
137 Cunit_Entity
=> Empty
,
139 Dynamic_Elab
=> False,
140 Fatal_Error
=> False,
141 Generate_Code
=> False,
142 Has_Allocator
=> False,
144 Is_Compiler_Unit
=> False,
145 Ident_String
=> Empty
,
152 Error_Location
=> No_Location
,
154 SPARK_Mode_Pragma
=> Empty
);
156 -- Parse system.ads so that the checksum is set right
157 -- Style checks are not applied.
160 Save_Mindex
: constant Nat
:= Multiple_Unit_Index
;
161 Save_Style
: constant Boolean := Style_Check
;
163 Multiple_Unit_Index
:= 0;
164 Style_Check
:= False;
165 Initialize_Scanner
(Units
.Last
, System_Source_File_Index
);
166 Discard_List
(Par
(Configuration_Pragmas
=> False));
167 Style_Check
:= Save_Style
;
168 Multiple_Unit_Index
:= Save_Mindex
;
170 end Ensure_System_Dependency
;
176 procedure Write_ALI
(Object
: Boolean) is
182 Last_Unit
: constant Unit_Number_Type
:= Units
.Last
;
183 -- Record unit number of last unit. We capture this in case we
184 -- have to add a dummy entry to the unit table for package System.
186 With_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
187 -- Array of flags to show which units are with'ed
189 Elab_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
190 -- Array of flags to show which units have pragma Elaborate set
192 Elab_All_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
193 -- Array of flags to show which units have pragma Elaborate All set
195 Elab_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
196 -- Array of flags to show which units have Elaborate_Desirable set
198 Elab_All_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
199 -- Array of flags to show which units have Elaborate_All_Desirable set
201 type Yes_No
is (Unknown
, Yes
, No
);
202 Implicit_With
: array (Units
.First
.. Last_Unit
) of Yes_No
;
203 -- Indicates if an implicit with has been given for the unit. Yes if
204 -- certainly present, no if certainly absent, unkonwn if not known.
206 Sdep_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 2));
207 -- Sorted table of source dependencies. One extra entry in case we
208 -- have to add a dummy entry for System.
211 -- Number of active entries in Sdep_Table
213 flag_compare_debug
: Int
;
214 pragma Import
(C
, flag_compare_debug
);
215 -- Import from toplev.c
217 -----------------------
218 -- Local Subprograms --
219 -----------------------
221 procedure Collect_Withs
(Cunit
: Node_Id
);
222 -- Collect with lines for entries in the context clause of the
223 -- given compilation unit, Cunit.
225 procedure Update_Tables_From_ALI_File
;
226 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
227 -- function), update tables from the ALI information, including
228 -- specifically the Compilation_Switches table.
230 function Up_To_Date_ALI_File_Exists
return Boolean;
231 -- If there exists an ALI file that is up to date, then this function
232 -- initializes the tables in the ALI spec to contain information on
233 -- this file (using Scan_ALI) and returns True. If no file exists,
234 -- or the file is not up to date, then False is returned.
236 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
);
237 -- Write out the library information for one unit for which code is
238 -- generated (includes unit line and with lines).
240 procedure Write_With_Lines
;
241 -- Write out with lines collected by calls to Collect_Withs
247 procedure Collect_Withs
(Cunit
: Node_Id
) is
249 Unum
: Unit_Number_Type
;
252 Item
:= First
(Context_Items
(Cunit
));
253 while Present
(Item
) loop
255 -- Process with clause
257 -- Ada 2005 (AI-50217): limited with_clauses do not create
258 -- dependencies, but must be recorded as components of the
259 -- partition, in case there is no regular with_clause for
260 -- the unit anywhere else.
262 if Nkind
(Item
) = N_With_Clause
then
263 Unum
:= Get_Cunit_Unit_Number
(Library_Unit
(Item
));
264 With_Flags
(Unum
) := True;
266 if not Limited_Present
(Item
) then
267 if Elaborate_Present
(Item
) then
268 Elab_Flags
(Unum
) := True;
271 if Elaborate_All_Present
(Item
) then
272 Elab_All_Flags
(Unum
) := True;
275 if Elaborate_All_Desirable
(Item
) then
276 Elab_All_Des_Flags
(Unum
) := True;
279 if Elaborate_Desirable
(Item
) then
280 Elab_Des_Flags
(Unum
) := True;
284 Set_From_With_Type
(Cunit_Entity
(Unum
));
287 if Implicit_With
(Unum
) /= Yes
then
288 if Implicit_With_From_Instantiation
(Item
) then
289 Implicit_With
(Unum
) := Yes
;
291 Implicit_With
(Unum
) := No
;
300 --------------------------------
301 -- Up_To_Date_ALI_File_Exists --
302 --------------------------------
304 function Up_To_Date_ALI_File_Exists
return Boolean is
305 Name
: File_Name_Type
;
306 Text
: Text_Buffer_Ptr
;
308 Sind
: Source_File_Index
;
311 Opt
.Check_Object_Consistency
:= True;
312 Read_Library_Info
(Name
, Text
);
314 -- Return if we could not find an ALI file
320 -- Return if ALI file has bad format
324 if Scan_ALI
(Name
, Text
, False, Err
=> True) = No_ALI_Id
then
328 -- If we have an OK ALI file, check if it is up to date
329 -- Note that we assume that the ALI read has all the entries
330 -- we have in our table, plus some additional ones (that can
331 -- come from expansion).
333 Id
:= First_Sdep_Entry
;
334 for J
in 1 .. Num_Sdep
loop
335 Sind
:= Units
.Table
(Sdep_Table
(J
)).Source_Index
;
337 while Sdep
.Table
(Id
).Sfile
/= File_Name
(Sind
) loop
338 if Id
= Sdep
.Last
then
345 if Sdep
.Table
(Id
).Stamp
/= Time_Stamp
(Sind
) then
351 end Up_To_Date_ALI_File_Exists
;
353 ---------------------------------
354 -- Update_Tables_From_ALI_File --
355 ---------------------------------
357 procedure Update_Tables_From_ALI_File
is
359 -- Build Compilation_Switches table
361 Compilation_Switches
.Init
;
363 for J
in First_Arg_Entry
.. Args
.Last
loop
364 Compilation_Switches
.Increment_Last
;
365 Compilation_Switches
.Table
(Compilation_Switches
.Last
) :=
368 end Update_Tables_From_ALI_File
;
370 ----------------------------
371 -- Write_Unit_Information --
372 ----------------------------
374 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
) is
375 Unode
: constant Node_Id
:= Cunit
(Unit_Num
);
376 Ukind
: constant Node_Kind
:= Nkind
(Unit
(Unode
));
377 Uent
: constant Entity_Id
:= Cunit_Entity
(Unit_Num
);
381 Write_Info_Initiate
('U');
382 Write_Info_Char
(' ');
383 Write_Info_Name
(Unit_Name
(Unit_Num
));
385 Write_Info_Name
(Unit_File_Name
(Unit_Num
));
388 Write_Info_Str
(Version_Get
(Unit_Num
));
390 -- Add BD parameter if Elaborate_Body pragma desirable
392 if Ekind
(Uent
) = E_Package
393 and then Elaborate_Body_Desirable
(Uent
)
395 Write_Info_Str
(" BD");
398 -- Add BN parameter if body needed for SAL
400 if (Is_Subprogram
(Uent
)
401 or else Ekind
(Uent
) = E_Package
402 or else Is_Generic_Unit
(Uent
))
403 and then Body_Needed_For_SAL
(Uent
)
405 Write_Info_Str
(" BN");
408 if Dynamic_Elab
(Unit_Num
) then
409 Write_Info_Str
(" DE");
412 -- Set the Elaborate_Body indication if either an explicit pragma
413 -- was present, or if this is an instantiation.
415 if Has_Pragma_Elaborate_Body
(Uent
)
416 or else (Ukind
= N_Package_Declaration
417 and then Is_Generic_Instance
(Uent
)
418 and then Present
(Corresponding_Body
(Unit
(Unode
))))
420 Write_Info_Str
(" EB");
423 -- Now see if we should tell the binder that an elaboration entity
424 -- is present, which must be set to true during elaboration.
425 -- We generate the indication if the following condition is met:
427 -- If this is a spec ...
429 if (Is_Subprogram
(Uent
)
431 Ekind
(Uent
) = E_Package
433 Is_Generic_Unit
(Uent
))
435 -- and an elaboration entity was declared ...
437 and then Present
(Elaboration_Entity
(Uent
))
439 -- and either the elaboration flag is required ...
442 (Elaboration_Entity_Required
(Uent
)
444 -- or this unit has elaboration code ...
446 or else not Has_No_Elaboration_Code
(Unode
)
448 -- or this unit has a separate body and this
449 -- body has elaboration code.
452 (Ekind
(Uent
) = E_Package
453 and then Present
(Body_Entity
(Uent
))
455 not Has_No_Elaboration_Code
458 (Body_Entity
(Uent
))))))
460 if Convention
(Uent
) = Convention_CIL
then
462 -- Special case for generic CIL packages which never have
465 Write_Info_Str
(" NE");
468 Write_Info_Str
(" EE");
472 if Has_No_Elaboration_Code
(Unode
) then
473 Write_Info_Str
(" NE");
476 Write_Info_Str
(" O");
477 Write_Info_Char
(OA_Setting
(Unit_Num
));
479 if Ekind_In
(Uent
, E_Package
, E_Package_Body
)
480 and then Present
(Finalizer
(Uent
))
482 Write_Info_Str
(" PF");
485 if Is_Preelaborated
(Uent
) then
486 Write_Info_Str
(" PR");
489 if Is_Pure
(Uent
) then
490 Write_Info_Str
(" PU");
493 if Has_RACW
(Unit_Num
) then
494 Write_Info_Str
(" RA");
497 if Is_Remote_Call_Interface
(Uent
) then
498 Write_Info_Str
(" RC");
501 if Is_Remote_Types
(Uent
) then
502 Write_Info_Str
(" RT");
505 if Is_Shared_Passive
(Uent
) then
506 Write_Info_Str
(" SP");
509 if Ukind
= N_Subprogram_Declaration
510 or else Ukind
= N_Subprogram_Body
512 Write_Info_Str
(" SU");
514 elsif Ukind
= N_Package_Declaration
516 Ukind
= N_Package_Body
518 -- If this is a wrapper package for a subprogram instantiation,
519 -- the user view is the subprogram. Note that in this case the
520 -- ali file contains both the spec and body of the instance.
522 if Is_Wrapper_Package
(Uent
) then
523 Write_Info_Str
(" SU");
525 Write_Info_Str
(" PK");
528 elsif Ukind
= N_Generic_Package_Declaration
then
529 Write_Info_Str
(" PK");
533 if Ukind
in N_Generic_Declaration
535 (Present
(Library_Unit
(Unode
))
537 Nkind
(Unit
(Library_Unit
(Unode
))) in N_Generic_Declaration
)
539 Write_Info_Str
(" GE");
542 if not Is_Internal_File_Name
(Unit_File_Name
(Unit_Num
), True) then
543 case Identifier_Casing
(Source_Index
(Unit_Num
)) is
544 when All_Lower_Case
=> Write_Info_Str
(" IL");
545 when All_Upper_Case
=> Write_Info_Str
(" IU");
549 case Keyword_Casing
(Source_Index
(Unit_Num
)) is
550 when Mixed_Case
=> Write_Info_Str
(" KM");
551 when All_Upper_Case
=> Write_Info_Str
(" KU");
556 if Initialize_Scalars
or else Invalid_Value_Used
then
557 Write_Info_Str
(" IS");
562 -- Generate with lines, first those that are directly with'ed
564 for J
in With_Flags
'Range loop
565 With_Flags
(J
) := False;
566 Elab_Flags
(J
) := False;
567 Elab_All_Flags
(J
) := False;
568 Elab_Des_Flags
(J
) := False;
569 Elab_All_Des_Flags
(J
) := False;
570 Implicit_With
(J
) := Unknown
;
573 Collect_Withs
(Unode
);
575 -- For a body, we must also check for any subunits which belong to
576 -- it and which have context clauses of their own, since these
577 -- with'ed units are part of its own elaboration dependencies.
579 if Nkind
(Unit
(Unode
)) in N_Unit_Body
then
580 for S
in Units
.First
.. Last_Unit
loop
582 -- We are only interested in subunits.
583 -- For preproc. data and def. files, Cunit is Empty, so
584 -- we need to test that first.
586 if Cunit
(S
) /= Empty
587 and then Nkind
(Unit
(Cunit
(S
))) = N_Subunit
589 Pnode
:= Library_Unit
(Cunit
(S
));
591 -- In gnatc mode, the errors in the subunits will not
592 -- have been recorded, but the analysis of the subunit
593 -- may have failed. There is no information to add to
594 -- ALI file in this case.
600 -- Find ultimate parent of the subunit
602 while Nkind
(Unit
(Pnode
)) = N_Subunit
loop
603 Pnode
:= Library_Unit
(Pnode
);
606 -- See if it belongs to current unit, and if so, include
609 if Pnode
= Unode
then
610 Collect_Withs
(Cunit
(S
));
618 -- Output linker option lines
620 for J
in 1 .. Linker_Option_Lines
.Last
loop
622 S
: Linker_Option_Entry
renames Linker_Option_Lines
.Table
(J
);
624 if S
.Unit
= Unit_Num
then
625 Write_Info_Initiate
('L');
626 Write_Info_Char
(' ');
627 Write_Info_Slit
(S
.Option
);
635 for J
in 1 .. Notes
.Last
loop
637 N
: constant Node_Id
:= Notes
.Table
(J
).Pragma_Node
;
638 L
: constant Source_Ptr
:= Sloc
(N
);
639 U
: constant Unit_Number_Type
:= Notes
.Table
(J
).Unit
;
644 Write_Info_Initiate
('N');
645 Write_Info_Char
(' ');
647 case Chars
(Pragma_Identifier
(N
)) is
648 when Name_Annotate
=>
656 when Name_Subtitle
=>
663 Write_Info_Int
(Int
(Get_Logical_Line_Number
(L
)));
664 Write_Info_Char
(':');
665 Write_Info_Int
(Int
(Get_Column_Number
(L
)));
671 A
:= First
(Pragma_Argument_Associations
(N
));
672 while Present
(A
) loop
673 Write_Info_Char
(' ');
675 if Chars
(A
) /= No_Name
then
676 Write_Info_Name
(Chars
(A
));
677 Write_Info_Char
(':');
681 Expr
: constant Node_Id
:= Expression
(A
);
684 if Nkind
(Expr
) = N_Identifier
then
685 Write_Info_Name
(Chars
(Expr
));
687 elsif Nkind
(Expr
) = N_Integer_Literal
688 and then Is_Static_Expression
(Expr
)
690 Write_Info_Uint
(Intval
(Expr
));
692 elsif Nkind
(Expr
) = N_String_Literal
693 and then Is_Static_Expression
(Expr
)
695 Write_Info_Slit
(Strval
(Expr
));
698 Write_Info_Str
("<expr>");
710 end Write_Unit_Information
;
712 ----------------------
713 -- Write_With_Lines --
714 ----------------------
716 procedure Write_With_Lines
is
717 With_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 1));
718 Num_Withs
: Int
:= 0;
719 Unum
: Unit_Number_Type
;
721 Uname
: Unit_Name_Type
;
722 Fname
: File_Name_Type
;
723 Pname
: constant Unit_Name_Type
:=
724 Get_Parent_Spec_Name
(Unit_Name
(Main_Unit
));
725 Body_Fname
: File_Name_Type
;
728 procedure Write_With_File_Names
729 (Nam
: in out File_Name_Type
;
731 -- Write source file name Nam and ALI file name for unit index Idx.
732 -- Possibly change Nam to lowercase (generating a new file name).
734 --------------------------
735 -- Write_With_File_Name --
736 --------------------------
738 procedure Write_With_File_Names
739 (Nam
: in out File_Name_Type
;
743 if not File_Names_Case_Sensitive
then
744 Get_Name_String
(Nam
);
745 To_Lower
(Name_Buffer
(1 .. Name_Len
));
749 Write_Info_Name
(Nam
);
751 Write_Info_Name
(Lib_File_Name
(Nam
, Idx
));
752 end Write_With_File_Names
;
754 -- Start of processing for Write_With_Lines
757 -- Loop to build the with table. A with on the main unit itself
758 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
759 -- the main unit is a subprogram with no spec, and a subunit of
760 -- it unnecessarily withs the parent.
762 for J
in Units
.First
+ 1 .. Last_Unit
loop
764 -- Add element to with table if it is with'ed or if it is the
765 -- parent spec of the main unit (case of main unit is a child
766 -- unit). The latter with is not needed for semantic purposes,
767 -- but is required by the binder for elaboration purposes.
768 -- For preproc. data and def. files, there is no Unit_Name,
769 -- check for that first.
771 if Unit_Name
(J
) /= No_Unit_Name
772 and then (With_Flags
(J
) or else Unit_Name
(J
) = Pname
)
774 Num_Withs
:= Num_Withs
+ 1;
775 With_Table
(Num_Withs
) := J
;
779 -- Sort and output the table
781 Sort
(With_Table
(1 .. Num_Withs
));
783 for J
in 1 .. Num_Withs
loop
784 Unum
:= With_Table
(J
);
785 Cunit
:= Units
.Table
(Unum
).Cunit
;
786 Uname
:= Units
.Table
(Unum
).Unit_Name
;
787 Fname
:= Units
.Table
(Unum
).Unit_File_Name
;
789 if Implicit_With
(Unum
) = Yes
then
790 Write_Info_Initiate
('Z');
792 elsif Ekind
(Cunit_Entity
(Unum
)) = E_Package
793 and then From_With_Type
(Cunit_Entity
(Unum
))
795 Write_Info_Initiate
('Y');
798 Write_Info_Initiate
('W');
801 Write_Info_Char
(' ');
802 Write_Info_Name
(Uname
);
804 -- Now we need to figure out the names of the files that contain
805 -- the with'ed unit. These will usually be the files for the body,
806 -- except in the case of a package that has no body. Note that we
807 -- have a specific exemption here for predefined library generics
808 -- (see comments for Generic_May_Lack_ALI). We do not generate
809 -- dependency upon the ALI file for such units. Older compilers
810 -- used to not support generating code (and ALI) for generics, and
811 -- we want to avoid having different processing (namely, different
812 -- lists of files to be compiled) for different stages of the
815 if not ((Nkind
(Unit
(Cunit
)) in N_Generic_Declaration
817 Nkind
(Unit
(Cunit
)) in N_Generic_Renaming_Declaration
)
818 and then Generic_May_Lack_ALI
(Fname
))
820 -- In SPARK mode, always generate the dependencies on ALI
821 -- files, which are required to compute frame conditions
828 if Is_Spec_Name
(Uname
) then
831 (Get_Body_Name
(Uname
),
832 Subunit
=> False, May_Fail
=> True);
836 (Get_Body_Name
(Uname
));
838 if Body_Fname
= No_File
then
839 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
840 Body_Index
:= Get_Unit_Index
(Uname
);
844 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
845 Body_Index
:= Get_Unit_Index
(Uname
);
848 -- A package is considered to have a body if it requires
849 -- a body or if a body is present in Ada 83 mode.
851 if Body_Required
(Cunit
)
852 or else (Ada_Version
= Ada_83
853 and then Full_Source_Name
(Body_Fname
) /= No_File
)
855 Write_With_File_Names
(Body_Fname
, Body_Index
);
857 Write_With_File_Names
(Fname
, Munit_Index
(Unum
));
860 if Ekind
(Cunit_Entity
(Unum
)) = E_Package
861 and then From_With_Type
(Cunit_Entity
(Unum
))
865 if Elab_Flags
(Unum
) then
866 Write_Info_Str
(" E");
869 if Elab_All_Flags
(Unum
) then
870 Write_Info_Str
(" EA");
873 if Elab_Des_Flags
(Unum
) then
874 Write_Info_Str
(" ED");
877 if Elab_All_Des_Flags
(Unum
) then
878 Write_Info_Str
(" AD");
886 -- Finally generate the special lines for cases of Restriction_Set
887 -- with No_Dependence and no restriction present.
890 Unam
: Unit_Name_Type
;
893 for J
in Restriction_Set_Dependences
.First
..
894 Restriction_Set_Dependences
.Last
896 Unam
:= Restriction_Set_Dependences
.Table
(J
);
898 -- Don't need an entry if already in the unit table
900 for U
in 0 .. Last_Unit
loop
901 if Unit_Name
(U
) = Unam
then
906 -- Otherwise generate the entry
908 Write_Info_Initiate
('W');
909 Write_Info_Char
(' ');
910 Write_Info_Name
(Unam
);
917 end Write_With_Lines
;
919 -- Start of processing for Write_ALI
922 -- We never write an ALI file if the original operating mode was
923 -- syntax-only (-gnats switch used in compiler invocation line)
925 if Original_Operating_Mode
= Check_Syntax
926 or flag_compare_debug
/= 0
931 -- Generation of ALI files may be disabled, e.g. for formal verification
934 if Disable_ALI_File
then
938 -- Build sorted source dependency table. We do this right away, because
939 -- it is referenced by Up_To_Date_ALI_File_Exists.
941 for Unum
in Units
.First
.. Last_Unit
loop
942 if Cunit_Entity
(Unum
) = Empty
943 or else not From_With_Type
(Cunit_Entity
(Unum
))
945 Num_Sdep
:= Num_Sdep
+ 1;
946 Sdep_Table
(Num_Sdep
) := Unum
;
950 -- Sort the table so that the D lines are in order
952 Lib
.Sort
(Sdep_Table
(1 .. Num_Sdep
));
954 -- If we are not generating code, and there is an up to date ALI file
955 -- file accessible, read it, and acquire the compilation arguments from
958 if Operating_Mode
/= Generate_Code
then
959 if Up_To_Date_ALI_File_Exists
then
960 Update_Tables_From_ALI_File
;
965 -- Otherwise acquire compilation arguments and prepare to write
966 -- out a new ali file.
968 Create_Output_Library_Info
;
970 -- Output version line
972 Write_Info_Initiate
('V');
973 Write_Info_Str
(" """);
974 Write_Info_Str
(Verbose_Library_Version
);
975 Write_Info_Char
('"');
979 -- Output main program line if this is acceptable main program
981 Output_Main_Program_Line
: declare
982 U
: Node_Id
:= Unit
(Units
.Table
(Main_Unit
).Cunit
);
985 procedure M_Parameters
;
986 -- Output parameters for main program line
992 procedure M_Parameters
is
994 if Main_Priority
(Main_Unit
) /= Default_Main_Priority
then
995 Write_Info_Char
(' ');
996 Write_Info_Nat
(Main_Priority
(Main_Unit
));
999 if Opt
.Time_Slice_Set
then
1000 Write_Info_Str
(" T=");
1001 Write_Info_Nat
(Opt
.Time_Slice_Value
);
1004 if Has_Allocator
(Main_Unit
) then
1005 Write_Info_Str
(" AB");
1008 if Main_CPU
(Main_Unit
) /= Default_Main_CPU
then
1009 Write_Info_Str
(" C=");
1010 Write_Info_Nat
(Main_CPU
(Main_Unit
));
1013 Write_Info_Str
(" W=");
1015 (WC_Encoding_Letters
(Wide_Character_Encoding_Method
));
1020 -- Start of processing for Output_Main_Program_Line
1023 if Nkind
(U
) = N_Subprogram_Body
1025 (Nkind
(U
) = N_Package_Body
1027 Nkind
(Original_Node
(U
)) in N_Subprogram_Instantiation
)
1029 -- If the unit is a subprogram instance, the entity for the
1030 -- subprogram is the alias of the visible entity, which is the
1031 -- related instance of the wrapper package. We retrieve the
1032 -- subprogram declaration of the desired entity.
1034 if Nkind
(U
) = N_Package_Body
then
1035 U
:= Parent
(Parent
(
1036 Alias
(Related_Instance
(Defining_Unit_Name
1037 (Specification
(Unit
(Library_Unit
(Parent
(U
)))))))));
1040 S
:= Specification
(U
);
1042 -- A generic subprogram is never a main program
1044 if Nkind
(U
) = N_Subprogram_Body
1045 and then Present
(Corresponding_Spec
(U
))
1047 Ekind_In
(Corresponding_Spec
(U
),
1048 E_Generic_Procedure
, E_Generic_Function
)
1052 elsif No
(Parameter_Specifications
(S
)) then
1053 if Nkind
(S
) = N_Procedure_Specification
then
1054 Write_Info_Initiate
('M');
1055 Write_Info_Str
(" P");
1060 Nam
: Node_Id
:= Defining_Unit_Name
(S
);
1063 -- If it is a child unit, get its simple name
1065 if Nkind
(Nam
) = N_Defining_Program_Unit_Name
then
1066 Nam
:= Defining_Identifier
(Nam
);
1069 if Is_Integer_Type
(Etype
(Nam
)) then
1070 Write_Info_Initiate
('M');
1071 Write_Info_Str
(" F");
1078 end Output_Main_Program_Line
;
1080 -- Write command argument ('A') lines
1082 for A
in 1 .. Compilation_Switches
.Last
loop
1083 Write_Info_Initiate
('A');
1084 Write_Info_Char
(' ');
1085 Write_Info_Str
(Compilation_Switches
.Table
(A
).all);
1086 Write_Info_Terminate
;
1089 -- Output parameters ('P') line
1091 Write_Info_Initiate
('P');
1093 if Compilation_Errors
then
1094 Write_Info_Str
(" CE");
1097 if Opt
.Detect_Blocking
then
1098 Write_Info_Str
(" DB");
1101 if Opt
.Float_Format
/= ' ' then
1102 Write_Info_Str
(" F");
1104 if Opt
.Float_Format
= 'I' then
1105 Write_Info_Char
('I');
1107 elsif Opt
.Float_Format_Long
= 'D' then
1108 Write_Info_Char
('D');
1111 Write_Info_Char
('G');
1116 and then not Is_Predefined_File_Name
(Unit_File_Name
(Main_Unit
))
1118 if Locking_Policy
/= ' ' then
1119 Write_Info_Str
(" L");
1120 Write_Info_Char
(Locking_Policy
);
1123 if Queuing_Policy
/= ' ' then
1124 Write_Info_Str
(" Q");
1125 Write_Info_Char
(Queuing_Policy
);
1128 if Task_Dispatching_Policy
/= ' ' then
1129 Write_Info_Str
(" T");
1130 Write_Info_Char
(Task_Dispatching_Policy
);
1131 Write_Info_Char
(' ');
1135 if Partition_Elaboration_Policy
/= ' ' then
1136 Write_Info_Str
(" E");
1137 Write_Info_Char
(Partition_Elaboration_Policy
);
1141 Write_Info_Str
(" NO");
1144 if No_Run_Time_Mode
then
1145 Write_Info_Str
(" NR");
1148 if Normalize_Scalars
then
1149 Write_Info_Str
(" NS");
1152 if Sec_Stack_Used
then
1153 Write_Info_Str
(" SS");
1156 if Unreserve_All_Interrupts
then
1157 Write_Info_Str
(" UA");
1160 if Exception_Mechanism
= Back_End_Exceptions
then
1161 Write_Info_Str
(" ZX");
1166 -- Before outputting the restrictions line, update the setting of
1167 -- the No_Elaboration_Code flag. Violations of this restriction
1168 -- cannot be detected until after the backend has been called since
1169 -- it is the backend that sets this flag. We have to check all units
1170 -- for which we have generated code
1172 for Unit
in Units
.First
.. Last_Unit
loop
1173 if Units
.Table
(Unit
).Generate_Code
1174 or else Unit
= Main_Unit
1176 if not Has_No_Elaboration_Code
(Cunit
(Unit
)) then
1177 Main_Restrictions
.Violated
(No_Elaboration_Code
) := True;
1182 -- Positional case (only if debug flag -gnatd.R is set)
1184 if Debug_Flag_Dot_RR
then
1186 -- Output first restrictions line
1188 Write_Info_Initiate
('R');
1189 Write_Info_Char
(' ');
1191 -- First the information for the boolean restrictions
1193 for R
in All_Boolean_Restrictions
loop
1194 if Main_Restrictions
.Set
(R
)
1195 and then not Restriction_Warnings
(R
)
1197 Write_Info_Char
('r');
1198 elsif Main_Restrictions
.Violated
(R
) then
1199 Write_Info_Char
('v');
1201 Write_Info_Char
('n');
1205 -- And now the information for the parameter restrictions
1207 for RP
in All_Parameter_Restrictions
loop
1208 if Main_Restrictions
.Set
(RP
)
1209 and then not Restriction_Warnings
(RP
)
1211 Write_Info_Char
('r');
1212 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1214 Write_Info_Char
('n');
1217 if not Main_Restrictions
.Violated
(RP
)
1218 or else RP
not in Checked_Parameter_Restrictions
1220 Write_Info_Char
('n');
1222 Write_Info_Char
('v');
1223 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1225 if Main_Restrictions
.Unknown
(RP
) then
1226 Write_Info_Char
('+');
1233 -- Named case (if debug flag -gnatd.R is not set)
1240 -- Write RN header line with preceding blank line
1243 Write_Info_Initiate
('R');
1244 Write_Info_Char
('N');
1247 -- First the lines for the boolean restrictions
1249 for R
in All_Boolean_Restrictions
loop
1250 if Main_Restrictions
.Set
(R
)
1251 and then not Restriction_Warnings
(R
)
1254 elsif Main_Restrictions
.Violated
(R
) then
1260 Write_Info_Initiate
('R');
1261 Write_Info_Char
(C
);
1262 Write_Info_Char
(' ');
1263 Write_Info_Str
(All_Boolean_Restrictions
'Image (R
));
1271 -- And now the lines for the parameter restrictions
1273 for RP
in All_Parameter_Restrictions
loop
1274 if Main_Restrictions
.Set
(RP
)
1275 and then not Restriction_Warnings
(RP
)
1277 Write_Info_Initiate
('R');
1278 Write_Info_Str
("R ");
1279 Write_Info_Str
(All_Parameter_Restrictions
'Image (RP
));
1280 Write_Info_Char
('=');
1281 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1285 if not Main_Restrictions
.Violated
(RP
)
1286 or else RP
not in Checked_Parameter_Restrictions
1290 Write_Info_Initiate
('R');
1291 Write_Info_Str
("V ");
1292 Write_Info_Str
(All_Parameter_Restrictions
'Image (RP
));
1293 Write_Info_Char
('=');
1294 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1296 if Main_Restrictions
.Unknown
(RP
) then
1297 Write_Info_Char
('+');
1305 -- Output R lines for No_Dependence entries
1307 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
1308 if In_Extended_Main_Source_Unit
(No_Dependences
.Table
(J
).Unit
)
1309 and then not No_Dependences
.Table
(J
).Warn
1311 Write_Info_Initiate
('R');
1312 Write_Info_Char
(' ');
1313 Write_Unit_Name
(No_Dependences
.Table
(J
).Unit
);
1318 -- Output interrupt state lines
1320 for J
in Interrupt_States
.First
.. Interrupt_States
.Last
loop
1321 Write_Info_Initiate
('I');
1322 Write_Info_Char
(' ');
1323 Write_Info_Nat
(Interrupt_States
.Table
(J
).Interrupt_Number
);
1324 Write_Info_Char
(' ');
1325 Write_Info_Char
(Interrupt_States
.Table
(J
).Interrupt_State
);
1326 Write_Info_Char
(' ');
1328 (Nat
(Get_Logical_Line_Number
1329 (Interrupt_States
.Table
(J
).Pragma_Loc
)));
1333 -- Output priority specific dispatching lines
1335 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
1336 Write_Info_Initiate
('S');
1337 Write_Info_Char
(' ');
1338 Write_Info_Char
(Specific_Dispatching
.Table
(J
).Dispatching_Policy
);
1339 Write_Info_Char
(' ');
1340 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).First_Priority
);
1341 Write_Info_Char
(' ');
1342 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).Last_Priority
);
1343 Write_Info_Char
(' ');
1345 (Nat
(Get_Logical_Line_Number
1346 (Specific_Dispatching
.Table
(J
).Pragma_Loc
)));
1350 -- Loop through file table to output information for all units for which
1351 -- we have generated code, as marked by the Generate_Code flag.
1353 for Unit
in Units
.First
.. Last_Unit
loop
1354 if Units
.Table
(Unit
).Generate_Code
1355 or else Unit
= Main_Unit
1357 Write_Info_EOL
; -- blank line
1358 Write_Unit_Information
(Unit
);
1362 Write_Info_EOL
; -- blank line
1364 -- Output external version reference lines
1366 for J
in 1 .. Version_Ref
.Last
loop
1367 Write_Info_Initiate
('E');
1368 Write_Info_Char
(' ');
1370 for K
in 1 .. String_Length
(Version_Ref
.Table
(J
)) loop
1371 Write_Info_Char_Code
(Get_String_Char
(Version_Ref
.Table
(J
), K
));
1377 -- Prepare to output the source dependency lines
1380 Unum
: Unit_Number_Type
;
1381 -- Number of unit being output
1383 Sind
: Source_File_Index
;
1384 -- Index of corresponding source file
1386 Fname
: File_Name_Type
;
1389 for J
in 1 .. Num_Sdep
loop
1390 Unum
:= Sdep_Table
(J
);
1391 Units
.Table
(Unum
).Dependency_Num
:= J
;
1392 Sind
:= Units
.Table
(Unum
).Source_Index
;
1394 Write_Info_Initiate
('D');
1395 Write_Info_Char
(' ');
1397 -- Normal case of a unit entry with a source index
1399 if Sind
/= No_Source_File
then
1400 Fname
:= File_Name
(Sind
);
1402 -- Ensure that on platforms where the file names are not
1403 -- case sensitive, the recorded file name is in lower case.
1405 if not File_Names_Case_Sensitive
then
1406 Get_Name_String
(Fname
);
1407 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1411 Write_Info_Name
(Fname
);
1412 Write_Info_Tab
(25);
1413 Write_Info_Str
(String (Time_Stamp
(Sind
)));
1414 Write_Info_Char
(' ');
1415 Write_Info_Str
(Get_Hex_String
(Source_Checksum
(Sind
)));
1417 -- If subunit, add unit name, omitting the %b at the end
1419 if Present
(Cunit
(Unum
))
1420 and then Nkind
(Unit
(Cunit
(Unum
))) = N_Subunit
1422 Get_Decoded_Name_String
(Unit_Name
(Unum
));
1423 Write_Info_Char
(' ');
1424 Write_Info_Str
(Name_Buffer
(1 .. Name_Len
- 2));
1427 -- If Source_Reference pragma used output information
1429 if Num_SRef_Pragmas
(Sind
) > 0 then
1430 Write_Info_Char
(' ');
1432 if Num_SRef_Pragmas
(Sind
) = 1 then
1433 Write_Info_Nat
(Int
(First_Mapped_Line
(Sind
)));
1438 Write_Info_Char
(':');
1439 Write_Info_Name
(Reference_Name
(Sind
));
1442 -- Case where there is no source index (happens for missing
1443 -- files). In this case we write a dummy time stamp.
1446 Write_Info_Name
(Unit_File_Name
(Unum
));
1447 Write_Info_Tab
(25);
1448 Write_Info_Str
(String (Dummy_Time_Stamp
));
1449 Write_Info_Char
(' ');
1450 Write_Info_Str
(Get_Hex_String
(0));
1457 -- Output cross-references
1459 if Opt
.Xref_Active
then
1463 -- Output SCO information if present
1465 if Generate_SCO
then
1469 -- Output SPARK cross-reference information if needed
1471 if Opt
.Xref_Active
and then SPARK_Mode
then
1472 SPARK_Specific
.Collect_SPARK_Xrefs
(Sdep_Table
=> Sdep_Table
,
1473 Num_Sdep
=> Num_Sdep
);
1474 SPARK_Specific
.Output_SPARK_Xrefs
;
1477 -- Output final blank line and we are done. This final blank line is
1478 -- probably junk, but we don't feel like making an incompatible change!
1480 Write_Info_Terminate
;
1481 Close_Output_Library_Info
;
1484 ---------------------
1485 -- Write_Unit_Name --
1486 ---------------------
1488 procedure Write_Unit_Name
(N
: Node_Id
) is
1490 if Nkind
(N
) = N_Identifier
then
1491 Write_Info_Name
(Chars
(N
));
1494 pragma Assert
(Nkind
(N
) = N_Selected_Component
);
1495 Write_Unit_Name
(Prefix
(N
));
1496 Write_Info_Char
('.');
1497 Write_Unit_Name
(Selector_Name
(N
));
1499 end Write_Unit_Name
;