sv_parser_parser/declarations/
interface_declarations.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn modport_declaration(s: Span) -> IResult<Span, ModportDeclaration> {
8    let (s, a) = keyword("modport")(s)?;
9    let (s, b) = list(symbol(","), modport_item)(s)?;
10    let (s, c) = symbol(";")(s)?;
11    Ok((s, ModportDeclaration { nodes: (a, b, c) }))
12}
13
14#[tracable_parser]
15#[packrat_parser]
16pub(crate) fn modport_item(s: Span) -> IResult<Span, ModportItem> {
17    let (s, a) = modport_identifier(s)?;
18    let (s, b) = paren(list(symbol(","), modport_ports_declaration))(s)?;
19    Ok((s, ModportItem { nodes: (a, b) }))
20}
21
22#[tracable_parser]
23#[packrat_parser]
24pub(crate) fn modport_ports_declaration(s: Span) -> IResult<Span, ModportPortsDeclaration> {
25    alt((
26        modport_ports_declaration_simple,
27        modport_ports_declaration_tf,
28        modport_ports_declaration_clocking,
29    ))(s)
30}
31
32#[tracable_parser]
33#[packrat_parser]
34pub(crate) fn modport_ports_declaration_simple(s: Span) -> IResult<Span, ModportPortsDeclaration> {
35    let (s, a) = many0(attribute_instance)(s)?;
36    let (s, b) = modport_simple_ports_declaration(s)?;
37    Ok((
38        s,
39        ModportPortsDeclaration::Simple(Box::new(ModportPortsDeclarationSimple { nodes: (a, b) })),
40    ))
41}
42
43#[tracable_parser]
44#[packrat_parser]
45pub(crate) fn modport_ports_declaration_tf(s: Span) -> IResult<Span, ModportPortsDeclaration> {
46    let (s, a) = many0(attribute_instance)(s)?;
47    let (s, b) = modport_tf_ports_declaration(s)?;
48    Ok((
49        s,
50        ModportPortsDeclaration::Tf(Box::new(ModportPortsDeclarationTf { nodes: (a, b) })),
51    ))
52}
53
54#[tracable_parser]
55#[packrat_parser]
56pub(crate) fn modport_ports_declaration_clocking(s: Span) -> IResult<Span, ModportPortsDeclaration> {
57    let (s, a) = many0(attribute_instance)(s)?;
58    let (s, b) = modport_clocking_declaration(s)?;
59    Ok((
60        s,
61        ModportPortsDeclaration::Clocking(Box::new(ModportPortsDeclarationClocking {
62            nodes: (a, b),
63        })),
64    ))
65}
66
67#[tracable_parser]
68#[packrat_parser]
69pub(crate) fn modport_clocking_declaration(s: Span) -> IResult<Span, ModportClockingDeclaration> {
70    let (s, a) = keyword("clocking")(s)?;
71    let (s, b) = clocking_identifier(s)?;
72    Ok((s, ModportClockingDeclaration { nodes: (a, b) }))
73}
74
75#[tracable_parser]
76#[packrat_parser]
77pub(crate) fn modport_simple_ports_declaration(
78    s: Span,
79) -> IResult<Span, ModportSimplePortsDeclaration> {
80    let (s, a) = port_direction(s)?;
81    let (s, b) = list(symbol(","), modport_simple_port)(s)?;
82    Ok((s, ModportSimplePortsDeclaration { nodes: (a, b) }))
83}
84
85#[tracable_parser]
86#[packrat_parser]
87pub(crate) fn modport_simple_port(s: Span) -> IResult<Span, ModportSimplePort> {
88    alt((modport_simple_port_named, modport_simple_port_ordered))(s)
89}
90
91#[tracable_parser]
92#[packrat_parser]
93pub(crate) fn modport_simple_port_ordered(s: Span) -> IResult<Span, ModportSimplePort> {
94    let (s, a) = port_identifier(s)?;
95    Ok((
96        s,
97        ModportSimplePort::Ordered(Box::new(ModportSimplePortOrdered { nodes: (a,) })),
98    ))
99}
100
101#[tracable_parser]
102#[packrat_parser]
103pub(crate) fn modport_simple_port_named(s: Span) -> IResult<Span, ModportSimplePort> {
104    let (s, a) = symbol(".")(s)?;
105    let (s, b) = port_identifier(s)?;
106    let (s, c) = paren(opt(expression))(s)?;
107    Ok((
108        s,
109        ModportSimplePort::Named(Box::new(ModportSimplePortNamed { nodes: (a, b, c) })),
110    ))
111}
112
113#[tracable_parser]
114#[packrat_parser]
115pub(crate) fn modport_tf_ports_declaration(s: Span) -> IResult<Span, ModportTfPortsDeclaration> {
116    let (s, a) = import_export(s)?;
117    let (s, b) = list(symbol(","), modport_tf_port)(s)?;
118    Ok((s, ModportTfPortsDeclaration { nodes: (a, b) }))
119}
120
121#[tracable_parser]
122#[packrat_parser]
123pub(crate) fn modport_tf_port(s: Span) -> IResult<Span, ModportTfPort> {
124    alt((
125        map(method_prototype, |x| {
126            ModportTfPort::MethodPrototype(Box::new(x))
127        }),
128        map(tf_identifier, |x| ModportTfPort::TfIdentifier(Box::new(x))),
129    ))(s)
130}
131
132#[tracable_parser]
133#[packrat_parser]
134pub(crate) fn import_export(s: Span) -> IResult<Span, ImportExport> {
135    alt((
136        map(keyword("import"), |x| ImportExport::Import(Box::new(x))),
137        map(keyword("export"), |x| ImportExport::Export(Box::new(x))),
138    ))(s)
139}