diff --git a/common.mk b/common.mk index 46722d33..161f4bc0 100644 --- a/common.mk +++ b/common.mk @@ -146,11 +146,8 @@ FIRTOOL_TARGETS = \ $(FIRTOOL_FILELIST) \ $(FIRTOOL_BB_MODS_FILELIST) -REPL_SEQ_MEM = --infer-rw --repl-seq-mem -c:$(MODEL):-o:$(FIRTOOL_SMEMS_CONF) +SFC_REPL_SEQ_MEM = --infer-rw --repl-seq-mem -c:$(MODEL):-o:$(SFC_SMEMS_CONF) -ifeq (,$(ENABLE_CUSTOM_FIRRTL_PASS)) - EXTRA_FIRRTL_OPTIONS += $(REPL_SEQ_MEM) -endif # DOC include start: FirrtlCompiler # hack: lower to low firrtl if Fixed types are found @@ -159,8 +156,10 @@ endif $(FIRTOOL_TARGETS) &: $(FIRRTL_FILE) $(FINAL_ANNO_FILE) $(VLOG_SOURCES) ifeq (,$(ENABLE_CUSTOM_FIRRTL_PASS)) $(eval SFC_LEVEL := $(if $(shell grep "Fixed<" $(FIRRTL_FILE)), low, none)) + $(eval EXTRA_FIRRTL_OPTIONS += $(if $(shell grep "Fixed<" $(FIRRTL_FILE)), $(SFC_REPL_SEQ_MEM),)) else $(eval SFC_LEVEL := low) + $(eval EXTRA_FIRRTL_OPTIONS += $(SFC_REPL_SEQ_MEM)) endif $(call run_scala_main,tapeout,barstools.tapeout.transforms.GenerateModelStageMain,\ --no-dedup \ @@ -174,8 +173,8 @@ endif -X $(SFC_LEVEL) \ $(EXTRA_FIRRTL_OPTIONS)) -mv $(SFC_FIRRTL_BASENAME).lo.fir $(SFC_FIRRTL_FILE) - $(if $(ENABLE_CUSTOM_FIRRTL_PASS), cat $(SFC_ANNO_FILE) | jq 'del(.[] | select(.target | test("io.cpu"))?)' > /tmp/unnec-anno-deleted.sfc.anno.json,) - $(if $(ENABLE_CUSTOM_FIRRTL_PASS), cat /tmp/unnec-anno-deleted.sfc.anno.json > $(SFC_ANNO_FILE) && rm /tmp/unnec-anno-deleted.sfc.anno.json,) + @if [ "$(SFC_LEVEL)" = low ]; then cat $(SFC_ANNO_FILE) | jq 'del(.[] | select(.target | test("io.cpu"))?)' > /tmp/unnec-anno-deleted.sfc.anno.json; fi + @if [ "$(SFC_LEVEL)" = low ]; then cat /tmp/unnec-anno-deleted.sfc.anno.json > $(SFC_ANNO_FILE) && rm /tmp/unnec-anno-deleted.sfc.anno.json; fi firtool \ --format=fir \ -O=release \ @@ -188,12 +187,13 @@ endif --warn-on-unprocessed-annotations \ --lowering-options=emittedLineLength=2048,noAlwaysComb,disallowLocalVariables,explicitBitcast,verifLabels,locationInfoStyle=wrapInAtSquareBracket \ --repl-seq-mem \ - --repl-seq-mem-circuit=$(MODEL) \ --repl-seq-mem-file=$(FIRTOOL_SMEMS_CONF) \ + --repl-seq-mem-circuit=$(MODEL) \ --annotation-file=$(SFC_ANNO_FILE) \ --split-verilog \ -o $(OUT_DIR) \ $(SFC_FIRRTL_FILE) + -mv $(SFC_SMEMS_CONF) $(FIRTOOL_SMEMS_CONF) $(SED) -i 's/.*/& /' $(FIRTOOL_SMEMS_CONF) # need trailing space for SFC macrocompiler # DOC include end: FirrtlCompiler @@ -214,8 +214,9 @@ $(TOP_MODS_FILELIST) $(MODEL_MODS_FILELIST) $(ALL_MODS_FILELIST) $(BB_MODS_FILEL $(TOP_SMEMS_CONF) $(HARNESS_SMEMS_CONF) &: $(FIRTOOL_TOP_SMEMS_JSON) $(FIRTOOL_MODEL_SMEMS_JSON) $(FIRTOOL_SMEMS_CONF) $(base_dir)/scripts/split-mems-conf.py \ --in-smems-conf $(FIRTOOL_SMEMS_CONF) \ - --in-dut-smems-json $(FIRTOOL_TOP_SMEMS_JSON) \ - --in-model-smems-json $(FIRTOOL_MODEL_SMEMS_JSON) \ + --in-model-hrchy-json $(FIRTOOL_MODEL_HRCHY_JSON) \ + --dut-module-name $(TOP) \ + --model-module-name $(MODEL) \ --out-dut-smems-conf $(TOP_SMEMS_CONF) \ --out-model-smems-conf $(HARNESS_SMEMS_CONF) diff --git a/scripts/split-mems-conf.py b/scripts/split-mems-conf.py index 89f338b1..b9eb7966 100755 --- a/scripts/split-mems-conf.py +++ b/scripts/split-mems-conf.py @@ -3,6 +3,7 @@ import os import json import argparse +import sys from typing import List, Optional # Schema of json emitted by circt @@ -23,43 +24,73 @@ from typing import List, Optional } """ +sys.setrecursionlimit(100) + + + +# Performing DFS recursively is not a problem here since the modules that +# we are interested in are close to the root of the module hierarchy +def dfs_find_root(tree, module_name): + if tree['module_name'] == module_name: + return tree + if len(tree['instances']) == 0: + exit(0) + for c in tree['instances']: + ret = dfs_find_root(c, module_name) + if ret is not None: + return ret + return None + + +def bfs_collect_module(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 + + 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='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() + parser = argparse.ArgumentParser(description='Use CIRCT (firtool) model-hrchy JSONs to create DUT and test harness smems confs or ') + parser.add_argument('--in-smems-conf', type=str, required=True, help='Overall smems conf file that contains all memory definitions') + parser.add_argument('--in-model-hrchy-json', type=str, required=True, help='JSON indicating which mem modules are in the DUT') + parser.add_argument('--dut-module-name', type=str, required=True, help='Module name of the DUT') + parser.add_argument('--model-module-name', type=str, required=True, help='Module name of the model') + 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, \ - 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) + with open(args.in_smems_conf) as isc, \ + open(args.in_model_hrchy_json) as imhj: + imhj_data = json.load(imhj) - dut_mods = set() - for e in idsj_data: - dut_mods.add(e['module_name']) + dut_root = dfs_find_root(imhj_data, args.dut_module_name) + dut_submodules = bfs_collect_module(dut_root) - model_mods = set() - for e in itsj_data: - model_mods.add(e['module_name']) + model_root = dfs_find_root(imhj_data, args.model_module_name) + model_submodules = bfs_collect_module(model_root) - 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() + 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 model_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_submodules: + odsc.write(l) + elif name in model_submodules: + otsc.write(l) + else: + assert False, "Unable to find smem CONF module in firtool emitted JSON files." + else: + exit(0) diff --git a/tools/barstools b/tools/barstools index 899387f4..e340f124 160000 --- a/tools/barstools +++ b/tools/barstools @@ -1 +1 @@ -Subproject commit 899387f4fb54279a8d5c0a16e543c2cc6e60f6b8 +Subproject commit e340f1240a2c5feeb85160a7f81a32496916a7c4 diff --git a/variables.mk b/variables.mk index 9c68d594..a457a813 100644 --- a/variables.mk +++ b/variables.mk @@ -167,6 +167,7 @@ FIRTOOL_TOP_SMEMS_JSON = $(OUT_DIR)/metadata/seq_mems.json FIRTOOL_MODEL_SMEMS_JSON = $(OUT_DIR)/metadata/tb_seq_mems.json # macrocompiler smems in/output +SFC_SMEMS_CONF ?= $(build_dir)/$(long_name).sfc.mems.conf TOP_SMEMS_CONF ?= $(build_dir)/$(long_name).top.mems.conf TOP_SMEMS_FILE ?= $(OUT_DIR)/$(long_name).top.mems.v TOP_SMEMS_FIR ?= $(build_dir)/$(long_name).top.mems.fir