validate method

void validate()

Method to validate the configuration of a single register.

Must check that its fields are mutually valid.

Implementation

void validate() {
  // start by running architectural register validation
  arch.validate();

  // reset value must fit within the register's width
  if (resetValue.bitLength > width) {
    throw CsrValidationException(
        'Register $name reset value does not fit within its width.');
  }

  // check that the field widths don't exceed the register width
  var impliedEnd = 0;
  for (final field in fields) {
    final currEnd = field.start + field.width - 1;
    if (currEnd > impliedEnd) {
      impliedEnd = currEnd;
    }
  }
  if (impliedEnd > width - 1) {
    throw CsrValidationException(
        'Register width implied by its fields exceeds true register width.');
  }
}