Skip to content

Commit

Permalink
fix(macros): Support visibility modifiers on model structs (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanuppal authored Feb 8, 2025
1 parent 8a6b0dc commit f34c554
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
cargo run --package example-verilog-project --bin tutorial # rerun
cargo run --package example-verilog-project --bin dynamic_model_tutorial
cargo run --package example-verilog-project --bin dpi_tutorial
cargo run --package example-verilog-project --bin visibility_works
test_spade:
strategy:
Expand Down
5 changes: 5 additions & 0 deletions examples/verilog-project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ path = "test/dynamic_model_tutorial.rs"
name = "dpi_tutorial"
path = "test/dpi_tutorial.rs"


[[bin]]
name = "visibility_works"
path = "test/visibility_works.rs"

[dependencies]
snafu.workspace = true
colog.workspace = true
Expand Down
47 changes: 47 additions & 0 deletions examples/verilog-project/test/visibility_works.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (C) 2024 Ethan Uppal.
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, version 3 of the License only.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <https://www.gnu.org/licenses/>.

use snafu::Whatever;
use verilog::{VerilatorRuntime, VerilatorRuntimeOptions};

mod enclosed {
use verilog::verilog;

#[verilog(src = "src/main.sv", name = "main")]
pub struct Main;
}

#[snafu::report]
fn main() -> Result<(), Whatever> {
colog::init();

let mut runtime = VerilatorRuntime::new(
"artifacts3".into(),
&["src/main.sv".as_ref()],
[],
VerilatorRuntimeOptions::default(),
true,
)?;

let mut main = runtime.create_model::<enclosed::Main>()?;

main.medium_input = u32::MAX;
println!("{}", main.medium_output);
assert_eq!(main.medium_output, 0);
main.eval();
println!("{}", main.medium_output);
assert_eq!(main.medium_output, u32::MAX);

Ok(())
}
3 changes: 2 additions & 1 deletion language-support/verilog-macro-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ pub fn build_verilated_struct(
});

let struct_name = item.ident;
let vis = item.vis;
let port_count = verilated_model_ports_impl.len();
quote! {
struct #struct_name<'ctx> {
#vis struct #struct_name<'ctx> {
#(#struct_members),*,
#[doc = "# Safety\nThe Rust binding to the model will not outlive the dynamic library context (with lifetime `'ctx`) and is dropped when this struct is."]
model: *mut #crate_name::__reexports::libc::c_void,
Expand Down

0 comments on commit f34c554

Please # to comment.