Files
cheri-cap-lib/fusesoc/fusesoc-script.py
Ivan Ribeiro 06eff948d9 Fix bsv_src_root
files_root is actually the directory where the fusesoc command was
executed, but what we want here is the location of the python file being
executed so we can find the bluespec sources
2023-10-02 17:46:29 +01:00

125 lines
3.2 KiB
Python

import yaml
import subprocess
import argparse
import shutil
import os
import glob
# get yaml file location from single argument
argparser = argparse.ArgumentParser()
argparser.add_argument('yaml_file')
args = argparser.parse_args()
# load yaml file
with open(args.yaml_file, "r") as yamlfile:
try:
print(yamlfile)
yamlcfg = yaml.safe_load(yamlfile)
except yaml.YAMLError as exc:
print(exc)
# TODO debug
print(yamlcfg)
print(yamlcfg['parameters']['capwidth'])
# use capwidth if provided, or default to CAP64
cfgwidth = yamlcfg["parameters"]["capwidth"]
capwidth = "CAP64" if cfgwidth in [None, ""] else cfgwidth
# TODO debug
print("capwidth:")
print(capwidth)
# get current working directory for file generation
workdir = os.getcwd()
# location of source files is actually one level above the location of the core file
bsv_src_root = os.path.join(os.path.dirname(__file__), "..")
print("bsv_src_root")
print(bsv_src_root)
# set up bluespec command + arguments
bscargs = list()
bscargs.extend(["bsc"])
bscargs.extend(["-vdir", workdir])
bscargs.extend(["-bdir", workdir])
bscargs.extend(["-simdir", workdir])
bscargs.extend(["-D", "{}".format(capwidth)])
bscargs.extend(["-D", "RISCV"])
bscargs.extend(["-verilog"])
bscargs.extend(["-u"])
bscargs.extend(["CHERICapWrap.bsv"])
# TODO debug
print(bscargs)
# blocking call to bsc to generate verilog files
subprocess.call(bscargs, cwd=bsv_src_root)
print("CCL AUTOGEN NAME:")
print("cheri-cap-lib-verilog-autogen-{}.core".format(capwidth[3:]))
# collect verilog files
vfiles = glob.glob(os.path.join(os.getcwd(), "*.v"))
print("verilog files:")
print(vfiles)
# generate systemverilog files
subprocess.call(["python3", bsv_src_root + "/CHERICapWrap.py", "--generator", "sv"] + vfiles, cwd=workdir)
# collect systemverilog files and package files
pkgfiles = glob.glob(os.path.join(os.getcwd(), "*_pkg.sv"))
svfiles = glob.glob(os.path.join(os.getcwd(), "*.sv"))
#
# remove package files from systemverilog files
for pkgfile in pkgfiles:
svfiles.remove(pkgfile)
print("svfiles and pkgfiles:")
print(svfiles)
print(pkgfiles)
# write core file
with open("cheri-cap-lib-verilog-autogen-{}.core".format(capwidth[3:]), 'w') as f:
txt = 'CAPI=2:\n'
txt += 'name: "ucam:cheri:cheri-cap-lib-verilog-autogen-{}"\n'.format(capwidth[3:])
txt += 'description: "Autogenerated Verilog & SystemVerilog versions of the cheri-cap-lib functions"\n\n'
txt += 'filesets:\n'
txt += ' files_pkg:\n'
txt += ' files:\n'
txt += ' - '
txt += '\n - '.join([os.path.basename(file) for file in pkgfiles])
txt += '\n'
txt += ' file_type: systemVerilogSource\n'
txt += ' files_v:\n'
txt += ' files:\n'
txt += ' - '
txt += '\n - '.join([os.path.basename(file) for file in vfiles])
txt += '\n'
txt += ' file_type: verilogSource\n'
txt += ' files_sv:\n'
txt += ' files:\n'
txt += ' - '
txt += '\n - '.join([os.path.basename(file) for file in svfiles])
txt += '\n'
txt += ' file_type: systemVerilogSource\n'
txt += '\n'
txt += 'targets:\n'
txt += ' default:\n'
txt += ' description: "Default target that contains the Verilog files"\n'
txt += ' filesets:\n'
txt += ' - files_v\n'
txt += ' - files_pkg\n'
txt += ' - files_sv\n'
f.write(txt)