cfgexpand: Update partition size when merging variables
[official-gcc.git] / gcc / ada / bindo-writers.adb
blob1fcfb11becb0dca502460864e34f3f160fa23221
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- B I N D O . W R I T E R S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2019, 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 Binderr; use Binderr;
27 with Butil; use Butil;
28 with Debug; use Debug;
29 with Fname; use Fname;
30 with Opt; use Opt;
31 with Output; use Output;
33 with Bindo.Units;
34 use Bindo.Units;
36 with GNAT; use GNAT;
37 with GNAT.Graphs; use GNAT.Graphs;
38 with GNAT.Sets; use GNAT.Sets;
40 package body Bindo.Writers is
42 -----------------
43 -- ALI_Writers --
44 -----------------
46 package body ALI_Writers is
48 -----------------------
49 -- Local subprograms --
50 -----------------------
52 procedure Write_All_Units;
53 pragma Inline (Write_All_Units);
54 -- Write the common form of units to standard output
56 procedure Write_Invocation_Construct (IC_Id : Invocation_Construct_Id);
57 pragma Inline (Write_Invocation_Construct);
58 -- Write invocation construct IC_Id to standard output
60 procedure Write_Invocation_Relation (IR_Id : Invocation_Relation_Id);
61 pragma Inline (Write_Invocation_Relation);
62 -- Write invocation relation IR_Id to standard output
64 procedure Write_Invocation_Signature (IS_Id : Invocation_Signature_Id);
65 pragma Inline (Write_Invocation_Signature);
66 -- Write invocation signature IS_Id to standard output
68 procedure Write_Statistics;
69 pragma Inline (Write_Statistics);
70 -- Write the statistical information of units to standard output
72 procedure Write_Unit (U_Id : Unit_Id);
73 pragma Inline (Write_Unit);
74 -- Write the invocation constructs and relations of unit U_Id to
75 -- standard output.
77 procedure Write_Unit_Common (U_Id : Unit_Id);
78 pragma Inline (Write_Unit_Common);
79 -- Write the common form of unit U_Id to standard output
81 -----------
82 -- Debug --
83 -----------
85 procedure pau renames Write_All_Units;
86 pragma Unreferenced (pau);
88 procedure pu (U_Id : Unit_Id) renames Write_Unit_Common;
89 pragma Unreferenced (pu);
91 ----------------------
92 -- Write_ALI_Tables --
93 ----------------------
95 procedure Write_ALI_Tables is
96 begin
97 -- Nothing to do when switch -d_A (output invocation tables) is not
98 -- in effect.
100 if not Debug_Flag_Underscore_AA then
101 return;
102 end if;
104 Write_Str ("ALI Tables");
105 Write_Eol;
106 Write_Eol;
108 Write_Statistics;
109 For_Each_Unit (Write_Unit'Access);
111 Write_Str ("ALI Tables end");
112 Write_Eol;
113 Write_Eol;
114 end Write_ALI_Tables;
116 ---------------------
117 -- Write_All_Units --
118 ---------------------
120 procedure Write_All_Units is
121 begin
122 For_Each_Unit (Write_Unit_Common'Access);
123 end Write_All_Units;
125 --------------------------------
126 -- Write_Invocation_Construct --
127 --------------------------------
129 procedure Write_Invocation_Construct (IC_Id : Invocation_Construct_Id) is
130 begin
131 pragma Assert (Present (IC_Id));
133 Write_Str (" invocation construct (IC_Id_");
134 Write_Int (Int (IC_Id));
135 Write_Str (")");
136 Write_Eol;
138 Write_Str (" Body_Placement = ");
139 Write_Str (Body_Placement (IC_Id)'Img);
140 Write_Eol;
142 Write_Str (" Kind = ");
143 Write_Str (Kind (IC_Id)'Img);
144 Write_Eol;
146 Write_Str (" Spec_Placement = ");
147 Write_Str (Spec_Placement (IC_Id)'Img);
148 Write_Eol;
150 Write_Invocation_Signature (Signature (IC_Id));
151 Write_Eol;
152 end Write_Invocation_Construct;
154 -------------------------------
155 -- Write_Invocation_Relation --
156 -------------------------------
158 procedure Write_Invocation_Relation (IR_Id : Invocation_Relation_Id) is
159 begin
160 pragma Assert (Present (IR_Id));
162 Write_Str (" invocation relation (IR_Id_");
163 Write_Int (Int (IR_Id));
164 Write_Str (")");
165 Write_Eol;
167 if Present (Extra (IR_Id)) then
168 Write_Str (" Extra = ");
169 Write_Name (Extra (IR_Id));
170 else
171 Write_Str (" Extra = none");
172 end if;
174 Write_Eol;
175 Write_Str (" Invoker");
176 Write_Eol;
178 Write_Invocation_Signature (Invoker (IR_Id));
180 Write_Str (" Kind = ");
181 Write_Str (Kind (IR_Id)'Img);
182 Write_Eol;
184 Write_Str (" Target");
185 Write_Eol;
187 Write_Invocation_Signature (Target (IR_Id));
188 Write_Eol;
189 end Write_Invocation_Relation;
191 --------------------------------
192 -- Write_Invocation_Signature --
193 --------------------------------
195 procedure Write_Invocation_Signature (IS_Id : Invocation_Signature_Id) is
196 begin
197 pragma Assert (Present (IS_Id));
199 Write_Str (" Signature (IS_Id_");
200 Write_Int (Int (IS_Id));
201 Write_Str (")");
202 Write_Eol;
204 Write_Str (" Column = ");
205 Write_Int (Int (Column (IS_Id)));
206 Write_Eol;
208 Write_Str (" Line = ");
209 Write_Int (Int (Line (IS_Id)));
210 Write_Eol;
212 if Present (Locations (IS_Id)) then
213 Write_Str (" Locations = ");
214 Write_Name (Locations (IS_Id));
215 else
216 Write_Str (" Locations = none");
217 end if;
219 Write_Eol;
220 Write_Str (" Name = ");
221 Write_Name (Name (IS_Id));
222 Write_Eol;
224 Write_Str (" Scope = ");
225 Write_Name (Scope (IS_Id));
226 Write_Eol;
227 end Write_Invocation_Signature;
229 ----------------------
230 -- Write_Statistics --
231 ----------------------
233 procedure Write_Statistics is
234 begin
235 Write_Str ("Units : ");
236 Write_Num (Int (Number_Of_Units));
237 Write_Eol;
239 Write_Str ("Units to elaborate: ");
240 Write_Num (Int (Number_Of_Elaborable_Units));
241 Write_Eol;
242 Write_Eol;
243 end Write_Statistics;
245 ----------------
246 -- Write_Unit --
247 ----------------
249 procedure Write_Unit (U_Id : Unit_Id) is
250 pragma Assert (Present (U_Id));
252 U_Rec : Unit_Record renames ALI.Units.Table (U_Id);
254 begin
255 Write_Unit_Common (U_Id);
257 Write_Str (" First_Invocation_Construct (IC_Id_");
258 Write_Int (Int (U_Rec.First_Invocation_Construct));
259 Write_Str (")");
260 Write_Eol;
262 Write_Str (" Last_Invocation_Construct (IC_Id_");
263 Write_Int (Int (U_Rec.Last_Invocation_Construct));
264 Write_Str (")");
265 Write_Eol;
267 Write_Str (" First_Invocation_Relation (IR_Id_");
268 Write_Int (Int (U_Rec.First_Invocation_Relation));
269 Write_Str (")");
270 Write_Eol;
272 Write_Str (" Last_Invocation_Relation (IR_Id_");
273 Write_Int (Int (U_Rec.Last_Invocation_Relation));
274 Write_Str (")");
275 Write_Eol;
277 Write_Str (" Invocation_Graph_Encoding = ");
278 Write_Str (Invocation_Graph_Encoding (U_Id)'Img);
279 Write_Eol;
280 Write_Eol;
282 For_Each_Invocation_Construct
283 (U_Id => U_Id,
284 Processor => Write_Invocation_Construct'Access);
286 For_Each_Invocation_Relation
287 (U_Id => U_Id,
288 Processor => Write_Invocation_Relation'Access);
289 end Write_Unit;
291 -----------------------
292 -- Write_Unit_Common --
293 -----------------------
295 procedure Write_Unit_Common (U_Id : Unit_Id) is
296 pragma Assert (Present (U_Id));
298 U_Rec : Unit_Record renames ALI.Units.Table (U_Id);
300 begin
301 Write_Str ("unit (U_Id_");
302 Write_Int (Int (U_Id));
303 Write_Str (") name = ");
304 Write_Name (U_Rec.Uname);
305 Write_Eol;
307 if U_Rec.SAL_Interface then
308 Write_Str (" SAL_Interface = True");
309 Write_Eol;
310 end if;
311 end Write_Unit_Common;
312 end ALI_Writers;
314 -------------------
315 -- Cycle_Writers --
316 -------------------
318 package body Cycle_Writers is
320 -----------------------
321 -- Local subprograms --
322 -----------------------
324 procedure Write_Cycle
325 (G : Library_Graph;
326 Cycle : Library_Graph_Cycle_Id);
327 pragma Inline (Write_Cycle);
328 -- Write the path of cycle Cycle found in library graph G to standard
329 -- output.
331 procedure Write_Cyclic_Edge
332 (G : Library_Graph;
333 Edge : Library_Graph_Edge_Id);
334 pragma Inline (Write_Cyclic_Edge);
335 -- Write cyclic edge Edge of library graph G to standard
337 -----------
338 -- Debug --
339 -----------
341 procedure palgc (G : Library_Graph) renames Write_Cycles;
342 pragma Unreferenced (palgc);
344 procedure plgc
345 (G : Library_Graph;
346 Cycle : Library_Graph_Cycle_Id) renames Write_Cycle;
347 pragma Unreferenced (plgc);
349 -----------------
350 -- Write_Cycle --
351 -----------------
353 procedure Write_Cycle
354 (G : Library_Graph;
355 Cycle : Library_Graph_Cycle_Id)
357 Edge : Library_Graph_Edge_Id;
358 Iter : Edges_Of_Cycle_Iterator;
360 begin
361 pragma Assert (Present (G));
362 pragma Assert (Present (Cycle));
364 -- Nothing to do when switch -d_P (output cycle paths) is not in
365 -- effect.
367 if not Debug_Flag_Underscore_PP then
368 return;
369 end if;
371 Write_Str ("cycle (LGC_Id_");
372 Write_Int (Int (Cycle));
373 Write_Str (")");
374 Write_Eol;
376 Iter := Iterate_Edges_Of_Cycle (G, Cycle);
377 while Has_Next (Iter) loop
378 Next (Iter, Edge);
380 Write_Cyclic_Edge (G, Edge);
381 end loop;
383 Write_Eol;
384 end Write_Cycle;
386 ------------------
387 -- Write_Cycles --
388 ------------------
390 procedure Write_Cycles (G : Library_Graph) is
391 Cycle : Library_Graph_Cycle_Id;
392 Iter : All_Cycle_Iterator;
394 begin
395 pragma Assert (Present (G));
397 Iter := Iterate_All_Cycles (G);
398 while Has_Next (Iter) loop
399 Next (Iter, Cycle);
401 Write_Cycle (G, Cycle);
402 end loop;
403 end Write_Cycles;
405 -----------------------
406 -- Write_Cyclic_Edge --
407 -----------------------
409 procedure Write_Cyclic_Edge
410 (G : Library_Graph;
411 Edge : Library_Graph_Edge_Id)
413 pragma Assert (Present (G));
414 pragma Assert (Present (Edge));
416 Pred : constant Library_Graph_Vertex_Id := Predecessor (G, Edge);
417 Succ : constant Library_Graph_Vertex_Id := Successor (G, Edge);
419 begin
420 Indent_By (Nested_Indentation);
421 Write_Name (Name (G, Succ));
422 Write_Str (" --> ");
423 Write_Name (Name (G, Pred));
424 Write_Str (" ");
426 if Is_Elaborate_All_Edge (G, Edge) then
427 Write_Str ("Elaborate_All edge");
429 elsif Is_Elaborate_Body_Edge (G, Edge) then
430 Write_Str ("Elaborate_Body edge");
432 elsif Is_Elaborate_Edge (G, Edge) then
433 Write_Str ("Elaborate edge");
435 elsif Is_Forced_Edge (G, Edge) then
436 Write_Str ("forced edge");
438 elsif Is_Invocation_Edge (G, Edge) then
439 Write_Str ("invocation edge");
441 else
442 pragma Assert (Is_With_Edge (G, Edge));
444 Write_Str ("with edge");
445 end if;
447 Write_Eol;
448 end Write_Cyclic_Edge;
449 end Cycle_Writers;
451 ------------------------
452 -- Dependency_Writers --
453 ------------------------
455 package body Dependency_Writers is
457 -----------------------
458 -- Local subprograms --
459 -----------------------
461 procedure Write_Dependencies_Of_Vertex
462 (G : Library_Graph;
463 Vertex : Library_Graph_Vertex_Id);
464 pragma Inline (Write_Dependencies_Of_Vertex);
465 -- Write the dependencies of vertex Vertex of library graph G to
466 -- standard output.
468 procedure Write_Dependency_Edge
469 (G : Library_Graph;
470 Edge : Library_Graph_Edge_Id);
471 pragma Inline (Write_Dependency_Edge);
472 -- Write the dependency described by edge Edge of library graph G to
473 -- standard output.
475 ------------------------
476 -- Write_Dependencies --
477 ------------------------
479 procedure Write_Dependencies (G : Library_Graph) is
480 Use_Formatting : constant Boolean := not Zero_Formatting;
482 Iter : Library_Graphs.All_Vertex_Iterator;
483 Vertex : Library_Graph_Vertex_Id;
485 begin
486 pragma Assert (Present (G));
488 -- Nothing to do when switch -e (output complete list of elaboration
489 -- order dependencies) is not in effect.
491 if not Elab_Dependency_Output then
492 return;
493 end if;
495 if Use_Formatting then
496 Write_Eol;
497 Write_Line ("ELABORATION ORDER DEPENDENCIES");
498 Write_Eol;
499 end if;
501 Info_Prefix_Suppress := True;
503 Iter := Iterate_All_Vertices (G);
504 while Has_Next (Iter) loop
505 Next (Iter, Vertex);
507 Write_Dependencies_Of_Vertex (G, Vertex);
508 end loop;
510 Info_Prefix_Suppress := False;
512 if Use_Formatting then
513 Write_Eol;
514 end if;
515 end Write_Dependencies;
517 ----------------------------------
518 -- Write_Dependencies_Of_Vertex --
519 ----------------------------------
521 procedure Write_Dependencies_Of_Vertex
522 (G : Library_Graph;
523 Vertex : Library_Graph_Vertex_Id)
525 Edge : Library_Graph_Edge_Id;
526 Iter : Edges_To_Successors_Iterator;
528 begin
529 pragma Assert (Present (G));
530 pragma Assert (Present (Vertex));
532 -- Nothing to do for internal and predefined units
534 if Is_Internal_Unit (G, Vertex)
535 or else Is_Predefined_Unit (G, Vertex)
536 then
537 return;
538 end if;
540 Iter := Iterate_Edges_To_Successors (G, Vertex);
541 while Has_Next (Iter) loop
542 Next (Iter, Edge);
544 Write_Dependency_Edge (G, Edge);
545 end loop;
546 end Write_Dependencies_Of_Vertex;
548 ---------------------------
549 -- Write_Dependency_Edge --
550 ---------------------------
552 procedure Write_Dependency_Edge
553 (G : Library_Graph;
554 Edge : Library_Graph_Edge_Id)
556 pragma Assert (Present (G));
557 pragma Assert (Present (Edge));
559 Pred : constant Library_Graph_Vertex_Id := Predecessor (G, Edge);
560 Succ : constant Library_Graph_Vertex_Id := Successor (G, Edge);
562 begin
563 -- Nothing to do for internal and predefined units
565 if Is_Internal_Unit (G, Succ)
566 or else Is_Predefined_Unit (G, Succ)
567 then
568 return;
569 end if;
571 Error_Msg_Unit_1 := Name (G, Pred);
572 Error_Msg_Unit_2 := Name (G, Succ);
573 Error_Msg_Output
574 (Msg => " unit $ must be elaborated before unit $",
575 Info => True);
577 Error_Msg_Unit_1 := Name (G, Succ);
578 Error_Msg_Unit_2 := Name (G, Pred);
580 if Is_Elaborate_All_Edge (G, Edge) then
581 Error_Msg_Output
582 (Msg =>
583 " reason: unit $ has with clause and pragma "
584 & "Elaborate_All for unit $",
585 Info => True);
587 elsif Is_Elaborate_Body_Edge (G, Edge) then
588 Error_Msg_Output
589 (Msg => " reason: unit $ has with clause for unit $",
590 Info => True);
592 elsif Is_Elaborate_Edge (G, Edge) then
593 Error_Msg_Output
594 (Msg =>
595 " reason: unit $ has with clause and pragma Elaborate "
596 & "for unit $",
597 Info => True);
599 elsif Is_Forced_Edge (G, Edge) then
600 Error_Msg_Output
601 (Msg =>
602 " reason: unit $ has a dependency on unit $ forced by -f "
603 & "switch",
604 Info => True);
606 elsif Is_Invocation_Edge (G, Edge) then
607 Error_Msg_Output
608 (Msg =>
609 " reason: unit $ invokes a construct of unit $ at "
610 & "elaboration time",
611 Info => True);
613 elsif Is_Spec_Before_Body_Edge (G, Edge) then
614 Error_Msg_Output
615 (Msg => " reason: spec must be elaborated before body",
616 Info => True);
618 else
619 pragma Assert (Is_With_Edge (G, Edge));
621 Error_Msg_Output
622 (Msg => " reason: unit $ has with clause for unit $",
623 Info => True);
624 end if;
625 end Write_Dependency_Edge;
626 end Dependency_Writers;
628 -------------------------------
629 -- Elaboration_Order_Writers --
630 -------------------------------
632 package body Elaboration_Order_Writers is
634 -----------------------
635 -- Local subprograms --
636 -----------------------
638 procedure Write_Unit (U_Id : Unit_Id);
639 pragma Inline (Write_Unit);
640 -- Write unit U_Id to standard output
642 procedure Write_Units (Order : Unit_Id_Table);
643 pragma Inline (Write_Units);
644 -- Write all units found in elaboration order Order to standard output
646 -----------------------------
647 -- Write_Elaboration_Order --
648 -----------------------------
650 procedure Write_Elaboration_Order (Order : Unit_Id_Table) is
651 Use_Formatting : constant Boolean := not Zero_Formatting;
653 begin
654 -- Nothing to do when switch -l (output chosen elaboration order) is
655 -- not in effect.
657 if not Elab_Order_Output then
658 return;
659 end if;
661 if Use_Formatting then
662 Write_Eol;
663 Write_Str ("ELABORATION ORDER");
664 Write_Eol;
665 end if;
667 Write_Units (Order);
669 if Use_Formatting then
670 Write_Eol;
671 end if;
672 end Write_Elaboration_Order;
674 ----------------
675 -- Write_Unit --
676 ----------------
678 procedure Write_Unit (U_Id : Unit_Id) is
679 Use_Formatting : constant Boolean := not Zero_Formatting;
681 begin
682 pragma Assert (Present (U_Id));
684 if Use_Formatting then
685 Write_Str (" ");
686 end if;
688 Write_Unit_Name (Name (U_Id));
689 Write_Eol;
690 end Write_Unit;
692 -----------------
693 -- Write_Units --
694 -----------------
696 procedure Write_Units (Order : Unit_Id_Table) is
697 begin
698 for Index in Unit_Id_Tables.First .. Unit_Id_Tables.Last (Order) loop
699 Write_Unit (Order.Table (Index));
700 end loop;
701 end Write_Units;
702 end Elaboration_Order_Writers;
704 ---------------
705 -- Indent_By --
706 ---------------
708 procedure Indent_By (Indent : Indentation_Level) is
709 begin
710 for Count in 1 .. Indent loop
711 Write_Char (' ');
712 end loop;
713 end Indent_By;
715 ------------------------------
716 -- Invocation_Graph_Writers --
717 ------------------------------
719 package body Invocation_Graph_Writers is
721 -----------------------
722 -- Local subprograms --
723 -----------------------
725 procedure Write_Elaboration_Root
726 (G : Invocation_Graph;
727 Root : Invocation_Graph_Vertex_Id);
728 pragma Inline (Write_Elaboration_Root);
729 -- Write elaboration root Root of invocation graph G to standard output
731 procedure Write_Elaboration_Roots (G : Invocation_Graph);
732 pragma Inline (Write_Elaboration_Roots);
733 -- Write all elaboration roots of invocation graph G to standard output
735 procedure Write_Invocation_Graph_Edge
736 (G : Invocation_Graph;
737 Edge : Invocation_Graph_Edge_Id);
738 pragma Inline (Write_Invocation_Graph_Edge);
739 -- Write edge Edge of invocation graph G to standard output
741 procedure Write_Invocation_Graph_Edges
742 (G : Invocation_Graph;
743 Vertex : Invocation_Graph_Vertex_Id);
744 pragma Inline (Write_Invocation_Graph_Edges);
745 -- Write all edges to targets of vertex Vertex of invocation graph G to
746 -- standard output.
748 procedure Write_Invocation_Graph_Vertex
749 (G : Invocation_Graph;
750 Vertex : Invocation_Graph_Vertex_Id);
751 pragma Inline (Write_Invocation_Graph_Vertex);
752 -- Write vertex Vertex of invocation graph G to standard output
754 procedure Write_Invocation_Graph_Vertices (G : Invocation_Graph);
755 pragma Inline (Write_Invocation_Graph_Vertices);
756 -- Write all vertices of invocation graph G to standard output
758 procedure Write_Statistics (G : Invocation_Graph);
759 pragma Inline (Write_Statistics);
760 -- Write the statistical information of invocation graph G to standard
761 -- output.
763 -----------
764 -- Debug --
765 -----------
767 procedure pige
768 (G : Invocation_Graph;
769 Edge : Invocation_Graph_Edge_Id) renames Write_Invocation_Graph_Edge;
770 pragma Unreferenced (pige);
772 procedure pigv
773 (G : Invocation_Graph;
774 Vertex : Invocation_Graph_Vertex_Id)
775 renames Write_Invocation_Graph_Vertex;
776 pragma Unreferenced (pigv);
778 ----------------------------
779 -- Write_Elaboration_Root --
780 ----------------------------
782 procedure Write_Elaboration_Root
783 (G : Invocation_Graph;
784 Root : Invocation_Graph_Vertex_Id)
786 begin
787 pragma Assert (Present (G));
788 pragma Assert (Present (Root));
790 Write_Str ("elaboration root (IGV_Id_");
791 Write_Int (Int (Root));
792 Write_Str (") name = ");
793 Write_Name (Name (G, Root));
794 Write_Eol;
795 end Write_Elaboration_Root;
797 -----------------------------
798 -- Write_Elaboration_Roots --
799 -----------------------------
801 procedure Write_Elaboration_Roots (G : Invocation_Graph) is
802 pragma Assert (Present (G));
804 Num_Of_Roots : constant Natural := Number_Of_Elaboration_Roots (G);
806 Iter : Elaboration_Root_Iterator;
807 Root : Invocation_Graph_Vertex_Id;
809 begin
810 Write_Str ("Elaboration roots: ");
811 Write_Int (Int (Num_Of_Roots));
812 Write_Eol;
814 if Num_Of_Roots > 0 then
815 Iter := Iterate_Elaboration_Roots (G);
816 while Has_Next (Iter) loop
817 Next (Iter, Root);
819 Write_Elaboration_Root (G, Root);
820 end loop;
821 else
822 Write_Eol;
823 end if;
824 end Write_Elaboration_Roots;
826 ----------------------------
827 -- Write_Invocation_Graph --
828 ----------------------------
830 procedure Write_Invocation_Graph (G : Invocation_Graph) is
831 begin
832 pragma Assert (Present (G));
834 -- Nothing to do when switch -d_I (output invocation graph) is not in
835 -- effect.
837 if not Debug_Flag_Underscore_II then
838 return;
839 end if;
841 Write_Str ("Invocation Graph");
842 Write_Eol;
843 Write_Eol;
845 Write_Statistics (G);
846 Write_Invocation_Graph_Vertices (G);
847 Write_Elaboration_Roots (G);
849 Write_Str ("Invocation Graph end");
850 Write_Eol;
852 Write_Eol;
853 end Write_Invocation_Graph;
855 ---------------------------------
856 -- Write_Invocation_Graph_Edge --
857 ---------------------------------
859 procedure Write_Invocation_Graph_Edge
860 (G : Invocation_Graph;
861 Edge : Invocation_Graph_Edge_Id)
863 pragma Assert (Present (G));
864 pragma Assert (Present (Edge));
866 Targ : constant Invocation_Graph_Vertex_Id := Target (G, Edge);
868 begin
869 Write_Str (" invocation graph edge (IGE_Id_");
870 Write_Int (Int (Edge));
871 Write_Str (")");
872 Write_Eol;
874 Write_Str (" Relation (IR_Id_");
875 Write_Int (Int (Relation (G, Edge)));
876 Write_Str (")");
877 Write_Eol;
879 Write_Str (" Target (IGV_Id_");
880 Write_Int (Int (Targ));
881 Write_Str (") name = ");
882 Write_Name (Name (G, Targ));
883 Write_Eol;
885 Write_Eol;
886 end Write_Invocation_Graph_Edge;
888 ----------------------------------
889 -- Write_Invocation_Graph_Edges --
890 ----------------------------------
892 procedure Write_Invocation_Graph_Edges
893 (G : Invocation_Graph;
894 Vertex : Invocation_Graph_Vertex_Id)
896 pragma Assert (Present (G));
897 pragma Assert (Present (Vertex));
899 Num_Of_Edges : constant Natural :=
900 Number_Of_Edges_To_Targets (G, Vertex);
902 Edge : Invocation_Graph_Edge_Id;
903 Iter : Invocation_Graphs.Edges_To_Targets_Iterator;
905 begin
906 Write_Str (" Edges to targets: ");
907 Write_Int (Int (Num_Of_Edges));
908 Write_Eol;
910 if Num_Of_Edges > 0 then
911 Iter := Iterate_Edges_To_Targets (G, Vertex);
912 while Has_Next (Iter) loop
913 Next (Iter, Edge);
915 Write_Invocation_Graph_Edge (G, Edge);
916 end loop;
917 else
918 Write_Eol;
919 end if;
920 end Write_Invocation_Graph_Edges;
922 -----------------------------------
923 -- Write_Invocation_Graph_Vertex --
924 -----------------------------------
926 procedure Write_Invocation_Graph_Vertex
927 (G : Invocation_Graph;
928 Vertex : Invocation_Graph_Vertex_Id)
930 begin
931 pragma Assert (Present (G));
932 pragma Assert (Present (Vertex));
934 Write_Str ("invocation graph vertex (IGV_Id_");
935 Write_Int (Int (Vertex));
936 Write_Str (") name = ");
937 Write_Name (Name (G, Vertex));
938 Write_Eol;
940 Write_Str (" Body_Vertex (LGV_Id_");
941 Write_Int (Int (Body_Vertex (G, Vertex)));
942 Write_Str (")");
943 Write_Eol;
945 Write_Str (" Construct (IC_Id_");
946 Write_Int (Int (Construct (G, Vertex)));
947 Write_Str (")");
948 Write_Eol;
950 Write_Str (" Spec_Vertex (LGV_Id_");
951 Write_Int (Int (Spec_Vertex (G, Vertex)));
952 Write_Str (")");
953 Write_Eol;
955 Write_Invocation_Graph_Edges (G, Vertex);
956 end Write_Invocation_Graph_Vertex;
958 -------------------------------------
959 -- Write_Invocation_Graph_Vertices --
960 -------------------------------------
962 procedure Write_Invocation_Graph_Vertices (G : Invocation_Graph) is
963 Iter : Invocation_Graphs.All_Vertex_Iterator;
964 Vertex : Invocation_Graph_Vertex_Id;
966 begin
967 pragma Assert (Present (G));
969 Iter := Iterate_All_Vertices (G);
970 while Has_Next (Iter) loop
971 Next (Iter, Vertex);
973 Write_Invocation_Graph_Vertex (G, Vertex);
974 end loop;
975 end Write_Invocation_Graph_Vertices;
977 ----------------------
978 -- Write_Statistics --
979 ----------------------
981 procedure Write_Statistics (G : Invocation_Graph) is
982 begin
983 pragma Assert (Present (G));
985 Write_Str ("Edges : ");
986 Write_Num (Int (Number_Of_Edges (G)));
987 Write_Eol;
989 Write_Str ("Roots : ");
990 Write_Num (Int (Number_Of_Elaboration_Roots (G)));
991 Write_Eol;
993 Write_Str ("Vertices: ");
994 Write_Num (Int (Number_Of_Vertices (G)));
995 Write_Eol;
996 Write_Eol;
998 for Kind in Invocation_Kind'Range loop
999 Write_Str (" ");
1000 Write_Num (Int (Invocation_Graph_Edge_Count (G, Kind)));
1001 Write_Str (" - ");
1002 Write_Str (Kind'Img);
1003 Write_Eol;
1004 end loop;
1006 Write_Eol;
1007 end Write_Statistics;
1008 end Invocation_Graph_Writers;
1010 ---------------------------
1011 -- Library_Graph_Writers --
1012 ---------------------------
1014 package body Library_Graph_Writers is
1016 -----------------------
1017 -- Local subprograms --
1018 -----------------------
1020 procedure Write_Component
1021 (G : Library_Graph;
1022 Comp : Component_Id);
1023 pragma Inline (Write_Component);
1024 -- Write component Comp of library graph G to standard output
1026 procedure Write_Component_Vertices
1027 (G : Library_Graph;
1028 Comp : Component_Id);
1029 pragma Inline (Write_Component_Vertices);
1030 -- Write all vertices of component Comp of library graph G to standard
1031 -- output.
1033 procedure Write_Components (G : Library_Graph);
1034 pragma Inline (Write_Component);
1035 -- Write all components of library graph G to standard output
1037 procedure Write_Edges_To_Successors
1038 (G : Library_Graph;
1039 Vertex : Library_Graph_Vertex_Id);
1040 pragma Inline (Write_Edges_To_Successors);
1041 -- Write all edges to successors of predecessor Vertex of library graph
1042 -- G to standard output.
1044 procedure Write_Library_Graph_Edge
1045 (G : Library_Graph;
1046 Edge : Library_Graph_Edge_Id);
1047 pragma Inline (Write_Library_Graph_Edge);
1048 -- Write edge Edge of library graph G to standard output
1050 procedure Write_Library_Graph_Vertex
1051 (G : Library_Graph;
1052 Vertex : Library_Graph_Vertex_Id);
1053 pragma Inline (Write_Library_Graph_Vertex);
1054 -- Write vertex Vertex of library graph G to standard output
1056 procedure Write_Library_Graph_Vertices (G : Library_Graph);
1057 pragma Inline (Write_Library_Graph_Vertices);
1058 -- Write all vertices of library graph G to standard output
1060 procedure Write_Statistics (G : Library_Graph);
1061 pragma Inline (Write_Statistics);
1062 -- Write the statistical information of library graph G to standard
1063 -- output.
1065 -----------
1066 -- Debug --
1067 -----------
1069 procedure pc
1070 (G : Library_Graph;
1071 Comp : Component_Id) renames Write_Component;
1072 pragma Unreferenced (pc);
1074 procedure plge
1075 (G : Library_Graph;
1076 Edge : Library_Graph_Edge_Id) renames Write_Library_Graph_Edge;
1077 pragma Unreferenced (plge);
1079 procedure plgv
1080 (G : Library_Graph;
1081 Vertex : Library_Graph_Vertex_Id) renames Write_Library_Graph_Vertex;
1082 pragma Unreferenced (plgv);
1084 ---------------------
1085 -- Write_Component --
1086 ---------------------
1088 procedure Write_Component
1089 (G : Library_Graph;
1090 Comp : Component_Id)
1092 begin
1093 pragma Assert (Present (G));
1094 pragma Assert (Present (Comp));
1096 Write_Str ("component (Comp_");
1097 Write_Int (Int (Comp));
1098 Write_Str (")");
1099 Write_Eol;
1101 Write_Str (" Pending_Strong_Predecessors = ");
1102 Write_Int (Int (Pending_Strong_Predecessors (G, Comp)));
1103 Write_Eol;
1105 Write_Str (" Pending_Weak_Predecessors = ");
1106 Write_Int (Int (Pending_Weak_Predecessors (G, Comp)));
1107 Write_Eol;
1109 Write_Component_Vertices (G, Comp);
1111 Write_Eol;
1112 end Write_Component;
1114 ------------------------------
1115 -- Write_Component_Vertices --
1116 ------------------------------
1118 procedure Write_Component_Vertices
1119 (G : Library_Graph;
1120 Comp : Component_Id)
1122 pragma Assert (Present (G));
1123 pragma Assert (Present (Comp));
1125 Num_Of_Vertices : constant Natural :=
1126 Number_Of_Component_Vertices (G, Comp);
1128 Iter : Component_Vertex_Iterator;
1129 Vertex : Library_Graph_Vertex_Id;
1131 begin
1132 Write_Str (" Vertices: ");
1133 Write_Int (Int (Num_Of_Vertices));
1134 Write_Eol;
1136 if Num_Of_Vertices > 0 then
1137 Iter := Iterate_Component_Vertices (G, Comp);
1138 while Has_Next (Iter) loop
1139 Next (Iter, Vertex);
1141 Write_Str (" library graph vertex (LGV_Id_");
1142 Write_Int (Int (Vertex));
1143 Write_Str (") name = ");
1144 Write_Name (Name (G, Vertex));
1145 Write_Eol;
1146 end loop;
1147 else
1148 Write_Eol;
1149 end if;
1150 end Write_Component_Vertices;
1152 ----------------------
1153 -- Write_Components --
1154 ----------------------
1156 procedure Write_Components (G : Library_Graph) is
1157 pragma Assert (Present (G));
1159 Num_Of_Comps : constant Natural := Number_Of_Components (G);
1161 Comp : Component_Id;
1162 Iter : Component_Iterator;
1164 begin
1165 -- Nothing to do when switch -d_L (output library item graph) is not
1166 -- in effect.
1168 if not Debug_Flag_Underscore_LL then
1169 return;
1170 end if;
1172 Write_Str ("Library Graph components");
1173 Write_Eol;
1174 Write_Eol;
1176 if Num_Of_Comps > 0 then
1177 Write_Str ("Components: ");
1178 Write_Num (Int (Num_Of_Comps));
1179 Write_Eol;
1181 Iter := Iterate_Components (G);
1182 while Has_Next (Iter) loop
1183 Next (Iter, Comp);
1185 Write_Component (G, Comp);
1186 end loop;
1187 else
1188 Write_Eol;
1189 end if;
1191 Write_Str ("Library Graph components end");
1192 Write_Eol;
1194 Write_Eol;
1195 end Write_Components;
1197 -------------------------------
1198 -- Write_Edges_To_Successors --
1199 -------------------------------
1201 procedure Write_Edges_To_Successors
1202 (G : Library_Graph;
1203 Vertex : Library_Graph_Vertex_Id)
1205 pragma Assert (Present (G));
1206 pragma Assert (Present (Vertex));
1208 Num_Of_Edges : constant Natural :=
1209 Number_Of_Edges_To_Successors (G, Vertex);
1211 Edge : Library_Graph_Edge_Id;
1212 Iter : Edges_To_Successors_Iterator;
1214 begin
1215 Write_Str (" Edges to successors: ");
1216 Write_Int (Int (Num_Of_Edges));
1217 Write_Eol;
1219 if Num_Of_Edges > 0 then
1220 Iter := Iterate_Edges_To_Successors (G, Vertex);
1221 while Has_Next (Iter) loop
1222 Next (Iter, Edge);
1224 Write_Library_Graph_Edge (G, Edge);
1225 end loop;
1226 else
1227 Write_Eol;
1228 end if;
1229 end Write_Edges_To_Successors;
1231 -------------------------
1232 -- Write_Library_Graph --
1233 -------------------------
1235 procedure Write_Library_Graph (G : Library_Graph) is
1236 begin
1237 pragma Assert (Present (G));
1239 -- Nothing to do when switch -d_L (output library item graph) is not
1240 -- in effect.
1242 if not Debug_Flag_Underscore_LL then
1243 return;
1244 end if;
1246 Write_Str ("Library Graph");
1247 Write_Eol;
1248 Write_Eol;
1250 Write_Statistics (G);
1251 Write_Library_Graph_Vertices (G);
1252 Write_Components (G);
1254 Write_Str ("Library Graph end");
1255 Write_Eol;
1257 Write_Eol;
1258 end Write_Library_Graph;
1260 ------------------------------
1261 -- Write_Library_Graph_Edge --
1262 ------------------------------
1264 procedure Write_Library_Graph_Edge
1265 (G : Library_Graph;
1266 Edge : Library_Graph_Edge_Id)
1268 pragma Assert (Present (G));
1269 pragma Assert (Present (Edge));
1271 Pred : constant Library_Graph_Vertex_Id := Predecessor (G, Edge);
1272 Succ : constant Library_Graph_Vertex_Id := Successor (G, Edge);
1274 begin
1275 Write_Str (" library graph edge (LGE_Id_");
1276 Write_Int (Int (Edge));
1277 Write_Str (")");
1278 Write_Eol;
1280 Write_Str (" Kind = ");
1281 Write_Str (Kind (G, Edge)'Img);
1282 Write_Eol;
1284 Write_Str (" Predecessor (LGV_Id_");
1285 Write_Int (Int (Pred));
1286 Write_Str (") name = ");
1287 Write_Name (Name (G, Pred));
1288 Write_Eol;
1290 Write_Str (" Successor (LGV_Id_");
1291 Write_Int (Int (Succ));
1292 Write_Str (") name = ");
1293 Write_Name (Name (G, Succ));
1294 Write_Eol;
1296 Write_Eol;
1297 end Write_Library_Graph_Edge;
1299 --------------------------------
1300 -- Write_Library_Graph_Vertex --
1301 --------------------------------
1303 procedure Write_Library_Graph_Vertex
1304 (G : Library_Graph;
1305 Vertex : Library_Graph_Vertex_Id)
1307 pragma Assert (Present (G));
1308 pragma Assert (Present (Vertex));
1310 Item : constant Library_Graph_Vertex_Id :=
1311 Corresponding_Item (G, Vertex);
1312 U_Id : constant Unit_Id := Unit (G, Vertex);
1314 begin
1315 Write_Str ("library graph vertex (LGV_Id_");
1316 Write_Int (Int (Vertex));
1317 Write_Str (") name = ");
1318 Write_Name (Name (G, Vertex));
1319 Write_Eol;
1321 if Present (Item) then
1322 Write_Str (" Corresponding_Item (LGV_Id_");
1323 Write_Int (Int (Item));
1324 Write_Str (") name = ");
1325 Write_Name (Name (G, Item));
1326 else
1327 Write_Str (" Corresponding_Item = none");
1328 end if;
1330 Write_Eol;
1331 Write_Str (" In_Elaboration_Order = ");
1333 if In_Elaboration_Order (G, Vertex) then
1334 Write_Str ("True");
1335 else
1336 Write_Str ("False");
1337 end if;
1339 Write_Eol;
1340 Write_Str (" Pending_Strong_Predecessors = ");
1341 Write_Int (Int (Pending_Strong_Predecessors (G, Vertex)));
1342 Write_Eol;
1344 Write_Str (" Pending_Weak_Predecessors = ");
1345 Write_Int (Int (Pending_Weak_Predecessors (G, Vertex)));
1346 Write_Eol;
1348 Write_Str (" Component (Comp_Id_");
1349 Write_Int (Int (Component (G, Vertex)));
1350 Write_Str (")");
1351 Write_Eol;
1353 Write_Str (" Unit (U_Id_");
1354 Write_Int (Int (U_Id));
1355 Write_Str (") name = ");
1356 Write_Name (Name (U_Id));
1357 Write_Eol;
1359 Write_Edges_To_Successors (G, Vertex);
1360 end Write_Library_Graph_Vertex;
1362 ----------------------------------
1363 -- Write_Library_Graph_Vertices --
1364 ----------------------------------
1366 procedure Write_Library_Graph_Vertices (G : Library_Graph) is
1367 Iter : Library_Graphs.All_Vertex_Iterator;
1368 Vertex : Library_Graph_Vertex_Id;
1370 begin
1371 pragma Assert (Present (G));
1373 Iter := Iterate_All_Vertices (G);
1374 while Has_Next (Iter) loop
1375 Next (Iter, Vertex);
1377 Write_Library_Graph_Vertex (G, Vertex);
1378 end loop;
1379 end Write_Library_Graph_Vertices;
1381 ----------------------
1382 -- Write_Statistics --
1383 ----------------------
1385 procedure Write_Statistics (G : Library_Graph) is
1386 begin
1387 Write_Str ("Components: ");
1388 Write_Num (Int (Number_Of_Components (G)));
1389 Write_Eol;
1391 Write_Str ("Edges : ");
1392 Write_Num (Int (Number_Of_Edges (G)));
1393 Write_Eol;
1395 Write_Str ("Vertices : ");
1396 Write_Num (Int (Number_Of_Vertices (G)));
1397 Write_Eol;
1398 Write_Eol;
1400 for Kind in Library_Graph_Edge_Kind'Range loop
1401 Write_Str (" ");
1402 Write_Num (Int (Library_Graph_Edge_Count (G, Kind)));
1403 Write_Str (" - ");
1404 Write_Str (Kind'Img);
1405 Write_Eol;
1406 end loop;
1408 Write_Eol;
1409 end Write_Statistics;
1410 end Library_Graph_Writers;
1412 -------------------
1413 -- Phase_Writers --
1414 -------------------
1416 package body Phase_Writers is
1418 subtype Phase_Message is String (1 .. 32);
1420 -- The following table contains the phase-specific messages for phase
1421 -- completion.
1423 End_Messages : constant array (Elaboration_Phase) of Phase_Message :=
1424 (Component_Discovery => "components discovered. ",
1425 Cycle_Diagnostics => "cycle diagnosed. ",
1426 Cycle_Discovery => "cycles discovered. ",
1427 Cycle_Validation => "cycles validated. ",
1428 Elaboration_Order_Validation => "elaboration order validated. ",
1429 Invocation_Graph_Construction => "invocation graph constructed. ",
1430 Invocation_Graph_Validation => "invocation graph validated. ",
1431 Library_Graph_Augmentation => "library graph augmented. ",
1432 Library_Graph_Construction => "library graph constructed. ",
1433 Library_Graph_Elaboration => "library graph elaborated. ",
1434 Library_Graph_Validation => "library graph validated. ",
1435 Unit_Collection => "units collected. ",
1436 Unit_Elaboration => "units elaborated. ");
1438 -- The following table contains the phase-specific messages for phase
1439 -- commencement.
1441 Start_Messages : constant array (Elaboration_Phase) of Phase_Message :=
1442 (Component_Discovery => "discovering components... ",
1443 Cycle_Diagnostics => "diagnosing cycle... ",
1444 Cycle_Discovery => "discovering cycles... ",
1445 Cycle_Validation => "validating cycles... ",
1446 Elaboration_Order_Validation => "validating elaboration order... ",
1447 Invocation_Graph_Construction => "constructing invocation graph...",
1448 Invocation_Graph_Validation => "validating invocation graph... ",
1449 Library_Graph_Augmentation => "augmenting library graph... ",
1450 Library_Graph_Construction => "constructing library graph... ",
1451 Library_Graph_Elaboration => "elaborating library graph... ",
1452 Library_Graph_Validation => "validating library graph... ",
1453 Unit_Collection => "collecting units... ",
1454 Unit_Elaboration => "elaborating units... ");
1456 -----------------------
1457 -- Local subprograms --
1458 -----------------------
1460 procedure Write_Phase_Message (Msg : Phase_Message);
1461 pragma Inline (Write_Phase_Message);
1462 -- Write elaboration phase-related message Msg to standard output
1464 ---------------
1465 -- End_Phase --
1466 ---------------
1468 procedure End_Phase (Phase : Elaboration_Phase) is
1469 begin
1470 Write_Phase_Message (End_Messages (Phase));
1471 end End_Phase;
1473 -----------------
1474 -- Start_Phase --
1475 -----------------
1477 procedure Start_Phase (Phase : Elaboration_Phase) is
1478 begin
1479 Write_Phase_Message (Start_Messages (Phase));
1480 end Start_Phase;
1482 -------------------------
1483 -- Write_Phase_Message --
1484 -------------------------
1486 procedure Write_Phase_Message (Msg : Phase_Message) is
1487 begin
1488 -- Nothing to do when switch -d_S (output elaboration order status)
1489 -- is not in effect.
1491 if not Debug_Flag_Underscore_SS then
1492 return;
1493 end if;
1495 Write_Str (Msg);
1496 Write_Eol;
1497 end Write_Phase_Message;
1498 end Phase_Writers;
1500 --------------------------
1501 -- Unit_Closure_Writers --
1502 --------------------------
1504 package body Unit_Closure_Writers is
1505 function Hash_File_Name (Nam : File_Name_Type) return Bucket_Range_Type;
1506 pragma Inline (Hash_File_Name);
1507 -- Obtain the hash value of key Nam
1509 package File_Name_Tables is new Membership_Sets
1510 (Element_Type => File_Name_Type,
1511 "=" => "=",
1512 Hash => Hash_File_Name);
1513 use File_Name_Tables;
1515 -----------------------
1516 -- Local subprograms --
1517 -----------------------
1519 procedure Write_File_Name (Nam : File_Name_Type);
1520 pragma Inline (Write_File_Name);
1521 -- Write file name Nam to standard output
1523 procedure Write_Subunit_Closure
1524 (Dep : Sdep_Id;
1525 Set : Membership_Set);
1526 pragma Inline (Write_Subunit_Closure);
1527 -- Write the subunit which corresponds to dependency Dep to standard
1528 -- output if it does not appear in set Set.
1530 procedure Write_Subunits_Closure (Set : Membership_Set);
1531 pragma Inline (Write_Subunits_Closure);
1532 -- Write all subunits to standard output if they do not appear in set
1533 -- Set.
1535 procedure Write_Unit_Closure
1536 (U_Id : Unit_Id;
1537 Set : Membership_Set);
1538 pragma Inline (Write_Unit_Closure);
1539 -- Write unit U_Id to standard output if it does not appear in set Set
1541 procedure Write_Units_Closure
1542 (Order : Unit_Id_Table;
1543 Set : Membership_Set);
1544 pragma Inline (Write_Units_Closure);
1545 -- Write all units of elaboration order Order to standard output if they
1546 -- do not appear in set Set.
1548 --------------------
1549 -- Hash_File_Name --
1550 --------------------
1552 function Hash_File_Name
1553 (Nam : File_Name_Type) return Bucket_Range_Type
1555 begin
1556 pragma Assert (Present (Nam));
1558 return Bucket_Range_Type (Nam);
1559 end Hash_File_Name;
1561 ---------------------
1562 -- Write_File_Name --
1563 ---------------------
1565 procedure Write_File_Name (Nam : File_Name_Type) is
1566 Use_Formatting : constant Boolean := not Zero_Formatting;
1568 begin
1569 pragma Assert (Present (Nam));
1571 if Use_Formatting then
1572 Write_Str (" ");
1573 end if;
1575 Write_Line (Get_Name_String (Nam));
1576 end Write_File_Name;
1578 ---------------------------
1579 -- Write_Subunit_Closure --
1580 ---------------------------
1582 procedure Write_Subunit_Closure
1583 (Dep : Sdep_Id;
1584 Set : Membership_Set)
1586 pragma Assert (Present (Dep));
1587 pragma Assert (Present (Set));
1589 Dep_Rec : Sdep_Record renames Sdep.Table (Dep);
1590 Source : constant File_Name_Type := Dep_Rec.Sfile;
1592 pragma Assert (Present (Source));
1594 begin
1595 -- Nothing to do when the source file has already been written
1597 if Contains (Set, Source) then
1598 return;
1600 -- Nothing to do when the source file does not denote a non-internal
1601 -- subunit.
1603 elsif not Present (Dep_Rec.Subunit_Name)
1604 or else Is_Internal_File_Name (Source)
1605 then
1606 return;
1607 end if;
1609 -- Mark the subunit as written
1611 Insert (Set, Source);
1612 Write_File_Name (Source);
1613 end Write_Subunit_Closure;
1615 ----------------------------
1616 -- Write_Subunits_Closure --
1617 ----------------------------
1619 procedure Write_Subunits_Closure (Set : Membership_Set) is
1620 begin
1621 pragma Assert (Present (Set));
1623 for Dep in Sdep.First .. Sdep.Last loop
1624 Write_Subunit_Closure (Dep, Set);
1625 end loop;
1626 end Write_Subunits_Closure;
1628 ------------------------
1629 -- Write_Unit_Closure --
1630 ------------------------
1632 procedure Write_Unit_Closure (Order : Unit_Id_Table) is
1633 Use_Formatting : constant Boolean := not Zero_Formatting;
1635 Set : Membership_Set;
1637 begin
1638 -- Nothing to do when switch -R (list sources referenced in closure)
1639 -- is not in effect.
1641 if not List_Closure then
1642 return;
1643 end if;
1645 if Use_Formatting then
1646 Write_Eol;
1647 Write_Line ("REFERENCED SOURCES");
1648 end if;
1650 -- Use a set to avoid writing duplicate units and subunits
1652 Set := Create (Number_Of_Elaborable_Units);
1654 Write_Units_Closure (Order, Set);
1655 Write_Subunits_Closure (Set);
1657 Destroy (Set);
1659 if Use_Formatting then
1660 Write_Eol;
1661 end if;
1662 end Write_Unit_Closure;
1664 ------------------------
1665 -- Write_Unit_Closure --
1666 ------------------------
1668 procedure Write_Unit_Closure
1669 (U_Id : Unit_Id;
1670 Set : Membership_Set)
1672 pragma Assert (Present (U_Id));
1673 pragma Assert (Present (Set));
1675 U_Rec : Unit_Record renames ALI.Units.Table (U_Id);
1676 Source : constant File_Name_Type := U_Rec.Sfile;
1678 pragma Assert (Present (Source));
1680 begin
1681 -- Nothing to do when the source file has already been written
1683 if Contains (Set, Source) then
1684 return;
1686 -- Nothing to do for internal source files unless switch -Ra (???) is
1687 -- in effect.
1689 elsif Is_Internal_File_Name (Source)
1690 and then not List_Closure_All
1691 then
1692 return;
1693 end if;
1695 -- Mark the source file as written
1697 Insert (Set, Source);
1698 Write_File_Name (Source);
1699 end Write_Unit_Closure;
1701 -------------------------
1702 -- Write_Units_Closure --
1703 -------------------------
1705 procedure Write_Units_Closure
1706 (Order : Unit_Id_Table;
1707 Set : Membership_Set)
1709 begin
1710 pragma Assert (Present (Set));
1712 for Index in reverse Unit_Id_Tables.First ..
1713 Unit_Id_Tables.Last (Order)
1714 loop
1715 Write_Unit_Closure
1716 (U_Id => Order.Table (Index),
1717 Set => Set);
1718 end loop;
1719 end Write_Units_Closure;
1720 end Unit_Closure_Writers;
1722 ---------------
1723 -- Write_Num --
1724 ---------------
1726 procedure Write_Num
1727 (Val : Int;
1728 Val_Indent : Indentation_Level := Number_Column)
1730 function Digits_Indentation return Indentation_Level;
1731 pragma Inline (Digits_Indentation);
1732 -- Determine the level of indentation the number requires in order to
1733 -- be right-justified by Val_Indent.
1735 ------------------------
1736 -- Digits_Indentation --
1737 ------------------------
1739 function Digits_Indentation return Indentation_Level is
1740 Indent : Indentation_Level;
1741 Num : Int;
1743 begin
1744 -- Treat zero as a single digit
1746 if Val = 0 then
1747 Indent := 1;
1749 else
1750 Indent := 0;
1751 Num := Val;
1753 -- Shrink the input value by dividing it until all of its digits
1754 -- are exhausted.
1756 while Num /= 0 loop
1757 Indent := Indent + 1;
1758 Num := Num / 10;
1759 end loop;
1760 end if;
1762 return Val_Indent - Indent;
1763 end Digits_Indentation;
1765 -- Start of processing for Write_Num
1767 begin
1768 Indent_By (Digits_Indentation);
1769 Write_Int (Val);
1770 end Write_Num;
1772 end Bindo.Writers;