store ospecfn and ispecfn in stagehelper
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 29 Apr 2019 21:54:11 +0000 (22:54 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 29 Apr 2019 21:54:11 +0000 (22:54 +0100)
src/add/singlepipe.py
src/add/stageapi.py

index 3675ea90d75f8e854c7e6d657196605e98ccb39a..c9faa5109406cc61c9cddc54a71ea31855fcdd6c 100644 (file)
@@ -198,13 +198,12 @@ class ControlBase(StageHelper, Elaboratable):
 
         # set up the input and output data
         if stage is not None:
-            self._new_data(self, self, "data")
+            self._new_data("data")
 
-    def _new_data(self, p, n, name):
+    def _new_data(self, name):
         """ allocates new data_i and data_o
         """
-        self.p.data_i = _spec(p.stage.ispec, "%s_i" % name)
-        self.n.data_o = _spec(n.stage.ospec, "%s_o" % name)
+        self.p.data_i, self.n.data_o = self.new_specs(name)
 
     @property
     def data_r(self):
@@ -280,7 +279,8 @@ class ControlBase(StageHelper, Elaboratable):
         # connect front and back of chain to ourselves
         front = pipechain[0]                # first in chain
         end = pipechain[-1]                 # last in chain
-        self._new_data(front, end, "chain") # NOTE: REPLACES existing data
+        self.set_specs(front, end) # NOTE: REPLACES existing data
+        self._new_data("chain") # NOTE: REPLACES existing data
         eqs += front._connect_in(self)      # front p to our p
         eqs += end._connect_out(self)       # end n   to out n
 
index 7dc3659ab58a89b87cfc83820f9a697a9ba6ed46..e819fefca4167cccc7ce9dc5ba937b90e047331b 100644 (file)
@@ -221,14 +221,27 @@ class StageHelper(Stage):
     """
     def __init__(self, stage):
         self.stage = stage
+        self._ispecfn = None
+        self._ospecfn = None
+        if stage is not None:
+            self.set_specs(self, self)
 
     def ospec(self, name):
-        assert self.stage is not None
-        return _spec(self.stage.ospec, name)
+        assert self._ospecfn is not None
+        return _spec(self._ospecfn, name)
 
     def ispec(self, name):
-        assert self.stage is not None
-        return _spec(self.stage.ispec, name)
+        assert self._ispecfn is not None
+        return _spec(self._ispecfn, name)
+
+    def set_specs(self, p, n):
+        self._ispecfn = p.stage.ispec
+        self._ospecfn = n.stage.ospec
+
+    def new_specs(self, name):
+        """ allocates new ispec and ospec pair
+        """
+        return self.ispec("%s_i" % name), self.ospec("%s_o" % name)
 
     def process(self, i):
         if self.stage and hasattr(self.stage, "process"):