examples/dataflow/structuring: test Cast
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Wed, 20 Jun 2012 16:29:03 +0000 (18:29 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Wed, 20 Jun 2012 16:29:03 +0000 (18:29 +0200)
examples/dataflow/structuring.py

index 3963777ed390ca977fc29ab479e37596d8777168..591d7fc6f05093d1be2440abfaceb98a02805259 100644 (file)
@@ -8,7 +8,6 @@ pack_factor = 5
 
 def source_gen():
        for i in range(80):
-               #print("==> " + str(i))
                yield Token("source", {"value": i})
 
 def sink_gen():
@@ -19,15 +18,23 @@ def sink_gen():
 
 def main():
        base_layout = [("value", BV(32))]
+       packed_layout = structuring.pack_layout(base_layout, pack_factor)
+       rawbits_layout = [("value", BV(32*pack_factor))]
        
        source = ActorNode(SimActor(source_gen(), ("source", Source, base_layout)))
+       sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, base_layout)))
+       
+       # A tortuous way of passing integer tokens.
        packer = ActorNode(structuring.Pack(base_layout, pack_factor))
+       to_raw = ActorNode(structuring.Cast(packed_layout, rawbits_layout))
+       from_raw = ActorNode(structuring.Cast(rawbits_layout, packed_layout))
        unpacker = ActorNode(structuring.Unpack(pack_factor, base_layout))
-       sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, base_layout)))
        
        g = DataFlowGraph()
        g.add_connection(source, packer)
-       g.add_connection(packer, unpacker)
+       g.add_connection(packer, to_raw)
+       g.add_connection(to_raw, from_raw)
+       g.add_connection(from_raw, unpacker)
        g.add_connection(unpacker, sink)
        comp = CompositeActor(g)