From: Luke Kenneth Casson Leighton Date: Thu, 11 Apr 2019 05:19:09 +0000 (+0100) Subject: code-shuffle to allow accumulation of results from eq in visit-generic way X-Git-Tag: ls180-24jan2020~1264 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a28e30c5cdf95b45a8ea2cbbe6bfcf525d9995d5;p=ieee754fpu.git code-shuffle to allow accumulation of results from eq in visit-generic way --- diff --git a/src/add/singlepipe.py b/src/add/singlepipe.py index 3d4eefb7..137f8163 100644 --- a/src/add/singlepipe.py +++ b/src/add/singlepipe.py @@ -297,52 +297,66 @@ class Visitor: python object, enumerate them, find out the list of Signals that way, and assign them. """ - def visit(self, o, i, fn): - res = [] + def visit(self, o, i, act): if isinstance(o, dict): - for (k, v) in o.items(): - print ("d-eq", v, i[k]) - res.append(fn(v, i[k])) - return res + return self.dict_visit(o, i, act) + res = act.prepare() if not isinstance(o, Sequence): o, i = [o], [i] for (ao, ai) in zip(o, i): #print ("visit", fn, ao, ai) if isinstance(ao, Record): - rres = [] - for idx, (field_name, field_shape, _) in enumerate(ao.layout): - if isinstance(field_shape, Layout): - val = ai.fields - else: - val = ai - if hasattr(val, field_name): # check for attribute - val = getattr(val, field_name) - else: - val = val[field_name] # dictionary-style specification - rres += self.visit(ao.fields[field_name], val, fn) + rres = self.record_visit(ao, ai, act) elif isinstance(ao, ArrayProxy) and not isinstance(ai, Value): - rres = [] - for p in ai.ports(): - op = getattr(ao, p.name) - #print (op, p, p.name) - rres.append(fn(op, p)) + rres = self.arrayproxy_visit(ao, ai, act) else: - rres = fn(ao, ai) - if not isinstance(rres, Sequence): - rres = [rres] + rres = act.fn(ao, ai) res += rres return res + def dict_visit(self, o, i, act): + res = act.prepare() + for (k, v) in o.items(): + print ("d-eq", v, i[k]) + res.append(act.fn(v, i[k])) + return res + + def record_visit(self, ao, ai, act): + res = act.prepare() + for idx, (field_name, field_shape, _) in enumerate(ao.layout): + if isinstance(field_shape, Layout): + val = ai.fields + else: + val = ai + if hasattr(val, field_name): # check for attribute + val = getattr(val, field_name) + else: + val = val[field_name] # dictionary-style specification + res += self.visit(ao.fields[field_name], val, act) + return res + + def arrayproxy_visit(self, ao, ai, act): + res = act.prepare() + for p in ai.ports(): + op = getattr(ao, p.name) + #print (op, p, p.name) + res.append(fn(op, p)) + return res + class Eq(Visitor): def __init__(self): self.res = [] + def prepare(self): + return [] + def fn(self, o, i): + rres = o.eq(i) + if not isinstance(rres, Sequence): + rres = [rres] + return rres def __call__(self, o, i): - def _eq_fn(o, i): - return o.eq(i) - res = self.visit(o, i, _eq_fn) - return res + return self.visit(o, i, self) def eq(o, i): """ makes signals equal: a helper routine which identifies if it is being