X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fadd%2Fexample_buf_pipe.py;h=ab2f3b1e124cbaa7a10585db2642710032ca54b6;hb=198cc1f879b9a83f1eee56024e03a90a4b73ee59;hp=037d35db30070c4d0133ff1358f7bbd40863ee70;hpb=64bd11bded25d7262bc98c40aa609c275eded4b2;p=ieee754fpu.git diff --git a/src/add/example_buf_pipe.py b/src/add/example_buf_pipe.py index 037d35db..ab2f3b1e 100644 --- a/src/add/example_buf_pipe.py +++ b/src/add/example_buf_pipe.py @@ -45,6 +45,8 @@ from nmigen import Signal, Cat, Const, Mux, Module from nmigen.cli import verilog, rtlil +from nmigen.hdl.rec import Record, Layout + from collections.abc import Sequence @@ -102,12 +104,26 @@ def eq(o, i): """ makes signals equal: a helper routine which identifies if it is being passsed a list (or tuple) of objects, and calls the objects' eq function. + + Record is a special (unusual, recursive) case, where the input + is specified as a dictionary (which may contain further dictionaries, + recursively), where the field names of the dictionary must match + the Record's field spec. """ if not isinstance(o, Sequence): o, i = [o], [i] res = [] for (ao, ai) in zip(o, i): - res.append(ao.eq(ai)) + #print ("eq", ao, ai) + if isinstance(ao, Record): + for idx, (field_name, field_shape, _) in enumerate(ao.layout): + if isinstance(field_shape, Layout): + rres = eq(ao.fields[field_name], ai.fields[field_name]) + else: + rres = eq(ao.fields[field_name], ai[field_name]) + res += rres + else: + res.append(ao.eq(ai)) return res