Merge remote-tracking branch 'origin/master' into xaig
[yosys.git] / examples / python-api / pass.py
1 #!/usr/bin/python3
2
3 from pyosys import libyosys as ys
4
5 import matplotlib.pyplot as plt
6 import numpy as np
7
8 class CellStatsPass(ys.Pass):
9
10 def __init__(self):
11 super().__init__("cell_stats", "Shows cell stats as plot")
12
13 def py_help(self):
14 ys.log("This pass uses the matplotlib library to display cell stats\n")
15
16 def py_execute(self, args, design):
17 ys.log_header(design, "Plotting cell stats\n")
18 cell_stats = {}
19 for module in design.selected_whole_modules_warn():
20 for cell in module.selected_cells():
21 if cell.type.str() in cell_stats:
22 cell_stats[cell.type.str()] += 1
23 else:
24 cell_stats[cell.type.str()] = 1
25 plt.bar(range(len(cell_stats)), height = list(cell_stats.values()),align='center')
26 plt.xticks(range(len(cell_stats)), list(cell_stats.keys()))
27 plt.show()
28
29 def py_clear_flags(self):
30 ys.log("Clear Flags - CellStatsPass\n")
31
32 p = CellStatsPass()