2015-10-14 09:27:42 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2024-04-08 22:33:50 -05:00
|
|
|
from __future__ import annotations
|
2015-10-14 09:27:42 -05:00
|
|
|
import fileinput
|
|
|
|
import json
|
|
|
|
|
2024-04-08 22:33:50 -05:00
|
|
|
class SimHelper:
|
|
|
|
name: str = ""
|
2024-04-10 18:15:24 -05:00
|
|
|
title: str = ""
|
2024-04-08 22:33:50 -05:00
|
|
|
ports: str = ""
|
|
|
|
desc: list[str]
|
|
|
|
code: list[str]
|
|
|
|
ver: str = "1"
|
2015-10-14 09:27:42 -05:00
|
|
|
|
2024-04-08 22:33:50 -05:00
|
|
|
def __init__(self) -> None:
|
|
|
|
self.desc = []
|
|
|
|
|
|
|
|
def __str__(self) -> str:
|
|
|
|
val = "tempCell = {\n"
|
|
|
|
val += f' {json.dumps(self.name)},\n'
|
2024-04-10 18:15:24 -05:00
|
|
|
val += f' {json.dumps(self.title)},\n'
|
2024-04-08 22:33:50 -05:00
|
|
|
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'
|
|
|
|
val += "};\n"
|
|
|
|
val += f'cell_help[{json.dumps(self.name)}] = tempCell;'
|
|
|
|
val += "\n"
|
|
|
|
val += f'cell_code[{json.dumps(self.name + "+")}] = tempCell;'
|
|
|
|
return val
|
|
|
|
|
|
|
|
simHelper = SimHelper()
|
2015-10-14 09:27:42 -05:00
|
|
|
|
|
|
|
for line in fileinput.input():
|
2024-04-08 22:33:50 -05:00
|
|
|
line = line.rstrip()
|
|
|
|
# special comments
|
2015-10-14 09:27:42 -05:00
|
|
|
if line.startswith("//-"):
|
2024-04-08 22:33:50 -05:00
|
|
|
simHelper.desc.append(line[4:] if len(line) > 4 else "")
|
|
|
|
elif line.startswith("//* "):
|
|
|
|
_, key, val = line.split(maxsplit=2)
|
|
|
|
setattr(simHelper, key, val)
|
|
|
|
|
|
|
|
# code parsing
|
2015-10-14 09:27:42 -05:00
|
|
|
if line.startswith("module "):
|
2024-04-08 22:33:50 -05:00
|
|
|
clean_line = line[7:].replace("\\", "").replace(";", "")
|
|
|
|
simHelper.name, simHelper.ports = clean_line.split(maxsplit=1)
|
|
|
|
simHelper.code = []
|
2015-10-16 19:22:42 -05:00
|
|
|
elif not line.startswith("endmodule"):
|
|
|
|
line = " " + line
|
2024-04-08 22:33:50 -05:00
|
|
|
try:
|
|
|
|
simHelper.code.append(line.replace("\t", " "))
|
|
|
|
except AttributeError:
|
|
|
|
# no module definition, ignore line
|
|
|
|
pass
|
2015-10-14 09:27:42 -05:00
|
|
|
if line.startswith("endmodule"):
|
2024-04-08 23:12:41 -05:00
|
|
|
if not simHelper.desc:
|
|
|
|
simHelper.desc.append("No help message for this cell type found.\n")
|
2024-04-08 22:33:50 -05:00
|
|
|
print(simHelper)
|
|
|
|
simHelper = SimHelper()
|
2015-10-14 09:27:42 -05:00
|
|
|
|