From: Luke Kenneth Casson Leighton Date: Mon, 27 Sep 2021 17:33:44 +0000 (+0100) Subject: add redirection of __Mux__ to allow overrides for more advanced behaviour X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=75a974cfb4aad0583dfd9441bff7347a048ab1f8;p=nmigen.git add redirection of __Mux__ 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 685924a..a2af8c7 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -150,6 +150,9 @@ class Value(metaclass=ABCMeta): super().__init__() self.src_loc = tracer.get_src_loc(1 + src_loc_at) + def __Mux__(self, val1, val0): + return _InternalMux(self, val1, val0) + def __bool__(self): raise TypeError("Attempted to convert nMigen value to Python boolean") @@ -720,6 +723,13 @@ class Operator(Value): def Mux(sel, val1, val0): + sel = Value.cast(sel) + if len(sel) != 1: + sel = sel.bool() + return sel.__Mux__(val1, val0) + + +def _InternalMux(sel, val1, val0): """Choose between two values. Parameters