• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • ACL2
    • Macro-libraries
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
          • Syntax-for-tools
          • Atc
            • Atc-implementation
              • Atc-abstract-syntax
              • Atc-pretty-printer
              • Atc-event-and-code-generation
                • Atc-symbolic-computation-states
                • Atc-symbolic-execution-rules
                • Atc-gen-ext-declon-lists
                • Atc-function-and-loop-generation
                  • Atc-gen-cfun-correct-thm
                  • Atc-typed-formals
                  • Atc-gen-outer-bindings-and-hyps
                  • Atc-gen-fundef
                  • Atc-gen-exec-stmt-while-for-loop
                  • Atc-gen-context-preamble
                  • Atc-gen-pop-frame-thm
                  • Atc-gen-loop-correct-thm
                  • Atc-gen-init-scope-thms
                  • Atc-gen-fun-correct-thm
                  • Atc-gen-fn-result-thm
                  • Atc-gen-loop-body-correct-thm
                  • Atc-gen-loop
                  • Atc-gen-loop-test-correct-thm
                  • Atc-check-guard-conjunct
                  • Atc-find-affected
                  • Atc-gen-cfun-final-compustate
                  • Atc-gen-init-inscope-auto
                    • Atc-gen-init-inscope-static
                    • Atc-gen-push-init-thm
                    • Atc-gen-loop-measure-fn
                    • Atc-gen-fun-endstate
                    • Atc-gen-loop-termination-thm
                    • Atc-gen-formal-thm
                    • Atc-gen-loop-final-compustate
                    • Atc-gen-loop-measure-thm
                    • Atc-gen-object-disjoint-hyps
                    • Atc-loop-body-term-subst
                    • Atc-gen-omap-update-formals
                    • Atc-gen-loop-tthm-formula
                    • Atc-gen-init-inscope
                    • Atc-gen-fn-def*
                    • Atc-gen-param-declon-list
                    • Atc-formal-affectablep
                    • Atc-gen-cfun-fun-env-thm
                    • Atc-gen-add-var-formals
                    • Atc-gen-cfun-fun-env-thm-name
                    • Atc-gen-fn-guard
                    • Atc-filter-exec-fun-args
                    • Atc-gen-context-preamble-aux-aux
                    • Atc-typed-formals-to-extobjs
                    • Atc-formal-affectable-listp
                  • Atc-statement-generation
                  • Atc-gen-fileset
                  • Atc-gen-everything
                  • Atc-gen-obj-declon
                  • Atc-gen-fileset-event
                  • Atc-tag-tables
                  • Atc-expression-generation
                  • Atc-generation-contexts
                  • Atc-gen-wf-thm
                  • Term-checkers-atc
                  • Atc-variable-tables
                  • Term-checkers-common
                  • Atc-gen-init-fun-env-thm
                  • Atc-gen-appconds
                  • Read-write-variables
                  • Atc-gen-thm-assert-events
                  • Test*
                  • Atc-gen-prog-const
                  • Atc-gen-expr-bool
                  • Atc-theorem-generation
                  • Atc-tag-generation
                  • Atc-gen-expr-pure
                  • Atc-function-tables
                  • Atc-object-tables
                • Fty-pseudo-term-utilities
                • Atc-term-recognizers
                • Atc-input-processing
                • Atc-shallow-embedding
                • Atc-process-inputs-and-gen-everything
                • Atc-table
                • Atc-fn
                • Atc-pretty-printing-options
                • Atc-types
                • Atc-macro-definition
              • Atc-tutorial
            • Language
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Atc-function-and-loop-generation

    Atc-gen-init-inscope-auto

    Generate the automatic storage scope of the initial symbol tale for a C function.

    Signature
    (atc-gen-init-inscope-auto fn fn-guard typed-formals prec-tags 
                               compst-var context names-to-avoid wrld) 
     
      → 
    (mv scope events names-to-avoid)
    Arguments
    fn — Guard (symbolp fn).
    fn-guard — Guard (symbolp fn-guard).
    typed-formals — Guard (atc-symbol-varinfo-alistp typed-formals).
    prec-tags — Guard (atc-string-taginfo-alistp prec-tags).
    compst-var — Guard (symbolp compst-var).
    context — Guard (atc-contextp context).
    names-to-avoid — Guard (symbol-listp names-to-avoid).
    wrld — Guard (plist-worldp wrld).
    Returns
    scope — Type (atc-symbol-varinfo-alistp scope), given (atc-symbol-varinfo-alistp typed-formals).
    events — Type (pseudo-event-form-listp events).
    names-to-avoid — Type (symbol-listp names-to-avoid), given (symbol-listp names-to-avoid).

    The initial symbol table consists of a scope for static storage and a scope for automatic storage. The latter consists of the ACL2 function parameters that represent C function parameters (i.e. not external objects).

    We go through the typed formals, and we select the ones not representing external objects, generating an entry in the scope (alist) for each.

    The -0 suffix that we use for the generated theorem name is motivated by the fact that these are the theorems for the initial symbol table; as we update the symbol table in the course of generating code, we use positive indices as suffixes.

    Definitions and Theorems

    Function: atc-gen-init-inscope-auto

    (defun atc-gen-init-inscope-auto
           (fn fn-guard typed-formals prec-tags
               compst-var context names-to-avoid wrld)
     (declare
          (xargs :guard (and (symbolp fn)
                             (symbolp fn-guard)
                             (atc-symbol-varinfo-alistp typed-formals)
                             (atc-string-taginfo-alistp prec-tags)
                             (symbolp compst-var)
                             (atc-contextp context)
                             (symbol-listp names-to-avoid)
                             (plist-worldp wrld))))
     (let ((__function__ 'atc-gen-init-inscope-auto))
      (declare (ignorable __function__))
      (b*
       (((when (endp typed-formals))
         (mv nil nil names-to-avoid))
        ((cons var info) (car typed-formals))
        (type (atc-var-info->type info))
        (var-thm (atc-var-info->thm info))
        (externalp (atc-var-info->externalp info))
        ((when externalp)
         (atc-gen-init-inscope-auto
              fn fn-guard (cdr typed-formals)
              prec-tags
              compst-var context names-to-avoid wrld))
        (type-pred (atc-type-to-recognizer type prec-tags))
        (name (pack fn '- var '-in-scope-0))
        ((mv name names-to-avoid)
         (fresh-logical-name-with-$s-suffix
              name nil names-to-avoid wrld))
        (var/varptr (if (or (type-case type :pointer)
                            (type-case type :array))
                        (add-suffix-to-fn var "-PTR")
                      var))
        (formula1
         (cons
          'and
          (cons
           (cons 'objdesign-of-var
                 (cons (cons 'ident
                             (cons (symbol-name var) 'nil))
                       (cons compst-var 'nil)))
           (cons
            (cons
             'equal
             (cons
              (cons
                  'read-object
                  (cons (cons 'objdesign-of-var
                              (cons (cons 'ident
                                          (cons (symbol-name var) 'nil))
                                    (cons compst-var 'nil)))
                        (cons compst-var 'nil)))
              (cons var/varptr 'nil)))
            (and
             (or (type-case type :pointer)
                 (type-case type :array))
             (cons
                (cons 'equal
                      (cons (cons 'read-object
                                  (cons (add-suffix-to-fn var "-OBJDES")
                                        (cons compst-var 'nil)))
                            (cons var 'nil)))
                'nil))))))
        (formula1
             (atc-contextualize formula1 context
                                fn fn-guard compst-var nil nil t wrld))
        (formula2 (cons type-pred (cons var 'nil)))
        (formula2 (atc-contextualize formula2 context
                                     fn fn-guard nil nil nil nil wrld))
        (formula (cons 'and
                       (cons formula1 (cons formula2 'nil))))
        (not-flexiblep-thms
             (atc-type-to-notflexarrmem-thms type prec-tags))
        (valuep-when-type-pred (atc-type-to-valuep-thm type prec-tags))
        (value-kind-when-type-pred
             (atc-type-to-value-kind-thm type prec-tags))
        (hints
         (cons
          (cons
           '"Goal"
           (cons
            ':in-theory
            (cons
             (cons
              'quote
              (cons
               (cons
                'objdesign-of-var-of-add-var-iff
                (cons
                 'read-object-of-objdesign-of-var-of-add-var
                 (cons
                  var-thm
                  (cons
                   'ident-fix-when-identp
                   (cons
                    'identp-of-ident
                    (cons
                     'equal-of-ident-and-ident
                     (cons
                      '(:e str-fix)
                      (append
                       not-flexiblep-thms
                       (cons
                        'remove-flexible-array-member-when-absent
                        (cons
                           'value-fix-when-valuep
                           (append (and (or (type-case type :pointer)
                                            (type-case type :array))
                                        '(read-object-of-add-var
                                              read-object-of-add-frame))
                                   (cons valuep-when-type-pred
                                         (cons value-kind-when-type-pred
                                               'nil)))))))))))))
               'nil))
             'nil)))
          'nil))
        ((mv event &)
         (evmac-generate-defthm name
                                :formula formula
                                :hints hints
                                :enable nil))
        ((mv scope-rest events-rest names-to-avoid)
         (atc-gen-init-inscope-auto fn fn-guard (cdr typed-formals)
                                    prec-tags compst-var
                                    context names-to-avoid wrld)))
       (mv (cons (cons var
                       (make-atc-var-info :type type
                                          :thm name
                                          :externalp nil))
                 scope-rest)
           (cons event events-rest)
           names-to-avoid))))

    Theorem: atc-symbol-varinfo-alistp-of-atc-gen-init-inscope-auto.scope

    (defthm atc-symbol-varinfo-alistp-of-atc-gen-init-inscope-auto.scope
     (implies
       (atc-symbol-varinfo-alistp typed-formals)
       (b*
         (((mv ?scope ?events ?names-to-avoid)
           (atc-gen-init-inscope-auto fn fn-guard
                                      typed-formals prec-tags compst-var
                                      context names-to-avoid wrld)))
         (atc-symbol-varinfo-alistp scope)))
     :rule-classes :rewrite)

    Theorem: pseudo-event-form-listp-of-atc-gen-init-inscope-auto.events

    (defthm pseudo-event-form-listp-of-atc-gen-init-inscope-auto.events
     (b* (((mv ?scope ?events ?names-to-avoid)
           (atc-gen-init-inscope-auto fn fn-guard
                                      typed-formals prec-tags compst-var
                                      context names-to-avoid wrld)))
       (pseudo-event-form-listp events))
     :rule-classes :rewrite)

    Theorem: symbol-listp-of-atc-gen-init-inscope-auto.names-to-avoid

    (defthm symbol-listp-of-atc-gen-init-inscope-auto.names-to-avoid
     (implies
       (symbol-listp names-to-avoid)
       (b*
         (((mv ?scope ?events ?names-to-avoid)
           (atc-gen-init-inscope-auto fn fn-guard
                                      typed-formals prec-tags compst-var
                                      context names-to-avoid wrld)))
         (symbol-listp names-to-avoid)))
     :rule-classes :rewrite)