2019-02-24 20:59:00 +01:00
|
|
|
# sv2v: SystemVerilog to Verilog
|
|
|
|
|
|
2019-04-04 05:12:52 +02:00
|
|
|
sv2v converts SystemVerilog ([IEEE 1800-2017]) to Verilog ([IEEE 1364-2005]),
|
|
|
|
|
with an emphasis on supporting synthesizable language constructs.
|
2019-03-27 08:41:41 +01:00
|
|
|
|
|
|
|
|
[IEEE 1800-2017]: https://ieeexplore.ieee.org/servlet/opac?punumber=8299593
|
|
|
|
|
[IEEE 1364-2005]: https://ieeexplore.ieee.org/servlet/opac?punumber=10779
|
2019-04-04 05:12:52 +02:00
|
|
|
|
|
|
|
|
The primary goal of this project is to create a completely free and open-source
|
|
|
|
|
tool for converting SystemVerilog to Verilog. While methods for performing this
|
|
|
|
|
conversion already exist, they generally either rely on commercial tools, or are
|
2019-04-23 17:59:15 +02:00
|
|
|
limited in scope.
|
2019-04-04 05:12:52 +02:00
|
|
|
|
|
|
|
|
This project was originally developed to target [Yosys], and so allows for
|
2023-05-07 20:15:31 +02:00
|
|
|
disabling the conversion of (passing through) those [SystemVerilog features that
|
|
|
|
|
Yosys supports].
|
2019-04-04 05:12:52 +02:00
|
|
|
|
2023-05-07 20:15:31 +02:00
|
|
|
[Yosys]: https://yosyshq.net/yosys/
|
|
|
|
|
[SystemVerilog features that Yosys supports]: https://github.com/YosysHQ/yosys#supported-features-from-systemverilog
|
2019-02-24 20:59:00 +01:00
|
|
|
|
2020-04-17 00:12:05 +02:00
|
|
|
The idea for this project was shared with me while I was an undergraduate at
|
|
|
|
|
Carnegie Mellon University as part of a joint Computer Science and Electrical
|
|
|
|
|
and Computer Engineering research project on open hardware under Professors [Ken
|
|
|
|
|
Mai] and [Dave Eckhardt]. I have greatly enjoyed collaborating with the team at
|
|
|
|
|
CMU since January 2019, even after my graduation the following May.
|
|
|
|
|
|
|
|
|
|
[Ken Mai]: https://engineering.cmu.edu/directory/bios/mai-kenneth.html
|
|
|
|
|
[Dave Eckhardt]: https://www.cs.cmu.edu/~davide/
|
|
|
|
|
|
2019-02-24 20:59:00 +01:00
|
|
|
|
2019-04-04 05:12:52 +02:00
|
|
|
## Dependencies
|
|
|
|
|
|
|
|
|
|
All of sv2v's dependencies are free and open-source.
|
|
|
|
|
|
|
|
|
|
* Build Dependencies
|
|
|
|
|
* [Haskell Stack](https://www.haskellstack.org/) - Haskell build system
|
|
|
|
|
* Haskell dependencies are managed in `sv2v.cabal`
|
|
|
|
|
* Test Dependencies
|
2023-05-07 20:15:31 +02:00
|
|
|
* [Icarus Verilog](https://steveicarus.github.io/iverilog/) - for Verilog
|
|
|
|
|
simulation
|
2019-04-04 05:12:52 +02:00
|
|
|
* [shUnit2](https://github.com/kward/shunit2) - test framework
|
2023-05-30 01:05:33 +02:00
|
|
|
* Python 3.x - for evaluating certain test cases
|
2019-04-04 05:12:52 +02:00
|
|
|
|
|
|
|
|
|
2019-02-24 20:59:00 +01:00
|
|
|
## Installation
|
|
|
|
|
|
|
|
|
|
### Pre-built binaries
|
|
|
|
|
|
2020-06-08 03:44:09 +02:00
|
|
|
Binaries for Ubuntu, macOS, and Windows are available on the [releases page]. If
|
|
|
|
|
your system is not covered, or you would like to build the latest commit, simple
|
2020-02-23 01:53:35 +01:00
|
|
|
instructions for building from source are below.
|
|
|
|
|
|
|
|
|
|
[releases page]: https://github.com/zachjs/sv2v/releases
|
2019-02-24 20:59:00 +01:00
|
|
|
|
|
|
|
|
### Building from source
|
|
|
|
|
|
2019-04-23 20:07:59 +02:00
|
|
|
You must have [Stack] installed to build sv2v. Then you can:
|
2019-02-24 20:59:00 +01:00
|
|
|
|
|
|
|
|
[Stack]: https://www.haskellstack.org/
|
|
|
|
|
|
|
|
|
|
```
|
2019-04-19 01:33:16 +02:00
|
|
|
git clone https://github.com/zachjs/sv2v.git
|
2019-02-24 20:59:00 +01:00
|
|
|
cd sv2v
|
|
|
|
|
make
|
|
|
|
|
```
|
|
|
|
|
|
2019-04-19 01:33:16 +02:00
|
|
|
This creates the executable at `./bin/sv2v`. Stack takes care of installing
|
|
|
|
|
exact (compatible) versions of the compiler and sv2v's build dependencies.
|
|
|
|
|
|
|
|
|
|
You can install the binary to your local bin path (typically `~/.local/bin`) by
|
|
|
|
|
running `stack install`, or copy over the executable manually.
|
2019-02-24 20:59:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
2023-05-07 20:15:31 +02:00
|
|
|
sv2v takes in a list of files and prints the converted Verilog to `stdout` by
|
|
|
|
|
default. Users should typically pass all of their SystemVerilog source files to
|
|
|
|
|
sv2v at once so it can properly resolve packages, interfaces, type parameters,
|
|
|
|
|
etc., across files. Using `--write=adjacent` will create a converted `.v` for
|
|
|
|
|
every `.sv` input file rather than printing to `stdout`. `--write`/`-w` can also
|
2023-06-14 04:53:36 +02:00
|
|
|
be used to specify a path to a `.v` output file. Undefined modules and
|
|
|
|
|
interfaces can be automatically loaded from library directories using
|
|
|
|
|
`--libdir`/`-y`.
|
2021-01-29 00:34:55 +01:00
|
|
|
|
2019-04-23 20:07:59 +02:00
|
|
|
Users may specify `include` search paths, define macros during preprocessing,
|
2019-11-20 05:29:19 +01:00
|
|
|
and exclude some of the conversions. Specifying `-` as an input file will read
|
|
|
|
|
from `stdin`.
|
2019-04-04 05:12:52 +02:00
|
|
|
|
2023-05-07 20:15:31 +02:00
|
|
|
Below is the current usage printout.
|
2019-02-26 21:03:49 +01:00
|
|
|
|
|
|
|
|
```
|
2019-03-29 00:55:53 +01:00
|
|
|
sv2v [OPTIONS] [FILES]
|
2019-02-26 21:03:49 +01:00
|
|
|
|
2019-09-15 16:31:50 +02:00
|
|
|
Preprocessing:
|
2023-06-22 06:05:06 +02:00
|
|
|
-I --incdir=DIR Add a directory to the include search path
|
2023-06-14 04:53:36 +02:00
|
|
|
-y --libdir=DIR Add a directory to the library search path used
|
|
|
|
|
when looking for undefined modules and interfaces
|
2019-09-15 16:31:50 +02:00
|
|
|
-D --define=NAME[=VALUE] Define a macro for preprocessing
|
|
|
|
|
--siloed Lex input files separately, so macros from
|
|
|
|
|
earlier files are not defined in later files
|
2023-06-22 06:05:06 +02:00
|
|
|
--skip-preprocessor Disable preprocessing of macros, comments, etc.
|
2019-09-15 16:31:50 +02:00
|
|
|
Conversion:
|
2021-08-06 06:16:39 +02:00
|
|
|
--pass-through Dump input without converting
|
2021-10-14 04:18:15 +02:00
|
|
|
-E --exclude=CONV Exclude a particular conversion (Always, Assert,
|
|
|
|
|
Interface, Logic, or UnbasedUnsized)
|
2019-09-15 16:31:50 +02:00
|
|
|
-v --verbose Retain certain conversion artifacts
|
2023-06-21 14:25:42 +02:00
|
|
|
-w --write=MODE/FILE/DIR How to write output; default is 'stdout'; use
|
2021-06-16 23:05:53 +02:00
|
|
|
'adjacent' to create a .v file next to each input;
|
2023-06-21 14:25:42 +02:00
|
|
|
use a path ending in .v to write to a file; use a
|
|
|
|
|
path to an existing directory to create a .v within
|
|
|
|
|
for each converted module
|
2023-06-19 04:36:43 +02:00
|
|
|
--top=NAME Remove uninstantiated modules except the given
|
|
|
|
|
top module; can be used multiple times
|
2019-09-15 16:31:50 +02:00
|
|
|
Other:
|
2021-08-10 06:10:29 +02:00
|
|
|
--oversized-numbers Disable standard-imposed 32-bit limit on unsized
|
|
|
|
|
number literals (e.g., 'h1_ffff_ffff, 4294967296)
|
2021-09-06 01:54:36 +02:00
|
|
|
--dump-prefix=PATH Create intermediate output files with the given
|
|
|
|
|
path prefix; used for internal debugging
|
2023-06-22 06:05:06 +02:00
|
|
|
--help Display this help message
|
2019-09-15 16:31:50 +02:00
|
|
|
--version Print version information
|
2019-04-02 22:19:59 +02:00
|
|
|
--numeric-version Print just the version number
|
2019-02-26 21:03:49 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
2019-04-19 01:33:16 +02:00
|
|
|
## Supported Features
|
|
|
|
|
|
|
|
|
|
sv2v supports most synthesizable SystemVerilog features. Current notable
|
2021-09-22 04:11:02 +02:00
|
|
|
exceptions include `defparam` on interface instances, certain synthesizable
|
|
|
|
|
usages of parameterized classes, and the `bind` keyword. Assertions are also
|
|
|
|
|
supported, but are simply dropped during conversion.
|
2019-04-19 01:33:16 +02:00
|
|
|
|
2021-09-22 04:11:02 +02:00
|
|
|
If you find a bug or have a feature request, please [create an issue].
|
2023-05-07 20:15:31 +02:00
|
|
|
Preference will be given to issues that include examples or test cases.
|
2021-09-22 04:11:02 +02:00
|
|
|
|
|
|
|
|
[create an issue]: https://github.com/zachjs/sv2v/issues/new
|
2019-04-19 01:33:16 +02:00
|
|
|
|
|
|
|
|
|
2019-04-23 20:07:59 +02:00
|
|
|
## SystemVerilog Front End
|
2019-02-24 20:59:00 +01:00
|
|
|
|
2020-02-07 05:27:51 +01:00
|
|
|
This project contains a preprocessor, lexer, and parser, and an abstract syntax
|
2019-04-04 05:12:52 +02:00
|
|
|
tree representation for a subset of the SystemVerilog specification. The parser
|
|
|
|
|
is not very strict. The AST allows for the representation of syntactically (and
|
2019-02-24 20:59:00 +01:00
|
|
|
semantically) invalid Verilog. The goal is to be more general in the
|
|
|
|
|
representation to enable more standardized and straightforward conversion
|
|
|
|
|
procedures. This could be extended into an independent and more fully-featured
|
2019-04-23 17:59:15 +02:00
|
|
|
front end if there is significant interest.
|
2019-04-04 05:12:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
## Testing
|
|
|
|
|
|
2023-05-31 04:33:57 +02:00
|
|
|
Once the [test dependencies] are installed, tests can be run with `make test`.
|
|
|
|
|
GitHub Actions is used to [automatically test] commits. Please review the [test
|
|
|
|
|
documentation] for guidance on adding, debugging, and interpreting tests.
|
2019-10-03 04:46:17 +02:00
|
|
|
|
2023-05-31 04:33:57 +02:00
|
|
|
[test dependencies]: #dependencies
|
|
|
|
|
[test documentation]: test/README.md
|
|
|
|
|
[automatically test]: https://github.com/zachjs/sv2v/actions
|
|
|
|
|
|
|
|
|
|
There is also a [SystemVerilog compliance suite] that tests open-source tools'
|
|
|
|
|
SystemVerilog support. Although not every test in the suite is applicable, it
|
|
|
|
|
has been a valuable asset in finding edge cases.
|
2019-10-03 04:46:17 +02:00
|
|
|
|
2023-05-07 20:15:31 +02:00
|
|
|
[SystemVerilog compliance suite]: https://github.com/chipsalliance/sv-tests
|
2019-02-24 20:59:00 +01:00
|
|
|
|
|
|
|
|
|
2019-04-23 20:07:59 +02:00
|
|
|
## Acknowledgements
|
|
|
|
|
|
|
|
|
|
This project was originally forked from [Tom Hawkin's Verilog parser]. While the
|
2019-10-03 04:46:17 +02:00
|
|
|
front end has changed substantially to support the larger SystemVerilog
|
|
|
|
|
standard, his project was a great starting point.
|
2019-04-23 20:07:59 +02:00
|
|
|
|
|
|
|
|
[Tom Hawkin's Verilog parser]: https://github.com/tomahawkins/verilog
|
|
|
|
|
|
|
|
|
|
Reid Long was invaluable in developing this tool, providing significant tests
|
2023-05-07 20:15:31 +02:00
|
|
|
and advice, and isolating many bugs.
|
2019-04-23 20:07:59 +02:00
|
|
|
|
|
|
|
|
Edric Kusuma helped me with the ins and outs of SystemVerilog, with which I had
|
|
|
|
|
no prior experience, and has also helped with test cases.
|
|
|
|
|
|
2023-05-07 20:15:31 +02:00
|
|
|
Since sv2v's public release, many people have taken the time to file detailed
|
2019-10-03 04:46:17 +02:00
|
|
|
bug reports and feature requests. I greatly appreciate their help in furthering
|
|
|
|
|
the project.
|