-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[difftest] move wave dump logic to 'dpi_common'
- Loading branch information
Showing
5 changed files
with
134 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use svdpi::SvScope; | ||
use tracing::error; | ||
|
||
mod dpi_export { | ||
use std::ffi::c_char; | ||
extern "C" { | ||
/// `export "DPI-C" function dump_wave(input string file)` | ||
pub fn dump_wave(path: *const c_char); | ||
} | ||
} | ||
|
||
fn dump_wave(scope: svdpi::SvScope, path: &str) { | ||
use std::ffi::CString; | ||
let path_cstring = CString::new(path).unwrap(); | ||
|
||
svdpi::set_scope(scope); | ||
unsafe { | ||
dpi_export::dump_wave(path_cstring.as_ptr()); | ||
} | ||
} | ||
|
||
pub struct DumpEndError; | ||
|
||
pub struct RealDumpControl { | ||
svscope: svdpi::SvScope, | ||
wave_path: String, | ||
dump_start: u64, | ||
dump_end: u64, | ||
|
||
started: bool, | ||
} | ||
|
||
impl RealDumpControl { | ||
pub fn new(svscope: SvScope, wave_path: &str, dump_range: &str) -> Self { | ||
let (dump_start, dump_end) = parse_range(dump_range); | ||
Self { | ||
svscope, | ||
wave_path: wave_path.to_owned(), | ||
dump_start, | ||
dump_end, | ||
|
||
started: false, | ||
} | ||
} | ||
|
||
pub fn start(&mut self) { | ||
if !self.started { | ||
dump_wave(self.svscope, &self.wave_path); | ||
self.started = true; | ||
} | ||
} | ||
|
||
pub fn trigger_watchdog(&mut self, tick: u64) -> Result<(), DumpEndError> { | ||
if self.dump_end != 0 && tick > self.dump_end { | ||
return Err(DumpEndError); | ||
} | ||
|
||
if tick >= self.dump_start { | ||
self.start(); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
pub struct EmptyDumpControl {} | ||
impl EmptyDumpControl { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
pub fn start(&mut self) { | ||
// do nothing | ||
} | ||
pub fn trigger_watchdog(&mut self, _tick: u64) -> Result<(), DumpEndError> { | ||
// do nothing | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn parse_range(input: &str) -> (u64, u64) { | ||
if input.is_empty() { | ||
return (0, 0); | ||
} | ||
|
||
let parts: Vec<&str> = input.split(",").collect(); | ||
|
||
if parts.len() != 1 && parts.len() != 2 { | ||
error!("invalid dump wave range: `{input}` was given"); | ||
return (0, 0); | ||
} | ||
|
||
const INVALID_NUMBER: &'static str = "invalid number"; | ||
|
||
if parts.len() == 1 { | ||
return (parts[0].parse().expect(INVALID_NUMBER), 0); | ||
} | ||
|
||
if parts[0].is_empty() { | ||
return (0, parts[1].parse().expect(INVALID_NUMBER)); | ||
} | ||
|
||
let start = parts[0].parse().expect(INVALID_NUMBER); | ||
let end = parts[1].parse().expect(INVALID_NUMBER); | ||
if start > end { | ||
panic!("dump start is larger than end: `{input}`"); | ||
} | ||
|
||
(start, end) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod dump; | ||
|
||
use tracing_subscriber::{EnvFilter, FmtSubscriber}; | ||
|
||
pub fn setup_logger() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters