Re: [sv-bc] Expected behavior of macro concatenation of macro

From: Greg Jaxon <Greg.Jaxon@synopsys.com>
Date: Wed Jun 23 2010 - 09:49:09 PDT
Wilson Snyder wrote:
Can we rewrite REPEAT (preferrably with an existing
simulator, or at least in a way that *might* be next-spec
compliant) so that this will work:

`REPEAT(`FUNC(n), d)

Or this

`REPEAT(`REPEAT(n,foo), d)
Using my suggested `define of  REPEAT,
My preprocessor yields the following:

`REPEAT(`REPEAT(n,foo), d )
`REPEAT_`REPEAT_n(foo)(d)
^^^^^^^^
Error:  ./svpp4.sv:18: The macro 'REPEAT_' has not been defined. (VER-913)
xpand the actual argument macro invocation at the point
when it is used in a formal substitution.
    

Yes, I think that's the right track.
  
For this reason, I think it was a mistake to pass `REPEAT_ as a macro actual argument.
You can use `CONCAT(REPEAT_,n) to form the identifier, but you don't want to
invoke that identifier until after it has been formed.  So the macro tic mark has to apply
to the result of another macro expansion.  That is not a feature mentioned in the LRM, and
I know of at least one preprocessor in which it is missing.

`define REPEAT( n, d ) ` ` CONCAT ( REPEAT_ , n ) ( d )  // not universally supported
probably should work, but its equivalent:
`define REPEAT( n, d ) `REPEAT_``n(d)
is guaranteed to work because it resembles the examples of section 22.5.1

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean. Received on Wed Jun 23 09:49:27 2010

This archive was generated by hypermail 2.1.8 : Wed Jun 23 2010 - 09:52:03 PDT