with System; use System;
with System.Storage_Elements; use System.Storage_Elements;
package body GNAT.Debug_Utilities is
H : constant array (0 .. 15) of Character := "0123456789ABCDEF";
function Image (A : Address) return Image_String is
S : Image_String;
P : Natural;
N : Integer_Address;
U : Natural := 0;
begin
S (S'Last) := '#';
P := Address_Image_Length - 1;
N := To_Integer (A);
while P > 3 loop
if U = 4 then
S (P) := '_';
P := P - 1;
U := 1;
else
U := U + 1;
end if;
S (P) := H (Integer (N mod 16));
P := P - 1;
N := N / 16;
end loop;
S (1 .. 3) := "16#";
return S;
end Image;
function Image (S : String) return String is
W : String (1 .. 2 * S'Length + 2);
P : Positive := 1;
begin
W (1) := '"';
for J in S'Range loop
if S (J) = '"' then
P := P + 1;
W (P) := '"';
end if;
P := P + 1;
W (P) := S (J);
end loop;
P := P + 1;
W (P) := '"';
return W (1 .. P);
end Image;
function Image_C (A : Address) return Image_C_String is
S : Image_C_String;
N : Integer_Address := To_Integer (A);
begin
for P in reverse 3 .. S'Last loop
S (P) := H (Integer (N mod 16));
N := N / 16;
end loop;
S (1 .. 2) := "0x";
return S;
end Image_C;
function Value (S : String) return System.Address is
Base : Integer_Address := 10;
Res : Integer_Address := 0;
Last : Natural := S'Last;
C : Character;
N : Integer_Address;
begin
if S (Last) = '#' or else S (Last) = ':' then
Last := Last - 1;
end if;
for J in S'First .. Last loop
C := S (J);
if C = 'x' then
if Res /= 0 then
raise Constraint_Error;
end if;
Base := 16;
elsif C = '#' or else C = ':' then
Base := Res;
Res := 0;
elsif C = '_' then
null;
else
if C in '0' .. '9' then
N := Character'Pos (C) - Character'Pos ('0');
elsif C in 'A' .. 'F' then
N := Character'Pos (C) - (Character'Pos ('A') - 10);
elsif C in 'a' .. 'f' then
N := Character'Pos (C) - (Character'Pos ('a') - 10);
else
raise Constraint_Error;
end if;
if N >= Base then
raise Constraint_Error;
else
Res := Res * Base + N;
end if;
end if;
end loop;
return To_Address (Res);
end Value;
end GNAT.Debug_Utilities;