From db5fd1e4c49e77dad65ca3dd0540a8d7da6deb8e Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 16 Dec 2018 17:41:42 +0000 Subject: [PATCH] compat.fhdl.structure: only convert to bool in If/Elif if necessary. --- nmigen/compat/fhdl/structure.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nmigen/compat/fhdl/structure.py b/nmigen/compat/fhdl/structure.py index 1743df2..c00f033 100644 --- a/nmigen/compat/fhdl/structure.py +++ b/nmigen/compat/fhdl/structure.py @@ -30,12 +30,16 @@ def Constant(value, bits_sign=None): class If(ast.Switch): @deprecated("instead of `If(cond, ...)`, use `with m.If(cond): ...`") def __init__(self, cond, *stmts): - cond = Value.wrap(cond).bool() + cond = Value.wrap(cond) + if len(cond) != 1: + cond = cond.bool() super().__init__(cond, {"1": ast.Statement.wrap(stmts)}) @deprecated("instead of `.Elif(cond, ...)`, use `with m.Elif(cond): ...`") def Elif(self, cond, *stmts): - cond = Value.wrap(cond).bool() + cond = Value.wrap(cond) + if len(cond) != 1: + cond = cond.bool() self.cases = OrderedDict(("-" + k, v) for k, v in self.cases.items()) self.cases["1" + "-" * len(self.test)] = ast.Statement.wrap(stmts) self.test = Cat(self.test, cond) -- 2.30.2