liberty_parser/lib.rs
1//! This crate reads Liberty format files, commonly used by
2//! [EDA](https://en.wikipedia.org/wiki/Electronic_design_automation) tools to describe library
3//! cells (including standard cells, hard IP, etc.).
4//!
5//! # Example
6//!
7//! ```
8//! use liberty_parser::parse_lib;
9//!
10//! let lib_str = r#"
11//! library(sample) {
12//! cell(AND2) {
13//! area: 1;
14//! }
15//! }
16//! "#;
17//!
18//! for lib in parse_lib(lib_str).unwrap() {
19//! println!("Library '{}' has {} cells", lib.name, lib.iter_cells().count());
20//! let area = lib
21//! .get_cell("AND2")
22//! .and_then(|c| c.simple_attribute("area"))
23//! .map_or(-1.0, |v| v.float());
24//! println!("Cell AND2 has area: {}", area);
25//! }
26//! ```
27
28pub mod ast;
29mod error;
30pub mod liberty;
31pub mod parser;
32
33pub use ast::{ParseResult, Value};
34
35pub use error::Error;
36
37/// Parse a string slice into a [liberty::Liberty] struct
38pub fn parse_lib(contents: &str) -> ParseResult<'_, liberty::Liberty> {
39 Ok(liberty::Liberty::from_ast(ast::LibertyAst::from_string(
40 contents,
41 )?))
42}