liberty_parse/
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_parse::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.cells.len());
20//!     let area = lib
21//!         .cells
22//!         .get("AND2")
23//!         .and_then(|c| c.simple_attributes.get("area"))
24//!         .map_or(-1.0, |v| v.float());
25//!     println!("Cell AND2 has area: {}", area);
26//! }
27//! ```
28
29pub mod ast;
30pub mod liberty;
31mod error;
32mod parser;
33
34pub use ast::{ParseResult, Value};
35
36pub use error::Error;
37
38/// Parse a string slice into a [liberty::Liberty] struct
39pub fn parse_lib(contents: &str) -> ParseResult<liberty::Liberty> {
40    Ok(liberty::Liberty::from_ast(ast::LibertyAst::from_string(
41        contents,
42    )?))
43}