Add assember CFI directives to millicode division and remainder routines.
[official-gcc.git] / gcc / ada / lib-writ.adb
blobdeecfc067c503df8eed5175ba002e4039b8795cf
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-2023, 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 Sinfo; use Sinfo;
54 with Sinfo.Nodes; use Sinfo.Nodes;
55 with Sinfo.Utils; use Sinfo.Utils;
56 with Sinput; use Sinput;
57 with Snames; use Snames;
58 with Stringt; use Stringt;
59 with Tbuild; use Tbuild;
60 with Uname; use Uname;
62 with System.Case_Util; use System.Case_Util;
63 with System.WCh_Con; use System.WCh_Con;
65 package body Lib.Writ is
67 -----------------------
68 -- Local subprograms --
69 -----------------------
71 function Present (N_Id : Name_Id) return Boolean;
72 pragma Inline (Present);
73 -- Determine whether a name with id N_Id exists
75 procedure Write_Invocation_Construct (IC_Id : Invocation_Construct_Id);
76 pragma Inline (Write_Invocation_Construct);
77 -- Write invocation construct IC_Id to the ALI file
79 procedure Write_Invocation_Graph;
80 pragma Inline (Write_Invocation_Graph);
81 -- Write out the invocation graph
83 procedure Write_Invocation_Graph_Attributes;
84 pragma Inline (Write_Invocation_Graph_Attributes);
85 -- Write out the attributes of the invocation graph
87 procedure Write_Invocation_Relation (IR_Id : Invocation_Relation_Id);
88 pragma Inline (Write_Invocation_Relation);
89 -- Write invocation relation IR_Id to the ALI file
91 procedure Write_Invocation_Signature (IS_Id : Invocation_Signature_Id);
92 pragma Inline (Write_Invocation_Signature);
93 -- Write invocation signature IS_Id to the ALI file
95 procedure Write_Unit_Name (N : Node_Id);
96 -- Used to write out the unit name for R (pragma Restriction) lines
97 -- for uses of Restriction (No_Dependence => unit-name).
99 ----------------------------------
100 -- Add_Preprocessing_Dependency --
101 ----------------------------------
103 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
104 begin
105 Units.Increment_Last;
106 Units.Table (Units.Last) :=
107 (Unit_File_Name => File_Name (S),
108 Unit_Name => No_Unit_Name,
109 Expected_Unit => No_Unit_Name,
110 Source_Index => S,
111 Cunit => Empty,
112 Cunit_Entity => Empty,
113 Dependency_Num => 0,
114 Dynamic_Elab => False,
115 Fatal_Error => None,
116 Generate_Code => False,
117 Has_RACW => False,
118 Filler => False,
119 Ident_String => Empty,
120 Is_Predefined_Renaming => False,
121 Is_Internal_Unit => False,
122 Is_Predefined_Unit => False,
123 Filler2 => False,
124 Loading => False,
125 Main_Priority => -1,
126 Main_CPU => -1,
127 Munit_Index => 0,
128 No_Elab_Code_All => False,
129 Primary_Stack_Count => 0,
130 Sec_Stack_Count => 0,
131 Serial_Number => 0,
132 Version => 0,
133 Error_Location => No_Location,
134 OA_Setting => 'O');
135 end Add_Preprocessing_Dependency;
137 ------------------------------
138 -- Ensure_System_Dependency --
139 ------------------------------
141 procedure Ensure_System_Dependency is
142 System_Uname : constant Unit_Name_Type :=
143 Name_To_Unit_Name (Name_System);
144 -- Unit name for system spec if needed for dummy entry
146 System_Fname : File_Name_Type;
147 -- File name for system spec if needed for dummy entry
149 begin
150 -- Nothing to do if we already compiled System
152 if Is_Loaded (System_Uname) then
153 return;
154 end if;
156 -- If no entry for system.ads in the units table, then add a entry
157 -- to the units table for system.ads, which will be referenced when
158 -- the ali file is generated. We need this because every unit depends
159 -- on system as a result of Targparm scanning the system.ads file to
160 -- determine the target dependent parameters for the compilation.
162 System_Fname := File_Name (System_Source_File_Index);
164 Units.Increment_Last;
165 Units.Table (Units.Last) :=
166 (Unit_File_Name => System_Fname,
167 Unit_Name => System_Uname,
168 Expected_Unit => System_Uname,
169 Source_Index => System_Source_File_Index,
170 Cunit => Empty,
171 Cunit_Entity => Empty,
172 Dependency_Num => 0,
173 Dynamic_Elab => False,
174 Fatal_Error => None,
175 Generate_Code => False,
176 Has_RACW => False,
177 Filler => False,
178 Ident_String => Empty,
179 Is_Predefined_Renaming => False,
180 Is_Internal_Unit => True,
181 Is_Predefined_Unit => True,
182 Filler2 => False,
183 Loading => False,
184 Main_Priority => -1,
185 Main_CPU => -1,
186 Munit_Index => 0,
187 No_Elab_Code_All => False,
188 Primary_Stack_Count => 0,
189 Sec_Stack_Count => 0,
190 Serial_Number => 0,
191 Version => 0,
192 Error_Location => No_Location,
193 OA_Setting => 'O');
194 Init_Unit_Name (Units.Last, System_Uname);
196 -- Parse system.ads so that the checksum is set right. Style checks are
197 -- not applied. The Ekind is set to ensure that this reference is always
198 -- present in the ali file.
200 declare
201 Save_Mindex : constant Nat := Multiple_Unit_Index;
202 Save_Style : constant Boolean := Style_Check;
203 begin
204 Multiple_Unit_Index := 0;
205 Style_Check := False;
206 Initialize_Scanner (Units.Last, System_Source_File_Index);
207 Discard_List (Par (Configuration_Pragmas => False));
208 Mutate_Ekind (Cunit_Entity (Units.Last), E_Package);
209 Set_Scope (Cunit_Entity (Units.Last), Standard_Standard);
210 Style_Check := Save_Style;
211 Multiple_Unit_Index := Save_Mindex;
212 end;
213 end Ensure_System_Dependency;
215 -------------
216 -- Present --
217 -------------
219 function Present (N_Id : Name_Id) return Boolean is
220 begin
221 return N_Id /= No_Name;
222 end Present;
224 ---------------
225 -- Write_ALI --
226 ---------------
228 procedure Write_ALI (Object : Boolean) is
230 ----------------
231 -- Local Data --
232 ----------------
234 Last_Unit : constant Unit_Number_Type := Units.Last;
235 -- Record unit number of last unit. We capture this in case we
236 -- have to add a dummy entry to the unit table for package System.
238 With_Flags : array (Units.First .. Last_Unit) of Boolean;
239 -- Array of flags to show which units are with'ed
241 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
242 -- Array of flags to show which units have pragma Elaborate set
244 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
245 -- Array of flags to show which units have pragma Elaborate All set
247 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
248 -- Array of flags to show which units have Elaborate_Desirable set
250 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
251 -- Array of flags to show which units have Elaborate_All_Desirable set
253 type Yes_No is (Unknown, Yes, No);
254 Has_Implicit_With : array (Units.First .. Last_Unit) of Yes_No;
255 -- Indicates if an implicit with has been given for the unit. Yes if
256 -- certainly present, No if certainly absent, Unknown if not known.
258 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
259 -- Sorted table of source dependencies. One extra entry in case we
260 -- have to add a dummy entry for System.
262 Num_Sdep : Nat := 0;
263 -- Number of active entries in Sdep_Table
265 -----------------------
266 -- Local Subprograms --
267 -----------------------
269 procedure Collect_Withs (Cunit : Node_Id);
270 -- Collect with lines for entries in the context clause of the given
271 -- compilation unit, Cunit.
273 procedure Output_CUDA_Symbols (Unit_Num : Unit_Number_Type);
274 -- Output CUDA symbols, so that the rest of the toolchain may know what
275 -- symbols need registering with the CUDA runtime.
277 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
278 -- Write out the library information for one unit for which code is
279 -- generated (includes unit line and with lines).
281 procedure Write_With_Lines;
282 -- Write out with lines collected by calls to Collect_Withs
284 -------------------
285 -- Collect_Withs --
286 -------------------
288 procedure Collect_Withs (Cunit : Node_Id) is
289 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean;
290 pragma Inline (Is_Implicit_With_Clause);
291 -- Determine whether a with clause denoted by Clause is implicit
293 -----------------------------
294 -- Is_Implicit_With_Clause --
295 -----------------------------
297 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean is
298 begin
299 -- With clauses created for ancestor units are marked as internal,
300 -- however, they emulate the semantics in Ada RM 10.1.2 (6/2),
301 -- 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 if Ekind (Uent) in E_Package | E_Package_Body
528 and then Present (Finalizer (Uent))
529 then
530 Write_Info_Str (" PF");
531 end if;
533 if Is_Preelaborated (Uent) then
534 Write_Info_Str (" PR");
535 end if;
537 if Is_Pure (Uent) then
538 Write_Info_Str (" PU");
539 end if;
541 if Has_RACW (Unit_Num) then
542 Write_Info_Str (" RA");
543 end if;
545 if Is_Remote_Call_Interface (Uent) then
546 Write_Info_Str (" RC");
547 end if;
549 if Is_Remote_Types (Uent) then
550 Write_Info_Str (" RT");
551 end if;
553 if Serious_Errors_Detected /= 0 then
554 Write_Info_Str (" SE");
555 end if;
557 if Is_Shared_Passive (Uent) then
558 Write_Info_Str (" SP");
559 end if;
561 if Ukind = N_Subprogram_Declaration
562 or else Ukind = N_Subprogram_Body
563 then
564 Write_Info_Str (" SU");
566 elsif Ukind = N_Package_Declaration
567 or else
568 Ukind = N_Package_Body
569 then
570 -- If this is a wrapper package for a subprogram instantiation,
571 -- the user view is the subprogram. Note that in this case the
572 -- ali file contains both the spec and body of the instance.
574 if Is_Wrapper_Package (Uent) then
575 Write_Info_Str (" SU");
576 else
577 Write_Info_Str (" PK");
578 end if;
580 elsif Ukind = N_Generic_Package_Declaration then
581 Write_Info_Str (" PK");
583 end if;
585 if Ukind in N_Generic_Declaration
586 or else
587 (Present (Library_Unit (Unode))
588 and then
589 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
590 then
591 Write_Info_Str (" GE");
592 end if;
594 if not Is_Internal_Unit (Unit_Num) then
595 case Identifier_Casing (Source_Index (Unit_Num)) is
596 when All_Lower_Case => Write_Info_Str (" IL");
597 when All_Upper_Case => Write_Info_Str (" IU");
598 when others => null;
599 end case;
601 case Keyword_Casing (Source_Index (Unit_Num)) is
602 when Mixed_Case => Write_Info_Str (" KM");
603 when All_Upper_Case => Write_Info_Str (" KU");
604 when others => null;
605 end case;
606 end if;
608 if Initialize_Scalars or else Invalid_Value_Used then
609 Write_Info_Str (" IS");
610 end if;
612 Write_Info_EOL;
614 -- Generate with lines, first those that are directly with'ed
616 for J in With_Flags'Range loop
617 With_Flags (J) := False;
618 Elab_Flags (J) := False;
619 Elab_All_Flags (J) := False;
620 Elab_Des_Flags (J) := False;
621 Elab_All_Des_Flags (J) := False;
622 Has_Implicit_With (J) := Unknown;
623 end loop;
625 Collect_Withs (Unode);
627 -- For a body, we must also check for any subunits which belong to
628 -- it and which have context clauses of their own, since these
629 -- with'ed units are part of its own elaboration dependencies.
631 if Nkind (Unit (Unode)) in N_Unit_Body then
632 for S in Units.First .. Last_Unit loop
634 -- We are only interested in subunits. For preproc. data and
635 -- def. files, Cunit is Empty, so we need to test that first.
637 if Cunit (S) /= Empty
638 and then Nkind (Unit (Cunit (S))) = N_Subunit
639 then
640 Pnode := Library_Unit (Cunit (S));
642 -- In gnatc mode, the errors in the subunits will not have
643 -- been recorded, but the analysis of the subunit may have
644 -- failed. There is no information to add to ALI file in
645 -- this case.
647 if No (Pnode) then
648 exit;
649 end if;
651 -- Find ultimate parent of the subunit
653 while Nkind (Unit (Pnode)) = N_Subunit loop
654 Pnode := Library_Unit (Pnode);
655 end loop;
657 -- See if it belongs to current unit, and if so, include
658 -- its with_clauses.
660 if Pnode = Unode then
661 Collect_Withs (Cunit (S));
662 end if;
663 end if;
664 end loop;
665 end if;
667 Write_With_Lines;
669 -- Generate task stack lines
671 if Primary_Stack_Count (Unit_Num) > 0
672 or else Sec_Stack_Count (Unit_Num) > 0
673 then
674 Write_Info_Initiate ('T');
675 Write_Info_Char (' ');
676 Write_Info_Int (Primary_Stack_Count (Unit_Num));
677 Write_Info_Char (' ');
678 Write_Info_Int (Sec_Stack_Count (Unit_Num));
679 Write_Info_EOL;
680 end if;
682 -- Generate the linker option lines
684 for J in 1 .. Linker_Option_Lines.Last loop
686 -- Pragma Linker_Options is not allowed in predefined generic
687 -- units. This is because they won't be read, due to the fact that
688 -- with lines for generic units lack the file name and lib name
689 -- parameters (see Lib_Writ spec for an explanation).
691 if Is_Generic_Unit (Cunit_Entity (Main_Unit))
692 and then Is_Predefined_Unit (Current_Sem_Unit)
693 and then Linker_Option_Lines.Table (J).Unit = Unit_Num
694 then
695 Set_Standard_Error;
696 Write_Line
697 ("linker options not allowed in predefined generic unit");
698 raise Unrecoverable_Error;
699 end if;
701 -- Output one linker option line
703 declare
704 S : Linker_Option_Entry renames Linker_Option_Lines.Table (J);
705 begin
706 if S.Unit = Unit_Num then
707 Write_Info_Initiate ('L');
708 Write_Info_Char (' ');
709 Write_Info_Slit (S.Option);
710 Write_Info_EOL;
711 end if;
712 end;
713 end loop;
715 -- Output notes
717 for J in 1 .. Notes.Last loop
718 declare
719 N : constant Node_Id := Notes.Table (J);
720 L : constant Source_Ptr := Sloc (N);
721 U : constant Unit_Number_Type :=
722 Unit (Get_Source_File_Index (L));
723 C : Character;
725 Note_Unit : Unit_Number_Type;
726 -- The unit in whose U section this note must be emitted:
727 -- notes for subunits are emitted along with the main unit;
728 -- all other notes are emitted as part of the enclosing
729 -- compilation unit.
731 begin
732 if U /= No_Unit and then Nkind (Unit (Cunit (U))) = N_Subunit
733 then
734 Note_Unit := Main_Unit;
735 else
736 Note_Unit := U;
737 end if;
739 -- No action needed for pragmas removed by the expander (for
740 -- example, pragmas of ignored ghost entities).
742 if Nkind (N) = N_Null_Statement then
743 pragma Assert (Nkind (Original_Node (N)) = N_Pragma);
744 null;
746 elsif Note_Unit = Unit_Num then
747 Write_Info_Initiate ('N');
748 Write_Info_Char (' ');
750 case Pragma_Name (N) is
751 when Name_Annotate | Name_GNAT_Annotate =>
752 C := 'A';
753 when Name_Comment =>
754 C := 'C';
755 when Name_Ident =>
756 C := 'I';
757 when Name_Title =>
758 C := 'T';
759 when Name_Subtitle =>
760 C := 'S';
761 when others =>
762 raise Program_Error;
763 end case;
765 Write_Info_Char (C);
766 Write_Info_Int (Int (Get_Logical_Line_Number (L)));
767 Write_Info_Char (':');
768 Write_Info_Int (Int (Get_Column_Number (L)));
770 -- Indicate source file of annotation if different from
771 -- compilation unit source file (case of annotation coming
772 -- from a separate).
774 if Get_Source_File_Index (L) /= Source_Index (Unit_Num) then
775 Write_Info_Char (':');
776 Write_Info_Name (File_Name (Get_Source_File_Index (L)));
777 end if;
779 declare
780 A : Node_Id;
782 begin
783 A := First (Pragma_Argument_Associations (N));
784 while Present (A) loop
785 Write_Info_Char (' ');
787 if Chars (A) /= No_Name then
788 Write_Info_Name (Chars (A));
789 Write_Info_Char (':');
790 end if;
792 declare
793 Expr : constant Node_Id := Expression (A);
795 begin
796 if Nkind (Expr) = N_Identifier then
797 Write_Info_Name (Chars (Expr));
799 elsif Nkind (Expr) = N_Integer_Literal
800 and then Is_OK_Static_Expression (Expr)
801 then
802 Write_Info_Uint (Intval (Expr));
804 elsif Nkind (Expr) = N_String_Literal
805 and then Is_OK_Static_Expression (Expr)
806 then
807 Write_Info_Slit (Strval (Expr));
809 else
810 Write_Info_Str ("<expr>");
811 end if;
812 end;
814 Next (A);
815 end loop;
816 end;
818 Write_Info_EOL;
819 end if;
820 end;
821 end loop;
822 end Write_Unit_Information;
824 ----------------------
825 -- Write_With_Lines --
826 ----------------------
828 procedure Write_With_Lines is
829 Pname : constant Unit_Name_Type :=
830 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
831 Body_Fname : File_Name_Type;
832 Body_Index : Nat;
833 Cunit : Node_Id;
834 Fname : File_Name_Type;
835 Num_Withs : Int := 0;
836 Unum : Unit_Number_Type;
837 Uname : Unit_Name_Type;
838 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
840 procedure Write_With_File_Names
841 (Nam : in out File_Name_Type;
842 Idx : Nat);
843 -- Write source file name Nam and ALI file name for unit index Idx.
844 -- Possibly change Nam to lowercase (generating a new file name).
846 ---------------------------
847 -- Write_With_File_Names --
848 ---------------------------
850 procedure Write_With_File_Names
851 (Nam : in out File_Name_Type;
852 Idx : Nat)
854 begin
855 if not File_Names_Case_Sensitive then
856 Get_Name_String (Nam);
857 To_Lower (Name_Buffer (1 .. Name_Len));
858 Nam := Name_Find;
859 end if;
861 Write_Info_Name (Nam);
862 Write_Info_Tab (49);
863 Write_Info_Name (Lib_File_Name (Nam, Idx));
864 end Write_With_File_Names;
866 -- Start of processing for Write_With_Lines
868 begin
869 -- Loop to build the with table. A with on the main unit itself
870 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
871 -- the main unit is a subprogram with no spec, and a subunit of
872 -- it unnecessarily withs the parent.
874 for J in Units.First + 1 .. Last_Unit loop
876 -- Add element to with table if it is with'ed or if it is the
877 -- parent spec of the main unit (case of main unit is a child
878 -- unit). The latter with is not needed for semantic purposes,
879 -- but is required by the binder for elaboration purposes. For
880 -- preprocessing data and definition files, there is no Unit_Name,
881 -- check for that first.
883 if Present (Unit_Name (J))
884 and then (With_Flags (J) or else Unit_Name (J) = Pname)
885 then
886 Num_Withs := Num_Withs + 1;
887 With_Table (Num_Withs) := J;
888 end if;
889 end loop;
891 -- Sort and output the table
893 Sort (With_Table (1 .. Num_Withs));
895 for J in 1 .. Num_Withs loop
896 Unum := With_Table (J);
898 -- Do not generate a with line for an ignored Ghost unit because
899 -- the unit does not have an ALI file.
901 if Is_Ignored_Ghost_Entity (Cunit_Entity (Unum)) then
902 goto Next_With_Line;
903 end if;
905 Cunit := Units.Table (Unum).Cunit;
906 Uname := Units.Table (Unum).Unit_Name;
907 Fname := Units.Table (Unum).Unit_File_Name;
909 -- Limited with clauses must be processed first because they are
910 -- the most specific among the three kinds.
912 if Ekind (Cunit_Entity (Unum)) = E_Package
913 and then From_Limited_With (Cunit_Entity (Unum))
914 then
915 Write_Info_Initiate ('Y');
917 elsif Has_Implicit_With (Unum) = Yes then
918 Write_Info_Initiate ('Z');
920 else
921 Write_Info_Initiate ('W');
922 end if;
924 Write_Info_Char (' ');
925 Write_Info_Name (Uname);
927 -- Now we need to figure out the names of the files that contain
928 -- the with'ed unit. These will usually be the files for the body,
929 -- except in the case of a package that has no body. Note that we
930 -- have a specific exemption here for predefined library generics
931 -- (see comments for Generic_May_Lack_ALI). We do not generate
932 -- dependency upon the ALI file for such units. Older compilers
933 -- used to not support generating code (and ALI) for generics, and
934 -- we want to avoid having different processing (namely, different
935 -- lists of files to be compiled) for different stages of the
936 -- bootstrap.
938 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
939 or else
940 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
941 and then Generic_May_Lack_ALI (Unum))
943 -- In SPARK mode, always generate the dependencies on ALI
944 -- files, which are required to compute frame conditions
945 -- of subprograms.
947 or else GNATprove_Mode
948 then
949 Write_Info_Tab (25);
951 if Is_Spec_Name (Uname) then
952 Body_Fname :=
953 Get_File_Name
954 (Uname => Get_Body_Name (Uname),
955 Subunit => False,
956 May_Fail => True);
958 Body_Index := Get_Unit_Index (Get_Body_Name (Uname));
960 if Body_Fname = No_File then
961 Body_Fname := Get_File_Name (Uname, Subunit => False);
962 Body_Index := Get_Unit_Index (Uname);
963 end if;
964 else
965 Body_Fname := Get_File_Name (Uname, Subunit => False);
966 Body_Index := Get_Unit_Index (Uname);
967 end if;
969 -- A package is considered to have a body if it requires
970 -- a body or if a body is present in Ada 83 mode.
972 if Body_Required (Cunit)
973 or else (Ada_Version = Ada_83
974 and then Full_Source_Name (Body_Fname) /= No_File)
975 then
976 Write_With_File_Names (Body_Fname, Body_Index);
977 else
978 Write_With_File_Names (Fname, Munit_Index (Unum));
979 end if;
981 if Ekind (Cunit_Entity (Unum)) = E_Package
982 and then From_Limited_With (Cunit_Entity (Unum))
983 then
984 null;
985 else
986 if Elab_Flags (Unum) then
987 Write_Info_Str (" E");
988 end if;
990 if Elab_All_Flags (Unum) then
991 Write_Info_Str (" EA");
992 end if;
994 if Elab_Des_Flags (Unum) then
995 Write_Info_Str (" ED");
996 end if;
998 if Elab_All_Des_Flags (Unum) then
999 Write_Info_Str (" AD");
1000 end if;
1001 end if;
1002 end if;
1004 Write_Info_EOL;
1006 <<Next_With_Line>>
1007 null;
1008 end loop;
1010 -- Finally generate the special lines for cases of Restriction_Set
1011 -- with No_Dependence and no restriction present.
1013 declare
1014 Unam : Unit_Name_Type;
1016 begin
1017 for J in Restriction_Set_Dependences.First ..
1018 Restriction_Set_Dependences.Last
1019 loop
1020 Unam := Restriction_Set_Dependences.Table (J);
1022 -- Don't need an entry if already in the unit table
1024 for U in 0 .. Last_Unit loop
1025 if Unit_Name (U) = Unam then
1026 goto Next_Restriction_Set;
1027 end if;
1028 end loop;
1030 -- Otherwise generate the entry
1032 Write_Info_Initiate ('W');
1033 Write_Info_Char (' ');
1034 Write_Info_Name (Unam);
1035 Write_Info_EOL;
1037 <<Next_Restriction_Set>>
1038 null;
1039 end loop;
1040 end;
1041 end Write_With_Lines;
1043 -- Start of processing for Write_ALI
1045 begin
1046 -- We never write an ALI file if the original operating mode was
1047 -- syntax-only (-gnats switch used in compiler invocation line).
1049 if Original_Operating_Mode = Check_Syntax then
1050 return;
1051 end if;
1053 -- Generation of ALI files may be disabled, e.g. for formal verification
1054 -- back-end.
1056 if Disable_ALI_File then
1057 return;
1058 end if;
1060 -- Build sorted source dependency table
1062 for Unum in Units.First .. Last_Unit loop
1063 if Cunit_Entity (Unum) = Empty
1064 or else not From_Limited_With (Cunit_Entity (Unum))
1065 then
1066 -- Units that are not analyzed need not appear in the dependency
1067 -- list. These units are either units appearing in limited_with
1068 -- clauses of other units, or units loaded for inlining that end
1069 -- up not inlined by a later decision of the inlining code, to
1070 -- prevent circularities. We want to exclude these files from the
1071 -- list of dependencies, so that the dependency number of other
1072 -- is correctly set, as that number is used by cross-reference
1073 -- tools to relate entity information to the unit in which they
1074 -- are declared.
1076 if Present (Cunit_Entity (Unum))
1077 and then Ekind (Cunit_Entity (Unum)) = E_Void
1078 and then Nkind (Unit (Cunit (Unum))) /= N_Subunit
1079 and then Serious_Errors_Detected = 0
1080 then
1081 null;
1083 else
1084 Num_Sdep := Num_Sdep + 1;
1085 Sdep_Table (Num_Sdep) := Unum;
1086 end if;
1087 end if;
1088 end loop;
1090 -- Sort the table so that the D lines are in order
1092 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
1094 -- Acquire compilation arguments and prepare to write out a new ali
1095 -- file.
1097 Create_Output_Library_Info;
1099 -- Output version line
1101 Write_Info_Initiate ('V');
1102 Write_Info_Str (" """);
1103 Write_Info_Str (Verbose_Library_Version);
1104 Write_Info_Char ('"');
1106 Write_Info_EOL;
1108 -- Output main program line if this is acceptable main program
1110 Output_Main_Program_Line : declare
1111 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
1112 S : Node_Id;
1114 procedure M_Parameters;
1115 -- Output parameters for main program line
1117 ------------------
1118 -- M_Parameters --
1119 ------------------
1121 procedure M_Parameters is
1122 begin
1123 if Main_Priority (Main_Unit) /= Default_Main_Priority then
1124 Write_Info_Char (' ');
1125 Write_Info_Nat (Main_Priority (Main_Unit));
1126 end if;
1128 if Opt.Time_Slice_Set then
1129 Write_Info_Str (" T=");
1130 Write_Info_Nat (Opt.Time_Slice_Value);
1131 end if;
1133 if Main_CPU (Main_Unit) /= Default_Main_CPU then
1134 Write_Info_Str (" C=");
1135 Write_Info_Nat (Main_CPU (Main_Unit));
1136 end if;
1138 Write_Info_Str (" W=");
1139 Write_Info_Char
1140 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
1142 Write_Info_EOL;
1143 end M_Parameters;
1145 -- Start of processing for Output_Main_Program_Line
1147 begin
1148 if Nkind (U) = N_Subprogram_Body
1149 or else
1150 (Nkind (U) = N_Package_Body
1151 and then
1152 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
1153 then
1154 -- If the unit is a subprogram instance, the entity for the
1155 -- subprogram is the alias of the visible entity, which is the
1156 -- related instance of the wrapper package. We retrieve the
1157 -- subprogram declaration of the desired entity.
1159 if Nkind (U) = N_Package_Body then
1160 U := Parent (Parent (
1161 Alias (Related_Instance (Defining_Unit_Name
1162 (Specification (Unit (Library_Unit (Parent (U)))))))));
1163 end if;
1165 S := Specification (U);
1167 -- A generic subprogram is never a main program
1169 if Nkind (U) = N_Subprogram_Body
1170 and then Present (Corresponding_Spec (U))
1171 and then Is_Generic_Subprogram (Corresponding_Spec (U))
1172 then
1173 null;
1175 elsif No (Parameter_Specifications (S)) then
1176 if Nkind (S) = N_Procedure_Specification then
1177 Write_Info_Initiate ('M');
1178 Write_Info_Str (" P");
1179 M_Parameters;
1181 else
1182 declare
1183 Nam : Node_Id := Defining_Unit_Name (S);
1185 begin
1186 -- If it is a child unit, get its simple name
1188 if Nkind (Nam) = N_Defining_Program_Unit_Name then
1189 Nam := Defining_Identifier (Nam);
1190 end if;
1192 if Is_Integer_Type (Etype (Nam)) then
1193 Write_Info_Initiate ('M');
1194 Write_Info_Str (" F");
1195 M_Parameters;
1196 end if;
1197 end;
1198 end if;
1199 end if;
1200 end if;
1201 end Output_Main_Program_Line;
1203 -- Write command argument ('A') lines
1205 for A in 1 .. Compilation_Switches.Last loop
1206 Write_Info_Initiate ('A');
1207 Write_Info_Char (' ');
1208 Write_Info_Str (Compilation_Switches.Table (A).all);
1209 Write_Info_Terminate;
1210 end loop;
1212 -- Output CUDA Kernel lines
1214 for Unit in Units.First .. Last_Unit loop
1215 if Present (Cunit (Unit)) then
1216 Output_CUDA_Symbols (Unit);
1217 end if;
1218 end loop;
1220 -- Output parameters ('P') line
1222 Write_Info_Initiate ('P');
1224 if Compilation_Errors then
1225 Write_Info_Str (" CE");
1226 end if;
1228 if Opt.Detect_Blocking then
1229 Write_Info_Str (" DB");
1230 end if;
1232 if Tasking_Used and then not Is_Predefined_Unit (Main_Unit) then
1233 if Locking_Policy /= ' ' then
1234 Write_Info_Str (" L");
1235 Write_Info_Char (Locking_Policy);
1236 end if;
1238 if Queuing_Policy /= ' ' then
1239 Write_Info_Str (" Q");
1240 Write_Info_Char (Queuing_Policy);
1241 end if;
1243 if Task_Dispatching_Policy /= ' ' then
1244 Write_Info_Str (" T");
1245 Write_Info_Char (Task_Dispatching_Policy);
1246 Write_Info_Char (' ');
1247 end if;
1248 end if;
1250 if GNATprove_Mode then
1251 Write_Info_Str (" GP");
1252 end if;
1254 if Partition_Elaboration_Policy /= ' ' then
1255 Write_Info_Str (" E");
1256 Write_Info_Char (Partition_Elaboration_Policy);
1257 end if;
1259 if No_Component_Reordering_Config then
1260 Write_Info_Str (" NC");
1261 end if;
1263 if not Object then
1264 Write_Info_Str (" NO");
1265 end if;
1267 if No_Run_Time_Mode then
1268 Write_Info_Str (" NR");
1269 end if;
1271 if Normalize_Scalars then
1272 Write_Info_Str (" NS");
1273 end if;
1275 if Default_SSO_Config /= ' ' then
1276 Write_Info_Str (" O");
1277 Write_Info_Char (Default_SSO_Config);
1278 end if;
1280 if Sec_Stack_Used then
1281 Write_Info_Str (" SS");
1282 end if;
1284 if Unreserve_All_Interrupts then
1285 Write_Info_Str (" UA");
1286 end if;
1288 if ZCX_Exceptions then
1289 Write_Info_Str (" ZX");
1290 end if;
1292 Write_Info_EOL;
1294 -- Before outputting the restrictions line, update the setting of
1295 -- the No_Elaboration_Code flag. Violations of this restriction
1296 -- cannot be detected until after the backend has been called since
1297 -- it is the backend that sets this flag. We have to check all units
1298 -- for which we have generated code
1300 for Unit in Units.First .. Last_Unit loop
1301 if Units.Table (Unit).Generate_Code then
1302 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1303 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1304 exit;
1305 end if;
1306 end if;
1307 end loop;
1309 -- Positional case (only if debug flag -gnatd.R is set)
1311 if Debug_Flag_Dot_RR then
1313 -- Output first restrictions line
1315 Write_Info_Initiate ('R');
1316 Write_Info_Char (' ');
1318 -- First the information for the boolean restrictions
1320 for R in All_Boolean_Restrictions loop
1321 if Main_Restrictions.Set (R)
1322 and then not Restriction_Warnings (R)
1323 then
1324 Write_Info_Char ('r');
1325 elsif Main_Restrictions.Violated (R) then
1326 Write_Info_Char ('v');
1327 else
1328 Write_Info_Char ('n');
1329 end if;
1330 end loop;
1332 -- And now the information for the parameter restrictions
1334 for RP in All_Parameter_Restrictions loop
1335 if Main_Restrictions.Set (RP)
1336 and then not Restriction_Warnings (RP)
1337 then
1338 Write_Info_Char ('r');
1339 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1340 else
1341 Write_Info_Char ('n');
1342 end if;
1344 if not Main_Restrictions.Violated (RP)
1345 or else RP not in Checked_Parameter_Restrictions
1346 then
1347 Write_Info_Char ('n');
1348 else
1349 Write_Info_Char ('v');
1350 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1352 if Main_Restrictions.Unknown (RP) then
1353 Write_Info_Char ('+');
1354 end if;
1355 end if;
1356 end loop;
1358 Write_Info_EOL;
1360 -- Named case (if debug flag -gnatd.R is not set)
1362 else
1363 declare
1364 C : Character;
1366 begin
1367 -- Write RN header line with preceding blank line
1369 Write_Info_EOL;
1370 Write_Info_Initiate ('R');
1371 Write_Info_Char ('N');
1372 Write_Info_EOL;
1374 -- First the lines for the boolean restrictions
1376 for R in All_Boolean_Restrictions loop
1377 if Main_Restrictions.Set (R)
1378 and then not Restriction_Warnings (R)
1379 then
1380 C := 'R';
1381 elsif Main_Restrictions.Violated (R) then
1382 C := 'V';
1383 else
1384 goto Continue;
1385 end if;
1387 Write_Info_Initiate ('R');
1388 Write_Info_Char (C);
1389 Write_Info_Char (' ');
1390 Write_Info_Str (All_Boolean_Restrictions'Image (R));
1391 Write_Info_EOL;
1393 <<Continue>>
1394 null;
1395 end loop;
1396 end;
1398 -- And now the lines for the parameter restrictions
1400 for RP in All_Parameter_Restrictions loop
1401 if Main_Restrictions.Set (RP)
1402 and then not Restriction_Warnings (RP)
1403 then
1404 Write_Info_Initiate ('R');
1405 Write_Info_Str ("R ");
1406 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1407 Write_Info_Char ('=');
1408 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1409 Write_Info_EOL;
1410 end if;
1412 if not Main_Restrictions.Violated (RP)
1413 or else RP not in Checked_Parameter_Restrictions
1414 then
1415 null;
1416 else
1417 Write_Info_Initiate ('R');
1418 Write_Info_Str ("V ");
1419 Write_Info_Str (All_Parameter_Restrictions'Image (RP));
1420 Write_Info_Char ('=');
1421 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1423 if Main_Restrictions.Unknown (RP) then
1424 Write_Info_Char ('+');
1425 end if;
1427 Write_Info_EOL;
1428 end if;
1429 end loop;
1430 end if;
1432 -- Output R lines for No_Dependence entries
1434 for J in No_Dependences.First .. No_Dependences.Last loop
1435 if In_Extended_Main_Source_Unit (No_Dependences.Table (J).Unit)
1436 and then not No_Dependences.Table (J).Warn
1437 then
1438 Write_Info_Initiate ('R');
1439 Write_Info_Char (' ');
1440 Write_Unit_Name (No_Dependences.Table (J).Unit);
1441 Write_Info_EOL;
1442 end if;
1443 end loop;
1445 -- Output interrupt state lines
1447 for J in Interrupt_States.First .. Interrupt_States.Last loop
1448 Write_Info_Initiate ('I');
1449 Write_Info_Char (' ');
1450 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1451 Write_Info_Char (' ');
1452 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1453 Write_Info_Char (' ');
1454 Write_Info_Nat
1455 (Nat (Get_Logical_Line_Number
1456 (Interrupt_States.Table (J).Pragma_Loc)));
1457 Write_Info_EOL;
1458 end loop;
1460 -- Output priority specific dispatching lines
1462 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1463 Write_Info_Initiate ('S');
1464 Write_Info_Char (' ');
1465 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1466 Write_Info_Char (' ');
1467 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1468 Write_Info_Char (' ');
1469 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1470 Write_Info_Char (' ');
1471 Write_Info_Nat
1472 (Nat (Get_Logical_Line_Number
1473 (Specific_Dispatching.Table (J).Pragma_Loc)));
1474 Write_Info_EOL;
1475 end loop;
1477 -- Loop through file table to output information for all units for which
1478 -- we have generated code, as marked by the Generate_Code flag.
1480 for Unit in Units.First .. Last_Unit loop
1481 if Units.Table (Unit).Generate_Code
1482 or else Unit = Main_Unit
1483 then
1484 Write_Info_EOL; -- blank line
1485 Write_Unit_Information (Unit);
1486 end if;
1487 end loop;
1489 Write_Info_EOL; -- blank line
1491 -- Output external version reference lines
1493 for J in 1 .. Version_Ref.Last loop
1494 Write_Info_Initiate ('E');
1495 Write_Info_Char (' ');
1497 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1498 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1499 end loop;
1501 Write_Info_EOL;
1502 end loop;
1504 -- Prepare to output the source dependency lines
1506 declare
1507 Unum : Unit_Number_Type;
1508 -- Number of unit being output
1510 Sind : Source_File_Index;
1511 -- Index of corresponding source file
1513 Fname : File_Name_Type;
1515 begin
1516 for J in 1 .. Num_Sdep loop
1517 Unum := Sdep_Table (J);
1518 Units.Table (Unum).Dependency_Num := J;
1519 Sind := Source_Index (Unum);
1521 Write_Info_Initiate ('D');
1522 Write_Info_Char (' ');
1524 -- Normal case of a unit entry with a source index
1526 if Sind > No_Source_File then
1528 if Config_Files_Store_Basename then
1529 Fname := Strip_Directory (File_Name (Sind));
1530 else
1531 Fname := File_Name (Sind);
1532 end if;
1534 -- Ensure that on platforms where the file names are not
1535 -- case sensitive, the recorded file name is in lower case.
1537 if not File_Names_Case_Sensitive then
1538 Get_Name_String (Fname);
1539 To_Lower (Name_Buffer (1 .. Name_Len));
1540 Fname := Name_Find;
1541 end if;
1543 Write_Info_Name_May_Be_Quoted (Fname);
1544 Write_Info_Tab (25);
1545 Write_Info_Str (String (Time_Stamp (Sind)));
1546 Write_Info_Char (' ');
1547 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1549 -- If the dependency comes from a limited_with clause, record
1550 -- limited_checksum. This is disabled until full checksum
1551 -- changes are checked.
1553 -- if Present (Cunit_Entity (Unum))
1554 -- and then From_Limited_With (Cunit_Entity (Unum))
1555 -- then
1556 -- Write_Info_Char (' ');
1557 -- Write_Info_Char ('Y');
1558 -- Write_Info_Str (Get_Hex_String (Limited_Chk_Sum (Sind)));
1559 -- end if;
1561 -- If subunit, add unit name, omitting the %b at the end
1563 if Present (Cunit (Unum)) then
1564 Get_Decoded_Name_String (Unit_Name (Unum));
1565 Write_Info_Char (' ');
1567 if Nkind (Unit (Cunit (Unum))) = N_Subunit then
1568 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1569 else
1570 Write_Info_Str (Name_Buffer (1 .. Name_Len));
1571 end if;
1572 end if;
1574 -- If Source_Reference pragma used, output information
1576 if Num_SRef_Pragmas (Sind) > 0 then
1577 Write_Info_Char (' ');
1579 if Num_SRef_Pragmas (Sind) = 1 then
1580 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1581 else
1582 Write_Info_Nat (0);
1583 end if;
1585 Write_Info_Char (':');
1586 Write_Info_Name (Reference_Name (Sind));
1587 end if;
1589 -- Case where there is no source index (happens for missing
1590 -- files). In this case we write a dummy time stamp.
1592 else
1593 Write_Info_Name (Unit_File_Name (Unum));
1594 Write_Info_Tab (25);
1595 Write_Info_Str (String (Dummy_Time_Stamp));
1596 Write_Info_Char (' ');
1597 Write_Info_Str (Get_Hex_String (0));
1598 end if;
1600 Write_Info_EOL;
1601 end loop;
1602 end;
1604 -- Output the invocation graph
1606 Write_Invocation_Graph;
1608 -- Output cross-references
1610 if Opt.Xref_Active then
1611 Output_References;
1612 end if;
1614 -- Output SCO information if present
1616 if Generate_SCO then
1617 SCO_Record_Filtered;
1618 SCO_Output;
1619 end if;
1621 -- Output final blank line and we are done. This final blank line is
1622 -- probably junk, but we don't feel like making an incompatible change.
1624 Write_Info_Terminate;
1625 Close_Output_Library_Info;
1626 end Write_ALI;
1628 --------------------------------
1629 -- Write_Invocation_Construct --
1630 --------------------------------
1632 procedure Write_Invocation_Construct (IC_Id : Invocation_Construct_Id) is
1633 begin
1634 -- G header
1636 Write_Info_Initiate ('G');
1637 Write_Info_Char (' ');
1639 -- line-kind
1641 Write_Info_Char
1642 (Invocation_Graph_Line_Kind_To_Code (Invocation_Construct_Line));
1643 Write_Info_Char (' ');
1645 -- construct-kind
1647 Write_Info_Char (Invocation_Construct_Kind_To_Code (Kind (IC_Id)));
1648 Write_Info_Char (' ');
1650 -- construct-spec-placement
1652 Write_Info_Char
1653 (Declaration_Placement_Kind_To_Code (Spec_Placement (IC_Id)));
1654 Write_Info_Char (' ');
1656 -- construct-body-placement
1658 Write_Info_Char
1659 (Declaration_Placement_Kind_To_Code (Body_Placement (IC_Id)));
1660 Write_Info_Char (' ');
1662 -- construct-signature
1664 Write_Invocation_Signature (Signature (IC_Id));
1665 Write_Info_EOL;
1666 end Write_Invocation_Construct;
1668 ---------------------------------------
1669 -- Write_Invocation_Graph_Attributes --
1670 ---------------------------------------
1672 procedure Write_Invocation_Graph_Attributes is
1673 begin
1674 -- G header
1676 Write_Info_Initiate ('G');
1677 Write_Info_Char (' ');
1679 -- line-kind
1681 Write_Info_Char
1682 (Invocation_Graph_Line_Kind_To_Code
1683 (Invocation_Graph_Attributes_Line));
1684 Write_Info_Char (' ');
1686 -- encoding-kind
1688 Write_Info_Char
1689 (Invocation_Graph_Encoding_Kind_To_Code (Invocation_Graph_Encoding));
1690 Write_Info_EOL;
1691 end Write_Invocation_Graph_Attributes;
1693 ----------------------------
1694 -- Write_Invocation_Graph --
1695 ----------------------------
1697 procedure Write_Invocation_Graph is
1698 begin
1699 Write_Invocation_Graph_Attributes;
1701 -- First write out all invocation constructs declared within the current
1702 -- unit. This ensures that when this invocation is read, the invocation
1703 -- constructs are materialized before they are referenced by invocation
1704 -- relations.
1706 For_Each_Invocation_Construct (Write_Invocation_Construct'Access);
1708 -- Write out all invocation relations that originate from invocation
1709 -- constructs delared in the current unit.
1711 For_Each_Invocation_Relation (Write_Invocation_Relation'Access);
1712 end Write_Invocation_Graph;
1714 -------------------------------
1715 -- Write_Invocation_Relation --
1716 -------------------------------
1718 procedure Write_Invocation_Relation (IR_Id : Invocation_Relation_Id) is
1719 begin
1720 -- G header
1722 Write_Info_Initiate ('G');
1723 Write_Info_Char (' ');
1725 -- line-kind
1727 Write_Info_Char
1728 (Invocation_Graph_Line_Kind_To_Code (Invocation_Relation_Line));
1729 Write_Info_Char (' ');
1731 -- relation-kind
1733 Write_Info_Char (Invocation_Kind_To_Code (Kind (IR_Id)));
1734 Write_Info_Char (' ');
1736 -- (extra-name | "none")
1738 if Present (Extra (IR_Id)) then
1739 Write_Info_Name (Extra (IR_Id));
1740 else
1741 Write_Info_Str ("none");
1742 end if;
1744 Write_Info_Char (' ');
1746 -- invoker-signature
1748 Write_Invocation_Signature (Invoker (IR_Id));
1749 Write_Info_Char (' ');
1751 -- target-signature
1753 Write_Invocation_Signature (Target (IR_Id));
1755 Write_Info_EOL;
1756 end Write_Invocation_Relation;
1758 --------------------------------
1759 -- Write_Invocation_Signature --
1760 --------------------------------
1762 procedure Write_Invocation_Signature (IS_Id : Invocation_Signature_Id) is
1763 begin
1764 -- [
1766 Write_Info_Char ('[');
1768 -- name
1770 Write_Info_Name (Name (IS_Id));
1771 Write_Info_Char (' ');
1773 -- scope
1775 Write_Info_Name (IS_Scope (IS_Id));
1776 Write_Info_Char (' ');
1778 -- line
1780 Write_Info_Nat (Line (IS_Id));
1781 Write_Info_Char (' ');
1783 -- column
1785 Write_Info_Nat (Column (IS_Id));
1786 Write_Info_Char (' ');
1788 -- (locations | "none")
1790 if Present (Locations (IS_Id)) then
1791 Write_Info_Name (Locations (IS_Id));
1792 else
1793 Write_Info_Str ("none");
1794 end if;
1796 -- ]
1798 Write_Info_Char (']');
1799 end Write_Invocation_Signature;
1801 ---------------------
1802 -- Write_Unit_Name --
1803 ---------------------
1805 procedure Write_Unit_Name (N : Node_Id) is
1806 begin
1807 if Nkind (N) = N_Identifier then
1808 Write_Info_Name (Chars (N));
1810 else
1811 pragma Assert (Nkind (N) = N_Selected_Component);
1812 Write_Unit_Name (Prefix (N));
1813 Write_Info_Char ('.');
1814 Write_Unit_Name (Selector_Name (N));
1815 end if;
1816 end Write_Unit_Name;
1818 end Lib.Writ;