1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2014, 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 -- This is wrong for AAMP???
63 ---------------------------------------
64 -- Representation of gcc Expressions --
65 ---------------------------------------
67 -- This table is used only if Frontend_Layout_On_Target is False, so gigi
68 -- lays out dynamic size/offset fields using encoded gcc expressions.
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 -- The following representation clause ensures that the above record
85 -- has no holes. We do this so that when instances of this record are
86 -- written by Tree_Gen, we do not write uninitialized values to the file.
88 for Exp_Node
use record
89 Expr
at 0 range 0 .. 31;
90 Op1
at 4 range 0 .. 31;
91 Op2
at 8 range 0 .. 31;
92 Op3
at 12 range 0 .. 31;
95 for Exp_Node
'Size use 16 * 8;
96 -- This ensures that we did not leave out any fields
98 package Rep_Table
is new Table
.Table
(
99 Table_Component_Type
=> Exp_Node
,
100 Table_Index_Type
=> Nat
,
101 Table_Low_Bound
=> 1,
102 Table_Initial
=> Alloc
.Rep_Table_Initial
,
103 Table_Increment
=> Alloc
.Rep_Table_Increment
,
104 Table_Name
=> "BE_Rep_Table");
106 --------------------------------------------------------------
107 -- Representation of Front-End Dynamic Size/Offset Entities --
108 --------------------------------------------------------------
110 package Dynamic_SO_Entity_Table
is new Table
.Table
(
111 Table_Component_Type
=> Entity_Id
,
112 Table_Index_Type
=> Nat
,
113 Table_Low_Bound
=> 1,
114 Table_Initial
=> Alloc
.Rep_Table_Initial
,
115 Table_Increment
=> Alloc
.Rep_Table_Increment
,
116 Table_Name
=> "FE_Rep_Table");
118 Unit_Casing
: Casing_Type
;
119 -- Identifier casing for current unit. This is set by List_Rep_Info for
120 -- each unit, before calling subprograms which may read it.
122 Need_Blank_Line
: Boolean;
123 -- Set True if a blank line is needed before outputting any information for
124 -- the current entity. Set True when a new entity is processed, and false
125 -- when the blank line is output.
127 -----------------------
128 -- Local Subprograms --
129 -----------------------
131 function Back_End_Layout
return Boolean;
132 -- Test for layout mode, True = back end, False = front end. This function
133 -- is used rather than checking the configuration parameter because we do
134 -- not want Repinfo to depend on Targparm (for ASIS)
136 procedure Blank_Line
;
137 -- Called before outputting anything for an entity. Ensures that
138 -- a blank line precedes the output for a particular entity.
140 procedure List_Entities
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
141 -- This procedure lists the entities associated with the entity E, starting
142 -- with the First_Entity and using the Next_Entity link. If a nested
143 -- package is found, entities within the package are recursively processed.
145 procedure List_Name
(Ent
: Entity_Id
);
146 -- List name of entity Ent in appropriate case. The name is listed with
147 -- full qualification up to but not including the compilation unit name.
149 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
150 -- List representation info for array type Ent
152 procedure List_Linker_Section
(Ent
: Entity_Id
);
153 -- List linker section for Ent (caller has checked that Ent is an entity
154 -- for which the Linker_Section_Pragma field is defined).
156 procedure List_Mechanisms
(Ent
: Entity_Id
);
157 -- List mechanism information for parameters of Ent, which is subprogram,
158 -- subprogram type, or an entry or entry family.
160 procedure List_Object_Info
(Ent
: Entity_Id
);
161 -- List representation info for object Ent
163 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
164 -- List representation info for record type Ent
166 procedure List_Scalar_Storage_Order
168 Bytes_Big_Endian
: Boolean);
169 -- List scalar storage order information for record or array type Ent.
170 -- Also includes bit order information for record types, if necessary.
172 procedure List_Type_Info
(Ent
: Entity_Id
);
173 -- List type info for type Ent
175 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean;
176 -- Returns True if Val represents a variable value, and False if it
177 -- represents a value that is fixed at compile time.
179 procedure Spaces
(N
: Natural);
180 -- Output given number of spaces
182 procedure Write_Info_Line
(S
: String);
183 -- Routine to write a line to Repinfo output file. This routine is passed
184 -- as a special output procedure to Output.Set_Special_Output. Note that
185 -- Write_Info_Line is called with an EOL character at the end of each line,
186 -- as per the Output spec, but the internal call to the appropriate routine
187 -- in Osint requires that the end of line sequence be stripped off.
189 procedure Write_Mechanism
(M
: Mechanism_Type
);
190 -- Writes symbolic string for mechanism represented by M
192 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False);
193 -- Given a representation value, write it out. No_Uint values or values
194 -- dependent on discriminants are written as two question marks. If the
195 -- flag Paren is set, then the output is surrounded in parentheses if it is
196 -- other than a simple value.
198 ---------------------
199 -- Back_End_Layout --
200 ---------------------
202 function Back_End_Layout
return Boolean is
204 -- We have back end layout if the back end has made any entries in the
205 -- table of GCC expressions, otherwise we have front end layout.
207 return Rep_Table
.Last
> 0;
214 procedure Blank_Line
is
216 if Need_Blank_Line
then
218 Need_Blank_Line
:= False;
222 ------------------------
223 -- Create_Discrim_Ref --
224 ------------------------
226 function Create_Discrim_Ref
(Discr
: Entity_Id
) return Node_Ref
is
229 (Expr
=> Discrim_Val
,
230 Op1
=> Discriminant_Number
(Discr
));
231 end Create_Discrim_Ref
;
233 ---------------------------
234 -- Create_Dynamic_SO_Ref --
235 ---------------------------
237 function Create_Dynamic_SO_Ref
(E
: Entity_Id
) return Dynamic_SO_Ref
is
239 Dynamic_SO_Entity_Table
.Append
(E
);
240 return UI_From_Int
(-Dynamic_SO_Entity_Table
.Last
);
241 end Create_Dynamic_SO_Ref
;
249 Op1
: Node_Ref_Or_Val
;
250 Op2
: Node_Ref_Or_Val
:= No_Uint
;
251 Op3
: Node_Ref_Or_Val
:= No_Uint
) return Node_Ref
259 return UI_From_Int
(-Rep_Table
.Last
);
262 ---------------------------
263 -- Get_Dynamic_SO_Entity --
264 ---------------------------
266 function Get_Dynamic_SO_Entity
(U
: Dynamic_SO_Ref
) return Entity_Id
is
268 return Dynamic_SO_Entity_Table
.Table
(-UI_To_Int
(U
));
269 end Get_Dynamic_SO_Entity
;
271 -----------------------
272 -- Is_Dynamic_SO_Ref --
273 -----------------------
275 function Is_Dynamic_SO_Ref
(U
: SO_Ref
) return Boolean is
278 end Is_Dynamic_SO_Ref
;
280 ----------------------
281 -- Is_Static_SO_Ref --
282 ----------------------
284 function Is_Static_SO_Ref
(U
: SO_Ref
) return Boolean is
287 end Is_Static_SO_Ref
;
293 procedure lgx
(U
: Node_Ref_Or_Val
) is
295 List_GCC_Expression
(U
);
299 ----------------------
300 -- List_Array_Info --
301 ----------------------
303 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
305 List_Type_Info
(Ent
);
308 Write_Str
("'Component_Size use ");
309 Write_Val
(Component_Size
(Ent
));
312 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
319 procedure List_Entities
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
323 function Find_Declaration
(E
: Entity_Id
) return Node_Id
;
324 -- Utility to retrieve declaration node for entity in the
325 -- case of package bodies and subprograms.
327 ----------------------
328 -- Find_Declaration --
329 ----------------------
331 function Find_Declaration
(E
: Entity_Id
) return Node_Id
is
337 and then Nkind
(Decl
) /= N_Package_Body
338 and then Nkind
(Decl
) /= N_Subprogram_Declaration
339 and then Nkind
(Decl
) /= N_Subprogram_Body
341 Decl
:= Parent
(Decl
);
345 end Find_Declaration
;
347 -- Start of processing for List_Entities
350 -- List entity if we have one, and it is not a renaming declaration.
351 -- For renamings, we don't get proper information, and really it makes
352 -- sense to restrict the output to the renamed entity.
355 and then Nkind
(Declaration_Node
(Ent
)) not in N_Renaming_Declaration
357 -- If entity is a subprogram and we are listing mechanisms,
358 -- then we need to list mechanisms for this entity.
360 if List_Representation_Info_Mechanisms
361 and then (Is_Subprogram
(Ent
)
362 or else Ekind
(Ent
) = E_Entry
363 or else Ekind
(Ent
) = E_Entry_Family
)
365 Need_Blank_Line
:= True;
366 List_Mechanisms
(Ent
);
369 E
:= First_Entity
(Ent
);
370 while Present
(E
) loop
371 Need_Blank_Line
:= True;
373 -- We list entities that come from source (excluding private or
374 -- incomplete types or deferred constants, where we will list the
375 -- info for the full view). If debug flag A is set, then all
376 -- entities are listed
378 if (Comes_From_Source
(E
)
379 and then not Is_Incomplete_Or_Private_Type
(E
)
380 and then not (Ekind
(E
) = E_Constant
381 and then Present
(Full_View
(E
))))
382 or else Debug_Flag_AA
384 if Is_Subprogram
(E
) then
385 List_Linker_Section
(E
);
387 if List_Representation_Info_Mechanisms
then
391 elsif Ekind_In
(E
, E_Entry
,
395 if List_Representation_Info_Mechanisms
then
399 elsif Is_Record_Type
(E
) then
400 if List_Representation_Info
>= 1 then
401 List_Record_Info
(E
, Bytes_Big_Endian
);
404 List_Linker_Section
(E
);
406 elsif Is_Array_Type
(E
) then
407 if List_Representation_Info
>= 1 then
408 List_Array_Info
(E
, Bytes_Big_Endian
);
411 List_Linker_Section
(E
);
413 elsif Is_Type
(E
) then
414 if List_Representation_Info
>= 2 then
416 List_Linker_Section
(E
);
419 elsif Ekind_In
(E
, E_Variable
, E_Constant
) then
420 if List_Representation_Info
>= 2 then
421 List_Object_Info
(E
);
422 List_Linker_Section
(E
);
425 elsif Ekind
(E
) = E_Loop_Parameter
or else Is_Formal
(E
) then
426 if List_Representation_Info
>= 2 then
427 List_Object_Info
(E
);
431 -- Recurse into nested package, but not if they are package
432 -- renamings (in particular renamings of the enclosing package,
433 -- as for some Java bindings and for generic instances).
435 if Ekind
(E
) = E_Package
then
436 if No
(Renamed_Object
(E
)) then
437 List_Entities
(E
, Bytes_Big_Endian
);
440 -- Recurse into bodies
442 elsif Ekind_In
(E
, E_Protected_Type
,
449 List_Entities
(E
, Bytes_Big_Endian
);
451 -- Recurse into blocks
453 elsif Ekind
(E
) = E_Block
then
454 List_Entities
(E
, Bytes_Big_Endian
);
458 E
:= Next_Entity
(E
);
461 -- For a package body, the entities of the visible subprograms are
462 -- declared in the corresponding spec. Iterate over its entities in
463 -- order to handle properly the subprogram bodies. Skip bodies in
464 -- subunits, which are listed independently.
466 if Ekind
(Ent
) = E_Package_Body
467 and then Present
(Corresponding_Spec
(Find_Declaration
(Ent
)))
469 E
:= First_Entity
(Corresponding_Spec
(Find_Declaration
(Ent
)));
470 while Present
(E
) loop
473 Nkind
(Find_Declaration
(E
)) = N_Subprogram_Declaration
475 Body_E
:= Corresponding_Body
(Find_Declaration
(E
));
479 Nkind
(Parent
(Find_Declaration
(Body_E
))) /= N_Subunit
481 List_Entities
(Body_E
, Bytes_Big_Endian
);
491 -------------------------
492 -- List_GCC_Expression --
493 -------------------------
495 procedure List_GCC_Expression
(U
: Node_Ref_Or_Val
) is
497 procedure Print_Expr
(Val
: Node_Ref_Or_Val
);
498 -- Internal recursive procedure to print expression
504 procedure Print_Expr
(Val
: Node_Ref_Or_Val
) is
507 UI_Write
(Val
, Decimal
);
511 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
513 procedure Binop
(S
: String);
514 -- Output text for binary operator with S being operator name
520 procedure Binop
(S
: String) is
523 Print_Expr
(Node
.Op1
);
525 Print_Expr
(Node
.Op2
);
529 -- Start of processing for Print_Expr
535 Print_Expr
(Node
.Op1
);
536 Write_Str
(" then ");
537 Print_Expr
(Node
.Op2
);
538 Write_Str
(" else ");
539 Print_Expr
(Node
.Op3
);
551 when Trunc_Div_Expr
=>
554 when Ceil_Div_Expr
=>
557 when Floor_Div_Expr
=>
560 when Trunc_Mod_Expr
=>
563 when Floor_Mod_Expr
=>
566 when Ceil_Mod_Expr
=>
569 when Exact_Div_Expr
=>
574 Print_Expr
(Node
.Op1
);
584 Print_Expr
(Node
.Op1
);
586 when Truth_Andif_Expr
=>
589 when Truth_Orif_Expr
=>
592 when Truth_And_Expr
=>
595 when Truth_Or_Expr
=>
598 when Truth_Xor_Expr
=>
601 when Truth_Not_Expr
=>
603 Print_Expr
(Node
.Op1
);
635 -- Start of processing for List_GCC_Expression
643 end List_GCC_Expression
;
645 -------------------------
646 -- List_Linker_Section --
647 -------------------------
649 procedure List_Linker_Section
(Ent
: Entity_Id
) is
653 if Present
(Linker_Section_Pragma
(Ent
)) then
654 Write_Str
("pragma Linker_Section (");
659 Last
(Pragma_Argument_Associations
(Linker_Section_Pragma
(Ent
)));
661 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
662 Arg
:= Expression
(Arg
);
665 pragma Assert
(Nkind
(Arg
) = N_String_Literal
);
666 String_To_Name_Buffer
(Strval
(Arg
));
667 Write_Str
(Name_Buffer
(1 .. Name_Len
));
671 end List_Linker_Section
;
673 ---------------------
674 -- List_Mechanisms --
675 ---------------------
677 procedure List_Mechanisms
(Ent
: Entity_Id
) is
686 Write_Str
("function ");
689 Write_Str
("operator ");
692 Write_Str
("procedure ");
694 when E_Subprogram_Type
=>
697 when E_Entry | E_Entry_Family
=>
698 Write_Str
("entry ");
704 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
705 Write_Str
(Name_Buffer
(1 .. Name_Len
));
706 Write_Str
(" declared at ");
707 Write_Location
(Sloc
(Ent
));
710 Write_Str
(" convention : ");
712 case Convention
(Ent
) is
713 when Convention_Ada
=>
715 when Convention_Ada_Pass_By_Copy
=>
716 Write_Line
("Ada_Pass_By_Copy");
717 when Convention_Ada_Pass_By_Reference
=>
718 Write_Line
("Ada_Pass_By_Reference");
719 when Convention_Intrinsic
=>
720 Write_Line
("Intrinsic");
721 when Convention_Entry
=>
722 Write_Line
("Entry");
723 when Convention_Ghost
=>
724 Write_Line
("Ghost");
725 when Convention_Protected
=>
726 Write_Line
("Protected");
727 when Convention_Assembler
=>
728 Write_Line
("Assembler");
731 when Convention_CIL
=>
733 when Convention_COBOL
=>
734 Write_Line
("COBOL");
735 when Convention_CPP
=>
737 when Convention_Fortran
=>
738 Write_Line
("Fortran");
739 when Convention_Java
=>
741 when Convention_Stdcall
=>
742 Write_Line
("Stdcall");
743 when Convention_Stubbed
=>
744 Write_Line
("Stubbed");
747 -- Find max length of formal name
750 Form
:= First_Formal
(Ent
);
751 while Present
(Form
) loop
752 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
754 if Name_Len
> Plen
then
761 -- Output formals and mechanisms
763 Form
:= First_Formal
(Ent
);
764 while Present
(Form
) loop
765 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
766 while Name_Len
<= Plen
loop
767 Name_Len
:= Name_Len
+ 1;
768 Name_Buffer
(Name_Len
) := ' ';
772 Write_Str
(Name_Buffer
(1 .. Plen
+ 1));
773 Write_Str
(": passed by ");
775 Write_Mechanism
(Mechanism
(Form
));
780 if Etype
(Ent
) /= Standard_Void_Type
then
781 Write_Str
(" returns by ");
782 Write_Mechanism
(Mechanism
(Ent
));
791 procedure List_Name
(Ent
: Entity_Id
) is
793 if not Is_Compilation_Unit
(Scope
(Ent
)) then
794 List_Name
(Scope
(Ent
));
798 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
799 Set_Casing
(Unit_Casing
);
800 Write_Str
(Name_Buffer
(1 .. Name_Len
));
803 ---------------------
804 -- List_Object_Info --
805 ---------------------
807 procedure List_Object_Info
(Ent
: Entity_Id
) is
813 Write_Str
("'Size use ");
814 Write_Val
(Esize
(Ent
));
819 Write_Str
("'Alignment use ");
820 Write_Val
(Alignment
(Ent
));
822 end List_Object_Info
;
824 ----------------------
825 -- List_Record_Info --
826 ----------------------
828 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
833 Max_Name_Length
: Natural;
834 Max_Suni_Length
: Natural;
838 List_Type_Info
(Ent
);
842 Write_Line
(" use record");
844 -- First loop finds out max line length and max starting position
845 -- length, for the purpose of lining things up nicely.
847 Max_Name_Length
:= 0;
848 Max_Suni_Length
:= 0;
850 Comp
:= First_Component_Or_Discriminant
(Ent
);
851 while Present
(Comp
) loop
852 Get_Decoded_Name_String
(Chars
(Comp
));
853 Max_Name_Length
:= Natural'Max (Max_Name_Length
, Name_Len
);
855 Cfbit
:= Component_Bit_Offset
(Comp
);
857 if Rep_Not_Constant
(Cfbit
) then
858 UI_Image_Length
:= 2;
861 -- Complete annotation in case not done
863 Set_Normalized_Position
(Comp
, Cfbit
/ SSU
);
864 Set_Normalized_First_Bit
(Comp
, Cfbit
mod SSU
);
866 Sunit
:= Cfbit
/ SSU
;
870 -- If the record is not packed, then we know that all fields whose
871 -- position is not specified have a starting normalized bit position
874 if Unknown_Normalized_First_Bit
(Comp
)
875 and then not Is_Packed
(Ent
)
877 Set_Normalized_First_Bit
(Comp
, Uint_0
);
881 Natural'Max (Max_Suni_Length
, UI_Image_Length
);
883 Next_Component_Or_Discriminant
(Comp
);
886 -- Second loop does actual output based on those values
888 Comp
:= First_Component_Or_Discriminant
(Ent
);
889 while Present
(Comp
) loop
891 Esiz
: constant Uint
:= Esize
(Comp
);
892 Bofs
: constant Uint
:= Component_Bit_Offset
(Comp
);
893 Npos
: constant Uint
:= Normalized_Position
(Comp
);
894 Fbit
: constant Uint
:= Normalized_First_Bit
(Comp
);
899 Get_Decoded_Name_String
(Chars
(Comp
));
900 Set_Casing
(Unit_Casing
);
901 Write_Str
(Name_Buffer
(1 .. Name_Len
));
903 for J
in 1 .. Max_Name_Length
- Name_Len
loop
909 if Known_Static_Normalized_Position
(Comp
) then
911 Spaces
(Max_Suni_Length
- UI_Image_Length
);
912 Write_Str
(UI_Image_Buffer
(1 .. UI_Image_Length
));
914 elsif Known_Component_Bit_Offset
(Comp
)
915 and then List_Representation_Info
= 3
917 Spaces
(Max_Suni_Length
- 2);
918 Write_Str
("bit offset");
919 Write_Val
(Bofs
, Paren
=> True);
920 Write_Str
(" size in bits = ");
921 Write_Val
(Esiz
, Paren
=> True);
925 elsif Known_Normalized_Position
(Comp
)
926 and then List_Representation_Info
= 3
928 Spaces
(Max_Suni_Length
- 2);
932 -- For the packed case, we don't know the bit positions if we
933 -- don't know the starting position.
935 if Is_Packed
(Ent
) then
936 Write_Line
("?? range ? .. ??;");
939 -- Otherwise we can continue
946 Write_Str
(" range ");
950 -- Allowing Uint_0 here is an annoying special case. Really this
951 -- should be a fine Esize value but currently it means unknown,
952 -- except that we know after gigi has back annotated that a size
953 -- of zero is real, since otherwise gigi back annotates using
954 -- No_Uint as the value to indicate unknown).
956 if (Esize
(Comp
) = Uint_0
or else Known_Static_Esize
(Comp
))
957 and then Known_Static_Normalized_First_Bit
(Comp
)
959 Lbit
:= Fbit
+ Esiz
- 1;
967 -- The test for Esize (Comp) not Uint_0 here is an annoying
968 -- special case. Officially a value of zero for Esize means
969 -- unknown, but here we use the fact that we know that gigi
970 -- annotates Esize with No_Uint, not Uint_0. Really everyone
971 -- should use No_Uint???
973 elsif List_Representation_Info
< 3
974 or else (Esize
(Comp
) /= Uint_0
and then Unknown_Esize
(Comp
))
978 -- List_Representation >= 3 and Known_Esize (Comp)
981 Write_Val
(Esiz
, Paren
=> True);
983 -- If in front end layout mode, then dynamic size is stored
984 -- in storage units, so renormalize for output
986 if not Back_End_Layout
then
991 -- Add appropriate first bit offset
1001 Write_Int
(UI_To_Int
(Fbit
) - 1);
1009 Next_Component_Or_Discriminant
(Comp
);
1012 Write_Line
("end record;");
1014 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
1015 end List_Record_Info
;
1021 procedure List_Rep_Info
(Bytes_Big_Endian
: Boolean) is
1025 if List_Representation_Info
/= 0
1026 or else List_Representation_Info_Mechanisms
1028 for U
in Main_Unit
.. Last_Unit
loop
1029 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
)) then
1030 Unit_Casing
:= Identifier_Casing
(Source_Index
(U
));
1032 -- Normal case, list to standard output
1034 if not List_Representation_Info_To_File
then
1036 Write_Str
("Representation information for unit ");
1037 Write_Unit_Name
(Unit_Name
(U
));
1041 for J
in 1 .. Col
- 1 loop
1046 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1048 -- List representation information to file
1051 Create_Repinfo_File_Access
.all
1052 (Get_Name_String
(File_Name
(Source_Index
(U
))));
1053 Set_Special_Output
(Write_Info_Line
'Access);
1054 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1055 Set_Special_Output
(null);
1056 Close_Repinfo_File_Access
.all;
1063 -------------------------------
1064 -- List_Scalar_Storage_Order --
1065 -------------------------------
1067 procedure List_Scalar_Storage_Order
1069 Bytes_Big_Endian
: Boolean)
1071 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean);
1072 -- Show attribute definition clause for Attr_Name (an endianness
1073 -- attribute), depending on whether or not the endianness is reversed
1074 -- compared to native endianness.
1080 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean) is
1084 Write_Str
("'" & Attr_Name
& " use System.");
1086 if Bytes_Big_Endian
xor Is_Reversed
then
1092 Write_Line
("_Order_First;");
1095 List_SSO
: constant Boolean :=
1096 Has_Rep_Item
(Ent
, Name_Scalar_Storage_Order
)
1097 or else SSO_Set_Low_By_Default
(Ent
)
1098 or else SSO_Set_High_By_Default
(Ent
);
1099 -- Scalar_Storage_Order is displayed if specified explicitly
1100 -- or set by Default_Scalar_Storage_Order.
1102 -- Start of processing for List_Scalar_Storage_Order
1105 -- For record types, list Bit_Order if not default, or if SSO is shown
1107 if Is_Record_Type
(Ent
)
1108 and then (List_SSO
or else Reverse_Bit_Order
(Ent
))
1110 List_Attr
("Bit_Order", Reverse_Bit_Order
(Ent
));
1113 -- List SSO if required. If not, then storage is supposed to be in
1117 List_Attr
("Scalar_Storage_Order", Reverse_Storage_Order
(Ent
));
1119 pragma Assert
(not Reverse_Storage_Order
(Ent
));
1122 end List_Scalar_Storage_Order
;
1124 --------------------
1125 -- List_Type_Info --
1126 --------------------
1128 procedure List_Type_Info
(Ent
: Entity_Id
) is
1132 -- Do not list size info for unconstrained arrays, not meaningful
1134 if Is_Array_Type
(Ent
) and then not Is_Constrained
(Ent
) then
1138 -- If Esize and RM_Size are the same and known, list as Size. This
1139 -- is a common case, which we may as well list in simple form.
1141 if Esize
(Ent
) = RM_Size
(Ent
) then
1144 Write_Str
("'Size use ");
1145 Write_Val
(Esize
(Ent
));
1148 -- For now, temporary case, to be removed when gigi properly back
1149 -- annotates RM_Size, if RM_Size is not set, then list Esize as Size.
1150 -- This avoids odd Object_Size output till we fix things???
1152 elsif Unknown_RM_Size
(Ent
) then
1155 Write_Str
("'Size use ");
1156 Write_Val
(Esize
(Ent
));
1159 -- Otherwise list size values separately if they are set
1164 Write_Str
("'Object_Size use ");
1165 Write_Val
(Esize
(Ent
));
1168 -- Note on following check: The RM_Size of a discrete type can
1169 -- legitimately be set to zero, so a special check is needed.
1173 Write_Str
("'Value_Size use ");
1174 Write_Val
(RM_Size
(Ent
));
1181 Write_Str
("'Alignment use ");
1182 Write_Val
(Alignment
(Ent
));
1185 -- Special stuff for fixed-point
1187 if Is_Fixed_Point_Type
(Ent
) then
1189 -- Write small (always a static constant)
1193 Write_Str
("'Small use ");
1194 UR_Write
(Small_Value
(Ent
));
1197 -- Write range if static
1200 R
: constant Node_Id
:= Scalar_Range
(Ent
);
1203 if Nkind
(Low_Bound
(R
)) = N_Real_Literal
1205 Nkind
(High_Bound
(R
)) = N_Real_Literal
1209 Write_Str
("'Range use ");
1210 UR_Write
(Realval
(Low_Bound
(R
)));
1212 UR_Write
(Realval
(High_Bound
(R
)));
1219 ----------------------
1220 -- Rep_Not_Constant --
1221 ----------------------
1223 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean is
1225 if Val
= No_Uint
or else Val
< 0 then
1230 end Rep_Not_Constant
;
1237 (Val
: Node_Ref_Or_Val
;
1238 D
: Discrim_List
) return Uint
1240 function B
(Val
: Boolean) return Uint
;
1241 -- Returns Uint_0 for False, Uint_1 for True
1243 function T
(Val
: Node_Ref_Or_Val
) return Boolean;
1244 -- Returns True for 0, False for any non-zero (i.e. True)
1246 function V
(Val
: Node_Ref_Or_Val
) return Uint
;
1247 -- Internal recursive routine to evaluate tree
1249 function W
(Val
: Uint
) return Word
;
1250 -- Convert Val to Word, assuming Val is always in the Int range. This
1251 -- is a helper function for the evaluation of bitwise expressions like
1252 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
1253 -- values out of the Int range are expected to be seen in such
1254 -- expressions only with overflowing byte sizes around, introducing
1255 -- inherent unreliabilities in computations anyway.
1261 function B
(Val
: Boolean) return Uint
is
1274 function T
(Val
: Node_Ref_Or_Val
) return Boolean is
1287 function V
(Val
: Node_Ref_Or_Val
) return Uint
is
1296 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
1301 if T
(Node
.Op1
) then
1302 return V
(Node
.Op2
);
1304 return V
(Node
.Op3
);
1308 return V
(Node
.Op1
) + V
(Node
.Op2
);
1311 return V
(Node
.Op1
) - V
(Node
.Op2
);
1314 return V
(Node
.Op1
) * V
(Node
.Op2
);
1316 when Trunc_Div_Expr
=>
1317 return V
(Node
.Op1
) / V
(Node
.Op2
);
1319 when Ceil_Div_Expr
=>
1322 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
1324 when Floor_Div_Expr
=>
1327 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
1329 when Trunc_Mod_Expr
=>
1330 return V
(Node
.Op1
) rem V
(Node
.Op2
);
1332 when Floor_Mod_Expr
=>
1333 return V
(Node
.Op1
) mod V
(Node
.Op2
);
1335 when Ceil_Mod_Expr
=>
1338 Q
:= UR_Ceiling
(L
/ UR_From_Uint
(R
));
1341 when Exact_Div_Expr
=>
1342 return V
(Node
.Op1
) / V
(Node
.Op2
);
1345 return -V
(Node
.Op1
);
1348 return UI_Min
(V
(Node
.Op1
), V
(Node
.Op2
));
1351 return UI_Max
(V
(Node
.Op1
), V
(Node
.Op2
));
1354 return UI_Abs
(V
(Node
.Op1
));
1356 when Truth_Andif_Expr
=>
1357 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
1359 when Truth_Orif_Expr
=>
1360 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
1362 when Truth_And_Expr
=>
1363 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
1365 when Truth_Or_Expr
=>
1366 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
1368 when Truth_Xor_Expr
=>
1369 return B
(T
(Node
.Op1
) xor T
(Node
.Op2
));
1371 when Truth_Not_Expr
=>
1372 return B
(not T
(Node
.Op1
));
1374 when Bit_And_Expr
=>
1377 return UI_From_Int
(Int
(W
(L
) and W
(R
)));
1380 return B
(V
(Node
.Op1
) < V
(Node
.Op2
));
1383 return B
(V
(Node
.Op1
) <= V
(Node
.Op2
));
1386 return B
(V
(Node
.Op1
) > V
(Node
.Op2
));
1389 return B
(V
(Node
.Op1
) >= V
(Node
.Op2
));
1392 return B
(V
(Node
.Op1
) = V
(Node
.Op2
));
1395 return B
(V
(Node
.Op1
) /= V
(Node
.Op2
));
1399 Sub
: constant Int
:= UI_To_Int
(Node
.Op1
);
1401 pragma Assert
(Sub
in D
'Range);
1414 -- We use an unchecked conversion to map Int values to their Word
1415 -- bitwise equivalent, which we could not achieve with a normal type
1416 -- conversion for negative Ints. We want bitwise equivalents because W
1417 -- is used as a helper for bit operators like Bit_And_Expr, and can be
1418 -- called for negative Ints in the context of aligning expressions like
1419 -- X+Align & -Align.
1421 function W
(Val
: Uint
) return Word
is
1422 function To_Word
is new Ada
.Unchecked_Conversion
(Int
, Word
);
1424 return To_Word
(UI_To_Int
(Val
));
1427 -- Start of processing for Rep_Value
1430 if Val
= No_Uint
then
1442 procedure Spaces
(N
: Natural) is
1444 for J
in 1 .. N
loop
1453 procedure Tree_Read
is
1455 Rep_Table
.Tree_Read
;
1462 procedure Tree_Write
is
1464 Rep_Table
.Tree_Write
;
1467 ---------------------
1468 -- Write_Info_Line --
1469 ---------------------
1471 procedure Write_Info_Line
(S
: String) is
1473 Write_Repinfo_Line_Access
.all (S
(S
'First .. S
'Last - 1));
1474 end Write_Info_Line
;
1476 ---------------------
1477 -- Write_Mechanism --
1478 ---------------------
1480 procedure Write_Mechanism
(M
: Mechanism_Type
) is
1484 Write_Str
("default");
1490 Write_Str
("reference");
1493 raise Program_Error
;
1495 end Write_Mechanism
;
1501 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False) is
1503 if Rep_Not_Constant
(Val
) then
1504 if List_Representation_Info
< 3 or else Val
= No_Uint
then
1508 if Back_End_Layout
then
1513 List_GCC_Expression
(Val
);
1516 List_GCC_Expression
(Val
);
1524 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));
1527 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));