Skip to content

Commit

Permalink
modelsim: ini options for GUI mode - now can setup with via "modelsim…
Browse files Browse the repository at this point in the history
….vsim_ini.gui" sim option
  • Loading branch information
alexrayne committed May 31, 2024
1 parent 2c0b75e commit 540bf48
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
21 changes: 21 additions & 0 deletions vunit/sim_if/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,27 @@ def fail():
except TypeError:
fail()

class DictOfStringOption(Option):
"""
Must be a dictinary of strings
"""

def validate(self, value):
def fail():
raise ValueError(f"Option {self.name!r} must be a dictionary of strings. Got {value!r}")

if not isinstance(value, dict):
fail()

try:
for name, elem in value.items():
if not is_string_not_iterable(name):
fail()
if not is_string_not_iterable(elem):
fail()
except TypeError:
fail()


class VHDLAssertLevelOption(Option):
"""
Expand Down
21 changes: 20 additions & 1 deletion vunit/sim_if/modelsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..ostools import Process, file_exists
from ..vhdl_standard import VHDL
from . import SimulatorInterface, ListOfStringOption, StringOption
from . import DictOfStringOption
from .vsim_simulator_mixin import VsimSimulatorMixin, fix_path

LOGGER = logging.getLogger(__name__)
Expand All @@ -41,6 +42,7 @@ class ModelSimInterface(VsimSimulatorMixin, SimulatorInterface): # pylint: disa
sim_options = [
ListOfStringOption("modelsim.vsim_flags"),
ListOfStringOption("modelsim.vsim_flags.gui"),
DictOfStringOption("modelsim.vsim_ini.gui"),
ListOfStringOption("modelsim.init_files.after_load"),
ListOfStringOption("modelsim.init_files.before_run"),
StringOption("modelsim.init_file.gui"),
Expand Down Expand Up @@ -232,6 +234,8 @@ def _create_load_function(self, test_suite_name, config, output_path):
"""
Create the vunit_load TCL function that runs the vsim command and loads the design
"""

self._vsim_extra_ini(config)

set_generic_str = " ".join(
(
Expand Down Expand Up @@ -329,7 +333,7 @@ def _create_run_function():
"""
Create the vunit_run function to run the test bench
"""
return """
tcl = """
proc _vunit_run_failure {} {
catch {
Expand Down Expand Up @@ -359,6 +363,7 @@ def _create_run_function():
restart -f
}
"""
return tcl

def _vsim_extra_args(self, config):
"""
Expand All @@ -371,6 +376,20 @@ def _vsim_extra_args(self, config):
vsim_extra_args = config.sim_options.get("modelsim.vsim_flags.gui", vsim_extra_args)

return " ".join(vsim_extra_args)

def _vsim_extra_ini(self, config):
if not self._gui:
return

cfg = parse_modelsimini(self._sim_cfg_file_name)

vsim_extra_ini = {}
vsim_extra_ini = config.sim_options.get("modelsim.vsim_ini.gui", vsim_extra_ini)
for name, val in vsim_extra_ini.items():
cfg.set("vsim", name, val)

write_modelsimini(cfg, self._sim_cfg_file_name)
return

def merge_coverage(self, file_name, args=None):
"""
Expand Down

0 comments on commit 540bf48

Please sign in to comment.