prjunnamed_netlist/cell/
target.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::{IoValue, Net, TargetPrototype, Value};

use crate::ParamValue;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TargetCell {
    pub kind: String,
    pub params: Vec<ParamValue>,
    pub inputs: Value,
    pub output_len: usize,
    pub ios: IoValue,
}

impl TargetCell {
    pub fn new(kind: impl Into<String>, prototype: &TargetPrototype) -> Self {
        let mut result = Self {
            kind: kind.into(),
            params: vec![],
            inputs: Value::new(),
            output_len: prototype.output_len,
            ios: IoValue::floating(prototype.io_len),
        };
        for param in &prototype.params {
            result.params.push(param.default.clone());
        }
        for input in &prototype.inputs {
            result.inputs.extend(Value::from(&input.default));
        }
        result
    }

    pub fn visit(&self, f: impl FnMut(Net)) {
        self.inputs.visit(f);
    }

    pub fn visit_mut(&mut self, f: impl FnMut(&mut Net)) {
        self.inputs.visit_mut(f);
    }
}