xlsynth 0.46.0

Accelerated Hardware Synthesis (XLS/XLSynth) via Rust
Documentation
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
// SPDX-License-Identifier: Apache-2.0

use std::collections::HashMap;

use crate::{
    ir_value::IrFormatPreference,
    vast::{Expr, GenerateLoop, IndexableExpr, VastFile, VastModule},
    XlsynthError,
};

use crate::vast_helpers_options::{CodegenOptions, TemplateVariable};

#[derive(Clone)]
pub struct Reset {
    pub signal: Expr,
    pub active_low: bool,
}

#[derive(Clone)]
pub struct RegisterDefinition {
    pub reg: Expr,
    pub next: Expr,
    pub reset_value: Option<Expr>,
    pub enable: Option<Expr>,
}

fn emit_template(template: &str, keys: &HashMap<TemplateVariable, String>) -> String {
    let mut template = template.to_string();
    for (key, value) in keys {
        let placeholder = format!("{{{{{key}}}}}");
        template = template.replace(&placeholder, value);
    }
    template
}

fn emit_registers_with_templates(
    clk: &Expr,
    reset: Option<Reset>,
    registers: &[RegisterDefinition],
    file: &mut VastFile,
    scope: &mut RegisterScope,
    opts: &CodegenOptions,
) -> Result<(), XlsynthError> {
    for register in registers {
        let mut keys: HashMap<TemplateVariable, String> = HashMap::new();
        keys.insert(TemplateVariable::Clock, clk.emit());
        if let Some(ref r) = reset {
            keys.insert(TemplateVariable::Reset, r.signal.emit());
        }
        keys.insert(TemplateVariable::Reg, register.reg.emit());
        keys.insert(TemplateVariable::Next, register.next.emit());
        if let Some(reset_value) = &register.reset_value {
            keys.insert(TemplateVariable::ResetValue, reset_value.emit());
        }
        if let Some(enable) = &register.enable {
            keys.insert(TemplateVariable::Enable, enable.emit());
        }
        let inline_string = match (
            keys.get(&TemplateVariable::ResetValue),
            keys.get(&TemplateVariable::Enable),
        ) {
            // TODO(meheff): use a CodegenOptions verify method instead of these unwraps
            (Some(_), Some(_)) => emit_template(
                opts.reg_with_reset_with_en_template.as_ref().unwrap(),
                &keys,
            ),
            (Some(_), None) => emit_template(opts.reg_with_reset_template.as_ref().unwrap(), &keys),
            (None, Some(_)) => emit_template(opts.reg_with_en_template.as_ref().unwrap(), &keys),
            (None, None) => emit_template(opts.reg_template.as_ref().unwrap(), &keys),
        };
        let inline_statement = file.make_inline_verilog_statement(&format!("{inline_string};"));
        match scope {
            RegisterScope::Module(module) => {
                module.add_member_inline_statement(inline_statement);
            }
            RegisterScope::GenerateLoop(generate_loop) => {
                generate_loop.add_inline_statement(&inline_statement);
            }
        }
    }
    Ok(())
}

pub enum RegisterScope<'a> {
    Module(&'a mut VastModule),
    GenerateLoop(&'a mut GenerateLoop),
}

// Defines an always_ff block for the given registers.
pub fn add_registers<'a>(
    clk: &Expr,
    reset: Option<Reset>,
    registers: &[RegisterDefinition],
    scope: &mut RegisterScope<'a>,
    file: &mut VastFile,
    options: Option<&CodegenOptions>,
) -> Result<(), XlsynthError> {
    if registers.is_empty() {
        return Ok(());
    }

    let any_with_reset = registers.iter().any(|r| r.reset_value.is_some());
    if any_with_reset {
        assert!(
            reset.is_some(),
            "Reset must be provided when any register has a reset value"
        );
    }

    if let Some(opts) = options {
        if [
            &opts.reg_template,
            &opts.reg_with_en_template,
            &opts.reg_with_reset_template,
            &opts.reg_with_reset_with_en_template,
        ]
        .iter()
        .any(|t| t.is_some())
        {
            return emit_registers_with_templates(clk, reset, registers, file, scope, opts);
        }
    }

    // Build a single always_ff block for all registers
    let posedge_clk = file.make_pos_edge(clk);
    let mut always_ff = match scope {
        RegisterScope::Module(module) => {
            module.add_always_ff(&[&posedge_clk])?.get_statement_block()
        }
        RegisterScope::GenerateLoop(generate_loop) => generate_loop
            .add_always_ff(&[&posedge_clk])?
            .get_statement_block(),
    };

    // Precompute assigned values (with enable ternary when provided)
    let mut assigned_values: Vec<Expr> = Vec::with_capacity(registers.len());
    for r in registers.iter() {
        let val: Expr = match &r.enable {
            Some(en) => file.make_ternary(en, &r.next, &r.reg),
            None => r.next.clone(),
        };
        assigned_values.push(val);
    }

    // Unconditionally assign registers without reset values
    for (i, r) in registers.iter().enumerate() {
        if r.reset_value.is_none() {
            always_ff.add_nonblocking_assignment(&r.reg, &assigned_values[i]);
        }
    }

    // Conditionally assign registers with reset values
    if any_with_reset {
        let rst = reset.expect("reset must be provided when registers have reset values");
        let cond_expr = if rst.active_low {
            file.make_logical_not(&rst.signal)
        } else {
            rst.signal.clone()
        };
        let cond = always_ff.add_cond(&cond_expr);
        let mut then_blk = cond.then_block();
        let mut else_blk = cond.add_else();
        for (i, r) in registers.iter().enumerate() {
            if let Some(ref rv) = r.reset_value {
                then_blk.add_nonblocking_assignment(&r.reg, rv);
                else_blk.add_nonblocking_assignment(&r.reg, &assigned_values[i]);
            }
        }
    }

    Ok(())
}

// Internal helper to fold a list of expressions using a binary reducer.
// - inputs: slice of expressions to reduce
// - identity: expression used when inputs is empty
// - combine: function that combines two expressions into one (e.g., a || b)
fn reduce_with<F>(
    inputs: &[Expr],
    identity: Expr,
    mut combine: F,
    file: &mut VastFile,
) -> Result<Expr, XlsynthError>
where
    F: FnMut(&mut VastFile, &Expr, &Expr) -> Expr,
{
    if inputs.is_empty() {
        return Ok(identity);
    }
    if inputs.len() == 1 {
        return Ok(inputs[0].clone());
    }
    let mut temps: Vec<Expr> = Vec::new();
    let mut accum: &Expr = &inputs[0];
    for input in inputs[1..].iter() {
        temps.push(combine(file, accum, input));
        accum = temps.last().unwrap();
    }
    Ok(accum.clone())
}

pub fn logical_or_reduce(
    inputs: &[Expr],
    invert: bool,
    file: &mut VastFile,
) -> Result<Expr, XlsynthError> {
    if inputs.is_empty() && invert {
        // Special case to avoid emitting !1'h0.
        return file.make_literal("bits[1]:1", &IrFormatPreference::Hex);
    }
    let id0 = file.make_literal("bits[1]:0", &IrFormatPreference::Hex)?;
    let reduced = reduce_with(inputs, id0, |f, a, b| f.make_logical_or(a, b), file)?;
    if invert {
        Ok(file.make_logical_not(&reduced))
    } else {
        Ok(reduced)
    }
}

pub fn logical_and_reduce(
    inputs: &[Expr],
    invert: bool,
    file: &mut VastFile,
) -> Result<Expr, XlsynthError> {
    if inputs.is_empty() && invert {
        // Special case to avoid emitting !1'h1.
        return file.make_literal("bits[1]:0", &IrFormatPreference::Hex);
    };
    let id1 = file.make_literal("bits[1]:1", &IrFormatPreference::Hex)?;
    let reduced = reduce_with(inputs, id1, |f, a, b| f.make_logical_and(a, b), file)?;
    if invert {
        Ok(file.make_logical_not(&reduced))
    } else {
        Ok(reduced)
    }
}

pub fn bitwise_or_reduce(inputs: &[Expr], file: &mut VastFile) -> Result<Expr, XlsynthError> {
    let id = file.make_unsized_zero_literal();
    reduce_with(inputs, id, |f, a, b| f.make_bitwise_or(a, b), file)
}

// Gathers all of the elements of the packed array given by `expr` into
// `elements`. `expr` should be a packed array with dimensions matching
// `dimensions` (major dimension first). Elements are created by making Verilog
// index expressions.
fn gather_elements(
    expr: &IndexableExpr,
    dimensions: &[i64],
    elements: &mut Vec<Expr>,
    file: &mut VastFile,
) {
    if dimensions.is_empty() {
        elements.push(expr.to_expr());
    } else {
        for i in 0..dimensions[0] {
            let index_literal = file.make_plain_literal(i as i32, &IrFormatPreference::Default);
            let index_expr = file
                .make_index_expr(expr, &index_literal)
                .to_indexable_expr();
            gather_elements(&index_expr, &dimensions[1..], elements, file);
        }
    }
}

/// Returns an expression which is the bitwise OR of all of the elements of the
/// packed array given by `expr`. `expr` should be a packed array with
/// dimensions matching `dimensions` (major dimension first).
pub fn bitwise_or_reduce_array_elements(
    expr: &IndexableExpr,
    dimensions: &[i64],
    file: &mut VastFile,
) -> Result<Expr, XlsynthError> {
    let mut elements: Vec<Expr> = Vec::new();
    gather_elements(expr, dimensions, &mut elements, file);
    bitwise_or_reduce(&elements, file)
}

#[cfg(test)]
mod tests {
    use crate::vast::{VastFile, VastFileType};
    use pretty_assertions::assert_eq;

    use super::*;

    #[test]
    fn test_logical_or_reduce_various_arity() {
        let mut file = VastFile::new(VastFileType::SystemVerilog);
        let mut module = file.add_module("lor");

        // Inputs: scalar logic signals
        let scalar = file.make_scalar_type();
        let a = module.add_input("a", &scalar);
        let b = module.add_input("b", &scalar);
        let c = module.add_input("c", &scalar);

        // Outputs
        let o0 = module.add_output("o0", &scalar);
        let o1 = module.add_output("o1", &scalar);
        let o2 = module.add_output("o2", &scalar);
        let o3 = module.add_output("o3", &scalar);

        // 0 inputs -> 0
        let e0 = logical_or_reduce(&[], false, &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o0.to_expr(), &e0));

        // 1 input -> a
        let e1 = logical_or_reduce(&[a.to_expr()], false, &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o1.to_expr(), &e1));

        // 2 inputs -> a || b
        let e2 = logical_or_reduce(&[a.to_expr(), b.to_expr()], false, &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o2.to_expr(), &e2));

        // 3 inputs -> a || b || c
        let e3 =
            logical_or_reduce(&[a.to_expr(), b.to_expr(), c.to_expr()], false, &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o3.to_expr(), &e3));

        let verilog = file.emit();
        let want = r#"module lor(
  input wire a,
  input wire b,
  input wire c,
  output wire o0,
  output wire o1,
  output wire o2,
  output wire o3
);
  assign o0 = 1'h0;
  assign o1 = a;
  assign o2 = a || b;
  assign o3 = a || b || c;
endmodule
"#;
        assert_eq!(verilog, want);
    }

    #[test]
    fn test_add_registers_with_reset_and_enable() {
        let mut file = VastFile::new(VastFileType::SystemVerilog);
        let mut module = file.add_module("regs_rst_en");

        let bit1 = file.make_bit_vector_type(1, false);
        let u8 = file.make_bit_vector_type(8, false);

        let clk = module.add_input("clk", &bit1);
        let clk_expr = clk.to_expr();
        let rst = module.add_input("rst", &bit1);
        let en = module.add_input("en", &bit1);
        let r = module.add_logic("r", &u8).expect("add_logic r");
        let r_next = module.add_logic("r_next", &u8).expect("add_logic r_next");
        let r2 = module.add_logic("r2", &u8).expect("add_logic r2");
        let r2_next = module.add_logic("r2_next", &u8).expect("add_logic r2_next");

        let reset_val = file
            .make_literal("bits[8]:0xAA", &IrFormatPreference::Hex)
            .expect("literal ok");
        let reset_val_r2 = file
            .make_literal("bits[8]:0x55", &IrFormatPreference::Hex)
            .expect("literal ok");

        let regs = [
            RegisterDefinition {
                reg: r.to_expr(),
                next: r_next.to_expr(),
                reset_value: Some(reset_val),
                enable: Some(en.to_expr()),
            },
            RegisterDefinition {
                reg: r2.to_expr(),
                next: r2_next.to_expr(),
                reset_value: Some(reset_val_r2),
                enable: None,
            },
        ];

        add_registers(
            &clk_expr,
            Some(Reset {
                signal: rst.to_expr(),
                active_low: true,
            }),
            &regs,
            &mut RegisterScope::Module(&mut module),
            &mut file,
            None,
        )
        .expect("add_registers ok");

        let sv = file.emit();
        let want = r#"module regs_rst_en(
  input wire clk,
  input wire rst,
  input wire en
);
  logic [7:0] r;
  logic [7:0] r_next;
  logic [7:0] r2;
  logic [7:0] r2_next;
  always_ff @ (posedge clk) begin
    if (!rst) begin
      r <= 8'haa;
      r2 <= 8'h55;
    end else begin
      r <= en ? r_next : r;
      r2 <= r2_next;
    end
  end
endmodule
"#;
        assert_eq!(sv, want);
    }

    #[test]
    fn test_add_registers_no_reset_path() {
        let mut file = VastFile::new(VastFileType::SystemVerilog);
        let mut module = file.add_module("regs_no_rst");

        let bit1 = file.make_bit_vector_type(1, false);
        let u8 = file.make_bit_vector_type(8, false);

        let clk = module.add_input("clk", &bit1);
        let clk_expr = clk.to_expr();
        let en = module.add_input("en", &bit1);
        let r = module.add_logic("r", &u8).expect("add_logic r");
        let r_next = module.add_logic("r_next", &u8).expect("add_logic r_next");
        let r2 = module.add_logic("r2", &u8).expect("add_logic r2");
        let r2_next = module.add_logic("r2_next", &u8).expect("add_logic r2_next");

        let regs = [
            RegisterDefinition {
                reg: r.to_expr(),
                next: r_next.to_expr(),
                reset_value: None,
                enable: Some(en.to_expr()),
            },
            RegisterDefinition {
                reg: r2.to_expr(),
                next: r2_next.to_expr(),
                reset_value: None,
                enable: None,
            },
        ];

        add_registers(
            &clk_expr,
            None,
            &regs,
            &mut RegisterScope::Module(&mut module),
            &mut file,
            None,
        )
        .expect("add_registers ok");

        let sv = file.emit();
        let want = r#"module regs_no_rst(
  input wire clk,
  input wire en
);
  logic [7:0] r;
  logic [7:0] r_next;
  logic [7:0] r2;
  logic [7:0] r2_next;
  always_ff @ (posedge clk) begin
    r <= en ? r_next : r;
    r2 <= r2_next;
  end
endmodule
"#;
        assert_eq!(sv, want);
    }

    #[test]
    fn test_add_registers_mixed_resets_panics() {
        // Mixed resets are now supported; verify generated output
        let mut file = VastFile::new(VastFileType::SystemVerilog);
        let mut module = file.add_module("regs_mixed");

        let bit1 = file.make_bit_vector_type(1, false);
        let u8 = file.make_bit_vector_type(8, false);

        let clk = module.add_input("clk", &bit1);
        let clk_expr = clk.to_expr();
        let rst = module.add_input("rst", &bit1);
        let en = module.add_input("en", &bit1);
        let r1 = module.add_logic("r1", &u8).expect("r1");
        let n1 = module.add_logic("n1", &u8).expect("n1");
        let r2 = module.add_logic("r2", &u8).expect("r2");
        let n2 = module.add_logic("n2", &u8).expect("n2");

        let reset_val = file
            .make_literal("bits[8]:0xAA", &IrFormatPreference::Hex)
            .expect("literal ok");

        let regs = [
            RegisterDefinition {
                reg: r1.to_expr(),
                next: n1.to_expr(),
                reset_value: Some(reset_val),
                enable: Some(en.to_expr()),
            },
            RegisterDefinition {
                reg: r2.to_expr(),
                next: n2.to_expr(),
                reset_value: None,
                enable: None,
            },
        ];

        add_registers(
            &clk_expr,
            Some(Reset {
                signal: rst.to_expr(),
                active_low: true,
            }),
            &regs,
            &mut RegisterScope::Module(&mut module),
            &mut file,
            None,
        )
        .expect("add_registers ok");

        let sv = file.emit();
        let want = r#"module regs_mixed(
  input wire clk,
  input wire rst,
  input wire en
);
  logic [7:0] r1;
  logic [7:0] n1;
  logic [7:0] r2;
  logic [7:0] n2;
  always_ff @ (posedge clk) begin
    r2 <= n2;
    if (!rst) begin
      r1 <= 8'haa;
    end else begin
      r1 <= en ? n1 : r1;
    end
  end
endmodule
"#;
        assert_eq!(sv, want);
    }

    #[test]
    fn test_add_registers_missing_reset_panics() {
        let res = std::panic::catch_unwind(|| {
            let mut file = VastFile::new(VastFileType::SystemVerilog);
            let mut module = file.add_module("regs_missing_rst");

            let bit1 = file.make_bit_vector_type(1, false);
            let u8 = file.make_bit_vector_type(8, false);

            let clk = module.add_input("clk", &bit1);
            let clk_expr = clk.to_expr();
            let r = module.add_logic("r", &u8).expect("r");
            let n = module.add_logic("n", &u8).expect("n");
            let reset_val = file
                .make_literal("bits[8]:0xAA", &IrFormatPreference::Hex)
                .expect("literal ok");

            let regs = [RegisterDefinition {
                reg: r.to_expr(),
                next: n.to_expr(),
                reset_value: Some(reset_val),
                enable: None,
            }];

            let _ = add_registers(
                &clk_expr,
                None,
                &regs,
                &mut RegisterScope::Module(&mut module),
                &mut file,
                None,
            );
        });
        assert!(
            res.is_err(),
            "expected panic when reset not provided but required"
        );
    }
    #[test]
    fn test_logical_or_reduce_inverted() {
        let mut file = VastFile::new(VastFileType::SystemVerilog);
        let mut module = file.add_module("lori");

        // Inputs: scalar logic signals
        let scalar = file.make_scalar_type();
        let a = module.add_input("a", &scalar);
        let b = module.add_input("b", &scalar);
        let c = module.add_input("c", &scalar);

        // Outputs
        let o0 = module.add_output("o0", &scalar);
        let o1 = module.add_output("o1", &scalar);
        let o2 = module.add_output("o2", &scalar);
        let o3 = module.add_output("o3", &scalar);

        // 0 inputs -> 1
        let e0 = logical_or_reduce(&[], true, &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o0.to_expr(), &e0));

        // 1 input -> !a
        let e1 = logical_or_reduce(&[a.to_expr()], true, &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o1.to_expr(), &e1));

        // 2 inputs -> !(a || b)
        let e2 = logical_or_reduce(&[a.to_expr(), b.to_expr()], true, &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o2.to_expr(), &e2));

        // 3 inputs -> !(a || b || c)
        let e3 =
            logical_or_reduce(&[a.to_expr(), b.to_expr(), c.to_expr()], true, &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o3.to_expr(), &e3));

        let verilog = file.emit();
        let want = r#"module lori(
  input wire a,
  input wire b,
  input wire c,
  output wire o0,
  output wire o1,
  output wire o2,
  output wire o3
);
  assign o0 = 1'h1;
  assign o1 = !a;
  assign o2 = !(a || b);
  assign o3 = !(a || b || c);
endmodule
"#;
        assert_eq!(verilog, want);
    }

    #[test]
    fn test_bitwise_or_reduce_various_arity() {
        let mut file = VastFile::new(VastFileType::SystemVerilog);
        let mut module = file.add_module("bor");

        // Inputs: 8-bit vectors
        let u8 = file.make_bit_vector_type(8, false);
        let a = module.add_input("a", &u8);
        let b = module.add_input("b", &u8);
        let c = module.add_input("c", &u8);

        // Outputs
        let o0 = module.add_output("o0", &u8);
        let o1 = module.add_output("o1", &u8);
        let o2 = module.add_output("o2", &u8);
        let o3 = module.add_output("o3", &u8);

        // 0 inputs -> '0
        let e0 = bitwise_or_reduce(&[], &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o0.to_expr(), &e0));

        // 1 input -> a
        let e1 = bitwise_or_reduce(&[a.to_expr()], &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o1.to_expr(), &e1));

        // 2 inputs -> a | b
        let e2 = bitwise_or_reduce(&[a.to_expr(), b.to_expr()], &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o2.to_expr(), &e2));

        // 3 inputs -> a | b | c
        let e3 = bitwise_or_reduce(&[a.to_expr(), b.to_expr(), c.to_expr()], &mut file).unwrap();
        module
            .add_member_continuous_assignment(file.make_continuous_assignment(&o3.to_expr(), &e3));

        let verilog = file.emit();
        let want = r#"module bor(
  input wire [7:0] a,
  input wire [7:0] b,
  input wire [7:0] c,
  output wire [7:0] o0,
  output wire [7:0] o1,
  output wire [7:0] o2,
  output wire [7:0] o3
);
  assign o0 = '0;
  assign o1 = a;
  assign o2 = a | b;
  assign o3 = a | b | c;
endmodule
"#;
        assert_eq!(verilog, want);
    }
}