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
);
652 -- Start of processing for List_GCC_Expression
660 end List_GCC_Expression
;
662 -------------------------
663 -- List_Linker_Section --
664 -------------------------
666 procedure List_Linker_Section
(Ent
: Entity_Id
) is
670 if Present
(Linker_Section_Pragma
(Ent
)) then
671 Write_Str
("pragma Linker_Section (");
676 Last
(Pragma_Argument_Associations
(Linker_Section_Pragma
(Ent
)));
678 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
679 Arg
:= Expression
(Arg
);
682 pragma Assert
(Nkind
(Arg
) = N_String_Literal
);
683 String_To_Name_Buffer
(Strval
(Arg
));
684 Write_Str
(Name_Buffer
(1 .. Name_Len
));
688 end List_Linker_Section
;
690 ---------------------
691 -- List_Mechanisms --
692 ---------------------
694 procedure List_Mechanisms
(Ent
: Entity_Id
) is
703 Write_Str
("function ");
706 Write_Str
("operator ");
709 Write_Str
("procedure ");
711 when E_Subprogram_Type
=>
714 when E_Entry | E_Entry_Family
=>
715 Write_Str
("entry ");
721 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
722 Write_Str
(Name_Buffer
(1 .. Name_Len
));
723 Write_Str
(" declared at ");
724 Write_Location
(Sloc
(Ent
));
727 Write_Str
(" convention : ");
729 case Convention
(Ent
) is
730 when Convention_Ada
=>
732 when Convention_Ada_Pass_By_Copy
=>
733 Write_Line
("Ada_Pass_By_Copy");
734 when Convention_Ada_Pass_By_Reference
=>
735 Write_Line
("Ada_Pass_By_Reference");
736 when Convention_Intrinsic
=>
737 Write_Line
("Intrinsic");
738 when Convention_Entry
=>
739 Write_Line
("Entry");
740 when Convention_Protected
=>
741 Write_Line
("Protected");
742 when Convention_Assembler
=>
743 Write_Line
("Assembler");
746 when Convention_COBOL
=>
747 Write_Line
("COBOL");
748 when Convention_CPP
=>
750 when Convention_Fortran
=>
751 Write_Line
("Fortran");
752 when Convention_Stdcall
=>
753 Write_Line
("Stdcall");
754 when Convention_Stubbed
=>
755 Write_Line
("Stubbed");
758 -- Find max length of formal name
761 Form
:= First_Formal
(Ent
);
762 while Present
(Form
) loop
763 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
765 if Name_Len
> Plen
then
772 -- Output formals and mechanisms
774 Form
:= First_Formal
(Ent
);
775 while Present
(Form
) loop
776 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
777 while Name_Len
<= Plen
loop
778 Name_Len
:= Name_Len
+ 1;
779 Name_Buffer
(Name_Len
) := ' ';
783 Write_Str
(Name_Buffer
(1 .. Plen
+ 1));
784 Write_Str
(": passed by ");
786 Write_Mechanism
(Mechanism
(Form
));
791 if Etype
(Ent
) /= Standard_Void_Type
then
792 Write_Str
(" returns by ");
793 Write_Mechanism
(Mechanism
(Ent
));
802 procedure List_Name
(Ent
: Entity_Id
) is
804 if not Is_Compilation_Unit
(Scope
(Ent
)) then
805 List_Name
(Scope
(Ent
));
809 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
810 Set_Casing
(Unit_Casing
);
811 Write_Str
(Name_Buffer
(1 .. Name_Len
));
814 ---------------------
815 -- List_Object_Info --
816 ---------------------
818 procedure List_Object_Info
(Ent
: Entity_Id
) is
824 Write_Str
("'Size use ");
825 Write_Val
(Esize
(Ent
));
830 Write_Str
("'Alignment use ");
831 Write_Val
(Alignment
(Ent
));
833 end List_Object_Info
;
835 ----------------------
836 -- List_Record_Info --
837 ----------------------
839 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
844 Max_Name_Length
: Natural;
845 Max_Suni_Length
: Natural;
849 List_Type_Info
(Ent
);
853 Write_Line
(" use record");
855 -- First loop finds out max line length and max starting position
856 -- length, for the purpose of lining things up nicely.
858 Max_Name_Length
:= 0;
859 Max_Suni_Length
:= 0;
861 Comp
:= First_Component_Or_Discriminant
(Ent
);
862 while Present
(Comp
) loop
864 -- Skip discriminant in unchecked union (since it is not there!)
866 if Ekind
(Comp
) = E_Discriminant
867 and then Is_Unchecked_Union
(Ent
)
874 Get_Decoded_Name_String
(Chars
(Comp
));
875 Max_Name_Length
:= Natural'Max (Max_Name_Length
, Name_Len
);
877 Cfbit
:= Component_Bit_Offset
(Comp
);
879 if Rep_Not_Constant
(Cfbit
) then
880 UI_Image_Length
:= 2;
883 -- Complete annotation in case not done
885 Set_Normalized_Position
(Comp
, Cfbit
/ SSU
);
886 Set_Normalized_First_Bit
(Comp
, Cfbit
mod SSU
);
888 Sunit
:= Cfbit
/ SSU
;
892 -- If the record is not packed, then we know that all fields
893 -- whose position is not specified have a starting normalized
894 -- bit position of zero.
896 if Unknown_Normalized_First_Bit
(Comp
)
897 and then not Is_Packed
(Ent
)
899 Set_Normalized_First_Bit
(Comp
, Uint_0
);
903 Natural'Max (Max_Suni_Length
, UI_Image_Length
);
906 Next_Component_Or_Discriminant
(Comp
);
909 -- Second loop does actual output based on those values
911 Comp
:= First_Component_Or_Discriminant
(Ent
);
912 while Present
(Comp
) loop
914 -- Skip discriminant in unchecked union (since it is not there!)
916 if Ekind
(Comp
) = E_Discriminant
917 and then Is_Unchecked_Union
(Ent
)
925 Esiz
: constant Uint
:= Esize
(Comp
);
926 Bofs
: constant Uint
:= Component_Bit_Offset
(Comp
);
927 Npos
: constant Uint
:= Normalized_Position
(Comp
);
928 Fbit
: constant Uint
:= Normalized_First_Bit
(Comp
);
933 Get_Decoded_Name_String
(Chars
(Comp
));
934 Set_Casing
(Unit_Casing
);
935 Write_Str
(Name_Buffer
(1 .. Name_Len
));
937 for J
in 1 .. Max_Name_Length
- Name_Len
loop
943 if Known_Static_Normalized_Position
(Comp
) then
945 Spaces
(Max_Suni_Length
- UI_Image_Length
);
946 Write_Str
(UI_Image_Buffer
(1 .. UI_Image_Length
));
948 elsif Known_Component_Bit_Offset
(Comp
)
949 and then List_Representation_Info
= 3
951 Spaces
(Max_Suni_Length
- 2);
952 Write_Str
("bit offset");
953 Write_Val
(Bofs
, Paren
=> True);
954 Write_Str
(" size in bits = ");
955 Write_Val
(Esiz
, Paren
=> True);
959 elsif Known_Normalized_Position
(Comp
)
960 and then List_Representation_Info
= 3
962 Spaces
(Max_Suni_Length
- 2);
966 -- For the packed case, we don't know the bit positions if we
967 -- don't know the starting position.
969 if Is_Packed
(Ent
) then
970 Write_Line
("?? range ? .. ??;");
973 -- Otherwise we can continue
980 Write_Str
(" range ");
984 -- Allowing Uint_0 here is an annoying special case. Really this
985 -- should be a fine Esize value but currently it means unknown,
986 -- except that we know after gigi has back annotated that a size
987 -- of zero is real, since otherwise gigi back annotates using
988 -- No_Uint as the value to indicate unknown).
990 if (Esize
(Comp
) = Uint_0
or else Known_Static_Esize
(Comp
))
991 and then Known_Static_Normalized_First_Bit
(Comp
)
993 Lbit
:= Fbit
+ Esiz
- 1;
1001 -- The test for Esize (Comp) not Uint_0 here is an annoying
1002 -- special case. Officially a value of zero for Esize means
1003 -- unknown, but here we use the fact that we know that gigi
1004 -- annotates Esize with No_Uint, not Uint_0. Really everyone
1005 -- should use No_Uint???
1007 elsif List_Representation_Info
< 3
1008 or else (Esize
(Comp
) /= Uint_0
and then Unknown_Esize
(Comp
))
1012 -- List_Representation >= 3 and Known_Esize (Comp)
1015 Write_Val
(Esiz
, Paren
=> True);
1017 -- If in front end layout mode, then dynamic size is stored
1018 -- in storage units, so renormalize for output
1020 if not Back_End_Layout
then
1025 -- Add appropriate first bit offset
1035 Write_Int
(UI_To_Int
(Fbit
) - 1);
1043 Next_Component_Or_Discriminant
(Comp
);
1046 Write_Line
("end record;");
1048 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
1049 end List_Record_Info
;
1055 procedure List_Rep_Info
(Bytes_Big_Endian
: Boolean) is
1059 if List_Representation_Info
/= 0
1060 or else List_Representation_Info_Mechanisms
1062 for U
in Main_Unit
.. Last_Unit
loop
1063 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
)) then
1064 Unit_Casing
:= Identifier_Casing
(Source_Index
(U
));
1066 -- Normal case, list to standard output
1068 if not List_Representation_Info_To_File
then
1070 Write_Str
("Representation information for unit ");
1071 Write_Unit_Name
(Unit_Name
(U
));
1075 for J
in 1 .. Col
- 1 loop
1080 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1082 -- List representation information to file
1085 Create_Repinfo_File_Access
.all
1086 (Get_Name_String
(File_Name
(Source_Index
(U
))));
1087 Set_Special_Output
(Write_Info_Line
'Access);
1088 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1089 Set_Special_Output
(null);
1090 Close_Repinfo_File_Access
.all;
1097 -------------------------------
1098 -- List_Scalar_Storage_Order --
1099 -------------------------------
1101 procedure List_Scalar_Storage_Order
1103 Bytes_Big_Endian
: Boolean)
1105 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean);
1106 -- Show attribute definition clause for Attr_Name (an endianness
1107 -- attribute), depending on whether or not the endianness is reversed
1108 -- compared to native endianness.
1114 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean) is
1118 Write_Str
("'" & Attr_Name
& " use System.");
1120 if Bytes_Big_Endian
xor Is_Reversed
then
1126 Write_Line
("_Order_First;");
1129 List_SSO
: constant Boolean :=
1130 Has_Rep_Item
(Ent
, Name_Scalar_Storage_Order
)
1131 or else SSO_Set_Low_By_Default
(Ent
)
1132 or else SSO_Set_High_By_Default
(Ent
);
1133 -- Scalar_Storage_Order is displayed if specified explicitly
1134 -- or set by Default_Scalar_Storage_Order.
1136 -- Start of processing for List_Scalar_Storage_Order
1139 -- For record types, list Bit_Order if not default, or if SSO is shown
1141 if Is_Record_Type
(Ent
)
1142 and then (List_SSO
or else Reverse_Bit_Order
(Ent
))
1144 List_Attr
("Bit_Order", Reverse_Bit_Order
(Ent
));
1147 -- List SSO if required. If not, then storage is supposed to be in
1151 List_Attr
("Scalar_Storage_Order", Reverse_Storage_Order
(Ent
));
1153 pragma Assert
(not Reverse_Storage_Order
(Ent
));
1156 end List_Scalar_Storage_Order
;
1158 --------------------
1159 -- List_Type_Info --
1160 --------------------
1162 procedure List_Type_Info
(Ent
: Entity_Id
) is
1166 -- Do not list size info for unconstrained arrays, not meaningful
1168 if Is_Array_Type
(Ent
) and then not Is_Constrained
(Ent
) then
1172 -- If Esize and RM_Size are the same and known, list as Size. This
1173 -- is a common case, which we may as well list in simple form.
1175 if Esize
(Ent
) = RM_Size
(Ent
) then
1178 Write_Str
("'Size use ");
1179 Write_Val
(Esize
(Ent
));
1182 -- For now, temporary case, to be removed when gigi properly back
1183 -- annotates RM_Size, if RM_Size is not set, then list Esize as Size.
1184 -- This avoids odd Object_Size output till we fix things???
1186 elsif Unknown_RM_Size
(Ent
) then
1189 Write_Str
("'Size use ");
1190 Write_Val
(Esize
(Ent
));
1193 -- Otherwise list size values separately if they are set
1198 Write_Str
("'Object_Size use ");
1199 Write_Val
(Esize
(Ent
));
1202 -- Note on following check: The RM_Size of a discrete type can
1203 -- legitimately be set to zero, so a special check is needed.
1207 Write_Str
("'Value_Size use ");
1208 Write_Val
(RM_Size
(Ent
));
1215 Write_Str
("'Alignment use ");
1216 Write_Val
(Alignment
(Ent
));
1219 -- Special stuff for fixed-point
1221 if Is_Fixed_Point_Type
(Ent
) then
1223 -- Write small (always a static constant)
1227 Write_Str
("'Small use ");
1228 UR_Write
(Small_Value
(Ent
));
1231 -- Write range if static
1234 R
: constant Node_Id
:= Scalar_Range
(Ent
);
1237 if Nkind
(Low_Bound
(R
)) = N_Real_Literal
1239 Nkind
(High_Bound
(R
)) = N_Real_Literal
1243 Write_Str
("'Range use ");
1244 UR_Write
(Realval
(Low_Bound
(R
)));
1246 UR_Write
(Realval
(High_Bound
(R
)));
1253 ----------------------
1254 -- Rep_Not_Constant --
1255 ----------------------
1257 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean is
1259 if Val
= No_Uint
or else Val
< 0 then
1264 end Rep_Not_Constant
;
1271 (Val
: Node_Ref_Or_Val
;
1272 D
: Discrim_List
) return Uint
1274 function B
(Val
: Boolean) return Uint
;
1275 -- Returns Uint_0 for False, Uint_1 for True
1277 function T
(Val
: Node_Ref_Or_Val
) return Boolean;
1278 -- Returns True for 0, False for any non-zero (i.e. True)
1280 function V
(Val
: Node_Ref_Or_Val
) return Uint
;
1281 -- Internal recursive routine to evaluate tree
1283 function W
(Val
: Uint
) return Word
;
1284 -- Convert Val to Word, assuming Val is always in the Int range. This
1285 -- is a helper function for the evaluation of bitwise expressions like
1286 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
1287 -- values out of the Int range are expected to be seen in such
1288 -- expressions only with overflowing byte sizes around, introducing
1289 -- inherent unreliabilities in computations anyway.
1295 function B
(Val
: Boolean) return Uint
is
1308 function T
(Val
: Node_Ref_Or_Val
) return Boolean is
1321 function V
(Val
: Node_Ref_Or_Val
) return Uint
is
1330 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
1335 if T
(Node
.Op1
) then
1336 return V
(Node
.Op2
);
1338 return V
(Node
.Op3
);
1342 return V
(Node
.Op1
) + V
(Node
.Op2
);
1345 return V
(Node
.Op1
) - V
(Node
.Op2
);
1348 return V
(Node
.Op1
) * V
(Node
.Op2
);
1350 when Trunc_Div_Expr
=>
1351 return V
(Node
.Op1
) / V
(Node
.Op2
);
1353 when Ceil_Div_Expr
=>
1356 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
1358 when Floor_Div_Expr
=>
1361 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
1363 when Trunc_Mod_Expr
=>
1364 return V
(Node
.Op1
) rem V
(Node
.Op2
);
1366 when Floor_Mod_Expr
=>
1367 return V
(Node
.Op1
) mod V
(Node
.Op2
);
1369 when Ceil_Mod_Expr
=>
1372 Q
:= UR_Ceiling
(L
/ UR_From_Uint
(R
));
1375 when Exact_Div_Expr
=>
1376 return V
(Node
.Op1
) / V
(Node
.Op2
);
1379 return -V
(Node
.Op1
);
1382 return UI_Min
(V
(Node
.Op1
), V
(Node
.Op2
));
1385 return UI_Max
(V
(Node
.Op1
), V
(Node
.Op2
));
1388 return UI_Abs
(V
(Node
.Op1
));
1390 when Truth_Andif_Expr
=>
1391 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
1393 when Truth_Orif_Expr
=>
1394 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
1396 when Truth_And_Expr
=>
1397 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
1399 when Truth_Or_Expr
=>
1400 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
1402 when Truth_Xor_Expr
=>
1403 return B
(T
(Node
.Op1
) xor T
(Node
.Op2
));
1405 when Truth_Not_Expr
=>
1406 return B
(not T
(Node
.Op1
));
1408 when Bit_And_Expr
=>
1411 return UI_From_Int
(Int
(W
(L
) and W
(R
)));
1414 return B
(V
(Node
.Op1
) < V
(Node
.Op2
));
1417 return B
(V
(Node
.Op1
) <= V
(Node
.Op2
));
1420 return B
(V
(Node
.Op1
) > V
(Node
.Op2
));
1423 return B
(V
(Node
.Op1
) >= V
(Node
.Op2
));
1426 return B
(V
(Node
.Op1
) = V
(Node
.Op2
));
1429 return B
(V
(Node
.Op1
) /= V
(Node
.Op2
));
1433 Sub
: constant Int
:= UI_To_Int
(Node
.Op1
);
1435 pragma Assert
(Sub
in D
'Range);
1448 -- We use an unchecked conversion to map Int values to their Word
1449 -- bitwise equivalent, which we could not achieve with a normal type
1450 -- conversion for negative Ints. We want bitwise equivalents because W
1451 -- is used as a helper for bit operators like Bit_And_Expr, and can be
1452 -- called for negative Ints in the context of aligning expressions like
1453 -- X+Align & -Align.
1455 function W
(Val
: Uint
) return Word
is
1456 function To_Word
is new Ada
.Unchecked_Conversion
(Int
, Word
);
1458 return To_Word
(UI_To_Int
(Val
));
1461 -- Start of processing for Rep_Value
1464 if Val
= No_Uint
then
1476 procedure Spaces
(N
: Natural) is
1478 for J
in 1 .. N
loop
1487 procedure Tree_Read
is
1489 Rep_Table
.Tree_Read
;
1496 procedure Tree_Write
is
1498 Rep_Table
.Tree_Write
;
1501 ---------------------
1502 -- Write_Info_Line --
1503 ---------------------
1505 procedure Write_Info_Line
(S
: String) is
1507 Write_Repinfo_Line_Access
.all (S
(S
'First .. S
'Last - 1));
1508 end Write_Info_Line
;
1510 ---------------------
1511 -- Write_Mechanism --
1512 ---------------------
1514 procedure Write_Mechanism
(M
: Mechanism_Type
) is
1518 Write_Str
("default");
1524 Write_Str
("reference");
1527 raise Program_Error
;
1529 end Write_Mechanism
;
1535 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False) is
1537 if Rep_Not_Constant
(Val
) then
1538 if List_Representation_Info
< 3 or else Val
= No_Uint
then
1542 if Back_End_Layout
then
1547 List_GCC_Expression
(Val
);
1550 List_GCC_Expression
(Val
);
1558 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));
1561 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));