1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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
;
37 with Nlists
; use Nlists
;
38 with Gnatvsn
; use Gnatvsn
;
40 with Osint
; use Osint
;
41 with Osint
.C
; use Osint
.C
;
43 with Par_SCO
; use Par_SCO
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
47 with Sinfo
; use Sinfo
;
48 with Sinput
; use Sinput
;
49 with Snames
; use Snames
;
50 with Stringt
; use Stringt
;
51 with Tbuild
; use Tbuild
;
52 with Ttypes
; use Ttypes
;
53 with Uname
; use Uname
;
55 with System
.Case_Util
; use System
.Case_Util
;
56 with System
.WCh_Con
; use System
.WCh_Con
;
58 package body Lib
.Writ
is
60 -----------------------
61 -- Local Subprograms --
62 -----------------------
64 procedure Write_Unit_Name
(N
: Node_Id
);
65 -- Used to write out the unit name for R (pragma Restriction) lines
66 -- for uses of Restriction (No_Dependence => unit-name).
68 ----------------------------------
69 -- Add_Preprocessing_Dependency --
70 ----------------------------------
72 procedure Add_Preprocessing_Dependency
(S
: Source_File_Index
) is
75 Units
.Table
(Units
.Last
) :=
76 (Unit_File_Name
=> File_Name
(S
),
77 Unit_Name
=> No_Unit_Name
,
78 Expected_Unit
=> No_Unit_Name
,
81 Cunit_Entity
=> Empty
,
83 Dynamic_Elab
=> False,
85 Generate_Code
=> False,
86 Has_Allocator
=> False,
88 Is_Compiler_Unit
=> False,
89 Ident_String
=> Empty
,
96 Error_Location
=> No_Location
,
98 end Add_Preprocessing_Dependency
;
100 ------------------------------
101 -- Ensure_System_Dependency --
102 ------------------------------
104 procedure Ensure_System_Dependency
is
105 System_Uname
: Unit_Name_Type
;
106 -- Unit name for system spec if needed for dummy entry
108 System_Fname
: File_Name_Type
;
109 -- File name for system spec if needed for dummy entry
112 -- Nothing to do if we already compiled System
114 for Unum
in Units
.First
.. Last_Unit
loop
115 if Units
.Table
(Unum
).Source_Index
= System_Source_File_Index
then
120 -- If no entry for system.ads in the units table, then add a entry
121 -- to the units table for system.ads, which will be referenced when
122 -- the ali file is generated. We need this because every unit depends
123 -- on system as a result of Targparm scanning the system.ads file to
124 -- determine the target dependent parameters for the compilation.
127 Name_Buffer
(1 .. 6) := "system";
128 System_Uname
:= Name_To_Unit_Name
(Name_Enter
);
129 System_Fname
:= File_Name
(System_Source_File_Index
);
131 Units
.Increment_Last
;
132 Units
.Table
(Units
.Last
) := (
133 Unit_File_Name
=> System_Fname
,
134 Unit_Name
=> System_Uname
,
135 Expected_Unit
=> System_Uname
,
136 Source_Index
=> System_Source_File_Index
,
138 Cunit_Entity
=> Empty
,
140 Dynamic_Elab
=> False,
141 Fatal_Error
=> False,
142 Generate_Code
=> False,
143 Has_Allocator
=> False,
145 Is_Compiler_Unit
=> False,
146 Ident_String
=> Empty
,
153 Error_Location
=> No_Location
,
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 Alfa 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");
885 end Write_With_Lines
;
887 -- Start of processing for Write_ALI
890 -- We never write an ALI file if the original operating mode was
891 -- syntax-only (-gnats switch used in compiler invocation line)
893 if Original_Operating_Mode
= Check_Syntax
894 or flag_compare_debug
/= 0
899 -- Generation of ALI files may be disabled, e.g. for formal verification
902 if Disable_ALI_File
then
906 -- Build sorted source dependency table. We do this right away, because
907 -- it is referenced by Up_To_Date_ALI_File_Exists.
909 for Unum
in Units
.First
.. Last_Unit
loop
910 if Cunit_Entity
(Unum
) = Empty
911 or else not From_With_Type
(Cunit_Entity
(Unum
))
913 Num_Sdep
:= Num_Sdep
+ 1;
914 Sdep_Table
(Num_Sdep
) := Unum
;
918 -- Sort the table so that the D lines are in order
920 Lib
.Sort
(Sdep_Table
(1 .. Num_Sdep
));
922 -- If we are not generating code, and there is an up to date ALI file
923 -- file accessible, read it, and acquire the compilation arguments from
926 if Operating_Mode
/= Generate_Code
then
927 if Up_To_Date_ALI_File_Exists
then
928 Update_Tables_From_ALI_File
;
933 -- Otherwise acquire compilation arguments and prepare to write
934 -- out a new ali file.
936 Create_Output_Library_Info
;
938 -- Output version line
940 Write_Info_Initiate
('V');
941 Write_Info_Str
(" """);
942 Write_Info_Str
(Verbose_Library_Version
);
943 Write_Info_Char
('"');
947 -- Output main program line if this is acceptable main program
949 Output_Main_Program_Line
: declare
950 U
: Node_Id
:= Unit
(Units
.Table
(Main_Unit
).Cunit
);
953 procedure M_Parameters
;
954 -- Output parameters for main program line
960 procedure M_Parameters
is
962 if Main_Priority
(Main_Unit
) /= Default_Main_Priority
then
963 Write_Info_Char
(' ');
964 Write_Info_Nat
(Main_Priority
(Main_Unit
));
967 if Opt
.Time_Slice_Set
then
968 Write_Info_Str
(" T=");
969 Write_Info_Nat
(Opt
.Time_Slice_Value
);
972 if Has_Allocator
(Main_Unit
) then
973 Write_Info_Str
(" AB");
976 if Main_CPU
(Main_Unit
) /= Default_Main_CPU
then
977 Write_Info_Str
(" C=");
978 Write_Info_Nat
(Main_CPU
(Main_Unit
));
981 Write_Info_Str
(" W=");
983 (WC_Encoding_Letters
(Wide_Character_Encoding_Method
));
988 -- Start of processing for Output_Main_Program_Line
991 if Nkind
(U
) = N_Subprogram_Body
993 (Nkind
(U
) = N_Package_Body
995 Nkind
(Original_Node
(U
)) in N_Subprogram_Instantiation
)
997 -- If the unit is a subprogram instance, the entity for the
998 -- subprogram is the alias of the visible entity, which is the
999 -- related instance of the wrapper package. We retrieve the
1000 -- subprogram declaration of the desired entity.
1002 if Nkind
(U
) = N_Package_Body
then
1003 U
:= Parent
(Parent
(
1004 Alias
(Related_Instance
(Defining_Unit_Name
1005 (Specification
(Unit
(Library_Unit
(Parent
(U
)))))))));
1008 S
:= Specification
(U
);
1010 -- A generic subprogram is never a main program
1012 if Nkind
(U
) = N_Subprogram_Body
1013 and then Present
(Corresponding_Spec
(U
))
1015 Ekind_In
(Corresponding_Spec
(U
),
1016 E_Generic_Procedure
, E_Generic_Function
)
1020 elsif No
(Parameter_Specifications
(S
)) then
1021 if Nkind
(S
) = N_Procedure_Specification
then
1022 Write_Info_Initiate
('M');
1023 Write_Info_Str
(" P");
1028 Nam
: Node_Id
:= Defining_Unit_Name
(S
);
1031 -- If it is a child unit, get its simple name
1033 if Nkind
(Nam
) = N_Defining_Program_Unit_Name
then
1034 Nam
:= Defining_Identifier
(Nam
);
1037 if Is_Integer_Type
(Etype
(Nam
)) then
1038 Write_Info_Initiate
('M');
1039 Write_Info_Str
(" F");
1046 end Output_Main_Program_Line
;
1048 -- Write command argument ('A') lines
1050 for A
in 1 .. Compilation_Switches
.Last
loop
1051 Write_Info_Initiate
('A');
1052 Write_Info_Char
(' ');
1053 Write_Info_Str
(Compilation_Switches
.Table
(A
).all);
1054 Write_Info_Terminate
;
1057 -- Output parameters ('P') line
1059 Write_Info_Initiate
('P');
1061 if Compilation_Errors
then
1062 Write_Info_Str
(" CE");
1065 if Opt
.Detect_Blocking
then
1066 Write_Info_Str
(" DB");
1069 if Opt
.Float_Format
/= ' ' then
1070 Write_Info_Str
(" F");
1072 if Opt
.Float_Format
= 'I' then
1073 Write_Info_Char
('I');
1075 elsif Opt
.Float_Format_Long
= 'D' then
1076 Write_Info_Char
('D');
1079 Write_Info_Char
('G');
1084 and then not Is_Predefined_File_Name
(Unit_File_Name
(Main_Unit
))
1086 if Locking_Policy
/= ' ' then
1087 Write_Info_Str
(" L");
1088 Write_Info_Char
(Locking_Policy
);
1091 if Queuing_Policy
/= ' ' then
1092 Write_Info_Str
(" Q");
1093 Write_Info_Char
(Queuing_Policy
);
1096 if Task_Dispatching_Policy
/= ' ' then
1097 Write_Info_Str
(" T");
1098 Write_Info_Char
(Task_Dispatching_Policy
);
1099 Write_Info_Char
(' ');
1103 if Partition_Elaboration_Policy
/= ' ' then
1104 Write_Info_Str
(" E");
1105 Write_Info_Char
(Partition_Elaboration_Policy
);
1109 Write_Info_Str
(" NO");
1112 if No_Run_Time_Mode
then
1113 Write_Info_Str
(" NR");
1116 if Normalize_Scalars
then
1117 Write_Info_Str
(" NS");
1120 if Sec_Stack_Used
then
1121 Write_Info_Str
(" SS");
1124 if Unreserve_All_Interrupts
then
1125 Write_Info_Str
(" UA");
1128 if Exception_Mechanism
= Back_End_Exceptions
then
1129 Write_Info_Str
(" ZX");
1134 -- Before outputting the restrictions line, update the setting of
1135 -- the No_Elaboration_Code flag. Violations of this restriction
1136 -- cannot be detected until after the backend has been called since
1137 -- it is the backend that sets this flag. We have to check all units
1138 -- for which we have generated code
1140 for Unit
in Units
.First
.. Last_Unit
loop
1141 if Units
.Table
(Unit
).Generate_Code
1142 or else Unit
= Main_Unit
1144 if not Has_No_Elaboration_Code
(Cunit
(Unit
)) then
1145 Main_Restrictions
.Violated
(No_Elaboration_Code
) := True;
1150 -- Positional case (only if debug flag -gnatd.R is set)
1152 if Debug_Flag_Dot_RR
then
1154 -- Output first restrictions line
1156 Write_Info_Initiate
('R');
1157 Write_Info_Char
(' ');
1159 -- First the information for the boolean restrictions
1161 for R
in All_Boolean_Restrictions
loop
1162 if Main_Restrictions
.Set
(R
)
1163 and then not Restriction_Warnings
(R
)
1165 Write_Info_Char
('r');
1166 elsif Main_Restrictions
.Violated
(R
) then
1167 Write_Info_Char
('v');
1169 Write_Info_Char
('n');
1173 -- And now the information for the parameter restrictions
1175 for RP
in All_Parameter_Restrictions
loop
1176 if Main_Restrictions
.Set
(RP
)
1177 and then not Restriction_Warnings
(RP
)
1179 Write_Info_Char
('r');
1180 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1182 Write_Info_Char
('n');
1185 if not Main_Restrictions
.Violated
(RP
)
1186 or else RP
not in Checked_Parameter_Restrictions
1188 Write_Info_Char
('n');
1190 Write_Info_Char
('v');
1191 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1193 if Main_Restrictions
.Unknown
(RP
) then
1194 Write_Info_Char
('+');
1201 -- Named case (if debug flag -gnatd.R is not set)
1208 -- Write RN header line with preceding blank line
1211 Write_Info_Initiate
('R');
1212 Write_Info_Char
('N');
1215 -- First the lines for the boolean restrictions
1217 for R
in All_Boolean_Restrictions
loop
1218 if Main_Restrictions
.Set
(R
)
1219 and then not Restriction_Warnings
(R
)
1222 elsif Main_Restrictions
.Violated
(R
) then
1228 Write_Info_Initiate
('R');
1229 Write_Info_Char
(C
);
1230 Write_Info_Char
(' ');
1231 Write_Info_Str
(All_Boolean_Restrictions
'Image (R
));
1239 -- And now the lines for the parameter restrictions
1241 for RP
in All_Parameter_Restrictions
loop
1242 if Main_Restrictions
.Set
(RP
)
1243 and then not Restriction_Warnings
(RP
)
1245 Write_Info_Initiate
('R');
1246 Write_Info_Str
("R ");
1247 Write_Info_Str
(All_Parameter_Restrictions
'Image (RP
));
1248 Write_Info_Char
('=');
1249 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1253 if not Main_Restrictions
.Violated
(RP
)
1254 or else RP
not in Checked_Parameter_Restrictions
1258 Write_Info_Initiate
('R');
1259 Write_Info_Str
("V ");
1260 Write_Info_Str
(All_Parameter_Restrictions
'Image (RP
));
1261 Write_Info_Char
('=');
1262 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1264 if Main_Restrictions
.Unknown
(RP
) then
1265 Write_Info_Char
('+');
1273 -- Output R lines for No_Dependence entries
1275 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
1276 if In_Extended_Main_Source_Unit
(No_Dependences
.Table
(J
).Unit
)
1277 and then not No_Dependences
.Table
(J
).Warn
1279 Write_Info_Initiate
('R');
1280 Write_Info_Char
(' ');
1281 Write_Unit_Name
(No_Dependences
.Table
(J
).Unit
);
1286 -- Output interrupt state lines
1288 for J
in Interrupt_States
.First
.. Interrupt_States
.Last
loop
1289 Write_Info_Initiate
('I');
1290 Write_Info_Char
(' ');
1291 Write_Info_Nat
(Interrupt_States
.Table
(J
).Interrupt_Number
);
1292 Write_Info_Char
(' ');
1293 Write_Info_Char
(Interrupt_States
.Table
(J
).Interrupt_State
);
1294 Write_Info_Char
(' ');
1296 (Nat
(Get_Logical_Line_Number
1297 (Interrupt_States
.Table
(J
).Pragma_Loc
)));
1301 -- Output priority specific dispatching lines
1303 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
1304 Write_Info_Initiate
('S');
1305 Write_Info_Char
(' ');
1306 Write_Info_Char
(Specific_Dispatching
.Table
(J
).Dispatching_Policy
);
1307 Write_Info_Char
(' ');
1308 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).First_Priority
);
1309 Write_Info_Char
(' ');
1310 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).Last_Priority
);
1311 Write_Info_Char
(' ');
1313 (Nat
(Get_Logical_Line_Number
1314 (Specific_Dispatching
.Table
(J
).Pragma_Loc
)));
1318 -- Loop through file table to output information for all units for which
1319 -- we have generated code, as marked by the Generate_Code flag.
1321 for Unit
in Units
.First
.. Last_Unit
loop
1322 if Units
.Table
(Unit
).Generate_Code
1323 or else Unit
= Main_Unit
1325 Write_Info_EOL
; -- blank line
1326 Write_Unit_Information
(Unit
);
1330 Write_Info_EOL
; -- blank line
1332 -- Output external version reference lines
1334 for J
in 1 .. Version_Ref
.Last
loop
1335 Write_Info_Initiate
('E');
1336 Write_Info_Char
(' ');
1338 for K
in 1 .. String_Length
(Version_Ref
.Table
(J
)) loop
1339 Write_Info_Char_Code
(Get_String_Char
(Version_Ref
.Table
(J
), K
));
1345 -- Prepare to output the source dependency lines
1348 Unum
: Unit_Number_Type
;
1349 -- Number of unit being output
1351 Sind
: Source_File_Index
;
1352 -- Index of corresponding source file
1354 Fname
: File_Name_Type
;
1357 for J
in 1 .. Num_Sdep
loop
1358 Unum
:= Sdep_Table
(J
);
1359 Units
.Table
(Unum
).Dependency_Num
:= J
;
1360 Sind
:= Units
.Table
(Unum
).Source_Index
;
1362 Write_Info_Initiate
('D');
1363 Write_Info_Char
(' ');
1365 -- Normal case of a unit entry with a source index
1367 if Sind
/= No_Source_File
then
1368 Fname
:= File_Name
(Sind
);
1370 -- Ensure that on platforms where the file names are not
1371 -- case sensitive, the recorded file name is in lower case.
1373 if not File_Names_Case_Sensitive
then
1374 Get_Name_String
(Fname
);
1375 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1379 Write_Info_Name
(Fname
);
1380 Write_Info_Tab
(25);
1381 Write_Info_Str
(String (Time_Stamp
(Sind
)));
1382 Write_Info_Char
(' ');
1383 Write_Info_Str
(Get_Hex_String
(Source_Checksum
(Sind
)));
1385 -- If subunit, add unit name, omitting the %b at the end
1387 if Present
(Cunit
(Unum
))
1388 and then Nkind
(Unit
(Cunit
(Unum
))) = N_Subunit
1390 Get_Decoded_Name_String
(Unit_Name
(Unum
));
1391 Write_Info_Char
(' ');
1392 Write_Info_Str
(Name_Buffer
(1 .. Name_Len
- 2));
1395 -- If Source_Reference pragma used output information
1397 if Num_SRef_Pragmas
(Sind
) > 0 then
1398 Write_Info_Char
(' ');
1400 if Num_SRef_Pragmas
(Sind
) = 1 then
1401 Write_Info_Nat
(Int
(First_Mapped_Line
(Sind
)));
1406 Write_Info_Char
(':');
1407 Write_Info_Name
(Reference_Name
(Sind
));
1410 -- Case where there is no source index (happens for missing
1411 -- files). In this case we write a dummy time stamp.
1414 Write_Info_Name
(Unit_File_Name
(Unum
));
1415 Write_Info_Tab
(25);
1416 Write_Info_Str
(String (Dummy_Time_Stamp
));
1417 Write_Info_Char
(' ');
1418 Write_Info_Str
(Get_Hex_String
(0));
1425 -- Output cross-references
1427 if Opt
.Xref_Active
then
1431 -- Output SCO information if present
1433 if Generate_SCO
then
1437 -- Output Alfa information if needed
1439 if Opt
.Xref_Active
and then Alfa_Mode
then
1440 Collect_Alfa
(Sdep_Table
=> Sdep_Table
, Num_Sdep
=> Num_Sdep
);
1444 -- Output target dependent information if needed
1446 if Generate_Target_Dependent_Info
then
1448 subtype Str4
is String (1 .. 4);
1450 procedure Gen_TDI_Bool
(Code
: Str4
; Val
: Boolean);
1451 -- Generate T line for Bool value
1453 procedure Gen_TDI_Nat
(Code
: Str4
; Val
: Int
);
1454 -- Generate T line for Pos or Nat value
1460 procedure Gen_TDI_Bool
(Code
: Str4
; Val
: Boolean) is
1462 Write_Info_Initiate
('T');
1463 Write_Info_Char
(' ');
1464 Write_Info_Str
(Code
);
1467 Write_Info_Str
(" TRUE");
1469 Write_Info_Str
(" FALSE");
1479 procedure Gen_TDI_Nat
(Code
: Str4
; Val
: Int
) is
1481 Write_Info_Initiate
('T');
1482 Write_Info_Char
(' ');
1483 Write_Info_Str
(Code
);
1484 Write_Info_Char
(' ');
1485 Write_Info_Nat
(Val
);
1490 -- Start of processing for Gen_TDI
1493 Gen_TDI_Nat
("SINS", Standard_Short_Short_Integer_Size
);
1494 Gen_TDI_Nat
("SINW", Standard_Short_Short_Integer_Width
);
1495 Gen_TDI_Nat
("SHIS", Standard_Short_Integer_Size
);
1496 Gen_TDI_Nat
("SHIW", Standard_Short_Integer_Width
);
1497 Gen_TDI_Nat
("INTS", Standard_Integer_Size
);
1498 Gen_TDI_Nat
("INTW", Standard_Integer_Width
);
1499 Gen_TDI_Nat
("LINS", Standard_Long_Integer_Size
);
1500 Gen_TDI_Nat
("LINW", Standard_Long_Integer_Width
);
1501 Gen_TDI_Nat
("LLIS", Standard_Long_Long_Integer_Size
);
1502 Gen_TDI_Nat
("LLIW", Standard_Long_Long_Integer_Width
);
1503 Gen_TDI_Nat
("SFLS", Standard_Short_Float_Size
);
1504 Gen_TDI_Nat
("SFLD", Standard_Short_Float_Digits
);
1505 Gen_TDI_Nat
("FLTS", Standard_Float_Size
);
1506 Gen_TDI_Nat
("FLTD", Standard_Float_Digits
);
1507 Gen_TDI_Nat
("LFLS", Standard_Long_Float_Size
);
1508 Gen_TDI_Nat
("LFLD", Standard_Long_Float_Digits
);
1509 Gen_TDI_Nat
("LLFS", Standard_Long_Long_Float_Size
);
1510 Gen_TDI_Nat
("LLFD", Standard_Long_Long_Float_Digits
);
1511 Gen_TDI_Nat
("CHAS", Standard_Character_Size
);
1512 Gen_TDI_Nat
("WCHS", Standard_Wide_Character_Size
);
1513 Gen_TDI_Nat
("WWCS", Standard_Wide_Wide_Character_Size
);
1514 Gen_TDI_Nat
("ADRS", System_Address_Size
);
1515 Gen_TDI_Nat
("MBMP", System_Max_Binary_Modulus_Power
);
1516 Gen_TDI_Nat
("MNMP", System_Max_Nonbinary_Modulus_Power
);
1517 Gen_TDI_Nat
("SUNI", System_Storage_Unit
);
1518 Gen_TDI_Nat
("WRDS", System_Word_Size
);
1519 Gen_TDI_Nat
("TICK", System_Tick_Nanoseconds
);
1520 Gen_TDI_Nat
("WCTS", Interfaces_Wchar_T_Size
);
1521 Gen_TDI_Nat
("MAXA", Maximum_Alignment
);
1522 Gen_TDI_Nat
("ALLA", System_Allocator_Alignment
);
1523 Gen_TDI_Nat
("MUNF", Max_Unaligned_Field
);
1524 Gen_TDI_Bool
("BEND", Bytes_Big_Endian
);
1525 Gen_TDI_Bool
("STRA", Target_Strict_Alignment
);
1526 Gen_TDI_Nat
("DFLA", Target_Double_Float_Alignment
);
1527 Gen_TDI_Nat
("DSCA", Target_Double_Scalar_Alignment
);
1531 -- Output final blank line and we are done. This final blank line is
1532 -- probably junk, but we don't feel like making an incompatible change!
1534 Write_Info_Terminate
;
1535 Close_Output_Library_Info
;
1538 ---------------------
1539 -- Write_Unit_Name --
1540 ---------------------
1542 procedure Write_Unit_Name
(N
: Node_Id
) is
1544 if Nkind
(N
) = N_Identifier
then
1545 Write_Info_Name
(Chars
(N
));
1548 pragma Assert
(Nkind
(N
) = N_Selected_Component
);
1549 Write_Unit_Name
(Prefix
(N
));
1550 Write_Info_Char
('.');
1551 Write_Unit_Name
(Selector_Name
(N
));
1553 end Write_Unit_Name
;