user123577
user123577

Reputation: 121

Undefined global variable when using QuestaSim

I have a variable defined in foo_const.v which is defined like this in foo_const.v:

localparam NUM_BITS = 32;

Then I have another file foo_const_slice.v which does this:

localparam SLICE_ADDR_BITS = NUM_BITS;

This compiles fine with the vcs command:

vcs -sverilog foo_const.v foo_const_slice.v

But when I try to use QuestaSim:

vlog -work work -sv foo_const.v foo_const_slice.v

I get the following error message:

** Error: foo_const_slice.v(46): (vlog-2730) Undefined variable: 'NUM_BITS'.

Upvotes: 0

Views: 992

Answers (1)

dave_59
dave_59

Reputation: 42698

The problem is that by default, each file that vlog compiles goes into a separate compilation unit, just like C/C++ and many other languages. By default, vcs concatenates all files together into a single compilation unit.

Although there is a way to change the default (you can look it up in the user manual), the proper way to code this is to put your parameters in a package, and import the package where needed.

Dave

Upvotes: 2

Related Questions