Skip to content

Commit

Permalink
Added vunit_tb_name for modelsim, riviera and activehdl
Browse files Browse the repository at this point in the history
Create 1033.feature.rst
  • Loading branch information
maleiter authored and LarsAsplund committed Jun 22, 2024
1 parent 127da15 commit ba1f56e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/news.d/1033.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Riviera-PRO, ModelSim/Questa, Active-HDL] Defined the TCL variable ``vunit_tb_name`` as the name of the top level design unit during the evaluation of the ``<simulator>.init_file`` scripts for Active-HDL, Riviera-PRO and ModelSim/Qusta.
[Active-HDL] Defined the TCL variable ``vunit_tb_path`` during the evaluation of the ``activehdl.init_file.gui`` script.
7 changes: 7 additions & 0 deletions docs/py/opts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ The following simulation options are known.
using the ``vsim`` command.
During script evaluation the ``vunit_tb_path`` variable is defined
as the path of the folder containing the test bench.
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
Must be a list of strings.

``modelsim.init_files.before_run``
Expand All @@ -136,6 +137,7 @@ The following simulation options are known.
For example this can be used to configure the waveform viewer.
During script evaluation the ``vunit_tb_path`` variable is defined
as the path of the folder containing the test bench.
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
Must be a string.

``rivierapro.vsim_flags``
Expand All @@ -153,6 +155,7 @@ The following simulation options are known.
using the ``vsim`` command.
During script evaluation the ``vunit_tb_path`` variable is defined
as the path of the folder containing the test bench.
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
Must be a list of strings.

``rivierapro.init_files.before_run``
Expand All @@ -166,6 +169,7 @@ The following simulation options are known.
For example this can be used to configure the waveform viewer.
During script evaluation the ``vunit_tb_path`` variable is defined
as the path of the folder containing the test bench.
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
Must be a string.

``activehdl.vsim_flags``
Expand All @@ -180,6 +184,9 @@ The following simulation options are known.
``activehdl.init_file.gui``
A user defined TCL-file that is sourced after the design has been loaded in the GUI.
For example this can be used to configure the waveform viewer.
During script evaluation the ``vunit_tb_path`` variable is defined
as the path of the folder containing the test bench.
Additionally, the ``vunit_tb_name`` variable is defined as the name of the test bench.
Must be a string.

``ghdl.elab_flags``
Expand Down
8 changes: 6 additions & 2 deletions vunit/sim_if/activehdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,20 +460,24 @@ def _create_batch_script(common_file_name, load_only=False):
def _create_user_init_function(self, config):
"""
Create the vunit_user_init function which sources the user defined TCL file in
simulator_name.init_file.gui
simulator_name.init_file.gui.
Also defines the vunit_tb_path and the vunit_tb_name variable.
"""
opt_name = self.name + ".init_file.gui"
init_file = config.sim_options.get(opt_name, None)
tcl = "proc vunit_user_init {} {\n"
if init_file is not None:
tcl += f'set vunit_tb_name {config.design_unit_name}\n'
tcl += f'set vunit_tb_path {fix_path(str(Path(config.tb_path).resolve()))}\n'
tcl += f'source "{fix_path(str(Path(init_file).resolve()))!s}"\n'
tcl += " return 0\n"
tcl += "}\n"
return tcl

def _create_gui_script(self, common_file_name, config):
"""
Create the user facing script which loads common functions and prints a help message
Create the user facing script which loads common functions and prints a help message.
Also defines the vunit_tb_path and the vunit_tb_name variable.
"""

tcl = ""
Expand Down
4 changes: 4 additions & 0 deletions vunit/sim_if/vsim_simulator_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ def _source_tcl_file(file_name, config, message):
"""
Create TCL to source a file and catch errors
Also defines the vunit_tb_path variable as the config.tb_path
and the vunit_tb_name variable as the config.design_unit_name
"""
template = """
set vunit_tb_path "%s"
set vunit_tb_name "%s"
set file_name "%s"
puts "Sourcing file ${file_name} from %s"
if {[catch {source ${file_name}} error_msg]} {
Expand All @@ -246,6 +249,7 @@ def _source_tcl_file(file_name, config, message):
"""
tcl = template % (
fix_path(str(Path(config.tb_path).resolve())),
config.design_unit_name,
fix_path(str(Path(file_name).resolve())),
message,
)
Expand Down

0 comments on commit ba1f56e

Please sign in to comment.