2012-06-20 12:25:01 -04:00
|
|
|
from migen.flow.network import *
|
|
|
|
from migen.actorlib import structuring
|
|
|
|
from migen.actorlib.sim import *
|
|
|
|
from migen.sim.generic import Simulator
|
|
|
|
from migen.sim.icarus import Runner
|
|
|
|
|
|
|
|
pack_factor = 5
|
|
|
|
|
|
|
|
def source_gen():
|
|
|
|
for i in range(80):
|
|
|
|
yield Token("source", {"value": i})
|
|
|
|
|
|
|
|
def sink_gen():
|
|
|
|
while True:
|
|
|
|
t = Token("sink")
|
|
|
|
yield t
|
|
|
|
print(t.value["value"])
|
|
|
|
|
|
|
|
def main():
|
|
|
|
base_layout = [("value", BV(32))]
|
2012-06-20 12:29:03 -04:00
|
|
|
packed_layout = structuring.pack_layout(base_layout, pack_factor)
|
|
|
|
rawbits_layout = [("value", BV(32*pack_factor))]
|
2012-06-20 12:25:01 -04:00
|
|
|
|
|
|
|
source = ActorNode(SimActor(source_gen(), ("source", Source, base_layout)))
|
2012-06-20 12:29:03 -04:00
|
|
|
sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, base_layout)))
|
|
|
|
|
|
|
|
# A tortuous way of passing integer tokens.
|
2012-06-20 12:25:01 -04:00
|
|
|
packer = ActorNode(structuring.Pack(base_layout, pack_factor))
|
2012-06-20 12:29:03 -04:00
|
|
|
to_raw = ActorNode(structuring.Cast(packed_layout, rawbits_layout))
|
|
|
|
from_raw = ActorNode(structuring.Cast(rawbits_layout, packed_layout))
|
2012-06-20 12:25:01 -04:00
|
|
|
unpacker = ActorNode(structuring.Unpack(pack_factor, base_layout))
|
|
|
|
|
|
|
|
g = DataFlowGraph()
|
|
|
|
g.add_connection(source, packer)
|
2012-06-20 12:29:03 -04:00
|
|
|
g.add_connection(packer, to_raw)
|
|
|
|
g.add_connection(to_raw, from_raw)
|
|
|
|
g.add_connection(from_raw, unpacker)
|
2012-06-20 12:25:01 -04:00
|
|
|
g.add_connection(unpacker, sink)
|
|
|
|
comp = CompositeActor(g)
|
|
|
|
|
|
|
|
fragment = comp.get_fragment()
|
|
|
|
sim = Simulator(fragment, Runner())
|
|
|
|
sim.run(100)
|
|
|
|
|
|
|
|
main()
|