Skip to content

Commit

Permalink
Merge pull request #2075 from Pinata-Consulting/memory-lists-source-f…
Browse files Browse the repository at this point in the history
…iles-actually-used

Memory lists source files actually used
  • Loading branch information
maliberty authored Jun 20, 2024
2 parents 5f3c603 + 24cd1aa commit f0caba6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
33 changes: 21 additions & 12 deletions flow/scripts/mem_dump.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import argparse
import json
import os
import sys


def format_ram_table_from_json(data, max_bits=None):
formatting = "{:<15} | {:<15} | {:<15} | {:<50}\n"
table = formatting.format("Rows",
"Width",
"Total bits",
"Name")
table += "-"*len(table) + "\n"
table = formatting.format("Rows", "Width", "Total bits", "Name")
table += "-" * len(table) + "\n"
max_ok = True
for module_name, module_info in data["modules"].items():
cells = module_info["cells"]
Expand All @@ -21,9 +17,7 @@ def format_ram_table_from_json(data, max_bits=None):
size = int(parameters["SIZE"], 2)
width = int(parameters["WIDTH"], 2)
bits = size * width
table += formatting.format(size,
width,
bits,
table += formatting.format(size, width, bits,
module_name + "." + memory)
if max_bits is not None and bits > max_bits:
max_ok = False
Expand All @@ -38,8 +32,23 @@ def format_ram_table_from_json(data, max_bits=None):

with open(args.file, 'r') as file:
json_data = json.load(file)
formatted_table, max_ok = format_ram_table_from_json(json_data, args.max_bits)
print()

src_files = set()
for module_name, module_info in json_data["modules"].items():
for cell in module_info["cells"].values():
if "src" not in cell["attributes"]:
continue
src_file = cell["attributes"]["src"].split(":")[0]
src_files.add(src_file)

print("Source files actually used in the design:")
print(" " + "\n ".join(src_files))

print("Memories found in the design:")
formatted_table, max_ok = format_ram_table_from_json(
json_data, args.max_bits)
print(formatted_table)
if not max_ok:
sys.exit("ERROR: Synthesized memory size exceeds maximum allowed bits " + str(args.max_bits))
sys.exit(
"ERROR: Synthesized memory size exceeds maximum allowed bits " +
str(args.max_bits))
2 changes: 2 additions & 0 deletions flow/scripts/synth_preamble.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ close $constr
proc synthesize_check {synth_args} {
# Generic synthesis
log_cmd synth -top $::env(DESIGN_NAME) -run :fine {*}$synth_args
# Get rid of unused modules
clean
json -o $::env(RESULTS_DIR)/mem.json
# Run report and check here so as to fail early if this synthesis run is doomed
exec -- python3 $::env(SCRIPTS_DIR)/mem_dump.py --max-bits $::env(SYNTH_MEMORY_MAX_BITS) $::env(RESULTS_DIR)/mem.json
Expand Down

0 comments on commit f0caba6

Please sign in to comment.