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

csr.reg: describe field shapes as shape-like objects. #87

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
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
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
Loading