1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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;
45 with Sinfo; use Sinfo;
46 with Sinput; use Sinput;
47 with Stringt; use Stringt;
48 with Tbuild; use Tbuild;
49 with Uname; use Uname;
51 with System.WCh_Con; use System.WCh_Con;
53 package body Lib.Writ is
55 ----------------------------------
56 -- Add_Preprocessing_Dependency --
57 ----------------------------------
59 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
62 Units.Table (Units.Last) :=
63 (Unit_File_Name => File_Name (S),
65 Expected_Unit => No_Name,
68 Cunit_Entity => Empty,
70 Dependent_Unit => True,
71 Dynamic_Elab => False,
73 Generate_Code => False,
75 Ident_String => Empty,
80 Error_Location => No_Location);
81 end Add_Preprocessing_Dependency;
83 ------------------------------
84 -- Ensure_System_Dependency --
85 ------------------------------
87 procedure Ensure_System_Dependency is
88 System_Uname : Unit_Name_Type;
89 -- Unit name for system spec if needed for dummy entry
91 System_Fname : File_Name_Type;
92 -- File name for system spec if needed for dummy entry
94 Save_Style : constant Boolean := Style_Check;
97 -- Nothing to do if we already compiled System
99 for Unum in Units.First .. Last_Unit loop
100 if Units.Table (Unum).Source_Index = System_Source_File_Index then
105 -- If no entry for system.ads in the units table, then add a entry
106 -- to the units table for system.ads, which will be referenced when
107 -- the ali file is generated. We need this because every unit depends
108 -- on system as a result of Targparm scanning the system.ads file to
109 -- determine the target dependent parameters for the compilation.
112 Name_Buffer (1 .. 6) := "system";
113 System_Uname := Name_To_Unit_Name (Name_Enter);
114 System_Fname := File_Name (System_Source_File_Index);
116 Units.Increment_Last;
117 Units.Table (Units.Last) := (
118 Unit_File_Name => System_Fname,
119 Unit_Name => System_Uname,
120 Expected_Unit => System_Uname,
121 Source_Index => System_Source_File_Index,
123 Cunit_Entity => Empty,
125 Dependent_Unit => True,
126 Dynamic_Elab => False,
127 Fatal_Error => False,
128 Generate_Code => False,
130 Ident_String => Empty,
135 Error_Location => No_Location);
137 -- Parse system.ads so that the checksum is set right
138 -- Style checks are not applied.
140 Style_Check := False;
141 Initialize_Scanner (Units.Last, System_Source_File_Index);
142 Discard_List (Par (Configuration_Pragmas => False));
143 Style_Check := Save_Style;
144 end Ensure_System_Dependency;
150 procedure Write_ALI (Object : Boolean) is
156 Last_Unit : constant Unit_Number_Type := Units.Last;
157 -- Record unit number of last unit. We capture this in case we
158 -- have to add a dummy entry to the unit table for package System.
160 With_Flags : array (Units.First .. Last_Unit) of Boolean;
161 -- Array of flags to show which units are with'ed
163 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
164 -- Array of flags to show which units have pragma Elaborate set
166 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
167 -- Array of flags to show which units have pragma Elaborate All set
169 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
170 -- Array of flags to show which units have Elaborate_All_Desirable set
172 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
173 -- Sorted table of source dependencies. One extra entry in case we
174 -- have to add a dummy entry for System.
177 -- Number of active entries in Sdep_Table
179 -----------------------
180 -- Local Subprograms --
181 -----------------------
183 procedure Collect_Withs (Cunit : Node_Id);
184 -- Collect with lines for entries in the context clause of the
185 -- given compilation unit, Cunit.
187 procedure Update_Tables_From_ALI_File;
188 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
189 -- function), update tables from the ALI information, including
190 -- specifically the Compilation_Switches table.
192 function Up_To_Date_ALI_File_Exists return Boolean;
193 -- If there exists an ALI file that is up to date, then this function
194 -- initializes the tables in the ALI spec to contain information on
195 -- this file (using Scan_ALI) and returns True. If no file exists,
196 -- or the file is not up to date, then False is returned.
198 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
199 -- Write out the library information for one unit for which code is
200 -- generated (includes unit line and with lines).
202 procedure Write_With_Lines;
203 -- Write out with lines collected by calls to Collect_Withs
209 procedure Collect_Withs (Cunit : Node_Id) is
211 Unum : Unit_Number_Type;
214 Item := First (Context_Items (Cunit));
215 while Present (Item) loop
217 -- limited_with_clauses do not create dependencies.
219 if Nkind (Item) = N_With_Clause
220 and then not (Limited_Present (Item))
222 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
223 With_Flags (Unum) := True;
225 if Elaborate_Present (Item) then
226 Elab_Flags (Unum) := True;
229 if Elaborate_All_Present (Item) then
230 Elab_All_Flags (Unum) := True;
233 if Elaborate_All_Desirable (Cunit_Entity (Unum)) then
234 Elab_Des_Flags (Unum) := True;
242 --------------------------------
243 -- Up_To_Date_ALI_File_Exists --
244 --------------------------------
246 function Up_To_Date_ALI_File_Exists return Boolean is
247 Name : File_Name_Type;
248 Text : Text_Buffer_Ptr;
250 Sind : Source_File_Index;
253 Opt.Check_Object_Consistency := True;
254 Read_Library_Info (Name, Text);
256 -- Return if we could not find an ALI file
262 -- Return if ALI file has bad format
266 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
270 -- If we have an OK ALI file, check if it is up to date
271 -- Note that we assume that the ALI read has all the entries
272 -- we have in our table, plus some additional ones (that can
273 -- come from expansion).
275 Id := First_Sdep_Entry;
276 for J in 1 .. Num_Sdep loop
277 Sind := Units.Table (Sdep_Table (J)).Source_Index;
279 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
280 if Id = Sdep.Last then
287 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
293 end Up_To_Date_ALI_File_Exists;
295 ---------------------------------
296 -- Update_Tables_From_ALI_File --
297 ---------------------------------
299 procedure Update_Tables_From_ALI_File is
301 -- Build Compilation_Switches table
303 Compilation_Switches.Init;
305 for J in First_Arg_Entry .. Args.Last loop
306 Compilation_Switches.Increment_Last;
307 Compilation_Switches.Table (Compilation_Switches.Last) :=
310 end Update_Tables_From_ALI_File;
312 ----------------------------
313 -- Write_Unit_Information --
314 ----------------------------
316 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
317 Unode : constant Node_Id := Cunit (Unit_Num);
318 Ukind : constant Node_Kind := Nkind (Unit (Unode));
319 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
323 Write_Info_Initiate ('U');
324 Write_Info_Char (' ');
325 Write_Info_Name (Unit_Name (Unit_Num));
327 Write_Info_Name (Unit_File_Name (Unit_Num));
330 Write_Info_Str (Version_Get (Unit_Num));
332 if (Is_Subprogram (Uent)
333 or else Ekind (Uent) = E_Package
334 or else Is_Generic_Unit (Uent))
335 and then Body_Needed_For_SAL (Uent)
337 Write_Info_Str (" BN");
340 if Dynamic_Elab (Unit_Num) then
341 Write_Info_Str (" DE");
344 -- We set the Elaborate_Body indication if either an explicit pragma
345 -- was present, or if this is an instantiation. RM 12.3(20) requires
346 -- that the body be immediately elaborated after the spec. We would
347 -- normally do that anyway, but the EB we generate here ensures that
348 -- this gets done even when we use the -p gnatbind switch.
350 if Has_Pragma_Elaborate_Body (Uent)
351 or else (Ukind = N_Package_Declaration
352 and then Is_Generic_Instance (Uent)
353 and then Present (Corresponding_Body (Unit (Unode))))
355 Write_Info_Str (" EB");
358 -- Now see if we should tell the binder that an elaboration entity
359 -- is present, which must be reset to true during elaboration. We
360 -- generate the indication if the following condition is met:
362 -- If this is a spec ...
364 if (Is_Subprogram (Uent)
366 Ekind (Uent) = E_Package
368 Is_Generic_Unit (Uent))
370 -- and an elaboration entity was declared ...
372 and then Present (Elaboration_Entity (Uent))
374 -- and either the elaboration flag is required ...
377 (Elaboration_Entity_Required (Uent)
379 -- or this unit has elaboration code ...
381 or else not Has_No_Elaboration_Code (Unode)
383 -- or this unit has a separate body and this
384 -- body has elaboration code.
387 (Ekind (Uent) = E_Package
388 and then Present (Body_Entity (Uent))
390 not Has_No_Elaboration_Code
393 (Body_Entity (Uent))))))
395 Write_Info_Str (" EE");
398 if Has_No_Elaboration_Code (Unode) then
399 Write_Info_Str (" NE");
402 if Is_Preelaborated (Uent) then
403 Write_Info_Str (" PR");
406 if Is_Pure (Uent) then
407 Write_Info_Str (" PU");
410 if Has_RACW (Unit_Num) then
411 Write_Info_Str (" RA");
414 if Is_Remote_Call_Interface (Uent) then
415 Write_Info_Str (" RC");
418 if Is_Remote_Types (Uent) then
419 Write_Info_Str (" RT");
422 if Is_Shared_Passive (Uent) then
423 Write_Info_Str (" SP");
426 if Ukind = N_Subprogram_Declaration
427 or else Ukind = N_Subprogram_Body
429 Write_Info_Str (" SU");
431 elsif Ukind = N_Package_Declaration
433 Ukind = N_Package_Body
435 -- If this is a wrapper package for a subprogram instantiation,
436 -- the user view is the subprogram. Note that in this case the
437 -- ali file contains both the spec and body of the instance.
439 if Is_Wrapper_Package (Uent) then
440 Write_Info_Str (" SU");
442 Write_Info_Str (" PK");
445 elsif Ukind = N_Generic_Package_Declaration then
446 Write_Info_Str (" PK");
450 if Ukind in N_Generic_Declaration
452 (Present (Library_Unit (Unode))
454 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
456 Write_Info_Str (" GE");
459 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
460 case Identifier_Casing (Source_Index (Unit_Num)) is
461 when All_Lower_Case => Write_Info_Str (" IL");
462 when All_Upper_Case => Write_Info_Str (" IU");
466 case Keyword_Casing (Source_Index (Unit_Num)) is
467 when Mixed_Case => Write_Info_Str (" KM");
468 when All_Upper_Case => Write_Info_Str (" KU");
473 if Initialize_Scalars then
474 Write_Info_Str (" IS");
479 -- Generate with lines, first those that are directly with'ed
481 for J in With_Flags'Range loop
482 With_Flags (J) := False;
483 Elab_Flags (J) := False;
484 Elab_All_Flags (J) := False;
485 Elab_Des_Flags (J) := False;
488 Collect_Withs (Unode);
490 -- For a body, we must also check for any subunits which belong to
491 -- it and which have context clauses of their own, since these
492 -- with'ed units are part of its own elaboration dependencies.
494 if Nkind (Unit (Unode)) in N_Unit_Body then
495 for S in Units.First .. Last_Unit loop
497 -- We are only interested in subunits.
498 -- For preproc. data and def. files, Cunit is Empty, so
499 -- we need to test that first.
501 if Cunit (S) /= Empty
502 and then Nkind (Unit (Cunit (S))) = N_Subunit
504 Pnode := Library_Unit (Cunit (S));
506 -- In gnatc mode, the errors in the subunits will not
507 -- have been recorded, but the analysis of the subunit
508 -- may have failed. There is no information to add to
509 -- ALI file in this case.
515 -- Find ultimate parent of the subunit
517 while Nkind (Unit (Pnode)) = N_Subunit loop
518 Pnode := Library_Unit (Pnode);
521 -- See if it belongs to current unit, and if so, include
524 if Pnode = Unode then
525 Collect_Withs (Cunit (S));
533 -- Output linker option lines
535 for J in 1 .. Linker_Option_Lines.Last loop
537 S : constant Linker_Option_Entry :=
538 Linker_Option_Lines.Table (J);
542 if S.Unit = Unit_Num then
543 Write_Info_Initiate ('L');
544 Write_Info_Str (" """);
546 for J in 1 .. String_Length (S.Option) loop
547 C := Get_Character (Get_String_Char (S.Option, J));
549 if C in Character'Val (16#20#) .. Character'Val (16#7E#)
560 Hex : constant array (0 .. 15) of Character :=
564 Write_Info_Char ('{');
565 Write_Info_Char (Hex (Character'Pos (C) / 16));
566 Write_Info_Char (Hex (Character'Pos (C) mod 16));
567 Write_Info_Char ('}');
572 Write_Info_Char ('"');
577 end Write_Unit_Information;
579 ----------------------
580 -- Write_With_Lines --
581 ----------------------
583 procedure Write_With_Lines is
584 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
585 Num_Withs : Int := 0;
586 Unum : Unit_Number_Type;
589 Uname : Unit_Name_Type;
590 Fname : File_Name_Type;
591 Pname : constant Unit_Name_Type :=
592 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
593 Body_Fname : File_Name_Type;
596 -- Loop to build the with table. A with on the main unit itself
597 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
598 -- the main unit is a subprogram with no spec, and a subunit of
599 -- it unecessarily withs the parent.
601 for J in Units.First + 1 .. Last_Unit loop
603 -- Add element to with table if it is with'ed or if it is the
604 -- parent spec of the main unit (case of main unit is a child
605 -- unit). The latter with is not needed for semantic purposes,
606 -- but is required by the binder for elaboration purposes.
607 -- For preproc. data and def. files, there is no Unit_Name,
608 -- check for that first.
610 if Unit_Name (J) /= No_Name
611 and then (With_Flags (J) or else Unit_Name (J) = Pname)
612 and then Units.Table (J).Dependent_Unit
614 Num_Withs := Num_Withs + 1;
615 With_Table (Num_Withs) := J;
619 -- Sort and output the table
621 Sort (With_Table (1 .. Num_Withs));
623 for J in 1 .. Num_Withs loop
624 Unum := With_Table (J);
625 Cunit := Units.Table (Unum).Cunit;
626 Cunite := Units.Table (Unum).Cunit_Entity;
627 Uname := Units.Table (Unum).Unit_Name;
628 Fname := Units.Table (Unum).Unit_File_Name;
630 Write_Info_Initiate ('W');
631 Write_Info_Char (' ');
632 Write_Info_Name (Uname);
634 -- Now we need to figure out the names of the files that contain
635 -- the with'ed unit. These will usually be the files for the body,
636 -- except in the case of a package that has no body.
638 if (Nkind (Unit (Cunit)) not in N_Generic_Declaration
640 Nkind (Unit (Cunit)) not in N_Generic_Renaming_Declaration)
641 or else Generic_Separately_Compiled (Cunite)
645 if Is_Spec_Name (Uname) then
647 Get_File_Name (Get_Body_Name (Uname), Subunit => False);
649 Body_Fname := Get_File_Name (Uname, Subunit => False);
652 -- A package is considered to have a body if it requires
653 -- a body or if a body is present in Ada 83 mode.
655 if Body_Required (Cunit)
657 and then Full_Source_Name (Body_Fname) /= No_File)
659 Write_Info_Name (Body_Fname);
661 Write_Info_Name (Lib_File_Name (Body_Fname));
663 Write_Info_Name (Fname);
665 Write_Info_Name (Lib_File_Name (Fname));
668 if Elab_Flags (Unum) then
669 Write_Info_Str (" E");
672 if Elab_All_Flags (Unum) then
673 Write_Info_Str (" EA");
676 if Elab_Des_Flags (Unum) then
677 Write_Info_Str (" ED");
683 end Write_With_Lines;
685 -- Start of processing for Writ_ALI
688 -- We never write an ALI file if the original operating mode was
689 -- syntax-only (-gnats switch used in compiler invocation line)
691 if Original_Operating_Mode = Check_Syntax then
695 -- Build sorted source dependency table. We do this right away,
696 -- because it is referenced by Up_To_Date_ALI_File_Exists.
698 for Unum in Units.First .. Last_Unit loop
699 if Cunit_Entity (Unum) = Empty
700 or else not From_With_Type (Cunit_Entity (Unum))
702 Num_Sdep := Num_Sdep + 1;
703 Sdep_Table (Num_Sdep) := Unum;
707 -- Sort the table so that the D lines are in order
709 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
711 -- If we are not generating code, and there is an up to date
712 -- ali file accessible, read it, and acquire the compilation
713 -- arguments from this file.
715 if Operating_Mode /= Generate_Code then
716 if Up_To_Date_ALI_File_Exists then
717 Update_Tables_From_ALI_File;
722 -- Otherwise acquire compilation arguments and prepare to write
723 -- out a new ali file.
725 Create_Output_Library_Info;
727 -- Output version line
729 Write_Info_Initiate ('V');
730 Write_Info_Str (" """);
731 Write_Info_Str (Library_Version);
732 Write_Info_Char ('"');
736 -- Output main program line if this is acceptable main program
738 Output_Main_Program_Line : declare
739 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
742 procedure M_Parameters;
743 -- Output parameters for main program line
749 procedure M_Parameters is
751 if Main_Priority (Main_Unit) /= Default_Main_Priority then
752 Write_Info_Char (' ');
753 Write_Info_Nat (Main_Priority (Main_Unit));
756 if Opt.Time_Slice_Set then
757 Write_Info_Str (" T=");
758 Write_Info_Nat (Opt.Time_Slice_Value);
761 Write_Info_Str (" W=");
763 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
768 -- Start of processing for Output_Main_Program_Line
771 if Nkind (U) = N_Subprogram_Body
772 or else (Nkind (U) = N_Package_Body
774 (Nkind (Original_Node (U)) = N_Function_Instantiation
776 Nkind (Original_Node (U)) =
777 N_Procedure_Instantiation))
779 -- If the unit is a subprogram instance, the entity for the
780 -- subprogram is the alias of the visible entity, which is the
781 -- related instance of the wrapper package. We retrieve the
782 -- subprogram declaration of the desired entity.
784 if Nkind (U) = N_Package_Body then
785 U := Parent (Parent (
786 Alias (Related_Instance (Defining_Unit_Name
787 (Specification (Unit (Library_Unit (Parent (U)))))))));
790 S := Specification (U);
792 if not Present (Parameter_Specifications (S)) then
793 if Nkind (S) = N_Procedure_Specification then
794 Write_Info_Initiate ('M');
795 Write_Info_Str (" P");
800 Nam : Node_Id := Defining_Unit_Name (S);
803 -- If it is a child unit, get its simple name.
805 if Nkind (Nam) = N_Defining_Program_Unit_Name then
806 Nam := Defining_Identifier (Nam);
809 if Is_Integer_Type (Etype (Nam)) then
810 Write_Info_Initiate ('M');
811 Write_Info_Str (" F");
818 end Output_Main_Program_Line;
820 -- Write command argmument ('A') lines
822 for A in 1 .. Compilation_Switches.Last loop
823 Write_Info_Initiate ('A');
824 Write_Info_Char (' ');
825 Write_Info_Str (Compilation_Switches.Table (A).all);
826 Write_Info_Terminate;
829 -- Output parameters ('P') line
831 Write_Info_Initiate ('P');
833 if Compilation_Errors then
834 Write_Info_Str (" CE");
837 if Opt.Float_Format /= ' ' then
838 Write_Info_Str (" F");
840 if Opt.Float_Format = 'I' then
841 Write_Info_Char ('I');
843 elsif Opt.Float_Format_Long = 'D' then
844 Write_Info_Char ('D');
847 Write_Info_Char ('G');
852 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
854 if Locking_Policy /= ' ' then
855 Write_Info_Str (" L");
856 Write_Info_Char (Locking_Policy);
859 if Queuing_Policy /= ' ' then
860 Write_Info_Str (" Q");
861 Write_Info_Char (Queuing_Policy);
864 if Task_Dispatching_Policy /= ' ' then
865 Write_Info_Str (" T");
866 Write_Info_Char (Task_Dispatching_Policy);
867 Write_Info_Char (' ');
872 Write_Info_Str (" NO");
875 if No_Run_Time_Mode then
876 Write_Info_Str (" NR");
879 if Normalize_Scalars then
880 Write_Info_Str (" NS");
883 if Unreserve_All_Interrupts then
884 Write_Info_Str (" UA");
887 if Exception_Mechanism /= Front_End_Setjmp_Longjmp_Exceptions then
888 if Unit_Exception_Table_Present then
889 Write_Info_Str (" UX");
892 Write_Info_Str (" ZX");
897 -- Before outputting the restrictions line, update the setting of
898 -- the No_Elaboration_Code flag. Violations of this restriction
899 -- cannot be detected until after the backend has been called since
900 -- it is the backend that sets this flag. We have to check all units
901 -- for which we have generated code
903 for Unit in Units.First .. Last_Unit loop
904 if Units.Table (Unit).Generate_Code
905 or else Unit = Main_Unit
907 if not Has_No_Elaboration_Code (Cunit (Unit)) then
908 Violations (No_ELaboration_Code) := True;
913 -- Output restrictions line
915 Write_Info_Initiate ('R');
916 Write_Info_Char (' ');
918 for J in All_Restrictions loop
919 if Main_Restrictions (J) then
920 Write_Info_Char ('r');
921 elsif Violations (J) then
922 Write_Info_Char ('v');
924 Write_Info_Char ('n');
930 -- Output interrupt state lines
932 for J in Interrupt_States.First .. Interrupt_States.Last loop
933 Write_Info_Initiate ('I');
934 Write_Info_Char (' ');
935 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
936 Write_Info_Char (' ');
937 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
938 Write_Info_Char (' ');
940 (Nat (Get_Logical_Line_Number
941 (Interrupt_States.Table (J).Pragma_Loc)));
945 -- Loop through file table to output information for all units for which
946 -- we have generated code, as marked by the Generate_Code flag.
948 for Unit in Units.First .. Last_Unit loop
949 if Units.Table (Unit).Generate_Code
950 or else Unit = Main_Unit
952 Write_Info_EOL; -- blank line
953 Write_Unit_Information (Unit);
957 Write_Info_EOL; -- blank line
959 -- Output external version reference lines
961 for J in 1 .. Version_Ref.Last loop
962 Write_Info_Initiate ('E');
963 Write_Info_Char (' ');
965 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
966 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
972 -- Prepare to output the source dependency lines
975 Unum : Unit_Number_Type;
976 -- Number of unit being output
978 Sind : Source_File_Index;
979 -- Index of corresponding source file
982 for J in 1 .. Num_Sdep loop
983 Unum := Sdep_Table (J);
984 Units.Table (Unum).Dependency_Num := J;
985 Sind := Units.Table (Unum).Source_Index;
987 Write_Info_Initiate ('D');
988 Write_Info_Char (' ');
990 -- Normal case of a dependent unit entry with a source index
992 if Sind /= No_Source_File
993 and then Units.Table (Unum).Dependent_Unit
995 Write_Info_Name (File_Name (Sind));
997 Write_Info_Str (String (Time_Stamp (Sind)));
998 Write_Info_Char (' ');
999 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1001 -- If subunit, add unit name, omitting the %b at the end
1003 if Present (Cunit (Unum))
1004 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1006 Get_Decoded_Name_String (Unit_Name (Unum));
1007 Write_Info_Char (' ');
1008 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1011 -- If Source_Reference pragma used output information
1013 if Num_SRef_Pragmas (Sind) > 0 then
1014 Write_Info_Char (' ');
1016 if Num_SRef_Pragmas (Sind) = 1 then
1017 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1022 Write_Info_Char (':');
1023 Write_Info_Name (Reference_Name (Sind));
1026 -- Case where there is no source index (happens for missing files)
1027 -- Also come here for non-dependent units.
1030 Write_Info_Name (Unit_File_Name (Unum));
1031 Write_Info_Tab (25);
1032 Write_Info_Str (String (Dummy_Time_Stamp));
1033 Write_Info_Char (' ');
1034 Write_Info_Str (Get_Hex_String (0));
1042 Write_Info_Terminate;
1043 Close_Output_Library_Info;