From 7382c6222be2e24dabe563f295d834c4a57b0790 Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Fri, 28 Dec 2018 01:33:19 -0500 Subject: [PATCH] hdl.ast: Add Assert and Assign statements. --- nmigen/hdl/ast.py | 53 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) 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) -- 2.30.2