Skip to content

Commit

Permalink
cellhelp: Add default format parse for simcells
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KrystalDelusion committed Apr 12, 2024
1 parent 6edbcf3 commit 3f1a914
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
12 changes: 8 additions & 4 deletions kernel/register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions techlibs/common/cellhelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ def __str__(self) -> str:
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():
Expand All @@ -62,7 +80,12 @@ def __str__(self) -> str:
# 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()
Expand Down

0 comments on commit 3f1a914

Please sign in to comment.