Main operator rewriting function.
(vl-op-oprewrite op args atts warnings) → (mv warnings expr)
Keeping this function separate from vl-expr-oprewrite helps to keep the mutual recursion as simple as possible.
Function:
(defun vl-op-oprewrite (op args atts warnings) (declare (xargs :guard (and (vl-op-p op) (vl-exprlist-p args) (vl-atts-p atts) (vl-warninglist-p warnings)))) (declare (xargs :guard (or (not (vl-op-arity op)) (equal (len args) (vl-op-arity op))))) (let ((__function__ 'vl-op-oprewrite)) (declare (ignorable __function__)) (case (vl-op-fix op) (:vl-qmark (b* (((list a b c) args) (or-a (make-vl-nonatom :op :vl-unary-bitor :args (list a) :atts (acons "VL_CONDITIONAL_FIX" nil atts)))) (if (vl-zatom-p b) (let ((nor-a (make-vl-nonatom :op :vl-unary-bitnot :args (list or-a) :atts (acons "VL_CONDITIONAL_FIX" nil atts)))) (mv (ok) (make-vl-nonatom :op :vl-qmark :atts atts :args (list nor-a c b)))) (mv (ok) (make-vl-nonatom :op :vl-qmark :atts atts :args (list or-a b c)))))) (:vl-binary-logand (b* (((list a b) args) (or-a (make-vl-nonatom :op :vl-unary-bitor :args (list a))) (or-b (make-vl-nonatom :op :vl-unary-bitor :args (list b))) (result (make-vl-nonatom :op :vl-binary-bitand :atts atts :args (list or-a or-b)))) (mv (ok) result))) (:vl-binary-logor (b* (((list a b) args) (or-a (make-vl-nonatom :op :vl-unary-bitor :args (list a))) (or-b (make-vl-nonatom :op :vl-unary-bitor :args (list b))) (result (make-vl-nonatom :op :vl-binary-bitor :atts atts :args (list or-a or-b)))) (mv (ok) result))) (:vl-unary-plus (b* (((list a) args) (|1'sb0| (make-vl-atom :guts (make-vl-constint :value 0 :origwidth 1 :origtype :vl-signed))) (result (make-vl-nonatom :op :vl-binary-plus :atts atts :args (list a |1'sb0|)))) (mv (ok) result))) (:vl-unary-minus (b* (((list a) args) (|1'sb0| (make-vl-atom :guts (make-vl-constint :value 0 :origwidth 1 :origtype :vl-signed))) (result (make-vl-nonatom :op :vl-binary-minus :atts atts :args (list |1'sb0| a)))) (mv (ok) result))) (:vl-unary-lognot (b* (((list a) args) (or-a (make-vl-nonatom :op :vl-unary-bitor :args (list a))) (~or-a (make-vl-nonatom :op :vl-unary-bitnot :args (list or-a))) (result (make-vl-nonatom :op :vl-concat :atts atts :args (list ~or-a)))) (mv (ok) result))) (:vl-unary-nand (b* (((list a) args) (and-a (make-vl-nonatom :op :vl-unary-bitand :args (list a))) (~and-a (make-vl-nonatom :op :vl-unary-bitnot :args (list and-a))) (result (make-vl-nonatom :op :vl-concat :atts atts :args (list ~and-a)))) (mv (ok) result))) (:vl-unary-nor (b* (((list a) args) (or-a (make-vl-nonatom :op :vl-unary-bitor :args (list a))) (~or-a (make-vl-nonatom :op :vl-unary-bitnot :args (list or-a))) (result (make-vl-nonatom :op :vl-concat :atts atts :args (list ~or-a)))) (mv (ok) result))) (:vl-unary-xnor (b* (((list a) args) (^a (make-vl-nonatom :op :vl-unary-xor :args (list a))) (~^a (make-vl-nonatom :op :vl-unary-bitnot :args (list ^a))) (result (make-vl-nonatom :op :vl-concat :atts atts :args (list ~^a)))) (mv (ok) result))) ((:vl-binary-eq) (b* (((list a b) args) (a~^b (make-vl-nonatom :op :vl-binary-xnor :args (list a b))) (result (make-vl-nonatom :op :vl-unary-bitand :atts atts :args (list a~^b)))) (mv (ok) result))) ((:vl-binary-neq) (b* (((list a b) args) (a^b (make-vl-nonatom :op :vl-binary-xor :args (list a b))) (result (make-vl-nonatom :op :vl-unary-bitor :atts atts :args (list a^b)))) (mv (ok) result))) (:vl-binary-cne (b* (((list a b) args) (a===b (make-vl-nonatom :op :vl-binary-ceq :args (list a b))) (~a===b (make-vl-nonatom :op :vl-unary-bitnot :args (list a===b))) (result (make-vl-nonatom :op :vl-concat :atts atts :args (list ~a===b)))) (mv (ok) result))) (:vl-binary-lt (b* (((list a b) args) (a>=b (make-vl-nonatom :op :vl-binary-gte :args (list a b))) (~a>=b (make-vl-nonatom :op :vl-unary-bitnot :args (list a>=b))) (result (make-vl-nonatom :op :vl-concat :atts atts :args (list ~a>=b)))) (mv (ok) result))) (:vl-binary-gt (b* (((list a b) args) (b>=a (make-vl-nonatom :op :vl-binary-gte :args (list b a))) (~b>=a (make-vl-nonatom :op :vl-unary-bitnot :args (list b>=a))) (result (make-vl-nonatom :op :vl-concat :atts atts :args (list ~b>=a)))) (mv (ok) result))) (:vl-binary-lte (b* (((list a b) args) (result (make-vl-nonatom :op :vl-binary-gte :atts atts :args (list b a)))) (mv (ok) result))) (:vl-multiconcat (let ((result (vl-maybe-consolidate-multiconcat (make-vl-nonatom :op :vl-multiconcat :args args :atts atts)))) (mv (ok) result))) (otherwise (mv (ok) (make-vl-nonatom :op op :args args :atts atts))))))
Theorem:
(defthm vl-warninglist-p-of-vl-op-oprewrite.warnings (b* (((mv ?warnings ?expr) (vl-op-oprewrite op args atts warnings))) (vl-warninglist-p warnings)) :rule-classes :rewrite)
Theorem:
(defthm vl-expr-p-of-vl-op-oprewrite.expr (b* (((mv ?warnings ?expr) (vl-op-oprewrite op args atts warnings))) (vl-expr-p expr)) :rule-classes :rewrite)
Theorem:
(defthm vl-op-oprewrite-of-vl-op-fix-op (equal (vl-op-oprewrite (vl-op-fix op) args atts warnings) (vl-op-oprewrite op args atts warnings)))
Theorem:
(defthm vl-op-oprewrite-vl-op-equiv-congruence-on-op (implies (vl-op-equiv op op-equiv) (equal (vl-op-oprewrite op args atts warnings) (vl-op-oprewrite op-equiv args atts warnings))) :rule-classes :congruence)
Theorem:
(defthm vl-op-oprewrite-of-vl-exprlist-fix-args (equal (vl-op-oprewrite op (vl-exprlist-fix args) atts warnings) (vl-op-oprewrite op args atts warnings)))
Theorem:
(defthm vl-op-oprewrite-vl-exprlist-equiv-congruence-on-args (implies (vl-exprlist-equiv args args-equiv) (equal (vl-op-oprewrite op args atts warnings) (vl-op-oprewrite op args-equiv atts warnings))) :rule-classes :congruence)
Theorem:
(defthm vl-op-oprewrite-of-vl-atts-fix-atts (equal (vl-op-oprewrite op args (vl-atts-fix atts) warnings) (vl-op-oprewrite op args atts warnings)))
Theorem:
(defthm vl-op-oprewrite-vl-atts-equiv-congruence-on-atts (implies (vl-atts-equiv atts atts-equiv) (equal (vl-op-oprewrite op args atts warnings) (vl-op-oprewrite op args atts-equiv warnings))) :rule-classes :congruence)
Theorem:
(defthm vl-op-oprewrite-of-vl-warninglist-fix-warnings (equal (vl-op-oprewrite op args atts (vl-warninglist-fix warnings)) (vl-op-oprewrite op args atts warnings)))
Theorem:
(defthm vl-op-oprewrite-vl-warninglist-equiv-congruence-on-warnings (implies (vl-warninglist-equiv warnings warnings-equiv) (equal (vl-op-oprewrite op args atts warnings) (vl-op-oprewrite op args atts warnings-equiv))) :rule-classes :congruence)