mod items;
pub use items::*;
use crate::ast::{AttributeList, GroupComments};
use crate::cell::Cell;
use crate::units;
use mut_set::MutSet;
use std::collections::HashMap;
use std::fmt::{Display, Write};
#[derive(Debug, derivative::Derivative)]
#[derivative(Default)]
#[derive(liberty_macros::Group)]
#[mut_set_derive::item(
macro(derive(Debug, Clone);
derive(derivative::Derivative);
derivative(Default);),
attr_filter(derivative;)
)]
pub struct Library {
#[id]
#[liberty(name)]
pub name: String,
#[liberty(comments)]
_comments: GroupComments<Self>,
#[liberty(undefined)]
_undefined: AttributeList,
#[liberty(simple)]
pub time_unit: units::TimeUnit,
#[liberty(complex(type = Option))]
pub capacitive_load_unit: Option<units::CapacitiveLoadUnit>,
#[liberty(simple)]
pub voltage_unit: units::VoltageUnit,
#[liberty(simple(type = Option))]
pub current_unit: Option<units::CurrentUnit>,
#[liberty(simple(type = Option))]
pub pulling_resistance_unit: Option<units::PullingResistanceUnit>,
#[liberty(simple(type = Option))]
pub leakage_power_unit: Option<units::LeakagePowerUnit>,
#[liberty(simple)]
#[derivative(Default(value = "80.0"))]
pub slew_upper_threshold_pct_rise: f64,
#[liberty(group(type = Set))]
pub cell: MutSet<Cell>,
pub voltage_map: HashMap<String, f64>,
pub sensitization_map: HashMap<String, Sensitization>,
}
impl Display for Library {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
self.fmt(f)
}
}
use crate::ast::parser;
use crate::ast::{AttriComment, CodeFormatter, Format, GroupAttri, ParserError};
impl Library {
#[inline]
pub fn fmt<T: Write>(&self, w: &mut T) -> std::fmt::Result {
let f = &mut crate::ast::CodeFormatter::new(w, " ");
<AttriComment as Format>::liberty(self.comment(), "", f)?;
self.fmt_liberty("library", f)
}
pub fn parse<'a>(i: &'a str) -> Result<Self, ParserError<'a>> {
let mut line_num = 1;
let input = match parser::comment_space_newline(i) {
Ok((input, n)) => {
line_num += n;
input
}
Err(e) => return Err(ParserError::NomError(line_num, e)),
};
let (input, key) = match parser::key::<nom::error::Error<&str>>(input) {
Ok(res) => res,
Err(e) => return Err(ParserError::NomError(line_num, e)),
};
if key == "library" {
match <Self as GroupAttri>::nom_parse(input, &mut line_num) {
Err(e) => return Err(ParserError::NomError(line_num, e)),
Ok((_, Err(e))) => return Err(ParserError::IdError(line_num, e)),
Ok((_, Ok(l))) => return Ok(l),
}
} else {
Err(ParserError::Other(line_num, format!("Need key=library, find={}", key)))
}
}
}