diff --git a/amaranth/hdl/ast.py b/amaranth/hdl/ast.py index dc243ab..c3468f8 100644 --- a/amaranth/hdl/ast.py +++ b/amaranth/hdl/ast.py @@ -116,15 +116,6 @@ class Shape: return "unsigned({})".format(self.width) def __eq__(self, other): - # TODO(nmigen-0.4): remove - if isinstance(other, tuple) and len(other) == 2: - width, signed = other - if isinstance(width, int) and isinstance(signed, bool): - return self.width == width and self.signed == signed - else: - raise TypeError("Shapes may be compared with other Shapes and (int, bool) tuples, " - "not {!r}" - .format(other)) if not isinstance(other, Shape): try: other = self.__class__.cast(other) diff --git a/tests/test_hdl_ast.py b/tests/test_hdl_ast.py index 1f14385..5231c0a 100644 --- a/tests/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -53,8 +53,7 @@ class ShapeTestCase(FHDLTestCase): def test_compare_tuple_wrong(self): with self.assertRaisesRegex(TypeError, - r"^Shapes may be compared with other Shapes and \(int, bool\) tuples, " - r"not \(2, 3\)$"): + r"^Shapes may be compared with shape-castable objects, not \(2, 3\)$"): Shape(1, True) == (2, 3) def test_repr(self): diff --git a/tests/test_hdl_rec.py b/tests/test_hdl_rec.py index 6eb4d3c..4e71296 100644 --- a/tests/test_hdl_rec.py +++ b/tests/test_hdl_rec.py @@ -30,28 +30,28 @@ class LayoutTestCase(FHDLTestCase): ]) ]) - self.assertFieldEqual(layout["cyc"], ((1, False), DIR_NONE)) - self.assertFieldEqual(layout["data"], ((32, True), DIR_NONE)) - self.assertFieldEqual(layout["stb"], ((1, False), DIR_FANOUT)) - self.assertFieldEqual(layout["ack"], ((1, False), DIR_FANIN)) + self.assertFieldEqual(layout["cyc"], (unsigned(1), DIR_NONE)) + self.assertFieldEqual(layout["data"], (signed(32), DIR_NONE)) + self.assertFieldEqual(layout["stb"], (unsigned(1), DIR_FANOUT)) + self.assertFieldEqual(layout["ack"], (unsigned(1), DIR_FANIN)) sublayout = layout["info"][0] self.assertEqual(layout["info"][1], DIR_NONE) - self.assertFieldEqual(sublayout["a"], ((1, False), DIR_NONE)) - self.assertFieldEqual(sublayout["b"], ((1, False), DIR_NONE)) + self.assertFieldEqual(sublayout["a"], (unsigned(1), DIR_NONE)) + self.assertFieldEqual(sublayout["b"], (unsigned(1), DIR_NONE)) def test_enum_field(self): layout = Layout.cast([ ("enum", UnsignedEnum), ("enum_dir", UnsignedEnum, DIR_FANOUT), ]) - self.assertFieldEqual(layout["enum"], ((2, False), DIR_NONE)) - self.assertFieldEqual(layout["enum_dir"], ((2, False), DIR_FANOUT)) + self.assertFieldEqual(layout["enum"], (unsigned(2), DIR_NONE)) + self.assertFieldEqual(layout["enum_dir"], (unsigned(2), DIR_FANOUT)) def test_range_field(self): layout = Layout.cast([ ("range", range(0, 7)), ]) - self.assertFieldEqual(layout["range"], ((3, False), DIR_NONE)) + self.assertFieldEqual(layout["range"], (unsigned(3), DIR_NONE)) def test_slice_tuple(self): layout = Layout.cast([ diff --git a/tests/test_lib_io.py b/tests/test_lib_io.py index 5043060..17f3a16 100644 --- a/tests/test_lib_io.py +++ b/tests/test_lib_io.py @@ -19,51 +19,51 @@ class PinLayoutCombTestCase(PinLayoutTestCase): def test_pin_layout_i(self): layout_1 = pin_layout(1, dir="i") self.assertLayoutEqual(layout_1.fields, { - "i": ((1, False), DIR_NONE), + "i": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="i") self.assertLayoutEqual(layout_2.fields, { - "i": ((2, False), DIR_NONE), + "i": (unsigned(2), DIR_NONE), }) def test_pin_layout_o(self): layout_1 = pin_layout(1, dir="o") self.assertLayoutEqual(layout_1.fields, { - "o": ((1, False), DIR_NONE), + "o": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="o") self.assertLayoutEqual(layout_2.fields, { - "o": ((2, False), DIR_NONE), + "o": (unsigned(2), DIR_NONE), }) def test_pin_layout_oe(self): layout_1 = pin_layout(1, dir="oe") self.assertLayoutEqual(layout_1.fields, { - "o": ((1, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "o": (unsigned(1), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="oe") self.assertLayoutEqual(layout_2.fields, { - "o": ((2, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "o": (unsigned(2), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) def test_pin_layout_io(self): layout_1 = pin_layout(1, dir="io") self.assertLayoutEqual(layout_1.fields, { - "i": ((1, False), DIR_NONE), - "o": ((1, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "i": (unsigned(1), DIR_NONE), + "o": (unsigned(1), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="io") self.assertLayoutEqual(layout_2.fields, { - "i": ((2, False), DIR_NONE), - "o": ((2, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "i": (unsigned(2), DIR_NONE), + "o": (unsigned(2), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) @@ -71,61 +71,61 @@ class PinLayoutSDRTestCase(PinLayoutTestCase): def test_pin_layout_i(self): layout_1 = pin_layout(1, dir="i", xdr=1) self.assertLayoutEqual(layout_1.fields, { - "i_clk": ((1, False), DIR_NONE), - "i": ((1, False), DIR_NONE), + "i_clk": (unsigned(1), DIR_NONE), + "i": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="i", xdr=1) self.assertLayoutEqual(layout_2.fields, { - "i_clk": ((1, False), DIR_NONE), - "i": ((2, False), DIR_NONE), + "i_clk": (unsigned(1), DIR_NONE), + "i": (unsigned(2), DIR_NONE), }) def test_pin_layout_o(self): layout_1 = pin_layout(1, dir="o", xdr=1) self.assertLayoutEqual(layout_1.fields, { - "o_clk": ((1, False), DIR_NONE), - "o": ((1, False), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="o", xdr=1) self.assertLayoutEqual(layout_2.fields, { - "o_clk": ((1, False), DIR_NONE), - "o": ((2, False), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o": (unsigned(2), DIR_NONE), }) def test_pin_layout_oe(self): layout_1 = pin_layout(1, dir="oe", xdr=1) self.assertLayoutEqual(layout_1.fields, { - "o_clk": ((1, False), DIR_NONE), - "o": ((1, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o": (unsigned(1), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="oe", xdr=1) self.assertLayoutEqual(layout_2.fields, { - "o_clk": ((1, False), DIR_NONE), - "o": ((2, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o": (unsigned(2), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) def test_pin_layout_io(self): layout_1 = pin_layout(1, dir="io", xdr=1) self.assertLayoutEqual(layout_1.fields, { - "i_clk": ((1, False), DIR_NONE), - "i": ((1, False), DIR_NONE), - "o_clk": ((1, False), DIR_NONE), - "o": ((1, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "i_clk": (unsigned(1), DIR_NONE), + "i": (unsigned(1), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o": (unsigned(1), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="io", xdr=1) self.assertLayoutEqual(layout_2.fields, { - "i_clk": ((1, False), DIR_NONE), - "i": ((2, False), DIR_NONE), - "o_clk": ((1, False), DIR_NONE), - "o": ((2, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "i_clk": (unsigned(1), DIR_NONE), + "i": (unsigned(2), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o": (unsigned(2), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) @@ -133,71 +133,71 @@ class PinLayoutDDRTestCase(PinLayoutTestCase): def test_pin_layout_i(self): layout_1 = pin_layout(1, dir="i", xdr=2) self.assertLayoutEqual(layout_1.fields, { - "i_clk": ((1, False), DIR_NONE), - "i0": ((1, False), DIR_NONE), - "i1": ((1, False), DIR_NONE), + "i_clk": (unsigned(1), DIR_NONE), + "i0": (unsigned(1), DIR_NONE), + "i1": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="i", xdr=2) self.assertLayoutEqual(layout_2.fields, { - "i_clk": ((1, False), DIR_NONE), - "i0": ((2, False), DIR_NONE), - "i1": ((2, False), DIR_NONE), + "i_clk": (unsigned(1), DIR_NONE), + "i0": (unsigned(2), DIR_NONE), + "i1": (unsigned(2), DIR_NONE), }) def test_pin_layout_o(self): layout_1 = pin_layout(1, dir="o", xdr=2) self.assertLayoutEqual(layout_1.fields, { - "o_clk": ((1, False), DIR_NONE), - "o0": ((1, False), DIR_NONE), - "o1": ((1, False), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o0": (unsigned(1), DIR_NONE), + "o1": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="o", xdr=2) self.assertLayoutEqual(layout_2.fields, { - "o_clk": ((1, False), DIR_NONE), - "o0": ((2, False), DIR_NONE), - "o1": ((2, False), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o0": (unsigned(2), DIR_NONE), + "o1": (unsigned(2), DIR_NONE), }) def test_pin_layout_oe(self): layout_1 = pin_layout(1, dir="oe", xdr=2) self.assertLayoutEqual(layout_1.fields, { - "o_clk": ((1, False), DIR_NONE), - "o0": ((1, False), DIR_NONE), - "o1": ((1, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o0": (unsigned(1), DIR_NONE), + "o1": (unsigned(1), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="oe", xdr=2) self.assertLayoutEqual(layout_2.fields, { - "o_clk": ((1, False), DIR_NONE), - "o0": ((2, False), DIR_NONE), - "o1": ((2, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o0": (unsigned(2), DIR_NONE), + "o1": (unsigned(2), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) def test_pin_layout_io(self): layout_1 = pin_layout(1, dir="io", xdr=2) self.assertLayoutEqual(layout_1.fields, { - "i_clk": ((1, False), DIR_NONE), - "i0": ((1, False), DIR_NONE), - "i1": ((1, False), DIR_NONE), - "o_clk": ((1, False), DIR_NONE), - "o0": ((1, False), DIR_NONE), - "o1": ((1, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "i_clk": (unsigned(1), DIR_NONE), + "i0": (unsigned(1), DIR_NONE), + "i1": (unsigned(1), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o0": (unsigned(1), DIR_NONE), + "o1": (unsigned(1), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), }) layout_2 = pin_layout(2, dir="io", xdr=2) self.assertLayoutEqual(layout_2.fields, { - "i_clk": ((1, False), DIR_NONE), - "i0": ((2, False), DIR_NONE), - "i1": ((2, False), DIR_NONE), - "o_clk": ((1, False), DIR_NONE), - "o0": ((2, False), DIR_NONE), - "o1": ((2, False), DIR_NONE), - "oe": ((1, False), DIR_NONE), + "i_clk": (unsigned(1), DIR_NONE), + "i0": (unsigned(2), DIR_NONE), + "i1": (unsigned(2), DIR_NONE), + "o_clk": (unsigned(1), DIR_NONE), + "o0": (unsigned(2), DIR_NONE), + "o1": (unsigned(2), DIR_NONE), + "oe": (unsigned(1), DIR_NONE), })