split method

  1. @override
List<Logic> split(
  1. List<int> widths
)
override

Splits this signal into LSB-first chunks with the provided widths.

The widths must be non-negative and sum exactly to width. A zero-width entry produces an empty Const chunk.

Implementation

@override
List<Logic> split(List<int> widths) {
  if (widths.any((chunkWidth) => chunkWidth < 0) ||
      widths.fold(0, (total, chunkWidth) => total + chunkWidth) != width) {
    throw ArgumentError.value(
      widths,
      'widths',
      'must be non-negative and sum to $width.',
    );
  }

  var start = 0;
  final chunks = <Logic>[];
  for (final chunkWidth in widths) {
    chunks.add(getRange(start, start + chunkWidth));
    start += chunkWidth;
  }
  return List<Logic>.unmodifiable(chunks);
}