• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
        • Warnings
        • Primitives
        • Use-set
        • Syntax
        • Getting-started
        • Utilities
        • Loader
          • Preprocessor
          • Vl-loadconfig
          • Lexer
          • Vl-loadstate
          • Parser
          • Vl-load-merge-descriptions
          • Scope-of-defines
          • Vl-load-file
          • Vl-flush-out-descriptions
          • Vl-description
          • Vl-loadresult
          • Vl-read-file
            • Vl-read-file-loop
            • Vl-read-file-loop-aux
            • Vl-read-file-rchars
          • Vl-find-basename/extension
          • Vl-read-files
          • Vl-find-file
          • Extended-characters
          • Vl-load
          • Vl-load-main
          • Vl-load-description
          • Vl-descriptions-left-to-load
          • Inject-warnings
          • Vl-load-descriptions
          • Vl-load-files
          • Vl-load-summary
          • Vl-collect-modules-from-descriptions
          • Vl-descriptionlist
        • Transforms
        • Lint
        • Mlib
        • Server
        • Kit
        • Printer
        • Esim-vl
        • Well-formedness
      • Sv
      • Vwsim
      • Fgl
      • Vl
      • X86isa
      • Svl
      • Rtl
    • Software-verification
    • Testing-utilities
    • Math
  • Loader

Vl-read-file

Read an entire file into a list of extended characters.

Signature
(vl-read-file filename &key (state 'state)) 
  → 
(mv okp result state)
Arguments
filename — The file to read.
    Guard (stringp filename).
Returns
okp — Type (booleanp okp).
result — On success, the entire contents of filename as a list of extended-characters.
    Type (vl-echarlist-p result), given the guard.
state — Type (state-p1 state), given (force (state-p1 state)).

We read the file with read-byte$ instead of read-char$, because this seems perhaps to be more reliable. In particular, even if the Lisp system wants to use Unicode or some other encoding for character streams, read-byte$ should always safely return octets.

Definitions and Theorems

Function: vl-read-file-fn

(defun vl-read-file-fn (filename state)
       (declare (xargs :stobjs (state)))
       (declare (xargs :guard (stringp filename)))
       (let ((__function__ 'vl-read-file))
            (declare (ignorable __function__))
            (b* ((filename (string-fix filename))
                 ((mv channel state)
                  (open-input-channel filename
                                      :byte state))
                 ((unless channel) (mv nil nil state))
                 ((mv data state)
                  (vl-read-file-loop channel filename 1 0))
                 (state (close-input-channel channel state)))
                (mv t data state))))

Theorem: booleanp-of-vl-read-file.okp

(defthm booleanp-of-vl-read-file.okp
        (b* (((mv ?okp ?result acl2::?state)
              (vl-read-file-fn filename state)))
            (booleanp okp))
        :rule-classes :type-prescription)

Theorem: vl-echarlist-p-of-vl-read-file.result

(defthm vl-echarlist-p-of-vl-read-file.result
        (implies (and (force (state-p state))
                      (force (stringp filename)))
                 (b* (((mv ?okp ?result acl2::?state)
                       (vl-read-file-fn filename state)))
                     (vl-echarlist-p result)))
        :rule-classes :rewrite)

Theorem: state-p1-of-vl-read-file.state

(defthm state-p1-of-vl-read-file.state
        (implies (force (state-p1 state))
                 (b* (((mv ?okp ?result acl2::?state)
                       (vl-read-file-fn filename state)))
                     (state-p1 state)))
        :rule-classes :rewrite)

Theorem: true-listp-of-vl-read-file

(defthm true-listp-of-vl-read-file
        (true-listp (mv-nth 1 (vl-read-file filename)))
        :rule-classes :type-prescription)

Theorem: vl-read-file-when-error

(defthm vl-read-file-when-error
        (b* (((mv okp result ?state)
              (vl-read-file filename)))
            (implies (not okp) (not result))))

Subtopics

Vl-read-file-loop
Logically nice loop for vl-read-file.
Vl-read-file-loop-aux
Tail-recursive, executable loop for vl-read-file.
Vl-read-file-rchars
Optimized alternative to vl-read-file that reads the entire file into nrev.