compat.fhdl.structure: handle If/Elif with multi-bit condition.
authorwhitequark <cz@m-labs.hk>
Sat, 15 Dec 2018 00:10:54 +0000 (00:10 +0000)
committerwhitequark <cz@m-labs.hk>
Sat, 15 Dec 2018 00:10:54 +0000 (00:10 +0000)
nmigen/compat/fhdl/structure.py

index 4f89080422b5e305ce86b482562e2e03b6312a3f..5a4d9fadc719a8e072aa9e6f9c5a4fc684c6150c 100644 (file)
@@ -29,10 +29,12 @@ 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()
         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()
         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)