sv_parser_parser/specify_section/
specify_path_delays.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn path_delay_value(s: Span) -> IResult<Span, PathDelayValue> {
8    alt((
9        map(list_of_path_delay_expressions, |x| {
10            PathDelayValue::ListOfPathDelayExpressions(Box::new(x))
11        }),
12        path_delay_value_paren,
13    ))(s)
14}
15
16#[tracable_parser]
17#[packrat_parser]
18pub(crate) fn path_delay_value_paren(s: Span) -> IResult<Span, PathDelayValue> {
19    let (s, a) = paren(list_of_path_delay_expressions)(s)?;
20    Ok((
21        s,
22        PathDelayValue::Paren(Box::new(PathDelayValueParen { nodes: (a,) })),
23    ))
24}
25
26#[tracable_parser]
27#[packrat_parser]
28pub(crate) fn list_of_path_delay_expressions(s: Span) -> IResult<Span, ListOfPathDelayExpressions> {
29    let (s, a) = list(symbol(","), t_path_delay_expression)(s)?;
30    Ok((s, ListOfPathDelayExpressions { nodes: (a,) }))
31}
32
33#[tracable_parser]
34#[packrat_parser]
35pub(crate) fn t_path_delay_expression(s: Span) -> IResult<Span, TPathDelayExpression> {
36    let (s, a) = path_delay_expression(s)?;
37    Ok((s, TPathDelayExpression { nodes: (a,) }))
38}
39
40#[tracable_parser]
41#[packrat_parser]
42pub(crate) fn path_delay_expression(s: Span) -> IResult<Span, PathDelayExpression> {
43    let (s, a) = constant_mintypmax_expression(s)?;
44    Ok((s, PathDelayExpression { nodes: (a,) }))
45}
46
47#[tracable_parser]
48#[packrat_parser]
49pub(crate) fn edge_sensitive_path_declaration(
50    s: Span,
51) -> IResult<Span, EdgeSensitivePathDeclaration> {
52    alt((
53        edge_sensitive_path_declaration_parallel,
54        edge_sensitive_path_declaration_full,
55    ))(s)
56}
57
58#[tracable_parser]
59#[packrat_parser]
60pub(crate) fn edge_sensitive_path_declaration_parallel(
61    s: Span,
62) -> IResult<Span, EdgeSensitivePathDeclaration> {
63    let (s, a) = parallel_edge_sensitive_path_description(s)?;
64    let (s, b) = symbol("=")(s)?;
65    let (s, c) = path_delay_value(s)?;
66    Ok((
67        s,
68        EdgeSensitivePathDeclaration::Parallel(Box::new(EdgeSensitivePathDeclarationParallel {
69            nodes: (a, b, c),
70        })),
71    ))
72}
73
74#[tracable_parser]
75#[packrat_parser]
76pub(crate) fn edge_sensitive_path_declaration_full(
77    s: Span,
78) -> IResult<Span, EdgeSensitivePathDeclaration> {
79    let (s, a) = full_edge_sensitive_path_description(s)?;
80    let (s, b) = symbol("=")(s)?;
81    let (s, c) = path_delay_value(s)?;
82    Ok((
83        s,
84        EdgeSensitivePathDeclaration::Full(Box::new(EdgeSensitivePathDeclarationFull {
85            nodes: (a, b, c),
86        })),
87    ))
88}
89
90#[tracable_parser]
91#[packrat_parser]
92pub(crate) fn parallel_edge_sensitive_path_description(
93    s: Span,
94) -> IResult<Span, ParallelEdgeSensitivePathDescription> {
95    let (s, a) = paren(tuple((
96        opt(edge_identifier),
97        specify_input_terminal_descriptor,
98        opt(polarity_operator),
99        symbol("=>"),
100        paren(tuple((
101            specify_output_terminal_descriptor,
102            opt(polarity_operator),
103            symbol(":"),
104            data_source_expression,
105        ))),
106    )))(s)?;
107    Ok((s, ParallelEdgeSensitivePathDescription { nodes: (a,) }))
108}
109
110#[tracable_parser]
111#[packrat_parser]
112pub(crate) fn full_edge_sensitive_path_description(
113    s: Span,
114) -> IResult<Span, FullEdgeSensitivePathDescription> {
115    let (s, a) = paren(tuple((
116        opt(edge_identifier),
117        list_of_path_inputs,
118        opt(polarity_operator),
119        symbol("*>"),
120        paren(tuple((
121            list_of_path_outputs,
122            opt(polarity_operator),
123            symbol(":"),
124            data_source_expression,
125        ))),
126    )))(s)?;
127    Ok((s, FullEdgeSensitivePathDescription { nodes: (a,) }))
128}
129
130#[tracable_parser]
131#[packrat_parser]
132pub(crate) fn data_source_expression(s: Span) -> IResult<Span, DataSourceExpression> {
133    let (s, a) = expression(s)?;
134    Ok((s, DataSourceExpression { nodes: (a,) }))
135}
136
137#[tracable_parser]
138#[packrat_parser]
139pub(crate) fn edge_identifier(s: Span) -> IResult<Span, EdgeIdentifier> {
140    alt((
141        map(keyword("posedge"), |x| EdgeIdentifier::Posedge(Box::new(x))),
142        map(keyword("negedge"), |x| EdgeIdentifier::Negedge(Box::new(x))),
143        map(keyword("edge"), |x| EdgeIdentifier::Edge(Box::new(x))),
144    ))(s)
145}
146
147#[tracable_parser]
148#[packrat_parser]
149pub(crate) fn state_dependent_path_declaration(
150    s: Span,
151) -> IResult<Span, StateDependentPathDeclaration> {
152    alt((
153        state_dependent_path_declaration_if_simple,
154        state_dependent_path_declaration_if_edge_sensitive,
155        state_dependent_path_declaration_if_none,
156    ))(s)
157}
158
159#[tracable_parser]
160#[packrat_parser]
161pub(crate) fn state_dependent_path_declaration_if_simple(
162    s: Span,
163) -> IResult<Span, StateDependentPathDeclaration> {
164    let (s, a) = keyword("if")(s)?;
165    let (s, b) = paren(module_path_expression)(s)?;
166    let (s, c) = simple_path_declaration(s)?;
167    Ok((
168        s,
169        StateDependentPathDeclaration::IfSimple(Box::new(StateDependentPathDeclarationIfSimple {
170            nodes: (a, b, c),
171        })),
172    ))
173}
174
175#[tracable_parser]
176#[packrat_parser]
177pub(crate) fn state_dependent_path_declaration_if_edge_sensitive(
178    s: Span,
179) -> IResult<Span, StateDependentPathDeclaration> {
180    let (s, a) = keyword("if")(s)?;
181    let (s, b) = paren(module_path_expression)(s)?;
182    let (s, c) = edge_sensitive_path_declaration(s)?;
183    Ok((
184        s,
185        StateDependentPathDeclaration::IfEdgeSensitive(Box::new(
186            StateDependentPathDeclarationIfEdgeSensitive { nodes: (a, b, c) },
187        )),
188    ))
189}
190
191#[tracable_parser]
192#[packrat_parser]
193pub(crate) fn state_dependent_path_declaration_if_none(
194    s: Span,
195) -> IResult<Span, StateDependentPathDeclaration> {
196    let (s, a) = keyword("ifnone")(s)?;
197    let (s, b) = simple_path_declaration(s)?;
198    Ok((
199        s,
200        StateDependentPathDeclaration::IfNone(Box::new(StateDependentPathDeclarationIfNone {
201            nodes: (a, b),
202        })),
203    ))
204}
205
206#[tracable_parser]
207#[packrat_parser]
208pub(crate) fn polarity_operator(s: Span) -> IResult<Span, PolarityOperator> {
209    alt((
210        map(symbol("+"), |x| PolarityOperator { nodes: (x,) }),
211        map(symbol("-"), |x| PolarityOperator { nodes: (x,) }),
212    ))(s)
213}