1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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 Restrict
; use Restrict
;
42 with Rident
; use Rident
;
44 with Sinfo
; use Sinfo
;
45 with Sinput
; use Sinput
;
46 with Snames
; use Snames
;
47 with Stringt
; use Stringt
;
48 with Tbuild
; use Tbuild
;
49 with Uname
; use Uname
;
51 with System
.Case_Util
; use System
.Case_Util
;
52 with System
.WCh_Con
; use System
.WCh_Con
;
54 package body Lib
.Writ
is
56 -----------------------
57 -- Local Subprograms --
58 -----------------------
60 procedure Write_Unit_Name
(N
: Node_Id
);
61 -- Used to write out the unit name for R (pragma Restriction) lines
62 -- for uses of Restriction (No_Dependence => unit-name).
64 ----------------------------------
65 -- Add_Preprocessing_Dependency --
66 ----------------------------------
68 procedure Add_Preprocessing_Dependency
(S
: Source_File_Index
) is
71 Units
.Table
(Units
.Last
) :=
72 (Unit_File_Name
=> File_Name
(S
),
73 Unit_Name
=> No_Unit_Name
,
74 Expected_Unit
=> No_Unit_Name
,
77 Cunit_Entity
=> Empty
,
79 Dynamic_Elab
=> False,
81 Generate_Code
=> False,
83 Is_Compiler_Unit
=> False,
84 Ident_String
=> Empty
,
90 Error_Location
=> No_Location
);
91 end Add_Preprocessing_Dependency
;
93 ------------------------------
94 -- Ensure_System_Dependency --
95 ------------------------------
97 procedure Ensure_System_Dependency
is
98 System_Uname
: Unit_Name_Type
;
99 -- Unit name for system spec if needed for dummy entry
101 System_Fname
: File_Name_Type
;
102 -- File name for system spec if needed for dummy entry
105 -- Nothing to do if we already compiled System
107 for Unum
in Units
.First
.. Last_Unit
loop
108 if Units
.Table
(Unum
).Source_Index
= System_Source_File_Index
then
113 -- If no entry for system.ads in the units table, then add a entry
114 -- to the units table for system.ads, which will be referenced when
115 -- the ali file is generated. We need this because every unit depends
116 -- on system as a result of Targparm scanning the system.ads file to
117 -- determine the target dependent parameters for the compilation.
120 Name_Buffer
(1 .. 6) := "system";
121 System_Uname
:= Name_To_Unit_Name
(Name_Enter
);
122 System_Fname
:= File_Name
(System_Source_File_Index
);
124 Units
.Increment_Last
;
125 Units
.Table
(Units
.Last
) := (
126 Unit_File_Name
=> System_Fname
,
127 Unit_Name
=> System_Uname
,
128 Expected_Unit
=> System_Uname
,
129 Source_Index
=> System_Source_File_Index
,
131 Cunit_Entity
=> Empty
,
133 Dynamic_Elab
=> False,
134 Fatal_Error
=> False,
135 Generate_Code
=> False,
137 Is_Compiler_Unit
=> False,
138 Ident_String
=> Empty
,
144 Error_Location
=> No_Location
);
146 -- Parse system.ads so that the checksum is set right
147 -- Style checks are not applied.
150 Save_Mindex
: constant Nat
:= Multiple_Unit_Index
;
151 Save_Style
: constant Boolean := Style_Check
;
153 Multiple_Unit_Index
:= 0;
154 Style_Check
:= False;
155 Initialize_Scanner
(Units
.Last
, System_Source_File_Index
);
156 Discard_List
(Par
(Configuration_Pragmas
=> False));
157 Style_Check
:= Save_Style
;
158 Multiple_Unit_Index
:= Save_Mindex
;
160 end Ensure_System_Dependency
;
166 procedure Write_ALI
(Object
: Boolean) is
172 Last_Unit
: constant Unit_Number_Type
:= Units
.Last
;
173 -- Record unit number of last unit. We capture this in case we
174 -- have to add a dummy entry to the unit table for package System.
176 With_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
177 -- Array of flags to show which units are with'ed
179 Elab_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
180 -- Array of flags to show which units have pragma Elaborate set
182 Elab_All_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
183 -- Array of flags to show which units have pragma Elaborate All set
185 Elab_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
186 -- Array of flags to show which units have Elaborate_Desirable set
188 Elab_All_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
189 -- Array of flags to show which units have Elaborate_All_Desirable set
191 Sdep_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 2));
192 -- Sorted table of source dependencies. One extra entry in case we
193 -- have to add a dummy entry for System.
196 -- Number of active entries in Sdep_Table
198 -----------------------
199 -- Local Subprograms --
200 -----------------------
202 procedure Collect_Withs
(Cunit
: Node_Id
);
203 -- Collect with lines for entries in the context clause of the
204 -- given compilation unit, Cunit.
206 procedure Update_Tables_From_ALI_File
;
207 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
208 -- function), update tables from the ALI information, including
209 -- specifically the Compilation_Switches table.
211 function Up_To_Date_ALI_File_Exists
return Boolean;
212 -- If there exists an ALI file that is up to date, then this function
213 -- initializes the tables in the ALI spec to contain information on
214 -- this file (using Scan_ALI) and returns True. If no file exists,
215 -- or the file is not up to date, then False is returned.
217 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
);
218 -- Write out the library information for one unit for which code is
219 -- generated (includes unit line and with lines).
221 procedure Write_With_Lines
;
222 -- Write out with lines collected by calls to Collect_Withs
228 procedure Collect_Withs
(Cunit
: Node_Id
) is
230 Unum
: Unit_Number_Type
;
233 Item
:= First
(Context_Items
(Cunit
));
234 while Present
(Item
) loop
236 -- Process with clause
238 -- Ada 2005 (AI-50217): limited with_clauses do not create
241 if Nkind
(Item
) = N_With_Clause
242 and then not (Limited_Present
(Item
))
244 Unum
:= Get_Cunit_Unit_Number
(Library_Unit
(Item
));
245 With_Flags
(Unum
) := True;
247 if Elaborate_Present
(Item
) then
248 Elab_Flags
(Unum
) := True;
251 if Elaborate_All_Present
(Item
) then
252 Elab_All_Flags
(Unum
) := True;
255 if Elaborate_All_Desirable
(Item
) then
256 Elab_All_Des_Flags
(Unum
) := True;
259 if Elaborate_Desirable
(Item
) then
260 Elab_Des_Flags
(Unum
) := True;
268 --------------------------------
269 -- Up_To_Date_ALI_File_Exists --
270 --------------------------------
272 function Up_To_Date_ALI_File_Exists
return Boolean is
273 Name
: File_Name_Type
;
274 Text
: Text_Buffer_Ptr
;
276 Sind
: Source_File_Index
;
279 Opt
.Check_Object_Consistency
:= True;
280 Read_Library_Info
(Name
, Text
);
282 -- Return if we could not find an ALI file
288 -- Return if ALI file has bad format
292 if Scan_ALI
(Name
, Text
, False, Err
=> True) = No_ALI_Id
then
296 -- If we have an OK ALI file, check if it is up to date
297 -- Note that we assume that the ALI read has all the entries
298 -- we have in our table, plus some additional ones (that can
299 -- come from expansion).
301 Id
:= First_Sdep_Entry
;
302 for J
in 1 .. Num_Sdep
loop
303 Sind
:= Units
.Table
(Sdep_Table
(J
)).Source_Index
;
305 while Sdep
.Table
(Id
).Sfile
/= File_Name
(Sind
) loop
306 if Id
= Sdep
.Last
then
313 if Sdep
.Table
(Id
).Stamp
/= Time_Stamp
(Sind
) then
319 end Up_To_Date_ALI_File_Exists
;
321 ---------------------------------
322 -- Update_Tables_From_ALI_File --
323 ---------------------------------
325 procedure Update_Tables_From_ALI_File
is
327 -- Build Compilation_Switches table
329 Compilation_Switches
.Init
;
331 for J
in First_Arg_Entry
.. Args
.Last
loop
332 Compilation_Switches
.Increment_Last
;
333 Compilation_Switches
.Table
(Compilation_Switches
.Last
) :=
336 end Update_Tables_From_ALI_File
;
338 ----------------------------
339 -- Write_Unit_Information --
340 ----------------------------
342 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
) is
343 Unode
: constant Node_Id
:= Cunit
(Unit_Num
);
344 Ukind
: constant Node_Kind
:= Nkind
(Unit
(Unode
));
345 Uent
: constant Entity_Id
:= Cunit_Entity
(Unit_Num
);
349 Write_Info_Initiate
('U');
350 Write_Info_Char
(' ');
351 Write_Info_Name
(Unit_Name
(Unit_Num
));
353 Write_Info_Name
(Unit_File_Name
(Unit_Num
));
356 Write_Info_Str
(Version_Get
(Unit_Num
));
358 -- Add BD parameter if Elaborate_Body pragma desirable
360 if Ekind
(Uent
) = E_Package
361 and then Elaborate_Body_Desirable
(Uent
)
363 Write_Info_Str
(" BD");
366 -- Add BN parameter if body needed for SAL
368 if (Is_Subprogram
(Uent
)
369 or else Ekind
(Uent
) = E_Package
370 or else Is_Generic_Unit
(Uent
))
371 and then Body_Needed_For_SAL
(Uent
)
373 Write_Info_Str
(" BN");
376 if Dynamic_Elab
(Unit_Num
) then
377 Write_Info_Str
(" DE");
380 -- Set the Elaborate_Body indication if either an explicit pragma
381 -- was present, or if this is an instantiation.
383 if Has_Pragma_Elaborate_Body
(Uent
)
384 or else (Ukind
= N_Package_Declaration
385 and then Is_Generic_Instance
(Uent
)
386 and then Present
(Corresponding_Body
(Unit
(Unode
))))
388 Write_Info_Str
(" EB");
391 -- Now see if we should tell the binder that an elaboration entity
392 -- is present, which must be set to true during elaboration.
393 -- We generate the indication if the following condition is met:
395 -- If this is a spec ...
397 if (Is_Subprogram
(Uent
)
399 Ekind
(Uent
) = E_Package
401 Is_Generic_Unit
(Uent
))
403 -- and an elaboration entity was declared ...
405 and then Present
(Elaboration_Entity
(Uent
))
407 -- and either the elaboration flag is required ...
410 (Elaboration_Entity_Required
(Uent
)
412 -- or this unit has elaboration code ...
414 or else not Has_No_Elaboration_Code
(Unode
)
416 -- or this unit has a separate body and this
417 -- body has elaboration code.
420 (Ekind
(Uent
) = E_Package
421 and then Present
(Body_Entity
(Uent
))
423 not Has_No_Elaboration_Code
426 (Body_Entity
(Uent
))))))
428 if Convention
(Uent
) = Convention_CIL
then
430 -- Special case for generic CIL packages which never have
433 Write_Info_Str
(" NE");
436 Write_Info_Str
(" EE");
440 if Has_No_Elaboration_Code
(Unode
) then
441 Write_Info_Str
(" NE");
444 if Is_Preelaborated
(Uent
) then
445 Write_Info_Str
(" PR");
448 if Is_Pure
(Uent
) then
449 Write_Info_Str
(" PU");
452 if Has_RACW
(Unit_Num
) then
453 Write_Info_Str
(" RA");
456 if Is_Remote_Call_Interface
(Uent
) then
457 Write_Info_Str
(" RC");
460 if Is_Remote_Types
(Uent
) then
461 Write_Info_Str
(" RT");
464 if Is_Shared_Passive
(Uent
) then
465 Write_Info_Str
(" SP");
468 if Ukind
= N_Subprogram_Declaration
469 or else Ukind
= N_Subprogram_Body
471 Write_Info_Str
(" SU");
473 elsif Ukind
= N_Package_Declaration
475 Ukind
= N_Package_Body
477 -- If this is a wrapper package for a subprogram instantiation,
478 -- the user view is the subprogram. Note that in this case the
479 -- ali file contains both the spec and body of the instance.
481 if Is_Wrapper_Package
(Uent
) then
482 Write_Info_Str
(" SU");
484 Write_Info_Str
(" PK");
487 elsif Ukind
= N_Generic_Package_Declaration
then
488 Write_Info_Str
(" PK");
492 if Ukind
in N_Generic_Declaration
494 (Present
(Library_Unit
(Unode
))
496 Nkind
(Unit
(Library_Unit
(Unode
))) in N_Generic_Declaration
)
498 Write_Info_Str
(" GE");
501 if not Is_Internal_File_Name
(Unit_File_Name
(Unit_Num
), True) then
502 case Identifier_Casing
(Source_Index
(Unit_Num
)) is
503 when All_Lower_Case
=> Write_Info_Str
(" IL");
504 when All_Upper_Case
=> Write_Info_Str
(" IU");
508 case Keyword_Casing
(Source_Index
(Unit_Num
)) is
509 when Mixed_Case
=> Write_Info_Str
(" KM");
510 when All_Upper_Case
=> Write_Info_Str
(" KU");
515 if Initialize_Scalars
then
516 Write_Info_Str
(" IS");
521 -- Generate with lines, first those that are directly with'ed
523 for J
in With_Flags
'Range loop
524 With_Flags
(J
) := False;
525 Elab_Flags
(J
) := False;
526 Elab_All_Flags
(J
) := False;
527 Elab_Des_Flags
(J
) := False;
528 Elab_All_Des_Flags
(J
) := False;
531 Collect_Withs
(Unode
);
533 -- For a body, we must also check for any subunits which belong to
534 -- it and which have context clauses of their own, since these
535 -- with'ed units are part of its own elaboration dependencies.
537 if Nkind
(Unit
(Unode
)) in N_Unit_Body
then
538 for S
in Units
.First
.. Last_Unit
loop
540 -- We are only interested in subunits.
541 -- For preproc. data and def. files, Cunit is Empty, so
542 -- we need to test that first.
544 if Cunit
(S
) /= Empty
545 and then Nkind
(Unit
(Cunit
(S
))) = N_Subunit
547 Pnode
:= Library_Unit
(Cunit
(S
));
549 -- In gnatc mode, the errors in the subunits will not
550 -- have been recorded, but the analysis of the subunit
551 -- may have failed. There is no information to add to
552 -- ALI file in this case.
558 -- Find ultimate parent of the subunit
560 while Nkind
(Unit
(Pnode
)) = N_Subunit
loop
561 Pnode
:= Library_Unit
(Pnode
);
564 -- See if it belongs to current unit, and if so, include
567 if Pnode
= Unode
then
568 Collect_Withs
(Cunit
(S
));
576 -- Output linker option lines
578 for J
in 1 .. Linker_Option_Lines
.Last
loop
580 S
: constant Linker_Option_Entry
:=
581 Linker_Option_Lines
.Table
(J
);
585 if S
.Unit
= Unit_Num
then
586 Write_Info_Initiate
('L');
587 Write_Info_Str
(" """);
589 for J
in 1 .. String_Length
(S
.Option
) loop
590 C
:= Get_Character
(Get_String_Char
(S
.Option
, J
));
592 if C
in Character'Val (16#
20#
) .. Character'Val (16#
7E#
)
603 Hex
: constant array (0 .. 15) of Character :=
607 Write_Info_Char
('{');
608 Write_Info_Char
(Hex
(Character'Pos (C
) / 16));
609 Write_Info_Char
(Hex
(Character'Pos (C
) mod 16));
610 Write_Info_Char
('}');
615 Write_Info_Char
('"');
620 end Write_Unit_Information
;
622 ----------------------
623 -- Write_With_Lines --
624 ----------------------
626 procedure Write_With_Lines
is
627 With_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 1));
628 Num_Withs
: Int
:= 0;
629 Unum
: Unit_Number_Type
;
631 Uname
: Unit_Name_Type
;
632 Fname
: File_Name_Type
;
633 Pname
: constant Unit_Name_Type
:=
634 Get_Parent_Spec_Name
(Unit_Name
(Main_Unit
));
635 Body_Fname
: File_Name_Type
;
638 procedure Write_With_File_Names
639 (Nam
: in out File_Name_Type
;
641 -- Write source file name Nam and ALI file name for unit index Idx.
642 -- Possibly change Nam to lowercase (generating a new file name).
644 --------------------------
645 -- Write_With_File_Name --
646 --------------------------
648 procedure Write_With_File_Names
649 (Nam
: in out File_Name_Type
;
653 if not File_Names_Case_Sensitive
then
654 Get_Name_String
(Nam
);
655 To_Lower
(Name_Buffer
(1 .. Name_Len
));
659 Write_Info_Name
(Nam
);
661 Write_Info_Name
(Lib_File_Name
(Nam
, Idx
));
662 end Write_With_File_Names
;
664 -- Start of processing for Write_With_Lines
667 -- Loop to build the with table. A with on the main unit itself
668 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
669 -- the main unit is a subprogram with no spec, and a subunit of
670 -- it unecessarily withs the parent.
672 for J
in Units
.First
+ 1 .. Last_Unit
loop
674 -- Add element to with table if it is with'ed or if it is the
675 -- parent spec of the main unit (case of main unit is a child
676 -- unit). The latter with is not needed for semantic purposes,
677 -- but is required by the binder for elaboration purposes.
678 -- For preproc. data and def. files, there is no Unit_Name,
679 -- check for that first.
681 if Unit_Name
(J
) /= No_Unit_Name
682 and then (With_Flags
(J
) or else Unit_Name
(J
) = Pname
)
684 Num_Withs
:= Num_Withs
+ 1;
685 With_Table
(Num_Withs
) := J
;
689 -- Sort and output the table
691 Sort
(With_Table
(1 .. Num_Withs
));
693 for J
in 1 .. Num_Withs
loop
694 Unum
:= With_Table
(J
);
695 Cunit
:= Units
.Table
(Unum
).Cunit
;
696 Uname
:= Units
.Table
(Unum
).Unit_Name
;
697 Fname
:= Units
.Table
(Unum
).Unit_File_Name
;
699 Write_Info_Initiate
('W');
700 Write_Info_Char
(' ');
701 Write_Info_Name
(Uname
);
703 -- Now we need to figure out the names of the files that contain
704 -- the with'ed unit. These will usually be the files for the body,
705 -- except in the case of a package that has no body. Note that we
706 -- have a specific exemption here for predefined library generics
707 -- (see comments for Generic_May_Lack_ALI). We do not generate
708 -- dependency upon the ALI file for such units. Older compilers
709 -- used to not support generating code (and ALI) for generics, and
710 -- we want to avoid having different processing (namely, different
711 -- lists of files to be compiled) for different stages of the
714 if not ((Nkind
(Unit
(Cunit
)) in N_Generic_Declaration
716 Nkind
(Unit
(Cunit
)) in N_Generic_Renaming_Declaration
)
717 and then Generic_May_Lack_ALI
(Fname
))
721 if Is_Spec_Name
(Uname
) then
724 (Get_Body_Name
(Uname
),
725 Subunit
=> False, May_Fail
=> True);
729 (Get_Body_Name
(Uname
));
731 if Body_Fname
= No_File
then
732 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
733 Body_Index
:= Get_Unit_Index
(Uname
);
737 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
738 Body_Index
:= Get_Unit_Index
(Uname
);
741 -- A package is considered to have a body if it requires
742 -- a body or if a body is present in Ada 83 mode.
744 if Body_Required
(Cunit
)
745 or else (Ada_Version
= Ada_83
746 and then Full_Source_Name
(Body_Fname
) /= No_File
)
748 Write_With_File_Names
(Body_Fname
, Body_Index
);
750 Write_With_File_Names
(Fname
, Munit_Index
(Unum
));
753 if Elab_Flags
(Unum
) then
754 Write_Info_Str
(" E");
757 if Elab_All_Flags
(Unum
) then
758 Write_Info_Str
(" EA");
761 if Elab_Des_Flags
(Unum
) then
762 Write_Info_Str
(" ED");
765 if Elab_All_Des_Flags
(Unum
) then
766 Write_Info_Str
(" AD");
772 end Write_With_Lines
;
774 -- Start of processing for Write_ALI
777 -- We never write an ALI file if the original operating mode was
778 -- syntax-only (-gnats switch used in compiler invocation line)
780 if Original_Operating_Mode
= Check_Syntax
then
784 -- Build sorted source dependency table. We do this right away,
785 -- because it is referenced by Up_To_Date_ALI_File_Exists.
787 for Unum
in Units
.First
.. Last_Unit
loop
788 if Cunit_Entity
(Unum
) = Empty
789 or else not From_With_Type
(Cunit_Entity
(Unum
))
791 Num_Sdep
:= Num_Sdep
+ 1;
792 Sdep_Table
(Num_Sdep
) := Unum
;
796 -- Sort the table so that the D lines are in order
798 Lib
.Sort
(Sdep_Table
(1 .. Num_Sdep
));
800 -- If we are not generating code, and there is an up to date
801 -- ali file accessible, read it, and acquire the compilation
802 -- arguments from this file.
804 if Operating_Mode
/= Generate_Code
then
805 if Up_To_Date_ALI_File_Exists
then
806 Update_Tables_From_ALI_File
;
811 -- Otherwise acquire compilation arguments and prepare to write
812 -- out a new ali file.
814 Create_Output_Library_Info
;
816 -- Output version line
818 Write_Info_Initiate
('V');
819 Write_Info_Str
(" """);
820 Write_Info_Str
(Verbose_Library_Version
);
821 Write_Info_Char
('"');
825 -- Output main program line if this is acceptable main program
827 Output_Main_Program_Line
: declare
828 U
: Node_Id
:= Unit
(Units
.Table
(Main_Unit
).Cunit
);
831 procedure M_Parameters
;
832 -- Output parameters for main program line
838 procedure M_Parameters
is
840 if Main_Priority
(Main_Unit
) /= Default_Main_Priority
then
841 Write_Info_Char
(' ');
842 Write_Info_Nat
(Main_Priority
(Main_Unit
));
845 if Opt
.Time_Slice_Set
then
846 Write_Info_Str
(" T=");
847 Write_Info_Nat
(Opt
.Time_Slice_Value
);
850 Write_Info_Str
(" W=");
852 (WC_Encoding_Letters
(Wide_Character_Encoding_Method
));
857 -- Start of processing for Output_Main_Program_Line
860 if Nkind
(U
) = N_Subprogram_Body
862 (Nkind
(U
) = N_Package_Body
864 Nkind
(Original_Node
(U
)) in N_Subprogram_Instantiation
)
866 -- If the unit is a subprogram instance, the entity for the
867 -- subprogram is the alias of the visible entity, which is the
868 -- related instance of the wrapper package. We retrieve the
869 -- subprogram declaration of the desired entity.
871 if Nkind
(U
) = N_Package_Body
then
872 U
:= Parent
(Parent
(
873 Alias
(Related_Instance
(Defining_Unit_Name
874 (Specification
(Unit
(Library_Unit
(Parent
(U
)))))))));
877 S
:= Specification
(U
);
879 if No
(Parameter_Specifications
(S
)) then
880 if Nkind
(S
) = N_Procedure_Specification
then
881 Write_Info_Initiate
('M');
882 Write_Info_Str
(" P");
887 Nam
: Node_Id
:= Defining_Unit_Name
(S
);
890 -- If it is a child unit, get its simple name
892 if Nkind
(Nam
) = N_Defining_Program_Unit_Name
then
893 Nam
:= Defining_Identifier
(Nam
);
896 if Is_Integer_Type
(Etype
(Nam
)) then
897 Write_Info_Initiate
('M');
898 Write_Info_Str
(" F");
905 end Output_Main_Program_Line
;
907 -- Write command argmument ('A') lines
909 for A
in 1 .. Compilation_Switches
.Last
loop
910 Write_Info_Initiate
('A');
911 Write_Info_Char
(' ');
912 Write_Info_Str
(Compilation_Switches
.Table
(A
).all);
913 Write_Info_Terminate
;
916 -- Output parameters ('P') line
918 Write_Info_Initiate
('P');
920 if Compilation_Errors
then
921 Write_Info_Str
(" CE");
924 if Opt
.Detect_Blocking
then
925 Write_Info_Str
(" DB");
928 if Opt
.Float_Format
/= ' ' then
929 Write_Info_Str
(" F");
931 if Opt
.Float_Format
= 'I' then
932 Write_Info_Char
('I');
934 elsif Opt
.Float_Format_Long
= 'D' then
935 Write_Info_Char
('D');
938 Write_Info_Char
('G');
943 and then not Is_Predefined_File_Name
(Unit_File_Name
(Main_Unit
))
945 if Locking_Policy
/= ' ' then
946 Write_Info_Str
(" L");
947 Write_Info_Char
(Locking_Policy
);
950 if Queuing_Policy
/= ' ' then
951 Write_Info_Str
(" Q");
952 Write_Info_Char
(Queuing_Policy
);
955 if Task_Dispatching_Policy
/= ' ' then
956 Write_Info_Str
(" T");
957 Write_Info_Char
(Task_Dispatching_Policy
);
958 Write_Info_Char
(' ');
963 Write_Info_Str
(" NO");
966 if No_Run_Time_Mode
then
967 Write_Info_Str
(" NR");
970 if Normalize_Scalars
then
971 Write_Info_Str
(" NS");
974 if Sec_Stack_Used
then
975 Write_Info_Str
(" SS");
978 if Unreserve_All_Interrupts
then
979 Write_Info_Str
(" UA");
982 if Exception_Mechanism
= Back_End_Exceptions
then
983 Write_Info_Str
(" ZX");
988 -- Before outputting the restrictions line, update the setting of
989 -- the No_Elaboration_Code flag. Violations of this restriction
990 -- cannot be detected until after the backend has been called since
991 -- it is the backend that sets this flag. We have to check all units
992 -- for which we have generated code
994 for Unit
in Units
.First
.. Last_Unit
loop
995 if Units
.Table
(Unit
).Generate_Code
996 or else Unit
= Main_Unit
998 if not Has_No_Elaboration_Code
(Cunit
(Unit
)) then
999 Main_Restrictions
.Violated
(No_Elaboration_Code
) := True;
1004 -- Output first restrictions line
1006 Write_Info_Initiate
('R');
1007 Write_Info_Char
(' ');
1009 -- First the information for the boolean restrictions
1011 for R
in All_Boolean_Restrictions
loop
1012 if Main_Restrictions
.Set
(R
)
1013 and then not Restriction_Warnings
(R
)
1015 Write_Info_Char
('r');
1016 elsif Main_Restrictions
.Violated
(R
) then
1017 Write_Info_Char
('v');
1019 Write_Info_Char
('n');
1023 -- And now the information for the parameter restrictions
1025 for RP
in All_Parameter_Restrictions
loop
1026 if Main_Restrictions
.Set
(RP
)
1027 and then not Restriction_Warnings
(RP
)
1029 Write_Info_Char
('r');
1030 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1032 Write_Info_Char
('n');
1035 if not Main_Restrictions
.Violated
(RP
)
1036 or else RP
not in Checked_Parameter_Restrictions
1038 Write_Info_Char
('n');
1040 Write_Info_Char
('v');
1041 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1043 if Main_Restrictions
.Unknown
(RP
) then
1044 Write_Info_Char
('+');
1051 -- Output R lines for No_Dependence entries
1053 for J
in No_Dependence
.First
.. No_Dependence
.Last
loop
1054 if In_Extended_Main_Source_Unit
(No_Dependence
.Table
(J
).Unit
)
1055 and then not No_Dependence
.Table
(J
).Warn
1057 Write_Info_Initiate
('R');
1058 Write_Info_Char
(' ');
1059 Write_Unit_Name
(No_Dependence
.Table
(J
).Unit
);
1064 -- Output interrupt state lines
1066 for J
in Interrupt_States
.First
.. Interrupt_States
.Last
loop
1067 Write_Info_Initiate
('I');
1068 Write_Info_Char
(' ');
1069 Write_Info_Nat
(Interrupt_States
.Table
(J
).Interrupt_Number
);
1070 Write_Info_Char
(' ');
1071 Write_Info_Char
(Interrupt_States
.Table
(J
).Interrupt_State
);
1072 Write_Info_Char
(' ');
1074 (Nat
(Get_Logical_Line_Number
1075 (Interrupt_States
.Table
(J
).Pragma_Loc
)));
1079 -- Output priority specific dispatching lines
1081 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
1082 Write_Info_Initiate
('S');
1083 Write_Info_Char
(' ');
1084 Write_Info_Char
(Specific_Dispatching
.Table
(J
).Dispatching_Policy
);
1085 Write_Info_Char
(' ');
1086 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).First_Priority
);
1087 Write_Info_Char
(' ');
1088 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).Last_Priority
);
1089 Write_Info_Char
(' ');
1091 (Nat
(Get_Logical_Line_Number
1092 (Specific_Dispatching
.Table
(J
).Pragma_Loc
)));
1096 -- Loop through file table to output information for all units for which
1097 -- we have generated code, as marked by the Generate_Code flag.
1099 for Unit
in Units
.First
.. Last_Unit
loop
1100 if Units
.Table
(Unit
).Generate_Code
1101 or else Unit
= Main_Unit
1103 Write_Info_EOL
; -- blank line
1104 Write_Unit_Information
(Unit
);
1108 Write_Info_EOL
; -- blank line
1110 -- Output external version reference lines
1112 for J
in 1 .. Version_Ref
.Last
loop
1113 Write_Info_Initiate
('E');
1114 Write_Info_Char
(' ');
1116 for K
in 1 .. String_Length
(Version_Ref
.Table
(J
)) loop
1117 Write_Info_Char_Code
(Get_String_Char
(Version_Ref
.Table
(J
), K
));
1123 -- Prepare to output the source dependency lines
1126 Unum
: Unit_Number_Type
;
1127 -- Number of unit being output
1129 Sind
: Source_File_Index
;
1130 -- Index of corresponding source file
1132 Fname
: File_Name_Type
;
1135 for J
in 1 .. Num_Sdep
loop
1136 Unum
:= Sdep_Table
(J
);
1137 Units
.Table
(Unum
).Dependency_Num
:= J
;
1138 Sind
:= Units
.Table
(Unum
).Source_Index
;
1140 Write_Info_Initiate
('D');
1141 Write_Info_Char
(' ');
1143 -- Normal case of a unit entry with a source index
1145 if Sind
/= No_Source_File
then
1146 Fname
:= File_Name
(Sind
);
1148 -- Ensure that on platforms where the file names are not
1149 -- case sensitive, the recorded file name is in lower case.
1151 if not File_Names_Case_Sensitive
then
1152 Get_Name_String
(Fname
);
1153 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1157 Write_Info_Name
(Fname
);
1158 Write_Info_Tab
(25);
1159 Write_Info_Str
(String (Time_Stamp
(Sind
)));
1160 Write_Info_Char
(' ');
1161 Write_Info_Str
(Get_Hex_String
(Source_Checksum
(Sind
)));
1163 -- If subunit, add unit name, omitting the %b at the end
1165 if Present
(Cunit
(Unum
))
1166 and then Nkind
(Unit
(Cunit
(Unum
))) = N_Subunit
1168 Get_Decoded_Name_String
(Unit_Name
(Unum
));
1169 Write_Info_Char
(' ');
1170 Write_Info_Str
(Name_Buffer
(1 .. Name_Len
- 2));
1173 -- If Source_Reference pragma used output information
1175 if Num_SRef_Pragmas
(Sind
) > 0 then
1176 Write_Info_Char
(' ');
1178 if Num_SRef_Pragmas
(Sind
) = 1 then
1179 Write_Info_Nat
(Int
(First_Mapped_Line
(Sind
)));
1184 Write_Info_Char
(':');
1185 Write_Info_Name
(Reference_Name
(Sind
));
1188 -- Case where there is no source index (happens for missing
1189 -- files). In this case we write a dummy time stamp.
1192 Write_Info_Name
(Unit_File_Name
(Unum
));
1193 Write_Info_Tab
(25);
1194 Write_Info_Str
(String (Dummy_Time_Stamp
));
1195 Write_Info_Char
(' ');
1196 Write_Info_Str
(Get_Hex_String
(0));
1204 Write_Info_Terminate
;
1205 Close_Output_Library_Info
;
1208 ---------------------
1209 -- Write_Unit_Name --
1210 ---------------------
1212 procedure Write_Unit_Name
(N
: Node_Id
) is
1214 if Nkind
(N
) = N_Identifier
then
1215 Write_Info_Name
(Chars
(N
));
1218 pragma Assert
(Nkind
(N
) = N_Selected_Component
);
1219 Write_Unit_Name
(Prefix
(N
));
1220 Write_Info_Char
('.');
1221 Write_Unit_Name
(Selector_Name
(N
));
1223 end Write_Unit_Name
;