pub mod logic;
mod port;
mod test;
use enum_dispatch::enum_dispatch;
pub use port::Port;
mod statetable;
pub use statetable::*;
mod ff;
pub use ff::{Ff, FfExpression};
mod latch;
pub use latch::{Latch, LatchExpression, LatchFfId};
mod function;
pub use function::FunctionExpression;
mod condition;
pub use condition::ConditionExpression;
mod tri_state;
use std::{
collections::HashMap,
fmt::{Debug, Display},
hash::Hash,
};
pub use tri_state::TriState;
#[enum_dispatch(BooleanExpression)]
pub trait BooleanExpressionLike: Display + Debug + Clone {
fn table(&self) -> logic::Table;
}
#[derive(Debug, Clone)]
#[enum_dispatch]
#[derive(serde::Serialize, serde::Deserialize)]
pub enum BooleanExpression {
Port(Port),
FF(FfExpression),
Latch(LatchExpression),
Function(FunctionExpression),
TriState(TriState),
}
impl Display for BooleanExpression {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BooleanExpression::Port(exp) => fmt::Display::fmt(&exp, f),
BooleanExpression::FF(exp) => fmt::Display::fmt(&exp, f),
BooleanExpression::Latch(exp) => fmt::Display::fmt(&exp, f),
BooleanExpression::Function(exp) => fmt::Display::fmt(&exp, f),
BooleanExpression::TriState(exp) => fmt::Display::fmt(&exp, f),
}
}
}
impl PartialEq for BooleanExpression {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.table() == other.table()
}
}
impl Eq for BooleanExpression {}
impl Hash for BooleanExpression {
#[inline]
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.table().hash(state);
}
}
impl std::str::FromStr for BooleanExpression {
type Err = fmt::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
todo!()
}
}
const BRACKET_L: char = '(';
const BRACKET_R: char = ')';
impl BooleanExpression {
pub fn from_str(
s: &str,
ff_map: &HashMap<LatchFfId, Ff>,
latch_map: &HashMap<LatchFfId, Latch>,
) -> Result<Self, fmt::Error> {
let l_pos_list = s.match_indices(BRACKET_L).map(|(i, _)| i).collect::<Vec<usize>>();
let r_pos_list = s.match_indices(BRACKET_R).map(|(i, _)| i).collect::<Vec<usize>>();
todo!()
}
}