1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2018, 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 ------------------------------------------------------------------------------
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 Stringt
; use Stringt
;
48 with Uname
; use Uname
;
49 with Urealp
; use Urealp
;
51 with Ada
.Unchecked_Conversion
;
55 package body Repinfo
is
58 -- Value for Storage_Unit, we do not want to get this from TTypes, since
59 -- this introduces problematic dependencies in ASIS, and in any case this
60 -- value is assumed to be 8 for the implementation of the DDA.
62 ---------------------------------------
63 -- Representation of GCC Expressions --
64 ---------------------------------------
66 -- A table internal to this unit is used to hold the values of back
67 -- annotated expressions. This table is written out by -gnatt and read
68 -- back in for ASIS processing.
70 -- Node values are stored as Uint values using the negative of the node
71 -- index in this table. Constants appear as non-negative Uint values.
73 type Exp_Node
is record
75 Op1
: Node_Ref_Or_Val
;
76 Op2
: Node_Ref_Or_Val
;
77 Op3
: Node_Ref_Or_Val
;
80 -- The following representation clause ensures that the above record
81 -- has no holes. We do this so that when instances of this record are
82 -- written by Tree_Gen, we do not write uninitialized values to the file.
84 for Exp_Node
use record
85 Expr
at 0 range 0 .. 31;
86 Op1
at 4 range 0 .. 31;
87 Op2
at 8 range 0 .. 31;
88 Op3
at 12 range 0 .. 31;
91 for Exp_Node
'Size use 16 * 8;
92 -- This ensures that we did not leave out any fields
94 package Rep_Table
is new Table
.Table
(
95 Table_Component_Type
=> Exp_Node
,
96 Table_Index_Type
=> Nat
,
98 Table_Initial
=> Alloc
.Rep_Table_Initial
,
99 Table_Increment
=> Alloc
.Rep_Table_Increment
,
100 Table_Name
=> "BE_Rep_Table");
102 --------------------------------------------------------------
103 -- Representation of Front-End Dynamic Size/Offset Entities --
104 --------------------------------------------------------------
106 package Dynamic_SO_Entity_Table
is new Table
.Table
(
107 Table_Component_Type
=> Entity_Id
,
108 Table_Index_Type
=> Nat
,
109 Table_Low_Bound
=> 1,
110 Table_Initial
=> Alloc
.Rep_Table_Initial
,
111 Table_Increment
=> Alloc
.Rep_Table_Increment
,
112 Table_Name
=> "FE_Rep_Table");
114 Unit_Casing
: Casing_Type
;
115 -- Identifier casing for current unit. This is set by List_Rep_Info for
116 -- each unit, before calling subprograms which may read it.
118 Need_Blank_Line
: Boolean;
119 -- Set True if a blank line is needed before outputting any information for
120 -- the current entity. Set True when a new entity is processed, and false
121 -- when the blank line is output.
123 -------------------------------
124 -- Set of Relevant Entities --
125 -------------------------------
127 Relevant_Entities_Size
: constant := 4093;
128 -- Number of headers in hash table
130 subtype Entity_Header_Num
is Integer range 0 .. Relevant_Entities_Size
- 1;
131 -- Range of headers in hash table
133 function Entity_Hash
(Id
: Entity_Id
) return Entity_Header_Num
;
134 -- Simple hash function for Entity_Ids
136 package Relevant_Entities
is new GNAT
.Htable
.Simple_HTable
137 (Header_Num
=> Entity_Header_Num
,
143 -- Hash table to record which compiler-generated entities are relevant
145 -----------------------
146 -- Local Subprograms --
147 -----------------------
149 function Back_End_Layout
return Boolean;
150 -- Test for layout mode, True = back end, False = front end. This function
151 -- is used rather than checking the configuration parameter because we do
152 -- not want Repinfo to depend on Targparm (for ASIS)
154 procedure Blank_Line
;
155 -- Called before outputting anything for an entity. Ensures that
156 -- a blank line precedes the output for a particular entity.
158 procedure List_Entities
160 Bytes_Big_Endian
: Boolean;
161 In_Subprogram
: Boolean := False);
162 -- This procedure lists the entities associated with the entity E, starting
163 -- with the First_Entity and using the Next_Entity link. If a nested
164 -- package is found, entities within the package are recursively processed.
165 -- When recursing within a subprogram body, Is_Subprogram suppresses
166 -- duplicate information about signature.
168 procedure List_Name
(Ent
: Entity_Id
);
169 -- List name of entity Ent in appropriate case. The name is listed with
170 -- full qualification up to but not including the compilation unit name.
172 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
173 -- List representation info for array type Ent
175 procedure List_Linker_Section
(Ent
: Entity_Id
);
176 -- List linker section for Ent (caller has checked that Ent is an entity
177 -- for which the Linker_Section_Pragma field is defined).
179 procedure List_Location
(Ent
: Entity_Id
);
180 -- List location information for Ent
182 procedure List_Mechanisms
(Ent
: Entity_Id
);
183 -- List mechanism information for parameters of Ent, which is subprogram,
184 -- subprogram type, or an entry or entry family.
186 procedure List_Object_Info
(Ent
: Entity_Id
);
187 -- List representation info for object Ent
189 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
190 -- List representation info for record type Ent
192 procedure List_Scalar_Storage_Order
194 Bytes_Big_Endian
: Boolean);
195 -- List scalar storage order information for record or array type Ent.
196 -- Also includes bit order information for record types, if necessary.
198 procedure List_Type_Info
(Ent
: Entity_Id
);
199 -- List type info for type Ent
201 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean;
202 -- Returns True if Val represents a variable value, and False if it
203 -- represents a value that is fixed at compile time.
205 procedure Spaces
(N
: Natural);
206 -- Output given number of spaces
208 procedure Write_Info_Line
(S
: String);
209 -- Routine to write a line to Repinfo output file. This routine is passed
210 -- as a special output procedure to Output.Set_Special_Output. Note that
211 -- Write_Info_Line is called with an EOL character at the end of each line,
212 -- as per the Output spec, but the internal call to the appropriate routine
213 -- in Osint requires that the end of line sequence be stripped off.
215 procedure Write_Mechanism
(M
: Mechanism_Type
);
216 -- Writes symbolic string for mechanism represented by M
218 procedure Write_Unknown_Val
;
219 -- Writes symbolic string for an unknown or non-representable value
221 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False);
222 -- Given a representation value, write it out. No_Uint values or values
223 -- dependent on discriminants are written as two question marks. If the
224 -- flag Paren is set, then the output is surrounded in parentheses if it is
225 -- other than a simple value.
227 ---------------------
228 -- Back_End_Layout --
229 ---------------------
231 function Back_End_Layout
return Boolean is
233 -- We have back-end layout if the back end has made any entries in the
234 -- table of GCC expressions, otherwise we have front-end layout.
236 return Rep_Table
.Last
> 0;
243 procedure Blank_Line
is
245 if Need_Blank_Line
then
247 Need_Blank_Line
:= False;
251 ------------------------
252 -- Create_Discrim_Ref --
253 ------------------------
255 function Create_Discrim_Ref
(Discr
: Entity_Id
) return Node_Ref
is
258 (Expr
=> Discrim_Val
,
259 Op1
=> Discriminant_Number
(Discr
));
260 end Create_Discrim_Ref
;
262 ---------------------------
263 -- Create_Dynamic_SO_Ref --
264 ---------------------------
266 function Create_Dynamic_SO_Ref
(E
: Entity_Id
) return Dynamic_SO_Ref
is
268 Dynamic_SO_Entity_Table
.Append
(E
);
269 return UI_From_Int
(-Dynamic_SO_Entity_Table
.Last
);
270 end Create_Dynamic_SO_Ref
;
278 Op1
: Node_Ref_Or_Val
;
279 Op2
: Node_Ref_Or_Val
:= No_Uint
;
280 Op3
: Node_Ref_Or_Val
:= No_Uint
) return Node_Ref
288 return UI_From_Int
(-Rep_Table
.Last
);
295 function Entity_Hash
(Id
: Entity_Id
) return Entity_Header_Num
is
297 return Entity_Header_Num
(Id
mod Relevant_Entities_Size
);
300 ---------------------------
301 -- Get_Dynamic_SO_Entity --
302 ---------------------------
304 function Get_Dynamic_SO_Entity
(U
: Dynamic_SO_Ref
) return Entity_Id
is
306 return Dynamic_SO_Entity_Table
.Table
(-UI_To_Int
(U
));
307 end Get_Dynamic_SO_Entity
;
309 -----------------------
310 -- Is_Dynamic_SO_Ref --
311 -----------------------
313 function Is_Dynamic_SO_Ref
(U
: SO_Ref
) return Boolean is
316 end Is_Dynamic_SO_Ref
;
318 ----------------------
319 -- Is_Static_SO_Ref --
320 ----------------------
322 function Is_Static_SO_Ref
(U
: SO_Ref
) return Boolean is
325 end Is_Static_SO_Ref
;
331 procedure lgx
(U
: Node_Ref_Or_Val
) is
333 List_GCC_Expression
(U
);
337 ----------------------
338 -- List_Array_Info --
339 ----------------------
341 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
345 if List_Representation_Info_To_JSON
then
349 List_Type_Info
(Ent
);
351 if List_Representation_Info_To_JSON
then
353 Write_Str
(" ""Component_Size"": ");
354 Write_Val
(Component_Size
(Ent
));
358 Write_Str
("'Component_Size use ");
359 Write_Val
(Component_Size
(Ent
));
363 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
365 List_Linker_Section
(Ent
);
367 if List_Representation_Info_To_JSON
then
377 procedure List_Entities
379 Bytes_Big_Endian
: Boolean;
380 In_Subprogram
: Boolean := False)
385 function Find_Declaration
(E
: Entity_Id
) return Node_Id
;
386 -- Utility to retrieve declaration node for entity in the
387 -- case of package bodies and subprograms.
389 ----------------------
390 -- Find_Declaration --
391 ----------------------
393 function Find_Declaration
(E
: Entity_Id
) return Node_Id
is
399 and then Nkind
(Decl
) /= N_Package_Body
400 and then Nkind
(Decl
) /= N_Subprogram_Declaration
401 and then Nkind
(Decl
) /= N_Subprogram_Body
403 Decl
:= Parent
(Decl
);
407 end Find_Declaration
;
409 -- Start of processing for List_Entities
412 -- List entity if we have one, and it is not a renaming declaration.
413 -- For renamings, we don't get proper information, and really it makes
414 -- sense to restrict the output to the renamed entity.
417 and then Nkind
(Declaration_Node
(Ent
)) not in N_Renaming_Declaration
419 -- If entity is a subprogram and we are listing mechanisms,
420 -- then we need to list mechanisms for this entity. We skip this
421 -- if it is a nested subprogram, as the information has already
422 -- been produced when listing the enclosing scope.
424 if List_Representation_Info_Mechanisms
425 and then (Is_Subprogram
(Ent
)
426 or else Ekind
(Ent
) = E_Entry
427 or else Ekind
(Ent
) = E_Entry_Family
)
428 and then not In_Subprogram
430 Need_Blank_Line
:= True;
431 List_Mechanisms
(Ent
);
434 E
:= First_Entity
(Ent
);
435 while Present
(E
) loop
436 Need_Blank_Line
:= True;
438 -- We list entities that come from source (excluding private or
439 -- incomplete types or deferred constants, for which we will list
440 -- the information for the full view). If requested, we also list
441 -- relevant entities that have been generated when processing the
442 -- original entities coming from source. But if debug flag A is
443 -- set, then all entities are listed.
445 if ((Comes_From_Source
(E
)
446 or else (Ekind
(E
) = E_Block
448 Nkind
(Parent
(E
)) = N_Implicit_Label_Declaration
450 Comes_From_Source
(Label_Construct
(Parent
(E
)))))
451 and then not Is_Incomplete_Or_Private_Type
(E
)
452 and then not (Ekind
(E
) = E_Constant
453 and then Present
(Full_View
(E
))))
454 or else (List_Representation_Info
= 4
455 and then Relevant_Entities
.Get
(E
))
456 or else Debug_Flag_AA
458 if Is_Subprogram
(E
) then
459 if List_Representation_Info_Mechanisms
then
463 -- Recurse into entities local to subprogram
465 List_Entities
(E
, Bytes_Big_Endian
, True);
467 elsif Is_Formal
(E
) and then In_Subprogram
then
470 elsif Ekind_In
(E
, E_Entry
,
474 if List_Representation_Info_Mechanisms
then
478 elsif Is_Record_Type
(E
) then
479 if List_Representation_Info
>= 1 then
480 List_Record_Info
(E
, Bytes_Big_Endian
);
483 elsif Is_Array_Type
(E
) then
484 if List_Representation_Info
>= 1 then
485 List_Array_Info
(E
, Bytes_Big_Endian
);
488 -- The component type is relevant for an array
490 if List_Representation_Info
= 4
491 and then Is_Itype
(Component_Type
(Base_Type
(E
)))
493 Relevant_Entities
.Set
494 (Component_Type
(Base_Type
(E
)), True);
497 elsif Is_Type
(E
) then
498 if List_Representation_Info
>= 2 then
500 if List_Representation_Info_To_JSON
then
504 List_Linker_Section
(E
);
505 if List_Representation_Info_To_JSON
then
511 elsif Ekind_In
(E
, E_Variable
, E_Constant
) then
512 if List_Representation_Info
>= 2 then
513 List_Object_Info
(E
);
516 elsif Ekind
(E
) = E_Loop_Parameter
or else Is_Formal
(E
) then
517 if List_Representation_Info
>= 2 then
518 List_Object_Info
(E
);
522 -- Recurse into nested package, but not if they are package
523 -- renamings (in particular renamings of the enclosing package,
524 -- as for some Java bindings and for generic instances).
526 if Ekind
(E
) = E_Package
then
527 if No
(Renamed_Object
(E
)) then
528 List_Entities
(E
, Bytes_Big_Endian
);
531 -- Recurse into bodies
533 elsif Ekind_In
(E
, E_Protected_Type
,
540 List_Entities
(E
, Bytes_Big_Endian
);
542 -- Recurse into blocks
544 elsif Ekind
(E
) = E_Block
then
545 List_Entities
(E
, Bytes_Big_Endian
);
549 E
:= Next_Entity
(E
);
552 -- For a package body, the entities of the visible subprograms are
553 -- declared in the corresponding spec. Iterate over its entities in
554 -- order to handle properly the subprogram bodies. Skip bodies in
555 -- subunits, which are listed independently.
557 if Ekind
(Ent
) = E_Package_Body
558 and then Present
(Corresponding_Spec
(Find_Declaration
(Ent
)))
560 E
:= First_Entity
(Corresponding_Spec
(Find_Declaration
(Ent
)));
561 while Present
(E
) loop
564 Nkind
(Find_Declaration
(E
)) = N_Subprogram_Declaration
566 Body_E
:= Corresponding_Body
(Find_Declaration
(E
));
570 Nkind
(Parent
(Find_Declaration
(Body_E
))) /= N_Subunit
572 List_Entities
(Body_E
, Bytes_Big_Endian
);
582 -------------------------
583 -- List_GCC_Expression --
584 -------------------------
586 procedure List_GCC_Expression
(U
: Node_Ref_Or_Val
) is
588 procedure Print_Expr
(Val
: Node_Ref_Or_Val
);
589 -- Internal recursive procedure to print expression
595 procedure Print_Expr
(Val
: Node_Ref_Or_Val
) is
598 UI_Write
(Val
, Decimal
);
602 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
604 procedure Unop
(S
: String);
605 -- Output text for unary operator with S being operator name
607 procedure Binop
(S
: String);
608 -- Output text for binary operator with S being operator name
614 procedure Unop
(S
: String) is
616 if List_Representation_Info_To_JSON
then
617 Write_Str
("{ ""code"": """);
618 if S
(S
'Last) = ' ' then
619 Write_Str
(S
(S
'First .. S
'Last - 1));
623 Write_Str
(""", ""operands"": [ ");
624 Print_Expr
(Node
.Op1
);
628 Print_Expr
(Node
.Op1
);
636 procedure Binop
(S
: String) is
638 if List_Representation_Info_To_JSON
then
639 Write_Str
("{ ""code"": """);
640 Write_Str
(S
(S
'First + 1 .. S
'Last - 1));
641 Write_Str
(""", ""operands"": [ ");
642 Print_Expr
(Node
.Op1
);
644 Print_Expr
(Node
.Op2
);
648 Print_Expr
(Node
.Op1
);
650 Print_Expr
(Node
.Op2
);
655 -- Start of processing for Print_Expr
660 if List_Representation_Info_To_JSON
then
661 Write_Str
("{ ""code"": ""?<>""");
662 Write_Str
(", ""operands"": [ ");
663 Print_Expr
(Node
.Op1
);
665 Print_Expr
(Node
.Op2
);
667 Print_Expr
(Node
.Op3
);
671 Print_Expr
(Node
.Op1
);
672 Write_Str
(" then ");
673 Print_Expr
(Node
.Op2
);
674 Write_Str
(" else ");
675 Print_Expr
(Node
.Op3
);
688 when Trunc_Div_Expr
=>
691 when Ceil_Div_Expr
=>
694 when Floor_Div_Expr
=>
697 when Trunc_Mod_Expr
=>
700 when Ceil_Mod_Expr
=>
703 when Floor_Mod_Expr
=>
706 when Exact_Div_Expr
=>
721 when Truth_And_Expr
=>
724 when Truth_Or_Expr
=>
727 when Truth_Xor_Expr
=>
730 when Truth_Not_Expr
=>
764 -- Start of processing for List_GCC_Expression
772 end List_GCC_Expression
;
774 -------------------------
775 -- List_Linker_Section --
776 -------------------------
778 procedure List_Linker_Section
(Ent
: Entity_Id
) is
779 function Expr_Value_S
(N
: Node_Id
) return Node_Id
;
780 -- Returns the folded value of the expression. This function is called
781 -- in instances where it has already been determined that the expression
782 -- is static or its value is known at compile time. This version is used
783 -- for string types and returns the corresponding N_String_Literal node.
784 -- NOTE: This is an exact copy of Sem_Eval.Expr_Value_S. Licensing stops
785 -- Repinfo from within Sem_Eval. Once ASIS is removed, and the licenses
786 -- are modified, Repinfo should be able to rely on Sem_Eval.
792 function Expr_Value_S
(N
: Node_Id
) return Node_Id
is
794 if Nkind
(N
) = N_String_Literal
then
797 pragma Assert
(Ekind
(Entity
(N
)) = E_Constant
);
798 return Expr_Value_S
(Constant_Value
(Entity
(N
)));
807 -- Start of processing for List_Linker_Section
810 if Present
(Linker_Section_Pragma
(Ent
)) then
811 Args
:= Pragma_Argument_Associations
(Linker_Section_Pragma
(Ent
));
812 Sect
:= Expr_Value_S
(Get_Pragma_Arg
(Last
(Args
)));
814 if List_Representation_Info_To_JSON
then
816 Write_Str
(" ""Linker_Section"": """);
818 Write_Str
("pragma Linker_Section (");
823 pragma Assert
(Nkind
(Sect
) = N_String_Literal
);
824 String_To_Name_Buffer
(Strval
(Sect
));
825 Write_Str
(Name_Buffer
(1 .. Name_Len
));
827 if not List_Representation_Info_To_JSON
then
831 end List_Linker_Section
;
837 procedure List_Location
(Ent
: Entity_Id
) is
839 pragma Assert
(List_Representation_Info_To_JSON
);
840 Write_Str
(" ""location"": """);
841 Write_Location
(Sloc
(Ent
));
845 ---------------------
846 -- List_Mechanisms --
847 ---------------------
849 procedure List_Mechanisms
(Ent
: Entity_Id
) is
850 First
: Boolean := True;
857 if List_Representation_Info_To_JSON
then
859 Write_Str
(" ""name"": """);
864 Write_Str
(" ""Convention"": """);
868 Write_Str
("function ");
871 Write_Str
("operator ");
874 Write_Str
("procedure ");
876 when E_Subprogram_Type
=>
882 Write_Str
("entry ");
889 Write_Str
(" declared at ");
890 Write_Location
(Sloc
(Ent
));
893 Write_Str
("convention : ");
896 case Convention
(Ent
) is
897 when Convention_Ada
=>
900 when Convention_Ada_Pass_By_Copy
=>
901 Write_Str
("Ada_Pass_By_Copy");
903 when Convention_Ada_Pass_By_Reference
=>
904 Write_Str
("Ada_Pass_By_Reference");
906 when Convention_Intrinsic
=>
907 Write_Str
("Intrinsic");
909 when Convention_Entry
=>
912 when Convention_Protected
=>
913 Write_Str
("Protected");
915 when Convention_Assembler
=>
916 Write_Str
("Assembler");
921 when Convention_COBOL
=>
924 when Convention_CPP
=>
927 when Convention_Fortran
=>
928 Write_Str
("Fortran");
930 when Convention_Stdcall
=>
931 Write_Str
("Stdcall");
933 when Convention_Stubbed
=>
934 Write_Str
("Stubbed");
937 if List_Representation_Info_To_JSON
then
939 Write_Str
(" ""formal"": [");
944 -- Find max length of formal name
947 Form
:= First_Formal
(Ent
);
948 while Present
(Form
) loop
949 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
951 if Name_Len
> Plen
then
958 -- Output formals and mechanisms
960 Form
:= First_Formal
(Ent
);
961 while Present
(Form
) loop
962 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
963 Set_Casing
(Unit_Casing
);
965 if List_Representation_Info_To_JSON
then
974 Write_Str
(" ""name"": """);
975 Write_Str
(Name_Buffer
(1 .. Name_Len
));
978 Write_Str
(" ""mechanism"": """);
979 Write_Mechanism
(Mechanism
(Form
));
983 while Name_Len
<= Plen
loop
984 Name_Len
:= Name_Len
+ 1;
985 Name_Buffer
(Name_Len
) := ' ';
989 Write_Str
(Name_Buffer
(1 .. Plen
+ 1));
990 Write_Str
(": passed by ");
992 Write_Mechanism
(Mechanism
(Form
));
999 if List_Representation_Info_To_JSON
then
1004 if Ekind
(Ent
) = E_Function
then
1005 if List_Representation_Info_To_JSON
then
1007 Write_Str
(" ""mechanism"": """);
1008 Write_Mechanism
(Mechanism
(Ent
));
1011 Write_Str
("returns by ");
1012 Write_Mechanism
(Mechanism
(Ent
));
1017 if not Is_Entry
(Ent
) then
1018 List_Linker_Section
(Ent
);
1021 if List_Representation_Info_To_JSON
then
1025 end List_Mechanisms
;
1031 procedure List_Name
(Ent
: Entity_Id
) is
1033 -- List the qualified name recursively, except
1034 -- at compilation unit level in default mode.
1036 if Is_Compilation_Unit
(Ent
) then
1038 elsif not Is_Compilation_Unit
(Scope
(Ent
))
1039 or else List_Representation_Info_To_JSON
1041 List_Name
(Scope
(Ent
));
1045 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
1046 Set_Casing
(Unit_Casing
);
1047 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1050 ---------------------
1051 -- List_Object_Info --
1052 ---------------------
1054 procedure List_Object_Info
(Ent
: Entity_Id
) is
1058 if List_Representation_Info_To_JSON
then
1061 Write_Str
(" ""name"": """);
1064 List_Location
(Ent
);
1066 Write_Str
(" ""Size"": ");
1067 Write_Val
(Esize
(Ent
));
1070 Write_Str
(" ""Alignment"": ");
1071 Write_Val
(Alignment
(Ent
));
1073 List_Linker_Section
(Ent
);
1080 Write_Str
("'Size use ");
1081 Write_Val
(Esize
(Ent
));
1086 Write_Str
("'Alignment use ");
1087 Write_Val
(Alignment
(Ent
));
1090 List_Linker_Section
(Ent
);
1092 end List_Object_Info
;
1094 ----------------------
1095 -- List_Record_Info --
1096 ----------------------
1098 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
1099 procedure Compute_Max_Length
1101 Starting_Position
: Uint
:= Uint_0
;
1102 Starting_First_Bit
: Uint
:= Uint_0
;
1103 Prefix_Length
: Natural := 0);
1104 -- Internal recursive procedure to compute the max length
1106 procedure List_Component_Layout
1108 Starting_Position
: Uint
:= Uint_0
;
1109 Starting_First_Bit
: Uint
:= Uint_0
;
1110 Prefix
: String := "";
1111 Indent
: Natural := 0);
1112 -- Procedure to display the layout of a single component
1114 procedure List_Record_Layout
1116 Starting_Position
: Uint
:= Uint_0
;
1117 Starting_First_Bit
: Uint
:= Uint_0
;
1118 Prefix
: String := "");
1119 -- Internal recursive procedure to display the layout
1121 procedure List_Structural_Record_Layout
1123 Outer_Ent
: Entity_Id
;
1124 Variant
: Node_Id
:= Empty
;
1125 Indent
: Natural := 0);
1126 -- Internal recursive procedure to display the structural layout
1128 Max_Name_Length
: Natural := 0;
1129 Max_Spos_Length
: Natural := 0;
1131 ------------------------
1132 -- Compute_Max_Length --
1133 ------------------------
1135 procedure Compute_Max_Length
1137 Starting_Position
: Uint
:= Uint_0
;
1138 Starting_First_Bit
: Uint
:= Uint_0
;
1139 Prefix_Length
: Natural := 0)
1144 Comp
:= First_Component_Or_Discriminant
(Ent
);
1145 while Present
(Comp
) loop
1147 -- Skip discriminant in unchecked union (since it is not there!)
1149 if Ekind
(Comp
) = E_Discriminant
1150 and then Is_Unchecked_Union
(Ent
)
1155 -- Skip _Parent component in extension (to avoid overlap)
1157 if Chars
(Comp
) = Name_uParent
then
1164 Ctyp
: constant Entity_Id
:= Underlying_Type
(Etype
(Comp
));
1165 Bofs
: constant Uint
:= Component_Bit_Offset
(Comp
);
1171 Name_Length
: Natural;
1174 Get_Decoded_Name_String
(Chars
(Comp
));
1175 Name_Length
:= Prefix_Length
+ Name_Len
;
1177 if Rep_Not_Constant
(Bofs
) then
1179 -- If the record is not packed, then we know that all fields
1180 -- whose position is not specified have starting normalized
1181 -- bit position of zero.
1183 if Unknown_Normalized_First_Bit
(Comp
)
1184 and then not Is_Packed
(Ent
)
1186 Set_Normalized_First_Bit
(Comp
, Uint_0
);
1189 UI_Image_Length
:= 2; -- For "??" marker
1192 Fbit
:= Bofs
mod SSU
;
1194 -- Complete annotation in case not done
1196 if Unknown_Normalized_First_Bit
(Comp
) then
1197 Set_Normalized_Position
(Comp
, Npos
);
1198 Set_Normalized_First_Bit
(Comp
, Fbit
);
1201 Spos
:= Starting_Position
+ Npos
;
1202 Sbit
:= Starting_First_Bit
+ Fbit
;
1209 -- If extended information is requested, recurse fully into
1210 -- record components, i.e. skip the outer level.
1212 if List_Representation_Info_Extended
1213 and then Is_Record_Type
(Ctyp
)
1215 Compute_Max_Length
(Ctyp
, Spos
, Sbit
, Name_Length
+ 1);
1222 Max_Name_Length
:= Natural'Max (Max_Name_Length
, Name_Length
);
1224 Natural'Max (Max_Spos_Length
, UI_Image_Length
);
1228 Next_Component_Or_Discriminant
(Comp
);
1230 end Compute_Max_Length
;
1232 ---------------------------
1233 -- List_Component_Layout --
1234 ---------------------------
1236 procedure List_Component_Layout
1238 Starting_Position
: Uint
:= Uint_0
;
1239 Starting_First_Bit
: Uint
:= Uint_0
;
1240 Prefix
: String := "";
1241 Indent
: Natural := 0)
1243 Esiz
: constant Uint
:= Esize
(Ent
);
1244 Npos
: constant Uint
:= Normalized_Position
(Ent
);
1245 Fbit
: constant Uint
:= Normalized_First_Bit
(Ent
);
1251 if List_Representation_Info_To_JSON
then
1255 Write_Str
(" ""name"": """);
1257 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1259 if Ekind
(Ent
) = E_Discriminant
then
1261 Write_Str
(" ""discriminant"": ");
1262 UI_Write
(Discriminant_Number
(Ent
));
1266 Write_Str
(" ""Position"": ");
1270 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1271 Spaces
(Max_Name_Length
- Prefix
'Length - Name_Len
);
1275 if Known_Static_Normalized_Position
(Ent
) then
1276 Spos
:= Starting_Position
+ Npos
;
1277 Sbit
:= Starting_First_Bit
+ Fbit
;
1284 Spaces
(Max_Spos_Length
- UI_Image_Length
);
1285 Write_Str
(UI_Image_Buffer
(1 .. UI_Image_Length
));
1287 elsif Known_Normalized_Position
(Ent
)
1288 and then List_Representation_Info
>= 3
1290 Spaces
(Max_Spos_Length
- 2);
1292 if Starting_Position
/= Uint_0
then
1293 UI_Write
(Starting_Position
);
1303 if List_Representation_Info_To_JSON
then
1306 Write_Str
(" ""First_Bit"": ");
1308 Write_Str
(" range ");
1311 Sbit
:= Starting_First_Bit
+ Fbit
;
1319 if List_Representation_Info_To_JSON
then
1322 Write_Str
(" ""Size"": ");
1327 -- Allowing Uint_0 here is an annoying special case. Really this
1328 -- should be a fine Esize value but currently it means unknown,
1329 -- except that we know after gigi has back annotated that a size
1330 -- of zero is real, since otherwise gigi back annotates using
1331 -- No_Uint as the value to indicate unknown.
1333 if (Esize
(Ent
) = Uint_0
or else Known_Static_Esize
(Ent
))
1334 and then Known_Static_Normalized_First_Bit
(Ent
)
1336 Lbit
:= Sbit
+ Esiz
- 1;
1338 if List_Representation_Info_To_JSON
then
1348 -- The test for Esize (Ent) not Uint_0 here is an annoying special
1349 -- case. Officially a value of zero for Esize means unknown, but
1350 -- here we use the fact that we know that gigi annotates Esize with
1351 -- No_Uint, not Uint_0. Really everyone should use No_Uint???
1353 elsif List_Representation_Info
< 3
1354 or else (Esize
(Ent
) /= Uint_0
and then Unknown_Esize
(Ent
))
1358 -- List_Representation >= 3 and Known_Esize (Ent)
1361 Write_Val
(Esiz
, Paren
=> not List_Representation_Info_To_JSON
);
1363 -- If in front-end layout mode, then dynamic size is stored in
1364 -- storage units, so renormalize for output.
1366 if not Back_End_Layout
then
1371 -- Add appropriate first bit offset
1373 if not List_Representation_Info_To_JSON
then
1382 Write_Int
(UI_To_Int
(Sbit
) - 1);
1387 if List_Representation_Info_To_JSON
then
1394 end List_Component_Layout
;
1396 ------------------------
1397 -- List_Record_Layout --
1398 ------------------------
1400 procedure List_Record_Layout
1402 Starting_Position
: Uint
:= Uint_0
;
1403 Starting_First_Bit
: Uint
:= Uint_0
;
1404 Prefix
: String := "")
1407 First
: Boolean := True;
1410 Comp
:= First_Component_Or_Discriminant
(Ent
);
1411 while Present
(Comp
) loop
1413 -- Skip discriminant in unchecked union (since it is not there!)
1415 if Ekind
(Comp
) = E_Discriminant
1416 and then Is_Unchecked_Union
(Ent
)
1421 -- Skip _Parent component in extension (to avoid overlap)
1423 if Chars
(Comp
) = Name_uParent
then
1430 Ctyp
: constant Entity_Id
:= Underlying_Type
(Etype
(Comp
));
1431 Npos
: constant Uint
:= Normalized_Position
(Comp
);
1432 Fbit
: constant Uint
:= Normalized_First_Bit
(Comp
);
1437 Get_Decoded_Name_String
(Chars
(Comp
));
1438 Set_Casing
(Unit_Casing
);
1440 -- If extended information is requested, recurse fully into
1441 -- record components, i.e. skip the outer level.
1443 if List_Representation_Info_Extended
1444 and then Is_Record_Type
(Ctyp
)
1445 and then Known_Static_Normalized_Position
(Comp
)
1446 and then Known_Static_Normalized_First_Bit
(Comp
)
1448 Spos
:= Starting_Position
+ Npos
;
1449 Sbit
:= Starting_First_Bit
+ Fbit
;
1456 List_Record_Layout
(Ctyp
,
1457 Spos
, Sbit
, Prefix
& Name_Buffer
(1 .. Name_Len
) & ".");
1462 if List_Representation_Info_To_JSON
then
1471 List_Component_Layout
(Comp
,
1472 Starting_Position
, Starting_First_Bit
, Prefix
);
1476 Next_Component_Or_Discriminant
(Comp
);
1478 end List_Record_Layout
;
1480 -----------------------------------
1481 -- List_Structural_Record_Layout --
1482 -----------------------------------
1484 procedure List_Structural_Record_Layout
1486 Outer_Ent
: Entity_Id
;
1487 Variant
: Node_Id
:= Empty
;
1488 Indent
: Natural := 0)
1490 function Derived_Discriminant
(Disc
: Entity_Id
) return Entity_Id
;
1491 -- This function assumes that Outer_Ent is an extension of Ent.
1492 -- Disc is a discriminant of Ent that does not itself constrain a
1493 -- discriminant of the parent type of Ent. Return the discriminant
1494 -- of Outer_Ent that ultimately constrains Disc, if any.
1496 ----------------------------
1497 -- Derived_Discriminant --
1498 ----------------------------
1500 function Derived_Discriminant
(Disc
: Entity_Id
) return Entity_Id
is
1501 Corr_Disc
: Entity_Id
;
1502 Derived_Disc
: Entity_Id
;
1505 Derived_Disc
:= First_Stored_Discriminant
(Outer_Ent
);
1507 -- Loop over the discriminants of the extension
1509 while Present
(Derived_Disc
) loop
1511 -- Check if this discriminant constrains another discriminant.
1512 -- If so, find the ultimately constrained discriminant and
1513 -- compare with the original components in the base type.
1515 if Present
(Corresponding_Discriminant
(Derived_Disc
)) then
1516 Corr_Disc
:= Corresponding_Discriminant
(Derived_Disc
);
1518 while Present
(Corresponding_Discriminant
(Corr_Disc
)) loop
1519 Corr_Disc
:= Corresponding_Discriminant
(Corr_Disc
);
1522 if Original_Record_Component
(Corr_Disc
) =
1523 Original_Record_Component
(Disc
)
1525 return Derived_Disc
;
1529 Next_Stored_Discriminant
(Derived_Disc
);
1532 -- Disc is not constrained by a discriminant of Outer_Ent
1535 end Derived_Discriminant
;
1537 -- Local declarations
1540 Comp_List
: Node_Id
;
1541 First
: Boolean := True;
1544 -- Start of processing for List_Structural_Record_Layout
1547 -- If we are dealing with a variant, just process the components
1549 if Present
(Variant
) then
1550 Comp_List
:= Component_List
(Variant
);
1552 -- Otherwise, we are dealing with the full record and need to get
1553 -- to its definition in order to retrieve its structural layout.
1557 Definition
: Node_Id
:=
1558 Type_Definition
(Declaration_Node
(Ent
));
1560 Is_Extension
: constant Boolean :=
1561 Is_Tagged_Type
(Ent
)
1562 and then Nkind
(Definition
) =
1563 N_Derived_Type_Definition
;
1566 Listed_Disc
: Entity_Id
;
1569 -- If this is an extension, first list the layout of the parent
1570 -- and then proceed to the extension part, if any.
1572 if Is_Extension
then
1573 List_Structural_Record_Layout
1574 (Base_Type
(Parent_Subtype
(Ent
)), Outer_Ent
);
1577 if Present
(Record_Extension_Part
(Definition
)) then
1578 Definition
:= Record_Extension_Part
(Definition
);
1582 -- If the record has discriminants and is not an unchecked
1583 -- union, then display them now.
1585 if Has_Discriminants
(Ent
)
1586 and then not Is_Unchecked_Union
(Ent
)
1588 Disc
:= First_Stored_Discriminant
(Ent
);
1589 while Present
(Disc
) loop
1591 -- If this is a record extension and the discriminant is
1592 -- the renaming of another discriminant, skip it.
1595 and then Present
(Corresponding_Discriminant
(Disc
))
1600 -- If this is the parent type of an extension, retrieve
1601 -- the derived discriminant from the extension, if any.
1603 if Ent
/= Outer_Ent
then
1604 Listed_Disc
:= Derived_Discriminant
(Disc
);
1606 if No
(Listed_Disc
) then
1610 Listed_Disc
:= Disc
;
1613 Get_Decoded_Name_String
(Chars
(Listed_Disc
));
1614 Set_Casing
(Unit_Casing
);
1623 List_Component_Layout
(Listed_Disc
, Indent
=> Indent
);
1626 Next_Stored_Discriminant
(Disc
);
1630 Comp_List
:= Component_List
(Definition
);
1634 -- Bail out for the null record
1636 if No
(Comp_List
) then
1640 -- Now deal with the regular components, if any
1642 if Present
(Component_Items
(Comp_List
)) then
1643 Comp
:= First_Non_Pragma
(Component_Items
(Comp_List
));
1644 while Present
(Comp
) loop
1646 -- Skip _Parent component in extension (to avoid overlap)
1648 if Chars
(Defining_Identifier
(Comp
)) = Name_uParent
then
1652 Get_Decoded_Name_String
(Chars
(Defining_Identifier
(Comp
)));
1653 Set_Casing
(Unit_Casing
);
1662 List_Component_Layout
1663 (Defining_Identifier
(Comp
), Indent
=> Indent
);
1666 Next_Non_Pragma
(Comp
);
1670 -- We are done if there is no variant part
1672 if No
(Variant_Part
(Comp_List
)) then
1680 Write_Str
(" ""variant"" : [");
1682 -- Otherwise we recurse on each variant
1684 Var
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
1686 while Present
(Var
) loop
1697 Write_Str
(" ""present"": ");
1698 Write_Val
(Present_Expr
(Var
));
1701 Write_Str
(" ""record"": [");
1703 List_Structural_Record_Layout
(Ent
, Outer_Ent
, Var
, Indent
+ 4);
1710 Next_Non_Pragma
(Var
);
1712 end List_Structural_Record_Layout
;
1714 -- Start of processing for List_Record_Info
1719 if List_Representation_Info_To_JSON
then
1723 List_Type_Info
(Ent
);
1725 -- First find out max line length and max starting position
1726 -- length, for the purpose of lining things up nicely.
1728 Compute_Max_Length
(Ent
);
1730 -- Then do actual output based on those values
1732 if List_Representation_Info_To_JSON
then
1734 Write_Str
(" ""record"": [");
1736 if Is_Base_Type
(Ent
) then
1737 List_Structural_Record_Layout
(Ent
, Ent
);
1739 List_Record_Layout
(Ent
);
1747 Write_Line
(" use record");
1749 List_Record_Layout
(Ent
);
1751 Write_Line
("end record;");
1754 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
1756 List_Linker_Section
(Ent
);
1758 if List_Representation_Info_To_JSON
then
1762 end List_Record_Info
;
1768 procedure List_Rep_Info
(Bytes_Big_Endian
: Boolean) is
1772 if List_Representation_Info
/= 0
1773 or else List_Representation_Info_Mechanisms
1775 for U
in Main_Unit
.. Last_Unit
loop
1776 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
)) then
1777 Unit_Casing
:= Identifier_Casing
(Source_Index
(U
));
1779 if List_Representation_Info
= 4 then
1780 Relevant_Entities
.Reset
;
1783 -- Normal case, list to standard output
1785 if not List_Representation_Info_To_File
then
1786 if not List_Representation_Info_To_JSON
then
1788 Write_Str
("Representation information for unit ");
1789 Write_Unit_Name
(Unit_Name
(U
));
1793 for J
in 1 .. Col
- 1 loop
1800 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1802 -- List representation information to file
1805 Create_Repinfo_File_Access
.all
1806 (Get_Name_String
(File_Name
(Source_Index
(U
))));
1807 Set_Special_Output
(Write_Info_Line
'Access);
1808 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1809 Cancel_Special_Output
;
1810 Close_Repinfo_File_Access
.all;
1817 -------------------------------
1818 -- List_Scalar_Storage_Order --
1819 -------------------------------
1821 procedure List_Scalar_Storage_Order
1823 Bytes_Big_Endian
: Boolean)
1825 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean);
1826 -- Show attribute definition clause for Attr_Name (an endianness
1827 -- attribute), depending on whether or not the endianness is reversed
1828 -- compared to native endianness.
1834 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean) is
1836 if List_Representation_Info_To_JSON
then
1839 Write_Str
(Attr_Name
);
1840 Write_Str
(""": ""System.");
1845 Write_Str
(Attr_Name
);
1846 Write_Str
(" use System.");
1849 if Bytes_Big_Endian
xor Is_Reversed
then
1855 Write_Str
("_Order_First");
1856 if List_Representation_Info_To_JSON
then
1863 List_SSO
: constant Boolean :=
1864 Has_Rep_Item
(Ent
, Name_Scalar_Storage_Order
)
1865 or else SSO_Set_Low_By_Default
(Ent
)
1866 or else SSO_Set_High_By_Default
(Ent
);
1867 -- Scalar_Storage_Order is displayed if specified explicitly
1868 -- or set by Default_Scalar_Storage_Order.
1870 -- Start of processing for List_Scalar_Storage_Order
1873 -- For record types, list Bit_Order if not default, or if SSO is shown
1875 if Is_Record_Type
(Ent
)
1876 and then (List_SSO
or else Reverse_Bit_Order
(Ent
))
1878 List_Attr
("Bit_Order", Reverse_Bit_Order
(Ent
));
1881 -- List SSO if required. If not, then storage is supposed to be in
1885 List_Attr
("Scalar_Storage_Order", Reverse_Storage_Order
(Ent
));
1887 pragma Assert
(not Reverse_Storage_Order
(Ent
));
1890 end List_Scalar_Storage_Order
;
1892 --------------------
1893 -- List_Type_Info --
1894 --------------------
1896 procedure List_Type_Info
(Ent
: Entity_Id
) is
1898 if List_Representation_Info_To_JSON
then
1899 Write_Str
(" ""name"": """);
1902 List_Location
(Ent
);
1905 -- Do not list size info for unconstrained arrays, not meaningful
1907 if Is_Array_Type
(Ent
) and then not Is_Constrained
(Ent
) then
1911 -- If Esize and RM_Size are the same, list as Size. This is a common
1912 -- case, which we may as well list in simple form.
1914 if Esize
(Ent
) = RM_Size
(Ent
) then
1915 if List_Representation_Info_To_JSON
then
1916 Write_Str
(" ""Size"": ");
1917 Write_Val
(Esize
(Ent
));
1922 Write_Str
("'Size use ");
1923 Write_Val
(Esize
(Ent
));
1927 -- Otherwise list size values separately
1930 if List_Representation_Info_To_JSON
then
1931 Write_Str
(" ""Object_Size"": ");
1932 Write_Val
(Esize
(Ent
));
1935 Write_Str
(" ""Value_Size"": ");
1936 Write_Val
(RM_Size
(Ent
));
1942 Write_Str
("'Object_Size use ");
1943 Write_Val
(Esize
(Ent
));
1948 Write_Str
("'Value_Size use ");
1949 Write_Val
(RM_Size
(Ent
));
1955 if List_Representation_Info_To_JSON
then
1956 Write_Str
(" ""Alignment"": ");
1957 Write_Val
(Alignment
(Ent
));
1961 Write_Str
("'Alignment use ");
1962 Write_Val
(Alignment
(Ent
));
1966 -- Special stuff for fixed-point
1968 if Is_Fixed_Point_Type
(Ent
) then
1970 -- Write small (always a static constant)
1972 if List_Representation_Info_To_JSON
then
1974 Write_Str
(" ""Small"": ");
1975 UR_Write
(Small_Value
(Ent
));
1979 Write_Str
("'Small use ");
1980 UR_Write
(Small_Value
(Ent
));
1984 -- Write range if static
1987 R
: constant Node_Id
:= Scalar_Range
(Ent
);
1990 if Nkind
(Low_Bound
(R
)) = N_Real_Literal
1992 Nkind
(High_Bound
(R
)) = N_Real_Literal
1994 if List_Representation_Info_To_JSON
then
1996 Write_Str
(" ""Range"": [ ");
1997 UR_Write
(Realval
(Low_Bound
(R
)));
1999 UR_Write
(Realval
(High_Bound
(R
)));
2004 Write_Str
("'Range use ");
2005 UR_Write
(Realval
(Low_Bound
(R
)));
2007 UR_Write
(Realval
(High_Bound
(R
)));
2015 ----------------------
2016 -- Rep_Not_Constant --
2017 ----------------------
2019 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean is
2021 if Val
= No_Uint
or else Val
< 0 then
2026 end Rep_Not_Constant
;
2032 function Rep_Value
(Val
: Node_Ref_Or_Val
; D
: Discrim_List
) return Uint
is
2034 function B
(Val
: Boolean) return Uint
;
2035 -- Returns Uint_0 for False, Uint_1 for True
2037 function T
(Val
: Node_Ref_Or_Val
) return Boolean;
2038 -- Returns True for 0, False for any non-zero (i.e. True)
2040 function V
(Val
: Node_Ref_Or_Val
) return Uint
;
2041 -- Internal recursive routine to evaluate tree
2043 function W
(Val
: Uint
) return Word
;
2044 -- Convert Val to Word, assuming Val is always in the Int range. This
2045 -- is a helper function for the evaluation of bitwise expressions like
2046 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
2047 -- values out of the Int range are expected to be seen in such
2048 -- expressions only with overflowing byte sizes around, introducing
2049 -- inherent unreliabilities in computations anyway.
2055 function B
(Val
: Boolean) return Uint
is
2068 function T
(Val
: Node_Ref_Or_Val
) return Boolean is
2081 function V
(Val
: Node_Ref_Or_Val
) return Uint
is
2090 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
2095 if T
(Node
.Op1
) then
2096 return V
(Node
.Op2
);
2098 return V
(Node
.Op3
);
2102 return V
(Node
.Op1
) + V
(Node
.Op2
);
2105 return V
(Node
.Op1
) - V
(Node
.Op2
);
2108 return V
(Node
.Op1
) * V
(Node
.Op2
);
2110 when Trunc_Div_Expr
=>
2111 return V
(Node
.Op1
) / V
(Node
.Op2
);
2113 when Ceil_Div_Expr
=>
2116 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
2118 when Floor_Div_Expr
=>
2121 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
2123 when Trunc_Mod_Expr
=>
2124 return V
(Node
.Op1
) rem V
(Node
.Op2
);
2126 when Floor_Mod_Expr
=>
2127 return V
(Node
.Op1
) mod V
(Node
.Op2
);
2129 when Ceil_Mod_Expr
=>
2132 Q
:= UR_Ceiling
(L
/ UR_From_Uint
(R
));
2135 when Exact_Div_Expr
=>
2136 return V
(Node
.Op1
) / V
(Node
.Op2
);
2139 return -V
(Node
.Op1
);
2142 return UI_Min
(V
(Node
.Op1
), V
(Node
.Op2
));
2145 return UI_Max
(V
(Node
.Op1
), V
(Node
.Op2
));
2148 return UI_Abs
(V
(Node
.Op1
));
2150 when Truth_And_Expr
=>
2151 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
2153 when Truth_Or_Expr
=>
2154 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
2156 when Truth_Xor_Expr
=>
2157 return B
(T
(Node
.Op1
) xor T
(Node
.Op2
));
2159 when Truth_Not_Expr
=>
2160 return B
(not T
(Node
.Op1
));
2162 when Bit_And_Expr
=>
2165 return UI_From_Int
(Int
(W
(L
) and W
(R
)));
2168 return B
(V
(Node
.Op1
) < V
(Node
.Op2
));
2171 return B
(V
(Node
.Op1
) <= V
(Node
.Op2
));
2174 return B
(V
(Node
.Op1
) > V
(Node
.Op2
));
2177 return B
(V
(Node
.Op1
) >= V
(Node
.Op2
));
2180 return B
(V
(Node
.Op1
) = V
(Node
.Op2
));
2183 return B
(V
(Node
.Op1
) /= V
(Node
.Op2
));
2187 Sub
: constant Int
:= UI_To_Int
(Node
.Op1
);
2189 pragma Assert
(Sub
in D
'Range);
2204 -- We use an unchecked conversion to map Int values to their Word
2205 -- bitwise equivalent, which we could not achieve with a normal type
2206 -- conversion for negative Ints. We want bitwise equivalents because W
2207 -- is used as a helper for bit operators like Bit_And_Expr, and can be
2208 -- called for negative Ints in the context of aligning expressions like
2209 -- X+Align & -Align.
2211 function W
(Val
: Uint
) return Word
is
2212 function To_Word
is new Ada
.Unchecked_Conversion
(Int
, Word
);
2214 return To_Word
(UI_To_Int
(Val
));
2217 -- Start of processing for Rep_Value
2220 if Val
= No_Uint
then
2232 procedure Spaces
(N
: Natural) is
2234 for J
in 1 .. N
loop
2243 procedure Tree_Read
is
2245 Rep_Table
.Tree_Read
;
2252 procedure Tree_Write
is
2254 Rep_Table
.Tree_Write
;
2257 ---------------------
2258 -- Write_Info_Line --
2259 ---------------------
2261 procedure Write_Info_Line
(S
: String) is
2263 Write_Repinfo_Line_Access
.all (S
(S
'First .. S
'Last - 1));
2264 end Write_Info_Line
;
2266 ---------------------
2267 -- Write_Mechanism --
2268 ---------------------
2270 procedure Write_Mechanism
(M
: Mechanism_Type
) is
2274 Write_Str
("default");
2280 Write_Str
("reference");
2283 raise Program_Error
;
2285 end Write_Mechanism
;
2287 -----------------------
2288 -- Write_Unknown_Val --
2289 -----------------------
2291 procedure Write_Unknown_Val
is
2293 if List_Representation_Info_To_JSON
then
2294 Write_Str
("""??""");
2298 end Write_Unknown_Val
;
2304 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False) is
2306 if Rep_Not_Constant
(Val
) then
2307 if List_Representation_Info
< 3 or else Val
= No_Uint
then
2315 if Back_End_Layout
then
2316 List_GCC_Expression
(Val
);
2318 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));