sv_parser_parser/behavioral_statements/
clocking_block.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn clocking_declaration(s: Span) -> IResult<Span, ClockingDeclaration> {
8    alt((clocking_declaration_local, clocking_declaration_global))(s)
9}
10
11#[tracable_parser]
12#[packrat_parser]
13pub(crate) fn clocking_declaration_local(s: Span) -> IResult<Span, ClockingDeclaration> {
14    let (s, a) = opt(default)(s)?;
15    let (s, b) = keyword("clocking")(s)?;
16    let (s, c) = opt(clocking_identifier)(s)?;
17    let (s, d) = clocking_event(s)?;
18    let (s, e) = symbol(";")(s)?;
19    let (s, (f, g)) = many_till(clocking_item, keyword("endclocking"))(s)?;
20    let (s, h) = opt(pair(symbol(":"), clocking_identifier))(s)?;
21    Ok((
22        s,
23        ClockingDeclaration::Local(Box::new(ClockingDeclarationLocal {
24            nodes: (a, b, c, d, e, f, g, h),
25        })),
26    ))
27}
28
29#[tracable_parser]
30#[packrat_parser]
31pub(crate) fn default(s: Span) -> IResult<Span, Default> {
32    let (s, a) = keyword("default")(s)?;
33    Ok((s, Default { nodes: (a,) }))
34}
35
36#[tracable_parser]
37#[packrat_parser]
38pub(crate) fn clocking_declaration_global(s: Span) -> IResult<Span, ClockingDeclaration> {
39    let (s, a) = keyword("global")(s)?;
40    let (s, b) = keyword("clocking")(s)?;
41    let (s, c) = opt(clocking_identifier)(s)?;
42    let (s, d) = clocking_event(s)?;
43    let (s, e) = symbol(";")(s)?;
44    let (s, f) = keyword("endclocking")(s)?;
45    let (s, g) = opt(pair(symbol(":"), clocking_identifier))(s)?;
46    Ok((
47        s,
48        ClockingDeclaration::Global(Box::new(ClockingDeclarationGlobal {
49            nodes: (a, b, c, d, e, f, g),
50        })),
51    ))
52}
53
54#[tracable_parser]
55#[packrat_parser]
56pub(crate) fn clocking_event(s: Span) -> IResult<Span, ClockingEvent> {
57    alt((clocking_event_identifier, clocking_event_expression))(s)
58}
59
60#[tracable_parser]
61#[packrat_parser]
62pub(crate) fn clocking_event_identifier(s: Span) -> IResult<Span, ClockingEvent> {
63    let (s, a) = symbol("@")(s)?;
64    let (s, b) = identifier(s)?;
65    Ok((
66        s,
67        ClockingEvent::Identifier(Box::new(ClockingEventIdentifier { nodes: (a, b) })),
68    ))
69}
70
71#[tracable_parser]
72#[packrat_parser]
73pub(crate) fn clocking_event_expression(s: Span) -> IResult<Span, ClockingEvent> {
74    let (s, a) = symbol("@")(s)?;
75    let (s, b) = paren(event_expression)(s)?;
76    Ok((
77        s,
78        ClockingEvent::Expression(Box::new(ClockingEventExpression { nodes: (a, b) })),
79    ))
80}
81
82#[tracable_parser]
83#[packrat_parser]
84pub(crate) fn clocking_item(s: Span) -> IResult<Span, ClockingItem> {
85    alt((
86        clocking_item_default,
87        clocking_item_direction,
88        clocking_item_assertion,
89    ))(s)
90}
91
92#[tracable_parser]
93#[packrat_parser]
94pub(crate) fn clocking_item_default(s: Span) -> IResult<Span, ClockingItem> {
95    let (s, a) = keyword("default")(s)?;
96    let (s, b) = default_skew(s)?;
97    let (s, c) = symbol(";")(s)?;
98    Ok((
99        s,
100        ClockingItem::Default(Box::new(ClockingItemDefault { nodes: (a, b, c) })),
101    ))
102}
103
104#[tracable_parser]
105#[packrat_parser]
106pub(crate) fn clocking_item_direction(s: Span) -> IResult<Span, ClockingItem> {
107    let (s, a) = clocking_direction(s)?;
108    let (s, b) = list_of_clocking_decl_assign(s)?;
109    let (s, c) = symbol(";")(s)?;
110    Ok((
111        s,
112        ClockingItem::Direction(Box::new(ClockingItemDirection { nodes: (a, b, c) })),
113    ))
114}
115
116#[tracable_parser]
117#[packrat_parser]
118pub(crate) fn clocking_item_assertion(s: Span) -> IResult<Span, ClockingItem> {
119    let (s, a) = many0(attribute_instance)(s)?;
120    let (s, b) = assertion_item_declaration(s)?;
121    Ok((
122        s,
123        ClockingItem::Assertion(Box::new(ClockingItemAssertion { nodes: (a, b) })),
124    ))
125}
126
127#[tracable_parser]
128#[packrat_parser]
129pub(crate) fn default_skew(s: Span) -> IResult<Span, DefaultSkew> {
130    alt((
131        default_skew_input_output,
132        default_skew_input,
133        default_skew_output,
134    ))(s)
135}
136
137#[tracable_parser]
138#[packrat_parser]
139pub(crate) fn default_skew_input(s: Span) -> IResult<Span, DefaultSkew> {
140    let (s, a) = keyword("input")(s)?;
141    let (s, b) = clocking_skew(s)?;
142    Ok((
143        s,
144        DefaultSkew::Input(Box::new(DefaultSkewInput { nodes: (a, b) })),
145    ))
146}
147
148#[tracable_parser]
149#[packrat_parser]
150pub(crate) fn default_skew_output(s: Span) -> IResult<Span, DefaultSkew> {
151    let (s, a) = keyword("output")(s)?;
152    let (s, b) = clocking_skew(s)?;
153    Ok((
154        s,
155        DefaultSkew::Output(Box::new(DefaultSkewOutput { nodes: (a, b) })),
156    ))
157}
158
159#[tracable_parser]
160#[packrat_parser]
161pub(crate) fn default_skew_input_output(s: Span) -> IResult<Span, DefaultSkew> {
162    let (s, a) = keyword("input")(s)?;
163    let (s, b) = clocking_skew(s)?;
164    let (s, c) = keyword("output")(s)?;
165    let (s, d) = clocking_skew(s)?;
166    Ok((
167        s,
168        DefaultSkew::InputOutput(Box::new(DefaultSkewInputOutput {
169            nodes: (a, b, c, d),
170        })),
171    ))
172}
173
174#[tracable_parser]
175#[packrat_parser]
176pub(crate) fn clocking_direction(s: Span) -> IResult<Span, ClockingDirection> {
177    alt((
178        clocking_direction_input_output,
179        clocking_direction_input,
180        clocking_direction_output,
181        clocking_direction_inout,
182    ))(s)
183}
184
185#[tracable_parser]
186#[packrat_parser]
187pub(crate) fn clocking_direction_input(s: Span) -> IResult<Span, ClockingDirection> {
188    let (s, a) = keyword("input")(s)?;
189    let (s, b) = opt(clocking_skew)(s)?;
190    Ok((
191        s,
192        ClockingDirection::Input(Box::new(ClockingDirectionInput { nodes: (a, b) })),
193    ))
194}
195
196#[tracable_parser]
197#[packrat_parser]
198pub(crate) fn clocking_direction_output(s: Span) -> IResult<Span, ClockingDirection> {
199    let (s, a) = keyword("output")(s)?;
200    let (s, b) = opt(clocking_skew)(s)?;
201    Ok((
202        s,
203        ClockingDirection::Output(Box::new(ClockingDirectionOutput { nodes: (a, b) })),
204    ))
205}
206
207#[tracable_parser]
208#[packrat_parser]
209pub(crate) fn clocking_direction_input_output(s: Span) -> IResult<Span, ClockingDirection> {
210    let (s, a) = keyword("input")(s)?;
211    let (s, b) = opt(clocking_skew)(s)?;
212    let (s, c) = keyword("output")(s)?;
213    let (s, d) = opt(clocking_skew)(s)?;
214    Ok((
215        s,
216        ClockingDirection::InputOutput(Box::new(ClockingDirectionInputOutput {
217            nodes: (a, b, c, d),
218        })),
219    ))
220}
221
222#[tracable_parser]
223#[packrat_parser]
224pub(crate) fn clocking_direction_inout(s: Span) -> IResult<Span, ClockingDirection> {
225    let (s, a) = keyword("inout")(s)?;
226    Ok((s, ClockingDirection::Inout(Box::new(a))))
227}
228
229#[tracable_parser]
230#[packrat_parser]
231pub(crate) fn list_of_clocking_decl_assign(s: Span) -> IResult<Span, ListOfClockingDeclAssign> {
232    let (s, a) = list(symbol(","), clocking_decl_assign)(s)?;
233    Ok((s, ListOfClockingDeclAssign { nodes: (a,) }))
234}
235
236#[tracable_parser]
237#[packrat_parser]
238pub(crate) fn clocking_decl_assign(s: Span) -> IResult<Span, ClockingDeclAssign> {
239    let (s, a) = signal_identifier(s)?;
240    let (s, b) = opt(pair(symbol("="), expression))(s)?;
241    Ok((s, ClockingDeclAssign { nodes: (a, b) }))
242}
243
244#[tracable_parser]
245#[packrat_parser]
246pub(crate) fn clocking_skew(s: Span) -> IResult<Span, ClockingSkew> {
247    alt((
248        clocking_skew_edge,
249        map(delay_control, |x| ClockingSkew::DelayControl(Box::new(x))),
250    ))(s)
251}
252
253#[tracable_parser]
254#[packrat_parser]
255pub(crate) fn clocking_skew_edge(s: Span) -> IResult<Span, ClockingSkew> {
256    let (s, a) = edge_identifier(s)?;
257    let (s, b) = opt(delay_control)(s)?;
258    Ok((
259        s,
260        ClockingSkew::Edge(Box::new(ClockingSkewEdge { nodes: (a, b) })),
261    ))
262}
263
264#[tracable_parser]
265#[packrat_parser]
266pub(crate) fn clocking_drive(s: Span) -> IResult<Span, ClockingDrive> {
267    let (s, a) = clockvar_expression(s)?;
268    let (s, b) = symbol("<=")(s)?;
269    let (s, c) = opt(cycle_delay)(s)?;
270    let (s, d) = expression(s)?;
271    Ok((
272        s,
273        ClockingDrive {
274            nodes: (a, b, c, d),
275        },
276    ))
277}
278
279#[tracable_parser]
280#[packrat_parser]
281pub(crate) fn cycle_delay(s: Span) -> IResult<Span, CycleDelay> {
282    alt((
283        cycle_delay_integral,
284        cycle_delay_identifier,
285        cycle_delay_expression,
286    ))(s)
287}
288
289#[tracable_parser]
290#[packrat_parser]
291pub(crate) fn cycle_delay_integral(s: Span) -> IResult<Span, CycleDelay> {
292    let (s, a) = symbol("##")(s)?;
293    let (s, b) = integral_number(s)?;
294    Ok((
295        s,
296        CycleDelay::Integral(Box::new(CycleDelayIntegral { nodes: (a, b) })),
297    ))
298}
299
300#[tracable_parser]
301#[packrat_parser]
302pub(crate) fn cycle_delay_identifier(s: Span) -> IResult<Span, CycleDelay> {
303    let (s, a) = symbol("##")(s)?;
304    let (s, b) = identifier(s)?;
305    Ok((
306        s,
307        CycleDelay::Identifier(Box::new(CycleDelayIdentifier { nodes: (a, b) })),
308    ))
309}
310
311#[tracable_parser]
312#[packrat_parser]
313pub(crate) fn cycle_delay_expression(s: Span) -> IResult<Span, CycleDelay> {
314    let (s, a) = symbol("##")(s)?;
315    let (s, b) = paren(expression)(s)?;
316    Ok((
317        s,
318        CycleDelay::Expression(Box::new(CycleDelayExpression { nodes: (a, b) })),
319    ))
320}
321
322#[tracable_parser]
323#[packrat_parser]
324pub(crate) fn clockvar(s: Span) -> IResult<Span, Clockvar> {
325    let (s, a) = hierarchical_identifier(s)?;
326    Ok((s, Clockvar { nodes: (a,) }))
327}
328
329#[tracable_parser]
330#[packrat_parser]
331pub(crate) fn clockvar_expression(s: Span) -> IResult<Span, ClockvarExpression> {
332    let (s, a) = clockvar(s)?;
333    let (s, b) = select(s)?;
334    Ok((s, ClockvarExpression { nodes: (a, b) }))
335}