From: whitequark Date: Thu, 13 Jun 2019 03:52:04 +0000 (+0000) Subject: compat.fhdl.structure: always order default case as the very last. X-Git-Tag: locally_working~163 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f689b777b41536912141b79e0710f5f02508afa1;p=nmigen.git compat.fhdl.structure: always order default case as the very last. --- diff --git a/nmigen/compat/fhdl/structure.py b/nmigen/compat/fhdl/structure.py index c0cf3cf..a36086e 100644 --- a/nmigen/compat/fhdl/structure.py +++ b/nmigen/compat/fhdl/structure.py @@ -79,6 +79,7 @@ class Case(ast.Switch): "`with m.Case(): stmts`") def __init__(self, test, cases): new_cases = [] + default = None for k, v in cases.items(): if isinstance(k, (bool, int)): k = Const(k) @@ -86,10 +87,13 @@ class Case(ast.Switch): and not (isinstance(k, str) and k == "default")): raise TypeError("Case object is not a Migen constant") if isinstance(k, str) and k == "default": - k = "-" * len(ast.Value.wrap(test)) + default = v else: k = k.value new_cases.append((k, v)) + if default is not None: + k = "-" * len(ast.Value.wrap(test)) + new_cases.append((k, default)) super().__init__(test, OrderedDict(new_cases)) @deprecated("instead of `Case(...).makedefault()`, use an explicit default case: "