Debian Codegraph @

gcc/ada/lib-writ.adb

raw
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-2025, 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 ------------------------------------------------------------------------------
25
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;
62
63 with System.Case_Util; use System.Case_Util;
64 with System.WCh_Con; use System.WCh_Con;
65
66 package body Lib.Writ is
67
68 -----------------------
69 -- Local subprograms --
70 -----------------------
71
72 function Present (N_Id : Name_Id) return Boolean;
73 pragma Inline (Present);
74 -- Determine whether a name with id N_Id exists
75
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
79
80 procedure Write_Invocation_Graph;
81 pragma Inline (Write_Invocation_Graph);
82 -- Write out the invocation graph
83
84 procedure Write_Invocation_Graph_Attributes;
85 pragma Inline (Write_Invocation_Graph_Attributes);
86 -- Write out the attributes of the invocation graph
87
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
91
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
95
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).
99
100 ----------------------------------
101 -- Add_Preprocessing_Dependency --
102 ----------------------------------
103
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;
137
138 ------------------------------
139 -- Ensure_System_Dependency --
140 ------------------------------
141
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
146
147 System_Fname : File_Name_Type;
148 -- File name for system spec if needed for dummy entry
149
150 begin
151 -- Nothing to do if we already compiled System
152
153 if Is_Loaded (System_Uname) then
154 return;
155 end if;
156
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.
162
163 System_Fname := File_Name (System_Source_File_Index);
164
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);
196
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.
200
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;
215
216 -------------
217 -- Present --
218 -------------
219
220 function Present (N_Id : Name_Id) return Boolean is
221 begin
222 return N_Id /= No_Name;
223 end Present;
224
225 ---------------
226 -- Write_ALI --
227 ---------------
228
229 procedure Write_ALI (Object : Boolean) is
230
231 ----------------
232 -- Local Data --
233 ----------------
234
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.
238
239 With_Flags : array (Units.First .. Last_Unit) of Boolean;
240 -- Array of flags to show which units are with'ed
241
242 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
243 -- Array of flags to show which units have pragma Elaborate set
244
245 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
246 -- Array of flags to show which units have pragma Elaborate All set
247
248 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
249 -- Array of flags to show which units have Elaborate_Desirable set
250
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
253
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.
258
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.
262
263 Num_Sdep : Nat := 0;
264 -- Number of active entries in Sdep_Table
265
266 -----------------------
267 -- Local Subprograms --
268 -----------------------
269
270 procedure Collect_Withs (Cunit : Node_Id);
271 -- Collect with lines for entries in the context clause of the given
272 -- compilation unit, Cunit.
273
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.
277
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).
281
282 procedure Write_With_Lines;
283 -- Write out with lines collected by calls to Collect_Withs
284
285 -------------------
286 -- Collect_Withs --
287 -------------------
288
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
293
294 -----------------------------
295 -- Is_Implicit_With_Clause --
296 -----------------------------
297
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
302 --
303 -- with A.B;
304 --
305 -- is almost equivalent to
306 --
307 -- with A;
308 -- with A.B;
309 --
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.
314
315 if Parent_With (Clause) then
316 return False;
317
318 else
319 return Is_Implicit_With (Clause);
320 end if;
321 end Is_Implicit_With_Clause;
322
323 -- Local variables
324
325 Item : Node_Id;
326 Unum : Unit_Number_Type;
327
328 -- Start of processing for Collect_Withs
329
330 begin
331 Item := First (Context_Items (Cunit));
332 while Present (Item) loop
333
334 -- Process with clause
335
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.
340
341 if Nkind (Item) = N_With_Clause then
342 Unum := Get_Cunit_Unit_Number (Withed_Lib_Unit (Item));
343 With_Flags (Unum) := True;
344
345 if not Limited_Present (Item) then
346 if Elaborate_Present (Item) then
347 Elab_Flags (Unum) := True;
348 end if;
349
350 if Elaborate_All_Present (Item) then
351 Elab_All_Flags (Unum) := True;
352 end if;
353
354 if Elaborate_All_Desirable (Item) then
355 Elab_All_Des_Flags (Unum) := True;
356 end if;
357
358 if Elaborate_Desirable (Item) then
359 Elab_Des_Flags (Unum) := True;
360 end if;
361
362 else
363 Set_From_Limited_With (Cunit_Entity (Unum));
364 end if;
365
366 if Is_Implicit_With_Clause (Item) then
367
368 -- A previous explicit with clause withs the unit. Retain
369 -- this classification, as it reflects the source relations
370 -- between units.
371
372 if Has_Implicit_With (Unum) = No then
373 null;
374
375 -- Otherwise this is either the first time any clause withs
376 -- the unit, or the unit is already implicitly withed.
377
378 else
379 Has_Implicit_With (Unum) := Yes;
380 end if;
381
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.
385
386 else
387 Has_Implicit_With (Unum) := No;
388 end if;
389 end if;
390
391 Next (Item);
392 end loop;
393 end Collect_Withs;
394
395 -------------------------
396 -- Output_CUDA_Symbols --
397 -------------------------
398
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;
418
419 Kernel_Elm := First_Elmt (Kernels);
420 while Present (Kernel_Elm) loop
421 Kernel := Node (Kernel_Elm);
422
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;
429
430 end Output_CUDA_Symbols;
431
432 ----------------------------
433 -- Write_Unit_Information --
434 ----------------------------
435
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;
441
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));
448
449 Write_Info_Tab (49);
450 Write_Info_Str (Version_Get (Unit_Num));
451
452 -- Add BD parameter if Elaborate_Body pragma desirable
453
454 if Ekind (Uent) = E_Package
455 and then Elaborate_Body_Desirable (Uent)
456 then
457 Write_Info_Str (" BD");
458 end if;
459
460 -- Add BN parameter if body needed for SAL
461
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;
469
470 if Dynamic_Elab (Unit_Num) then
471 Write_Info_Str (" DE");
472 end if;
473
474 -- Set the Elaborate_Body indication if either an explicit pragma
475 -- was present, or if this is an instantiation.
476
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;
484
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:
488
489 -- If this is a spec ...
490
491 if (Is_Subprogram (Uent)
492 or else Ekind (Uent) = E_Package
493 or else Is_Generic_Unit (Uent))
494
495 -- and an elaboration entity was declared ...
496
497 and then Present (Elaboration_Entity (Uent))
498
499 -- and either the elaboration flag is required ...
500
501 and then (Elaboration_Entity_Required (Uent)
502
503 -- or this unit has elaboration code ...
504
505 or else not Has_No_Elaboration_Code (Unode)
506
507 -- or this unit has a separate body and this
508 -- body has elaboration code.
509
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;
519
520 if Has_No_Elaboration_Code (Unode) then
521 Write_Info_Str (" NE");
522 end if;
523
524 Write_Info_Str (" O");
525 Write_Info_Char (OA_Setting (Unit_Num));
526
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.
529
530 if Ukind in N_Package_Declaration | N_Package_Body then
531 declare
532 E : constant Entity_Id := Defining_Entity (Unit (Unode));
533
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;
542
543 if Is_Preelaborated (Uent) then
544 Write_Info_Str (" PR");
545 end if;
546
547 if Is_Pure (Uent) then
548 Write_Info_Str (" PU");
549 end if;
550
551 if Has_RACW (Unit_Num) then
552 Write_Info_Str (" RA");
553 end if;
554
555 if Is_Remote_Call_Interface (Uent) then
556 Write_Info_Str (" RC");
557 end if;
558
559 if Is_Remote_Types (Uent) then
560 Write_Info_Str (" RT");
561 end if;
562
563 if Serious_Errors_Detected /= 0 then
564 Write_Info_Str (" SE");
565 end if;
566
567 if Is_Shared_Passive (Uent) then
568 Write_Info_Str (" SP");
569 end if;
570
571 if Ukind = N_Subprogram_Declaration
572 or else Ukind = N_Subprogram_Body
573 then
574 Write_Info_Str (" SU");
575
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.
583
584 if Is_Wrapper_Package (Uent) then
585 Write_Info_Str (" SU");
586 else
587 Write_Info_Str (" PK");
588 end if;
589
590 elsif Ukind = N_Generic_Package_Declaration then
591 Write_Info_Str (" PK");
592
593 end if;
594
595 if Ukind in N_Generic_Declaration
596 or else
597 (Ukind in N_Lib_Unit_Body
598 and then Present (Spec_Lib_Unit (Unode))
599 and then Nkind (Unit (Spec_Lib_Unit (Unode)))
600 in N_Generic_Declaration)
601 then
602 Write_Info_Str (" GE");
603 end if;
604
605 if not Is_Internal_Unit (Unit_Num) then
606 case Identifier_Casing (Source_Index (Unit_Num)) is
607 when All_Lower_Case => Write_Info_Str (" IL");
608 when All_Upper_Case => Write_Info_Str (" IU");
609 when others => null;
610 end case;
611
612 case Keyword_Casing (Source_Index (Unit_Num)) is
613 when Mixed_Case => Write_Info_Str (" KM");
614 when All_Upper_Case => Write_Info_Str (" KU");
615 when others => null;
616 end case;
617 end if;
618
619 if Initialize_Scalars or else Invalid_Value_Used then
620 Write_Info_Str (" IS");
621 end if;
622
623 Write_Info_EOL;
624
625 -- Generate with lines, first those that are directly with'ed
626
627 for J in With_Flags'Range loop
628 With_Flags (J) := False;
629 Elab_Flags (J) := False;
630 Elab_All_Flags (J) := False;
631 Elab_Des_Flags (J) := False;
632 Elab_All_Des_Flags (J) := False;
633 Has_Implicit_With (J) := Unknown;
634 end loop;
635
636 Collect_Withs (Unode);
637
638 -- For a body, we must also check for any subunits which belong to
639 -- it and which have context clauses of their own, since these
640 -- with'ed units are part of its own elaboration dependencies.
641
642 if Nkind (Unit (Unode)) in N_Lib_Unit_Body then
643 for S in Units.First .. Last_Unit loop
644
645 -- We are only interested in subunits. For preproc. data and
646 -- def. files, Cunit is Empty, so we need to test that first.
647
648 if Cunit (S) /= Empty
649 and then Nkind (Unit (Cunit (S))) = N_Subunit
650 then
651 Pnode := Subunit_Parent (Cunit (S));
652
653 -- In gnatc mode, the errors in the subunits will not have
654 -- been recorded, but the analysis of the subunit may have
655 -- failed. There is no information to add to ALI file in
656 -- this case.
657
658 if No (Pnode) then
659 exit;
660 end if;
661
662 -- Find ultimate parent of the subunit
663
664 while Nkind (Unit (Pnode)) = N_Subunit loop
665 Pnode := Subunit_Parent (Pnode);
666 end loop;
667
668 -- See if it belongs to current unit, and if so, include
669 -- its with_clauses.
670
671 if Pnode = Unode then
672 Collect_Withs (Cunit (S));
673 end if;
674 end if;
675 end loop;
676 end if;
677
678 Write_With_Lines;
679
680 -- Generate task stack lines
681
682 if Primary_Stack_Count (Unit_Num) > 0
683 or else Sec_Stack_Count (Unit_Num) > 0
684 then
685 Write_Info_Initiate ('T');
686 Write_Info_Char (' ');
687 Write_Info_Int (Primary_Stack_Count (Unit_Num));
688 Write_Info_Char (' ');
689 Write_Info_Int (Sec_Stack_Count (Unit_Num));
690 Write_Info_EOL;
691 end if;
692
693 -- Generate the linker option lines
694
695 for J in 1 .. Linker_Option_Lines.Last loop
696
697 -- Pragma Linker_Options is not allowed in predefined generic
698 -- units. This is because they won't be read, due to the fact that
699 -- with lines for generic units lack the file name and lib name
700 -- parameters (see Lib_Writ spec for an explanation).
701
702 if Is_Generic_Unit (Cunit_Entity (Main_Unit))
703 and then Is_Predefined_Unit (Current_Sem_Unit)
704 and then Linker_Option_Lines.Table (J).Unit = Unit_Num
705 then
706 Set_Standard_Error;
707 Write_Line
708 ("linker options not allowed in predefined generic unit");
709 raise Unrecoverable_Error;
710 end if;
711
712 -- Output one linker option line
713
714 declare
715 S : Linker_Option_Entry renames Linker_Option_Lines.Table (J);
716 begin
717 if S.Unit = Unit_Num then
718 Write_Info_Initiate ('L');
719 Write_Info_Char (' ');
720 Write_Info_Slit (S.Option);
721 Write_Info_EOL;
722 end if;
723 end;
724 end loop;
725
726 -- Output notes
727
728 for J in 1 .. Notes.Last loop
729 declare
730 N : constant Node_Id := Notes.Table (J);
731 L : constant Source_Ptr := Sloc (N);
732 U : constant Unit_Number_Type :=
733 Unit (Get_Source_File_Index (L));
734 C : Character;
735
736 Note_Unit : Unit_Number_Type;
737 -- The unit in whose U section this note must be emitted:
738 -- notes for subunits are emitted along with the main unit;
739 -- all other notes are emitted as part of the enclosing
740 -- compilation unit.
741
742 begin
743 if U /= No_Unit and then Nkind (Unit (Cunit (U))) = N_Subunit
744 then
745 Note_Unit := Main_Unit;
746 else
747 Note_Unit := U;
748 end if;
749
750 -- No action needed for pragmas removed by the expander (for
751 -- example, pragmas of ignored ghost entities).
752
753 if Nkind (N) = N_Null_Statement then
754 pragma Assert (Nkind (Original_Node (N)) = N_Pragma);
755 null;
756
757 elsif Note_Unit = Unit_Num then
758 Write_Info_Initiate ('N');
759 Write_Info_Char (' ');
760
761 case Pragma_Name (N) is
762 when Name_Annotate | Name_GNAT_Annotate =>
763 C := 'A';
764 when Name_Comment =>
765 C := 'C';
766 when Name_Ident =>
767 C := 'I';
768 when Name_Title =>
769 C := 'T';
770 when Name_Subtitle =>
771 C := 'S';
772 when others =>
773 raise Program_Error;
774 end case;
775
776 Write_Info_Char (C);
777 Write_Info_Int (Int (Get_Logical_Line_Number (L)));
778 Write_Info_Char (':');
779 Write_Info_Int (Int (Get_Column_Number (L)));
780
781 -- Indicate source file of annotation if different from
782 -- compilation unit source file (case of annotation coming
783 -- from a separate).
784
785 if Get_Source_File_Index (L) /= Source_Index (Unit_Num) then
786 Write_Info_Char (':');
787 Write_Info_Name (File_Name (Get_Source_File_Index (L)));
788 end if;
789
790 declare
791 A : Node_Id;
792
793 begin
794 A := First (Pragma_Argument_Associations (N));
795 while Present (A) loop
796 Write_Info_Char (' ');
797
798 if Chars (A) /= No_Name then
799 Write_Info_Name (Chars (A));
800 Write_Info_Char (':');
801 end if;
802
803 declare
804 Expr : constant Node_Id := Expression (A);
805
806 begin
807 if Nkind (Expr) = N_Identifier then
808 Write_Info_Name (Chars (Expr));
809
810 elsif Nkind (Expr) = N_Integer_Literal
811 and then Is_OK_Static_Expression (Expr)
812 then
813 Write_Info_Uint (Intval (Expr));
814
815 elsif Nkind (Expr) = N_String_Literal
816 and then Is_OK_Static_Expression (Expr)
817 then
818 Write_Info_Slit (Strval (Expr));
819
820 else
821 Write_Info_Str ("<expr>");
822 end if;
823 end;
824
825 Next (A);
826 end loop;
827 end;
828
829 Write_Info_EOL;
830 end if;
831 end;
832 end loop;
833 end Write_Unit_Information;
834
835 ----------------------
836 -- Write_With_Lines --
837 ----------------------
838
839 procedure Write_With_Lines is
840 Pname : constant Unit_Name_Type :=
841 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
842 Body_Fname : File_Name_Type;
843 Body_Index : Nat;
844 Cunit : Node_Id;
845 Fname : File_Name_Type;
846 Num_Withs : Int := 0;
847 Unum : Unit_Number_Type;
848 Uname : Unit_Name_Type;
849 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
850
851 procedure Write_With_File_Names
852 (Nam : in out File_Name_Type;
853 Idx : Nat);
854 -- Write source file name Nam and ALI file name for unit index Idx.
855 -- Possibly change Nam to lowercase (generating a new file name).
856
857 ---------------------------
858 -- Write_With_File_Names --
859 ---------------------------
860
861 procedure Write_With_File_Names
862 (Nam : in out File_Name_Type;
863 Idx : Nat)
864 is
865 begin
866 if not File_Names_Case_Sensitive then
867 Get_Name_String (Nam);
868 To_Lower (Name_Buffer (1 .. Name_Len));
869 Nam := Name_Find;
870 end if;
871
872 Write_Info_Name (Nam);
873 Write_Info_Tab (49);
874 Write_Info_Name (Lib_File_Name (Nam, Idx));
875 end Write_With_File_Names;
876
877 -- Start of processing for Write_With_Lines
878
879 begin
880 -- Loop to build the with table. A with on the main unit itself
881 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
882 -- the main unit is a subprogram with no spec, and a subunit of
883 -- it unnecessarily withs the parent.
884
885 for J in Units.First + 1 .. Last_Unit loop
886
887 -- Add element to with table if it is with'ed or if it is the
888 -- parent spec of the main unit (case of main unit is a child
889 -- unit). The latter with is not needed for semantic purposes,
890 -- but is required by the binder for elaboration purposes. For
891 -- preprocessing data and definition files, there is no Unit_Name,
892 -- check for that first.
893
894 if Present (Unit_Name (J))
895 and then (With_Flags (J) or else Unit_Name (J) = Pname)
896 then
897 Num_Withs := Num_Withs + 1;
898 With_Table (Num_Withs) := J;
899 end if;
900 end loop;
901
902 -- Sort and output the table
903
904 Sort (With_Table (1 .. Num_Withs));
905
906 for J in 1 .. Num_Withs loop
907 Unum := With_Table (J);
908
909 -- Do not generate a with line for an ignored Ghost unit because
910 -- the unit does not have an ALI file.
911
912 if Is_Ignored_Ghost_Entity (Cunit_Entity (Unum)) then
913 goto Next_With_Line;
914 end if;
915
916 Cunit := Units.Table (Unum).Cunit;
917 Uname := Units.Table (Unum).Unit_Name;
918 Fname := Units.Table (Unum).Unit_File_Name;
919
920 -- Limited with clauses must be processed first because they are
921 -- the most specific among the three kinds.
922
923 if Ekind (Cunit_Entity (Unum)) = E_Package
924 and then From_Limited_With (Cunit_Entity (Unum))
925 then
926 Write_Info_Initiate ('Y');
927
928 elsif Has_Implicit_With (Unum) = Yes then
929 Write_Info_Initiate ('Z');
930
931 else
932 Write_Info_Initiate ('W');
933 end if;
934
935 Write_Info_Char (' ');
936 Write_Info_Name (Uname);
937
938 -- Now we need to figure out the names of the files that contain
939 -- the with'ed unit. These will usually be the files for the body,
940 -- except in the case of a package that has no body. Note that we
941 -- have a specific exemption here for predefined library generics
942 -- (see comments for Generic_May_Lack_ALI). We do not generate
943 -- dependency upon the ALI file for such units. Older compilers
944 -- used to not support generating code (and ALI) for generics, and
945 -- we want to avoid having different processing (namely, different
946 -- lists of files to be compiled) for different stages of the
947 -- bootstrap.
948
949 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
950 or else
951 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
952 and then Generic_May_Lack_ALI (Unum))
953
954 -- In SPARK mode, always generate the dependencies on ALI
955 -- files, which are required to compute frame conditions
956 -- of subprograms.
957
958 or else GNATprove_Mode
959 then
960 Write_Info_Tab (25);
961
962 if Is_Spec_Name (Uname) then
963 Body_Fname :=
964 Get_File_Name
965 (Uname => Get_Body_Name (Uname),
966 Subunit => False,
967 May_Fail => True);
968
969 Body_Index := Get_Unit_Index (Get_Body_Name (Uname));
970
971 if Body_Fname = No_File then
972 Body_Fname := Get_File_Name (Uname, Subunit => False);
973 Body_Index := Get_Unit_Index (Uname);
974 end if;
975 else
976 Body_Fname := Get_File_Name (Uname, Subunit => False);
977 Body_Index := Get_Unit_Index (Uname);
978 end if;
979
980 -- A package is considered to have a body if it requires
981 -- a body or if a body is present in Ada 83 mode.
982
983 if Body_Required (Cunit)
984 or else (Ada_Version = Ada_83
985 and then Full_Source_Name (Body_Fname) /= No_File)
986 then
987 Write_With_File_Names (Body_Fname, Body_Index);
988 else
989 Write_With_File_Names (Fname, Munit_Index (Unum));
990 end if;
991
992 if Ekind (Cunit_Entity (Unum)) = E_Package
993 and then From_Limited_With (Cunit_Entity (Unum))
994 then
995 null;
996 else
997 if Elab_Flags (Unum) then
998 Write_Info_Str (" E");
999 end if;
1000
1001 if Elab_All_Flags (Unum) then
1002 Write_Info_Str (" EA");
1003 end if;
1004
1005 if Elab_Des_Flags (Unum) then
1006 Write_Info_Str (" ED");
1007 end if;
1008
1009 if Elab_All_Des_Flags (Unum) then
1010 Write_Info_Str (" AD");
1011 end if;
1012 end if;
1013 end if;
1014
1015 Write_Info_EOL;
1016
1017 <<Next_With_Line>>
1018 null;
1019 end loop;
1020
1021 -- Finally generate the special lines for cases of Restriction_Set
1022 -- with No_Dependence and no restriction present.
1023
1024 declare
1025 Unam : Unit_Name_Type;
1026
1027 begin
1028 for J in Restriction_Set_Dependences.First ..
1029 Restriction_Set_Dependences.Last
1030 loop
1031 Unam := Restriction_Set_Dependences.Table (J);
1032
1033 -- Don't need an entry if already in the unit table
1034
1035 for U in 0 .. Last_Unit loop
1036 if Unit_Name (U) = Unam then
1037 goto Next_Restriction_Set;
1038 end if;
1039 end loop;
1040
1041 -- Otherwise generate the entry
1042
1043 Write_Info_Initiate ('W');
1044 Write_Info_Char (' ');
1045 Write_Info_Name (Unam);
1046 Write_Info_EOL;
1047
1048 <<Next_Restriction_Set>>
1049 null;
1050 end loop;
1051 end;
1052 end Write_With_Lines;
1053
1054 -- Start of processing for Write_ALI
1055
1056 begin
1057 -- We never write an ALI file if the original operating mode was
1058 -- syntax-only (-gnats switch used in compiler invocation line).
1059
1060 if Original_Operating_Mode = Check_Syntax then
1061 return;
1062 end if;
1063
1064 -- Generation of ALI files may be disabled, e.g. for formal verification
1065 -- back-end.
1066
1067 if Disable_ALI_File then
1068 return;
1069 end if;
1070
1071 -- Build sorted source dependency table
1072
1073 for Unum in Units.First .. Last_Unit loop
1074 if Cunit_Entity (Unum) = Empty
1075 or else not From_Limited_With (Cunit_Entity (Unum))
1076 then
1077 -- Units that are not analyzed need not appear in the dependency
1078 -- list. These units are either units appearing in limited_with
1079 -- clauses of other units, or units loaded for inlining that end
1080 -- up not inlined by a later decision of the inlining code, to
1081 -- prevent circularities. We want to exclude these files from the
1082 -- list of dependencies, so that the dependency number of other
1083 -- is correctly set, as that number is used by cross-reference
1084 -- tools to relate entity information to the unit in which they
1085 -- are declared.
1086
1087 if Present (Cunit_Entity (Unum))
1088 and then Ekind (Cunit_Entity (Unum)) = E_Void
1089 and then Nkind (Unit (Cunit (Unum))) /= N_Subunit
1090 and then Serious_Errors_Detected = 0
1091 then
1092 null;
1093
1094 else
1095 Num_Sdep := Num_Sdep + 1;
1096 Sdep_Table (Num_Sdep) := Unum;
1097 end if;
1098 end if;
1099 end loop;
1100
1101 -- Sort the table so that the D lines are in order
1102
1103 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
1104
1105 -- Acquire compilation arguments and prepare to write out a new ali
1106 -- file.
1107
1108 Create_Output_Library_Info;
1109
1110 -- Output version line
1111
1112 Write_Info_Initiate ('V');
1113 Write_Info_Str (" """);
1114 Write_Info_Str (Verbose_Library_Version);
1115 Write_Info_Char ('"');
1116
1117 Write_Info_EOL;
1118
1119 -- Output main program line if this is acceptable main program
1120
1121 Output_Main_Program_Line : declare
1122 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
1123 S : Node_Id;
1124
1125 procedure M_Parameters;
1126 -- Output parameters for main program line
1127
1128 ------------------
1129 -- M_Parameters --
1130 ------------------
1131
1132 procedure M_Parameters is
1133 begin
1134 if Main_Priority (Main_Unit) /= Default_Main_Priority then
1135 Write_Info_Char (' ');
1136 Write_Info_Nat (Main_Priority (Main_Unit));
1137 end if;
1138
1139 if Opt.Time_Slice_Set then
1140 Write_Info_Str (" T=");
1141 Write_Info_Nat (Opt.Time_Slice_Value);
1142 end if;
1143
1144 if Main_CPU (Main_Unit) /= Default_Main_CPU then
1145 Write_Info_Str (" C=");
1146 Write_Info_Nat (Main_CPU (Main_Unit));
1147 end if;
1148
1149 Write_Info_Str (" W=");
1150 Write_Info_Char
1151 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
1152
1153 Write_Info_EOL;
1154 end M_Parameters;
1155
1156 -- Start of processing for Output_Main_Program_Line
1157
1158 begin
1159 if Nkind (U) = N_Subprogram_Body
1160 or else
1161 (Nkind (U) = N_Package_Body
1162 and then
1163 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
1164 then
1165 -- If the unit is a subprogram instance, the entity for the
1166 -- subprogram is the alias of the visible entity, which is the
1167 -- related instance of the wrapper package. We retrieve the
1168 -- subprogram declaration of the desired entity.
1169
1170 if Nkind (U) = N_Package_Body then
1171 U := Parent (Parent (
1172 Alias (Related_Instance (Defining_Unit_Name
1173 (Specification (Unit (Spec_Lib_Unit (Parent (U)))))))));
1174 end if;
1175
1176 S := Specification (U);
1177
1178 -- A generic subprogram is never a main program
1179
1180 if Nkind (U) = N_Subprogram_Body
1181 and then Present (Corresponding_Spec (U))
1182 and then Is_Generic_Subprogram (Corresponding_Spec (U))
1183 then
1184 null;
1185
1186 elsif No (Parameter_Specifications (S)) then
1187 if Nkind (S) = N_Procedure_Specification then
1188 Write_Info_Initiate ('M');
1189 Write_Info_Str (" P");
1190 M_Parameters;
1191
1192 else
1193 declare
1194 Nam : Node_Id := Defining_Unit_Name (S);
1195
1196 begin
1197 -- If it is a child unit, get its simple name
1198
1199 if Nkind (Nam) = N_Defining_Program_Unit_Name then
1200 Nam := Defining_Identifier (Nam);
1201 end if;
1202
1203 if Is_Integer_Type (Etype (Nam)) then
1204 Write_Info_Initiate ('M');
1205 Write_Info_Str (" F");
1206 M_Parameters;
1207 end if;
1208 end;
1209 end if;
1210 end if;
1211 end if;
1212 end Output_Main_Program_Line;
1213
1214 -- Write command argument ('A') lines
1215
1216 for A in 1 .. Compilation_Switches.Last loop
1217 Write_Info_Initiate ('A');
1218 Write_Info_Char (' ');
1219 Write_Info_Str (Compilation_Switches.Table (A).all);
1220 Write_Info_Terminate;
1221 end loop;
1222
1223 -- Output CUDA Kernel lines
1224
1225 for Unit in Units.First .. Last_Unit loop
1226 if Present (Cunit (Unit)) then
1227 Output_CUDA_Symbols (Unit);
1228 end if;
1229 end loop;
1230
1231 -- Output parameters ('P') line
1232
1233 Write_Info_Initiate ('P');
1234
1235 if Compilation_Errors then
1236 Write_Info_Str (" CE");
1237 end if;
1238
1239 if Opt.Detect_Blocking then
1240 Write_Info_Str (" DB");
1241 end if;
1242
1243 if Locking_Policy /= ' ' then
1244 Write_Info_Str (" L");
1245 Write_Info_Char (Locking_Policy);
1246 end if;
1247
1248 if Queuing_Policy /= ' ' then
1249 Write_Info_Str (" Q");
1250 Write_Info_Char (Queuing_Policy);
1251 end if;
1252
1253 if Task_Dispatching_Policy /= ' ' then
1254 Write_Info_Str (" T");
1255 Write_Info_Char (Task_Dispatching_Policy);
1256 end if;
1257
1258 if GNATprove_Mode then
1259 Write_Info_Str (" GP");
1260 end if;
1261
1262 if Partition_Elaboration_Policy /= ' ' then
1263 Write_Info_Str (" E");
1264 Write_Info_Char (Partition_Elaboration_Policy);
1265 end if;
1266
1267 if Opt.Interrupts_System_By_Default then
1268 Write_Info_Str (" ID");
1269 end if;
1270
1271 if No_Component_Reordering_Config then
1272 Write_Info_Str (" NC");
1273 end if;
1274
1275 if not Object then
1276 Write_Info_Str (" NO");
1277 end if;
1278
1279 if No_Run_Time_Mode then
1280 Write_Info_Str (" NR");
1281 end if;
1282
1283 if Normalize_Scalars then
1284 Write_Info_Str (" NS");
1285 end if;
1286
1287 if Default_SSO_Config /= ' ' then
1288 Write_Info_Str (" O");
1289 Write_Info_Char (Default_SSO_Config);
1290 end if;
1291
1292 if Sec_Stack_Used then
1293 Write_Info_Str (" SS");
1294 end if;
1295
1296 if Unreserve_All_Interrupts then
1297 Write_Info_Str (" UA");
1298 end if;
1299
1300 if ZCX_Exceptions then
1301 Write_Info_Str (" ZX");
1302 end if;
1303
1304 Write_Info_EOL;
1305
1306 -- Before outputting the restrictions line, update the setting of
1307 -- the No_Elaboration_Code flag. Violations of this restriction
1308 -- cannot be detected until after the backend has been called since
1309 -- it is the backend that sets this flag. We have to check all units
1310 -- for which we have generated code
1311
1312 for Unit in Units.First .. Last_Unit loop
1313 if Units.Table (Unit).Generate_Code then
1314 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1315 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1316 exit;
1317 end if;
1318 end if;
1319 end loop;
1320
1321 -- Positional case (only if debug flag -gnatd.R is set)
1322
1323 if Debug_Flag_Dot_RR then
1324
1325 -- Output first restrictions line
1326
1327 Write_Info_Initiate ('R');
1328 Write_Info_Char (' ');
1329
1330 -- First the information for the boolean restrictions
1331
1332 for R in All_Boolean_Restrictions loop
1333 if Main_Restrictions.Set (R)
1334 and then not Restriction_Warnings (R)
1335 then
1336 Write_Info_Char ('r');
1337 elsif Main_Restrictions.Violated (R) then
1338 Write_Info_Char ('v');
1339 else
1340 Write_Info_Char ('n');
1341 end if;
1342 end loop;
1343
1344 -- And now the information for the parameter restrictions
1345
1346 for RP in All_Parameter_Restrictions loop
1347 if Main_Restrictions.Set (RP)
1348 and then not Restriction_Warnings (RP)
1349 then
1350 Write_Info_Char ('r');
1351 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1352 else
1353 Write_Info_Char ('n');
1354 end if;
1355
1356 if not Main_Restrictions.Violated (RP)
1357 or else RP not in Checked_Parameter_Restrictions
1358 then
1359 Write_Info_Char ('n');
1360 else
1361 Write_Info_Char ('v');
1362 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1363
1364 if Main_Restrictions.Unknown (RP) then
1365 Write_Info_Char ('+');
1366 end if;
1367 end if;
1368 end loop;
1369
1370 Write_Info_EOL;
1371
1372 -- Named case (if debug flag -gnatd.R is not set)
1373
1374 else
1375 declare
1376 C : Character;
1377
1378 begin
1379 -- Write RN header line with preceding blank line
1380
1381 Write_Info_EOL;
1382 Write_Info_Initiate ('R');
1383 Write_Info_Char ('N');
1384 Write_Info_EOL;
1385
1386 -- First the lines for the boolean restrictions
1387
1388 for R in All_Boolean_Restrictions loop
1389 if Main_Restrictions.Set (R)
1390 and then not Restriction_Warnings (R)
1391 then
1392 C := 'R';
1393 elsif Main_Restrictions.Violated (R) then
1394 C := 'V';
1395 else
1396 goto Continue;
1397 end if;
1398
1399 Write_Info_Initiate ('R');
1400 Write_Info_Char (C);
1401 Write_Info_Char (' ');
1402 Write_Info_Str (All_Boolean_Restrictions'Image (R));
1403 Write_Info_EOL;
1404
1405 <<Continue>>
1406 null;
1407 end loop;
1408 end;
1409
1410 -- And now the lines for the parameter restrictions
1411
1412 for RP in All_Parameter_Restrictions loop
1413 if Main_Restrictions.Set (RP)
1414 and then not Restriction_Warnings (RP)
1415 then
1416 Write_Info_Initiate ('R');
1417 Write_Info_Str ("R ");
1418 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1419 Write_Info_Char ('=');
1420 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1421 Write_Info_EOL;
1422 end if;
1423
1424 if not Main_Restrictions.Violated (RP)
1425 or else RP not in Checked_Parameter_Restrictions
1426 then
1427 null;
1428 else
1429 Write_Info_Initiate ('R');
1430 Write_Info_Str ("V ");
1431 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1432 Write_Info_Char ('=');
1433 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1434
1435 if Main_Restrictions.Unknown (RP) then
1436 Write_Info_Char ('+');
1437 end if;
1438
1439 Write_Info_EOL;
1440 end if;
1441 end loop;
1442 end if;
1443
1444 -- Output R lines for No_Dependence entries
1445
1446 for J in No_Dependences.First .. No_Dependences.Last loop
1447 if In_Extended_Main_Source_Unit (No_Dependences.Table (J).Unit)
1448 and then not No_Dependences.Table (J).Warn
1449 then
1450 Write_Info_Initiate ('R');
1451 Write_Info_Char (' ');
1452 Write_Unit_Name (No_Dependences.Table (J).Unit);
1453 Write_Info_EOL;
1454 end if;
1455 end loop;
1456
1457 -- Output interrupt state lines
1458
1459 for J in Interrupt_States.First .. Interrupt_States.Last loop
1460 Write_Info_Initiate ('I');
1461 Write_Info_Char (' ');
1462 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1463 Write_Info_Char (' ');
1464 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1465 Write_Info_Char (' ');
1466 Write_Info_Nat
1467 (Nat (Get_Logical_Line_Number
1468 (Interrupt_States.Table (J).Pragma_Loc)));
1469 Write_Info_EOL;
1470 end loop;
1471
1472 -- Output priority specific dispatching lines
1473
1474 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1475 Write_Info_Initiate ('S');
1476 Write_Info_Char (' ');
1477 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1478 Write_Info_Char (' ');
1479 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1480 Write_Info_Char (' ');
1481 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1482 Write_Info_Char (' ');
1483 Write_Info_Nat
1484 (Nat (Get_Logical_Line_Number
1485 (Specific_Dispatching.Table (J).Pragma_Loc)));
1486 Write_Info_EOL;
1487 end loop;
1488
1489 -- Loop through file table to output information for all units for which
1490 -- we have generated code, as marked by the Generate_Code flag.
1491
1492 for Unit in Units.First .. Last_Unit loop
1493 if Units.Table (Unit).Generate_Code
1494 or else Unit = Main_Unit
1495 then
1496 Write_Info_EOL; -- blank line
1497 Write_Unit_Information (Unit);
1498 end if;
1499 end loop;
1500
1501 Write_Info_EOL; -- blank line
1502
1503 -- Output external version reference lines
1504
1505 for J in 1 .. Version_Ref.Last loop
1506 Write_Info_Initiate ('E');
1507 Write_Info_Char (' ');
1508
1509 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1510 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1511 end loop;
1512
1513 Write_Info_EOL;
1514 end loop;
1515
1516 -- Prepare to output the source dependency lines
1517
1518 declare
1519 Unum : Unit_Number_Type;
1520 -- Number of unit being output
1521
1522 Sind : Source_File_Index;
1523 -- Index of corresponding source file
1524
1525 Fname : File_Name_Type;
1526
1527 begin
1528 for J in 1 .. Num_Sdep loop
1529 Unum := Sdep_Table (J);
1530 Units.Table (Unum).Dependency_Num := J;
1531 Sind := Source_Index (Unum);
1532
1533 Write_Info_Initiate ('D');
1534 Write_Info_Char (' ');
1535
1536 -- Normal case of a unit entry with a source index
1537
1538 if Sind > No_Source_File then
1539
1540 if Config_Files_Store_Basename then
1541 Fname := Strip_Directory (File_Name (Sind));
1542 else
1543 Fname := File_Name (Sind);
1544 end if;
1545
1546 -- Ensure that on platforms where the file names are not
1547 -- case sensitive, the recorded file name is in lower case.
1548
1549 if not File_Names_Case_Sensitive then
1550 Get_Name_String (Fname);
1551 To_Lower (Name_Buffer (1 .. Name_Len));
1552 Fname := Name_Find;
1553 end if;
1554
1555 Write_Info_Name_May_Be_Quoted (Fname);
1556 Write_Info_Tab (25);
1557 Write_Info_Str (String (Time_Stamp (Sind)));
1558 Write_Info_Char (' ');
1559 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1560
1561 -- If the dependency comes from a limited_with clause, record
1562 -- limited_checksum. This is disabled until full checksum
1563 -- changes are checked.
1564
1565 -- if Present (Cunit_Entity (Unum))
1566 -- and then From_Limited_With (Cunit_Entity (Unum))
1567 -- then
1568 -- Write_Info_Char (' ');
1569 -- Write_Info_Char ('Y');
1570 -- Write_Info_Str (Get_Hex_String (Limited_Chk_Sum (Sind)));
1571 -- end if;
1572
1573 -- If subunit, add unit name, omitting the %b at the end
1574
1575 if Present (Cunit (Unum)) then
1576 Get_Decoded_Name_String (Unit_Name (Unum));
1577 Write_Info_Char (' ');
1578
1579 if Nkind (Unit (Cunit (Unum))) = N_Subunit then
1580 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1581 else
1582 Write_Info_Str (Name_Buffer (1 .. Name_Len));
1583 end if;
1584 end if;
1585
1586 -- If Source_Reference pragma used, output information
1587
1588 if Num_SRef_Pragmas (Sind) > 0 then
1589 Write_Info_Char (' ');
1590
1591 if Num_SRef_Pragmas (Sind) = 1 then
1592 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1593 else
1594 Write_Info_Nat (0);
1595 end if;
1596
1597 Write_Info_Char (':');
1598 Write_Info_Name (Reference_Name (Sind));
1599 end if;
1600
1601 -- Case where there is no source index (happens for missing
1602 -- files). In this case we write a dummy time stamp.
1603
1604 else
1605 Write_Info_Name (Unit_File_Name (Unum));
1606 Write_Info_Tab (25);
1607 Write_Info_Str (String (Dummy_Time_Stamp));
1608 Write_Info_Char (' ');
1609 Write_Info_Str (Get_Hex_String (0));
1610 end if;
1611
1612 Write_Info_EOL;
1613 end loop;
1614 end;
1615
1616 -- Output the invocation graph
1617
1618 Write_Invocation_Graph;
1619
1620 -- Output cross-references
1621
1622 if Opt.Xref_Active then
1623 Output_References;
1624 end if;
1625
1626 -- Output SCO information if present
1627
1628 if Generate_SCO then
1629 SCO_Record_Filtered;
1630 SCO_Output;
1631 end if;
1632
1633 -- Output final blank line and we are done. This final blank line is
1634 -- probably junk, but we don't feel like making an incompatible change.
1635
1636 Write_Info_Terminate;
1637 Close_Output_Library_Info;
1638 end Write_ALI;
1639
1640 --------------------------------
1641 -- Write_Invocation_Construct --
1642 --------------------------------
1643
1644 procedure Write_Invocation_Construct (IC_Id : Invocation_Construct_Id) is
1645 begin
1646 -- G header
1647
1648 Write_Info_Initiate ('G');
1649 Write_Info_Char (' ');
1650
1651 -- line-kind
1652
1653 Write_Info_Char
1654 (Invocation_Graph_Line_Kind_To_Code (Invocation_Construct_Line));
1655 Write_Info_Char (' ');
1656
1657 -- construct-kind
1658
1659 Write_Info_Char (Invocation_Construct_Kind_To_Code (Kind (IC_Id)));
1660 Write_Info_Char (' ');
1661
1662 -- construct-spec-placement
1663
1664 Write_Info_Char
1665 (Declaration_Placement_Kind_To_Code (Spec_Placement (IC_Id)));
1666 Write_Info_Char (' ');
1667
1668 -- construct-body-placement
1669
1670 Write_Info_Char
1671 (Declaration_Placement_Kind_To_Code (Body_Placement (IC_Id)));
1672 Write_Info_Char (' ');
1673
1674 -- construct-signature
1675
1676 Write_Invocation_Signature (Signature (IC_Id));
1677 Write_Info_EOL;
1678 end Write_Invocation_Construct;
1679
1680 ---------------------------------------
1681 -- Write_Invocation_Graph_Attributes --
1682 ---------------------------------------
1683
1684 procedure Write_Invocation_Graph_Attributes is
1685 begin
1686 -- G header
1687
1688 Write_Info_Initiate ('G');
1689 Write_Info_Char (' ');
1690
1691 -- line-kind
1692
1693 Write_Info_Char
1694 (Invocation_Graph_Line_Kind_To_Code
1695 (Invocation_Graph_Attributes_Line));
1696 Write_Info_Char (' ');
1697
1698 -- encoding-kind
1699
1700 Write_Info_Char
1701 (Invocation_Graph_Encoding_Kind_To_Code (Invocation_Graph_Encoding));
1702 Write_Info_EOL;
1703 end Write_Invocation_Graph_Attributes;
1704
1705 ----------------------------
1706 -- Write_Invocation_Graph --
1707 ----------------------------
1708
1709 procedure Write_Invocation_Graph is
1710 begin
1711 Write_Invocation_Graph_Attributes;
1712
1713 -- First write out all invocation constructs declared within the current
1714 -- unit. This ensures that when this invocation is read, the invocation
1715 -- constructs are materialized before they are referenced by invocation
1716 -- relations.
1717
1718 For_Each_Invocation_Construct (Write_Invocation_Construct'Access);
1719
1720 -- Write out all invocation relations that originate from invocation
1721 -- constructs delared in the current unit.
1722
1723 For_Each_Invocation_Relation (Write_Invocation_Relation'Access);
1724 end Write_Invocation_Graph;
1725
1726 -------------------------------
1727 -- Write_Invocation_Relation --
1728 -------------------------------
1729
1730 procedure Write_Invocation_Relation (IR_Id : Invocation_Relation_Id) is
1731 begin
1732 -- G header
1733
1734 Write_Info_Initiate ('G');
1735 Write_Info_Char (' ');
1736
1737 -- line-kind
1738
1739 Write_Info_Char
1740 (Invocation_Graph_Line_Kind_To_Code (Invocation_Relation_Line));
1741 Write_Info_Char (' ');
1742
1743 -- relation-kind
1744
1745 Write_Info_Char (Invocation_Kind_To_Code (Kind (IR_Id)));
1746 Write_Info_Char (' ');
1747
1748 -- (extra-name | "none")
1749
1750 if Present (Extra (IR_Id)) then
1751 Write_Info_Name (Extra (IR_Id));
1752 else
1753 Write_Info_Str ("none");
1754 end if;
1755
1756 Write_Info_Char (' ');
1757
1758 -- invoker-signature
1759
1760 Write_Invocation_Signature (Invoker (IR_Id));
1761 Write_Info_Char (' ');
1762
1763 -- target-signature
1764
1765 Write_Invocation_Signature (Target (IR_Id));
1766
1767 Write_Info_EOL;
1768 end Write_Invocation_Relation;
1769
1770 --------------------------------
1771 -- Write_Invocation_Signature --
1772 --------------------------------
1773
1774 procedure Write_Invocation_Signature (IS_Id : Invocation_Signature_Id) is
1775 begin
1776 -- [
1777
1778 Write_Info_Char ('[');
1779
1780 -- name
1781
1782 Write_Info_Name (Name (IS_Id));
1783 Write_Info_Char (' ');
1784
1785 -- scope
1786
1787 Write_Info_Name (IS_Scope (IS_Id));
1788 Write_Info_Char (' ');
1789
1790 -- line
1791
1792 Write_Info_Nat (Line (IS_Id));
1793 Write_Info_Char (' ');
1794
1795 -- column
1796
1797 Write_Info_Nat (Column (IS_Id));
1798 Write_Info_Char (' ');
1799
1800 -- (locations | "none")
1801
1802 if Present (Locations (IS_Id)) then
1803 Write_Info_Name (Locations (IS_Id));
1804 else
1805 Write_Info_Str ("none");
1806 end if;
1807
1808 -- ]
1809
1810 Write_Info_Char (']');
1811 end Write_Invocation_Signature;
1812
1813 ---------------------
1814 -- Write_Unit_Name --
1815 ---------------------
1816
1817 procedure Write_Unit_Name (N : Node_Id) is
1818 begin
1819 if Nkind (N) = N_Identifier then
1820 Write_Info_Name (Chars (N));
1821
1822 else
1823 pragma Assert (Nkind (N) = N_Selected_Component);
1824 Write_Unit_Name (Prefix (N));
1825 Write_Info_Char ('.');
1826 Write_Unit_Name (Selector_Name (N));
1827 end if;
1828 end Write_Unit_Name;
1829
1830 end Lib.Writ;