• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
        • Warnings
        • Primitives
        • Use-set
        • Syntax
        • Getting-started
        • Utilities
        • Loader
        • Transforms
        • Lint
        • Mlib
          • Scopestack
          • Filtering-by-name
          • Vl-namefactory
          • Substitution
          • Allexprs
          • Hid-tools
            • Following-hids
              • Vl-follow-hidexpr
              • Vl-partselect-type-top-dimension-replacement
              • Vl-hidindex-datatype-resolve-dims
              • Vl-follow-hidexpr-error
              • Vl-follow-hidexpr-dimscheck
              • Vl-index-find-type
              • Vl-follow-hidexpr-dimcheck
                • Vl-partselect-expr-type
                • Vl-ss-find-hidexpr-range!!
                • Vl-hidstep
                • Vl-ss-find-hidexpr-range
                • Vl-genarrayblocklist-find-block
                • Vl-flatten-hidindex
                • Vl-hidexpr-resolved-p
                • Vl-flatten-hidexpr
                • Vl-hidindex-resolved-p
                • Vl-hidtrace
              • Vl-hidexpr-traverse-datatype
              • Abstract-hids
              • Vl-hidexpr-find-type
            • Vl-consteval
            • Range-tools
            • Lvalexprs
            • Hierarchy
            • Finding-by-name
            • Expr-tools
            • Expr-slicing
            • Stripping-functions
            • Stmt-tools
            • Modnamespace
            • Vl-parse-expr-from-str
            • Welltyped
            • Reordering-by-name
            • Flat-warnings
            • Genblob
            • Expr-building
            • Datatype-tools
            • Syscalls
            • Relocate
            • Expr-cleaning
            • Namemangle
            • Caremask
            • Port-tools
            • Lvalues
          • Server
          • Kit
          • Printer
          • Esim-vl
          • Well-formedness
        • Sv
        • Fgl
        • Vwsim
        • Vl
        • X86isa
        • Svl
        • Rtl
      • Software-verification
      • Math
      • Testing-utilities
    • Following-hids

    Vl-follow-hidexpr-dimcheck

    Check an array index against the corresponding array bounds.

    Signature
    (vl-follow-hidexpr-dimcheck name index dim &key strictp) → err
    Arguments
    name — Name being the array, for better errors.
        Guard (stringp name).
    index — An index into an array.
        Guard (vl-expr-p index).
    dim — Bounds from the corresponding declaration.
        Guard (vl-packeddimension-p dim).
    strictp — Require indices to be resolved?.
        Guard (booleanp strictp).
    Returns
    err — Type (maybe-stringp err).

    In strict mode, we require that the index and the array dimensions all be resolved and that the index be in range.

    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.

    Definitions and Theorems

    Function: vl-follow-hidexpr-dimcheck-fn

    (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: maybe-stringp-of-vl-follow-hidexpr-dimcheck

    (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: vl-follow-hidexpr-dimcheck-fn-of-str-fix-name

    (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: vl-follow-hidexpr-dimcheck-fn-streqv-congruence-on-name

    (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: vl-follow-hidexpr-dimcheck-fn-of-vl-expr-fix-index

    (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: vl-follow-hidexpr-dimcheck-fn-vl-expr-equiv-congruence-on-index

    (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: vl-follow-hidexpr-dimcheck-fn-of-vl-packeddimension-fix-dim

    (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: vl-follow-hidexpr-dimcheck-fn-vl-packeddimension-equiv-congruence-on-dim

    (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: vl-follow-hidexpr-dimcheck-fn-of-bool-fix-strictp

    (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: vl-follow-hidexpr-dimcheck-fn-iff-congruence-on-strictp

    (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)