From: whitequark Date: Mon, 26 Oct 2020 19:50:21 +0000 (+0000) Subject: build.dsl: clean up inversion logic. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a44bc97c62c8898a092154fca589ece56bfa3796;p=nmigen.git build.dsl: clean up inversion logic. * Add invert= argument to DiffPairs() constructor, like in Pins(). * Make PinsN() and DiffPairsN() pass invert= to the corresponding construtor instead of mutating. --- diff --git a/nmigen/build/dsl.py b/nmigen/build/dsl.py index 9924e12..3b445f6 100644 --- a/nmigen/build/dsl.py +++ b/nmigen/build/dsl.py @@ -55,13 +55,11 @@ class Pins: def PinsN(*args, **kwargs): - pins = Pins(*args, **kwargs) - pins.invert = True - return pins + return Pins(*args, invert=True, **kwargs) class DiffPairs: - def __init__(self, p, n, *, dir="io", conn=None, assert_width=None): + def __init__(self, p, n, *, dir="io", invert=False, conn=None, assert_width=None): self.p = Pins(p, dir=dir, conn=conn, assert_width=assert_width) self.n = Pins(n, dir=dir, conn=conn, assert_width=assert_width) @@ -71,7 +69,7 @@ class DiffPairs: .format(self.p, self.n)) self.dir = dir - self.invert = False + self.invert = bool(invert) def __len__(self): return len(self.p.names) @@ -85,9 +83,7 @@ class DiffPairs: def DiffPairsN(*args, **kwargs): - diff_pairs = DiffPairs(*args, **kwargs) - diff_pairs.invert = True - return diff_pairs + return DiffPairs(*args, invert=True, **kwargs) class Attrs(OrderedDict): diff --git a/tests/test_build_dsl.py b/tests/test_build_dsl.py index 76cd2e9..580b962 100644 --- a/tests/test_build_dsl.py +++ b/tests/test_build_dsl.py @@ -94,6 +94,10 @@ class DiffPairsTestCase(FHDLTestCase): self.assertEqual(dp.n.names, ["B0"]) self.assertEqual(dp.invert, True) + def test_invert_arg(self): + dp = DiffPairs(p="A0", n="B0", invert=True) + self.assertEqual(dp.invert, True) + def test_conn(self): dp = DiffPairs(p="0 1 2", n="3 4 5", conn=("pmod", 0)) self.assertEqual(list(dp), [