2012-06-17 15:19:47 -04:00
|
|
|
from migen.flow.network import *
|
2012-06-22 09:01:47 -04:00
|
|
|
from migen.actorlib import misc
|
2012-06-17 15:19:47 -04:00
|
|
|
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):
|
|
|
|
v = i + 5
|
|
|
|
print("==> " + str(v))
|
|
|
|
yield Token("source", {"value": v})
|
|
|
|
|
|
|
|
def sink_gen():
|
|
|
|
while True:
|
|
|
|
t = Token("sink")
|
|
|
|
yield t
|
|
|
|
print(t.value["value"])
|
|
|
|
|
|
|
|
def main():
|
2012-11-29 15:22:38 -05:00
|
|
|
source = ActorNode(SimActor(source_gen(), ("source", Source, [("value", 32)])))
|
2012-06-22 09:01:47 -04:00
|
|
|
loop = ActorNode(misc.IntSequence(32))
|
2012-11-29 15:22:38 -05:00
|
|
|
sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, [("value", 32)])))
|
2012-06-17 15:19:47 -04:00
|
|
|
g = DataFlowGraph()
|
|
|
|
g.add_connection(source, loop)
|
|
|
|
g.add_connection(loop, sink)
|
|
|
|
comp = CompositeActor(g)
|
|
|
|
fragment = comp.get_fragment()
|
|
|
|
sim = Simulator(fragment, Runner())
|
|
|
|
sim.run(500)
|
|
|
|
|
|
|
|
main()
|