File size: 2,263 Bytes
784ee2c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #!/usr/bin/env python3
import os
import json
from pathlib import Path
class RunUtils:
@staticmethod
def get_config(config_file):
"""Load the JSON configuration file"""
with open(config_file, "r") as fid:
raw = [line.strip() for line in fid if not line.strip().startswith("#")]
json_data = json.loads("\n".join(raw))
return json_data
@staticmethod
def ensure_results_dir(output_dir, memory_name):
"""Ensures that the results directory exists"""
p = str(Path(output_dir).expanduser().resolve(strict=False))
results_dir = os.sep.join([p, memory_name])
if not os.path.exists(results_dir):
os.makedirs(results_dir)
return results_dir
@staticmethod
def get_output_file_names(memory_name, output_dir):
"""
Returns the full paths to the output file names using the memory name
as the base name
"""
results_dir = RunUtils.ensure_results_dir(output_dir, memory_name)
lib_file_name = os.path.join(results_dir, memory_name + ".lib")
lef_file_name = os.path.join(results_dir, memory_name + ".lef")
verilog_file_name = os.path.join(results_dir, memory_name + ".v")
sv_blackbox_file_name = os.path.join(results_dir, memory_name + ".sv")
return (lib_file_name, lef_file_name, verilog_file_name, sv_blackbox_file_name)
@staticmethod
def write_memory(memory, output_dir):
"""Generates the output file names and then writes the files"""
lib_file_name, lef_file_name, verilog_file_name, sv_blackbox_file_name = (
RunUtils.get_output_file_names(memory.get_name(), output_dir)
)
RunUtils.write_all(
memory,
lib_file_name,
lef_file_name,
verilog_file_name,
sv_blackbox_file_name,
)
@staticmethod
def write_all(
memory, lib_file_name, lef_file_name, verilog_file_name, sv_blackbox_file_name
):
"""Writes the files"""
memory.write_liberty_file(lib_file_name)
memory.write_lef_file(lef_file_name)
memory.write_verilog_file(verilog_file_name)
memory.write_verilog_file(sv_blackbox_file_name, True)
|