29 #define STAT_INT_MEMBERS X(num_wires) X(num_wire_bits) X(num_pub_wires) X(num_pub_wire_bits) \
30 X(num_memories) X(num_memory_bits) X(num_cells) X(num_processes)
32 #define X(_name) int _name;
41 #define X(_name) sum._name += _name;
52 #define X(_name) sum._name *= other;
62 #define X(_name) _name = 0;
69 #define X(_name) _name = 0;
73 for (
auto &it : mod->
wires_)
75 if (!design->
selected(mod, it.second))
78 if (it.first[0] ==
'\\') {
80 num_pub_wire_bits += it.second->width;
84 num_wire_bits += it.second->width;
88 if (!design->
selected(mod, it.second))
91 num_memory_bits += it.second->width * it.second->size;
94 for (
auto &it : mod->
cells_)
96 if (!design->
selected(mod, it.second))
103 if (cell_type.
in(
"$not",
"$pos",
"$neg",
104 "$logic_not",
"$logic_and",
"$logic_or",
105 "$reduce_and",
"$reduce_or",
"$reduce_xor",
"$reduce_xnor",
"$reduce_bool",
106 "$lut",
"$and",
"$or",
"$xor",
"$xnor",
107 "$shl",
"$shr",
"$sshl",
"$sshr",
"$shift",
"$shiftx",
108 "$lt",
"$le",
"$eq",
"$ne",
"$eqx",
"$nex",
"$ge",
"$gt",
109 "$add",
"$sub",
"$mul",
"$div",
"$mod",
"$pow")) {
110 int width_a = it.second->hasPort(
"\\A") ?
GetSize(it.second->getPort(
"\\A")) : 0;
111 int width_b = it.second->hasPort(
"\\B") ?
GetSize(it.second->getPort(
"\\B")) : 0;
112 int width_y = it.second->hasPort(
"\\Y") ?
GetSize(it.second->getPort(
"\\Y")) : 0;
113 cell_type =
stringf(
"%s_%d", cell_type.c_str(), std::max<int>({width_a, width_b, width_y}));
115 else if (cell_type.
in(
"$mux",
"$pmux"))
117 else if (cell_type.
in(
"$sr",
"$dff",
"$dffsr",
"$adff",
"$dlatch",
"$dlatchsr"))
126 if (!design->
selected(mod, it.second))
134 log(
" Number of wires: %6d\n", num_wires);
135 log(
" Number of wire bits: %6d\n", num_wire_bits);
136 log(
" Number of public wires: %6d\n", num_pub_wires);
137 log(
" Number of public wire bits: %6d\n", num_pub_wire_bits);
138 log(
" Number of memories: %6d\n", num_memories);
139 log(
" Number of memory bits: %6d\n", num_memory_bits);
140 log(
" Number of processes: %6d\n", num_processes);
141 log(
" Number of cells: %6d\n", num_cells);
150 std::map<RTLIL::IdString, int, RTLIL::sort_by_id_str> num_cells_by_type;
153 for (
auto &it : num_cells_by_type)
154 if (mod_stat.count(it.first) > 0) {
155 log(
" %*s%-*s %6d\n", 2*level,
"", 26-2*level,
RTLIL::id2cstr(it.first), it.second);
156 mod_data = mod_data +
hierarchy_worker(mod_stat, it.first, level+1) * it.second;
157 mod_data.num_cells -= it.second;
171 log(
" stat [options] [selection]\n");
173 log(
"Print some statistics (number of objects) on the selected portion of the\n");
176 log(
" -top <module>\n");
177 log(
" print design hierarchy with this module as top. if the design is fully\n");
178 log(
" selected and a module has the 'top' attribute set, this module is used\n");
179 log(
" default value for this option.\n");
182 log(
" annotate internal cell types with their word width.\n");
183 log(
" e.g. $add_8 for an 8 bit wide $add cell.\n");
190 bool width_mode =
false;
192 std::map<RTLIL::IdString, statdata_t> mod_stat;
195 for (argidx = 1; argidx < args.size(); argidx++)
197 if (args[argidx] ==
"-width") {
201 if (args[argidx] ==
"-top" && argidx+1 < args.size()) {
203 log_cmd_error(
"Can't find module %s.\n", args[argidx+1].c_str());
217 if (it.second->get_bool_attribute(
"\\top"))
220 statdata_t data(design, it.second, width_mode);
221 mod_stat[it.first] = data;
232 log(
"=== design hierarchy ===\n");
const char * c_str() const
bool selected(T1 *module) const
std::string stringf(const char *fmt,...)
bool selected_module(RTLIL::IdString mod_name) const
void log_header(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
std::map< RTLIL::IdString, RTLIL::Memory * > memories
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
bool in(T first, Args...rest)
static std::string escape_id(std::string str)
bool full_selection() const
#define PRIVATE_NAMESPACE_BEGIN
int GetSize(RTLIL::Wire *wire)
bool selected_whole_module(RTLIL::IdString mod_name) const
statdata_t(RTLIL::Design *design, RTLIL::Module *mod, bool width_mode)
statdata_t hierarchy_worker(std::map< RTLIL::IdString, statdata_t > &mod_stat, RTLIL::IdString mod, int level)
#define PRIVATE_NAMESPACE_END
STAT_INT_MEMBERS std::map< RTLIL::IdString, int, RTLIL::sort_by_id_str > num_cells_by_type
static const char * id2cstr(const RTLIL::IdString &str)
void log_cmd_error(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Process * > processes
#define USING_YOSYS_NAMESPACE
std::map< RTLIL::IdString, RTLIL::Module * > modules_
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
void log(const char *format,...)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
statdata_t operator*(int other) const
statdata_t operator+(const statdata_t &other) const