evaluate method

(BigInt, StringBuffer) evaluate({
  1. bool printOut = false,
  2. bool logic = false,
  3. bool header = true,
  4. int prefix = 1,
  5. int extraSpace = 5,
})

Evaluate the (un)compressed partial product array logic = =true will read the logic gate outputs at each level. printOut = true will print out the array in the StringBuffer. extraSpace add spacing for readability. header add a header for the column position. prefix add a prefix count of spaces.

Implementation

(BigInt, StringBuffer) evaluate(
    {bool printOut = false,
    bool logic = false,
    bool header = true,
    int prefix = 1,
    int extraSpace = 5}) {
  final ts = StringBuffer();
  final rows = longestColumn();
  final width = maxWidth();
  var accum = BigInt.zero;

  for (var row = 0; row < rows; row++) {
    final shift = usesColumnAlignedRows ? 0 : rowShift[row];
    final rowLogic = <Logic>[];
    for (var col = columns.length - 1; col >= 0; col--) {
      final colList = columns[col].toList();
      if (row < colList.length) {
        rowLogic.insert(0, colList[row].logic);
      } else if (usesColumnAlignedRows) {
        rowLogic.insert(0, Const(0));
      }
    }
    final rowBits = [for (final c in rowLogic) c.value].reversed.toList()
      ..addAll(List.filled(shift, LogicValue.zero));
    final rowBitsExtend = rowBits.length < width
        ? rowBits.concat().zeroExtend(width)
        : rowBits.concat();
    final val = rowBitsExtend.toBigInt();
    accum += val;
    ts
      ..write(rowLogic.listString('',
          header: header & (row == 0),
          alignHigh: width,
          prefix: prefix,
          extraSpace: extraSpace,
          intValue: true,
          shift: shift))
      ..write('\n');
  }

  final sum = Logic(width: width)..put(accum.toSigned(width));
  ts.write(sum.elements
      .listString('p', prefix: 1, extraSpace: extraSpace, intValue: true));

  return (sum.value.toBigInt().toSigned(width), ts);
}