use crate::traits::*;
use libreda_db::netlist::prelude::TerminalId;
use libreda_db::prelude::{NetlistBase, NetlistUtil};
pub struct ZeroInterconnectDelayModel<D> {
delay_model: D,
}
impl<D> ZeroInterconnectDelayModel<D> {
pub fn new(delay_model: D) -> Self {
Self { delay_model }
}
}
impl<D> LoadBase for ZeroInterconnectDelayModel<D>
where
D: LoadBase,
{
type Load = D::Load;
fn sum_loads(&self, load1: &Self::Load, load2: &Self::Load) -> Self::Load {
self.delay_model.sum_loads(load1, load2)
}
}
impl<D> TimingBase for ZeroInterconnectDelayModel<D>
where
D: TimingBase,
{
type Signal = D::Signal;
type LogicValue = D::LogicValue;
}
impl<D> DelayBase for ZeroInterconnectDelayModel<D>
where
D: DelayBase,
{
type Delay = D::Delay;
fn summarize_delays(&self, signal1: &Self::Signal, signal2: &Self::Signal) -> Self::Signal {
self.delay_model.summarize_delays(signal1, signal2)
}
fn get_delay(&self, from: &Self::Signal, to: &Self::Signal) -> Self::Delay {
self.delay_model.get_delay(from, to)
}
}
impl<D, N: NetlistBase> InterconnectDelayModel<N> for ZeroInterconnectDelayModel<D>
where
D: DelayBase,
{
fn interconnect_output(
&self,
netlist: &N,
source_terminal: &TerminalId<N>,
input_signal: &Self::Signal,
target_terminal: &TerminalId<N>,
output_load: &Self::Load,
) -> Option<Self::Signal> {
let source_net = netlist.net_of_terminal(source_terminal);
let target_net = netlist.net_of_terminal(target_terminal);
if source_net.is_some() && source_net == target_net {
Some(input_signal.clone())
} else {
None
}
}
}