script to unqify modules
This commit is contained in:
@@ -243,6 +243,12 @@ $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(ALL_MODS_FILELIST) $(BB_MODS_FILEL
|
|||||||
$(SED) -i 's/\.\///' $(TOP_MODS_FILELIST)
|
$(SED) -i 's/\.\///' $(TOP_MODS_FILELIST)
|
||||||
$(SED) -i 's/\.\///' $(MODEL_MODS_FILELIST)
|
$(SED) -i 's/\.\///' $(MODEL_MODS_FILELIST)
|
||||||
$(SED) -i 's/\.\///' $(BB_MODS_FILELIST)
|
$(SED) -i 's/\.\///' $(BB_MODS_FILELIST)
|
||||||
|
$(base_dir)/scripts/uniqify-module-names.py \
|
||||||
|
--top-filelist $(TOP_MODS_FILELIST) \
|
||||||
|
--mod-filelist $(MODEL_MODS_FILELIST) \
|
||||||
|
--gen-collateral-path $(GEN_COLLATERAL_DIR) \
|
||||||
|
--model-hier-json $(MFC_MODEL_HRCHY_JSON) \
|
||||||
|
--dut $(TOP)
|
||||||
sort -u $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(BB_MODS_FILELIST) > $(ALL_MODS_FILELIST)
|
sort -u $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(BB_MODS_FILELIST) > $(ALL_MODS_FILELIST)
|
||||||
|
|
||||||
$(TOP_BB_MODS_FILELIST) $(MODEL_BB_MODS_FILELIST) &: $(BB_MODS_FILELIST) $(MFC_TOP_HRCHY_JSON) $(FINAL_ANNO_FILE)
|
$(TOP_BB_MODS_FILELIST) $(MODEL_BB_MODS_FILELIST) &: $(BB_MODS_FILELIST) $(MFC_TOP_HRCHY_JSON) $(FINAL_ANNO_FILE)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ parser.add_argument("--mod-filelist", type=str, required=True, help="Abs path to
|
|||||||
parser.add_argument("--gen-collateral-path", dest="gcpath", type=str, required=True, help="Abs path to the gen-collateral directory")
|
parser.add_argument("--gen-collateral-path", dest="gcpath", type=str, required=True, help="Abs path to the gen-collateral directory")
|
||||||
parser.add_argument("--model-hier-json", type=str, required=True, help="Path to hierarchy JSON emitted by firtool. Must include DUT as a module.")
|
parser.add_argument("--model-hier-json", type=str, required=True, help="Path to hierarchy JSON emitted by firtool. Must include DUT as a module.")
|
||||||
parser.add_argument('--dut', type=str, required=True, help='Name of the DUT module.')
|
parser.add_argument('--dut', type=str, required=True, help='Name of the DUT module.')
|
||||||
parser.add_argument('--model', type=str, required=True, help='Name of the MODEL module.')
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@@ -33,6 +32,9 @@ def get_filelist(filelist):
|
|||||||
|
|
||||||
return fnames
|
return fnames
|
||||||
|
|
||||||
|
def update_filelist(cur_file, new_file):
|
||||||
|
sh.sed("-i", f"s/\b{cur_file}\b/{new_file}/", os.path.join(args.gcpath, args.mod_filelist))
|
||||||
|
|
||||||
|
|
||||||
def generate_copy(c, sfx):
|
def generate_copy(c, sfx):
|
||||||
(cur_name, ext) = os.path.splitext(c)
|
(cur_name, ext) = os.path.splitext(c)
|
||||||
@@ -43,43 +45,45 @@ def generate_copy(c, sfx):
|
|||||||
new_file = os.path.join(args.gcpath, new_file)
|
new_file = os.path.join(args.gcpath, new_file)
|
||||||
|
|
||||||
shutil.copy(cur_file, new_file)
|
shutil.copy(cur_file, new_file)
|
||||||
sh.sed("-i", f"s/{cur_name}/{new_name}/", new_file)
|
sh.sed("-i", f"s/\b{cur_name}\b/{new_name}/", new_file)
|
||||||
|
|
||||||
return new_file
|
return new_file
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def dfs_update_modules(tree, common_fnames, visited):
|
def dfs_update_modules(tree, common_fnames, visited, top_fnames, updated_modules):
|
||||||
# List of direct submodules to update
|
# List of direct submodules to update
|
||||||
childs_to_update = list()
|
childs_to_update = list()
|
||||||
for child in tree['instances']:
|
for child in tree['instances']:
|
||||||
|
# We don't have to change stuff that are under the dut
|
||||||
if (child['module_name'] == args.dut) or (child['module_name'] in visited):
|
if (child['module_name'] == args.dut) or (child['module_name'] in visited):
|
||||||
continue
|
continue
|
||||||
if dfs_update_modules(child, common_fnames, visited):
|
if dfs_update_modules(child, common_fnames, visited, top_fnames, updated_modules):
|
||||||
childs_to_update.append(child['module_name'])
|
childs_to_update.append(child['module_name'])
|
||||||
|
if (child['module_name'] + ".sv") in common_fnames:
|
||||||
|
child['module_name'] = child['module_name'] + "_Model"
|
||||||
|
updated_modules.append(child['module_name'])
|
||||||
|
|
||||||
cur_module = tree['module_name']
|
cur_module = tree['module_name']
|
||||||
cur_file = cur_module + ".sv"
|
cur_file = cur_module + ".sv"
|
||||||
new_file = None
|
new_file = None
|
||||||
|
|
||||||
# cur_file is in the common list, generate a new file
|
# cur_file is in the common list, generate a new file
|
||||||
for c in common_fnames:
|
if cur_file in common_fnames:
|
||||||
if cur_file == c:
|
new_file = generate_copy(cur_file, "Model")
|
||||||
new_file = generate_copy(c, "Model")
|
update_filelist(cur_file, os.path.basename(new_file))
|
||||||
|
|
||||||
# has some child to update, but new_file wasn't generated
|
# has some child to update, but new_file wasn't generated
|
||||||
if (new_file is None) and len(childs_to_update) > 0:
|
if (new_file is None) and len(childs_to_update) > 0:
|
||||||
if cur_module == args.model:
|
new_file = os.path.join(args.gcpath, cur_file)
|
||||||
new_file = os.path.join(args.gcpath, cur_file)
|
assert(cur_file not in top_fnames)
|
||||||
else:
|
|
||||||
new_file = generate_copy(cur_file, "Model")
|
|
||||||
|
|
||||||
if new_file is not None:
|
if new_file is not None:
|
||||||
print(f"-- {cur_module}")
|
print(f"-- {cur_module}")
|
||||||
|
|
||||||
for submodule_name in childs_to_update:
|
for submodule_name in childs_to_update:
|
||||||
print(f"|- {submodule_name}")
|
print(f"|- {submodule_name}")
|
||||||
sh.sed("-i", f"s/{submodule_name}/{submodule_name}_Model/", new_file)
|
if (submodule_name + ".sv") in common_fnames:
|
||||||
|
sh.sed("-i", f"s/\b{submodule_name}\b/{submodule_name}_Model/", new_file)
|
||||||
|
|
||||||
visited.add(cur_module)
|
visited.add(cur_module)
|
||||||
return (new_file is not None)
|
return (new_file is not None)
|
||||||
@@ -88,16 +92,18 @@ def dfs_update_modules(tree, common_fnames, visited):
|
|||||||
def main():
|
def main():
|
||||||
top_fnames = set(get_filelist(args.top_filelist))
|
top_fnames = set(get_filelist(args.top_filelist))
|
||||||
mod_fnames = set(get_filelist(args.mod_filelist))
|
mod_fnames = set(get_filelist(args.mod_filelist))
|
||||||
|
|
||||||
common_fnames = top_fnames.intersection(mod_fnames)
|
common_fnames = top_fnames.intersection(mod_fnames)
|
||||||
for c in common_fnames:
|
|
||||||
print(c)
|
|
||||||
|
|
||||||
imhj = open(args.model_hier_json, "r")
|
imhj = open(args.model_hier_json, "r")
|
||||||
imhj_data = json.load(imhj)
|
imhj_data = json.load(imhj)
|
||||||
|
|
||||||
visited = set()
|
visited = set()
|
||||||
dfs_update_modules(imhj_data, common_fnames, visited)
|
updated_modules = list()
|
||||||
|
dfs_update_modules(imhj_data, common_fnames, visited, top_fnames, updated_modules)
|
||||||
|
|
||||||
|
out_file = open(args.model_hier_json, "w")
|
||||||
|
json.dump(imhj_data, out_file, indent=2)
|
||||||
|
out_file.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user