1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2016, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Alloc
; use Alloc
;
33 with Atree
; use Atree
;
34 with Casing
; use Casing
;
35 with Debug
; use Debug
;
36 with Einfo
; use Einfo
;
38 with Namet
; use Namet
;
39 with Nlists
; use Nlists
;
41 with Output
; use Output
;
42 with Sem_Aux
; use Sem_Aux
;
43 with Sinfo
; use Sinfo
;
44 with Sinput
; use Sinput
;
45 with Snames
; use Snames
;
46 with Stand
; use Stand
;
47 with Stringt
; use Stringt
;
48 with Table
; use Table
;
49 with Uname
; use Uname
;
50 with Urealp
; use Urealp
;
52 with Ada
.Unchecked_Conversion
;
54 package body Repinfo
is
57 -- Value for Storage_Unit, we do not want to get this from TTypes, since
58 -- this introduces problematic dependencies in ASIS, and in any case this
59 -- value is assumed to be 8 for the implementation of the DDA.
61 ---------------------------------------
62 -- Representation of gcc Expressions --
63 ---------------------------------------
65 -- This table is used only if Frontend_Layout_On_Target is False, so gigi
66 -- lays out dynamic size/offset fields using encoded gcc expressions.
68 -- A table internal to this unit is used to hold the values of back
69 -- annotated expressions. This table is written out by -gnatt and read
70 -- back in for ASIS processing.
72 -- Node values are stored as Uint values using the negative of the node
73 -- index in this table. Constants appear as non-negative Uint values.
75 type Exp_Node
is record
77 Op1
: Node_Ref_Or_Val
;
78 Op2
: Node_Ref_Or_Val
;
79 Op3
: Node_Ref_Or_Val
;
82 -- The following representation clause ensures that the above record
83 -- has no holes. We do this so that when instances of this record are
84 -- written by Tree_Gen, we do not write uninitialized values to the file.
86 for Exp_Node
use record
87 Expr
at 0 range 0 .. 31;
88 Op1
at 4 range 0 .. 31;
89 Op2
at 8 range 0 .. 31;
90 Op3
at 12 range 0 .. 31;
93 for Exp_Node
'Size use 16 * 8;
94 -- This ensures that we did not leave out any fields
96 package Rep_Table
is new Table
.Table
(
97 Table_Component_Type
=> Exp_Node
,
98 Table_Index_Type
=> Nat
,
100 Table_Initial
=> Alloc
.Rep_Table_Initial
,
101 Table_Increment
=> Alloc
.Rep_Table_Increment
,
102 Table_Name
=> "BE_Rep_Table");
104 --------------------------------------------------------------
105 -- Representation of Front-End Dynamic Size/Offset Entities --
106 --------------------------------------------------------------
108 package Dynamic_SO_Entity_Table
is new Table
.Table
(
109 Table_Component_Type
=> Entity_Id
,
110 Table_Index_Type
=> Nat
,
111 Table_Low_Bound
=> 1,
112 Table_Initial
=> Alloc
.Rep_Table_Initial
,
113 Table_Increment
=> Alloc
.Rep_Table_Increment
,
114 Table_Name
=> "FE_Rep_Table");
116 Unit_Casing
: Casing_Type
;
117 -- Identifier casing for current unit. This is set by List_Rep_Info for
118 -- each unit, before calling subprograms which may read it.
120 Need_Blank_Line
: Boolean;
121 -- Set True if a blank line is needed before outputting any information for
122 -- the current entity. Set True when a new entity is processed, and false
123 -- when the blank line is output.
125 -----------------------
126 -- Local Subprograms --
127 -----------------------
129 function Back_End_Layout
return Boolean;
130 -- Test for layout mode, True = back end, False = front end. This function
131 -- is used rather than checking the configuration parameter because we do
132 -- not want Repinfo to depend on Targparm (for ASIS)
134 procedure Blank_Line
;
135 -- Called before outputting anything for an entity. Ensures that
136 -- a blank line precedes the output for a particular entity.
138 procedure List_Entities
140 Bytes_Big_Endian
: Boolean;
141 In_Subprogram
: Boolean := False);
142 -- This procedure lists the entities associated with the entity E, starting
143 -- with the First_Entity and using the Next_Entity link. If a nested
144 -- package is found, entities within the package are recursively processed.
145 -- When recursing within a subprogram body, Is_Subprogram suppresses
146 -- duplicate information about signature.
148 procedure List_Name
(Ent
: Entity_Id
);
149 -- List name of entity Ent in appropriate case. The name is listed with
150 -- full qualification up to but not including the compilation unit name.
152 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
153 -- List representation info for array type Ent
155 procedure List_Linker_Section
(Ent
: Entity_Id
);
156 -- List linker section for Ent (caller has checked that Ent is an entity
157 -- for which the Linker_Section_Pragma field is defined).
159 procedure List_Mechanisms
(Ent
: Entity_Id
);
160 -- List mechanism information for parameters of Ent, which is subprogram,
161 -- subprogram type, or an entry or entry family.
163 procedure List_Object_Info
(Ent
: Entity_Id
);
164 -- List representation info for object Ent
166 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
167 -- List representation info for record type Ent
169 procedure List_Scalar_Storage_Order
171 Bytes_Big_Endian
: Boolean);
172 -- List scalar storage order information for record or array type Ent.
173 -- Also includes bit order information for record types, if necessary.
175 procedure List_Type_Info
(Ent
: Entity_Id
);
176 -- List type info for type Ent
178 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean;
179 -- Returns True if Val represents a variable value, and False if it
180 -- represents a value that is fixed at compile time.
182 procedure Spaces
(N
: Natural);
183 -- Output given number of spaces
185 procedure Write_Info_Line
(S
: String);
186 -- Routine to write a line to Repinfo output file. This routine is passed
187 -- as a special output procedure to Output.Set_Special_Output. Note that
188 -- Write_Info_Line is called with an EOL character at the end of each line,
189 -- as per the Output spec, but the internal call to the appropriate routine
190 -- in Osint requires that the end of line sequence be stripped off.
192 procedure Write_Mechanism
(M
: Mechanism_Type
);
193 -- Writes symbolic string for mechanism represented by M
195 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False);
196 -- Given a representation value, write it out. No_Uint values or values
197 -- dependent on discriminants are written as two question marks. If the
198 -- flag Paren is set, then the output is surrounded in parentheses if it is
199 -- other than a simple value.
201 ---------------------
202 -- Back_End_Layout --
203 ---------------------
205 function Back_End_Layout
return Boolean is
207 -- We have back end layout if the back end has made any entries in the
208 -- table of GCC expressions, otherwise we have front end layout.
210 return Rep_Table
.Last
> 0;
217 procedure Blank_Line
is
219 if Need_Blank_Line
then
221 Need_Blank_Line
:= False;
225 ------------------------
226 -- Create_Discrim_Ref --
227 ------------------------
229 function Create_Discrim_Ref
(Discr
: Entity_Id
) return Node_Ref
is
232 (Expr
=> Discrim_Val
,
233 Op1
=> Discriminant_Number
(Discr
));
234 end Create_Discrim_Ref
;
236 ---------------------------
237 -- Create_Dynamic_SO_Ref --
238 ---------------------------
240 function Create_Dynamic_SO_Ref
(E
: Entity_Id
) return Dynamic_SO_Ref
is
242 Dynamic_SO_Entity_Table
.Append
(E
);
243 return UI_From_Int
(-Dynamic_SO_Entity_Table
.Last
);
244 end Create_Dynamic_SO_Ref
;
252 Op1
: Node_Ref_Or_Val
;
253 Op2
: Node_Ref_Or_Val
:= No_Uint
;
254 Op3
: Node_Ref_Or_Val
:= No_Uint
) return Node_Ref
262 return UI_From_Int
(-Rep_Table
.Last
);
265 ---------------------------
266 -- Get_Dynamic_SO_Entity --
267 ---------------------------
269 function Get_Dynamic_SO_Entity
(U
: Dynamic_SO_Ref
) return Entity_Id
is
271 return Dynamic_SO_Entity_Table
.Table
(-UI_To_Int
(U
));
272 end Get_Dynamic_SO_Entity
;
274 -----------------------
275 -- Is_Dynamic_SO_Ref --
276 -----------------------
278 function Is_Dynamic_SO_Ref
(U
: SO_Ref
) return Boolean is
281 end Is_Dynamic_SO_Ref
;
283 ----------------------
284 -- Is_Static_SO_Ref --
285 ----------------------
287 function Is_Static_SO_Ref
(U
: SO_Ref
) return Boolean is
290 end Is_Static_SO_Ref
;
296 procedure lgx
(U
: Node_Ref_Or_Val
) is
298 List_GCC_Expression
(U
);
302 ----------------------
303 -- List_Array_Info --
304 ----------------------
306 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
308 List_Type_Info
(Ent
);
311 Write_Str
("'Component_Size use ");
312 Write_Val
(Component_Size
(Ent
));
315 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
322 procedure List_Entities
324 Bytes_Big_Endian
: Boolean;
325 In_Subprogram
: Boolean := False)
330 function Find_Declaration
(E
: Entity_Id
) return Node_Id
;
331 -- Utility to retrieve declaration node for entity in the
332 -- case of package bodies and subprograms.
334 ----------------------
335 -- Find_Declaration --
336 ----------------------
338 function Find_Declaration
(E
: Entity_Id
) return Node_Id
is
344 and then Nkind
(Decl
) /= N_Package_Body
345 and then Nkind
(Decl
) /= N_Subprogram_Declaration
346 and then Nkind
(Decl
) /= N_Subprogram_Body
348 Decl
:= Parent
(Decl
);
352 end Find_Declaration
;
354 -- Start of processing for List_Entities
357 -- List entity if we have one, and it is not a renaming declaration.
358 -- For renamings, we don't get proper information, and really it makes
359 -- sense to restrict the output to the renamed entity.
362 and then Nkind
(Declaration_Node
(Ent
)) not in N_Renaming_Declaration
364 -- If entity is a subprogram and we are listing mechanisms,
365 -- then we need to list mechanisms for this entity. We skip this
366 -- if it is a nested subprogram, as the information has already
367 -- been produced when listing the enclosing scope.
369 if List_Representation_Info_Mechanisms
370 and then (Is_Subprogram
(Ent
)
371 or else Ekind
(Ent
) = E_Entry
372 or else Ekind
(Ent
) = E_Entry_Family
)
373 and then not In_Subprogram
375 Need_Blank_Line
:= True;
376 List_Mechanisms
(Ent
);
379 E
:= First_Entity
(Ent
);
380 while Present
(E
) loop
381 Need_Blank_Line
:= True;
383 -- We list entities that come from source (excluding private or
384 -- incomplete types or deferred constants, where we will list the
385 -- info for the full view). If debug flag A is set, then all
386 -- entities are listed
388 if (Comes_From_Source
(E
)
389 and then not Is_Incomplete_Or_Private_Type
(E
)
390 and then not (Ekind
(E
) = E_Constant
391 and then Present
(Full_View
(E
))))
392 or else Debug_Flag_AA
394 if Is_Subprogram
(E
) then
395 List_Linker_Section
(E
);
397 if List_Representation_Info_Mechanisms
then
401 -- Recurse into entities local to subprogram
403 List_Entities
(E
, Bytes_Big_Endian
, True);
405 elsif Ekind
(E
) in Formal_Kind
and then In_Subprogram
then
408 elsif Ekind_In
(E
, E_Entry
,
412 if List_Representation_Info_Mechanisms
then
416 elsif Is_Record_Type
(E
) then
417 if List_Representation_Info
>= 1 then
418 List_Record_Info
(E
, Bytes_Big_Endian
);
421 List_Linker_Section
(E
);
423 elsif Is_Array_Type
(E
) then
424 if List_Representation_Info
>= 1 then
425 List_Array_Info
(E
, Bytes_Big_Endian
);
428 List_Linker_Section
(E
);
430 elsif Is_Type
(E
) then
431 if List_Representation_Info
>= 2 then
433 List_Linker_Section
(E
);
436 elsif Ekind_In
(E
, E_Variable
, E_Constant
) then
437 if List_Representation_Info
>= 2 then
438 List_Object_Info
(E
);
439 List_Linker_Section
(E
);
442 elsif Ekind
(E
) = E_Loop_Parameter
or else Is_Formal
(E
) then
443 if List_Representation_Info
>= 2 then
444 List_Object_Info
(E
);
448 -- Recurse into nested package, but not if they are package
449 -- renamings (in particular renamings of the enclosing package,
450 -- as for some Java bindings and for generic instances).
452 if Ekind
(E
) = E_Package
then
453 if No
(Renamed_Object
(E
)) then
454 List_Entities
(E
, Bytes_Big_Endian
);
457 -- Recurse into bodies
459 elsif Ekind_In
(E
, E_Protected_Type
,
466 List_Entities
(E
, Bytes_Big_Endian
);
468 -- Recurse into blocks
470 elsif Ekind
(E
) = E_Block
then
471 List_Entities
(E
, Bytes_Big_Endian
);
475 E
:= Next_Entity
(E
);
478 -- For a package body, the entities of the visible subprograms are
479 -- declared in the corresponding spec. Iterate over its entities in
480 -- order to handle properly the subprogram bodies. Skip bodies in
481 -- subunits, which are listed independently.
483 if Ekind
(Ent
) = E_Package_Body
484 and then Present
(Corresponding_Spec
(Find_Declaration
(Ent
)))
486 E
:= First_Entity
(Corresponding_Spec
(Find_Declaration
(Ent
)));
487 while Present
(E
) loop
490 Nkind
(Find_Declaration
(E
)) = N_Subprogram_Declaration
492 Body_E
:= Corresponding_Body
(Find_Declaration
(E
));
496 Nkind
(Parent
(Find_Declaration
(Body_E
))) /= N_Subunit
498 List_Entities
(Body_E
, Bytes_Big_Endian
);
508 -------------------------
509 -- List_GCC_Expression --
510 -------------------------
512 procedure List_GCC_Expression
(U
: Node_Ref_Or_Val
) is
514 procedure Print_Expr
(Val
: Node_Ref_Or_Val
);
515 -- Internal recursive procedure to print expression
521 procedure Print_Expr
(Val
: Node_Ref_Or_Val
) is
524 UI_Write
(Val
, Decimal
);
528 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
530 procedure Binop
(S
: String);
531 -- Output text for binary operator with S being operator name
537 procedure Binop
(S
: String) is
540 Print_Expr
(Node
.Op1
);
542 Print_Expr
(Node
.Op2
);
546 -- Start of processing for Print_Expr
552 Print_Expr
(Node
.Op1
);
553 Write_Str
(" then ");
554 Print_Expr
(Node
.Op2
);
555 Write_Str
(" else ");
556 Print_Expr
(Node
.Op3
);
568 when Trunc_Div_Expr
=>
571 when Ceil_Div_Expr
=>
574 when Floor_Div_Expr
=>
577 when Trunc_Mod_Expr
=>
580 when Floor_Mod_Expr
=>
583 when Ceil_Mod_Expr
=>
586 when Exact_Div_Expr
=>
591 Print_Expr
(Node
.Op1
);
601 Print_Expr
(Node
.Op1
);
603 when Truth_Andif_Expr
=>
606 when Truth_Orif_Expr
=>
609 when Truth_And_Expr
=>
612 when Truth_Or_Expr
=>
615 when Truth_Xor_Expr
=>
618 when Truth_Not_Expr
=>
620 Print_Expr
(Node
.Op1
);
651 -- Start of processing for List_GCC_Expression
659 end List_GCC_Expression
;
661 -------------------------
662 -- List_Linker_Section --
663 -------------------------
665 procedure List_Linker_Section
(Ent
: Entity_Id
) is
669 if Present
(Linker_Section_Pragma
(Ent
)) then
670 Write_Str
("pragma Linker_Section (");
675 Last
(Pragma_Argument_Associations
(Linker_Section_Pragma
(Ent
)));
677 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
678 Arg
:= Expression
(Arg
);
681 pragma Assert
(Nkind
(Arg
) = N_String_Literal
);
682 String_To_Name_Buffer
(Strval
(Arg
));
683 Write_Str
(Name_Buffer
(1 .. Name_Len
));
687 end List_Linker_Section
;
689 ---------------------
690 -- List_Mechanisms --
691 ---------------------
693 procedure List_Mechanisms
(Ent
: Entity_Id
) is
702 Write_Str
("function ");
705 Write_Str
("operator ");
708 Write_Str
("procedure ");
710 when E_Subprogram_Type
=>
716 Write_Str
("entry ");
722 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
723 Write_Str
(Name_Buffer
(1 .. Name_Len
));
724 Write_Str
(" declared at ");
725 Write_Location
(Sloc
(Ent
));
728 Write_Str
(" convention : ");
730 case Convention
(Ent
) is
731 when Convention_Ada
=>
734 when Convention_Ada_Pass_By_Copy
=>
735 Write_Line
("Ada_Pass_By_Copy");
737 when Convention_Ada_Pass_By_Reference
=>
738 Write_Line
("Ada_Pass_By_Reference");
740 when Convention_Intrinsic
=>
741 Write_Line
("Intrinsic");
743 when Convention_Entry
=>
744 Write_Line
("Entry");
746 when Convention_Protected
=>
747 Write_Line
("Protected");
749 when Convention_Assembler
=>
750 Write_Line
("Assembler");
755 when Convention_COBOL
=>
756 Write_Line
("COBOL");
758 when Convention_CPP
=>
761 when Convention_Fortran
=>
762 Write_Line
("Fortran");
764 when Convention_Stdcall
=>
765 Write_Line
("Stdcall");
767 when Convention_Stubbed
=>
768 Write_Line
("Stubbed");
771 -- Find max length of formal name
774 Form
:= First_Formal
(Ent
);
775 while Present
(Form
) loop
776 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
778 if Name_Len
> Plen
then
785 -- Output formals and mechanisms
787 Form
:= First_Formal
(Ent
);
788 while Present
(Form
) loop
789 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
790 while Name_Len
<= Plen
loop
791 Name_Len
:= Name_Len
+ 1;
792 Name_Buffer
(Name_Len
) := ' ';
796 Write_Str
(Name_Buffer
(1 .. Plen
+ 1));
797 Write_Str
(": passed by ");
799 Write_Mechanism
(Mechanism
(Form
));
804 if Etype
(Ent
) /= Standard_Void_Type
then
805 Write_Str
(" returns by ");
806 Write_Mechanism
(Mechanism
(Ent
));
815 procedure List_Name
(Ent
: Entity_Id
) is
817 if not Is_Compilation_Unit
(Scope
(Ent
)) then
818 List_Name
(Scope
(Ent
));
822 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
823 Set_Casing
(Unit_Casing
);
824 Write_Str
(Name_Buffer
(1 .. Name_Len
));
827 ---------------------
828 -- List_Object_Info --
829 ---------------------
831 procedure List_Object_Info
(Ent
: Entity_Id
) is
837 Write_Str
("'Size use ");
838 Write_Val
(Esize
(Ent
));
843 Write_Str
("'Alignment use ");
844 Write_Val
(Alignment
(Ent
));
846 end List_Object_Info
;
848 ----------------------
849 -- List_Record_Info --
850 ----------------------
852 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
857 Max_Name_Length
: Natural;
858 Max_Suni_Length
: Natural;
862 List_Type_Info
(Ent
);
866 Write_Line
(" use record");
868 -- First loop finds out max line length and max starting position
869 -- length, for the purpose of lining things up nicely.
871 Max_Name_Length
:= 0;
872 Max_Suni_Length
:= 0;
874 Comp
:= First_Component_Or_Discriminant
(Ent
);
875 while Present
(Comp
) loop
877 -- Skip discriminant in unchecked union (since it is not there!)
879 if Ekind
(Comp
) = E_Discriminant
880 and then Is_Unchecked_Union
(Ent
)
887 Get_Decoded_Name_String
(Chars
(Comp
));
888 Max_Name_Length
:= Natural'Max (Max_Name_Length
, Name_Len
);
890 Cfbit
:= Component_Bit_Offset
(Comp
);
892 if Rep_Not_Constant
(Cfbit
) then
893 UI_Image_Length
:= 2;
896 -- Complete annotation in case not done
898 Set_Normalized_Position
(Comp
, Cfbit
/ SSU
);
899 Set_Normalized_First_Bit
(Comp
, Cfbit
mod SSU
);
901 Sunit
:= Cfbit
/ SSU
;
905 -- If the record is not packed, then we know that all fields
906 -- whose position is not specified have a starting normalized
907 -- bit position of zero.
909 if Unknown_Normalized_First_Bit
(Comp
)
910 and then not Is_Packed
(Ent
)
912 Set_Normalized_First_Bit
(Comp
, Uint_0
);
916 Natural'Max (Max_Suni_Length
, UI_Image_Length
);
919 Next_Component_Or_Discriminant
(Comp
);
922 -- Second loop does actual output based on those values
924 Comp
:= First_Component_Or_Discriminant
(Ent
);
925 while Present
(Comp
) loop
927 -- Skip discriminant in unchecked union (since it is not there!)
929 if Ekind
(Comp
) = E_Discriminant
930 and then Is_Unchecked_Union
(Ent
)
938 Esiz
: constant Uint
:= Esize
(Comp
);
939 Bofs
: constant Uint
:= Component_Bit_Offset
(Comp
);
940 Npos
: constant Uint
:= Normalized_Position
(Comp
);
941 Fbit
: constant Uint
:= Normalized_First_Bit
(Comp
);
946 Get_Decoded_Name_String
(Chars
(Comp
));
947 Set_Casing
(Unit_Casing
);
948 Write_Str
(Name_Buffer
(1 .. Name_Len
));
950 for J
in 1 .. Max_Name_Length
- Name_Len
loop
956 if Known_Static_Normalized_Position
(Comp
) then
958 Spaces
(Max_Suni_Length
- UI_Image_Length
);
959 Write_Str
(UI_Image_Buffer
(1 .. UI_Image_Length
));
961 elsif Known_Component_Bit_Offset
(Comp
)
962 and then List_Representation_Info
= 3
964 Spaces
(Max_Suni_Length
- 2);
965 Write_Str
("bit offset");
966 Write_Val
(Bofs
, Paren
=> True);
967 Write_Str
(" size in bits = ");
968 Write_Val
(Esiz
, Paren
=> True);
972 elsif Known_Normalized_Position
(Comp
)
973 and then List_Representation_Info
= 3
975 Spaces
(Max_Suni_Length
- 2);
979 -- For the packed case, we don't know the bit positions if we
980 -- don't know the starting position.
982 if Is_Packed
(Ent
) then
983 Write_Line
("?? range ? .. ??;");
986 -- Otherwise we can continue
993 Write_Str
(" range ");
997 -- Allowing Uint_0 here is an annoying special case. Really this
998 -- should be a fine Esize value but currently it means unknown,
999 -- except that we know after gigi has back annotated that a size
1000 -- of zero is real, since otherwise gigi back annotates using
1001 -- No_Uint as the value to indicate unknown).
1003 if (Esize
(Comp
) = Uint_0
or else Known_Static_Esize
(Comp
))
1004 and then Known_Static_Normalized_First_Bit
(Comp
)
1006 Lbit
:= Fbit
+ Esiz
- 1;
1014 -- The test for Esize (Comp) not Uint_0 here is an annoying
1015 -- special case. Officially a value of zero for Esize means
1016 -- unknown, but here we use the fact that we know that gigi
1017 -- annotates Esize with No_Uint, not Uint_0. Really everyone
1018 -- should use No_Uint???
1020 elsif List_Representation_Info
< 3
1021 or else (Esize
(Comp
) /= Uint_0
and then Unknown_Esize
(Comp
))
1025 -- List_Representation >= 3 and Known_Esize (Comp)
1028 Write_Val
(Esiz
, Paren
=> True);
1030 -- If in front end layout mode, then dynamic size is stored
1031 -- in storage units, so renormalize for output
1033 if not Back_End_Layout
then
1038 -- Add appropriate first bit offset
1048 Write_Int
(UI_To_Int
(Fbit
) - 1);
1056 Next_Component_Or_Discriminant
(Comp
);
1059 Write_Line
("end record;");
1061 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
1062 end List_Record_Info
;
1068 procedure List_Rep_Info
(Bytes_Big_Endian
: Boolean) is
1072 if List_Representation_Info
/= 0
1073 or else List_Representation_Info_Mechanisms
1075 for U
in Main_Unit
.. Last_Unit
loop
1076 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
)) then
1077 Unit_Casing
:= Identifier_Casing
(Source_Index
(U
));
1079 -- Normal case, list to standard output
1081 if not List_Representation_Info_To_File
then
1083 Write_Str
("Representation information for unit ");
1084 Write_Unit_Name
(Unit_Name
(U
));
1088 for J
in 1 .. Col
- 1 loop
1093 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1095 -- List representation information to file
1098 Create_Repinfo_File_Access
.all
1099 (Get_Name_String
(File_Name
(Source_Index
(U
))));
1100 Set_Special_Output
(Write_Info_Line
'Access);
1101 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1102 Set_Special_Output
(null);
1103 Close_Repinfo_File_Access
.all;
1110 -------------------------------
1111 -- List_Scalar_Storage_Order --
1112 -------------------------------
1114 procedure List_Scalar_Storage_Order
1116 Bytes_Big_Endian
: Boolean)
1118 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean);
1119 -- Show attribute definition clause for Attr_Name (an endianness
1120 -- attribute), depending on whether or not the endianness is reversed
1121 -- compared to native endianness.
1127 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean) is
1131 Write_Str
("'" & Attr_Name
& " use System.");
1133 if Bytes_Big_Endian
xor Is_Reversed
then
1139 Write_Line
("_Order_First;");
1142 List_SSO
: constant Boolean :=
1143 Has_Rep_Item
(Ent
, Name_Scalar_Storage_Order
)
1144 or else SSO_Set_Low_By_Default
(Ent
)
1145 or else SSO_Set_High_By_Default
(Ent
);
1146 -- Scalar_Storage_Order is displayed if specified explicitly
1147 -- or set by Default_Scalar_Storage_Order.
1149 -- Start of processing for List_Scalar_Storage_Order
1152 -- For record types, list Bit_Order if not default, or if SSO is shown
1154 if Is_Record_Type
(Ent
)
1155 and then (List_SSO
or else Reverse_Bit_Order
(Ent
))
1157 List_Attr
("Bit_Order", Reverse_Bit_Order
(Ent
));
1160 -- List SSO if required. If not, then storage is supposed to be in
1164 List_Attr
("Scalar_Storage_Order", Reverse_Storage_Order
(Ent
));
1166 pragma Assert
(not Reverse_Storage_Order
(Ent
));
1169 end List_Scalar_Storage_Order
;
1171 --------------------
1172 -- List_Type_Info --
1173 --------------------
1175 procedure List_Type_Info
(Ent
: Entity_Id
) is
1179 -- Do not list size info for unconstrained arrays, not meaningful
1181 if Is_Array_Type
(Ent
) and then not Is_Constrained
(Ent
) then
1185 -- If Esize and RM_Size are the same and known, list as Size. This
1186 -- is a common case, which we may as well list in simple form.
1188 if Esize
(Ent
) = RM_Size
(Ent
) then
1191 Write_Str
("'Size use ");
1192 Write_Val
(Esize
(Ent
));
1195 -- For now, temporary case, to be removed when gigi properly back
1196 -- annotates RM_Size, if RM_Size is not set, then list Esize as Size.
1197 -- This avoids odd Object_Size output till we fix things???
1199 elsif Unknown_RM_Size
(Ent
) then
1202 Write_Str
("'Size use ");
1203 Write_Val
(Esize
(Ent
));
1206 -- Otherwise list size values separately if they are set
1211 Write_Str
("'Object_Size use ");
1212 Write_Val
(Esize
(Ent
));
1215 -- Note on following check: The RM_Size of a discrete type can
1216 -- legitimately be set to zero, so a special check is needed.
1220 Write_Str
("'Value_Size use ");
1221 Write_Val
(RM_Size
(Ent
));
1228 Write_Str
("'Alignment use ");
1229 Write_Val
(Alignment
(Ent
));
1232 -- Special stuff for fixed-point
1234 if Is_Fixed_Point_Type
(Ent
) then
1236 -- Write small (always a static constant)
1240 Write_Str
("'Small use ");
1241 UR_Write
(Small_Value
(Ent
));
1244 -- Write range if static
1247 R
: constant Node_Id
:= Scalar_Range
(Ent
);
1250 if Nkind
(Low_Bound
(R
)) = N_Real_Literal
1252 Nkind
(High_Bound
(R
)) = N_Real_Literal
1256 Write_Str
("'Range use ");
1257 UR_Write
(Realval
(Low_Bound
(R
)));
1259 UR_Write
(Realval
(High_Bound
(R
)));
1266 ----------------------
1267 -- Rep_Not_Constant --
1268 ----------------------
1270 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean is
1272 if Val
= No_Uint
or else Val
< 0 then
1277 end Rep_Not_Constant
;
1284 (Val
: Node_Ref_Or_Val
;
1285 D
: Discrim_List
) return Uint
1287 function B
(Val
: Boolean) return Uint
;
1288 -- Returns Uint_0 for False, Uint_1 for True
1290 function T
(Val
: Node_Ref_Or_Val
) return Boolean;
1291 -- Returns True for 0, False for any non-zero (i.e. True)
1293 function V
(Val
: Node_Ref_Or_Val
) return Uint
;
1294 -- Internal recursive routine to evaluate tree
1296 function W
(Val
: Uint
) return Word
;
1297 -- Convert Val to Word, assuming Val is always in the Int range. This
1298 -- is a helper function for the evaluation of bitwise expressions like
1299 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
1300 -- values out of the Int range are expected to be seen in such
1301 -- expressions only with overflowing byte sizes around, introducing
1302 -- inherent unreliabilities in computations anyway.
1308 function B
(Val
: Boolean) return Uint
is
1321 function T
(Val
: Node_Ref_Or_Val
) return Boolean is
1334 function V
(Val
: Node_Ref_Or_Val
) return Uint
is
1343 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
1348 if T
(Node
.Op1
) then
1349 return V
(Node
.Op2
);
1351 return V
(Node
.Op3
);
1355 return V
(Node
.Op1
) + V
(Node
.Op2
);
1358 return V
(Node
.Op1
) - V
(Node
.Op2
);
1361 return V
(Node
.Op1
) * V
(Node
.Op2
);
1363 when Trunc_Div_Expr
=>
1364 return V
(Node
.Op1
) / V
(Node
.Op2
);
1366 when Ceil_Div_Expr
=>
1369 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
1371 when Floor_Div_Expr
=>
1374 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
1376 when Trunc_Mod_Expr
=>
1377 return V
(Node
.Op1
) rem V
(Node
.Op2
);
1379 when Floor_Mod_Expr
=>
1380 return V
(Node
.Op1
) mod V
(Node
.Op2
);
1382 when Ceil_Mod_Expr
=>
1385 Q
:= UR_Ceiling
(L
/ UR_From_Uint
(R
));
1388 when Exact_Div_Expr
=>
1389 return V
(Node
.Op1
) / V
(Node
.Op2
);
1392 return -V
(Node
.Op1
);
1395 return UI_Min
(V
(Node
.Op1
), V
(Node
.Op2
));
1398 return UI_Max
(V
(Node
.Op1
), V
(Node
.Op2
));
1401 return UI_Abs
(V
(Node
.Op1
));
1403 when Truth_Andif_Expr
=>
1404 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
1406 when Truth_Orif_Expr
=>
1407 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
1409 when Truth_And_Expr
=>
1410 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
1412 when Truth_Or_Expr
=>
1413 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
1415 when Truth_Xor_Expr
=>
1416 return B
(T
(Node
.Op1
) xor T
(Node
.Op2
));
1418 when Truth_Not_Expr
=>
1419 return B
(not T
(Node
.Op1
));
1421 when Bit_And_Expr
=>
1424 return UI_From_Int
(Int
(W
(L
) and W
(R
)));
1427 return B
(V
(Node
.Op1
) < V
(Node
.Op2
));
1430 return B
(V
(Node
.Op1
) <= V
(Node
.Op2
));
1433 return B
(V
(Node
.Op1
) > V
(Node
.Op2
));
1436 return B
(V
(Node
.Op1
) >= V
(Node
.Op2
));
1439 return B
(V
(Node
.Op1
) = V
(Node
.Op2
));
1442 return B
(V
(Node
.Op1
) /= V
(Node
.Op2
));
1446 Sub
: constant Int
:= UI_To_Int
(Node
.Op1
);
1448 pragma Assert
(Sub
in D
'Range);
1460 -- We use an unchecked conversion to map Int values to their Word
1461 -- bitwise equivalent, which we could not achieve with a normal type
1462 -- conversion for negative Ints. We want bitwise equivalents because W
1463 -- is used as a helper for bit operators like Bit_And_Expr, and can be
1464 -- called for negative Ints in the context of aligning expressions like
1465 -- X+Align & -Align.
1467 function W
(Val
: Uint
) return Word
is
1468 function To_Word
is new Ada
.Unchecked_Conversion
(Int
, Word
);
1470 return To_Word
(UI_To_Int
(Val
));
1473 -- Start of processing for Rep_Value
1476 if Val
= No_Uint
then
1488 procedure Spaces
(N
: Natural) is
1490 for J
in 1 .. N
loop
1499 procedure Tree_Read
is
1501 Rep_Table
.Tree_Read
;
1508 procedure Tree_Write
is
1510 Rep_Table
.Tree_Write
;
1513 ---------------------
1514 -- Write_Info_Line --
1515 ---------------------
1517 procedure Write_Info_Line
(S
: String) is
1519 Write_Repinfo_Line_Access
.all (S
(S
'First .. S
'Last - 1));
1520 end Write_Info_Line
;
1522 ---------------------
1523 -- Write_Mechanism --
1524 ---------------------
1526 procedure Write_Mechanism
(M
: Mechanism_Type
) is
1530 Write_Str
("default");
1536 Write_Str
("reference");
1539 raise Program_Error
;
1541 end Write_Mechanism
;
1547 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False) is
1549 if Rep_Not_Constant
(Val
) then
1550 if List_Representation_Info
< 3 or else Val
= No_Uint
then
1554 if Back_End_Layout
then
1559 List_GCC_Expression
(Val
);
1562 List_GCC_Expression
(Val
);
1570 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));
1573 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));