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

Save GHDL args to JSON file #581

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion tests/unit/test_ghdl_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_elaborate_e_project(self):

self.assertEqual(
simif._get_command( # pylint: disable=protected-access
config, join("output_path", "ghdl"), True
config, join("output_path", "ghdl"), True, True, None
),
[
join("prefix", "ghdl"),
Expand Down
62 changes: 35 additions & 27 deletions vunit/sim_if/ghdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
import subprocess
import shlex
from json import dump
from sys import stdout # To avoid output catched in non-verbose mode
from warnings import warn
from ..exceptions import CompileError
Expand Down Expand Up @@ -234,7 +235,7 @@ def compile_vhdl_file_command(self, source_file):
cmd += [source_file.name]
return cmd

def _get_command(self, config, output_path, ghdl_e):
def _get_command(self, config, output_path, elaborate_only, ghdl_e, wave_file):
"""
Return GHDL simulation command
"""
Expand All @@ -251,24 +252,39 @@ def _get_command(self, config, output_path, ghdl_e):
"--workdir=%s" % self._project.get_library(config.library_name).directory
]
cmd += ["-P%s" % lib.directory for lib in self._project.get_libraries()]

bin_path = join(
output_path, "%s-%s" % (config.entity_name, config.architecture_name)
)
if self._has_output_flag():
cmd += [
"-o",
join(
output_path,
"%s-%s" % (config.entity_name, config.architecture_name),
),
]
cmd += ["-o", bin_path]
cmd += config.sim_options.get("ghdl.elab_flags", [])
cmd += [config.entity_name, config.architecture_name]

sim = config.sim_options.get("ghdl.sim_flags", [])
for name, value in config.generics.items():
sim += ["-g%s=%s" % (name, value)]
sim += ["--assert-level=%s" % config.vhdl_assert_stop_level]
if config.sim_options.get("disable_ieee_warnings", False):
sim += ["--ieee-asserts=disable"]

if wave_file:
if self._gtkwave_fmt == "ghw":
sim += ["--wave=%s" % wave_file]
elif self._gtkwave_fmt == "vcd":
sim += ["--vcd=%s" % wave_file]

if not ghdl_e:
cmd += config.sim_options.get("ghdl.sim_flags", [])
for name, value in config.generics.items():
cmd += ["-g%s=%s" % (name, value)]
cmd += ["--assert-level=%s" % config.vhdl_assert_stop_level]
if config.sim_options.get("disable_ieee_warnings", False):
cmd += ["--ieee-asserts=disable"]
cmd += sim
if elaborate_only:
cmd += ["--no-run"]
else:
try:
os.makedirs(output_path, mode=0o777)
except OSError:
pass
with open(join(output_path, "args.json"), "w") as fname:
dump({"build": cmd, "sim": sim}, fname)

return cmd

Expand All @@ -286,25 +302,17 @@ def simulate( # pylint: disable=too-many-locals

ghdl_e = elaborate_only and config.sim_options.get("ghdl.elab_e", False)

cmd = self._get_command(config, script_path, ghdl_e)

if elaborate_only and not ghdl_e:
cmd += ["--no-run"]

if self._gtkwave_fmt is not None and not ghdl_e:
if self._gtkwave_fmt is not None:
data_file_name = join(script_path, "wave.%s" % self._gtkwave_fmt)

if exists(data_file_name):
os.remove(data_file_name)

if self._gtkwave_fmt == "ghw":
cmd += ["--wave=%s" % data_file_name]
elif self._gtkwave_fmt == "vcd":
cmd += ["--vcd=%s" % data_file_name]

else:
data_file_name = None

cmd = self._get_command(
config, script_path, elaborate_only, ghdl_e, data_file_name
)

status = True
try:
proc = Process(cmd)
Expand Down