• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • 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
            • Stmtrewrite
              • Vl-modulelist-stmtrewrite
              • Vl-blockstmt-rewrite
              • Vl-repeatstmt-rewrite
              • Vl-flatten-blocks
                • Vl-stmt-rewrite-top
                • Vl-casestmt-rewrite
                • Vl-stmt-rewrite
                • Vl-waitstmt-rewrite
                • Vl-ifstmt-combine-rewrite
                • Vl-forstmt-rewrite
                • Vl-initiallist-stmtrewrite
                • Vl-alwayslist-stmtrewrite
                • Vl-initial-stmtrewrite
                • Vl-foreverstmt-rewrite
                • Vl-always-stmtrewrite
                • Vl-module-stmtrewrite
                • Vl-design-stmtrewrite
                • Vl-remove-null-statements
                • Vl-$vcover-stmt-p
                • Vl-$display-stmt-p
                • Vl-caselist-all-null-p
              • 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
    • Stmtrewrite

    Vl-flatten-blocks

    Collapse nested begin/end and fork/join blocks.

    Signature
    (vl-flatten-blocks sequentialp stmts) → new-stmts
    Arguments
    sequentialp — are we working with a sequential (begin/end) or parallel (fork/join) block.
        Guard (booleanp sequentialp).
    stmts — Guard (vl-stmtlist-p stmts).
    Returns
    new-stmts — Type (vl-stmtlist-p new-stmts), given the guard.

    This function carries out rewrites such as:

    begin               begin
      foo = a;    -->     foo = a;
      begin               bar = b;
        bar = b;          baz = c;
        baz = c;          goo = d;
      end               end
      goo = d;
    end

    It can similarly collapse fork/join blocks with inner fork/join blocks.

    We don't try to merge blocks that have their own scopes (i.e., names/decls). Handling them correctly seems very tricky because of hierarchical identifiers, etc.

    BOZO. We recursively flatten sub-blocks. I'm not sure if we need to do this, given the way that vl-stmt-rewrite works. Well, it's probably just some useless computation if it's not necessary.

    Definitions and Theorems

    Function: vl-flatten-blocks

    (defun vl-flatten-blocks (sequentialp stmts)
     (declare (xargs :guard (and (booleanp sequentialp)
                                 (vl-stmtlist-p stmts))))
     (let ((__function__ 'vl-flatten-blocks))
      (declare (ignorable __function__))
      (b* ((stmts (vl-stmtlist-fix stmts))
           ((when (atom stmts)) nil)
           ((unless (and (vl-blockstmt-p (car stmts))
                         (eq (vl-blockstmt->sequentialp (car stmts))
                             sequentialp)
                         (not (vl-blockstmt->name (car stmts)))
                         (atom (vl-blockstmt->vardecls (car stmts)))
                         (atom (vl-blockstmt->paramdecls (car stmts)))))
            (cons (car stmts)
                  (vl-flatten-blocks sequentialp (cdr stmts))))
           (merged-stmts
                (append-without-guard (vl-blockstmt->stmts (car stmts))
                                      (cdr stmts))))
        (vl-flatten-blocks sequentialp merged-stmts))))

    Theorem: vl-stmtlist-p-of-vl-flatten-blocks

    (defthm vl-stmtlist-p-of-vl-flatten-blocks
      (implies (and (force (booleanp sequentialp))
                    (force (vl-stmtlist-p stmts)))
               (b* ((new-stmts (vl-flatten-blocks sequentialp stmts)))
                 (vl-stmtlist-p new-stmts)))
      :rule-classes :rewrite)