marlin_verilator/dpi.rs
1// Copyright (C) 2024 Ethan Uppal.
2//
3// This Source Code Form is subject to the terms of the Mozilla Public License,
4// v. 2.0. If a copy of the MPL was not distributed with this file, You can
5// obtain one at https://mozilla.org/MPL/2.0/.
6
7//! See the [`#[verilog::dpi]`](https://docs.rs/marlin/latest/marlin/verilog/attr.dpi.html) macro for details.
8
9use std::ffi;
10
11/// A `&'static dyn DpiFunction` represents a Rust function suitable for use in
12/// Verilator DPI. See the [`#[verilog::dpi]`](https://docs.rs/marlin/latest/marlin/verilog/attr.dpi.html)
13/// macro for details.
14pub trait DpiFunction: Sync {
15 /// The Rust-declared name of the DPI function. This should be taken to be
16 /// equivalent to the name given for the DPI C function in Verilog
17 /// source code.
18 fn name(&self) -> &'static str;
19
20 /// A list of `(name, c_type)` pairs serving as the parameters of the
21 /// generated C function and the generated function pointer type for the
22 /// Rust function.
23 fn signature(&self) -> &'static [(&'static str, &'static str)];
24
25 /// The Rust function as a function pointer.
26 fn pointer(&self) -> *const ffi::c_void;
27}