when expanding preprocessor macros, iverilog 0.9.7 does a sed-style text substition of macro parameter names to values instead of replacing the tokens only.
This is a problem when other tokens contain macro parameter names. Consider
define DECLAREINT(name, i) integer name=iDECLAREINT(bar, 2);
When substituting tokens, (as verilator does) this expands to:
integer bar=2;
When substituting text, as iverilog does, it expands to:
2nteger bar= 2;
(Note that both compilers be called with -E to just precompile.)
Unsurprisingly, this does not compile.
While it is easy to work around this bug if one is aware of it (just rename i to something more unique), there may also exist cases where the bug will cause code to be compiled wrong, possibly leading to debugging headaches.
The bug also only seems to appear if the macro parameter is the prefix of another token, if the other token just contains the macro parameter (such as 'r' in 'integer', no substitution appears.)
Sorry, the bugtracker ate my backticks. Sample file attached.
Actually no, the preprocessor does attempt to do token replacement (try replacing "i" with "n" in your example) - you've just found the corner case where it doesn't work!
Also present in development, where it will be fixed first.
I've pushed a fix for this to github in both the development and v0.9 branches.
Thanks for reporting this.