1 from nmigen
import Elaboratable
2 from ieee754
.pipeline
import DynamicPipe
3 from nmutil
.singlepipe
import StageChain
6 class PipeModBase(Elaboratable
):
7 """PipeModBase: common code between nearly every pipeline module
9 def __init__(self
, pspec
, modname
):
10 self
.modname
= modname
# use this to give a name to this module
18 def setup(self
, m
, i
):
19 """ links module to inputs and outputs
21 setattr(m
.submodules
, self
.modname
, self
)
22 m
.d
.comb
+= self
.i
.eq(i
)
25 class PipeModBaseChain(DynamicPipe
):
26 """PipeModBaseChain: common code between stage-chained pipes
28 Links a set of combinatorial modules (get_chain) together
29 and uses pspec.pipekls to dynamically select the pipeline type
30 Also conforms to the Pipeline Stage API
32 def __init__(self
, pspec
):
34 self
.chain
= self
.get_chain()
35 super().__init
__(pspec
)
38 """ returns the input spec of the first module in the chain
40 return self
.chain
[0].ispec()
43 """ returns the output spec of the last module in the chain
45 return self
.chain
[-1].ospec()
48 return self
.o
# ... returned here (see setup comment below)
50 def setup(self
, m
, i
):
51 """ links module to inputs and outputs
53 StageChain(self
.chain
).setup(m
, i
) # input linked here, through chain
54 self
.o
= self
.chain
[-1].o
# output is the last thing in the chain...