EDAboard.com | EDAboard.eu | EDAboard.de | EDAboard.co.uk | RTV forum PL | NewsGroups PL

problem with parameterized macros

Ask a question - edaboard.com

elektroda.net NewsGroups Forum Index - Verilog Language - problem with parameterized macros

unfrostedpoptart
Guest

Sat Sep 03, 2011 6:01 am   



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

Steven Sharp
Guest

Sat Sep 03, 2011 6:26 am   



On Sep 3, 12:01 am, unfrostedpoptart <da...@therogoffs.com> wrote:
Quote:

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?

Macros are pure text substitution. Your ?: operator isn't going to be
evaluated by the macro substitution process to choose between two
pieces of text to insert; it will simply be inserted along with the
rest of the text. So your declaration will expand into

logic (A_SZ)>1 ? [(A_SZ-1):0] : a;

Which is completely invalid syntax.

Quote:
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!

I don't believe it does.

unfrostedpoptart
Guest

Sat Sep 03, 2011 6:44 am   



On Friday, September 2, 2011 9:26:16 PM UTC-7, Steven Sharp wrote:
Quote:
On Sep 3, 12:01 am, unfrostedpoptart <da...@therogoffs.com> wrote:

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?

Macros are pure text substitution. Your ?: operator isn't going to be
evaluated by the macro substitution process to choose between two
pieces of text to insert; it will simply be inserted along with the
rest of the text. So your declaration will expand into

logic (A_SZ)>1 ? [(A_SZ-1):0] : a;

Which is completely invalid syntax.

Thanks Steven. For some reason my brain had a blind spot and missed this.

Quote:

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!

I don't believe it does.

Sad

elektroda.net NewsGroups Forum Index - Verilog Language - problem with parameterized macros

Ask a question - edaboard.com

Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
RTV map EDAboard.com map News map EDAboard.eu map EDAboard.de map EDAboard.co.uk map Opony