derive StageChain from StageHelper, use set_specs instead of manual ispec/ospec
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 29 Apr 2019 22:03:11 +0000 (23:03 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 29 Apr 2019 22:03:11 +0000 (23:03 +0100)
function, add auto-detect to set_specs to determine if it is
passed an object that has a "stage"

src/add/singlepipe.py
src/add/stageapi.py

index c9faa5109406cc61c9cddc54a71ea31855fcdd6c..d917e4c40cee15a810e25b817a1ea7844ecd120b 100644 (file)
@@ -279,7 +279,7 @@ 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.set_specs(front, end) # NOTE: REPLACES existing data
+        self.set_specs(front, end) # sets up ispec/ospec functions
         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 259b9de92a9ce20a81f792321ba959cc6f99bbb3..eb90315c7fcc70518839ed95403ad2a1831bec91 100644 (file)
@@ -155,8 +155,14 @@ class StageHelper(Stage):
         return _spec(self._ispecfn, name)
 
     def set_specs(self, p, n):
-        self._ispecfn = p.stage.ispec
-        self._ospecfn = n.stage.ospec
+        """ sets up the ispecfn and ospecfn for getting input and output data
+        """
+        if hasattr(p, "stage"):
+            p = p.stage
+        if hasattr(n, "stage"):
+            n = n.stage
+        self._ispecfn = p.ispec
+        self._ospecfn = n.ospec
 
     def new_specs(self, name):
         """ allocates new ispec and ospec pair
@@ -179,7 +185,7 @@ class StageHelper(Stage):
         return i
 
 
-class StageChain(StageCls):
+class StageChain(StageHelper):
     """ pass in a list of stages, and they will automatically be
         chained together via their input and output specs into a
         combinatorial chain, to create one giant combinatorial block.
@@ -220,17 +226,9 @@ class StageChain(StageCls):
     def __init__(self, chain, specallocate=False):
         assert len(chain) > 0, "stage chain must be non-zero length"
         self.chain = chain
+        StageHelper.__init__(self, None)
         self.setup = self._sa_setup if specallocate else self._na_setup
-
-    def ispec(self):
-        """ returns the ispec of the first of the chain
-        """
-        return _spec(self.chain[0].ispec, "chainin")
-
-    def ospec(self):
-        """ returns the ospec of the last of the chain
-        """
-        return _spec(self.chain[-1].ospec, "chainout")
+        self.set_specs(self.chain[0], self.chain[-1])
 
     def _sa_setup(self, m, i):
         for (idx, c) in enumerate(self.chain):