hdl.xfrm: Add Assert and Assume abstract methods for StatementVisitor, implement...
authorWilliam D. Jones <thor0505@comcast.net>
Sun, 30 Dec 2018 10:17:39 +0000 (05:17 -0500)
committerwhitequark <cz@m-labs.hk>
Wed, 2 Jan 2019 11:17:39 +0000 (11:17 +0000)
nmigen/back/pysim.py
nmigen/hdl/xfrm.py

index 0bcb0b338100238631528fd0cf28cc9ce9b90943..a1e43a5f8a4c5a873399891ae253b092bd7962f5 100644 (file)
@@ -297,6 +297,12 @@ class _StatementCompiler(StatementVisitor):
             lhs(state, normalize(rhs(state), shape))
         return run
 
+    def on_Assert(self, stmt):
+        raise NotImplementedError("Asserts not yet implemented for Simulator backend.") # :nocov:
+
+    def on_Assume(self, stmt):
+        pass # :nocov:
+
     def on_Switch(self, stmt):
         test  = self.rrhs_compiler(stmt.test)
         cases = []
index e70f9d17fd140c82bb282fd9729416eeb6db711a..d7c142a48acbf696cd7e8da1e31bf6dad0b4b779 100644 (file)
@@ -141,6 +141,14 @@ class StatementVisitor(metaclass=ABCMeta):
     def on_Assign(self, stmt):
         pass # :nocov:
 
+    @abstractmethod
+    def on_Assert(self, stmt):
+        pass # :nocov:
+
+    @abstractmethod
+    def on_Assume(self, stmt):
+        pass # :nocov:
+
     @abstractmethod
     def on_Switch(self, stmt):
         pass # :nocov:
@@ -155,6 +163,10 @@ class StatementVisitor(metaclass=ABCMeta):
     def on_statement(self, stmt):
         if type(stmt) is Assign:
             return self.on_Assign(stmt)
+        elif type(stmt) is Assert:
+            return self.on_Assert(stmt)
+        elif type(stmt) is Assume:
+            return self.on_Assume(stmt)
         elif isinstance(stmt, Switch):
             # Uses `isinstance()` and not `type() is` because nmigen.compat requires it.
             return self.on_Switch(stmt)
@@ -174,6 +186,12 @@ class StatementTransformer(StatementVisitor):
     def on_Assign(self, stmt):
         return Assign(self.on_value(stmt.lhs), self.on_value(stmt.rhs))
 
+    def on_Assert(self, stmt):
+        return Assert(self.on_value(stmt.test), _check=stmt._check, _en=stmt._en)
+
+    def on_Assume(self, stmt):
+        return Assume(self.on_value(stmt.test), _check=stmt._check, _en=stmt._en)
+
     def on_Switch(self, stmt):
         cases = OrderedDict((k, self.on_statement(s)) for k, s in stmt.cases.items())
         return Switch(self.on_value(stmt.test), cases)
@@ -294,6 +312,10 @@ class SwitchCleaner(StatementVisitor):
     def on_Assign(self, stmt):
         return stmt
 
+    on_Assert = on_Assign
+
+    on_Assume = on_Assign
+
     def on_Switch(self, stmt):
         cases = OrderedDict((k, self.on_statement(s)) for k, s in stmt.cases.items())
         if any(len(s) for s in cases.values()):
@@ -338,6 +360,10 @@ class LHSGroupAnalyzer(StatementVisitor):
     def on_Assign(self, stmt):
         self.unify(*stmt._lhs_signals())
 
+    on_Assert = on_Assign
+
+    on_Assume = on_Assign
+
     def on_Switch(self, stmt):
         for case_stmts in stmt.cases.values():
             self.on_statements(case_stmts)
@@ -362,6 +388,13 @@ class LHSGroupFilter(SwitchCleaner):
         if any_lhs_signal in self.signals:
             return stmt
 
+    def on_Assert(self, stmt):
+        any_lhs_signal = next(iter(stmt._lhs_signals()))
+        if any_lhs_signal in self.signals:
+            return stmt
+
+    on_Assume = on_Assert
+
 
 class _ControlInserter(FragmentTransformer):
     def __init__(self, controls):