1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- B I N D O . W R I T E R S --
9 -- Copyright (C) 2019, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Binderr
; use Binderr
;
27 with Butil
; use Butil
;
28 with Debug
; use Debug
;
29 with Fname
; use Fname
;
31 with Output
; use Output
;
37 with GNAT
.Graphs
; use GNAT
.Graphs
;
38 with GNAT
.Sets
; use GNAT
.Sets
;
40 package body Bindo
.Writers
is
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
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
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
97 -- Nothing to do when switch -d_A (output invocation tables) is not
100 if not Debug_Flag_Underscore_AA
then
104 Write_Str
("ALI Tables");
109 For_Each_Unit
(Write_Unit
'Access);
111 Write_Str
("ALI Tables end");
114 end Write_ALI_Tables
;
116 ---------------------
117 -- Write_All_Units --
118 ---------------------
120 procedure Write_All_Units
is
122 For_Each_Unit
(Write_Unit_Common
'Access);
125 --------------------------------
126 -- Write_Invocation_Construct --
127 --------------------------------
129 procedure Write_Invocation_Construct
(IC_Id
: Invocation_Construct_Id
) is
131 pragma Assert
(Present
(IC_Id
));
133 Write_Str
(" invocation construct (IC_Id_");
134 Write_Int
(Int
(IC_Id
));
138 Write_Str
(" Body_Placement = ");
139 Write_Str
(Body_Placement
(IC_Id
)'Img);
142 Write_Str
(" Kind = ");
143 Write_Str
(Kind
(IC_Id
)'Img);
146 Write_Str
(" Spec_Placement = ");
147 Write_Str
(Spec_Placement
(IC_Id
)'Img);
150 Write_Invocation_Signature
(Signature
(IC_Id
));
152 end Write_Invocation_Construct
;
154 -------------------------------
155 -- Write_Invocation_Relation --
156 -------------------------------
158 procedure Write_Invocation_Relation
(IR_Id
: Invocation_Relation_Id
) is
160 pragma Assert
(Present
(IR_Id
));
162 Write_Str
(" invocation relation (IR_Id_");
163 Write_Int
(Int
(IR_Id
));
167 if Present
(Extra
(IR_Id
)) then
168 Write_Str
(" Extra = ");
169 Write_Name
(Extra
(IR_Id
));
171 Write_Str
(" Extra = none");
175 Write_Str
(" Invoker");
178 Write_Invocation_Signature
(Invoker
(IR_Id
));
180 Write_Str
(" Kind = ");
181 Write_Str
(Kind
(IR_Id
)'Img);
184 Write_Str
(" Target");
187 Write_Invocation_Signature
(Target
(IR_Id
));
189 end Write_Invocation_Relation
;
191 --------------------------------
192 -- Write_Invocation_Signature --
193 --------------------------------
195 procedure Write_Invocation_Signature
(IS_Id
: Invocation_Signature_Id
) is
197 pragma Assert
(Present
(IS_Id
));
199 Write_Str
(" Signature (IS_Id_");
200 Write_Int
(Int
(IS_Id
));
204 Write_Str
(" Column = ");
205 Write_Int
(Int
(Column
(IS_Id
)));
208 Write_Str
(" Line = ");
209 Write_Int
(Int
(Line
(IS_Id
)));
212 if Present
(Locations
(IS_Id
)) then
213 Write_Str
(" Locations = ");
214 Write_Name
(Locations
(IS_Id
));
216 Write_Str
(" Locations = none");
220 Write_Str
(" Name = ");
221 Write_Name
(Name
(IS_Id
));
224 Write_Str
(" Scope = ");
225 Write_Name
(Scope
(IS_Id
));
227 end Write_Invocation_Signature
;
229 ----------------------
230 -- Write_Statistics --
231 ----------------------
233 procedure Write_Statistics
is
235 Write_Str
("Units : ");
236 Write_Num
(Int
(Number_Of_Units
));
239 Write_Str
("Units to elaborate: ");
240 Write_Num
(Int
(Number_Of_Elaborable_Units
));
243 end Write_Statistics
;
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
);
255 Write_Unit_Common
(U_Id
);
257 Write_Str
(" First_Invocation_Construct (IC_Id_");
258 Write_Int
(Int
(U_Rec
.First_Invocation_Construct
));
262 Write_Str
(" Last_Invocation_Construct (IC_Id_");
263 Write_Int
(Int
(U_Rec
.Last_Invocation_Construct
));
267 Write_Str
(" First_Invocation_Relation (IR_Id_");
268 Write_Int
(Int
(U_Rec
.First_Invocation_Relation
));
272 Write_Str
(" Last_Invocation_Relation (IR_Id_");
273 Write_Int
(Int
(U_Rec
.Last_Invocation_Relation
));
277 Write_Str
(" Invocation_Graph_Encoding = ");
278 Write_Str
(Invocation_Graph_Encoding
(U_Id
)'Img);
282 For_Each_Invocation_Construct
284 Processor
=> Write_Invocation_Construct
'Access);
286 For_Each_Invocation_Relation
288 Processor
=> Write_Invocation_Relation
'Access);
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
);
301 Write_Str
("unit (U_Id_");
302 Write_Int
(Int
(U_Id
));
303 Write_Str
(") name = ");
304 Write_Name
(U_Rec
.Uname
);
307 if U_Rec
.SAL_Interface
then
308 Write_Str
(" SAL_Interface = True");
311 end Write_Unit_Common
;
318 package body Cycle_Writers
is
320 -----------------------
321 -- Local subprograms --
322 -----------------------
324 procedure Write_Cycle
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
331 procedure Write_Cyclic_Edge
333 Edge
: Library_Graph_Edge_Id
);
334 pragma Inline
(Write_Cyclic_Edge
);
335 -- Write cyclic edge Edge of library graph G to standard
341 procedure palgc
(G
: Library_Graph
) renames Write_Cycles
;
342 pragma Unreferenced
(palgc
);
346 Cycle
: Library_Graph_Cycle_Id
) renames Write_Cycle
;
347 pragma Unreferenced
(plgc
);
353 procedure Write_Cycle
355 Cycle
: Library_Graph_Cycle_Id
)
357 Edge
: Library_Graph_Edge_Id
;
358 Iter
: Edges_Of_Cycle_Iterator
;
361 pragma Assert
(Present
(G
));
362 pragma Assert
(Present
(Cycle
));
364 -- Nothing to do when switch -d_P (output cycle paths) is not in
367 if not Debug_Flag_Underscore_PP
then
371 Write_Str
("cycle (LGC_Id_");
372 Write_Int
(Int
(Cycle
));
376 Iter
:= Iterate_Edges_Of_Cycle
(G
, Cycle
);
377 while Has_Next
(Iter
) loop
380 Write_Cyclic_Edge
(G
, Edge
);
390 procedure Write_Cycles
(G
: Library_Graph
) is
391 Cycle
: Library_Graph_Cycle_Id
;
392 Iter
: All_Cycle_Iterator
;
395 pragma Assert
(Present
(G
));
397 Iter
:= Iterate_All_Cycles
(G
);
398 while Has_Next
(Iter
) loop
401 Write_Cycle
(G
, Cycle
);
405 -----------------------
406 -- Write_Cyclic_Edge --
407 -----------------------
409 procedure Write_Cyclic_Edge
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
);
420 Indent_By
(Nested_Indentation
);
421 Write_Name
(Name
(G
, Succ
));
423 Write_Name
(Name
(G
, Pred
));
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");
442 pragma Assert
(Is_With_Edge
(G
, Edge
));
444 Write_Str
("with edge");
448 end Write_Cyclic_Edge
;
451 ------------------------
452 -- Dependency_Writers --
453 ------------------------
455 package body Dependency_Writers
is
457 -----------------------
458 -- Local subprograms --
459 -----------------------
461 procedure Write_Dependencies_Of_Vertex
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
468 procedure Write_Dependency_Edge
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
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
;
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
495 if Use_Formatting
then
497 Write_Line
("ELABORATION ORDER DEPENDENCIES");
501 Info_Prefix_Suppress
:= True;
503 Iter
:= Iterate_All_Vertices
(G
);
504 while Has_Next
(Iter
) loop
507 Write_Dependencies_Of_Vertex
(G
, Vertex
);
510 Info_Prefix_Suppress
:= False;
512 if Use_Formatting
then
515 end Write_Dependencies
;
517 ----------------------------------
518 -- Write_Dependencies_Of_Vertex --
519 ----------------------------------
521 procedure Write_Dependencies_Of_Vertex
523 Vertex
: Library_Graph_Vertex_Id
)
525 Edge
: Library_Graph_Edge_Id
;
526 Iter
: Edges_To_Successors_Iterator
;
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
)
540 Iter
:= Iterate_Edges_To_Successors
(G
, Vertex
);
541 while Has_Next
(Iter
) loop
544 Write_Dependency_Edge
(G
, Edge
);
546 end Write_Dependencies_Of_Vertex
;
548 ---------------------------
549 -- Write_Dependency_Edge --
550 ---------------------------
552 procedure Write_Dependency_Edge
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
);
563 -- Nothing to do for internal and predefined units
565 if Is_Internal_Unit
(G
, Succ
)
566 or else Is_Predefined_Unit
(G
, Succ
)
571 Error_Msg_Unit_1
:= Name
(G
, Pred
);
572 Error_Msg_Unit_2
:= Name
(G
, Succ
);
574 (Msg
=> " unit $ must be elaborated before unit $",
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
583 " reason: unit $ has with clause and pragma "
584 & "Elaborate_All for unit $",
587 elsif Is_Elaborate_Body_Edge
(G
, Edge
) then
589 (Msg
=> " reason: unit $ has with clause for unit $",
592 elsif Is_Elaborate_Edge
(G
, Edge
) then
595 " reason: unit $ has with clause and pragma Elaborate "
599 elsif Is_Forced_Edge
(G
, Edge
) then
602 " reason: unit $ has a dependency on unit $ forced by -f "
606 elsif Is_Invocation_Edge
(G
, Edge
) then
609 " reason: unit $ invokes a construct of unit $ at "
610 & "elaboration time",
613 elsif Is_Spec_Before_Body_Edge
(G
, Edge
) then
615 (Msg
=> " reason: spec must be elaborated before body",
619 pragma Assert
(Is_With_Edge
(G
, Edge
));
622 (Msg
=> " reason: unit $ has with clause for unit $",
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
;
654 -- Nothing to do when switch -l (output chosen elaboration order) is
657 if not Elab_Order_Output
then
661 if Use_Formatting
then
663 Write_Str
("ELABORATION ORDER");
669 if Use_Formatting
then
672 end Write_Elaboration_Order
;
678 procedure Write_Unit
(U_Id
: Unit_Id
) is
679 Use_Formatting
: constant Boolean := not Zero_Formatting
;
682 pragma Assert
(Present
(U_Id
));
684 if Use_Formatting
then
688 Write_Unit_Name
(Name
(U_Id
));
696 procedure Write_Units
(Order
: Unit_Id_Table
) is
698 for Index
in Unit_Id_Tables
.First
.. Unit_Id_Tables
.Last
(Order
) loop
699 Write_Unit
(Order
.Table
(Index
));
702 end Elaboration_Order_Writers
;
708 procedure Indent_By
(Indent
: Indentation_Level
) is
710 for Count
in 1 .. Indent
loop
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
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
768 (G
: Invocation_Graph
;
769 Edge
: Invocation_Graph_Edge_Id
) renames Write_Invocation_Graph_Edge
;
770 pragma Unreferenced
(pige
);
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
)
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
));
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
;
810 Write_Str
("Elaboration roots: ");
811 Write_Int
(Int
(Num_Of_Roots
));
814 if Num_Of_Roots
> 0 then
815 Iter
:= Iterate_Elaboration_Roots
(G
);
816 while Has_Next
(Iter
) loop
819 Write_Elaboration_Root
(G
, Root
);
824 end Write_Elaboration_Roots
;
826 ----------------------------
827 -- Write_Invocation_Graph --
828 ----------------------------
830 procedure Write_Invocation_Graph
(G
: Invocation_Graph
) is
832 pragma Assert
(Present
(G
));
834 -- Nothing to do when switch -d_I (output invocation graph) is not in
837 if not Debug_Flag_Underscore_II
then
841 Write_Str
("Invocation Graph");
845 Write_Statistics
(G
);
846 Write_Invocation_Graph_Vertices
(G
);
847 Write_Elaboration_Roots
(G
);
849 Write_Str
("Invocation Graph end");
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
);
869 Write_Str
(" invocation graph edge (IGE_Id_");
870 Write_Int
(Int
(Edge
));
874 Write_Str
(" Relation (IR_Id_");
875 Write_Int
(Int
(Relation
(G
, Edge
)));
879 Write_Str
(" Target (IGV_Id_");
880 Write_Int
(Int
(Targ
));
881 Write_Str
(") name = ");
882 Write_Name
(Name
(G
, Targ
));
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
;
906 Write_Str
(" Edges to targets: ");
907 Write_Int
(Int
(Num_Of_Edges
));
910 if Num_Of_Edges
> 0 then
911 Iter
:= Iterate_Edges_To_Targets
(G
, Vertex
);
912 while Has_Next
(Iter
) loop
915 Write_Invocation_Graph_Edge
(G
, Edge
);
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
)
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
));
940 Write_Str
(" Body_Vertex (LGV_Id_");
941 Write_Int
(Int
(Body_Vertex
(G
, Vertex
)));
945 Write_Str
(" Construct (IC_Id_");
946 Write_Int
(Int
(Construct
(G
, Vertex
)));
950 Write_Str
(" Spec_Vertex (LGV_Id_");
951 Write_Int
(Int
(Spec_Vertex
(G
, Vertex
)));
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
;
967 pragma Assert
(Present
(G
));
969 Iter
:= Iterate_All_Vertices
(G
);
970 while Has_Next
(Iter
) loop
973 Write_Invocation_Graph_Vertex
(G
, Vertex
);
975 end Write_Invocation_Graph_Vertices
;
977 ----------------------
978 -- Write_Statistics --
979 ----------------------
981 procedure Write_Statistics
(G
: Invocation_Graph
) is
983 pragma Assert
(Present
(G
));
985 Write_Str
("Edges : ");
986 Write_Num
(Int
(Number_Of_Edges
(G
)));
989 Write_Str
("Roots : ");
990 Write_Num
(Int
(Number_Of_Elaboration_Roots
(G
)));
993 Write_Str
("Vertices: ");
994 Write_Num
(Int
(Number_Of_Vertices
(G
)));
998 for Kind
in Invocation_Kind
'Range loop
1000 Write_Num
(Int
(Invocation_Graph_Edge_Count
(G
, Kind
)));
1002 Write_Str
(Kind
'Img);
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
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
1028 Comp
: Component_Id
);
1029 pragma Inline
(Write_Component_Vertices
);
1030 -- Write all vertices of component Comp of library graph G to standard
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
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
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
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
1071 Comp
: Component_Id
) renames Write_Component
;
1072 pragma Unreferenced
(pc
);
1076 Edge
: Library_Graph_Edge_Id
) renames Write_Library_Graph_Edge
;
1077 pragma Unreferenced
(plge
);
1081 Vertex
: Library_Graph_Vertex_Id
) renames Write_Library_Graph_Vertex
;
1082 pragma Unreferenced
(plgv
);
1084 ---------------------
1085 -- Write_Component --
1086 ---------------------
1088 procedure Write_Component
1090 Comp
: Component_Id
)
1093 pragma Assert
(Present
(G
));
1094 pragma Assert
(Present
(Comp
));
1096 Write_Str
("component (Comp_");
1097 Write_Int
(Int
(Comp
));
1101 Write_Str
(" Pending_Strong_Predecessors = ");
1102 Write_Int
(Int
(Pending_Strong_Predecessors
(G
, Comp
)));
1105 Write_Str
(" Pending_Weak_Predecessors = ");
1106 Write_Int
(Int
(Pending_Weak_Predecessors
(G
, Comp
)));
1109 Write_Component_Vertices
(G
, Comp
);
1112 end Write_Component
;
1114 ------------------------------
1115 -- Write_Component_Vertices --
1116 ------------------------------
1118 procedure Write_Component_Vertices
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
;
1132 Write_Str
(" Vertices: ");
1133 Write_Int
(Int
(Num_Of_Vertices
));
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
));
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
;
1165 -- Nothing to do when switch -d_L (output library item graph) is not
1168 if not Debug_Flag_Underscore_LL
then
1172 Write_Str
("Library Graph components");
1176 if Num_Of_Comps
> 0 then
1177 Write_Str
("Components: ");
1178 Write_Num
(Int
(Num_Of_Comps
));
1181 Iter
:= Iterate_Components
(G
);
1182 while Has_Next
(Iter
) loop
1185 Write_Component
(G
, Comp
);
1191 Write_Str
("Library Graph components end");
1195 end Write_Components
;
1197 -------------------------------
1198 -- Write_Edges_To_Successors --
1199 -------------------------------
1201 procedure Write_Edges_To_Successors
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
;
1215 Write_Str
(" Edges to successors: ");
1216 Write_Int
(Int
(Num_Of_Edges
));
1219 if Num_Of_Edges
> 0 then
1220 Iter
:= Iterate_Edges_To_Successors
(G
, Vertex
);
1221 while Has_Next
(Iter
) loop
1224 Write_Library_Graph_Edge
(G
, Edge
);
1229 end Write_Edges_To_Successors
;
1231 -------------------------
1232 -- Write_Library_Graph --
1233 -------------------------
1235 procedure Write_Library_Graph
(G
: Library_Graph
) is
1237 pragma Assert
(Present
(G
));
1239 -- Nothing to do when switch -d_L (output library item graph) is not
1242 if not Debug_Flag_Underscore_LL
then
1246 Write_Str
("Library Graph");
1250 Write_Statistics
(G
);
1251 Write_Library_Graph_Vertices
(G
);
1252 Write_Components
(G
);
1254 Write_Str
("Library Graph end");
1258 end Write_Library_Graph
;
1260 ------------------------------
1261 -- Write_Library_Graph_Edge --
1262 ------------------------------
1264 procedure Write_Library_Graph_Edge
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
);
1275 Write_Str
(" library graph edge (LGE_Id_");
1276 Write_Int
(Int
(Edge
));
1280 Write_Str
(" Kind = ");
1281 Write_Str
(Kind
(G
, Edge
)'Img);
1284 Write_Str
(" Predecessor (LGV_Id_");
1285 Write_Int
(Int
(Pred
));
1286 Write_Str
(") name = ");
1287 Write_Name
(Name
(G
, Pred
));
1290 Write_Str
(" Successor (LGV_Id_");
1291 Write_Int
(Int
(Succ
));
1292 Write_Str
(") name = ");
1293 Write_Name
(Name
(G
, Succ
));
1297 end Write_Library_Graph_Edge
;
1299 --------------------------------
1300 -- Write_Library_Graph_Vertex --
1301 --------------------------------
1303 procedure Write_Library_Graph_Vertex
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
);
1315 Write_Str
("library graph vertex (LGV_Id_");
1316 Write_Int
(Int
(Vertex
));
1317 Write_Str
(") name = ");
1318 Write_Name
(Name
(G
, Vertex
));
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
));
1327 Write_Str
(" Corresponding_Item = none");
1331 Write_Str
(" In_Elaboration_Order = ");
1333 if In_Elaboration_Order
(G
, Vertex
) then
1336 Write_Str
("False");
1340 Write_Str
(" Pending_Strong_Predecessors = ");
1341 Write_Int
(Int
(Pending_Strong_Predecessors
(G
, Vertex
)));
1344 Write_Str
(" Pending_Weak_Predecessors = ");
1345 Write_Int
(Int
(Pending_Weak_Predecessors
(G
, Vertex
)));
1348 Write_Str
(" Component (Comp_Id_");
1349 Write_Int
(Int
(Component
(G
, Vertex
)));
1353 Write_Str
(" Unit (U_Id_");
1354 Write_Int
(Int
(U_Id
));
1355 Write_Str
(") name = ");
1356 Write_Name
(Name
(U_Id
));
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
;
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
);
1379 end Write_Library_Graph_Vertices
;
1381 ----------------------
1382 -- Write_Statistics --
1383 ----------------------
1385 procedure Write_Statistics
(G
: Library_Graph
) is
1387 Write_Str
("Components: ");
1388 Write_Num
(Int
(Number_Of_Components
(G
)));
1391 Write_Str
("Edges : ");
1392 Write_Num
(Int
(Number_Of_Edges
(G
)));
1395 Write_Str
("Vertices : ");
1396 Write_Num
(Int
(Number_Of_Vertices
(G
)));
1400 for Kind
in Library_Graph_Edge_Kind
'Range loop
1402 Write_Num
(Int
(Library_Graph_Edge_Count
(G
, Kind
)));
1404 Write_Str
(Kind
'Img);
1409 end Write_Statistics
;
1410 end Library_Graph_Writers
;
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
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
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
1468 procedure End_Phase
(Phase
: Elaboration_Phase
) is
1470 Write_Phase_Message
(End_Messages
(Phase
));
1477 procedure Start_Phase
(Phase
: Elaboration_Phase
) is
1479 Write_Phase_Message
(Start_Messages
(Phase
));
1482 -------------------------
1483 -- Write_Phase_Message --
1484 -------------------------
1486 procedure Write_Phase_Message
(Msg
: Phase_Message
) is
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
1497 end Write_Phase_Message
;
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
,
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
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
1535 procedure Write_Unit_Closure
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
1556 pragma Assert
(Present
(Nam
));
1558 return Bucket_Range_Type
(Nam
);
1561 ---------------------
1562 -- Write_File_Name --
1563 ---------------------
1565 procedure Write_File_Name
(Nam
: File_Name_Type
) is
1566 Use_Formatting
: constant Boolean := not Zero_Formatting
;
1569 pragma Assert
(Present
(Nam
));
1571 if Use_Formatting
then
1575 Write_Line
(Get_Name_String
(Nam
));
1576 end Write_File_Name
;
1578 ---------------------------
1579 -- Write_Subunit_Closure --
1580 ---------------------------
1582 procedure Write_Subunit_Closure
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
));
1595 -- Nothing to do when the source file has already been written
1597 if Contains
(Set
, Source
) then
1600 -- Nothing to do when the source file does not denote a non-internal
1603 elsif not Present
(Dep_Rec
.Subunit_Name
)
1604 or else Is_Internal_File_Name
(Source
)
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
1621 pragma Assert
(Present
(Set
));
1623 for Dep
in Sdep
.First
.. Sdep
.Last
loop
1624 Write_Subunit_Closure
(Dep
, Set
);
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
;
1638 -- Nothing to do when switch -R (list sources referenced in closure)
1639 -- is not in effect.
1641 if not List_Closure
then
1645 if Use_Formatting
then
1647 Write_Line
("REFERENCED SOURCES");
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
);
1659 if Use_Formatting
then
1662 end Write_Unit_Closure
;
1664 ------------------------
1665 -- Write_Unit_Closure --
1666 ------------------------
1668 procedure Write_Unit_Closure
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
));
1681 -- Nothing to do when the source file has already been written
1683 if Contains
(Set
, Source
) then
1686 -- Nothing to do for internal source files unless switch -Ra (???) is
1689 elsif Is_Internal_File_Name
(Source
)
1690 and then not List_Closure_All
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
)
1710 pragma Assert
(Present
(Set
));
1712 for Index
in reverse Unit_Id_Tables
.First
..
1713 Unit_Id_Tables
.Last
(Order
)
1716 (U_Id
=> Order
.Table
(Index
),
1719 end Write_Units_Closure
;
1720 end Unit_Closure_Writers
;
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
;
1744 -- Treat zero as a single digit
1753 -- Shrink the input value by dividing it until all of its digits
1757 Indent
:= Indent
+ 1;
1762 return Val_Indent
- Indent
;
1763 end Digits_Indentation
;
1765 -- Start of processing for Write_Num
1768 Indent_By
(Digits_Indentation
);