From: Luke Kenneth Casson Leighton Date: Tue, 28 Sep 2021 16:34:00 +0000 (+0100) Subject: add redirection of __Repl__ to allow overrides for more advanced behaviour X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=160d23ee7ea78c3f2d522fc7daa1705bf8cb4f17;p=nmigen.git add redirection of __Repl__ to allow overrides for more advanced behaviour without changing fundamental language characteristics or semantics in nmigen https://bugs.libre-soc.org/show_bug.cgi?id=458 --- diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index 7b1fd8f..e645dc6 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -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) @@ -875,7 +878,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 diff --git a/nmigen/hdl/xfrm.py b/nmigen/hdl/xfrm.py index 9c527e0..d55afb8 100644 --- a/nmigen/hdl/xfrm.py +++ b/nmigen/hdl/xfrm.py @@ -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)