Check equality between two PipeContext instances.
authorSamuel A. Falvo II <kc5tja@arrl.net>
Fri, 17 Jul 2020 23:27:03 +0000 (16:27 -0700)
committerSamuel A. Falvo II <kc5tja@arrl.net>
Fri, 17 Jul 2020 23:27:03 +0000 (16:27 -0700)
src/nmutil/concurrentunit.py

index fd11a3e99cdb8968e4bb61bb0fcc04207d0aedaa..f4667b6ed52634e82aba215a708ef63ec20e177a 100644 (file)
@@ -10,6 +10,7 @@
 
 from math import log
 from nmigen import Module, Elaboratable, Signal
+from nmigen.asserts import Assert
 from nmigen.cli import main, verilog
 
 from nmutil.singlepipe import PassThroughStage
@@ -41,8 +42,20 @@ class PipeContext:
     def eq(self, i):
         ret = [self.muxid.eq(i.muxid)]
         ret.append(self.op.eq(i.op))
+        # don't forget to update matches if you add fields later.
         return ret
 
+    def matches(self, another):
+        """
+        Returns a list of Assert()s validating that this context
+        matches the other context.
+        """
+        # I couldn't figure a clean way of overloading the == operator.
+        return [
+            Assert(self.muxid == another.muxid),
+            Assert(self.op == another.op),
+        ]
+
     def __iter__(self):
         yield self.muxid
         yield self.op