actorlib/structuring/Cast: support inversion
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Mon, 25 Mar 2013 14:54:09 +0000 (15:54 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Mon, 25 Mar 2013 14:54:09 +0000 (15:54 +0100)
migen/actorlib/structuring.py

index 6f6483b280f748f5b9f5a291c14eb021f9c3f50a..dbe2204ab17a77d60db60baa89341edf4b21908c 100644 (file)
@@ -8,14 +8,20 @@ def _rawbits_layout(l):
                return l
 
 class Cast(CombinatorialActor):
-       def __init__(self, layout_from, layout_to):
+       def __init__(self, layout_from, layout_to, reverse_from=False, reverse_to=False):
+               self.reverse_from = reverse_from
+               self.reverse_to = reverse_to
                CombinatorialActor.__init__(self,
                        ("sink", Sink, _rawbits_layout(layout_from)),
                        ("source", Source, _rawbits_layout(layout_to)))
        
        def get_process_fragment(self):
                sigs_from = self.token("sink").flatten()
+               if self.reverse_from:
+                       sigs_from = list(reversed(sigs_from))
                sigs_to = self.token("source").flatten()
+               if self.reverse_to:
+                       sigs_to = list(reversed(sigs_to))
                if sum(len(s) for s in sigs_from) != sum(len(s) for s in sigs_to):
                        raise TypeError
                return Fragment([