From: Luke Kenneth Casson Leighton Date: Sat, 20 Apr 2019 22:52:33 +0000 (+0100) Subject: create example Object class (annoyingly) X-Git-Tag: ls180-24jan2020~1200 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=11227d5052a44ee65850cc49b040b3adfb8001de;p=ieee754fpu.git create example Object class (annoyingly) --- diff --git a/src/add/fpcommon/pack.py b/src/add/fpcommon/pack.py index 0f75d46c..97d69111 100644 --- a/src/add/fpcommon/pack.py +++ b/src/add/fpcommon/pack.py @@ -8,24 +8,16 @@ from nmigen.cli import main, verilog from fpbase import FPNumOut from fpbase import FPState from fpcommon.roundz import FPRoundData +from singlepipe import Object -class FPPackData: +class FPPackData(Object): def __init__(self, width, id_wid): + Object.__init__(self) self.z = Signal(width, reset_less=True) self.mid = Signal(id_wid, reset_less=True) - def __iter__(self): - yield self.z - yield self.mid - - def eq(self, i): - return [self.z.eq(i.z), self.mid.eq(i.mid)] - - def ports(self): - return list(self) - class FPPackMod: diff --git a/src/add/singlepipe.py b/src/add/singlepipe.py index 0b9bf631..753dec1b 100644 --- a/src/add/singlepipe.py +++ b/src/add/singlepipe.py @@ -179,6 +179,36 @@ from collections.abc import Sequence from queue import Queue +class Object: + def __init__(self): + self.fields = {} + + def __setattr__(self, k, v): + print ("kv", k, v) + if (k.startswith('_') or k in ["fields", "name", "src_loc"] or + k in dir(Object) or "fields" not in self.__dict__): + return object.__setattr__(self, k, v) + self.fields[k] = v + + def __getattr__(self, k): + if k in self.fields: + return self.fields[k] + return object.__getattr__(self, k) + + def __iter__(self): + for x in self.fields.values(): + yield x + + def eq(self, inp): + res = [] + for (o, i) in zip(self, inp): + res.append(eq(o, i)) + return res + + def ports(self): + return list(self) + + class RecordObject(Record): def __init__(self, layout=None, name=None): Record.__init__(self, layout=layout or [], name=None)