return self.elems
-class If(ast.Switch):
+class If(ast._InternalSwitch):
@deprecated("instead of `If(cond, ...)`, use `with m.If(cond): ...`")
def __init__(self, cond, *stmts):
cond = Value.cast(cond)
return self
-class Case(ast.Switch):
+class Case(ast._InternalSwitch):
@deprecated("instead of `Case(test, { value: stmts })`, use `with m.Switch(test):` and "
"`with m.Case(value): stmts`; instead of `\"default\": stmts`, use "
"`with m.Case(): stmts`")
"Shape", "signed", "unsigned",
"Value", "Const", "C", "AnyConst", "AnySeq", "Operator", "Mux", "Part", "Slice", "Cat", "Repl",
"Array", "ArrayProxy",
+ "_InternalSwitch",
"Signal", "ClockSignal", "ResetSignal",
"UserValue", "ValueCastable",
"Sample", "Past", "Stable", "Rose", "Fell", "Initial",
def __Mux__(self, val1, val0):
return _InternalMux(self, val1, val0)
+ def __Switch__(self, cases, *, src_loc=None, src_loc_at=0, case_src_locs={}):
+ return _InternalSwitch(self, cases, src_loc=src_loc,
+ src_loc_at=src_loc_at,
+ case_src_locs=case_src_locs)
+
def __bool__(self):
raise TypeError("Attempted to convert nMigen value to Python boolean")
# @final
-class Switch(Statement):
+def Switch(test, cases, *, src_loc=None, src_loc_at=0, case_src_locs={}):
+ return test.__Switch__(cases, src_loc=src_loc, src_loc_at=src_loc_at,
+ case_src_locs=case_src_locs)
+
+
+class _InternalSwitch(Statement):
def __init__(self, test, cases, *, src_loc=None, src_loc_at=0, case_src_locs={}):
if src_loc is None:
super().__init__(src_loc_at=src_loc_at)
new_stmt = self.on_Assume(stmt)
elif type(stmt) is Cover:
new_stmt = self.on_Cover(stmt)
- elif isinstance(stmt, Switch):
+ elif isinstance(stmt, _InternalSwitch):
# Uses `isinstance()` and not `type() is` because nmigen.compat requires it.
new_stmt = self.on_Switch(stmt)
elif isinstance(stmt, Iterable):
new_stmt = self.on_unknown_statement(stmt)
if isinstance(new_stmt, Statement) and self.replace_statement_src_loc(stmt, new_stmt):
new_stmt.src_loc = stmt.src_loc
- if isinstance(new_stmt, Switch) and isinstance(stmt, Switch):
+ if (isinstance(new_stmt, _InternalSwitch) and
+ isinstance(stmt, _InternalSwitch)):
new_stmt.case_src_locs = stmt.case_src_locs
if isinstance(new_stmt, Property):
new_stmt._MustUse__used = True