2012-06-08 11:54:03 -04:00
|
|
|
from migen.fhdl.structure import *
|
|
|
|
from migen.flow.actor import *
|
2012-12-14 09:55:38 -05:00
|
|
|
from migen.flow.transactions import *
|
2012-06-08 11:54:03 -04:00
|
|
|
from migen.flow.network import *
|
|
|
|
from migen.actorlib.sim import *
|
|
|
|
from migen.sim.generic import Simulator
|
|
|
|
from migen.sim.icarus import Runner
|
|
|
|
|
|
|
|
def source_gen():
|
|
|
|
for i in range(10):
|
|
|
|
print("Sending: " + str(i))
|
|
|
|
yield Token("source", {"value": i})
|
|
|
|
|
|
|
|
def sink_gen():
|
|
|
|
while True:
|
|
|
|
t = Token("sink")
|
|
|
|
yield t
|
|
|
|
print("Received: " + str(t.value["value"]))
|
|
|
|
|
|
|
|
def main():
|
2012-12-12 16:20:48 -05:00
|
|
|
source = SimActor(source_gen(), ("source", Source, [("value", 32)]))
|
|
|
|
sink = SimActor(sink_gen(), ("sink", Sink, [("value", 32)]))
|
2012-06-08 16:49:49 -04:00
|
|
|
g = DataFlowGraph()
|
|
|
|
g.add_connection(source, sink)
|
2012-06-08 11:54:03 -04:00
|
|
|
comp = CompositeActor(g)
|
|
|
|
def end_simulation(s):
|
2012-12-12 16:20:48 -05:00
|
|
|
s.interrupt = source.token_exchanger.done
|
2012-06-08 11:54:03 -04:00
|
|
|
fragment = comp.get_fragment() + Fragment(sim=[end_simulation])
|
|
|
|
sim = Simulator(fragment, Runner())
|
|
|
|
sim.run()
|
|
|
|
|
|
|
|
main()
|