Find the variables affected by a term.
(atc-find-affected fn term typed-formals prec-fns wrld) → (mv erp affected)
This is used on the body of each non-recursive target function
In checking that the terms at the leaves have the same form,
we allow
When we encounter ifs with mbt tests, we recursively process the `then' branch, skipping the `else' branch. This is because only the `then' branch represents C code.
Function:
(defun atc-find-affected (fn term typed-formals prec-fns wrld) (declare (xargs :guard (and (symbolp fn) (pseudo-termp term) (atc-symbol-varinfo-alistp typed-formals) (atc-symbol-fninfo-alistp prec-fns) (plist-worldp wrld)))) (let ((__function__ 'atc-find-affected)) (declare (ignorable __function__)) (b* (((reterr) nil) ((mv okp test then else) (fty-check-if-call term)) ((when okp) (b* (((mv mbtp &) (check-mbt-call test)) ((when mbtp) (atc-find-affected fn then typed-formals prec-fns wrld)) ((erp then-affected) (atc-find-affected fn then typed-formals prec-fns wrld)) ((erp else-affected) (atc-find-affected fn else typed-formals prec-fns wrld))) (if (equal then-affected else-affected) (retok then-affected) (reterr (msg "When generating code for function ~x0, ~ an IF branch affects variables ~x1, ~ while the other branch affects variables ~x2: ~ this is disallowed." fn then-affected else-affected))))) ((mv okp & body &) (fty-check-lambda-call term)) ((when okp) (atc-find-affected fn body typed-formals prec-fns wrld)) ((erp okp & & & & affected & & &) (atc-check-cfun-call term nil prec-fns wrld)) ((when okp) (retok affected)) ((mv okp & & & affected & &) (atc-check-loop-call term nil prec-fns)) ((when okp) (retok affected)) ((when (pseudo-term-case term :var)) (b* ((var (pseudo-term-var->name term))) (if (atc-formal-affectablep var typed-formals) (retok (list var)) (retok nil)))) ((mv okp terms) (fty-check-list-call term)) ((when okp) (cond ((and (symbol-listp terms) (atc-formal-affectable-listp terms typed-formals)) (retok terms)) ((and (symbol-listp (cdr terms)) (atc-formal-affectable-listp (cdr terms) typed-formals)) (retok (cdr terms))) (t (reterr (msg "When generating code for function ~x0, ~ a term ~x1 was encountered that ~ returns multiple values but they, ~ or at least all of them except the first one, ~ are not all formal parameters of ~x0 ~ of pointer or array type." fn term)))))) (retok nil))))
Theorem:
(defthm symbol-listp-of-atc-find-affected.affected (implies (atc-symbol-varinfo-alistp typed-formals) (b* (((mv acl2::?erp ?affected) (atc-find-affected fn term typed-formals prec-fns wrld))) (symbol-listp affected))) :rule-classes :rewrite)