use std::{hash::Hash, str::FromStr, sync::Arc};
use crate::{
ast::GroupComments, common::items::WordSet, expression::IdBooleanExpression,
timing::items::Mode,
};
#[derive(Default, Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set_derive::item(
macro(derive(Debug, Clone,Default);)
)]
pub struct LeakagePower {
#[id]
#[liberty(name)]
name: Vec<String>,
#[liberty(comments)]
_comments: GroupComments<Self>,
#[liberty(undefined)]
_undefined: crate::ast::AttributeList,
#[id]
#[liberty(simple(type = Option))]
power_level: Option<String>,
#[id]
#[liberty(simple)]
related_pg_pin: WordSet,
#[id]
#[liberty(simple(type = Option))]
when: Option<IdBooleanExpression>,
#[liberty(simple)]
value: f64,
#[liberty(complex(type = Option))]
mode: Option<Mode>,
}
#[derive(Debug, Default, Clone, Hash, Eq, PartialEq)]
pub struct LeakagePowerId {
power_level: Option<String>,
related_pg_pin: WordSet,
when: Option<IdBooleanExpression>,
}
#[derive(Default, Debug, Clone)]
#[derive(liberty_macros::Group)]
#[mut_set_derive::item(
macro(derive(Debug, Clone,Default);)
)]
pub struct Statetable {
#[id]
#[liberty(name)]
pub name: [String; 2],
#[liberty(comments)]
_comments: GroupComments<Self>,
#[liberty(undefined)]
_undefined: crate::ast::AttributeList,
#[liberty(simple)]
pub table: Table,
}
#[derive(Debug, Default, Clone, Hash, Eq, PartialEq)]
pub struct StatetableId {
pub input_npde: Vec<String>,
pub internal_node: Vec<String>,
}
#[derive(Default, Debug, Clone)]
pub struct Table {
pub v: Vec<String>,
}
impl std::fmt::Display for Table {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.v, f)
}
}
impl FromStr for Table {
type Err = std::fmt::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self {
v: s
.split("\\\n")
.filter_map(|line| {
let _l = line
.trim_start()
.trim_end_matches(|c: char| c == ',' || c.is_ascii_whitespace());
if _l == "" {
None
} else {
Some(_l.to_owned())
}
})
.collect(),
})
}
}
impl crate::ast::SimpleAttri for Table {
fn nom_parse<'a>(
i: &'a str,
line_num: &mut usize,
) -> nom::IResult<
&'a str,
Result<Self, (Self::Err, crate::ast::AttriValue)>,
nom::error::Error<&'a str>,
> {
let (input, simple_multi) = crate::ast::parser::simple_multi(i, line_num)?;
match Self::parse(simple_multi) {
Ok(s) => Ok((input, Ok(s))),
Err(e) => {
Ok((input, Err((e, crate::ast::AttriValue::Simple(simple_multi.to_string())))))
}
}
}
}
#[test]
fn statetable_test() {
let _ = crate::ast::test_parse_group::<Statetable>(
r#"(" CLK EN SE",ENL) {
table : " H L L : - : L ,\
H L H : - : H ,\
H H L : - : H ,\
H H H : - : H ,\
L - - : - : N ";
}
"#,
);
}