File size: 1,167 Bytes
ce57c19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from pyosys import libyosys as ys

# loading design
design = ys.Design()

ys.run_pass("read_verilog tests/simple/fiedler-cooley.v", design)
ys.run_pass("hierarchy -check -auto-top", design)

# top module inspection
top_module = design.top_module()

for id, wire in top_module.wires_.items():
	if not wire.port_input and not wire.port_output:
		continue
	description = "input" if wire.port_input else "output"
	description += " " + wire.name.str()
	if wire.width != 1:
		frm = wire.start_offset
		to = wire.start_offset + wire.width
		if wire.upto:
			to, frm = frm, to
		description += f" [{to}:{frm}]"
	print(description)

# synth

ys.run_pass("synth", design)

# adding the enable line

enable_line = top_module.addWire("\\enable")
enable_line.port_input = True
top_module.fixup_ports()

# hooking the enable line to the internal dff cells

for cell in top_module.cells_.values():
	if cell.type != "$_DFF_P_":
		continue
	cell.type = "$_DFFE_PP_"
	cell.setPort("\\E", ys.SigSpec(enable_line))

# run check

top_module.check()
ys.run_pass("stat", design)

# write outputs

ys.run_pass("write_verilog out.v", design)
ys.run_pass("synth_ice40 -json out.json", design)