From: Dmitry Selyutin Date: Wed, 17 Aug 2022 17:03:20 +0000 (+0300) Subject: pysvp64dis: refactor inheritance model X-Git-Tag: sv_maxu_works-initial~44 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4e0967014378c2b85a08e9087e90a42c66d5caba;p=openpower-isa.git pysvp64dis: refactor inheritance model --- diff --git a/src/openpower/sv/trans/pysvp64dis.py b/src/openpower/sv/trans/pysvp64dis.py index dd0b5c6a..ec84892e 100644 --- a/src/openpower/sv/trans/pysvp64dis.py +++ b/src/openpower/sv/trans/pysvp64dis.py @@ -22,16 +22,18 @@ DATABASE = _Database(_find_wiki_dir()) class Instruction(_SelectableInt): - def __init__(self, value, byteorder=ByteOrder.LITTLE): + def __init__(self, value, byteorder=ByteOrder.LITTLE, bits=32): if isinstance(value, _SelectableInt): value = value.value elif isinstance(value, bytes): value = int.from_bytes(value, byteorder=str(byteorder)) - if not isinstance(value, int) or (value < 0) or (value > ((1 << 32) - 1)): + if not isinstance(value, int): raise ValueError(value) + if not isinstance(bits, int) or (bits not in {32, 64}): + raise ValueError(bits) - return super().__init__(value=value, bits=32) + return super().__init__(value=value, bits=bits) def __repr__(self): return f"{self.__class__.__name__}({self.value:08x})" @@ -54,7 +56,7 @@ class Instruction(_SelectableInt): return None -class PrefixedInstruction(_SelectableInt): +class PrefixedInstruction(Instruction): def __init__(self, prefix, suffix, byteorder=ByteOrder.LITTLE): insn = _functools.partial(Instruction, byteorder=byteorder) (prefix, suffix) = map(insn, (prefix, suffix)) @@ -78,6 +80,10 @@ class PrefixedInstruction(_SelectableInt): def suffix(self): return Instruction(self[32:64]) + @property + def major(self): + return self.suffix.major + @property def dbrecord(self): return self.suffix.dbrecord