Re: [myhdl-list] difficulty using itertools with MyHDL
Brought to you by:
jandecaluwe
|
From: George P. <ge...@ga...> - 2006-10-21 13:39:06
|
>> So at this point I would look for a workaround and convert
>> iterator objects to the "officially" supported types
>> (for behavior or structure) as desired. The advantage is
>> of course that no change to MyHDL would be required.
>>
>> A workaround for your case could be the following. Just use
>> itertools to set up your iterator as desired. Then convert
>> it to a generator using a one-liner generator expression, e.g.:
>>
>> ordered_tests = (t for t in chain(stage1, stage2, stopsim()))
>>
>> This should work for any iterator you can imagine.
>>
>>
Hi Jan, I like your solution, but I've hit a snag and I'm not sure why
I'm getting the error message below. Could you perhaps enlighten me? ;-)
I've pasted a stripped-down example below:
Thanks,
George
$ python -i test__ascii_timing_spec.py
>>> eggs()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "test__ascii_timing_spec.py", line 92, in eggs
sim.run()
File "/usr/lib/python2.4/site-packages/myhdl/_Simulation.py", line
132, in run
waiter.next(waiters, actives, exc)
File "/usr/lib/python2.4/site-packages/myhdl/_Waiter.py", line 128, in
next
schedule((_simulator._time + clause._time, self))
AttributeError: 'tuple' object has no attribute '_time'
>>>
#
---------------------------------------------------------------------------
from myhdl import Signal, delay, Simulation, instance, instances
def eggs():
def bench(sigs, cts):
def driver(sigs):
clk = sigs['clk']
for i in range(10):
yield delay(1)
clk.next = not clk
def monitor(sigs, cts):
clk = sigs['clk']
i = 0
while True:
yield delay(1)
print "clk = " + str(clk)
i += 1
import itertools
# Execute the driver and monitor together
combo = (t for t in itertools.izip(driver(sigs), monitor(sigs,
cts)))
return combo
sigs = dict(clk=Signal(bool(0)))
ref_cts = dict(clk = [1, 0, 1, 0, 1, 0, 1, 1,
0, 0, 1, 1, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 1, 1])
sim = Simulation(bench(sigs, ref_cts))
sim.run()
#
---------------------------------------------------------------------------
|