aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/progmodes/verilog-mode.el181
1 files changed, 105 insertions, 76 deletions
diff --git a/lisp/progmodes/verilog-mode.el b/lisp/progmodes/verilog-mode.el
index cc601601193..87f901ae113 100644
--- a/lisp/progmodes/verilog-mode.el
+++ b/lisp/progmodes/verilog-mode.el
@@ -9,7 +9,7 @@
9;; Keywords: languages 9;; Keywords: languages
10;; The "Version" is the date followed by the decimal rendition of the Git 10;; The "Version" is the date followed by the decimal rendition of the Git
11;; commit hex. 11;; commit hex.
12;; Version: 2019.12.17.268053413 12;; Version: 2020.02.23.232634261
13 13
14;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this 14;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
15;; file on 19/3/2008, and the maintainer agreed that when a bug is 15;; file on 19/3/2008, and the maintainer agreed that when a bug is
@@ -124,7 +124,7 @@
124;; 124;;
125 125
126;; This variable will always hold the version number of the mode 126;; This variable will always hold the version number of the mode
127(defconst verilog-mode-version "2019-12-17-ffa2ba5-vpo-GNU" 127(defconst verilog-mode-version "2020-02-23-dddb795-vpo-GNU"
128 "Version of this Verilog mode.") 128 "Version of this Verilog mode.")
129(defconst verilog-mode-release-emacs t 129(defconst verilog-mode-release-emacs t
130 "If non-nil, this version of Verilog mode was released with Emacs itself.") 130 "If non-nil, this version of Verilog mode was released with Emacs itself.")
@@ -1282,6 +1282,18 @@ won't merge conflict."
1282(put 'verilog-auto-inst-template-numbers 'safe-local-variable 1282(put 'verilog-auto-inst-template-numbers 'safe-local-variable
1283 '(lambda (x) (memq x '(nil t lhs)))) 1283 '(lambda (x) (memq x '(nil t lhs))))
1284 1284
1285(defcustom verilog-auto-inst-template-required nil
1286 "If non-nil, when creating a port with AUTOINST, require a template.
1287Any port which does not have a template will be ommitted from the
1288instantiation.
1289
1290If nil, if a port is not templated it will be inserted to connect
1291to a net with the same name as the port."
1292 :version "28.0"
1293 :group 'verilog-mode-auto
1294 :type 'boolean)
1295(put 'verilog-auto-inst-template-required 'safe-local-variable 'verilog-booleanp)
1296
1285(defcustom verilog-auto-inst-column 40 1297(defcustom verilog-auto-inst-column 40
1286 "Indent-to column number for net name part of AUTOINST created pin." 1298 "Indent-to column number for net name part of AUTOINST created pin."
1287 :group 'verilog-mode-indent 1299 :group 'verilog-mode-indent
@@ -3117,7 +3129,7 @@ See also `verilog-font-lock-extra-types'.")
3117 (:foreground "DimGray" :italic t)) 3129 (:foreground "DimGray" :italic t))
3118 (((class grayscale) (background dark)) 3130 (((class grayscale) (background dark))
3119 (:foreground "LightGray" :italic t)) 3131 (:foreground "LightGray" :italic t))
3120 (t (:italis t))) 3132 (t (:italic t)))
3121 "Font lock mode face used to background highlight translate-off regions." 3133 "Font lock mode face used to background highlight translate-off regions."
3122 :group 'font-lock-highlighting-faces) 3134 :group 'font-lock-highlighting-faces)
3123 3135
@@ -4571,9 +4583,11 @@ More specifically, point @ in the line foo : @ begin"
4571 nil))) 4583 nil)))
4572 4584
4573(defun verilog-backward-up-list (arg) 4585(defun verilog-backward-up-list (arg)
4574 "Call `backward-up-list' ARG, ignoring comments." 4586 "Call `backward-up-list' ARG, ignoring comments and errors."
4575 (let ((parse-sexp-ignore-comments t)) 4587 (let ((parse-sexp-ignore-comments t))
4576 (backward-up-list arg))) 4588 (condition-case nil
4589 (backward-up-list arg) ;; May throw Unbalanced parenthesis
4590 (error nil))))
4577 4591
4578(defun verilog-forward-sexp-cmt (arg) 4592(defun verilog-forward-sexp-cmt (arg)
4579 "Call `forward-sexp' ARG, inside comments." 4593 "Call `forward-sexp' ARG, inside comments."
@@ -11370,9 +11384,10 @@ See the example in `verilog-auto-inout-modport'."
11370(defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning 11384(defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
11371(defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning 11385(defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
11372 11386
11373(defun verilog-auto-inst-port (port-st indent-pt moddecls tpl-list tpl-num for-star par-values) 11387(defun verilog-auto-inst-port (section port-st indent-pt moddecls tpl-list tpl-num
11388 for-star par-values)
11374 "Print out an instantiation connection for this PORT-ST. 11389 "Print out an instantiation connection for this PORT-ST.
11375Insert to INDENT-PT, use template TPL-LIST. 11390Inside SECTION, insert to INDENT-PT, use template TPL-LIST.
11376@ are instantiation numbers, replaced with TPL-NUM. 11391@ are instantiation numbers, replaced with TPL-NUM.
11377@\"(expression @)\" are evaluated, with @ as a variable. 11392@\"(expression @)\" are evaluated, with @ as a variable.
11378If FOR-STAR add comment it is a .* expansion. 11393If FOR-STAR add comment it is a .* expansion.
@@ -11474,60 +11489,74 @@ If PAR-VALUES replace final strings with these parameter values."
11474 (setq tpl-net (verilog-string-replace-matches "\\[\\]\\[\\]" dflt-bits nil nil tpl-net)) 11489 (setq tpl-net (verilog-string-replace-matches "\\[\\]\\[\\]" dflt-bits nil nil tpl-net))
11475 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net))) 11490 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
11476 ;; Insert it 11491 ;; Insert it
11477 (indent-to indent-pt) 11492 (when (or tpl-ass (not verilog-auto-inst-template-required))
11478 (insert "." port) 11493 (verilog-auto-inst-first section)
11479 (unless (and verilog-auto-inst-dot-name 11494 (indent-to indent-pt)
11480 (equal port tpl-net)) 11495 (insert "." port)
11481 (indent-to verilog-auto-inst-column) 11496 (unless (and verilog-auto-inst-dot-name
11482 (insert "(" tpl-net ")")) 11497 (equal port tpl-net))
11483 (insert ",") 11498 (indent-to verilog-auto-inst-column)
11484 (cond (tpl-ass 11499 (insert "(" tpl-net ")"))
11485 (verilog-read-auto-template-hit tpl-ass) 11500 (insert ",")
11486 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) 11501 (cond (tpl-ass
11487 verilog-auto-inst-column)) 11502 (verilog-read-auto-template-hit tpl-ass)
11488 ;; verilog-insert requires the complete comment in one call - including the newline 11503 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
11489 (cond ((equal verilog-auto-inst-template-numbers 'lhs) 11504 verilog-auto-inst-column))
11490 (verilog-insert " // Templated" 11505 ;; verilog-insert requires the complete comment in one call - including the newline
11491 " LHS: " (nth 0 tpl-ass) 11506 (cond ((equal verilog-auto-inst-template-numbers 'lhs)
11492 "\n")) 11507 (verilog-insert " // Templated"
11493 (verilog-auto-inst-template-numbers 11508 " LHS: " (nth 0 tpl-ass)
11494 (verilog-insert " // Templated" 11509 "\n"))
11495 " T" (int-to-string (nth 2 tpl-ass)) 11510 (verilog-auto-inst-template-numbers
11496 " L" (int-to-string (nth 3 tpl-ass)) 11511 (verilog-insert " // Templated"
11497 "\n")) 11512 " T" (int-to-string (nth 2 tpl-ass))
11498 (t 11513 " L" (int-to-string (nth 3 tpl-ass))
11499 (verilog-insert " // Templated\n")))) 11514 "\n"))
11500 (for-star 11515 (t
11501 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) 11516 (verilog-insert " // Templated\n"))))
11502 verilog-auto-inst-column)) 11517 (for-star
11503 (verilog-insert " // Implicit .*\n")) 11518 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
11504 (t 11519 verilog-auto-inst-column))
11505 (insert "\n"))))) 11520 (verilog-insert " // Implicit .*\n"))
11506;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3") 11521 (t
11522 (insert "\n"))))))
11523;;(verilog-auto-inst-port "" (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
11507;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]") 11524;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
11508;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));") 11525;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
11509 11526
11510(defun verilog-auto-inst-port-list (sig-list indent-pt moddecls tpl-list tpl-num for-star par-values) 11527(defvar verilog-auto-inst-first-section nil
11511 "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'." 11528 "Local first-in-section for `verilog-auto-inst-first'.")
11512 (when verilog-auto-inst-sort 11529(defvar verilog-auto-inst-first-any nil
11513 (setq sig-list (sort (copy-alist sig-list) #'verilog-signals-sort-compare))) 11530 "Local first-in-any-section for `verilog-auto-inst-first'.")
11514 (mapc (lambda (port)
11515 (verilog-auto-inst-port port indent-pt moddecls
11516 tpl-list tpl-num for-star par-values))
11517 sig-list))
11518 11531
11519(defun verilog-auto-inst-first () 11532(defun verilog-auto-inst-first (section)
11520 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]." 11533 "Insert , and SECTION before port, as part of \\[verilog-auto-inst]."
11521 ;; Do we need a trailing comma? 11534 ;; Do we need a trailing comma?
11522 ;; There maybe an ifdef or something similar before us. What a mess. Thus 11535 ;; There maybe an ifdef or something similar before us. What a mess. Thus
11523 ;; to avoid trouble we only insert on preceding ) or *. 11536 ;; to avoid trouble we only insert on preceding ) or *.
11524 ;; Insert first port on new line 11537 ;; Insert first port on new line
11525 (insert "\n") ; Must insert before search, so point will move forward if insert comma 11538 (when verilog-auto-inst-first-any
11526 (save-excursion 11539 (setq verilog-auto-inst-first-any nil)
11527 (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil) 11540 (insert "\n") ; Must insert before search, so point will move forward if insert comma
11528 (when (looking-at ")\\|\\*") ; Generally don't insert, unless we are fairly sure 11541 (save-excursion
11529 (forward-char 1) 11542 (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
11530 (insert ",")))) 11543 (when (looking-at ")\\|\\*") ; Generally don't insert, unless we are fairly sure
11544 (forward-char 1)
11545 (insert ","))))
11546 (when verilog-auto-inst-first-section
11547 (setq verilog-auto-inst-first-section nil)
11548 (verilog-insert-indent section)))
11549
11550(defun verilog-auto-inst-port-list (section sig-list indent-pt moddecls
11551 tpl-list tpl-num for-star par-values)
11552 "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
11553 (when verilog-auto-inst-sort
11554 (setq sig-list (sort (copy-alist sig-list) #'verilog-signals-sort-compare)))
11555 (let ((verilog-auto-inst-first-section t))
11556 (mapc (lambda (port)
11557 (verilog-auto-inst-port section port indent-pt moddecls
11558 tpl-list tpl-num for-star par-values))
11559 sig-list)))
11531 11560
11532(defun verilog-auto-star () 11561(defun verilog-auto-star ()
11533 "Expand SystemVerilog .* pins, as part of \\[verilog-auto]. 11562 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
@@ -11697,6 +11726,10 @@ Templates:
11697 debugging is completed though, it will result in lots of extra differences 11726 debugging is completed though, it will result in lots of extra differences
11698 and merge conflicts. 11727 and merge conflicts.
11699 11728
11729 If a connection name does not match any template, it is
11730 connected to a net by the same name as the port (unless
11731 `verilog-auto-inst-template-required' is true).
11732
11700 Setting `verilog-auto-template-warn-unused' will report errors 11733 Setting `verilog-auto-template-warn-unused' will report errors
11701 if any template lines are unused. 11734 if any template lines are unused.
11702 11735
@@ -11874,10 +11907,11 @@ For more information see the \\[verilog-faq] and forums at URL
11874 (1+ (current-column)))) 11907 (1+ (current-column))))
11875 (verilog-auto-inst-column (max verilog-auto-inst-column 11908 (verilog-auto-inst-column (max verilog-auto-inst-column
11876 (+ 16 (* 8 (/ (+ indent-pt 7) 8))))) 11909 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11910 (verilog-auto-inst-first-any t)
11877 (modi (verilog-modi-current)) 11911 (modi (verilog-modi-current))
11878 (moddecls (verilog-modi-get-decls modi)) 11912 (moddecls (verilog-modi-get-decls modi))
11879 submod submodi submoddecls 11913 submod submodi submoddecls
11880 inst skip-pins tpl-list tpl-num did-first par-values) 11914 inst skip-pins tpl-list tpl-num par-values)
11881 11915
11882 ;; Find module name that is instantiated 11916 ;; Find module name that is instantiated
11883 (setq submod (verilog-read-inst-module) 11917 (setq submod (verilog-read-inst-module)
@@ -11914,51 +11948,46 @@ For more information see the \\[verilog-faq] and forums at URL
11914 (vl-dir "interfaced")) 11948 (vl-dir "interfaced"))
11915 (when (and sig-list 11949 (when (and sig-list
11916 verilog-auto-inst-interfaced-ports) 11950 verilog-auto-inst-interfaced-ports)
11917 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11918 ;; Note these are searched for in verilog-read-sub-decls. 11951 ;; Note these are searched for in verilog-read-sub-decls.
11919 (verilog-insert-indent "// Interfaced\n") 11952 (verilog-auto-inst-port-list "// Interfaced\n"
11920 (verilog-auto-inst-port-list sig-list indent-pt moddecls 11953 sig-list indent-pt moddecls
11921 tpl-list tpl-num for-star par-values))) 11954 tpl-list tpl-num for-star par-values)))
11922 (let ((sig-list (verilog-signals-not-in 11955 (let ((sig-list (verilog-signals-not-in
11923 (verilog-decls-get-interfaces submoddecls) 11956 (verilog-decls-get-interfaces submoddecls)
11924 skip-pins)) 11957 skip-pins))
11925 (vl-dir "interface")) 11958 (vl-dir "interface"))
11926 (when sig-list 11959 (when sig-list
11927 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11928 ;; Note these are searched for in verilog-read-sub-decls. 11960 ;; Note these are searched for in verilog-read-sub-decls.
11929 (verilog-insert-indent "// Interfaces\n") 11961 (verilog-auto-inst-port-list "// Interfaces\n"
11930 (verilog-auto-inst-port-list sig-list indent-pt moddecls 11962 sig-list indent-pt moddecls
11931 tpl-list tpl-num for-star par-values))) 11963 tpl-list tpl-num for-star par-values)))
11932 (let ((sig-list (verilog-signals-not-in 11964 (let ((sig-list (verilog-signals-not-in
11933 (verilog-decls-get-outputs submoddecls) 11965 (verilog-decls-get-outputs submoddecls)
11934 skip-pins)) 11966 skip-pins))
11935 (vl-dir "output")) 11967 (vl-dir "output"))
11936 (when sig-list 11968 (when sig-list
11937 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 11969 (verilog-auto-inst-port-list "// Outputs\n"
11938 (verilog-insert-indent "// Outputs\n") 11970 sig-list indent-pt moddecls
11939 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11940 tpl-list tpl-num for-star par-values))) 11971 tpl-list tpl-num for-star par-values)))
11941 (let ((sig-list (verilog-signals-not-in 11972 (let ((sig-list (verilog-signals-not-in
11942 (verilog-decls-get-inouts submoddecls) 11973 (verilog-decls-get-inouts submoddecls)
11943 skip-pins)) 11974 skip-pins))
11944 (vl-dir "inout")) 11975 (vl-dir "inout"))
11945 (when sig-list 11976 (when sig-list
11946 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 11977 (verilog-auto-inst-port-list "// Inouts\n"
11947 (verilog-insert-indent "// Inouts\n") 11978 sig-list indent-pt moddecls
11948 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11949 tpl-list tpl-num for-star par-values))) 11979 tpl-list tpl-num for-star par-values)))
11950 (let ((sig-list (verilog-signals-not-in 11980 (let ((sig-list (verilog-signals-not-in
11951 (verilog-decls-get-inputs submoddecls) 11981 (verilog-decls-get-inputs submoddecls)
11952 skip-pins)) 11982 skip-pins))
11953 (vl-dir "input")) 11983 (vl-dir "input"))
11954 (when sig-list 11984 (when sig-list
11955 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 11985 (verilog-auto-inst-port-list "// Inputs\n"
11956 (verilog-insert-indent "// Inputs\n") 11986 sig-list indent-pt moddecls
11957 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11958 tpl-list tpl-num for-star par-values))) 11987 tpl-list tpl-num for-star par-values)))
11959 ;; Kill extra semi 11988 ;; Kill extra semi
11960 (save-excursion 11989 (save-excursion
11961 (cond (did-first 11990 (cond ((not verilog-auto-inst-first-any)
11962 (re-search-backward "," pt t) 11991 (re-search-backward "," pt t)
11963 (delete-char 1) 11992 (delete-char 1)
11964 (insert ");") 11993 (insert ");")
@@ -12020,10 +12049,11 @@ Templates:
12020 (1+ (current-column)))) 12049 (1+ (current-column))))
12021 (verilog-auto-inst-column (max verilog-auto-inst-column 12050 (verilog-auto-inst-column (max verilog-auto-inst-column
12022 (+ 16 (* 8 (/ (+ indent-pt 7) 8))))) 12051 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
12052 (verilog-auto-inst-first-any t)
12023 (modi (verilog-modi-current)) 12053 (modi (verilog-modi-current))
12024 (moddecls (verilog-modi-get-decls modi)) 12054 (moddecls (verilog-modi-get-decls modi))
12025 submod submodi submoddecls 12055 submod submodi submoddecls
12026 inst skip-pins tpl-list tpl-num did-first) 12056 inst skip-pins tpl-list tpl-num)
12027 ;; Find module name that is instantiated 12057 ;; Find module name that is instantiated
12028 (setq submod (save-excursion 12058 (setq submod (save-excursion
12029 ;; Get to the point where AUTOINST normally is to read the module 12059 ;; Get to the point where AUTOINST normally is to read the module
@@ -12060,14 +12090,13 @@ Templates:
12060 (when regexp 12090 (when regexp
12061 (setq sig-list (verilog-signals-matching-regexp sig-list regexp))) 12091 (setq sig-list (verilog-signals-matching-regexp sig-list regexp)))
12062 (when sig-list 12092 (when sig-list
12063 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
12064 ;; Note these are searched for in verilog-read-sub-decls. 12093 ;; Note these are searched for in verilog-read-sub-decls.
12065 (verilog-insert-indent "// Parameters\n") 12094 (verilog-auto-inst-port-list "// Parameters\n"
12066 (verilog-auto-inst-port-list sig-list indent-pt moddecls 12095 sig-list indent-pt moddecls
12067 tpl-list tpl-num nil nil))) 12096 tpl-list tpl-num nil nil)))
12068 ;; Kill extra semi 12097 ;; Kill extra semi
12069 (save-excursion 12098 (save-excursion
12070 (cond (did-first 12099 (cond ((not verilog-auto-inst-first-any)
12071 (re-search-backward "," pt t) 12100 (re-search-backward "," pt t)
12072 (delete-char 1) 12101 (delete-char 1)
12073 (insert ")") 12102 (insert ")")