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

From: Surya Pratik Saha <spsaha@cal.interrasystems.com>
Date: Wed Jun 23 2010 - 21:00:42 PDT
Hi,
I agree with Greg regarding his comment "it was a mistake to pass `REPEAT_ as a macro actual argument.". Otherwise for the following case it is not sure what should be expected result:

`define MAC_0 0
`define MAC_ 1
`define MAC(a, b) a``b
module top;
    int x;
    initial begin
        x = `MAC(`MAC_, 0);
        $display("%d", x);
    end
endmodule

Will it be '0' or '10'.

Regards
Surya


-------- Original Message  --------
Subject: Re:[sv-bc] Expected behavior of macro concatenation of macro
From: Greg Jaxon <Greg.Jaxon@synopsys.com>
To: Wilson Snyder <wsnyder@wsnyder.org>
Cc: "sv-bc@eda.org" <sv-bc@eda.org>
Date: Wednesday, June 23, 2010 10:19:09 PM
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.


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

This archive was generated by hypermail 2.1.8 : Wed Jun 23 2010 - 21:05:00 PDT