mirror of https://github.com/YosysHQ/yosys.git
Docs: Convert write_cell_rst to use SimHelper
This commit is contained in:
parent
4662476ec8
commit
1e5a50ff3a
|
@ -880,54 +880,39 @@ struct HelpPass : public Pass {
|
|||
}
|
||||
fclose(f);
|
||||
}
|
||||
void write_cell_rst(std::string cell, std::string help, std::string code)
|
||||
void write_cell_rst(Yosys::SimHelper cell)
|
||||
{
|
||||
// open
|
||||
string safe_name = cell.substr(1);
|
||||
FILE *f = fopen(stringf("docs/source/cell/%s.rst", safe_name.c_str()).c_str(), "wt");
|
||||
FILE *f = fopen(stringf("docs/source/cell/%s.rst", cell.filesafe_name().c_str()).c_str(), "wt");
|
||||
|
||||
// make header
|
||||
string short_help = "";
|
||||
string long_help = "";
|
||||
string title_line = cell;
|
||||
for (auto line : split_tokens(help, "\n")) {
|
||||
if (short_help == "") {
|
||||
size_t first_pos = line.find_first_not_of(" \t");
|
||||
// skip empty lines
|
||||
if (first_pos == string::npos) continue;
|
||||
if (line.find(cell.c_str()) == string::npos) {
|
||||
// strip leading/trailing space
|
||||
size_t last_pos = line.find_last_not_of(" \t");
|
||||
short_help = line.substr(first_pos, last_pos - first_pos +1);
|
||||
// skip missing help message
|
||||
if (short_help == "No help message for this cell type found.") {
|
||||
long_help += line;
|
||||
long_help += "\n";
|
||||
} else {
|
||||
title_line = stringf("%s - %s", cell.c_str(), short_help.c_str());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
long_help += line;
|
||||
long_help += "\n";
|
||||
}
|
||||
}
|
||||
string title_line;
|
||||
if (cell.short_desc.length())
|
||||
title_line = stringf("%s - %s", cell.name.c_str(), cell.short_desc.c_str());
|
||||
else title_line = cell.name;
|
||||
string underline = "\n";
|
||||
underline.insert(0, title_line.length(), '=');
|
||||
fprintf(f, "%s\n", title_line.c_str());
|
||||
fprintf(f, "%s\n", underline.c_str());
|
||||
|
||||
// help text
|
||||
fprintf(f, "%s\n", long_help.c_str());
|
||||
fprintf(f, "%s\n", cell.desc.c_str());
|
||||
|
||||
// source code
|
||||
fprintf(f, "Simulation model (Verilog)\n");
|
||||
fprintf(f, "--------------------------\n\n");
|
||||
fprintf(f, ".. code:: verilog\n\n");
|
||||
std::stringstream ss;
|
||||
ss << code;
|
||||
ss << cell.code;
|
||||
for (std::string line; std::getline(ss, line, '\n');) {
|
||||
fprintf(f, "\t%s\n", line.c_str());
|
||||
fprintf(f, " %s\n", line.c_str());
|
||||
}
|
||||
|
||||
// footer
|
||||
fprintf(f, "\n.. note::\n\n");
|
||||
fprintf(f, " This page was auto-generated from the output of\n");
|
||||
fprintf(f, " ``help %s``.\n", cell.name.c_str());
|
||||
|
||||
// close
|
||||
fclose(f);
|
||||
}
|
||||
|
@ -988,7 +973,7 @@ struct HelpPass : public Pass {
|
|||
}
|
||||
else if (args[1] == "-write-rst-cells-manual") {
|
||||
for (auto &it : cell_help_messages.cell_help) {
|
||||
write_cell_rst(it.first, it.second.desc, it.second.code);
|
||||
write_cell_rst(it.second);
|
||||
}
|
||||
}
|
||||
else if (pass_register.count(args[1])) {
|
||||
|
|
Loading…
Reference in New Issue