addTypedInput<LogicType extends Logic> method

LogicType addTypedInput<LogicType extends Logic>(
  1. String name,
  2. LogicType source
)
inherited

Registers a signal as an input to this Module and returns an input port that can be consumed. The type of the port will be LogicType and constructed via Logic.clone, so it is required that the source implements clone functionality that matches the type and properly updates the Logic.name as well.

This is a good way to construct inputs that have matching widths or dimensions to their source signal, or to make a LogicStructure an input. You can use this on a Logic, LogicArray, or LogicStructure.

The source cannot be or contain any LogicNets. If source is a Const (or is a LogicStructure that includes a Const), 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 input and should only be used within this Module. The provided source is accessible via inputSource.

Implementation

LogicType addTypedInput<LogicType extends Logic>(
    String name, LogicType source) {
  _checkForSafePortName(name);

  // ignore: parameter_assignments
  source = _validateType<LogicType>(source, isOutput: false, name: name);

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

  final inPort = (source.clone(name: name) as LogicType)..gets(source);

  if (inPort.name != name) {
    throw PortTypeException.forIntendedName(name,
        'The `clone` method for $source failed to update the signal name.');
  }

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

  _inputs[name] = inPort;

  _inputSources[name] = source;

  return inPort;
}