]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/verilog-mode.el
Update copyright year to 2015
[gnu-emacs] / lisp / progmodes / verilog-mode.el
index b07e2ba5203e381ac5f07636d3d535f6ab3011e2..7b6f2d3a819af85973ee74891df28731db637f68 100644 (file)
@@ -1,6 +1,6 @@
 ;;; verilog-mode.el --- major mode for editing verilog source in Emacs
 
-;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
+;; Copyright (C) 1996-2015 Free Software Foundation, Inc.
 
 ;; Author: Michael McNamara <mac@verilog.com>
 ;;    Wilson Snyder <wsnyder@wsnyder.org>
 ;;; Code:
 
 ;; This variable will always hold the version number of the mode
-(defconst verilog-mode-version "2014-03-15-702457d-vpo"
+(defconst verilog-mode-version "2014-11-12-aa4b777-vpo"
   "Version of this Verilog mode.")
 (defconst verilog-mode-release-emacs t
   "If non-nil, this version of Verilog mode was released with Emacs itself.")
@@ -1020,6 +1020,20 @@ SystemVerilog designs."
   :type 'string)
 (put 'verilog-assignment-delay 'safe-local-variable 'stringp)
 
+(defcustom verilog-auto-arg-format 'packed
+  "Formatting to use for AUTOARG signal names.
+If 'packed', then as many inputs and outputs that fit within
+`fill-column' will be put onto one line.
+
+If 'single', then a single input or output will be put onto each
+line."
+  :version "25.1"
+  :type '(radio (const :tag "Line up Assignments and Declarations" packed)
+               (const :tag "Line up Assignment statements" single))
+  :group 'verilog-mode-auto)
+(put 'verilog-auto-arg-format 'safe-local-variable
+     '(lambda (x) (memq x '(packed single))))
+
 (defcustom verilog-auto-arg-sort nil
   "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
 Declaration order is advantageous with order based instantiations
@@ -1460,6 +1474,8 @@ If set will become buffer local.")
        :help           "Help on AUTOINPUT - adding inputs from cells"]
       ["AUTOINSERTLISP"                        (describe-function 'verilog-auto-insert-lisp)
        :help           "Help on AUTOINSERTLISP - insert text from a lisp function"]
+      ["AUTOINSERTLAST"                        (describe-function 'verilog-auto-insert-last)
+       :help           "Help on AUTOINSERTLISPLAST - insert text from a lisp function"]
       ["AUTOINST"                      (describe-function 'verilog-auto-inst)
        :help           "Help on AUTOINST - adding pins for cells"]
       ["AUTOINST (.*)"                 (describe-function 'verilog-auto-star)
@@ -2251,7 +2267,11 @@ find the errors."
          ;;  "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
 
 (defconst verilog-no-indent-begin-re
-  "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>")
+  (eval-when-compile
+    (verilog-regexp-words
+     '("always" "always_comb" "always_ff" "always_latch" "initial" "final" ;; procedural blocks
+       "if" "else"                                                         ;; conditional statements
+       "while" "for" "foreach" "repeat" "do" "forever" ))))                ;; loop statements
 
 (defconst verilog-ends-re
   ;; Parenthesis indicate type of keyword found
@@ -2309,6 +2329,7 @@ find the errors."
                "endinterface"
                "endpackage"
                "endsequence"
+               "endproperty"
                "endspecify"
                "endtable"
                "endtask"
@@ -2341,6 +2362,7 @@ find the errors."
           "\\(program\\)\\|"      ; 13
           "\\(sequence\\)\\|"     ; 14
          "\\(clocking\\)\\|"      ; 15
+         "\\(property\\)\\|"      ; 16
          "\\)\\>\\)"))
 (defconst verilog-end-block-re
   (eval-when-compile
@@ -2405,7 +2427,7 @@ find the errors."
    "\\(\\<package\\>\\)\\|"
    "\\(\\<final\\>\\)\\|"
    "\\(@\\)\\|"
-   "\\(\\<while\\>\\)\\|"
+   "\\(\\<while\\>\\)\\|\\(\\<do\\>\\)\\|"
    "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
    "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
    "#"))
@@ -2499,15 +2521,20 @@ find the errors."
        "join" "join_any" "join_none"
        "end"
        "endcase"
-       "endconfig"
+       "endchecker"
        "endclass"
        "endclocking"
+       "endconfig"
        "endfunction"
        "endgenerate"
+       "endgroup"
        "endmodule"
        "endprimitive"
        "endinterface"
        "endpackage"
+       "endprogram"
+       "endproperty"
+       "endsequence"
        "endspecify"
        "endtable"
        "endtask" )
@@ -2705,9 +2732,9 @@ find the errors."
 (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
 (defconst verilog-extended-case-re "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
 (defconst verilog-extended-complete-re
-  (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
+  (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
          "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
-         "\\|\\(\\(\\<import\\>\\s-+\\)?\\(\"DPI-C\"\\s-+\\)?\\(\\<pure\\>\\s-+\\)?\\(function\\>\\|task\\>\\)\\)"
+         "\\|\\(\\(\\<import\\>\\s-+\\)?\\(\"DPI-C\"\\s-+\\)?\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-+=\\s-+\\)?\\(function\\>\\|task\\>\\)\\)"
          "\\|" verilog-extended-case-re ))
 (defconst verilog-basic-complete-re
   (eval-when-compile
@@ -2737,10 +2764,45 @@ find the errors."
   "String used to mark end of excluded text.")
 (defconst verilog-preprocessor-re
   (eval-when-compile
-    (verilog-regexp-words
-     `(
-       "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else"
-       ))))
+    (concat
+     ;; single words
+     "\\(?:"
+     (verilog-regexp-words
+      `("`__FILE__"
+       "`__LINE__"
+       "`celldefine"
+       "`else"
+       "`end_keywords"
+       "`endcelldefine"
+       "`endif"
+       "`nounconnected_drive"
+       "`resetall"
+       "`unconnected_drive"
+       "`undefineall"))
+     "\\)\\|\\(?:"
+     ;; two words: i.e. `ifdef DEFINE
+     "\\<\\(`elsif\\|`ifn?def\\|`undef\\|`default_nettype\\|`begin_keywords\\)\\>\\s-"
+     "\\)\\|\\(?:"
+     ;; `line number "filename" level
+     "\\<\\(`line\\)\\>\\s-+[0-9]+\\s-+\"[^\"]+\"\\s-+[012]"
+     "\\)\\|\\(?:"
+     ;;`include "file" or `include <file>
+     "\\<\\(`include\\)\\>\\s-+\\(?:\"[^\"]+\"\\|<[^>]+>\\)"
+     "\\)\\|\\(?:"
+     ;; `pragma <stuff> (no mention in IEEE 1800-2012 that pragma can span multiple lines
+     "\\<\\(`pragma\\)\\>\\s-+.+$"
+     "\\)\\|\\(?:"
+     ;; `timescale time_unit / time_precision
+     "\\<\\(`timescale\\)\\>\\s-+10\\{0,2\\}\\s-*[munpf]?s\\s-*\\/\\s-*10\\{0,2\\}\\s-*[munpf]?s"
+     "\\)\\|\\(?:"
+     ;; `define and `if can span multiple lines if line ends in '\'. NOTE: `if is not IEEE 1800-2012
+     ;; from http://www.emacswiki.org/emacs/MultilineRegexp
+     (concat "\\<\\(`define\\|`if\\)\\>" ;; directive
+            "\\s-+" ;; separator
+            "\\(.*\\(?:\n.*\\)*?\\)" ;; definition: to tend of line, the maybe more lines (excludes any trailing \n)
+            "\\(?:\n\\s-*\n\\|\\'\\)") ;; blank line or EOF
+     "\\)"
+     )))
 
 (defconst verilog-keywords
   '( "`case" "`default" "`define" "`else" "`endfor" "`endif"
@@ -2907,7 +2969,7 @@ See also `verilog-font-lock-extra-types'.")
           '(
             "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
             "event" "genvar" "inout" "input" "integer" "localparam"
-            "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or"
+            "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" "notif1" "or"
             "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
             "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
             "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
@@ -3160,7 +3222,7 @@ and `verilog-scan'.")
   (setq verilog-scan-cache-tick nil))
 
 (defun verilog-scan-cache-ok-p ()
-  "Return t iff the scan cache is up to date."
+  "Return t if the scan cache is up to date."
   (or (and verilog-scan-cache-preserving
           (eq verilog-scan-cache-preserving (current-buffer))
           verilog-scan-cache-tick)
@@ -4107,9 +4169,7 @@ Uses `verilog-scan' cache."
     (while (and
            (> (marker-position e) (point))
            (verilog-re-search-forward
-            (concat
-             "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>"
-             "\\|\\(`endif\\)\\|\\(`else\\)")
+            verilog-auto-end-comment-lines-re
             nil 'move))
       (goto-char (match-beginning 0))
       (let ((indent-str (verilog-indent-line)))
@@ -4138,45 +4198,47 @@ Uses `verilog-scan' cache."
        ;; or the token before us unambiguously ends a statement,
        ;; then move back a token and test again.
        (not (or
-          ;; stop if beginning of buffer
-             (bolp)
-          ;; stop if we find a ;
+             ;; stop if beginning of buffer
+             (bobp)
+             ;; stop if we find a ;
              (= (preceding-char) ?\;)
-          ;; stop if we see a named coverpoint
+             ;; stop if we see a named coverpoint
              (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
-          ;; keep going if we are in the middle of a word
+             ;; keep going if we are in the middle of a word
              (not (or (looking-at "\\<") (forward-word -1)))
-          ;; stop if we see an assertion (perhaps labeled)
+             ;; stop if we see an assertion (perhaps labeled)
              (and
               (looking-at "\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
               (progn
-             (setq h (point))
-             (save-excursion
-               (verilog-backward-token)
-               (if (looking-at verilog-label-re)
-                   (setq h (point))))
-             (goto-char h)))
-          ;; stop if we see an extended complete reg, perhaps a complete one
+                (setq h (point))
+                (save-excursion
+                  (verilog-backward-token)
+                  (if (looking-at verilog-label-re)
+                      (setq h (point))))
+                (goto-char h)))
+             ;; stop if we see an extended complete reg, perhaps a complete one
              (and
-           (looking-at verilog-complete-reg)
-           (let* ((p (point)))
-             (while (and (looking-at verilog-extended-complete-re)
-                         (progn (setq p (point))
-                                (verilog-backward-token)
-                                (/= p (point)))))
-             (goto-char p)))
-          ;; stop if we see a complete reg (previous found extended ones)
+              (looking-at verilog-complete-reg)
+              (let* ((p (point)))
+                (while (and (looking-at verilog-extended-complete-re)
+                            (progn (setq p (point))
+                                   (verilog-backward-token)
+                                   (/= p (point)))))
+                (goto-char p)))
+             ;; stop if we see a complete reg (previous found extended ones)
              (looking-at verilog-basic-complete-re)
-          ;; stop if previous token is an ender
+             ;; stop if previous token is an ender
              (save-excursion
-            (verilog-backward-token)
-            (or
-             (looking-at verilog-end-block-re)
-             (looking-at verilog-preprocessor-re))))) ;; end of test
-    (verilog-backward-syntactic-ws)
-    (verilog-backward-token))
+               (verilog-backward-token)
+               (looking-at verilog-end-block-re))))
+      (verilog-backward-syntactic-ws)
+      (verilog-backward-token))
     ;; Now point is where the previous line ended.
-    (verilog-forward-syntactic-ws)))
+    (verilog-forward-syntactic-ws)
+    ;; Skip forward over any preprocessor directives, as they have wacky indentation
+    (if (looking-at verilog-preprocessor-re)
+       (progn (goto-char (match-end 0))
+              (verilog-forward-syntactic-ws)))))
 
 (defun verilog-beg-of-statement-1 ()
   "Move backward to beginning of statement."
@@ -4190,13 +4252,12 @@ Uses `verilog-scan' cache."
         (verilog-backward-syntactic-ws)
         (if (or (bolp)
                 (= (preceding-char) ?\;)
-               (save-excursion
+               (progn
                  (verilog-backward-token)
                  (looking-at verilog-ends-re)))
             (progn
               (goto-char pt)
-              (throw 'done t))
-          (verilog-backward-token))))
+              (throw 'done t)))))
     (verilog-forward-syntactic-ws)))
 ;
 ;    (while (and
@@ -4754,10 +4815,10 @@ primitive or interface named NAME."
                  (cond
                   ((match-end 5) ;; of verilog-end-block-ordered-re
                    (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
-                   (setq name-re "\\w+\\s-*("))
+                   (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
                   ((match-end 6) ;; of verilog-end-block-ordered-re
                    (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
-                   (setq name-re "\\w+\\s-*("))
+                   (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
                   ((match-end 7) ;; of verilog-end-block-ordered-re
                    (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
                   ((match-end 8) ;; of verilog-end-block-ordered-re
@@ -4776,6 +4837,8 @@ primitive or interface named NAME."
                    (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
                   ((match-end 15) ;; of verilog-end-block-ordered-re
                    (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
+                  ((match-end 16) ;; of verilog-end-block-ordered-re
+                   (setq reg "\\(\\<property\\>\\)\\|\\<endproperty\\>"))
 
                   (t (error "Problem in verilog-set-auto-endcomments")))
                  (let (b e)
@@ -5094,7 +5157,11 @@ FILENAME to find directory to run in, or defaults to `buffer-file-name`."
        (verilog-mode)
        ;; Without this force, it takes a few idle seconds
        ;; to get the color, which is very jarring
-       (when fontlocked (font-lock-fontify-buffer))))))
+        (unless (fboundp 'font-lock-ensure)
+          ;; We should use font-lock-ensure in preference to
+          ;; font-lock-fontify-buffer, but IIUC the problem this is supposed to
+          ;; solve only appears in Emacsen older than font-lock-ensure anyway.
+          (when fontlocked (font-lock-fontify-buffer)))))))
 \f
 
 ;;
@@ -5140,23 +5207,29 @@ Save the result unless optional NO-SAVE is t."
    ;; Make sure any sub-files we read get proper mode
    (setq-default major-mode 'verilog-mode)
    ;; Ditto files already read in
-   (mapc (lambda (buf)
-          (when (buffer-file-name buf)
-            (with-current-buffer buf
-              (verilog-mode))))
-        (buffer-list))
-   ;; Process the files
-   (mapcar (lambda (buf)
+   ;; Remember buffer list, so don't later pickup any verilog-getopt files
+   (let ((orig-buffer-list (buffer-list)))
+     (mapc (lambda (buf)
             (when (buffer-file-name buf)
-              (save-excursion
-                (if (not (file-exists-p (buffer-file-name buf)))
-                    (error
-                     (concat "File not found: " (buffer-file-name buf))))
-                (message (concat "Processing " (buffer-file-name buf)))
-                (set-buffer buf)
-                (funcall funref)
-                (unless no-save (save-buffer)))))
-          (buffer-list))))
+              (with-current-buffer buf
+                (verilog-mode)
+                (verilog-auto-reeval-locals)
+                (verilog-getopt-flags))))
+          orig-buffer-list)
+     ;; Process the files
+     (mapcar (lambda (buf)
+              (when (buffer-file-name buf)
+                (save-excursion
+                  (if (not (file-exists-p (buffer-file-name buf)))
+                      (error
+                       (concat "File not found: " (buffer-file-name buf))))
+                  (message (concat "Processing " (buffer-file-name buf)))
+                  (set-buffer buf)
+                  (funcall funref)
+                  (when (and (not no-save)
+                             (buffer-modified-p)) ;; Avoid "no changes to be saved"
+                    (save-buffer)))))
+            orig-buffer-list))))
 
 (defun verilog-batch-auto ()
   "For use with --batch, perform automatic expansions as a stand-alone tool.
@@ -5820,7 +5893,9 @@ Set point to where line starts."
    (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
     t
     (forward-word -1)
-    (while (= (preceding-char) ?\_)
+    (while (or (= (preceding-char) ?\_)
+               (= (preceding-char) ?\@)
+               (= (preceding-char) ?\.))
       (forward-word -1))
     (cond
      ((looking-at "\\<else\\>")
@@ -6074,14 +6149,18 @@ Return >0 for nested struct."
 (defun verilog-at-constraint-p ()
   "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
   (if (save-excursion
+       (let ((p (point)))
        (and
         (equal (char-after) ?\{)
         (forward-list)
         (progn (backward-char 1)
                (verilog-backward-ws&directives)
+         (and
                (or (equal (char-before) ?\{) ;; empty case
                     (equal (char-before) ?\;)
-                    (equal (char-before) ?\})))))
+                    (equal (char-before) ?\}))
+                    ;; skip what looks like bus repetition operator {#{
+                    (not (string-match "^{\\s-*[0-9]+\\s-*{" (buffer-substring p (point)))))))))
       (progn
         (let ( (pt (point)) (pass 0))
           (verilog-backward-ws&directives)
@@ -6400,6 +6479,9 @@ Only look at a few lines to determine indent level."
           (looking-at verilog-declaration-re))
       (verilog-indent-declaration ind))
 
+     (;-- form feeds - ignored as bug in indent-line-to in < 24.5
+      (looking-at "\f"))
+
      (;-- Everything else
       t
       (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
@@ -8234,7 +8316,8 @@ Return an array of [outputs inouts inputs wire reg assign const]."
                        (setq typedefed
                              (if typedefed (concat typedefed " " keywd) keywd)))
                       (t (setq vec nil  enum nil  rvalue nil  signed nil
-                               typedefed nil  multidim nil  sig-paren paren
+                               typedefed keywd  ; Have a type
+                               multidim nil  sig-paren paren
                                expect-signal 'sigs-var  modport nil))))
                ;; Interface with optional modport in v2k arglist?
                ;; Skip over parsing modport, and take the interface name as the type
@@ -8864,7 +8947,6 @@ IGNORE-NEXT is true to ignore next token, fake from inside case statement."
   (save-excursion
     (let* (;;(dbg "")
           sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
-      (search-forward ")")
       (verilog-read-always-signals-recurse nil nil nil)
       (setq sigs-out-i (append sigs-out-i sigs-out-unk)
            sigs-out-unk nil)
@@ -9635,7 +9717,7 @@ Return modi if successful, else print message unless IGNORE-ERROR is true."
                allow-cache
                (setq modi (gethash module verilog-modi-lookup-cache))
                (equal verilog-modi-lookup-last-current current)
-               ;; Iff hit is in current buffer, then tick must match
+               ;; If hit is in current buffer, then tick must match
                (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
                    (not (equal current (verilog-modi-file-or-buffer modi)))))
           ;;(message "verilog-modi-lookup: HIT %S" modi)
@@ -10613,7 +10695,7 @@ If FORCE, always reread it."
 ;;
 
 (defun verilog-auto-arg-ports (sigs message indent-pt)
-  "Print a list of ports for an AUTOINST.
+  "Print a list of ports for AUTOARG.
 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
   (when sigs
     (when verilog-auto-arg-sort
@@ -10625,13 +10707,20 @@ Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
     (let ((space ""))
       (indent-to indent-pt)
       (while sigs
-       (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
+       (cond ((equal verilog-auto-arg-format 'single)
+              (insert space)
+              (indent-to indent-pt)
+              (setq space "\n"))
+             ;; verilog-auto-arg-format 'packed
+             ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
               (insert "\n")
-              (indent-to indent-pt))
-             (t (insert space)))
+              (indent-to indent-pt)
+              (setq space " "))
+             (t
+              (insert space)
+              (setq space " ")))
        (insert (verilog-sig-name (car sigs)) ",")
-       (setq sigs (cdr sigs)
-             space " ")))))
+       (setq sigs (cdr sigs))))))
 
 (defun verilog-auto-arg ()
   "Expand AUTOARG statements.
@@ -10666,9 +10755,11 @@ Typing \\[verilog-auto] will make this into:
          output o;
        endmodule
 
-The argument declarations may be printed in declaration order to best suit
-order based instantiations, or alphabetically, based on the
-`verilog-auto-arg-sort' variable.
+The argument declarations may be printed in declaration order to
+best suit order based instantiations, or alphabetically, based on
+the `verilog-auto-arg-sort' variable.
+
+Formatting is controlled with `verilog-auto-arg-format' variable.
 
 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
 predeclared and are not redeclared by AUTOARG.  AUTOARG will make a
@@ -11692,6 +11783,9 @@ Limitations:
 
   Typedefs must match `verilog-typedef-regexp', which is disabled by default.
 
+  Types are added to declarations if an AUTOLOGIC or
+  `verilog-auto-wire-type' is set to logic.
+
   Signals matching `verilog-auto-output-ignore-regexp' are not included.
 
 An example (see `verilog-auto-inst' for what else is going on here):
@@ -11784,10 +11878,18 @@ Typing \\[verilog-auto] will make this into:
           wire tempa = i;
           wire tempb = tempa;
           wire o = tempb;
-       endmodule"
+       endmodule
+
+You may also provide an optional regular expression, in which case only
+signals matching the regular expression will be included.  For example the
+same expansion will result from only extracting outputs starting with ov:
+
+          /*AUTOOUTPUTEVERY(\"^ov\")*/"
   (save-excursion
     ;;Point must be at insertion point
     (let* ((indent-pt (current-indentation))
+          (params (verilog-read-auto-params 0 1))
+          (regexp (nth 0 params))
           (v2k  (verilog-in-paren-quick))
           (modi (verilog-modi-current))
           (moddecls (verilog-modi-get-decls modi))
@@ -11795,6 +11897,11 @@ Typing \\[verilog-auto] will make this into:
                      (verilog-signals-not-in
                       (verilog-decls-get-signals moddecls)
                       (verilog-decls-get-ports moddecls)))))
+      (when regexp
+       (setq sig-list (verilog-signals-matching-regexp
+                       sig-list regexp)))
+      (setq sig-list (verilog-signals-not-matching-regexp
+                     sig-list verilog-auto-output-ignore-regexp))
       (verilog-forward-or-insert-line)
       (when v2k (verilog-repair-open-comma))
       (when sig-list
@@ -11820,6 +11927,9 @@ Limitations:
 
   Typedefs must match `verilog-typedef-regexp', which is disabled by default.
 
+  Types are added to declarations if an AUTOLOGIC or
+  `verilog-auto-wire-type' is set to logic.
+
   Signals matching `verilog-auto-input-ignore-regexp' are not included.
 
 An example (see `verilog-auto-inst' for what else is going on here):
@@ -11900,6 +12010,9 @@ Limitations:
 
   Typedefs must match `verilog-typedef-regexp', which is disabled by default.
 
+  Types are added to declarations if an AUTOLOGIC or
+  `verilog-auto-wire-type' is set to logic.
+
   Signals matching `verilog-auto-inout-ignore-regexp' are not included.
 
 An example (see `verilog-auto-inst' for what else is going on here):
@@ -12016,13 +12129,14 @@ same expansion will result from only extracting signals starting with i:
 
           /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
 
-You may also provide an optional second regular expression, in
-which case only signals which have that pin direction and data
-type will be included.  This matches against everything before
-the signal name in the declaration, for example against
-\"input\" (single bit), \"output logic\" (direction and type) or
-\"output [1:0]\" (direction and implicit type).  You also
-probably want to skip spaces in your regexp.
+You may also provide an optional third argument regular
+expression, in which case only signals which have that pin
+direction and data type matching that regular expression will be
+included.  This matches against everything before the signal name
+in the declaration, for example against \"input\" (single bit),
+\"output logic\" (direction and type) or \"output
+[1:0]\" (direction and implicit type).  You also probably want to
+skip spaces in your regexp.
 
 For example, the below will result in matching the output \"o\"
 against the previous example's module:
@@ -12141,7 +12255,21 @@ You may also provide an optional regular expression, in which case only
 signals matching the regular expression will be included.  For example the
 same expansion will result from only extracting signals starting with i:
 
-          /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
+          /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/
+
+You may also provide an optional third argument regular
+expression, in which case only signals which have that pin
+direction and data type matching that regular expression will be
+included.  This matches against everything before the signal name
+in the declaration, for example against \"input\" (single bit),
+\"output logic\" (direction and type) or \"output
+[1:0]\" (direction and implicit type).  You also probably want to
+skip spaces in your regexp.
+
+For example, the below will result in matching the output \"o\"
+against the previous example's module:
+
+          /*AUTOINOUTCOMP(\"ExampMain\",\"\",\"^output.*\")*/"
   (verilog-auto-inout-module t nil))
 
 (defun verilog-auto-inout-in ()
@@ -12192,7 +12320,7 @@ You may also provide an optional regular expression, in which case only
 signals matching the regular expression will be included.  For example the
 same expansion will result from only extracting signals starting with i:
 
-          /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
+          /*AUTOINOUTIN(\"ExampMain\",\"^i\")*/"
   (verilog-auto-inout-module nil t))
 
 (defun verilog-auto-inout-param ()
@@ -12385,9 +12513,13 @@ driver/monitor using AUTOINST in the testbench."
 
 (defun verilog-auto-insert-lisp ()
   "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
-The Lisp code provided is called, and the Lisp code calls
-`insert` to insert text into the current file beginning on the
-line after the AUTOINSERTLISP.
+The Lisp code provided is called before other AUTOS are expanded,
+and the Lisp code generally will call `insert` to insert text
+into the current file beginning on the line after the
+AUTOINSERTLISP.
+
+See also AUTOINSERTLAST and `verilog-auto-insert-last' which
+executes after (as opposed to before) other AUTOs.
 
 See also AUTO_LISP, which takes a Lisp expression and evaluates
 it during `verilog-auto-inst' but does not insert any text.
@@ -12444,9 +12576,25 @@ text:
       (setq verilog-scan-cache-tick nil) ;; Clear cache; inserted unknown text
       (verilog-delete-empty-auto-pair))))
 
+(defun verilog-auto-insert-last ()
+  "Expand AUTOINSERTLAST statements, as part of \\[verilog-auto].
+The Lisp code provided is called after all other AUTOS have been
+expanded, and the Lisp code generally will call `insert` to
+insert text into the current file beginning on the line after the
+AUTOINSERTLAST.
+
+Other than when called (after AUTOs are expanded), the functionality
+is otherwise identical to AUTOINSERTLISP and `verilog-auto-insert-lisp' which
+executes before (as opposed to after) other AUTOs.
+
+See `verilog-auto-insert-lisp' for examples."
+  (verilog-auto-insert-lisp))
+
 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
   "Return list of signals for current AUTOSENSE block."
-  (let* ((sigss (verilog-read-always-signals))
+  (let* ((sigss (save-excursion
+                 (search-forward ")")
+                 (verilog-read-always-signals)))
         (sig-list (verilog-signals-not-params
                    (verilog-signals-not-in (verilog-alw-get-inputs sigss)
                                            (append (and (not verilog-auto-sense-include-inputs)
@@ -12636,11 +12784,12 @@ Typing \\[verilog-auto] will make this into:
                           (save-excursion
                             (verilog-read-signals
                              (save-excursion
-                               (verilog-re-search-backward-quick "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t)
+                               (verilog-re-search-backward-quick
+                                "\\(@\\|\\<\\(begin\\|if\\|case\\|always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
                                (point))
                              (point)))))
       (save-excursion
-       (verilog-re-search-backward-quick "@" nil t)
+       (verilog-re-search-backward-quick "\\(@\\|\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
         (setq sigss (verilog-read-always-signals)))
       (setq dly-list (verilog-alw-get-outputs-delayed sigss))
       (setq sig-list (verilog-signals-not-in (append
@@ -13170,6 +13319,7 @@ Using \\[describe-function], see also:
     `verilog-auto-inout-param'  for AUTOINOUTPARAM copying params from elsewhere
     `verilog-auto-input'        for AUTOINPUT making hierarchy inputs
     `verilog-auto-insert-lisp'  for AUTOINSERTLISP insert code from lisp function
+    `verilog-auto-insert-last'  for AUTOINSERTLAST insert code from lisp function
     `verilog-auto-inst'         for AUTOINST instantiation pins
     `verilog-auto-star'         for AUTOINST .* SystemVerilog pins
     `verilog-auto-inst-param'   for AUTOINSTPARAM instantiation params
@@ -13246,7 +13396,6 @@ Wilson Snyder (wsnyder@wsnyder.org)."
                 (verilog-inject-arg))
               ;;
               ;; Do user inserts first, so their code can insert AUTOs
-              ;; We may provide an AUTOINSERTLISPLAST if another cleanup pass is needed
               (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
                                          'verilog-auto-insert-lisp)
               ;; Expand instances before need the signals the instances input/output
@@ -13280,11 +13429,13 @@ Wilson Snyder (wsnyder@wsnyder.org)."
               (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
               (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
               ;; outputevery needs AUTOOUTPUTs done first
-              (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\*/" 'verilog-auto-output-every)
+              (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\((.*?)\\)?\\*/" 'verilog-auto-output-every)
               ;; After we've created all new variables
               (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
               ;; Must be after all inputs outputs are generated
               (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
+              ;; User inserts
+              (verilog-auto-re-search-do "/\\*AUTOINSERTLAST(.*?)\\*/" 'verilog-auto-insert-last)
               ;; Fix line numbers (comments only)
               (when verilog-auto-inst-template-numbers
                 (verilog-auto-templated-rel))
@@ -13453,7 +13604,7 @@ See also `verilog-header' for an alternative format."
   > "`ovm_object_utils_begin(" name ")" \n
   > (- verilog-indent-level) " `ovm_object_utils_end" \n
   > _ \n
-  > "function new(name=\"" name "\");" \n
+  > "function new(string name=\"" name "\");" \n
   > "super.new(name);" \n
   > (- verilog-indent-level) "endfunction" \n
   > _ \n
@@ -13467,7 +13618,7 @@ See also `verilog-header' for an alternative format."
   > "`uvm_object_utils_begin(" name ")" \n
   > (- verilog-indent-level) "`uvm_object_utils_end" \n
   > _ \n
-  > "function new(name=\"" name "\");" \n
+  > "function new(string name=\"" name "\");" \n
   > "super.new(name);" \n
   > (- verilog-indent-level) "endfunction" \n
   > _ \n
@@ -13481,7 +13632,7 @@ See also `verilog-header' for an alternative format."
   > "`uvm_component_utils_begin(" name ")" \n
   > (- verilog-indent-level) "`uvm_component_utils_end" \n
   > _ \n
-  > "function new(name=\"\", uvm_component parent);" \n
+  > "function new(string name=\"\", uvm_component parent);" \n
   > "super.new(name, parent);" \n
   > (- verilog-indent-level) "endfunction" \n
   > _ \n