# Which simulator is correctly interpreting these nested macros?

**URL:** <https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, macro-nested\
**Created:** [May 29, 2014, 3:01pm UTC](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532 "2014-05-29T15:01:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkc120](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/f05b48/32.png) [@jkc120](https://verificationacademy.com/forums/u/jkc120)\
**Post date:** [May 29, 2014, 3:01pm UTC](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/1 "2014-05-29T15:01:55Z")

</div>

I am trying to determine which of two simulators are doing “the right thing” with the following nested macro. Here’s a very simplified example:

```verilog
`define FOO foo
`define BAR bar
`define JOIN_ME( __prefix,__ name) __prefix``__ name
`define JOINED `JOIN_ME(`FOO, `BAR)
`define JOINED_STR `"`JOINED`"

module macro_test ();
initial begin
    #1;
    $display("JOINED_STR: %s", `JOINED_STR);
end
endmodule

```

I have one simulator that displays:

JOINED\_STR: foobar

While the other does the following:

JOINED\_STR: `JOIN\_ME(foo, bar)

Which is doing the right thing? Does the LRM have anything to say about such cases?

Thanks!

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [May 29, 2014, 5:52pm UTC](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/2 "2014-05-29T17:52:37Z")

</div>

I believe the correct behavior is

JOINED\_STR: foobar

The LRM says

> The macro text and argument defaults may contain usages of other text macros. Such usages shall be substituted after the outer macro is substituted, not when it is defined.

and

> An `" overrides the usual lexical meaning of " and indicates that the expansion shall include the quotation mark, substitution of actual arguments, and expansions of embedded macros. This allows string literals to be constructed from macro arguments.

The LRM committee discussion that explicitly adds the fact that the string must expand the embedded macros can be found here: [404](http://www.eda.org/svdb/view.php?id=1338)

---

<div class="post-metadata">

**Author:** ![jkc120](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/f05b48/32.png) [@jkc120](https://verificationacademy.com/forums/u/jkc120)\
**Post date:** [May 29, 2014, 6:22pm UTC](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/3 "2014-05-29T18:22:30Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/2):_

Thank you very much Dave. What’s concerning to me is that the simulator in question doing the “wrong” thing appears to continue to do the wrong thing despite the LRM clearly stating this and having done so for many years from the dates in the LRM committee discussion.

So, tool bug then?

Also, is there a way to work around this that would be simulator agnostic in the meantime?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [May 29, 2014, 7:01pm UTC](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/4 "2014-05-29T19:01:45Z")

</div>

_In reply to [jkc120](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/3):_

Difficult for me to suggest a workaround without knowing why you needed these nested macros in the first place.

---

<div class="post-metadata">

**Author:** ![jkc120](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/f05b48/32.png) [@jkc120](https://verificationacademy.com/forums/u/jkc120)\
**Post date:** [May 29, 2014, 7:50pm UTC](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/5 "2014-05-29T19:50:57Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/4):_

Without going into too much detail (that I wouldn’t be permitted to post here anyway), basically I noticed this particular bug in the simulator due to this construct used in the testbench I was given:

`define JOIN( __prefix,__ name) __prefix``__ name ... `define TRACKER\_SUFFIX .trk  
`define TRACKER_FILE `JOIN(`TEST_FILE,`TRACKER\_SUFFIX)  
`define TRACKER_FILE_STRING `“`TRACKER_FILE`”

`TRACKER_FILE_STRING is used later to write out the tracker .trk file, which should be test1.sv.trk for example, but with the one simulator we get files with: `JOIN(test1.sv,.trk?)? instead of test1.sv.trk

Thanks!

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [May 29, 2014, 8:32pm UTC](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/6 "2014-05-29T20:32:26Z")

</div>

_In reply to [jkc120](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/5):_

How about

```verilog
`define FOO foo
`define BAR bar
`define JOIN_ME( __prefix,__ name) __prefix``__ name
`define QUOTE(_me) `"_me`"
`define JOINED `JOIN_ME(`FOO, `BAR)
`define JOINED_STR `QUOTE(`JOINED)
 
module macro_test ();
initial begin
    #1;
    $display("JOINED_STR: %s", `JOINED_STR);
end
endmodule

```

---

<div class="post-metadata">

**Author:** ![jkc120](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/f05b48/32.png) [@jkc120](https://verificationacademy.com/forums/u/jkc120)\
**Post date:** [May 29, 2014, 8:52pm UTC](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/7 "2014-05-29T20:52:01Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/which-simulator-is-correctly-interpreting-these-nested-macros/29532/6):_

Unfortunately, it still doesn’t work:

JOINED\_STR: `JOIN\_ME(foo, bar)

It seems this vendor’s simulator is simply not compliant to the LRM for `"

I guess at this point I have no recourse but to wait for them to fix the bug?

Thank you for your time!
