1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 Debug; use Debug;
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 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 type Yes_No is (Unknown, Yes, No);
200 Implicit_With : array (Units.First .. Last_Unit) of Yes_No;
201 -- Indicates if an implicit with has been given for the unit. Yes if
202 -- certainly present, no if certainly absent, unkonwn if not known.
204 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
205 -- Sorted table of source dependencies. One extra entry in case we
206 -- have to add a dummy entry for System.
209 -- Number of active entries in Sdep_Table
211 flag_compare_debug : Int;
212 pragma Import (C, flag_compare_debug);
213 -- Import from toplev.c
215 -----------------------
216 -- Local Subprograms --
217 -----------------------
219 procedure Collect_Withs (Cunit : Node_Id);
220 -- Collect with lines for entries in the context clause of the
221 -- given compilation unit, Cunit.
223 procedure Update_Tables_From_ALI_File;
224 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
225 -- function), update tables from the ALI information, including
226 -- specifically the Compilation_Switches table.
228 function Up_To_Date_ALI_File_Exists return Boolean;
229 -- If there exists an ALI file that is up to date, then this function
230 -- initializes the tables in the ALI spec to contain information on
231 -- this file (using Scan_ALI) and returns True. If no file exists,
232 -- or the file is not up to date, then False is returned.
234 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
235 -- Write out the library information for one unit for which code is
236 -- generated (includes unit line and with lines).
238 procedure Write_With_Lines;
239 -- Write out with lines collected by calls to Collect_Withs
245 procedure Collect_Withs (Cunit : Node_Id) is
247 Unum : Unit_Number_Type;
250 Item := First (Context_Items (Cunit));
251 while Present (Item) loop
253 -- Process with clause
255 -- Ada 2005 (AI-50217): limited with_clauses do not create
256 -- dependencies, but must be recorded as components of the
257 -- partition, in case there is no regular with_clause for
258 -- the unit anywhere else.
260 if Nkind (Item) = N_With_Clause then
261 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
262 With_Flags (Unum) := True;
264 if not Limited_Present (Item) then
265 if Elaborate_Present (Item) then
266 Elab_Flags (Unum) := True;
269 if Elaborate_All_Present (Item) then
270 Elab_All_Flags (Unum) := True;
273 if Elaborate_All_Desirable (Item) then
274 Elab_All_Des_Flags (Unum) := True;
277 if Elaborate_Desirable (Item) then
278 Elab_Des_Flags (Unum) := True;
282 Set_From_With_Type (Cunit_Entity (Unum));
285 if Implicit_With (Unum) /= Yes then
286 if Implicit_With_From_Instantiation (Item) then
287 Implicit_With (Unum) := Yes;
289 Implicit_With (Unum) := No;
298 --------------------------------
299 -- Up_To_Date_ALI_File_Exists --
300 --------------------------------
302 function Up_To_Date_ALI_File_Exists return Boolean is
303 Name : File_Name_Type;
304 Text : Text_Buffer_Ptr;
306 Sind : Source_File_Index;
309 Opt.Check_Object_Consistency := True;
310 Read_Library_Info (Name, Text);
312 -- Return if we could not find an ALI file
318 -- Return if ALI file has bad format
322 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
326 -- If we have an OK ALI file, check if it is up to date
327 -- Note that we assume that the ALI read has all the entries
328 -- we have in our table, plus some additional ones (that can
329 -- come from expansion).
331 Id := First_Sdep_Entry;
332 for J in 1 .. Num_Sdep loop
333 Sind := Units.Table (Sdep_Table (J)).Source_Index;
335 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
336 if Id = Sdep.Last then
343 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
349 end Up_To_Date_ALI_File_Exists;
351 ---------------------------------
352 -- Update_Tables_From_ALI_File --
353 ---------------------------------
355 procedure Update_Tables_From_ALI_File is
357 -- Build Compilation_Switches table
359 Compilation_Switches.Init;
361 for J in First_Arg_Entry .. Args.Last loop
362 Compilation_Switches.Increment_Last;
363 Compilation_Switches.Table (Compilation_Switches.Last) :=
366 end Update_Tables_From_ALI_File;
368 ----------------------------
369 -- Write_Unit_Information --
370 ----------------------------
372 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
373 Unode : constant Node_Id := Cunit (Unit_Num);
374 Ukind : constant Node_Kind := Nkind (Unit (Unode));
375 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
379 Write_Info_Initiate ('U');
380 Write_Info_Char (' ');
381 Write_Info_Name (Unit_Name (Unit_Num));
383 Write_Info_Name (Unit_File_Name (Unit_Num));
386 Write_Info_Str (Version_Get (Unit_Num));
388 -- Add BD parameter if Elaborate_Body pragma desirable
390 if Ekind (Uent) = E_Package
391 and then Elaborate_Body_Desirable (Uent)
393 Write_Info_Str (" BD");
396 -- Add BN parameter if body needed for SAL
398 if (Is_Subprogram (Uent)
399 or else Ekind (Uent) = E_Package
400 or else Is_Generic_Unit (Uent))
401 and then Body_Needed_For_SAL (Uent)
403 Write_Info_Str (" BN");
406 if Dynamic_Elab (Unit_Num) then
407 Write_Info_Str (" DE");
410 -- Set the Elaborate_Body indication if either an explicit pragma
411 -- was present, or if this is an instantiation.
413 if Has_Pragma_Elaborate_Body (Uent)
414 or else (Ukind = N_Package_Declaration
415 and then Is_Generic_Instance (Uent)
416 and then Present (Corresponding_Body (Unit (Unode))))
418 Write_Info_Str (" EB");
421 -- Now see if we should tell the binder that an elaboration entity
422 -- is present, which must be set to true during elaboration.
423 -- We generate the indication if the following condition is met:
425 -- If this is a spec ...
427 if (Is_Subprogram (Uent)
429 Ekind (Uent) = E_Package
431 Is_Generic_Unit (Uent))
433 -- and an elaboration entity was declared ...
435 and then Present (Elaboration_Entity (Uent))
437 -- and either the elaboration flag is required ...
440 (Elaboration_Entity_Required (Uent)
442 -- or this unit has elaboration code ...
444 or else not Has_No_Elaboration_Code (Unode)
446 -- or this unit has a separate body and this
447 -- body has elaboration code.
450 (Ekind (Uent) = E_Package
451 and then Present (Body_Entity (Uent))
453 not Has_No_Elaboration_Code
456 (Body_Entity (Uent))))))
458 if Convention (Uent) = Convention_CIL then
460 -- Special case for generic CIL packages which never have
463 Write_Info_Str (" NE");
466 Write_Info_Str (" EE");
470 if Has_No_Elaboration_Code (Unode) then
471 Write_Info_Str (" NE");
474 Write_Info_Str (" O");
475 Write_Info_Char (OA_Setting (Unit_Num));
477 if Ekind_In (Uent, E_Package, E_Package_Body)
478 and then Present (Finalizer (Uent))
480 Write_Info_Str (" PF");
483 if Is_Preelaborated (Uent) then
484 Write_Info_Str (" PR");
487 if Is_Pure (Uent) then
488 Write_Info_Str (" PU");
491 if Has_RACW (Unit_Num) then
492 Write_Info_Str (" RA");
495 if Is_Remote_Call_Interface (Uent) then
496 Write_Info_Str (" RC");
499 if Is_Remote_Types (Uent) then
500 Write_Info_Str (" RT");
503 if Is_Shared_Passive (Uent) then
504 Write_Info_Str (" SP");
507 if Ukind = N_Subprogram_Declaration
508 or else Ukind = N_Subprogram_Body
510 Write_Info_Str (" SU");
512 elsif Ukind = N_Package_Declaration
514 Ukind = N_Package_Body
516 -- If this is a wrapper package for a subprogram instantiation,
517 -- the user view is the subprogram. Note that in this case the
518 -- ali file contains both the spec and body of the instance.
520 if Is_Wrapper_Package (Uent) then
521 Write_Info_Str (" SU");
523 Write_Info_Str (" PK");
526 elsif Ukind = N_Generic_Package_Declaration then
527 Write_Info_Str (" PK");
531 if Ukind in N_Generic_Declaration
533 (Present (Library_Unit (Unode))
535 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
537 Write_Info_Str (" GE");
540 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
541 case Identifier_Casing (Source_Index (Unit_Num)) is
542 when All_Lower_Case => Write_Info_Str (" IL");
543 when All_Upper_Case => Write_Info_Str (" IU");
547 case Keyword_Casing (Source_Index (Unit_Num)) is
548 when Mixed_Case => Write_Info_Str (" KM");
549 when All_Upper_Case => Write_Info_Str (" KU");
554 if Initialize_Scalars or else Invalid_Value_Used then
555 Write_Info_Str (" IS");
560 -- Generate with lines, first those that are directly with'ed
562 for J in With_Flags'Range loop
563 With_Flags (J) := False;
564 Elab_Flags (J) := False;
565 Elab_All_Flags (J) := False;
566 Elab_Des_Flags (J) := False;
567 Elab_All_Des_Flags (J) := False;
568 Implicit_With (J) := Unknown;
571 Collect_Withs (Unode);
573 -- For a body, we must also check for any subunits which belong to
574 -- it and which have context clauses of their own, since these
575 -- with'ed units are part of its own elaboration dependencies.
577 if Nkind (Unit (Unode)) in N_Unit_Body then
578 for S in Units.First .. Last_Unit loop
580 -- We are only interested in subunits.
581 -- For preproc. data and def. files, Cunit is Empty, so
582 -- we need to test that first.
584 if Cunit (S) /= Empty
585 and then Nkind (Unit (Cunit (S))) = N_Subunit
587 Pnode := Library_Unit (Cunit (S));
589 -- In gnatc mode, the errors in the subunits will not
590 -- have been recorded, but the analysis of the subunit
591 -- may have failed. There is no information to add to
592 -- ALI file in this case.
598 -- Find ultimate parent of the subunit
600 while Nkind (Unit (Pnode)) = N_Subunit loop
601 Pnode := Library_Unit (Pnode);
604 -- See if it belongs to current unit, and if so, include
607 if Pnode = Unode then
608 Collect_Withs (Cunit (S));
616 -- Output linker option lines
618 for J in 1 .. Linker_Option_Lines.Last loop
620 S : Linker_Option_Entry renames Linker_Option_Lines.Table (J);
622 if S.Unit = Unit_Num then
623 Write_Info_Initiate ('L');
624 Write_Info_Char (' ');
625 Write_Info_Slit (S.Option);
633 for J in 1 .. Notes.Last loop
635 N : constant Node_Id := Notes.Table (J).Pragma_Node;
636 L : constant Source_Ptr := Sloc (N);
637 U : constant Unit_Number_Type := Notes.Table (J).Unit;
642 Write_Info_Initiate ('N');
643 Write_Info_Char (' ');
645 case Chars (Pragma_Identifier (N)) is
646 when Name_Annotate =>
654 when Name_Subtitle =>
661 Write_Info_Int (Int (Get_Logical_Line_Number (L)));
662 Write_Info_Char (':');
663 Write_Info_Int (Int (Get_Column_Number (L)));
669 A := First (Pragma_Argument_Associations (N));
670 while Present (A) loop
671 Write_Info_Char (' ');
673 if Chars (A) /= No_Name then
674 Write_Info_Name (Chars (A));
675 Write_Info_Char (':');
679 Expr : constant Node_Id := Expression (A);
682 if Nkind (Expr) = N_Identifier then
683 Write_Info_Name (Chars (Expr));
685 elsif Nkind (Expr) = N_Integer_Literal
686 and then Is_Static_Expression (Expr)
688 Write_Info_Uint (Intval (Expr));
690 elsif Nkind (Expr) = N_String_Literal
691 and then Is_Static_Expression (Expr)
693 Write_Info_Slit (Strval (Expr));
696 Write_Info_Str ("<expr>");
708 end Write_Unit_Information;
710 ----------------------
711 -- Write_With_Lines --
712 ----------------------
714 procedure Write_With_Lines is
715 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
716 Num_Withs : Int := 0;
717 Unum : Unit_Number_Type;
719 Uname : Unit_Name_Type;
720 Fname : File_Name_Type;
721 Pname : constant Unit_Name_Type :=
722 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
723 Body_Fname : File_Name_Type;
726 procedure Write_With_File_Names
727 (Nam : in out File_Name_Type;
729 -- Write source file name Nam and ALI file name for unit index Idx.
730 -- Possibly change Nam to lowercase (generating a new file name).
732 --------------------------
733 -- Write_With_File_Name --
734 --------------------------
736 procedure Write_With_File_Names
737 (Nam : in out File_Name_Type;
741 if not File_Names_Case_Sensitive then
742 Get_Name_String (Nam);
743 To_Lower (Name_Buffer (1 .. Name_Len));
747 Write_Info_Name (Nam);
749 Write_Info_Name (Lib_File_Name (Nam, Idx));
750 end Write_With_File_Names;
752 -- Start of processing for Write_With_Lines
755 -- Loop to build the with table. A with on the main unit itself
756 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
757 -- the main unit is a subprogram with no spec, and a subunit of
758 -- it unnecessarily withs the parent.
760 for J in Units.First + 1 .. Last_Unit loop
762 -- Add element to with table if it is with'ed or if it is the
763 -- parent spec of the main unit (case of main unit is a child
764 -- unit). The latter with is not needed for semantic purposes,
765 -- but is required by the binder for elaboration purposes.
766 -- For preproc. data and def. files, there is no Unit_Name,
767 -- check for that first.
769 if Unit_Name (J) /= No_Unit_Name
770 and then (With_Flags (J) or else Unit_Name (J) = Pname)
772 Num_Withs := Num_Withs + 1;
773 With_Table (Num_Withs) := J;
777 -- Sort and output the table
779 Sort (With_Table (1 .. Num_Withs));
781 for J in 1 .. Num_Withs loop
782 Unum := With_Table (J);
783 Cunit := Units.Table (Unum).Cunit;
784 Uname := Units.Table (Unum).Unit_Name;
785 Fname := Units.Table (Unum).Unit_File_Name;
787 if Implicit_With (Unum) = Yes then
788 Write_Info_Initiate ('Z');
790 elsif Ekind (Cunit_Entity (Unum)) = E_Package
791 and then From_With_Type (Cunit_Entity (Unum))
793 Write_Info_Initiate ('Y');
796 Write_Info_Initiate ('W');
799 Write_Info_Char (' ');
800 Write_Info_Name (Uname);
802 -- Now we need to figure out the names of the files that contain
803 -- the with'ed unit. These will usually be the files for the body,
804 -- except in the case of a package that has no body. Note that we
805 -- have a specific exemption here for predefined library generics
806 -- (see comments for Generic_May_Lack_ALI). We do not generate
807 -- dependency upon the ALI file for such units. Older compilers
808 -- used to not support generating code (and ALI) for generics, and
809 -- we want to avoid having different processing (namely, different
810 -- lists of files to be compiled) for different stages of the
813 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
815 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
816 and then Generic_May_Lack_ALI (Fname))
818 -- In SPARK mode, always generate the dependencies on ALI
819 -- files, which are required to compute frame conditions
826 if Is_Spec_Name (Uname) then
829 (Get_Body_Name (Uname),
830 Subunit => False, May_Fail => True);
834 (Get_Body_Name (Uname));
836 if Body_Fname = No_File then
837 Body_Fname := Get_File_Name (Uname, Subunit => False);
838 Body_Index := Get_Unit_Index (Uname);
842 Body_Fname := Get_File_Name (Uname, Subunit => False);
843 Body_Index := Get_Unit_Index (Uname);
846 -- A package is considered to have a body if it requires
847 -- a body or if a body is present in Ada 83 mode.
849 if Body_Required (Cunit)
850 or else (Ada_Version = Ada_83
851 and then Full_Source_Name (Body_Fname) /= No_File)
853 Write_With_File_Names (Body_Fname, Body_Index);
855 Write_With_File_Names (Fname, Munit_Index (Unum));
858 if Ekind (Cunit_Entity (Unum)) = E_Package
859 and then From_With_Type (Cunit_Entity (Unum))
863 if Elab_Flags (Unum) then
864 Write_Info_Str (" E");
867 if Elab_All_Flags (Unum) then
868 Write_Info_Str (" EA");
871 if Elab_Des_Flags (Unum) then
872 Write_Info_Str (" ED");
875 if Elab_All_Des_Flags (Unum) then
876 Write_Info_Str (" AD");
883 end Write_With_Lines;
885 -- Start of processing for Write_ALI
888 -- We never write an ALI file if the original operating mode was
889 -- syntax-only (-gnats switch used in compiler invocation line)
891 if Original_Operating_Mode = Check_Syntax
892 or flag_compare_debug /= 0
897 -- Generation of ALI files may be disabled, e.g. for formal verification
900 if Disable_ALI_File then
904 -- Build sorted source dependency table. We do this right away, because
905 -- it is referenced by Up_To_Date_ALI_File_Exists.
907 for Unum in Units.First .. Last_Unit loop
908 if Cunit_Entity (Unum) = Empty
909 or else not From_With_Type (Cunit_Entity (Unum))
911 Num_Sdep := Num_Sdep + 1;
912 Sdep_Table (Num_Sdep) := Unum;
916 -- Sort the table so that the D lines are in order
918 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
920 -- If we are not generating code, and there is an up to date ALI file
921 -- file accessible, read it, and acquire the compilation arguments from
924 if Operating_Mode /= Generate_Code then
925 if Up_To_Date_ALI_File_Exists then
926 Update_Tables_From_ALI_File;
931 -- Otherwise acquire compilation arguments and prepare to write
932 -- out a new ali file.
934 Create_Output_Library_Info;
936 -- Output version line
938 Write_Info_Initiate ('V');
939 Write_Info_Str (" """);
940 Write_Info_Str (Verbose_Library_Version);
941 Write_Info_Char ('"');
945 -- Output main program line if this is acceptable main program
947 Output_Main_Program_Line : declare
948 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
951 procedure M_Parameters;
952 -- Output parameters for main program line
958 procedure M_Parameters is
960 if Main_Priority (Main_Unit) /= Default_Main_Priority then
961 Write_Info_Char (' ');
962 Write_Info_Nat (Main_Priority (Main_Unit));
965 if Opt.Time_Slice_Set then
966 Write_Info_Str (" T=");
967 Write_Info_Nat (Opt.Time_Slice_Value);
970 if Has_Allocator (Main_Unit) then
971 Write_Info_Str (" AB");
974 if Main_CPU (Main_Unit) /= Default_Main_CPU then
975 Write_Info_Str (" C=");
976 Write_Info_Nat (Main_CPU (Main_Unit));
979 Write_Info_Str (" W=");
981 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
986 -- Start of processing for Output_Main_Program_Line
989 if Nkind (U) = N_Subprogram_Body
991 (Nkind (U) = N_Package_Body
993 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
995 -- If the unit is a subprogram instance, the entity for the
996 -- subprogram is the alias of the visible entity, which is the
997 -- related instance of the wrapper package. We retrieve the
998 -- subprogram declaration of the desired entity.
1000 if Nkind (U) = N_Package_Body then
1001 U := Parent (Parent (
1002 Alias (Related_Instance (Defining_Unit_Name
1003 (Specification (Unit (Library_Unit (Parent (U)))))))));
1006 S := Specification (U);
1008 -- A generic subprogram is never a main program
1010 if Nkind (U) = N_Subprogram_Body
1011 and then Present (Corresponding_Spec (U))
1013 Ekind_In (Corresponding_Spec (U),
1014 E_Generic_Procedure, E_Generic_Function)
1018 elsif No (Parameter_Specifications (S)) then
1019 if Nkind (S) = N_Procedure_Specification then
1020 Write_Info_Initiate ('M');
1021 Write_Info_Str (" P");
1026 Nam : Node_Id := Defining_Unit_Name (S);
1029 -- If it is a child unit, get its simple name
1031 if Nkind (Nam) = N_Defining_Program_Unit_Name then
1032 Nam := Defining_Identifier (Nam);
1035 if Is_Integer_Type (Etype (Nam)) then
1036 Write_Info_Initiate ('M');
1037 Write_Info_Str (" F");
1044 end Output_Main_Program_Line;
1046 -- Write command argument ('A') lines
1048 for A in 1 .. Compilation_Switches.Last loop
1049 Write_Info_Initiate ('A');
1050 Write_Info_Char (' ');
1051 Write_Info_Str (Compilation_Switches.Table (A).all);
1052 Write_Info_Terminate;
1055 -- Output parameters ('P') line
1057 Write_Info_Initiate ('P');
1059 if Compilation_Errors then
1060 Write_Info_Str (" CE");
1063 if Opt.Detect_Blocking then
1064 Write_Info_Str (" DB");
1067 if Opt.Float_Format /= ' ' then
1068 Write_Info_Str (" F");
1070 if Opt.Float_Format = 'I' then
1071 Write_Info_Char ('I');
1073 elsif Opt.Float_Format_Long = 'D' then
1074 Write_Info_Char ('D');
1077 Write_Info_Char ('G');
1082 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
1084 if Locking_Policy /= ' ' then
1085 Write_Info_Str (" L");
1086 Write_Info_Char (Locking_Policy);
1089 if Queuing_Policy /= ' ' then
1090 Write_Info_Str (" Q");
1091 Write_Info_Char (Queuing_Policy);
1094 if Task_Dispatching_Policy /= ' ' then
1095 Write_Info_Str (" T");
1096 Write_Info_Char (Task_Dispatching_Policy);
1097 Write_Info_Char (' ');
1101 if Partition_Elaboration_Policy /= ' ' then
1102 Write_Info_Str (" E");
1103 Write_Info_Char (Partition_Elaboration_Policy);
1107 Write_Info_Str (" NO");
1110 if No_Run_Time_Mode then
1111 Write_Info_Str (" NR");
1114 if Normalize_Scalars then
1115 Write_Info_Str (" NS");
1118 if Sec_Stack_Used then
1119 Write_Info_Str (" SS");
1122 if Unreserve_All_Interrupts then
1123 Write_Info_Str (" UA");
1126 if Exception_Mechanism = Back_End_Exceptions then
1127 Write_Info_Str (" ZX");
1132 -- Before outputting the restrictions line, update the setting of
1133 -- the No_Elaboration_Code flag. Violations of this restriction
1134 -- cannot be detected until after the backend has been called since
1135 -- it is the backend that sets this flag. We have to check all units
1136 -- for which we have generated code
1138 for Unit in Units.First .. Last_Unit loop
1139 if Units.Table (Unit).Generate_Code
1140 or else Unit = Main_Unit
1142 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1143 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1148 -- Positional case (only if debug flag -gnatd.R is set)
1150 if Debug_Flag_Dot_RR then
1152 -- Output first restrictions line
1154 Write_Info_Initiate ('R');
1155 Write_Info_Char (' ');
1157 -- First the information for the boolean restrictions
1159 for R in All_Boolean_Restrictions loop
1160 if Main_Restrictions.Set (R)
1161 and then not Restriction_Warnings (R)
1163 Write_Info_Char ('r');
1164 elsif Main_Restrictions.Violated (R) then
1165 Write_Info_Char ('v');
1167 Write_Info_Char ('n');
1171 -- And now the information for the parameter restrictions
1173 for RP in All_Parameter_Restrictions loop
1174 if Main_Restrictions.Set (RP)
1175 and then not Restriction_Warnings (RP)
1177 Write_Info_Char ('r');
1178 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1180 Write_Info_Char ('n');
1183 if not Main_Restrictions.Violated (RP)
1184 or else RP not in Checked_Parameter_Restrictions
1186 Write_Info_Char ('n');
1188 Write_Info_Char ('v');
1189 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1191 if Main_Restrictions.Unknown (RP) then
1192 Write_Info_Char ('+');
1199 -- Named case (if debug flag -gnatd.R is not set)
1206 -- Write RN header line with preceding blank line
1209 Write_Info_Initiate ('R');
1210 Write_Info_Char ('N');
1213 -- First the lines for the boolean restrictions
1215 for R in All_Boolean_Restrictions loop
1216 if Main_Restrictions.Set (R)
1217 and then not Restriction_Warnings (R)
1220 elsif Main_Restrictions.Violated (R) then
1226 Write_Info_Initiate ('R');
1227 Write_Info_Char (C);
1228 Write_Info_Char (' ');
1229 Write_Info_Str (All_Boolean_Restrictions'Image (R));
1237 -- And now the lines for the parameter restrictions
1239 for RP in All_Parameter_Restrictions loop
1240 if Main_Restrictions.Set (RP)
1241 and then not Restriction_Warnings (RP)
1243 Write_Info_Initiate ('R');
1244 Write_Info_Str ("R ");
1245 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1246 Write_Info_Char ('=');
1247 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1251 if not Main_Restrictions.Violated (RP)
1252 or else RP not in Checked_Parameter_Restrictions
1256 Write_Info_Initiate ('R');
1257 Write_Info_Str ("V ");
1258 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1259 Write_Info_Char ('=');
1260 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1262 if Main_Restrictions.Unknown (RP) then
1263 Write_Info_Char ('+');
1271 -- Output R lines for No_Dependence entries
1273 for J in No_Dependences.First .. No_Dependences.Last loop
1274 if In_Extended_Main_Source_Unit (No_Dependences.Table (J).Unit)
1275 and then not No_Dependences.Table (J).Warn
1277 Write_Info_Initiate ('R');
1278 Write_Info_Char (' ');
1279 Write_Unit_Name (No_Dependences.Table (J).Unit);
1284 -- Output interrupt state lines
1286 for J in Interrupt_States.First .. Interrupt_States.Last loop
1287 Write_Info_Initiate ('I');
1288 Write_Info_Char (' ');
1289 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1290 Write_Info_Char (' ');
1291 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1292 Write_Info_Char (' ');
1294 (Nat (Get_Logical_Line_Number
1295 (Interrupt_States.Table (J).Pragma_Loc)));
1299 -- Output priority specific dispatching lines
1301 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1302 Write_Info_Initiate ('S');
1303 Write_Info_Char (' ');
1304 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1305 Write_Info_Char (' ');
1306 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1307 Write_Info_Char (' ');
1308 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1309 Write_Info_Char (' ');
1311 (Nat (Get_Logical_Line_Number
1312 (Specific_Dispatching.Table (J).Pragma_Loc)));
1316 -- Loop through file table to output information for all units for which
1317 -- we have generated code, as marked by the Generate_Code flag.
1319 for Unit in Units.First .. Last_Unit loop
1320 if Units.Table (Unit).Generate_Code
1321 or else Unit = Main_Unit
1323 Write_Info_EOL; -- blank line
1324 Write_Unit_Information (Unit);
1328 Write_Info_EOL; -- blank line
1330 -- Output external version reference lines
1332 for J in 1 .. Version_Ref.Last loop
1333 Write_Info_Initiate ('E');
1334 Write_Info_Char (' ');
1336 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1337 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1343 -- Prepare to output the source dependency lines
1346 Unum : Unit_Number_Type;
1347 -- Number of unit being output
1349 Sind : Source_File_Index;
1350 -- Index of corresponding source file
1352 Fname : File_Name_Type;
1355 for J in 1 .. Num_Sdep loop
1356 Unum := Sdep_Table (J);
1357 Units.Table (Unum).Dependency_Num := J;
1358 Sind := Units.Table (Unum).Source_Index;
1360 Write_Info_Initiate ('D');
1361 Write_Info_Char (' ');
1363 -- Normal case of a unit entry with a source index
1365 if Sind /= No_Source_File then
1366 Fname := File_Name (Sind);
1368 -- Ensure that on platforms where the file names are not
1369 -- case sensitive, the recorded file name is in lower case.
1371 if not File_Names_Case_Sensitive then
1372 Get_Name_String (Fname);
1373 To_Lower (Name_Buffer (1 .. Name_Len));
1377 Write_Info_Name (Fname);
1378 Write_Info_Tab (25);
1379 Write_Info_Str (String (Time_Stamp (Sind)));
1380 Write_Info_Char (' ');
1381 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1383 -- If subunit, add unit name, omitting the %b at the end
1385 if Present (Cunit (Unum))
1386 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1388 Get_Decoded_Name_String (Unit_Name (Unum));
1389 Write_Info_Char (' ');
1390 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1393 -- If Source_Reference pragma used output information
1395 if Num_SRef_Pragmas (Sind) > 0 then
1396 Write_Info_Char (' ');
1398 if Num_SRef_Pragmas (Sind) = 1 then
1399 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1404 Write_Info_Char (':');
1405 Write_Info_Name (Reference_Name (Sind));
1408 -- Case where there is no source index (happens for missing
1409 -- files). In this case we write a dummy time stamp.
1412 Write_Info_Name (Unit_File_Name (Unum));
1413 Write_Info_Tab (25);
1414 Write_Info_Str (String (Dummy_Time_Stamp));
1415 Write_Info_Char (' ');
1416 Write_Info_Str (Get_Hex_String (0));
1423 -- Output cross-references
1425 if Opt.Xref_Active then
1429 -- Output SCO information if present
1431 if Generate_SCO then
1435 -- Output SPARK cross-reference information if needed
1437 if Opt.Xref_Active and then SPARK_Mode then
1438 SPARK_Specific.Collect_SPARK_Xrefs (Sdep_Table => Sdep_Table,
1439 Num_Sdep => Num_Sdep);
1440 SPARK_Specific.Output_SPARK_Xrefs;
1443 -- Output final blank line and we are done. This final blank line is
1444 -- probably junk, but we don't feel like making an incompatible change!
1446 Write_Info_Terminate;
1447 Close_Output_Library_Info;
1450 ---------------------
1451 -- Write_Unit_Name --
1452 ---------------------
1454 procedure Write_Unit_Name (N : Node_Id) is
1456 if Nkind (N) = N_Identifier then
1457 Write_Info_Name (Chars (N));
1460 pragma Assert (Nkind (N) = N_Selected_Component);
1461 Write_Unit_Name (Prefix (N));
1462 Write_Info_Char ('.');
1463 Write_Unit_Name (Selector_Name (N));
1465 end Write_Unit_Name;