|
| 1 | +import argparse |
| 2 | +import json |
| 3 | +import os |
| 4 | +import sys |
| 5 | + |
| 6 | + |
| 7 | +def format_ram_table_from_json(data, max_bits=None): |
| 8 | + formatting = "{:<15} | {:<15} | {:<15} | {:<50}\n" |
| 9 | + table = formatting.format("Rows", |
| 10 | + "Width", |
| 11 | + "Total bits", |
| 12 | + "Name") |
| 13 | + table += "-"*len(table) + "\n" |
| 14 | + max_ok = True |
| 15 | + for module_name, module_info in data["modules"].items(): |
| 16 | + cells = module_info["cells"] |
| 17 | + for memory, cell in cells.items(): |
| 18 | + if not cell["type"].startswith("$mem"): |
| 19 | + continue |
| 20 | + parameters = cell["parameters"] |
| 21 | + size = int(parameters["SIZE"], 2) |
| 22 | + width = int(parameters["WIDTH"], 2) |
| 23 | + bits = size * width |
| 24 | + table += formatting.format(size, |
| 25 | + width, |
| 26 | + bits, |
| 27 | + module_name + "." + memory) |
| 28 | + if max_bits is not None and bits > max_bits: |
| 29 | + max_ok = False |
| 30 | + return table, max_ok |
| 31 | + |
| 32 | + |
| 33 | +if __name__ == "__main__": |
| 34 | + parser = argparse.ArgumentParser() |
| 35 | + parser.add_argument("file") |
| 36 | + parser.add_argument("-m", "--max-bits", type=int, default=None) |
| 37 | + args = parser.parse_args() |
| 38 | + |
| 39 | + with open(args.file, 'r') as file: |
| 40 | + json_data = json.load(file) |
| 41 | + formatted_table, max_ok = format_ram_table_from_json(json_data, args.max_bits) |
| 42 | + print() |
| 43 | + print(formatted_table) |
| 44 | + if not max_ok: |
| 45 | + sys.exit("ERROR: Synthesized memory size exceeds maximum allowed bits " + str(args.max_bits)) |
0 commit comments