1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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 Einfo
; use Einfo
;
30 with Errout
; use Errout
;
31 with Fname
; use Fname
;
32 with Fname
.UF
; use Fname
.UF
;
33 with Lib
.Util
; use Lib
.Util
;
34 with Lib
.Xref
; use Lib
.Xref
;
35 with Nlists
; use Nlists
;
36 with Gnatvsn
; use Gnatvsn
;
38 with Osint
; use Osint
;
39 with Osint
.C
; use Osint
.C
;
41 with Par_SCO
; use Par_SCO
;
42 with Restrict
; use Restrict
;
43 with Rident
; use Rident
;
45 with Sinfo
; use Sinfo
;
46 with Sinput
; use Sinput
;
47 with Snames
; use Snames
;
48 with Stringt
; use Stringt
;
49 with Tbuild
; use Tbuild
;
50 with Uname
; use Uname
;
52 with System
.Case_Util
; use System
.Case_Util
;
53 with System
.WCh_Con
; use System
.WCh_Con
;
55 package body Lib
.Writ
is
57 -----------------------
58 -- Local Subprograms --
59 -----------------------
61 procedure Write_Unit_Name
(N
: Node_Id
);
62 -- Used to write out the unit name for R (pragma Restriction) lines
63 -- for uses of Restriction (No_Dependence => unit-name).
65 ----------------------------------
66 -- Add_Preprocessing_Dependency --
67 ----------------------------------
69 procedure Add_Preprocessing_Dependency
(S
: Source_File_Index
) is
72 Units
.Table
(Units
.Last
) :=
73 (Unit_File_Name
=> File_Name
(S
),
74 Unit_Name
=> No_Unit_Name
,
75 Expected_Unit
=> No_Unit_Name
,
78 Cunit_Entity
=> Empty
,
80 Dynamic_Elab
=> False,
82 Generate_Code
=> False,
84 Is_Compiler_Unit
=> False,
85 Ident_String
=> Empty
,
91 Error_Location
=> No_Location
,
93 end Add_Preprocessing_Dependency
;
95 ------------------------------
96 -- Ensure_System_Dependency --
97 ------------------------------
99 procedure Ensure_System_Dependency
is
100 System_Uname
: Unit_Name_Type
;
101 -- Unit name for system spec if needed for dummy entry
103 System_Fname
: File_Name_Type
;
104 -- File name for system spec if needed for dummy entry
107 -- Nothing to do if we already compiled System
109 for Unum
in Units
.First
.. Last_Unit
loop
110 if Units
.Table
(Unum
).Source_Index
= System_Source_File_Index
then
115 -- If no entry for system.ads in the units table, then add a entry
116 -- to the units table for system.ads, which will be referenced when
117 -- the ali file is generated. We need this because every unit depends
118 -- on system as a result of Targparm scanning the system.ads file to
119 -- determine the target dependent parameters for the compilation.
122 Name_Buffer
(1 .. 6) := "system";
123 System_Uname
:= Name_To_Unit_Name
(Name_Enter
);
124 System_Fname
:= File_Name
(System_Source_File_Index
);
126 Units
.Increment_Last
;
127 Units
.Table
(Units
.Last
) := (
128 Unit_File_Name
=> System_Fname
,
129 Unit_Name
=> System_Uname
,
130 Expected_Unit
=> System_Uname
,
131 Source_Index
=> System_Source_File_Index
,
133 Cunit_Entity
=> Empty
,
135 Dynamic_Elab
=> False,
136 Fatal_Error
=> False,
137 Generate_Code
=> False,
139 Is_Compiler_Unit
=> False,
140 Ident_String
=> Empty
,
146 Error_Location
=> No_Location
,
149 -- Parse system.ads so that the checksum is set right
150 -- Style checks are not applied.
153 Save_Mindex
: constant Nat
:= Multiple_Unit_Index
;
154 Save_Style
: constant Boolean := Style_Check
;
156 Multiple_Unit_Index
:= 0;
157 Style_Check
:= False;
158 Initialize_Scanner
(Units
.Last
, System_Source_File_Index
);
159 Discard_List
(Par
(Configuration_Pragmas
=> False));
160 Style_Check
:= Save_Style
;
161 Multiple_Unit_Index
:= Save_Mindex
;
163 end Ensure_System_Dependency
;
169 procedure Write_ALI
(Object
: Boolean) is
175 Last_Unit
: constant Unit_Number_Type
:= Units
.Last
;
176 -- Record unit number of last unit. We capture this in case we
177 -- have to add a dummy entry to the unit table for package System.
179 With_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
180 -- Array of flags to show which units are with'ed
182 Elab_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
183 -- Array of flags to show which units have pragma Elaborate set
185 Elab_All_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
186 -- Array of flags to show which units have pragma Elaborate All set
188 Elab_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
189 -- Array of flags to show which units have Elaborate_Desirable set
191 Elab_All_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
192 -- Array of flags to show which units have Elaborate_All_Desirable set
194 Sdep_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 2));
195 -- Sorted table of source dependencies. One extra entry in case we
196 -- have to add a dummy entry for System.
199 -- Number of active entries in Sdep_Table
201 flag_compare_debug
: Int
;
202 pragma Import
(C
, flag_compare_debug
);
203 -- Import from toplev.c
205 -----------------------
206 -- Local Subprograms --
207 -----------------------
209 procedure Collect_Withs
(Cunit
: Node_Id
);
210 -- Collect with lines for entries in the context clause of the
211 -- given compilation unit, Cunit.
213 procedure Update_Tables_From_ALI_File
;
214 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
215 -- function), update tables from the ALI information, including
216 -- specifically the Compilation_Switches table.
218 function Up_To_Date_ALI_File_Exists
return Boolean;
219 -- If there exists an ALI file that is up to date, then this function
220 -- initializes the tables in the ALI spec to contain information on
221 -- this file (using Scan_ALI) and returns True. If no file exists,
222 -- or the file is not up to date, then False is returned.
224 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
);
225 -- Write out the library information for one unit for which code is
226 -- generated (includes unit line and with lines).
228 procedure Write_With_Lines
;
229 -- Write out with lines collected by calls to Collect_Withs
235 procedure Collect_Withs
(Cunit
: Node_Id
) is
237 Unum
: Unit_Number_Type
;
240 Item
:= First
(Context_Items
(Cunit
));
241 while Present
(Item
) loop
243 -- Process with clause
245 -- Ada 2005 (AI-50217): limited with_clauses do not create
246 -- dependencies, but must be recorded as components of the
247 -- partition, in case there is no regular with_clause for
248 -- the unit anywhere else.
250 if Nkind
(Item
) = N_With_Clause
then
251 Unum
:= Get_Cunit_Unit_Number
(Library_Unit
(Item
));
252 With_Flags
(Unum
) := True;
254 if not Limited_Present
(Item
) then
255 if Elaborate_Present
(Item
) then
256 Elab_Flags
(Unum
) := True;
259 if Elaborate_All_Present
(Item
) then
260 Elab_All_Flags
(Unum
) := True;
263 if Elaborate_All_Desirable
(Item
) then
264 Elab_All_Des_Flags
(Unum
) := True;
267 if Elaborate_Desirable
(Item
) then
268 Elab_Des_Flags
(Unum
) := True;
272 Set_From_With_Type
(Cunit_Entity
(Unum
));
280 --------------------------------
281 -- Up_To_Date_ALI_File_Exists --
282 --------------------------------
284 function Up_To_Date_ALI_File_Exists
return Boolean is
285 Name
: File_Name_Type
;
286 Text
: Text_Buffer_Ptr
;
288 Sind
: Source_File_Index
;
291 Opt
.Check_Object_Consistency
:= True;
292 Read_Library_Info
(Name
, Text
);
294 -- Return if we could not find an ALI file
300 -- Return if ALI file has bad format
304 if Scan_ALI
(Name
, Text
, False, Err
=> True) = No_ALI_Id
then
308 -- If we have an OK ALI file, check if it is up to date
309 -- Note that we assume that the ALI read has all the entries
310 -- we have in our table, plus some additional ones (that can
311 -- come from expansion).
313 Id
:= First_Sdep_Entry
;
314 for J
in 1 .. Num_Sdep
loop
315 Sind
:= Units
.Table
(Sdep_Table
(J
)).Source_Index
;
317 while Sdep
.Table
(Id
).Sfile
/= File_Name
(Sind
) loop
318 if Id
= Sdep
.Last
then
325 if Sdep
.Table
(Id
).Stamp
/= Time_Stamp
(Sind
) then
331 end Up_To_Date_ALI_File_Exists
;
333 ---------------------------------
334 -- Update_Tables_From_ALI_File --
335 ---------------------------------
337 procedure Update_Tables_From_ALI_File
is
339 -- Build Compilation_Switches table
341 Compilation_Switches
.Init
;
343 for J
in First_Arg_Entry
.. Args
.Last
loop
344 Compilation_Switches
.Increment_Last
;
345 Compilation_Switches
.Table
(Compilation_Switches
.Last
) :=
348 end Update_Tables_From_ALI_File
;
350 ----------------------------
351 -- Write_Unit_Information --
352 ----------------------------
354 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
) is
355 Unode
: constant Node_Id
:= Cunit
(Unit_Num
);
356 Ukind
: constant Node_Kind
:= Nkind
(Unit
(Unode
));
357 Uent
: constant Entity_Id
:= Cunit_Entity
(Unit_Num
);
361 Write_Info_Initiate
('U');
362 Write_Info_Char
(' ');
363 Write_Info_Name
(Unit_Name
(Unit_Num
));
365 Write_Info_Name
(Unit_File_Name
(Unit_Num
));
368 Write_Info_Str
(Version_Get
(Unit_Num
));
370 -- Add BD parameter if Elaborate_Body pragma desirable
372 if Ekind
(Uent
) = E_Package
373 and then Elaborate_Body_Desirable
(Uent
)
375 Write_Info_Str
(" BD");
378 -- Add BN parameter if body needed for SAL
380 if (Is_Subprogram
(Uent
)
381 or else Ekind
(Uent
) = E_Package
382 or else Is_Generic_Unit
(Uent
))
383 and then Body_Needed_For_SAL
(Uent
)
385 Write_Info_Str
(" BN");
388 if Dynamic_Elab
(Unit_Num
) then
389 Write_Info_Str
(" DE");
392 -- Set the Elaborate_Body indication if either an explicit pragma
393 -- was present, or if this is an instantiation.
395 if Has_Pragma_Elaborate_Body
(Uent
)
396 or else (Ukind
= N_Package_Declaration
397 and then Is_Generic_Instance
(Uent
)
398 and then Present
(Corresponding_Body
(Unit
(Unode
))))
400 Write_Info_Str
(" EB");
403 -- Now see if we should tell the binder that an elaboration entity
404 -- is present, which must be set to true during elaboration.
405 -- We generate the indication if the following condition is met:
407 -- If this is a spec ...
409 if (Is_Subprogram
(Uent
)
411 Ekind
(Uent
) = E_Package
413 Is_Generic_Unit
(Uent
))
415 -- and an elaboration entity was declared ...
417 and then Present
(Elaboration_Entity
(Uent
))
419 -- and either the elaboration flag is required ...
422 (Elaboration_Entity_Required
(Uent
)
424 -- or this unit has elaboration code ...
426 or else not Has_No_Elaboration_Code
(Unode
)
428 -- or this unit has a separate body and this
429 -- body has elaboration code.
432 (Ekind
(Uent
) = E_Package
433 and then Present
(Body_Entity
(Uent
))
435 not Has_No_Elaboration_Code
438 (Body_Entity
(Uent
))))))
440 if Convention
(Uent
) = Convention_CIL
then
442 -- Special case for generic CIL packages which never have
445 Write_Info_Str
(" NE");
448 Write_Info_Str
(" EE");
452 if Has_No_Elaboration_Code
(Unode
) then
453 Write_Info_Str
(" NE");
456 Write_Info_Str
(" O");
457 Write_Info_Char
(OA_Setting
(Unit_Num
));
459 if Is_Preelaborated
(Uent
) then
460 Write_Info_Str
(" PR");
463 if Is_Pure
(Uent
) then
464 Write_Info_Str
(" PU");
467 if Has_RACW
(Unit_Num
) then
468 Write_Info_Str
(" RA");
471 if Is_Remote_Call_Interface
(Uent
) then
472 Write_Info_Str
(" RC");
475 if Is_Remote_Types
(Uent
) then
476 Write_Info_Str
(" RT");
479 if Is_Shared_Passive
(Uent
) then
480 Write_Info_Str
(" SP");
483 if Ukind
= N_Subprogram_Declaration
484 or else Ukind
= N_Subprogram_Body
486 Write_Info_Str
(" SU");
488 elsif Ukind
= N_Package_Declaration
490 Ukind
= N_Package_Body
492 -- If this is a wrapper package for a subprogram instantiation,
493 -- the user view is the subprogram. Note that in this case the
494 -- ali file contains both the spec and body of the instance.
496 if Is_Wrapper_Package
(Uent
) then
497 Write_Info_Str
(" SU");
499 Write_Info_Str
(" PK");
502 elsif Ukind
= N_Generic_Package_Declaration
then
503 Write_Info_Str
(" PK");
507 if Ukind
in N_Generic_Declaration
509 (Present
(Library_Unit
(Unode
))
511 Nkind
(Unit
(Library_Unit
(Unode
))) in N_Generic_Declaration
)
513 Write_Info_Str
(" GE");
516 if not Is_Internal_File_Name
(Unit_File_Name
(Unit_Num
), True) then
517 case Identifier_Casing
(Source_Index
(Unit_Num
)) is
518 when All_Lower_Case
=> Write_Info_Str
(" IL");
519 when All_Upper_Case
=> Write_Info_Str
(" IU");
523 case Keyword_Casing
(Source_Index
(Unit_Num
)) is
524 when Mixed_Case
=> Write_Info_Str
(" KM");
525 when All_Upper_Case
=> Write_Info_Str
(" KU");
530 if Initialize_Scalars
or else Invalid_Value_Used
then
531 Write_Info_Str
(" IS");
536 -- Generate with lines, first those that are directly with'ed
538 for J
in With_Flags
'Range loop
539 With_Flags
(J
) := False;
540 Elab_Flags
(J
) := False;
541 Elab_All_Flags
(J
) := False;
542 Elab_Des_Flags
(J
) := False;
543 Elab_All_Des_Flags
(J
) := False;
546 Collect_Withs
(Unode
);
548 -- For a body, we must also check for any subunits which belong to
549 -- it and which have context clauses of their own, since these
550 -- with'ed units are part of its own elaboration dependencies.
552 if Nkind
(Unit
(Unode
)) in N_Unit_Body
then
553 for S
in Units
.First
.. Last_Unit
loop
555 -- We are only interested in subunits.
556 -- For preproc. data and def. files, Cunit is Empty, so
557 -- we need to test that first.
559 if Cunit
(S
) /= Empty
560 and then Nkind
(Unit
(Cunit
(S
))) = N_Subunit
562 Pnode
:= Library_Unit
(Cunit
(S
));
564 -- In gnatc mode, the errors in the subunits will not
565 -- have been recorded, but the analysis of the subunit
566 -- may have failed. There is no information to add to
567 -- ALI file in this case.
573 -- Find ultimate parent of the subunit
575 while Nkind
(Unit
(Pnode
)) = N_Subunit
loop
576 Pnode
:= Library_Unit
(Pnode
);
579 -- See if it belongs to current unit, and if so, include
582 if Pnode
= Unode
then
583 Collect_Withs
(Cunit
(S
));
591 -- Output linker option lines
593 for J
in 1 .. Linker_Option_Lines
.Last
loop
595 S
: Linker_Option_Entry
renames Linker_Option_Lines
.Table
(J
);
597 if S
.Unit
= Unit_Num
then
598 Write_Info_Initiate
('L');
599 Write_Info_Char
(' ');
600 Write_Info_Slit
(S
.Option
);
608 for J
in 1 .. Notes
.Last
loop
610 N
: constant Node_Id
:= Notes
.Table
(J
).Pragma_Node
;
611 L
: constant Source_Ptr
:= Sloc
(N
);
612 U
: constant Unit_Number_Type
:= Notes
.Table
(J
).Unit
;
617 Write_Info_Initiate
('N');
618 Write_Info_Char
(' ');
620 case Chars
(Pragma_Identifier
(N
)) is
621 when Name_Annotate
=>
629 when Name_Subtitle
=>
636 Write_Info_Int
(Int
(Get_Logical_Line_Number
(L
)));
637 Write_Info_Char
(':');
638 Write_Info_Int
(Int
(Get_Column_Number
(L
)));
644 A
:= First
(Pragma_Argument_Associations
(N
));
645 while Present
(A
) loop
646 Write_Info_Char
(' ');
648 if Chars
(A
) /= No_Name
then
649 Write_Info_Name
(Chars
(A
));
650 Write_Info_Char
(':');
654 Expr
: constant Node_Id
:= Expression
(A
);
657 if Nkind
(Expr
) = N_Identifier
then
658 Write_Info_Name
(Chars
(Expr
));
660 elsif Nkind
(Expr
) = N_Integer_Literal
661 and then Is_Static_Expression
(Expr
)
663 Write_Info_Uint
(Intval
(Expr
));
665 elsif Nkind
(Expr
) = N_String_Literal
666 and then Is_Static_Expression
(Expr
)
668 Write_Info_Slit
(Strval
(Expr
));
671 Write_Info_Str
("<expr>");
683 end Write_Unit_Information
;
685 ----------------------
686 -- Write_With_Lines --
687 ----------------------
689 procedure Write_With_Lines
is
690 With_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 1));
691 Num_Withs
: Int
:= 0;
692 Unum
: Unit_Number_Type
;
694 Uname
: Unit_Name_Type
;
695 Fname
: File_Name_Type
;
696 Pname
: constant Unit_Name_Type
:=
697 Get_Parent_Spec_Name
(Unit_Name
(Main_Unit
));
698 Body_Fname
: File_Name_Type
;
701 procedure Write_With_File_Names
702 (Nam
: in out File_Name_Type
;
704 -- Write source file name Nam and ALI file name for unit index Idx.
705 -- Possibly change Nam to lowercase (generating a new file name).
707 --------------------------
708 -- Write_With_File_Name --
709 --------------------------
711 procedure Write_With_File_Names
712 (Nam
: in out File_Name_Type
;
716 if not File_Names_Case_Sensitive
then
717 Get_Name_String
(Nam
);
718 To_Lower
(Name_Buffer
(1 .. Name_Len
));
722 Write_Info_Name
(Nam
);
724 Write_Info_Name
(Lib_File_Name
(Nam
, Idx
));
725 end Write_With_File_Names
;
727 -- Start of processing for Write_With_Lines
730 -- Loop to build the with table. A with on the main unit itself
731 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
732 -- the main unit is a subprogram with no spec, and a subunit of
733 -- it unnecessarily withs the parent.
735 for J
in Units
.First
+ 1 .. Last_Unit
loop
737 -- Add element to with table if it is with'ed or if it is the
738 -- parent spec of the main unit (case of main unit is a child
739 -- unit). The latter with is not needed for semantic purposes,
740 -- but is required by the binder for elaboration purposes.
741 -- For preproc. data and def. files, there is no Unit_Name,
742 -- check for that first.
744 if Unit_Name
(J
) /= No_Unit_Name
745 and then (With_Flags
(J
) or else Unit_Name
(J
) = Pname
)
747 Num_Withs
:= Num_Withs
+ 1;
748 With_Table
(Num_Withs
) := J
;
752 -- Sort and output the table
754 Sort
(With_Table
(1 .. Num_Withs
));
756 for J
in 1 .. Num_Withs
loop
757 Unum
:= With_Table
(J
);
758 Cunit
:= Units
.Table
(Unum
).Cunit
;
759 Uname
:= Units
.Table
(Unum
).Unit_Name
;
760 Fname
:= Units
.Table
(Unum
).Unit_File_Name
;
762 if Ekind
(Cunit_Entity
(Unum
)) = E_Package
763 and then From_With_Type
(Cunit_Entity
(Unum
))
765 Write_Info_Initiate
('Y');
767 Write_Info_Initiate
('W');
770 Write_Info_Char
(' ');
771 Write_Info_Name
(Uname
);
773 -- Now we need to figure out the names of the files that contain
774 -- the with'ed unit. These will usually be the files for the body,
775 -- except in the case of a package that has no body. Note that we
776 -- have a specific exemption here for predefined library generics
777 -- (see comments for Generic_May_Lack_ALI). We do not generate
778 -- dependency upon the ALI file for such units. Older compilers
779 -- used to not support generating code (and ALI) for generics, and
780 -- we want to avoid having different processing (namely, different
781 -- lists of files to be compiled) for different stages of the
784 if not ((Nkind
(Unit
(Cunit
)) in N_Generic_Declaration
786 Nkind
(Unit
(Cunit
)) in N_Generic_Renaming_Declaration
)
787 and then Generic_May_Lack_ALI
(Fname
))
791 if Is_Spec_Name
(Uname
) then
794 (Get_Body_Name
(Uname
),
795 Subunit
=> False, May_Fail
=> True);
799 (Get_Body_Name
(Uname
));
801 if Body_Fname
= No_File
then
802 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
803 Body_Index
:= Get_Unit_Index
(Uname
);
807 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
808 Body_Index
:= Get_Unit_Index
(Uname
);
811 -- A package is considered to have a body if it requires
812 -- a body or if a body is present in Ada 83 mode.
814 if Body_Required
(Cunit
)
815 or else (Ada_Version
= Ada_83
816 and then Full_Source_Name
(Body_Fname
) /= No_File
)
818 Write_With_File_Names
(Body_Fname
, Body_Index
);
820 Write_With_File_Names
(Fname
, Munit_Index
(Unum
));
823 if Ekind
(Cunit_Entity
(Unum
)) = E_Package
824 and then From_With_Type
(Cunit_Entity
(Unum
))
828 if Elab_Flags
(Unum
) then
829 Write_Info_Str
(" E");
832 if Elab_All_Flags
(Unum
) then
833 Write_Info_Str
(" EA");
836 if Elab_Des_Flags
(Unum
) then
837 Write_Info_Str
(" ED");
840 if Elab_All_Des_Flags
(Unum
) then
841 Write_Info_Str
(" AD");
848 end Write_With_Lines
;
850 -- Start of processing for Write_ALI
853 -- We never write an ALI file if the original operating mode was
854 -- syntax-only (-gnats switch used in compiler invocation line)
856 if Original_Operating_Mode
= Check_Syntax
857 or flag_compare_debug
/= 0
862 -- Build sorted source dependency table. We do this right away,
863 -- because it is referenced by Up_To_Date_ALI_File_Exists.
865 for Unum
in Units
.First
.. Last_Unit
loop
866 if Cunit_Entity
(Unum
) = Empty
867 or else not From_With_Type
(Cunit_Entity
(Unum
))
869 Num_Sdep
:= Num_Sdep
+ 1;
870 Sdep_Table
(Num_Sdep
) := Unum
;
874 -- Sort the table so that the D lines are in order
876 Lib
.Sort
(Sdep_Table
(1 .. Num_Sdep
));
878 -- If we are not generating code, and there is an up to date
879 -- ali file accessible, read it, and acquire the compilation
880 -- arguments from this file.
882 if Operating_Mode
/= Generate_Code
then
883 if Up_To_Date_ALI_File_Exists
then
884 Update_Tables_From_ALI_File
;
889 -- Otherwise acquire compilation arguments and prepare to write
890 -- out a new ali file.
892 Create_Output_Library_Info
;
894 -- Output version line
896 Write_Info_Initiate
('V');
897 Write_Info_Str
(" """);
898 Write_Info_Str
(Verbose_Library_Version
);
899 Write_Info_Char
('"');
903 -- Output main program line if this is acceptable main program
905 Output_Main_Program_Line
: declare
906 U
: Node_Id
:= Unit
(Units
.Table
(Main_Unit
).Cunit
);
909 procedure M_Parameters
;
910 -- Output parameters for main program line
916 procedure M_Parameters
is
918 if Main_Priority
(Main_Unit
) /= Default_Main_Priority
then
919 Write_Info_Char
(' ');
920 Write_Info_Nat
(Main_Priority
(Main_Unit
));
923 if Opt
.Time_Slice_Set
then
924 Write_Info_Str
(" T=");
925 Write_Info_Nat
(Opt
.Time_Slice_Value
);
928 Write_Info_Str
(" W=");
930 (WC_Encoding_Letters
(Wide_Character_Encoding_Method
));
935 -- Start of processing for Output_Main_Program_Line
938 if Nkind
(U
) = N_Subprogram_Body
940 (Nkind
(U
) = N_Package_Body
942 Nkind
(Original_Node
(U
)) in N_Subprogram_Instantiation
)
944 -- If the unit is a subprogram instance, the entity for the
945 -- subprogram is the alias of the visible entity, which is the
946 -- related instance of the wrapper package. We retrieve the
947 -- subprogram declaration of the desired entity.
949 if Nkind
(U
) = N_Package_Body
then
950 U
:= Parent
(Parent
(
951 Alias
(Related_Instance
(Defining_Unit_Name
952 (Specification
(Unit
(Library_Unit
(Parent
(U
)))))))));
955 S
:= Specification
(U
);
957 if No
(Parameter_Specifications
(S
)) then
958 if Nkind
(S
) = N_Procedure_Specification
then
959 Write_Info_Initiate
('M');
960 Write_Info_Str
(" P");
965 Nam
: Node_Id
:= Defining_Unit_Name
(S
);
968 -- If it is a child unit, get its simple name
970 if Nkind
(Nam
) = N_Defining_Program_Unit_Name
then
971 Nam
:= Defining_Identifier
(Nam
);
974 if Is_Integer_Type
(Etype
(Nam
)) then
975 Write_Info_Initiate
('M');
976 Write_Info_Str
(" F");
983 end Output_Main_Program_Line
;
985 -- Write command argument ('A') lines
987 for A
in 1 .. Compilation_Switches
.Last
loop
988 Write_Info_Initiate
('A');
989 Write_Info_Char
(' ');
990 Write_Info_Str
(Compilation_Switches
.Table
(A
).all);
991 Write_Info_Terminate
;
994 -- Output parameters ('P') line
996 Write_Info_Initiate
('P');
998 if Compilation_Errors
then
999 Write_Info_Str
(" CE");
1002 if Opt
.Detect_Blocking
then
1003 Write_Info_Str
(" DB");
1006 if Opt
.Float_Format
/= ' ' then
1007 Write_Info_Str
(" F");
1009 if Opt
.Float_Format
= 'I' then
1010 Write_Info_Char
('I');
1012 elsif Opt
.Float_Format_Long
= 'D' then
1013 Write_Info_Char
('D');
1016 Write_Info_Char
('G');
1021 and then not Is_Predefined_File_Name
(Unit_File_Name
(Main_Unit
))
1023 if Locking_Policy
/= ' ' then
1024 Write_Info_Str
(" L");
1025 Write_Info_Char
(Locking_Policy
);
1028 if Queuing_Policy
/= ' ' then
1029 Write_Info_Str
(" Q");
1030 Write_Info_Char
(Queuing_Policy
);
1033 if Task_Dispatching_Policy
/= ' ' then
1034 Write_Info_Str
(" T");
1035 Write_Info_Char
(Task_Dispatching_Policy
);
1036 Write_Info_Char
(' ');
1041 Write_Info_Str
(" NO");
1044 if No_Run_Time_Mode
then
1045 Write_Info_Str
(" NR");
1048 if Normalize_Scalars
then
1049 Write_Info_Str
(" NS");
1052 if Sec_Stack_Used
then
1053 Write_Info_Str
(" SS");
1056 if Unreserve_All_Interrupts
then
1057 Write_Info_Str
(" UA");
1060 if Exception_Mechanism
= Back_End_Exceptions
then
1061 Write_Info_Str
(" ZX");
1066 -- Before outputting the restrictions line, update the setting of
1067 -- the No_Elaboration_Code flag. Violations of this restriction
1068 -- cannot be detected until after the backend has been called since
1069 -- it is the backend that sets this flag. We have to check all units
1070 -- for which we have generated code
1072 for Unit
in Units
.First
.. Last_Unit
loop
1073 if Units
.Table
(Unit
).Generate_Code
1074 or else Unit
= Main_Unit
1076 if not Has_No_Elaboration_Code
(Cunit
(Unit
)) then
1077 Main_Restrictions
.Violated
(No_Elaboration_Code
) := True;
1082 -- Output first restrictions line
1084 Write_Info_Initiate
('R');
1085 Write_Info_Char
(' ');
1087 -- First the information for the boolean restrictions
1089 for R
in All_Boolean_Restrictions
loop
1090 if Main_Restrictions
.Set
(R
)
1091 and then not Restriction_Warnings
(R
)
1093 Write_Info_Char
('r');
1094 elsif Main_Restrictions
.Violated
(R
) then
1095 Write_Info_Char
('v');
1097 Write_Info_Char
('n');
1101 -- And now the information for the parameter restrictions
1103 for RP
in All_Parameter_Restrictions
loop
1104 if Main_Restrictions
.Set
(RP
)
1105 and then not Restriction_Warnings
(RP
)
1107 Write_Info_Char
('r');
1108 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1110 Write_Info_Char
('n');
1113 if not Main_Restrictions
.Violated
(RP
)
1114 or else RP
not in Checked_Parameter_Restrictions
1116 Write_Info_Char
('n');
1118 Write_Info_Char
('v');
1119 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1121 if Main_Restrictions
.Unknown
(RP
) then
1122 Write_Info_Char
('+');
1129 -- Output R lines for No_Dependence entries
1131 for J
in No_Dependence
.First
.. No_Dependence
.Last
loop
1132 if In_Extended_Main_Source_Unit
(No_Dependence
.Table
(J
).Unit
)
1133 and then not No_Dependence
.Table
(J
).Warn
1135 Write_Info_Initiate
('R');
1136 Write_Info_Char
(' ');
1137 Write_Unit_Name
(No_Dependence
.Table
(J
).Unit
);
1142 -- Output interrupt state lines
1144 for J
in Interrupt_States
.First
.. Interrupt_States
.Last
loop
1145 Write_Info_Initiate
('I');
1146 Write_Info_Char
(' ');
1147 Write_Info_Nat
(Interrupt_States
.Table
(J
).Interrupt_Number
);
1148 Write_Info_Char
(' ');
1149 Write_Info_Char
(Interrupt_States
.Table
(J
).Interrupt_State
);
1150 Write_Info_Char
(' ');
1152 (Nat
(Get_Logical_Line_Number
1153 (Interrupt_States
.Table
(J
).Pragma_Loc
)));
1157 -- Output priority specific dispatching lines
1159 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
1160 Write_Info_Initiate
('S');
1161 Write_Info_Char
(' ');
1162 Write_Info_Char
(Specific_Dispatching
.Table
(J
).Dispatching_Policy
);
1163 Write_Info_Char
(' ');
1164 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).First_Priority
);
1165 Write_Info_Char
(' ');
1166 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).Last_Priority
);
1167 Write_Info_Char
(' ');
1169 (Nat
(Get_Logical_Line_Number
1170 (Specific_Dispatching
.Table
(J
).Pragma_Loc
)));
1174 -- Loop through file table to output information for all units for which
1175 -- we have generated code, as marked by the Generate_Code flag.
1177 for Unit
in Units
.First
.. Last_Unit
loop
1178 if Units
.Table
(Unit
).Generate_Code
1179 or else Unit
= Main_Unit
1181 Write_Info_EOL
; -- blank line
1182 Write_Unit_Information
(Unit
);
1186 Write_Info_EOL
; -- blank line
1188 -- Output external version reference lines
1190 for J
in 1 .. Version_Ref
.Last
loop
1191 Write_Info_Initiate
('E');
1192 Write_Info_Char
(' ');
1194 for K
in 1 .. String_Length
(Version_Ref
.Table
(J
)) loop
1195 Write_Info_Char_Code
(Get_String_Char
(Version_Ref
.Table
(J
), K
));
1201 -- Prepare to output the source dependency lines
1204 Unum
: Unit_Number_Type
;
1205 -- Number of unit being output
1207 Sind
: Source_File_Index
;
1208 -- Index of corresponding source file
1210 Fname
: File_Name_Type
;
1213 for J
in 1 .. Num_Sdep
loop
1214 Unum
:= Sdep_Table
(J
);
1215 Units
.Table
(Unum
).Dependency_Num
:= J
;
1216 Sind
:= Units
.Table
(Unum
).Source_Index
;
1218 Write_Info_Initiate
('D');
1219 Write_Info_Char
(' ');
1221 -- Normal case of a unit entry with a source index
1223 if Sind
/= No_Source_File
then
1224 Fname
:= File_Name
(Sind
);
1226 -- Ensure that on platforms where the file names are not
1227 -- case sensitive, the recorded file name is in lower case.
1229 if not File_Names_Case_Sensitive
then
1230 Get_Name_String
(Fname
);
1231 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1235 Write_Info_Name
(Fname
);
1236 Write_Info_Tab
(25);
1237 Write_Info_Str
(String (Time_Stamp
(Sind
)));
1238 Write_Info_Char
(' ');
1239 Write_Info_Str
(Get_Hex_String
(Source_Checksum
(Sind
)));
1241 -- If subunit, add unit name, omitting the %b at the end
1243 if Present
(Cunit
(Unum
))
1244 and then Nkind
(Unit
(Cunit
(Unum
))) = N_Subunit
1246 Get_Decoded_Name_String
(Unit_Name
(Unum
));
1247 Write_Info_Char
(' ');
1248 Write_Info_Str
(Name_Buffer
(1 .. Name_Len
- 2));
1251 -- If Source_Reference pragma used output information
1253 if Num_SRef_Pragmas
(Sind
) > 0 then
1254 Write_Info_Char
(' ');
1256 if Num_SRef_Pragmas
(Sind
) = 1 then
1257 Write_Info_Nat
(Int
(First_Mapped_Line
(Sind
)));
1262 Write_Info_Char
(':');
1263 Write_Info_Name
(Reference_Name
(Sind
));
1266 -- Case where there is no source index (happens for missing
1267 -- files). In this case we write a dummy time stamp.
1270 Write_Info_Name
(Unit_File_Name
(Unum
));
1271 Write_Info_Tab
(25);
1272 Write_Info_Str
(String (Dummy_Time_Stamp
));
1273 Write_Info_Char
(' ');
1274 Write_Info_Str
(Get_Hex_String
(0));
1281 -- Output cross-references
1285 -- Output SCO information if present
1287 if Generate_SCO
then
1291 -- Output final blank line and we are done. This final blank line is
1292 -- probably junk, but we don't feel like making an incompatible change!
1294 Write_Info_Terminate
;
1295 Close_Output_Library_Info
;
1298 ---------------------
1299 -- Write_Unit_Name --
1300 ---------------------
1302 procedure Write_Unit_Name
(N
: Node_Id
) is
1304 if Nkind
(N
) = N_Identifier
then
1305 Write_Info_Name
(Chars
(N
));
1308 pragma Assert
(Nkind
(N
) = N_Selected_Component
);
1309 Write_Unit_Name
(Prefix
(N
));
1310 Write_Info_Char
('.');
1311 Write_Unit_Name
(Selector_Name
(N
));
1313 end Write_Unit_Name
;