>"The Verilog Preprocessor: Force for `good and `evil"
>
> http://www.veripool.org/papers
>
>It has lots of fun examples - did you know you could make
>hash tables in the preprocessor? Of main interest to this
>group are the portability issues it discusses. I intended
>to convert this section into specification proposals, but
>haven't gotten the chance yet. I'll try to send out at
>least a summary of the issues discovered.
From this paper I would suggest some of the following
corners in the preprocessor specification be addressed. I
think several existing implementations agree with me on #1
to #4 below, #5 to #7 may be more controversial and need
more work.
1. Specify `define may be used in the body of other
definitions, when so, the define takes effect at
substitution time (as normal with substitution text.)
// Note the newline is required in the DEF macro.
`define DODEF(d) d \
`define DEF2 DODEF(`define DEF 1)
// ...
`DEF2
// DEF is now defined
2. Specify `ifdef, `ifndef, `elif and `include may reference
another define indirectly.
`define DEFINED
`define INDIRECT(d) d
`ifdef `INDIRECT(DEFINED) ...
3. Specify that when `` creates a new token this may be a
new preprocessor token that is then recognized by the
preprocessor.
`define REPEAT(n,v) \
`REPEAT_``n(v)
`define REPEAT_1(d) d
`define REPEAT_2(d) `REPEAT_1(d)d
`REPEAT(2,"v ") // v v v
4. Specify that "expand embedded macros" includes expanding
lower level macros before substitution.
`define THRU(d) d
`define MSG(m) `"m`"
$display(`MSG(`THRU(hello)))
Simulators give conflicting results, some give "hello" and
some give "`thru(hello)" The former is probably more useful.
The correct behaviour is undefined, the specification says
only to "expand embedded macros"
5. Extension: Specify that when stringifying, newlines are
converted to spaces. Otherwise stringification of a
multiline macro may result in an error, because the quoted
result has a newline without a backslash escape.
`define MULTILINE line1 \
line2
`define MSG(m) `"m`"
$display(`MSG(`MULTILINE)) // line1 line2
6. Extension: Variable arguments to define, ALA C:
`define MSG(FMT, ...) $display(FMT ,`` `__VA_ARGS__)
7. Extension: Some method to allow `` expansion to be nested
as it can in the C preprocessor; see the paper for
motivation. IE
`define ZERO_0 0
`define NOTNOT(a) a
`define VALUE(a) `ZERO_```NOTNOT(a) // Not `` but a new operator?
`VALUE(0)
-> 0 // Would like this, but fails
-- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Mon, 25 Oct 2010 14:46:27 -0400 (EDT)
This archive was generated by hypermail 2.1.8 : Mon Oct 25 2010 - 11:49:13 PDT