diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-05-27 09:52:21 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-05-27 09:52:21 +0200 |
commit | e8c9722ebc2b610d6bd6f70fc88e04ea6ec4041c (patch) | |
tree | 1cf59bb20f75293208161bd752ff12dbf6e4f1d6 | |
parent | ba126785e1ce562f242b1a104ada9cfb554f62e8 (diff) | |
download | ghdl-e8c9722ebc2b610d6bd6f70fc88e04ea6ec4041c.tar.gz ghdl-e8c9722ebc2b610d6bd6f70fc88e04ea6ec4041c.tar.bz2 ghdl-e8c9722ebc2b610d6bd6f70fc88e04ea6ec4041c.zip |
utils_io: add put_addr (to display addresses)
-rw-r--r-- | src/utils_io.adb | 20 | ||||
-rw-r--r-- | src/utils_io.ads | 4 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/utils_io.adb b/src/utils_io.adb index d883ccddf..78b9a9d7b 100644 --- a/src/utils_io.adb +++ b/src/utils_io.adb @@ -14,6 +14,8 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <gnu.org/licenses>. +with Ada.Unchecked_Conversion; + with Simple_IO; use Simple_IO; package body Utils_IO is @@ -46,4 +48,22 @@ package body Utils_IO is begin Put_Trim (Int64'Image (V)); end Put_Int64; + + Hex_Map : constant array (0 .. 15) of Character := "0123456789ABCDEF"; + + procedure Put_Addr (V : System.Address) + is + type Integer_Address is mod System.Memory_Size; + function To_Integer is new Ada.Unchecked_Conversion + (Source => System.Address, Target => Integer_Address); + Res : String (1 .. System.Word_Size / 4); + Val : Integer_Address := To_Integer (V); + begin + for I in reverse Res'Range loop + Res (I) := Hex_Map (Natural (Val and 15)); + Val := Val / 16; + end loop; + Put (Res); + end Put_Addr; + end Utils_IO; diff --git a/src/utils_io.ads b/src/utils_io.ads index ef0c5f1ee..a99d52c3c 100644 --- a/src/utils_io.ads +++ b/src/utils_io.ads @@ -14,6 +14,8 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <gnu.org/licenses>. +with System; + with Types; use Types; package Utils_IO is @@ -27,4 +29,6 @@ package Utils_IO is procedure Put_Uns32 (V : Uns32); procedure Put_Int32 (V : Int32); procedure Put_Int64 (V : Int64); + + procedure Put_Addr (V : System.Address); end Utils_IO; |