I want to create a macro with multiple parameters just like $display.
You can't. Verilog and SystemVerilog do not support variadic macros.
Here is a workaround if your goal is to use this for formatting strings or output, and you want to avoid having to type $sformat
all over the place. You can define the macro to have a single argument, and combine that argument with $sformat
. The caveat with doing this is that you must wrap the argument in parentheses when using the macro.
Note the ()
's for $sformatf
are not part of the macro:
`define format_macro(A) \
$write("%s", $sformatf A ); \
Then you can do this:
`format_macro(("a = %d", a))
`format_macro(("a = %d, b = %d", a, b))
BTW, there is an excellent screencast here which shows how to customize messaging in UVM. In it, the author shows this macro technique, along with some other nice tips if you're using UVM.