From: Luke Kenneth Casson Leighton Date: Mon, 29 Apr 2019 22:03:11 +0000 (+0100) Subject: derive StageChain from StageHelper, use set_specs instead of manual ispec/ospec X-Git-Tag: ls180-24jan2020~1109 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c0cf0a1485b502c7a32ed82186bb8b567de7f2e1;p=ieee754fpu.git derive StageChain from StageHelper, use set_specs instead of manual ispec/ospec function, add auto-detect to set_specs to determine if it is passed an object that has a "stage" --- diff --git a/src/add/singlepipe.py b/src/add/singlepipe.py index c9faa510..d917e4c4 100644 --- a/src/add/singlepipe.py +++ b/src/add/singlepipe.py @@ -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 diff --git a/src/add/stageapi.py b/src/add/stageapi.py index 259b9de9..eb90315c 100644 --- a/src/add/stageapi.py +++ b/src/add/stageapi.py @@ -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):