"Value", "Const", "C", "AnyConst", "AnySeq", "Operator", "Mux", "Part", "Slice", "Cat", "Repl",
"Array", "ArrayProxy",
"_InternalSwitch", "_InternalAssign", "_InternalRepl", "_InternalCat",
+ "_InternalPart",
"Signal", "ClockSignal", "ResetSignal",
"UserValue", "ValueCastable",
"Sample", "Past", "Stable", "Rose", "Fell", "Initial",
# *MUST NOT* use "Type (2) - dsl.Module" nmigen language constructs
# (m.If, m.Else, m.Switch, m.FSM): it creates complications in dsl.Module.
+ def __Part__(self, offset, width, stride, *, src_loc_at=0):
+ return _InternalPart(self, offset, width, stride, src_loc_at=src_loc_at)
+ def __Repl__(self, count, *, src_loc_at=0):
+ return _InternalRepl(self, count, src_loc_at=src_loc_at)
def __Repl__(self, count, *, src_loc_at=0):
return _InternalRepl(self, count, src_loc_at=src_loc_at)
def __Cat__(self, *args, src_loc_at=0):
@final
-class Part(Value):
+def Part(value, offset, width, stride=1, *, src_loc_at=0):
+ return value.__Part__(offset, width, stride, src_loc_at=src_loc_at)
+
+
+class _InternalPart(Value):
def __init__(self, value, offset, width, stride=1, *, src_loc_at=0):
if not isinstance(width, int) or width < 0:
raise TypeError("Part width must be a non-negative integer, not {!r}".format(width))
tuple(ValueKey(o) for o in self.value.operands)))
elif isinstance(self.value, Slice):
self._hash = hash((ValueKey(self.value.value), self.value.start, self.value.stop))
- elif isinstance(self.value, Part):
+ elif isinstance(self.value, _InternalPart):
self._hash = hash((ValueKey(self.value.value), ValueKey(self.value.offset),
self.value.width, self.value.stride))
elif isinstance(self.value, _InternalCat):
return (ValueKey(self.value.value) == ValueKey(other.value.value) and
self.value.start == other.value.start and
self.value.stop == other.value.stop)
- elif isinstance(self.value, Part):
+ elif isinstance(self.value, _InternalPart):
return (ValueKey(self.value.value) == ValueKey(other.value.value) and
ValueKey(self.value.offset) == ValueKey(other.value.offset) and
self.value.width == other.value.width and
def test_shape(self):
s1 = self.c.bit_select(self.s, 2)
- self.assertIsInstance(s1, Part)
+ self.assertIsInstance(s1, _InternalPart)
self.assertEqual(s1.shape(), unsigned(2))
self.assertIsInstance(s1.shape(), Shape)
s2 = self.c.bit_select(self.s, 0)
- self.assertIsInstance(s2, Part)
+ self.assertIsInstance(s2, _InternalPart)
self.assertEqual(s2.shape(), unsigned(0))
def test_stride(self):
s1 = self.c.bit_select(self.s, 2)
- self.assertIsInstance(s1, Part)
+ self.assertIsInstance(s1, _InternalPart)
self.assertEqual(s1.stride, 1)
def test_const(self):
def test_shape(self):
s1 = self.c.word_select(self.s, 2)
- self.assertIsInstance(s1, Part)
+ self.assertIsInstance(s1, _InternalPart)
self.assertEqual(s1.shape(), unsigned(2))
self.assertIsInstance(s1.shape(), Shape)
def test_stride(self):
s1 = self.c.word_select(self.s, 2)
- self.assertIsInstance(s1, Part)
+ self.assertIsInstance(s1, _InternalPart)
self.assertEqual(s1.stride, 2)
def test_const(self):