README.md 5.79 KB
Newer Older
1 2
# sv2v: SystemVerilog to Verilog

Zachary Snow committed
3 4
sv2v converts SystemVerilog ([IEEE 1800-2017]) to Verilog ([IEEE 1364-2005]),
with an emphasis on supporting synthesizable language constructs.
5 6 7

[IEEE 1800-2017]: https://ieeexplore.ieee.org/servlet/opac?punumber=8299593
[IEEE 1364-2005]: https://ieeexplore.ieee.org/servlet/opac?punumber=10779
Zachary Snow committed
8 9 10 11

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
12
limited in scope.
Zachary Snow committed
13 14

This project was originally developed to target [Yosys], and so allows for
15 16
disabling the conversion of (passing through) those [SystemVerilog features
which Yosys supports].
Zachary Snow committed
17

18
[Yosys]: http://www.clifford.at/yosys/
19
[SystemVerilog features which Yosys supports]: https://github.com/YosysHQ/yosys#supported-features-from-systemverilog
20

Zachary Snow committed
21 22 23 24 25 26 27 28 29
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/

30

Zachary Snow committed
31 32 33 34 35 36 37 38 39 40 41 42
## 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


43 44 45 46
## Installation

### Pre-built binaries

Zachary Snow committed
47 48
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
Zachary Snow committed
49 50 51
instructions for building from source are below.

[releases page]: https://github.com/zachjs/sv2v/releases
52 53 54

### Building from source

55
You must have [Stack] installed to build sv2v. Then you can:
56 57 58 59

[Stack]: https://www.haskellstack.org/

```
Zachary Snow committed
60
git clone https://github.com/zachjs/sv2v.git
61 62 63 64
cd sv2v
make
```

Zachary Snow committed
65 66 67 68 69
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.
70 71 72 73


## Usage

Zachary Snow committed
74
sv2v takes in a list of files and prints the converted Verilog to `stdout`.
75
Users may specify `include` search paths, define macros during preprocessing,
76 77
and exclude some of the conversions. Specifying `-` as an input file will read
from `stdin`.
Zachary Snow committed
78 79

Below is the current usage printout. This interface is subject to change.
80 81

```
82
sv2v [OPTIONS] [FILES]
83

84 85 86 87 88
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
89
     --skip-preprocessor    Disable preprocessor
90
Conversion:
91
  -E --exclude=CONV         Exclude a particular conversion (always, assert,
92
                            interface, or logic)
93 94 95 96
  -v --verbose              Retain certain conversion artifacts
Other:
     --help                 Display help message
     --version              Print version information
97
     --numeric-version      Print just the version number
98 99 100
```


Zachary Snow committed
101 102 103
## Supported Features

sv2v supports most synthesizable SystemVerilog features. Current notable
104 105
exceptions include `export` and interface arrays. Assertions are also supported,
but are simply dropped during conversion.
Zachary Snow committed
106 107 108 109 110

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.


111
## SystemVerilog Front End
112

113
This project contains a preprocessor, lexer, and parser, and an abstract syntax
Zachary Snow committed
114 115
tree representation for a subset of the SystemVerilog specification. The parser
is not very strict. The AST allows for the representation of syntactically (and
116 117 118
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
119
front end if there is significant interest.
Zachary Snow committed
120 121 122 123


## Testing

Zachary Snow committed
124
Once the [test dependencies](#dependencies) are installed, tests can be run with
Zachary Snow committed
125
`make test`. GitHub Actions is used to automatically test commits.
Zachary Snow committed
126 127 128 129 130 131

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
132 133


134 135 136
## Acknowledgements

This project was originally forked from [Tom Hawkin's Verilog parser]. While the
Zachary Snow committed
137 138
front end has changed substantially to support the larger SystemVerilog
standard, his project was a great starting point.
139 140 141 142 143 144 145 146 147 148

[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.

Zachary Snow committed
149 150 151 152
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.

153

154 155
## License

156
See the [LICENSE file](LICENSE) for copyright and licensing information.