2021-03-12 21:02:57 +08:00
|
|
|
#!/usr/bin/env python3
|
2019-09-05 21:09:15 +08:00
|
|
|
from fusesoc.capi2.generator import Generator
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
2021-03-12 21:02:57 +08:00
|
|
|
import sys
|
2019-09-05 21:09:15 +08:00
|
|
|
import tempfile
|
2021-03-12 21:02:57 +08:00
|
|
|
if sys.version[0] == '2':
|
|
|
|
devnull = open(os.devnull, 'w')
|
|
|
|
else:
|
|
|
|
from subprocess import DEVNULL as devnull
|
2019-09-05 21:09:15 +08:00
|
|
|
|
|
|
|
class SwervConfigGenerator(Generator):
|
|
|
|
def run(self):
|
2021-03-12 21:02:57 +08:00
|
|
|
build_path="swerv_config"
|
|
|
|
script_root = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
|
2019-09-05 21:09:15 +08:00
|
|
|
files = [
|
2021-03-12 21:02:57 +08:00
|
|
|
{os.path.join(build_path, "common_defines.vh") : {
|
2019-09-05 21:09:15 +08:00
|
|
|
"copyto" : "config/common_defines.vh",
|
|
|
|
"file_type" : "systemVerilogSource"}},
|
2021-03-12 21:02:57 +08:00
|
|
|
{os.path.join(build_path, "pic_ctrl_verilator_unroll.sv") : {
|
2019-09-05 21:09:15 +08:00
|
|
|
"copyto" : "config/pic_ctrl_verilator_unroll.sv",
|
|
|
|
"is_include_file" : True,
|
|
|
|
"file_type" : "systemVerilogSource"}},
|
2021-03-12 21:02:57 +08:00
|
|
|
{os.path.join(build_path, "pic_map_auto.h") : {
|
2019-09-05 21:09:15 +08:00
|
|
|
"copyto" : "config/pic_map_auto.h",
|
|
|
|
"is_include_file" : True,
|
|
|
|
"file_type" : "systemVerilogSource"}}]
|
|
|
|
|
|
|
|
tmp_dir = os.path.join(tempfile.mkdtemp(), 'core')
|
2021-03-12 21:02:57 +08:00
|
|
|
shutil.copytree(script_root, tmp_dir)
|
2019-09-05 21:09:15 +08:00
|
|
|
|
|
|
|
cwd = tmp_dir
|
|
|
|
|
|
|
|
env = os.environ.copy()
|
|
|
|
env['RV_ROOT'] = tmp_dir
|
2021-03-12 21:02:57 +08:00
|
|
|
env['BUILD_PATH'] = build_path
|
2019-09-05 21:09:15 +08:00
|
|
|
args = ['configs/swerv.config'] + self.config.get('args', [])
|
2021-03-12 21:02:57 +08:00
|
|
|
rc = subprocess.call(args, cwd=cwd, env=env, stdout=devnull)
|
2019-09-05 21:09:15 +08:00
|
|
|
if rc:
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
filenames = []
|
|
|
|
for f in files:
|
|
|
|
for k in f:
|
|
|
|
filenames.append(k)
|
|
|
|
|
|
|
|
for f in filenames:
|
|
|
|
d = os.path.dirname(f)
|
|
|
|
if d and not os.path.exists(d):
|
|
|
|
os.makedirs(d)
|
|
|
|
shutil.copy2(os.path.join(cwd, f),f)
|
|
|
|
|
|
|
|
self.add_files(files)
|
|
|
|
|
|
|
|
g = SwervConfigGenerator()
|
|
|
|
g.run()
|
|
|
|
g.write()
|