#verilog #verilator

verilator

Automated generation of Verilator test modules

7 releases

Uses old Rust 2015

0.1.6 Apr 10, 2021
0.1.5 Feb 20, 2021
0.1.4 Apr 21, 2020
0.1.3 Oct 30, 2019
0.1.1 May 15, 2018

#51 in Build Utils

Download history 6/week @ 2022-03-08 25/week @ 2022-03-15 23/week @ 2022-03-22 4/week @ 2022-03-29 3/week @ 2022-04-05 5/week @ 2022-04-12 7/week @ 2022-04-19 61/week @ 2022-04-26 60/week @ 2022-05-03 109/week @ 2022-05-10 25/week @ 2022-05-17 47/week @ 2022-05-24 63/week @ 2022-05-31 20/week @ 2022-06-07 4/week @ 2022-06-14 6/week @ 2022-06-21

93 downloads per month
Used in verilated

MIT/Apache

33KB
1K SLoC

verilated - Verilator Porcelain for Rust

A build dependency for running verilator to generate Rust bindings to Verilog code.

Motivation

Usage

# Cargo.toml
[build-dependencies]
verilator = { version = "0.1", features = ["gen", "module"] }
// build.rs
extern crate verilator;

use verilator::gen::Verilator;
use verilator::module::ModuleGenerator;

fn main() {
    ...
    // Generate CPP shim from Rust
    ModuleGenerator::new().generate("src/main.rs");
    
    ...
    // Generate CPP from Verilog, ...
    Verilator::new()
        .file("rtl/top.v");
    // ... and from ModuleGenerator output ...
        .file("top.cpp")
    // ... compile and link into crate.
        .build("top");
}

Example

#![feature(proc_macro)]

extern crate verilated;
extern crate verilated_module;
use verilated_module::module;
use verilated::test_bench::TestBench;

#[module(top)]
pub struct Top {
    #[port(clock)] pub clk_i: bool,
    #[port(reset)] pub rst_i: bool,
    #[port(output)] pub count_o: [bool; 4],
}

fn main() {
    let mut tb = TestBench::<Top>::init(|core, tick_count| {
        if tick_count > 10 {
            return false;
        }

        println!("{}: count_o = {}", tick_count, core.count_o());

        true
    });

    while !tb.done() {
        tb.tick();
    }
}

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in verilated-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1–1.7MB
~48K SLoC