From: Eric Botcazou Date: Wed, 14 Nov 2018 11:42:16 +0000 (+0000) Subject: [Ada] More complete information level for -gnatR output X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b5f581cdbba4f24c762f9e7d9741b7488bf752d7;p=gcc.git [Ada] More complete information level for -gnatR output This adds a 4th information level for the -gnatR output, where relevant compiler-generated types are listed in addition to the information already output by -gnatR3. For the following package P: package P is type Arr0 is array (Positive range <>) of Boolean; type Rec (D1 : Positive; D2 : Boolean) is record C1 : Integer; C2 : Arr0 (1 .. D1); case D2 is when False => C3 : Character; when True => C4 : String (1 .. 3); C5 : Float; end case; end record; type Arr1 is array (1 .. 8) of Rec (1, True); end P; the output generated by -gnatR4 must be: Representation information for unit P (spec) -------------------------------------------- for Arr0'Alignment use 1; for Arr0'Component_Size use 8; for Rec'Object_Size use 17179869344; for Rec'Value_Size use (if (#2 != 0) then ((((#1 + 15) & -4) + 8) * 8) else ((((#1 + 15) & -4) + 1) * 8) end); for Rec'Alignment use 4; for Rec use record D1 at 0 range 0 .. 31; D2 at 4 range 0 .. 7; C1 at 8 range 0 .. 31; C2 at 12 range 0 .. ((#1 * 8)) - 1; C3 at ((#1 + 15) & -4) range 0 .. 7; C4 at ((#1 + 15) & -4) range 0 .. 23; C5 at (((#1 + 15) & -4) + 4) range 0 .. 31; end record; for Arr1'Size use 1536; for Arr1'Alignment use 4; for Arr1'Component_Size use 192; for Tarr1c'Size use 192; for Tarr1c'Alignment use 4; for Tarr1c use record D1 at 0 range 0 .. 31; D2 at 4 range 0 .. 7; C1 at 8 range 0 .. 31; C2 at 12 range 0 .. 7; C4 at 16 range 0 .. 23; C5 at 20 range 0 .. 31; end record; 2018-11-14 Eric Botcazou gcc/ada/ * doc/gnat_ugn/building_executable_programs_with_gnat.rst (-gnatR): Document new -gnatR4 level. * gnat_ugn.texi: Regenerate. * opt.ads (List_Representation_Info): Bump upper bound to 4. * repinfo.adb: Add with clause for GNAT.HTable. (Relevant_Entities_Size): New constant. (Entity_Header_Num): New type. (Entity_Hash): New function. (Relevant_Entities): New set implemented with GNAT.HTable. (List_Entities): Also list compiled-generated entities present in the Relevant_Entities set. Consider that the Component_Type of an array type is relevant. (List_Rep_Info): Reset Relevant_Entities for each unit. * switch-c.adb (Scan_Front_End_Switches): Add support for -gnatR4. * switch-m.adb (Normalize_Compiler_Switches): Likewise * usage.adb (Usage): Likewise. From-SVN: r266131 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 7390a5c5291..1de2a84915c 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,22 @@ +2018-11-14 Eric Botcazou + + * doc/gnat_ugn/building_executable_programs_with_gnat.rst + (-gnatR): Document new -gnatR4 level. + * gnat_ugn.texi: Regenerate. + * opt.ads (List_Representation_Info): Bump upper bound to 4. + * repinfo.adb: Add with clause for GNAT.HTable. + (Relevant_Entities_Size): New constant. + (Entity_Header_Num): New type. + (Entity_Hash): New function. + (Relevant_Entities): New set implemented with GNAT.HTable. + (List_Entities): Also list compiled-generated entities present + in the Relevant_Entities set. Consider that the Component_Type + of an array type is relevant. + (List_Rep_Info): Reset Relevant_Entities for each unit. + * switch-c.adb (Scan_Front_End_Switches): Add support for -gnatR4. + * switch-m.adb (Normalize_Compiler_Switches): Likewise + * usage.adb (Usage): Likewise. + 2018-11-14 Javier Miranda * exp_disp.adb (Expand_Interface_Thunk): Extend handling of diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst index 1455087b1eb..1b69bdd457a 100644 --- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst +++ b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst @@ -2081,7 +2081,7 @@ Alphabetical List of All Switches .. index:: -gnatR (gcc) -:switch:`-gnatR[0|1|2|3][e][j][m][s]` +:switch:`-gnatR[0|1|2|3|4][e][j][m][s]` Output representation information for declared types, objects and subprograms. Note that this switch is not allowed if a previous :switch:`-gnatD` switch has been given, since these two switches @@ -5843,13 +5843,14 @@ Debugging Control .. index:: -gnatR (gcc) -:switch:`-gnatR[0|1|2|3][e][j][m][s]` +:switch:`-gnatR[0|1|2|3|4][e][j][m][s]` This switch controls output from the compiler of a listing showing representation information for declared types, objects and subprograms. For :switch:`-gnatR0`, no information is output (equivalent to omitting the :switch:`-gnatR` switch). For :switch:`-gnatR1` (which is the default, so :switch:`-gnatR` with no parameter has the same effect), size and alignment information is listed for declared array and record types. + For :switch:`-gnatR2`, size and alignment information is listed for all declared types and objects. The ``Linker_Section`` is also listed for any entity for which the ``Linker_Section`` is set explicitly or implicitly (the @@ -5862,9 +5863,13 @@ Debugging Control n'th discriminant. See source files :file:`repinfo.ads/adb` in the GNAT sources for full details on the format of :switch:`-gnatR3` output. + For :switch:`-gnatR4`, information for relevant compiler-generated types + is also listed, i.e. when they are structurally part of other declared + types and objects. + If the switch is followed by an ``e`` (e.g. :switch:`-gnatR2e`), then extended representation information for record sub-components of records - are included. + is included. If the switch is followed by an ``m`` (e.g. :switch:`-gnatRm`), then subprogram conventions and parameter passing mechanisms for all the diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi index aeaa1461c05..d28d53dc7fa 100644 --- a/gcc/ada/gnat_ugn.texi +++ b/gcc/ada/gnat_ugn.texi @@ -21,7 +21,7 @@ @copying @quotation -GNAT User's Guide for Native Platforms , Aug 20, 2018 +GNAT User's Guide for Native Platforms , Nov 09, 2018 AdaCore @@ -9977,7 +9977,7 @@ Treat pragma Restrictions as Restriction_Warnings. @table @asis -@item @code{-gnatR[0|1|2|3][e][j][m][s]} +@item @code{-gnatR[0|1|2|3|4][e][j][m][s]} Output representation information for declared types, objects and subprograms. Note that this switch is not allowed if a previous @@ -15092,7 +15092,7 @@ restriction warnings rather than restrictions. @table @asis -@item @code{-gnatR[0|1|2|3][e][j][m][s]} +@item @code{-gnatR[0|1|2|3|4][e][j][m][s]} This switch controls output from the compiler of a listing showing representation information for declared types, objects and subprograms. @@ -15100,6 +15100,7 @@ For @code{-gnatR0}, no information is output (equivalent to omitting the @code{-gnatR} switch). For @code{-gnatR1} (which is the default, so @code{-gnatR} with no parameter has the same effect), size and alignment information is listed for declared array and record types. + For @code{-gnatR2}, size and alignment information is listed for all declared types and objects. The @code{Linker_Section} is also listed for any entity for which the @code{Linker_Section} is set explicitly or implicitly (the @@ -15112,9 +15113,13 @@ a mostly obvious format with #n being used to represent the value of the n'th discriminant. See source files @code{repinfo.ads/adb} in the GNAT sources for full details on the format of @code{-gnatR3} output. +For @code{-gnatR4}, information for relevant compiler-generated types +is also listed, i.e. when they are structurally part of other declared +types and objects. + If the switch is followed by an @code{e} (e.g. @code{-gnatR2e}), then extended representation information for record sub-components of records -are included. +is included. If the switch is followed by an @code{m} (e.g. @code{-gnatRm}), then subprogram conventions and parameter passing mechanisms for all the diff --git a/gcc/ada/opt.ads b/gcc/ada/opt.ads index 26143030da1..668d41304d8 100644 --- a/gcc/ada/opt.ads +++ b/gcc/ada/opt.ads @@ -986,26 +986,27 @@ package Opt is -- the list of object dependencies (-M switch). Output depends if -a switch -- is used or not. This list can be used directly in a Makefile. - List_Representation_Info : Int range 0 .. 3 := 0; + List_Representation_Info : Int range 0 .. 4 := 0; -- GNAT -- Set non-zero by -gnatR switch to list representation information. -- The settings are as follows: -- -- 0 = no listing of representation information (default as above) - -- 1 = list rep info for user defined record and array types - -- 2 = list rep info for all user defined types and objects + -- 1 = list rep info for user-defined record and array types + -- 2 = list rep info for all user-defined types and objects -- 3 = like 2, but variable fields are decoded symbolically + -- 4 = like 3, but list rep info for relevant compiler-generated types List_Representation_Info_To_File : Boolean := False; -- GNAT - -- Set true by -gnatRs switch. Causes information from -gnatR/1/2/3/m to be + -- Set true by -gnatRs switch. Causes information from -gnatR[1-4]m to be -- written to file.rep (where file is the name of the source file) instead -- of stdout. For example, if file x.adb is compiled using -gnatR2s then -- representation info is written to x.adb.ref. List_Representation_Info_To_JSON : Boolean := False; -- GNAT - -- Set true by -gnatRj switch. Causes information from -gnatR/1/2/3/m to be + -- Set true by -gnatRj switch. Causes information from -gnatR[1-4]m to be -- output in the JSON data interchange format. List_Representation_Info_Mechanisms : Boolean := False; diff --git a/gcc/ada/repinfo.adb b/gcc/ada/repinfo.adb index 2a0d568777b..d0d46fcde4f 100644 --- a/gcc/ada/repinfo.adb +++ b/gcc/ada/repinfo.adb @@ -50,6 +50,8 @@ with Urealp; use Urealp; with Ada.Unchecked_Conversion; +with GNAT.HTable; + package body Repinfo is SSU : constant := 8; @@ -118,6 +120,28 @@ package body Repinfo is -- the current entity. Set True when a new entity is processed, and false -- when the blank line is output. + ------------------------------- + -- Set of Relevant Entities -- + ------------------------------- + + Relevant_Entities_Size : constant := 4093; + -- Number of headers in hash table + + subtype Entity_Header_Num is Integer range 0 .. Relevant_Entities_Size - 1; + -- Range of headers in hash table + + function Entity_Hash (Id : Entity_Id) return Entity_Header_Num; + -- Simple hash function for Entity_Ids + + package Relevant_Entities is new GNAT.Htable.Simple_HTable + (Header_Num => Entity_Header_Num, + Element => Boolean, + No_Element => False, + Key => Entity_Id, + Hash => Entity_Hash, + Equal => "="); + -- Hash table to record which compiler-generated entities are relevant + ----------------------- -- Local Subprograms -- ----------------------- @@ -264,6 +288,15 @@ package body Repinfo is return UI_From_Int (-Rep_Table.Last); end Create_Node; + ----------------- + -- Entity_Hash -- + ----------------- + + function Entity_Hash (Id : Entity_Id) return Entity_Header_Num is + begin + return Entity_Header_Num (Id mod Relevant_Entities_Size); + end Entity_Hash; + --------------------------- -- Get_Dynamic_SO_Entity -- --------------------------- @@ -403,9 +436,11 @@ package body Repinfo is Need_Blank_Line := True; -- We list entities that come from source (excluding private or - -- incomplete types or deferred constants, where we will list the - -- info for the full view). If debug flag A is set, then all - -- entities are listed + -- incomplete types or deferred constants, for which we will list + -- the information for the full view). If requested, we also list + -- relevant entities that have been generated when processing the + -- original entities coming from source. But if debug flag A is + -- set, then all entities are listed. if ((Comes_From_Source (E) or else (Ekind (E) = E_Block @@ -416,6 +451,8 @@ package body Repinfo is and then not Is_Incomplete_Or_Private_Type (E) and then not (Ekind (E) = E_Constant and then Present (Full_View (E)))) + or else (List_Representation_Info = 4 + and then Relevant_Entities.Get (E)) or else Debug_Flag_AA then if Is_Subprogram (E) then @@ -448,6 +485,15 @@ package body Repinfo is List_Array_Info (E, Bytes_Big_Endian); end if; + -- The component type is relevant for an array + + if List_Representation_Info = 4 + and then Is_Itype (Component_Type (Base_Type (E))) + then + Relevant_Entities.Set + (Component_Type (Base_Type (E)), True); + end if; + elsif Is_Type (E) then if List_Representation_Info >= 2 then Blank_Line; @@ -1239,7 +1285,7 @@ package body Repinfo is Write_Str (UI_Image_Buffer (1 .. UI_Image_Length)); elsif Known_Normalized_Position (Ent) - and then List_Representation_Info = 3 + and then List_Representation_Info >= 3 then Spaces (Max_Spos_Length - 2); @@ -1730,6 +1776,10 @@ package body Repinfo is if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then Unit_Casing := Identifier_Casing (Source_Index (U)); + if List_Representation_Info = 4 then + Relevant_Entities.Reset; + end if; + -- Normal case, list to standard output if not List_Representation_Info_To_File then diff --git a/gcc/ada/switch-c.adb b/gcc/ada/switch-c.adb index ab7c2b30c49..eaeac066cac 100644 --- a/gcc/ada/switch-c.adb +++ b/gcc/ada/switch-c.adb @@ -1204,7 +1204,7 @@ package body Switch.C is case C is - when '0' .. '3' => + when '0' .. '4' => List_Representation_Info := Character'Pos (C) - Character'Pos ('0'); diff --git a/gcc/ada/switch-m.adb b/gcc/ada/switch-m.adb index 689655ecd4b..d2983ab7548 100644 --- a/gcc/ada/switch-m.adb +++ b/gcc/ada/switch-m.adb @@ -462,37 +462,29 @@ package body Switch.M is Add_Switch_Component (Storing (Storing'First .. Last_Stored)); - -- -gnatR may be followed by '0', '1', '2' or '3', - -- then by 's' + -- -gnatR may be followed by '0', '1', '2', '3' or '4', + -- then by 'e', 'j', 'm' or 's'. when 'R' => Last_Stored := First_Stored; Storing (Last_Stored) := 'R'; Ptr := Ptr + 1; - if Ptr <= Max - and then Switch_Chars (Ptr) in '0' .. '9' - then + while Ptr <= Max loop C := Switch_Chars (Ptr); - if C in '4' .. '9' then - Last := 0; - return; + case C is - else + when '0' .. '4' | 'e' | 'j' | 'm' | 's' => Last_Stored := Last_Stored + 1; Storing (Last_Stored) := C; Ptr := Ptr + 1; - if Ptr <= Max - and then Switch_Chars (Ptr) = 's' - then - Last_Stored := Last_Stored + 1; - Storing (Last_Stored) := 's'; - Ptr := Ptr + 1; - end if; - end if; - end if; + when others => + Last := 0; + return; + end case; + end loop; Add_Switch_Component (Storing (Storing'First .. Last_Stored)); diff --git a/gcc/ada/usage.adb b/gcc/ada/usage.adb index 754e8d89f8b..2581b02ca33 100644 --- a/gcc/ada/usage.adb +++ b/gcc/ada/usage.adb @@ -402,7 +402,7 @@ begin Write_Switch_Char ("R?"); Write_Line - ("List rep info (?=0/1/2/3/e/m for none/types/all/symbolic/ext/mech)"); + ("List rep info (?=0/1/2/3/4/e/m for none/types/all/sym/cg/ext/mech)"); Write_Switch_Char ("R?j"); Write_Line ("List rep info in the JSON data interchange format"); Write_Switch_Char ("R?s");