Repository: olofk/edalize (language: python)

Issue:
Add modelsim option prerun_tcl
This PR adds a new option for Modelsim which helps to execute Tcl scripts before simulation.

A very important use-cae is to disable the IEEE warnings. In Modelsim, this can either be done using the modelsim.ini or via Tcl commands. This Tcl commands have to be run right before simulation and not while compiling. This PR adds an option to specify a Tcl script which will be executed right before simulation starts.


Discussion / hints:
I have the same problem. Hope this pull request will be accepted in the near future.
@olofk Can you have a look on this topic? I'm sorry for pressure. :disappointed: 
Thank you for this patch. However, I would like to propose an alternative solution that doesn't require adding an extra option, and might also have other uses. In my limited testing, modelsim (or at least questasim) supports multiple do statements on the command line and it will execute them in order. So, how about just swapping order of the items on the command line, like ` $(VSIM) -c $(addprefix -pli ,$(VPI_MODULES)) $(EXTRA_OPTIONS) $(TOPLEVEL) -do "run -all; quit -code [expr [coverage attribute -name TESTSTATUS -concise] >= 2 ? [coverage attribute -name TESTSTATUS -concise] : 0]; exit"`

Then we can add the scripts we want as user files (in FuseSoC that would be e.g. `coverage.do : {file_type : user, copyto : .}`) and run it by adding `vsim_options : ["-do", "coverage.do"]`.

Would that work?
This would be a way better solution!

I will check this out and give you feedback in a new PR. :-)
Don't forget to rerun and update the tests if you submit a PR :)

Fix patch:
diff --git a/.gitignore b/.gitignore
index 3fd8a5f54..08786a20d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,4 +4,8 @@ __pycache__
 /.eggs
 /.tox
 .vscode/
-build/
\ No newline at end of file
+build/
+dist/
+venv/
+.project
+.pydevproject
\ No newline at end of file
diff --git a/edalize/modelsim.py b/edalize/modelsim.py
index 551228dd7..1646f7676 100644
--- a/edalize/modelsim.py
+++ b/edalize/modelsim.py
@@ -44,7 +44,7 @@
 all: work $(VPI_MODULES)
 
 run: work $(VPI_MODULES)
-	$(VSIM) -do "run -all; quit -code [expr [coverage attribute -name TESTSTATUS -concise] >= 2 ? [coverage attribute -name TESTSTATUS -concise] : 0]; exit" -c $(addprefix -pli ,$(VPI_MODULES)) $(EXTRA_OPTIONS) $(TOPLEVEL)
+	$(VSIM) -c $(addprefix -pli ,$(VPI_MODULES)) $(EXTRA_OPTIONS) -do "run -all; quit -code [expr [coverage attribute -name TESTSTATUS -concise] >= 2 ? [coverage attribute -name TESTSTATUS -concise] : 0]; exit" $(TOPLEVEL)
 
 run-gui: work $(VPI_MODULES)
 	$(VSIM) -gui $(addprefix -pli ,$(VPI_MODULES)) $(EXTRA_OPTIONS) $(TOPLEVEL)


Test patch:
diff --git a/tests/test_modelsim/Makefile b/tests/test_modelsim/Makefile
index 02d76e5b2..b5b8bdbde 100644
--- a/tests/test_modelsim/Makefile
+++ b/tests/test_modelsim/Makefile
@@ -33,7 +33,7 @@ EXTRA_OPTIONS ?= $(VSIM_OPTIONS) $(addprefix -g,$(PARAMETERS)) $(addprefix +,$(P
 all: work $(VPI_MODULES)
 
 run: work $(VPI_MODULES)
-	$(VSIM) -do "run -all; quit -code [expr [coverage attribute -name TESTSTATUS -concise] >= 2 ? [coverage attribute -name TESTSTATUS -concise] : 0]; exit" -c $(addprefix -pli ,$(VPI_MODULES)) $(EXTRA_OPTIONS) $(TOPLEVEL)
+	$(VSIM) -c $(addprefix -pli ,$(VPI_MODULES)) $(EXTRA_OPTIONS) -do "run -all; quit -code [expr [coverage attribute -name TESTSTATUS -concise] >= 2 ? [coverage attribute -name TESTSTATUS -concise] : 0]; exit" $(TOPLEVEL)
 
 run-gui: work $(VPI_MODULES)
 	$(VSIM) -gui $(addprefix -pli ,$(VPI_MODULES)) $(EXTRA_OPTIONS) $(TOPLEVEL)
diff --git a/tests/test_modelsim/vsim2.cmd b/tests/test_modelsim/vsim2.cmd
index 4d19a2ca9..ddb1073c2 100644
--- a/tests/test_modelsim/vsim2.cmd
+++ b/tests/test_modelsim/vsim2.cmd
@@ -1,1 +1,1 @@
--do run -all; quit -code [expr [coverage attribute -name TESTSTATUS -concise] >= 2 ? [coverage attribute -name TESTSTATUS -concise] : 0]; exit -c a few vsim_options -gvlogparam_bool=1 -gvlogparam_int=42 -gvlogparam_str=hello +plusarg_bool=1 +plusarg_int=42 +plusarg_str=hello top_module
+-c a few vsim_options -gvlogparam_bool=1 -gvlogparam_int=42 -gvlogparam_str=hello +plusarg_bool=1 +plusarg_int=42 +plusarg_str=hello -do run -all; quit -code [expr [coverage attribute -name TESTSTATUS -concise] >= 2 ? [coverage attribute -name TESTSTATUS -concise] : 0]; exit top_module