rust_hdl_core/
atom.rs

1use crate::ast::VerilogLiteral;
2use crate::constraint::PinConstraint;
3use crate::synth::VCDValue;
4use crate::type_descriptor::{TypeDescriptor, TypeKind};
5
6#[doc(hidden)]
7#[derive(Copy, Clone, Debug, PartialEq)]
8pub enum AtomKind {
9    InputParameter,
10    OutputParameter,
11    StubInputSignal,
12    StubOutputSignal,
13    Constant,
14    LocalSignal,
15    InOutParameter,
16    OutputPassthrough,
17}
18
19impl AtomKind {
20    pub fn is_parameter(&self) -> bool {
21        matches!(
22            self,
23            AtomKind::InputParameter
24                | AtomKind::OutputParameter
25                | AtomKind::InOutParameter
26                | AtomKind::OutputPassthrough
27        )
28    }
29    pub fn is_stub(&self) -> bool {
30        matches!(self, AtomKind::StubInputSignal | AtomKind::StubOutputSignal)
31    }
32}
33
34#[doc(hidden)]
35pub trait Atom {
36    fn bits(&self) -> usize;
37    fn connected(&self) -> bool;
38    fn changed(&self) -> bool;
39    fn kind(&self) -> AtomKind;
40    fn descriptor(&self) -> TypeDescriptor;
41    fn vcd(&self) -> VCDValue;
42    fn id(&self) -> usize;
43    fn verilog(&self) -> VerilogLiteral;
44    fn constraints(&self) -> Vec<PinConstraint>;
45}
46
47pub fn is_atom_an_enum(atom: &dyn Atom) -> bool {
48    matches!(atom.descriptor().kind, TypeKind::Enum(_))
49}
50
51pub fn is_atom_signed(atom: &dyn Atom) -> bool {
52    matches!(atom.descriptor().kind, TypeKind::Signed(_))
53}
54
55pub fn get_atom_typename(atom: &dyn Atom) -> String {
56    atom.descriptor().name
57}