Flatten out bottom-level if tests about data signals, such as
(vl-edgesynth-flatten-data-ifs x edgetable nf vardecls assigns) → (mv new-stmt nf vardecls assigns)
This is a best-effort transform that leaves the statement alone when it's not supported.
Originally I tried to just fail when the sizes of the true/false branch didn't line up, but that caused problems because sometimes we would see things like:
if (data-expr) q <= d1; else q <= 0;
And the plain integers are badly sized. To deal with this, we now go ahead and do the work of introducing temporary wires as necessary. The only lousy part of this is that we can't really extend the vl-delta-p, since we're not sure everything's going to work out yet.
Function:
(defun vl-edgesynth-flatten-data-ifs (x edgetable nf vardecls assigns) (declare (xargs :guard (and (and (vl-stmt-p x) (vl-edgesynth-stmt-p x)) (vl-edgetable-p edgetable) (vl-namefactory-p nf) (vl-vardecllist-p vardecls) (vl-assignlist-p assigns)))) (let ((__function__ 'vl-edgesynth-flatten-data-ifs)) (declare (ignorable __function__)) (b* (((when (vl-atomicstmt-p x)) (mv x nf vardecls assigns)) ((when (vl-ifstmt-p x)) (b* (((vl-ifstmt x) x) ((mv type ?guts) (vl-edgesynth-classify-iftest x.condition edgetable)) ((mv true nf vardecls assigns) (vl-edgesynth-flatten-data-ifs x.truebranch edgetable nf vardecls assigns)) ((mv false nf vardecls assigns) (vl-edgesynth-flatten-data-ifs x.falsebranch edgetable nf vardecls assigns)) ((unless (and (equal type :data) (vl-atomicstmt-p true) (vl-atomicstmt-p false))) (mv (change-vl-ifstmt x :truebranch true :falsebranch false) nf vardecls assigns))) (vl-edgesynth-merge-data-ifs x.condition true false nf vardecls assigns))) ((when (vl-blockstmt-p x)) (raise "Thought we already got rid of block statements!") (mv x nf vardecls assigns))) (raise "Should be impossible.") (mv x nf vardecls assigns))))
Theorem:
(defthm vl-edgesynth-stmt-p-of-vl-edgesynth-flatten-data-ifs.new-stmt (implies (force (vl-edgesynth-stmt-p x)) (b* (((mv ?new-stmt ?nf ?vardecls ?assigns) (vl-edgesynth-flatten-data-ifs x edgetable nf vardecls assigns))) (vl-edgesynth-stmt-p new-stmt))) :rule-classes :rewrite)
Theorem:
(defthm vl-namefactory-p-of-vl-edgesynth-flatten-data-ifs.nf (implies (and (force (vl-edgesynth-stmt-p x)) (force (vl-namefactory-p nf))) (b* (((mv ?new-stmt ?nf ?vardecls ?assigns) (vl-edgesynth-flatten-data-ifs x edgetable nf vardecls assigns))) (vl-namefactory-p nf))) :rule-classes :rewrite)
Theorem:
(defthm vl-edgesynth-flatten-data-ifs-basics (implies (and (force (vl-edgesynth-stmt-p x)) (force (vl-namefactory-p nf)) (force (vl-vardecllist-p vardecls)) (force (vl-assignlist-p assigns))) (b* (((mv ?new-x ?nf ?vardecls ?assigns) (vl-edgesynth-flatten-data-ifs x edgetable nf vardecls assigns))) (and (vl-vardecllist-p vardecls) (vl-assignlist-p assigns)))))