1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2006, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with Alloc
; use Alloc
;
35 with Atree
; use Atree
;
36 with Casing
; use Casing
;
37 with Debug
; use Debug
;
38 with Einfo
; use Einfo
;
40 with Namet
; use Namet
;
42 with Output
; use Output
;
43 with Sinfo
; use Sinfo
;
44 with Sinput
; use Sinput
;
45 with Snames
; use Snames
;
46 with Stand
; use Stand
;
47 with Table
; use Table
;
48 with Uname
; use Uname
;
49 with Urealp
; use Urealp
;
51 with Ada
.Unchecked_Conversion
;
53 package body Repinfo
is
56 -- Value for Storage_Unit, we do not want to get this from TTypes, since
57 -- this introduces problematic dependencies in ASIS, and in any case this
58 -- value is assumed to be 8 for the implementation of the DDA.
60 -- This is wrong for AAMP???
62 ---------------------------------------
63 -- Representation of gcc Expressions --
64 ---------------------------------------
66 -- This table is used only if Frontend_Layout_On_Target is False, so that
67 -- gigi lays out dynamic size/offset fields using encoded gcc
70 -- A table internal to this unit is used to hold the values of back
71 -- annotated expressions. This table is written out by -gnatt and read
72 -- back in for ASIS processing.
74 -- Node values are stored as Uint values using the negative of the node
75 -- index in this table. Constants appear as non-negative Uint values.
77 type Exp_Node
is record
79 Op1
: Node_Ref_Or_Val
;
80 Op2
: Node_Ref_Or_Val
;
81 Op3
: Node_Ref_Or_Val
;
84 package Rep_Table
is new Table
.Table
(
85 Table_Component_Type
=> Exp_Node
,
86 Table_Index_Type
=> Nat
,
88 Table_Initial
=> Alloc
.Rep_Table_Initial
,
89 Table_Increment
=> Alloc
.Rep_Table_Increment
,
90 Table_Name
=> "BE_Rep_Table");
92 --------------------------------------------------------------
93 -- Representation of Front-End Dynamic Size/Offset Entities --
94 --------------------------------------------------------------
96 package Dynamic_SO_Entity_Table
is new Table
.Table
(
97 Table_Component_Type
=> Entity_Id
,
98 Table_Index_Type
=> Nat
,
100 Table_Initial
=> Alloc
.Rep_Table_Initial
,
101 Table_Increment
=> Alloc
.Rep_Table_Increment
,
102 Table_Name
=> "FE_Rep_Table");
104 Unit_Casing
: Casing_Type
;
105 -- Identifier casing for current unit
107 Need_Blank_Line
: Boolean;
108 -- Set True if a blank line is needed before outputting any information for
109 -- the current entity. Set True when a new entity is processed, and false
110 -- when the blank line is output.
112 -----------------------
113 -- Local Subprograms --
114 -----------------------
116 function Back_End_Layout
return Boolean;
117 -- Test for layout mode, True = back end, False = front end. This function
118 -- is used rather than checking the configuration parameter because we do
119 -- not want Repinfo to depend on Targparm (for ASIS)
121 procedure Blank_Line
;
122 -- Called before outputting anything for an entity. Ensures that
123 -- a blank line precedes the output for a particular entity.
125 procedure List_Entities
(Ent
: Entity_Id
);
126 -- This procedure lists the entities associated with the entity E, starting
127 -- with the First_Entity and using the Next_Entity link. If a nested
128 -- package is found, entities within the package are recursively processed.
130 procedure List_Name
(Ent
: Entity_Id
);
131 -- List name of entity Ent in appropriate case. The name is listed with
132 -- full qualification up to but not including the compilation unit name.
134 procedure List_Array_Info
(Ent
: Entity_Id
);
135 -- List representation info for array type Ent
137 procedure List_Mechanisms
(Ent
: Entity_Id
);
138 -- List mechanism information for parameters of Ent, which is subprogram,
139 -- subprogram type, or an entry or entry family.
141 procedure List_Object_Info
(Ent
: Entity_Id
);
142 -- List representation info for object Ent
144 procedure List_Record_Info
(Ent
: Entity_Id
);
145 -- List representation info for record type Ent
147 procedure List_Type_Info
(Ent
: Entity_Id
);
148 -- List type info for type Ent
150 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean;
151 -- Returns True if Val represents a variable value, and False if it
152 -- represents a value that is fixed at compile time.
154 procedure Spaces
(N
: Natural);
155 -- Output given number of spaces
157 procedure Write_Info_Line
(S
: String);
158 -- Routine to write a line to Repinfo output file. This routine is passed
159 -- as a special output procedure to Output.Set_Special_Output. Note that
160 -- Write_Info_Line is called with an EOL character at the end of each line,
161 -- as per the Output spec, but the internal call to the appropriate routine
162 -- in Osint requires that the end of line sequence be stripped off.
164 procedure Write_Mechanism
(M
: Mechanism_Type
);
165 -- Writes symbolic string for mechanism represented by M
167 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False);
168 -- Given a representation value, write it out. No_Uint values or values
169 -- dependent on discriminants are written as two question marks. If the
170 -- flag Paren is set, then the output is surrounded in parentheses if it is
171 -- other than a simple value.
173 ---------------------
174 -- Back_End_Layout --
175 ---------------------
177 function Back_End_Layout
return Boolean is
179 -- We have back end layout if the back end has made any entries in the
180 -- table of GCC expressions, otherwise we have front end layout.
182 return Rep_Table
.Last
> 0;
189 procedure Blank_Line
is
191 if Need_Blank_Line
then
193 Need_Blank_Line
:= False;
197 ------------------------
198 -- Create_Discrim_Ref --
199 ------------------------
201 function Create_Discrim_Ref
(Discr
: Entity_Id
) return Node_Ref
is
202 N
: constant Uint
:= Discriminant_Number
(Discr
);
205 Rep_Table
.Increment_Last
;
207 Rep_Table
.Table
(T
).Expr
:= Discrim_Val
;
208 Rep_Table
.Table
(T
).Op1
:= N
;
209 Rep_Table
.Table
(T
).Op2
:= No_Uint
;
210 Rep_Table
.Table
(T
).Op3
:= No_Uint
;
211 return UI_From_Int
(-T
);
212 end Create_Discrim_Ref
;
214 ---------------------------
215 -- Create_Dynamic_SO_Ref --
216 ---------------------------
218 function Create_Dynamic_SO_Ref
(E
: Entity_Id
) return Dynamic_SO_Ref
is
221 Dynamic_SO_Entity_Table
.Increment_Last
;
222 T
:= Dynamic_SO_Entity_Table
.Last
;
223 Dynamic_SO_Entity_Table
.Table
(T
) := E
;
224 return UI_From_Int
(-T
);
225 end Create_Dynamic_SO_Ref
;
233 Op1
: Node_Ref_Or_Val
;
234 Op2
: Node_Ref_Or_Val
:= No_Uint
;
235 Op3
: Node_Ref_Or_Val
:= No_Uint
) return Node_Ref
239 Rep_Table
.Increment_Last
;
241 Rep_Table
.Table
(T
).Expr
:= Expr
;
242 Rep_Table
.Table
(T
).Op1
:= Op1
;
243 Rep_Table
.Table
(T
).Op2
:= Op2
;
244 Rep_Table
.Table
(T
).Op3
:= Op3
;
245 return UI_From_Int
(-T
);
248 ---------------------------
249 -- Get_Dynamic_SO_Entity --
250 ---------------------------
252 function Get_Dynamic_SO_Entity
(U
: Dynamic_SO_Ref
) return Entity_Id
is
254 return Dynamic_SO_Entity_Table
.Table
(-UI_To_Int
(U
));
255 end Get_Dynamic_SO_Entity
;
257 -----------------------
258 -- Is_Dynamic_SO_Ref --
259 -----------------------
261 function Is_Dynamic_SO_Ref
(U
: SO_Ref
) return Boolean is
264 end Is_Dynamic_SO_Ref
;
266 ----------------------
267 -- Is_Static_SO_Ref --
268 ----------------------
270 function Is_Static_SO_Ref
(U
: SO_Ref
) return Boolean is
273 end Is_Static_SO_Ref
;
279 procedure lgx
(U
: Node_Ref_Or_Val
) is
281 List_GCC_Expression
(U
);
285 ----------------------
286 -- List_Array_Info --
287 ----------------------
289 procedure List_Array_Info
(Ent
: Entity_Id
) is
291 List_Type_Info
(Ent
);
294 Write_Str
("'Component_Size use ");
295 Write_Val
(Component_Size
(Ent
));
303 procedure List_Entities
(Ent
: Entity_Id
) is
307 function Find_Declaration
(E
: Entity_Id
) return Node_Id
;
308 -- Utility to retrieve declaration node for entity in the
309 -- case of package bodies and subprograms.
311 ----------------------
312 -- Find_Declaration --
313 ----------------------
315 function Find_Declaration
(E
: Entity_Id
) return Node_Id
is
321 and then Nkind
(Decl
) /= N_Package_Body
322 and then Nkind
(Decl
) /= N_Subprogram_Declaration
323 and then Nkind
(Decl
) /= N_Subprogram_Body
325 Decl
:= Parent
(Decl
);
329 end Find_Declaration
;
331 -- Start of processing for List_Entities
334 -- List entity if we have one, and it is not a renaming declaration.
335 -- For renamings, we don't get proper information, and really it makes
336 -- sense to restrict the output to the renamed entity.
339 and then Nkind
(Declaration_Node
(Ent
)) not in N_Renaming_Declaration
341 -- If entity is a subprogram and we are listing mechanisms,
342 -- then we need to list mechanisms for this entity.
344 if List_Representation_Info_Mechanisms
345 and then (Is_Subprogram
(Ent
)
346 or else Ekind
(Ent
) = E_Entry
347 or else Ekind
(Ent
) = E_Entry_Family
)
349 Need_Blank_Line
:= True;
350 List_Mechanisms
(Ent
);
353 E
:= First_Entity
(Ent
);
354 while Present
(E
) loop
355 Need_Blank_Line
:= True;
357 -- We list entities that come from source (excluding private or
358 -- incomplete types or deferred constants, where we will list the
359 -- info for the full view). If debug flag A is set, then all
360 -- entities are listed
362 if (Comes_From_Source
(E
)
363 and then not Is_Incomplete_Or_Private_Type
(E
)
364 and then not (Ekind
(E
) = E_Constant
365 and then Present
(Full_View
(E
))))
366 or else Debug_Flag_AA
372 Ekind
(E
) = E_Entry_Family
374 Ekind
(E
) = E_Subprogram_Type
376 if List_Representation_Info_Mechanisms
then
380 elsif Is_Record_Type
(E
) then
381 if List_Representation_Info
>= 1 then
382 List_Record_Info
(E
);
385 elsif Is_Array_Type
(E
) then
386 if List_Representation_Info
>= 1 then
390 elsif Is_Type
(E
) then
391 if List_Representation_Info
>= 2 then
395 elsif Ekind
(E
) = E_Variable
397 Ekind
(E
) = E_Constant
399 Ekind
(E
) = E_Loop_Parameter
403 if List_Representation_Info
>= 2 then
404 List_Object_Info
(E
);
409 -- Recurse into nested package, but not if they are package
410 -- renamings (in particular renamings of the enclosing package,
411 -- as for some Java bindings and for generic instances).
413 if Ekind
(E
) = E_Package
then
414 if No
(Renamed_Object
(E
)) then
418 -- Recurse into bodies
420 elsif Ekind
(E
) = E_Protected_Type
422 Ekind
(E
) = E_Task_Type
424 Ekind
(E
) = E_Subprogram_Body
426 Ekind
(E
) = E_Package_Body
428 Ekind
(E
) = E_Task_Body
430 Ekind
(E
) = E_Protected_Body
434 -- Recurse into blocks
436 elsif Ekind
(E
) = E_Block
then
441 E
:= Next_Entity
(E
);
444 -- For a package body, the entities of the visible subprograms are
445 -- declared in the corresponding spec. Iterate over its entities in
446 -- order to handle properly the subprogram bodies. Skip bodies in
447 -- subunits, which are listed independently.
449 if Ekind
(Ent
) = E_Package_Body
450 and then Present
(Corresponding_Spec
(Find_Declaration
(Ent
)))
452 E
:= First_Entity
(Corresponding_Spec
(Find_Declaration
(Ent
)));
454 while Present
(E
) loop
457 Nkind
(Find_Declaration
(E
)) = N_Subprogram_Declaration
459 Body_E
:= Corresponding_Body
(Find_Declaration
(E
));
463 Nkind
(Parent
(Find_Declaration
(Body_E
))) /= N_Subunit
465 List_Entities
(Body_E
);
475 -------------------------
476 -- List_GCC_Expression --
477 -------------------------
479 procedure List_GCC_Expression
(U
: Node_Ref_Or_Val
) is
481 procedure Print_Expr
(Val
: Node_Ref_Or_Val
);
482 -- Internal recursive procedure to print expression
488 procedure Print_Expr
(Val
: Node_Ref_Or_Val
) is
491 UI_Write
(Val
, Decimal
);
495 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
497 procedure Binop
(S
: String);
498 -- Output text for binary operator with S being operator name
504 procedure Binop
(S
: String) is
507 Print_Expr
(Node
.Op1
);
509 Print_Expr
(Node
.Op2
);
513 -- Start of processing for Print_Expr
519 Print_Expr
(Node
.Op1
);
520 Write_Str
(" then ");
521 Print_Expr
(Node
.Op2
);
522 Write_Str
(" else ");
523 Print_Expr
(Node
.Op3
);
535 when Trunc_Div_Expr
=>
538 when Ceil_Div_Expr
=>
541 when Floor_Div_Expr
=>
544 when Trunc_Mod_Expr
=>
547 when Floor_Mod_Expr
=>
550 when Ceil_Mod_Expr
=>
553 when Exact_Div_Expr
=>
558 Print_Expr
(Node
.Op1
);
568 Print_Expr
(Node
.Op1
);
570 when Truth_Andif_Expr
=>
573 when Truth_Orif_Expr
=>
576 when Truth_And_Expr
=>
579 when Truth_Or_Expr
=>
582 when Truth_Xor_Expr
=>
585 when Truth_Not_Expr
=>
587 Print_Expr
(Node
.Op1
);
619 -- Start of processing for List_GCC_Expression
627 end List_GCC_Expression
;
629 ---------------------
630 -- List_Mechanisms --
631 ---------------------
633 procedure List_Mechanisms
(Ent
: Entity_Id
) is
642 Write_Str
("function ");
645 Write_Str
("operator ");
648 Write_Str
("procedure ");
650 when E_Subprogram_Type
=>
653 when E_Entry | E_Entry_Family
=>
654 Write_Str
("entry ");
660 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
661 Write_Str
(Name_Buffer
(1 .. Name_Len
));
662 Write_Str
(" declared at ");
663 Write_Location
(Sloc
(Ent
));
666 Write_Str
(" convention : ");
668 case Convention
(Ent
) is
669 when Convention_Ada
=> Write_Line
("Ada");
670 when Convention_Intrinsic
=> Write_Line
("InLineinsic");
671 when Convention_Entry
=> Write_Line
("Entry");
672 when Convention_Protected
=> Write_Line
("Protected");
673 when Convention_Assembler
=> Write_Line
("Assembler");
674 when Convention_C
=> Write_Line
("C");
675 when Convention_COBOL
=> Write_Line
("COBOL");
676 when Convention_CPP
=> Write_Line
("C++");
677 when Convention_Fortran
=> Write_Line
("Fortran");
678 when Convention_Java
=> Write_Line
("Java");
679 when Convention_Stdcall
=> Write_Line
("Stdcall");
680 when Convention_Stubbed
=> Write_Line
("Stubbed");
683 -- Find max length of formal name
686 Form
:= First_Formal
(Ent
);
687 while Present
(Form
) loop
688 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
690 if Name_Len
> Plen
then
697 -- Output formals and mechanisms
699 Form
:= First_Formal
(Ent
);
700 while Present
(Form
) loop
701 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
703 while Name_Len
<= Plen
loop
704 Name_Len
:= Name_Len
+ 1;
705 Name_Buffer
(Name_Len
) := ' ';
709 Write_Str
(Name_Buffer
(1 .. Plen
+ 1));
710 Write_Str
(": passed by ");
712 Write_Mechanism
(Mechanism
(Form
));
717 if Etype
(Ent
) /= Standard_Void_Type
then
718 Write_Str
(" returns by ");
719 Write_Mechanism
(Mechanism
(Ent
));
728 procedure List_Name
(Ent
: Entity_Id
) is
730 if not Is_Compilation_Unit
(Scope
(Ent
)) then
731 List_Name
(Scope
(Ent
));
735 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
736 Set_Casing
(Unit_Casing
);
737 Write_Str
(Name_Buffer
(1 .. Name_Len
));
740 ---------------------
741 -- List_Object_Info --
742 ---------------------
744 procedure List_Object_Info
(Ent
: Entity_Id
) is
750 Write_Str
("'Size use ");
751 Write_Val
(Esize
(Ent
));
756 Write_Str
("'Alignment use ");
757 Write_Val
(Alignment
(Ent
));
759 end List_Object_Info
;
761 ----------------------
762 -- List_Record_Info --
763 ----------------------
765 procedure List_Record_Info
(Ent
: Entity_Id
) is
770 Max_Name_Length
: Natural;
771 Max_Suni_Length
: Natural;
775 List_Type_Info
(Ent
);
779 Write_Line
(" use record");
781 -- First loop finds out max line length and max starting position
782 -- length, for the purpose of lining things up nicely.
784 Max_Name_Length
:= 0;
785 Max_Suni_Length
:= 0;
787 Comp
:= First_Entity
(Ent
);
788 while Present
(Comp
) loop
789 if Ekind
(Comp
) = E_Component
790 or else Ekind
(Comp
) = E_Discriminant
792 Get_Decoded_Name_String
(Chars
(Comp
));
793 Max_Name_Length
:= Natural'Max (Max_Name_Length
, Name_Len
);
795 Cfbit
:= Component_Bit_Offset
(Comp
);
797 if Rep_Not_Constant
(Cfbit
) then
798 UI_Image_Length
:= 2;
801 -- Complete annotation in case not done
803 Set_Normalized_Position
(Comp
, Cfbit
/ SSU
);
804 Set_Normalized_First_Bit
(Comp
, Cfbit
mod SSU
);
806 Sunit
:= Cfbit
/ SSU
;
810 -- If the record is not packed, then we know that all fields whose
811 -- position is not specified have a starting normalized bit
814 if Unknown_Normalized_First_Bit
(Comp
)
815 and then not Is_Packed
(Ent
)
817 Set_Normalized_First_Bit
(Comp
, Uint_0
);
821 Natural'Max (Max_Suni_Length
, UI_Image_Length
);
824 Comp
:= Next_Entity
(Comp
);
827 -- Second loop does actual output based on those values
829 Comp
:= First_Entity
(Ent
);
830 while Present
(Comp
) loop
831 if Ekind
(Comp
) = E_Component
832 or else Ekind
(Comp
) = E_Discriminant
835 Esiz
: constant Uint
:= Esize
(Comp
);
836 Bofs
: constant Uint
:= Component_Bit_Offset
(Comp
);
837 Npos
: constant Uint
:= Normalized_Position
(Comp
);
838 Fbit
: constant Uint
:= Normalized_First_Bit
(Comp
);
843 Get_Decoded_Name_String
(Chars
(Comp
));
844 Set_Casing
(Unit_Casing
);
845 Write_Str
(Name_Buffer
(1 .. Name_Len
));
847 for J
in 1 .. Max_Name_Length
- Name_Len
loop
853 if Known_Static_Normalized_Position
(Comp
) then
855 Spaces
(Max_Suni_Length
- UI_Image_Length
);
856 Write_Str
(UI_Image_Buffer
(1 .. UI_Image_Length
));
858 elsif Known_Component_Bit_Offset
(Comp
)
859 and then List_Representation_Info
= 3
861 Spaces
(Max_Suni_Length
- 2);
862 Write_Str
("bit offset");
863 Write_Val
(Bofs
, Paren
=> True);
864 Write_Str
(" size in bits = ");
865 Write_Val
(Esiz
, Paren
=> True);
869 elsif Known_Normalized_Position
(Comp
)
870 and then List_Representation_Info
= 3
872 Spaces
(Max_Suni_Length
- 2);
876 -- For the packed case, we don't know the bit positions
877 -- if we don't know the starting position!
879 if Is_Packed
(Ent
) then
880 Write_Line
("?? range ? .. ??;");
883 -- Otherwise we can continue
890 Write_Str
(" range ");
894 -- Allowing Uint_0 here is a kludge, really this should be a
895 -- fine Esize value but currently it means unknown, except that
896 -- we know after gigi has back annotated that a size of zero is
897 -- real, since otherwise gigi back annotates using No_Uint as
898 -- the value to indicate unknown).
900 if (Esize
(Comp
) = Uint_0
or else Known_Static_Esize
(Comp
))
901 and then Known_Static_Normalized_First_Bit
(Comp
)
903 Lbit
:= Fbit
+ Esiz
- 1;
911 -- The test for Esize (Comp) not being Uint_0 here is a kludge.
912 -- Officially a value of zero for Esize means unknown, but here
913 -- we use the fact that we know that gigi annotates Esize with
914 -- No_Uint, not Uint_0. Really everyone should use No_Uint???
916 elsif List_Representation_Info
< 3
917 or else (Esize
(Comp
) /= Uint_0
and then Unknown_Esize
(Comp
))
921 else -- List_Representation >= 3 and Known_Esize (Comp)
923 Write_Val
(Esiz
, Paren
=> True);
925 -- If in front end layout mode, then dynamic size is stored
926 -- in storage units, so renormalize for output
928 if not Back_End_Layout
then
933 -- Add appropriate first bit offset
943 Write_Int
(UI_To_Int
(Fbit
) - 1);
952 Comp
:= Next_Entity
(Comp
);
955 Write_Line
("end record;");
956 end List_Record_Info
;
962 procedure List_Rep_Info
is
966 if List_Representation_Info
/= 0
967 or else List_Representation_Info_Mechanisms
969 for U
in Main_Unit
.. Last_Unit
loop
970 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
)) then
972 -- Normal case, list to standard output
974 if not List_Representation_Info_To_File
then
975 Unit_Casing
:= Identifier_Casing
(Source_Index
(U
));
977 Write_Str
("Representation information for unit ");
978 Write_Unit_Name
(Unit_Name
(U
));
982 for J
in 1 .. Col
- 1 loop
987 List_Entities
(Cunit_Entity
(U
));
989 -- List representation information to file
992 Create_Repinfo_File_Access
.all
993 (File_Name
(Source_Index
(U
)));
994 Set_Special_Output
(Write_Info_Line
'Access);
995 List_Entities
(Cunit_Entity
(U
));
996 Set_Special_Output
(null);
997 Close_Repinfo_File_Access
.all;
1004 --------------------
1005 -- List_Type_Info --
1006 --------------------
1008 procedure List_Type_Info
(Ent
: Entity_Id
) is
1012 -- Do not list size info for unconstrained arrays, not meaningful
1014 if Is_Array_Type
(Ent
) and then not Is_Constrained
(Ent
) then
1018 -- If Esize and RM_Size are the same and known, list as Size. This
1019 -- is a common case, which we may as well list in simple form.
1021 if Esize
(Ent
) = RM_Size
(Ent
) then
1024 Write_Str
("'Size use ");
1025 Write_Val
(Esize
(Ent
));
1028 -- For now, temporary case, to be removed when gigi properly back
1029 -- annotates RM_Size, if RM_Size is not set, then list Esize as Size.
1030 -- This avoids odd Object_Size output till we fix things???
1032 elsif Unknown_RM_Size
(Ent
) then
1035 Write_Str
("'Size use ");
1036 Write_Val
(Esize
(Ent
));
1039 -- Otherwise list size values separately if they are set
1044 Write_Str
("'Object_Size use ");
1045 Write_Val
(Esize
(Ent
));
1048 -- Note on following check: The RM_Size of a discrete type can
1049 -- legitimately be set to zero, so a special check is needed.
1053 Write_Str
("'Value_Size use ");
1054 Write_Val
(RM_Size
(Ent
));
1061 Write_Str
("'Alignment use ");
1062 Write_Val
(Alignment
(Ent
));
1066 ----------------------
1067 -- Rep_Not_Constant --
1068 ----------------------
1070 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean is
1072 if Val
= No_Uint
or else Val
< 0 then
1077 end Rep_Not_Constant
;
1084 (Val
: Node_Ref_Or_Val
;
1085 D
: Discrim_List
) return Uint
1087 function B
(Val
: Boolean) return Uint
;
1088 -- Returns Uint_0 for False, Uint_1 for True
1090 function T
(Val
: Node_Ref_Or_Val
) return Boolean;
1091 -- Returns True for 0, False for any non-zero (i.e. True)
1093 function V
(Val
: Node_Ref_Or_Val
) return Uint
;
1094 -- Internal recursive routine to evaluate tree
1096 function W
(Val
: Uint
) return Word
;
1097 -- Convert Val to Word, assuming Val is always in the Int range. This is
1098 -- a helper function for the evaluation of bitwise expressions like
1099 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
1100 -- values out of the Int range are expected to be seen in such
1101 -- expressions only with overflowing byte sizes around, introducing
1102 -- inherent unreliabilties in computations anyway.
1108 function B
(Val
: Boolean) return Uint
is
1121 function T
(Val
: Node_Ref_Or_Val
) return Boolean is
1134 function V
(Val
: Node_Ref_Or_Val
) return Uint
is
1143 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
1148 if T
(Node
.Op1
) then
1149 return V
(Node
.Op2
);
1151 return V
(Node
.Op3
);
1155 return V
(Node
.Op1
) + V
(Node
.Op2
);
1158 return V
(Node
.Op1
) - V
(Node
.Op2
);
1161 return V
(Node
.Op1
) * V
(Node
.Op2
);
1163 when Trunc_Div_Expr
=>
1164 return V
(Node
.Op1
) / V
(Node
.Op2
);
1166 when Ceil_Div_Expr
=>
1169 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
1171 when Floor_Div_Expr
=>
1174 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
1176 when Trunc_Mod_Expr
=>
1177 return V
(Node
.Op1
) rem V
(Node
.Op2
);
1179 when Floor_Mod_Expr
=>
1180 return V
(Node
.Op1
) mod V
(Node
.Op2
);
1182 when Ceil_Mod_Expr
=>
1185 Q
:= UR_Ceiling
(L
/ UR_From_Uint
(R
));
1188 when Exact_Div_Expr
=>
1189 return V
(Node
.Op1
) / V
(Node
.Op2
);
1192 return -V
(Node
.Op1
);
1195 return UI_Min
(V
(Node
.Op1
), V
(Node
.Op2
));
1198 return UI_Max
(V
(Node
.Op1
), V
(Node
.Op2
));
1201 return UI_Abs
(V
(Node
.Op1
));
1203 when Truth_Andif_Expr
=>
1204 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
1206 when Truth_Orif_Expr
=>
1207 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
1209 when Truth_And_Expr
=>
1210 return B
(T
(Node
.Op1
) and T
(Node
.Op2
));
1212 when Truth_Or_Expr
=>
1213 return B
(T
(Node
.Op1
) or T
(Node
.Op2
));
1215 when Truth_Xor_Expr
=>
1216 return B
(T
(Node
.Op1
) xor T
(Node
.Op2
));
1218 when Truth_Not_Expr
=>
1219 return B
(not T
(Node
.Op1
));
1221 when Bit_And_Expr
=>
1224 return UI_From_Int
(Int
(W
(L
) and W
(R
)));
1227 return B
(V
(Node
.Op1
) < V
(Node
.Op2
));
1230 return B
(V
(Node
.Op1
) <= V
(Node
.Op2
));
1233 return B
(V
(Node
.Op1
) > V
(Node
.Op2
));
1236 return B
(V
(Node
.Op1
) >= V
(Node
.Op2
));
1239 return B
(V
(Node
.Op1
) = V
(Node
.Op2
));
1242 return B
(V
(Node
.Op1
) /= V
(Node
.Op2
));
1246 Sub
: constant Int
:= UI_To_Int
(Node
.Op1
);
1249 pragma Assert
(Sub
in D
'Range);
1262 -- We use an unchecked conversion to map Int values to their Word
1263 -- bitwise equivalent, which we could not achieve with a normal type
1264 -- conversion for negative Ints. We want bitwise equivalents because W
1265 -- is used as a helper for bit operators like Bit_And_Expr, and can be
1266 -- called for negative Ints in the context of aligning expressions like
1267 -- X+Align & -Align.
1269 function W
(Val
: Uint
) return Word
is
1270 function To_Word
is new Ada
.Unchecked_Conversion
(Int
, Word
);
1272 return To_Word
(UI_To_Int
(Val
));
1275 -- Start of processing for Rep_Value
1278 if Val
= No_Uint
then
1290 procedure Spaces
(N
: Natural) is
1292 for J
in 1 .. N
loop
1301 procedure Tree_Read
is
1303 Rep_Table
.Tree_Read
;
1310 procedure Tree_Write
is
1312 Rep_Table
.Tree_Write
;
1315 ---------------------
1316 -- Write_Info_Line --
1317 ---------------------
1319 procedure Write_Info_Line
(S
: String) is
1321 Write_Repinfo_Line_Access
.all (S
(S
'First .. S
'Last - 1));
1322 end Write_Info_Line
;
1324 ---------------------
1325 -- Write_Mechanism --
1326 ---------------------
1328 procedure Write_Mechanism
(M
: Mechanism_Type
) is
1332 Write_Str
("default");
1338 Write_Str
("reference");
1341 Write_Str
("descriptor");
1344 Write_Str
("descriptor (UBS)");
1347 Write_Str
("descriptor (UBSB)");
1350 Write_Str
("descriptor (UBA)");
1353 Write_Str
("descriptor (S)");
1356 Write_Str
("descriptor (SB)");
1359 Write_Str
("descriptor (A)");
1362 Write_Str
("descriptor (NCA)");
1365 raise Program_Error
;
1367 end Write_Mechanism
;
1373 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False) is
1375 if Rep_Not_Constant
(Val
) then
1376 if List_Representation_Info
< 3 or else Val
= No_Uint
then
1380 if Back_End_Layout
then
1385 List_GCC_Expression
(Val
);
1388 List_GCC_Expression
(Val
);
1396 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));
1399 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));