From: Luke Kenneth Casson Leighton Date: Sat, 2 Oct 2021 15:28:28 +0000 (+0100) Subject: Module._check_signed_cond() performs a Value.cast (now self._AstType.cast) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7d5f6d6c31c13c18115fe10663e5b031957ee6fc;p=nmigen.git Module._check_signed_cond() performs a Value.cast (now self._AstType.cast) in each instance it is used (for m.If and m.Elif). therefore, why not move the bool check-and-convert *into* Module._check_signed_cond() --- diff --git a/nmigen/hdl/dsl.py b/nmigen/hdl/dsl.py index 90c2976..982b3a5 100644 --- a/nmigen/hdl/dsl.py +++ b/nmigen/hdl/dsl.py @@ -181,6 +181,7 @@ class Module(_ModuleBuilderRoot, Elaboratable): # to complete the Type 1 (ast.*) nmigen language construct abstraction # from Type 2 (Module - this class) Module must be told what AST type # it may cast m.If/Elif conditions and m.Switch + self._astType = _astType or Value def _check_context(self, construct, context): if self._ctrl_context != context: @@ -221,6 +222,10 @@ class Module(_ModuleBuilderRoot, Elaboratable): "Replace `~flag` with `not flag`. (If this is a false positive, " "silence this warning with `m.If(x)` → `m.If(x.bool())`.)", SyntaxWarning, stacklevel=4) + # check if the condition is not considered boolean, and only + # convert it if it is not + if not cond.considered_bool(): + cond = cond.bool() return cond @_guardedcontextmanager("If")