3 use IEEE.STD_LOGIC_1164.
all;
4 USE ieee.numeric_std.
ALL;
8 function s_tostr
(val
: std_logic_vector) return string;
9 function u_tostr
(val
: std_logic_vector) return string;
11 function to_bstring
(sl
: std_logic) return string;
12 function to_bstring
(slv
: std_logic_vector) return string;
17 package body easyprint
is
19 -- ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ====
20 -- From http://stackoverflow.com/a/24336034 By Morten Zilmer
21 -- Allows printing a std_logic_vector as a string that represents it's binary form.
22 -- ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ====
23 function to_bstring
(sl
: std_logic) return string is
24 variable sl_str_v
: string(1 to 3); -- std_logic image with quotes around
26 sl_str_v
:= std_logic'image(sl
);
27 return ""
& sl_str_v
(2); -- "" & character to get string
30 function to_bstring
(slv
: std_logic_vector) return string is
31 alias slv_norm
: std_logic_vector(1 to slv
'length) is slv
;
32 variable sl_str_v
: string(1 to 1); -- String of std_logic
33 variable res_v
: string(1 to slv
'length);
35 for idx
in slv_norm
'range loop
36 sl_str_v
:= to_bstring
(slv_norm
(idx
));
37 res_v
(idx
) := sl_str_v
(1);
41 -- ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ====
44 -- converts an std_logic_vector to a string that represents it's signed value
45 function s_tostr
(val
: std_logic_vector) return string is
47 return integer'image( to_integer
(signed
(val
)) );
50 -- converts an std_logic_vector to a string that represents it's unsigned value
51 function u_tostr
(val
: std_logic_vector) return string is
53 return integer'image( to_integer
(unsigned
(val
)) );