Skip to content

Commit de2a1bf

Browse files
committed
xcelium: Fixups and add tests
1 parent f11795d commit de2a1bf

File tree

6 files changed

+135
-19
lines changed

6 files changed

+135
-19
lines changed

edalize/tools/xcelium.py

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def setup(self, edam):
5757
has_system_verilog = True
5858

5959
# This file is a normal source file
60-
src_files.append(f["name"])
60+
src_files.append(f)
6161
unused_files.remove(f)
6262

6363
if file_type in self.TCL_SCRIPT_TYPES:
@@ -71,9 +71,6 @@ def setup(self, edam):
7171
self.edam = edam.copy()
7272
self.edam["files"] = unused_files
7373

74-
all_files = src_files + include_files + tcl_files + dpi_libraries
75-
self.src_files = src_files
76-
7774
# Append option flags
7875
en_64bit_cmd = [] if self.tool_options.get("32bit") else ["-64bit"]
7976
sv_cmd = ["-sv"] if has_system_verilog else []
@@ -88,7 +85,7 @@ def setup(self, edam):
8885
# Append TCL scripts
8986
tcl_cmd = []
9087
for tcl in tcl_files:
91-
tcl_cmd.append(["-input", tcl])
88+
tcl_cmd += ["-input", tcl]
9289

9390
# Append DPI libraries
9491
dpi_lib_cmd = []
@@ -104,43 +101,94 @@ def setup(self, edam):
104101
)
105102
)
106103

104+
# Append Verilog parameters
105+
vlogparam_cmd = []
106+
for k, v in self.vlogparam.items():
107+
val = self._param_value_str(v, str_quote_style='"')
108+
vlogparam_cmd.append(f"-defparam {self.toplevel}.{k}={val}")
109+
107110
# Append include directories
108111
incdir_cmd = ["+incdir+" + d for d in incdirs]
109112

110113
# Append top level module
111114
top_cmd = ["-top", self.toplevel]
112115

116+
prev_fileopts = ("", "", {})
117+
filegroups = []
118+
# Iterate over all relevant source files. If a file has
119+
# different file_type, logical_name or defines compared
120+
# to the previous file, we put it in a new file group
121+
for f in src_files:
122+
lib = f.get("logical_name", "")
123+
defines = f.get("define", {})
124+
file_type = f.get("file_type")
125+
fileopts = (file_type, lib, defines)
126+
if fileopts != prev_fileopts:
127+
filegroups.append((fileopts, []))
128+
filegroups[-1][1].append(f["name"])
129+
prev_fileopts = fileopts
130+
131+
files_cmd = []
132+
for fg in filegroups:
133+
# Ignore empty file groups
134+
if fg[1]:
135+
(_, lib, defines) = fg[0]
136+
if lib:
137+
files_cmd += ["-makelib", lib]
138+
for k, v in defines.items():
139+
files_cmd += ["-define", f"{k}={v}"]
140+
files_cmd += fg[1]
141+
if lib:
142+
files_cmd += ["-endlib"]
143+
144+
# This file seems to only be created after a successful build
145+
target = "xcelium.d/run.d/hdl.var"
146+
113147
# Prepare the simulation command
148+
# -enable_cmdline_define_redefinition is required to support file-specific defines
114149
self.commands.add(
115-
["xrun"]
116-
+ en_64bit_cmd
150+
[
151+
"xrun",
152+
"-elaborate",
153+
"-f",
154+
"xrun.f",
155+
"-enable_cmdline_define_redefinition",
156+
]
157+
+ files_cmd,
158+
[target],
159+
[f["name"] for f in src_files]
160+
+ include_files
161+
+ tcl_files
162+
+ dpi_libraries
163+
+ ["xrun.f"],
164+
)
165+
166+
self.xrun_f = (
167+
en_64bit_cmd
117168
+ sv_cmd
118-
+ timescale_cmd
119169
+ tcl_cmd
120170
+ dpi_lib_cmd
121171
+ macro_def_cmd
172+
+ vlogparam_cmd
122173
+ incdir_cmd
123174
+ top_cmd
124-
+ ["-f", "xrun.f"]
125-
+ self.tool_options.get("xrun_options", []),
126-
["run"],
127-
include_files + tcl_files + dpi_libraries + ["xrun.f"],
175+
+ self.tool_options.get("xrun_options", [])
128176
)
129-
130-
self.commands.set_default_target("run")
177+
self.commands.set_default_target(target)
131178

132179
def write_config_files(self):
133-
# Update f files to include all sources
134-
self.update_config_file("xrun.f", "\n".join(self.src_files) + "\n")
180+
print(self.xrun_f)
181+
# Keep all command-line options in xrun.f to detect build config changes
182+
self.update_config_file("xrun.f", "\n".join(self.xrun_f) + "\n")
135183

136184
def run(self):
137-
args = ["run"]
185+
args = ["-R"]
138186

139187
# Set plusargs
140188
if self.plusarg:
141189
plusargs = []
142190
for key, value in self.plusarg.items():
143191
plusargs += ["+{}={}".format(key, self._param_value_str(value))]
144-
args.append("EXTRA_OPTIONS=" + " ".join(plusargs))
192+
args += plusargs
145193

146-
return ("make", args, self.work_root)
194+
return ("xrun", args, self.work_root)

tests/test_tool_xcelium.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from .edalize_tool_common import tool_fixture
2+
3+
4+
def test_tool_xcelium(tool_fixture):
5+
6+
tool_options = {
7+
"32bit": True,
8+
"timescale": "2beardseconds/1fortnight",
9+
"xrun_options": ["some", "xrun", "options"],
10+
}
11+
12+
tf = tool_fixture("xcelium", tool_options=tool_options)
13+
14+
name = "design"
15+
16+
tf.tool.configure()
17+
tf.compare_config_files(
18+
[
19+
"xrun.f",
20+
]
21+
)
22+
23+
24+
def test_tool_xcelium_minimal(tool_fixture):
25+
tf = tool_fixture("xcelium", tool_options={}, paramtypes=[], ref_subdir="minimal")
26+
27+
name = "design"
28+
29+
tf.tool.configure()
30+
tf.compare_config_files(
31+
[
32+
"xrun.f",
33+
]
34+
)

tests/tools/xcelium/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Auto generated by Edalize
2+
3+
all: xcelium.d/run.d/hdl.var
4+
5+
xcelium.d/run.d/hdl.var: sv_file.sv vlog_file.v vlog_with_define.v another_sv_file.sv vlog_incfile tcl_file.tcl xrun.f
6+
$(EDALIZE_LAUNCHER) xrun -elaborate -f xrun.f -enable_cmdline_define_redefinition sv_file.sv vlog_file.v -define FD_KEY=FD_VAL vlog_with_define.v another_sv_file.sv
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Auto generated by Edalize
2+
3+
all: xcelium.d/run.d/hdl.var
4+
5+
xcelium.d/run.d/hdl.var: sv_file.sv vlog_file.v vlog_with_define.v another_sv_file.sv vlog_incfile tcl_file.tcl xrun.f
6+
$(EDALIZE_LAUNCHER) xrun -elaborate -f xrun.f -enable_cmdline_define_redefinition sv_file.sv vlog_file.v -define FD_KEY=FD_VAL vlog_with_define.v another_sv_file.sv

tests/tools/xcelium/minimal/xrun.f

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-64bit
2+
-sv
3+
-input
4+
tcl_file.tcl
5+
+incdir+.
6+
-top
7+
top_module

tests/tools/xcelium/xrun.f

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-sv
2+
-input
3+
tcl_file.tcl
4+
+define+vlogdefine_bool=1
5+
+define+vlogdefine_int=42
6+
+define+vlogdefine_str=""hello""
7+
-defparam top_module.vlogparam_bool=1
8+
-defparam top_module.vlogparam_int=42
9+
-defparam top_module.vlogparam_str="hello"
10+
+incdir+.
11+
-top
12+
top_module
13+
some
14+
xrun
15+
options

0 commit comments

Comments
 (0)