add docs and change examples to reflect changing interfaces

This commit is contained in:
Yehowshua Immanuel 2022-09-13 19:35:23 -04:00
parent 320b0d348d
commit a0713c1f38
10 changed files with 95 additions and 85 deletions

61
examples/vcd.rs Normal file
View file

@ -0,0 +1,61 @@
use std::fs::File;
use fastwave::*;
use num::{BigUint};
fn indented_print(indent : u8, name : &String) {
for _ in 0..indent {print!(" ");}
print!(" |");
print!(" ");
println!("{name}");
}
fn print_root_scope_tree(root_idx: ScopeIdx, vcd: &VCD, indent : u8) {
if vcd.child_scopes_by_idx(root_idx).is_empty() {
indented_print(indent, vcd.scope_name_by_idx(root_idx));
} else {
for child_scope_idx in vcd.child_scopes_by_idx(root_idx) {
indented_print(indent, vcd.scope_name_by_idx(child_scope_idx));
let ScopeIdx(idx) = child_scope_idx;
print_root_scope_tree(child_scope_idx, vcd.clone(), indent + 1);
}
}
}
fn ui_all_scopes(vcd: &VCD) {
for root_scope_idx in vcd.root_scopes_by_idx() {
print_root_scope_tree(root_scope_idx, vcd, 0u8);
}
}
fn main() -> std::io::Result<()> {
use std::time::Instant;
let now = Instant::now();
let file_path = "tests/vcd-files/icarus/CPU.vcd";
let file = File::open(file_path)?;
let vcd = parse_vcd(file).unwrap();
let elapsed = now.elapsed();
println!("Parsed VCD file {} : {:.2?}", file_path, elapsed);
println!("Printing Scopes");
ui_all_scopes(&vcd);
// let state_signal = vcd.
// let name = state_signal.name();
// let time = BigUint::from(57760000u32);
// let val = state_signal
// .query_string_val_on_tmln(
// &time,
// &vcd.tmstmps_encoded_as_u8s,
// &vcd.all_signals,
// )
// .unwrap();
// println!("Signal `{name}` has value `{val}` at time `{time}`");
Ok(())
}

View file

@ -1,34 +0,0 @@
use clap::Parser;
use std::fs::File;
use fastwave::*;
use num::{BigUint};
fn main() -> std::io::Result<()> {
use std::time::Instant;
let now = Instant::now();
let file_path = "tests/vcd-files/icarus/CPU.vcd";
let file = File::open(file_path).unwrap();
let vcd = parse_vcd(file).unwrap();
let elapsed = now.elapsed();
println!("Parsed VCD file {} : {:.2?}", file_path, elapsed);
// testbench -> CPU -> rs2_data[31:0] @ 4687s
let rs2_data_signal = &vcd.all_signals[51];
let name = rs2_data_signal.name();
let time = BigUint::from(4687u32);
let val = rs2_data_signal
.query_num_val_on_tmln(
&time,
&vcd.tmstmps_encoded_as_u8s,
&vcd.all_signals,
)
.unwrap();
println!("Signal `{name}` has value `{val}` at time `{time}`");
Ok(())
}

View file

@ -1,34 +0,0 @@
use clap::Parser;
use std::fs::File;
use fastwave::*;
use num::{BigUint};
fn main() -> std::io::Result<()> {
use std::time::Instant;
let now = Instant::now();
let file_path = "tests/vcd-files/amaranth/up_counter.vcd";
let file = File::open(file_path)?;
let vcd = parse_vcd(file).unwrap();
let elapsed = now.elapsed();
println!("Parsed VCD file {} : {:.2?}", file_path, elapsed);
let state_signal = &vcd.all_signals[4];
let name = state_signal.name();
let time = BigUint::from(57760000u32);
let val = state_signal
.query_string_val_on_tmln(
&time,
&vcd.tmstmps_encoded_as_u8s,
&vcd.all_signals,
)
.unwrap();
println!("Signal `{name}` has value `{val}` at time `{time}`");
Ok(())
}