From aeed18a63d687cdaa9c00b98d46c66583fef6e2d Mon Sep 17 00:00:00 2001 From: "Samuel A. Falvo II" Date: Fri, 17 Jul 2020 16:27:03 -0700 Subject: [PATCH] Check equality between two PipeContext instances. --- src/nmutil/concurrentunit.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 -- 2.30.2