@@ -162,24 +162,31 @@ def __init__(self, bitwidth: int, addrwidth: int, name: str = '',
162162 ---------------------------
163163 Simultaneous Read and Write
164164 ---------------------------
165+ ..
166+ # For ``doctest``.
167+ >>> import pyrtl
168+ >>> pyrtl.reset_working_block()
169+
165170 In PyRTL simulations, if the same address is read and written in the same cycle,
166171 the read will return the `last` value stored in the MemBlock, not the newly
167172 written value. Example::
168173
169- mem = pyrtl.MemBlock(addrwidth=1, bitwidth=1)
170- mem[0] <<= 1
171- read_data = pyrtl.Output(name="read_data", bitwidth=1)
172- read_data <<= mem[0]
174+ >>> mem = pyrtl.MemBlock(addrwidth=1, bitwidth=1)
175+ >>> mem[0] <<= 1
176+ >>> read_data = pyrtl.Output(name="read_data", bitwidth=1)
177+ >>> read_data <<= mem[0]
173178
174- # In the first cycle, read_data will be the default MemBlock data value (0),
175- # not the newly written value (1).
176- sim = pyrtl.Simulation()
177- sim.step()
178- print("Cycle 0 read_data", sim.inspect("read_data"))
179+ >>> # In the first cycle, read_data will be the default MemBlock data value
180+ >>> # (0), not the newly written value (1).
181+ >>> sim = pyrtl.Simulation()
182+ >>> sim.step()
183+ >>> sim.inspect("read_data")
184+ 0
179185
180186 # In the second cycle, read_data will be the newly written value (1).
181- sim.step()
182- print("Cycle 1 read_data", sim.inspect("read_data"))
187+ >>> sim.step()
188+ >>> sim.inspect("read_data")
189+ 1
183190
184191 -----------------------------
185192 Mapping MemBlocks to Hardware
0 commit comments