Jump to content
ljepson74

string literal spanning a newline (using a backslash) - vendor supported?

Recommended Posts

A backslash can be used to extend a string literal onto the next line if "the new line is immediately preceded by a \ (backslash)."

    Section 5.9 of 1800-2012.pdf, the SystemVerilog LRM

 

I don't think I have ever been able to get this work and w/o looking I seem to recall it has been in Verilog/SystemVerilog for a while.

 

Can someone tell me if vendors support this and perhaps correct the code below on edaplayground?

 

example from LRM:

$display("Humpty Dumpty sat on a wall. \
Humpty Dumpty had a great fall.");

See example here (on Sept 29, urls below are updated in response to Tudor comment below.  thx.):

http://www.edaplayground.com/x/4Tyw 

https://www.edaplayground.com/x/4Tyw    //if the above does not work, try this one, with https://

Share this post


Link to post
Share on other sites

Thanks, Tudor and Dave.

*) I updated the urls, per Tudor comment.

*) Aldec and Mentor simulators were the two that I did not use.  I now tried Aldec on edaplayground and see that it works.  Unfortunately, with regards to this SV feature, I'm not using either of these simulators.  Can anyone confirm that neither Cadence nor Synopsys support this?  (Well, I guess I've figured out that they don't, now that I have witnessed at least one simulator support it.  Aldec's.)

 

 

Thanks.

Share this post


Link to post
Share on other sites

I think the problem is with EDAplayground.com appending extra characters at the end of each line. Look carefully at the error messages coming from each tool and you'll see a good explanation of the problem. I believe Aldec is incorrectly ignoring that extra character, so it appears that it is "working".

Share this post


Link to post
Share on other sites

Doulos/Victor, any thoughts?

Is your editor causing mischief and adding characters at the ends of lines?

 

Dave, I see your point now.  i.e. In edaplayground the error message seems to point to a space after the backslash.

Thanks.

Share this post


Link to post
Share on other sites

Yes, thanks Dave.  (I shouldn't assume everyone I've seen on here monitors all the threads.)

Feedback from Victor (the creator of edaplayground) on the edaplayground forum:

I've seen this before. The server uses "\r\n" DOS line endings, and some simulators don't grok these. The fix for EDA Playground would be to use "\n" line endings instead of "\r\n"
 
You can see this by using "Download files after run"

Share this post


Link to post
Share on other sites

From http://www.asic-world.com/systemverilog/literal_values4.html

 

    string  a;
    a = "This is multi line comment \n
         and this is second line";

    /*

    Outputs:

    a = This is multi line comment^M
            and this is second line

    */

//You will have ^M which is the dos character for new line. if you write to a file with this line. If you want to avoid that, then the next solution should be used

    string tmg ={" \n"                                               ,
        "//periodic signal intf.KEYCONTROL_CLK \n"         ,
        "fork\n"                                           ,
        "   begin\n"                                       ,
        "     the_clock = 0;\n"                            ,
        "     forever begin\n"                             ,
        "       if(the_clock == 0)\n"                      ,
        "          #(5000000/2 * 1ps);\n"                  ,
        "       else\n"                                    ,
        "          #((5000000-5000000/2) * 1ps);\n"        ,
        "       the_clock=~the_clock;\n"                   ,
        "     end\n"                                       ,
        "   end\n"                                         ,
        "join_none\n"};

        
        $display ( tmg);

 

Obviously, the second example is recommended

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×