#1267 Handle `", `\`", and `` in macro definitions.

closed-accepted
nobody
None
5
2013-10-07
2013-05-17
Jared Casper
No

Implements page 644 of IEEE 1800-2012.

`` is now overloaded with the Icarus-specific "stringify" expansions.
It is now used as indicated in 1800-2012 when appearing inside a macro
definition, and the Icarus way when not. To do so, it uses the fact
that istack->file is NULL iff we are processing expanded macro text,
which is a bit of hack but seems to work as is.

" and`" on the other hand are treated the same inside and outside of macro definitions.


The versions of VCS, NCVerilog, and ModelSim that I have didn't agree on the handling of these sequences outside of macros (they had spotty and inconsistent handling of these sequences in general). While the standard seems to indicate that these sequences should only be handled specially inside macro definitions, I have followed what VCS does and allowed them anywhere. This makes sense to me as it doesn't force me to define a macro to stringify a macro expansion (i.e. `foo can now also be written"foo" anywhere). I also did it this way to make the implementation cleaner. I initially had the " and`" actions only do the transformations if istack->file was NULL and just ECHO otherwise. However, the semantics of this wasn't clear, should it move into the CSTRING start condition? Doesn't seem like that was what was intended. In any case, passing it through as is would certainly result in a syntax error once it hit the compiler proper, so I don't think handling them outside of macro definitions eliminates a use case.

Comments or suggested changes are welcome, especially regarding the hack-ish check of istack->file == NULL, the handling of w.r.t. the Icarus meaning of, and the handling of " and`" outside of macro defintions.

1 Attachments

Discussion

  • Jared Casper
    Jared Casper
    2013-05-17

    D'oh, sourceforge ate a bunch of characters...

    Implements page 644 of IEEE 1800-2012.

    `` is now overloaded with the Icarus-specific "stringify" expansions. It is now used as indicated in 1800-2012 when appearing inside a macro definition, and the Icarus way when not. To do so, it uses the fact that istack->file is NULL iff we are processing expanded macro text, which is a bit of hack but works as is.

    `" and `\`" on the other hand are treated the same inside and outside of macro definitions.


    The versions of VCS, NCVerilog, and ModelSim that I have didn't agree on the handling of these sequences outside of macros (they had spotty and inconsistent handling of these sequences in general). While the standard seems to indicate that these sequences should only be handled specially inside macro definitions, I have followed what VCS does and allowed them anywhere. This makes sense to me as it doesn't force me to define a macro to stringify a macro expansion (i.e. ``foo can now also be written `"`foo`" anywhere). I also did it this way to make the implementation cleaner. I initially had the `" and `\`" actions only do the transformations if istack->file was NULL and just ECHO otherwise. However, the semantics of this wasn't clear, should it move into the CSTRING start condition? Doesn't seem like that was what was intended. In any case, passing it through as is would certainly result in a syntax error once it hit the compiler proper, so I don't think handling them outside of macro definitions eliminates a use case.

    Comments or suggested changes are welcome, especially regarding the hack-ish check of istack->file == NULL, the handling `` of w.r.t. the Icarus meaning of ``, and the handling of `" and `\`" outside of macro defintions.

     
  • Cary R.
    Cary R.
    2013-10-07

    • status: open --> closed-accepted
     
  • Cary R.
    Cary R.
    2013-10-07

    I have applied this patch and pushed it to master. I'm not certain I like the idea of " and`" working anywhere since the standard specifically states these are related to the macro text.

    It would also be nice to have some test code for these new features.