From 57cd8d29db5e0fb32aaa7b813617b91c5ab31792 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:48:47 +1200 Subject: [PATCH] cellhelp: Add default format parse for simcells Since `simcells.v` uses consistent formatting we can handle it specifically to help tidy up sphinx warnings about the truth tables, and instead chuck them in a code block which when printing to rst. Also has the side effect that rst code blocks can be added manually with `//- ::` followed by a blank line. --- kernel/register.cc | 12 ++++++++---- techlibs/common/cellhelp.py | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/kernel/register.cc b/kernel/register.cc index 99225ba51..383450525 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -988,10 +988,14 @@ struct HelpPass : public Pass { } else if (cell_help_messages.cell_help.count(args[1])) { SimHelper help_cell = cell_help_messages.cell_help.at(args[1]); - if (help_cell.ver == "2") { - log("\n %s %s\n", help_cell.name.c_str(), help_cell.ports.c_str()); - log("\n%s\n", help_cell.title.c_str()); - log("%s\n", help_cell.desc.c_str()); + if (help_cell.ver == "2" || help_cell.ver == "2a") { + log("\n %s %s\n\n", help_cell.name.c_str(), help_cell.ports.c_str()); + if (help_cell.title != "") log("%s\n", help_cell.title.c_str()); + std::stringstream ss; + ss << help_cell.desc; + for (std::string line; std::getline(ss, line, '\n');) { + if (line != "::") log("%s\n", line.c_str()); + } log("Run 'help %s+' to display the Verilog model for this cell type.\n", args[1].c_str()); log("\n"); } else { diff --git a/techlibs/common/cellhelp.py b/techlibs/common/cellhelp.py index 1d55d17f5..a975c31e5 100644 --- a/techlibs/common/cellhelp.py +++ b/techlibs/common/cellhelp.py @@ -36,6 +36,24 @@ class SimHelper: val += f'cell_code[{json.dumps(self.name + "+")}] = tempCell;' return val +def simcells_reparse(cell: SimHelper): + # cut manual signature + cell.desc = cell.desc[3:] + + # code-block truth table + new_desc = [] + indent = "" + for line in cell.desc: + if line.startswith("Truth table:"): + indent = " " + new_desc.pop() + new_desc.extend(["::", ""]) + new_desc.append(indent + line) + cell.desc = new_desc + + # set version + cell.ver = "2a" + simHelper = SimHelper() for line in fileinput.input(): @@ -62,7 +80,12 @@ for line in fileinput.input(): # no module definition, ignore line pass if line.startswith("endmodule"): + short_filename = Path(fileinput.filename()).name + if simHelper.ver == "1" and short_filename == "simcells.v": + # default simcells parsing + simcells_reparse(simHelper) if not simHelper.desc: + # no help simHelper.desc.append("No help message for this cell type found.\n") print(simHelper) simHelper = SimHelper()