[sv-bc] Re: [sv-ec] Query regarding Macro substitution

From: Steven Sharp <sharp_at_.....>
Date: Thu Jun 29 2006 - 08:19:06 PDT
I just noticed that Kausik sent this to the EC instead of the BC, which
might explain why there was no reply.  This falls more within the BC area.
I don't have the original email any more, just my reply to it.

The issue is what should happen if the `` characters appear as part of
an escaped identifier.  By normal Verilog rules, those would just be part
of the escaped identifier name.  For complete backward compatibility, SV
would have to give the same answer.  But that would mean that there is
no way to use the `` token-pasting operation in a macro to create an
escaped identifier.  That seems undesirable.  It may be worthwhile to
give up the backward compatibility in the unlikely case that someone has
used `` inside a Verilog escaped identifier, to get the ability to build
an escaped identifier with ``.

In case this is not clear, consider an example macro

`define foo(x) \abc[``x``]

In Verilog, `foo(0) would expand into \abc[``x``].  In other words,
the `` characters would just be treated as part of the escaped identifier,
and so would the x.  If SystemVerilog is fully backward compatible with
Verilog in this case, it would also have to expand into that.  But the
desired goal here is probably to get it to expand into \abc[0] instead.
It may be worthwile to lose the ability to create an escaped identifier
that contains `` in order to gain the ability to build escaped identifiers
with token-pasting.


------------- Begin Forwarded Message -------------

X-Authentication-Warning: server.eda-stds.org: majordom set sender to 
owner-sv-ec@eda-stds.org using -f
Date: Wed, 28 Jun 2006 18:54:15 -0400 (EDT)
From: Steven Sharp <sharp@cadence.com>
Subject: Re: [sv-ec] Query regarding  Macro substitution 
To: sv-ec@eda-stds.org, kausikd@cal.interrasystems.com
MIME-Version: 1.0
Content-MD5: pgCHvfTIplNpqt4he3TYWw==
X-Received: By mx-sanjose2.Cadence.COM as k5SMtMZw028608 at Wed Jun 28 15:55:22 
2006
X-Virus-Scanned: ClamAV 0.88/1572/Wed Jun 28 07:49:41 2006 on 
server.eda-stds.org
X-Virus-Scanned: ClamAV 0.88/1572/Wed Jun 28 07:49:41 2006 on 
server.eda-stds.org
X-Virus-Status: Clean
X-pstn-levels: (S:73.07639/99.90000 R:95.9108 P:95.9108 M:96.8350 C:98.4741 )
X-pstn-settings: 3 (1.0000:1.0000) s gt3 gt2 gt1 r p m c 
X-pstn-addresses: from <sharp@cadence.com> [145/6] 
X-OriginalArrivalTime: 28 Jun 2006 22:55:22.0510 (UTC) 
FILETIME=[EFB07AE0:01C69B05]


>From: "Kausik Datta" <kausikd@cal.interrasystems.com>

>LRM is not clear about how "``" will be interpreted within escaped
>identifier.

Well, the behavior is already defined in Verilog.  If SV is supposed
to be backward compatible with Verilog, then it should get the same
answer as Verilog (even though that may not be what would be preferred).

An escaped identifier includes all characters up until the next
white space, and that includes ` characters.  Verilog will treat
the `` in both of your examples as part of the escaped identifier.
If SV is backward compatible with Verilog, then it will also treat
them as part of the escaped identifier, not as a token pasting
operation.  Otherwise it would get a different result than Verilog
for existing code.  This means that you cannot use a `` to paste
together two tokens to create an escaped identifier (which could
be an inconvenient limitation).

From your example VCS output, it looks like they are trying to
treat the `` as a token pasting operation, but only inside a macro
that has an argument.  The logic is presumably that token pasting
is only really useful if you have a macro argument to paste onto
an identifier.  If there are no arguments, then it follows the rules.
Or maybe there isn't any logic, and this inconsistent behavior is
just an accident in their code.

Steven Sharp
sharp@cadence.com


------------- End Forwarded Message -------------


Steven Sharp
sharp@cadence.com
Received on Thu, 29 Jun 2006 11:19:06 -0400 (EDT)

This archive was generated by hypermail 2.1.8 : Thu Jun 29 2006 - 08:19:16 PDT