https://github.com/dalance/rust-dpi-sample
https://github.com/dalance/rust-dpi-sample
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/dalance/rust-dpi-sample
- Owner: dalance
- Created: 2020-01-30T12:15:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-09-13T09:33:03.000Z (almost 5 years ago)
- Last Synced: 2025-01-28T13:54:39.036Z (over 1 year ago)
- Language: SystemVerilog
- Size: 5.86 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rust-dpi-sample
This is an example project using Rust from System Verilog DPI.
You can try like below:
```console
$ make
...
[src/lib.rs:49] a = "Hello World"
Object { x: 10000, y: "Hello" } is destroied
00000001 + 00000002 = 03
00000001 + 00000002 = 0003
00000001 + 00000002 = 00000003
00000001 + 00000002 = 0000000000000003
00000001 + 00000002 = 0000000000000003
00000011 ^ 00000022 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033
- test.sv:43: Verilog $finish
```
The default target of `Makefile` uses [Verilator](https://www.veripool.org/wiki/verilator) as System Verilog simulator.
If you can use Synopsys VCS, `make vcs` can be used.
# Source code example
## Rust side
`#[no_mangle]` and `extern "C"` is required.
```rust
#[no_mangle]
pub extern "C" fn add_i8(x: i8, y: i8) -> i8 {
x + y
}
```
## System Verilog side
```systemverilog
import "DPI-C" function byte add_i8 (input byte x, input byte y);
```