-
Notifications
You must be signed in to change notification settings - Fork 5
/
sim
executable file
·148 lines (116 loc) · 4.63 KB
/
sim
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
#!/usr/bin/env python
########################################################################
##
## Copyright 2015 PMC-Sierra, Inc.
##
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License. You may
## obtain a copy of the License at
## http://www.apache.org/licenses/LICENSE-2.0 Unless required by
## applicable law or agreed to in writing, software distributed under the
## License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
## CONDITIONS OF ANY KIND, either express or implied. See the License for
## the specific language governing permissions and limitations under the
## License.
##
########################################################################
########################################################################
##
## Author: Logan Gunthorpe
##
## Description:
## Script to take care of running a simulation.
##
########################################################################
from __future__ import print_function
from __future__ import unicode_literals
import os
import sys
import glob
import subprocess as sp
import time
PROJ_NAME = "textswap" # Name of the project, top c code, and the associated RTL directory
ROOT = os.path.dirname(os.path.realpath(__file__))
LIBCAPI = os.path.join(ROOT, "libs", "capi")
sys.path.insert(0, os.path.join(LIBCAPI, "scripts"))
import build
import colour as cl
NCVLOG_ARGS = ["-SV"]
NCVHDL_ARGS = ["-V200X", "-SMARTORDER"]
NCELAB_ARGS = ["-ACCESS", "+rwc", "-TIMESCALE", "1ns/1ns"]
waf_conf = build.load_waf_cache()
PSLSE_SRC = waf_conf['PSLSE_DIR']
AFU_DRIVER = os.path.join(PSLSE_SRC, "afu_driver")
if not os.path.exists(AFU_DRIVER):
print(cl.red("Cannot find afu_driver source, is the project "
"configured for simulation?"))
sys.exit(-1)
AFU_SRC = os.path.join(AFU_DRIVER, "src")
AFU_DRIVER_RTL = glob.glob(os.path.join(AFU_DRIVER, "verilog", "*.v"))
CAPI_VHDL_SRCS = glob.glob(os.path.join(LIBCAPI, "rtl", "*.vhd"))
VLOG_SRCS = glob.glob(os.path.join(ROOT, "rtl", "*.v")) + AFU_DRIVER_RTL
VHDL_SRCS = glob.glob(os.path.join(ROOT, "rtl", "*.vhd"))
BSUB = ["bsub", "-Ip", "-q", "sim"]
def do_build(**kwopts):
if kwopts.get("no_build", False):
return
build.run_waf(ROOT, **kwopts)
build.hdl.make_libraries("capi")
build.hdl.compile_vhdl(CAPI_VHDL_SRCS, ncvhdl_args=NCVHDL_ARGS,
work="capi", **kwopts)
build.hdl.compile_verilog(VLOG_SRCS, ncvlog_args=NCVLOG_ARGS, **kwopts)
build.hdl.compile_vhdl(VHDL_SRCS, ncvhdl_args=NCVHDL_ARGS, **kwopts)
build.run_make(AFU_SRC, log_file_name="afu_driver.log", **kwopts)
build.hdl.elaborate("work.top", ncelab_args=NCELAB_ARGS, **kwopts)
if __name__ == "__main__":
import optparse
if "--" in sys.argv:
x = sys.argv.index("--")
myargs = sys.argv[:x]
capiargs = sys.argv[x+1:]
else:
myargs = sys.argv
capiargs = []
parser = optparse.OptionParser()
parser.add_option("-e", "--exe", action="store", default=PROJ_NAME,
help="run specified executable")
parser.add_option("-B", "--no-build", action="store_true",
help="don't build, just run")
parser.add_option("--build", action="store_true",
help="don't run, just build")
build.options(parser)
options, args = parser.parse_args()
kwopts = options.__dict__
build.append_environ("LD_LIBRARY_PATH", os.path.abspath(AFU_SRC))
build.chdir(**kwopts)
build.gen_pslse_params(PAGED_PERCENT=0,
TIMEOUT=2)
try:
do_build(**kwopts)
if options.build:
sys.exit(0)
hdl_sim = build.hdl.Simulate("work.top", bsub=BSUB, **kwopts)
with hdl_sim:
sim = build.CapiRunner("./" + options.exe, hdl_sim,
args=capiargs, **kwopts)
sim.start()
exit_code = sim.wait()
if exit_code:
print(cl.red("capi sim exited with non-zero status code: %d" %
exit_code))
sys.exit(exit_code)
except KeyboardInterrupt:
pass
except sp.CalledProcessError as e:
print(cl.red(str(e)))
sys.exit(e.returncode)
except OSError as e:
print(cl.red(str(e)))
print(cl.red("Ensure you have sourced setup_tools!"))
sys.exit(10)
except IOError as e:
print(cl.red("ERROR: " + str(e)))
sys.exit(11)
except build.SystemSimException as e:
print(cl.red("ERROR: " + str(e)))
sys.exit(12)