Skip to content

Commit

Permalink
Add initial cocotb support to the sim flow
Browse files Browse the repository at this point in the history
This adds a flow option called cocotb_module. Setting this enables
cocotb support. To begin with, cocotb support is only enabled for
the Icarus Verilog and ModelSim/QuestaSim tools.
  • Loading branch information
olofk committed May 27, 2023
1 parent c2389d3 commit e2c859a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion edalize/flows/edaflow.py
Expand Up @@ -311,7 +311,7 @@ def configure(self):
# Write out execution file
self.commands.write(os.path.join(self.work_root, "Makefile"))

def _run_tool(self, cmd, args=[], cwd=None, quiet=False):
def _run_tool(self, cmd, args=[], cwd=None, quiet=False, env={}):
logger.debug("Running " + cmd)
logger.debug("args : " + " ".join(args))

Expand All @@ -325,6 +325,7 @@ def _run_tool(self, cmd, args=[], cwd=None, quiet=False):
stderr=self.stderr,
capture_output=capture_output,
check=True,
env={**os.environ, **env},
)
except FileNotFoundError:
_s = "Command '{}' not found. Make sure it is in $PATH".format(cmd)
Expand Down
39 changes: 38 additions & 1 deletion edalize/flows/sim.py
Expand Up @@ -10,10 +10,47 @@ class Sim(Generic):

argtypes = ["plusarg", "vlogdefine", "vlogparam"]

FLOW_OPTIONS = {
**Generic.FLOW_OPTIONS,
**{
"cocotb_module": {
"type": "str",
"desc": "Cocotb test python module. (Enables Cocotb simulations)",
},
},
}

def configure_tools(self, flow):
if self.flow_options.get("cocotb_module"):
tool = self.flow_options.get("tool")
cocotb_options = {
"icarus": (
"vvp_options",
[
"-M",
"`cocotb-config --lib-dir`",
"-m",
"`cocotb-config --lib-name vpi icarus`",
],
),
"modelsim": (
"vsim_options",
["-pli", "`cocotb-config --lib-name-path vpi questa`"],
),
}
(opt, val) = cocotb_options[tool]
self.edam["tool_options"][tool][opt] = (
self.edam["tool_options"][tool].get(opt, []) + val
)

super().configure_tools(flow)

def run(self, args=None):
tool = self.flow_options.get("tool")
run_tool = self.flow.get_node(tool).inst

# Get run command from simulator
(cmd, args, cwd) = run_tool.run()
self._run_tool(cmd, args=args, cwd=cwd)
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)

0 comments on commit e2c859a

Please sign in to comment.