From 3f80507ce4a2f8ae659da2d27ab81d0a3be8f564 Mon Sep 17 00:00:00 2001 From: joey0320 Date: Sat, 29 Apr 2023 18:21:48 -0700 Subject: [PATCH] rm split-bb-files.py --- common.mk | 10 +--- scripts/split-bb-files.py | 82 -------------------------------- scripts/uniquify-module-names.py | 18 ++++--- variables.mk | 4 -- vlsi/Makefile | 4 +- 5 files changed, 15 insertions(+), 103 deletions(-) delete mode 100755 scripts/split-bb-files.py diff --git a/common.mk b/common.mk index 7afdf57b..0868088b 100644 --- a/common.mk +++ b/common.mk @@ -249,14 +249,6 @@ $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(ALL_MODS_FILELIST) $(BB_MODS_FILEL $(SED) -i 's/\.\///' $(BB_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) - $(base_dir)/scripts/split-bb-files.py \ - --in-bb-f $(BB_MODS_FILELIST) \ - --in-top-hrchy-json $(MFC_TOP_HRCHY_JSON) \ - --in-anno-json $(FINAL_ANNO_FILE) \ - --out-top-bb-f $(TOP_BB_MODS_FILELIST) \ - --out-model-bb-f $(MODEL_BB_MODS_FILELIST) - $(TOP_SMEMS_CONF) $(MODEL_SMEMS_CONF) &: $(MFC_SMEMS_CONF) $(MFC_MODEL_HRCHY_JSON_UNIQUIFIED) $(base_dir)/scripts/split-mems-conf.py \ --in-smems-conf $(MFC_SMEMS_CONF) \ @@ -280,7 +272,7 @@ $(MODEL_SMEMS_FILE) $(MODEL_SMEMS_FIR) &: $(MODEL_SMEMS_CONF) | $(TOP_SMEMS_FILE # note: {MODEL,TOP}_BB_MODS_FILELIST is added as a req. so that the files get generated, # however it is really unneeded since ALL_MODS_FILELIST includes all BB files ######################################################################################## -$(sim_common_files): $(sim_files) $(ALL_MODS_FILELIST) $(TOP_SMEMS_FILE) $(MODEL_SMEMS_FILE) $(TOP_BB_MODS_FILELIST) $(MODEL_BB_MODS_FILELIST) +$(sim_common_files): $(sim_files) $(ALL_MODS_FILELIST) $(TOP_SMEMS_FILE) $(MODEL_SMEMS_FILE) $(BB_MODS_FILELIST) sort -u $(sim_files) $(ALL_MODS_FILELIST) | grep -v '.*\.\(svh\|h\)$$' > $@ echo "$(TOP_SMEMS_FILE)" >> $@ echo "$(MODEL_SMEMS_FILE)" >> $@ diff --git a/scripts/split-bb-files.py b/scripts/split-bb-files.py deleted file mode 100755 index 959a10a2..00000000 --- a/scripts/split-bb-files.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python3 - -import json -import argparse -from collections import defaultdict - -# Schema of *.f emitted by circt -""" -//gen-collateral/SimUART.cc -//gen-collateral/AsyncQueueSource.sv -//gen-collateral/AsyncQueueSink.sv -//gen-collateral/AsyncQueueSource_1.sv -//gen-collateral/AsyncQueueSink_1.sv -//gen-collateral/AsyncQueueSource_2.sv -//gen-collateral/AsyncQueueSink_2.sv -//gen-collateral/AsyncResetSynchronizerShiftReg_w4_d3_i0.sv -""" - -def bfs_collect_submodules(tree): - output = set() - q = [(tree['instance_name'], tree['module_name'], tree['instances'])] - - while len(q) != 0: - front = q[0] - q.pop(0) - - (inst, mod, child) = front - output.add(mod) - for c in child: - q.append((c['instance_name'], c['module_name'], c['instances'])) - return output - -def write_lines_to_file(lines, file_path): - with open(file_path, "w") as fp: - for line in lines: - fp.write("%s\n" % line) - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Create *.model.bb.f and *.top.bb.f blackbox filelists') - parser.add_argument('--in-bb-f', type=str, required=True, help='All blackbox files filelist (includes both MODEL/TOP files)') - parser.add_argument('--in-top-hrchy-json', type=str, required=True, help='List containing hierarchy of top modules (top-module-hierarchy.json)') - parser.add_argument('--in-anno-json', type=str, required=True, help='Anno. file with blackbox annotations') - parser.add_argument('--out-top-bb-f', type=str, required=True, help='List of blackbox files for TOP') - parser.add_argument('--out-model-bb-f', type=str, required=True, help='List of blackbox files for MODEL') - args = parser.parse_args() - - # module_path -> list of bb paths (not fully resolved paths) - mod_bb_dict = defaultdict(list) - with open(args.in_anno_json, "r") as f: - anno_data = json.load(f) - for anno in anno_data: - if 'BlackBoxInlineAnno' in anno['class']: - mod_bb_dict[anno['target']].append(anno['name']) - if 'BlackBoxPathAnno' in anno['class']: - mod_bb_dict[anno['target']].append(anno['path']) - - with open(args.in_top_hrchy_json) as ihj: - ihj_data = json.load(ihj) - top_inner_modules = bfs_collect_submodules(ihj_data) - - with open(args.in_bb_f) as ibf: - lines = ibf.read().splitlines() - - tbfs = set() - for mod_path, bb_files in mod_bb_dict.items(): - leaf_mod = mod_path.split('.')[-1] - - # if matched, add the fully resolved path to the top bb filelist - if leaf_mod in top_inner_modules: - for line in lines: - for bb_file in bb_files: - if bb_file in line: - tbfs.add(line) - - # now tbfs should be complete (need to remove tbf files from original bb file for model bb) - mbfs = set() - for line in lines: - if not line in tbfs: - mbfs.add(line) - - write_lines_to_file(tbfs, args.out_top_bb_f) - write_lines_to_file(mbfs, args.out_model_bb_f) diff --git a/scripts/uniquify-module-names.py b/scripts/uniquify-module-names.py index 641ef563..768a061e 100755 --- a/scripts/uniquify-module-names.py +++ b/scripts/uniquify-module-names.py @@ -54,14 +54,14 @@ def generate_copy(c, sfx): bash(f"sed -i s/\"module {cur_name}\"/\"module {new_name}\"/ {new_file}") return new_file -def dfs_update_modules(tree, common_fnames, visited, ext_dict): +def dfs_update_modules(tree, common_fnames, visited): # List of direct submodules to update childs_to_update = list() for child in tree['instances']: # We don't have to change stuff that are under the dut if (child['module_name'] == args.dut): continue - if dfs_update_modules(child, common_fnames, visited, ext_dict): + if dfs_update_modules(child, common_fnames, visited): childs_to_update.append(child['module_name']) if (child['module_name']) in common_fnames: child['module_name'] = child['module_name'] + "_" + MODEL_SFX @@ -87,7 +87,7 @@ def bfs_update(tree, common_fnames, ext_dict, filelist): (inst, mod, child, parent) = front try: - cur_file = mod + "." + ext_dict[mod] + cur_file = mod + "." + ext_dict[mod][0] except: cur_file = mod + ".sv" @@ -99,7 +99,7 @@ def bfs_update(tree, common_fnames, ext_dict, filelist): new_file = generate_copy(cur_file, MODEL_SFX) filelist.append((mod, new_file)) if parent is not None and ((parent, mod) not in updated_submodule): - parent_file = os.path.join(args.gcpath, parent + "." + ext_dict[parent]) + parent_file = os.path.join(args.gcpath, parent + "." + ext_dict[parent][0]) bash(f"sed -i s/\"{mod} \"/\"{mod}_{MODEL_SFX} \"/ {parent_file}") updated_submodule.add((parent, mod)) mod_updated = True @@ -165,6 +165,10 @@ def write_filelist_model(modules, out_file, ext_dict): else: df.write(f"{fname}\n") + if len(ext_dict[m]) > 1: + assert(len(ext_dict[m]) == 2) + df.write(f"{args.target_dir}/{m}.{ext_dict[m][1]}\n") + def get_file_ext(all_filelist): ext_dict = dict() with open(all_filelist) as fl: @@ -174,7 +178,9 @@ def get_file_ext(all_filelist): ext = fname_strip[-1] fname_strip.pop() module = ".".join(fname_strip) - ext_dict[module] = ext + if module not in ext_dict.keys(): + ext_dict[module] = list() + ext_dict[module].append(ext) return ext_dict def main(): @@ -197,7 +203,7 @@ def main(): visited = set() filelist = list() bfs_update(imhj_data, common_modules, ext_dict, filelist) - dfs_update_modules(imhj_data, common_modules, visited, ext_dict) + dfs_update_modules(imhj_data, common_modules, visited) json.dump(imhj_data, out_file, indent=2) write_filelist_model(set(filelist), args.out_model_filelist, ext_dict) diff --git a/variables.mk b/variables.mk index 1f659ac7..443caa94 100644 --- a/variables.mk +++ b/variables.mk @@ -186,10 +186,6 @@ MODEL_MODS_FILELIST ?= $(build_dir)/$(long_name).model.f # list of all blackbox files (may be included in the top/model.f files) # this has the build_dir appended BB_MODS_FILELIST ?= $(build_dir)/$(long_name).bb.f -# top blackbox module files to include -TOP_BB_MODS_FILELIST ?= $(build_dir)/$(long_name).top.bb.f -# model blackbox module files to include (not including top blackbox modules) -MODEL_BB_MODS_FILELIST ?= $(build_dir)/$(long_name).model.bb.f # all module files to include (top, model, bb included) ALL_MODS_FILELIST ?= $(build_dir)/$(long_name).all.f diff --git a/vlsi/Makefile b/vlsi/Makefile index 8259e7a6..ad51c754 100644 --- a/vlsi/Makefile +++ b/vlsi/Makefile @@ -72,7 +72,7 @@ VLSI_RTL = $(build_dir)/syn.f ifneq ($(CUSTOM_VLOG), ) RTL_DEPS = $(CUSTOM_VLOG) else - RTL_DEPS = $(TOP_MODS_FILELIST) $(TOP_BB_MODS_FILELIST) $(TOP_SMEMS_FILE) + RTL_DEPS = $(TOP_MODS_FILELIST) $(TOP_SMEMS_FILE) endif $(VLSI_RTL): $(RTL_DEPS) @@ -80,7 +80,7 @@ ifneq ($(CUSTOM_VLOG), ) > $(VLSI_RTL) $(foreach file,$^,echo $(file) >> $(VLSI_RTL)) else - cat $(TOP_MODS_FILELIST) $(TOP_BB_MODS_FILELIST) | sort -u > $(VLSI_RTL) + cat $(TOP_MODS_FILELIST) | sort -u > $(VLSI_RTL) echo $(TOP_SMEMS_FILE) >> $(VLSI_RTL) endif