From: William D. Jones Date: Fri, 28 Dec 2018 06:33:19 +0000 (-0500) Subject: hdl.ast: Add Assert and Assign statements. X-Git-Tag: working~102 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e6517a33c73463b1c36be0c979273d717d89a95c;p=nmigen.git hdl.ast: Add Assert and Assign statements. --- diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index fc6a0de..9295ed4 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -12,8 +12,9 @@ __all__ = [ "Value", "Const", "C", "Operator", "Mux", "Part", "Slice", "Cat", "Repl", "Array", "ArrayProxy", "Signal", "ClockSignal", "ResetSignal", - "Statement", "Assign", "Switch", "Delay", "Tick", "Passive", - "ValueKey", "ValueDict", "ValueSet", "SignalKey", "SignalDict", "SignalSet", + "Statement", "Assign", "Assert", "Assume", "Switch", "Delay", "Tick", + "Passive", "ValueKey", "ValueDict", "ValueSet", "SignalKey", "SignalDict", + "SignalSet", ] @@ -826,6 +827,54 @@ class Assign(Statement): return "(eq {!r} {!r})".format(self.lhs, self.rhs) +class Assert(Statement): + def __init__(self, test, _check=None, _en=None): + self.test = Value.wrap(test) + + self._check = _check + if self._check is None: + self._check = Signal(reset_less=True, name="$assert$check") + self._check.src_loc = self.test.src_loc + + self._en = _en + if _en is None: + self._en = Signal(reset_less=True, name="$assert$en") + self._en.src_loc = self.test.src_loc + + def _lhs_signals(self): + return ValueSet((self._en, self._check)) + + def _rhs_signals(self): + return self.test._rhs_signals() + + def __repr__(self): + return "(assert {!r})".format(self.test) + + +class Assume(Statement): + def __init__(self, test, _check=None, _en=None): + self.test = Value.wrap(test) + + self._check = _check + if self._check is None: + self._check = Signal(reset_less=True, name="$assume$check") + self._check.src_loc = self.test.src_loc + + self._en = _en + if self._en is None: + self._en = Signal(reset_less=True, name="$assume$en") + self._en.src_loc = self.test.src_loc + + def _lhs_signals(self): + return ValueSet((self._en, self._check)) + + def _rhs_signals(self): + return self.test._rhs_signals() + + def __repr__(self): + return "(assume {!r})".format(self.test) + + class Switch(Statement): def __init__(self, test, cases): self.test = Value.wrap(test)