~ruther/gtkwave-tcl-generator

ref: 0f5f43a5584cc3f4e7571d635a06ce126d1001dd gtkwave-tcl-generator/src/display_elements.rs -rw-r--r-- 3.1 KiB
0f5f43a5 — František Boháček feat: Add parser and tcl generator 2 years ago
                                                                                
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use std::{slice::Iter, fmt::Display};

#[derive(Eq, PartialEq, Clone)]
pub enum DisplayElement {
    Signal(Signal),
    Empty(Vec<DisplayOption>)
}

#[derive(Eq, PartialEq, Clone, Copy)]
pub enum DisplayOption {
    Color(DisplayColor),
    Format(DisplayFormat),
    Omit
}

#[derive(Eq, PartialEq, Clone)]
pub struct Signal {
    name: String,
    options: Vec<DisplayOption>
}

impl From<&str> for Signal {
    fn from(value: &str) -> Self {
        Self {
            name: value.to_owned(),
            options: vec![]
        }
    }
}

#[derive(Eq, PartialEq, Clone)]
pub struct Entity {
    name: String,
    architecture: Option<Architecture>,
}

#[derive(Eq, PartialEq, Clone)]
pub struct Architecture {
    name: String,
    entity_name: String,
    signals: Vec<Signal>
}

#[derive(Eq, PartialEq, Copy, Clone)]
pub enum DisplayColor {
    Normal,
    Red,
    Orange,
    Yellow,
    Green,
    Blue,
    Indigo,
    Violet,
    Cycle,
}

impl Display for DisplayColor {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", match self {
            DisplayColor::Normal => "Normal",
            DisplayColor::Red => "Red",
            DisplayColor::Orange => "Orange",
            DisplayColor::Yellow => "Yellow",
            DisplayColor::Green => "Green",
            DisplayColor::Blue => "Blue",
            DisplayColor::Indigo => "Indigo",
            DisplayColor::Violet => "Violet",
            DisplayColor::Cycle => "Cycle",
        })
    }
}

#[derive(Eq, PartialEq, Copy, Clone)]
pub enum DisplayFormat {
    Hex,
    Decimal,
    SignedDecimal,
    Binary,
}

impl Display for DisplayFormat {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", match self {
            DisplayFormat::Hex => "Hex",
            DisplayFormat::Decimal => "Decimal",
            DisplayFormat::SignedDecimal => "SignedDecimal",
            DisplayFormat::Binary => "Binary",
        })
    }
}

impl Signal {
    pub fn new(name: String, options: Vec<DisplayOption>) -> Self {
        Self {
            name,
            options
        }
    }

    pub fn name(&self) -> &str {
        &self.name
    }

    pub fn options(&self) -> Iter<'_, DisplayOption> {
        self.options.iter()
    }
}

impl Entity {
    pub fn new(name: String) -> Self {
        Self {
            name,
            architecture: None
        }
    }

    pub fn name(&self) -> &str {
        &self.name
    }

    pub fn add_architecture(&mut self, architecture: Architecture) {
        self.architecture = Some(architecture);
    }

    pub fn architecture(&self) -> Option<&Architecture> {
        self.architecture.as_ref()
    }
}

impl Architecture {
    pub fn new(name: String, entity_name: String, signals: Vec<Signal>) -> Self {
        Self {
            name,
            entity_name,
            signals,
        }
    }

    pub fn signals(&self) -> Iter<'_, Signal> {
        self.signals.iter()
    }

    pub fn name(&self) -> &str {
        &self.name
    }

    pub fn entity_name(&self) -> &str {
        &self.entity_name
    }
}