1#![deny(missing_docs)]
2mod attribute;
14mod cell;
15mod characters;
16mod connect;
17mod constant;
18mod design;
19mod identifier;
20mod memory;
21mod module;
22mod process;
23mod sigspec;
24mod string;
25mod switch;
26mod sync;
27mod value;
28mod wire;
29
30use std::collections::HashMap;
31
32use getset::Getters;
33use nom_locate::LocatedSpan;
34use nom_tracable::TracableInfo;
35use serde::Serialize;
36
37#[derive(Debug, Clone, PartialEq, Serialize, Eq)]
39pub enum Id {
40 Public(String),
42 Autogen(String),
44}
45
46#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
48#[getset(get = "pub")]
49pub struct Design {
50 autoidx: Option<i32>,
52 modules: HashMap<String, Module>,
54}
55
56#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
59#[getset(get = "pub")]
60pub struct Module {
61 attributes: HashMap<String, Constant>,
63 parameters: HashMap<String, Option<Constant>>,
65 wires: HashMap<Id, Wire>,
67 memories: HashMap<String, Memory>,
69 cells: HashMap<String, Cell>,
71 processes: HashMap<String, Process>,
73 connections: Vec<(SigSpec, SigSpec)>,
75}
76
77#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
79#[getset(get = "pub")]
80pub struct Cell {
81 cell_type: String,
83 parameters: HashMap<String, Constant>,
85 connections: HashMap<String, SigSpec>,
87}
88
89#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
91#[getset(get = "pub")]
92pub struct Wire {
93 width: usize,
95 offset: usize,
97 input: bool,
99 output: bool,
101 inout: bool,
103 upto: bool,
105 signed: bool,
107 attributes: HashMap<String, Constant>,
109}
110
111#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
113#[getset(get = "pub")]
114pub struct Memory {
115 width: usize,
117 size: usize,
119 offset: usize,
121 attributes: HashMap<String, Constant>,
123}
124
125#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
127#[getset(get = "pub")]
128pub struct Process {
129 attributes: HashMap<String, Constant>,
131 assignments: Vec<(SigSpec, SigSpec)>,
133 switches: Vec<Switch>,
135 syncs: Vec<Sync>,
137}
138
139#[derive(Debug, Clone, PartialEq, Serialize)]
141pub enum Constant {
142 Value(Vec<char>),
144 Integer(i32),
146 String(String),
148}
149
150#[derive(Debug, Clone, PartialEq, Serialize)]
152pub enum SigSpec {
153 Constant(Constant),
155 WireId(String),
157 Range(Box<SigSpec>, usize, Option<usize>),
159 Concat(Vec<SigSpec>),
161}
162
163#[derive(Debug, Clone, PartialEq, Serialize)]
165pub enum CaseBody {
166 Switch(Switch),
168 Assign((SigSpec, SigSpec)),
170}
171
172#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
174#[getset(get = "pub")]
175pub struct Case {
176 pub(crate) attributes: HashMap<String, Constant>,
178 pub(crate) compare_against: Option<Vec<SigSpec>>,
180 pub(crate) case_bodies: Vec<CaseBody>,
182}
183
184#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
186#[getset(get = "pub")]
187pub struct Switch {
188 pub(crate) attributes: HashMap<String, Constant>,
190 pub(crate) switch_on_sigspec: SigSpec,
192 pub(crate) cases: Vec<Case>,
194}
195
196#[derive(Debug, Clone, PartialEq, Serialize)]
198pub enum SyncOn {
199 Global,
201 Init,
203 Always,
205 Signal(SignalSync, SigSpec),
207}
208
209#[derive(Debug, Clone, PartialEq, Serialize)]
211pub enum SignalSync {
212 Low,
214 High,
216 Posedge,
218 Negedge,
220 Edge,
222}
223
224#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
226#[getset(get = "pub")]
227pub struct Sync {
228 sync_event: SyncOn,
230 updates: Vec<(SigSpec, SigSpec)>,
232 memwrs: HashMap<String, Memwr>,
234}
235
236#[derive(Debug, Clone, PartialEq, Getters, Serialize)]
238#[getset(get = "pub")]
239pub struct Memwr {
240 attributes: HashMap<String, Constant>,
242 address: SigSpec,
244 data: SigSpec,
246 enable: SigSpec,
248 priority_mask: SigSpec,
250}
251
252type Span<'a> = LocatedSpan<&'a str, TracableInfo>;
255
256pub fn parse(input: &str) -> Result<Design, Span> {
258 Design::new_from_str(input)
259}
260
261#[cfg(test)]
262mod tests {
263 #[test]
264 fn test_sanity() {
265 assert_eq!(1 + 1, 2);
266 }
267}