sv_parser_parser/specify_section/
system_timing_check_event_definitions.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn timing_check_event(s: Span) -> IResult<Span, TimingCheckEvent> {
8    let (s, a) = opt(timing_check_event_control)(s)?;
9    let (s, b) = specify_terminal_descriptor(s)?;
10    let (s, c) = opt(pair(symbol("&&&"), timing_check_condition))(s)?;
11    Ok((s, TimingCheckEvent { nodes: (a, b, c) }))
12}
13
14#[tracable_parser]
15#[packrat_parser]
16pub(crate) fn controlled_timing_check_event(s: Span) -> IResult<Span, ControlledTimingCheckEvent> {
17    let (s, a) = timing_check_event_control(s)?;
18    let (s, b) = specify_terminal_descriptor(s)?;
19    let (s, c) = opt(pair(symbol("&&&"), timing_check_condition))(s)?;
20    Ok((s, ControlledTimingCheckEvent { nodes: (a, b, c) }))
21}
22
23#[tracable_parser]
24#[packrat_parser]
25pub(crate) fn timing_check_event_control(s: Span) -> IResult<Span, TimingCheckEventControl> {
26    alt((
27        map(keyword("posedge"), |x| {
28            TimingCheckEventControl::Posedge(Box::new(x))
29        }),
30        map(keyword("negedge"), |x| {
31            TimingCheckEventControl::Negedge(Box::new(x))
32        }),
33        map(edge_control_specifier, |x| {
34            TimingCheckEventControl::EdgeControlSpecifier(Box::new(x))
35        }),
36        map(keyword("edge"), |x| {
37            TimingCheckEventControl::Edge(Box::new(x))
38        }),
39    ))(s)
40}
41
42#[tracable_parser]
43#[packrat_parser]
44pub(crate) fn specify_terminal_descriptor(s: Span) -> IResult<Span, SpecifyTerminalDescriptor> {
45    alt((
46        map(specify_input_terminal_descriptor, |x| {
47            SpecifyTerminalDescriptor::SpecifyInputTerminalDescriptor(Box::new(x))
48        }),
49        map(specify_output_terminal_descriptor, |x| {
50            SpecifyTerminalDescriptor::SpecifyOutputTerminalDescriptor(Box::new(x))
51        }),
52    ))(s)
53}
54
55#[tracable_parser]
56#[packrat_parser]
57pub(crate) fn edge_control_specifier(s: Span) -> IResult<Span, EdgeControlSpecifier> {
58    let (s, a) = keyword("edge")(s)?;
59    let (s, b) = bracket(list(symbol(","), edge_descriptor))(s)?;
60    Ok((s, EdgeControlSpecifier { nodes: (a, b) }))
61}
62
63#[tracable_parser]
64#[packrat_parser]
65pub(crate) fn edge_descriptor(s: Span) -> IResult<Span, EdgeDescriptor> {
66    alt((
67        map(keyword("01"), |x| EdgeDescriptor { nodes: (x,) }),
68        map(keyword("10"), |x| EdgeDescriptor { nodes: (x,) }),
69        map(keyword("x0"), |x| EdgeDescriptor { nodes: (x,) }),
70        map(keyword("x1"), |x| EdgeDescriptor { nodes: (x,) }),
71        map(keyword("X0"), |x| EdgeDescriptor { nodes: (x,) }),
72        map(keyword("X1"), |x| EdgeDescriptor { nodes: (x,) }),
73        map(keyword("z0"), |x| EdgeDescriptor { nodes: (x,) }),
74        map(keyword("z1"), |x| EdgeDescriptor { nodes: (x,) }),
75        map(keyword("Z0"), |x| EdgeDescriptor { nodes: (x,) }),
76        map(keyword("Z1"), |x| EdgeDescriptor { nodes: (x,) }),
77        map(keyword("0x"), |x| EdgeDescriptor { nodes: (x,) }),
78        map(keyword("1x"), |x| EdgeDescriptor { nodes: (x,) }),
79        map(keyword("0X"), |x| EdgeDescriptor { nodes: (x,) }),
80        map(keyword("1X"), |x| EdgeDescriptor { nodes: (x,) }),
81        map(keyword("0z"), |x| EdgeDescriptor { nodes: (x,) }),
82        map(keyword("1z"), |x| EdgeDescriptor { nodes: (x,) }),
83        map(keyword("0Z"), |x| EdgeDescriptor { nodes: (x,) }),
84        map(keyword("1Z"), |x| EdgeDescriptor { nodes: (x,) }),
85    ))(s)
86}
87
88#[tracable_parser]
89#[packrat_parser]
90pub(crate) fn timing_check_condition(s: Span) -> IResult<Span, TimingCheckCondition> {
91    alt((
92        map(scalar_timing_check_condition, |x| {
93            TimingCheckCondition::ScalarTimingCheckCondition(Box::new(x))
94        }),
95        timing_check_condition_paren,
96    ))(s)
97}
98
99#[tracable_parser]
100#[packrat_parser]
101pub(crate) fn timing_check_condition_paren(s: Span) -> IResult<Span, TimingCheckCondition> {
102    let (s, a) = paren(scalar_timing_check_condition)(s)?;
103    Ok((
104        s,
105        TimingCheckCondition::Paren(Box::new(TimingCheckConditionParen { nodes: (a,) })),
106    ))
107}
108
109#[tracable_parser]
110#[packrat_parser]
111pub(crate) fn scalar_timing_check_condition(s: Span) -> IResult<Span, ScalarTimingCheckCondition> {
112    alt((
113        map(expression, |x| {
114            ScalarTimingCheckCondition::Expression(Box::new(x))
115        }),
116        scalar_timing_check_condition_unary,
117        scalar_timing_check_condition_binary,
118    ))(s)
119}
120
121#[tracable_parser]
122#[packrat_parser]
123pub(crate) fn scalar_timing_check_condition_unary(
124    s: Span,
125) -> IResult<Span, ScalarTimingCheckCondition> {
126    let (s, a) = symbol("~")(s)?;
127    let (s, b) = expression(s)?;
128    Ok((
129        s,
130        ScalarTimingCheckCondition::Unary(Box::new(ScalarTimingCheckConditionUnary {
131            nodes: (a, b),
132        })),
133    ))
134}
135
136#[tracable_parser]
137#[packrat_parser]
138pub(crate) fn scalar_timing_check_condition_binary(
139    s: Span,
140) -> IResult<Span, ScalarTimingCheckCondition> {
141    let (s, a) = expression(s)?;
142    let (s, b) = alt((symbol("==="), symbol("=="), symbol("!=="), symbol("!=")))(s)?;
143    let (s, c) = scalar_constant(s)?;
144    Ok((
145        s,
146        ScalarTimingCheckCondition::Binary(Box::new(ScalarTimingCheckConditionBinary {
147            nodes: (a, b, c),
148        })),
149    ))
150}
151
152#[tracable_parser]
153#[packrat_parser]
154pub(crate) fn scalar_constant(s: Span) -> IResult<Span, ScalarConstant> {
155    alt((
156        map(keyword("1'b0"), |x| ScalarConstant { nodes: (x,) }),
157        map(keyword("1'b1"), |x| ScalarConstant { nodes: (x,) }),
158        map(keyword("1'B0"), |x| ScalarConstant { nodes: (x,) }),
159        map(keyword("1'B1"), |x| ScalarConstant { nodes: (x,) }),
160        map(keyword("'b0"), |x| ScalarConstant { nodes: (x,) }),
161        map(keyword("'b1"), |x| ScalarConstant { nodes: (x,) }),
162        map(keyword("'B0"), |x| ScalarConstant { nodes: (x,) }),
163        map(keyword("'B1"), |x| ScalarConstant { nodes: (x,) }),
164        map(keyword("1"), |x| ScalarConstant { nodes: (x,) }),
165        map(keyword("0"), |x| ScalarConstant { nodes: (x,) }),
166    ))(s)
167}