Skip to content

Commit

Permalink
verilator: Fix dependencies on testbench files in makefile
Browse files Browse the repository at this point in the history
The build is a two-stage process. First, the RTL files are "verilated"
into C++ files and a <project>.mk file is created. Then, the verilated
C++ files together with the testbench are compiled into an executable.

The Makefile generated by Edalize had a dependency on the testbench
files for the first step, but the testbench files are really only used
in the second step, so there was nothing to pick up the changes.
  • Loading branch information
olofk committed Apr 10, 2023
1 parent 573b1f0 commit 19736c9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
5 changes: 3 additions & 2 deletions edalize/tools/verilator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def setup(self, edam):
if not self._add_include_dir(f, incdirs):
vlog_files.append(f["name"])
elif file_type in ["cppSource", "systemCSource", "cSource"]:
depfile = False
if not self._add_include_dir(f, incdirs):
opt_c_files.append(f["name"])
elif file_type == "vlt":
Expand Down Expand Up @@ -109,7 +110,7 @@ def setup(self, edam):
"-G{}={}".format(k, self._param_value_str(v, str_quote_style='\\"'))
)
for k, v in self.vlogdefine.items():
vc.append("-D{}={}\n".format(k, self._param_value_str(v)))
vc.append("-D{}={}".format(k, self._param_value_str(v)))

self.vc = vc

Expand All @@ -128,7 +129,7 @@ def setup(self, edam):
commands.add(
["make", "-f", mk_file] + self.tool_options.get("make_options", []),
[exe_file],
[mk_file],
[mk_file] + opt_c_files,
)
commands.set_default_target(exe_file)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_tool_verilator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .edalize_tool_common import tool_fixture


def test_tool_verilator(tool_fixture):
tf = tool_fixture("verilator")

name = "design"

tf.tool.configure()
tf.compare_config_files(
[
name + ".vc",
]
)
9 changes: 9 additions & 0 deletions tests/tools/verilator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Auto generated by Edalize

all: Vtop_module

Vtop_module.mk: design.vc sv_file.sv vlog_file.v vlog05_file.v vlog_incfile another_sv_file.sv
$(EDALIZE_LAUNCHER) verilator -f design.vc

Vtop_module: Vtop_module.mk c_file.c cpp_file.cpp
$(EDALIZE_LAUNCHER) make -f Vtop_module.mk
19 changes: 19 additions & 0 deletions tests/tools/verilator/design.vc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--Mdir .
--cc
+incdir+.
-CFLAGS -I.
sv_file.sv
vlog_file.v
vlog05_file.v
another_sv_file.sv
--top-module top_module

--exe
c_file.c
cpp_file.cpp
-Gvlogparam_bool=1
-Gvlogparam_int=42
-Gvlogparam_str=\"hello\"
-Dvlogdefine_bool=1
-Dvlogdefine_int=42
-Dvlogdefine_str=hello

0 comments on commit 19736c9

Please sign in to comment.