Implement -mmemcpy-strategy= and -mmemset-strategy= options
[official-gcc.git] / gcc / ada / lib-writ.adb
blobc95b9dc4f837c535596b6498f34de5078f9766ab
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B . W R I T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with ALI; use ALI;
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;
38 with Opt; use Opt;
39 with Osint; use Osint;
40 with Osint.C; use Osint.C;
41 with Par;
42 with Par_SCO; use Par_SCO;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Scn; use Scn;
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
71 begin
72 Units.Increment_Last;
73 Units.Table (Units.Last) :=
74 (Unit_File_Name => File_Name (S),
75 Unit_Name => No_Unit_Name,
76 Expected_Unit => No_Unit_Name,
77 Source_Index => S,
78 Cunit => Empty,
79 Cunit_Entity => Empty,
80 Dependency_Num => 0,
81 Dynamic_Elab => False,
82 Fatal_Error => False,
83 Generate_Code => False,
84 Has_Allocator => False,
85 Has_RACW => False,
86 Is_Compiler_Unit => False,
87 Ident_String => Empty,
88 Loading => False,
89 Main_Priority => -1,
90 Main_CPU => -1,
91 Munit_Index => 0,
92 Serial_Number => 0,
93 Version => 0,
94 Error_Location => No_Location,
95 OA_Setting => 'O',
96 SPARK_Mode_Pragma => Empty);
97 end Add_Preprocessing_Dependency;
99 ------------------------------
100 -- Ensure_System_Dependency --
101 ------------------------------
103 procedure Ensure_System_Dependency is
104 System_Uname : Unit_Name_Type;
105 -- Unit name for system spec if needed for dummy entry
107 System_Fname : File_Name_Type;
108 -- File name for system spec if needed for dummy entry
110 begin
111 -- Nothing to do if we already compiled System
113 for Unum in Units.First .. Last_Unit loop
114 if Units.Table (Unum).Source_Index = System_Source_File_Index then
115 return;
116 end if;
117 end loop;
119 -- If no entry for system.ads in the units table, then add a entry
120 -- to the units table for system.ads, which will be referenced when
121 -- the ali file is generated. We need this because every unit depends
122 -- on system as a result of Targparm scanning the system.ads file to
123 -- determine the target dependent parameters for the compilation.
125 Name_Len := 6;
126 Name_Buffer (1 .. 6) := "system";
127 System_Uname := Name_To_Unit_Name (Name_Enter);
128 System_Fname := File_Name (System_Source_File_Index);
130 Units.Increment_Last;
131 Units.Table (Units.Last) := (
132 Unit_File_Name => System_Fname,
133 Unit_Name => System_Uname,
134 Expected_Unit => System_Uname,
135 Source_Index => System_Source_File_Index,
136 Cunit => Empty,
137 Cunit_Entity => Empty,
138 Dependency_Num => 0,
139 Dynamic_Elab => False,
140 Fatal_Error => False,
141 Generate_Code => False,
142 Has_Allocator => False,
143 Has_RACW => False,
144 Is_Compiler_Unit => False,
145 Ident_String => Empty,
146 Loading => False,
147 Main_Priority => -1,
148 Main_CPU => -1,
149 Munit_Index => 0,
150 Serial_Number => 0,
151 Version => 0,
152 Error_Location => No_Location,
153 OA_Setting => 'O',
154 SPARK_Mode_Pragma => Empty);
156 -- Parse system.ads so that the checksum is set right
157 -- Style checks are not applied.
159 declare
160 Save_Mindex : constant Nat := Multiple_Unit_Index;
161 Save_Style : constant Boolean := Style_Check;
162 begin
163 Multiple_Unit_Index := 0;
164 Style_Check := False;
165 Initialize_Scanner (Units.Last, System_Source_File_Index);
166 Discard_List (Par (Configuration_Pragmas => False));
167 Style_Check := Save_Style;
168 Multiple_Unit_Index := Save_Mindex;
169 end;
170 end Ensure_System_Dependency;
172 ---------------
173 -- Write_ALI --
174 ---------------
176 procedure Write_ALI (Object : Boolean) is
178 ----------------
179 -- Local Data --
180 ----------------
182 Last_Unit : constant Unit_Number_Type := Units.Last;
183 -- Record unit number of last unit. We capture this in case we
184 -- have to add a dummy entry to the unit table for package System.
186 With_Flags : array (Units.First .. Last_Unit) of Boolean;
187 -- Array of flags to show which units are with'ed
189 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
190 -- Array of flags to show which units have pragma Elaborate set
192 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
193 -- Array of flags to show which units have pragma Elaborate All set
195 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
196 -- Array of flags to show which units have Elaborate_Desirable set
198 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
199 -- Array of flags to show which units have Elaborate_All_Desirable set
201 type Yes_No is (Unknown, Yes, No);
202 Implicit_With : array (Units.First .. Last_Unit) of Yes_No;
203 -- Indicates if an implicit with has been given for the unit. Yes if
204 -- certainly present, no if certainly absent, unkonwn if not known.
206 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
207 -- Sorted table of source dependencies. One extra entry in case we
208 -- have to add a dummy entry for System.
210 Num_Sdep : Nat := 0;
211 -- Number of active entries in Sdep_Table
213 flag_compare_debug : Int;
214 pragma Import (C, flag_compare_debug);
215 -- Import from toplev.c
217 -----------------------
218 -- Local Subprograms --
219 -----------------------
221 procedure Collect_Withs (Cunit : Node_Id);
222 -- Collect with lines for entries in the context clause of the
223 -- given compilation unit, Cunit.
225 procedure Update_Tables_From_ALI_File;
226 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
227 -- function), update tables from the ALI information, including
228 -- specifically the Compilation_Switches table.
230 function Up_To_Date_ALI_File_Exists return Boolean;
231 -- If there exists an ALI file that is up to date, then this function
232 -- initializes the tables in the ALI spec to contain information on
233 -- this file (using Scan_ALI) and returns True. If no file exists,
234 -- or the file is not up to date, then False is returned.
236 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
237 -- Write out the library information for one unit for which code is
238 -- generated (includes unit line and with lines).
240 procedure Write_With_Lines;
241 -- Write out with lines collected by calls to Collect_Withs
243 -------------------
244 -- Collect_Withs --
245 -------------------
247 procedure Collect_Withs (Cunit : Node_Id) is
248 Item : Node_Id;
249 Unum : Unit_Number_Type;
251 begin
252 Item := First (Context_Items (Cunit));
253 while Present (Item) loop
255 -- Process with clause
257 -- Ada 2005 (AI-50217): limited with_clauses do not create
258 -- dependencies, but must be recorded as components of the
259 -- partition, in case there is no regular with_clause for
260 -- the unit anywhere else.
262 if Nkind (Item) = N_With_Clause then
263 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
264 With_Flags (Unum) := True;
266 if not Limited_Present (Item) then
267 if Elaborate_Present (Item) then
268 Elab_Flags (Unum) := True;
269 end if;
271 if Elaborate_All_Present (Item) then
272 Elab_All_Flags (Unum) := True;
273 end if;
275 if Elaborate_All_Desirable (Item) then
276 Elab_All_Des_Flags (Unum) := True;
277 end if;
279 if Elaborate_Desirable (Item) then
280 Elab_Des_Flags (Unum) := True;
281 end if;
283 else
284 Set_From_With_Type (Cunit_Entity (Unum));
285 end if;
287 if Implicit_With (Unum) /= Yes then
288 if Implicit_With_From_Instantiation (Item) then
289 Implicit_With (Unum) := Yes;
290 else
291 Implicit_With (Unum) := No;
292 end if;
293 end if;
294 end if;
296 Next (Item);
297 end loop;
298 end Collect_Withs;
300 --------------------------------
301 -- Up_To_Date_ALI_File_Exists --
302 --------------------------------
304 function Up_To_Date_ALI_File_Exists return Boolean is
305 Name : File_Name_Type;
306 Text : Text_Buffer_Ptr;
307 Id : Sdep_Id;
308 Sind : Source_File_Index;
310 begin
311 Opt.Check_Object_Consistency := True;
312 Read_Library_Info (Name, Text);
314 -- Return if we could not find an ALI file
316 if Text = null then
317 return False;
318 end if;
320 -- Return if ALI file has bad format
322 Initialize_ALI;
324 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
325 return False;
326 end if;
328 -- If we have an OK ALI file, check if it is up to date
329 -- Note that we assume that the ALI read has all the entries
330 -- we have in our table, plus some additional ones (that can
331 -- come from expansion).
333 Id := First_Sdep_Entry;
334 for J in 1 .. Num_Sdep loop
335 Sind := Units.Table (Sdep_Table (J)).Source_Index;
337 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
338 if Id = Sdep.Last then
339 return False;
340 else
341 Id := Id + 1;
342 end if;
343 end loop;
345 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
346 return False;
347 end if;
348 end loop;
350 return True;
351 end Up_To_Date_ALI_File_Exists;
353 ---------------------------------
354 -- Update_Tables_From_ALI_File --
355 ---------------------------------
357 procedure Update_Tables_From_ALI_File is
358 begin
359 -- Build Compilation_Switches table
361 Compilation_Switches.Init;
363 for J in First_Arg_Entry .. Args.Last loop
364 Compilation_Switches.Increment_Last;
365 Compilation_Switches.Table (Compilation_Switches.Last) :=
366 Args.Table (J);
367 end loop;
368 end Update_Tables_From_ALI_File;
370 ----------------------------
371 -- Write_Unit_Information --
372 ----------------------------
374 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
375 Unode : constant Node_Id := Cunit (Unit_Num);
376 Ukind : constant Node_Kind := Nkind (Unit (Unode));
377 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
378 Pnode : Node_Id;
380 begin
381 Write_Info_Initiate ('U');
382 Write_Info_Char (' ');
383 Write_Info_Name (Unit_Name (Unit_Num));
384 Write_Info_Tab (25);
385 Write_Info_Name (Unit_File_Name (Unit_Num));
387 Write_Info_Tab (49);
388 Write_Info_Str (Version_Get (Unit_Num));
390 -- Add BD parameter if Elaborate_Body pragma desirable
392 if Ekind (Uent) = E_Package
393 and then Elaborate_Body_Desirable (Uent)
394 then
395 Write_Info_Str (" BD");
396 end if;
398 -- Add BN parameter if body needed for SAL
400 if (Is_Subprogram (Uent)
401 or else Ekind (Uent) = E_Package
402 or else Is_Generic_Unit (Uent))
403 and then Body_Needed_For_SAL (Uent)
404 then
405 Write_Info_Str (" BN");
406 end if;
408 if Dynamic_Elab (Unit_Num) then
409 Write_Info_Str (" DE");
410 end if;
412 -- Set the Elaborate_Body indication if either an explicit pragma
413 -- was present, or if this is an instantiation.
415 if Has_Pragma_Elaborate_Body (Uent)
416 or else (Ukind = N_Package_Declaration
417 and then Is_Generic_Instance (Uent)
418 and then Present (Corresponding_Body (Unit (Unode))))
419 then
420 Write_Info_Str (" EB");
421 end if;
423 -- Now see if we should tell the binder that an elaboration entity
424 -- is present, which must be set to true during elaboration.
425 -- We generate the indication if the following condition is met:
427 -- If this is a spec ...
429 if (Is_Subprogram (Uent)
430 or else
431 Ekind (Uent) = E_Package
432 or else
433 Is_Generic_Unit (Uent))
435 -- and an elaboration entity was declared ...
437 and then Present (Elaboration_Entity (Uent))
439 -- and either the elaboration flag is required ...
441 and then
442 (Elaboration_Entity_Required (Uent)
444 -- or this unit has elaboration code ...
446 or else not Has_No_Elaboration_Code (Unode)
448 -- or this unit has a separate body and this
449 -- body has elaboration code.
451 or else
452 (Ekind (Uent) = E_Package
453 and then Present (Body_Entity (Uent))
454 and then
455 not Has_No_Elaboration_Code
456 (Parent
457 (Declaration_Node
458 (Body_Entity (Uent))))))
459 then
460 if Convention (Uent) = Convention_CIL then
462 -- Special case for generic CIL packages which never have
463 -- elaboration code
465 Write_Info_Str (" NE");
467 else
468 Write_Info_Str (" EE");
469 end if;
470 end if;
472 if Has_No_Elaboration_Code (Unode) then
473 Write_Info_Str (" NE");
474 end if;
476 Write_Info_Str (" O");
477 Write_Info_Char (OA_Setting (Unit_Num));
479 if Ekind_In (Uent, E_Package, E_Package_Body)
480 and then Present (Finalizer (Uent))
481 then
482 Write_Info_Str (" PF");
483 end if;
485 if Is_Preelaborated (Uent) then
486 Write_Info_Str (" PR");
487 end if;
489 if Is_Pure (Uent) then
490 Write_Info_Str (" PU");
491 end if;
493 if Has_RACW (Unit_Num) then
494 Write_Info_Str (" RA");
495 end if;
497 if Is_Remote_Call_Interface (Uent) then
498 Write_Info_Str (" RC");
499 end if;
501 if Is_Remote_Types (Uent) then
502 Write_Info_Str (" RT");
503 end if;
505 if Is_Shared_Passive (Uent) then
506 Write_Info_Str (" SP");
507 end if;
509 if Ukind = N_Subprogram_Declaration
510 or else Ukind = N_Subprogram_Body
511 then
512 Write_Info_Str (" SU");
514 elsif Ukind = N_Package_Declaration
515 or else
516 Ukind = N_Package_Body
517 then
518 -- If this is a wrapper package for a subprogram instantiation,
519 -- the user view is the subprogram. Note that in this case the
520 -- ali file contains both the spec and body of the instance.
522 if Is_Wrapper_Package (Uent) then
523 Write_Info_Str (" SU");
524 else
525 Write_Info_Str (" PK");
526 end if;
528 elsif Ukind = N_Generic_Package_Declaration then
529 Write_Info_Str (" PK");
531 end if;
533 if Ukind in N_Generic_Declaration
534 or else
535 (Present (Library_Unit (Unode))
536 and then
537 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
538 then
539 Write_Info_Str (" GE");
540 end if;
542 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
543 case Identifier_Casing (Source_Index (Unit_Num)) is
544 when All_Lower_Case => Write_Info_Str (" IL");
545 when All_Upper_Case => Write_Info_Str (" IU");
546 when others => null;
547 end case;
549 case Keyword_Casing (Source_Index (Unit_Num)) is
550 when Mixed_Case => Write_Info_Str (" KM");
551 when All_Upper_Case => Write_Info_Str (" KU");
552 when others => null;
553 end case;
554 end if;
556 if Initialize_Scalars or else Invalid_Value_Used then
557 Write_Info_Str (" IS");
558 end if;
560 Write_Info_EOL;
562 -- Generate with lines, first those that are directly with'ed
564 for J in With_Flags'Range loop
565 With_Flags (J) := False;
566 Elab_Flags (J) := False;
567 Elab_All_Flags (J) := False;
568 Elab_Des_Flags (J) := False;
569 Elab_All_Des_Flags (J) := False;
570 Implicit_With (J) := Unknown;
571 end loop;
573 Collect_Withs (Unode);
575 -- For a body, we must also check for any subunits which belong to
576 -- it and which have context clauses of their own, since these
577 -- with'ed units are part of its own elaboration dependencies.
579 if Nkind (Unit (Unode)) in N_Unit_Body then
580 for S in Units.First .. Last_Unit loop
582 -- We are only interested in subunits.
583 -- For preproc. data and def. files, Cunit is Empty, so
584 -- we need to test that first.
586 if Cunit (S) /= Empty
587 and then Nkind (Unit (Cunit (S))) = N_Subunit
588 then
589 Pnode := Library_Unit (Cunit (S));
591 -- In gnatc mode, the errors in the subunits will not
592 -- have been recorded, but the analysis of the subunit
593 -- may have failed. There is no information to add to
594 -- ALI file in this case.
596 if No (Pnode) then
597 exit;
598 end if;
600 -- Find ultimate parent of the subunit
602 while Nkind (Unit (Pnode)) = N_Subunit loop
603 Pnode := Library_Unit (Pnode);
604 end loop;
606 -- See if it belongs to current unit, and if so, include
607 -- its with_clauses.
609 if Pnode = Unode then
610 Collect_Withs (Cunit (S));
611 end if;
612 end if;
613 end loop;
614 end if;
616 Write_With_Lines;
618 -- Output linker option lines
620 for J in 1 .. Linker_Option_Lines.Last loop
621 declare
622 S : Linker_Option_Entry renames Linker_Option_Lines.Table (J);
623 begin
624 if S.Unit = Unit_Num then
625 Write_Info_Initiate ('L');
626 Write_Info_Char (' ');
627 Write_Info_Slit (S.Option);
628 Write_Info_EOL;
629 end if;
630 end;
631 end loop;
633 -- Output notes
635 for J in 1 .. Notes.Last loop
636 declare
637 N : constant Node_Id := Notes.Table (J).Pragma_Node;
638 L : constant Source_Ptr := Sloc (N);
639 U : constant Unit_Number_Type := Notes.Table (J).Unit;
640 C : Character;
642 begin
643 if U = Unit_Num then
644 Write_Info_Initiate ('N');
645 Write_Info_Char (' ');
647 case Chars (Pragma_Identifier (N)) is
648 when Name_Annotate =>
649 C := 'A';
650 when Name_Comment =>
651 C := 'C';
652 when Name_Ident =>
653 C := 'I';
654 when Name_Title =>
655 C := 'T';
656 when Name_Subtitle =>
657 C := 'S';
658 when others =>
659 raise Program_Error;
660 end case;
662 Write_Info_Char (C);
663 Write_Info_Int (Int (Get_Logical_Line_Number (L)));
664 Write_Info_Char (':');
665 Write_Info_Int (Int (Get_Column_Number (L)));
667 declare
668 A : Node_Id;
670 begin
671 A := First (Pragma_Argument_Associations (N));
672 while Present (A) loop
673 Write_Info_Char (' ');
675 if Chars (A) /= No_Name then
676 Write_Info_Name (Chars (A));
677 Write_Info_Char (':');
678 end if;
680 declare
681 Expr : constant Node_Id := Expression (A);
683 begin
684 if Nkind (Expr) = N_Identifier then
685 Write_Info_Name (Chars (Expr));
687 elsif Nkind (Expr) = N_Integer_Literal
688 and then Is_Static_Expression (Expr)
689 then
690 Write_Info_Uint (Intval (Expr));
692 elsif Nkind (Expr) = N_String_Literal
693 and then Is_Static_Expression (Expr)
694 then
695 Write_Info_Slit (Strval (Expr));
697 else
698 Write_Info_Str ("<expr>");
699 end if;
700 end;
702 Next (A);
703 end loop;
704 end;
706 Write_Info_EOL;
707 end if;
708 end;
709 end loop;
710 end Write_Unit_Information;
712 ----------------------
713 -- Write_With_Lines --
714 ----------------------
716 procedure Write_With_Lines is
717 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
718 Num_Withs : Int := 0;
719 Unum : Unit_Number_Type;
720 Cunit : Node_Id;
721 Uname : Unit_Name_Type;
722 Fname : File_Name_Type;
723 Pname : constant Unit_Name_Type :=
724 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
725 Body_Fname : File_Name_Type;
726 Body_Index : Nat;
728 procedure Write_With_File_Names
729 (Nam : in out File_Name_Type;
730 Idx : Nat);
731 -- Write source file name Nam and ALI file name for unit index Idx.
732 -- Possibly change Nam to lowercase (generating a new file name).
734 --------------------------
735 -- Write_With_File_Name --
736 --------------------------
738 procedure Write_With_File_Names
739 (Nam : in out File_Name_Type;
740 Idx : Nat)
742 begin
743 if not File_Names_Case_Sensitive then
744 Get_Name_String (Nam);
745 To_Lower (Name_Buffer (1 .. Name_Len));
746 Nam := Name_Find;
747 end if;
749 Write_Info_Name (Nam);
750 Write_Info_Tab (49);
751 Write_Info_Name (Lib_File_Name (Nam, Idx));
752 end Write_With_File_Names;
754 -- Start of processing for Write_With_Lines
756 begin
757 -- Loop to build the with table. A with on the main unit itself
758 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
759 -- the main unit is a subprogram with no spec, and a subunit of
760 -- it unnecessarily withs the parent.
762 for J in Units.First + 1 .. Last_Unit loop
764 -- Add element to with table if it is with'ed or if it is the
765 -- parent spec of the main unit (case of main unit is a child
766 -- unit). The latter with is not needed for semantic purposes,
767 -- but is required by the binder for elaboration purposes.
768 -- For preproc. data and def. files, there is no Unit_Name,
769 -- check for that first.
771 if Unit_Name (J) /= No_Unit_Name
772 and then (With_Flags (J) or else Unit_Name (J) = Pname)
773 then
774 Num_Withs := Num_Withs + 1;
775 With_Table (Num_Withs) := J;
776 end if;
777 end loop;
779 -- Sort and output the table
781 Sort (With_Table (1 .. Num_Withs));
783 for J in 1 .. Num_Withs loop
784 Unum := With_Table (J);
785 Cunit := Units.Table (Unum).Cunit;
786 Uname := Units.Table (Unum).Unit_Name;
787 Fname := Units.Table (Unum).Unit_File_Name;
789 if Implicit_With (Unum) = Yes then
790 Write_Info_Initiate ('Z');
792 elsif Ekind (Cunit_Entity (Unum)) = E_Package
793 and then From_With_Type (Cunit_Entity (Unum))
794 then
795 Write_Info_Initiate ('Y');
797 else
798 Write_Info_Initiate ('W');
799 end if;
801 Write_Info_Char (' ');
802 Write_Info_Name (Uname);
804 -- Now we need to figure out the names of the files that contain
805 -- the with'ed unit. These will usually be the files for the body,
806 -- except in the case of a package that has no body. Note that we
807 -- have a specific exemption here for predefined library generics
808 -- (see comments for Generic_May_Lack_ALI). We do not generate
809 -- dependency upon the ALI file for such units. Older compilers
810 -- used to not support generating code (and ALI) for generics, and
811 -- we want to avoid having different processing (namely, different
812 -- lists of files to be compiled) for different stages of the
813 -- bootstrap.
815 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
816 or else
817 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
818 and then Generic_May_Lack_ALI (Fname))
820 -- In SPARK mode, always generate the dependencies on ALI
821 -- files, which are required to compute frame conditions
822 -- of subprograms.
824 or else SPARK_Mode
825 then
826 Write_Info_Tab (25);
828 if Is_Spec_Name (Uname) then
829 Body_Fname :=
830 Get_File_Name
831 (Get_Body_Name (Uname),
832 Subunit => False, May_Fail => True);
834 Body_Index :=
835 Get_Unit_Index
836 (Get_Body_Name (Uname));
838 if Body_Fname = No_File then
839 Body_Fname := Get_File_Name (Uname, Subunit => False);
840 Body_Index := Get_Unit_Index (Uname);
841 end if;
843 else
844 Body_Fname := Get_File_Name (Uname, Subunit => False);
845 Body_Index := Get_Unit_Index (Uname);
846 end if;
848 -- A package is considered to have a body if it requires
849 -- a body or if a body is present in Ada 83 mode.
851 if Body_Required (Cunit)
852 or else (Ada_Version = Ada_83
853 and then Full_Source_Name (Body_Fname) /= No_File)
854 then
855 Write_With_File_Names (Body_Fname, Body_Index);
856 else
857 Write_With_File_Names (Fname, Munit_Index (Unum));
858 end if;
860 if Ekind (Cunit_Entity (Unum)) = E_Package
861 and then From_With_Type (Cunit_Entity (Unum))
862 then
863 null;
864 else
865 if Elab_Flags (Unum) then
866 Write_Info_Str (" E");
867 end if;
869 if Elab_All_Flags (Unum) then
870 Write_Info_Str (" EA");
871 end if;
873 if Elab_Des_Flags (Unum) then
874 Write_Info_Str (" ED");
875 end if;
877 if Elab_All_Des_Flags (Unum) then
878 Write_Info_Str (" AD");
879 end if;
880 end if;
881 end if;
883 Write_Info_EOL;
884 end loop;
886 -- Finally generate the special lines for cases of Restriction_Set
887 -- with No_Dependence and no restriction present.
889 declare
890 Unam : Unit_Name_Type;
892 begin
893 for J in Restriction_Set_Dependences.First ..
894 Restriction_Set_Dependences.Last
895 loop
896 Unam := Restriction_Set_Dependences.Table (J);
898 -- Don't need an entry if already in the unit table
900 for U in 0 .. Last_Unit loop
901 if Unit_Name (U) = Unam then
902 goto Continue;
903 end if;
904 end loop;
906 -- Otherwise generate the entry
908 Write_Info_Initiate ('W');
909 Write_Info_Char (' ');
910 Write_Info_Name (Unam);
911 Write_Info_EOL;
913 <<Continue>>
914 null;
915 end loop;
916 end;
917 end Write_With_Lines;
919 -- Start of processing for Write_ALI
921 begin
922 -- We never write an ALI file if the original operating mode was
923 -- syntax-only (-gnats switch used in compiler invocation line)
925 if Original_Operating_Mode = Check_Syntax
926 or flag_compare_debug /= 0
927 then
928 return;
929 end if;
931 -- Generation of ALI files may be disabled, e.g. for formal verification
932 -- back-end.
934 if Disable_ALI_File then
935 return;
936 end if;
938 -- Build sorted source dependency table. We do this right away, because
939 -- it is referenced by Up_To_Date_ALI_File_Exists.
941 for Unum in Units.First .. Last_Unit loop
942 if Cunit_Entity (Unum) = Empty
943 or else not From_With_Type (Cunit_Entity (Unum))
944 then
945 Num_Sdep := Num_Sdep + 1;
946 Sdep_Table (Num_Sdep) := Unum;
947 end if;
948 end loop;
950 -- Sort the table so that the D lines are in order
952 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
954 -- If we are not generating code, and there is an up to date ALI file
955 -- file accessible, read it, and acquire the compilation arguments from
956 -- this file.
958 if Operating_Mode /= Generate_Code then
959 if Up_To_Date_ALI_File_Exists then
960 Update_Tables_From_ALI_File;
961 return;
962 end if;
963 end if;
965 -- Otherwise acquire compilation arguments and prepare to write
966 -- out a new ali file.
968 Create_Output_Library_Info;
970 -- Output version line
972 Write_Info_Initiate ('V');
973 Write_Info_Str (" """);
974 Write_Info_Str (Verbose_Library_Version);
975 Write_Info_Char ('"');
977 Write_Info_EOL;
979 -- Output main program line if this is acceptable main program
981 Output_Main_Program_Line : declare
982 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
983 S : Node_Id;
985 procedure M_Parameters;
986 -- Output parameters for main program line
988 ------------------
989 -- M_Parameters --
990 ------------------
992 procedure M_Parameters is
993 begin
994 if Main_Priority (Main_Unit) /= Default_Main_Priority then
995 Write_Info_Char (' ');
996 Write_Info_Nat (Main_Priority (Main_Unit));
997 end if;
999 if Opt.Time_Slice_Set then
1000 Write_Info_Str (" T=");
1001 Write_Info_Nat (Opt.Time_Slice_Value);
1002 end if;
1004 if Has_Allocator (Main_Unit) then
1005 Write_Info_Str (" AB");
1006 end if;
1008 if Main_CPU (Main_Unit) /= Default_Main_CPU then
1009 Write_Info_Str (" C=");
1010 Write_Info_Nat (Main_CPU (Main_Unit));
1011 end if;
1013 Write_Info_Str (" W=");
1014 Write_Info_Char
1015 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
1017 Write_Info_EOL;
1018 end M_Parameters;
1020 -- Start of processing for Output_Main_Program_Line
1022 begin
1023 if Nkind (U) = N_Subprogram_Body
1024 or else
1025 (Nkind (U) = N_Package_Body
1026 and then
1027 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
1028 then
1029 -- If the unit is a subprogram instance, the entity for the
1030 -- subprogram is the alias of the visible entity, which is the
1031 -- related instance of the wrapper package. We retrieve the
1032 -- subprogram declaration of the desired entity.
1034 if Nkind (U) = N_Package_Body then
1035 U := Parent (Parent (
1036 Alias (Related_Instance (Defining_Unit_Name
1037 (Specification (Unit (Library_Unit (Parent (U)))))))));
1038 end if;
1040 S := Specification (U);
1042 -- A generic subprogram is never a main program
1044 if Nkind (U) = N_Subprogram_Body
1045 and then Present (Corresponding_Spec (U))
1046 and then
1047 Ekind_In (Corresponding_Spec (U),
1048 E_Generic_Procedure, E_Generic_Function)
1049 then
1050 null;
1052 elsif No (Parameter_Specifications (S)) then
1053 if Nkind (S) = N_Procedure_Specification then
1054 Write_Info_Initiate ('M');
1055 Write_Info_Str (" P");
1056 M_Parameters;
1058 else
1059 declare
1060 Nam : Node_Id := Defining_Unit_Name (S);
1062 begin
1063 -- If it is a child unit, get its simple name
1065 if Nkind (Nam) = N_Defining_Program_Unit_Name then
1066 Nam := Defining_Identifier (Nam);
1067 end if;
1069 if Is_Integer_Type (Etype (Nam)) then
1070 Write_Info_Initiate ('M');
1071 Write_Info_Str (" F");
1072 M_Parameters;
1073 end if;
1074 end;
1075 end if;
1076 end if;
1077 end if;
1078 end Output_Main_Program_Line;
1080 -- Write command argument ('A') lines
1082 for A in 1 .. Compilation_Switches.Last loop
1083 Write_Info_Initiate ('A');
1084 Write_Info_Char (' ');
1085 Write_Info_Str (Compilation_Switches.Table (A).all);
1086 Write_Info_Terminate;
1087 end loop;
1089 -- Output parameters ('P') line
1091 Write_Info_Initiate ('P');
1093 if Compilation_Errors then
1094 Write_Info_Str (" CE");
1095 end if;
1097 if Opt.Detect_Blocking then
1098 Write_Info_Str (" DB");
1099 end if;
1101 if Opt.Float_Format /= ' ' then
1102 Write_Info_Str (" F");
1104 if Opt.Float_Format = 'I' then
1105 Write_Info_Char ('I');
1107 elsif Opt.Float_Format_Long = 'D' then
1108 Write_Info_Char ('D');
1110 else
1111 Write_Info_Char ('G');
1112 end if;
1113 end if;
1115 if Tasking_Used
1116 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
1117 then
1118 if Locking_Policy /= ' ' then
1119 Write_Info_Str (" L");
1120 Write_Info_Char (Locking_Policy);
1121 end if;
1123 if Queuing_Policy /= ' ' then
1124 Write_Info_Str (" Q");
1125 Write_Info_Char (Queuing_Policy);
1126 end if;
1128 if Task_Dispatching_Policy /= ' ' then
1129 Write_Info_Str (" T");
1130 Write_Info_Char (Task_Dispatching_Policy);
1131 Write_Info_Char (' ');
1132 end if;
1133 end if;
1135 if Partition_Elaboration_Policy /= ' ' then
1136 Write_Info_Str (" E");
1137 Write_Info_Char (Partition_Elaboration_Policy);
1138 end if;
1140 if not Object then
1141 Write_Info_Str (" NO");
1142 end if;
1144 if No_Run_Time_Mode then
1145 Write_Info_Str (" NR");
1146 end if;
1148 if Normalize_Scalars then
1149 Write_Info_Str (" NS");
1150 end if;
1152 if Sec_Stack_Used then
1153 Write_Info_Str (" SS");
1154 end if;
1156 if Unreserve_All_Interrupts then
1157 Write_Info_Str (" UA");
1158 end if;
1160 if Exception_Mechanism = Back_End_Exceptions then
1161 Write_Info_Str (" ZX");
1162 end if;
1164 Write_Info_EOL;
1166 -- Before outputting the restrictions line, update the setting of
1167 -- the No_Elaboration_Code flag. Violations of this restriction
1168 -- cannot be detected until after the backend has been called since
1169 -- it is the backend that sets this flag. We have to check all units
1170 -- for which we have generated code
1172 for Unit in Units.First .. Last_Unit loop
1173 if Units.Table (Unit).Generate_Code
1174 or else Unit = Main_Unit
1175 then
1176 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1177 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1178 end if;
1179 end if;
1180 end loop;
1182 -- Positional case (only if debug flag -gnatd.R is set)
1184 if Debug_Flag_Dot_RR then
1186 -- Output first restrictions line
1188 Write_Info_Initiate ('R');
1189 Write_Info_Char (' ');
1191 -- First the information for the boolean restrictions
1193 for R in All_Boolean_Restrictions loop
1194 if Main_Restrictions.Set (R)
1195 and then not Restriction_Warnings (R)
1196 then
1197 Write_Info_Char ('r');
1198 elsif Main_Restrictions.Violated (R) then
1199 Write_Info_Char ('v');
1200 else
1201 Write_Info_Char ('n');
1202 end if;
1203 end loop;
1205 -- And now the information for the parameter restrictions
1207 for RP in All_Parameter_Restrictions loop
1208 if Main_Restrictions.Set (RP)
1209 and then not Restriction_Warnings (RP)
1210 then
1211 Write_Info_Char ('r');
1212 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1213 else
1214 Write_Info_Char ('n');
1215 end if;
1217 if not Main_Restrictions.Violated (RP)
1218 or else RP not in Checked_Parameter_Restrictions
1219 then
1220 Write_Info_Char ('n');
1221 else
1222 Write_Info_Char ('v');
1223 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1225 if Main_Restrictions.Unknown (RP) then
1226 Write_Info_Char ('+');
1227 end if;
1228 end if;
1229 end loop;
1231 Write_Info_EOL;
1233 -- Named case (if debug flag -gnatd.R is not set)
1235 else
1236 declare
1237 C : Character;
1239 begin
1240 -- Write RN header line with preceding blank line
1242 Write_Info_EOL;
1243 Write_Info_Initiate ('R');
1244 Write_Info_Char ('N');
1245 Write_Info_EOL;
1247 -- First the lines for the boolean restrictions
1249 for R in All_Boolean_Restrictions loop
1250 if Main_Restrictions.Set (R)
1251 and then not Restriction_Warnings (R)
1252 then
1253 C := 'R';
1254 elsif Main_Restrictions.Violated (R) then
1255 C := 'V';
1256 else
1257 goto Continue;
1258 end if;
1260 Write_Info_Initiate ('R');
1261 Write_Info_Char (C);
1262 Write_Info_Char (' ');
1263 Write_Info_Str (All_Boolean_Restrictions'Image (R));
1264 Write_Info_EOL;
1266 <<Continue>>
1267 null;
1268 end loop;
1269 end;
1271 -- And now the lines for the parameter restrictions
1273 for RP in All_Parameter_Restrictions loop
1274 if Main_Restrictions.Set (RP)
1275 and then not Restriction_Warnings (RP)
1276 then
1277 Write_Info_Initiate ('R');
1278 Write_Info_Str ("R ");
1279 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1280 Write_Info_Char ('=');
1281 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1282 Write_Info_EOL;
1283 end if;
1285 if not Main_Restrictions.Violated (RP)
1286 or else RP not in Checked_Parameter_Restrictions
1287 then
1288 null;
1289 else
1290 Write_Info_Initiate ('R');
1291 Write_Info_Str ("V ");
1292 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1293 Write_Info_Char ('=');
1294 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1296 if Main_Restrictions.Unknown (RP) then
1297 Write_Info_Char ('+');
1298 end if;
1300 Write_Info_EOL;
1301 end if;
1302 end loop;
1303 end if;
1305 -- Output R lines for No_Dependence entries
1307 for J in No_Dependences.First .. No_Dependences.Last loop
1308 if In_Extended_Main_Source_Unit (No_Dependences.Table (J).Unit)
1309 and then not No_Dependences.Table (J).Warn
1310 then
1311 Write_Info_Initiate ('R');
1312 Write_Info_Char (' ');
1313 Write_Unit_Name (No_Dependences.Table (J).Unit);
1314 Write_Info_EOL;
1315 end if;
1316 end loop;
1318 -- Output interrupt state lines
1320 for J in Interrupt_States.First .. Interrupt_States.Last loop
1321 Write_Info_Initiate ('I');
1322 Write_Info_Char (' ');
1323 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1324 Write_Info_Char (' ');
1325 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1326 Write_Info_Char (' ');
1327 Write_Info_Nat
1328 (Nat (Get_Logical_Line_Number
1329 (Interrupt_States.Table (J).Pragma_Loc)));
1330 Write_Info_EOL;
1331 end loop;
1333 -- Output priority specific dispatching lines
1335 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1336 Write_Info_Initiate ('S');
1337 Write_Info_Char (' ');
1338 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1339 Write_Info_Char (' ');
1340 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1341 Write_Info_Char (' ');
1342 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1343 Write_Info_Char (' ');
1344 Write_Info_Nat
1345 (Nat (Get_Logical_Line_Number
1346 (Specific_Dispatching.Table (J).Pragma_Loc)));
1347 Write_Info_EOL;
1348 end loop;
1350 -- Loop through file table to output information for all units for which
1351 -- we have generated code, as marked by the Generate_Code flag.
1353 for Unit in Units.First .. Last_Unit loop
1354 if Units.Table (Unit).Generate_Code
1355 or else Unit = Main_Unit
1356 then
1357 Write_Info_EOL; -- blank line
1358 Write_Unit_Information (Unit);
1359 end if;
1360 end loop;
1362 Write_Info_EOL; -- blank line
1364 -- Output external version reference lines
1366 for J in 1 .. Version_Ref.Last loop
1367 Write_Info_Initiate ('E');
1368 Write_Info_Char (' ');
1370 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1371 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1372 end loop;
1374 Write_Info_EOL;
1375 end loop;
1377 -- Prepare to output the source dependency lines
1379 declare
1380 Unum : Unit_Number_Type;
1381 -- Number of unit being output
1383 Sind : Source_File_Index;
1384 -- Index of corresponding source file
1386 Fname : File_Name_Type;
1388 begin
1389 for J in 1 .. Num_Sdep loop
1390 Unum := Sdep_Table (J);
1391 Units.Table (Unum).Dependency_Num := J;
1392 Sind := Units.Table (Unum).Source_Index;
1394 Write_Info_Initiate ('D');
1395 Write_Info_Char (' ');
1397 -- Normal case of a unit entry with a source index
1399 if Sind /= No_Source_File then
1400 Fname := File_Name (Sind);
1402 -- Ensure that on platforms where the file names are not
1403 -- case sensitive, the recorded file name is in lower case.
1405 if not File_Names_Case_Sensitive then
1406 Get_Name_String (Fname);
1407 To_Lower (Name_Buffer (1 .. Name_Len));
1408 Fname := Name_Find;
1409 end if;
1411 Write_Info_Name (Fname);
1412 Write_Info_Tab (25);
1413 Write_Info_Str (String (Time_Stamp (Sind)));
1414 Write_Info_Char (' ');
1415 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1417 -- If subunit, add unit name, omitting the %b at the end
1419 if Present (Cunit (Unum))
1420 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1421 then
1422 Get_Decoded_Name_String (Unit_Name (Unum));
1423 Write_Info_Char (' ');
1424 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1425 end if;
1427 -- If Source_Reference pragma used output information
1429 if Num_SRef_Pragmas (Sind) > 0 then
1430 Write_Info_Char (' ');
1432 if Num_SRef_Pragmas (Sind) = 1 then
1433 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1434 else
1435 Write_Info_Nat (0);
1436 end if;
1438 Write_Info_Char (':');
1439 Write_Info_Name (Reference_Name (Sind));
1440 end if;
1442 -- Case where there is no source index (happens for missing
1443 -- files). In this case we write a dummy time stamp.
1445 else
1446 Write_Info_Name (Unit_File_Name (Unum));
1447 Write_Info_Tab (25);
1448 Write_Info_Str (String (Dummy_Time_Stamp));
1449 Write_Info_Char (' ');
1450 Write_Info_Str (Get_Hex_String (0));
1451 end if;
1453 Write_Info_EOL;
1454 end loop;
1455 end;
1457 -- Output cross-references
1459 if Opt.Xref_Active then
1460 Output_References;
1461 end if;
1463 -- Output SCO information if present
1465 if Generate_SCO then
1466 SCO_Output;
1467 end if;
1469 -- Output SPARK cross-reference information if needed
1471 if Opt.Xref_Active and then SPARK_Mode then
1472 SPARK_Specific.Collect_SPARK_Xrefs (Sdep_Table => Sdep_Table,
1473 Num_Sdep => Num_Sdep);
1474 SPARK_Specific.Output_SPARK_Xrefs;
1475 end if;
1477 -- Output final blank line and we are done. This final blank line is
1478 -- probably junk, but we don't feel like making an incompatible change!
1480 Write_Info_Terminate;
1481 Close_Output_Library_Info;
1482 end Write_ALI;
1484 ---------------------
1485 -- Write_Unit_Name --
1486 ---------------------
1488 procedure Write_Unit_Name (N : Node_Id) is
1489 begin
1490 if Nkind (N) = N_Identifier then
1491 Write_Info_Name (Chars (N));
1493 else
1494 pragma Assert (Nkind (N) = N_Selected_Component);
1495 Write_Unit_Name (Prefix (N));
1496 Write_Info_Char ('.');
1497 Write_Unit_Name (Selector_Name (N));
1498 end if;
1499 end Write_Unit_Name;
1501 end Lib.Writ;