scir/netlist.rs
1//! Netlist export.
2
3use crate::schema::Schema;
4use crate::{Library, NetlistLibConversion};
5use std::io::Write;
6use std::path::Path;
7
8/// A netlister that tracks how cells and instances are translated between SCIR and the output netlist format.
9pub trait ConvertibleNetlister<S: Schema + ?Sized> {
10 /// The error type returned when writing out a SCIR netlist.
11 type Error: From<std::io::Error>;
12
13 /// The netlist options type.
14 ///
15 /// Many netlisters accept options, allowing the user to configure things like
16 /// netlist indentation, naming conventions, etc. This is the type of the object
17 /// that stores those options.
18 type Options<'a>;
19
20 /// Writes a netlist of a SCIR library to the provided output stream.
21 fn write_scir_netlist<W: Write>(
22 &self,
23 lib: &Library<S>,
24 out: &mut W,
25 opts: Self::Options<'_>,
26 ) -> Result<NetlistLibConversion, Self::Error>;
27
28 /// Writes a netlist of a SCIR library to a file at the given path.
29 ///
30 /// The file and any parent directories will be created if necessary.
31 fn write_scir_netlist_to_file(
32 &self,
33 lib: &Library<S>,
34 path: impl AsRef<Path>,
35 opts: Self::Options<'_>,
36 ) -> Result<NetlistLibConversion, Self::Error> {
37 let path = path.as_ref();
38 if let Some(parent) = path.parent() {
39 std::fs::create_dir_all(parent)?;
40 }
41 let mut f = std::fs::File::create(path)?;
42 let conv = self.write_scir_netlist(lib, &mut f, opts)?;
43 Ok(conv)
44 }
45}