So I was writing some verilog in quartus and wondering why the heck it was misbehaving.
I eventually discovered the problem was some constants where I had inadvertantly used a backtick instead of a single quote. For example I had 32`hdeadbeef
instead of 32'hdeadbeef
.
What I find surprising is that this compiled, did I find a bug in quartus? is this some obscure bit of verilog syntax? if so what does it mean?
2 Answers 2
I have just been reading the IEEE standard about macro's and defines. There is nothing in there which says that the macro name must be known. (In your case `hdeadbeef would not match any define).
However I can imagine them not defining that as that would be too far fetched.
Using common sense I would say it is a bug in the parser.
Speculating:
The following is allowed:
`ifdef this_variable_is_not_defined
So maybe the code for that got also used for `this_macro_does_not_exist
-
\$\begingroup\$ It does seem quite plausible that it is treating the unknown macro as an empty string and then treating the number that was supposed to represent the width as a straight decimal constant of default width. \$\endgroup\$Peter Green– Peter Green2018年03月09日 19:35:39 +00:00Commented Mar 9, 2018 at 19:35
-
\$\begingroup\$ That is what I was assuming. Just tried it in Vivado but there I get an error message. \$\endgroup\$Oldfart– Oldfart2018年03月09日 19:38:06 +00:00Commented Mar 9, 2018 at 19:38
-
\$\begingroup\$ I haven't tried Vivado but I have noticed in the past that Quartus is a lot less strict about Verilog than Modelsim is. \$\endgroup\$Peter Green– Peter Green2018年03月09日 19:42:28 +00:00Commented Mar 9, 2018 at 19:42
-
1\$\begingroup\$ The LRM says "After a text macro is defined, it can be used in the source description by using the (`` ` ``) character, followed by the macro name." I understand this to mean "before a text macro is defined, it cannot be used ..." Otherwise, a simple misspelling of a compiler directive, like `celdefine would go unnoticed. This is the only rational behavior. \$\endgroup\$dave_59– dave_592018年03月10日 05:29:32 +00:00Commented Mar 10, 2018 at 5:29
This is most likely a bug and should have been an error . The backtick ` is only used in with compiler directives
-
\$\begingroup\$ Yes, and one of those directives is
`define <name>
-- and when you want to use <name> in a statement, you say`<name>
. Not a bug. \$\endgroup\$Dave Tweed– Dave Tweed2018年03月09日 23:18:01 +00:00Commented Mar 9, 2018 at 23:18 -
1\$\begingroup\$ @DaveTweed that assumes someone already has the statement `define deadbeef in their code, which I doubt \$\endgroup\$dave_59– dave_592018年03月10日 00:27:38 +00:00Commented Mar 10, 2018 at 0:27
-
\$\begingroup\$ No, it doesn't. It's perfectly OK to refer to an undefined symbol, which expands to nothing. \$\endgroup\$Dave Tweed– Dave Tweed2018年03月10日 01:52:22 +00:00Commented Mar 10, 2018 at 1:52
-
2\$\begingroup\$ Not true. You should get an undefined compiler directive or macro. Try it. \$\endgroup\$dave_59– dave_592018年03月10日 02:38:53 +00:00Commented Mar 10, 2018 at 2:38