Mux constructor Null safety
Constructs a multiplexer which passes d0
or d1
to out depending
on if control
is 0 or 1, respectively.
Implementation
Mux(Logic control, Logic d1, Logic d0, {super.name = 'mux'}) {
if (control.width != 1) {
throw Exception('Control must be single bit Logic, but found $control.');
}
if (d0.width != d1.width) {
throw Exception('d0 ($d0) and d1 ($d1) must be same width');
}
_controlName = Module.unpreferredName('control_${control.name}');
_d0Name = Module.unpreferredName('d0_${d0.name}');
_d1Name = Module.unpreferredName('d1_${d1.name}');
_outName = Module.unpreferredName('out');
addInput(_controlName, control);
addInput(_d0Name, d0, width: d0.width);
addInput(_d1Name, d1, width: d1.width);
addOutput(_outName, width: d0.width);
_setup();
}