remove unused import
[nmutil.git] / src / nmutil / pipemodbase.py
1 """
2 This work is funded through NLnet under Grant 2019-02-012
3
4 License: LGPLv3+
5
6 Associated bugreports:
7 * https://bugs.libre-soc.org/show_bug.cgi?id=538
8
9 """
10
11 from nmigen import Elaboratable
12 from ieee754.pipeline import DynamicPipe
13 from nmutil.singlepipe import StageChain
14
15
16 class PipeModBase(Elaboratable):
17 """PipeModBase: common code between nearly every pipeline module
18 """
19 def __init__(self, pspec, modname):
20 self.modname = modname # use this to give a name to this module
21 self.pspec = pspec
22 self.i = self.ispec()
23 self.o = self.ospec()
24
25 def process(self, i):
26 return self.o
27
28 def setup(self, m, i):
29 """ links module to inputs and outputs
30 """
31 setattr(m.submodules, self.modname, self)
32 m.d.comb += self.i.eq(i)
33
34
35 class PipeModBaseChain(DynamicPipe):
36 """PipeModBaseChain: common code between stage-chained pipes
37
38 Links a set of combinatorial modules (get_chain) together
39 and uses pspec.pipekls to dynamically select the pipeline type
40 Also conforms to the Pipeline Stage API
41 """
42 def __init__(self, pspec):
43 self.pspec = pspec
44 self.chain = self.get_chain()
45 super().__init__(pspec)
46
47 def ispec(self):
48 """ returns the input spec of the first module in the chain
49 """
50 return self.chain[0].ispec()
51
52 def ospec(self):
53 """ returns the output spec of the last module in the chain
54 """
55 return self.chain[-1].ospec()
56
57 def process(self, i):
58 return self.o # ... returned here (see setup comment below)
59
60 def setup(self, m, i):
61 """ links module to inputs and outputs
62 """
63 StageChain(self.chain).setup(m, i) # input linked here, through chain
64 self.o = self.chain[-1].o # output is the last thing in the chain...