Skip to content

Commit 6d83724

Browse files
committed
csr.reg: describe field shapes as shape-like objects.
1 parent 58d7a69 commit 6d83724

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

amaranth_soc/csr/action.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class R(FieldAction):
1212
1313
Parameters
1414
----------
15-
shape : :ref:`shape-castable <lang-shapecasting>`
15+
shape : :ref:`shape-like object <lang-shapelike>`
1616
Shape of the field.
1717
1818
Interface attributes
@@ -44,7 +44,7 @@ class W(FieldAction):
4444
4545
Parameters
4646
----------
47-
shape : :ref:`shape-castable <lang-shapecasting>`
47+
shape : :ref:`shape-like object <lang-shapelike>`
4848
Shape of the field.
4949
5050
Interface attributes
@@ -79,7 +79,7 @@ class RW(FieldAction):
7979
8080
Parameters
8181
----------
82-
shape : :ref:`shape-castable <lang-shapecasting>`
82+
shape : :ref:`shape-like object <lang-shapelike>`
8383
Shape of the field.
8484
init : :class:`int`
8585
Storage initial value.
@@ -127,7 +127,7 @@ class RW1C(FieldAction):
127127
128128
Parameters
129129
----------
130-
shape : :ref:`shape-castable <lang-shapecasting>`
130+
shape : :ref:`shape-like object <lang-shapelike>`
131131
Shape of the field.
132132
init : :class:`int`
133133
Storage initial value.
@@ -181,7 +181,7 @@ class RW1S(FieldAction):
181181
182182
Parameters
183183
----------
184-
shape : :ref:`shape-castable <lang-shapecasting>`
184+
shape : :ref:`shape-like object <lang-shapelike>`
185185
Shape of the field.
186186
init : :class:`int`
187187
Storage initial value.
@@ -230,7 +230,7 @@ class _Reserved(FieldAction):
230230
231231
Parameters
232232
----------
233-
shape : :ref:`shape-castable <lang-shapecasting>`
233+
shape : :ref:`shape-like object <lang-shapelike>`
234234
Shape of the field.
235235
236236
Interface attributes

amaranth_soc/csr/reg.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Mapping, Sequence
22
from contextlib import contextmanager
33
from amaranth import *
4+
from amaranth.hdl import ShapeLike
45
from amaranth.lib import enum, wiring
56
from amaranth.lib.wiring import In, Out, connect, flipped
67
from amaranth.utils import ceil_log2
@@ -34,7 +35,7 @@ class Signature(wiring.Signature):
3435
3536
Parameters
3637
----------
37-
shape : :ref:`shape-castable <lang-shapecasting>`
38+
shape : :ref:`shape-like object <lang-shapelike>`
3839
Shape of the field.
3940
access : :class:`FieldPort.Access`
4041
Field access mode.
@@ -53,10 +54,8 @@ class Signature(wiring.Signature):
5354
this strobe is asserted.
5455
"""
5556
def __init__(self, shape, access):
56-
try:
57-
Shape.cast(shape)
58-
except TypeError as e:
59-
raise TypeError(f"Field shape must be a shape-castable object, not {shape!r}") from e
57+
if not isinstance(shape, ShapeLike):
58+
raise TypeError(f"Field shape must be a shape-like object, not {shape!r}")
6059
# TODO(py3.9): Remove this. Python 3.8 and below use cls.__name__ in the error message
6160
# instead of cls.__qualname__.
6261
# FieldPort.Access(access)
@@ -119,7 +118,7 @@ def __repr__(self):
119118
120119
Attributes
121120
----------
122-
shape : :ref:`shape-castable <lang-shapecasting>`
121+
shape : :ref:`shape-like object <lang-shapelike>`
123122
Shape of the field. See :class:`FieldPort.Signature`.
124123
access : :class:`FieldPort.Access`
125124
Field access mode. See :class:`FieldPort.Signature`.
@@ -190,7 +189,7 @@ class FieldAction(wiring.Component):
190189
191190
Parameters
192191
----------
193-
shape : :ref:`shape-castable <lang-shapecasting>`
192+
shape : :ref:`shape-like object <lang-shapelike>`
194193
Shape of the field. See :class:`FieldPort.Signature`.
195194
access : :class:`FieldPort.Access`
196195
Field access mode. See :class:`FieldPort.Signature`.

tests/test_csr_reg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_eq(self):
102102

103103
def test_wrong_shape(self):
104104
with self.assertRaisesRegex(TypeError,
105-
r"Field shape must be a shape-castable object, not 'foo'"):
105+
r"Field shape must be a shape-like object, not 'foo'"):
106106
port = FieldPort.Signature("foo", "rw")
107107

108108
def test_wrong_access(self):

0 commit comments

Comments
 (0)