call nmoperator.cat/eq/shape instead of as global functions
[ieee754fpu.git] / src / add / example_buf_pipe.py
1 """ Pipeline and BufferedHandshake examples
2 """
3
4 from nmoperator import eq
5 from singlepipe import (PrevControl, NextControl, ControlBase,
6 StageCls, Stage, StageChain,
7 BufferedHandshake, UnbufferedPipeline)
8
9 from nmigen import Signal, Module
10 from nmigen.cli import verilog, rtlil
11
12
13 class ExampleAddStage(StageCls):
14 """ an example of how to use the buffered pipeline, as a class instance
15 """
16
17 def ispec(self):
18 """ returns a tuple of input signals which will be the incoming data
19 """
20 return (Signal(16), Signal(16))
21
22 def ospec(self):
23 """ returns an output signal which will happen to contain the sum
24 of the two inputs
25 """
26 return Signal(16)
27
28 def process(self, i):
29 """ process the input data (sums the values in the tuple) and returns it
30 """
31 return i[0] + i[1]
32
33
34 class ExampleBufPipeAdd(BufferedHandshake):
35 """ an example of how to use the buffered pipeline, using a class instance
36 """
37
38 def __init__(self):
39 addstage = ExampleAddStage()
40 BufferedHandshake.__init__(self, addstage)
41
42
43 class ExampleStage(Stage):
44 """ an example of how to use the buffered pipeline, in a static class
45 fashion
46 """
47
48 def ispec():
49 return Signal(16, name="example_input_signal")
50
51 def ospec():
52 return Signal(16, name="example_output_signal")
53
54 def process(i):
55 """ process the input data and returns it (adds 1)
56 """
57 return i + 1
58
59
60 class ExampleStageCls(StageCls):
61 """ an example of how to use the buffered pipeline, in a static class
62 fashion
63 """
64
65 def ispec(self):
66 return Signal(16, name="example_input_signal")
67
68 def ospec(self):
69 return Signal(16, name="example_output_signal")
70
71 def process(self, i):
72 """ process the input data and returns it (adds 1)
73 """
74 return i + 1
75
76
77 class ExampleBufPipe(BufferedHandshake):
78 """ an example of how to use the buffered pipeline.
79 """
80
81 def __init__(self):
82 BufferedHandshake.__init__(self, ExampleStage)
83
84
85 class ExamplePipeline(UnbufferedPipeline):
86 """ an example of how to use the unbuffered pipeline.
87 """
88
89 def __init__(self):
90 UnbufferedPipeline.__init__(self, ExampleStage)
91
92
93 if __name__ == '__main__':
94 dut = ExampleBufPipe()
95 vl = rtlil.convert(dut, ports=dut.ports())
96 with open("test_bufpipe.il", "w") as f:
97 f.write(vl)
98
99 dut = ExamplePipeline()
100 vl = rtlil.convert(dut, ports=dut.ports())
101 with open("test_combpipe.il", "w") as f:
102 f.write(vl)