lib.memory: Add Signature.create
implementations.
This commit is contained in:
parent
83701d74cf
commit
23f1b63425
|
@ -98,6 +98,9 @@ class WritePort:
|
||||||
"en": wiring.In(en_width),
|
"en": wiring.In(en_width),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def create(self, *, path=None, src_loc_at=0):
|
||||||
|
return WritePort(self, memory=None, domain="sync", path=path, src_loc_at=1 + src_loc_at)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def addr_width(self):
|
def addr_width(self):
|
||||||
return self._addr_width
|
return self._addr_width
|
||||||
|
@ -121,7 +124,7 @@ class WritePort:
|
||||||
return f"WritePort.Signature(addr_width={self.addr_width}, shape={self.shape}{granularity})"
|
return f"WritePort.Signature(addr_width={self.addr_width}, shape={self.shape}{granularity})"
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, signature, *, memory, domain):
|
def __init__(self, signature, *, memory, domain, path=None, src_loc_at=0):
|
||||||
if not isinstance(signature, WritePort.Signature):
|
if not isinstance(signature, WritePort.Signature):
|
||||||
raise TypeError(f"Expected `WritePort.Signature`, not {signature!r}")
|
raise TypeError(f"Expected `WritePort.Signature`, not {signature!r}")
|
||||||
if memory is not None:
|
if memory is not None:
|
||||||
|
@ -138,7 +141,7 @@ class WritePort:
|
||||||
self._signature = signature
|
self._signature = signature
|
||||||
self._memory = memory
|
self._memory = memory
|
||||||
self._domain = domain
|
self._domain = domain
|
||||||
self.__dict__.update(signature.members.create())
|
self.__dict__.update(signature.members.create(path=path, src_loc_at=1 + src_loc_at))
|
||||||
if memory is not None:
|
if memory is not None:
|
||||||
memory._w_ports.append(self)
|
memory._w_ports.append(self)
|
||||||
|
|
||||||
|
@ -211,6 +214,9 @@ class ReadPort:
|
||||||
"en": wiring.In(1, init=1),
|
"en": wiring.In(1, init=1),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def create(self, *, path=None, src_loc_at=0):
|
||||||
|
return ReadPort(self, memory=None, domain="sync", path=path, src_loc_at=1 + src_loc_at)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def addr_width(self):
|
def addr_width(self):
|
||||||
return self._addr_width
|
return self._addr_width
|
||||||
|
@ -228,7 +234,7 @@ class ReadPort:
|
||||||
return f"ReadPort.Signature(addr_width={self.addr_width}, shape={self.shape})"
|
return f"ReadPort.Signature(addr_width={self.addr_width}, shape={self.shape})"
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, signature, *, memory, domain, transparent_for=()):
|
def __init__(self, signature, *, memory, domain, transparent_for=(), path=None, src_loc_at=0):
|
||||||
if not isinstance(signature, ReadPort.Signature):
|
if not isinstance(signature, ReadPort.Signature):
|
||||||
raise TypeError(f"Expected `ReadPort.Signature`, not {signature!r}")
|
raise TypeError(f"Expected `ReadPort.Signature`, not {signature!r}")
|
||||||
if memory is not None:
|
if memory is not None:
|
||||||
|
@ -252,7 +258,7 @@ class ReadPort:
|
||||||
self._memory = memory
|
self._memory = memory
|
||||||
self._domain = domain
|
self._domain = domain
|
||||||
self._transparent_for = transparent_for
|
self._transparent_for = transparent_for
|
||||||
self.__dict__.update(signature.members.create())
|
self.__dict__.update(signature.members.create(path=path, src_loc_at=1 + src_loc_at))
|
||||||
if domain == "comb":
|
if domain == "comb":
|
||||||
self.en = Const(1)
|
self.en = Const(1)
|
||||||
if memory is not None:
|
if memory is not None:
|
||||||
|
|
|
@ -122,6 +122,15 @@ class WritePortTestCase(FHDLTestCase):
|
||||||
self.assertIs(port.memory, m)
|
self.assertIs(port.memory, m)
|
||||||
self.assertEqual(m.w_ports, (port,))
|
self.assertEqual(m.w_ports, (port,))
|
||||||
|
|
||||||
|
signature = memory.WritePort.Signature(shape=MyStruct, addr_width=4)
|
||||||
|
port = signature.create()
|
||||||
|
self.assertEqual(port.signature, signature)
|
||||||
|
self.assertIsNone(port.memory)
|
||||||
|
self.assertEqual(port.domain, "sync")
|
||||||
|
self.assertRepr(port.addr, "(sig port__addr)")
|
||||||
|
port = signature.create(path=("abc",))
|
||||||
|
self.assertRepr(port.addr, "(sig abc__addr)")
|
||||||
|
|
||||||
def test_constructor_wrong(self):
|
def test_constructor_wrong(self):
|
||||||
signature = memory.ReadPort.Signature(shape=8, addr_width=4)
|
signature = memory.ReadPort.Signature(shape=8, addr_width=4)
|
||||||
with self.assertRaisesRegex(TypeError,
|
with self.assertRaisesRegex(TypeError,
|
||||||
|
@ -224,6 +233,15 @@ class ReadPortTestCase(FHDLTestCase):
|
||||||
self.assertIs(port.memory, m)
|
self.assertIs(port.memory, m)
|
||||||
self.assertEqual(port.transparent_for, (write_port,))
|
self.assertEqual(port.transparent_for, (write_port,))
|
||||||
|
|
||||||
|
signature = memory.ReadPort.Signature(shape=MyStruct, addr_width=4)
|
||||||
|
port = signature.create()
|
||||||
|
self.assertEqual(port.signature, signature)
|
||||||
|
self.assertIsNone(port.memory)
|
||||||
|
self.assertEqual(port.domain, "sync")
|
||||||
|
self.assertRepr(port.addr, "(sig port__addr)")
|
||||||
|
port = signature.create(path=("abc",))
|
||||||
|
self.assertRepr(port.addr, "(sig abc__addr)")
|
||||||
|
|
||||||
def test_constructor_wrong(self):
|
def test_constructor_wrong(self):
|
||||||
signature = memory.WritePort.Signature(shape=8, addr_width=4)
|
signature = memory.WritePort.Signature(shape=8, addr_width=4)
|
||||||
with self.assertRaisesRegex(TypeError,
|
with self.assertRaisesRegex(TypeError,
|
||||||
|
|
Loading…
Reference in a new issue