hdl.ast: Add Assert and Assign statements.
authorWilliam D. Jones <thor0505@comcast.net>
Fri, 28 Dec 2018 06:33:19 +0000 (01:33 -0500)
committerwhitequark <cz@m-labs.hk>
Wed, 2 Jan 2019 11:17:39 +0000 (11:17 +0000)
nmigen/hdl/ast.py

index fc6a0de9dca19cc29d7c441db0ff76109d2d613c..9295ed441e3db0d3bda4aa5cafa4f5ebb9fa6eae 100644 (file)
@@ -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)