From 455a7bc6c8e46493d5124d5a1b8d5f76d50503dd Mon Sep 17 00:00:00 2001 From: Wanda Date: Wed, 13 Mar 2024 13:46:39 +0100 Subject: [PATCH] lib.memory: Allow setting `Memory.init`. The `init` property is already mutable, so this adds no actual new functionality, just convenience. --- amaranth/lib/memory.py | 4 ++++ tests/test_lib_memory.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/amaranth/lib/memory.py b/amaranth/lib/memory.py index 7d1175c..802671e 100644 --- a/amaranth/lib/memory.py +++ b/amaranth/lib/memory.py @@ -408,6 +408,10 @@ class Memory(wiring.Component): def init(self): return self._init + @init.setter + def init(self, init): + self._init = Memory.Init(init, shape=self._shape, depth=self._depth) + @property def attrs(self): return self._attrs diff --git a/tests/test_lib_memory.py b/tests/test_lib_memory.py index eb7512b..222b98b 100644 --- a/tests/test_lib_memory.py +++ b/tests/test_lib_memory.py @@ -311,6 +311,8 @@ class MemoryTestCase(FHDLTestCase): self.assertEqual(m.init._raw, [0, 2, 0, 0]) m.init[2:] = [4, 5] self.assertEqual(list(m.init), [0, 2, 4, 5]) + m.init = [6, 7] + self.assertEqual(list(m.init), [6, 7, 0, 0]) def test_init_set_shapecastable(self): m = Memory(shape=MyStruct, depth=4, init=[])