sv_parser_parser/instantiations/
generated_instantiation.rs1use crate::*;
2
3#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn generate_region(s: Span) -> IResult<Span, GenerateRegion> {
8 let (s, a) = keyword("generate")(s)?;
9 let (s, (b, c)) = many_till(generate_item, keyword("endgenerate"))(s)?;
10 Ok((s, GenerateRegion { nodes: (a, b, c) }))
11}
12
13#[tracable_parser]
14#[packrat_parser]
15pub(crate) fn loop_generate_construct(s: Span) -> IResult<Span, LoopGenerateConstruct> {
16 let (s, a) = keyword("for")(s)?;
17 let (s, b) = paren(tuple((
18 generate_initialization,
19 symbol(";"),
20 genvar_expression,
21 symbol(";"),
22 genvar_iteration,
23 )))(s)?;
24 let (s, c) = generate_block(s)?;
25 Ok((s, LoopGenerateConstruct { nodes: (a, b, c) }))
26}
27
28#[tracable_parser]
29#[packrat_parser]
30pub(crate) fn generate_initialization(s: Span) -> IResult<Span, GenvarInitialization> {
31 let (s, a) = opt(map(keyword("genvar"), |x| Genvar { nodes: (x,) }))(s)?;
32 let (s, b) = genvar_identifier(s)?;
33 let (s, c) = symbol("=")(s)?;
34 let (s, d) = constant_expression(s)?;
35 Ok((
36 s,
37 GenvarInitialization {
38 nodes: (a, b, c, d),
39 },
40 ))
41}
42
43#[tracable_parser]
44#[packrat_parser]
45pub(crate) fn genvar_iteration(s: Span) -> IResult<Span, GenvarIteration> {
46 alt((
47 genvar_iteration_assignment,
48 genvar_iteration_prefix,
49 genvar_iteration_suffix,
50 ))(s)
51}
52
53#[tracable_parser]
54#[packrat_parser]
55pub(crate) fn genvar_iteration_assignment(s: Span) -> IResult<Span, GenvarIteration> {
56 let (s, a) = genvar_identifier(s)?;
57 let (s, b) = assignment_operator(s)?;
58 let (s, c) = genvar_expression(s)?;
59 Ok((
60 s,
61 GenvarIteration::Assignment(Box::new(GenvarIterationAssignment { nodes: (a, b, c) })),
62 ))
63}
64
65#[tracable_parser]
66#[packrat_parser]
67pub(crate) fn genvar_iteration_prefix(s: Span) -> IResult<Span, GenvarIteration> {
68 let (s, a) = inc_or_dec_operator(s)?;
69 let (s, b) = genvar_identifier(s)?;
70 Ok((
71 s,
72 GenvarIteration::Prefix(Box::new(GenvarIterationPrefix { nodes: (a, b) })),
73 ))
74}
75
76#[tracable_parser]
77#[packrat_parser]
78pub(crate) fn genvar_iteration_suffix(s: Span) -> IResult<Span, GenvarIteration> {
79 let (s, a) = genvar_identifier(s)?;
80 let (s, b) = inc_or_dec_operator(s)?;
81 Ok((
82 s,
83 GenvarIteration::Suffix(Box::new(GenvarIterationSuffix { nodes: (a, b) })),
84 ))
85}
86
87#[tracable_parser]
88#[packrat_parser]
89pub(crate) fn conditional_generate_construct(
90 s: Span,
91) -> IResult<Span, ConditionalGenerateConstruct> {
92 alt((
93 map(if_generate_construct, |x| {
94 ConditionalGenerateConstruct::If(Box::new(x))
95 }),
96 map(case_generate_construct, |x| {
97 ConditionalGenerateConstruct::Case(Box::new(x))
98 }),
99 ))(s)
100}
101
102#[tracable_parser]
103#[packrat_parser]
104pub(crate) fn if_generate_construct(s: Span) -> IResult<Span, IfGenerateConstruct> {
105 let (s, a) = keyword("if")(s)?;
106 let (s, b) = paren(constant_expression)(s)?;
107 let (s, c) = generate_block(s)?;
108 let (s, d) = opt(pair(keyword("else"), generate_block))(s)?;
109 Ok((
110 s,
111 IfGenerateConstruct {
112 nodes: (a, b, c, d),
113 },
114 ))
115}
116
117#[tracable_parser]
118#[packrat_parser]
119pub(crate) fn case_generate_construct(s: Span) -> IResult<Span, CaseGenerateConstruct> {
120 let (s, a) = keyword("case")(s)?;
121 let (s, b) = paren(constant_expression)(s)?;
122 let (s, c) = many1(case_generate_item)(s)?;
123 let (s, d) = keyword("endcase")(s)?;
124 Ok((
125 s,
126 CaseGenerateConstruct {
127 nodes: (a, b, c, d),
128 },
129 ))
130}
131
132#[tracable_parser]
133#[packrat_parser]
134pub(crate) fn case_generate_item(s: Span) -> IResult<Span, CaseGenerateItem> {
135 alt((case_generate_item_nondefault, case_generate_item_default))(s)
136}
137
138#[recursive_parser]
139#[tracable_parser]
140#[packrat_parser]
141pub(crate) fn case_generate_item_nondefault(s: Span) -> IResult<Span, CaseGenerateItem> {
142 let (s, a) = list(symbol(","), constant_expression)(s)?;
143 let (s, b) = symbol(":")(s)?;
144 let (s, c) = generate_block(s)?;
145 Ok((
146 s,
147 CaseGenerateItem::Nondefault(Box::new(CaseGenerateItemNondefault { nodes: (a, b, c) })),
148 ))
149}
150
151#[tracable_parser]
152#[packrat_parser]
153pub(crate) fn case_generate_item_default(s: Span) -> IResult<Span, CaseGenerateItem> {
154 let (s, a) = keyword("default")(s)?;
155 let (s, b) = opt(symbol(":"))(s)?;
156 let (s, c) = generate_block(s)?;
157 Ok((
158 s,
159 CaseGenerateItem::Default(Box::new(CaseGenerateItemDefault { nodes: (a, b, c) })),
160 ))
161}
162
163#[tracable_parser]
164#[packrat_parser]
165pub(crate) fn generate_block(s: Span) -> IResult<Span, GenerateBlock> {
166 alt((
167 map(generate_item, |x| GenerateBlock::GenerateItem(Box::new(x))),
168 generate_block_multiple,
169 ))(s)
170}
171
172#[tracable_parser]
173#[packrat_parser]
174pub(crate) fn generate_block_multiple(s: Span) -> IResult<Span, GenerateBlock> {
175 let (s, a) = opt(pair(generate_block_identifier, symbol(":")))(s)?;
176 let (s, b) = keyword("begin")(s)?;
177 let (s, c) = opt(pair(symbol(":"), generate_block_identifier))(s)?;
178 let (s, (d, e)) = many_till(generate_item, keyword("end"))(s)?;
179 let (s, f) = opt(pair(symbol(":"), generate_block_identifier))(s)?;
180 Ok((
181 s,
182 GenerateBlock::Multiple(Box::new(GenerateBlockMultiple {
183 nodes: (a, b, c, d, e, f),
184 })),
185 ))
186}
187
188#[tracable_parser]
189#[packrat_parser]
190pub(crate) fn generate_item(s: Span) -> IResult<Span, GenerateItem> {
191 alt((
192 map(module_or_generate_item, |x| {
193 GenerateItem::ModuleOrGenerateItem(Box::new(x))
194 }),
195 map(interface_or_generate_item, |x| {
196 GenerateItem::InterfaceOrGenerateItem(Box::new(x))
197 }),
198 map(checker_or_generate_item, |x| {
199 GenerateItem::CheckerOrGenerateItem(Box::new(x))
200 }),
201 ))(s)
202}