Attribute Macro dpi

Source
#[dpi]
Expand description

Marlin allows you to import Rust functions into (System)Verilog over DPI. The function must have “C” linkage and be imported into SystemVerilog with “DPI-C” linkage.

For example:

// in Rust
#[verilog::dpi]
pub extern "C" fn three(out: &mut u32) {
    *out = 3;
}
// in SystemVerilog
import "DPI-C" function void three(output int out);

The Rust function can only take in primitive integer types at or below 64-bit width and booleans. The order and count of parameters must correspond exactly with the SystemVerilog import declaration.

Any input parameter on the Verilog side should correspond to a plain argument on the Rust side. Any output or inout parmaeter on the Verilog side should corresponding to a mutable reference on the Rust side. Note that the names of parmaeters on either side are irrelevant and need not correspond.

Here are some examples:

SystemVerilog parameterRust parameter
output int foofoo: &mut i32
input bit barbar: bool

§More

Please reference the Verilator docs on VPI for further information. You can also see the corresponding page in the Marlin handbook.