From: Samuel A. Falvo II Date: Fri, 17 Jul 2020 23:27:03 +0000 (-0700) Subject: Check equality between two PipeContext instances. X-Git-Tag: 24jan2021_ls180~34 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=aeed18a63d687cdaa9c00b98d46c66583fef6e2d;p=nmutil.git Check equality between two PipeContext instances. --- diff --git a/src/nmutil/concurrentunit.py b/src/nmutil/concurrentunit.py index fd11a3e..f4667b6 100644 --- a/src/nmutil/concurrentunit.py +++ b/src/nmutil/concurrentunit.py @@ -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