#938 Support `define macro concatenation with ``

devel
closed-out-of-date
nobody
5
2014-09-08
2013-10-03
No

Summary: Support for the SystemVerilog concatenation operator `` in macros

Test case: (test.v)

`define CLOCK(name,speed) wire name; assign name = CLOCK_``speed``_Mhz

`CLOCK(P_CLK,100)

Current result:

$ iverilog -E test.v; cat a.out
test.v:5: warning: macro _Mhz undefined (and assumed null) at this point
        wire P_CLK; assign P_CLK = CLOCK_``100""

Expected result:

$ iverilog -E test.v; cat a.out
wire P_CLK; assign P_CLK = CLOCK_100_Mhz

Proposed patch:

diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex
index c4f37ed..a36dd82 100644
--- a/ivlpp/lexor.lex
+++ b/ivlpp/lexor.lex
@@ -1069,6 +1069,11 @@ static void def_finish()
         define_macro(def_argv(0), "", 0, def_argc);
     else
     {
+        /* Strip out '``' continuation marks */
+        char *cp;
+        while ((cp = strstr(define_text, "``")) != NULL) {
+            memmove(cp, cp+2, strlen(cp+2)+1);
+        }
         define_macro(def_argv(0), define_text, 0, def_argc);

         free(define_text);

Discussion

  • Cary R.
    Cary R.
    2013-10-03

    Jared has already submitted a patch that adds this functionality, but Steve and I have been too busy to apply it. Adding this correctly is possibly slightly more complicated then your patch since Icarus already uses `` to emit a string version of the macro. This is very handy during debug since you can see how a macro actually expands and display it using $display, etc.

    I will look at your suggested patch while applying the patch from Jared to make sure everything is covered correctly.

     
  • Thanks - I thought there was probably more to it for a 'standards complete' implementation, but I like to add my workaround as a reference implementation in my bugs.

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

    • status: open --> closed-out-of-date
     
  • Cary R.
    Cary R.
    2013-10-07

    I have applied and pushed the other patch that adds this functionality so I am closing this one as out of date.