Skip to content

Commit 5d91132

Browse files
wanda-phiwhitequark
authored andcommitted
sim: fix using 0-width Switch.
1 parent a669aa3 commit 5d91132

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

amaranth/sim/_pyrtl.py

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

tests/test_sim.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,19 @@ def test_large_expr_parser_overflow(self):
10141014
m.d.comb += a.eq(op)
10151015
Simulator(m)
10161016

1017+
def test_switch_zero(self):
1018+
m = Module()
1019+
a = Signal(0)
1020+
o = Signal()
1021+
with m.Switch(a):
1022+
with m.Case(""):
1023+
m.d.comb += o.eq(1)
1024+
with self.assertSimulation(m) as sim:
1025+
def process():
1026+
yield Settle()
1027+
self.assertEqual((yield o), 1)
1028+
sim.add_process(process)
1029+
10171030

10181031
class SimulatorRegressionTestCase(FHDLTestCase):
10191032
def test_bug_325(self):

0 commit comments

Comments
 (0)