34 lines
854 B
Python
34 lines
854 B
Python
|
import networkx as nx
|
||
|
|
||
|
from migen.fhdl.structure import *
|
||
|
from migen.flow.actor import *
|
||
|
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():
|
||
|
source = SimActor(source_gen(), ("source", Source, [("value", BV(32))]))
|
||
|
sink = SimActor(sink_gen(), ("sink", Sink, [("value", BV(32))]))
|
||
|
g = nx.MultiDiGraph()
|
||
|
add_connection(g, source, sink)
|
||
|
comp = CompositeActor(g)
|
||
|
def end_simulation(s):
|
||
|
s.interrupt = source.done
|
||
|
fragment = comp.get_fragment() + Fragment(sim=[end_simulation])
|
||
|
sim = Simulator(fragment, Runner())
|
||
|
sim.run()
|
||
|
|
||
|
main()
|