We could now make a simple tcl based flow.
A Modelsim script for adder example (vsim -c -do run.do):
# run.do
# General cocotb settings
exec cocotb-config --prefix > /tmp/cocotb-prefix
set COCOTB_DIR [string trim [read [open "/tmp/cocotb-prefix" r]]]
set VPI_LIB $COCOTB_DIR/cocotb/libs/modelsim/libcocotbvpi.so
set ::env(COCOTB_SIM) 1
set ::env(PYTHONPATH) ${COCOTB_DIR}/cocotb/libs/modelsim
# This test settings
set ::env(MODULE) test_adder
set ::env(PYTHONPATH) ./:../model:$::env(PYTHONPATH)
# Compile and run
vlog ../hdl/adder.v
vsim -pli $VPI_LIB adder
run -all
Should we add such flow under examples (can use Icarus in CI) or document it?
I ended up making a tcl package with some helper procedures that set the ::env vars and launch simulation with the right library.
Using TCLLIBPATH envar to point to the package folder, your script can then use package require cocotb and call the procedures. Keeps the script clean, and less brittle if the underlying details change.
You can get the output of exec directly, btw.
Also using file commands is platform agnostic:
if {[catch {set COCOTB_DIR [file normalize [exec cocotb-config --prefix]]}]} {
puts "cocotb-config failed to execute"
puts " $::errorInfo"
exit -code 1
}
set VPI_LIB [file join $COCOTB_DIR cocotb libs modelsim libcocotbvpi.so]
...
@garmin-mjames thank you for the hint.
I close in favor of https://github.com/cocotb/cocotb/issues/1718
Most helpful comment
You can get the output of exec directly, btw.
Also using file commands is platform agnostic: