addInOutArray method

LogicArray addInOutArray(
  1. String name,
  2. Logic source, {
  3. List<int> dimensions = const [1],
  4. int elementWidth = 1,
  5. int numUnpackedDimensions = 0,
})

Registers and returns an inOut LogicArray port to this Module with the specified dimensions, elementWidth, and numUnpackedDimensions named name.

This is very similar to addInOut, except for LogicArrays.

Performs validation on overall width matching for source, but not on dimensions, elementWidth, or numUnpackedDimensions.

Implementation

LogicArray addInOutArray(
  String name,
  Logic source, {
  List<int> dimensions = const [1],
  int elementWidth = 1,
  int numUnpackedDimensions = 0,
}) {
  _checkForSafePortName(name);

  // make sure we register all the _inOutDrivers properly
  final sourceElems = TraverseableCollection<Logic>()..add(source);
  for (var i = 0; i < sourceElems.length; i++) {
    final sei = sourceElems[i];
    _inOutDrivers.add(sei);

    if (sei.isArrayMember) {
      sourceElems.add(sei.parentStructure!);
    }

    if (sei is LogicArray) {
      sourceElems.addAll(sei.elements);
    }
  }

  final inOutArr = LogicArray.net(
    name: name,
    dimensions,
    elementWidth,
    numUnpackedDimensions: numUnpackedDimensions,
    naming: Naming.reserved,
  )
    ..gets(source)
    // ignore: invalid_use_of_protected_member
    ..setAllParentModule(this);

  // there may be packed arrays created by the `gets` above, so this makes
  // sure we catch all of those.
  _inOutDrivers.addAll(inOutArr.srcConnections);

  _inOuts[name] = inOutArr;

  _inOutSources[name] = source;

  return inOutArr;
}