0c30c8147e984294f3aaade766fb87f9d867ed31
[litex.git] / litex / gen / examples / basic / namer.py
1 from migen import *
2 from migen.fhdl import verilog
3
4 from functools import reduce
5 from operator import or_
6
7
8 def gen_list(n):
9 s = [Signal() for i in range(n)]
10 return s
11
12
13 def gen_2list(n):
14 s = [Signal(2) for i in range(n)]
15 return s
16
17
18 class Foo:
19 def __init__(self):
20 la = gen_list(3)
21 lb = gen_2list(2)
22 self.sigs = la + lb
23
24
25 class Bar:
26 def __init__(self):
27 self.sigs = gen_list(2)
28
29
30 class Example(Module):
31 def __init__(self):
32 a = [Bar() for x in range(3)]
33 b = [Foo() for x in range(3)]
34 c = b
35 b = [Bar() for x in range(2)]
36
37 output = Signal()
38 allsigs = []
39 for lst in [a, b, c]:
40 for obj in lst:
41 allsigs.extend(obj.sigs)
42 self.comb += output.eq(reduce(or_, allsigs))
43
44 print(verilog.convert(Example()))