pub struct Writer<W: Write> { /* private fields */ }Expand description
Struct wrapping an std::io::Write with methods for writing VCD commands and data.
§Example
use std::{fs::File, io::BufWriter};
use vcd::{Value, TimescaleUnit};
let mut writer = vcd::Writer::new(BufWriter::new(File::create("test.vcd")?));
writer.timescale(1, TimescaleUnit::US)?;
writer.add_module("top")?;
let clock = writer.add_wire(1, "clock")?;
writer.upscope()?;
writer.enddefinitions()?;
let mut t = 0;
while t < 100 {
writer.timestamp(t)?;
writer.change_scalar(clock, Value::V0)?;
t += 2;
writer.timestamp(t)?;
writer.change_scalar(clock, Value::V1)?;
t += 2;
}Implementations§
Source§impl<W: Write> Writer<W>
impl<W: Write> Writer<W>
Sourcepub fn new(writer: W) -> Writer<W>
pub fn new(writer: W) -> Writer<W>
Creates a Writer wrapping an io::Write.
let mut buf = Vec::new();
let mut vcd = vcd::Writer::new(&mut buf);Sourcepub fn header(&mut self, h: &Header) -> Result<()>
pub fn header(&mut self, h: &Header) -> Result<()>
Writes a complete header with the fields from a Header struct from the parser.
Sourcepub fn timescale(&mut self, ts: u32, unit: TimescaleUnit) -> Result<()>
pub fn timescale(&mut self, ts: u32, unit: TimescaleUnit) -> Result<()>
Writes a $timescale command.
Sourcepub fn add_module(&mut self, identifier: &str) -> Result<()>
pub fn add_module(&mut self, identifier: &str) -> Result<()>
Writes a $scope command for a module.
Convenience wrapper around Writer::scope_def.
Sourcepub fn scope(&mut self, s: &Scope) -> Result<()>
pub fn scope(&mut self, s: &Scope) -> Result<()>
Writes a $scope command, a series of $var commands, and an
$upscope commands from a Scope structure from the parser.
Sourcepub fn var_def(
&mut self,
var_type: VarType,
width: u32,
id: IdCode,
reference: &str,
index: Option<ReferenceIndex>,
) -> Result<()>
pub fn var_def( &mut self, var_type: VarType, width: u32, id: IdCode, reference: &str, index: Option<ReferenceIndex>, ) -> Result<()>
Writes a $var command with a specified id.
Sourcepub fn add_var(
&mut self,
var_type: VarType,
width: u32,
reference: &str,
index: Option<ReferenceIndex>,
) -> Result<IdCode>
pub fn add_var( &mut self, var_type: VarType, width: u32, reference: &str, index: Option<ReferenceIndex>, ) -> Result<IdCode>
Writes a $var command with the next available ID, returning the assigned ID.
Convenience wrapper around Writer::var_def.
Sourcepub fn add_wire(&mut self, width: u32, reference: &str) -> Result<IdCode>
pub fn add_wire(&mut self, width: u32, reference: &str) -> Result<IdCode>
Adds a $var for a wire with the next available ID, returning the assigned ID.
Convenience wrapper around Writer::add_var.
Sourcepub fn var(&mut self, v: &Var) -> Result<()>
pub fn var(&mut self, v: &Var) -> Result<()>
Writes a $var command from a Var structure from the parser.
Sourcepub fn enddefinitions(&mut self) -> Result<()>
pub fn enddefinitions(&mut self) -> Result<()>
Writes a $enddefinitions command to end the header.
Sourcepub fn change_scalar<V: Into<Value>>(&mut self, id: IdCode, v: V) -> Result<()>
pub fn change_scalar<V: Into<Value>>(&mut self, id: IdCode, v: V) -> Result<()>
Writes a change to a scalar variable.
Sourcepub fn change_vector(
&mut self,
id: IdCode,
v: impl IntoIterator<Item = Value>,
) -> Result<()>
pub fn change_vector( &mut self, id: IdCode, v: impl IntoIterator<Item = Value>, ) -> Result<()>
Writes a change to a vector variable.
Sourcepub fn change_real(&mut self, id: IdCode, v: f64) -> Result<()>
pub fn change_real(&mut self, id: IdCode, v: f64) -> Result<()>
Writes a change to a real variable.
Sourcepub fn change_string(&mut self, id: IdCode, v: &str) -> Result<()>
pub fn change_string(&mut self, id: IdCode, v: &str) -> Result<()>
Writes a change to a string variable.
Sourcepub fn begin(&mut self, c: SimulationCommand) -> Result<()>
pub fn begin(&mut self, c: SimulationCommand) -> Result<()>
Writes the beginning of a simulation command.