Warm tip: This article is reproduced from serverfault.com, please click

Recursively compile files in a directory using Modelsim and a TCL script

发布于 2020-12-11 16:40:48

I use modelsim to simulate my HDL designs. I would like to build a script-based workflow so that I don't have to use the GUI and can simulate faster.

My typical directory tree is:

rtl/
  includes/
  module1/
  module2/

What I need to do is to compile all the .sv and .vhd files that might be in the rtl folder and load the design in modelsim.

I have a scheleton for my script which is:

quit -sim
vdel -all -lib work
vlib work
vmap work work

# compile systemverilog
vlog -work work -svinputport=net rtl/file1.sv
vlog -work work -svinputport=net rtl/module1/file2.sv

# compile vhdl
vcom -work rtl/file3.vhd
vcom -work rtl/module2/file4.vhd

# Load design
vsim work.top_name -voptargs=+acc

run -all

What I would like to do is to automate the search for .sv and .vhd file and compile them in correct order. A basic solution I tried, uses a foreach loop:

 foreach file [fileutil::findByPattern $basepath *.sv] {
    vlog -work work -svinputport=net $file
  }

But modelsim is not happy with this as file may be not always compiled in correct order. Any hint would be appreciated, thanks in advance.

Andrea

Questioner
a_bet
Viewed
0
dave_59 2020-12-12 04:08:12

It's not possible to automatically order SystemVerilog files unless you establish some coding conventions. Macros and other compiler directives are sensitive to compilation order and there are too many cases where the only way to handle it with an explicitly ordered file list. With macros, you typically typically use `include "file.svh" where ever the macros are needed, and the file.svh does not wind up on the command line.

Package references require parsing the file, and if the only reference to a package is via an import statement, you might be able to write a script to build a dependency list by parsing through all the files.

But most people just manually create files that have the necessary files in the correct order. This will alway be more efficient because the files only need to be parsed once in the correct order.