Parse (the data bytes of) a file.
(parse-file path data gcc) → (mv erp tunit)
We also pass a flag saying whether GCC extensions should be accepted.
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 gcc) (declare (xargs :guard (and (filepathp path) (byte-listp data) (booleanp gcc)))) (let ((__function__ 'parse-file)) (declare (ignorable __function__)) (with-local-stobj parstate (mv-let (erp tunit parstate) (b* ((parstate (init-parstate data gcc 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 gcc))) (transunitp tunit)) :rule-classes :rewrite)