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 (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
139 -- This procedure lists the entities associated with the entity E, starting
140 -- with the First_Entity and using the Next_Entity link. If a nested
141 -- package is found, entities within the package are recursively processed.
143 procedure List_Name (Ent : Entity_Id);
144 -- List name of entity Ent in appropriate case. The name is listed with
145 -- full qualification up to but not including the compilation unit name.
147 procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
148 -- List representation info for array type Ent
150 procedure List_Linker_Section (Ent : Entity_Id);
151 -- List linker section for Ent (caller has checked that Ent is an entity
152 -- for which the Linker_Section_Pragma field is defined).
154 procedure List_Mechanisms (Ent : Entity_Id);
155 -- List mechanism information for parameters of Ent, which is subprogram,
156 -- subprogram type, or an entry or entry family.
158 procedure List_Object_Info (Ent : Entity_Id);
159 -- List representation info for object Ent
161 procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
162 -- List representation info for record type Ent
164 procedure List_Scalar_Storage_Order
166 Bytes_Big_Endian : Boolean);
167 -- List scalar storage order information for record or array type Ent.
168 -- Also includes bit order information for record types, if necessary.
170 procedure List_Type_Info (Ent : Entity_Id);
171 -- List type info for type Ent
173 function Rep_Not_Constant (Val : Node_Ref_Or_Val) return Boolean;
174 -- Returns True if Val represents a variable value, and False if it
175 -- represents a value that is fixed at compile time.
177 procedure Spaces (N : Natural);
178 -- Output given number of spaces
180 procedure Write_Info_Line (S : String);
181 -- Routine to write a line to Repinfo output file. This routine is passed
182 -- as a special output procedure to Output.Set_Special_Output. Note that
183 -- Write_Info_Line is called with an EOL character at the end of each line,
184 -- as per the Output spec, but the internal call to the appropriate routine
185 -- in Osint requires that the end of line sequence be stripped off.
187 procedure Write_Mechanism (M : Mechanism_Type);
188 -- Writes symbolic string for mechanism represented by M
190 procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False);
191 -- Given a representation value, write it out. No_Uint values or values
192 -- dependent on discriminants are written as two question marks. If the
193 -- flag Paren is set, then the output is surrounded in parentheses if it is
194 -- other than a simple value.
196 ---------------------
197 -- Back_End_Layout --
198 ---------------------
200 function Back_End_Layout return Boolean is
202 -- We have back end layout if the back end has made any entries in the
203 -- table of GCC expressions, otherwise we have front end layout.
205 return Rep_Table.Last > 0;
212 procedure Blank_Line is
214 if Need_Blank_Line then
216 Need_Blank_Line := False;
220 ------------------------
221 -- Create_Discrim_Ref --
222 ------------------------
224 function Create_Discrim_Ref (Discr : Entity_Id) return Node_Ref is
227 (Expr => Discrim_Val,
228 Op1 => Discriminant_Number (Discr));
229 end Create_Discrim_Ref;
231 ---------------------------
232 -- Create_Dynamic_SO_Ref --
233 ---------------------------
235 function Create_Dynamic_SO_Ref (E : Entity_Id) return Dynamic_SO_Ref is
237 Dynamic_SO_Entity_Table.Append (E);
238 return UI_From_Int (-Dynamic_SO_Entity_Table.Last);
239 end Create_Dynamic_SO_Ref;
247 Op1 : Node_Ref_Or_Val;
248 Op2 : Node_Ref_Or_Val := No_Uint;
249 Op3 : Node_Ref_Or_Val := No_Uint) return Node_Ref
257 return UI_From_Int (-Rep_Table.Last);
260 ---------------------------
261 -- Get_Dynamic_SO_Entity --
262 ---------------------------
264 function Get_Dynamic_SO_Entity (U : Dynamic_SO_Ref) return Entity_Id is
266 return Dynamic_SO_Entity_Table.Table (-UI_To_Int (U));
267 end Get_Dynamic_SO_Entity;
269 -----------------------
270 -- Is_Dynamic_SO_Ref --
271 -----------------------
273 function Is_Dynamic_SO_Ref (U : SO_Ref) return Boolean is
276 end Is_Dynamic_SO_Ref;
278 ----------------------
279 -- Is_Static_SO_Ref --
280 ----------------------
282 function Is_Static_SO_Ref (U : SO_Ref) return Boolean is
285 end Is_Static_SO_Ref;
291 procedure lgx (U : Node_Ref_Or_Val) is
293 List_GCC_Expression (U);
297 ----------------------
298 -- List_Array_Info --
299 ----------------------
301 procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
303 List_Type_Info (Ent);
306 Write_Str ("'Component_Size use ");
307 Write_Val (Component_Size (Ent));
310 List_Scalar_Storage_Order (Ent, Bytes_Big_Endian);
317 procedure List_Entities (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
321 function Find_Declaration (E : Entity_Id) return Node_Id;
322 -- Utility to retrieve declaration node for entity in the
323 -- case of package bodies and subprograms.
325 ----------------------
326 -- Find_Declaration --
327 ----------------------
329 function Find_Declaration (E : Entity_Id) return Node_Id is
335 and then Nkind (Decl) /= N_Package_Body
336 and then Nkind (Decl) /= N_Subprogram_Declaration
337 and then Nkind (Decl) /= N_Subprogram_Body
339 Decl := Parent (Decl);
343 end Find_Declaration;
345 -- Start of processing for List_Entities
348 -- List entity if we have one, and it is not a renaming declaration.
349 -- For renamings, we don't get proper information, and really it makes
350 -- sense to restrict the output to the renamed entity.
353 and then Nkind (Declaration_Node (Ent)) not in N_Renaming_Declaration
355 -- If entity is a subprogram and we are listing mechanisms,
356 -- then we need to list mechanisms for this entity.
358 if List_Representation_Info_Mechanisms
359 and then (Is_Subprogram (Ent)
360 or else Ekind (Ent) = E_Entry
361 or else Ekind (Ent) = E_Entry_Family)
363 Need_Blank_Line := True;
364 List_Mechanisms (Ent);
367 E := First_Entity (Ent);
368 while Present (E) loop
369 Need_Blank_Line := True;
371 -- We list entities that come from source (excluding private or
372 -- incomplete types or deferred constants, where we will list the
373 -- info for the full view). If debug flag A is set, then all
374 -- entities are listed
376 if (Comes_From_Source (E)
377 and then not Is_Incomplete_Or_Private_Type (E)
378 and then not (Ekind (E) = E_Constant
379 and then Present (Full_View (E))))
380 or else Debug_Flag_AA
382 if Is_Subprogram (E) then
383 List_Linker_Section (E);
385 if List_Representation_Info_Mechanisms then
389 elsif Ekind_In (E, E_Entry,
393 if List_Representation_Info_Mechanisms then
397 elsif Is_Record_Type (E) then
398 if List_Representation_Info >= 1 then
399 List_Record_Info (E, Bytes_Big_Endian);
402 List_Linker_Section (E);
404 elsif Is_Array_Type (E) then
405 if List_Representation_Info >= 1 then
406 List_Array_Info (E, Bytes_Big_Endian);
409 List_Linker_Section (E);
411 elsif Is_Type (E) then
412 if List_Representation_Info >= 2 then
414 List_Linker_Section (E);
417 elsif Ekind_In (E, E_Variable, E_Constant) then
418 if List_Representation_Info >= 2 then
419 List_Object_Info (E);
420 List_Linker_Section (E);
423 elsif Ekind (E) = E_Loop_Parameter or else Is_Formal (E) then
424 if List_Representation_Info >= 2 then
425 List_Object_Info (E);
429 -- Recurse into nested package, but not if they are package
430 -- renamings (in particular renamings of the enclosing package,
431 -- as for some Java bindings and for generic instances).
433 if Ekind (E) = E_Package then
434 if No (Renamed_Object (E)) then
435 List_Entities (E, Bytes_Big_Endian);
438 -- Recurse into bodies
440 elsif Ekind_In (E, E_Protected_Type,
447 List_Entities (E, Bytes_Big_Endian);
449 -- Recurse into blocks
451 elsif Ekind (E) = E_Block then
452 List_Entities (E, Bytes_Big_Endian);
456 E := Next_Entity (E);
459 -- For a package body, the entities of the visible subprograms are
460 -- declared in the corresponding spec. Iterate over its entities in
461 -- order to handle properly the subprogram bodies. Skip bodies in
462 -- subunits, which are listed independently.
464 if Ekind (Ent) = E_Package_Body
465 and then Present (Corresponding_Spec (Find_Declaration (Ent)))
467 E := First_Entity (Corresponding_Spec (Find_Declaration (Ent)));
468 while Present (E) loop
471 Nkind (Find_Declaration (E)) = N_Subprogram_Declaration
473 Body_E := Corresponding_Body (Find_Declaration (E));
477 Nkind (Parent (Find_Declaration (Body_E))) /= N_Subunit
479 List_Entities (Body_E, Bytes_Big_Endian);
489 -------------------------
490 -- List_GCC_Expression --
491 -------------------------
493 procedure List_GCC_Expression (U : Node_Ref_Or_Val) is
495 procedure Print_Expr (Val : Node_Ref_Or_Val);
496 -- Internal recursive procedure to print expression
502 procedure Print_Expr (Val : Node_Ref_Or_Val) is
505 UI_Write (Val, Decimal);
509 Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));
511 procedure Binop (S : String);
512 -- Output text for binary operator with S being operator name
518 procedure Binop (S : String) is
521 Print_Expr (Node.Op1);
523 Print_Expr (Node.Op2);
527 -- Start of processing for Print_Expr
533 Print_Expr (Node.Op1);
534 Write_Str (" then ");
535 Print_Expr (Node.Op2);
536 Write_Str (" else ");
537 Print_Expr (Node.Op3);
549 when Trunc_Div_Expr =>
552 when Ceil_Div_Expr =>
555 when Floor_Div_Expr =>
558 when Trunc_Mod_Expr =>
561 when Floor_Mod_Expr =>
564 when Ceil_Mod_Expr =>
567 when Exact_Div_Expr =>
572 Print_Expr (Node.Op1);
582 Print_Expr (Node.Op1);
584 when Truth_Andif_Expr =>
587 when Truth_Orif_Expr =>
590 when Truth_And_Expr =>
593 when Truth_Or_Expr =>
596 when Truth_Xor_Expr =>
599 when Truth_Not_Expr =>
601 Print_Expr (Node.Op1);
633 -- Start of processing for List_GCC_Expression
641 end List_GCC_Expression;
643 -------------------------
644 -- List_Linker_Section --
645 -------------------------
647 procedure List_Linker_Section (Ent : Entity_Id) is
651 if Present (Linker_Section_Pragma (Ent)) then
652 Write_Str ("pragma Linker_Section (");
657 Last (Pragma_Argument_Associations (Linker_Section_Pragma (Ent)));
659 if Nkind (Arg) = N_Pragma_Argument_Association then
660 Arg := Expression (Arg);
663 pragma Assert (Nkind (Arg) = N_String_Literal);
664 String_To_Name_Buffer (Strval (Arg));
665 Write_Str (Name_Buffer (1 .. Name_Len));
669 end List_Linker_Section;
671 ---------------------
672 -- List_Mechanisms --
673 ---------------------
675 procedure List_Mechanisms (Ent : Entity_Id) is
684 Write_Str ("function ");
687 Write_Str ("operator ");
690 Write_Str ("procedure ");
692 when E_Subprogram_Type =>
695 when E_Entry | E_Entry_Family =>
696 Write_Str ("entry ");
702 Get_Unqualified_Decoded_Name_String (Chars (Ent));
703 Write_Str (Name_Buffer (1 .. Name_Len));
704 Write_Str (" declared at ");
705 Write_Location (Sloc (Ent));
708 Write_Str (" convention : ");
710 case Convention (Ent) is
711 when Convention_Ada =>
713 when Convention_Ada_Pass_By_Copy =>
714 Write_Line ("Ada_Pass_By_Copy");
715 when Convention_Ada_Pass_By_Reference =>
716 Write_Line ("Ada_Pass_By_Reference");
717 when Convention_Intrinsic =>
718 Write_Line ("Intrinsic");
719 when Convention_Entry =>
720 Write_Line ("Entry");
721 when Convention_Protected =>
722 Write_Line ("Protected");
723 when Convention_Assembler =>
724 Write_Line ("Assembler");
727 when Convention_COBOL =>
728 Write_Line ("COBOL");
729 when Convention_CPP =>
731 when Convention_Fortran =>
732 Write_Line ("Fortran");
733 when Convention_Stdcall =>
734 Write_Line ("Stdcall");
735 when Convention_Stubbed =>
736 Write_Line ("Stubbed");
739 -- Find max length of formal name
742 Form := First_Formal (Ent);
743 while Present (Form) loop
744 Get_Unqualified_Decoded_Name_String (Chars (Form));
746 if Name_Len > Plen then
753 -- Output formals and mechanisms
755 Form := First_Formal (Ent);
756 while Present (Form) loop
757 Get_Unqualified_Decoded_Name_String (Chars (Form));
758 while Name_Len <= Plen loop
759 Name_Len := Name_Len + 1;
760 Name_Buffer (Name_Len) := ' ';
764 Write_Str (Name_Buffer (1 .. Plen + 1));
765 Write_Str (": passed by ");
767 Write_Mechanism (Mechanism (Form));
772 if Etype (Ent) /= Standard_Void_Type then
773 Write_Str (" returns by ");
774 Write_Mechanism (Mechanism (Ent));
783 procedure List_Name (Ent : Entity_Id) is
785 if not Is_Compilation_Unit (Scope (Ent)) then
786 List_Name (Scope (Ent));
790 Get_Unqualified_Decoded_Name_String (Chars (Ent));
791 Set_Casing (Unit_Casing);
792 Write_Str (Name_Buffer (1 .. Name_Len));
795 ---------------------
796 -- List_Object_Info --
797 ---------------------
799 procedure List_Object_Info (Ent : Entity_Id) is
805 Write_Str ("'Size use ");
806 Write_Val (Esize (Ent));
811 Write_Str ("'Alignment use ");
812 Write_Val (Alignment (Ent));
814 end List_Object_Info;
816 ----------------------
817 -- List_Record_Info --
818 ----------------------
820 procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
825 Max_Name_Length : Natural;
826 Max_Suni_Length : Natural;
830 List_Type_Info (Ent);
834 Write_Line (" use record");
836 -- First loop finds out max line length and max starting position
837 -- length, for the purpose of lining things up nicely.
839 Max_Name_Length := 0;
840 Max_Suni_Length := 0;
842 Comp := First_Component_Or_Discriminant (Ent);
843 while Present (Comp) loop
845 -- Skip discriminant in unchecked union (since it is not there!)
847 if Ekind (Comp) = E_Discriminant
848 and then Is_Unchecked_Union (Ent)
855 Get_Decoded_Name_String (Chars (Comp));
856 Max_Name_Length := Natural'Max (Max_Name_Length, Name_Len);
858 Cfbit := Component_Bit_Offset (Comp);
860 if Rep_Not_Constant (Cfbit) then
861 UI_Image_Length := 2;
864 -- Complete annotation in case not done
866 Set_Normalized_Position (Comp, Cfbit / SSU);
867 Set_Normalized_First_Bit (Comp, Cfbit mod SSU);
869 Sunit := Cfbit / SSU;
873 -- If the record is not packed, then we know that all fields
874 -- whose position is not specified have a starting normalized
875 -- bit position of zero.
877 if Unknown_Normalized_First_Bit (Comp)
878 and then not Is_Packed (Ent)
880 Set_Normalized_First_Bit (Comp, Uint_0);
884 Natural'Max (Max_Suni_Length, UI_Image_Length);
887 Next_Component_Or_Discriminant (Comp);
890 -- Second loop does actual output based on those values
892 Comp := First_Component_Or_Discriminant (Ent);
893 while Present (Comp) loop
895 -- Skip discriminant in unchecked union (since it is not there!)
897 if Ekind (Comp) = E_Discriminant
898 and then Is_Unchecked_Union (Ent)
906 Esiz : constant Uint := Esize (Comp);
907 Bofs : constant Uint := Component_Bit_Offset (Comp);
908 Npos : constant Uint := Normalized_Position (Comp);
909 Fbit : constant Uint := Normalized_First_Bit (Comp);
914 Get_Decoded_Name_String (Chars (Comp));
915 Set_Casing (Unit_Casing);
916 Write_Str (Name_Buffer (1 .. Name_Len));
918 for J in 1 .. Max_Name_Length - Name_Len loop
924 if Known_Static_Normalized_Position (Comp) then
926 Spaces (Max_Suni_Length - UI_Image_Length);
927 Write_Str (UI_Image_Buffer (1 .. UI_Image_Length));
929 elsif Known_Component_Bit_Offset (Comp)
930 and then List_Representation_Info = 3
932 Spaces (Max_Suni_Length - 2);
933 Write_Str ("bit offset");
934 Write_Val (Bofs, Paren => True);
935 Write_Str (" size in bits = ");
936 Write_Val (Esiz, Paren => True);
940 elsif Known_Normalized_Position (Comp)
941 and then List_Representation_Info = 3
943 Spaces (Max_Suni_Length - 2);
947 -- For the packed case, we don't know the bit positions if we
948 -- don't know the starting position.
950 if Is_Packed (Ent) then
951 Write_Line ("?? range ? .. ??;");
954 -- Otherwise we can continue
961 Write_Str (" range ");
965 -- Allowing Uint_0 here is an annoying special case. Really this
966 -- should be a fine Esize value but currently it means unknown,
967 -- except that we know after gigi has back annotated that a size
968 -- of zero is real, since otherwise gigi back annotates using
969 -- No_Uint as the value to indicate unknown).
971 if (Esize (Comp) = Uint_0 or else Known_Static_Esize (Comp))
972 and then Known_Static_Normalized_First_Bit (Comp)
974 Lbit := Fbit + Esiz - 1;
982 -- The test for Esize (Comp) not Uint_0 here is an annoying
983 -- special case. Officially a value of zero for Esize means
984 -- unknown, but here we use the fact that we know that gigi
985 -- annotates Esize with No_Uint, not Uint_0. Really everyone
986 -- should use No_Uint???
988 elsif List_Representation_Info < 3
989 or else (Esize (Comp) /= Uint_0 and then Unknown_Esize (Comp))
993 -- List_Representation >= 3 and Known_Esize (Comp)
996 Write_Val (Esiz, Paren => True);
998 -- If in front end layout mode, then dynamic size is stored
999 -- in storage units, so renormalize for output
1001 if not Back_End_Layout then
1006 -- Add appropriate first bit offset
1016 Write_Int (UI_To_Int (Fbit) - 1);
1024 Next_Component_Or_Discriminant (Comp);
1027 Write_Line ("end record;");
1029 List_Scalar_Storage_Order (Ent, Bytes_Big_Endian);
1030 end List_Record_Info;
1036 procedure List_Rep_Info (Bytes_Big_Endian : Boolean) is
1040 if List_Representation_Info /= 0
1041 or else List_Representation_Info_Mechanisms
1043 for U in Main_Unit .. Last_Unit loop
1044 if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then
1045 Unit_Casing := Identifier_Casing (Source_Index (U));
1047 -- Normal case, list to standard output
1049 if not List_Representation_Info_To_File then
1051 Write_Str ("Representation information for unit ");
1052 Write_Unit_Name (Unit_Name (U));
1056 for J in 1 .. Col - 1 loop
1061 List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
1063 -- List representation information to file
1066 Create_Repinfo_File_Access.all
1067 (Get_Name_String (File_Name (Source_Index (U))));
1068 Set_Special_Output (Write_Info_Line'Access);
1069 List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
1070 Set_Special_Output (null);
1071 Close_Repinfo_File_Access.all;
1078 -------------------------------
1079 -- List_Scalar_Storage_Order --
1080 -------------------------------
1082 procedure List_Scalar_Storage_Order
1084 Bytes_Big_Endian : Boolean)
1086 procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean);
1087 -- Show attribute definition clause for Attr_Name (an endianness
1088 -- attribute), depending on whether or not the endianness is reversed
1089 -- compared to native endianness.
1095 procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean) is
1099 Write_Str ("'" & Attr_Name & " use System.");
1101 if Bytes_Big_Endian xor Is_Reversed then
1107 Write_Line ("_Order_First;");
1110 List_SSO : constant Boolean :=
1111 Has_Rep_Item (Ent, Name_Scalar_Storage_Order)
1112 or else SSO_Set_Low_By_Default (Ent)
1113 or else SSO_Set_High_By_Default (Ent);
1114 -- Scalar_Storage_Order is displayed if specified explicitly
1115 -- or set by Default_Scalar_Storage_Order.
1117 -- Start of processing for List_Scalar_Storage_Order
1120 -- For record types, list Bit_Order if not default, or if SSO is shown
1122 if Is_Record_Type (Ent)
1123 and then (List_SSO or else Reverse_Bit_Order (Ent))
1125 List_Attr ("Bit_Order", Reverse_Bit_Order (Ent));
1128 -- List SSO if required. If not, then storage is supposed to be in
1132 List_Attr ("Scalar_Storage_Order", Reverse_Storage_Order (Ent));
1134 pragma Assert (not Reverse_Storage_Order (Ent));
1137 end List_Scalar_Storage_Order;
1139 --------------------
1140 -- List_Type_Info --
1141 --------------------
1143 procedure List_Type_Info (Ent : Entity_Id) is
1147 -- Do not list size info for unconstrained arrays, not meaningful
1149 if Is_Array_Type (Ent) and then not Is_Constrained (Ent) then
1153 -- If Esize and RM_Size are the same and known, list as Size. This
1154 -- is a common case, which we may as well list in simple form.
1156 if Esize (Ent) = RM_Size (Ent) then
1159 Write_Str ("'Size use ");
1160 Write_Val (Esize (Ent));
1163 -- For now, temporary case, to be removed when gigi properly back
1164 -- annotates RM_Size, if RM_Size is not set, then list Esize as Size.
1165 -- This avoids odd Object_Size output till we fix things???
1167 elsif Unknown_RM_Size (Ent) then
1170 Write_Str ("'Size use ");
1171 Write_Val (Esize (Ent));
1174 -- Otherwise list size values separately if they are set
1179 Write_Str ("'Object_Size use ");
1180 Write_Val (Esize (Ent));
1183 -- Note on following check: The RM_Size of a discrete type can
1184 -- legitimately be set to zero, so a special check is needed.
1188 Write_Str ("'Value_Size use ");
1189 Write_Val (RM_Size (Ent));
1196 Write_Str ("'Alignment use ");
1197 Write_Val (Alignment (Ent));
1200 -- Special stuff for fixed-point
1202 if Is_Fixed_Point_Type (Ent) then
1204 -- Write small (always a static constant)
1208 Write_Str ("'Small use ");
1209 UR_Write (Small_Value (Ent));
1212 -- Write range if static
1215 R : constant Node_Id := Scalar_Range (Ent);
1218 if Nkind (Low_Bound (R)) = N_Real_Literal
1220 Nkind (High_Bound (R)) = N_Real_Literal
1224 Write_Str ("'Range use ");
1225 UR_Write (Realval (Low_Bound (R)));
1227 UR_Write (Realval (High_Bound (R)));
1234 ----------------------
1235 -- Rep_Not_Constant --
1236 ----------------------
1238 function Rep_Not_Constant (Val : Node_Ref_Or_Val) return Boolean is
1240 if Val = No_Uint or else Val < 0 then
1245 end Rep_Not_Constant;
1252 (Val : Node_Ref_Or_Val;
1253 D : Discrim_List) return Uint
1255 function B (Val : Boolean) return Uint;
1256 -- Returns Uint_0 for False, Uint_1 for True
1258 function T (Val : Node_Ref_Or_Val) return Boolean;
1259 -- Returns True for 0, False for any non-zero (i.e. True)
1261 function V (Val : Node_Ref_Or_Val) return Uint;
1262 -- Internal recursive routine to evaluate tree
1264 function W (Val : Uint) return Word;
1265 -- Convert Val to Word, assuming Val is always in the Int range. This
1266 -- is a helper function for the evaluation of bitwise expressions like
1267 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
1268 -- values out of the Int range are expected to be seen in such
1269 -- expressions only with overflowing byte sizes around, introducing
1270 -- inherent unreliabilities in computations anyway.
1276 function B (Val : Boolean) return Uint is
1289 function T (Val : Node_Ref_Or_Val) return Boolean is
1302 function V (Val : Node_Ref_Or_Val) return Uint is
1311 Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));
1316 if T (Node.Op1) then
1317 return V (Node.Op2);
1319 return V (Node.Op3);
1323 return V (Node.Op1) + V (Node.Op2);
1326 return V (Node.Op1) - V (Node.Op2);
1329 return V (Node.Op1) * V (Node.Op2);
1331 when Trunc_Div_Expr =>
1332 return V (Node.Op1) / V (Node.Op2);
1334 when Ceil_Div_Expr =>
1337 (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));
1339 when Floor_Div_Expr =>
1342 (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));
1344 when Trunc_Mod_Expr =>
1345 return V (Node.Op1) rem V (Node.Op2);
1347 when Floor_Mod_Expr =>
1348 return V (Node.Op1) mod V (Node.Op2);
1350 when Ceil_Mod_Expr =>
1353 Q := UR_Ceiling (L / UR_From_Uint (R));
1356 when Exact_Div_Expr =>
1357 return V (Node.Op1) / V (Node.Op2);
1360 return -V (Node.Op1);
1363 return UI_Min (V (Node.Op1), V (Node.Op2));
1366 return UI_Max (V (Node.Op1), V (Node.Op2));
1369 return UI_Abs (V (Node.Op1));
1371 when Truth_Andif_Expr =>
1372 return B (T (Node.Op1) and then T (Node.Op2));
1374 when Truth_Orif_Expr =>
1375 return B (T (Node.Op1) or else T (Node.Op2));
1377 when Truth_And_Expr =>
1378 return B (T (Node.Op1) and then T (Node.Op2));
1380 when Truth_Or_Expr =>
1381 return B (T (Node.Op1) or else T (Node.Op2));
1383 when Truth_Xor_Expr =>
1384 return B (T (Node.Op1) xor T (Node.Op2));
1386 when Truth_Not_Expr =>
1387 return B (not T (Node.Op1));
1389 when Bit_And_Expr =>
1392 return UI_From_Int (Int (W (L) and W (R)));
1395 return B (V (Node.Op1) < V (Node.Op2));
1398 return B (V (Node.Op1) <= V (Node.Op2));
1401 return B (V (Node.Op1) > V (Node.Op2));
1404 return B (V (Node.Op1) >= V (Node.Op2));
1407 return B (V (Node.Op1) = V (Node.Op2));
1410 return B (V (Node.Op1) /= V (Node.Op2));
1414 Sub : constant Int := UI_To_Int (Node.Op1);
1416 pragma Assert (Sub in D'Range);
1429 -- We use an unchecked conversion to map Int values to their Word
1430 -- bitwise equivalent, which we could not achieve with a normal type
1431 -- conversion for negative Ints. We want bitwise equivalents because W
1432 -- is used as a helper for bit operators like Bit_And_Expr, and can be
1433 -- called for negative Ints in the context of aligning expressions like
1434 -- X+Align & -Align.
1436 function W (Val : Uint) return Word is
1437 function To_Word is new Ada.Unchecked_Conversion (Int, Word);
1439 return To_Word (UI_To_Int (Val));
1442 -- Start of processing for Rep_Value
1445 if Val = No_Uint then
1457 procedure Spaces (N : Natural) is
1459 for J in 1 .. N loop
1468 procedure Tree_Read is
1470 Rep_Table.Tree_Read;
1477 procedure Tree_Write is
1479 Rep_Table.Tree_Write;
1482 ---------------------
1483 -- Write_Info_Line --
1484 ---------------------
1486 procedure Write_Info_Line (S : String) is
1488 Write_Repinfo_Line_Access.all (S (S'First .. S'Last - 1));
1489 end Write_Info_Line;
1491 ---------------------
1492 -- Write_Mechanism --
1493 ---------------------
1495 procedure Write_Mechanism (M : Mechanism_Type) is
1499 Write_Str ("default");
1505 Write_Str ("reference");
1508 raise Program_Error;
1510 end Write_Mechanism;
1516 procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False) is
1518 if Rep_Not_Constant (Val) then
1519 if List_Representation_Info < 3 or else Val = No_Uint then
1523 if Back_End_Layout then
1528 List_GCC_Expression (Val);
1531 List_GCC_Expression (Val);
1539 Write_Name_Decoded (Chars (Get_Dynamic_SO_Entity (Val)));
1542 Write_Name_Decoded (Chars (Get_Dynamic_SO_Entity (Val)));