add redirection of __Repl__ to allow overrides for more advanced behaviour
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 28 Sep 2021 16:34:00 +0000 (17:34 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 2 Oct 2021 14:58:16 +0000 (15:58 +0100)
without changing fundamental language characteristics or semantics in nmigen
https://bugs.libre-soc.org/show_bug.cgi?id=458

nmigen/hdl/ast.py
nmigen/hdl/xfrm.py

index 6a1a05ee9d6beb5289a671a9745375c474d3a9a3..e24cb590ffe0c74b04437fd60a8d27ba7be9dc32 100644 (file)
@@ -15,7 +15,7 @@ __all__ = [
     "Shape", "signed", "unsigned",
     "Value", "Const", "C", "AnyConst", "AnySeq", "Operator", "Mux", "Part", "Slice", "Cat", "Repl",
     "Array", "ArrayProxy",
-    "_InternalSwitch", "_InternalAssign",
+    "_InternalSwitch", "_InternalAssign", "_InternalRepl",
     "Signal", "ClockSignal", "ResetSignal",
     "UserValue", "ValueCastable",
     "Sample", "Past", "Stable", "Rose", "Fell", "Initial",
@@ -151,6 +151,9 @@ class Value(metaclass=ABCMeta):
         super().__init__()
         self.src_loc = tracer.get_src_loc(1 + src_loc_at)
 
+    def __Repl__(self, count, *, src_loc_at=0):
+        return _InternalRepl(self, count, src_loc_at=src_loc_at)
+
     def __Mux__(self, val1, val0):
         return _InternalMux(self, val1, val0)
 
@@ -872,7 +875,11 @@ class Cat(Value):
 
 
 @final
-class Repl(Value):
+def Repl(value, count, *, src_loc_at=0):
+    return value.__Repl__(count, src_loc_at=src_loc_at)
+
+
+class _InternalRepl(Value):
     """Replicate a value
 
     An input value is replicated (repeated) several times
index 9c527e0dd7233ba31737126c0bf3e8b12a4419ad..d55afb8fcb6ab25134a5af2c24b6a94039e87e2b 100644 (file)
@@ -106,7 +106,7 @@ class ValueVisitor(metaclass=ABCMeta):
             new_value = self.on_Part(value)
         elif type(value) is Cat:
             new_value = self.on_Cat(value)
-        elif type(value) is Repl:
+        elif type(value) is _InternalRepl:
             new_value = self.on_Repl(value)
         elif type(value) is ArrayProxy:
             new_value = self.on_ArrayProxy(value)