Open stefanpie opened 9 months ago
I wanted to follow up on this pull request after some more experimenting:
Other Verilog Edge Cases Odin II does not support spaces in integer literals. For example, the following integer literals will cause errors in Odin II.
32'h 0000_0000,
32'h ffff_ffff,
32'h 0000_0010,
However, if you remove the space from the integer literals, as shown below, Odin II can parse the Verilog without throwing those specific errors.
32'h0000_0000,
32'hffff_ffff,
32'h0000_0010,
For more details and examples, see section "2.5.1 Integer constants" of the Verilog 1995 standard (https://ieeexplore.ieee.org/document/803556).
Workaround Python Preprocessing Module To workaround both the escaped identifier and integer literal parsing bugs in Odin II, I wrote a Python module that can "preprocess" Verilog source to transform it into Verilog that Odin II can currently parse. This seems to address the two main issues I am having at the moment, and I wanted to share this in case others come across this issue. See the attached zip file for the module code: verilog_preprocessor.zip. I use Python 3.10 with type annotations. The module only uses standard library imports and should work standalone.
Hello, VTR devs. This is Stefan Abi-Karam from Georgia Tech, and I am running into some simple parsing errors when it comes to using Odin II on some Verilog designs. The core issue is that Odin II seems to support only a limited subset of allowable verilog syntax (just talking about "simple" 1995 Verilog, nothing new or SystemVerilog related), which excludes using backslashes for escaping identifiers. This causes some issues in my current flow when using Yosys before sending designs into Odin II. Please see the "2.7.1 Escaped identifiers" section of the 1995 Verilog standard (https://ieeexplore.ieee.org/document/803556) for more details and examples of what I am referring to.
My current flow looks as follows:
Yosys tends to produce Verilog that is generally good for Odin, except for the fact that it uses backslash to escape identifiers, which means that after the backslash, they can contain any of the printable ASCII characters in an identifier as long as a space follows the identifier.
Examples of escaping identifiers using backslash:
I have also seen this behavior with module names as well.
Even though the Parmys flow seems to be the way forward, I still think it's reasonable to use Odin in the meantime and expect it to handle escaping identifiers. Many other users and tools besides Yosys might also use this feature as well, especially if a tool is autogenerating some Verilog.
Expected Behaviour
Odin II should be able to parse Verilog identifiers that are escaped via a backslash according to the 1995 Verilog Standard.
Current Behaviour
Right now, Odin II cannot parse Verilog identifiers that are escaped with a backslash.
Some forms of this error from Odin II are shown below.
Possible Solution
Looking at the parsing code for Odin in
/odin_ii/src/verilog/verilog_flex.l
, it seems that the parsing code could be modified to support this as follows.I am not a C++, Bison, or flex expert, but this seems like one possible way to approach the problem after some initial research.
The other "solution" is just to use Parmys as the way forward. I have not tested this yet, as getting a build from a source working for me is still a work in progress on my limited-sudo-access research server. I would assume this works since it is a plugin for Yosys, and Yosys will happily parse and use this escaped identifier syntax everywhere. This would also fit into my EDA flow anyway.
Steps to Reproduce
You can reproduce this with a simple
test.v
Verilog design and Odin II:I just call Odin II as follows:
I am using the
EArch.xml
from/vtr_flow/arch/timing/EArch.xml
.Context
This is mainly causing issues in the EDA flow that I am currently using, as described above, under the assumption that I don't have Parmys. In general, I want to be able to do some simple preprocessing and cleanup of my design in another tool like Yosys before passing it into Odin, and I want to let upstream tools generate Verilog for Odin that supports escaped identifiers.
Using Yosys, I tried various techniques and combinations of commands to prevent the exported verilog from having escaped identifiers, but none worked.
Your Environment
I am using a build of VTR, Odin, and Yosys packages as conda packages form from the litex-hub (https://github.com/litex-hub/litex-conda-packages + https://anaconda.org/LiteX-Hub).