Fix split-mems-confi.py

This commit is contained in:
joey0320
2022-12-31 20:52:17 -08:00
parent 4f2d791d3c
commit b4626e964e

View File

@@ -28,21 +28,21 @@ sys.setrecursionlimit(100)
# Performing DFS recursively is not a problem here since the modules that def bfs_find_root(tree, module_name):
# we are interested in are close to the root of the module hierarchy q = [tree]
def dfs_find_root(tree, module_name):
if tree['module_name'] == module_name: while len(q) != 0:
return tree front = q[0]
if len(tree['instances']) == 0: q.pop(0)
exit(0)
for c in tree['instances']: if front['module_name'] == module_name:
ret = dfs_find_root(c, module_name) return front
if ret is not None: for c in front['instances']:
return ret q.append(c)
return None return None
def bfs_collect_module(tree): def bfs_collect_submodules(tree):
output = set() output = set()
q = [(tree['instance_name'], tree['module_name'], tree['instances'])] q = [(tree['instance_name'], tree['module_name'], tree['instances'])]
@@ -71,11 +71,11 @@ if __name__ == "__main__":
open(args.in_model_hrchy_json) as imhj: open(args.in_model_hrchy_json) as imhj:
imhj_data = json.load(imhj) imhj_data = json.load(imhj)
dut_root = dfs_find_root(imhj_data, args.dut_module_name) dut_root = bfs_find_root(imhj_data, args.dut_module_name)
dut_submodules = bfs_collect_module(dut_root) dut_submodules = bfs_collect_submodules(dut_root)
model_root = dfs_find_root(imhj_data, args.model_module_name) model_root = bfs_find_root(imhj_data, args.model_module_name)
model_submodules = bfs_collect_module(model_root) model_submodules = bfs_collect_submodules(model_root)
with open(args.out_dut_smems_conf, "w") as odsc, \ with open(args.out_dut_smems_conf, "w") as odsc, \
open(args.out_model_smems_conf, "w") as otsc: open(args.out_model_smems_conf, "w") as otsc: