1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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;
36 with Nlists; use Nlists;
37 with Gnatvsn; use Gnatvsn;
39 with Osint; use Osint;
40 with Osint.C; use Osint.C;
42 with Par_SCO; use Par_SCO;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
46 with Sinfo; use Sinfo;
47 with Sinput; use Sinput;
48 with Snames; use Snames;
49 with Stringt; use Stringt;
50 with Tbuild; use Tbuild;
51 with Uname; use Uname;
53 with System.Case_Util; use System.Case_Util;
54 with System.WCh_Con; use System.WCh_Con;
56 package body Lib.Writ is
58 -----------------------
59 -- Local Subprograms --
60 -----------------------
62 procedure Write_Unit_Name (N : Node_Id);
63 -- Used to write out the unit name for R (pragma Restriction) lines
64 -- for uses of Restriction (No_Dependence => unit-name).
66 ----------------------------------
67 -- Add_Preprocessing_Dependency --
68 ----------------------------------
70 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
73 Units.Table (Units.Last) :=
74 (Unit_File_Name => File_Name (S),
75 Unit_Name => No_Unit_Name,
76 Expected_Unit => No_Unit_Name,
79 Cunit_Entity => Empty,
81 Dynamic_Elab => False,
83 Generate_Code => False,
84 Has_Allocator => False,
86 Is_Compiler_Unit => False,
87 Ident_String => Empty,
94 Error_Location => No_Location,
96 end Add_Preprocessing_Dependency;
98 ------------------------------
99 -- Ensure_System_Dependency --
100 ------------------------------
102 procedure Ensure_System_Dependency is
103 System_Uname : Unit_Name_Type;
104 -- Unit name for system spec if needed for dummy entry
106 System_Fname : File_Name_Type;
107 -- File name for system spec if needed for dummy entry
110 -- Nothing to do if we already compiled System
112 for Unum in Units.First .. Last_Unit loop
113 if Units.Table (Unum).Source_Index = System_Source_File_Index then
118 -- If no entry for system.ads in the units table, then add a entry
119 -- to the units table for system.ads, which will be referenced when
120 -- the ali file is generated. We need this because every unit depends
121 -- on system as a result of Targparm scanning the system.ads file to
122 -- determine the target dependent parameters for the compilation.
125 Name_Buffer (1 .. 6) := "system";
126 System_Uname := Name_To_Unit_Name (Name_Enter);
127 System_Fname := File_Name (System_Source_File_Index);
129 Units.Increment_Last;
130 Units.Table (Units.Last) := (
131 Unit_File_Name => System_Fname,
132 Unit_Name => System_Uname,
133 Expected_Unit => System_Uname,
134 Source_Index => System_Source_File_Index,
136 Cunit_Entity => Empty,
138 Dynamic_Elab => False,
139 Fatal_Error => False,
140 Generate_Code => False,
141 Has_Allocator => False,
143 Is_Compiler_Unit => False,
144 Ident_String => Empty,
151 Error_Location => No_Location,
154 -- Parse system.ads so that the checksum is set right
155 -- Style checks are not applied.
158 Save_Mindex : constant Nat := Multiple_Unit_Index;
159 Save_Style : constant Boolean := Style_Check;
161 Multiple_Unit_Index := 0;
162 Style_Check := False;
163 Initialize_Scanner (Units.Last, System_Source_File_Index);
164 Discard_List (Par (Configuration_Pragmas => False));
165 Style_Check := Save_Style;
166 Multiple_Unit_Index := Save_Mindex;
168 end Ensure_System_Dependency;
174 procedure Write_ALI (Object : Boolean) is
180 Last_Unit : constant Unit_Number_Type := Units.Last;
181 -- Record unit number of last unit. We capture this in case we
182 -- have to add a dummy entry to the unit table for package System.
184 With_Flags : array (Units.First .. Last_Unit) of Boolean;
185 -- Array of flags to show which units are with'ed
187 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
188 -- Array of flags to show which units have pragma Elaborate set
190 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
191 -- Array of flags to show which units have pragma Elaborate All set
193 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
194 -- Array of flags to show which units have Elaborate_Desirable set
196 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
197 -- Array of flags to show which units have Elaborate_All_Desirable set
199 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
200 -- Sorted table of source dependencies. One extra entry in case we
201 -- have to add a dummy entry for System.
204 -- Number of active entries in Sdep_Table
206 flag_compare_debug : Int;
207 pragma Import (C, flag_compare_debug);
208 -- Import from toplev.c
210 -----------------------
211 -- Local Subprograms --
212 -----------------------
214 procedure Collect_Withs (Cunit : Node_Id);
215 -- Collect with lines for entries in the context clause of the
216 -- given compilation unit, Cunit.
218 procedure Update_Tables_From_ALI_File;
219 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
220 -- function), update tables from the ALI information, including
221 -- specifically the Compilation_Switches table.
223 function Up_To_Date_ALI_File_Exists return Boolean;
224 -- If there exists an ALI file that is up to date, then this function
225 -- initializes the tables in the ALI spec to contain information on
226 -- this file (using Scan_ALI) and returns True. If no file exists,
227 -- or the file is not up to date, then False is returned.
229 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
230 -- Write out the library information for one unit for which code is
231 -- generated (includes unit line and with lines).
233 procedure Write_With_Lines;
234 -- Write out with lines collected by calls to Collect_Withs
240 procedure Collect_Withs (Cunit : Node_Id) is
242 Unum : Unit_Number_Type;
245 Item := First (Context_Items (Cunit));
246 while Present (Item) loop
248 -- Process with clause
250 -- Ada 2005 (AI-50217): limited with_clauses do not create
251 -- dependencies, but must be recorded as components of the
252 -- partition, in case there is no regular with_clause for
253 -- the unit anywhere else.
255 if Nkind (Item) = N_With_Clause then
256 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
257 With_Flags (Unum) := True;
259 if not Limited_Present (Item) then
260 if Elaborate_Present (Item) then
261 Elab_Flags (Unum) := True;
264 if Elaborate_All_Present (Item) then
265 Elab_All_Flags (Unum) := True;
268 if Elaborate_All_Desirable (Item) then
269 Elab_All_Des_Flags (Unum) := True;
272 if Elaborate_Desirable (Item) then
273 Elab_Des_Flags (Unum) := True;
277 Set_From_With_Type (Cunit_Entity (Unum));
285 --------------------------------
286 -- Up_To_Date_ALI_File_Exists --
287 --------------------------------
289 function Up_To_Date_ALI_File_Exists return Boolean is
290 Name : File_Name_Type;
291 Text : Text_Buffer_Ptr;
293 Sind : Source_File_Index;
296 Opt.Check_Object_Consistency := True;
297 Read_Library_Info (Name, Text);
299 -- Return if we could not find an ALI file
305 -- Return if ALI file has bad format
309 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
313 -- If we have an OK ALI file, check if it is up to date
314 -- Note that we assume that the ALI read has all the entries
315 -- we have in our table, plus some additional ones (that can
316 -- come from expansion).
318 Id := First_Sdep_Entry;
319 for J in 1 .. Num_Sdep loop
320 Sind := Units.Table (Sdep_Table (J)).Source_Index;
322 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
323 if Id = Sdep.Last then
330 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
336 end Up_To_Date_ALI_File_Exists;
338 ---------------------------------
339 -- Update_Tables_From_ALI_File --
340 ---------------------------------
342 procedure Update_Tables_From_ALI_File is
344 -- Build Compilation_Switches table
346 Compilation_Switches.Init;
348 for J in First_Arg_Entry .. Args.Last loop
349 Compilation_Switches.Increment_Last;
350 Compilation_Switches.Table (Compilation_Switches.Last) :=
353 end Update_Tables_From_ALI_File;
355 ----------------------------
356 -- Write_Unit_Information --
357 ----------------------------
359 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
360 Unode : constant Node_Id := Cunit (Unit_Num);
361 Ukind : constant Node_Kind := Nkind (Unit (Unode));
362 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
366 Write_Info_Initiate ('U');
367 Write_Info_Char (' ');
368 Write_Info_Name (Unit_Name (Unit_Num));
370 Write_Info_Name (Unit_File_Name (Unit_Num));
373 Write_Info_Str (Version_Get (Unit_Num));
375 -- Add BD parameter if Elaborate_Body pragma desirable
377 if Ekind (Uent) = E_Package
378 and then Elaborate_Body_Desirable (Uent)
380 Write_Info_Str (" BD");
383 -- Add BN parameter if body needed for SAL
385 if (Is_Subprogram (Uent)
386 or else Ekind (Uent) = E_Package
387 or else Is_Generic_Unit (Uent))
388 and then Body_Needed_For_SAL (Uent)
390 Write_Info_Str (" BN");
393 if Dynamic_Elab (Unit_Num) then
394 Write_Info_Str (" DE");
397 -- Set the Elaborate_Body indication if either an explicit pragma
398 -- was present, or if this is an instantiation.
400 if Has_Pragma_Elaborate_Body (Uent)
401 or else (Ukind = N_Package_Declaration
402 and then Is_Generic_Instance (Uent)
403 and then Present (Corresponding_Body (Unit (Unode))))
405 Write_Info_Str (" EB");
408 -- Now see if we should tell the binder that an elaboration entity
409 -- is present, which must be set to true during elaboration.
410 -- We generate the indication if the following condition is met:
412 -- If this is a spec ...
414 if (Is_Subprogram (Uent)
416 Ekind (Uent) = E_Package
418 Is_Generic_Unit (Uent))
420 -- and an elaboration entity was declared ...
422 and then Present (Elaboration_Entity (Uent))
424 -- and either the elaboration flag is required ...
427 (Elaboration_Entity_Required (Uent)
429 -- or this unit has elaboration code ...
431 or else not Has_No_Elaboration_Code (Unode)
433 -- or this unit has a separate body and this
434 -- body has elaboration code.
437 (Ekind (Uent) = E_Package
438 and then Present (Body_Entity (Uent))
440 not Has_No_Elaboration_Code
443 (Body_Entity (Uent))))))
445 if Convention (Uent) = Convention_CIL then
447 -- Special case for generic CIL packages which never have
450 Write_Info_Str (" NE");
453 Write_Info_Str (" EE");
457 if Has_No_Elaboration_Code (Unode) then
458 Write_Info_Str (" NE");
461 Write_Info_Str (" O");
462 Write_Info_Char (OA_Setting (Unit_Num));
464 if Ekind_In (Uent, E_Package, E_Package_Body)
465 and then Present (Finalizer (Uent))
467 Write_Info_Str (" PF");
470 if Is_Preelaborated (Uent) then
471 Write_Info_Str (" PR");
474 if Is_Pure (Uent) then
475 Write_Info_Str (" PU");
478 if Has_RACW (Unit_Num) then
479 Write_Info_Str (" RA");
482 if Is_Remote_Call_Interface (Uent) then
483 Write_Info_Str (" RC");
486 if Is_Remote_Types (Uent) then
487 Write_Info_Str (" RT");
490 if Is_Shared_Passive (Uent) then
491 Write_Info_Str (" SP");
494 if Ukind = N_Subprogram_Declaration
495 or else Ukind = N_Subprogram_Body
497 Write_Info_Str (" SU");
499 elsif Ukind = N_Package_Declaration
501 Ukind = N_Package_Body
503 -- If this is a wrapper package for a subprogram instantiation,
504 -- the user view is the subprogram. Note that in this case the
505 -- ali file contains both the spec and body of the instance.
507 if Is_Wrapper_Package (Uent) then
508 Write_Info_Str (" SU");
510 Write_Info_Str (" PK");
513 elsif Ukind = N_Generic_Package_Declaration then
514 Write_Info_Str (" PK");
518 if Ukind in N_Generic_Declaration
520 (Present (Library_Unit (Unode))
522 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
524 Write_Info_Str (" GE");
527 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
528 case Identifier_Casing (Source_Index (Unit_Num)) is
529 when All_Lower_Case => Write_Info_Str (" IL");
530 when All_Upper_Case => Write_Info_Str (" IU");
534 case Keyword_Casing (Source_Index (Unit_Num)) is
535 when Mixed_Case => Write_Info_Str (" KM");
536 when All_Upper_Case => Write_Info_Str (" KU");
541 if Initialize_Scalars or else Invalid_Value_Used then
542 Write_Info_Str (" IS");
547 -- Generate with lines, first those that are directly with'ed
549 for J in With_Flags'Range loop
550 With_Flags (J) := False;
551 Elab_Flags (J) := False;
552 Elab_All_Flags (J) := False;
553 Elab_Des_Flags (J) := False;
554 Elab_All_Des_Flags (J) := False;
557 Collect_Withs (Unode);
559 -- For a body, we must also check for any subunits which belong to
560 -- it and which have context clauses of their own, since these
561 -- with'ed units are part of its own elaboration dependencies.
563 if Nkind (Unit (Unode)) in N_Unit_Body then
564 for S in Units.First .. Last_Unit loop
566 -- We are only interested in subunits.
567 -- For preproc. data and def. files, Cunit is Empty, so
568 -- we need to test that first.
570 if Cunit (S) /= Empty
571 and then Nkind (Unit (Cunit (S))) = N_Subunit
573 Pnode := Library_Unit (Cunit (S));
575 -- In gnatc mode, the errors in the subunits will not
576 -- have been recorded, but the analysis of the subunit
577 -- may have failed. There is no information to add to
578 -- ALI file in this case.
584 -- Find ultimate parent of the subunit
586 while Nkind (Unit (Pnode)) = N_Subunit loop
587 Pnode := Library_Unit (Pnode);
590 -- See if it belongs to current unit, and if so, include
593 if Pnode = Unode then
594 Collect_Withs (Cunit (S));
602 -- Output linker option lines
604 for J in 1 .. Linker_Option_Lines.Last loop
606 S : Linker_Option_Entry renames Linker_Option_Lines.Table (J);
608 if S.Unit = Unit_Num then
609 Write_Info_Initiate ('L');
610 Write_Info_Char (' ');
611 Write_Info_Slit (S.Option);
619 for J in 1 .. Notes.Last loop
621 N : constant Node_Id := Notes.Table (J).Pragma_Node;
622 L : constant Source_Ptr := Sloc (N);
623 U : constant Unit_Number_Type := Notes.Table (J).Unit;
628 Write_Info_Initiate ('N');
629 Write_Info_Char (' ');
631 case Chars (Pragma_Identifier (N)) is
632 when Name_Annotate =>
640 when Name_Subtitle =>
647 Write_Info_Int (Int (Get_Logical_Line_Number (L)));
648 Write_Info_Char (':');
649 Write_Info_Int (Int (Get_Column_Number (L)));
655 A := First (Pragma_Argument_Associations (N));
656 while Present (A) loop
657 Write_Info_Char (' ');
659 if Chars (A) /= No_Name then
660 Write_Info_Name (Chars (A));
661 Write_Info_Char (':');
665 Expr : constant Node_Id := Expression (A);
668 if Nkind (Expr) = N_Identifier then
669 Write_Info_Name (Chars (Expr));
671 elsif Nkind (Expr) = N_Integer_Literal
672 and then Is_Static_Expression (Expr)
674 Write_Info_Uint (Intval (Expr));
676 elsif Nkind (Expr) = N_String_Literal
677 and then Is_Static_Expression (Expr)
679 Write_Info_Slit (Strval (Expr));
682 Write_Info_Str ("<expr>");
694 end Write_Unit_Information;
696 ----------------------
697 -- Write_With_Lines --
698 ----------------------
700 procedure Write_With_Lines is
701 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
702 Num_Withs : Int := 0;
703 Unum : Unit_Number_Type;
705 Uname : Unit_Name_Type;
706 Fname : File_Name_Type;
707 Pname : constant Unit_Name_Type :=
708 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
709 Body_Fname : File_Name_Type;
712 procedure Write_With_File_Names
713 (Nam : in out File_Name_Type;
715 -- Write source file name Nam and ALI file name for unit index Idx.
716 -- Possibly change Nam to lowercase (generating a new file name).
718 --------------------------
719 -- Write_With_File_Name --
720 --------------------------
722 procedure Write_With_File_Names
723 (Nam : in out File_Name_Type;
727 if not File_Names_Case_Sensitive then
728 Get_Name_String (Nam);
729 To_Lower (Name_Buffer (1 .. Name_Len));
733 Write_Info_Name (Nam);
735 Write_Info_Name (Lib_File_Name (Nam, Idx));
736 end Write_With_File_Names;
738 -- Start of processing for Write_With_Lines
741 -- Loop to build the with table. A with on the main unit itself
742 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
743 -- the main unit is a subprogram with no spec, and a subunit of
744 -- it unnecessarily withs the parent.
746 for J in Units.First + 1 .. Last_Unit loop
748 -- Add element to with table if it is with'ed or if it is the
749 -- parent spec of the main unit (case of main unit is a child
750 -- unit). The latter with is not needed for semantic purposes,
751 -- but is required by the binder for elaboration purposes.
752 -- For preproc. data and def. files, there is no Unit_Name,
753 -- check for that first.
755 if Unit_Name (J) /= No_Unit_Name
756 and then (With_Flags (J) or else Unit_Name (J) = Pname)
758 Num_Withs := Num_Withs + 1;
759 With_Table (Num_Withs) := J;
763 -- Sort and output the table
765 Sort (With_Table (1 .. Num_Withs));
767 for J in 1 .. Num_Withs loop
768 Unum := With_Table (J);
769 Cunit := Units.Table (Unum).Cunit;
770 Uname := Units.Table (Unum).Unit_Name;
771 Fname := Units.Table (Unum).Unit_File_Name;
773 if Ekind (Cunit_Entity (Unum)) = E_Package
774 and then From_With_Type (Cunit_Entity (Unum))
776 Write_Info_Initiate ('Y');
778 Write_Info_Initiate ('W');
781 Write_Info_Char (' ');
782 Write_Info_Name (Uname);
784 -- Now we need to figure out the names of the files that contain
785 -- the with'ed unit. These will usually be the files for the body,
786 -- except in the case of a package that has no body. Note that we
787 -- have a specific exemption here for predefined library generics
788 -- (see comments for Generic_May_Lack_ALI). We do not generate
789 -- dependency upon the ALI file for such units. Older compilers
790 -- used to not support generating code (and ALI) for generics, and
791 -- we want to avoid having different processing (namely, different
792 -- lists of files to be compiled) for different stages of the
795 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
797 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
798 and then Generic_May_Lack_ALI (Fname))
800 -- In Alfa mode, always generate the dependencies on ALI
801 -- files, which are required to compute frame conditions
808 if Is_Spec_Name (Uname) then
811 (Get_Body_Name (Uname),
812 Subunit => False, May_Fail => True);
816 (Get_Body_Name (Uname));
818 if Body_Fname = No_File then
819 Body_Fname := Get_File_Name (Uname, Subunit => False);
820 Body_Index := Get_Unit_Index (Uname);
824 Body_Fname := Get_File_Name (Uname, Subunit => False);
825 Body_Index := Get_Unit_Index (Uname);
828 -- A package is considered to have a body if it requires
829 -- a body or if a body is present in Ada 83 mode.
831 if Body_Required (Cunit)
832 or else (Ada_Version = Ada_83
833 and then Full_Source_Name (Body_Fname) /= No_File)
835 Write_With_File_Names (Body_Fname, Body_Index);
837 Write_With_File_Names (Fname, Munit_Index (Unum));
840 if Ekind (Cunit_Entity (Unum)) = E_Package
841 and then From_With_Type (Cunit_Entity (Unum))
845 if Elab_Flags (Unum) then
846 Write_Info_Str (" E");
849 if Elab_All_Flags (Unum) then
850 Write_Info_Str (" EA");
853 if Elab_Des_Flags (Unum) then
854 Write_Info_Str (" ED");
857 if Elab_All_Des_Flags (Unum) then
858 Write_Info_Str (" AD");
865 end Write_With_Lines;
867 -- Start of processing for Write_ALI
870 -- We never write an ALI file if the original operating mode was
871 -- syntax-only (-gnats switch used in compiler invocation line)
873 if Original_Operating_Mode = Check_Syntax
874 or flag_compare_debug /= 0
879 -- Generation of ALI files may be disabled, e.g. for formal verification
882 if Disable_ALI_File then
886 -- Build sorted source dependency table. We do this right away, because
887 -- it is referenced by Up_To_Date_ALI_File_Exists.
889 for Unum in Units.First .. Last_Unit loop
890 if Cunit_Entity (Unum) = Empty
891 or else not From_With_Type (Cunit_Entity (Unum))
893 Num_Sdep := Num_Sdep + 1;
894 Sdep_Table (Num_Sdep) := Unum;
898 -- Sort the table so that the D lines are in order
900 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
902 -- If we are not generating code, and there is an up to date ALI file
903 -- file accessible, read it, and acquire the compilation arguments from
906 if Operating_Mode /= Generate_Code then
907 if Up_To_Date_ALI_File_Exists then
908 Update_Tables_From_ALI_File;
913 -- Otherwise acquire compilation arguments and prepare to write
914 -- out a new ali file.
916 Create_Output_Library_Info;
918 -- Output version line
920 Write_Info_Initiate ('V');
921 Write_Info_Str (" """);
922 Write_Info_Str (Verbose_Library_Version);
923 Write_Info_Char ('"');
927 -- Output main program line if this is acceptable main program
929 Output_Main_Program_Line : declare
930 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
933 procedure M_Parameters;
934 -- Output parameters for main program line
940 procedure M_Parameters is
942 if Main_Priority (Main_Unit) /= Default_Main_Priority then
943 Write_Info_Char (' ');
944 Write_Info_Nat (Main_Priority (Main_Unit));
947 if Opt.Time_Slice_Set then
948 Write_Info_Str (" T=");
949 Write_Info_Nat (Opt.Time_Slice_Value);
952 if Has_Allocator (Main_Unit) then
953 Write_Info_Str (" AB");
956 if Main_CPU (Main_Unit) /= Default_Main_CPU then
957 Write_Info_Str (" C=");
958 Write_Info_Nat (Main_CPU (Main_Unit));
961 Write_Info_Str (" W=");
963 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
968 -- Start of processing for Output_Main_Program_Line
971 if Nkind (U) = N_Subprogram_Body
973 (Nkind (U) = N_Package_Body
975 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
977 -- If the unit is a subprogram instance, the entity for the
978 -- subprogram is the alias of the visible entity, which is the
979 -- related instance of the wrapper package. We retrieve the
980 -- subprogram declaration of the desired entity.
982 if Nkind (U) = N_Package_Body then
983 U := Parent (Parent (
984 Alias (Related_Instance (Defining_Unit_Name
985 (Specification (Unit (Library_Unit (Parent (U)))))))));
988 S := Specification (U);
990 if No (Parameter_Specifications (S)) then
991 if Nkind (S) = N_Procedure_Specification then
992 Write_Info_Initiate ('M');
993 Write_Info_Str (" P");
998 Nam : Node_Id := Defining_Unit_Name (S);
1001 -- If it is a child unit, get its simple name
1003 if Nkind (Nam) = N_Defining_Program_Unit_Name then
1004 Nam := Defining_Identifier (Nam);
1007 if Is_Integer_Type (Etype (Nam)) then
1008 Write_Info_Initiate ('M');
1009 Write_Info_Str (" F");
1016 end Output_Main_Program_Line;
1018 -- Write command argument ('A') lines
1020 for A in 1 .. Compilation_Switches.Last loop
1021 Write_Info_Initiate ('A');
1022 Write_Info_Char (' ');
1023 Write_Info_Str (Compilation_Switches.Table (A).all);
1024 Write_Info_Terminate;
1027 -- Output parameters ('P') line
1029 Write_Info_Initiate ('P');
1031 if Compilation_Errors then
1032 Write_Info_Str (" CE");
1035 if Opt.Detect_Blocking then
1036 Write_Info_Str (" DB");
1039 if Opt.Float_Format /= ' ' then
1040 Write_Info_Str (" F");
1042 if Opt.Float_Format = 'I' then
1043 Write_Info_Char ('I');
1045 elsif Opt.Float_Format_Long = 'D' then
1046 Write_Info_Char ('D');
1049 Write_Info_Char ('G');
1054 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
1056 if Locking_Policy /= ' ' then
1057 Write_Info_Str (" L");
1058 Write_Info_Char (Locking_Policy);
1061 if Queuing_Policy /= ' ' then
1062 Write_Info_Str (" Q");
1063 Write_Info_Char (Queuing_Policy);
1066 if Task_Dispatching_Policy /= ' ' then
1067 Write_Info_Str (" T");
1068 Write_Info_Char (Task_Dispatching_Policy);
1069 Write_Info_Char (' ');
1074 Write_Info_Str (" NO");
1077 if No_Run_Time_Mode then
1078 Write_Info_Str (" NR");
1081 if Normalize_Scalars then
1082 Write_Info_Str (" NS");
1085 if Sec_Stack_Used then
1086 Write_Info_Str (" SS");
1089 if Unreserve_All_Interrupts then
1090 Write_Info_Str (" UA");
1093 if Exception_Mechanism = Back_End_Exceptions then
1094 Write_Info_Str (" ZX");
1099 -- Before outputting the restrictions line, update the setting of
1100 -- the No_Elaboration_Code flag. Violations of this restriction
1101 -- cannot be detected until after the backend has been called since
1102 -- it is the backend that sets this flag. We have to check all units
1103 -- for which we have generated code
1105 for Unit in Units.First .. Last_Unit loop
1106 if Units.Table (Unit).Generate_Code
1107 or else Unit = Main_Unit
1109 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1110 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1115 -- Output first restrictions line
1117 Write_Info_Initiate ('R');
1118 Write_Info_Char (' ');
1120 -- First the information for the boolean restrictions
1122 for R in All_Boolean_Restrictions loop
1123 if Main_Restrictions.Set (R)
1124 and then not Restriction_Warnings (R)
1126 Write_Info_Char ('r');
1127 elsif Main_Restrictions.Violated (R) then
1128 Write_Info_Char ('v');
1130 Write_Info_Char ('n');
1134 -- And now the information for the parameter restrictions
1136 for RP in All_Parameter_Restrictions loop
1137 if Main_Restrictions.Set (RP)
1138 and then not Restriction_Warnings (RP)
1140 Write_Info_Char ('r');
1141 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1143 Write_Info_Char ('n');
1146 if not Main_Restrictions.Violated (RP)
1147 or else RP not in Checked_Parameter_Restrictions
1149 Write_Info_Char ('n');
1151 Write_Info_Char ('v');
1152 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1154 if Main_Restrictions.Unknown (RP) then
1155 Write_Info_Char ('+');
1162 -- Output R lines for No_Dependence entries
1164 for J in No_Dependences.First .. No_Dependences.Last loop
1165 if In_Extended_Main_Source_Unit (No_Dependences.Table (J).Unit)
1166 and then not No_Dependences.Table (J).Warn
1168 Write_Info_Initiate ('R');
1169 Write_Info_Char (' ');
1170 Write_Unit_Name (No_Dependences.Table (J).Unit);
1175 -- Output interrupt state lines
1177 for J in Interrupt_States.First .. Interrupt_States.Last loop
1178 Write_Info_Initiate ('I');
1179 Write_Info_Char (' ');
1180 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1181 Write_Info_Char (' ');
1182 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1183 Write_Info_Char (' ');
1185 (Nat (Get_Logical_Line_Number
1186 (Interrupt_States.Table (J).Pragma_Loc)));
1190 -- Output priority specific dispatching lines
1192 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1193 Write_Info_Initiate ('S');
1194 Write_Info_Char (' ');
1195 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1196 Write_Info_Char (' ');
1197 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1198 Write_Info_Char (' ');
1199 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1200 Write_Info_Char (' ');
1202 (Nat (Get_Logical_Line_Number
1203 (Specific_Dispatching.Table (J).Pragma_Loc)));
1207 -- Loop through file table to output information for all units for which
1208 -- we have generated code, as marked by the Generate_Code flag.
1210 for Unit in Units.First .. Last_Unit loop
1211 if Units.Table (Unit).Generate_Code
1212 or else Unit = Main_Unit
1214 Write_Info_EOL; -- blank line
1215 Write_Unit_Information (Unit);
1219 Write_Info_EOL; -- blank line
1221 -- Output external version reference lines
1223 for J in 1 .. Version_Ref.Last loop
1224 Write_Info_Initiate ('E');
1225 Write_Info_Char (' ');
1227 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1228 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1234 -- Prepare to output the source dependency lines
1237 Unum : Unit_Number_Type;
1238 -- Number of unit being output
1240 Sind : Source_File_Index;
1241 -- Index of corresponding source file
1243 Fname : File_Name_Type;
1246 for J in 1 .. Num_Sdep loop
1247 Unum := Sdep_Table (J);
1248 Units.Table (Unum).Dependency_Num := J;
1249 Sind := Units.Table (Unum).Source_Index;
1251 Write_Info_Initiate ('D');
1252 Write_Info_Char (' ');
1254 -- Normal case of a unit entry with a source index
1256 if Sind /= No_Source_File then
1257 Fname := File_Name (Sind);
1259 -- Ensure that on platforms where the file names are not
1260 -- case sensitive, the recorded file name is in lower case.
1262 if not File_Names_Case_Sensitive then
1263 Get_Name_String (Fname);
1264 To_Lower (Name_Buffer (1 .. Name_Len));
1268 Write_Info_Name (Fname);
1269 Write_Info_Tab (25);
1270 Write_Info_Str (String (Time_Stamp (Sind)));
1271 Write_Info_Char (' ');
1272 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1274 -- If subunit, add unit name, omitting the %b at the end
1276 if Present (Cunit (Unum))
1277 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1279 Get_Decoded_Name_String (Unit_Name (Unum));
1280 Write_Info_Char (' ');
1281 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1284 -- If Source_Reference pragma used output information
1286 if Num_SRef_Pragmas (Sind) > 0 then
1287 Write_Info_Char (' ');
1289 if Num_SRef_Pragmas (Sind) = 1 then
1290 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1295 Write_Info_Char (':');
1296 Write_Info_Name (Reference_Name (Sind));
1299 -- Case where there is no source index (happens for missing
1300 -- files). In this case we write a dummy time stamp.
1303 Write_Info_Name (Unit_File_Name (Unum));
1304 Write_Info_Tab (25);
1305 Write_Info_Str (String (Dummy_Time_Stamp));
1306 Write_Info_Char (' ');
1307 Write_Info_Str (Get_Hex_String (0));
1314 -- Output cross-references
1316 if Opt.Xref_Active then
1320 -- Output SCO information if present
1322 if Generate_SCO then
1326 -- Output Alfa information if needed
1328 if Opt.Xref_Active and then Alfa_Mode then
1329 Collect_Alfa (Sdep_Table => Sdep_Table, Num_Sdep => Num_Sdep);
1333 -- Output final blank line and we are done. This final blank line is
1334 -- probably junk, but we don't feel like making an incompatible change!
1336 Write_Info_Terminate;
1337 Close_Output_Library_Info;
1340 ---------------------
1341 -- Write_Unit_Name --
1342 ---------------------
1344 procedure Write_Unit_Name (N : Node_Id) is
1346 if Nkind (N) = N_Identifier then
1347 Write_Info_Name (Chars (N));
1350 pragma Assert (Nkind (N) = N_Selected_Component);
1351 Write_Unit_Name (Prefix (N));
1352 Write_Info_Char ('.');
1353 Write_Unit_Name (Selector_Name (N));
1355 end Write_Unit_Name;