• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
        • Warnings
        • Primitives
        • Use-set
        • Syntax
        • Getting-started
        • Utilities
        • Loader
        • Transforms
          • Expression-sizing
          • Occform
          • Oprewrite
          • Expand-functions
          • Delayredux
          • Unparameterization
          • Caseelim
          • Split
          • Selresolve
          • Weirdint-elim
          • Vl-delta
          • Replicate-insts
          • Rangeresolve
          • Propagate
          • Clean-selects
          • Clean-params
          • Blankargs
          • Inline-mods
          • Expr-simp
          • Trunc
          • Always-top
            • Edgesynth
              • Vl-edgesynth-stmt-p
              • Vl-edgetable-p
              • Vl-always-edgesynth
              • Vl-edgesynth-merge-data-ifs
              • Vl-assignstmtlist->controls
              • Vl-assignstmtlist->lhses
              • Vl-assignstmtlist->rhses
              • Vl-edgesynth-flatten-data-ifs
                • Vl-edgesynth-pattern-match
                • Nedgeflop
                • Vl-edgesynth-make-data-inputs
                • Vl-edgesynth-make-clock-inputs
                • Vl-edgesynth-stmt-clklift
                • Vl-edgesynth-blockelim
                • Vl-alwayslist-edgesynth
                • Vl-edgesynth-create
                • Vl-edgesynth-classify-iftest
                • Vl-module-edgesynth
                • Vl-edgesynth-normalize-ifs
                • Vl-edgesynth-delays-okp
                • Vl-edgesynth-stmt-assigns
                • Vl-make-edgetable
                • Vl-edgesynth-sort-edges
                • Vl-modulelist-edgesynth
                • Vl-modulelist-edgesynth-aux
                • Vl-assignstmtlist-p
                • Vl-edgesynth-edgelist-p
                • Vl-assigncontrols-p
                • Vl-edgesynth-stmt-conditions
                • Vl-edgesynth-edge-p
                • Vl-design-edgesynth
                • Vl-edgesynth-get-delay
                • Vl-edgesynth-iftype-p
                • Edge-tables
              • Stmtrewrite
              • Cblock
              • Vl-always-convert-regports
              • Vl-always-convert-regs
              • Stmttemps
              • Edgesplit
              • Vl-always-check-reg
              • Vl-convert-regs
              • Latchsynth
              • Vl-always-check-regs
              • Vl-match-always-at-some-edges
              • Unelse
              • Vl-always-convert-reg
              • Vl-design-always-backend
              • Vl-stmt-guts
              • Vl-always-convert-regport
              • Vl-always-scary-regs
              • Eliminitial
              • Ifmerge
              • Vl-edge-control-p
              • Elimalways
            • Gatesplit
            • Gate-elim
            • Expression-optimization
            • Elim-supplies
            • Wildelim
            • Drop-blankports
            • Clean-warnings
            • Addinstnames
            • Custom-transform-hooks
            • Annotate
            • Latchcode
            • Elim-unused-vars
            • Problem-modules
          • Lint
          • Mlib
          • Server
          • Kit
          • Printer
          • Esim-vl
          • Well-formedness
        • Sv
        • Fgl
        • Vwsim
        • Vl
        • X86isa
        • Svl
        • Rtl
      • Software-verification
      • Math
      • Testing-utilities
    • Edgesynth

    Vl-edgesynth-flatten-data-ifs

    Flatten out bottom-level if tests about data signals, such as if (data-expr) q <= d1 else q <= d2 into assignments like q <= data-expr ? d1 : d2.

    Signature
    (vl-edgesynth-flatten-data-ifs x edgetable nf vardecls assigns) 
      → 
    (mv new-stmt nf vardecls assigns)
    Arguments
    x — Guard (and (vl-stmt-p x) (vl-edgesynth-stmt-p x)).
    edgetable — Guard (vl-edgetable-p edgetable).
    nf — Guard (vl-namefactory-p nf).
    vardecls — Guard (vl-vardecllist-p vardecls).
    assigns — Guard (vl-assignlist-p assigns).
    Returns
    new-stmt — Type (vl-edgesynth-stmt-p new-stmt), given (force (vl-edgesynth-stmt-p x)).
    nf — Type (vl-namefactory-p nf), given (and (force (vl-edgesynth-stmt-p x)) (force (vl-namefactory-p nf))).

    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.

    Definitions and Theorems

    Function: vl-edgesynth-flatten-data-ifs

    (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: vl-edgesynth-stmt-p-of-vl-edgesynth-flatten-data-ifs.new-stmt

    (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: vl-namefactory-p-of-vl-edgesynth-flatten-data-ifs.nf

    (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: vl-edgesynth-flatten-data-ifs-basics

    (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)))))