Re: [sv-ec] comment in compiler macros

From: Steven Sharp <sharp_at_.....>
Date: Thu Jun 25 2009 - 15:40:31 PDT
Like Gord's implementation, ours has no trouble accepting this example
and treating it as it was intended: as a multi-line macro with comments
in it that don't mess up the line where it is substituted.

The reason for that LRM text was to prevent line comments in the macro
text from affecting the rest of the line where the macro is expanded.
For example

  `define FOO 1  // true
  
  if (`FOO) $display ("true");
  
You don't want this treated as

  if (1  // true) $display ("true");
  
where the comment on the macro affects the rest of the line.  The LRM
prevented this by saying that the comment was not part of the expanded
text.  With multi-line macros added to the language, we have to be more
careful how we interpret this LRM text, to get the desired result without
the strange results you suggest for your testcase.

The way that appears to work is to apply the backslash-newline first,
treating it as a line continuation.  Fortunately, the LRM says that this
is replaced with a newline in the expansion text.  This newline can then
serve to terminate the line comment, so that the characters between the
// and the newline can be discarded as a comment.  If the LRM had said
that the backslash-newline is replaced with a space, then neither order
would work.

One thing to keep in mind is that the LRM does not say that the comment
is not part of the macro text.  It says that if it is included in the
text (which indicates that it *is* part of the text), then it shall not
be part of the substituted text.  So first you determine what is part
of the macro text (which involves finding the first newline not preceded
by a backslash).  It may include line comments.  Then you determine the
substutution text, in which newlines preceded by backslashes are replaced
with newlines, and comments are not included.

Steven Sharp
sharp@cadence.com


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Thu Jun 25 15:43:30 2009

This archive was generated by hypermail 2.1.8 : Thu Jun 25 2009 - 15:44:20 PDT