i386: Allow all register_operand SUBREGs in x86_ternlog_idx.
[official-gcc.git] / gcc / ada / lib-writ.adb
blob3d43907a08b33f1ea290adf555f2aa8754560e75
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-2024, 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 Einfo.Entities; use Einfo.Entities;
32 with Einfo.Utils; use Einfo.Utils;
33 with Elists; use Elists;
34 with Errout; use Errout;
35 with Fname; use Fname;
36 with Fname.UF; use Fname.UF;
37 with Lib.Util; use Lib.Util;
38 with Lib.Xref; use Lib.Xref;
39 with Nlists; use Nlists;
40 with Gnatvsn; use Gnatvsn;
41 with GNAT_CUDA; use GNAT_CUDA;
42 with Opt; use Opt;
43 with Osint; use Osint;
44 with Osint.C; use Osint.C;
45 with Output; use Output;
46 with Par;
47 with Par_SCO; use Par_SCO;
48 with Restrict; use Restrict;
49 with Rident; use Rident;
50 with Stand; use Stand;
51 with Scn; use Scn;
52 with Sem_Eval; use Sem_Eval;
53 with Sem_Util; use Sem_Util;
54 with Sinfo; use Sinfo;
55 with Sinfo.Nodes; use Sinfo.Nodes;
56 with Sinfo.Utils; use Sinfo.Utils;
57 with Sinput; use Sinput;
58 with Snames; use Snames;
59 with Stringt; use Stringt;
60 with Tbuild; use Tbuild;
61 with Uname; use Uname;
63 with System.Case_Util; use System.Case_Util;
64 with System.WCh_Con; use System.WCh_Con;
66 package body Lib.Writ is
68 -----------------------
69 -- Local subprograms --
70 -----------------------
72 function Present (N_Id : Name_Id) return Boolean;
73 pragma Inline (Present);
74 -- Determine whether a name with id N_Id exists
76 procedure Write_Invocation_Construct (IC_Id : Invocation_Construct_Id);
77 pragma Inline (Write_Invocation_Construct);
78 -- Write invocation construct IC_Id to the ALI file
80 procedure Write_Invocation_Graph;
81 pragma Inline (Write_Invocation_Graph);
82 -- Write out the invocation graph
84 procedure Write_Invocation_Graph_Attributes;
85 pragma Inline (Write_Invocation_Graph_Attributes);
86 -- Write out the attributes of the invocation graph
88 procedure Write_Invocation_Relation (IR_Id : Invocation_Relation_Id);
89 pragma Inline (Write_Invocation_Relation);
90 -- Write invocation relation IR_Id to the ALI file
92 procedure Write_Invocation_Signature (IS_Id : Invocation_Signature_Id);
93 pragma Inline (Write_Invocation_Signature);
94 -- Write invocation signature IS_Id to the ALI file
96 procedure Write_Unit_Name (N : Node_Id);
97 -- Used to write out the unit name for R (pragma Restriction) lines
98 -- for uses of Restriction (No_Dependence => unit-name).
100 ----------------------------------
101 -- Add_Preprocessing_Dependency --
102 ----------------------------------
104 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
105 begin
106 Units.Increment_Last;
107 Units.Table (Units.Last) :=
108 (Unit_File_Name => File_Name (S),
109 Unit_Name => No_Unit_Name,
110 Expected_Unit => No_Unit_Name,
111 Source_Index => S,
112 Cunit => Empty,
113 Cunit_Entity => Empty,
114 Dependency_Num => 0,
115 Dynamic_Elab => False,
116 Fatal_Error => None,
117 Generate_Code => False,
118 Has_RACW => False,
119 Filler => False,
120 Ident_String => Empty,
121 Is_Predefined_Renaming => False,
122 Is_Internal_Unit => False,
123 Is_Predefined_Unit => False,
124 Filler2 => False,
125 Loading => False,
126 Main_Priority => -1,
127 Main_CPU => -1,
128 Munit_Index => 0,
129 No_Elab_Code_All => False,
130 Primary_Stack_Count => 0,
131 Sec_Stack_Count => 0,
132 Serial_Number => 0,
133 Version => 0,
134 Error_Location => No_Location,
135 OA_Setting => 'O');
136 end Add_Preprocessing_Dependency;
138 ------------------------------
139 -- Ensure_System_Dependency --
140 ------------------------------
142 procedure Ensure_System_Dependency is
143 System_Uname : constant Unit_Name_Type :=
144 Name_To_Unit_Name (Name_System);
145 -- Unit name for system spec if needed for dummy entry
147 System_Fname : File_Name_Type;
148 -- File name for system spec if needed for dummy entry
150 begin
151 -- Nothing to do if we already compiled System
153 if Is_Loaded (System_Uname) then
154 return;
155 end if;
157 -- If no entry for system.ads in the units table, then add a entry
158 -- to the units table for system.ads, which will be referenced when
159 -- the ali file is generated. We need this because every unit depends
160 -- on system as a result of Targparm scanning the system.ads file to
161 -- determine the target dependent parameters for the compilation.
163 System_Fname := File_Name (System_Source_File_Index);
165 Units.Increment_Last;
166 Units.Table (Units.Last) :=
167 (Unit_File_Name => System_Fname,
168 Unit_Name => System_Uname,
169 Expected_Unit => System_Uname,
170 Source_Index => System_Source_File_Index,
171 Cunit => Empty,
172 Cunit_Entity => Empty,
173 Dependency_Num => 0,
174 Dynamic_Elab => False,
175 Fatal_Error => None,
176 Generate_Code => False,
177 Has_RACW => False,
178 Filler => False,
179 Ident_String => Empty,
180 Is_Predefined_Renaming => False,
181 Is_Internal_Unit => True,
182 Is_Predefined_Unit => True,
183 Filler2 => False,
184 Loading => False,
185 Main_Priority => -1,
186 Main_CPU => -1,
187 Munit_Index => 0,
188 No_Elab_Code_All => False,
189 Primary_Stack_Count => 0,
190 Sec_Stack_Count => 0,
191 Serial_Number => 0,
192 Version => 0,
193 Error_Location => No_Location,
194 OA_Setting => 'O');
195 Init_Unit_Name (Units.Last, System_Uname);
197 -- Parse system.ads so that the checksum is set right. Style checks are
198 -- not applied. The Ekind is set to ensure that this reference is always
199 -- present in the ali file.
201 declare
202 Save_Mindex : constant Nat := Multiple_Unit_Index;
203 Save_Style : constant Boolean := Style_Check;
204 begin
205 Multiple_Unit_Index := 0;
206 Style_Check := False;
207 Initialize_Scanner (Units.Last, System_Source_File_Index);
208 Discard_List (Par (Configuration_Pragmas => False));
209 Mutate_Ekind (Cunit_Entity (Units.Last), E_Package);
210 Set_Scope (Cunit_Entity (Units.Last), Standard_Standard);
211 Style_Check := Save_Style;
212 Multiple_Unit_Index := Save_Mindex;
213 end;
214 end Ensure_System_Dependency;
216 -------------
217 -- Present --
218 -------------
220 function Present (N_Id : Name_Id) return Boolean is
221 begin
222 return N_Id /= No_Name;
223 end Present;
225 ---------------
226 -- Write_ALI --
227 ---------------
229 procedure Write_ALI (Object : Boolean) is
231 ----------------
232 -- Local Data --
233 ----------------
235 Last_Unit : constant Unit_Number_Type := Units.Last;
236 -- Record unit number of last unit. We capture this in case we
237 -- have to add a dummy entry to the unit table for package System.
239 With_Flags : array (Units.First .. Last_Unit) of Boolean;
240 -- Array of flags to show which units are with'ed
242 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
243 -- Array of flags to show which units have pragma Elaborate set
245 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
246 -- Array of flags to show which units have pragma Elaborate All set
248 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
249 -- Array of flags to show which units have Elaborate_Desirable set
251 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
252 -- Array of flags to show which units have Elaborate_All_Desirable set
254 type Yes_No is (Unknown, Yes, No);
255 Has_Implicit_With : array (Units.First .. Last_Unit) of Yes_No;
256 -- Indicates if an implicit with has been given for the unit. Yes if
257 -- certainly present, No if certainly absent, Unknown if not known.
259 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
260 -- Sorted table of source dependencies. One extra entry in case we
261 -- have to add a dummy entry for System.
263 Num_Sdep : Nat := 0;
264 -- Number of active entries in Sdep_Table
266 -----------------------
267 -- Local Subprograms --
268 -----------------------
270 procedure Collect_Withs (Cunit : Node_Id);
271 -- Collect with lines for entries in the context clause of the given
272 -- compilation unit, Cunit.
274 procedure Output_CUDA_Symbols (Unit_Num : Unit_Number_Type);
275 -- Output CUDA symbols, so that the rest of the toolchain may know what
276 -- symbols need registering with the CUDA runtime.
278 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
279 -- Write out the library information for one unit for which code is
280 -- generated (includes unit line and with lines).
282 procedure Write_With_Lines;
283 -- Write out with lines collected by calls to Collect_Withs
285 -------------------
286 -- Collect_Withs --
287 -------------------
289 procedure Collect_Withs (Cunit : Node_Id) is
290 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean;
291 pragma Inline (Is_Implicit_With_Clause);
292 -- Determine whether a with clause denoted by Clause is implicit
294 -----------------------------
295 -- Is_Implicit_With_Clause --
296 -----------------------------
298 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean is
299 begin
300 -- With clauses created for ancestor units are marked as internal,
301 -- however, they emulate the semantics in RM 10.1.2 (6/2), where
303 -- with A.B;
305 -- is almost equivalent to
307 -- with A;
308 -- with A.B;
310 -- For ALI encoding purposes, they are considered to be explicit.
311 -- Note that the clauses cannot be marked as explicit because they
312 -- will be subjected to various checks related to with clauses and
313 -- possibly cause false positives.
315 if Parent_With (Clause) then
316 return False;
318 else
319 return Implicit_With (Clause);
320 end if;
321 end Is_Implicit_With_Clause;
323 -- Local variables
325 Item : Node_Id;
326 Unum : Unit_Number_Type;
328 -- Start of processing for Collect_Withs
330 begin
331 Item := First (Context_Items (Cunit));
332 while Present (Item) loop
334 -- Process with clause
336 -- Ada 2005 (AI-50217): limited with_clauses do not create
337 -- dependencies, but must be recorded as components of the
338 -- partition, in case there is no regular with_clause for
339 -- the unit anywhere else.
341 if Nkind (Item) = N_With_Clause then
342 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
343 With_Flags (Unum) := True;
345 if not Limited_Present (Item) then
346 if Elaborate_Present (Item) then
347 Elab_Flags (Unum) := True;
348 end if;
350 if Elaborate_All_Present (Item) then
351 Elab_All_Flags (Unum) := True;
352 end if;
354 if Elaborate_All_Desirable (Item) then
355 Elab_All_Des_Flags (Unum) := True;
356 end if;
358 if Elaborate_Desirable (Item) then
359 Elab_Des_Flags (Unum) := True;
360 end if;
362 else
363 Set_From_Limited_With (Cunit_Entity (Unum));
364 end if;
366 if Is_Implicit_With_Clause (Item) then
368 -- A previous explicit with clause withs the unit. Retain
369 -- this classification, as it reflects the source relations
370 -- between units.
372 if Has_Implicit_With (Unum) = No then
373 null;
375 -- Otherwise this is either the first time any clause withs
376 -- the unit, or the unit is already implicitly withed.
378 else
379 Has_Implicit_With (Unum) := Yes;
380 end if;
382 -- Otherwise the current with clause is explicit. Such clauses
383 -- take precedence over existing implicit clauses because they
384 -- reflect the source relations between unit.
386 else
387 Has_Implicit_With (Unum) := No;
388 end if;
389 end if;
391 Next (Item);
392 end loop;
393 end Collect_Withs;
395 -------------------------
396 -- Output_CUDA_Symbols --
397 -------------------------
399 procedure Output_CUDA_Symbols (Unit_Num : Unit_Number_Type) is
400 Unit_Id : constant Node_Id := Unit (Cunit (Unit_Num));
401 Spec_Id : Node_Id;
402 Kernels : Elist_Id;
403 Kernel_Elm : Elmt_Id;
404 Kernel : Entity_Id;
405 begin
406 if not Enable_CUDA_Expansion
407 or else Nkind (Unit_Id) = N_Null_Statement
408 then
409 return;
410 end if;
411 Spec_Id := (if Nkind (Unit_Id) = N_Package_Body
412 then Corresponding_Spec (Unit_Id)
413 else Defining_Unit_Name (Specification (Unit_Id)));
414 Kernels := Get_CUDA_Kernels (Spec_Id);
415 if No (Kernels) then
416 return;
417 end if;
419 Kernel_Elm := First_Elmt (Kernels);
420 while Present (Kernel_Elm) loop
421 Kernel := Node (Kernel_Elm);
423 Write_Info_Initiate ('K');
424 Write_Info_Char (' ');
425 Write_Info_Name (Chars (Kernel));
426 Write_Info_Terminate;
427 Next_Elmt (Kernel_Elm);
428 end loop;
430 end Output_CUDA_Symbols;
432 ----------------------------
433 -- Write_Unit_Information --
434 ----------------------------
436 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
437 Unode : constant Node_Id := Cunit (Unit_Num);
438 Ukind : constant Node_Kind := Nkind (Unit (Unode));
439 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
440 Pnode : Node_Id;
442 begin
443 Write_Info_Initiate ('U');
444 Write_Info_Char (' ');
445 Write_Info_Name (Unit_Name (Unit_Num));
446 Write_Info_Tab (25);
447 Write_Info_Name (Unit_File_Name (Unit_Num));
449 Write_Info_Tab (49);
450 Write_Info_Str (Version_Get (Unit_Num));
452 -- Add BD parameter if Elaborate_Body pragma desirable
454 if Ekind (Uent) = E_Package
455 and then Elaborate_Body_Desirable (Uent)
456 then
457 Write_Info_Str (" BD");
458 end if;
460 -- Add BN parameter if body needed for SAL
462 if (Is_Subprogram (Uent)
463 or else Ekind (Uent) = E_Package
464 or else Is_Generic_Unit (Uent))
465 and then Body_Needed_For_SAL (Uent)
466 then
467 Write_Info_Str (" BN");
468 end if;
470 if Dynamic_Elab (Unit_Num) then
471 Write_Info_Str (" DE");
472 end if;
474 -- Set the Elaborate_Body indication if either an explicit pragma
475 -- was present, or if this is an instantiation.
477 if Has_Pragma_Elaborate_Body (Uent)
478 or else (Ukind = N_Package_Declaration
479 and then Is_Generic_Instance (Uent)
480 and then Present (Corresponding_Body (Unit (Unode))))
481 then
482 Write_Info_Str (" EB");
483 end if;
485 -- Now see if we should tell the binder that an elaboration entity
486 -- is present, which must be set to true during elaboration.
487 -- We generate the indication if the following condition is met:
489 -- If this is a spec ...
491 if (Is_Subprogram (Uent)
492 or else Ekind (Uent) = E_Package
493 or else Is_Generic_Unit (Uent))
495 -- and an elaboration entity was declared ...
497 and then Present (Elaboration_Entity (Uent))
499 -- and either the elaboration flag is required ...
501 and then (Elaboration_Entity_Required (Uent)
503 -- or this unit has elaboration code ...
505 or else not Has_No_Elaboration_Code (Unode)
507 -- or this unit has a separate body and this
508 -- body has elaboration code.
510 or else
511 (Ekind (Uent) = E_Package
512 and then Present (Body_Entity (Uent))
513 and then
514 not Has_No_Elaboration_Code
515 (Parent (Declaration_Node (Body_Entity (Uent))))))
516 then
517 Write_Info_Str (" EE");
518 end if;
520 if Has_No_Elaboration_Code (Unode) then
521 Write_Info_Str (" NE");
522 end if;
524 Write_Info_Str (" O");
525 Write_Info_Char (OA_Setting (Unit_Num));
527 -- For a package instance with a body that is a library unit, the two
528 -- compilation units share Cunit_Entity so we cannot rely on Uent.
530 if Ukind in N_Package_Declaration | N_Package_Body then
531 declare
532 E : constant Entity_Id := Defining_Entity (Unit (Unode));
534 begin
535 if Ekind (E) in E_Package | E_Package_Body
536 and then Present (Finalizer (E))
537 then
538 Write_Info_Str (" PF");
539 end if;
540 end;
541 end if;
543 if Is_Preelaborated (Uent) then
544 Write_Info_Str (" PR");
545 end if;
547 if Is_Pure (Uent) then
548 Write_Info_Str (" PU");
549 end if;
551 if Has_RACW (Unit_Num) then
552 Write_Info_Str (" RA");
553 end if;
555 if Is_Remote_Call_Interface (Uent) then
556 Write_Info_Str (" RC");
557 end if;
559 if Is_Remote_Types (Uent) then
560 Write_Info_Str (" RT");
561 end if;
563 if Serious_Errors_Detected /= 0 then
564 Write_Info_Str (" SE");
565 end if;
567 if Is_Shared_Passive (Uent) then
568 Write_Info_Str (" SP");
569 end if;
571 if Ukind = N_Subprogram_Declaration
572 or else Ukind = N_Subprogram_Body
573 then
574 Write_Info_Str (" SU");
576 elsif Ukind = N_Package_Declaration
577 or else
578 Ukind = N_Package_Body
579 then
580 -- If this is a wrapper package for a subprogram instantiation,
581 -- the user view is the subprogram. Note that in this case the
582 -- ali file contains both the spec and body of the instance.
584 if Is_Wrapper_Package (Uent) then
585 Write_Info_Str (" SU");
586 else
587 Write_Info_Str (" PK");
588 end if;
590 elsif Ukind = N_Generic_Package_Declaration then
591 Write_Info_Str (" PK");
593 end if;
595 if Ukind in N_Generic_Declaration
596 or else
597 (Present (Library_Unit (Unode))
598 and then
599 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
600 then
601 Write_Info_Str (" GE");
602 end if;
604 if not Is_Internal_Unit (Unit_Num) then
605 case Identifier_Casing (Source_Index (Unit_Num)) is
606 when All_Lower_Case => Write_Info_Str (" IL");
607 when All_Upper_Case => Write_Info_Str (" IU");
608 when others => null;
609 end case;
611 case Keyword_Casing (Source_Index (Unit_Num)) is
612 when Mixed_Case => Write_Info_Str (" KM");
613 when All_Upper_Case => Write_Info_Str (" KU");
614 when others => null;
615 end case;
616 end if;
618 if Initialize_Scalars or else Invalid_Value_Used then
619 Write_Info_Str (" IS");
620 end if;
622 Write_Info_EOL;
624 -- Generate with lines, first those that are directly with'ed
626 for J in With_Flags'Range loop
627 With_Flags (J) := False;
628 Elab_Flags (J) := False;
629 Elab_All_Flags (J) := False;
630 Elab_Des_Flags (J) := False;
631 Elab_All_Des_Flags (J) := False;
632 Has_Implicit_With (J) := Unknown;
633 end loop;
635 Collect_Withs (Unode);
637 -- For a body, we must also check for any subunits which belong to
638 -- it and which have context clauses of their own, since these
639 -- with'ed units are part of its own elaboration dependencies.
641 if Nkind (Unit (Unode)) in N_Unit_Body then
642 for S in Units.First .. Last_Unit loop
644 -- We are only interested in subunits. For preproc. data and
645 -- def. files, Cunit is Empty, so we need to test that first.
647 if Cunit (S) /= Empty
648 and then Nkind (Unit (Cunit (S))) = N_Subunit
649 then
650 Pnode := Library_Unit (Cunit (S));
652 -- In gnatc mode, the errors in the subunits will not have
653 -- been recorded, but the analysis of the subunit may have
654 -- failed. There is no information to add to ALI file in
655 -- this case.
657 if No (Pnode) then
658 exit;
659 end if;
661 -- Find ultimate parent of the subunit
663 while Nkind (Unit (Pnode)) = N_Subunit loop
664 Pnode := Library_Unit (Pnode);
665 end loop;
667 -- See if it belongs to current unit, and if so, include
668 -- its with_clauses.
670 if Pnode = Unode then
671 Collect_Withs (Cunit (S));
672 end if;
673 end if;
674 end loop;
675 end if;
677 Write_With_Lines;
679 -- Generate task stack lines
681 if Primary_Stack_Count (Unit_Num) > 0
682 or else Sec_Stack_Count (Unit_Num) > 0
683 then
684 Write_Info_Initiate ('T');
685 Write_Info_Char (' ');
686 Write_Info_Int (Primary_Stack_Count (Unit_Num));
687 Write_Info_Char (' ');
688 Write_Info_Int (Sec_Stack_Count (Unit_Num));
689 Write_Info_EOL;
690 end if;
692 -- Generate the linker option lines
694 for J in 1 .. Linker_Option_Lines.Last loop
696 -- Pragma Linker_Options is not allowed in predefined generic
697 -- units. This is because they won't be read, due to the fact that
698 -- with lines for generic units lack the file name and lib name
699 -- parameters (see Lib_Writ spec for an explanation).
701 if Is_Generic_Unit (Cunit_Entity (Main_Unit))
702 and then Is_Predefined_Unit (Current_Sem_Unit)
703 and then Linker_Option_Lines.Table (J).Unit = Unit_Num
704 then
705 Set_Standard_Error;
706 Write_Line
707 ("linker options not allowed in predefined generic unit");
708 raise Unrecoverable_Error;
709 end if;
711 -- Output one linker option line
713 declare
714 S : Linker_Option_Entry renames Linker_Option_Lines.Table (J);
715 begin
716 if S.Unit = Unit_Num then
717 Write_Info_Initiate ('L');
718 Write_Info_Char (' ');
719 Write_Info_Slit (S.Option);
720 Write_Info_EOL;
721 end if;
722 end;
723 end loop;
725 -- Output notes
727 for J in 1 .. Notes.Last loop
728 declare
729 N : constant Node_Id := Notes.Table (J);
730 L : constant Source_Ptr := Sloc (N);
731 U : constant Unit_Number_Type :=
732 Unit (Get_Source_File_Index (L));
733 C : Character;
735 Note_Unit : Unit_Number_Type;
736 -- The unit in whose U section this note must be emitted:
737 -- notes for subunits are emitted along with the main unit;
738 -- all other notes are emitted as part of the enclosing
739 -- compilation unit.
741 begin
742 if U /= No_Unit and then Nkind (Unit (Cunit (U))) = N_Subunit
743 then
744 Note_Unit := Main_Unit;
745 else
746 Note_Unit := U;
747 end if;
749 -- No action needed for pragmas removed by the expander (for
750 -- example, pragmas of ignored ghost entities).
752 if Nkind (N) = N_Null_Statement then
753 pragma Assert (Nkind (Original_Node (N)) = N_Pragma);
754 null;
756 elsif Note_Unit = Unit_Num then
757 Write_Info_Initiate ('N');
758 Write_Info_Char (' ');
760 case Pragma_Name (N) is
761 when Name_Annotate | Name_GNAT_Annotate =>
762 C := 'A';
763 when Name_Comment =>
764 C := 'C';
765 when Name_Ident =>
766 C := 'I';
767 when Name_Title =>
768 C := 'T';
769 when Name_Subtitle =>
770 C := 'S';
771 when others =>
772 raise Program_Error;
773 end case;
775 Write_Info_Char (C);
776 Write_Info_Int (Int (Get_Logical_Line_Number (L)));
777 Write_Info_Char (':');
778 Write_Info_Int (Int (Get_Column_Number (L)));
780 -- Indicate source file of annotation if different from
781 -- compilation unit source file (case of annotation coming
782 -- from a separate).
784 if Get_Source_File_Index (L) /= Source_Index (Unit_Num) then
785 Write_Info_Char (':');
786 Write_Info_Name (File_Name (Get_Source_File_Index (L)));
787 end if;
789 declare
790 A : Node_Id;
792 begin
793 A := First (Pragma_Argument_Associations (N));
794 while Present (A) loop
795 Write_Info_Char (' ');
797 if Chars (A) /= No_Name then
798 Write_Info_Name (Chars (A));
799 Write_Info_Char (':');
800 end if;
802 declare
803 Expr : constant Node_Id := Expression (A);
805 begin
806 if Nkind (Expr) = N_Identifier then
807 Write_Info_Name (Chars (Expr));
809 elsif Nkind (Expr) = N_Integer_Literal
810 and then Is_OK_Static_Expression (Expr)
811 then
812 Write_Info_Uint (Intval (Expr));
814 elsif Nkind (Expr) = N_String_Literal
815 and then Is_OK_Static_Expression (Expr)
816 then
817 Write_Info_Slit (Strval (Expr));
819 else
820 Write_Info_Str ("<expr>");
821 end if;
822 end;
824 Next (A);
825 end loop;
826 end;
828 Write_Info_EOL;
829 end if;
830 end;
831 end loop;
832 end Write_Unit_Information;
834 ----------------------
835 -- Write_With_Lines --
836 ----------------------
838 procedure Write_With_Lines is
839 Pname : constant Unit_Name_Type :=
840 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
841 Body_Fname : File_Name_Type;
842 Body_Index : Nat;
843 Cunit : Node_Id;
844 Fname : File_Name_Type;
845 Num_Withs : Int := 0;
846 Unum : Unit_Number_Type;
847 Uname : Unit_Name_Type;
848 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
850 procedure Write_With_File_Names
851 (Nam : in out File_Name_Type;
852 Idx : Nat);
853 -- Write source file name Nam and ALI file name for unit index Idx.
854 -- Possibly change Nam to lowercase (generating a new file name).
856 ---------------------------
857 -- Write_With_File_Names --
858 ---------------------------
860 procedure Write_With_File_Names
861 (Nam : in out File_Name_Type;
862 Idx : Nat)
864 begin
865 if not File_Names_Case_Sensitive then
866 Get_Name_String (Nam);
867 To_Lower (Name_Buffer (1 .. Name_Len));
868 Nam := Name_Find;
869 end if;
871 Write_Info_Name (Nam);
872 Write_Info_Tab (49);
873 Write_Info_Name (Lib_File_Name (Nam, Idx));
874 end Write_With_File_Names;
876 -- Start of processing for Write_With_Lines
878 begin
879 -- Loop to build the with table. A with on the main unit itself
880 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
881 -- the main unit is a subprogram with no spec, and a subunit of
882 -- it unnecessarily withs the parent.
884 for J in Units.First + 1 .. Last_Unit loop
886 -- Add element to with table if it is with'ed or if it is the
887 -- parent spec of the main unit (case of main unit is a child
888 -- unit). The latter with is not needed for semantic purposes,
889 -- but is required by the binder for elaboration purposes. For
890 -- preprocessing data and definition files, there is no Unit_Name,
891 -- check for that first.
893 if Present (Unit_Name (J))
894 and then (With_Flags (J) or else Unit_Name (J) = Pname)
895 then
896 Num_Withs := Num_Withs + 1;
897 With_Table (Num_Withs) := J;
898 end if;
899 end loop;
901 -- Sort and output the table
903 Sort (With_Table (1 .. Num_Withs));
905 for J in 1 .. Num_Withs loop
906 Unum := With_Table (J);
908 -- Do not generate a with line for an ignored Ghost unit because
909 -- the unit does not have an ALI file.
911 if Is_Ignored_Ghost_Entity (Cunit_Entity (Unum)) then
912 goto Next_With_Line;
913 end if;
915 Cunit := Units.Table (Unum).Cunit;
916 Uname := Units.Table (Unum).Unit_Name;
917 Fname := Units.Table (Unum).Unit_File_Name;
919 -- Limited with clauses must be processed first because they are
920 -- the most specific among the three kinds.
922 if Ekind (Cunit_Entity (Unum)) = E_Package
923 and then From_Limited_With (Cunit_Entity (Unum))
924 then
925 Write_Info_Initiate ('Y');
927 elsif Has_Implicit_With (Unum) = Yes then
928 Write_Info_Initiate ('Z');
930 else
931 Write_Info_Initiate ('W');
932 end if;
934 Write_Info_Char (' ');
935 Write_Info_Name (Uname);
937 -- Now we need to figure out the names of the files that contain
938 -- the with'ed unit. These will usually be the files for the body,
939 -- except in the case of a package that has no body. Note that we
940 -- have a specific exemption here for predefined library generics
941 -- (see comments for Generic_May_Lack_ALI). We do not generate
942 -- dependency upon the ALI file for such units. Older compilers
943 -- used to not support generating code (and ALI) for generics, and
944 -- we want to avoid having different processing (namely, different
945 -- lists of files to be compiled) for different stages of the
946 -- bootstrap.
948 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
949 or else
950 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
951 and then Generic_May_Lack_ALI (Unum))
953 -- In SPARK mode, always generate the dependencies on ALI
954 -- files, which are required to compute frame conditions
955 -- of subprograms.
957 or else GNATprove_Mode
958 then
959 Write_Info_Tab (25);
961 if Is_Spec_Name (Uname) then
962 Body_Fname :=
963 Get_File_Name
964 (Uname => Get_Body_Name (Uname),
965 Subunit => False,
966 May_Fail => True);
968 Body_Index := Get_Unit_Index (Get_Body_Name (Uname));
970 if Body_Fname = No_File then
971 Body_Fname := Get_File_Name (Uname, Subunit => False);
972 Body_Index := Get_Unit_Index (Uname);
973 end if;
974 else
975 Body_Fname := Get_File_Name (Uname, Subunit => False);
976 Body_Index := Get_Unit_Index (Uname);
977 end if;
979 -- A package is considered to have a body if it requires
980 -- a body or if a body is present in Ada 83 mode.
982 if Body_Required (Cunit)
983 or else (Ada_Version = Ada_83
984 and then Full_Source_Name (Body_Fname) /= No_File)
985 then
986 Write_With_File_Names (Body_Fname, Body_Index);
987 else
988 Write_With_File_Names (Fname, Munit_Index (Unum));
989 end if;
991 if Ekind (Cunit_Entity (Unum)) = E_Package
992 and then From_Limited_With (Cunit_Entity (Unum))
993 then
994 null;
995 else
996 if Elab_Flags (Unum) then
997 Write_Info_Str (" E");
998 end if;
1000 if Elab_All_Flags (Unum) then
1001 Write_Info_Str (" EA");
1002 end if;
1004 if Elab_Des_Flags (Unum) then
1005 Write_Info_Str (" ED");
1006 end if;
1008 if Elab_All_Des_Flags (Unum) then
1009 Write_Info_Str (" AD");
1010 end if;
1011 end if;
1012 end if;
1014 Write_Info_EOL;
1016 <<Next_With_Line>>
1017 null;
1018 end loop;
1020 -- Finally generate the special lines for cases of Restriction_Set
1021 -- with No_Dependence and no restriction present.
1023 declare
1024 Unam : Unit_Name_Type;
1026 begin
1027 for J in Restriction_Set_Dependences.First ..
1028 Restriction_Set_Dependences.Last
1029 loop
1030 Unam := Restriction_Set_Dependences.Table (J);
1032 -- Don't need an entry if already in the unit table
1034 for U in 0 .. Last_Unit loop
1035 if Unit_Name (U) = Unam then
1036 goto Next_Restriction_Set;
1037 end if;
1038 end loop;
1040 -- Otherwise generate the entry
1042 Write_Info_Initiate ('W');
1043 Write_Info_Char (' ');
1044 Write_Info_Name (Unam);
1045 Write_Info_EOL;
1047 <<Next_Restriction_Set>>
1048 null;
1049 end loop;
1050 end;
1051 end Write_With_Lines;
1053 -- Start of processing for Write_ALI
1055 begin
1056 -- We never write an ALI file if the original operating mode was
1057 -- syntax-only (-gnats switch used in compiler invocation line).
1059 if Original_Operating_Mode = Check_Syntax then
1060 return;
1061 end if;
1063 -- Generation of ALI files may be disabled, e.g. for formal verification
1064 -- back-end.
1066 if Disable_ALI_File then
1067 return;
1068 end if;
1070 -- Build sorted source dependency table
1072 for Unum in Units.First .. Last_Unit loop
1073 if Cunit_Entity (Unum) = Empty
1074 or else not From_Limited_With (Cunit_Entity (Unum))
1075 then
1076 -- Units that are not analyzed need not appear in the dependency
1077 -- list. These units are either units appearing in limited_with
1078 -- clauses of other units, or units loaded for inlining that end
1079 -- up not inlined by a later decision of the inlining code, to
1080 -- prevent circularities. We want to exclude these files from the
1081 -- list of dependencies, so that the dependency number of other
1082 -- is correctly set, as that number is used by cross-reference
1083 -- tools to relate entity information to the unit in which they
1084 -- are declared.
1086 if Present (Cunit_Entity (Unum))
1087 and then Ekind (Cunit_Entity (Unum)) = E_Void
1088 and then Nkind (Unit (Cunit (Unum))) /= N_Subunit
1089 and then Serious_Errors_Detected = 0
1090 then
1091 null;
1093 else
1094 Num_Sdep := Num_Sdep + 1;
1095 Sdep_Table (Num_Sdep) := Unum;
1096 end if;
1097 end if;
1098 end loop;
1100 -- Sort the table so that the D lines are in order
1102 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
1104 -- Acquire compilation arguments and prepare to write out a new ali
1105 -- file.
1107 Create_Output_Library_Info;
1109 -- Output version line
1111 Write_Info_Initiate ('V');
1112 Write_Info_Str (" """);
1113 Write_Info_Str (Verbose_Library_Version);
1114 Write_Info_Char ('"');
1116 Write_Info_EOL;
1118 -- Output main program line if this is acceptable main program
1120 Output_Main_Program_Line : declare
1121 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
1122 S : Node_Id;
1124 procedure M_Parameters;
1125 -- Output parameters for main program line
1127 ------------------
1128 -- M_Parameters --
1129 ------------------
1131 procedure M_Parameters is
1132 begin
1133 if Main_Priority (Main_Unit) /= Default_Main_Priority then
1134 Write_Info_Char (' ');
1135 Write_Info_Nat (Main_Priority (Main_Unit));
1136 end if;
1138 if Opt.Time_Slice_Set then
1139 Write_Info_Str (" T=");
1140 Write_Info_Nat (Opt.Time_Slice_Value);
1141 end if;
1143 if Main_CPU (Main_Unit) /= Default_Main_CPU then
1144 Write_Info_Str (" C=");
1145 Write_Info_Nat (Main_CPU (Main_Unit));
1146 end if;
1148 Write_Info_Str (" W=");
1149 Write_Info_Char
1150 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
1152 Write_Info_EOL;
1153 end M_Parameters;
1155 -- Start of processing for Output_Main_Program_Line
1157 begin
1158 if Nkind (U) = N_Subprogram_Body
1159 or else
1160 (Nkind (U) = N_Package_Body
1161 and then
1162 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
1163 then
1164 -- If the unit is a subprogram instance, the entity for the
1165 -- subprogram is the alias of the visible entity, which is the
1166 -- related instance of the wrapper package. We retrieve the
1167 -- subprogram declaration of the desired entity.
1169 if Nkind (U) = N_Package_Body then
1170 U := Parent (Parent (
1171 Alias (Related_Instance (Defining_Unit_Name
1172 (Specification (Unit (Library_Unit (Parent (U)))))))));
1173 end if;
1175 S := Specification (U);
1177 -- A generic subprogram is never a main program
1179 if Nkind (U) = N_Subprogram_Body
1180 and then Present (Corresponding_Spec (U))
1181 and then Is_Generic_Subprogram (Corresponding_Spec (U))
1182 then
1183 null;
1185 elsif No (Parameter_Specifications (S)) then
1186 if Nkind (S) = N_Procedure_Specification then
1187 Write_Info_Initiate ('M');
1188 Write_Info_Str (" P");
1189 M_Parameters;
1191 else
1192 declare
1193 Nam : Node_Id := Defining_Unit_Name (S);
1195 begin
1196 -- If it is a child unit, get its simple name
1198 if Nkind (Nam) = N_Defining_Program_Unit_Name then
1199 Nam := Defining_Identifier (Nam);
1200 end if;
1202 if Is_Integer_Type (Etype (Nam)) then
1203 Write_Info_Initiate ('M');
1204 Write_Info_Str (" F");
1205 M_Parameters;
1206 end if;
1207 end;
1208 end if;
1209 end if;
1210 end if;
1211 end Output_Main_Program_Line;
1213 -- Write command argument ('A') lines
1215 for A in 1 .. Compilation_Switches.Last loop
1216 Write_Info_Initiate ('A');
1217 Write_Info_Char (' ');
1218 Write_Info_Str (Compilation_Switches.Table (A).all);
1219 Write_Info_Terminate;
1220 end loop;
1222 -- Output CUDA Kernel lines
1224 for Unit in Units.First .. Last_Unit loop
1225 if Present (Cunit (Unit)) then
1226 Output_CUDA_Symbols (Unit);
1227 end if;
1228 end loop;
1230 -- Output parameters ('P') line
1232 Write_Info_Initiate ('P');
1234 if Compilation_Errors then
1235 Write_Info_Str (" CE");
1236 end if;
1238 if Opt.Detect_Blocking then
1239 Write_Info_Str (" DB");
1240 end if;
1242 if Tasking_Used and then not Is_Predefined_Unit (Main_Unit) then
1243 if Locking_Policy /= ' ' then
1244 Write_Info_Str (" L");
1245 Write_Info_Char (Locking_Policy);
1246 end if;
1248 if Queuing_Policy /= ' ' then
1249 Write_Info_Str (" Q");
1250 Write_Info_Char (Queuing_Policy);
1251 end if;
1253 if Task_Dispatching_Policy /= ' ' then
1254 Write_Info_Str (" T");
1255 Write_Info_Char (Task_Dispatching_Policy);
1256 Write_Info_Char (' ');
1257 end if;
1258 end if;
1260 if GNATprove_Mode then
1261 Write_Info_Str (" GP");
1262 end if;
1264 if Partition_Elaboration_Policy /= ' ' then
1265 Write_Info_Str (" E");
1266 Write_Info_Char (Partition_Elaboration_Policy);
1267 end if;
1269 if Opt.Interrupts_System_By_Default then
1270 Write_Info_Str (" ID");
1271 end if;
1273 if No_Component_Reordering_Config then
1274 Write_Info_Str (" NC");
1275 end if;
1277 if not Object then
1278 Write_Info_Str (" NO");
1279 end if;
1281 if No_Run_Time_Mode then
1282 Write_Info_Str (" NR");
1283 end if;
1285 if Normalize_Scalars then
1286 Write_Info_Str (" NS");
1287 end if;
1289 if Default_SSO_Config /= ' ' then
1290 Write_Info_Str (" O");
1291 Write_Info_Char (Default_SSO_Config);
1292 end if;
1294 if Sec_Stack_Used then
1295 Write_Info_Str (" SS");
1296 end if;
1298 if Unreserve_All_Interrupts then
1299 Write_Info_Str (" UA");
1300 end if;
1302 if ZCX_Exceptions then
1303 Write_Info_Str (" ZX");
1304 end if;
1306 Write_Info_EOL;
1308 -- Before outputting the restrictions line, update the setting of
1309 -- the No_Elaboration_Code flag. Violations of this restriction
1310 -- cannot be detected until after the backend has been called since
1311 -- it is the backend that sets this flag. We have to check all units
1312 -- for which we have generated code
1314 for Unit in Units.First .. Last_Unit loop
1315 if Units.Table (Unit).Generate_Code then
1316 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1317 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1318 exit;
1319 end if;
1320 end if;
1321 end loop;
1323 -- Positional case (only if debug flag -gnatd.R is set)
1325 if Debug_Flag_Dot_RR then
1327 -- Output first restrictions line
1329 Write_Info_Initiate ('R');
1330 Write_Info_Char (' ');
1332 -- First the information for the boolean restrictions
1334 for R in All_Boolean_Restrictions loop
1335 if Main_Restrictions.Set (R)
1336 and then not Restriction_Warnings (R)
1337 then
1338 Write_Info_Char ('r');
1339 elsif Main_Restrictions.Violated (R) then
1340 Write_Info_Char ('v');
1341 else
1342 Write_Info_Char ('n');
1343 end if;
1344 end loop;
1346 -- And now the information for the parameter restrictions
1348 for RP in All_Parameter_Restrictions loop
1349 if Main_Restrictions.Set (RP)
1350 and then not Restriction_Warnings (RP)
1351 then
1352 Write_Info_Char ('r');
1353 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1354 else
1355 Write_Info_Char ('n');
1356 end if;
1358 if not Main_Restrictions.Violated (RP)
1359 or else RP not in Checked_Parameter_Restrictions
1360 then
1361 Write_Info_Char ('n');
1362 else
1363 Write_Info_Char ('v');
1364 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1366 if Main_Restrictions.Unknown (RP) then
1367 Write_Info_Char ('+');
1368 end if;
1369 end if;
1370 end loop;
1372 Write_Info_EOL;
1374 -- Named case (if debug flag -gnatd.R is not set)
1376 else
1377 declare
1378 C : Character;
1380 begin
1381 -- Write RN header line with preceding blank line
1383 Write_Info_EOL;
1384 Write_Info_Initiate ('R');
1385 Write_Info_Char ('N');
1386 Write_Info_EOL;
1388 -- First the lines for the boolean restrictions
1390 for R in All_Boolean_Restrictions loop
1391 if Main_Restrictions.Set (R)
1392 and then not Restriction_Warnings (R)
1393 then
1394 C := 'R';
1395 elsif Main_Restrictions.Violated (R) then
1396 C := 'V';
1397 else
1398 goto Continue;
1399 end if;
1401 Write_Info_Initiate ('R');
1402 Write_Info_Char (C);
1403 Write_Info_Char (' ');
1404 Write_Info_Str (All_Boolean_Restrictions'Image (R));
1405 Write_Info_EOL;
1407 <<Continue>>
1408 null;
1409 end loop;
1410 end;
1412 -- And now the lines for the parameter restrictions
1414 for RP in All_Parameter_Restrictions loop
1415 if Main_Restrictions.Set (RP)
1416 and then not Restriction_Warnings (RP)
1417 then
1418 Write_Info_Initiate ('R');
1419 Write_Info_Str ("R ");
1420 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1421 Write_Info_Char ('=');
1422 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1423 Write_Info_EOL;
1424 end if;
1426 if not Main_Restrictions.Violated (RP)
1427 or else RP not in Checked_Parameter_Restrictions
1428 then
1429 null;
1430 else
1431 Write_Info_Initiate ('R');
1432 Write_Info_Str ("V ");
1433 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1434 Write_Info_Char ('=');
1435 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1437 if Main_Restrictions.Unknown (RP) then
1438 Write_Info_Char ('+');
1439 end if;
1441 Write_Info_EOL;
1442 end if;
1443 end loop;
1444 end if;
1446 -- Output R lines for No_Dependence entries
1448 for J in No_Dependences.First .. No_Dependences.Last loop
1449 if In_Extended_Main_Source_Unit (No_Dependences.Table (J).Unit)
1450 and then not No_Dependences.Table (J).Warn
1451 then
1452 Write_Info_Initiate ('R');
1453 Write_Info_Char (' ');
1454 Write_Unit_Name (No_Dependences.Table (J).Unit);
1455 Write_Info_EOL;
1456 end if;
1457 end loop;
1459 -- Output interrupt state lines
1461 for J in Interrupt_States.First .. Interrupt_States.Last loop
1462 Write_Info_Initiate ('I');
1463 Write_Info_Char (' ');
1464 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1465 Write_Info_Char (' ');
1466 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1467 Write_Info_Char (' ');
1468 Write_Info_Nat
1469 (Nat (Get_Logical_Line_Number
1470 (Interrupt_States.Table (J).Pragma_Loc)));
1471 Write_Info_EOL;
1472 end loop;
1474 -- Output priority specific dispatching lines
1476 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1477 Write_Info_Initiate ('S');
1478 Write_Info_Char (' ');
1479 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1480 Write_Info_Char (' ');
1481 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1482 Write_Info_Char (' ');
1483 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1484 Write_Info_Char (' ');
1485 Write_Info_Nat
1486 (Nat (Get_Logical_Line_Number
1487 (Specific_Dispatching.Table (J).Pragma_Loc)));
1488 Write_Info_EOL;
1489 end loop;
1491 -- Loop through file table to output information for all units for which
1492 -- we have generated code, as marked by the Generate_Code flag.
1494 for Unit in Units.First .. Last_Unit loop
1495 if Units.Table (Unit).Generate_Code
1496 or else Unit = Main_Unit
1497 then
1498 Write_Info_EOL; -- blank line
1499 Write_Unit_Information (Unit);
1500 end if;
1501 end loop;
1503 Write_Info_EOL; -- blank line
1505 -- Output external version reference lines
1507 for J in 1 .. Version_Ref.Last loop
1508 Write_Info_Initiate ('E');
1509 Write_Info_Char (' ');
1511 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1512 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1513 end loop;
1515 Write_Info_EOL;
1516 end loop;
1518 -- Prepare to output the source dependency lines
1520 declare
1521 Unum : Unit_Number_Type;
1522 -- Number of unit being output
1524 Sind : Source_File_Index;
1525 -- Index of corresponding source file
1527 Fname : File_Name_Type;
1529 begin
1530 for J in 1 .. Num_Sdep loop
1531 Unum := Sdep_Table (J);
1532 Units.Table (Unum).Dependency_Num := J;
1533 Sind := Source_Index (Unum);
1535 Write_Info_Initiate ('D');
1536 Write_Info_Char (' ');
1538 -- Normal case of a unit entry with a source index
1540 if Sind > No_Source_File then
1542 if Config_Files_Store_Basename then
1543 Fname := Strip_Directory (File_Name (Sind));
1544 else
1545 Fname := File_Name (Sind);
1546 end if;
1548 -- Ensure that on platforms where the file names are not
1549 -- case sensitive, the recorded file name is in lower case.
1551 if not File_Names_Case_Sensitive then
1552 Get_Name_String (Fname);
1553 To_Lower (Name_Buffer (1 .. Name_Len));
1554 Fname := Name_Find;
1555 end if;
1557 Write_Info_Name_May_Be_Quoted (Fname);
1558 Write_Info_Tab (25);
1559 Write_Info_Str (String (Time_Stamp (Sind)));
1560 Write_Info_Char (' ');
1561 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1563 -- If the dependency comes from a limited_with clause, record
1564 -- limited_checksum. This is disabled until full checksum
1565 -- changes are checked.
1567 -- if Present (Cunit_Entity (Unum))
1568 -- and then From_Limited_With (Cunit_Entity (Unum))
1569 -- then
1570 -- Write_Info_Char (' ');
1571 -- Write_Info_Char ('Y');
1572 -- Write_Info_Str (Get_Hex_String (Limited_Chk_Sum (Sind)));
1573 -- end if;
1575 -- If subunit, add unit name, omitting the %b at the end
1577 if Present (Cunit (Unum)) then
1578 Get_Decoded_Name_String (Unit_Name (Unum));
1579 Write_Info_Char (' ');
1581 if Nkind (Unit (Cunit (Unum))) = N_Subunit then
1582 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1583 else
1584 Write_Info_Str (Name_Buffer (1 .. Name_Len));
1585 end if;
1586 end if;
1588 -- If Source_Reference pragma used, output information
1590 if Num_SRef_Pragmas (Sind) > 0 then
1591 Write_Info_Char (' ');
1593 if Num_SRef_Pragmas (Sind) = 1 then
1594 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1595 else
1596 Write_Info_Nat (0);
1597 end if;
1599 Write_Info_Char (':');
1600 Write_Info_Name (Reference_Name (Sind));
1601 end if;
1603 -- Case where there is no source index (happens for missing
1604 -- files). In this case we write a dummy time stamp.
1606 else
1607 Write_Info_Name (Unit_File_Name (Unum));
1608 Write_Info_Tab (25);
1609 Write_Info_Str (String (Dummy_Time_Stamp));
1610 Write_Info_Char (' ');
1611 Write_Info_Str (Get_Hex_String (0));
1612 end if;
1614 Write_Info_EOL;
1615 end loop;
1616 end;
1618 -- Output the invocation graph
1620 Write_Invocation_Graph;
1622 -- Output cross-references
1624 if Opt.Xref_Active then
1625 Output_References;
1626 end if;
1628 -- Output SCO information if present
1630 if Generate_SCO then
1631 SCO_Record_Filtered;
1632 SCO_Output;
1633 end if;
1635 -- Output final blank line and we are done. This final blank line is
1636 -- probably junk, but we don't feel like making an incompatible change.
1638 Write_Info_Terminate;
1639 Close_Output_Library_Info;
1640 end Write_ALI;
1642 --------------------------------
1643 -- Write_Invocation_Construct --
1644 --------------------------------
1646 procedure Write_Invocation_Construct (IC_Id : Invocation_Construct_Id) is
1647 begin
1648 -- G header
1650 Write_Info_Initiate ('G');
1651 Write_Info_Char (' ');
1653 -- line-kind
1655 Write_Info_Char
1656 (Invocation_Graph_Line_Kind_To_Code (Invocation_Construct_Line));
1657 Write_Info_Char (' ');
1659 -- construct-kind
1661 Write_Info_Char (Invocation_Construct_Kind_To_Code (Kind (IC_Id)));
1662 Write_Info_Char (' ');
1664 -- construct-spec-placement
1666 Write_Info_Char
1667 (Declaration_Placement_Kind_To_Code (Spec_Placement (IC_Id)));
1668 Write_Info_Char (' ');
1670 -- construct-body-placement
1672 Write_Info_Char
1673 (Declaration_Placement_Kind_To_Code (Body_Placement (IC_Id)));
1674 Write_Info_Char (' ');
1676 -- construct-signature
1678 Write_Invocation_Signature (Signature (IC_Id));
1679 Write_Info_EOL;
1680 end Write_Invocation_Construct;
1682 ---------------------------------------
1683 -- Write_Invocation_Graph_Attributes --
1684 ---------------------------------------
1686 procedure Write_Invocation_Graph_Attributes is
1687 begin
1688 -- G header
1690 Write_Info_Initiate ('G');
1691 Write_Info_Char (' ');
1693 -- line-kind
1695 Write_Info_Char
1696 (Invocation_Graph_Line_Kind_To_Code
1697 (Invocation_Graph_Attributes_Line));
1698 Write_Info_Char (' ');
1700 -- encoding-kind
1702 Write_Info_Char
1703 (Invocation_Graph_Encoding_Kind_To_Code (Invocation_Graph_Encoding));
1704 Write_Info_EOL;
1705 end Write_Invocation_Graph_Attributes;
1707 ----------------------------
1708 -- Write_Invocation_Graph --
1709 ----------------------------
1711 procedure Write_Invocation_Graph is
1712 begin
1713 Write_Invocation_Graph_Attributes;
1715 -- First write out all invocation constructs declared within the current
1716 -- unit. This ensures that when this invocation is read, the invocation
1717 -- constructs are materialized before they are referenced by invocation
1718 -- relations.
1720 For_Each_Invocation_Construct (Write_Invocation_Construct'Access);
1722 -- Write out all invocation relations that originate from invocation
1723 -- constructs delared in the current unit.
1725 For_Each_Invocation_Relation (Write_Invocation_Relation'Access);
1726 end Write_Invocation_Graph;
1728 -------------------------------
1729 -- Write_Invocation_Relation --
1730 -------------------------------
1732 procedure Write_Invocation_Relation (IR_Id : Invocation_Relation_Id) is
1733 begin
1734 -- G header
1736 Write_Info_Initiate ('G');
1737 Write_Info_Char (' ');
1739 -- line-kind
1741 Write_Info_Char
1742 (Invocation_Graph_Line_Kind_To_Code (Invocation_Relation_Line));
1743 Write_Info_Char (' ');
1745 -- relation-kind
1747 Write_Info_Char (Invocation_Kind_To_Code (Kind (IR_Id)));
1748 Write_Info_Char (' ');
1750 -- (extra-name | "none")
1752 if Present (Extra (IR_Id)) then
1753 Write_Info_Name (Extra (IR_Id));
1754 else
1755 Write_Info_Str ("none");
1756 end if;
1758 Write_Info_Char (' ');
1760 -- invoker-signature
1762 Write_Invocation_Signature (Invoker (IR_Id));
1763 Write_Info_Char (' ');
1765 -- target-signature
1767 Write_Invocation_Signature (Target (IR_Id));
1769 Write_Info_EOL;
1770 end Write_Invocation_Relation;
1772 --------------------------------
1773 -- Write_Invocation_Signature --
1774 --------------------------------
1776 procedure Write_Invocation_Signature (IS_Id : Invocation_Signature_Id) is
1777 begin
1778 -- [
1780 Write_Info_Char ('[');
1782 -- name
1784 Write_Info_Name (Name (IS_Id));
1785 Write_Info_Char (' ');
1787 -- scope
1789 Write_Info_Name (IS_Scope (IS_Id));
1790 Write_Info_Char (' ');
1792 -- line
1794 Write_Info_Nat (Line (IS_Id));
1795 Write_Info_Char (' ');
1797 -- column
1799 Write_Info_Nat (Column (IS_Id));
1800 Write_Info_Char (' ');
1802 -- (locations | "none")
1804 if Present (Locations (IS_Id)) then
1805 Write_Info_Name (Locations (IS_Id));
1806 else
1807 Write_Info_Str ("none");
1808 end if;
1810 -- ]
1812 Write_Info_Char (']');
1813 end Write_Invocation_Signature;
1815 ---------------------
1816 -- Write_Unit_Name --
1817 ---------------------
1819 procedure Write_Unit_Name (N : Node_Id) is
1820 begin
1821 if Nkind (N) = N_Identifier then
1822 Write_Info_Name (Chars (N));
1824 else
1825 pragma Assert (Nkind (N) = N_Selected_Component);
1826 Write_Unit_Name (Prefix (N));
1827 Write_Info_Char ('.');
1828 Write_Unit_Name (Selector_Name (N));
1829 end if;
1830 end Write_Unit_Name;
1832 end Lib.Writ;