1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with Atree; use Atree;
29 with Casing; use Casing;
30 with Einfo; use Einfo;
31 with Errout; use Errout;
32 with Fname; use Fname;
33 with Fname.UF; use Fname.UF;
34 with Lib.Util; use Lib.Util;
35 with Lib.Xref; use Lib.Xref;
36 with Namet; use Namet;
37 with Nlists; use Nlists;
38 with Gnatvsn; use Gnatvsn;
40 with Osint; use Osint;
41 with Osint.C; use Osint.C;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
46 with Sinfo; use Sinfo;
47 with Sinput; use Sinput;
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),
75 Expected_Unit => No_Name,
78 Cunit_Entity => Empty,
80 Dynamic_Elab => False,
82 Generate_Code => 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 Ident_String => Empty,
143 Error_Location => No_Location);
145 -- Parse system.ads so that the checksum is set right
146 -- Style checks are not applied.
149 Save_Mindex : constant Nat := Multiple_Unit_Index;
150 Save_Style : constant Boolean := Style_Check;
152 Multiple_Unit_Index := 0;
153 Style_Check := False;
154 Initialize_Scanner (Units.Last, System_Source_File_Index);
155 Discard_List (Par (Configuration_Pragmas => False));
156 Style_Check := Save_Style;
157 Multiple_Unit_Index := Save_Mindex;
159 end Ensure_System_Dependency;
165 procedure Write_ALI (Object : Boolean) is
171 Last_Unit : constant Unit_Number_Type := Units.Last;
172 -- Record unit number of last unit. We capture this in case we
173 -- have to add a dummy entry to the unit table for package System.
175 With_Flags : array (Units.First .. Last_Unit) of Boolean;
176 -- Array of flags to show which units are with'ed
178 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
179 -- Array of flags to show which units have pragma Elaborate set
181 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
182 -- Array of flags to show which units have pragma Elaborate All set
184 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
185 -- Array of flags to show which units have Elaborate_All_Desirable set
187 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
188 -- Sorted table of source dependencies. One extra entry in case we
189 -- have to add a dummy entry for System.
192 -- Number of active entries in Sdep_Table
194 -----------------------
195 -- Local Subprograms --
196 -----------------------
198 procedure Collect_Withs (Cunit : Node_Id);
199 -- Collect with lines for entries in the context clause of the
200 -- given compilation unit, Cunit.
202 procedure Update_Tables_From_ALI_File;
203 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
204 -- function), update tables from the ALI information, including
205 -- specifically the Compilation_Switches table.
207 function Up_To_Date_ALI_File_Exists return Boolean;
208 -- If there exists an ALI file that is up to date, then this function
209 -- initializes the tables in the ALI spec to contain information on
210 -- this file (using Scan_ALI) and returns True. If no file exists,
211 -- or the file is not up to date, then False is returned.
213 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
214 -- Write out the library information for one unit for which code is
215 -- generated (includes unit line and with lines).
217 procedure Write_With_Lines;
218 -- Write out with lines collected by calls to Collect_Withs
224 procedure Collect_Withs (Cunit : Node_Id) is
226 Unum : Unit_Number_Type;
229 Item := First (Context_Items (Cunit));
230 while Present (Item) loop
232 -- Ada 2005 (AI-50217): limited with_clauses do not create
235 if Nkind (Item) = N_With_Clause
236 and then not (Limited_Present (Item))
238 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
239 With_Flags (Unum) := True;
241 if Elaborate_Present (Item) then
242 Elab_Flags (Unum) := True;
245 if Elaborate_All_Present (Item) then
246 Elab_All_Flags (Unum) := True;
249 if Elaborate_All_Desirable (Cunit_Entity (Unum)) then
250 Elab_Des_Flags (Unum) := True;
258 --------------------------------
259 -- Up_To_Date_ALI_File_Exists --
260 --------------------------------
262 function Up_To_Date_ALI_File_Exists return Boolean is
263 Name : File_Name_Type;
264 Text : Text_Buffer_Ptr;
266 Sind : Source_File_Index;
269 Opt.Check_Object_Consistency := True;
270 Read_Library_Info (Name, Text);
272 -- Return if we could not find an ALI file
278 -- Return if ALI file has bad format
282 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
286 -- If we have an OK ALI file, check if it is up to date
287 -- Note that we assume that the ALI read has all the entries
288 -- we have in our table, plus some additional ones (that can
289 -- come from expansion).
291 Id := First_Sdep_Entry;
292 for J in 1 .. Num_Sdep loop
293 Sind := Units.Table (Sdep_Table (J)).Source_Index;
295 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
296 if Id = Sdep.Last then
303 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
309 end Up_To_Date_ALI_File_Exists;
311 ---------------------------------
312 -- Update_Tables_From_ALI_File --
313 ---------------------------------
315 procedure Update_Tables_From_ALI_File is
317 -- Build Compilation_Switches table
319 Compilation_Switches.Init;
321 for J in First_Arg_Entry .. Args.Last loop
322 Compilation_Switches.Increment_Last;
323 Compilation_Switches.Table (Compilation_Switches.Last) :=
326 end Update_Tables_From_ALI_File;
328 ----------------------------
329 -- Write_Unit_Information --
330 ----------------------------
332 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
333 Unode : constant Node_Id := Cunit (Unit_Num);
334 Ukind : constant Node_Kind := Nkind (Unit (Unode));
335 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
339 Write_Info_Initiate ('U');
340 Write_Info_Char (' ');
341 Write_Info_Name (Unit_Name (Unit_Num));
343 Write_Info_Name (Unit_File_Name (Unit_Num));
346 Write_Info_Str (Version_Get (Unit_Num));
348 if (Is_Subprogram (Uent)
349 or else Ekind (Uent) = E_Package
350 or else Is_Generic_Unit (Uent))
351 and then Body_Needed_For_SAL (Uent)
353 Write_Info_Str (" BN");
356 if Dynamic_Elab (Unit_Num) then
357 Write_Info_Str (" DE");
360 -- We set the Elaborate_Body indication if either an explicit pragma
361 -- was present, or if this is an instantiation. RM 12.3(20) requires
362 -- that the body be immediately elaborated after the spec. We would
363 -- normally do that anyway, but the EB we generate here ensures that
364 -- this gets done even when we use the -p gnatbind switch.
366 if Has_Pragma_Elaborate_Body (Uent)
367 or else (Ukind = N_Package_Declaration
368 and then Is_Generic_Instance (Uent)
369 and then Present (Corresponding_Body (Unit (Unode))))
371 Write_Info_Str (" EB");
374 -- Now see if we should tell the binder that an elaboration entity
375 -- is present, which must be reset to true during elaboration. We
376 -- generate the indication if the following condition is met:
378 -- If this is a spec ...
380 if (Is_Subprogram (Uent)
382 Ekind (Uent) = E_Package
384 Is_Generic_Unit (Uent))
386 -- and an elaboration entity was declared ...
388 and then Present (Elaboration_Entity (Uent))
390 -- and either the elaboration flag is required ...
393 (Elaboration_Entity_Required (Uent)
395 -- or this unit has elaboration code ...
397 or else not Has_No_Elaboration_Code (Unode)
399 -- or this unit has a separate body and this
400 -- body has elaboration code.
403 (Ekind (Uent) = E_Package
404 and then Present (Body_Entity (Uent))
406 not Has_No_Elaboration_Code
409 (Body_Entity (Uent))))))
411 Write_Info_Str (" EE");
414 if Has_No_Elaboration_Code (Unode) then
415 Write_Info_Str (" NE");
418 if Is_Preelaborated (Uent) then
419 Write_Info_Str (" PR");
422 if Is_Pure (Uent) then
423 Write_Info_Str (" PU");
426 if Has_RACW (Unit_Num) then
427 Write_Info_Str (" RA");
430 if Is_Remote_Call_Interface (Uent) then
431 Write_Info_Str (" RC");
434 if Is_Remote_Types (Uent) then
435 Write_Info_Str (" RT");
438 if Is_Shared_Passive (Uent) then
439 Write_Info_Str (" SP");
442 if Ukind = N_Subprogram_Declaration
443 or else Ukind = N_Subprogram_Body
445 Write_Info_Str (" SU");
447 elsif Ukind = N_Package_Declaration
449 Ukind = N_Package_Body
451 -- If this is a wrapper package for a subprogram instantiation,
452 -- the user view is the subprogram. Note that in this case the
453 -- ali file contains both the spec and body of the instance.
455 if Is_Wrapper_Package (Uent) then
456 Write_Info_Str (" SU");
458 Write_Info_Str (" PK");
461 elsif Ukind = N_Generic_Package_Declaration then
462 Write_Info_Str (" PK");
466 if Ukind in N_Generic_Declaration
468 (Present (Library_Unit (Unode))
470 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
472 Write_Info_Str (" GE");
475 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
476 case Identifier_Casing (Source_Index (Unit_Num)) is
477 when All_Lower_Case => Write_Info_Str (" IL");
478 when All_Upper_Case => Write_Info_Str (" IU");
482 case Keyword_Casing (Source_Index (Unit_Num)) is
483 when Mixed_Case => Write_Info_Str (" KM");
484 when All_Upper_Case => Write_Info_Str (" KU");
489 if Initialize_Scalars then
490 Write_Info_Str (" IS");
495 -- Generate with lines, first those that are directly with'ed
497 for J in With_Flags'Range loop
498 With_Flags (J) := False;
499 Elab_Flags (J) := False;
500 Elab_All_Flags (J) := False;
501 Elab_Des_Flags (J) := False;
504 Collect_Withs (Unode);
506 -- For a body, we must also check for any subunits which belong to
507 -- it and which have context clauses of their own, since these
508 -- with'ed units are part of its own elaboration dependencies.
510 if Nkind (Unit (Unode)) in N_Unit_Body then
511 for S in Units.First .. Last_Unit loop
513 -- We are only interested in subunits.
514 -- For preproc. data and def. files, Cunit is Empty, so
515 -- we need to test that first.
517 if Cunit (S) /= Empty
518 and then Nkind (Unit (Cunit (S))) = N_Subunit
520 Pnode := Library_Unit (Cunit (S));
522 -- In gnatc mode, the errors in the subunits will not
523 -- have been recorded, but the analysis of the subunit
524 -- may have failed. There is no information to add to
525 -- ALI file in this case.
531 -- Find ultimate parent of the subunit
533 while Nkind (Unit (Pnode)) = N_Subunit loop
534 Pnode := Library_Unit (Pnode);
537 -- See if it belongs to current unit, and if so, include
540 if Pnode = Unode then
541 Collect_Withs (Cunit (S));
549 -- Output linker option lines
551 for J in 1 .. Linker_Option_Lines.Last loop
553 S : constant Linker_Option_Entry :=
554 Linker_Option_Lines.Table (J);
558 if S.Unit = Unit_Num then
559 Write_Info_Initiate ('L');
560 Write_Info_Str (" """);
562 for J in 1 .. String_Length (S.Option) loop
563 C := Get_Character (Get_String_Char (S.Option, J));
565 if C in Character'Val (16#20#) .. Character'Val (16#7E#)
576 Hex : constant array (0 .. 15) of Character :=
580 Write_Info_Char ('{');
581 Write_Info_Char (Hex (Character'Pos (C) / 16));
582 Write_Info_Char (Hex (Character'Pos (C) mod 16));
583 Write_Info_Char ('}');
588 Write_Info_Char ('"');
593 end Write_Unit_Information;
595 ----------------------
596 -- Write_With_Lines --
597 ----------------------
599 procedure Write_With_Lines is
600 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
601 Num_Withs : Int := 0;
602 Unum : Unit_Number_Type;
605 Uname : Unit_Name_Type;
606 Fname : File_Name_Type;
607 Pname : constant Unit_Name_Type :=
608 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
609 Body_Fname : File_Name_Type;
613 -- Loop to build the with table. A with on the main unit itself
614 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
615 -- the main unit is a subprogram with no spec, and a subunit of
616 -- it unecessarily withs the parent.
618 for J in Units.First + 1 .. Last_Unit loop
620 -- Add element to with table if it is with'ed or if it is the
621 -- parent spec of the main unit (case of main unit is a child
622 -- unit). The latter with is not needed for semantic purposes,
623 -- but is required by the binder for elaboration purposes.
624 -- For preproc. data and def. files, there is no Unit_Name,
625 -- check for that first.
627 if Unit_Name (J) /= No_Name
628 and then (With_Flags (J) or else Unit_Name (J) = Pname)
630 Num_Withs := Num_Withs + 1;
631 With_Table (Num_Withs) := J;
635 -- Sort and output the table
637 Sort (With_Table (1 .. Num_Withs));
639 for J in 1 .. Num_Withs loop
640 Unum := With_Table (J);
641 Cunit := Units.Table (Unum).Cunit;
642 Cunite := Units.Table (Unum).Cunit_Entity;
643 Uname := Units.Table (Unum).Unit_Name;
644 Fname := Units.Table (Unum).Unit_File_Name;
646 Write_Info_Initiate ('W');
647 Write_Info_Char (' ');
648 Write_Info_Name (Uname);
650 -- Now we need to figure out the names of the files that contain
651 -- the with'ed unit. These will usually be the files for the body,
652 -- except in the case of a package that has no body.
654 if (Nkind (Unit (Cunit)) not in N_Generic_Declaration
656 Nkind (Unit (Cunit)) not in N_Generic_Renaming_Declaration)
657 or else Generic_Separately_Compiled (Cunite)
661 if Is_Spec_Name (Uname) then
664 (Get_Body_Name (Uname),
665 Subunit => False, May_Fail => True);
669 (Get_Body_Name (Uname));
671 if Body_Fname = No_File then
672 Body_Fname := Get_File_Name (Uname, Subunit => False);
673 Body_Index := Get_Unit_Index (Uname);
677 Body_Fname := Get_File_Name (Uname, Subunit => False);
678 Body_Index := Get_Unit_Index (Uname);
681 -- A package is considered to have a body if it requires
682 -- a body or if a body is present in Ada 83 mode.
684 if Body_Required (Cunit)
685 or else (Ada_Version = Ada_83
686 and then Full_Source_Name (Body_Fname) /= No_File)
688 -- Ensure that on platforms where the file names are not
689 -- case sensitive, the recorded file name is in lower case.
691 if not File_Names_Case_Sensitive then
692 Get_Name_String (Body_Fname);
693 To_Lower (Name_Buffer (1 .. Name_Len));
694 Body_Fname := Name_Find;
697 Write_Info_Name (Body_Fname);
700 (Lib_File_Name (Body_Fname, Body_Index));
702 -- Ensure that on platforms where the file names are not
703 -- case sensitive, the recorded file name is in lower case.
705 if not File_Names_Case_Sensitive then
706 Get_Name_String (Fname);
707 To_Lower (Name_Buffer (1 .. Name_Len));
711 Write_Info_Name (Fname);
714 (Lib_File_Name (Fname, Munit_Index (Unum)));
717 if Elab_Flags (Unum) then
718 Write_Info_Str (" E");
721 if Elab_All_Flags (Unum) then
722 Write_Info_Str (" EA");
725 if Elab_Des_Flags (Unum) then
726 Write_Info_Str (" ED");
732 end Write_With_Lines;
734 -- Start of processing for Write_ALI
737 -- We never write an ALI file if the original operating mode was
738 -- syntax-only (-gnats switch used in compiler invocation line)
740 if Original_Operating_Mode = Check_Syntax then
744 -- Build sorted source dependency table. We do this right away,
745 -- because it is referenced by Up_To_Date_ALI_File_Exists.
747 for Unum in Units.First .. Last_Unit loop
748 if Cunit_Entity (Unum) = Empty
749 or else not From_With_Type (Cunit_Entity (Unum))
751 Num_Sdep := Num_Sdep + 1;
752 Sdep_Table (Num_Sdep) := Unum;
756 -- Sort the table so that the D lines are in order
758 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
760 -- If we are not generating code, and there is an up to date
761 -- ali file accessible, read it, and acquire the compilation
762 -- arguments from this file.
764 if Operating_Mode /= Generate_Code then
765 if Up_To_Date_ALI_File_Exists then
766 Update_Tables_From_ALI_File;
771 -- Otherwise acquire compilation arguments and prepare to write
772 -- out a new ali file.
774 Create_Output_Library_Info;
776 -- Output version line
778 Write_Info_Initiate ('V');
779 Write_Info_Str (" """);
780 Write_Info_Str (Verbose_Library_Version);
781 Write_Info_Char ('"');
785 -- Output main program line if this is acceptable main program
787 Output_Main_Program_Line : declare
788 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
791 procedure M_Parameters;
792 -- Output parameters for main program line
798 procedure M_Parameters is
800 if Main_Priority (Main_Unit) /= Default_Main_Priority then
801 Write_Info_Char (' ');
802 Write_Info_Nat (Main_Priority (Main_Unit));
805 if Opt.Time_Slice_Set then
806 Write_Info_Str (" T=");
807 Write_Info_Nat (Opt.Time_Slice_Value);
810 Write_Info_Str (" W=");
812 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
817 -- Start of processing for Output_Main_Program_Line
820 if Nkind (U) = N_Subprogram_Body
821 or else (Nkind (U) = N_Package_Body
823 (Nkind (Original_Node (U)) = N_Function_Instantiation
825 Nkind (Original_Node (U)) =
826 N_Procedure_Instantiation))
828 -- If the unit is a subprogram instance, the entity for the
829 -- subprogram is the alias of the visible entity, which is the
830 -- related instance of the wrapper package. We retrieve the
831 -- subprogram declaration of the desired entity.
833 if Nkind (U) = N_Package_Body then
834 U := Parent (Parent (
835 Alias (Related_Instance (Defining_Unit_Name
836 (Specification (Unit (Library_Unit (Parent (U)))))))));
839 S := Specification (U);
841 if not Present (Parameter_Specifications (S)) then
842 if Nkind (S) = N_Procedure_Specification then
843 Write_Info_Initiate ('M');
844 Write_Info_Str (" P");
849 Nam : Node_Id := Defining_Unit_Name (S);
852 -- If it is a child unit, get its simple name
854 if Nkind (Nam) = N_Defining_Program_Unit_Name then
855 Nam := Defining_Identifier (Nam);
858 if Is_Integer_Type (Etype (Nam)) then
859 Write_Info_Initiate ('M');
860 Write_Info_Str (" F");
867 end Output_Main_Program_Line;
869 -- Write command argmument ('A') lines
871 for A in 1 .. Compilation_Switches.Last loop
872 Write_Info_Initiate ('A');
873 Write_Info_Char (' ');
874 Write_Info_Str (Compilation_Switches.Table (A).all);
875 Write_Info_Terminate;
878 -- Output parameters ('P') line
880 Write_Info_Initiate ('P');
882 if Compilation_Errors then
883 Write_Info_Str (" CE");
886 if Opt.Detect_Blocking then
887 Write_Info_Str (" DB");
890 if Opt.Float_Format /= ' ' then
891 Write_Info_Str (" F");
893 if Opt.Float_Format = 'I' then
894 Write_Info_Char ('I');
896 elsif Opt.Float_Format_Long = 'D' then
897 Write_Info_Char ('D');
900 Write_Info_Char ('G');
905 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
907 if Locking_Policy /= ' ' then
908 Write_Info_Str (" L");
909 Write_Info_Char (Locking_Policy);
912 if Queuing_Policy /= ' ' then
913 Write_Info_Str (" Q");
914 Write_Info_Char (Queuing_Policy);
917 if Task_Dispatching_Policy /= ' ' then
918 Write_Info_Str (" T");
919 Write_Info_Char (Task_Dispatching_Policy);
920 Write_Info_Char (' ');
925 Write_Info_Str (" NO");
928 if No_Run_Time_Mode then
929 Write_Info_Str (" NR");
932 if Normalize_Scalars then
933 Write_Info_Str (" NS");
936 if Sec_Stack_Used then
937 Write_Info_Str (" SS");
940 if Unreserve_All_Interrupts then
941 Write_Info_Str (" UA");
944 if Exception_Mechanism = Back_End_Exceptions then
945 Write_Info_Str (" ZX");
950 -- Before outputting the restrictions line, update the setting of
951 -- the No_Elaboration_Code flag. Violations of this restriction
952 -- cannot be detected until after the backend has been called since
953 -- it is the backend that sets this flag. We have to check all units
954 -- for which we have generated code
956 for Unit in Units.First .. Last_Unit loop
957 if Units.Table (Unit).Generate_Code
958 or else Unit = Main_Unit
960 if not Has_No_Elaboration_Code (Cunit (Unit)) then
961 Main_Restrictions.Violated (No_Elaboration_Code) := True;
966 -- Output first restrictions line
968 Write_Info_Initiate ('R');
969 Write_Info_Char (' ');
971 -- First the information for the boolean restrictions
973 for R in All_Boolean_Restrictions loop
974 if Main_Restrictions.Set (R)
975 and then not Restriction_Warnings (R)
977 Write_Info_Char ('r');
978 elsif Main_Restrictions.Violated (R) then
979 Write_Info_Char ('v');
981 Write_Info_Char ('n');
985 -- And now the information for the parameter restrictions
987 for RP in All_Parameter_Restrictions loop
988 if Main_Restrictions.Set (RP)
989 and then not Restriction_Warnings (RP)
991 Write_Info_Char ('r');
992 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
994 Write_Info_Char ('n');
997 if not Main_Restrictions.Violated (RP)
998 or else RP not in Checked_Parameter_Restrictions
1000 Write_Info_Char ('n');
1002 Write_Info_Char ('v');
1003 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1005 if Main_Restrictions.Unknown (RP) then
1006 Write_Info_Char ('+');
1013 -- Output R lines for No_Dependence entries
1015 for J in No_Dependence.First .. No_Dependence.Last loop
1016 if In_Extended_Main_Source_Unit (No_Dependence.Table (J).Unit)
1017 and then not No_Dependence.Table (J).Warn
1019 Write_Info_Initiate ('R');
1020 Write_Info_Char (' ');
1021 Write_Unit_Name (No_Dependence.Table (J).Unit);
1026 -- Output interrupt state lines
1028 for J in Interrupt_States.First .. Interrupt_States.Last loop
1029 Write_Info_Initiate ('I');
1030 Write_Info_Char (' ');
1031 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1032 Write_Info_Char (' ');
1033 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1034 Write_Info_Char (' ');
1036 (Nat (Get_Logical_Line_Number
1037 (Interrupt_States.Table (J).Pragma_Loc)));
1041 -- Loop through file table to output information for all units for which
1042 -- we have generated code, as marked by the Generate_Code flag.
1044 for Unit in Units.First .. Last_Unit loop
1045 if Units.Table (Unit).Generate_Code
1046 or else Unit = Main_Unit
1048 Write_Info_EOL; -- blank line
1049 Write_Unit_Information (Unit);
1053 Write_Info_EOL; -- blank line
1055 -- Output external version reference lines
1057 for J in 1 .. Version_Ref.Last loop
1058 Write_Info_Initiate ('E');
1059 Write_Info_Char (' ');
1061 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1062 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1068 -- Prepare to output the source dependency lines
1071 Unum : Unit_Number_Type;
1072 -- Number of unit being output
1074 Sind : Source_File_Index;
1075 -- Index of corresponding source file
1077 Fname : File_Name_Type;
1080 for J in 1 .. Num_Sdep loop
1081 Unum := Sdep_Table (J);
1082 Units.Table (Unum).Dependency_Num := J;
1083 Sind := Units.Table (Unum).Source_Index;
1085 Write_Info_Initiate ('D');
1086 Write_Info_Char (' ');
1088 -- Normal case of a unit entry with a source index
1090 if Sind /= No_Source_File then
1091 Fname := File_Name (Sind);
1093 -- Ensure that on platforms where the file names are not
1094 -- case sensitive, the recorded file name is in lower case.
1096 if not File_Names_Case_Sensitive then
1097 Get_Name_String (Fname);
1098 To_Lower (Name_Buffer (1 .. Name_Len));
1102 Write_Info_Name (Fname);
1103 Write_Info_Tab (25);
1104 Write_Info_Str (String (Time_Stamp (Sind)));
1105 Write_Info_Char (' ');
1106 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1108 -- If subunit, add unit name, omitting the %b at the end
1110 if Present (Cunit (Unum))
1111 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1113 Get_Decoded_Name_String (Unit_Name (Unum));
1114 Write_Info_Char (' ');
1115 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1118 -- If Source_Reference pragma used output information
1120 if Num_SRef_Pragmas (Sind) > 0 then
1121 Write_Info_Char (' ');
1123 if Num_SRef_Pragmas (Sind) = 1 then
1124 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1129 Write_Info_Char (':');
1130 Write_Info_Name (Reference_Name (Sind));
1133 -- Case where there is no source index (happens for missing
1134 -- files). In this case we write a dummy time stamp.
1137 Write_Info_Name (Unit_File_Name (Unum));
1138 Write_Info_Tab (25);
1139 Write_Info_Str (String (Dummy_Time_Stamp));
1140 Write_Info_Char (' ');
1141 Write_Info_Str (Get_Hex_String (0));
1149 Write_Info_Terminate;
1150 Close_Output_Library_Info;
1153 ---------------------
1154 -- Write_Unit_Name --
1155 ---------------------
1157 procedure Write_Unit_Name (N : Node_Id) is
1159 if Nkind (N) = N_Identifier then
1160 Write_Info_Name (Chars (N));
1163 pragma Assert (Nkind (N) = N_Selected_Component);
1164 Write_Unit_Name (Prefix (N));
1165 Write_Info_Char ('.');
1166 Write_Unit_Name (Selector_Name (N));
1168 end Write_Unit_Name;