From 1256b7cf4863409680c3be08bf76a220daeb5b99 Mon Sep 17 00:00:00 2001 From: sherbst-openai Date: Tue, 19 Nov 2024 14:16:06 -0800 Subject: [PATCH] Add timescale option to SlangConfig (#20) --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 7 +++++++ tests/test.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec97ffe..f22dc0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,7 +322,7 @@ dependencies = [ [[package]] name = "slang-rs" -version = "0.11.0" +version = "0.12.0" dependencies = [ "num-bigint", "num-traits", diff --git a/Cargo.toml b/Cargo.toml index 8c2e259..58a8686 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "slang-rs" -version = "0.11.0" +version = "0.12.0" edition = "2021" license = "Apache-2.0" description = "Rust bindings for the Slang Verilog parser" diff --git a/src/lib.rs b/src/lib.rs index 7779937..c2b93e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ pub struct SlangConfig<'a> { pub libdirs: &'a [&'a str], pub libexts: &'a [&'a str], pub ignore_unknown_modules: bool, + pub timescale: Option<&'a str>, } impl<'a> Default for SlangConfig<'a> { @@ -32,6 +33,7 @@ impl<'a> Default for SlangConfig<'a> { libdirs: &[], libexts: &[], ignore_unknown_modules: true, + timescale: None, } } } @@ -112,6 +114,11 @@ pub fn run_slang(cfg: &SlangConfig) -> Result> args.push(libext); } + if let Some(timescale) = cfg.timescale { + args.push("--timescale"); + args.push(timescale); + } + for source in cfg.sources.iter() { args.push(source); } diff --git a/tests/test.rs b/tests/test.rs index 26c137b..cc6093a 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -671,4 +671,50 @@ endmodule assert_eq!(modules, vec!["A", "B", "C", "D"]); } + + #[test] + fn test_timescale_option() { + let verilog_a = str2tmpfile( + " +module A( + input clk +); + B b(); +endmodule +", + ) + .unwrap(); + + let verilog_b = str2tmpfile( + " +`timescale 1ns/1ps +module B; +endmodule +", + ) + .unwrap(); + + let cfg = SlangConfig { + sources: &[ + verilog_b.path().to_str().unwrap(), + verilog_a.path().to_str().unwrap(), + ], + tops: &["A"], + timescale: Some("1ns/1ps"), + ..Default::default() + }; + + assert_eq!( + extract_ports(&cfg, false)["A"], + vec![Port { + dir: PortDir::Input, + name: "clk".to_string(), + ty: Type::Logic { + signed: false, + packed_dimensions: vec![], + unpacked_dimensions: vec![] + }, + }] + ); + } }