1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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
,
92 end Add_Preprocessing_Dependency
;
94 ------------------------------
95 -- Ensure_System_Dependency --
96 ------------------------------
98 procedure Ensure_System_Dependency
is
99 System_Uname
: Unit_Name_Type
;
100 -- Unit name for system spec if needed for dummy entry
102 System_Fname
: File_Name_Type
;
103 -- File name for system spec if needed for dummy entry
106 -- Nothing to do if we already compiled System
108 for Unum
in Units
.First
.. Last_Unit
loop
109 if Units
.Table
(Unum
).Source_Index
= System_Source_File_Index
then
114 -- If no entry for system.ads in the units table, then add a entry
115 -- to the units table for system.ads, which will be referenced when
116 -- the ali file is generated. We need this because every unit depends
117 -- on system as a result of Targparm scanning the system.ads file to
118 -- determine the target dependent parameters for the compilation.
121 Name_Buffer
(1 .. 6) := "system";
122 System_Uname
:= Name_To_Unit_Name
(Name_Enter
);
123 System_Fname
:= File_Name
(System_Source_File_Index
);
125 Units
.Increment_Last
;
126 Units
.Table
(Units
.Last
) := (
127 Unit_File_Name
=> System_Fname
,
128 Unit_Name
=> System_Uname
,
129 Expected_Unit
=> System_Uname
,
130 Source_Index
=> System_Source_File_Index
,
132 Cunit_Entity
=> Empty
,
134 Dynamic_Elab
=> False,
135 Fatal_Error
=> False,
136 Generate_Code
=> False,
138 Is_Compiler_Unit
=> False,
139 Ident_String
=> Empty
,
145 Error_Location
=> No_Location
,
148 -- Parse system.ads so that the checksum is set right
149 -- Style checks are not applied.
152 Save_Mindex
: constant Nat
:= Multiple_Unit_Index
;
153 Save_Style
: constant Boolean := Style_Check
;
155 Multiple_Unit_Index
:= 0;
156 Style_Check
:= False;
157 Initialize_Scanner
(Units
.Last
, System_Source_File_Index
);
158 Discard_List
(Par
(Configuration_Pragmas
=> False));
159 Style_Check
:= Save_Style
;
160 Multiple_Unit_Index
:= Save_Mindex
;
162 end Ensure_System_Dependency
;
168 procedure Write_ALI
(Object
: Boolean) is
174 Last_Unit
: constant Unit_Number_Type
:= Units
.Last
;
175 -- Record unit number of last unit. We capture this in case we
176 -- have to add a dummy entry to the unit table for package System.
178 With_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
179 -- Array of flags to show which units are with'ed
181 Elab_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
182 -- Array of flags to show which units have pragma Elaborate set
184 Elab_All_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
185 -- Array of flags to show which units have pragma Elaborate All set
187 Elab_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
188 -- Array of flags to show which units have Elaborate_Desirable set
190 Elab_All_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
191 -- Array of flags to show which units have Elaborate_All_Desirable set
193 Sdep_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 2));
194 -- Sorted table of source dependencies. One extra entry in case we
195 -- have to add a dummy entry for System.
198 -- Number of active entries in Sdep_Table
200 flag_compare_debug
: Int
;
201 pragma Import
(C
, flag_compare_debug
);
202 -- Import from toplev.c
204 -----------------------
205 -- Local Subprograms --
206 -----------------------
208 procedure Collect_Withs
(Cunit
: Node_Id
);
209 -- Collect with lines for entries in the context clause of the
210 -- given compilation unit, Cunit.
212 procedure Update_Tables_From_ALI_File
;
213 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
214 -- function), update tables from the ALI information, including
215 -- specifically the Compilation_Switches table.
217 function Up_To_Date_ALI_File_Exists
return Boolean;
218 -- If there exists an ALI file that is up to date, then this function
219 -- initializes the tables in the ALI spec to contain information on
220 -- this file (using Scan_ALI) and returns True. If no file exists,
221 -- or the file is not up to date, then False is returned.
223 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
);
224 -- Write out the library information for one unit for which code is
225 -- generated (includes unit line and with lines).
227 procedure Write_With_Lines
;
228 -- Write out with lines collected by calls to Collect_Withs
234 procedure Collect_Withs
(Cunit
: Node_Id
) is
236 Unum
: Unit_Number_Type
;
239 Item
:= First
(Context_Items
(Cunit
));
240 while Present
(Item
) loop
242 -- Process with clause
244 -- Ada 2005 (AI-50217): limited with_clauses do not create
245 -- dependencies, but must be recorded as components of the
246 -- partition, in case there is no regular with_clause for
247 -- the unit anywhere else.
249 if Nkind
(Item
) = N_With_Clause
then
250 Unum
:= Get_Cunit_Unit_Number
(Library_Unit
(Item
));
251 With_Flags
(Unum
) := True;
253 if not Limited_Present
(Item
) then
254 if Elaborate_Present
(Item
) then
255 Elab_Flags
(Unum
) := True;
258 if Elaborate_All_Present
(Item
) then
259 Elab_All_Flags
(Unum
) := True;
262 if Elaborate_All_Desirable
(Item
) then
263 Elab_All_Des_Flags
(Unum
) := True;
266 if Elaborate_Desirable
(Item
) then
267 Elab_Des_Flags
(Unum
) := True;
271 Set_From_With_Type
(Cunit_Entity
(Unum
));
279 --------------------------------
280 -- Up_To_Date_ALI_File_Exists --
281 --------------------------------
283 function Up_To_Date_ALI_File_Exists
return Boolean is
284 Name
: File_Name_Type
;
285 Text
: Text_Buffer_Ptr
;
287 Sind
: Source_File_Index
;
290 Opt
.Check_Object_Consistency
:= True;
291 Read_Library_Info
(Name
, Text
);
293 -- Return if we could not find an ALI file
299 -- Return if ALI file has bad format
303 if Scan_ALI
(Name
, Text
, False, Err
=> True) = No_ALI_Id
then
307 -- If we have an OK ALI file, check if it is up to date
308 -- Note that we assume that the ALI read has all the entries
309 -- we have in our table, plus some additional ones (that can
310 -- come from expansion).
312 Id
:= First_Sdep_Entry
;
313 for J
in 1 .. Num_Sdep
loop
314 Sind
:= Units
.Table
(Sdep_Table
(J
)).Source_Index
;
316 while Sdep
.Table
(Id
).Sfile
/= File_Name
(Sind
) loop
317 if Id
= Sdep
.Last
then
324 if Sdep
.Table
(Id
).Stamp
/= Time_Stamp
(Sind
) then
330 end Up_To_Date_ALI_File_Exists
;
332 ---------------------------------
333 -- Update_Tables_From_ALI_File --
334 ---------------------------------
336 procedure Update_Tables_From_ALI_File
is
338 -- Build Compilation_Switches table
340 Compilation_Switches
.Init
;
342 for J
in First_Arg_Entry
.. Args
.Last
loop
343 Compilation_Switches
.Increment_Last
;
344 Compilation_Switches
.Table
(Compilation_Switches
.Last
) :=
347 end Update_Tables_From_ALI_File
;
349 ----------------------------
350 -- Write_Unit_Information --
351 ----------------------------
353 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
) is
354 Unode
: constant Node_Id
:= Cunit
(Unit_Num
);
355 Ukind
: constant Node_Kind
:= Nkind
(Unit
(Unode
));
356 Uent
: constant Entity_Id
:= Cunit_Entity
(Unit_Num
);
360 Write_Info_Initiate
('U');
361 Write_Info_Char
(' ');
362 Write_Info_Name
(Unit_Name
(Unit_Num
));
364 Write_Info_Name
(Unit_File_Name
(Unit_Num
));
367 Write_Info_Str
(Version_Get
(Unit_Num
));
369 -- Add BD parameter if Elaborate_Body pragma desirable
371 if Ekind
(Uent
) = E_Package
372 and then Elaborate_Body_Desirable
(Uent
)
374 Write_Info_Str
(" BD");
377 -- Add BN parameter if body needed for SAL
379 if (Is_Subprogram
(Uent
)
380 or else Ekind
(Uent
) = E_Package
381 or else Is_Generic_Unit
(Uent
))
382 and then Body_Needed_For_SAL
(Uent
)
384 Write_Info_Str
(" BN");
387 if Dynamic_Elab
(Unit_Num
) then
388 Write_Info_Str
(" DE");
391 -- Set the Elaborate_Body indication if either an explicit pragma
392 -- was present, or if this is an instantiation.
394 if Has_Pragma_Elaborate_Body
(Uent
)
395 or else (Ukind
= N_Package_Declaration
396 and then Is_Generic_Instance
(Uent
)
397 and then Present
(Corresponding_Body
(Unit
(Unode
))))
399 Write_Info_Str
(" EB");
402 -- Now see if we should tell the binder that an elaboration entity
403 -- is present, which must be set to true during elaboration.
404 -- We generate the indication if the following condition is met:
406 -- If this is a spec ...
408 if (Is_Subprogram
(Uent
)
410 Ekind
(Uent
) = E_Package
412 Is_Generic_Unit
(Uent
))
414 -- and an elaboration entity was declared ...
416 and then Present
(Elaboration_Entity
(Uent
))
418 -- and either the elaboration flag is required ...
421 (Elaboration_Entity_Required
(Uent
)
423 -- or this unit has elaboration code ...
425 or else not Has_No_Elaboration_Code
(Unode
)
427 -- or this unit has a separate body and this
428 -- body has elaboration code.
431 (Ekind
(Uent
) = E_Package
432 and then Present
(Body_Entity
(Uent
))
434 not Has_No_Elaboration_Code
437 (Body_Entity
(Uent
))))))
439 if Convention
(Uent
) = Convention_CIL
then
441 -- Special case for generic CIL packages which never have
444 Write_Info_Str
(" NE");
447 Write_Info_Str
(" EE");
451 if Has_No_Elaboration_Code
(Unode
) then
452 Write_Info_Str
(" NE");
455 Write_Info_Str
(" O");
456 Write_Info_Char
(OA_Setting
(Unit_Num
));
458 if Is_Preelaborated
(Uent
) then
459 Write_Info_Str
(" PR");
462 if Is_Pure
(Uent
) then
463 Write_Info_Str
(" PU");
466 if Has_RACW
(Unit_Num
) then
467 Write_Info_Str
(" RA");
470 if Is_Remote_Call_Interface
(Uent
) then
471 Write_Info_Str
(" RC");
474 if Is_Remote_Types
(Uent
) then
475 Write_Info_Str
(" RT");
478 if Is_Shared_Passive
(Uent
) then
479 Write_Info_Str
(" SP");
482 if Ukind
= N_Subprogram_Declaration
483 or else Ukind
= N_Subprogram_Body
485 Write_Info_Str
(" SU");
487 elsif Ukind
= N_Package_Declaration
489 Ukind
= N_Package_Body
491 -- If this is a wrapper package for a subprogram instantiation,
492 -- the user view is the subprogram. Note that in this case the
493 -- ali file contains both the spec and body of the instance.
495 if Is_Wrapper_Package
(Uent
) then
496 Write_Info_Str
(" SU");
498 Write_Info_Str
(" PK");
501 elsif Ukind
= N_Generic_Package_Declaration
then
502 Write_Info_Str
(" PK");
506 if Ukind
in N_Generic_Declaration
508 (Present
(Library_Unit
(Unode
))
510 Nkind
(Unit
(Library_Unit
(Unode
))) in N_Generic_Declaration
)
512 Write_Info_Str
(" GE");
515 if not Is_Internal_File_Name
(Unit_File_Name
(Unit_Num
), True) then
516 case Identifier_Casing
(Source_Index
(Unit_Num
)) is
517 when All_Lower_Case
=> Write_Info_Str
(" IL");
518 when All_Upper_Case
=> Write_Info_Str
(" IU");
522 case Keyword_Casing
(Source_Index
(Unit_Num
)) is
523 when Mixed_Case
=> Write_Info_Str
(" KM");
524 when All_Upper_Case
=> Write_Info_Str
(" KU");
529 if Initialize_Scalars
or else Invalid_Value_Used
then
530 Write_Info_Str
(" IS");
535 -- Generate with lines, first those that are directly with'ed
537 for J
in With_Flags
'Range loop
538 With_Flags
(J
) := False;
539 Elab_Flags
(J
) := False;
540 Elab_All_Flags
(J
) := False;
541 Elab_Des_Flags
(J
) := False;
542 Elab_All_Des_Flags
(J
) := False;
545 Collect_Withs
(Unode
);
547 -- For a body, we must also check for any subunits which belong to
548 -- it and which have context clauses of their own, since these
549 -- with'ed units are part of its own elaboration dependencies.
551 if Nkind
(Unit
(Unode
)) in N_Unit_Body
then
552 for S
in Units
.First
.. Last_Unit
loop
554 -- We are only interested in subunits.
555 -- For preproc. data and def. files, Cunit is Empty, so
556 -- we need to test that first.
558 if Cunit
(S
) /= Empty
559 and then Nkind
(Unit
(Cunit
(S
))) = N_Subunit
561 Pnode
:= Library_Unit
(Cunit
(S
));
563 -- In gnatc mode, the errors in the subunits will not
564 -- have been recorded, but the analysis of the subunit
565 -- may have failed. There is no information to add to
566 -- ALI file in this case.
572 -- Find ultimate parent of the subunit
574 while Nkind
(Unit
(Pnode
)) = N_Subunit
loop
575 Pnode
:= Library_Unit
(Pnode
);
578 -- See if it belongs to current unit, and if so, include
581 if Pnode
= Unode
then
582 Collect_Withs
(Cunit
(S
));
590 -- Output linker option lines
592 for J
in 1 .. Linker_Option_Lines
.Last
loop
594 S
: constant Linker_Option_Entry
:=
595 Linker_Option_Lines
.Table
(J
);
599 if S
.Unit
= Unit_Num
then
600 Write_Info_Initiate
('L');
601 Write_Info_Str
(" """);
603 for J
in 1 .. String_Length
(S
.Option
) loop
604 C
:= Get_Character
(Get_String_Char
(S
.Option
, J
));
606 if C
in Character'Val (16#
20#
) .. Character'Val (16#
7E#
)
617 Hex
: constant array (0 .. 15) of Character :=
621 Write_Info_Char
('{');
622 Write_Info_Char
(Hex
(Character'Pos (C
) / 16));
623 Write_Info_Char
(Hex
(Character'Pos (C
) mod 16));
624 Write_Info_Char
('}');
629 Write_Info_Char
('"');
634 end Write_Unit_Information
;
636 ----------------------
637 -- Write_With_Lines --
638 ----------------------
640 procedure Write_With_Lines
is
641 With_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 1));
642 Num_Withs
: Int
:= 0;
643 Unum
: Unit_Number_Type
;
645 Uname
: Unit_Name_Type
;
646 Fname
: File_Name_Type
;
647 Pname
: constant Unit_Name_Type
:=
648 Get_Parent_Spec_Name
(Unit_Name
(Main_Unit
));
649 Body_Fname
: File_Name_Type
;
652 procedure Write_With_File_Names
653 (Nam
: in out File_Name_Type
;
655 -- Write source file name Nam and ALI file name for unit index Idx.
656 -- Possibly change Nam to lowercase (generating a new file name).
658 --------------------------
659 -- Write_With_File_Name --
660 --------------------------
662 procedure Write_With_File_Names
663 (Nam
: in out File_Name_Type
;
667 if not File_Names_Case_Sensitive
then
668 Get_Name_String
(Nam
);
669 To_Lower
(Name_Buffer
(1 .. Name_Len
));
673 Write_Info_Name
(Nam
);
675 Write_Info_Name
(Lib_File_Name
(Nam
, Idx
));
676 end Write_With_File_Names
;
678 -- Start of processing for Write_With_Lines
681 -- Loop to build the with table. A with on the main unit itself
682 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
683 -- the main unit is a subprogram with no spec, and a subunit of
684 -- it unnecessarily withs the parent.
686 for J
in Units
.First
+ 1 .. Last_Unit
loop
688 -- Add element to with table if it is with'ed or if it is the
689 -- parent spec of the main unit (case of main unit is a child
690 -- unit). The latter with is not needed for semantic purposes,
691 -- but is required by the binder for elaboration purposes.
692 -- For preproc. data and def. files, there is no Unit_Name,
693 -- check for that first.
695 if Unit_Name
(J
) /= No_Unit_Name
696 and then (With_Flags
(J
) or else Unit_Name
(J
) = Pname
)
698 Num_Withs
:= Num_Withs
+ 1;
699 With_Table
(Num_Withs
) := J
;
703 -- Sort and output the table
705 Sort
(With_Table
(1 .. Num_Withs
));
707 for J
in 1 .. Num_Withs
loop
708 Unum
:= With_Table
(J
);
709 Cunit
:= Units
.Table
(Unum
).Cunit
;
710 Uname
:= Units
.Table
(Unum
).Unit_Name
;
711 Fname
:= Units
.Table
(Unum
).Unit_File_Name
;
713 if Ekind
(Cunit_Entity
(Unum
)) = E_Package
714 and then From_With_Type
(Cunit_Entity
(Unum
))
716 Write_Info_Initiate
('Y');
718 Write_Info_Initiate
('W');
721 Write_Info_Char
(' ');
722 Write_Info_Name
(Uname
);
724 -- Now we need to figure out the names of the files that contain
725 -- the with'ed unit. These will usually be the files for the body,
726 -- except in the case of a package that has no body. Note that we
727 -- have a specific exemption here for predefined library generics
728 -- (see comments for Generic_May_Lack_ALI). We do not generate
729 -- dependency upon the ALI file for such units. Older compilers
730 -- used to not support generating code (and ALI) for generics, and
731 -- we want to avoid having different processing (namely, different
732 -- lists of files to be compiled) for different stages of the
735 if not ((Nkind
(Unit
(Cunit
)) in N_Generic_Declaration
737 Nkind
(Unit
(Cunit
)) in N_Generic_Renaming_Declaration
)
738 and then Generic_May_Lack_ALI
(Fname
))
742 if Is_Spec_Name
(Uname
) then
745 (Get_Body_Name
(Uname
),
746 Subunit
=> False, May_Fail
=> True);
750 (Get_Body_Name
(Uname
));
752 if Body_Fname
= No_File
then
753 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
754 Body_Index
:= Get_Unit_Index
(Uname
);
758 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
759 Body_Index
:= Get_Unit_Index
(Uname
);
762 -- A package is considered to have a body if it requires
763 -- a body or if a body is present in Ada 83 mode.
765 if Body_Required
(Cunit
)
766 or else (Ada_Version
= Ada_83
767 and then Full_Source_Name
(Body_Fname
) /= No_File
)
769 Write_With_File_Names
(Body_Fname
, Body_Index
);
771 Write_With_File_Names
(Fname
, Munit_Index
(Unum
));
774 if Ekind
(Cunit_Entity
(Unum
)) = E_Package
775 and then From_With_Type
(Cunit_Entity
(Unum
))
779 if Elab_Flags
(Unum
) then
780 Write_Info_Str
(" E");
783 if Elab_All_Flags
(Unum
) then
784 Write_Info_Str
(" EA");
787 if Elab_Des_Flags
(Unum
) then
788 Write_Info_Str
(" ED");
791 if Elab_All_Des_Flags
(Unum
) then
792 Write_Info_Str
(" AD");
799 end Write_With_Lines
;
801 -- Start of processing for Write_ALI
804 -- We never write an ALI file if the original operating mode was
805 -- syntax-only (-gnats switch used in compiler invocation line)
807 if Original_Operating_Mode
= Check_Syntax
808 or flag_compare_debug
/= 0
813 -- Build sorted source dependency table. We do this right away,
814 -- because it is referenced by Up_To_Date_ALI_File_Exists.
816 for Unum
in Units
.First
.. Last_Unit
loop
817 if Cunit_Entity
(Unum
) = Empty
818 or else not From_With_Type
(Cunit_Entity
(Unum
))
820 Num_Sdep
:= Num_Sdep
+ 1;
821 Sdep_Table
(Num_Sdep
) := Unum
;
825 -- Sort the table so that the D lines are in order
827 Lib
.Sort
(Sdep_Table
(1 .. Num_Sdep
));
829 -- If we are not generating code, and there is an up to date
830 -- ali file accessible, read it, and acquire the compilation
831 -- arguments from this file.
833 if Operating_Mode
/= Generate_Code
then
834 if Up_To_Date_ALI_File_Exists
then
835 Update_Tables_From_ALI_File
;
840 -- Otherwise acquire compilation arguments and prepare to write
841 -- out a new ali file.
843 Create_Output_Library_Info
;
845 -- Output version line
847 Write_Info_Initiate
('V');
848 Write_Info_Str
(" """);
849 Write_Info_Str
(Verbose_Library_Version
);
850 Write_Info_Char
('"');
854 -- Output main program line if this is acceptable main program
856 Output_Main_Program_Line
: declare
857 U
: Node_Id
:= Unit
(Units
.Table
(Main_Unit
).Cunit
);
860 procedure M_Parameters
;
861 -- Output parameters for main program line
867 procedure M_Parameters
is
869 if Main_Priority
(Main_Unit
) /= Default_Main_Priority
then
870 Write_Info_Char
(' ');
871 Write_Info_Nat
(Main_Priority
(Main_Unit
));
874 if Opt
.Time_Slice_Set
then
875 Write_Info_Str
(" T=");
876 Write_Info_Nat
(Opt
.Time_Slice_Value
);
879 Write_Info_Str
(" W=");
881 (WC_Encoding_Letters
(Wide_Character_Encoding_Method
));
886 -- Start of processing for Output_Main_Program_Line
889 if Nkind
(U
) = N_Subprogram_Body
891 (Nkind
(U
) = N_Package_Body
893 Nkind
(Original_Node
(U
)) in N_Subprogram_Instantiation
)
895 -- If the unit is a subprogram instance, the entity for the
896 -- subprogram is the alias of the visible entity, which is the
897 -- related instance of the wrapper package. We retrieve the
898 -- subprogram declaration of the desired entity.
900 if Nkind
(U
) = N_Package_Body
then
901 U
:= Parent
(Parent
(
902 Alias
(Related_Instance
(Defining_Unit_Name
903 (Specification
(Unit
(Library_Unit
(Parent
(U
)))))))));
906 S
:= Specification
(U
);
908 if No
(Parameter_Specifications
(S
)) then
909 if Nkind
(S
) = N_Procedure_Specification
then
910 Write_Info_Initiate
('M');
911 Write_Info_Str
(" P");
916 Nam
: Node_Id
:= Defining_Unit_Name
(S
);
919 -- If it is a child unit, get its simple name
921 if Nkind
(Nam
) = N_Defining_Program_Unit_Name
then
922 Nam
:= Defining_Identifier
(Nam
);
925 if Is_Integer_Type
(Etype
(Nam
)) then
926 Write_Info_Initiate
('M');
927 Write_Info_Str
(" F");
934 end Output_Main_Program_Line
;
936 -- Write command argument ('A') lines
938 for A
in 1 .. Compilation_Switches
.Last
loop
939 Write_Info_Initiate
('A');
940 Write_Info_Char
(' ');
941 Write_Info_Str
(Compilation_Switches
.Table
(A
).all);
942 Write_Info_Terminate
;
945 -- Output parameters ('P') line
947 Write_Info_Initiate
('P');
949 if Compilation_Errors
then
950 Write_Info_Str
(" CE");
953 if Opt
.Detect_Blocking
then
954 Write_Info_Str
(" DB");
957 if Opt
.Float_Format
/= ' ' then
958 Write_Info_Str
(" F");
960 if Opt
.Float_Format
= 'I' then
961 Write_Info_Char
('I');
963 elsif Opt
.Float_Format_Long
= 'D' then
964 Write_Info_Char
('D');
967 Write_Info_Char
('G');
972 and then not Is_Predefined_File_Name
(Unit_File_Name
(Main_Unit
))
974 if Locking_Policy
/= ' ' then
975 Write_Info_Str
(" L");
976 Write_Info_Char
(Locking_Policy
);
979 if Queuing_Policy
/= ' ' then
980 Write_Info_Str
(" Q");
981 Write_Info_Char
(Queuing_Policy
);
984 if Task_Dispatching_Policy
/= ' ' then
985 Write_Info_Str
(" T");
986 Write_Info_Char
(Task_Dispatching_Policy
);
987 Write_Info_Char
(' ');
992 Write_Info_Str
(" NO");
995 if No_Run_Time_Mode
then
996 Write_Info_Str
(" NR");
999 if Normalize_Scalars
then
1000 Write_Info_Str
(" NS");
1003 if Sec_Stack_Used
then
1004 Write_Info_Str
(" SS");
1007 if Unreserve_All_Interrupts
then
1008 Write_Info_Str
(" UA");
1011 if Exception_Mechanism
= Back_End_Exceptions
then
1012 Write_Info_Str
(" ZX");
1017 -- Before outputting the restrictions line, update the setting of
1018 -- the No_Elaboration_Code flag. Violations of this restriction
1019 -- cannot be detected until after the backend has been called since
1020 -- it is the backend that sets this flag. We have to check all units
1021 -- for which we have generated code
1023 for Unit
in Units
.First
.. Last_Unit
loop
1024 if Units
.Table
(Unit
).Generate_Code
1025 or else Unit
= Main_Unit
1027 if not Has_No_Elaboration_Code
(Cunit
(Unit
)) then
1028 Main_Restrictions
.Violated
(No_Elaboration_Code
) := True;
1033 -- Output first restrictions line
1035 Write_Info_Initiate
('R');
1036 Write_Info_Char
(' ');
1038 -- First the information for the boolean restrictions
1040 for R
in All_Boolean_Restrictions
loop
1041 if Main_Restrictions
.Set
(R
)
1042 and then not Restriction_Warnings
(R
)
1044 Write_Info_Char
('r');
1045 elsif Main_Restrictions
.Violated
(R
) then
1046 Write_Info_Char
('v');
1048 Write_Info_Char
('n');
1052 -- And now the information for the parameter restrictions
1054 for RP
in All_Parameter_Restrictions
loop
1055 if Main_Restrictions
.Set
(RP
)
1056 and then not Restriction_Warnings
(RP
)
1058 Write_Info_Char
('r');
1059 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1061 Write_Info_Char
('n');
1064 if not Main_Restrictions
.Violated
(RP
)
1065 or else RP
not in Checked_Parameter_Restrictions
1067 Write_Info_Char
('n');
1069 Write_Info_Char
('v');
1070 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1072 if Main_Restrictions
.Unknown
(RP
) then
1073 Write_Info_Char
('+');
1080 -- Output R lines for No_Dependence entries
1082 for J
in No_Dependence
.First
.. No_Dependence
.Last
loop
1083 if In_Extended_Main_Source_Unit
(No_Dependence
.Table
(J
).Unit
)
1084 and then not No_Dependence
.Table
(J
).Warn
1086 Write_Info_Initiate
('R');
1087 Write_Info_Char
(' ');
1088 Write_Unit_Name
(No_Dependence
.Table
(J
).Unit
);
1093 -- Output interrupt state lines
1095 for J
in Interrupt_States
.First
.. Interrupt_States
.Last
loop
1096 Write_Info_Initiate
('I');
1097 Write_Info_Char
(' ');
1098 Write_Info_Nat
(Interrupt_States
.Table
(J
).Interrupt_Number
);
1099 Write_Info_Char
(' ');
1100 Write_Info_Char
(Interrupt_States
.Table
(J
).Interrupt_State
);
1101 Write_Info_Char
(' ');
1103 (Nat
(Get_Logical_Line_Number
1104 (Interrupt_States
.Table
(J
).Pragma_Loc
)));
1108 -- Output priority specific dispatching lines
1110 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
1111 Write_Info_Initiate
('S');
1112 Write_Info_Char
(' ');
1113 Write_Info_Char
(Specific_Dispatching
.Table
(J
).Dispatching_Policy
);
1114 Write_Info_Char
(' ');
1115 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).First_Priority
);
1116 Write_Info_Char
(' ');
1117 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).Last_Priority
);
1118 Write_Info_Char
(' ');
1120 (Nat
(Get_Logical_Line_Number
1121 (Specific_Dispatching
.Table
(J
).Pragma_Loc
)));
1125 -- Loop through file table to output information for all units for which
1126 -- we have generated code, as marked by the Generate_Code flag.
1128 for Unit
in Units
.First
.. Last_Unit
loop
1129 if Units
.Table
(Unit
).Generate_Code
1130 or else Unit
= Main_Unit
1132 Write_Info_EOL
; -- blank line
1133 Write_Unit_Information
(Unit
);
1137 Write_Info_EOL
; -- blank line
1139 -- Output external version reference lines
1141 for J
in 1 .. Version_Ref
.Last
loop
1142 Write_Info_Initiate
('E');
1143 Write_Info_Char
(' ');
1145 for K
in 1 .. String_Length
(Version_Ref
.Table
(J
)) loop
1146 Write_Info_Char_Code
(Get_String_Char
(Version_Ref
.Table
(J
), K
));
1152 -- Prepare to output the source dependency lines
1155 Unum
: Unit_Number_Type
;
1156 -- Number of unit being output
1158 Sind
: Source_File_Index
;
1159 -- Index of corresponding source file
1161 Fname
: File_Name_Type
;
1164 for J
in 1 .. Num_Sdep
loop
1165 Unum
:= Sdep_Table
(J
);
1166 Units
.Table
(Unum
).Dependency_Num
:= J
;
1167 Sind
:= Units
.Table
(Unum
).Source_Index
;
1169 Write_Info_Initiate
('D');
1170 Write_Info_Char
(' ');
1172 -- Normal case of a unit entry with a source index
1174 if Sind
/= No_Source_File
then
1175 Fname
:= File_Name
(Sind
);
1177 -- Ensure that on platforms where the file names are not
1178 -- case sensitive, the recorded file name is in lower case.
1180 if not File_Names_Case_Sensitive
then
1181 Get_Name_String
(Fname
);
1182 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1186 Write_Info_Name
(Fname
);
1187 Write_Info_Tab
(25);
1188 Write_Info_Str
(String (Time_Stamp
(Sind
)));
1189 Write_Info_Char
(' ');
1190 Write_Info_Str
(Get_Hex_String
(Source_Checksum
(Sind
)));
1192 -- If subunit, add unit name, omitting the %b at the end
1194 if Present
(Cunit
(Unum
))
1195 and then Nkind
(Unit
(Cunit
(Unum
))) = N_Subunit
1197 Get_Decoded_Name_String
(Unit_Name
(Unum
));
1198 Write_Info_Char
(' ');
1199 Write_Info_Str
(Name_Buffer
(1 .. Name_Len
- 2));
1202 -- If Source_Reference pragma used output information
1204 if Num_SRef_Pragmas
(Sind
) > 0 then
1205 Write_Info_Char
(' ');
1207 if Num_SRef_Pragmas
(Sind
) = 1 then
1208 Write_Info_Nat
(Int
(First_Mapped_Line
(Sind
)));
1213 Write_Info_Char
(':');
1214 Write_Info_Name
(Reference_Name
(Sind
));
1217 -- Case where there is no source index (happens for missing
1218 -- files). In this case we write a dummy time stamp.
1221 Write_Info_Name
(Unit_File_Name
(Unum
));
1222 Write_Info_Tab
(25);
1223 Write_Info_Str
(String (Dummy_Time_Stamp
));
1224 Write_Info_Char
(' ');
1225 Write_Info_Str
(Get_Hex_String
(0));
1233 Write_Info_Terminate
;
1234 Close_Output_Library_Info
;
1237 ---------------------
1238 -- Write_Unit_Name --
1239 ---------------------
1241 procedure Write_Unit_Name
(N
: Node_Id
) is
1243 if Nkind
(N
) = N_Identifier
then
1244 Write_Info_Name
(Chars
(N
));
1247 pragma Assert
(Nkind
(N
) = N_Selected_Component
);
1248 Write_Unit_Name
(Prefix
(N
));
1249 Write_Info_Char
('.');
1250 Write_Unit_Name
(Selector_Name
(N
));
1252 end Write_Unit_Name
;