From: Dmitry Selyutin Date: Sun, 3 Sep 2023 19:09:39 +0000 (+0300) Subject: insndb/core: support operands comparison X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e7b6893c530e537bd747e14898a643739b6a14d3;p=openpower-isa.git insndb/core: support operands comparison --- diff --git a/src/openpower/insndb/core.py b/src/openpower/insndb/core.py index 867f9c4b..8e489b46 100644 --- a/src/openpower/insndb/core.py +++ b/src/openpower/insndb/core.py @@ -988,6 +988,7 @@ class Record(Dataclass): return self["Rc"].value +@_functools.total_ordering class Operand: def __init__(self, record, name): self.__record = record @@ -1000,6 +1001,19 @@ class Operand: def __repr__(self): return f"{self.__class__.__name__}({self.name})" + def __lt__(self, other): + if self.__class__ is not other.__class__: + return NotImplemented + return ((self.name < other.name) or (self.span < other.span)) + + def __eq__(self, other): + if self.__class__ is not other.__class__: + return NotImplemented + return ((self.name == other.name) and (self.span == other.span)) + + def __hash__(self): + return hash((self.name, self.span),) + @property def name(self): return self.__name