SystemVerilog enhances the TEXT-MACRO feature (a.k.a `define-s by many young engineers) of Verilog by a good length. Significant enhancements done are:
- Added capability to extend the definition to multiple lines
- Added macros with arguments;
- Macro arguments can have default values too! (not fully supported by all tools though)
However there are few caveats – in general any text-macro usage in any computer language is hard to debug when it fails to compile. So be ready to be patient while debugging macro code.
Recently an online forum user asked a question on SystemVerilog macros. Here is what the user defined to start with:
To a bare eye, the above looks fine. However a SV compiler would through an error at it. As per the LRM:
If formal arguments are used, the list of formal argument names shall be enclosed in parentheses following
the name of the macro. The left parenthesis shall follow the text macro name immediately, with no space in
between.
In other words – as it is with any Metro station sign, you should be careful with the GAP/spaces :-)
Notice that “extra space” after the macro name CHECK1 is now gone! This works in Questa 10.2.
So next time when you code your macros – mind the GAP :-)