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
68
69
70
71
72
73
74
75
76
77
78
79
//! Tydi nets (e.g. wires and ports) and connections between them.

use tydi_intern::Id;

use crate::{component::Instance, identifier::Identifier, r#type::Type};

/// An I/O mode.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Mode {
    /// An input.
    Input,
    /// An output.
    Output,
}

/// A wire inside a component.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Wire {
    /// The identifier of the wire.
    pub identifier: Id<Identifier>,
    /// The type of the wire.
    pub typ: Id<Type>,
    // TODO: default driver
}

/// A port of a component.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Port {
    /// The identifier of the port.
    pub identifier: Id<Identifier>,
    /// The mode of the port.
    pub mode: Mode,
    /// The type of the port.
    pub typ: Id<Type>,
    // TODO: default driver
}

/// A port of an instance.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct InstancePort {
    /// The instance.
    pub instance: Id<Instance>,
    /// The port of the instance.
    pub port: Id<Port>,
}

impl InstancePort {
    /// Create a new InstancePort.
    pub fn new(instance: Id<Instance>, port: Id<Port>) -> Self {
        Self { instance, port }
    }
}

/// A net that is sinked and sourced.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Net {
    /// A port of the component itself.
    Port(Id<Port>),
    /// A wire inside the component.
    Wire(Wire),
    /// The port of an instance.
    InstancePort(InstancePort),
}

/// A connection between two nets.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Connection {
    /// The sourcing net.
    pub source: Id<Net>,
    /// The sinking net.
    pub sink: Id<Net>,
}

impl Connection {
    /// Create a new connection between source and sink.
    pub fn new(source: Id<Net>, sink: Id<Net>) -> Self {
        Self { source, sink }
    }
}