Skip to content

Commit

Permalink
cellhelp: Add source line to help
Browse files Browse the repository at this point in the history
Include Source file and line number in SimHelper struct, and use it for verilog code caption in rst dump.
Also reformat python string conversion to iterate over a list of fields instead of repeating code for each.
  • Loading branch information
KrystalDelusion committed Apr 12, 2024
1 parent 4ddfa90 commit 6edbcf3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion kernel/register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ struct SimHelper {
}
string title;
string ports;
string source;
string desc;
string code;
string ver;
Expand Down Expand Up @@ -901,7 +902,8 @@ struct HelpPass : public Pass {
// source code
fprintf(f, "Simulation model (Verilog)\n");
fprintf(f, "--------------------------\n\n");
fprintf(f, ".. code:: verilog\n\n");
fprintf(f, ".. code-block:: verilog\n");
fprintf(f, " :caption: %s\n\n", cell.source.c_str());
std::stringstream ss;
ss << cell.code;
for (std::string line; std::getline(ss, line, '\n');) {
Expand Down
21 changes: 15 additions & 6 deletions techlibs/common/cellhelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from __future__ import annotations
import fileinput
import json
from pathlib import Path

class SimHelper:
name: str = ""
title: str = ""
ports: str = ""
source: str = ""
desc: list[str]
code: list[str]
ver: str = "1"
Expand All @@ -16,14 +18,19 @@ def __init__(self) -> None:
self.desc = []

def __str__(self) -> str:
printed_fields = [
"name", "title", "ports", "source", "desc", "code", "ver",
]
# generate C++ struct
val = "tempCell = {\n"
val += f' {json.dumps(self.name)},\n'
val += f' {json.dumps(self.title)},\n'
val += f' {json.dumps(self.ports)},\n'
val += ' ' + json.dumps("\n".join(self.desc)) + ',\n'
val += ' ' + json.dumps("\n".join(self.code)) + ',\n'
val += f' {json.dumps(self.ver)},\n'
for field in printed_fields:
field_val = getattr(self, field)
if isinstance(field_val, list):
field_val = "\n".join(field_val)
val += f' {json.dumps(field_val)},\n'
val += "};\n"

# map name to struct
val += f'cell_help[{json.dumps(self.name)}] = tempCell;'
val += "\n"
val += f'cell_code[{json.dumps(self.name + "+")}] = tempCell;'
Expand All @@ -45,6 +52,8 @@ def __str__(self) -> str:
clean_line = line[7:].replace("\\", "").replace(";", "")
simHelper.name, simHelper.ports = clean_line.split(maxsplit=1)
simHelper.code = []
short_filename = Path(fileinput.filename()).name
simHelper.source = f'{short_filename}:{fileinput.filelineno()}'
elif not line.startswith("endmodule"):
line = " " + line
try:
Expand Down

0 comments on commit 6edbcf3

Please sign in to comment.