Check an array index against the corresponding array bounds.
(vl-follow-hidexpr-dimcheck name index dim &key strictp) → err
In strict mode, we require that the
In non-strict mode, we tolerate unresolved indices and declaration bounds. Note that we still do bounds checking if the indices and array bounds happen to be resolved.
Function:
(defun vl-follow-hidexpr-dimcheck-fn (name index dim strictp) (declare (xargs :guard (and (stringp name) (vl-expr-p index) (vl-packeddimension-p dim) (booleanp strictp)))) (let ((__function__ 'vl-follow-hidexpr-dimcheck)) (declare (ignorable __function__)) (b* ((dim (vl-packeddimension-fix dim)) ((when (eq dim :vl-unsized-dimension)) nil) ((unless (vl-expr-resolved-p index)) (if strictp "unresolved array index" nil)) ((unless (vl-range-resolved-p dim)) (if strictp (cat "unresolved bounds on declaration of " name) nil)) ((vl-range dim)) (idxval (vl-resolved->val index)) (msbval (vl-resolved->val dim.msb)) (lsbval (vl-resolved->val dim.lsb)) (minval (min msbval lsbval)) (maxval (max msbval lsbval)) ((unless (and (<= minval idxval) (<= idxval maxval))) (cat "array index " (natstr idxval) " out of bounds (" (natstr minval) " to " (natstr maxval) ")"))) nil)))
Theorem:
(defthm maybe-stringp-of-vl-follow-hidexpr-dimcheck (b* ((err (vl-follow-hidexpr-dimcheck-fn name index dim strictp))) (maybe-stringp err)) :rule-classes :type-prescription)
Theorem:
(defthm vl-follow-hidexpr-dimcheck-fn-of-str-fix-name (equal (vl-follow-hidexpr-dimcheck-fn (str-fix name) index dim strictp) (vl-follow-hidexpr-dimcheck-fn name index dim strictp)))
Theorem:
(defthm vl-follow-hidexpr-dimcheck-fn-streqv-congruence-on-name (implies (streqv name name-equiv) (equal (vl-follow-hidexpr-dimcheck-fn name index dim strictp) (vl-follow-hidexpr-dimcheck-fn name-equiv index dim strictp))) :rule-classes :congruence)
Theorem:
(defthm vl-follow-hidexpr-dimcheck-fn-of-vl-expr-fix-index (equal (vl-follow-hidexpr-dimcheck-fn name (vl-expr-fix index) dim strictp) (vl-follow-hidexpr-dimcheck-fn name index dim strictp)))
Theorem:
(defthm vl-follow-hidexpr-dimcheck-fn-vl-expr-equiv-congruence-on-index (implies (vl-expr-equiv index index-equiv) (equal (vl-follow-hidexpr-dimcheck-fn name index dim strictp) (vl-follow-hidexpr-dimcheck-fn name index-equiv dim strictp))) :rule-classes :congruence)
Theorem:
(defthm vl-follow-hidexpr-dimcheck-fn-of-vl-packeddimension-fix-dim (equal (vl-follow-hidexpr-dimcheck-fn name index (vl-packeddimension-fix dim) strictp) (vl-follow-hidexpr-dimcheck-fn name index dim strictp)))
Theorem:
(defthm vl-follow-hidexpr-dimcheck-fn-vl-packeddimension-equiv-congruence-on-dim (implies (vl-packeddimension-equiv dim dim-equiv) (equal (vl-follow-hidexpr-dimcheck-fn name index dim strictp) (vl-follow-hidexpr-dimcheck-fn name index dim-equiv strictp))) :rule-classes :congruence)
Theorem:
(defthm vl-follow-hidexpr-dimcheck-fn-of-bool-fix-strictp (equal (vl-follow-hidexpr-dimcheck-fn name index dim (acl2::bool-fix strictp)) (vl-follow-hidexpr-dimcheck-fn name index dim strictp)))
Theorem:
(defthm vl-follow-hidexpr-dimcheck-fn-iff-congruence-on-strictp (implies (iff strictp strictp-equiv) (equal (vl-follow-hidexpr-dimcheck-fn name index dim strictp) (vl-follow-hidexpr-dimcheck-fn name index dim strictp-equiv))) :rule-classes :congruence)