From 86250157b7311a8c26f76cdf4fbb1a60232abcc1 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Mon, 29 May 2023 14:21:39 +0100 Subject: [PATCH] regs: add __repr__ --- riscemu/registers.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/riscemu/registers.py b/riscemu/registers.py index ef7ef51..338ebde 100644 --- a/riscemu/registers.py +++ b/riscemu/registers.py @@ -142,8 +142,8 @@ class Registers: + " ".join(self._reg_repr("a{}".format(i)) for i in range(8)) ) - def _reg_repr(self, reg: str): - txt = "{:4}=0x{:08X}".format(reg, self.get(reg, False)) + def _reg_repr(self, reg: str, name_len=4, fmt="08X"): + txt = "{:{}}=0x{:{}}".format(reg, name_len, self.get(reg, False), fmt) if reg == "fp": reg = "s0" if reg == self.last_set: @@ -285,3 +285,10 @@ class Registers: :return: The list """ return ["zero", "ra", "sp", "gp", "tp", "fp"] + + def __repr__(self): + return "".format( + "{" + + ", ".join(self._reg_repr("a{}".format(i), 2, "0x") for i in range(8)) + + "}" + )