1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
use crate::*;

// -----------------------------------------------------------------------------

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation(s: Span) -> IResult<Span, GateInstantiation> {
    alt((
        gate_instantiation_cmos,
        gate_instantiation_enable,
        gate_instantiation_mos,
        gate_instantiation_n_input,
        gate_instantiation_n_output,
        gate_instantiation_pass_en,
        gate_instantiation_pass,
        gate_instantiation_pulldown,
        gate_instantiation_pullup,
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation_cmos(s: Span) -> IResult<Span, GateInstantiation> {
    let (s, a) = cmos_switchtype(s)?;
    let (s, b) = opt(delay3)(s)?;
    let (s, c) = list(symbol(","), cmos_switch_instance)(s)?;
    let (s, d) = symbol(";")(s)?;
    Ok((
        s,
        GateInstantiation::Cmos(Box::new(GateInstantiationCmos {
            nodes: (a, b, c, d),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation_enable(s: Span) -> IResult<Span, GateInstantiation> {
    let (s, a) = enable_gatetype(s)?;
    let (s, b) = opt(drive_strength)(s)?;
    let (s, c) = opt(delay3)(s)?;
    let (s, d) = list(symbol(","), enable_gate_instance)(s)?;
    let (s, e) = symbol(";")(s)?;
    Ok((
        s,
        GateInstantiation::Enable(Box::new(GateInstantiationEnable {
            nodes: (a, b, c, d, e),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation_mos(s: Span) -> IResult<Span, GateInstantiation> {
    let (s, a) = mos_switchtype(s)?;
    let (s, b) = opt(delay3)(s)?;
    let (s, c) = list(symbol(","), mos_switch_instance)(s)?;
    let (s, d) = symbol(";")(s)?;
    Ok((
        s,
        GateInstantiation::Mos(Box::new(GateInstantiationMos {
            nodes: (a, b, c, d),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation_n_input(s: Span) -> IResult<Span, GateInstantiation> {
    let (s, a) = n_input_gatetype(s)?;
    let (s, b) = opt(drive_strength)(s)?;
    let (s, c) = opt(delay2)(s)?;
    let (s, d) = list(symbol(","), n_input_gate_instance)(s)?;
    let (s, e) = symbol(";")(s)?;
    Ok((
        s,
        GateInstantiation::NInput(Box::new(GateInstantiationNInput {
            nodes: (a, b, c, d, e),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation_n_output(s: Span) -> IResult<Span, GateInstantiation> {
    let (s, a) = n_output_gatetype(s)?;
    let (s, b) = opt(drive_strength)(s)?;
    let (s, c) = opt(delay2)(s)?;
    let (s, d) = list(symbol(","), n_output_gate_instance)(s)?;
    let (s, e) = symbol(";")(s)?;
    Ok((
        s,
        GateInstantiation::NOutput(Box::new(GateInstantiationNOutput {
            nodes: (a, b, c, d, e),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation_pass_en(s: Span) -> IResult<Span, GateInstantiation> {
    let (s, a) = pass_en_switchtype(s)?;
    let (s, b) = opt(delay2)(s)?;
    let (s, c) = list(symbol(","), pass_enable_switch_instance)(s)?;
    let (s, d) = symbol(";")(s)?;
    Ok((
        s,
        GateInstantiation::PassEn(Box::new(GateInstantiationPassEn {
            nodes: (a, b, c, d),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation_pass(s: Span) -> IResult<Span, GateInstantiation> {
    let (s, a) = pass_switchtype(s)?;
    let (s, b) = list(symbol(","), pass_switch_instance)(s)?;
    let (s, c) = symbol(";")(s)?;
    Ok((
        s,
        GateInstantiation::Pass(Box::new(GateInstantiationPass { nodes: (a, b, c) })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation_pulldown(s: Span) -> IResult<Span, GateInstantiation> {
    let (s, a) = keyword("pulldown")(s)?;
    let (s, b) = opt(pulldown_strength)(s)?;
    let (s, c) = list(symbol(","), pull_gate_instance)(s)?;
    let (s, d) = symbol(";")(s)?;
    Ok((
        s,
        GateInstantiation::Pulldown(Box::new(GateInstantiationPulldown {
            nodes: (a, b, c, d),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn gate_instantiation_pullup(s: Span) -> IResult<Span, GateInstantiation> {
    let (s, a) = keyword("pullup")(s)?;
    let (s, b) = opt(pullup_strength)(s)?;
    let (s, c) = list(symbol(","), pull_gate_instance)(s)?;
    let (s, d) = symbol(";")(s)?;
    Ok((
        s,
        GateInstantiation::Pullup(Box::new(GateInstantiationPullup {
            nodes: (a, b, c, d),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn cmos_switch_instance(s: Span) -> IResult<Span, CmosSwitchInstance> {
    let (s, a) = opt(name_of_instance)(s)?;
    let (s, b) = paren(tuple((
        output_terminal,
        symbol(","),
        input_terminal,
        symbol(","),
        ncontrol_terminal,
        symbol(","),
        pcontrol_terminal,
    )))(s)?;
    Ok((s, CmosSwitchInstance { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn enable_gate_instance(s: Span) -> IResult<Span, EnableGateInstance> {
    let (s, a) = opt(name_of_instance)(s)?;
    let (s, b) = paren(tuple((
        output_terminal,
        symbol(","),
        input_terminal,
        symbol(","),
        enable_terminal,
    )))(s)?;
    Ok((s, EnableGateInstance { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn mos_switch_instance(s: Span) -> IResult<Span, MosSwitchInstance> {
    let (s, a) = opt(name_of_instance)(s)?;
    let (s, b) = paren(tuple((
        output_terminal,
        symbol(","),
        input_terminal,
        symbol(","),
        enable_terminal,
    )))(s)?;
    Ok((s, MosSwitchInstance { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn n_input_gate_instance(s: Span) -> IResult<Span, NInputGateInstance> {
    let (s, a) = opt(name_of_instance)(s)?;
    let (s, b) = paren(tuple((
        output_terminal,
        symbol(","),
        list(symbol(","), input_terminal),
    )))(s)?;
    Ok((s, NInputGateInstance { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn n_output_gate_instance(s: Span) -> IResult<Span, NOutputGateInstance> {
    let (s, a) = opt(name_of_instance)(s)?;
    let (s, b) = paren(tuple((
        list(
            terminated(symbol(","), peek(pair(output_terminal, symbol(",")))),
            output_terminal,
        ),
        symbol(","),
        input_terminal,
    )))(s)?;
    Ok((s, NOutputGateInstance { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn pass_switch_instance(s: Span) -> IResult<Span, PassSwitchInstance> {
    let (s, a) = opt(name_of_instance)(s)?;
    let (s, b) = paren(tuple((inout_terminal, symbol(","), inout_terminal)))(s)?;
    Ok((s, PassSwitchInstance { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn pass_enable_switch_instance(s: Span) -> IResult<Span, PassEnableSwitchInstance> {
    let (s, a) = opt(name_of_instance)(s)?;
    let (s, b) = paren(tuple((
        inout_terminal,
        symbol(","),
        inout_terminal,
        symbol(","),
        enable_terminal,
    )))(s)?;
    Ok((s, PassEnableSwitchInstance { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn pull_gate_instance(s: Span) -> IResult<Span, PullGateInstance> {
    let (s, a) = opt(name_of_instance)(s)?;
    let (s, b) = paren(output_terminal)(s)?;
    Ok((s, PullGateInstance { nodes: (a, b) }))
}