1use super::value::{Expr, TypeInfo};
9
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
12pub enum BinKind {
13 Normal,
14 Ignore,
15 Illegal,
16}
17
18#[derive(Clone, Debug, PartialEq)]
20pub enum ArrayKind {
21 None,
23 Open,
25 Fixed(Expr),
27}
28
29#[derive(Clone, Debug, PartialEq)]
31pub enum Bound {
32 Expr(Expr),
33 Dollar,
34}
35
36#[derive(Clone, Debug, PartialEq)]
38pub enum RangeItem {
39 Single(Expr),
41 Range(Bound, Bound),
43 Tolerance {
46 center: Expr,
47 tol: Expr,
48 relative: bool,
49 },
50}
51
52#[derive(Clone, Debug, PartialEq)]
54pub struct RepeatRange {
55 pub lo: Expr,
56 pub hi: Option<Expr>,
57}
58
59impl RepeatRange {
60 pub fn exactly(n: i128) -> RepeatRange {
61 RepeatRange {
62 lo: Expr::int(n),
63 hi: None,
64 }
65 }
66
67 pub fn between(lo: i128, hi: i128) -> RepeatRange {
68 RepeatRange {
69 lo: Expr::int(lo),
70 hi: Some(Expr::int(hi)),
71 }
72 }
73}
74
75#[derive(Clone, Debug, PartialEq)]
77pub enum TransRep {
78 Once,
79 Consecutive(RepeatRange),
81 Goto(RepeatRange),
83 NonConsecutive(RepeatRange),
85}
86
87#[derive(Clone, Debug, PartialEq)]
89pub struct TransItem {
90 pub values: Vec<RangeItem>,
91 pub rep: TransRep,
92}
93
94impl TransItem {
95 pub fn new(values: Vec<RangeItem>) -> TransItem {
96 TransItem {
97 values,
98 rep: TransRep::Once,
99 }
100 }
101
102 pub fn rep(mut self, rep: TransRep) -> TransItem {
103 self.rep = rep;
104 self
105 }
106}
107
108pub type TransSet = Vec<TransItem>;
110
111#[derive(Clone, Debug, PartialEq)]
113pub enum BinBody {
114 Trans(Vec<TransSet>),
116 DefaultSeq,
118 Ranges {
122 items: Vec<RangeItem>,
123 with: Option<Expr>,
124 },
125 Set(Expr),
127 Default,
129}
130
131#[derive(Clone, Debug, PartialEq)]
132pub struct BinDecl {
133 pub name: String,
134 pub kind: BinKind,
135 pub array: ArrayKind,
136 pub wildcard: bool,
137 pub iff: Option<Expr>,
139 pub body: BinBody,
140}
141
142impl BinDecl {
143 pub fn ranges(name: &str, items: Vec<RangeItem>) -> BinDecl {
145 BinDecl {
146 name: name.to_string(),
147 kind: BinKind::Normal,
148 array: ArrayKind::None,
149 wildcard: false,
150 iff: None,
151 body: BinBody::Ranges { items, with: None },
152 }
153 }
154
155 pub fn kind(mut self, kind: BinKind) -> BinDecl {
156 self.kind = kind;
157 self
158 }
159
160 pub fn array(mut self, array: ArrayKind) -> BinDecl {
161 self.array = array;
162 self
163 }
164
165 pub fn wildcard(mut self) -> BinDecl {
166 self.wildcard = true;
167 self
168 }
169
170 pub fn iff(mut self, iff: Expr) -> BinDecl {
171 self.iff = Some(iff);
172 self
173 }
174
175 pub fn with(mut self, with: Expr) -> BinDecl {
176 if let BinBody::Ranges { with: w, .. } = &mut self.body {
177 *w = Some(with);
178 }
179 self
180 }
181
182 pub fn trans(name: &str, sets: Vec<TransSet>) -> BinDecl {
184 BinDecl {
185 name: name.to_string(),
186 kind: BinKind::Normal,
187 array: ArrayKind::None,
188 wildcard: false,
189 iff: None,
190 body: BinBody::Trans(sets),
191 }
192 }
193
194 pub fn default_seq(name: &str) -> BinDecl {
196 BinDecl {
197 name: name.to_string(),
198 kind: BinKind::Normal,
199 array: ArrayKind::None,
200 wildcard: false,
201 iff: None,
202 body: BinBody::DefaultSeq,
203 }
204 }
205
206 pub fn default_bin(name: &str) -> BinDecl {
207 BinDecl {
208 name: name.to_string(),
209 kind: BinKind::Normal,
210 array: ArrayKind::None,
211 wildcard: false,
212 iff: None,
213 body: BinBody::Default,
214 }
215 }
216}
217
218#[derive(Clone, Debug, PartialEq)]
220pub enum Matches {
221 Count(Expr),
224 All,
226}
227
228impl Matches {
229 pub fn one() -> Matches {
231 Matches::Count(Expr::int(1))
232 }
233}
234
235#[derive(Clone, Debug, PartialEq)]
237pub enum SelectExpr {
238 Binsof {
241 cp: String,
242 bin: Option<String>,
243 intersect: Option<Vec<RangeItem>>,
244 },
245 Not(Box<SelectExpr>),
246 And(Box<SelectExpr>, Box<SelectExpr>),
247 Or(Box<SelectExpr>, Box<SelectExpr>),
248 With {
251 sel: Box<SelectExpr>,
252 expr: Expr,
253 matches: Matches,
254 },
255 All,
257 Set {
261 expr: Expr,
262 matches: Matches,
263 },
264}
265
266#[derive(Clone, Debug, PartialEq)]
269pub struct CrossBinDecl {
270 pub name: String,
271 pub kind: BinKind,
272 pub select: SelectExpr,
273 pub iff: Option<Expr>,
275}
276
277impl CrossBinDecl {
278 pub fn new(name: &str, kind: BinKind, select: SelectExpr) -> CrossBinDecl {
279 CrossBinDecl {
280 name: name.to_string(),
281 kind,
282 select,
283 iff: None,
284 }
285 }
286
287 pub fn iff(mut self, iff: Expr) -> CrossBinDecl {
288 self.iff = Some(iff);
289 self
290 }
291}
292
293#[derive(Clone, Debug, PartialEq)]
295pub struct CrossDecl {
296 pub name: String,
297 pub items: Vec<String>,
300 pub iff: Option<Expr>,
302 pub bins: Vec<CrossBinDecl>,
303 pub options: Vec<(String, Expr)>,
304 pub type_options: Vec<(String, Expr)>,
305}
306
307impl CrossDecl {
308 pub fn new(name: &str, items: &[&str]) -> CrossDecl {
309 CrossDecl {
310 name: name.to_string(),
311 items: items.iter().map(|s| s.to_string()).collect(),
312 iff: None,
313 bins: Vec::new(),
314 options: Vec::new(),
315 type_options: Vec::new(),
316 }
317 }
318
319 pub fn bin(mut self, bin: CrossBinDecl) -> CrossDecl {
320 self.bins.push(bin);
321 self
322 }
323}
324
325#[derive(Clone, Debug, PartialEq)]
327pub struct CoverpointDecl {
328 pub name: String,
329 pub ty: TypeInfo,
330 pub expr: Expr,
332 pub iff: Option<Expr>,
334 pub bins: Vec<BinDecl>,
335 pub enum_values: Option<Vec<(String, i128)>>,
338 pub options: Vec<(String, Expr)>,
340 pub type_options: Vec<(String, Expr)>,
342}
343
344#[derive(Clone, Debug, PartialEq)]
346pub struct CovGroupDecl {
347 pub name: String,
348 pub options: Vec<(String, Expr)>,
351 pub type_options: Vec<(String, Expr)>,
354 pub coverpoints: Vec<CoverpointDecl>,
355 pub crosses: Vec<CrossDecl>,
356}
357
358impl CovGroupDecl {
359 pub fn new(name: &str) -> CovGroupDecl {
360 CovGroupDecl {
361 name: name.to_string(),
362 options: Vec::new(),
363 type_options: Vec::new(),
364 coverpoints: Vec::new(),
365 crosses: Vec::new(),
366 }
367 }
368
369 pub fn coverpoint(mut self, cp: CoverpointDecl) -> CovGroupDecl {
370 self.coverpoints.push(cp);
371 self
372 }
373
374 pub fn cross(mut self, x: CrossDecl) -> CovGroupDecl {
375 self.crosses.push(x);
376 self
377 }
378
379 pub fn option(mut self, name: &str, v: Expr) -> CovGroupDecl {
380 self.options.push((name.to_string(), v));
381 self
382 }
383
384 pub fn type_option(mut self, name: &str, v: Expr) -> CovGroupDecl {
385 self.type_options.push((name.to_string(), v));
386 self
387 }
388}
389
390impl CoverpointDecl {
391 pub fn new(name: &str, ty: TypeInfo, expr: Expr) -> CoverpointDecl {
392 CoverpointDecl {
393 name: name.to_string(),
394 ty,
395 expr,
396 iff: None,
397 bins: Vec::new(),
398 enum_values: None,
399 options: Vec::new(),
400 type_options: Vec::new(),
401 }
402 }
403
404 pub fn bin(mut self, bin: BinDecl) -> CoverpointDecl {
405 self.bins.push(bin);
406 self
407 }
408}