Skip to content

Commit

Permalink
csr.reg: describe field shapes as shape-like objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfng committed May 17, 2024
1 parent 58d7a69 commit 6d83724
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
12 changes: 6 additions & 6 deletions amaranth_soc/csr/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class R(FieldAction):
Parameters
----------
shape : :ref:`shape-castable <lang-shapecasting>`
shape : :ref:`shape-like object <lang-shapelike>`
Shape of the field.
Interface attributes
Expand Down Expand Up @@ -44,7 +44,7 @@ class W(FieldAction):
Parameters
----------
shape : :ref:`shape-castable <lang-shapecasting>`
shape : :ref:`shape-like object <lang-shapelike>`
Shape of the field.
Interface attributes
Expand Down Expand Up @@ -79,7 +79,7 @@ class RW(FieldAction):
Parameters
----------
shape : :ref:`shape-castable <lang-shapecasting>`
shape : :ref:`shape-like object <lang-shapelike>`
Shape of the field.
init : :class:`int`
Storage initial value.
Expand Down Expand Up @@ -127,7 +127,7 @@ class RW1C(FieldAction):
Parameters
----------
shape : :ref:`shape-castable <lang-shapecasting>`
shape : :ref:`shape-like object <lang-shapelike>`
Shape of the field.
init : :class:`int`
Storage initial value.
Expand Down Expand Up @@ -181,7 +181,7 @@ class RW1S(FieldAction):
Parameters
----------
shape : :ref:`shape-castable <lang-shapecasting>`
shape : :ref:`shape-like object <lang-shapelike>`
Shape of the field.
init : :class:`int`
Storage initial value.
Expand Down Expand Up @@ -230,7 +230,7 @@ class _Reserved(FieldAction):
Parameters
----------
shape : :ref:`shape-castable <lang-shapecasting>`
shape : :ref:`shape-like object <lang-shapelike>`
Shape of the field.
Interface attributes
Expand Down
13 changes: 6 additions & 7 deletions amaranth_soc/csr/reg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Mapping, Sequence
from contextlib import contextmanager
from amaranth import *
from amaranth.hdl import ShapeLike
from amaranth.lib import enum, wiring
from amaranth.lib.wiring import In, Out, connect, flipped
from amaranth.utils import ceil_log2
Expand Down Expand Up @@ -34,7 +35,7 @@ class Signature(wiring.Signature):
Parameters
----------
shape : :ref:`shape-castable <lang-shapecasting>`
shape : :ref:`shape-like object <lang-shapelike>`
Shape of the field.
access : :class:`FieldPort.Access`
Field access mode.
Expand All @@ -53,10 +54,8 @@ class Signature(wiring.Signature):
this strobe is asserted.
"""
def __init__(self, shape, access):
try:
Shape.cast(shape)
except TypeError as e:
raise TypeError(f"Field shape must be a shape-castable object, not {shape!r}") from e
if not isinstance(shape, ShapeLike):
raise TypeError(f"Field shape must be a shape-like object, not {shape!r}")
# TODO(py3.9): Remove this. Python 3.8 and below use cls.__name__ in the error message
# instead of cls.__qualname__.
# FieldPort.Access(access)
Expand Down Expand Up @@ -119,7 +118,7 @@ def __repr__(self):
Attributes
----------
shape : :ref:`shape-castable <lang-shapecasting>`
shape : :ref:`shape-like object <lang-shapelike>`
Shape of the field. See :class:`FieldPort.Signature`.
access : :class:`FieldPort.Access`
Field access mode. See :class:`FieldPort.Signature`.
Expand Down Expand Up @@ -190,7 +189,7 @@ class FieldAction(wiring.Component):
Parameters
----------
shape : :ref:`shape-castable <lang-shapecasting>`
shape : :ref:`shape-like object <lang-shapelike>`
Shape of the field. See :class:`FieldPort.Signature`.
access : :class:`FieldPort.Access`
Field access mode. See :class:`FieldPort.Signature`.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_csr_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_eq(self):

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

def test_wrong_access(self):
Expand Down

0 comments on commit 6d83724

Please sign in to comment.