3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-23 09:05:32 +00:00

cellref: Add json dump

New `help -dump-cells-json <file>` to dump cells list.
Add 'group' field to SimHelper class/struct with defaults to gate_other and word_other depending on source (simcells or simlib).
Add 'unary' group to unary operator cells for testing (based on internal cell library docs page).
This commit is contained in:
Krystine Sherwin 2024-05-21 12:16:32 +12:00
parent 7eb33f1933
commit 7c5b10fe50
No known key found for this signature in database
3 changed files with 113 additions and 7 deletions

View file

@ -19,6 +19,7 @@
#include "kernel/yosys.h"
#include "kernel/satgen.h"
#include "kernel/json.h"
#include <string.h>
#include <stdlib.h>
@ -763,6 +764,7 @@ struct SimHelper {
string source;
string desc;
string code;
string group;
string ver;
};
@ -950,6 +952,77 @@ struct HelpPass : public Pass {
// close
fclose(f);
}
bool dump_cells_json(PrettyJson &json) {
// init json
json.begin_object();
json.entry("version", "Yosys internal cells");
json.entry("generator", yosys_version_str);
dict<string, dict<string, pair<SimHelper, CellType>>> groups;
// iterate over cells
bool raise_error = false;
for (auto &it : yosys_celltypes.cell_types) {
auto name = it.first.str();
if (cell_help_messages.contains(name)) {
auto cell_help = cell_help_messages.get(name);
dict<string, pair<SimHelper, CellType>> *cell_group;
if (groups.count(cell_help.group) != 0) {
cell_group = &groups.at(cell_help.group);
} else {
cell_group = new dict<string, pair<SimHelper, CellType>>();
groups.emplace(cell_help.group, *cell_group);
}
auto cell_pair = pair<SimHelper, CellType>(cell_help, it.second);
cell_group->emplace(name, cell_pair);
} else {
log("ERROR: Missing cell help for cell '%s'.\n", name.c_str());
raise_error |= true;
}
}
// write to json
json.name("groups");
json.begin_array();
groups.sort();
for (auto &it : groups) {
json.begin_object();
json.name("group"); json.value(it.first.c_str());
json.name("cells"); json.begin_array();
for (auto &it2 : it.second) {
auto ch = it2.second.first;
auto ct = it2.second.second;
json.begin_object();
json.name("cell"); json.value(ch.name);
json.name("title"); json.value(ch.title);
json.name("ports"); json.value(ch.ports);
json.name("source"); json.value(ch.source);
json.name("desc"); json.value(ch.desc);
json.name("code"); json.value(ch.code);
json.name("inputs"); json.begin_array();
for (auto &input : ct.inputs)
json.value(input.c_str());
json.end_array();
json.name("outputs"); json.begin_array();
for (auto &output : ct.outputs)
json.value(output.c_str());
json.end_array();
dict<string, bool> prop_dict = {
{"is_evaluable", ct.is_evaluable},
{"is_combinatorial", ct.is_combinatorial},
{"is_synthesizable", ct.is_synthesizable},
};
json.name("properties"); json.value(prop_dict);
json.end_object();
}
json.end_array();
json.end_object();
}
json.end_array();
json.end_object();
return raise_error;
}
void execute(std::vector<std::string> args, RTLIL::Design*) override
{
if (args.size() == 1) {
@ -1053,6 +1126,16 @@ struct HelpPass : public Pass {
else
log("No such command or cell type: %s\n", args[1].c_str());
return;
} else if (args.size() == 3) {
if (args[1] == "-dump-cells-json") {
PrettyJson json;
if (!json.write_to_file(args[2]))
log_error("Can't open file `%s' for writing: %s\n", args[2].c_str(), strerror(errno));
if (dump_cells_json(json)) {
log_error("One or more cells defined in celltypes.h are missing help documentation.\n");
}
}
return;
}
help();