Skip to content

Commit

Permalink
csr.reg: use path instead of name in {FieldMap,FieldArray}.flatten().
Browse files Browse the repository at this point in the history
  • Loading branch information
jfng committed Dec 7, 2023
1 parent 0313d44 commit 3204e89
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions amaranth_soc/csr/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,16 @@ def flatten(self):
Yields
------
iter(:class:`str`)
Name of the field. It is prefixed by the name of every nested field collection.
Path of the field. It is prefixed by the name of every nested field collection.
:class:`Field`
Register field.
"""
for key, field in self.items():
if isinstance(field, Field):
yield (key,), field
elif isinstance(field, (FieldMap, FieldArray)):
for sub_name, sub_field in field.flatten():
yield (key, *sub_name), sub_field
for sub_path, sub_field in field.flatten():
yield (key, *sub_path), sub_field
else:
assert False # :nocov:

Expand Down Expand Up @@ -341,16 +341,16 @@ def flatten(self):
Yields
------
iter(:class:`str`)
Name of the field. It is prefixed by the name of every nested field collection.
Path of the field. It is prefixed by the name of every nested field collection.
:class:`Field`
Register field.
"""
for key, field in enumerate(self._fields):
if isinstance(field, Field):
yield (key,), field
elif isinstance(field, (FieldMap, FieldArray)):
for sub_name, sub_field in field.flatten():
yield (key, *sub_name), sub_field
for sub_path, sub_field in field.flatten():
yield (key, *sub_path), sub_field
else:
assert False # :nocov:

Expand Down Expand Up @@ -407,13 +407,13 @@ def __init__(self, access="rw", fields=None):
raise TypeError(f"Field collection must be a FieldMap or a FieldArray, not {fields!r}")

width = 0
for field_name, field in fields.flatten():
for field_path, field in fields.flatten():
width += Shape.cast(field.shape).width
if field.access.readable() and not access.readable():
raise ValueError(f"Field {'__'.join(field_name)} is readable, but register access "
raise ValueError(f"Field {'__'.join(field_path)} is readable, but register access "
f"mode is {access!r}")
if field.access.writable() and not access.writable():
raise ValueError(f"Field {'__'.join(field_name)} is writable, but register access "
raise ValueError(f"Field {'__'.join(field_path)} is writable, but register access "
f"mode is {access!r}")

self._width = width
Expand Down Expand Up @@ -441,7 +441,7 @@ def __iter__(self):
Yields
------
iter(:class:`str`)
Name of the field. It is prefixed by the name of every nested field collection.
Path of the field. It is prefixed by the name of every nested field collection.
:class:`Field`
Register field.
"""
Expand All @@ -452,8 +452,8 @@ def elaborate(self, platform):

field_start = 0

for field_name, field in self.fields.flatten():
m.submodules["__".join(str(key) for key in field_name)] = field
for field_path, field in self.fields.flatten():
m.submodules["__".join(str(key) for key in field_path)] = field

field_slice = slice(field_start, field_start + Shape.cast(field.shape).width)

Expand Down

0 comments on commit 3204e89

Please sign in to comment.