Skip to content

Commit

Permalink
Docs: Initial version of cell_ref autogen
Browse files Browse the repository at this point in the history
  • Loading branch information
KrystalDelusion committed Apr 9, 2024
1 parent eb6c939 commit 575daf1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/build/
/source/cmd
/source/cell
/source/temp
/source/_images/**/*.log
/source/_images/**/*.aux
Expand Down
1 change: 1 addition & 0 deletions docs/source/appendix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Appendix
:includehidden:

cmd_ref
cell_ref
12 changes: 12 additions & 0 deletions docs/source/cell_ref.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. _cell_ref:

================================================================================
Internal cell reference
================================================================================

.. toctree::
:caption: Internal cell reference
:maxdepth: 1
:glob:

/cell/*
60 changes: 58 additions & 2 deletions kernel/register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ struct HelpPass : public Pass {
log(" help <celltype>+ .... print verilog code for given cell type\n");
log("\n");
}
void write_rst(std::string cmd, std::string title, std::string text)
void write_cmd_rst(std::string cmd, std::string title, std::string text)
{
FILE *f = fopen(stringf("docs/source/cmd/%s.rst", cmd.c_str()).c_str(), "wt");
// make header
Expand Down Expand Up @@ -864,6 +864,57 @@ struct HelpPass : public Pass {
}
fclose(f);
}
void write_cell_rst(std::string cell, std::string help, std::string code)
{
// open
string safe_name = cell.substr(1);
FILE *f = fopen(stringf("docs/source/cell/%s.rst", safe_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 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());

// source code
fprintf(f, ".. code:: verilog\n\n");
std::stringstream ss;
ss << code;
for (std::string line; std::getline(ss, line, '\n');) {
fprintf(f, "\t%s\n", line.c_str());
}

// close
fclose(f);
}
void execute(std::vector<std::string> args, RTLIL::Design*) override
{
if (args.size() == 1) {
Expand Down Expand Up @@ -917,7 +968,12 @@ struct HelpPass : public Pass {
log("\n");
}
log_streams.pop_back();
write_rst(it.first, it.second->short_help, buf.str());
write_cmd_rst(it.first, it.second->short_help, buf.str());
}
}
else if (args[1] == "-write-rst-cells-manual") {
for (auto &it : cell_help_messages.cell_help) {
write_cell_rst(it.first, it.second, cell_help_messages.cell_code.at(it.first + "+"));
}
}
else if (pass_register.count(args[1])) {
Expand Down

0 comments on commit 575daf1

Please sign in to comment.