Rename variables | Small fixes | Move out-srcs to new dir

This commit is contained in:
abejgonzalez
2022-10-13 15:39:48 -07:00
committed by joey0320
parent f5914ec9e9
commit 9f2fd22cc0
6 changed files with 133 additions and 115 deletions

View File

@@ -25,41 +25,41 @@ from typing import List, Optional
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Use CIRCT (firtool) smems JSONs to create DUT and test harness smems confs')
parser.add_argument('--in-smems-conf', type=str, required=True, help='')
parser.add_argument('--in-dut-smems-json', type=str, required=True, help='')
parser.add_argument('--in-tb-smems-json', type=str, required=True, help='')
parser.add_argument('--out-dut-smems-conf', type=str, required=True, help='')
parser.add_argument('--out-tb-smems-conf', type=str, required=True, help='')
parser.add_argument('--in-smems-conf', type=str, required=True, help='Overall smems conf file that contains all memory definitions')
parser.add_argument('--in-dut-smems-json', type=str, required=True, help='JSON indicating which mem modules are in the DUT')
parser.add_argument('--in-model-smems-json', type=str, required=True, help='JSON indicating which mem modules are in the top-most level module (but not in the DUT)')
parser.add_argument('--out-dut-smems-conf', type=str, required=True, help='Smems conf with only DUT mem module definitions')
parser.add_argument('--out-model-smems-conf', type=str, required=True, help='Smems conf with only top-most level mem module definitions (not including DUT modules)')
args = parser.parse_args()
with open(args.in_smems_conf) as isc:
with open(args.in_dut_smems_json) as idsj:
with open(args.in_tb_smems_json) as itsj:
idsj_data = json.load(idsj)
itsj_data = json.load(itsj)
with open(args.in_smems_conf) as isc, \
open(args.in_dut_smems_json) as idsj, \
open(args.in_model_smems_json) as itsj:
idsj_data = json.load(idsj)
itsj_data = json.load(itsj)
dut_mods = set()
for e in idsj_data:
dut_mods.add(e['module_name'])
dut_mods = set()
for e in idsj_data:
dut_mods.add(e['module_name'])
tb_mods = set()
for e in itsj_data:
tb_mods.add(e['module_name'])
model_mods = set()
for e in itsj_data:
model_mods.add(e['module_name'])
with open(args.out_dut_smems_conf, "w") as odsc:
with open(args.out_tb_smems_conf, "w") as otsc:
for l in isc:
sl = l.split()
with open(args.out_dut_smems_conf, "w") as odsc, \
open(args.out_model_smems_conf, "w") as otsc:
for l in isc:
sl = l.split()
# the line can't be split then stop immediately (normally an empty file)
if len(sl) > 2:
name = sl[1]
# the line can't be split then stop immediately (normally an empty file)
if len(sl) > 2:
name = sl[1]
if name in dut_mods:
odsc.write(l)
elif name in tb_mods:
otsc.write(l)
else:
assert False, "Unable to find smem CONF module in firtool emitted JSON files."
else:
exit(0)
if name in dut_mods:
odsc.write(l)
elif name in model_mods:
otsc.write(l)
else:
assert False, "Unable to find smem CONF module in firtool emitted JSON files."
else:
exit(0)

View File

@@ -54,15 +54,15 @@ def find_mod_by_name(js: dict, name: str) -> Optional[List[dict]]:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Convert CIRCT (firtool) hierarchy JSON into DUT and test harness filelists')
parser.add_argument('--tb-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('--out-dut-filelist', type=str, required=True, help='Path to output filelist including all modules under the DUT.')
parser.add_argument('--out-tb-filelist', type=str, required=True, help='Path to output filelist including all modules under the top-most module but not modules under the DUT.')
parser.add_argument('--out-model-filelist', type=str, required=True, help='Path to output filelist including all modules under the top-most module but not modules under the DUT.')
parser.add_argument('--in-all-filelist', type=str, required=True, help='Path to input filelist that has all modules (relative paths).')
parser.add_argument('--build-dir', type=str, required=True, help='Path to where module sources are located (combined with --in-all-filelist gives the absolute path to module sources).')
parser.add_argument('--target-dir', type=str, required=True, help='Path to where module sources are located (combined with --in-all-filelist gives the absolute path to module sources).')
args = parser.parse_args()
with open(args.tb_hier_json) as f:
with open(args.model_hier_json) as f:
j = json.load(f)
dut_tops = find_mod_by_name(j, args.dut)
@@ -71,42 +71,41 @@ if __name__ == "__main__":
dut_top = dut_tops[0]
dut_mods = set(get_modules(dut_top))
tb_mods = set(get_modules(j)) - dut_mods
both_mods = dut_mods.intersection(tb_mods)
model_mods = set(get_modules(j)) - dut_mods
both_mods = dut_mods.intersection(model_mods)
assert len(both_mods) == 0
with open(args.out_dut_filelist, 'w') as df:
with open(args.in_all_filelist) as fl:
# add paths that correspond to modules to output file
for path in fl:
writeOut = False
for dm in dut_mods:
if dm in path:
writeOut = True
break
with open(args.out_dut_filelist, 'w') as df, \
open(args.in_all_filelist) as fl:
# add paths that correspond to modules to output file
for path in fl:
writeOut = False
for dm in dut_mods:
if dm in path:
writeOut = True
break
# prepend the build directory to get filelist with absolute paths
if writeOut:
if not args.build_dir in path:
df.write(f"{args.build_dir}/{path}")
else:
df.write(f"{path}")
# prepend the target directory to get filelist with absolute paths
if writeOut:
if not args.target_dir in path:
df.write(f"{args.target_dir}/{path}")
else:
df.write(f"{path}")
with open(args.out_model_filelist, 'w') as df, \
open(args.in_all_filelist) as fl:
# add paths that correspond to modules to output file
for path in fl:
writeOut = False
for dm in model_mods:
if dm in path:
writeOut = True
break
with open(args.out_tb_filelist, 'w') as df:
with open(args.in_all_filelist) as fl:
# add paths that correspond to modules to output file
for path in fl:
writeOut = False
for dm in tb_mods:
if dm in path:
writeOut = True
break
# prepend the build directory to get filelist with absolute paths
if writeOut:
if not args.build_dir in path:
df.write(f"{args.build_dir}/{path}")
else:
df.write(f"{path}")
# prepend the target directory to get filelist with absolute paths
if writeOut:
if not args.target_dir in path:
df.write(f"{args.target_dir}/{path}")
else:
df.write(f"{path}")