help on a complex macro

This is a discussion on help on a complex macro within the verilog forums in Programming Languages category; Hi, Can somebody explain what is m3 meant to be doing in this code? And before that, is it a valid verilog code? `define m1(a1,a2) a1 = a1 - a2; `define m2(a2,a3) (a2 * a3) `define m3(t) `" calling : `\`"m1(t)`\`"AND `\`m2(t)` \`"`" module mod; reg v1, v2, v3; always begin `m1(v1,v2); v3 = `m2(v1,v2); $display(`m3(v1)); end endmodule...

Go Back   Application Development Forum > Programming Languages > verilog

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-05-2008, 03:44 AM
very_very_log
Guest
 
Default help on a complex macro

Hi,
Can somebody explain what is m3 meant to be doing in this code?
And before that, is it a valid verilog code?

`define m1(a1,a2) a1 = a1 - a2;
`define m2(a2,a3) (a2 * a3)
`define m3(t) `" calling : `\`"m1(t)`\`"AND `\`m2(t)` \`"`"

module mod;
reg v1, v2, v3;
always begin
`m1(v1,v2);
v3 = `m2(v1,v2);
$display(`m3(v1));
end
endmodule
Reply With Quote
  #2  
Old 09-05-2008, 07:07 PM
sharp@cadence.com
Guest
 
Default Re: help on a complex macro

On Sep 5, 3:44*am, very_very_log <sgiitne...@gmail.com> wrote:
> Hi,
> Can somebody explain what is m3 meant to be doing in this code?
> And before that, is it a valid verilog code?
>
> `define m3(t) * * * `" calling : `\`"m1(t)`\`"AND `\`m2(t)` \`"`"


It is not valid Verilog code. It is SystemVerilog code.

The `" sequence turns into an ordinary quote after arguments have been
substituted (and presumably nested macros expanded, as this case
requires). If ordinary quotes were used, this would be a string
literal, and macro arguments and macro invocations would not be
recognized as such inside of it. This gives the same capability as
the C language macro "stringizing" operator, letting macros build
strings from pieces that include arguments.

The `\`" sequence turns into a \" in the resulting expansion. Inside
a string literal, that \" sequence means that there is a literal "
character inside the string.

The other SV macro extension is ``, which acts as a token delimiter
when looking for macro arguments, but is then discarded. This allows
you to connect the expansion of a macro argument to an identifier
without any spaces between them, building a larger identifier. This
gives the
same capability as the C language macro "token pasting" operator,
letting macros build identifiers from pieces that include arguments.

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 12:46 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.