-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·178 lines (135 loc) · 6.16 KB
/
run.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python3
from os.path import join, dirname
from vunit import VUnit, VUnitCLI
import logging
import subprocess
import os
import glob
import multiprocessing
import json
logger = logging.getLogger(__name__)
class Module:
def __init__(self, name, d):
def get_as_list(key, is_file_list=True):
val_list = d.get(key,[])
if not isinstance(val_list, list):
val_list = [val_list]
ret_list = []
for item in val_list:
if is_file_list:
ret_list += glob.glob(join(self.path,item))
else:
ret_list.append(item)
# print('get_as_list ', key, ' ret=', ret_list)
return ret_list
self.name = name
self.library_name = d.get('library', None)
self.path = d.get('path', ".")
self.tb_files = get_as_list('tb_files')
files = get_as_list('files')
self.files = [f for f in files if not f in self.tb_files]
self.top = d.get('top', None)
self.tb_top = d.get('tb_top', None)
self.depends = get_as_list('depends', False)
self.tb_configs = d.get('tb_configs', [])
class Manifest:
def __init__(self, mani_dict):
modules = mani_dict['modules']
self.modules = {}
for id, m in modules.items():
self.modules[id] = Module(id, m)
@classmethod
def load_from_file(self, filename = 'Manifest.json'):
with open(filename, 'r') as file:
content = json.load(file)
return Manifest(content)
def get_module(self, mod_name):
return self.modules[mod_name]
def add_module(self, vu, module, libname, add_tb=True):
logger.info("add_module %s" % module.name)
lib_name = libname
if module.library_name:
lib_name = module.library_name
lib = vu.add_library(lib_name, allow_duplicate=True)
for file in module.files:
if not file in module.tb_files:
logger.info("adding file %s", file)
lib.add_source_files(file)
else:
logger.info("skipping file %s as it's provided as a testbench", file)
if add_tb and module.tb_top:
for tb in module.tb_files:
if not tb.endswith('.py'):
logger.debug("adding testbench file %s", tb)
lib.add_source_files(tb)
try:
testbench = lib.entity(module.tb_top)
if module.tb_configs:
for cfg in module.tb_configs:
testbench.add_config(str(cfg), cfg)
except:
logger.warning("Failed to get or configure testbench {} from VUnit".format(module.tb_top))
if module.depends != None:
for dep in module.depends:
self.add_module(vu, self.get_module(dep), libname, add_tb=False)
def module_files(self, module_name):
mod = self.get_module(module_name)
dep_files = mod.files
if mod.depends != None:
for dep in mod.depends:
dep_files += self.module_files(dep)
return dep_files
def synth_vivado(srcs, top):
tcl = join('vivado', 'vivado.tcl')
cmd = ["vivado", "-mode", "tcl", "-nojournal", "-source", tcl, "-tclargs", "3", "4"]
env={'VHDL_SRCS':(" ").join(srcs), 'TOP_MODULE':top}
env.update(dict(os.environ))
try:
proc = subprocess.Popen(cmd, env=env)
if proc.wait() != 0:
logger.error("There were some errors")
except ValueError as e:
print("got ", e)
exit(1)
if __name__ == '__main__':
cli = VUnitCLI()
cli.parser.add_argument('--module', action='append', dest='modules', default=None, help='set top module to <MODULE>')
cli.parser.add_argument('--synth', dest='synth', default=None, help='Synthesize using tool <TOOL>')
cli.parser.set_defaults(num_threads=multiprocessing.cpu_count())
args = cli.parse_args()
vu = VUnit.from_args(args=args)
vu.add_osvvm()
vu.add_verification_components()
# vu.enable_check_preprocessing()
# vu.enable_location_preprocessing()
manifest = Manifest.load_from_file()
ghdl_flags = ['--warn-reserved', '--warn-default-binding', '--warn-binding', '--warn-reserved', '--warn-nested-comment', '--warn-parenthesis', '--warn-vital-generic',
'--warn-delayed-checks', '--warn-body', '--warn-specs', '--warn-runtime-error', '--warn-shared', '--warn-hide', '--warn-unused', '--warn-others',
'--warn-pure', '--warn-static', '-fcolor-diagnostics', '-fdiagnostics-show-option', '-fcaret-diagnostics' ]
modules = []
if args.modules == None:
modules = manifest.modules.values()
else:
for m in args.modules:
if m in manifest.modules:
modules.append(manifest.modules.get(m))
else:
logger.error("Module {} not defined in Manifest".format(m))
exit(1)
for top_module in modules:
print(top_module.name, top_module.top, len(top_module.tb_files), top_module.tb_top)
if top_module.top:
manifest.add_module(vu, top_module, top_module.name + '_work' )
if args.synth != None:
file_list = manifest.module_files(top_module.name) # FIXME TODO
print("file-list: {}".format(file_list))
synth_vivado(srcs=file_list , top=top_module.top)
else:
if len(top_module.tb_files) > 0 and top_module.tb_top:
vu.set_sim_option("ghdl.elab_flags", ["-O3"] + ghdl_flags, allow_empty=True)
vu.main()
else:
logger.warning("top_module: {} does not have tb_files or tb_top set.. skipping".format(top_module.name))
print(top_module.top, len(top_module.tb_files), top_module.tb_top)
else:
logger.warning("top_module: {} no top.. skipping".format(top_module.name))