_Endpoint: allow direct access of payload elements
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 20 Oct 2014 06:47:48 +0000 (08:47 +0200)
committerSebastien Bourdeauducq <sb@m-labs.hk>
Mon, 20 Oct 2014 15:09:56 +0000 (23:09 +0800)
migen/flow/actor.py

index d80937244f88314660d6ce97c2445ba7ebcfda36..00837fd336bd6eb1b5eaf949ac03fe5164be693f 100644 (file)
@@ -12,8 +12,17 @@ def _make_m2s(layout):
                        r.append((f[0], _make_m2s(f[1])))
        return r
 
+def _check_layout(layout, packetized):
+       reserveds = ["stb", "ack", "payload"]
+       if packetized:
+               reserveds += ["sop", "eop"]
+       for f in layout:
+               if f[0] in reserveds:
+                       raise ValueError(f[0] + " cannot be used in Sink/Source layout")
+
 class _Endpoint(Record):
        def __init__(self, layout, packetized=False):
+               _check_layout(layout, packetized)
                endpoint_layout = [
                        ("payload", _make_m2s(layout)),
                        ("stb", 1, DIR_M_TO_S),
@@ -26,6 +35,12 @@ class _Endpoint(Record):
                        ]
                Record.__init__(self, endpoint_layout)
 
+       def __del__(self):
+               pass
+
+       def __getattr__(self, name):
+               return getattr(self.payload, name)
+
 class Source(_Endpoint):
        def connect(self, sink):
                return Record.connect(self, sink)