connectIO method

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

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

The srcInterface should be an external instance of the Interface passed in from outside the module, and connectIO should be called on a new instance of the Interface to be used by module for all input and output connectivity. For example:

MyMod(MyIntf srcIntf) {
  srcIntf = MyIntf(args)..connectIO(this, srcIntf, inputTags: ... );
}

All signals in the interface with specified TagType will be connected to the Module via Module.addInput, Module.addOutput, or Module.addInOut based on inputTags, outputTags, and inOutTags, respectively. uniquify can be used to uniquifiy port names by manipulating the original name of the port.

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

Implementation

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

  if (inputTags != null) {
    for (final port in getPorts(inputTags).values) {
      port <=
          switch (port) {
            LogicArray() => module.addInputArray(
                uniquify(port.name),
                srcInterface.port(port.name),
                dimensions: port.dimensions,
                elementWidth: port.elementWidth,
                numUnpackedDimensions: port.numUnpackedDimensions,
              ),
            BaseLogicArray() => module.addTypedInput(
                uniquify(port.name),
                srcInterface.port(port.name) as BaseLogicArray,
              ),
            _ => module.addInput(
                uniquify(port.name),
                srcInterface.port(port.name),
                width: port.width,
              ),
          };
    }
  }

  if (outputTags != null) {
    for (final port in getPorts(outputTags).values) {
      final output = switch (port) {
        LogicArray() => module.addOutputArray(
            uniquify(port.name),
            dimensions: port.dimensions,
            elementWidth: port.elementWidth,
            numUnpackedDimensions: port.numUnpackedDimensions,
          ),
        BaseLogicArray() => module.addTypedOutput(
            uniquify(port.name),
            port.clone,
          ),
        _ => module.addOutput(
            uniquify(port.name),
            width: port.width,
          ),
      };
      output <= port;
      srcInterface.port(port.name) <= output;
    }
  }

  if (inOutTags != null) {
    _connectInOutPorts(
      module,
      srcInterface,
      inOutTags,
      uniquify: uniquify,
    );
  }
}