Skip to content

Commit d3c65a8

Browse files
Generate top json
1 parent b745e0a commit d3c65a8

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

hdl/projects/grapefruit/BUCK

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ rdl_file(
3232
"//hdl/ip/vhd/espi:espi_regs_pkg",
3333
],
3434
outputs = [
35-
"gfruit_top_map.html",
35+
"gfruit_top_map.html",
36+
"gfruit_top_map.json"
3637
]
3738
)
3839

tools/site_cobble/rdl_pkg/json_dump.py

+34
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
4545
MemNode,
4646
)
4747

48+
def convert_only_map_to_json(rdlc: RDLCompiler, obj: RootNode, path: Union[str, PathLike]):
49+
# Convert entire register model to primitive datatypes (a dict/list tree)
50+
json_obj = convert_addr_map_only(rdlc, obj.top)
51+
52+
# Write to a JSON file
53+
with open(path, "w") as f:
54+
json.dump(json_obj, f, indent=4)
4855

4956
def convert_to_json(rdlc: RDLCompiler, obj: RootNode, path: Union[str, PathLike]):
5057
# Convert entire register model to primitive datatypes (a dict/list tree)
@@ -114,6 +121,33 @@ def convert_mem(obj: MemNode) -> dict:
114121
return json_obj
115122

116123

124+
def convert_addr_map_only(
125+
rdlc: RDLCompiler, obj: Union[AddrmapNode, RegfileNode]
126+
) -> dict:
127+
if obj.is_array:
128+
rdlc.msg.fatal("JSON export does not support arrays", obj.inst.inst_src_ref)
129+
130+
json_obj = dict()
131+
if isinstance(obj, AddrmapNode):
132+
json_obj["type"] = "addrmap"
133+
elif isinstance(obj, RegfileNode):
134+
json_obj["type"] = "regfile"
135+
else:
136+
raise RuntimeError
137+
138+
json_obj["inst_name"] = obj.inst_name
139+
json_obj["addr_offset"] = obj.address_offset
140+
141+
json_obj["children"] = []
142+
for child in obj.children():
143+
if isinstance(child, AddrmapNode):
144+
json_child = convert_addr_map_only(rdlc, child)
145+
else:
146+
continue
147+
json_obj["children"].append(json_child)
148+
149+
return json_obj
150+
117151
def convert_addrmap_or_regfile(
118152
rdlc: RDLCompiler, obj: Union[AddrmapNode, RegfileNode]
119153
) -> dict:

tools/site_cobble/rdl_pkg/rdl_cli.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
except ModuleNotFoundError:
2222
from rdl_pkg.exporter import MapExporter, MapofMapsExporter
2323
from rdl_pkg.listeners import PreExportListener, MyModelPrintingListener
24-
from rdl_pkg.json_dump import convert_to_json
24+
from rdl_pkg.json_dump import convert_to_json, convert_only_map_to_json
2525

2626
parser = argparse.ArgumentParser()
2727
parser.add_argument(
@@ -64,6 +64,13 @@ def main():
6464
# Dump Jinja template-based outputs (filter out .json)
6565
exporter = MapofMapsExporter()
6666
exporter.export(pre_export.maps[0], output_filenames_no_json)
67+
json_files = [x for x in output_filenames if ".json" in str(x)]
68+
if len(json_files) == 1:
69+
json_name = Path(json_files[0])
70+
convert_only_map_to_json(rdlc, root, json_name)
71+
elif len(json_files) > 1:
72+
raise Exception(f'Specified too many .json outputs: {json_files.join(",")}')
73+
6774
else:
6875
# For each standard map, we're going to generate:
6976
# Standard bsv package from this base address

0 commit comments

Comments
 (0)