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

From: Greg Jaxon <Greg.Jaxon@synopsys.com>
Date: Tue Jun 22 2010 - 14:02:20 PDT
I am not convinced that what this testcase expects is LRM-specified behavior.

Personally I would have written:
`define REPEAT(n, d) `REPEAT_``n(d)
since that clearly forms the REPEAT_n macro's name  (during substitution of n)  before invoking it.

The LRM is not specific about whether the (first) actual argument (to `CONCAT) below
should be expanded before it is substituted or after.   Had the repeat count also been
suppplied by a macro definition
`define CNT 3
 `REPEAT(`CNT, $write...

you cannot get the desired result without expanding `CNT before substituting for n.

Greg Jaxon

Wilson Snyder wrote:
What is the expected result of this code, which uses `` to
build a macro name?  I'd like the answer to be "repeats: 1 1
1" to match the C preprocessor, but this doesn't seem to be
well supported.  Either way, a spec example stating the
behavior using `` to concatenate a define name would be
appreciated.

`define REPEAT_0(d)
`define REPEAT_1(d) d
`define REPEAT_2(d) `REPEAT_1(d)d
`define REPEAT_3(d) `REPEAT_2(d)d
`define REPEAT_4(d) `REPEAT_3(d)d
`define REPEAT_5(d) `REPEAT_4(d)d
`define REPEAT_6(d) `REPEAT_5(d)d
`define REPEAT_7(d) `REPEAT_6(d)d
`define REPEAT_8(d) `REPEAT_7(d)d
`define REPEAT_9(d) `REPEAT_8(d)d

`define CONCAT(a, b) a``b
`define REPEAT(n, d) `CONCAT(`REPEAT_, n)(d)

module t;
   initial begin
      $write("repeats: ");
      `REPEAT(3, $write("1 ");)
      $write("\n");
   end
endmodule

  

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean. Received on Tue Jun 22 14:02:40 2010

This archive was generated by hypermail 2.1.8 : Tue Jun 22 2010 - 14:05:34 PDT