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