Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SystemVerilog: How to specify array size using a constant?

1,646 views
Skip to first unread message

Andrew FPGA

unread,
Mar 16, 2010, 6:51:34 PM3/16/10
to
Hi SV and verilog folk,
I would like to specify an array range using a constant, for code
readability, etc reasons. Yet, the obvious results in a Questa 6.6
compile error. Surely SV supports such a basic thing as this somehow?
Any ideas on how I can do this?

e.g.
//declare a constant like this.
const uint8 NUM_1G_PORTS = 4;

//attempt to declare an array of objects
GMII_driver GMII_driver_port[0:NUM_1G_PORTS-1]; //line 175

Kaboom, Questa 6.6 chokes on it:
# ** Error: ../../top.sv(175): Range must be bounded by constant
expressions.

Bit frustrating. Been using SV for > 6 months now, using CRV, ABV,
abstract classes, virtual interfaces, mailboxes, queues, etc etc,.
Awesome. But I still can't get something as simple as this to work.

Of course the workaround is to just stick the constant value of 3 in
there. But I resent it deeply :(

(I suppose I could dynamically allocate...yes this is the best
workaround I have. But can I do it without having to use a dynamic
array, and call new?)

Cheers
Andrew

Marcus Harnisch

unread,
Mar 17, 2010, 3:29:02 PM3/17/10
to
Hi Andrew

Andrew FPGA <andrew.n...@gmail.com> writes:

> //declare a constant like this.
> const uint8 NUM_1G_PORTS = 4;
>
> //attempt to declare an array of objects
> GMII_driver GMII_driver_port[0:NUM_1G_PORTS-1]; //line 175
>
> Kaboom, Questa 6.6 chokes on it:
> # ** Error: ../../top.sv(175): Range must be bounded by constant
> expressions.

Constant values are not fixed at elaboration time. The array
declaration needs a known value though.

> Any ideas on how I can do this?

Use a parameter. Or good old `define.

--
Marcus Harnisch
http://www.doulos.com/

sh...@cadence.com

unread,
Mar 19, 2010, 1:47:41 PM3/19/10
to
On Mar 16, 6:51 pm, Andrew FPGA <andrew.newsgr...@gmail.com> wrote:
> Hi SV and verilog folk,
> I would like to specify an array range using a constant, for code
> readability, etc reasons. Yet, the obvious results in a Questa 6.6
> compile error. Surely SV supports such a basic thing as this somehow?
> Any ideas on how I can do this?

Use a parameter, not a const variable. A const variable is not a
compile-time constant. It is just a variable that you can't change
after it is initialized. Its value is set at runtime, and not even at
the start in some cases. A parameter or localparam is a compile-time
constant, and is what is required here.

0 new messages