Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cocotb verilator flow_tool option #409

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion edalize/flows/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: BSD-2-Clause

from edalize.flows.generic import Generic
import os


class Sim(Generic):
Expand All @@ -23,6 +24,8 @@ class Sim(Generic):
def configure_tools(self, flow):
if self.flow_options.get("cocotb_module"):
tool = self.flow_options.get("tool")
share_dir = os.popen("cocotb-config --share").read().rstrip() \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouild prefer evaluating cocotb-config --share directly like we do with cocotb-config --libdir. That makes the script more portable if we want to run it on a different machine than it was created on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by changing the share directory evaluation to a direct call in tools/verilator.py rather than a system call. see commit aa7d8c3.

+ "/lib/verilator/verilator.cpp"
cocotb_options = {
"icarus": (
"vvp_options",
Expand All @@ -37,6 +40,15 @@ def configure_tools(self, flow):
"vsim_options",
["-pli", "`cocotb-config --lib-name-path vpi questa`"],
),
"verilator": (
"verilator_options",
["--vpi",
"--public-flat-rw --prefix Vtop",
"-LDFLAGS \"-Wl,-rpath,`cocotb-config --lib-dir` -L`cocotb-config --lib-dir` \
-lcocotbvpi_verilator -lgpi -lcocotb -lgpilog -lcocotbutils\"",
f"{share_dir}"
],
),
}
(opt, val) = cocotb_options[tool]
self.edam["tool_options"][tool][opt] = (
Expand All @@ -53,4 +65,4 @@ def run(self, args=None):
(cmd, args, cwd) = run_tool.run()
cocotb_module = self.flow_options.get("cocotb_module")
env = {"MODULE": cocotb_module} if cocotb_module else {}
self._run_tool(cmd, args=args, cwd=cwd, env=env)
self._run_tool(cmd, args=args, cwd=cwd, env=env)
5 changes: 3 additions & 2 deletions edalize/tools/verilator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def setup(self, edam):
vc.append("-D{}={}".format(k, self._param_value_str(v)))

self.vc = vc

if self.edam["flow_options"].get("cocotb_module"):
self.toplevel = "top"
mk_file = f"V{self.toplevel}.mk"
exe_file = f"V{self.toplevel}"
commands = EdaCommands()
Expand Down Expand Up @@ -173,4 +174,4 @@ def run(self):
"xml-only",
]:
return
return ("./V" + self.toplevel, self.args, self.work_root)
return ("./V" + self.toplevel, self.args, self.work_root)