2020-11-27 13:25:08 -06:00
|
|
|
#####################################################################
|
|
|
|
# Python script to generate all the post-pnr testbenches
|
|
|
|
# based on auto-generated pre-PnR testbenches
|
|
|
|
# This script will
|
|
|
|
# - Find all the pre-PnR testbenches in parent directory
|
|
|
|
# For instance:
|
|
|
|
# ../k4_arch/pre_pnr/verilog_testbenches/and2_autocheck_top_tb.v
|
|
|
|
# - Use post_pnr_testbench_convert.py to generate the post-PnR testbenches
|
|
|
|
# and place at a similar path than the pre-PnR testbenches
|
|
|
|
# For instance:
|
|
|
|
# ../k4_arch/post_pnr/verilog_testbenches/and2_post_pnr_autocheck_top_tb.v
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
import os
|
|
|
|
from os.path import dirname, abspath
|
|
|
|
import shutil
|
|
|
|
import re
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import subprocess
|
|
|
|
import glob
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Initialize logger
|
|
|
|
#####################################################################
|
|
|
|
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
|
|
|
|
|
2020-11-28 15:39:18 -06:00
|
|
|
#####################################################################
|
|
|
|
# Parse the options
|
|
|
|
#####################################################################
|
|
|
|
parser = argparse.ArgumentParser(description='Generate post-PnR testbenches for a given directory')
|
|
|
|
parser.add_argument('--pre_pnr_testbench_dir_name', required=True,
|
|
|
|
help='Specify the directory path for the pre-PnR Verilog testbenches')
|
2020-11-29 23:38:16 -06:00
|
|
|
parser.add_argument('--pin_assignment_file', required=True,
|
|
|
|
help='Specify the file path to the pin assignment JSON description as input')
|
2020-11-28 15:39:18 -06:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-11-27 13:25:08 -06:00
|
|
|
#####################################################################
|
|
|
|
# Walk through the parent directory and find all the pre-PnR testbenches
|
|
|
|
#####################################################################
|
|
|
|
logging.info("Finding pre-PnR testbenches...");
|
|
|
|
|
2020-11-30 23:41:29 -06:00
|
|
|
script_base_dir_abspath = dirname(os.path.abspath(__file__))
|
2020-11-28 15:39:18 -06:00
|
|
|
pre_pnr_testbench_dir_abspath = abspath(args.pre_pnr_testbench_dir_name) + "/prepnr/verilog_testbench";
|
2020-11-27 13:25:08 -06:00
|
|
|
|
|
|
|
# Count how many testbenches have been converted
|
|
|
|
num_converted_testbenches = 0
|
|
|
|
|
|
|
|
# Collect the pre-PnR testbenches to be converted
|
|
|
|
pre_pnr_testbench_files = []
|
2020-11-28 15:39:18 -06:00
|
|
|
|
|
|
|
# Add to list
|
|
|
|
for globbed_file in glob.glob(pre_pnr_testbench_dir_abspath + "/*_autocheck_top_tb.v"):
|
|
|
|
pre_pnr_testbench_files.append(globbed_file)
|
|
|
|
# If we have testbenches to convert, try to create the directory of post-pnr testbenches
|
|
|
|
post_pnr_testbench_dir_abspath = abspath(args.pre_pnr_testbench_dir_name) + "/postpnr/verilog_testbench";
|
2020-11-27 13:25:08 -06:00
|
|
|
|
|
|
|
logging.info("Found " + str(len(pre_pnr_testbench_files)) + " pre-PnR testbenches")
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Try to create the directory of post-pnr testbenches
|
|
|
|
#####################################################################
|
2020-11-28 15:39:18 -06:00
|
|
|
os.makedirs(post_pnr_testbench_dir_abspath, exist_ok=True)
|
2020-11-27 13:25:08 -06:00
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Convert pre-PnR testbenches to post-PnR testbenches
|
|
|
|
#####################################################################
|
|
|
|
logging.info("Converting pre-PnR testbench to post-PnR testbench...");
|
|
|
|
for curr_pre_pnr_testbench_file in pre_pnr_testbench_files:
|
2020-11-28 15:41:48 -06:00
|
|
|
logging.info("Processing " + curr_pre_pnr_testbench_file + " testbench:")
|
2020-11-27 13:25:08 -06:00
|
|
|
curr_post_pnr_testbench_file = re.sub("_autocheck_top_tb.v$", "_post_pnr_autocheck_top_tb.v", curr_pre_pnr_testbench_file)
|
2020-11-27 15:17:33 -06:00
|
|
|
curr_post_pnr_testbench_file = re.sub("\/prepnr\/", "\/postpnr\/", curr_post_pnr_testbench_file)
|
2020-11-30 23:41:29 -06:00
|
|
|
cmd = "python3 " + script_base_dir_abspath + "/post_pnr_testbench_converter.py " \
|
2020-11-27 13:25:08 -06:00
|
|
|
+ " --pre_pnr_testbench " + curr_pre_pnr_testbench_file \
|
|
|
|
+ " --post_pnr_testbench " + curr_post_pnr_testbench_file
|
|
|
|
subprocess.run(cmd, shell=True, check=True)
|
|
|
|
num_converted_testbenches += 1
|
2020-11-28 15:41:48 -06:00
|
|
|
logging.info("Done")
|
2020-11-27 13:25:08 -06:00
|
|
|
|
|
|
|
logging.info("\nConverted " + str(num_converted_testbenches) + " testbenches.")
|
2020-11-29 23:38:16 -06:00
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Convert post-PnR testbenches to wrapper testbenches
|
|
|
|
#####################################################################
|
|
|
|
logging.info("Converting pre-PnR testbench to post-PnR testbench...");
|
|
|
|
for curr_pre_pnr_testbench_file in pre_pnr_testbench_files:
|
|
|
|
curr_post_pnr_testbench_file = re.sub("_autocheck_top_tb.v$", "_post_pnr_autocheck_top_tb.v", curr_pre_pnr_testbench_file)
|
|
|
|
curr_post_pnr_testbench_file = re.sub("\/prepnr\/", "\/postpnr\/", curr_post_pnr_testbench_file)
|
2020-11-29 23:48:01 -06:00
|
|
|
curr_wrapper_testbench_file = re.sub("_autocheck_top_tb.v$", "_wrapper_autocheck_top_tb.v", curr_post_pnr_testbench_file)
|
2020-11-29 23:38:16 -06:00
|
|
|
logging.info("Processing " + curr_post_pnr_testbench_file + " testbench:")
|
2020-12-01 09:14:43 -06:00
|
|
|
cmd = "python3 " + script_base_dir_abspath + "/post_pnr_wrapper_testbench_converter.py " \
|
2020-11-29 23:38:16 -06:00
|
|
|
+ " --post_pnr_testbench " + curr_post_pnr_testbench_file \
|
|
|
|
+ " --pin_assignment_file " + args.pin_assignment_file \
|
|
|
|
+ " --wrapper_testbench " + curr_wrapper_testbench_file
|
|
|
|
subprocess.run(cmd, shell=True, check=True)
|
|
|
|
num_converted_testbenches += 1
|
|
|
|
logging.info("Done")
|
|
|
|
|
|
|
|
logging.info("\nConverted " + str(num_converted_testbenches) + " testbenches.")
|