• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
      • Sv
      • Fgl
      • Vwsim
      • Vl
        • Syntax
          • Vl-module
          • Vl-vardecl
          • Vl-fundecl
          • Vl-interface
          • Vl-design
          • Vl-assign
          • Vl-modinst
          • Vl-gateinst
          • Vl-taskdecl
          • Vl-portdecl
          • Vl-commentmap
            • Vl-commentmap-p
              • Vl-descriptionlist-inject-comments-aux
              • Vl-commentmap-entry-sort
              • Vl-commentmap-falp
              • Vl-adjust-minloc-for-comments
                • Vl-kill-whitespace-and-comments
                • Vl-description-inject-comments
                • Vl-gather-comments
                • Vl-descriptionlist-inject-comments
                • Vl-description-add-warning
                • Vl-description-set-comments
                • Vl-gather-comments-fal
                • Vl-commentmap-fal
                • Vl-description->minloc
                • Vl-description->maxloc
                • Vl-description->comments
                • Vl-description-has-comments-p
              • Vl-commentmap-fix
              • Vl-commentmap-equiv
            • Vl-dpiimport
            • Vl-ansi-portdecl
            • Vl-package
            • Vl-paramdecl
            • Vl-dpiexport
            • Vl-class
            • Vl-sort-blockitems-aux
            • Vl-plainarglist->exprs
            • Vl-taskdecllist->names
            • Expressions-and-datatypes
            • Vl-fundecllist->names
            • Vl-udp
            • Vl-port
            • Vl-genelement
            • Vl-clkdecl
            • Vl-parse-temps
            • Vl-bind
            • Vl-namedarg
            • Vl-exprdist
            • Vl-clkassign
            • Vl-range
            • Vl-propport
            • Vl-typedef
            • Vl-gatedelay
            • Vl-dimension
            • Vl-sequence
            • Vl-clkskew
            • Vl-program
            • Vl-gatestrength
            • Vl-property
            • Vl-config
            • Vl-always
            • Vl-import
            • Vl-repeateventcontrol
            • Vl-timeliteral
            • Vl-initial
            • Vl-eventcontrol
            • Vl-final
            • Vl-udpsymbol-p
            • Vl-maybe-clkskew
            • Vl-function-specialization
            • Vl-alias
            • Vl-maybe-nettypename
            • Vl-maybe-gatedelay
            • Vl-letdecl
            • Vl-direction-p
            • Vl-modelement
            • Vl-maybe-timeprecisiondecl
            • Vl-maybe-scopeid
            • Vl-maybe-gatestrength
            • Vl-maybe-direction
            • Vl-maybe-delayoreventcontrol
            • Vl-gclkdecl
            • Vl-fwdtypedef
            • Vl-maybe-udpsymbol-p
            • Vl-maybe-timeunitdecl
            • Vl-maybe-timeliteral
            • Vl-maybe-parse-temps
            • Vl-maybe-cstrength
            • Vl-arguments
            • Vl-maybe-module
            • Vl-maybe-design
            • Vl-covergroup
            • Vl-udpline
            • Vl-timeunitdecl
            • Vl-genvar
            • Vl-defaultdisable
            • Vl-context1
            • Vl-timeprecisiondecl
            • Vl-sort-blockitems
            • Vl-elabtask
            • Vl-udpedge
            • Vl-delaycontrol
            • Vl-context
            • Vl-ctxelement
            • Vl-ctxelement->loc
            • Vl-modelement->loc
            • Statements
            • Vl-blockitem
            • Vl-vardecllist
            • Vl-interface->ifports
            • Vl-syntaxversion
            • Vl-nettypename-p
            • Vl-module->ifports
            • Vl-lifetime-p
            • Vl-paramdecllist
            • Vl-modelementlist->genelements
            • Vl-importlist
            • Vl-typedeflist
            • Vl-gatetype-p
            • Vl-cstrength-p
            • Vl-port->name
            • Vl-genelement->loc
            • Vl-delayoreventcontrol
            • Vl-udpentry-p
            • Vl-portdecllist
            • Vl-elabtask->loc
            • Property-expressions
            • Vl-taskdecllist
            • Vl-port->loc
            • Vl-fundecllist
            • Vl-sequencelist
            • Vl-propertylist
            • Vl-portlist
            • Vl-dpiimportlist
            • Vl-dpiexportlist
            • Vl-classlist
            • Vl-arguments->args
            • Vl-alwaystype-p
            • Vl-modinstlist
            • Vl-importpart-p
            • Vl-importpart-fix
            • Vl-bindlist
            • Vl-initiallist
            • Vl-genvarlist
            • Vl-gclkdecllist
            • Vl-function-specialization-map
            • Vl-finallist
            • Vl-elabtasklist
            • Vl-defaultdisablelist
            • Vl-clkdecllist
            • Vl-cassertionlist
            • Vl-blockstmt-p
            • Vl-assignlist
            • Vl-assertionlist
            • Vl-alwayslist
            • Vl-aliaslist
            • Vl-udptable
            • Vl-udplist
            • Vl-udpentrylist
            • Vl-propportlist
            • Vl-programlist
            • Vl-packagelist
            • Vl-namedarglist
            • Vl-modulelist
            • Vl-modportlist
            • Vl-modport-portlist
            • Vl-letdecllist
            • Vl-interfacelist
            • Vl-gateinstlist
            • Vl-fwdtypedeflist
            • Vl-covergrouplist
            • Vl-configlist
            • Vl-clkassignlist
            • Vl-blockitemlist
            • Vl-ansi-portdecllist
            • Vl-regularportlist
            • Vl-paramdecllist-list
            • Vl-modelementlist
            • Vl-interfaceportlist
            • Vl-casekey-p
            • Sv::maybe-4veclist
          • Loader
          • Warnings
          • Getting-started
          • Utilities
          • Printer
          • Kit
          • Mlib
          • Transforms
        • X86isa
        • Svl
        • Rtl
      • Software-verification
      • Math
      • Testing-utilities
    • Vl-commentmap-p

    Vl-adjust-minloc-for-comments

    Tweak starting location so that we get comments preceding the module keyword.

    Signature
    (vl-adjust-minloc-for-comments acc minloc descs) 
      → 
    adjusted-minloc
    Arguments
    acc — Initially line 0 of the file.
        Guard (vl-location-p acc).
    minloc — True minloc of the module we're considering.
        Guard (vl-location-p minloc).
    descs — All top-level descriptions found in the file.
        Guard (vl-descriptionlist-p descs).
    Returns
    adjusted-minloc — Type (vl-location-p adjusted-minloc), given the guard.

    It turns out that useful comments about a module (or other kind of top-level description) are often put before the module instead of within it. For instance:

    // Module: SuchAndSo
    // Author: John Q. Designer
    // Purpose: This module is responsible for blah blah blah.  It
    //          interfaces with units blah and blah, and implements ...
    // ...
    module SuchAndSo (...) ;
      ...
    endmodule

    This is especially common when modules are written in separate files, and the comments describing the module are found at the top. Unfortunately, our basic approach to comment gathering—associating all comments between module and endmodule—misses these comments.

    To correct for this, we no longer use the actual minloc for the module. Instead, we (almost) choose the largest maxloc of any other module such that other-maxloc < minloc. That sounds like gibberish but it makes sense if you just draw what portion of the file you want:

    module foo1 (...);
     ...
    endmodule
    
    module foo2 (...);
     ...
    endmodule              <-- largest maxloc less than minloc of bar
    
    // helpful comments about module bar, which we
    // want to make sure are associated with bar.
    module bar (...);
     ...
    endmodule

    Well, we don't quite use the maxloc of the previous module. Instead, we use maxloc+1. The reason for this is that sometimes people put in really stupid comments after end keywords, such as:

    module foo (...);
      ...
    endmodule // foo

    And we don't want to associate this // foo comment with the subsequent module.

    Definitions and Theorems

    Function: vl-adjust-minloc-for-comments

    (defun vl-adjust-minloc-for-comments (acc minloc descs)
      (declare (xargs :guard (and (vl-location-p acc)
                                  (vl-location-p minloc)
                                  (vl-descriptionlist-p descs))))
      (let ((__function__ 'vl-adjust-minloc-for-comments))
        (declare (ignorable __function__))
        (b* (((when (atom descs)) acc)
             (mod1.maxloc (vl-description->maxloc (car descs)))
             ((unless (and (equal (vl-location->filename acc)
                                  (vl-location->filename mod1.maxloc))
                           (< (vl-location->line mod1.maxloc)
                              (vl-location->line minloc))
                           (< (vl-location->line acc)
                              (vl-location->line mod1.maxloc))))
              (vl-adjust-minloc-for-comments acc minloc (cdr descs)))
             (acc (change-vl-location
                       acc
                       :line (min (+ 1 (vl-location->line mod1.maxloc))
                                  (vl-location->line minloc)))))
          (vl-adjust-minloc-for-comments acc minloc (cdr descs)))))

    Theorem: vl-location-p-of-vl-adjust-minloc-for-comments

    (defthm vl-location-p-of-vl-adjust-minloc-for-comments
      (implies
           (and (vl-location-p$inline acc)
                (vl-location-p$inline minloc)
                (vl-descriptionlist-p descs))
           (b* ((adjusted-minloc
                     (vl-adjust-minloc-for-comments acc minloc descs)))
             (vl-location-p adjusted-minloc)))
      :rule-classes :rewrite)

    Theorem: bound-of-vl-adjust-minloc-for-comments

    (defthm bound-of-vl-adjust-minloc-for-comments
     (implies (and (<= (vl-location->line acc)
                       (vl-location->line minloc))
                   (force (vl-location-p acc))
                   (force (vl-location-p minloc))
                   (force (vl-descriptionlist-p descs)))
              (<= (vl-location->line
                       (vl-adjust-minloc-for-comments acc minloc descs))
                  (vl-location->line minloc)))
     :rule-classes ((:rewrite) (:linear)))