Skip to content

Commit 0ecd06a

Browse files
wanda-phiwhitequark
authored andcommitted
sim: fix using 0-width Switch.
1 parent 8033ddf commit 0ecd06a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

amaranth/sim/_pyrtl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def on_Switch(self, stmt):
378378
value = int("".join("0" if b == "-" else b for b in pattern), 2)
379379
gen_checks.append(f"{value} == ({mask} & {gen_test})")
380380
else:
381-
value = int(pattern, 2)
381+
value = int(pattern or "0", 2)
382382
gen_checks.append(f"{value} == {gen_test}")
383383
if index == 0:
384384
self.emitter.append(f"if {' or '.join(gen_checks)}:")

tests/test_sim.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,18 @@ def test_large_expr_parser_overflow(self):
10641064
m.d.comb += a.eq(op)
10651065
Simulator(m)
10661066

1067+
def test_switch_zero(self):
1068+
m = Module()
1069+
a = Signal(0)
1070+
o = Signal()
1071+
with m.Switch(a):
1072+
with m.Case(""):
1073+
m.d.comb += o.eq(1)
1074+
with self.assertSimulation(m) as sim:
1075+
def process():
1076+
self.assertEqual((yield o), 1)
1077+
sim.add_testbench(process)
1078+
10671079

10681080
class SimulatorRegressionTestCase(FHDLTestCase):
10691081
def test_bug_325(self):

0 commit comments

Comments
 (0)