addTypedOutput<LogicType extends Logic> method

LogicType addTypedOutput<LogicType extends Logic>(
  1. String name,
  2. LogicType logicGenerator({
    1. String name,
    })
)
inherited

Registers an output to this Module and returns an output port that can be driven by this Module or consumed outside of it. The type of the port will be LogicType and constructed via logicGenerator, which must properly update the name of the generated LogicType as well.

This is a good way to construct outputs that have matching widths or dimensions to another signal, or to make a LogicStructure an output. You can use this on a Logic, LogicArray, or LogicStructure.

The logicGenerator cannot create ports that are or contain any LogicNets in them. If a Const is generated (or included in a LogicStructure), the LogicType must be set to Logic, since Consts cannot be driven and are not suitable as ports.

The return value is the same as what is returned by output.

Implementation

LogicType addTypedOutput<LogicType extends Logic>(
    String name, LogicType Function({String name}) logicGenerator) {
  _checkForSafePortName(name);

  // must make a new clone of it, to avoid people using ports of other modules
  var outPort = logicGenerator(name: name);

  outPort = _validateType<LogicType>(outPort, isOutput: true, name: name);

  if (outPort.isNet || (outPort is LogicStructure && outPort.hasNets)) {
    throw PortTypeException(
        outPort, 'Typed outputs cannot have nets in them.');
  }

  if (outPort.name != name) {
    throw PortTypeException.forIntendedName(
        name,
        'The `logicGenerator` function failed to'
        ' update the signal name on $outPort.');
  }

  if (outPort is LogicStructure) {
    outPort.setAllParentModule(this);
  } else {
    outPort.parentModule = this;
  }

  _outputs[name] = outPort;

  return outPort;
}