|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -import os |
4 | 3 | import sys |
5 | | -import json |
6 | 4 | import argparse |
7 | | -from pathlib import Path |
8 | 5 |
|
| 6 | +from utils.run_utils import RunUtils |
9 | 7 | from utils.class_process import Process |
10 | | -from utils.class_memory import Memory |
11 | | - |
12 | | -from utils.create_lib import create_lib |
13 | | -from utils.create_lef import create_lef |
14 | | -from utils.create_verilog import create_verilog |
| 8 | +from utils.memory_factory import MemoryFactory |
| 9 | +from utils.timing_data import TimingData |
15 | 10 |
|
16 | 11 | ################################################################################ |
17 | 12 | # RUN GENERATOR |
@@ -45,34 +40,44 @@ def get_args() -> argparse.Namespace: |
45 | 40 | return parser.parse_args() |
46 | 41 |
|
47 | 42 |
|
48 | | -def ensure_results_dir(output_dir, memory_name): |
49 | | - if output_dir: # Output dir was set by command line option |
50 | | - p = str(Path(output_dir).expanduser().resolve(strict=False)) |
51 | | - results_dir = os.sep.join([p, memory_name]) |
52 | | - else: |
53 | | - results_dir = os.sep.join([os.getcwd(), "results", memory_name]) |
54 | | - if not os.path.exists(results_dir): |
55 | | - os.makedirs(results_dir) |
56 | | - return results_dir |
| 43 | +def get_memory_type(json_data): |
| 44 | + if "memory_type" in json_data: |
| 45 | + return json_data["memory_type"] |
| 46 | + return "RAM" |
57 | 47 |
|
58 | 48 |
|
59 | | -def main(args: argparse.Namespace): |
| 49 | +def get_port_config(json_data): |
| 50 | + if "port_configuration" in json_data: |
| 51 | + return json_data["port_configuration"] |
| 52 | + return "SP" |
60 | 53 |
|
61 | | - # Load the JSON configuration file |
62 | | - with open(args.config, "r") as fid: |
63 | | - raw = [line.strip() for line in fid if not line.strip().startswith("#")] |
64 | | - json_data = json.loads("\n".join(raw)) |
65 | 54 |
|
| 55 | +def main(args: argparse.Namespace): |
| 56 | + json_data = RunUtils.get_config(args.config) |
66 | 57 | # Create a process object (shared by all srams) |
67 | 58 | process = Process(json_data) |
| 59 | + timing_data = TimingData(json_data) |
| 60 | + |
| 61 | + memory_type = get_memory_type(json_data) |
| 62 | + port_config = get_port_config(json_data) |
68 | 63 |
|
69 | 64 | # Go through each sram and generate the lib, lef and v files |
70 | 65 | for sram_data in json_data["srams"]: |
71 | | - memory = Memory(process, sram_data) |
72 | | - results_dir = ensure_results_dir(args.output_dir, memory.name) |
73 | | - create_lib(memory, results_dir) |
74 | | - create_lef(memory, results_dir) |
75 | | - create_verilog(memory, results_dir) |
| 66 | + name = str(sram_data["name"]) |
| 67 | + width_in_bits = int(sram_data["width"]) |
| 68 | + depth = int(sram_data["depth"]) |
| 69 | + num_banks = int(sram_data["banks"]) |
| 70 | + memory = MemoryFactory.create( |
| 71 | + name, |
| 72 | + width_in_bits, |
| 73 | + depth, |
| 74 | + num_banks, |
| 75 | + memory_type, |
| 76 | + port_config, |
| 77 | + process, |
| 78 | + timing_data, |
| 79 | + ) |
| 80 | + RunUtils.write_memory(memory, args.output_dir) |
76 | 81 |
|
77 | 82 |
|
78 | 83 | ### Entry point |
|
0 commit comments