SlicePortReference constructor

SlicePortReference(
  1. BridgeModule module,
  2. String portName, {
  3. List<int>? dimensionAccess,
  4. int? sliceUpperIndex,
  5. int? sliceLowerIndex,
})

Creates a slice port reference with the specified parameters.

The dimensionAccess list contains indices for multi-dimensional array access, while sliceUpperIndex and sliceLowerIndex define slicing. Both slice indices must be provided together or both must be null.

The constructor automatically optimizes certain patterns:

  • Single-bit slices like [3:3] become array access [3]
  • Full-width slices that match array dimensions are simplified

Implementation

SlicePortReference(super.module, super.portName,
    {List<int>? dimensionAccess, int? sliceUpperIndex, int? sliceLowerIndex})
    : super._() {
  if ((sliceUpperIndex == null) != (sliceLowerIndex == null)) {
    throw RohdBridgeException(
        'Both or neither slice indices must be provided');
  }

  if (sliceUpperIndex == sliceLowerIndex && sliceUpperIndex != null) {
    // if we have something like [3:3], just convert to [3]
    this.dimensionAccess = [
      if (dimensionAccess != null) ...dimensionAccess,
      sliceUpperIndex
    ];
    this.sliceUpperIndex = null;
    this.sliceLowerIndex = null;
  } else if (port is LogicArray &&
      sliceLowerIndex == 0 &&
      sliceUpperIndex != null &&
      (dimensionAccess == null ||
          dimensionAccess.length < (port as LogicArray).dimensions.length) &&
      sliceUpperIndex ==
          (port as LogicArray).dimensions[(dimensionAccess?.length ?? 0)] -
              1) {
    // if we have something like [7:0] on an array at the end, but it's still
    // referring to a dimension of the array, and that's the full width, then
    // just omit it since it's the same
    this.dimensionAccess = dimensionAccess;
    this.sliceUpperIndex = null;
    this.sliceLowerIndex = null;
  } else if (port is LogicArray &&
      sliceLowerIndex == 0 &&
      sliceUpperIndex != null &&
      dimensionAccess != null &&
      dimensionAccess.length == (port as LogicArray).dimensions.length &&
      (port as LogicArray).elementWidth == sliceUpperIndex + 1) {
    // if we have something like [7:0] on an array at the end, and that's the
    // full width, then just omit it since it's the same
    this.dimensionAccess = dimensionAccess;
    this.sliceUpperIndex = null;
    this.sliceLowerIndex = null;
  } else if (port is! LogicArray &&
      sliceLowerIndex == 0 &&
      sliceUpperIndex != null &&
      (dimensionAccess == null || dimensionAccess.isEmpty) &&
      port.width == sliceUpperIndex + 1) {
    // if we have something like [7:0] on a non-array at the end and it's the
    // full width, then just omit it since it's the same
    this.dimensionAccess = null;
    this.sliceUpperIndex = null;
    this.sliceLowerIndex = null;
  } else {
    this.dimensionAccess = dimensionAccess;
    this.sliceUpperIndex = sliceUpperIndex;
    this.sliceLowerIndex = sliceLowerIndex;
  }
}