sv2v/README.md

164 lines
6.2 KiB
Markdown
Raw Normal View History

# 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.
[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
2019-04-23 20:07:59 +02:00
disabling the conversion of (passing through) those [SystemVerilog features
which Yosys supports].
2019-04-04 05:12:52 +02:00
2019-02-26 21:03:49 +01:00
[Yosys]: http://www.clifford.at/yosys/
[SystemVerilog features which Yosys supports]: https://github.com/YosysHQ/yosys#supported-features-from-systemverilog
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-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
* [Icarus Verilog](http://iverilog.icarus.com) - for Verilog simulation
* [shUnit2](https://github.com/kward/shunit2) - test framework
2020-12-10 22:25:26 +01:00
* Python (any version) - for generating certain test cases
2019-04-04 05:12:52 +02: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
### Building from source
2019-04-23 20:07:59 +02:00
You must have [Stack] installed to build sv2v. Then you can:
[Stack]: https://www.haskellstack.org/
```
2019-04-19 01:33:16 +02:00
git clone https://github.com/zachjs/sv2v.git
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.
## Usage
2019-04-04 05:12:52 +02:00
sv2v takes in a list of files and prints the converted Verilog to `stdout`.
2021-01-29 00:34:55 +01:00
Using `--write=adjacent` will create a converted `.v` for every `.sv` input file
rather than printing to `stdout`.
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
Below is the current usage printout. This interface is subject to change.
2019-02-26 21:03:49 +01:00
```
sv2v [OPTIONS] [FILES]
2019-02-26 21:03:49 +01:00
2019-09-15 16:31:50 +02:00
Preprocessing:
-I --incdir=DIR Add directory to include search path
-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
2020-03-19 01:02:20 +01:00
--skip-preprocessor Disable preprocessor
2019-09-15 16:31:50 +02:00
Conversion:
2020-03-19 01:02:20 +01:00
-E --exclude=CONV Exclude a particular conversion (always, assert,
2019-08-08 04:10:03 +02:00
interface, or logic)
2019-09-15 16:31:50 +02:00
-v --verbose Retain certain conversion artifacts
2021-01-29 00:34:55 +01:00
-w --write=MODE How to write output; default is 'stdout'; use
'adjacent' to create a .v file next to each input
2019-09-15 16:31:50 +02:00
Other:
--help Display help message
--version Print version information
--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
exceptions include `defparam` on interface instances and references to typedefs
within interface instances. Assertions are also supported, but are simply
dropped during conversion.
2019-04-19 01:33:16 +02:00
If you find a bug or have a feature request, please create an issue. Preference
will be given to issues which include examples or test cases.
2019-04-23 20:07:59 +02:00
## SystemVerilog Front End
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
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
2019-10-03 04:46:17 +02:00
Once the [test dependencies](#dependencies) are installed, tests can be run with
2020-06-08 03:44:09 +02:00
`make test`. GitHub Actions is used to automatically test commits.
2019-10-03 04:46:17 +02:00
There is also a [SystemVerilog compliance suite] being created to test
open-source tools' SystemVerilog support. Although not every test in the suite
is applicable, it has been a valuable asset in finding edge cases.
[SystemVerilog compliance suite]: https://github.com/SymbiFlow/sv-tests
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
and advice, and isolating many bugs. His projects can be found
[here](https://bitbucket.org/ReidLong/).
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.
2019-10-03 04:46:17 +02:00
Since sv2v's public release, several people have taken the time to file detailed
bug reports and feature requests. I greatly appreciate their help in furthering
the project.
2019-04-23 20:07:59 +02:00
## License
2019-04-23 20:37:31 +02:00
See the [LICENSE file](LICENSE) for copyright and licensing information.