U
unfrostedpoptart
Guest
Hi all.
I had a great idea that should be simple but I can't get it to work. Don't know if it's SV, me, or Cadence's implementation.
Here's the idea:
Given a parameter with the size of a signal, automatically declare the signal.
parameter A_SZ=5;
// this would generate
logic [4:0] a;
parameter B_SZ=1; // single bit
logic b;
My idea was this:
`define BITRANGE(size) (size)>1 ? [(size-1):0] : /* single bit */
logic `BITRANGE(A_SZ) a;
This is just giving lots of errors. I don't know if I need to quote/escape some of this or if it's not possible (at least in ncverilog). Any ideas?
I actually want to get fancier with a second, optional parameter:
`define BITRANGE(size,lsb=0) (size)>1 ? [(size+lsb-1):lsb] : /* single bit */
logic `BITRANGE(A_SZ,5) a; // expand to logic [9:5] a;
It doesn't look like ncverilog supports default values for macro parameters at all!
Thanks,
David
I had a great idea that should be simple but I can't get it to work. Don't know if it's SV, me, or Cadence's implementation.
Here's the idea:
Given a parameter with the size of a signal, automatically declare the signal.
parameter A_SZ=5;
// this would generate
logic [4:0] a;
parameter B_SZ=1; // single bit
logic b;
My idea was this:
`define BITRANGE(size) (size)>1 ? [(size-1):0] : /* single bit */
logic `BITRANGE(A_SZ) a;
This is just giving lots of errors. I don't know if I need to quote/escape some of this or if it's not possible (at least in ncverilog). Any ideas?
I actually want to get fancier with a second, optional parameter:
`define BITRANGE(size,lsb=0) (size)>1 ? [(size+lsb-1):lsb] : /* single bit */
logic `BITRANGE(A_SZ,5) a; // expand to logic [9:5] a;
It doesn't look like ncverilog supports default values for macro parameters at all!
Thanks,
David