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

From: Wilson Snyder <wsnyder@wsnyder.org>
Date: Tue Jun 22 2010 - 11:24:07 PDT

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 11:24:27 2010

This archive was generated by hypermail 2.1.8 : Tue Jun 22 2010 - 11:27:11 PDT