Closed nrother closed 7 years ago
You should use the built-in m4 eval() macro in this situation. You can tell it to generate zero-padded hex output with additional parameters:
constant cname, eval(20+6, 16, 2)
evalh() is really just a convenience macro that does the same internally as well as masking the result to guarantee it won't exceed two digits:
define(`evalh', `eval((const2m4($1)) & 0xFF, 16, 2) ; $1')
The reason why evalh() and related don't work is that constants are converted into a call to the hidden const() macro which exposes Picoblaze level constant values to the m4 processor. evalh() appends a comment after the generated value showing the original expression to make assembled listings easier to interpret. That prevents it from being nested within other macros because m4 chokes on the comment when it is passed into const(). This needs to be documented since it isn't obvious that another macro is being invoked for the constant definition.
Ah, that's tricky. Thanks for documenting this!
I'm not sure if m4 supports this, but in this situation support for block comments would be great. This way you could embed the comment as intended, but without eating up the rest of the line.
You can configure m4 for block comments but not at the same time as an inline comment. It may be possible to craft the const() macro to strip off a comment in its value argument.
The following code (from the manual) fails
Error message:
The same happens when using
evald
instead ofevalh
. Usingeval
works, but produces the wrong result, obviously.