Commit 7883c42e by Eric Botcazou Committed by Pierre-Marie de Rodat

[Ada] Factor out worker procedure for -gnatR

This extracts a worker procedure for printing the layout of a single component
from List_Record_Layout so as to make the next change more readable.

2018-05-29  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* repinfo.adb (List_Component_Layout): New procedure extracted from...
	(List_Record_Layout): ...here.  Invoke it.

From-SVN: r260867
parent 76b382d9
2018-05-29 Eric Botcazou <ebotcazou@adacore.com> 2018-05-29 Eric Botcazou <ebotcazou@adacore.com>
* repinfo.adb (List_Component_Layout): New procedure extracted from...
(List_Record_Layout): ...here. Invoke it.
2018-05-29 Eric Botcazou <ebotcazou@adacore.com>
* repinfo.adb (Write_Unknown_Val): New procedure. * repinfo.adb (Write_Unknown_Val): New procedure.
(List_GCC_Expression): Call it. (List_GCC_Expression): Call it.
(List_Record_Layout): Likewise. (List_Record_Layout): Likewise.
......
...@@ -891,6 +891,13 @@ package body Repinfo is ...@@ -891,6 +891,13 @@ package body Repinfo is
Prefix_Length : Natural := 0); Prefix_Length : Natural := 0);
-- Internal recursive procedure to compute the max length -- Internal recursive procedure to compute the max length
procedure List_Component_Layout
(Ent : Entity_Id;
Starting_Position : Uint := Uint_0;
Starting_First_Bit : Uint := Uint_0;
Prefix : String := "");
-- Procedure to display the layout of a single component
procedure List_Record_Layout procedure List_Record_Layout
(Ent : Entity_Id; (Ent : Entity_Id;
Starting_Position : Uint := Uint_0; Starting_Position : Uint := Uint_0;
...@@ -1002,6 +1009,126 @@ package body Repinfo is ...@@ -1002,6 +1009,126 @@ package body Repinfo is
end loop; end loop;
end Compute_Max_Length; end Compute_Max_Length;
---------------------------
-- List_Component_Layout --
---------------------------
procedure List_Component_Layout
(Ent : Entity_Id;
Starting_Position : Uint := Uint_0;
Starting_First_Bit : Uint := Uint_0;
Prefix : String := "")
is
Esiz : constant Uint := Esize (Ent);
Npos : constant Uint := Normalized_Position (Ent);
Fbit : constant Uint := Normalized_First_Bit (Ent);
Spos : Uint;
Sbit : Uint;
Lbit : Uint;
begin
Write_Str (" ");
Write_Str (Prefix);
Write_Str (Name_Buffer (1 .. Name_Len));
Spaces (Max_Name_Length - Prefix'Length - Name_Len);
Write_Str (" at ");
if Known_Static_Normalized_Position (Ent) then
Spos := Starting_Position + Npos;
Sbit := Starting_First_Bit + Fbit;
if Sbit >= SSU then
Spos := Spos + 1;
end if;
UI_Image (Spos);
Spaces (Max_Spos_Length - UI_Image_Length);
Write_Str (UI_Image_Buffer (1 .. UI_Image_Length));
elsif Known_Normalized_Position (Ent)
and then List_Representation_Info = 3
then
Spaces (Max_Spos_Length - 2);
if Starting_Position /= Uint_0 then
UI_Write (Starting_Position);
Write_Str (" + ");
end if;
Write_Val (Npos);
else
Write_Unknown_Val;
end if;
Write_Str (" range ");
Sbit := Starting_First_Bit + Fbit;
if Sbit >= SSU then
Sbit := Sbit - SSU;
end if;
UI_Write (Sbit);
Write_Str (" .. ");
-- Allowing Uint_0 here is an annoying special case. Really
-- this should be a fine Esize value but currently it means
-- unknown, except that we know after gigi has back annotated
-- that a size of zero is real, since otherwise gigi back
-- annotates using No_Uint as the value to indicate unknown.
if (Esize (Ent) = Uint_0 or else Known_Static_Esize (Ent))
and then Known_Static_Normalized_First_Bit (Ent)
then
Lbit := Sbit + Esiz - 1;
if Lbit < 10 then
Write_Char (' ');
end if;
UI_Write (Lbit);
-- The test for Esize (Ent) not Uint_0 here is an annoying
-- special case. Officially a value of zero for Esize means
-- unknown, but here we use the fact that we know that gigi
-- annotates Esize with No_Uint, not Uint_0. Really everyone
-- should use No_Uint???
elsif List_Representation_Info < 3
or else (Esize (Ent) /= Uint_0 and then Unknown_Esize (Ent))
then
Write_Unknown_Val;
-- List_Representation >= 3 and Known_Esize (Ent)
else
Write_Val (Esiz, Paren => True);
-- If in front end layout mode, then dynamic size is stored
-- in storage units, so renormalize for output
if not Back_End_Layout then
Write_Str (" * ");
Write_Int (SSU);
end if;
-- Add appropriate first bit offset
if Sbit = 0 then
Write_Str (" - 1");
elsif Sbit = 1 then
null;
else
Write_Str (" + ");
Write_Int (UI_To_Int (Sbit) - 1);
end if;
end if;
Write_Line (";");
end List_Component_Layout;
------------------------ ------------------------
-- List_Record_Layout -- -- List_Record_Layout --
------------------------ ------------------------
...@@ -1036,12 +1163,10 @@ package body Repinfo is ...@@ -1036,12 +1163,10 @@ package body Repinfo is
declare declare
Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp)); Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
Esiz : constant Uint := Esize (Comp);
Npos : constant Uint := Normalized_Position (Comp); Npos : constant Uint := Normalized_Position (Comp);
Fbit : constant Uint := Normalized_First_Bit (Comp); Fbit : constant Uint := Normalized_First_Bit (Comp);
Spos : Uint; Spos : Uint;
Sbit : Uint; Sbit : Uint;
Lbit : Uint;
begin begin
Get_Decoded_Name_String (Chars (Comp)); Get_Decoded_Name_String (Chars (Comp));
...@@ -1069,121 +1194,8 @@ package body Repinfo is ...@@ -1069,121 +1194,8 @@ package body Repinfo is
goto Continue; goto Continue;
end if; end if;
Write_Str (" "); List_Component_Layout (Comp,
Write_Str (Prefix); Starting_Position, Starting_First_Bit, Prefix);
Write_Str (Name_Buffer (1 .. Name_Len));
for J in 1 .. Max_Name_Length - Prefix'Length - Name_Len loop
Write_Char (' ');
end loop;
Write_Str (" at ");
if Known_Static_Normalized_Position (Comp) then
Spos := Starting_Position + Npos;
Sbit := Starting_First_Bit + Fbit;
if Sbit >= SSU then
Spos := Spos + 1;
end if;
UI_Image (Spos);
Spaces (Max_Spos_Length - UI_Image_Length);
Write_Str (UI_Image_Buffer (1 .. UI_Image_Length));
elsif Known_Normalized_Position (Comp)
and then List_Representation_Info = 3
then
Spaces (Max_Spos_Length - 2);
if Starting_Position /= Uint_0 then
UI_Write (Starting_Position);
Write_Str (" + ");
end if;
Write_Val (Npos);
else
-- For the packed case, we don't know the bit positions if
-- we don't know the starting position.
if Is_Packed (Ent) then
Write_Line ("?? range ? .. ??;");
goto Continue;
-- Otherwise we can continue
else
Write_Unknown_Val;
end if;
end if;
Write_Str (" range ");
Sbit := Starting_First_Bit + Fbit;
if Sbit >= SSU then
Sbit := Sbit - SSU;
end if;
UI_Write (Sbit);
Write_Str (" .. ");
-- Allowing Uint_0 here is an annoying special case. Really
-- this should be a fine Esize value but currently it means
-- unknown, except that we know after gigi has back annotated
-- that a size of zero is real, since otherwise gigi back
-- annotates using No_Uint as the value to indicate unknown.
if (Esize (Comp) = Uint_0 or else Known_Static_Esize (Comp))
and then Known_Static_Normalized_First_Bit (Comp)
then
Lbit := Sbit + Esiz - 1;
if Lbit < 10 then
Write_Char (' ');
end if;
UI_Write (Lbit);
-- The test for Esize (Comp) not Uint_0 here is an annoying
-- special case. Officially a value of zero for Esize means
-- unknown, but here we use the fact that we know that gigi
-- annotates Esize with No_Uint, not Uint_0. Really everyone
-- should use No_Uint???
elsif List_Representation_Info < 3
or else (Esize (Comp) /= Uint_0 and then Unknown_Esize (Comp))
then
Write_Unknown_Val;
-- List_Representation >= 3 and Known_Esize (Comp)
else
Write_Val (Esiz, Paren => True);
-- If in front end layout mode, then dynamic size is stored
-- in storage units, so renormalize for output
if not Back_End_Layout then
Write_Str (" * ");
Write_Int (SSU);
end if;
-- Add appropriate first bit offset
if Sbit = 0 then
Write_Str (" - 1");
elsif Sbit = 1 then
null;
else
Write_Str (" + ");
Write_Int (UI_To_Int (Sbit) - 1);
end if;
end if;
Write_Line (";");
end; end;
<<Continue>> <<Continue>>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment