Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variable keyword argument support to nmigen.hdl.rec.Record #339

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions nmigen/hdl/rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ def __eq__(self, other):
# Unlike most Values, Record *can* be subclassed.
class Record(Value):
@staticmethod
def like(other, *, name=None, name_suffix=None, src_loc_at=0):
def like(other, *, name=None, name_suffix=None, src_loc_at=0, **kwargs):
kw = dict()
kw.update(other.kwargs)
kw.update(kwargs)

if name is not None:
new_name = str(name)
elif name_suffix is not None:
Expand All @@ -96,14 +100,16 @@ def concat(a, b):
field = other[field_name]
if isinstance(field, Record):
fields[field_name] = Record.like(field, name=concat(new_name, field_name),
src_loc_at=1 + src_loc_at)
src_loc_at=1 + src_loc_at, **kw)
else:
fields[field_name] = Signal.like(field, name=concat(new_name, field_name),
src_loc_at=1 + src_loc_at)
src_loc_at=1 + src_loc_at, **kw)

return Record(other.layout, name=new_name, fields=fields, src_loc_at=1, **kw)

return Record(other.layout, name=new_name, fields=fields, src_loc_at=1)
def __init__(self, layout, *, name=None, fields=None, src_loc_at=0, **kwargs):
self.kwargs = kwargs

def __init__(self, layout, *, name=None, fields=None, src_loc_at=0):
if name is None:
name = tracer.get_var_name(depth=2 + src_loc_at, default=None)

Expand All @@ -128,10 +134,10 @@ def concat(a, b):
else:
if isinstance(field_shape, Layout):
self.fields[field_name] = Record(field_shape, name=concat(name, field_name),
src_loc_at=1 + src_loc_at)
src_loc_at=1 + src_loc_at, **kwargs)
else:
self.fields[field_name] = Signal(field_shape, name=concat(name, field_name),
src_loc_at=1 + src_loc_at)
src_loc_at=1 + src_loc_at, **kwargs)

def __getattr__(self, name):
return self[name]
Expand Down