1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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,
83 Has_Allocator
=> False,
85 Is_Compiler_Unit
=> False,
86 Ident_String
=> Empty
,
93 Error_Location
=> No_Location
,
95 end Add_Preprocessing_Dependency
;
97 ------------------------------
98 -- Ensure_System_Dependency --
99 ------------------------------
101 procedure Ensure_System_Dependency
is
102 System_Uname
: Unit_Name_Type
;
103 -- Unit name for system spec if needed for dummy entry
105 System_Fname
: File_Name_Type
;
106 -- File name for system spec if needed for dummy entry
109 -- Nothing to do if we already compiled System
111 for Unum
in Units
.First
.. Last_Unit
loop
112 if Units
.Table
(Unum
).Source_Index
= System_Source_File_Index
then
117 -- If no entry for system.ads in the units table, then add a entry
118 -- to the units table for system.ads, which will be referenced when
119 -- the ali file is generated. We need this because every unit depends
120 -- on system as a result of Targparm scanning the system.ads file to
121 -- determine the target dependent parameters for the compilation.
124 Name_Buffer
(1 .. 6) := "system";
125 System_Uname
:= Name_To_Unit_Name
(Name_Enter
);
126 System_Fname
:= File_Name
(System_Source_File_Index
);
128 Units
.Increment_Last
;
129 Units
.Table
(Units
.Last
) := (
130 Unit_File_Name
=> System_Fname
,
131 Unit_Name
=> System_Uname
,
132 Expected_Unit
=> System_Uname
,
133 Source_Index
=> System_Source_File_Index
,
135 Cunit_Entity
=> Empty
,
137 Dynamic_Elab
=> False,
138 Fatal_Error
=> False,
139 Generate_Code
=> False,
140 Has_Allocator
=> False,
142 Is_Compiler_Unit
=> False,
143 Ident_String
=> Empty
,
150 Error_Location
=> No_Location
,
153 -- Parse system.ads so that the checksum is set right
154 -- Style checks are not applied.
157 Save_Mindex
: constant Nat
:= Multiple_Unit_Index
;
158 Save_Style
: constant Boolean := Style_Check
;
160 Multiple_Unit_Index
:= 0;
161 Style_Check
:= False;
162 Initialize_Scanner
(Units
.Last
, System_Source_File_Index
);
163 Discard_List
(Par
(Configuration_Pragmas
=> False));
164 Style_Check
:= Save_Style
;
165 Multiple_Unit_Index
:= Save_Mindex
;
167 end Ensure_System_Dependency
;
173 procedure Write_ALI
(Object
: Boolean) is
179 Last_Unit
: constant Unit_Number_Type
:= Units
.Last
;
180 -- Record unit number of last unit. We capture this in case we
181 -- have to add a dummy entry to the unit table for package System.
183 With_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
184 -- Array of flags to show which units are with'ed
186 Elab_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
187 -- Array of flags to show which units have pragma Elaborate set
189 Elab_All_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
190 -- Array of flags to show which units have pragma Elaborate All set
192 Elab_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
193 -- Array of flags to show which units have Elaborate_Desirable set
195 Elab_All_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
196 -- Array of flags to show which units have Elaborate_All_Desirable set
198 Sdep_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 2));
199 -- Sorted table of source dependencies. One extra entry in case we
200 -- have to add a dummy entry for System.
203 -- Number of active entries in Sdep_Table
205 flag_compare_debug
: Int
;
206 pragma Import
(C
, flag_compare_debug
);
207 -- Import from toplev.c
209 -----------------------
210 -- Local Subprograms --
211 -----------------------
213 procedure Collect_Withs
(Cunit
: Node_Id
);
214 -- Collect with lines for entries in the context clause of the
215 -- given compilation unit, Cunit.
217 procedure Update_Tables_From_ALI_File
;
218 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
219 -- function), update tables from the ALI information, including
220 -- specifically the Compilation_Switches table.
222 function Up_To_Date_ALI_File_Exists
return Boolean;
223 -- If there exists an ALI file that is up to date, then this function
224 -- initializes the tables in the ALI spec to contain information on
225 -- this file (using Scan_ALI) and returns True. If no file exists,
226 -- or the file is not up to date, then False is returned.
228 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
);
229 -- Write out the library information for one unit for which code is
230 -- generated (includes unit line and with lines).
232 procedure Write_With_Lines
;
233 -- Write out with lines collected by calls to Collect_Withs
239 procedure Collect_Withs
(Cunit
: Node_Id
) is
241 Unum
: Unit_Number_Type
;
244 Item
:= First
(Context_Items
(Cunit
));
245 while Present
(Item
) loop
247 -- Process with clause
249 -- Ada 2005 (AI-50217): limited with_clauses do not create
250 -- dependencies, but must be recorded as components of the
251 -- partition, in case there is no regular with_clause for
252 -- the unit anywhere else.
254 if Nkind
(Item
) = N_With_Clause
then
255 Unum
:= Get_Cunit_Unit_Number
(Library_Unit
(Item
));
256 With_Flags
(Unum
) := True;
258 if not Limited_Present
(Item
) then
259 if Elaborate_Present
(Item
) then
260 Elab_Flags
(Unum
) := True;
263 if Elaborate_All_Present
(Item
) then
264 Elab_All_Flags
(Unum
) := True;
267 if Elaborate_All_Desirable
(Item
) then
268 Elab_All_Des_Flags
(Unum
) := True;
271 if Elaborate_Desirable
(Item
) then
272 Elab_Des_Flags
(Unum
) := True;
276 Set_From_With_Type
(Cunit_Entity
(Unum
));
284 --------------------------------
285 -- Up_To_Date_ALI_File_Exists --
286 --------------------------------
288 function Up_To_Date_ALI_File_Exists
return Boolean is
289 Name
: File_Name_Type
;
290 Text
: Text_Buffer_Ptr
;
292 Sind
: Source_File_Index
;
295 Opt
.Check_Object_Consistency
:= True;
296 Read_Library_Info
(Name
, Text
);
298 -- Return if we could not find an ALI file
304 -- Return if ALI file has bad format
308 if Scan_ALI
(Name
, Text
, False, Err
=> True) = No_ALI_Id
then
312 -- If we have an OK ALI file, check if it is up to date
313 -- Note that we assume that the ALI read has all the entries
314 -- we have in our table, plus some additional ones (that can
315 -- come from expansion).
317 Id
:= First_Sdep_Entry
;
318 for J
in 1 .. Num_Sdep
loop
319 Sind
:= Units
.Table
(Sdep_Table
(J
)).Source_Index
;
321 while Sdep
.Table
(Id
).Sfile
/= File_Name
(Sind
) loop
322 if Id
= Sdep
.Last
then
329 if Sdep
.Table
(Id
).Stamp
/= Time_Stamp
(Sind
) then
335 end Up_To_Date_ALI_File_Exists
;
337 ---------------------------------
338 -- Update_Tables_From_ALI_File --
339 ---------------------------------
341 procedure Update_Tables_From_ALI_File
is
343 -- Build Compilation_Switches table
345 Compilation_Switches
.Init
;
347 for J
in First_Arg_Entry
.. Args
.Last
loop
348 Compilation_Switches
.Increment_Last
;
349 Compilation_Switches
.Table
(Compilation_Switches
.Last
) :=
352 end Update_Tables_From_ALI_File
;
354 ----------------------------
355 -- Write_Unit_Information --
356 ----------------------------
358 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
) is
359 Unode
: constant Node_Id
:= Cunit
(Unit_Num
);
360 Ukind
: constant Node_Kind
:= Nkind
(Unit
(Unode
));
361 Uent
: constant Entity_Id
:= Cunit_Entity
(Unit_Num
);
365 Write_Info_Initiate
('U');
366 Write_Info_Char
(' ');
367 Write_Info_Name
(Unit_Name
(Unit_Num
));
369 Write_Info_Name
(Unit_File_Name
(Unit_Num
));
372 Write_Info_Str
(Version_Get
(Unit_Num
));
374 -- Add BD parameter if Elaborate_Body pragma desirable
376 if Ekind
(Uent
) = E_Package
377 and then Elaborate_Body_Desirable
(Uent
)
379 Write_Info_Str
(" BD");
382 -- Add BN parameter if body needed for SAL
384 if (Is_Subprogram
(Uent
)
385 or else Ekind
(Uent
) = E_Package
386 or else Is_Generic_Unit
(Uent
))
387 and then Body_Needed_For_SAL
(Uent
)
389 Write_Info_Str
(" BN");
392 if Dynamic_Elab
(Unit_Num
) then
393 Write_Info_Str
(" DE");
396 -- Set the Elaborate_Body indication if either an explicit pragma
397 -- was present, or if this is an instantiation.
399 if Has_Pragma_Elaborate_Body
(Uent
)
400 or else (Ukind
= N_Package_Declaration
401 and then Is_Generic_Instance
(Uent
)
402 and then Present
(Corresponding_Body
(Unit
(Unode
))))
404 Write_Info_Str
(" EB");
407 -- Now see if we should tell the binder that an elaboration entity
408 -- is present, which must be set to true during elaboration.
409 -- We generate the indication if the following condition is met:
411 -- If this is a spec ...
413 if (Is_Subprogram
(Uent
)
415 Ekind
(Uent
) = E_Package
417 Is_Generic_Unit
(Uent
))
419 -- and an elaboration entity was declared ...
421 and then Present
(Elaboration_Entity
(Uent
))
423 -- and either the elaboration flag is required ...
426 (Elaboration_Entity_Required
(Uent
)
428 -- or this unit has elaboration code ...
430 or else not Has_No_Elaboration_Code
(Unode
)
432 -- or this unit has a separate body and this
433 -- body has elaboration code.
436 (Ekind
(Uent
) = E_Package
437 and then Present
(Body_Entity
(Uent
))
439 not Has_No_Elaboration_Code
442 (Body_Entity
(Uent
))))))
444 if Convention
(Uent
) = Convention_CIL
then
446 -- Special case for generic CIL packages which never have
449 Write_Info_Str
(" NE");
452 Write_Info_Str
(" EE");
456 if Has_No_Elaboration_Code
(Unode
) then
457 Write_Info_Str
(" NE");
460 Write_Info_Str
(" O");
461 Write_Info_Char
(OA_Setting
(Unit_Num
));
463 if Is_Preelaborated
(Uent
) then
464 Write_Info_Str
(" PR");
467 if Is_Pure
(Uent
) then
468 Write_Info_Str
(" PU");
471 if Has_RACW
(Unit_Num
) then
472 Write_Info_Str
(" RA");
475 if Is_Remote_Call_Interface
(Uent
) then
476 Write_Info_Str
(" RC");
479 if Is_Remote_Types
(Uent
) then
480 Write_Info_Str
(" RT");
483 if Is_Shared_Passive
(Uent
) then
484 Write_Info_Str
(" SP");
487 if Ukind
= N_Subprogram_Declaration
488 or else Ukind
= N_Subprogram_Body
490 Write_Info_Str
(" SU");
492 elsif Ukind
= N_Package_Declaration
494 Ukind
= N_Package_Body
496 -- If this is a wrapper package for a subprogram instantiation,
497 -- the user view is the subprogram. Note that in this case the
498 -- ali file contains both the spec and body of the instance.
500 if Is_Wrapper_Package
(Uent
) then
501 Write_Info_Str
(" SU");
503 Write_Info_Str
(" PK");
506 elsif Ukind
= N_Generic_Package_Declaration
then
507 Write_Info_Str
(" PK");
511 if Ukind
in N_Generic_Declaration
513 (Present
(Library_Unit
(Unode
))
515 Nkind
(Unit
(Library_Unit
(Unode
))) in N_Generic_Declaration
)
517 Write_Info_Str
(" GE");
520 if not Is_Internal_File_Name
(Unit_File_Name
(Unit_Num
), True) then
521 case Identifier_Casing
(Source_Index
(Unit_Num
)) is
522 when All_Lower_Case
=> Write_Info_Str
(" IL");
523 when All_Upper_Case
=> Write_Info_Str
(" IU");
527 case Keyword_Casing
(Source_Index
(Unit_Num
)) is
528 when Mixed_Case
=> Write_Info_Str
(" KM");
529 when All_Upper_Case
=> Write_Info_Str
(" KU");
534 if Initialize_Scalars
or else Invalid_Value_Used
then
535 Write_Info_Str
(" IS");
540 -- Generate with lines, first those that are directly with'ed
542 for J
in With_Flags
'Range loop
543 With_Flags
(J
) := False;
544 Elab_Flags
(J
) := False;
545 Elab_All_Flags
(J
) := False;
546 Elab_Des_Flags
(J
) := False;
547 Elab_All_Des_Flags
(J
) := False;
550 Collect_Withs
(Unode
);
552 -- For a body, we must also check for any subunits which belong to
553 -- it and which have context clauses of their own, since these
554 -- with'ed units are part of its own elaboration dependencies.
556 if Nkind
(Unit
(Unode
)) in N_Unit_Body
then
557 for S
in Units
.First
.. Last_Unit
loop
559 -- We are only interested in subunits.
560 -- For preproc. data and def. files, Cunit is Empty, so
561 -- we need to test that first.
563 if Cunit
(S
) /= Empty
564 and then Nkind
(Unit
(Cunit
(S
))) = N_Subunit
566 Pnode
:= Library_Unit
(Cunit
(S
));
568 -- In gnatc mode, the errors in the subunits will not
569 -- have been recorded, but the analysis of the subunit
570 -- may have failed. There is no information to add to
571 -- ALI file in this case.
577 -- Find ultimate parent of the subunit
579 while Nkind
(Unit
(Pnode
)) = N_Subunit
loop
580 Pnode
:= Library_Unit
(Pnode
);
583 -- See if it belongs to current unit, and if so, include
586 if Pnode
= Unode
then
587 Collect_Withs
(Cunit
(S
));
595 -- Output linker option lines
597 for J
in 1 .. Linker_Option_Lines
.Last
loop
599 S
: Linker_Option_Entry
renames Linker_Option_Lines
.Table
(J
);
601 if S
.Unit
= Unit_Num
then
602 Write_Info_Initiate
('L');
603 Write_Info_Char
(' ');
604 Write_Info_Slit
(S
.Option
);
612 for J
in 1 .. Notes
.Last
loop
614 N
: constant Node_Id
:= Notes
.Table
(J
).Pragma_Node
;
615 L
: constant Source_Ptr
:= Sloc
(N
);
616 U
: constant Unit_Number_Type
:= Notes
.Table
(J
).Unit
;
621 Write_Info_Initiate
('N');
622 Write_Info_Char
(' ');
624 case Chars
(Pragma_Identifier
(N
)) is
625 when Name_Annotate
=>
633 when Name_Subtitle
=>
640 Write_Info_Int
(Int
(Get_Logical_Line_Number
(L
)));
641 Write_Info_Char
(':');
642 Write_Info_Int
(Int
(Get_Column_Number
(L
)));
648 A
:= First
(Pragma_Argument_Associations
(N
));
649 while Present
(A
) loop
650 Write_Info_Char
(' ');
652 if Chars
(A
) /= No_Name
then
653 Write_Info_Name
(Chars
(A
));
654 Write_Info_Char
(':');
658 Expr
: constant Node_Id
:= Expression
(A
);
661 if Nkind
(Expr
) = N_Identifier
then
662 Write_Info_Name
(Chars
(Expr
));
664 elsif Nkind
(Expr
) = N_Integer_Literal
665 and then Is_Static_Expression
(Expr
)
667 Write_Info_Uint
(Intval
(Expr
));
669 elsif Nkind
(Expr
) = N_String_Literal
670 and then Is_Static_Expression
(Expr
)
672 Write_Info_Slit
(Strval
(Expr
));
675 Write_Info_Str
("<expr>");
687 end Write_Unit_Information
;
689 ----------------------
690 -- Write_With_Lines --
691 ----------------------
693 procedure Write_With_Lines
is
694 With_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 1));
695 Num_Withs
: Int
:= 0;
696 Unum
: Unit_Number_Type
;
698 Uname
: Unit_Name_Type
;
699 Fname
: File_Name_Type
;
700 Pname
: constant Unit_Name_Type
:=
701 Get_Parent_Spec_Name
(Unit_Name
(Main_Unit
));
702 Body_Fname
: File_Name_Type
;
705 procedure Write_With_File_Names
706 (Nam
: in out File_Name_Type
;
708 -- Write source file name Nam and ALI file name for unit index Idx.
709 -- Possibly change Nam to lowercase (generating a new file name).
711 --------------------------
712 -- Write_With_File_Name --
713 --------------------------
715 procedure Write_With_File_Names
716 (Nam
: in out File_Name_Type
;
720 if not File_Names_Case_Sensitive
then
721 Get_Name_String
(Nam
);
722 To_Lower
(Name_Buffer
(1 .. Name_Len
));
726 Write_Info_Name
(Nam
);
728 Write_Info_Name
(Lib_File_Name
(Nam
, Idx
));
729 end Write_With_File_Names
;
731 -- Start of processing for Write_With_Lines
734 -- Loop to build the with table. A with on the main unit itself
735 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
736 -- the main unit is a subprogram with no spec, and a subunit of
737 -- it unnecessarily withs the parent.
739 for J
in Units
.First
+ 1 .. Last_Unit
loop
741 -- Add element to with table if it is with'ed or if it is the
742 -- parent spec of the main unit (case of main unit is a child
743 -- unit). The latter with is not needed for semantic purposes,
744 -- but is required by the binder for elaboration purposes.
745 -- For preproc. data and def. files, there is no Unit_Name,
746 -- check for that first.
748 if Unit_Name
(J
) /= No_Unit_Name
749 and then (With_Flags
(J
) or else Unit_Name
(J
) = Pname
)
751 Num_Withs
:= Num_Withs
+ 1;
752 With_Table
(Num_Withs
) := J
;
756 -- Sort and output the table
758 Sort
(With_Table
(1 .. Num_Withs
));
760 for J
in 1 .. Num_Withs
loop
761 Unum
:= With_Table
(J
);
762 Cunit
:= Units
.Table
(Unum
).Cunit
;
763 Uname
:= Units
.Table
(Unum
).Unit_Name
;
764 Fname
:= Units
.Table
(Unum
).Unit_File_Name
;
766 if Ekind
(Cunit_Entity
(Unum
)) = E_Package
767 and then From_With_Type
(Cunit_Entity
(Unum
))
769 Write_Info_Initiate
('Y');
771 Write_Info_Initiate
('W');
774 Write_Info_Char
(' ');
775 Write_Info_Name
(Uname
);
777 -- Now we need to figure out the names of the files that contain
778 -- the with'ed unit. These will usually be the files for the body,
779 -- except in the case of a package that has no body. Note that we
780 -- have a specific exemption here for predefined library generics
781 -- (see comments for Generic_May_Lack_ALI). We do not generate
782 -- dependency upon the ALI file for such units. Older compilers
783 -- used to not support generating code (and ALI) for generics, and
784 -- we want to avoid having different processing (namely, different
785 -- lists of files to be compiled) for different stages of the
788 if not ((Nkind
(Unit
(Cunit
)) in N_Generic_Declaration
790 Nkind
(Unit
(Cunit
)) in N_Generic_Renaming_Declaration
)
791 and then Generic_May_Lack_ALI
(Fname
))
795 if Is_Spec_Name
(Uname
) then
798 (Get_Body_Name
(Uname
),
799 Subunit
=> False, May_Fail
=> True);
803 (Get_Body_Name
(Uname
));
805 if Body_Fname
= No_File
then
806 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
807 Body_Index
:= Get_Unit_Index
(Uname
);
811 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
812 Body_Index
:= Get_Unit_Index
(Uname
);
815 -- A package is considered to have a body if it requires
816 -- a body or if a body is present in Ada 83 mode.
818 if Body_Required
(Cunit
)
819 or else (Ada_Version
= Ada_83
820 and then Full_Source_Name
(Body_Fname
) /= No_File
)
822 Write_With_File_Names
(Body_Fname
, Body_Index
);
824 Write_With_File_Names
(Fname
, Munit_Index
(Unum
));
827 if Ekind
(Cunit_Entity
(Unum
)) = E_Package
828 and then From_With_Type
(Cunit_Entity
(Unum
))
832 if Elab_Flags
(Unum
) then
833 Write_Info_Str
(" E");
836 if Elab_All_Flags
(Unum
) then
837 Write_Info_Str
(" EA");
840 if Elab_Des_Flags
(Unum
) then
841 Write_Info_Str
(" ED");
844 if Elab_All_Des_Flags
(Unum
) then
845 Write_Info_Str
(" AD");
852 end Write_With_Lines
;
854 -- Start of processing for Write_ALI
857 -- We never write an ALI file if the original operating mode was
858 -- syntax-only (-gnats switch used in compiler invocation line)
860 if Original_Operating_Mode
= Check_Syntax
861 or flag_compare_debug
/= 0
866 -- Build sorted source dependency table. We do this right away, because
867 -- it is referenced by Up_To_Date_ALI_File_Exists.
869 for Unum
in Units
.First
.. Last_Unit
loop
870 if Cunit_Entity
(Unum
) = Empty
871 or else not From_With_Type
(Cunit_Entity
(Unum
))
873 Num_Sdep
:= Num_Sdep
+ 1;
874 Sdep_Table
(Num_Sdep
) := Unum
;
878 -- Sort the table so that the D lines are in order
880 Lib
.Sort
(Sdep_Table
(1 .. Num_Sdep
));
882 -- If we are not generating code, and there is an up to date ALI file
883 -- file accessible, read it, and acquire the compilation arguments from
886 if Operating_Mode
/= Generate_Code
then
887 if Up_To_Date_ALI_File_Exists
then
888 Update_Tables_From_ALI_File
;
893 -- Otherwise acquire compilation arguments and prepare to write
894 -- out a new ali file.
896 Create_Output_Library_Info
;
898 -- Output version line
900 Write_Info_Initiate
('V');
901 Write_Info_Str
(" """);
902 Write_Info_Str
(Verbose_Library_Version
);
903 Write_Info_Char
('"');
907 -- Output main program line if this is acceptable main program
909 Output_Main_Program_Line
: declare
910 U
: Node_Id
:= Unit
(Units
.Table
(Main_Unit
).Cunit
);
913 procedure M_Parameters
;
914 -- Output parameters for main program line
920 procedure M_Parameters
is
922 if Main_Priority
(Main_Unit
) /= Default_Main_Priority
then
923 Write_Info_Char
(' ');
924 Write_Info_Nat
(Main_Priority
(Main_Unit
));
927 if Opt
.Time_Slice_Set
then
928 Write_Info_Str
(" T=");
929 Write_Info_Nat
(Opt
.Time_Slice_Value
);
932 if Has_Allocator
(Main_Unit
) then
933 Write_Info_Str
(" AB");
936 if Main_CPU
(Main_Unit
) /= Default_Main_CPU
then
937 Write_Info_Str
(" C=");
938 Write_Info_Nat
(Main_CPU
(Main_Unit
));
941 Write_Info_Str
(" W=");
943 (WC_Encoding_Letters
(Wide_Character_Encoding_Method
));
948 -- Start of processing for Output_Main_Program_Line
951 if Nkind
(U
) = N_Subprogram_Body
953 (Nkind
(U
) = N_Package_Body
955 Nkind
(Original_Node
(U
)) in N_Subprogram_Instantiation
)
957 -- If the unit is a subprogram instance, the entity for the
958 -- subprogram is the alias of the visible entity, which is the
959 -- related instance of the wrapper package. We retrieve the
960 -- subprogram declaration of the desired entity.
962 if Nkind
(U
) = N_Package_Body
then
963 U
:= Parent
(Parent
(
964 Alias
(Related_Instance
(Defining_Unit_Name
965 (Specification
(Unit
(Library_Unit
(Parent
(U
)))))))));
968 S
:= Specification
(U
);
970 if No
(Parameter_Specifications
(S
)) then
971 if Nkind
(S
) = N_Procedure_Specification
then
972 Write_Info_Initiate
('M');
973 Write_Info_Str
(" P");
978 Nam
: Node_Id
:= Defining_Unit_Name
(S
);
981 -- If it is a child unit, get its simple name
983 if Nkind
(Nam
) = N_Defining_Program_Unit_Name
then
984 Nam
:= Defining_Identifier
(Nam
);
987 if Is_Integer_Type
(Etype
(Nam
)) then
988 Write_Info_Initiate
('M');
989 Write_Info_Str
(" F");
996 end Output_Main_Program_Line
;
998 -- Write command argument ('A') lines
1000 for A
in 1 .. Compilation_Switches
.Last
loop
1001 Write_Info_Initiate
('A');
1002 Write_Info_Char
(' ');
1003 Write_Info_Str
(Compilation_Switches
.Table
(A
).all);
1004 Write_Info_Terminate
;
1007 -- Output parameters ('P') line
1009 Write_Info_Initiate
('P');
1011 if Compilation_Errors
then
1012 Write_Info_Str
(" CE");
1015 if Opt
.Detect_Blocking
then
1016 Write_Info_Str
(" DB");
1019 if Opt
.Float_Format
/= ' ' then
1020 Write_Info_Str
(" F");
1022 if Opt
.Float_Format
= 'I' then
1023 Write_Info_Char
('I');
1025 elsif Opt
.Float_Format_Long
= 'D' then
1026 Write_Info_Char
('D');
1029 Write_Info_Char
('G');
1034 and then not Is_Predefined_File_Name
(Unit_File_Name
(Main_Unit
))
1036 if Locking_Policy
/= ' ' then
1037 Write_Info_Str
(" L");
1038 Write_Info_Char
(Locking_Policy
);
1041 if Queuing_Policy
/= ' ' then
1042 Write_Info_Str
(" Q");
1043 Write_Info_Char
(Queuing_Policy
);
1046 if Task_Dispatching_Policy
/= ' ' then
1047 Write_Info_Str
(" T");
1048 Write_Info_Char
(Task_Dispatching_Policy
);
1049 Write_Info_Char
(' ');
1054 Write_Info_Str
(" NO");
1057 if No_Run_Time_Mode
then
1058 Write_Info_Str
(" NR");
1061 if Normalize_Scalars
then
1062 Write_Info_Str
(" NS");
1065 if Sec_Stack_Used
then
1066 Write_Info_Str
(" SS");
1069 if Unreserve_All_Interrupts
then
1070 Write_Info_Str
(" UA");
1073 if Exception_Mechanism
= Back_End_Exceptions
then
1074 Write_Info_Str
(" ZX");
1079 -- Before outputting the restrictions line, update the setting of
1080 -- the No_Elaboration_Code flag. Violations of this restriction
1081 -- cannot be detected until after the backend has been called since
1082 -- it is the backend that sets this flag. We have to check all units
1083 -- for which we have generated code
1085 for Unit
in Units
.First
.. Last_Unit
loop
1086 if Units
.Table
(Unit
).Generate_Code
1087 or else Unit
= Main_Unit
1089 if not Has_No_Elaboration_Code
(Cunit
(Unit
)) then
1090 Main_Restrictions
.Violated
(No_Elaboration_Code
) := True;
1095 -- Output first restrictions line
1097 Write_Info_Initiate
('R');
1098 Write_Info_Char
(' ');
1100 -- First the information for the boolean restrictions
1102 for R
in All_Boolean_Restrictions
loop
1103 if Main_Restrictions
.Set
(R
)
1104 and then not Restriction_Warnings
(R
)
1106 Write_Info_Char
('r');
1107 elsif Main_Restrictions
.Violated
(R
) then
1108 Write_Info_Char
('v');
1110 Write_Info_Char
('n');
1114 -- And now the information for the parameter restrictions
1116 for RP
in All_Parameter_Restrictions
loop
1117 if Main_Restrictions
.Set
(RP
)
1118 and then not Restriction_Warnings
(RP
)
1120 Write_Info_Char
('r');
1121 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1123 Write_Info_Char
('n');
1126 if not Main_Restrictions
.Violated
(RP
)
1127 or else RP
not in Checked_Parameter_Restrictions
1129 Write_Info_Char
('n');
1131 Write_Info_Char
('v');
1132 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1134 if Main_Restrictions
.Unknown
(RP
) then
1135 Write_Info_Char
('+');
1142 -- Output R lines for No_Dependence entries
1144 for J
in No_Dependence
.First
.. No_Dependence
.Last
loop
1145 if In_Extended_Main_Source_Unit
(No_Dependence
.Table
(J
).Unit
)
1146 and then not No_Dependence
.Table
(J
).Warn
1148 Write_Info_Initiate
('R');
1149 Write_Info_Char
(' ');
1150 Write_Unit_Name
(No_Dependence
.Table
(J
).Unit
);
1155 -- Output interrupt state lines
1157 for J
in Interrupt_States
.First
.. Interrupt_States
.Last
loop
1158 Write_Info_Initiate
('I');
1159 Write_Info_Char
(' ');
1160 Write_Info_Nat
(Interrupt_States
.Table
(J
).Interrupt_Number
);
1161 Write_Info_Char
(' ');
1162 Write_Info_Char
(Interrupt_States
.Table
(J
).Interrupt_State
);
1163 Write_Info_Char
(' ');
1165 (Nat
(Get_Logical_Line_Number
1166 (Interrupt_States
.Table
(J
).Pragma_Loc
)));
1170 -- Output priority specific dispatching lines
1172 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
1173 Write_Info_Initiate
('S');
1174 Write_Info_Char
(' ');
1175 Write_Info_Char
(Specific_Dispatching
.Table
(J
).Dispatching_Policy
);
1176 Write_Info_Char
(' ');
1177 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).First_Priority
);
1178 Write_Info_Char
(' ');
1179 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).Last_Priority
);
1180 Write_Info_Char
(' ');
1182 (Nat
(Get_Logical_Line_Number
1183 (Specific_Dispatching
.Table
(J
).Pragma_Loc
)));
1187 -- Loop through file table to output information for all units for which
1188 -- we have generated code, as marked by the Generate_Code flag.
1190 for Unit
in Units
.First
.. Last_Unit
loop
1191 if Units
.Table
(Unit
).Generate_Code
1192 or else Unit
= Main_Unit
1194 Write_Info_EOL
; -- blank line
1195 Write_Unit_Information
(Unit
);
1199 Write_Info_EOL
; -- blank line
1201 -- Output external version reference lines
1203 for J
in 1 .. Version_Ref
.Last
loop
1204 Write_Info_Initiate
('E');
1205 Write_Info_Char
(' ');
1207 for K
in 1 .. String_Length
(Version_Ref
.Table
(J
)) loop
1208 Write_Info_Char_Code
(Get_String_Char
(Version_Ref
.Table
(J
), K
));
1214 -- Prepare to output the source dependency lines
1217 Unum
: Unit_Number_Type
;
1218 -- Number of unit being output
1220 Sind
: Source_File_Index
;
1221 -- Index of corresponding source file
1223 Fname
: File_Name_Type
;
1226 for J
in 1 .. Num_Sdep
loop
1227 Unum
:= Sdep_Table
(J
);
1228 Units
.Table
(Unum
).Dependency_Num
:= J
;
1229 Sind
:= Units
.Table
(Unum
).Source_Index
;
1231 Write_Info_Initiate
('D');
1232 Write_Info_Char
(' ');
1234 -- Normal case of a unit entry with a source index
1236 if Sind
/= No_Source_File
then
1237 Fname
:= File_Name
(Sind
);
1239 -- Ensure that on platforms where the file names are not
1240 -- case sensitive, the recorded file name is in lower case.
1242 if not File_Names_Case_Sensitive
then
1243 Get_Name_String
(Fname
);
1244 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1248 Write_Info_Name
(Fname
);
1249 Write_Info_Tab
(25);
1250 Write_Info_Str
(String (Time_Stamp
(Sind
)));
1251 Write_Info_Char
(' ');
1252 Write_Info_Str
(Get_Hex_String
(Source_Checksum
(Sind
)));
1254 -- If subunit, add unit name, omitting the %b at the end
1256 if Present
(Cunit
(Unum
))
1257 and then Nkind
(Unit
(Cunit
(Unum
))) = N_Subunit
1259 Get_Decoded_Name_String
(Unit_Name
(Unum
));
1260 Write_Info_Char
(' ');
1261 Write_Info_Str
(Name_Buffer
(1 .. Name_Len
- 2));
1264 -- If Source_Reference pragma used output information
1266 if Num_SRef_Pragmas
(Sind
) > 0 then
1267 Write_Info_Char
(' ');
1269 if Num_SRef_Pragmas
(Sind
) = 1 then
1270 Write_Info_Nat
(Int
(First_Mapped_Line
(Sind
)));
1275 Write_Info_Char
(':');
1276 Write_Info_Name
(Reference_Name
(Sind
));
1279 -- Case where there is no source index (happens for missing
1280 -- files). In this case we write a dummy time stamp.
1283 Write_Info_Name
(Unit_File_Name
(Unum
));
1284 Write_Info_Tab
(25);
1285 Write_Info_Str
(String (Dummy_Time_Stamp
));
1286 Write_Info_Char
(' ');
1287 Write_Info_Str
(Get_Hex_String
(0));
1294 -- Output cross-references
1298 -- Output SCO information if present
1300 if Generate_SCO
then
1304 -- Output final blank line and we are done. This final blank line is
1305 -- probably junk, but we don't feel like making an incompatible change!
1307 Write_Info_Terminate
;
1308 Close_Output_Library_Info
;
1311 ---------------------
1312 -- Write_Unit_Name --
1313 ---------------------
1315 procedure Write_Unit_Name
(N
: Node_Id
) is
1317 if Nkind
(N
) = N_Identifier
then
1318 Write_Info_Name
(Chars
(N
));
1321 pragma Assert
(Nkind
(N
) = N_Selected_Component
);
1322 Write_Unit_Name
(Prefix
(N
));
1323 Write_Info_Char
('.');
1324 Write_Unit_Name
(Selector_Name
(N
));
1326 end Write_Unit_Name
;