compat.fhdl.structure: only convert to bool in If/Elif if necessary.

This commit is contained in:
whitequark 2018-12-16 17:41:42 +00:00
parent 9bce35098f
commit db5fd1e4c4

View file

@ -30,12 +30,16 @@ def Constant(value, bits_sign=None):
class If(ast.Switch): class If(ast.Switch):
@deprecated("instead of `If(cond, ...)`, use `with m.If(cond): ...`") @deprecated("instead of `If(cond, ...)`, use `with m.If(cond): ...`")
def __init__(self, cond, *stmts): 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)}) super().__init__(cond, {"1": ast.Statement.wrap(stmts)})
@deprecated("instead of `.Elif(cond, ...)`, use `with m.Elif(cond): ...`") @deprecated("instead of `.Elif(cond, ...)`, use `with m.Elif(cond): ...`")
def Elif(self, cond, *stmts): 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 = OrderedDict(("-" + k, v) for k, v in self.cases.items())
self.cases["1" + "-" * len(self.test)] = ast.Statement.wrap(stmts) self.cases["1" + "-" * len(self.test)] = ast.Statement.wrap(stmts)
self.test = Cat(self.test, cond) self.test = Cat(self.test, cond)