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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::core::ast::VerilogLiteral;
use crate::core::constraint::PinConstraint;
use crate::core::prelude::TypeKind;
use crate::core::synth::VCDValue;
use crate::core::type_descriptor::TypeDescriptor;

#[doc(hidden)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum AtomKind {
    InputParameter,
    OutputParameter,
    StubInputSignal,
    StubOutputSignal,
    Constant,
    LocalSignal,
    InOutParameter,
    OutputPassthrough,
}

impl AtomKind {
    pub fn is_parameter(&self) -> bool {
        match self {
            AtomKind::InputParameter
            | AtomKind::OutputParameter
            | AtomKind::InOutParameter
            | AtomKind::OutputPassthrough => true,
            _ => false,
        }
    }
    pub fn is_stub(&self) -> bool {
        match self {
            AtomKind::StubInputSignal | AtomKind::StubOutputSignal => true,
            _ => false,
        }
    }
}

#[doc(hidden)]
pub trait Atom {
    fn bits(&self) -> usize;
    fn connected(&self) -> bool;
    fn changed(&self) -> bool;
    fn kind(&self) -> AtomKind;
    fn descriptor(&self) -> TypeDescriptor;
    fn vcd(&self) -> VCDValue;
    fn id(&self) -> usize;
    fn verilog(&self) -> VerilogLiteral;
    fn constraints(&self) -> Vec<PinConstraint>;
}

pub fn is_atom_an_enum(atom: &dyn Atom) -> bool {
    match atom.descriptor().kind {
        TypeKind::Enum(_) => true,
        _ => false,
    }
}

pub fn is_atom_signed(atom: &dyn Atom) -> bool {
    match atom.descriptor().kind {
        TypeKind::Signed(_) => true,
        _ => false,
    }
}

pub fn get_atom_typename(atom: &dyn Atom) -> String {
    atom.descriptor().name.to_string()
}