From 75a974cfb4aad0583dfd9441bff7347a048ab1f8 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 27 Sep 2021 18:33:44 +0100 Subject: [PATCH] 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 --- nmigen/hdl/ast.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 -- 2.30.2