Parse (the data bytes of) a file.
(parse-file path data version) → (mv erp tunit)
We also pass an indication of the C version.
If successful, the result is a translation unit. We create a local stobj with the parser state, we initialize it with the data bytes, and we attempt to parse them as a translation unit. The final parser state is discarded, as is the case for local stobjs, since it is no longer needed.
If an error occurs, we enhance it with
information about the file path.
It is the case that
Function:
(defun parse-file (path data version) (declare (xargs :guard (and (filepathp path) (byte-listp data) (c::versionp version)))) (let ((__function__ 'parse-file)) (declare (ignorable __function__)) (with-local-stobj parstate (mv-let (erp tunit parstate) (b* ((parstate (init-parstate data version parstate)) ((mv erp tunit parstate) (parse-translation-unit parstate))) (if erp (if (msgp erp) (mv (msg "Error in file ~x0: ~@1" (filepath->unwrap path) erp) (irr-transunit) parstate) (prog2$ (raise "Internal error: ~x0 is not a message." erp) (mv t (irr-transunit) parstate))) (mv nil tunit parstate))) (mv erp tunit)))))
Theorem:
(defthm transunitp-of-parse-file.tunit (b* (((mv acl2::?erp ?tunit) (parse-file path data version))) (transunitp tunit)) :rule-classes :rewrite)