remove unneeded code
[ieee754fpu.git] / src / ieee754 / fpcommon / modbase.py
1 from nmigen import Elaboratable
2 from ieee754.pipeline import DynamicPipe
3 from nmutil.singlepipe import StageChain
4
5
6 class FPModBase(Elaboratable):
7 """FPModBase: common code between nearly every pipeline module
8 """
9 def __init__(self, pspec, modname):
10 self.modname = modname # use this to give a name to this module
11 self.pspec = pspec
12 self.i = self.ispec()
13 self.o = self.ospec()
14
15 def process(self, i):
16 return self.o
17
18 def setup(self, m, i):
19 """ links module to inputs and outputs
20 """
21 setattr(m.submodules, self.modname, self)
22 m.d.comb += self.i.eq(i)
23
24
25 class FPModBaseChain(DynamicPipe):
26 """FPModBaseChain: common code between stage-chained pipes
27
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
31 """
32 def __init__(self, pspec):
33 self.pspec = pspec
34 self.chain = self.get_chain()
35 super().__init__(pspec)
36
37 def ispec(self):
38 """ returns the input spec of the first module in the chain
39 """
40 return self.chain[0].ispec()
41
42 def ospec(self):
43 """ returns the output spec of the last module in the chain
44 """
45 return self.chain[-1].ospec()
46
47 def process(self, i):
48 return self.o # ... returned here (see setup comment below)
49
50 def setup(self, m, i):
51 """ links module to inputs and outputs
52 """
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...