connectIO method

void connectIO(
  1. Module module,
  2. Interface srcInterface,
  3. {Iterable<TagType>? inputTags,
  4. Iterable<TagType>? outputTags,
  5. String uniquify(
    1. String original
    )?}
)

Connects module's inputs and outputs up to srcInterface and this Interface.

The srcInterface should be a new instance of the Interface to be used by module for all input and output connectivity. All signals in the interface with specified TagType will be connected to the Module via Module.addInput or Module.addOutput based on inputTags and outputTags, respectively. uniquify can be used to uniquifiy port names by manipulating the original name of the port.

If inputTags or outputTags is not specified, then, respectively, no inputs or outputs will be added.

Implementation

void connectIO(Module module, Interface<dynamic> srcInterface,
    {Iterable<TagType>? inputTags,
    Iterable<TagType>? outputTags,
    String Function(String original)? uniquify}) {
  uniquify ??= (original) => original;

  if (inputTags != null) {
    for (final port in getPorts(inputTags).values) {
      port <=
          (port is LogicArray
              // ignore: invalid_use_of_protected_member
              ? module.addInputArray(
                  port.name,
                  srcInterface.port(port.name),
                  dimensions: port.dimensions,
                  elementWidth: port.elementWidth,
                  numUnpackedDimensions: port.numUnpackedDimensions,
                )
              // ignore: invalid_use_of_protected_member
              : module.addInput(
                  uniquify(port.name),
                  srcInterface.port(port.name),
                  width: port.width,
                ));
    }
  }

  if (outputTags != null) {
    for (final port in getPorts(outputTags).values) {
      // ignore: invalid_use_of_protected_member
      final output = (port is LogicArray
          // ignore: invalid_use_of_protected_member
          ? module.addOutputArray(
              port.name,
              dimensions: port.dimensions,
              elementWidth: port.elementWidth,
              numUnpackedDimensions: port.numUnpackedDimensions,
            )
          // ignore: invalid_use_of_protected_member
          : module.addOutput(
              uniquify(port.name),
              width: port.width,
            ));
      output <= port;
      srcInterface.port(port.name) <= output;
    }
  }
}