Skip to content

Commit c29726d

Browse files
committed
csr.reg: use path instead of name in {FieldMap,FieldArray}.flatten().
See amaranth-lang/amaranth#909.
1 parent fd8973f commit c29726d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

amaranth_soc/csr/reg.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,16 @@ def flatten(self):
285285
Yields
286286
------
287287
iter(:class:`str`)
288-
Name of the field. It is prefixed by the name of every nested field collection.
288+
Path of the field. It is prefixed by the name of every nested field collection.
289289
:class:`Field`
290290
Register field.
291291
"""
292292
for key, field in self.items():
293293
if isinstance(field, Field):
294294
yield (key,), field
295295
elif isinstance(field, (FieldMap, FieldArray)):
296-
for sub_name, sub_field in field.flatten():
297-
yield (key, *sub_name), sub_field
296+
for sub_path, sub_field in field.flatten():
297+
yield (key, *sub_path), sub_field
298298
else:
299299
assert False # :nocov:
300300

@@ -341,16 +341,16 @@ def flatten(self):
341341
Yields
342342
------
343343
iter(:class:`str`)
344-
Name of the field. It is prefixed by the name of every nested field collection.
344+
Path of the field. It is prefixed by the name of every nested field collection.
345345
:class:`Field`
346346
Register field.
347347
"""
348348
for key, field in enumerate(self._fields):
349349
if isinstance(field, Field):
350350
yield (key,), field
351351
elif isinstance(field, (FieldMap, FieldArray)):
352-
for sub_name, sub_field in field.flatten():
353-
yield (key, *sub_name), sub_field
352+
for sub_path, sub_field in field.flatten():
353+
yield (key, *sub_path), sub_field
354354
else:
355355
assert False # :nocov:
356356

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

409409
width = 0
410-
for field_name, field in fields.flatten():
410+
for field_path, field in fields.flatten():
411411
width += Shape.cast(field.shape).width
412412
if field.access.readable() and not access.readable():
413-
raise ValueError(f"Field {'__'.join(field_name)} is readable, but register access "
413+
raise ValueError(f"Field {'__'.join(field_path)} is readable, but register access "
414414
f"mode is {access!r}")
415415
if field.access.writable() and not access.writable():
416-
raise ValueError(f"Field {'__'.join(field_name)} is writable, but register access "
416+
raise ValueError(f"Field {'__'.join(field_path)} is writable, but register access "
417417
f"mode is {access!r}")
418418

419419
self._width = width
@@ -441,7 +441,7 @@ def __iter__(self):
441441
Yields
442442
------
443443
iter(:class:`str`)
444-
Name of the field. It is prefixed by the name of every nested field collection.
444+
Path of the field. It is prefixed by the name of every nested field collection.
445445
:class:`Field`
446446
Register field.
447447
"""
@@ -452,8 +452,8 @@ def elaborate(self, platform):
452452

453453
field_start = 0
454454

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

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

0 commit comments

Comments
 (0)