• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
      • Sv
      • Fgl
      • Vwsim
      • Vl
        • Syntax
        • Loader
          • Preprocessor
            • Vl-iframe
            • Preprocessor-ifdef-minutia
            • Vl-preprocess
            • Vl-preprocess-loop
            • Vl-includeskips
            • Vl-read-until-end-of-define
            • Vl-define-formallist->defaults
            • Vl-define
            • Vl-expand-define
            • Vl-read-include
            • Vl-substitute-into-macro-text
            • Vl-process-ifdef
            • Ppst
            • Vl-read-define-default-text
            • Vl-process-define
              • Preprocessor-include-minutia
              • Vl-trim-for-preproc
              • Vl-line-up-define-formals-and-actuals
              • Vl-process-undef
              • Vl-split-define-text
              • Vl-def-context
              • Vl-process-endif
              • Scan-backward-for-non-whitespace
              • Vl-ifdef-context
              • Scan-backward-for-whitespace
              • Vl-atvl-atts-text
              • Scan-for-non-whitespace
              • Vl-check-remaining-formals-all-have-defaults
              • Vl-process-else
              • Vl-is-compiler-directive-p
              • Vl-includeskips-controller-lookup
              • Vl-ifdef-use-map
              • Vl-defines
              • Vl-def-use-map
              • Vl-nice-bytes
              • Vl-safe-previous-n
              • Vl-safe-next-n
              • Vl-ppst-pad
              • Vl-filename-to-string-literal
              • Vl-maybe-update-filemap
              • *vl-preprocess-clock*
              • Vl-ppst->warnings
              • Vl-ppst->iskips
              • Vl-ppst->ifdefmap
              • Vl-ppst->idcache
              • Vl-istack
              • Vl-ppst->istack
              • Vl-ppst->includes
              • Vl-ppst->filemap
              • Vl-ppst->defmap
              • Vl-ppst->defines
              • Vl-ppst->config
              • Vl-ppst->bytes
              • Vl-ppst->activep
              • Vl-ppst->acc
              • Vl-ppst-record-ifdef-use
              • Vl-ppst-record-def-use
              • Vl-ifdef-context-list
              • Vl-def-context-list
              • Vl-ppst-update-warnings
              • Vl-ppst-update-istack
              • Vl-ppst-update-iskips
              • Vl-ppst-update-includes
              • Vl-ppst-update-ifdefmap
              • Vl-ppst-update-idcache
              • Vl-ppst-update-filemap
              • Vl-ppst-update-defmap
              • Vl-ppst-update-defines
              • Vl-ppst-update-config
              • Vl-ppst-update-activep
              • Vl-ppst-update-bytes
              • Vl-ppst-update-acc
              • Vl-ppst-unsound-nreverse-acc
            • Vl-loadconfig
            • Vl-loadstate
            • Lexer
            • Parser
            • Vl-load-merge-descriptions
            • Vl-find-basename/extension
            • Vl-load-file
            • Vl-loadresult
            • Scope-of-defines
            • Vl-find-file
            • Vl-flush-out-descriptions
            • Vl-description
            • Vl-read-file
            • Vl-includeskips-report-gather
            • Vl-load-main
            • Extended-characters
            • Vl-load
            • Vl-load-description
            • Vl-descriptions-left-to-load
            • Inject-warnings
            • Vl-preprocess-debug
            • Vl-write-preprocessor-debug-file
            • Vl-read-file-report-gather
            • Vl-load-descriptions
            • Vl-load-files
            • Translate-off
            • Vl-load-read-file-hook
            • Vl-read-file-report
            • Vl-loadstate-pad
            • Vl-load-summary
            • Vl-collect-modules-from-descriptions
            • Vl-loadstate->warnings
            • Vl-iskips-report
            • Vl-descriptionlist
          • Warnings
          • Getting-started
          • Utilities
          • Printer
          • Kit
          • Mlib
          • Transforms
        • X86isa
        • Svl
        • Rtl
      • Software-verification
      • Math
      • Testing-utilities
    • Preprocessor

    Vl-process-define

    Handler for define directives.

    Signature
    (vl-process-define loc echars ppst) 
      → 
    (mv successp remainder ppst)
    Arguments
    loc — Guard (vl-location-p loc).
    echars — Guard (vl-echarlist-p echars).
    Returns
    remainder — Type (vl-echarlist-p remainder).

    We assume that `define has just been read and echars is the text which comes right after the `define directive. We read the name and text for this new macro definition, and update the defines table appropriately if activep is set.

    Definitions and Theorems

    Function: vl-process-define

    (defun vl-process-define (loc echars ppst)
     (declare (xargs :stobjs (ppst)))
     (declare (xargs :guard (and (vl-location-p loc)
                                 (vl-echarlist-p echars))))
     (let ((__function__ 'vl-process-define))
      (declare (ignorable __function__))
      (b*
       ((echars (vl-echarlist-fix echars))
        ((mv & remainder)
         (vl-read-while-whitespace echars))
        ((mv name & remainder)
         (vl-read-identifier remainder))
        ((unless name)
         (let
          ((ppst
              (vl-ppst-fatal :msg "~a0: found a `define without a name."
                             :args (list loc))))
          (mv nil echars ppst)))
        ((when (vl-is-compiler-directive-p name))
         (let
          ((ppst
              (vl-ppst-fatal :msg "~a0: refusing to permit `define ~s1."
                             :args (list loc name))))
          (mv nil echars ppst)))
        ((mv successp text remainder ppst)
         (vl-read-until-end-of-define remainder ppst))
        ((unless successp) (mv nil echars ppst))
        ((unless (vl-ppst->activep))
         (mv t remainder ppst))
        ((mv okp formals body ppst)
         (vl-split-define-text text ppst))
        ((unless okp) (mv nil remainder ppst))
        (formal-names (vl-define-formallist->names formals))
        ((unless (uniquep formal-names))
         (let
          ((ppst
                (vl-ppst-fatal
                     :msg "~a0: `define ~s1 has repeated arguments ~&2."
                     :args (list loc name
                                 (duplicated-members formal-names)))))
          (mv nil echars ppst)))
        (new-def (make-vl-define :formals formals
                                 :body (vl-echarlist->string body)
                                 :loc loc
                                 :stickyp nil))
        (defines (vl-ppst->defines))
        (prev-def (vl-find-define name defines))
        (ppst
         (b* (((unless prev-def) ppst)
              (new-str (str::trim (vl-define->body new-def)))
              (old-str (str::trim (vl-define->body prev-def)))
              ((when (equal new-str old-str)) ppst))
          (vl-ppst-warn
           :type
           (if (vl-define->stickyp prev-def)
               :vl-warn-define-ignored
             :vl-warn-define-smashed)
           :msg
           (if
            (vl-define->stickyp prev-def)
            "Preprocessor warning: ignoring redefinition of ~s0:~% ~
                               - Keeping  ~s1     // from ~a2~% ~
                               - Ignoring ~s3     // from ~a4~%"
            "Preprocessor warning: redefining ~s0:~% ~
                             - Was ~s1     // from ~a2~% ~
                             - Now ~s3     // from ~a4~%")
           :args (list name old-str (vl-define->loc prev-def)
                       new-str loc))))
        (defines (if (and prev-def (vl-define->stickyp prev-def))
                     defines
                   (vl-add-define name new-def defines))
    )
        (ppst (vl-ppst-update-defines defines)))
       (mv t remainder ppst))))

    Theorem: vl-echarlist-p-of-vl-process-define.remainder

    (defthm vl-echarlist-p-of-vl-process-define.remainder
      (b* (((mv ?successp ?remainder ?ppst)
            (vl-process-define loc echars ppst)))
        (vl-echarlist-p remainder))
      :rule-classes :rewrite)

    Theorem: true-listp-of-vl-process-define-remainder

    (defthm true-listp-of-vl-process-define-remainder
      (true-listp (mv-nth 1 (vl-process-define loc echars ppst)))
      :rule-classes :type-prescription)

    Theorem: acl2-count-of-vl-process-define

    (defthm acl2-count-of-vl-process-define
      (<= (acl2-count (mv-nth 1 (vl-process-define loc echars ppst)))
          (acl2-count (vl-echarlist-fix echars)))
      :rule-classes ((:rewrite) (:linear)))

    Theorem: acl2-count-of-vl-process-define-strong

    (defthm acl2-count-of-vl-process-define-strong
     (implies
          (mv-nth 0 (vl-process-define loc echars ppst))
          (< (acl2-count (mv-nth 1 (vl-process-define loc echars ppst)))
             (acl2-count (vl-echarlist-fix echars))))
     :rule-classes ((:rewrite) (:linear)))