1 ;;; verilog-mode.el --- major mode for editing verilog source in Emacs
3 ;; Copyright (C) 1996-2017 Free Software Foundation, Inc.
5 ;; Author: Michael McNamara <mac@verilog.com>
6 ;; Wilson Snyder <wsnyder@wsnyder.org>
7 ;; X-URL: http://www.verilog.com
8 ;; X-URL: http://www.veripool.org
10 ;; Keywords: languages
12 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
13 ;; file on 19/3/2008, and the maintainer agreed that when a bug is
14 ;; filed in the Emacs bug reporting system against this file, a copy
15 ;; of the bug report be sent to the maintainer's email address.
17 ;; This code supports Emacs 21.1 and later
18 ;; And XEmacs 21.1 and later
19 ;; Please do not make changes that break Emacs 21. Thanks!
23 ;; This file is part of GNU Emacs.
25 ;; GNU Emacs is free software: you can redistribute it and/or modify
26 ;; it under the terms of the GNU General Public License as published by
27 ;; the Free Software Foundation, either version 3 of the License, or
28 ;; (at your option) any later version.
30 ;; GNU Emacs is distributed in the hope that it will be useful,
31 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
32 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 ;; GNU General Public License for more details.
35 ;; You should have received a copy of the GNU General Public License
36 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
43 ;; A major mode for editing Verilog and SystemVerilog HDL source code (IEEE
44 ;; 1364-2005 and IEEE 1800-2012 standards). When you have entered Verilog
45 ;; mode, you may get more info by pressing C-h m. You may also get online
46 ;; help describing various functions by: C-h f <Name of function you want
49 ;; KNOWN BUGS / BUG REPORTS
50 ;; =======================
52 ;; SystemVerilog is a rapidly evolving language, and hence this mode is
53 ;; under continuous development. Please report any issues to the issue
56 ;; http://www.veripool.org/verilog-mode
58 ;; Please use verilog-submit-bug-report to submit a report; type C-c
59 ;; C-b to invoke this and as a result we will have a much easier time
60 ;; of reproducing the bug you find, and hence fixing it.
62 ;; INSTALLING THE MODE
63 ;; ===================
65 ;; An older version of this mode may be already installed as a part of
66 ;; your environment, and one method of updating would be to update
67 ;; your Emacs environment. Sometimes this is difficult for local
68 ;; political/control reasons, and hence you can always install a
69 ;; private copy (or even a shared copy) which overrides the system
72 ;; You can get step by step help in installing this file by going to
73 ;; <http://www.verilog.com/emacs_install.html>
75 ;; The short list of installation instructions are: To set up
76 ;; automatic Verilog mode, put this file in your load path, and put
77 ;; the following in code (please un comment it first!) in your
78 ;; .emacs, or in your site's site-load.el
80 ;; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
81 ;; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
83 ;; Be sure to examine at the help for verilog-auto, and the other
84 ;; verilog-auto-* functions for some major coding time savers.
86 ;; If you want to customize Verilog mode to fit your needs better,
87 ;; you may add the below lines (the values of the variables presented
88 ;; here are the defaults). Note also that if you use an Emacs that
89 ;; supports custom, it's probably better to use the custom menu to
90 ;; edit these. If working as a member of a large team these settings
91 ;; should be common across all users (in a site-start file), or set
92 ;; in Local Variables in every file. Otherwise, different people's
93 ;; AUTO expansion may result different whitespace changes.
95 ;; ;; Enable syntax highlighting of **all** languages
96 ;; (global-font-lock-mode t)
98 ;; ;; User customization for Verilog mode
99 ;; (setq verilog-indent-level 3
100 ;; verilog-indent-level-module 3
101 ;; verilog-indent-level-declaration 3
102 ;; verilog-indent-level-behavioral 3
103 ;; verilog-indent-level-directive 1
104 ;; verilog-case-indent 2
105 ;; verilog-auto-newline t
106 ;; verilog-auto-indent-on-newline t
107 ;; verilog-tab-always-indent t
108 ;; verilog-auto-endcomments t
109 ;; verilog-minimum-comment-distance 40
110 ;; verilog-indent-begin-after-if t
111 ;; verilog-auto-lineup 'declarations
112 ;; verilog-highlight-p1800-keywords nil
113 ;; verilog-linter "my_lint_shell_command"
119 ;; See commit history at http://www.veripool.org/verilog-mode.html
120 ;; (This section is required to appease checkdoc.)
125 ;; This variable will always hold the version number of the mode
126 (defconst verilog-mode-version
"2017-05-08-b240c8f-vpo-GNU"
127 "Version of this Verilog mode.")
128 (defconst verilog-mode-release-emacs t
129 "If non-nil, this version of Verilog mode was released with Emacs itself.")
131 (defun verilog-version ()
132 "Inform caller of the version of this file."
134 (message "Using verilog-mode version %s" verilog-mode-version
))
136 ;; Insure we have certain packages, and deal with it if we don't
137 ;; Be sure to note which Emacs flavor and version added each feature.
139 ;; Provide stuff if we are XEmacs
140 (when (featurep 'xemacs
)
145 (require 'regexp-opt
)
147 ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
154 (defmacro when
(cond &rest body
)
155 (list 'if cond
(cons 'progn body
))))
158 (if (fboundp 'unless
)
160 (defmacro unless
(cond &rest body
)
161 (cons 'if
(cons cond
(cons nil body
)))))
164 (if (fboundp 'store-match-data
)
166 (defmacro store-match-data
(&rest _args
) nil
))
169 (if (fboundp 'char-before
)
171 (defmacro char-before
(&rest _body
)
172 (char-after (1- (point)))))
177 (defsubst point-at-bol
(&optional N
)
178 (save-excursion (beginning-of-line N
) (point))))
183 (defsubst point-at-eol
(&optional N
)
184 (save-excursion (end-of-line N
) (point))))
190 (if (fboundp 'match-string-no-properties
)
192 (defsubst match-string-no-properties
(num &optional string
)
193 "Return string of text matched by last search, without text properties.
194 NUM specifies which parenthesized expression in the last regexp.
195 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
196 Zero means the entire text matched by the whole regexp or whole string.
197 STRING should be given if the last search was by `string-match' on STRING."
198 (if (match-beginning num
)
202 (match-beginning num
) (match-end num
))))
203 (set-text-properties 0 (length result
) nil result
)
205 (buffer-substring-no-properties (match-beginning num
)
210 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
211 nil
; We've got what we needed
212 ;; We have the old custom-library, hack around it!
213 (defmacro defgroup
(&rest _args
) nil
)
214 (defmacro customize
(&rest _args
)
216 "Sorry, Customize is not available with this version of Emacs"))
217 (defmacro defcustom
(var value doc
&rest _args
)
218 `(defvar ,var
,value
,doc
))
220 (if (fboundp 'defface
)
222 (defmacro defface
(var values doc
&rest _args
)
226 (if (and (featurep 'custom
) (fboundp 'customize-group
))
227 nil
; We've got what we needed
228 ;; We have an intermediate custom-library, hack around it!
229 (defmacro customize-group
(var &rest _args
)
233 (defvar inhibit-modification-hooks
)
234 (defvar inhibit-point-motion-hooks
)
235 (defvar deactivate-mark
)
238 ;; OK, do this stuff if we are NOT XEmacs:
239 (unless (featurep 'xemacs
)
240 (unless (fboundp 'region-active-p
)
241 (defmacro region-active-p
()
242 `(and transient-mark-mode mark-active
))))
245 ;; Provide a regular expression optimization routine, using regexp-opt
246 ;; if provided by the user's elisp libraries
248 ;; The below were disabled when GNU Emacs 22 was released;
249 ;; perhaps some still need to be there to support Emacs 21.
250 (if (featurep 'xemacs
)
251 (if (fboundp 'regexp-opt
)
252 ;; regexp-opt is defined, does it take 3 or 2 arguments?
253 (if (fboundp 'function-max-args
)
254 (let ((args (function-max-args `regexp-opt
)))
256 ((eq args
3) ; It takes 3
257 (condition-case nil
; Hide this defun from emacses
258 ; with just a two input regexp
259 (defun verilog-regexp-opt (a b
)
260 "Deal with differing number of required arguments for `regexp-opt'.
261 Call `regexp-opt' on A and B."
265 ((eq args
2) ; It takes 2
266 (defun verilog-regexp-opt (a b
)
267 "Call `regexp-opt' on A and B."
271 ;; We can't tell; assume it takes 2
272 (defun verilog-regexp-opt (a b
)
273 "Call `regexp-opt' on A and B."
276 ;; There is no regexp-opt, provide our own
277 (defun verilog-regexp-opt (strings &optional paren _shy
)
278 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
279 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
)))
282 (defalias 'verilog-regexp-opt
'regexp-opt
)))
284 ;; emacs >=22 has looking-back, but older emacs and xemacs don't.
285 ;; This function is lifted directly from emacs's subr.el
286 ;; so that it can be used by xemacs.
287 ;; The idea for this was borrowed from org-mode via this link:
288 ;; https://lists.gnu.org/archive/html/emacs-orgmode/2009-12/msg00032.html
291 ((fboundp 'looking-back
)
292 (defalias 'verilog-looking-back
'looking-back
))
294 (defun verilog-looking-back (regexp limit
&optional greedy
)
295 "Return non-nil if text before point matches regular expression REGEXP.
296 Like `looking-at' except matches before point, and is slower.
297 LIMIT if non-nil speeds up the search by specifying a minimum
298 starting position, to avoid checking matches that would start
301 If GREEDY is non-nil, extend the match backwards as far as
302 possible, stopping when a single additional previous character
303 cannot be part of a match for REGEXP. When the match is
304 extended, its starting position is allowed to occur before
307 As a general recommendation, try to avoid using `looking-back'
308 wherever possible, since it is slow."
309 (let ((start (point))
312 (and (re-search-backward (concat "\\(?:" regexp
"\\)\\=") limit t
)
316 (narrow-to-region (point-min) start
)
317 (while (and (> pos
(point-min))
321 (looking-at (concat "\\(?:" regexp
"\\)\\'"))))
325 (looking-at (concat "\\(?:" regexp
"\\)\\'")))))
326 (not (null pos
)))))))
330 ((fboundp 'restore-buffer-modified-p
)
331 ;; Faster, as does not update mode line when nothing changes
332 (defalias 'verilog-restore-buffer-modified-p
'restore-buffer-modified-p
))
334 (defalias 'verilog-restore-buffer-modified-p
'set-buffer-modified-p
))))
337 ;; Both xemacs and emacs
339 (require 'diff
) ; diff-command and diff-switches
342 (require 'compile
) ; compilation-error-regexp-alist-alist
345 (unless (fboundp 'buffer-chars-modified-tick
) ; Emacs 22 added
346 (defmacro buffer-chars-modified-tick
() (buffer-modified-tick)))
348 ;; Added in Emacs 24.1
350 (unless (fboundp 'prog-mode
)
351 (define-derived-mode prog-mode fundamental-mode
"Prog"))
353 ;; Added in Emacs 25.1
355 (unless (fboundp 'forward-word-strictly
)
356 (defalias 'forward-word-strictly
'forward-word
))
360 (defun verilog-regexp-words (a)
361 "Call `regexp-opt' with word delimiters for the words A."
362 (concat "\\<" (verilog-regexp-opt a t
) "\\>")))
363 (defun verilog-regexp-words (a)
364 "Call `regexp-opt' with word delimiters for the words A."
365 ;; The FAQ references this function, so user LISP sometimes calls it
366 (concat "\\<" (verilog-regexp-opt a t
) "\\>"))
368 (defun verilog-easy-menu-filter (menu)
369 "Filter `easy-menu-define' MENU to support new features."
370 (cond ((not (featurep 'xemacs
))
371 menu
) ; GNU Emacs - passthru
372 ;; XEmacs doesn't support :help. Strip it.
373 ;; Recursively filter the a submenu
375 (mapcar 'verilog-easy-menu-filter menu
))
376 ;; Look for [:help "blah"] and remove
378 (let ((i 0) (out []))
379 (while (< i
(length menu
))
380 (if (equal `:help
(aref menu i
))
382 (setq out
(vconcat out
(vector (aref menu i
)))
385 (t menu
))) ; Default - ok
386 ;;(verilog-easy-menu-filter
387 ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
388 ;; "----" ["MB" nil :help "Help MB"]))
390 (defun verilog-define-abbrev-table (tablename definitions
&optional docstring
&rest props
)
391 "Filter `define-abbrev-table' TABLENAME DEFINITIONS
392 Provides DOCSTRING PROPS in newer Emacs (23.1)."
394 (apply 'define-abbrev-table tablename definitions docstring props
)
396 (define-abbrev-table tablename definitions
))))
398 (defun verilog-define-abbrev (table name expansion
&optional hook
)
399 "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
400 Provides SYSTEM-FLAG in newer Emacs."
402 (define-abbrev table name expansion hook
0 t
)
404 (define-abbrev table name expansion hook
))))
406 (defun verilog-customize ()
407 "Customize variables and other settings used by Verilog-Mode."
409 (customize-group 'verilog-mode
))
411 (defun verilog-font-customize ()
412 "Customize fonts used by Verilog-Mode."
414 (if (fboundp 'customize-apropos
)
415 (customize-apropos "font-lock-*" 'faces
)))
417 (defun verilog-booleanp (value)
418 "Return t if VALUE is boolean.
419 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
420 This function may be removed when Emacs 21 is no longer supported."
421 (or (equal value t
) (equal value nil
)))
423 (defun verilog-insert-last-command-event ()
424 "Insert the `last-command-event'."
425 (insert (if (featurep 'xemacs
)
426 ;; XEmacs 21.5 doesn't like last-command-event
428 ;; And GNU Emacs 22 has obsoleted last-command-char
429 last-command-event
)))
431 (defvar verilog-no-change-functions nil
432 "True if `after-change-functions' is disabled.
433 Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")
435 (defvar verilog-in-hooks nil
436 "True when within a `verilog-run-hooks' block.")
438 (defmacro verilog-run-hooks
(&rest hooks
)
439 "Run each hook in HOOKS using `run-hooks'.
440 Set `verilog-in-hooks' during this time, to assist AUTO caches."
441 `(let ((verilog-in-hooks t
))
442 (run-hooks ,@hooks
)))
444 (defun verilog-syntax-ppss (&optional pos
)
445 (when verilog-no-change-functions
447 (verilog-scan-cache-flush)
448 ;; else don't let the AUTO code itself get away with flushing the cache,
449 ;; as that'll make things very slow
451 (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
452 (verilog-point-text))))
453 (if (fboundp 'syntax-ppss
)
455 (parse-partial-sexp (point-min) (or pos
(point)))))
457 (defgroup verilog-mode nil
458 "Major mode for Verilog source code."
462 ;; (defgroup verilog-mode-fonts nil
463 ;; "Facilitates easy customization fonts used in Verilog source text"
464 ;; :link '(customize-apropos "font-lock-*" 'faces)
465 ;; :group 'verilog-mode)
467 (defgroup verilog-mode-indent nil
468 "Customize indentation and highlighting of Verilog source text."
469 :group
'verilog-mode
)
471 (defgroup verilog-mode-actions nil
472 "Customize actions on Verilog source text."
473 :group
'verilog-mode
)
475 (defgroup verilog-mode-auto nil
476 "Customize AUTO actions when expanding Verilog source text."
477 :group
'verilog-mode
)
479 (defvar verilog-debug nil
480 "Non-nil means enable debug messages for `verilog-mode' internals.")
482 (defvar verilog-warn-fatal nil
483 "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
485 (defcustom verilog-linter
486 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
487 "Unix program and arguments to call to run a lint checker on Verilog source.
488 Depending on the `verilog-set-compile-command', this may be invoked when
489 you type \\[compile]. When the compile completes, \\[next-error] will take
490 you to the next lint error."
492 :group
'verilog-mode-actions
)
493 ;; We don't mark it safe, as it's used as a shell command
495 (defcustom verilog-coverage
496 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
497 "Program and arguments to use to annotate for coverage Verilog source.
498 Depending on the `verilog-set-compile-command', this may be invoked when
499 you type \\[compile]. When the compile completes, \\[next-error] will take
500 you to the next lint error."
502 :group
'verilog-mode-actions
)
503 ;; We don't mark it safe, as it's used as a shell command
505 (defcustom verilog-simulator
506 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
507 "Program and arguments to use to interpret Verilog source.
508 Depending on the `verilog-set-compile-command', this may be invoked when
509 you type \\[compile]. When the compile completes, \\[next-error] will take
510 you to the next lint error."
512 :group
'verilog-mode-actions
)
513 ;; We don't mark it safe, as it's used as a shell command
515 (defcustom verilog-compiler
516 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
517 "Program and arguments to use to compile Verilog source.
518 Depending on the `verilog-set-compile-command', this may be invoked when
519 you type \\[compile]. When the compile completes, \\[next-error] will take
520 you to the next lint error."
522 :group
'verilog-mode-actions
)
523 ;; We don't mark it safe, as it's used as a shell command
525 (defcustom verilog-preprocessor
526 ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
527 "vppreproc __FLAGS__ __FILE__"
528 "Program and arguments to use to preprocess Verilog source.
529 This is invoked with `verilog-preprocess', and depending on the
530 `verilog-set-compile-command', may also be invoked when you type
531 \\[compile]. When the compile completes, \\[next-error] will
532 take you to the next lint error."
534 :group
'verilog-mode-actions
)
535 ;; We don't mark it safe, as it's used as a shell command
537 (defvar verilog-preprocess-history nil
538 "History for `verilog-preprocess'.")
540 (defvar verilog-tool
'verilog-linter
541 "Which tool to use for building compiler-command.
542 Either nil, `verilog-linter', `verilog-compiler',
543 `verilog-coverage', `verilog-preprocessor', or `verilog-simulator'.
544 Alternatively use the \"Choose Compilation Action\" menu. See
545 `verilog-set-compile-command' for more information.")
547 (defcustom verilog-highlight-translate-off nil
548 "Non-nil means background-highlight code excluded from translation.
549 That is, all code between \"// synopsys translate_off\" and
550 \"// synopsys translate_on\" is highlighted using a different background color
551 \(face `verilog-font-lock-translate-off-face').
553 Note: This will slow down on-the-fly fontification (and thus editing).
555 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
556 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
558 :group
'verilog-mode-indent
)
559 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
560 (put 'verilog-highlight-translate-off
'safe-local-variable
'verilog-booleanp
)
562 (defcustom verilog-auto-lineup
'declarations
563 "Type of statements to lineup across multiple lines.
564 If `all' is selected, then all line ups described below are done.
566 If `declarations', then just declarations are lined up with any
567 preceding declarations, taking into account widths and the like,
568 so or example the code:
575 If `assignment', then assignments are lined up with any preceding
576 assignments, so for example the code
577 a_long_variable <= b + c;
580 a_long_variable <= b + c;
583 In order to speed up editing, large blocks of statements are lined up
584 only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
585 are lineup only when \\[verilog-pretty-declarations] is typed."
587 :type
'(radio (const :tag
"Line up Assignments and Declarations" all
)
588 (const :tag
"Line up Assignment statements" assignments
)
589 (const :tag
"Line up Declarations" declarations
)
590 (function :tag
"Other"))
591 :group
'verilog-mode-indent
)
592 (put 'verilog-auto-lineup
'safe-local-variable
593 '(lambda (x) (memq x
'(nil all assignments declarations
))))
595 (defcustom verilog-indent-level
3
596 "Indentation of Verilog statements with respect to containing block."
597 :group
'verilog-mode-indent
599 (put 'verilog-indent-level
'safe-local-variable
'integerp
)
601 (defcustom verilog-indent-level-module
3
602 "Indentation of Module level Verilog statements (eg always, initial).
603 Set to 0 to get initial and always statements lined up on the left side of
605 :group
'verilog-mode-indent
607 (put 'verilog-indent-level-module
'safe-local-variable
'integerp
)
609 (defcustom verilog-indent-level-declaration
3
610 "Indentation of declarations with respect to containing block.
611 Set to 0 to get them list right under containing block."
612 :group
'verilog-mode-indent
614 (put 'verilog-indent-level-declaration
'safe-local-variable
'integerp
)
616 (defcustom verilog-indent-declaration-macros nil
617 "How to treat macro expansions in a declaration.
622 If non nil, treat as:
626 :group
'verilog-mode-indent
628 (put 'verilog-indent-declaration-macros
'safe-local-variable
'verilog-booleanp
)
630 (defcustom verilog-indent-lists t
631 "How to treat indenting items in a list.
632 If t (the default), indent as:
633 always @( posedge a or
637 always @( posedge a or
639 :group
'verilog-mode-indent
641 (put 'verilog-indent-lists
'safe-local-variable
'verilog-booleanp
)
643 (defcustom verilog-indent-level-behavioral
3
644 "Absolute indentation of first begin in a task or function block.
645 Set to 0 to get such code to start at the left side of the screen."
646 :group
'verilog-mode-indent
648 (put 'verilog-indent-level-behavioral
'safe-local-variable
'integerp
)
650 (defcustom verilog-indent-level-directive
1
651 "Indentation to add to each level of \\=`ifdef declarations.
652 Set to 0 to have all directives start at the left side of the screen."
653 :group
'verilog-mode-indent
655 (put 'verilog-indent-level-directive
'safe-local-variable
'integerp
)
657 (defcustom verilog-cexp-indent
2
658 "Indentation of Verilog statements split across lines."
659 :group
'verilog-mode-indent
661 (put 'verilog-cexp-indent
'safe-local-variable
'integerp
)
663 (defcustom verilog-case-indent
2
664 "Indentation for case statements."
665 :group
'verilog-mode-indent
667 (put 'verilog-case-indent
'safe-local-variable
'integerp
)
669 (defcustom verilog-auto-newline t
670 "Non-nil means automatically newline after semicolons."
671 :group
'verilog-mode-indent
673 (put 'verilog-auto-newline
'safe-local-variable
'verilog-booleanp
)
675 (defcustom verilog-auto-indent-on-newline t
676 "Non-nil means automatically indent line after newline."
677 :group
'verilog-mode-indent
679 (put 'verilog-auto-indent-on-newline
'safe-local-variable
'verilog-booleanp
)
681 (defcustom verilog-tab-always-indent t
682 "Non-nil means TAB should always re-indent the current line.
683 A nil value means TAB will only reindent when at the beginning of the line."
684 :group
'verilog-mode-indent
686 (put 'verilog-tab-always-indent
'safe-local-variable
'verilog-booleanp
)
688 (defcustom verilog-tab-to-comment nil
689 "Non-nil means TAB moves to the right hand column in preparation for a comment."
690 :group
'verilog-mode-actions
692 (put 'verilog-tab-to-comment
'safe-local-variable
'verilog-booleanp
)
694 (defcustom verilog-indent-begin-after-if t
695 "Non-nil means indent begin statements following if, else, while, etc.
696 Otherwise, line them up."
697 :group
'verilog-mode-indent
699 (put 'verilog-indent-begin-after-if
'safe-local-variable
'verilog-booleanp
)
701 (defcustom verilog-align-ifelse nil
702 "Non-nil means align `else' under matching `if'.
703 Otherwise else is lined up with first character on line holding matching if."
704 :group
'verilog-mode-indent
706 (put 'verilog-align-ifelse
'safe-local-variable
'verilog-booleanp
)
708 (defcustom verilog-minimum-comment-distance
10
709 "Minimum distance (in lines) between begin and end required before a comment.
710 Setting this variable to zero results in every end acquiring a comment; the
711 default avoids too many redundant comments in tight quarters."
712 :group
'verilog-mode-indent
714 (put 'verilog-minimum-comment-distance
'safe-local-variable
'integerp
)
716 (defcustom verilog-highlight-p1800-keywords nil
717 "Non-nil means highlight words newly reserved by IEEE-1800.
718 These will appear in `verilog-font-lock-p1800-face' in order to gently
719 suggest changing where these words are used as variables to something else.
720 A nil value means highlight these words as appropriate for the SystemVerilog
721 IEEE-1800 standard. Note that changing this will require restarting Emacs
722 to see the effect as font color choices are cached by Emacs."
723 :group
'verilog-mode-indent
725 (put 'verilog-highlight-p1800-keywords
'safe-local-variable
'verilog-booleanp
)
727 (defcustom verilog-highlight-grouping-keywords nil
728 "Non-nil means highlight grouping keywords more dramatically.
729 If false, these words are in the `font-lock-type-face'; if True
730 then they are in `verilog-font-lock-grouping-keywords-face'.
731 Some find that special highlighting on these grouping constructs
732 allow the structure of the code to be understood at a glance."
733 :group
'verilog-mode-indent
735 (put 'verilog-highlight-grouping-keywords
'safe-local-variable
'verilog-booleanp
)
737 (defcustom verilog-highlight-modules nil
738 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
739 When true, mousing over module names will allow jumping to the
740 module definition. If false, this is not supported. Setting
741 this is experimental, and may lead to bad performance."
742 :group
'verilog-mode-indent
744 (put 'verilog-highlight-modules
'safe-local-variable
'verilog-booleanp
)
746 (defcustom verilog-highlight-includes t
747 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
748 When true, mousing over include file names will allow jumping to the
749 file referenced. If false, this is not supported."
750 :group
'verilog-mode-indent
752 (put 'verilog-highlight-includes
'safe-local-variable
'verilog-booleanp
)
754 (defcustom verilog-auto-declare-nettype nil
755 "Non-nil specifies the data type to use with `verilog-auto-input' etc.
756 Set this to \"wire\" if the Verilog code uses \"\\=`default_nettype
757 none\". Note using \\=`default_nettype none isn't recommended practice; this
758 mode is experimental."
759 :version
"24.1" ; rev670
760 :group
'verilog-mode-actions
762 (put 'verilog-auto-declare-nettype
'safe-local-variable
`stringp
)
764 (defcustom verilog-auto-wire-comment t
765 "Non-nil indicates to insert to/from comments with `verilog-auto-wire' etc."
767 :group
'verilog-mode-actions
769 (put 'verilog-auto-wire-comment
'safe-local-variable
`verilog-booleanp
)
771 (defcustom verilog-auto-wire-type nil
772 "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
773 Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'.
774 Set this to \"wire\" to force use of wire when logic is otherwise appropriate;
775 this is generally only appropriate when making a non-SystemVerilog wrapper
776 containing SystemVerilog cells."
777 :version
"24.1" ; rev673
778 :group
'verilog-mode-actions
780 (put 'verilog-auto-wire-type
'safe-local-variable
`stringp
)
782 (defcustom verilog-auto-endcomments t
783 "Non-nil means insert a comment /* ... */ after `end's.
784 The name of the function or case will be set between the braces."
785 :group
'verilog-mode-actions
787 (put 'verilog-auto-endcomments
'safe-local-variable
'verilog-booleanp
)
789 (defcustom verilog-auto-delete-trailing-whitespace nil
790 "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
791 :version
"24.1" ; rev703
792 :group
'verilog-mode-actions
794 (put 'verilog-auto-delete-trailing-whitespace
'safe-local-variable
'verilog-booleanp
)
796 (defcustom verilog-auto-ignore-concat nil
797 "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
798 This will exclude signals referenced as pin connections in {...}
799 from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
800 for backward compatibility only and not set in new designs; it
801 may be removed in future versions."
802 :group
'verilog-mode-actions
804 (put 'verilog-auto-ignore-concat
'safe-local-variable
'verilog-booleanp
)
806 (defcustom verilog-auto-read-includes nil
807 "Non-nil means to automatically read includes before AUTOs.
808 This will do a `verilog-read-defines' and `verilog-read-includes' before
809 each AUTO expansion. This makes it easier to embed defines and includes,
810 but can result in very slow reading times if there are many or large
812 :group
'verilog-mode-actions
814 (put 'verilog-auto-read-includes
'safe-local-variable
'verilog-booleanp
)
816 (defcustom verilog-auto-save-policy nil
817 "Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
818 A value of `force' will always do a \\[verilog-auto] automatically if
819 needed on every save. A value of `detect' will do \\[verilog-auto]
820 automatically when it thinks necessary. A value of `ask' will query the
821 user when it thinks updating is needed.
823 You should not rely on the `ask' or `detect' policies, they are safeguards
824 only. They do not detect when AUTOINSTs need to be updated because a
825 sub-module's port list has changed."
826 :group
'verilog-mode-actions
827 :type
'(choice (const nil
) (const ask
) (const detect
) (const force
)))
829 (defcustom verilog-auto-star-expand t
830 "Non-nil means to expand SystemVerilog .* instance ports.
831 They will be expanded in the same way as if there was an AUTOINST in the
832 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
833 :group
'verilog-mode-actions
835 (put 'verilog-auto-star-expand
'safe-local-variable
'verilog-booleanp
)
837 (defcustom verilog-auto-star-save nil
838 "Non-nil means save to disk SystemVerilog .* instance expansions.
839 A nil value indicates direct connections will be removed before saving.
840 Only meaningful to those created due to `verilog-auto-star-expand' being set.
842 Instead of setting this, you may want to use /*AUTOINST*/, which will
844 :group
'verilog-mode-actions
846 (put 'verilog-auto-star-save
'safe-local-variable
'verilog-booleanp
)
848 (defvar verilog-auto-update-tick nil
849 "Modification tick at which autos were last performed.")
851 (defvar verilog-auto-last-file-locals nil
852 "Text from file-local-variables during last evaluation.")
854 (defvar verilog-diff-function
'verilog-diff-report
855 "Function to run when `verilog-diff-auto' detects differences.
856 Function takes three arguments, the original buffer, the
857 difference buffer, and the point in original buffer with the
860 (defvar verilog-diff-ignore-regexp nil
861 "Non-nil specifies regexp which `verilog-diff-auto' will ignore.
862 This is typically nil.")
869 (defvar verilog-error-regexp-added nil
)
871 (defvar verilog-error-regexp-emacs-alist
874 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
876 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
878 ".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
880 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
882 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
885 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
886 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
888 "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
890 "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
892 "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
894 "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
896 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
898 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
900 "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
902 "List of regexps for Verilog compilers.
903 See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
905 (defvar verilog-error-regexp-xemacs-alist
906 ;; Emacs form is '((v-tool "re" 1 2) ...)
907 ;; XEmacs form is '(verilog ("re" 1 2) ...)
908 ;; So we can just map from Emacs to XEmacs
909 (cons 'verilog
(mapcar 'cdr verilog-error-regexp-emacs-alist
))
910 "List of regexps for Verilog compilers.
911 See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
913 (defvar verilog-error-font-lock-keywords
916 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
917 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
919 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t
)
920 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t
)
921 ;; verilog-IES (nc-verilog)
922 (".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t
)
923 (".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t
)
924 ;; verilog-surefire-1
925 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t
)
926 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t
)
927 ;; verilog-surefire-2
928 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t
)
929 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t
)
932 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
933 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
935 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
936 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
938 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t
)
939 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t
)
941 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
942 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
944 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
945 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t
)
947 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t
)
948 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
950 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t
)
951 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t
)
953 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t
)
954 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t
)
956 "Keywords to also highlight in Verilog *compilation* buffers.
957 Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
959 (defcustom verilog-library-flags
'("")
960 "List of standard Verilog arguments to use for /*AUTOINST*/.
961 These arguments are used to find files for `verilog-auto', and match
962 the flags accepted by a standard Verilog-XL simulator.
964 -f filename Reads more `verilog-library-flags' from the filename.
965 +incdir+dir Adds the directory to `verilog-library-directories'.
966 -Idir Adds the directory to `verilog-library-directories'.
967 -y dir Adds the directory to `verilog-library-directories'.
968 +libext+.v Adds the extensions to `verilog-library-extensions'.
969 -v filename Adds the filename to `verilog-library-files'.
971 filename Adds the filename to `verilog-library-files'.
972 This is not recommended, -v is a better choice.
974 You might want these defined in each file; put at the *END* of your file
978 // verilog-library-flags:(\"-y dir -y otherdir\")
981 Verilog-mode attempts to detect changes to this local variable, but they
982 are only insured to be correct when the file is first visited. Thus if you
983 have problems, use \\[find-alternate-file] RET to have these take effect.
985 See also the variables mentioned above."
986 :group
'verilog-mode-auto
987 :type
'(repeat string
))
988 (put 'verilog-library-flags
'safe-local-variable
'listp
)
990 (defcustom verilog-library-directories
'(".")
991 "List of directories when looking for files for /*AUTOINST*/.
992 The directory may be relative to the current file, or absolute.
993 Environment variables are also expanded in the directory names.
994 Having at least the current directory is a good idea.
996 You might want these defined in each file; put at the *END* of your file
1000 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
1003 Verilog-mode attempts to detect changes to this local variable, but they
1004 are only insured to be correct when the file is first visited. Thus if you
1005 have problems, use \\[find-alternate-file] RET to have these take effect.
1007 See also `verilog-library-flags', `verilog-library-files'
1008 and `verilog-library-extensions'."
1009 :group
'verilog-mode-auto
1010 :type
'(repeat file
))
1011 (put 'verilog-library-directories
'safe-local-variable
'listp
)
1013 (defcustom verilog-library-files
'()
1014 "List of files to search for modules.
1015 AUTOINST will use this when it needs to resolve a module name.
1016 This is a complete path, usually to a technology file with many standard
1017 cells defined in it.
1019 You might want these defined in each file; put at the *END* of your file
1023 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
1026 Verilog-mode attempts to detect changes to this local variable, but they
1027 are only insured to be correct when the file is first visited. Thus if you
1028 have problems, use \\[find-alternate-file] RET to have these take effect.
1030 See also `verilog-library-flags', `verilog-library-directories'."
1031 :group
'verilog-mode-auto
1032 :type
'(repeat directory
))
1033 (put 'verilog-library-files
'safe-local-variable
'listp
)
1035 (defcustom verilog-library-extensions
'(".v" ".sv")
1036 "List of extensions to use when looking for files for /*AUTOINST*/.
1037 See also `verilog-library-flags', `verilog-library-directories'."
1038 :type
'(repeat string
)
1039 :group
'verilog-mode-auto
)
1040 (put 'verilog-library-extensions
'safe-local-variable
'listp
)
1042 (defcustom verilog-active-low-regexp nil
1043 "If true, treat signals matching this regexp as active low.
1044 This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
1045 you will probably also need `verilog-auto-reset-widths' set."
1046 :group
'verilog-mode-auto
1047 :type
'(choice (const nil
) regexp
))
1048 (put 'verilog-active-low-regexp
'safe-local-variable
'stringp
)
1050 (defcustom verilog-auto-sense-include-inputs nil
1051 "Non-nil means AUTOSENSE should include all inputs.
1052 If nil, only inputs that are NOT output signals in the same block are
1054 :group
'verilog-mode-auto
1056 (put 'verilog-auto-sense-include-inputs
'safe-local-variable
'verilog-booleanp
)
1058 (defcustom verilog-auto-sense-defines-constant nil
1059 "Non-nil means AUTOSENSE should assume all defines represent constants.
1060 When true, the defines will not be included in sensitivity lists. To
1061 maintain compatibility with other sites, this should be set at the bottom
1062 of each Verilog file that requires it, rather than being set globally."
1063 :group
'verilog-mode-auto
1065 (put 'verilog-auto-sense-defines-constant
'safe-local-variable
'verilog-booleanp
)
1067 (defcustom verilog-auto-reset-blocking-in-non t
1068 "Non-nil means AUTORESET will reset blocking statements.
1069 When true, AUTORESET will reset in blocking statements those
1070 signals which were assigned with blocking assignments (=) even in
1071 a block with non-blocking assignments (<=).
1073 If nil, all blocking assigned signals are ignored when any
1074 non-blocking assignment is in the AUTORESET block. This allows
1075 blocking assignments to be used for temporary values and not have
1076 those temporaries reset. See example in `verilog-auto-reset'."
1077 :version
"24.1" ; rev718
1079 :group
'verilog-mode-auto
)
1080 (put 'verilog-auto-reset-blocking-in-non
'safe-local-variable
'verilog-booleanp
)
1082 (defcustom verilog-auto-reset-widths t
1083 "True means AUTORESET should determine the width of signals.
1084 This is then used to set the width of the zero (32'h0 for example). This
1085 is required by some lint tools that aren't smart enough to ignore widths of
1086 the constant zero. This may result in ugly code when parameters determine
1087 the MSB or LSB of a signal inside an AUTORESET.
1089 If nil, AUTORESET uses \"0\" as the constant.
1091 If `unbased', AUTORESET used the unbased unsized literal \"\\='0\"
1092 as the constant. This setting is strongly recommended for
1093 SystemVerilog designs."
1095 :group
'verilog-mode-auto
)
1096 (put 'verilog-auto-reset-widths
'safe-local-variable
1097 '(lambda (x) (memq x
'(nil t unbased
))))
1099 (defcustom verilog-assignment-delay
""
1100 "Text used for delays in delayed assignments. Add a trailing space if set."
1101 :group
'verilog-mode-auto
1103 (put 'verilog-assignment-delay
'safe-local-variable
'stringp
)
1105 (defcustom verilog-auto-arg-format
'packed
1106 "Formatting to use for AUTOARG signal names.
1107 If `packed', then as many inputs and outputs that fit within
1108 `fill-column' will be put onto one line.
1110 If `single', then a single input or output will be put onto each
1113 :type
'(radio (const :tag
"Line up Assignments and Declarations" packed
)
1114 (const :tag
"Line up Assignment statements" single
))
1115 :group
'verilog-mode-auto
)
1116 (put 'verilog-auto-arg-format
'safe-local-variable
1117 '(lambda (x) (memq x
'(packed single
))))
1119 (defcustom verilog-auto-arg-sort nil
1120 "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
1121 Declaration order is advantageous with order based instantiations
1122 and is the default for backward compatibility. Sorted order
1123 reduces changes when declarations are moved around in a file, and
1124 it's bad practice to rely on order based instantiations anyhow.
1126 See also `verilog-auto-inst-sort'."
1127 :group
'verilog-mode-auto
1129 (put 'verilog-auto-arg-sort
'safe-local-variable
'verilog-booleanp
)
1131 (defcustom verilog-auto-inst-dot-name nil
1132 "Non-nil means when creating ports with AUTOINST, use .name syntax.
1133 This will use \".port\" instead of \".port(port)\" when possible.
1134 This is only legal in SystemVerilog files, and will confuse older
1135 simulators. Setting `verilog-auto-inst-vector' to nil may also
1136 be desirable to increase how often .name will be used."
1137 :group
'verilog-mode-auto
1139 (put 'verilog-auto-inst-dot-name
'safe-local-variable
'verilog-booleanp
)
1141 (defcustom verilog-auto-inst-param-value nil
1142 "Non-nil means AUTOINST will replace parameters with the parameter value.
1143 If nil, leave parameters as symbolic names.
1145 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
1146 listed as such there (as when the default value is acceptable), it will not
1147 be replaced, and will remain symbolic.
1149 For example, imagine a submodule uses parameters to declare the size of its
1150 inputs. This is then used by an upper module:
1152 module InstModule (o,i);
1154 input [WIDTH-1:0] i;
1155 parameter type OUT_t;
1161 // Beginning of automatic outputs
1163 // End of automatics
1173 Note even though WIDTH=10, the AUTOINST has left the parameter as
1174 a symbolic name. Likewise the OUT_t is preserved as the name
1175 from the instantiated module.
1177 If `verilog-auto-inst-param-value' is set, this will
1182 // Beginning of automatic outputs
1184 // End of automatics
1194 Note that the instantiation now has \"i[9:0]\" as the WIDTH
1195 was expanded. Likewise the data type of \"o\" in the AUTOOUTPUT
1196 is now upper_t, from the OUT_t parameter override.
1197 This second expansion of parameter types can be overridden with
1198 `verilog-auto-inst-param-value-type'."
1199 :group
'verilog-mode-auto
1201 (put 'verilog-auto-inst-param-value
'safe-local-variable
'verilog-booleanp
)
1203 (defcustom verilog-auto-inst-param-value-type t
1204 "Non-nil means expand parameter type in instantiations.
1205 If nil, leave parameter types as symbolic names.
1207 See `verilog-auto-inst-param-value'."
1209 :group
'verilog-mode-auto
1211 (put 'verilog-auto-inst-param-value-type
'safe-local-variable
'verilog-booleanp
)
1213 (defcustom verilog-auto-inst-sort nil
1214 "Non-nil means AUTOINST signals will be sorted, not in declaration order.
1215 Also affects AUTOINSTPARAM. Declaration order is the default for
1216 backward compatibility, and as some teams prefer signals that are
1217 declared together to remain together. Sorted order reduces
1218 changes when declarations are moved around in a file.
1220 See also `verilog-auto-arg-sort'."
1221 :version
"24.1" ; rev688
1222 :group
'verilog-mode-auto
1224 (put 'verilog-auto-inst-sort
'safe-local-variable
'verilog-booleanp
)
1226 (defcustom verilog-auto-inst-vector t
1227 "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
1228 If nil, skip the subscript when it matches the entire bus as declared in
1229 the module (AUTOWIRE signals always are subscripted, you must manually
1230 declare the wire to have the subscripts removed.) Setting this to nil may
1231 speed up some simulators, but is less general and harder to read, so avoid."
1232 :group
'verilog-mode-auto
1234 (put 'verilog-auto-inst-vector
'safe-local-variable
'verilog-booleanp
)
1236 (defcustom verilog-auto-inst-template-numbers nil
1237 "If true, when creating templated ports with AUTOINST, add a comment.
1239 If t, the comment will add the line number of the template that
1240 was used for that port declaration. This setting is suggested
1241 only for debugging use, as regular use may cause a large numbers
1244 If `lhs', the comment will show the left hand side of the
1245 AUTO_TEMPLATE rule that is matched. This is less precise than
1246 numbering (t) when multiple rules have the same pin name, but
1247 won't merge conflict."
1248 :group
'verilog-mode-auto
1249 :type
'(choice (const nil
) (const t
) (const lhs
)))
1250 (put 'verilog-auto-inst-template-numbers
'safe-local-variable
1251 '(lambda (x) (memq x
'(nil t lhs
))))
1253 (defcustom verilog-auto-inst-column
40
1254 "Indent-to column number for net name part of AUTOINST created pin."
1255 :group
'verilog-mode-indent
1257 (put 'verilog-auto-inst-column
'safe-local-variable
'integerp
)
1259 (defcustom verilog-auto-inst-interfaced-ports nil
1260 "Non-nil means include interfaced ports in AUTOINST expansions."
1261 :version
"24.3" ; rev773, default change rev815
1262 :group
'verilog-mode-auto
1264 (put 'verilog-auto-inst-interfaced-ports
'safe-local-variable
'verilog-booleanp
)
1266 (defcustom verilog-auto-input-ignore-regexp nil
1267 "If non-nil, when creating AUTOINPUT, ignore signals matching this regexp.
1268 See the \\[verilog-faq] for examples on using this."
1269 :group
'verilog-mode-auto
1270 :type
'(choice (const nil
) regexp
))
1271 (put 'verilog-auto-input-ignore-regexp
'safe-local-variable
'stringp
)
1273 (defcustom verilog-auto-inout-ignore-regexp nil
1274 "If non-nil, when creating AUTOINOUT, ignore signals matching this regexp.
1275 See the \\[verilog-faq] for examples on using this."
1276 :group
'verilog-mode-auto
1277 :type
'(choice (const nil
) regexp
))
1278 (put 'verilog-auto-inout-ignore-regexp
'safe-local-variable
'stringp
)
1280 (defcustom verilog-auto-output-ignore-regexp nil
1281 "If non-nil, when creating AUTOOUTPUT, ignore signals matching this regexp.
1282 See the \\[verilog-faq] for examples on using this."
1283 :group
'verilog-mode-auto
1284 :type
'(choice (const nil
) regexp
))
1285 (put 'verilog-auto-output-ignore-regexp
'safe-local-variable
'stringp
)
1287 (defcustom verilog-auto-template-warn-unused nil
1288 "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
1289 This feature is not supported before Emacs 21.1 or XEmacs 21.4."
1290 :version
"24.3" ; rev787
1291 :group
'verilog-mode-auto
1293 (put 'verilog-auto-template-warn-unused
'safe-local-variable
'verilog-booleanp
)
1295 (defcustom verilog-auto-tieoff-declaration
"wire"
1296 "Data type used for the declaration for AUTOTIEOFF.
1297 If \"wire\" then create a wire, if \"assign\" create an
1298 assignment, else the data type for variable creation."
1299 :version
"24.1" ; rev713
1300 :group
'verilog-mode-auto
1302 (put 'verilog-auto-tieoff-declaration
'safe-local-variable
'stringp
)
1304 (defcustom verilog-auto-tieoff-ignore-regexp nil
1305 "If non-nil, when creating AUTOTIEOFF, ignore signals matching this regexp.
1306 See the \\[verilog-faq] for examples on using this."
1307 :group
'verilog-mode-auto
1308 :type
'(choice (const nil
) regexp
))
1309 (put 'verilog-auto-tieoff-ignore-regexp
'safe-local-variable
'stringp
)
1311 (defcustom verilog-auto-unused-ignore-regexp nil
1312 "If non-nil, when creating AUTOUNUSED, ignore signals matching this regexp.
1313 See the \\[verilog-faq] for examples on using this."
1314 :group
'verilog-mode-auto
1315 :type
'(choice (const nil
) regexp
))
1316 (put 'verilog-auto-unused-ignore-regexp
'safe-local-variable
'stringp
)
1318 (defcustom verilog-case-fold t
1319 "Non-nil means `verilog-mode' regexps should ignore case.
1320 This variable is t for backward compatibility; nil is suggested."
1322 :group
'verilog-mode
1324 (put 'verilog-case-fold
'safe-local-variable
'verilog-booleanp
)
1326 (defcustom verilog-typedef-regexp nil
1327 "If non-nil, regular expression that matches Verilog-2001 typedef names.
1328 For example, \"_t$\" matches typedefs named with _t, as in the C language.
1329 See also `verilog-case-fold'."
1330 :group
'verilog-mode-auto
1331 :type
'(choice (const nil
) regexp
))
1332 (put 'verilog-typedef-regexp
'safe-local-variable
'stringp
)
1334 (defcustom verilog-mode-hook
'verilog-set-compile-command
1335 "Hook run after Verilog mode is loaded."
1337 :group
'verilog-mode
)
1339 (defcustom verilog-auto-hook nil
1340 "Hook run after `verilog-mode' updates AUTOs."
1341 :group
'verilog-mode-auto
1344 (defcustom verilog-before-auto-hook nil
1345 "Hook run before `verilog-mode' updates AUTOs."
1346 :group
'verilog-mode-auto
1349 (defcustom verilog-delete-auto-hook nil
1350 "Hook run after `verilog-mode' deletes AUTOs."
1351 :group
'verilog-mode-auto
1354 (defcustom verilog-before-delete-auto-hook nil
1355 "Hook run before `verilog-mode' deletes AUTOs."
1356 :group
'verilog-mode-auto
1359 (defcustom verilog-getopt-flags-hook nil
1360 "Hook run after `verilog-getopt-flags' determines the Verilog option lists."
1361 :group
'verilog-mode-auto
1364 (defcustom verilog-before-getopt-flags-hook nil
1365 "Hook run before `verilog-getopt-flags' determines the Verilog option lists."
1366 :group
'verilog-mode-auto
1369 (defcustom verilog-before-save-font-hook nil
1370 "Hook run before `verilog-save-font-no-change-functions' removes highlighting."
1371 :version
"24.3" ; rev735
1372 :group
'verilog-mode-auto
1375 (defcustom verilog-after-save-font-hook nil
1376 "Hook run after `verilog-save-font-no-change-functions' restores highlighting."
1377 :version
"24.3" ; rev735
1378 :group
'verilog-mode-auto
1381 (defvar verilog-imenu-generic-expression
1382 '((nil "^\\s-*\\(?:m\\(?:odule\\|acromodule\\)\\|p\\(?:rimitive\\|rogram\\|ackage\\)\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 1)
1383 ("*Variables*" "^\\s-*\\(reg\\|wire\\|logic\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3)
1384 ("*Classes*" "^\\s-*\\(?:\\(?:virtual\\|interface\\)\\s-+\\)?class\\s-+\\([A-Za-z_][A-Za-z0-9_]+\\)" 1)
1385 ("*Tasks*" "^\\s-*\\(?:\\(?:static\\|pure\\|virtual\\|local\\|protected\\)\\s-+\\)*task\\s-+\\(?:\\(?:static\\|automatic\\)\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_:]+\\)" 1)
1386 ("*Functions*" "^\\s-*\\(?:\\(?:static\\|pure\\|virtual\\|local\\|protected\\)\\s-+\\)*function\\s-+\\(?:\\(?:static\\|automatic\\)\\s-+\\)?\\(?:\\w+\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_:]+\\)" 1)
1387 ("*Interfaces*" "^\\s-*interface\\s-+\\([a-zA-Z_0-9]+\\)" 1)
1388 ("*Types*" "^\\s-*typedef\\s-+.*\\s-+\\([a-zA-Z_0-9]+\\)\\s-*;" 1))
1389 "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
1392 ;; provide a verilog-header function.
1393 ;; Customization variables:
1395 (defvar verilog-date-scientific-format nil
1396 "If non-nil, dates are written in scientific format (e.g. 1997/09/17).
1397 If nil, in European format (e.g. 17.09.1997). The brain-dead American
1398 format (e.g. 09/17/1997) is not supported.")
1400 (defvar verilog-company nil
1401 "Default name of Company for Verilog header.
1402 If set will become buffer local.")
1403 (make-variable-buffer-local 'verilog-company
)
1405 (defvar verilog-project nil
1406 "Default name of Project for Verilog header.
1407 If set will become buffer local.")
1408 (make-variable-buffer-local 'verilog-project
)
1410 ;;; Keymap and Menu:
1413 (defvar verilog-mode-map
1414 (let ((map (make-sparse-keymap)))
1415 (define-key map
";" 'electric-verilog-semi
)
1416 (define-key map
[(control 59)] 'electric-verilog-semi-with-comment
)
1417 (define-key map
":" 'electric-verilog-colon
)
1418 ;;(define-key map "=" 'electric-verilog-equal)
1419 (define-key map
"`" 'electric-verilog-tick
)
1420 (define-key map
"\t" 'electric-verilog-tab
)
1421 (define-key map
"\r" 'electric-verilog-terminate-line
)
1422 ;; backspace/delete key bindings
1423 (define-key map
[backspace] 'backward-delete-char-untabify)
1424 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
1425 (define-key map [delete] 'delete-char)
1426 (define-key map [(meta delete)] 'kill-word))
1427 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
1428 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
1429 (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
1430 (define-key map "\M-\t" (if (fboundp 'completion-at-point)
1431 'completion-at-point 'verilog-complete-word))
1432 (define-key map "\M-?" (if (fboundp 'completion-help-at-point)
1433 'completion-help-at-point 'verilog-show-completions))
1434 ;; Note \C-c and letter are reserved for users
1435 (define-key map "\C-c`" 'verilog-lint-off)
1436 (define-key map "\C-c*" 'verilog-delete-auto-star-implicit)
1437 (define-key map "\C-c?" 'verilog-diff-auto)
1438 (define-key map "\C-c\C-r" 'verilog-label-be)
1439 (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
1440 (define-key map "\C-c=" 'verilog-pretty-expr)
1441 (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
1442 (define-key map "\C-c/" 'verilog-star-comment)
1443 (define-key map "\C-c\C-c" 'verilog-comment-region)
1444 (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1445 (when (featurep 'xemacs)
1446 (define-key map [(meta control h)] 'verilog-mark-defun)
1447 (define-key map "\M-\C-a" 'verilog-beg-of-defun)
1448 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1449 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1450 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1451 (define-key map "\C-c\C-a" 'verilog-auto)
1452 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1453 (define-key map "\C-c\C-p" 'verilog-preprocess)
1454 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1455 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1456 (define-key map "\C-c\C-h" 'verilog-header)
1458 "Keymap used in Verilog mode.")
1462 verilog-menu verilog-mode-map "Menu for Verilog mode"
1463 (verilog-easy-menu-filter
1465 ("Choose Compilation Action"
1468 (setq verilog-tool nil)
1469 (verilog-set-compile-command))
1471 :selected (equal verilog-tool nil)
1472 :help "When invoking compilation, use compile-command"]
1475 (setq verilog-tool 'verilog-linter)
1476 (verilog-set-compile-command))
1478 :selected (equal verilog-tool `verilog-linter)
1479 :help "When invoking compilation, use lint checker"]
1482 (setq verilog-tool 'verilog-coverage)
1483 (verilog-set-compile-command))
1485 :selected (equal verilog-tool `verilog-coverage)
1486 :help "When invoking compilation, annotate for coverage"]
1489 (setq verilog-tool 'verilog-simulator)
1490 (verilog-set-compile-command))
1492 :selected (equal verilog-tool `verilog-simulator)
1493 :help "When invoking compilation, interpret Verilog source"]
1496 (setq verilog-tool 'verilog-compiler)
1497 (verilog-set-compile-command))
1499 :selected (equal verilog-tool `verilog-compiler)
1500 :help "When invoking compilation, compile Verilog source"]
1503 (setq verilog-tool 'verilog-preprocessor)
1504 (verilog-set-compile-command))
1506 :selected (equal verilog-tool `verilog-preprocessor)
1507 :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1510 ["Beginning of function" verilog-beg-of-defun
1512 :help "Move backward to the beginning of the current function or procedure"]
1513 ["End of function" verilog-end-of-defun
1515 :help "Move forward to the end of the current function or procedure"]
1516 ["Mark function" verilog-mark-defun
1518 :help "Mark the current Verilog function or procedure"]
1519 ["Goto function/module" verilog-goto-defun
1520 :help "Move to specified Verilog module/task/function"]
1521 ["Move to beginning of block" electric-verilog-backward-sexp
1522 :help "Move backward over one balanced expression"]
1523 ["Move to end of block" electric-verilog-forward-sexp
1524 :help "Move forward over one balanced expression"]
1527 ["Comment Region" verilog-comment-region
1528 :help "Put marked area into a comment"]
1529 ["UnComment Region" verilog-uncomment-region
1530 :help "Uncomment an area commented with Comment Region"]
1531 ["Multi-line comment insert" verilog-star-comment
1532 :help "Insert Verilog /* */ comment at point"]
1533 ["Lint error to comment" verilog-lint-off
1534 :help "Convert a Verilog linter warning line into a disable statement"]
1538 :help "Perform compilation-action (above) on the current buffer"]
1539 ["AUTO, Save, Compile" verilog-auto-save-compile
1540 :help "Recompute AUTOs, save buffer, and compile"]
1541 ["Next Compile Error" next-error
1542 :help "Visit next compilation error message and corresponding source code"]
1543 ["Ignore Lint Warning at point" verilog-lint-off
1544 :help "Convert a Verilog linter warning line into a disable statement"]
1546 ["Line up declarations around point" verilog-pretty-declarations
1547 :help "Line up declarations around point"]
1548 ["Line up equations around point" verilog-pretty-expr
1549 :help "Line up expressions around point"]
1550 ["Redo/insert comments on every end" verilog-label-be
1551 :help "Label matching begin ... end statements"]
1552 ["Expand [x:y] vector line" verilog-expand-vector
1553 :help "Take a signal vector on the current line and expand it to multiple lines"]
1554 ["Insert begin-end block" verilog-insert-block
1555 :help "Insert begin ... end"]
1556 ["Complete word" ,(if (fboundp 'completion-at-point)
1557 'completion-at-point 'verilog-complete-word)
1558 :help "Complete word at point"]
1560 ["Recompute AUTOs" verilog-auto
1561 :help "Expand AUTO meta-comment statements"]
1562 ["Kill AUTOs" verilog-delete-auto
1563 :help "Remove AUTO expansions"]
1564 ["Diff AUTOs" verilog-diff-auto
1565 :help "Show differences in AUTO expansions"]
1566 ["Inject AUTOs" verilog-inject-auto
1567 :help "Inject AUTOs into legacy non-AUTO buffer"]
1569 ["AUTO General" (describe-function 'verilog-auto)
1570 :help "Help introduction on AUTOs"]
1571 ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
1572 :help "Help on verilog-library-flags"]
1573 ["AUTO Library Path" (describe-variable 'verilog-library-directories)
1574 :help "Help on verilog-library-directories"]
1575 ["AUTO Library Files" (describe-variable 'verilog-library-files)
1576 :help "Help on verilog-library-files"]
1577 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
1578 :help "Help on verilog-library-extensions"]
1579 ["AUTO `define Reading" (describe-function 'verilog-read-defines)
1580 :help "Help on reading `defines"]
1581 ["AUTO `include Reading" (describe-function 'verilog-read-includes)
1582 :help "Help on parsing `includes"]
1583 ["AUTOARG" (describe-function 'verilog-auto-arg)
1584 :help "Help on AUTOARG - declaring module port list"]
1585 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
1586 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1587 ["AUTOASSIGNMODPORT" (describe-function 'verilog-auto-assign-modport)
1588 :help "Help on AUTOASSIGNMODPORT - creating assignments to/from modports"]
1589 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1590 :help "Help on AUTOINOUT - adding inouts from cells"]
1591 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
1592 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1593 ["AUTOINOUTIN" (describe-function 'verilog-auto-inout-in)
1594 :help "Help on AUTOINOUTIN - copying i/o from another file as all inputs"]
1595 ["AUTOINOUTMODPORT" (describe-function 'verilog-auto-inout-modport)
1596 :help "Help on AUTOINOUTMODPORT - copying i/o from an interface modport"]
1597 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1598 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1599 ["AUTOINOUTPARAM" (describe-function 'verilog-auto-inout-param)
1600 :help "Help on AUTOINOUTPARAM - copying parameters from another file"]
1601 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1602 :help "Help on AUTOINPUT - adding inputs from cells"]
1603 ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
1604 :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
1605 ["AUTOINSERTLAST" (describe-function 'verilog-auto-insert-last)
1606 :help "Help on AUTOINSERTLISPLAST - insert text from a lisp function"]
1607 ["AUTOINST" (describe-function 'verilog-auto-inst)
1608 :help "Help on AUTOINST - adding pins for cells"]
1609 ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
1610 :help "Help on expanding Verilog-2001 .* pins"]
1611 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
1612 :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
1613 ["AUTOLOGIC" (describe-function 'verilog-auto-logic)
1614 :help "Help on AUTOLOGIC - declaring logic signals"]
1615 ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
1616 :help "Help on AUTOOUTPUT - adding outputs from cells"]
1617 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
1618 :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
1619 ["AUTOREG" (describe-function 'verilog-auto-reg)
1620 :help "Help on AUTOREG - declaring registers for non-wires"]
1621 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
1622 :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
1623 ["AUTORESET" (describe-function 'verilog-auto-reset)
1624 :help "Help on AUTORESET - resetting always blocks"]
1625 ["AUTOSENSE or AS" (describe-function 'verilog-auto-sense)
1626 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1627 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1628 :help "Help on AUTOTIEOFF - tying off unused outputs"]
1629 ["AUTOUNDEF" (describe-function 'verilog-auto-undef)
1630 :help "Help on AUTOUNDEF - undefine all local defines"]
1631 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1632 :help "Help on AUTOUNUSED - terminating unused inputs"]
1633 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
1634 :help "Help on AUTOWIRE - declaring wires for cells"]
1637 ["Submit bug report" verilog-submit-bug-report
1638 :help "Submit via mail a bug report on verilog-mode.el"]
1639 ["Version and FAQ" verilog-faq
1640 :help "Show the current version, and where to get the FAQ etc"]
1641 ["Customize Verilog Mode..." verilog-customize
1642 :help "Customize variables and other settings used by Verilog-Mode"]
1643 ["Customize Verilog Fonts & Colors" verilog-font-customize
1644 :help "Customize fonts used by Verilog-Mode."])))
1647 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1648 (verilog-easy-menu-filter
1650 ["Header" verilog-sk-header
1651 :help "Insert a header block at the top of file"]
1652 ["Comment" verilog-sk-comment
1653 :help "Insert a comment block"]
1655 ["Module" verilog-sk-module
1656 :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
1657 ["OVM Class" verilog-sk-ovm-class
1658 :help "Insert an OVM class block"]
1659 ["UVM Object" verilog-sk-uvm-object
1660 :help "Insert an UVM object block"]
1661 ["UVM Component" verilog-sk-uvm-component
1662 :help "Insert an UVM component block"]
1663 ["Primitive" verilog-sk-primitive
1664 :help "Insert a primitive .. (.. );.. endprimitive block"]
1666 ["Input" verilog-sk-input
1667 :help "Insert an input declaration"]
1668 ["Output" verilog-sk-output
1669 :help "Insert an output declaration"]
1670 ["Inout" verilog-sk-inout
1671 :help "Insert an inout declaration"]
1672 ["Wire" verilog-sk-wire
1673 :help "Insert a wire declaration"]
1674 ["Reg" verilog-sk-reg
1675 :help "Insert a register declaration"]
1676 ["Define thing under point as a register" verilog-sk-define-signal
1677 :help "Define signal under point as a register at the top of the module"]
1679 ["Initial" verilog-sk-initial
1680 :help "Insert an initial begin .. end block"]
1681 ["Always" verilog-sk-always
1682 :help "Insert an always @(AS) begin .. end block"]
1683 ["Function" verilog-sk-function
1684 :help "Insert a function .. begin .. end endfunction block"]
1685 ["Task" verilog-sk-task
1686 :help "Insert a task .. begin .. end endtask block"]
1687 ["Specify" verilog-sk-specify
1688 :help "Insert a specify .. endspecify block"]
1689 ["Generate" verilog-sk-generate
1690 :help "Insert a generate .. endgenerate block"]
1692 ["Begin" verilog-sk-begin
1693 :help "Insert a begin .. end block"]
1695 :help "Insert an if (..) begin .. end block"]
1696 ["(if) else" verilog-sk-else-if
1697 :help "Insert an else if (..) begin .. end block"]
1698 ["For" verilog-sk-for
1699 :help "Insert a for (...) begin .. end block"]
1700 ["While" verilog-sk-while
1701 :help "Insert a while (...) begin .. end block"]
1702 ["Fork" verilog-sk-fork
1703 :help "Insert a fork begin .. end .. join block"]
1704 ["Repeat" verilog-sk-repeat
1705 :help "Insert a repeat (..) begin .. end block"]
1706 ["Case" verilog-sk-case
1707 :help "Insert a case block, prompting for details"]
1708 ["Casex" verilog-sk-casex
1709 :help "Insert a casex (...) item: begin.. end endcase block"]
1710 ["Casez" verilog-sk-casez
1711 :help "Insert a casez (...) item: begin.. end endcase block"])))
1713 (defvar verilog-mode-abbrev-table nil
1714 "Abbrev table in use in Verilog-mode buffers.")
1716 ;;(makunbound 'verilog-mode-abbrev-table) ; For testing, clear out old defvar
1717 (verilog-define-abbrev-table
1718 'verilog-mode-abbrev-table ()
1719 "Abbrev table for Verilog mode skeletons."
1721 ;; Only expand in code.
1722 :enable-function (lambda () (not (verilog-in-comment-or-string-p))))
1723 (verilog-define-abbrev verilog-mode-abbrev-table "class" "" 'verilog-sk-ovm-class)
1724 (verilog-define-abbrev verilog-mode-abbrev-table "always" "" 'verilog-sk-always)
1725 (verilog-define-abbrev verilog-mode-abbrev-table "begin" nil `verilog-sk-begin)
1726 (verilog-define-abbrev verilog-mode-abbrev-table "case" "" `verilog-sk-case)
1727 (verilog-define-abbrev verilog-mode-abbrev-table "for" "" `verilog-sk-for)
1728 (verilog-define-abbrev verilog-mode-abbrev-table "generate" "" `verilog-sk-generate)
1729 (verilog-define-abbrev verilog-mode-abbrev-table "initial" "" `verilog-sk-initial)
1730 (verilog-define-abbrev verilog-mode-abbrev-table "fork" "" `verilog-sk-fork)
1731 (verilog-define-abbrev verilog-mode-abbrev-table "module" "" `verilog-sk-module)
1732 (verilog-define-abbrev verilog-mode-abbrev-table "primitive" "" `verilog-sk-primitive)
1733 (verilog-define-abbrev verilog-mode-abbrev-table "repeat" "" `verilog-sk-repeat)
1734 (verilog-define-abbrev verilog-mode-abbrev-table "specify" "" `verilog-sk-specify)
1735 (verilog-define-abbrev verilog-mode-abbrev-table "task" "" `verilog-sk-task)
1736 (verilog-define-abbrev verilog-mode-abbrev-table "while" "" `verilog-sk-while)
1737 (verilog-define-abbrev verilog-mode-abbrev-table "casex" "" `verilog-sk-casex)
1738 (verilog-define-abbrev verilog-mode-abbrev-table "casez" "" `verilog-sk-casez)
1739 (verilog-define-abbrev verilog-mode-abbrev-table "if" "" `verilog-sk-if)
1740 (verilog-define-abbrev verilog-mode-abbrev-table "else if" "" `verilog-sk-else-if)
1741 (verilog-define-abbrev verilog-mode-abbrev-table "assign" "" `verilog-sk-assign)
1742 (verilog-define-abbrev verilog-mode-abbrev-table "function" "" `verilog-sk-function)
1743 (verilog-define-abbrev verilog-mode-abbrev-table "input" "" `verilog-sk-input)
1744 (verilog-define-abbrev verilog-mode-abbrev-table "output" "" `verilog-sk-output)
1745 (verilog-define-abbrev verilog-mode-abbrev-table "inout" "" `verilog-sk-inout)
1746 (verilog-define-abbrev verilog-mode-abbrev-table "wire" "" `verilog-sk-wire)
1747 (verilog-define-abbrev verilog-mode-abbrev-table "reg" "" `verilog-sk-reg)
1753 (defsubst verilog-within-string ()
1754 (nth 3 (parse-partial-sexp (point-at-bol) (point))))
1756 (defsubst verilog-string-match-fold (regexp string &optional start)
1757 "Like `string-match', but use `verilog-case-fold'.
1758 Return index of start of first match for REGEXP in STRING, or nil.
1759 Matching ignores case if `verilog-case-fold' is non-nil.
1760 If third arg START is non-nil, start search at that index in STRING."
1761 (let ((case-fold-search verilog-case-fold))
1762 (string-match regexp string start)))
1764 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1765 "Replace occurrences of FROM-STRING with TO-STRING.
1766 FIXEDCASE and LITERAL as in `replace-match'. STRING is what to replace.
1767 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1768 will break, as the o's continuously replace. xa -> x works ok though."
1769 ;; Hopefully soon to an Emacs built-in
1770 ;; Also note \ in the replacement prevent multiple replacements; IE
1771 ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
1772 ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
1774 (while (string-match from-string string start)
1775 (setq string (replace-match to-string fixedcase literal string)
1776 start (min (length string) (+ (match-beginning 0) (length to-string)))))
1779 (defsubst verilog-string-remove-spaces (string)
1780 "Remove spaces surrounding STRING."
1782 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
1783 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
1786 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
1787 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1788 "Like `re-search-forward', but skips over match in comments or strings."
1789 (let ((mdata '(nil nil))) ; So match-end will return nil if no matches found
1791 (re-search-forward REGEXP BOUND NOERROR)
1792 (setq mdata (match-data))
1793 (and (verilog-skip-forward-comment-or-string)
1795 (setq mdata '(nil nil))
1799 (store-match-data mdata)
1802 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
1803 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1804 "Like `re-search-backward', but skips over match in comments or strings."
1805 (let ((mdata '(nil nil))) ; So match-end will return nil if no matches found
1807 (re-search-backward REGEXP BOUND NOERROR)
1808 (setq mdata (match-data))
1809 (and (verilog-skip-backward-comment-or-string)
1811 (setq mdata '(nil nil))
1815 (store-match-data mdata)
1818 (defsubst verilog-re-search-forward-quick (regexp bound noerror)
1819 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
1820 but trashes match data and is faster for REGEXP that doesn't match often.
1821 This uses `verilog-scan' and text properties to ignore comments,
1822 so there may be a large up front penalty for the first search."
1824 (while (and (not pt)
1825 (re-search-forward regexp bound noerror))
1826 (if (verilog-inside-comment-or-string-p (match-beginning 0))
1827 (re-search-forward "[/\"\n]" nil t) ; Only way a comment or quote can end
1828 (setq pt (match-end 0))))
1831 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
1832 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1833 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
1834 but trashes match data and is faster for REGEXP that doesn't match often.
1835 This uses `verilog-scan' and text properties to ignore comments,
1836 so there may be a large up front penalty for the first search."
1838 (while (and (not pt)
1839 (re-search-backward regexp bound noerror))
1840 (if (verilog-inside-comment-or-string-p (match-beginning 0))
1841 (re-search-backward "[/\"]" nil t) ; Only way a comment or quote can begin
1842 (setq pt (match-beginning 0))))
1845 (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
1846 "Like `re-search-forward', but first search for SUBSTR constant.
1847 Then searched for the normal REGEXP (which contains SUBSTR), with given
1848 BOUND and NOERROR. The REGEXP must fit within a single line.
1849 This speeds up complicated regexp matches."
1850 ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
1851 ;; thus require matches to be on one line, and use beginning-of-line.
1853 (while (and (not done)
1854 (search-forward substr bound noerror))
1857 (setq done (re-search-forward regexp (point-at-eol) noerror)))
1858 (unless (and (<= (match-beginning 0) (point))
1859 (>= (match-end 0) (point)))
1861 (when done (goto-char done))
1863 ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ; -end (test bait)
1865 (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
1866 "Like `re-search-backward', but first search for SUBSTR constant.
1867 Then searched for the normal REGEXP (which contains SUBSTR), with given
1868 BOUND and NOERROR. The REGEXP must fit within a single line.
1869 This speeds up complicated regexp matches."
1870 ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
1871 ;; thus require matches to be on one line, and use beginning-of-line.
1873 (while (and (not done)
1874 (search-backward substr bound noerror))
1877 (setq done (re-search-backward regexp (point-at-bol) noerror)))
1878 (unless (and (<= (match-beginning 0) (point))
1879 (>= (match-end 0) (point)))
1881 (when done (goto-char done))
1883 ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ; -end (test bait)
1885 (defun verilog-delete-trailing-whitespace ()
1886 "Delete trailing spaces or tabs, but not newlines nor linefeeds.
1887 Also add missing final newline.
1889 To call this from the command line, see \\[verilog-batch-diff-auto].
1891 To call on \\[verilog-auto], set `verilog-auto-delete-trailing-whitespace'."
1892 ;; Similar to `delete-trailing-whitespace' but that's not present in XEmacs
1894 (goto-char (point-min))
1895 (while (re-search-forward "[ \t]+$" nil t) ; Not syntactic WS as no formfeed
1896 (replace-match "" nil nil))
1897 (goto-char (point-max))
1898 (unless (bolp) (insert "\n"))))
1900 (defvar compile-command)
1901 (defvar create-lockfiles) ; Emacs 24
1903 ;; compilation program
1904 (defun verilog-set-compile-command ()
1905 "Function to compute shell command to compile Verilog.
1907 This reads `verilog-tool' and sets `compile-command'. This specifies the
1908 program that executes when you type \\[compile] or
1909 \\[verilog-auto-save-compile].
1911 By default `verilog-tool' uses a Makefile if one exists in the
1912 current directory. If not, it is set to the `verilog-linter',
1913 `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
1914 or `verilog-simulator' variables, as selected with the Verilog ->
1915 \"Choose Compilation Action\" menu.
1917 You should set `verilog-tool' or the other variables to the path and
1918 arguments for your Verilog simulator. For example:
1921 \"(cd /tmp; surecov %s)\".
1923 In the former case, the path to the current buffer is concat'ed to the
1924 value of `verilog-tool'; in the later, the path to the current buffer is
1925 substituted for the %s.
1927 Where __FLAGS__ appears in the string `verilog-current-flags'
1928 will be substituted.
1930 Where __FILE__ appears in the string, the variable
1931 `buffer-file-name' of the current buffer, without the directory
1932 portion, will be substituted."
1935 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1936 (file-exists-p "Makefile"))
1937 (set (make-local-variable 'compile-command) "make "))
1939 (set (make-local-variable 'compile-command)
1941 (if (string-match "%s" (eval verilog-tool))
1942 (format (eval verilog-tool) (or buffer-file-name ""))
1943 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1945 (verilog-modify-compile-command))
1947 (defun verilog-expand-command (command)
1948 "Replace meta-information in COMMAND and return it.
1949 Where __FLAGS__ appears in the string `verilog-current-flags'
1950 will be substituted. Where __FILE__ appears in the string, the
1951 current buffer's file-name, without the directory portion, will
1953 (setq command (verilog-string-replace-matches
1954 ;; Note \\b only works if under verilog syntax table
1955 "\\b__FLAGS__\\b" (verilog-current-flags)
1957 (setq command (verilog-string-replace-matches
1958 "\\b__FILE__\\b" (file-name-nondirectory
1959 (or (buffer-file-name) ""))
1963 ;; Eliminate compile warning
1964 (defvar verilog-compile-command-pre-mod)
1965 (defvar verilog-compile-command-post-mod)
1967 (defun verilog-modify-compile-command ()
1968 "Update `compile-command' using `verilog-expand-command'."
1969 ;; Entry into verilog-mode a call to this before Local Variables exist
1970 ;; Likewise user may have hook or something that changes the flags.
1971 ;; So, remember we're responsible for the expansion and on re-entry
1972 ;; recompute __FLAGS__ on each reentry.
1973 (when (stringp compile-command)
1975 (boundp 'verilog-compile-command-post-mod)
1976 (equal compile-command verilog-compile-command-post-mod))
1977 (setq compile-command verilog-compile-command-pre-mod))
1979 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1980 (set (make-local-variable 'verilog-compile-command-pre-mod)
1982 (set (make-local-variable 'compile-command)
1983 (verilog-expand-command compile-command))
1984 (set (make-local-variable 'verilog-compile-command-post-mod)
1987 (if (featurep 'xemacs)
1988 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1989 (defun verilog-error-regexp-add-xemacs ()
1990 "Teach XEmacs about verilog errors.
1991 Called by `compilation-mode-hook'. This allows \\[next-error] to
1994 (if (boundp 'compilation-error-regexp-systems-alist)
1996 (not (equal compilation-error-regexp-systems-list 'all))
1997 (not (member compilation-error-regexp-systems-list 'verilog)))
1998 (push 'verilog compilation-error-regexp-systems-list)))
1999 (if (boundp 'compilation-error-regexp-alist-alist)
2000 (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
2001 (setcdr compilation-error-regexp-alist-alist
2002 (cons verilog-error-regexp-xemacs-alist
2003 (cdr compilation-error-regexp-alist-alist)))))
2004 (if (boundp 'compilation-font-lock-keywords)
2006 (set (make-local-variable 'compilation-font-lock-keywords)
2007 verilog-error-font-lock-keywords)
2008 (font-lock-set-defaults)))
2009 ;; Need to re-run compilation-error-regexp builder
2010 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
2011 (compilation-build-compilation-error-regexp-alist))
2014 ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
2015 (defun verilog-error-regexp-add-emacs ()
2016 "Tell Emacs compile that we are Verilog.
2017 Called by `compilation-mode-hook'. This allows \\[next-error] to
2020 (when (boundp 'compilation-error-regexp-alist-alist)
2021 (when (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
2024 (push (car item) compilation-error-regexp-alist)
2025 (push item compilation-error-regexp-alist-alist))
2026 verilog-error-regexp-emacs-alist))))
2028 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
2029 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
2031 (defconst verilog-compiler-directives
2034 ;; compiler directives, from IEEE 1800-2012 section 22.1
2035 "`__FILE__" "`__LINE" "`begin_keywords" "`celldefine" "`default_nettype"
2036 "`define" "`else" "`elsif" "`end_keywords" "`endcelldefine" "`endif"
2037 "`ifdef" "`ifndef" "`include" "`line" "`nounconnected_drive" "`pragma"
2038 "`resetall" "`timescale" "`unconnected_drive" "`undef" "`undefineall"
2039 ;; compiler directives not covered by IEEE 1800
2040 "`case" "`default" "`endfor" "`endprotect" "`endswitch" "`endwhile" "`for"
2041 "`format" "`if" "`let" "`protect" "`switch" "`timescale" "`time_scale"
2044 "List of Verilog compiler directives.")
2046 (defconst verilog-directive-re
2047 (verilog-regexp-words verilog-compiler-directives))
2049 (defconst verilog-directive-re-1
2050 (concat "[ \t]*" verilog-directive-re))
2052 (defconst verilog-directive-begin
2053 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
2055 (defconst verilog-directive-middle
2056 "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
2058 (defconst verilog-directive-end
2059 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
2061 (defconst verilog-ovm-begin-re
2065 "`ovm_component_utils_begin"
2066 "`ovm_component_param_utils_begin"
2067 "`ovm_field_utils_begin"
2068 "`ovm_object_utils_begin"
2069 "`ovm_object_param_utils_begin"
2070 "`ovm_sequence_utils_begin"
2071 "`ovm_sequencer_utils_begin"
2074 (defconst verilog-ovm-end-re
2078 "`ovm_component_utils_end"
2079 "`ovm_field_utils_end"
2080 "`ovm_object_utils_end"
2081 "`ovm_sequence_utils_end"
2082 "`ovm_sequencer_utils_end"
2085 (defconst verilog-uvm-begin-re
2089 "`uvm_component_utils_begin"
2090 "`uvm_component_param_utils_begin"
2091 "`uvm_field_utils_begin"
2092 "`uvm_object_utils_begin"
2093 "`uvm_object_param_utils_begin"
2094 "`uvm_sequence_utils_begin"
2095 "`uvm_sequencer_utils_begin"
2098 (defconst verilog-uvm-end-re
2102 "`uvm_component_utils_end"
2103 "`uvm_field_utils_end"
2104 "`uvm_object_utils_end"
2105 "`uvm_sequence_utils_end"
2106 "`uvm_sequencer_utils_end"
2109 (defconst verilog-vmm-begin-re
2113 "`vmm_data_member_begin"
2114 "`vmm_env_member_begin"
2115 "`vmm_scenario_member_begin"
2116 "`vmm_subenv_member_begin"
2117 "`vmm_xactor_member_begin"
2120 (defconst verilog-vmm-end-re
2124 "`vmm_data_member_end"
2125 "`vmm_env_member_end"
2126 "`vmm_scenario_member_end"
2127 "`vmm_subenv_member_end"
2128 "`vmm_xactor_member_end"
2131 (defconst verilog-vmm-statement-re
2135 "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
2136 ;; "`vmm_xactor_member_enum_array"
2137 ;; "`vmm_xactor_member_scalar_array"
2138 ;; "`vmm_xactor_member_scalar"
2141 (defconst verilog-ovm-statement-re
2150 "`ovm_analysis_imp_decl"
2151 "`ovm_blocking_get_imp_decl"
2152 "`ovm_blocking_get_peek_imp_decl"
2153 "`ovm_blocking_master_imp_decl"
2154 "`ovm_blocking_peek_imp_decl"
2155 "`ovm_blocking_put_imp_decl"
2156 "`ovm_blocking_slave_imp_decl"
2157 "`ovm_blocking_transport_imp_decl"
2158 "`ovm_component_registry"
2159 "`ovm_component_registry_param"
2160 "`ovm_component_utils"
2163 "`ovm_declare_sequence_lib"
2170 "`ovm_field_aa_int_byte"
2171 "`ovm_field_aa_int_byte_unsigned"
2172 "`ovm_field_aa_int_int"
2173 "`ovm_field_aa_int_int_unsigned"
2174 "`ovm_field_aa_int_integer"
2175 "`ovm_field_aa_int_integer_unsigned"
2176 "`ovm_field_aa_int_key"
2177 "`ovm_field_aa_int_longint"
2178 "`ovm_field_aa_int_longint_unsigned"
2179 "`ovm_field_aa_int_shortint"
2180 "`ovm_field_aa_int_shortint_unsigned"
2181 "`ovm_field_aa_int_string"
2182 "`ovm_field_aa_object_int"
2183 "`ovm_field_aa_object_string"
2184 "`ovm_field_aa_string_int"
2185 "`ovm_field_aa_string_string"
2186 "`ovm_field_array_int"
2187 "`ovm_field_array_object"
2188 "`ovm_field_array_string"
2193 "`ovm_field_queue_int"
2194 "`ovm_field_queue_object"
2195 "`ovm_field_queue_string"
2196 "`ovm_field_sarray_int"
2201 "`ovm_get_peek_imp_decl"
2208 "`ovm_master_imp_decl"
2210 "`ovm_non_blocking_transport_imp_decl"
2211 "`ovm_nonblocking_get_imp_decl"
2212 "`ovm_nonblocking_get_peek_imp_decl"
2213 "`ovm_nonblocking_master_imp_decl"
2214 "`ovm_nonblocking_peek_imp_decl"
2215 "`ovm_nonblocking_put_imp_decl"
2216 "`ovm_nonblocking_slave_imp_decl"
2217 "`ovm_object_registry"
2218 "`ovm_object_registry_param"
2220 "`ovm_peek_imp_decl"
2221 "`ovm_phase_func_decl"
2222 "`ovm_phase_task_decl"
2223 "`ovm_print_aa_int_object"
2224 "`ovm_print_aa_string_int"
2225 "`ovm_print_aa_string_object"
2226 "`ovm_print_aa_string_string"
2227 "`ovm_print_array_int"
2228 "`ovm_print_array_object"
2229 "`ovm_print_array_string"
2230 "`ovm_print_object_queue"
2231 "`ovm_print_queue_int"
2232 "`ovm_print_string_queue"
2235 "`ovm_rand_send_with"
2237 "`ovm_sequence_utils"
2238 "`ovm_slave_imp_decl"
2239 "`ovm_transport_imp_decl"
2240 "`ovm_update_sequence_lib"
2241 "`ovm_update_sequence_lib_and_item"
2244 "`static_message") nil )))
2246 (defconst verilog-uvm-statement-re
2251 "`uvm_analysis_imp_decl"
2252 "`uvm_blocking_get_imp_decl"
2253 "`uvm_blocking_get_peek_imp_decl"
2254 "`uvm_blocking_master_imp_decl"
2255 "`uvm_blocking_peek_imp_decl"
2256 "`uvm_blocking_put_imp_decl"
2257 "`uvm_blocking_slave_imp_decl"
2258 "`uvm_blocking_transport_imp_decl"
2259 "`uvm_component_param_utils"
2260 "`uvm_component_registry"
2261 "`uvm_component_registry_param"
2262 "`uvm_component_utils"
2265 "`uvm_create_seq" ; Undocumented in 1.1
2266 "`uvm_declare_p_sequencer"
2267 "`uvm_declare_sequence_lib" ; Deprecated in 1.1
2270 "`uvm_do_callbacks_exit_on"
2271 "`uvm_do_obj_callbacks"
2272 "`uvm_do_obj_callbacks_exit_on"
2275 "`uvm_do_on_pri_with"
2279 "`uvm_do_seq" ; Undocumented in 1.1
2280 "`uvm_do_seq_with" ; Undocumented in 1.1
2283 "`uvm_error_context"
2285 "`uvm_fatal_context"
2286 "`uvm_field_aa_int_byte"
2287 "`uvm_field_aa_int_byte_unsigned"
2288 "`uvm_field_aa_int_enum"
2289 "`uvm_field_aa_int_int"
2290 "`uvm_field_aa_int_int_unsigned"
2291 "`uvm_field_aa_int_integer"
2292 "`uvm_field_aa_int_integer_unsigned"
2293 "`uvm_field_aa_int_key"
2294 "`uvm_field_aa_int_longint"
2295 "`uvm_field_aa_int_longint_unsigned"
2296 "`uvm_field_aa_int_shortint"
2297 "`uvm_field_aa_int_shortint_unsigned"
2298 "`uvm_field_aa_int_string"
2299 "`uvm_field_aa_object_int"
2300 "`uvm_field_aa_object_string"
2301 "`uvm_field_aa_string_int"
2302 "`uvm_field_aa_string_string"
2303 "`uvm_field_array_enum"
2304 "`uvm_field_array_int"
2305 "`uvm_field_array_object"
2306 "`uvm_field_array_string"
2311 "`uvm_field_queue_enum"
2312 "`uvm_field_queue_int"
2313 "`uvm_field_queue_object"
2314 "`uvm_field_queue_string"
2316 "`uvm_field_sarray_enum"
2317 "`uvm_field_sarray_int"
2318 "`uvm_field_sarray_object"
2319 "`uvm_field_sarray_string"
2322 "`uvm_file" ; Undocumented in 1.1, use `__FILE__
2324 "`uvm_get_peek_imp_decl"
2327 "`uvm_line" ; Undocumented in 1.1, use `__LINE__
2328 "`uvm_master_imp_decl"
2329 "`uvm_non_blocking_transport_imp_decl" ; Deprecated in 1.1
2330 "`uvm_nonblocking_get_imp_decl"
2331 "`uvm_nonblocking_get_peek_imp_decl"
2332 "`uvm_nonblocking_master_imp_decl"
2333 "`uvm_nonblocking_peek_imp_decl"
2334 "`uvm_nonblocking_put_imp_decl"
2335 "`uvm_nonblocking_slave_imp_decl"
2336 "`uvm_nonblocking_transport_imp_decl"
2337 "`uvm_object_param_utils"
2338 "`uvm_object_registry"
2339 "`uvm_object_registry_param" ; Undocumented in 1.1
2353 "`uvm_peek_imp_decl"
2356 "`uvm_rand_send_pri"
2357 "`uvm_rand_send_pri_with"
2358 "`uvm_rand_send_with"
2359 "`uvm_record_attribute"
2364 "`uvm_sequence_utils" ; Deprecated in 1.1
2365 "`uvm_set_super_type"
2366 "`uvm_slave_imp_decl"
2367 "`uvm_transport_imp_decl"
2369 "`uvm_unpack_arrayN"
2375 "`uvm_unpack_queueN"
2377 "`uvm_unpack_sarray"
2378 "`uvm_unpack_sarrayN"
2379 "`uvm_unpack_string"
2380 "`uvm_update_sequence_lib" ; Deprecated in 1.1
2381 "`uvm_update_sequence_lib_and_item" ; Deprecated in 1.1
2383 "`uvm_warning_context") nil )))
2387 ;; Regular expressions used to calculate indent, etc.
2389 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
2396 (defconst verilog-assignment-operator-re
2400 ;; blocking assignment_operator
2401 "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
2402 ;; non blocking assignment operator
2405 "==" "!=" "===" "!==" "<=" ">=" "==?" "!=?" "<->"
2409 "|->" "|=>" "#-#" "#=#"
2410 ;; distribution weighting
2414 (defconst verilog-assignment-operation-re
2416 ;; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)"
2417 ;; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)"
2418 "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" ))
2420 (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
2421 (defconst verilog-property-re
2422 (concat "\\(" verilog-label-re "\\)?"
2423 ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
2424 "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
2426 (defconst verilog-no-indent-begin-re
2428 (verilog-regexp-words
2429 '("always" "always_comb" "always_ff" "always_latch" "initial" "final" ; procedural blocks
2430 "if" "else" ; conditional statements
2431 "while" "for" "foreach" "repeat" "do" "forever" )))) ; loop statements
2433 (defconst verilog-ends-re
2434 ;; Parenthesis indicate type of keyword found
2436 "\\(\\<else\\>\\)\\|" ; 1
2437 "\\(\\<if\\>\\)\\|" ; 2
2438 "\\(\\<assert\\>\\)\\|" ; 3
2439 "\\(\\<end\\>\\)\\|" ; 3.1
2440 "\\(\\<endcase\\>\\)\\|" ; 4
2441 "\\(\\<endfunction\\>\\)\\|" ; 5
2442 "\\(\\<endtask\\>\\)\\|" ; 6
2443 "\\(\\<endspecify\\>\\)\\|" ; 7
2444 "\\(\\<endtable\\>\\)\\|" ; 8
2445 "\\(\\<endgenerate\\>\\)\\|" ; 9
2446 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
2447 "\\(\\<endclass\\>\\)\\|" ; 11
2448 "\\(\\<endgroup\\>\\)\\|" ; 12
2450 "\\(\\<`vmm_data_member_end\\>\\)\\|"
2451 "\\(\\<`vmm_env_member_end\\>\\)\\|"
2452 "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
2453 "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
2454 "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
2456 "\\(\\<`ovm_component_utils_end\\>\\)\\|"
2457 "\\(\\<`ovm_field_utils_end\\>\\)\\|"
2458 "\\(\\<`ovm_object_utils_end\\>\\)\\|"
2459 "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
2460 "\\(\\<`ovm_sequencer_utils_end\\>\\)"
2462 "\\(\\<`uvm_component_utils_end\\>\\)\\|"
2463 "\\(\\<`uvm_field_utils_end\\>\\)\\|"
2464 "\\(\\<`uvm_object_utils_end\\>\\)\\|"
2465 "\\(\\<`uvm_sequence_utils_end\\>\\)\\|"
2466 "\\(\\<`uvm_sequencer_utils_end\\>\\)"
2469 (defconst verilog-auto-end-comment-lines-re
2470 ;; Matches to names in this list cause auto-end-commenting
2472 verilog-directive-re "\\)\\|\\("
2474 (verilog-regexp-words
2503 ;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
2504 ;; verilog-end-block-ordered-re matches exactly the same strings.
2505 (defconst verilog-end-block-ordered-re
2506 ;; Parenthesis indicate type of keyword found
2507 (concat "\\(\\<endcase\\>\\)\\|" ; 1
2508 "\\(\\<end\\>\\)\\|" ; 2
2509 "\\(\\<end" ; 3, but not used
2510 "\\(" ; 4, but not used
2511 "\\(function\\)\\|" ; 5
2513 "\\(module\\)\\|" ; 7
2514 "\\(primitive\\)\\|" ; 8
2515 "\\(interface\\)\\|" ; 9
2516 "\\(package\\)\\|" ; 10
2517 "\\(class\\)\\|" ; 11
2518 "\\(group\\)\\|" ; 12
2519 "\\(program\\)\\|" ; 13
2520 "\\(sequence\\)\\|" ; 14
2521 "\\(clocking\\)\\|" ; 15
2522 "\\(property\\)\\|" ; 16
2524 (defconst verilog-end-block-re
2526 (verilog-regexp-words
2528 `("end" ; closes begin
2529 "endcase" ; closes any of case, casex casez or randcase
2530 "join" "join_any" "join_none" ; closes fork
2545 "`ovm_component_utils_end"
2546 "`ovm_field_utils_end"
2547 "`ovm_object_utils_end"
2548 "`ovm_sequence_utils_end"
2549 "`ovm_sequencer_utils_end"
2551 "`uvm_component_utils_end"
2552 "`uvm_field_utils_end"
2553 "`uvm_object_utils_end"
2554 "`uvm_sequence_utils_end"
2555 "`uvm_sequencer_utils_end"
2557 "`vmm_data_member_end"
2558 "`vmm_env_member_end"
2559 "`vmm_scenario_member_end"
2560 "`vmm_subenv_member_end"
2561 "`vmm_xactor_member_end"
2565 (defconst verilog-endcomment-reason-re
2566 ;; Parenthesis indicate type of keyword found
2568 "\\(\\<begin\\>\\)\\|" ; 1
2569 "\\(\\<else\\>\\)\\|" ; 2
2570 "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
2571 "\\(\\<always\\(?:_ff\\)?\\>\\(?:[ \t]*@\\)\\)\\|" ; 4 (matches always or always_ff w/ @...)
2572 "\\(\\<always\\(?:_comb\\|_latch\\)?\\>\\)\\|" ; 5 (matches always, always_comb, always_latch w/o @...)
2573 "\\(\\<fork\\>\\)\\|" ; 7
2575 verilog-property-re "\\|"
2576 "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
2577 "\\(\\<clocking\\>\\)\\|"
2578 "\\(\\<task\\>\\)\\|"
2579 "\\(\\<function\\>\\)\\|"
2580 "\\(\\<initial\\>\\)\\|"
2581 "\\(\\<interface\\>\\)\\|"
2582 "\\(\\<package\\>\\)\\|"
2583 "\\(\\<final\\>\\)\\|"
2585 "\\(\\<while\\>\\)\\|\\(\\<do\\>\\)\\|"
2586 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
2587 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
2590 (defconst verilog-named-block-re "begin[ \t]*:")
2592 ;; These words begin a block which can occur inside a module which should be indented,
2593 ;; and closed with the respective word from the end-block list
2595 (defconst verilog-beg-block-re
2597 (verilog-regexp-words
2599 "case" "casex" "casez" "randcase"
2609 "`ovm_component_utils_begin"
2610 "`ovm_component_param_utils_begin"
2611 "`ovm_field_utils_begin"
2612 "`ovm_object_utils_begin"
2613 "`ovm_object_param_utils_begin"
2614 "`ovm_sequence_utils_begin"
2615 "`ovm_sequencer_utils_begin"
2617 "`uvm_component_utils_begin"
2618 "`uvm_component_param_utils_begin"
2619 "`uvm_field_utils_begin"
2620 "`uvm_object_utils_begin"
2621 "`uvm_object_param_utils_begin"
2622 "`uvm_sequence_utils_begin"
2623 "`uvm_sequencer_utils_begin"
2625 "`vmm_data_member_begin"
2626 "`vmm_env_member_begin"
2627 "`vmm_scenario_member_begin"
2628 "`vmm_subenv_member_begin"
2629 "`vmm_xactor_member_begin"
2631 ;; These are the same words, in a specific order in the regular
2632 ;; expression so that matching will work nicely for
2633 ;; verilog-forward-sexp and verilog-calc-indent
2634 (defconst verilog-beg-block-re-ordered
2635 ( concat "\\(\\<begin\\>\\)" ;1
2636 "\\|\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
2637 "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
2638 "\\|\\(\\<class\\>\\)" ;6
2639 "\\|\\(\\<table\\>\\)" ;7
2640 "\\|\\(\\<specify\\>\\)" ;8
2641 "\\|\\(\\<function\\>\\)" ;9
2642 "\\|\\(\\(?:\\<\\(?:virtual\\|protected\\|static\\)\\>\\s-+\\)*\\<function\\>\\)" ;10
2643 "\\|\\(\\<task\\>\\)" ;11
2644 "\\|\\(\\(?:\\<\\(?:virtual\\|protected\\|static\\)\\>\\s-+\\)*\\<task\\>\\)" ;12
2645 "\\|\\(\\<generate\\>\\)" ;13
2646 "\\|\\(\\<covergroup\\>\\)" ;14
2647 "\\|\\(\\(?:\\(?:\\<cover\\>\\s-+\\)\\|\\(?:\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;15
2648 "\\|\\(\\<\\(?:rand\\)?sequence\\>\\)" ;16
2649 "\\|\\(\\<clocking\\>\\)" ;17
2650 "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;18
2651 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
2655 (defconst verilog-end-block-ordered-rry
2656 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2657 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
2658 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2659 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
2660 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
2661 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
2662 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
2663 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
2664 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
2665 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
2666 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
2667 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
2668 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
2671 (defconst verilog-nameable-item-re
2673 (verilog-regexp-words
2676 "join" "join_any" "join_none"
2698 (defconst verilog-declaration-opener
2700 (verilog-regexp-words
2701 `("module" "begin" "task" "function"))))
2703 (defconst verilog-declaration-prefix-re
2705 (verilog-regexp-words
2708 "inout" "input" "output" "ref"
2710 "const" "static" "protected" "local"
2712 "localparam" "parameter" "var"
2716 (defconst verilog-declaration-core-re
2718 (verilog-regexp-words
2720 ;; port direction (by themselves)
2721 "inout" "input" "output"
2722 ;; integer_atom_type
2723 "byte" "shortint" "int" "longint" "integer" "time"
2724 ;; integer_vector_type
2727 "shortreal" "real" "realtime"
2729 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
2731 "string" "event" "chandle" "virtual" "enum" "genvar"
2734 "mailbox" "semaphore"
2736 (defconst verilog-declaration-re
2737 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
2738 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
2739 (defconst verilog-optional-signed-re "\\s-*\\(\\(un\\)?signed\\)?")
2740 (defconst verilog-optional-signed-range-re
2742 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<\\(un\\)?signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
2743 (defconst verilog-macroexp-re "`\\sw+")
2745 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
2746 (defconst verilog-declaration-re-2-no-macro
2747 (concat "\\s-*" verilog-declaration-re
2748 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2750 (defconst verilog-declaration-re-2-macro
2751 (concat "\\s-*" verilog-declaration-re
2752 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2753 "\\|\\(" verilog-macroexp-re "\\)"
2755 (defconst verilog-declaration-re-1-macro
2756 (concat "^" verilog-declaration-re-2-macro))
2758 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
2760 (defconst verilog-defun-re
2761 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
2762 (defconst verilog-end-defun-re
2763 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
2764 (defconst verilog-zero-indent-re
2765 (concat verilog-defun-re "\\|" verilog-end-defun-re))
2766 (defconst verilog-inst-comment-re
2767 (eval-when-compile (verilog-regexp-words `("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced"))))
2769 (defconst verilog-behavioral-block-beg-re
2770 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
2771 "function" "task"))))
2772 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
2773 (defconst verilog-in-constraint-re ; keywords legal in constraint blocks starting a statement/block
2774 (eval-when-compile (verilog-regexp-words `("if" "else" "solve" "foreach"))))
2776 (defconst verilog-indent-re
2778 (verilog-regexp-words
2781 "always" "always_latch" "always_ff" "always_comb"
2783 ;; "unique" "priority"
2784 "case" "casex" "casez" "randcase" "endcase"
2786 "clocking" "endclocking"
2787 "config" "endconfig"
2788 "covergroup" "endgroup"
2789 "fork" "join" "join_any" "join_none"
2790 "function" "endfunction"
2792 "generate" "endgenerate"
2794 "interface" "endinterface"
2795 "module" "macromodule" "endmodule"
2796 "package" "endpackage"
2797 "primitive" "endprimitive"
2798 "program" "endprogram"
2799 "property" "endproperty"
2800 "sequence" "randsequence" "endsequence"
2801 "specify" "endspecify"
2808 "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
2809 "`while" "`endwhile"
2814 "`protect" "`endprotect"
2815 "`switch" "`endswitch"
2819 "`ovm_component_utils_begin"
2820 "`ovm_component_param_utils_begin"
2821 "`ovm_field_utils_begin"
2822 "`ovm_object_utils_begin"
2823 "`ovm_object_param_utils_begin"
2824 "`ovm_sequence_utils_begin"
2825 "`ovm_sequencer_utils_begin"
2827 "`ovm_component_utils_end"
2828 "`ovm_field_utils_end"
2829 "`ovm_object_utils_end"
2830 "`ovm_sequence_utils_end"
2831 "`ovm_sequencer_utils_end"
2833 "`uvm_component_utils_begin"
2834 "`uvm_component_param_utils_begin"
2835 "`uvm_field_utils_begin"
2836 "`uvm_object_utils_begin"
2837 "`uvm_object_param_utils_begin"
2838 "`uvm_sequence_utils_begin"
2839 "`uvm_sequencer_utils_begin"
2841 "`uvm_component_utils_end" ; Typo in spec, it's not uvm_component_end
2842 "`uvm_field_utils_end"
2843 "`uvm_object_utils_end"
2844 "`uvm_sequence_utils_end"
2845 "`uvm_sequencer_utils_end"
2847 "`vmm_data_member_begin"
2848 "`vmm_env_member_begin"
2849 "`vmm_scenario_member_begin"
2850 "`vmm_subenv_member_begin"
2851 "`vmm_xactor_member_begin"
2853 "`vmm_data_member_end"
2854 "`vmm_env_member_end"
2855 "`vmm_scenario_member_end"
2856 "`vmm_subenv_member_end"
2857 "`vmm_xactor_member_end"
2860 (defconst verilog-defun-level-not-generate-re
2862 (verilog-regexp-words
2863 `( "module" "macromodule" "primitive" "class" "program"
2864 "interface" "package" "config"))))
2866 (defconst verilog-defun-level-re
2868 (verilog-regexp-words
2870 `( "module" "macromodule" "primitive" "class" "program"
2871 "interface" "package" "config")
2872 `( "initial" "final" "always" "always_comb" "always_ff"
2873 "always_latch" "endtask" "endfunction" )))))
2875 (defconst verilog-defun-level-generate-only-re
2877 (verilog-regexp-words
2878 `( "initial" "final" "always" "always_comb" "always_ff"
2879 "always_latch" "endtask" "endfunction" ))))
2881 (defconst verilog-cpp-level-re
2883 (verilog-regexp-words
2885 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2888 (defconst verilog-dpi-import-export-re
2890 "\\(\\<\\(import\\|export\\)\\>\\s-+\"DPI\\(-C\\)?\"\\s-+\\(\\<\\(context\\|pure\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\<\\(function\\|task\\)\\>\\)"
2893 (defconst verilog-default-clocking-re "\\<default\\s-+clocking\\>")
2894 (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
2895 (defconst verilog-extended-case-re "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\|randcase\\)")
2896 (defconst verilog-extended-complete-re
2897 ;; verilog-beg-of-statement also looks backward one token to extend this match
2898 (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\|\\<static\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
2899 "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
2900 "\\|\\(\\(\\<\\(import\\|export\\)\\>\\s-+\\)?\\(\"DPI\\(-C\\)?\"\\s-+\\)?\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\(function\\>\\|task\\>\\)\\)"
2901 "\\|" verilog-extended-case-re ))
2902 (defconst verilog-basic-complete-re
2904 (verilog-regexp-words
2906 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
2907 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
2908 "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
2910 (defconst verilog-complete-reg
2912 verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)"))
2914 (defconst verilog-end-statement-re
2915 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
2916 verilog-end-block-re "\\)"))
2918 (defconst verilog-endcase-re
2919 (concat verilog-extended-case-re "\\|"
2924 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
2925 "String used to mark beginning of excluded text.")
2926 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
2927 "String used to mark end of excluded text.")
2928 (defconst verilog-preprocessor-re
2933 (verilog-regexp-words
2941 "`nounconnected_drive"
2943 "`unconnected_drive"
2946 ;; two words: i.e. `ifdef DEFINE
2947 "\\<\\(`elsif\\|`ifn?def\\|`undef\\|`default_nettype\\|`begin_keywords\\)\\>\\s-"
2949 ;; `line number "filename" level
2950 "\\<\\(`line\\)\\>\\s-+[0-9]+\\s-+\"[^\"]+\"\\s-+[012]"
2952 ;;`include "file" or `include <file>
2953 "\\<\\(`include\\)\\>\\s-+\\(?:\"[^\"]+\"\\|<[^>]+>\\)"
2955 ;; `pragma <stuff> (no mention in IEEE 1800-2012 that pragma can span multiple lines
2956 "\\<\\(`pragma\\)\\>\\s-+.+$"
2958 ;; `timescale time_unit / time_precision
2959 "\\<\\(`timescale\\)\\>\\s-+10\\{0,2\\}\\s-*[munpf]?s\\s-*\\/\\s-*10\\{0,2\\}\\s-*[munpf]?s"
2961 ;; `define and `if can span multiple lines if line ends in '\'. NOTE: `if is not IEEE 1800-2012
2962 ;; from http://www.emacswiki.org/emacs/MultilineRegexp
2963 (concat "\\<\\(`define\\|`if\\)\\>" ; directive
2965 "\\(?:.*?\\(?:\n.*\\)*?\\)" ; definition: to end of line, then maybe more lines (excludes any trailing \n)
2966 "\\(?:\n\\s-*\n\\|\\'\\)") ; blank line or EOF
2968 ;; `<macro>() : i.e. `uvm_info(a,b,c) or any other pre-defined macro
2969 ;; Since parameters inside the macro can have parentheses, and
2970 ;; the macro can span multiple lines, just look for the opening
2971 ;; parentheses and then continue to the end of the first
2973 (concat "\\<`\\w+\\>\\s-*("
2974 "\\(?:.*?\\(?:\n.*\\)*?\\)" ; definition: to end of line, then maybe more lines (excludes any trailing \n)
2975 "\\(?:\n\\s-*\n\\|\\'\\)") ; blank line or EOF
2979 (defconst verilog-keywords
2980 (append verilog-compiler-directives
2982 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
2983 "assert" "assign" "assume" "automatic" "before" "begin" "bind"
2984 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
2985 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
2986 "config" "const" "constraint" "context" "continue" "cover"
2987 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
2988 "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
2989 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
2990 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
2991 "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
2992 "endtask" "enum" "event" "expect" "export" "extends" "extern"
2993 "final" "first_match" "for" "force" "foreach" "forever" "fork"
2994 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
2995 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
2996 "include" "initial" "inout" "input" "inside" "instance" "int"
2997 "integer" "interface" "intersect" "join" "join_any" "join_none"
2998 "large" "liblist" "library" "local" "localparam" "logic"
2999 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
3000 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
3001 "notif0" "notif1" "null" "or" "output" "package" "packed"
3002 "parameter" "pmos" "posedge" "primitive" "priority" "program"
3003 "property" "protected" "pull0" "pull1" "pulldown" "pullup"
3004 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
3005 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
3006 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
3007 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
3008 "showcancelled" "signed" "small" "solve" "specify" "specparam"
3009 "static" "string" "strong0" "strong1" "struct" "super" "supply0"
3010 "supply1" "table" "tagged" "task" "this" "throughout" "time"
3011 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
3012 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
3013 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
3014 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
3015 "wire" "with" "within" "wor" "xnor" "xor"
3017 "accept_on" "checker" "endchecker" "eventually" "global" "implies"
3018 "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
3019 "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
3020 "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
3022 "implements" "interconnect" "nettype" "soft"
3024 "List of Verilog keywords.")
3026 (defconst verilog-comment-start-regexp "//\\|/\\*"
3027 "Dual comment value for `comment-start-regexp'.")
3029 (defvar verilog-mode-syntax-table
3030 (let ((table (make-syntax-table)))
3031 ;; Populate the syntax TABLE.
3032 (modify-syntax-entry ?\\ "\\" table)
3033 (modify-syntax-entry ?+ "." table)
3034 (modify-syntax-entry ?- "." table)
3035 (modify-syntax-entry ?= "." table)
3036 (modify-syntax-entry ?% "." table)
3037 (modify-syntax-entry ?< "." table)
3038 (modify-syntax-entry ?> "." table)
3039 (modify-syntax-entry ?& "." table)
3040 (modify-syntax-entry ?| "." table)
3041 (modify-syntax-entry ?` "w" table) ; ` is part of definition symbols in Verilog
3042 (modify-syntax-entry ?_ "w" table)
3043 (modify-syntax-entry ?\' "." table)
3045 ;; Set up TABLE to handle block and line style comments.
3046 (if (featurep 'xemacs)
3048 ;; XEmacs (formerly Lucid) has the best implementation
3049 (modify-syntax-entry ?/ ". 1456" table)
3050 (modify-syntax-entry ?* ". 23" table)
3051 (modify-syntax-entry ?\n "> b" table))
3052 ;; Emacs does things differently, but we can work with it
3053 (modify-syntax-entry ?/ ". 124b" table)
3054 (modify-syntax-entry ?* ". 23" table)
3055 (modify-syntax-entry ?\n "> b" table))
3057 "Syntax table used in Verilog mode buffers.")
3059 (defvar verilog-font-lock-keywords nil
3060 "Default highlighting for Verilog mode.")
3062 (defvar verilog-font-lock-keywords-1 nil
3063 "Subdued level highlighting for Verilog mode.")
3065 (defvar verilog-font-lock-keywords-2 nil
3066 "Medium level highlighting for Verilog mode.
3067 See also `verilog-font-lock-extra-types'.")
3069 (defvar verilog-font-lock-keywords-3 nil
3070 "Gaudy level highlighting for Verilog mode.
3071 See also `verilog-font-lock-extra-types'.")
3073 (defvar verilog-font-lock-translate-off-face
3074 'verilog-font-lock-translate-off-face
3075 "Font to use for translated off regions.")
3076 (defface verilog-font-lock-translate-off-face
3079 (:background "gray90" :italic t ))
3082 (:background "gray10" :italic t ))
3083 (((class grayscale) (background light))
3084 (:foreground "DimGray" :italic t))
3085 (((class grayscale) (background dark))
3086 (:foreground "LightGray" :italic t))
3088 "Font lock mode face used to background highlight translate-off regions."
3089 :group 'font-lock-highlighting-faces)
3091 (defvar verilog-font-lock-p1800-face
3092 'verilog-font-lock-p1800-face
3093 "Font to use for p1800 keywords.")
3094 (defface verilog-font-lock-p1800-face
3097 (:foreground "DarkOrange3" :bold t ))
3100 (:foreground "orange1" :bold t ))
3102 "Font lock mode face used to highlight P1800 keywords."
3103 :group 'font-lock-highlighting-faces)
3105 (defvar verilog-font-lock-ams-face
3106 'verilog-font-lock-ams-face
3107 "Font to use for Analog/Mixed Signal keywords.")
3108 (defface verilog-font-lock-ams-face
3111 (:foreground "Purple" :bold t ))
3114 (:foreground "orange1" :bold t ))
3116 "Font lock mode face used to highlight AMS keywords."
3117 :group 'font-lock-highlighting-faces)
3119 (defvar verilog-font-lock-grouping-keywords-face
3120 'verilog-font-lock-grouping-keywords-face
3121 "Font to use for Verilog Grouping Keywords (such as begin..end).")
3122 (defface verilog-font-lock-grouping-keywords-face
3125 (:foreground "Purple" :bold t ))
3128 (:foreground "orange1" :bold t ))
3130 "Font lock mode face used to highlight verilog grouping keywords."
3131 :group 'font-lock-highlighting-faces)
3133 (let* ((verilog-type-font-keywords
3137 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
3138 "event" "genvar" "inout" "input" "integer" "localparam"
3139 "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" "notif1" "or"
3140 "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
3141 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
3142 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
3143 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
3144 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
3145 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
3148 (verilog-pragma-keywords
3151 '("surefire" "auto" "synopsys" "rtl_synthesis" "verilint" "leda" "0in"
3154 (verilog-1800-2005-keywords
3157 '("alias" "assert" "assume" "automatic" "before" "bind"
3158 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
3159 "clocking" "config" "const" "constraint" "context" "continue"
3160 "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
3161 "dist" "do" "edge" "endclass" "endclocking" "endconfig"
3162 "endgroup" "endprogram" "endproperty" "endsequence" "enum"
3163 "expect" "export" "extends" "extern" "first_match" "foreach"
3164 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
3165 "illegal_bins" "import" "incdir" "include" "inside" "instance"
3166 "int" "intersect" "large" "liblist" "library" "local" "longint"
3167 "matches" "medium" "modport" "new" "noshowcancelled" "null"
3168 "packed" "program" "property" "protected" "pull0" "pull1"
3169 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
3170 "randcase" "randsequence" "ref" "release" "return" "scalared"
3171 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
3172 "specparam" "static" "string" "strong0" "strong1" "struct"
3173 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
3174 "type" "union" "unsigned" "use" "var" "virtual" "void"
3175 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
3178 (verilog-1800-2009-keywords
3181 '("accept_on" "checker" "endchecker" "eventually" "global"
3182 "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
3183 "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
3184 "sync_accept_on" "sync_reject_on" "unique0" "until"
3185 "until_with" "untyped" "weak" ) nil )))
3187 (verilog-1800-2012-keywords
3190 '("implements" "interconnect" "nettype" "soft" ) nil )))
3192 (verilog-ams-keywords
3195 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
3196 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
3197 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
3198 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
3199 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
3200 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
3201 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
3202 "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
3203 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
3204 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
3205 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
3207 (verilog-font-keywords
3211 "assign" "case" "casex" "casez" "randcase" "deassign"
3212 "default" "disable" "else" "endcase" "endfunction"
3213 "endgenerate" "endinterface" "endmodule" "endprimitive"
3214 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
3215 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
3216 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
3217 "package" "endpackage" "always" "always_comb" "always_ff"
3218 "always_latch" "posedge" "primitive" "priority" "release"
3219 "repeat" "specify" "table" "task" "unique" "wait" "while"
3220 "class" "program" "endclass" "endprogram"
3223 (verilog-font-grouping-keywords
3226 '( "begin" "end" ) nil ))))
3228 (setq verilog-font-lock-keywords
3230 ;; Fontify all builtin keywords
3231 (concat "\\<\\(" verilog-font-keywords "\\|"
3232 ;; And user/system tasks and functions
3233 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
3235 ;; Fontify all types
3236 (if verilog-highlight-grouping-keywords
3237 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
3238 'verilog-font-lock-grouping-keywords-face)
3239 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
3240 'font-lock-type-face))
3241 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
3242 'font-lock-type-face)
3243 ;; Fontify IEEE-1800-2005 keywords appropriately
3244 (if verilog-highlight-p1800-keywords
3245 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
3246 'verilog-font-lock-p1800-face)
3247 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
3248 'font-lock-type-face))
3249 ;; Fontify IEEE-1800-2009 keywords appropriately
3250 (if verilog-highlight-p1800-keywords
3251 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
3252 'verilog-font-lock-p1800-face)
3253 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
3254 'font-lock-type-face))
3255 ;; Fontify IEEE-1800-2012 keywords appropriately
3256 (if verilog-highlight-p1800-keywords
3257 (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
3258 'verilog-font-lock-p1800-face)
3259 (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
3260 'font-lock-type-face))
3261 ;; Fontify Verilog-AMS keywords
3262 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
3263 'verilog-font-lock-ams-face)))
3265 (setq verilog-font-lock-keywords-1
3266 (append verilog-font-lock-keywords
3268 ;; Fontify module definitions
3270 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
3271 '(1 font-lock-keyword-face)
3272 '(3 font-lock-function-name-face 'prepend))
3273 ;; Fontify function definitions
3275 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
3276 '(1 font-lock-keyword-face)
3277 '(3 font-lock-constant-face prepend))
3278 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
3279 (1 font-lock-keyword-face)
3280 (2 font-lock-constant-face append))
3281 '("\\<function\\>\\s-+\\(\\sw+\\)"
3282 1 'font-lock-constant-face append))))
3284 (setq verilog-font-lock-keywords-2
3285 (append verilog-font-lock-keywords-1
3288 (concat "\\(//\\s-*\\(" verilog-pragma-keywords "\\)\\s-.*\\)")
3289 ;; Fontify escaped names
3290 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
3291 ;; Fontify macro definitions/ uses
3292 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
3293 'font-lock-preprocessor-face
3294 'font-lock-type-face))
3295 ;; Fontify delays/numbers
3296 '("\\(@\\)\\|\\([ \t\n\f\r]#\\s-*\\(\\([0-9_.]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
3297 0 font-lock-type-face append)
3298 ;; Fontify property/sequence cycle delays - these start with '##'
3299 '("\\(##\\(\\sw+\\|\\[[^]]+\\]\\)\\)"
3300 0 font-lock-type-face append)
3301 ;; Fontify instantiation names
3302 '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
3305 (setq verilog-font-lock-keywords-3
3306 (append verilog-font-lock-keywords-2
3307 (when verilog-highlight-translate-off
3309 ;; Fontify things in translate off regions
3310 '(verilog-match-translate-off
3311 (0 'verilog-font-lock-translate-off-face prepend))
3315 ;; Buffer state preservation
3317 (defmacro verilog-save-buffer-state (&rest body)
3318 "Execute BODY forms, saving state around insignificant change.
3319 Changes in text properties like `face' or `syntax-table' are
3320 considered insignificant. This macro allows text properties to
3321 be changed, even in a read-only buffer.
3323 A change is considered significant if it affects the buffer text
3324 in any way that isn't completely restored again. Any
3325 user-visible changes to the buffer must not be within a
3326 `verilog-save-buffer-state'."
3327 `(let ((inhibit-point-motion-hooks t)
3328 (verilog-no-change-functions t))
3329 ,(if (fboundp 'with-silent-modifications)
3330 `(with-silent-modifications ,@body)
3331 ;; Backward compatible version of with-silent-modifications
3332 `(let* ((modified (buffer-modified-p))
3333 (buffer-undo-list t)
3334 (inhibit-read-only t)
3335 (inhibit-modification-hooks t)
3336 ;; XEmacs ignores inhibit-modification-hooks.
3337 before-change-functions after-change-functions
3339 buffer-file-name ; Prevent primitives checking
3340 buffer-file-truename) ; for file modification
3345 (verilog-restore-buffer-modified-p nil)))))))
3348 (defvar verilog-save-font-mod-hooked nil
3349 "Local variable when inside a `verilog-save-font-no-change-functions' block.")
3350 (make-variable-buffer-local 'verilog-save-font-mod-hooked)
3352 (defmacro verilog-save-font-no-change-functions (&rest body)
3353 "Execute BODY forms, disabling all change hooks in BODY.
3354 Includes temporary disabling of `font-lock' to restore the buffer
3355 to full text form for parsing. Additional actions may be specified with
3356 `verilog-before-save-font-hook' and `verilog-after-save-font-hook'.
3357 For insignificant changes, see instead `verilog-save-buffer-state'."
3358 `(if verilog-save-font-mod-hooked ; Short-circuit a recursive call
3360 ;; Before version 20, match-string with font-lock returns a
3361 ;; vector that is not equal to the string. IE if on "input"
3362 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
3363 ;; Therefore we must remove and restore font-lock mode
3364 (verilog-run-hooks 'verilog-before-save-font-hook)
3365 (let* ((verilog-save-font-mod-hooked (- (point-max) (point-min)))
3366 ;; Significant speed savings with no font-lock properties
3367 (fontlocked (when (and (boundp 'font-lock-mode) font-lock-mode)
3370 (run-hook-with-args 'before-change-functions (point-min) (point-max))
3372 ;; Must inhibit and restore hooks before restoring font-lock
3373 (let* ((inhibit-point-motion-hooks t)
3374 (inhibit-modification-hooks t)
3375 (verilog-no-change-functions t)
3376 ;; XEmacs and pre-Emacs 21 ignore inhibit-modification-hooks.
3377 before-change-functions after-change-functions)
3380 (run-hook-with-args 'after-change-functions (point-min) (point-max)
3381 verilog-save-font-mod-hooked) ; old length
3382 (when fontlocked (font-lock-mode t))
3383 (verilog-run-hooks 'verilog-after-save-font-hook)))))
3386 ;; Comment detection and caching
3388 (defvar verilog-scan-cache-preserving nil
3389 "If true, the specified buffer's comment properties are static.
3390 Buffer changes will be ignored. See `verilog-inside-comment-or-string-p'
3391 and `verilog-scan'.")
3393 (defvar verilog-scan-cache-tick nil
3394 "Modification tick at which `verilog-scan' was last completed.")
3395 (make-variable-buffer-local 'verilog-scan-cache-tick)
3397 (defun verilog-scan-cache-flush ()
3398 "Flush the `verilog-scan' cache."
3399 (setq verilog-scan-cache-tick nil))
3401 (defun verilog-scan-cache-ok-p ()
3402 "Return t if the scan cache is up to date."
3403 (or (and verilog-scan-cache-preserving
3404 (eq verilog-scan-cache-preserving (current-buffer))
3405 verilog-scan-cache-tick)
3406 (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
3408 (defmacro verilog-save-scan-cache (&rest body)
3409 "Execute the BODY forms, allowing scan cache preservation within BODY.
3410 This requires that insertions must use `verilog-insert'."
3411 ;; If the buffer is out of date, trash it, as we'll not check later the tick
3412 ;; Note this must work properly if there's multiple layers of calls
3413 ;; to verilog-save-scan-cache even with differing ticks.
3415 (unless (verilog-scan-cache-ok-p) ; Must be before let
3416 (setq verilog-scan-cache-tick nil))
3417 (let* ((verilog-scan-cache-preserving (current-buffer)))
3420 (defun verilog-scan-region (beg end)
3421 "Parse between BEG and END for `verilog-inside-comment-or-string-p'.
3422 This creates v-cmts properties where comments are in force."
3423 ;; Why properties and not overlays? Overlays have much slower non O(1)
3425 ;; This function is warm - called on every verilog-insert
3428 (verilog-save-buffer-state
3431 (while (< (point) end)
3432 (cond ((looking-at "//")
3434 (or (search-forward "\n" end t)
3436 ;; "1+": The leading // or /* itself isn't considered as
3437 ;; being "inside" the comment, so that a (search-backward)
3438 ;; that lands at the start of the // won't mis-indicate
3439 ;; it's inside a comment. Also otherwise it would be
3440 ;; hard to find a commented out /*AS*/ vs one that isn't
3441 (put-text-property (1+ pt) (point) 'v-cmts t))
3442 ((looking-at "/\\*")
3444 (or (search-forward "*/" end t)
3445 ;; No error - let later code indicate it so we can
3446 ;; use inside functions on-the-fly
3447 ;;(error "%s: Unmatched /* */, at char %d"
3448 ;; (verilog-point-text) (point))
3450 (put-text-property (1+ pt) (point) 'v-cmts t))
3453 (or (re-search-forward "[^\\]\"" end t) ; don't forward-char first, since we look for a non backslash first
3454 ;; No error - let later code indicate it so we can
3456 (put-text-property (1+ pt) (point) 'v-cmts t))
3459 (if (re-search-forward "[/\"]" end t)
3461 (goto-char end))))))))))
3463 (defun verilog-scan ()
3464 "Parse the buffer, marking all comments with properties.
3465 Also assumes any text inserted since `verilog-scan-cache-tick'
3466 either is ok to parse as a non-comment, or `verilog-insert' was used."
3467 ;; See also `verilog-scan-debug' and `verilog-scan-and-debug'
3468 (unless (verilog-scan-cache-ok-p)
3470 (verilog-save-buffer-state
3472 (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
3473 verilog-scan-cache-preserving verilog-scan-cache-tick
3474 (buffer-chars-modified-tick)))
3475 (remove-text-properties (point-min) (point-max) '(v-cmts nil))
3476 (verilog-scan-region (point-min) (point-max))
3477 (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
3478 (when verilog-debug (message "Scanning... done"))))))
3480 (defun verilog-scan-debug ()
3481 "For debugging, show with display face results of `verilog-scan'."
3483 ;;(if dbg (setq dbg (concat dbg (format "verilog-scan-debug\n"))))
3485 (goto-char (point-min))
3486 (remove-text-properties (point-min) (point-max) '(face nil))
3488 (cond ((get-text-property (point) 'v-cmts)
3489 (put-text-property (point) (1+ (point)) `face 'underline)
3490 ;;(if dbg (setq dbg (concat dbg (format " v-cmts at %S\n" (point)))))
3493 (goto-char (or (next-property-change (point)) (point-max))))))))
3495 (defun verilog-scan-and-debug ()
3496 "For debugging, run `verilog-scan' and `verilog-scan-debug'."
3497 (let (verilog-scan-cache-preserving
3498 verilog-scan-cache-tick)
3499 (goto-char (point-min))
3501 (verilog-scan-debug)))
3503 (defun verilog-inside-comment-or-string-p (&optional pos)
3504 "Check if optional point POS is inside a comment.
3505 This may require a slow pre-parse of the buffer with `verilog-scan'
3506 to establish comment properties on all text."
3507 ;; This function is very hot
3510 (and (>= pos (point-min))
3511 (get-text-property pos 'v-cmts))
3512 (get-text-property (point) 'v-cmts)))
3514 (defun verilog-insert (&rest stuff)
3515 "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
3516 Any insert that includes a comment must have the entire comment
3517 inserted using a single call to `verilog-insert'."
3520 (insert (car stuff))
3521 (setq stuff (cdr stuff)))
3522 (verilog-scan-region pt (point))))
3526 (defun verilog-declaration-end ()
3527 (search-forward ";"))
3529 (defun verilog-point-text (&optional pointnum)
3530 "Return text describing where POINTNUM or current point is (for errors).
3531 Use filename, if current buffer being edited shorten to just buffer name."
3532 (concat (or (and (equal (window-buffer) (current-buffer))
3536 ":" (int-to-string (1+ (count-lines (point-min) (or pointnum (point)))))))
3538 (defun electric-verilog-backward-sexp ()
3539 "Move backward over one balanced expression."
3541 ;; before that see if we are in a comment
3542 (verilog-backward-sexp))
3544 (defun electric-verilog-forward-sexp ()
3545 "Move forward over one balanced expression."
3547 ;; before that see if we are in a comment
3548 (verilog-forward-sexp))
3550 (defun verilog-forward-sexp-function (arg)
3551 "Move forward ARG sexps."
3552 ;; Used by hs-minor-mode
3554 (verilog-backward-sexp)
3555 (verilog-forward-sexp)))
3557 (defun verilog-backward-sexp ()
3562 (if (not (looking-at "\\<"))
3563 (forward-word-strictly -1))
3565 ((verilog-skip-backward-comment-or-string))
3566 ((looking-at "\\<else\\>")
3568 verilog-end-block-re
3569 "\\|\\(\\<else\\>\\)"
3570 "\\|\\(\\<if\\>\\)"))
3571 (while (and (not found)
3572 (verilog-re-search-backward reg nil 'move))
3574 ((match-end 1) ; matched verilog-end-block-re
3575 ;; try to leap back to matching outward block by striding across
3576 ;; indent level changing tokens then immediately
3577 ;; previous line governs indentation.
3578 (verilog-leap-to-head))
3579 ((match-end 2) ; else, we're in deep
3580 (setq elsec (1+ elsec)))
3581 ((match-end 3) ; found it
3582 (setq elsec (1- elsec))
3584 ;; Now previous line describes syntax
3585 (setq found 't))))))
3586 ((looking-at verilog-end-block-re)
3587 (verilog-leap-to-head))
3588 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
3591 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
3593 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
3595 (verilog-re-search-backward "\\<class\\>" nil 'move))
3597 (verilog-re-search-backward "\\<program\\>" nil 'move))
3599 (verilog-re-search-backward "\\<interface\\>" nil 'move))
3601 (verilog-re-search-backward "\\<package\\>" nil 'move))
3604 (backward-sexp 1))))
3609 (defun verilog-forward-sexp ()
3614 (if (not (looking-at "\\<"))
3615 (forward-word-strictly -1))
3617 ((verilog-skip-forward-comment-or-string)
3618 (verilog-forward-syntactic-ws))
3619 ((looking-at verilog-beg-block-re-ordered)
3622 ;; Search forward for matching end
3623 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
3625 ;; Search forward for matching endcase
3626 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique0?\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
3627 (setq md 3) ; ender is third item in regexp
3630 ;; might be "disable fork" or "wait fork"
3634 (looking-at verilog-disable-fork-re)
3635 (and (looking-at "fork")
3637 (setq here (point)) ; sometimes a fork is just a fork
3638 (forward-word-strictly -1)
3639 (looking-at verilog-disable-fork-re))))
3640 (progn ; it is a disable fork; ignore it
3641 (goto-char (match-end 0))
3642 (forward-word-strictly 1)
3644 (progn ; it is a nice simple fork
3645 (goto-char here) ; return from looking for "disable fork"
3646 ;; Search forward for matching join
3647 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))))
3649 ;; Search forward for matching endclass
3650 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
3653 ;; Search forward for matching endtable
3654 (setq reg "\\<endtable\\>" )
3657 ;; Search forward for matching endspecify
3658 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
3660 ;; Search forward for matching endfunction
3661 (setq reg "\\<endfunction\\>" )
3664 ;; Search forward for matching endfunction
3665 (setq reg "\\<endfunction\\>" )
3668 ;; Search forward for matching endtask
3669 (setq reg "\\<endtask\\>" )
3672 ;; Search forward for matching endtask
3673 (setq reg "\\<endtask\\>" )
3676 ;; Search forward for matching endgenerate
3677 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
3679 ;; Search forward for matching endgroup
3680 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
3682 ;; Search forward for matching endproperty
3683 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
3685 ;; Search forward for matching endsequence
3686 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
3687 (setq md 3)) ; 3 to get to endsequence in the reg above
3689 ;; Search forward for matching endclocking
3690 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
3692 (forward-word-strictly 1))
3697 (while (verilog-re-search-forward reg nil 'move)
3699 ((match-end md) ; a closer in regular expression, so we are climbing out
3700 (setq depth (1- depth))
3701 (if (= 0 depth) ; we are out!
3703 ((match-end 1) ; an opener in the r-e, so we are in deeper now
3704 (setq here (point)) ; remember where we started
3705 (goto-char (match-beginning 1))
3708 (looking-at verilog-disable-fork-re)
3709 (and (looking-at "fork")
3711 (forward-word-strictly -1)
3712 (looking-at verilog-disable-fork-re))))
3713 (progn ; it is a disable fork; another false alarm
3714 (goto-char (match-end 0)))
3715 (progn ; it is a simple fork (or has nothing to do with fork)
3717 (setq depth (1+ depth))))))))))
3718 (if (verilog-re-search-forward reg nil 'move)
3719 (throw 'skip 1))))))
3721 ((looking-at (concat
3722 "\\(\\<\\(macro\\)?module\\>\\)\\|"
3723 "\\(\\<primitive\\>\\)\\|"
3724 "\\(\\<class\\>\\)\\|"
3725 "\\(\\<program\\>\\)\\|"
3726 "\\(\\<interface\\>\\)\\|"
3727 "\\(\\<package\\>\\)"))
3730 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
3732 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
3734 (verilog-re-search-forward "\\<endclass\\>" nil 'move))
3736 (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
3738 (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
3740 (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
3743 (if (= (following-char) ?\) )
3745 (forward-sexp 1)))))
3748 (if (= (following-char) ?\) )
3750 (forward-sexp 1))))))
3752 (defun verilog-declaration-beg ()
3753 (verilog-re-search-backward verilog-declaration-re (bobp) t))
3759 (defvar verilog-which-tool 1)
3761 (define-derived-mode verilog-mode prog-mode "Verilog"
3762 "Major mode for editing Verilog code.
3763 \\<verilog-mode-map>
3764 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
3765 AUTOs can improve coding efficiency.
3767 Use \\[verilog-faq] for a pointer to frequently asked questions.
3769 NEWLINE, TAB indents for Verilog code.
3770 Delete converts tabs to spaces as it moves back.
3772 Supports highlighting.
3774 Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
3775 with no args, if that value is non-nil.
3777 Variables controlling indentation/edit style:
3779 variable `verilog-indent-level' (default 3)
3780 Indentation of Verilog statements with respect to containing block.
3781 `verilog-indent-level-module' (default 3)
3782 Absolute indentation of Module level Verilog statements.
3783 Set to 0 to get initial and always statements lined up
3784 on the left side of your screen.
3785 `verilog-indent-level-declaration' (default 3)
3786 Indentation of declarations with respect to containing block.
3787 Set to 0 to get them list right under containing block.
3788 `verilog-indent-level-behavioral' (default 3)
3789 Indentation of first begin in a task or function block
3790 Set to 0 to get such code to lined up underneath the task or
3792 `verilog-indent-level-directive' (default 1)
3793 Indentation of \\=`ifdef/\\=`endif blocks.
3794 `verilog-cexp-indent' (default 1)
3795 Indentation of Verilog statements broken across lines i.e.:
3798 `verilog-case-indent' (default 2)
3799 Indentation for case statements.
3800 `verilog-auto-newline' (default nil)
3801 Non-nil means automatically newline after semicolons and the punctuation
3803 `verilog-auto-indent-on-newline' (default t)
3804 Non-nil means automatically indent line after newline.
3805 `verilog-tab-always-indent' (default t)
3806 Non-nil means TAB in Verilog mode should always reindent the current line,
3807 regardless of where in the line point is when the TAB command is used.
3808 `verilog-indent-begin-after-if' (default t)
3809 Non-nil means to indent begin statements following a preceding
3810 if, else, while, for and repeat statements, if any. Otherwise,
3811 the begin is lined up with the preceding token. If t, you get:
3813 begin // amount of indent based on `verilog-cexp-indent'
3817 `verilog-auto-endcomments' (default t)
3818 Non-nil means a comment /* ... */ is set after the ends which ends
3819 cases, tasks, functions and modules.
3820 The type and name of the object will be set between the braces.
3821 `verilog-minimum-comment-distance' (default 10)
3822 Minimum distance (in lines) between begin and end required before a comment
3823 will be inserted. Setting this variable to zero results in every
3824 end acquiring a comment; the default avoids too many redundant
3825 comments in tight quarters.
3826 `verilog-auto-lineup' (default `declarations')
3827 List of contexts where auto lineup of code should be done.
3829 Variables controlling other actions:
3831 `verilog-linter' (default `surelint')
3832 Unix program to call to run the lint checker. This is the default
3833 command for \\[compile-command] and \\[verilog-auto-save-compile].
3835 See \\[customize] for the complete list of variables.
3837 AUTO expansion functions are, in part:
3839 \\[verilog-auto] Expand AUTO statements.
3840 \\[verilog-delete-auto] Remove the AUTOs.
3841 \\[verilog-inject-auto] Insert AUTOs for the first time.
3843 Some other functions are:
3845 \\[completion-at-point] Complete word with appropriate possibilities.
3846 \\[verilog-mark-defun] Mark function.
3847 \\[verilog-beg-of-defun] Move to beginning of current function.
3848 \\[verilog-end-of-defun] Move to end of current function.
3849 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
3851 \\[verilog-comment-region] Put marked area in a comment.
3852 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
3853 \\[verilog-insert-block] Insert begin ... end.
3854 \\[verilog-star-comment] Insert /* ... */.
3856 \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
3857 \\[verilog-sk-begin] Insert a begin .. end block.
3858 \\[verilog-sk-case] Insert a case block, prompting for details.
3859 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
3860 \\[verilog-sk-generate] Insert a generate .. endgenerate block.
3861 \\[verilog-sk-header] Insert a header block at the top of file.
3862 \\[verilog-sk-initial] Insert an initial begin .. end block.
3863 \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
3864 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
3865 \\[verilog-sk-ovm-class] Insert an OVM Class block.
3866 \\[verilog-sk-uvm-object] Insert an UVM Object block.
3867 \\[verilog-sk-uvm-component] Insert an UVM Component block.
3868 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
3869 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
3870 \\[verilog-sk-specify] Insert a specify .. endspecify block.
3871 \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
3872 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
3873 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
3874 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
3875 \\[verilog-sk-if] Insert an if (..) begin .. end block.
3876 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
3877 \\[verilog-sk-comment] Insert a comment block.
3878 \\[verilog-sk-assign] Insert an assign .. = ..; statement.
3879 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
3880 \\[verilog-sk-input] Insert an input declaration, prompting for details.
3881 \\[verilog-sk-output] Insert an output declaration, prompting for details.
3882 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
3883 \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
3884 \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
3885 \\[verilog-sk-reg] Insert a register declaration, prompting for details.
3886 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
3888 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
3889 Key bindings specific to `verilog-mode-map' are:
3891 \\{verilog-mode-map}"
3892 :abbrev-table verilog-mode-abbrev-table
3893 (set (make-local-variable 'beginning-of-defun-function)
3894 'verilog-beg-of-defun)
3895 (set (make-local-variable 'end-of-defun-function)
3896 'verilog-end-of-defun)
3897 (set-syntax-table verilog-mode-syntax-table)
3898 (set (make-local-variable 'indent-line-function)
3899 #'verilog-indent-line-relative)
3900 (set (make-local-variable 'comment-indent-function) 'verilog-comment-indent)
3901 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
3902 (set (make-local-variable 'comment-start) "// ")
3903 (set (make-local-variable 'comment-end) "")
3904 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
3905 (set (make-local-variable 'comment-multi-line) nil)
3906 ;; Set up for compilation
3907 (setq verilog-which-tool 1)
3908 (setq verilog-tool 'verilog-linter)
3909 (verilog-set-compile-command)
3910 (when (boundp 'hack-local-variables-hook) ; Also modify any file-local-variables
3911 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
3914 (when (featurep 'xemacs)
3915 (easy-menu-add verilog-stmt-menu)
3916 (easy-menu-add verilog-menu)
3917 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
3919 ;; Stuff for GNU Emacs
3920 (set (make-local-variable 'font-lock-defaults)
3921 `((verilog-font-lock-keywords
3922 verilog-font-lock-keywords-1
3923 verilog-font-lock-keywords-2
3924 verilog-font-lock-keywords-3)
3926 ,(if (functionp 'syntax-ppss)
3927 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
3928 ;; font-lock-beginning-of-syntax-function, so
3929 ;; font-lock-beginning-of-syntax-function, can't use
3930 ;; verilog-beg-of-defun.
3932 'verilog-beg-of-defun)))
3933 ;;------------------------------------------------------------
3934 ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
3935 ;; all buffer local:
3936 (unless noninteractive ; Else can't see the result, and change hooks are slow
3937 (when (featurep 'xemacs)
3938 (make-local-hook 'font-lock-mode-hook)
3939 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
3940 (make-local-hook 'after-change-functions))
3941 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
3942 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
3943 (add-hook 'after-change-functions 'verilog-highlight-region t t))
3945 ;; Tell imenu how to handle Verilog.
3946 (set (make-local-variable 'imenu-generic-expression)
3947 verilog-imenu-generic-expression)
3948 ;; Tell which-func-modes that imenu knows about verilog
3949 (when (and (boundp 'which-func-modes) (listp which-func-modes))
3950 (add-to-list 'which-func-modes 'verilog-mode))
3952 (when (boundp 'hs-special-modes-alist)
3953 (unless (assq 'verilog-mode hs-special-modes-alist)
3954 (setq hs-special-modes-alist
3955 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
3956 verilog-forward-sexp-function)
3957 hs-special-modes-alist))))
3959 (add-hook 'completion-at-point-functions
3960 #'verilog-completion-at-point nil 'local)
3963 (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local)
3964 ;; verilog-mode-hook call added by define-derived-mode
3967 ;;; Integration with the speedbar
3970 ;; Avoid problems with XEmacs byte-compiles.
3971 ;; For GNU Emacs, the eval-after-load will handle if it isn't loaded yet.
3972 (when (eval-when-compile (fboundp 'declare-function))
3973 (declare-function speedbar-add-supported-extension "speedbar" (extension)))
3975 (defun verilog-speedbar-initialize ()
3976 "Initialize speedbar to understand `verilog-mode'."
3977 ;; Set Verilog file extensions (extracted from `auto-mode-alist')
3978 (let ((mode-alist auto-mode-alist))
3980 (when (eq (cdar mode-alist) 'verilog-mode)
3981 (speedbar-add-supported-extension (caar mode-alist)))
3982 (setq mode-alist (cdr mode-alist)))))
3984 ;; If the speedbar is loaded, execute initialization instructions right away,
3985 ;; otherwise add the initialization instructions to the speedbar loader.
3986 (eval-after-load "speedbar" '(verilog-speedbar-initialize))
3989 ;;; Electric functions:
3992 (defun electric-verilog-terminate-line (&optional arg)
3993 "Terminate line and indent next line.
3994 With optional ARG, remove existing end of line comments."
3996 ;; before that see if we are in a comment
3997 (let ((state (save-excursion (verilog-syntax-ppss))))
3999 ((nth 7 state) ; Inside // comment
4002 (delete-horizontal-space)
4007 (beginning-of-line)))
4008 (verilog-indent-line))
4009 ((nth 4 state) ; Inside any comment (hence /**/)
4011 (verilog-more-comment))
4013 ;; First, check if current line should be indented
4015 (delete-horizontal-space)
4017 (skip-chars-forward " \t")
4018 (if (looking-at verilog-auto-end-comment-lines-re)
4019 (let ((indent-str (verilog-indent-line)))
4020 ;; Maybe we should set some endcomments
4021 (if verilog-auto-endcomments
4022 (verilog-set-auto-endcomments indent-str arg))
4024 (delete-horizontal-space)
4031 (delete-horizontal-space)
4033 ;; see if we should line up assignments
4035 (if (or (eq 'all verilog-auto-lineup)
4036 (eq 'assignments verilog-auto-lineup))
4037 (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
4041 (if verilog-auto-indent-on-newline
4042 (verilog-indent-line)))
4046 (defun electric-verilog-terminate-and-indent ()
4047 "Insert a newline and indent for the next statement."
4049 (electric-verilog-terminate-line 1))
4051 (defun electric-verilog-semi ()
4052 "Insert `;' character and reindent the line."
4054 (verilog-insert-last-command-event)
4056 (if (or (verilog-in-comment-or-string-p)
4057 (verilog-in-escaped-name-p))
4061 (verilog-forward-ws&directives)
4062 (verilog-indent-line))
4063 (if (and verilog-auto-newline
4064 (not (verilog-parenthesis-depth)))
4065 (electric-verilog-terminate-line))))
4067 (defun electric-verilog-semi-with-comment ()
4068 "Insert `;' character, reindent the line and indent for comment."
4073 (verilog-indent-line))
4074 (indent-for-comment))
4076 (defun electric-verilog-colon ()
4077 "Insert `:' and do all indentations except line indent on this line."
4079 (verilog-insert-last-command-event)
4080 ;; Do nothing if within string.
4082 (verilog-within-string)
4083 (not (verilog-in-case-region-p)))
4087 (lim (progn (verilog-beg-of-statement) (point))))
4089 (verilog-backward-case-item lim)
4090 (verilog-indent-line)))
4091 ;; (let ((verilog-tab-always-indent nil))
4092 ;; (verilog-indent-line))
4095 ;;(defun electric-verilog-equal ()
4096 ;; "Insert `=', and do indentation if within block."
4098 ;; (verilog-insert-last-command-event)
4099 ;; Could auto line up expressions, but not yet
4100 ;; (if (eq (car (verilog-calculate-indent)) 'block)
4101 ;; (let ((verilog-tab-always-indent nil))
4102 ;; (verilog-indent-command)))
4105 (defun electric-verilog-tick ()
4106 "Insert back-tick, and indent to column 0 if this is a CPP directive."
4108 (verilog-insert-last-command-event)
4110 (if (verilog-in-directive-p)
4111 (verilog-indent-line))))
4113 (defun electric-verilog-tab ()
4114 "Function called when TAB is pressed in Verilog mode."
4116 ;; If verilog-tab-always-indent, indent the beginning of the line.
4118 ;; The region is active, indent it.
4119 ((and (region-active-p)
4120 (not (eq (region-beginning) (region-end))))
4121 (indent-region (region-beginning) (region-end) nil))
4122 ((or verilog-tab-always-indent
4124 (skip-chars-backward " \t")
4126 (let* ((oldpnt (point))
4130 (skip-chars-forward " \t")
4131 (verilog-indent-line)
4132 (back-to-indentation)
4134 (if (< (point) boi-point)
4135 (back-to-indentation)
4136 (cond ((not verilog-tab-to-comment))
4140 (indent-for-comment)
4141 (when (and (eolp) (= oldpnt (point)))
4142 ;; kill existing comment
4144 (re-search-forward comment-start-skip oldpnt 'move)
4145 (goto-char (match-beginning 0))
4146 (skip-chars-backward " \t")
4147 (kill-region (point) oldpnt)))))))
4148 (t (progn (insert "\t")))))
4151 ;;; Interactive functions:
4154 (defun verilog-indent-buffer ()
4155 "Indent-region the entire buffer as Verilog code.
4156 To call this from the command line, see \\[verilog-batch-indent]."
4159 (indent-region (point-min) (point-max) nil))
4161 (defun verilog-insert-block ()
4162 "Insert Verilog begin ... end; block in the code with right indentation."
4164 (verilog-indent-line)
4166 (electric-verilog-terminate-line)
4168 (electric-verilog-terminate-line)
4171 (verilog-indent-line)))
4173 (defun verilog-star-comment ()
4174 "Insert Verilog star comment at point."
4176 (verilog-indent-line)
4184 (defun verilog-insert-1 (fmt max)
4185 "Use format string FMT to insert integers 0 to MAX - 1.
4186 Inserts one integer per line, at the current column. Stops early
4187 if it reaches the end of the buffer."
4188 (let ((col (current-column))
4192 (insert (format fmt n))
4194 ;; Note that this function does not bother to check for lines
4195 ;; shorter than col.
4199 (move-to-column col))))))
4201 (defun verilog-insert-indices (max)
4202 "Insert a set of indices into a rectangle.
4203 The upper left corner is defined by point. Indices begin with 0
4204 and extend to the MAX - 1. If no prefix arg is given, the user
4205 is prompted for a value. The indices are surrounded by square
4206 brackets []. For example, the following code with the point
4207 located after the first `a' gives:
4213 a = b ==> insert-indices ==> a[ 4] = b
4219 (interactive "NMAX: ")
4220 (verilog-insert-1 "[%3d]" max))
4222 (defun verilog-generate-numbers (max)
4223 "Insert a set of generated numbers into a rectangle.
4224 The upper left corner is defined by point. The numbers are padded to three
4225 digits, starting with 000 and extending to (MAX - 1). If no prefix argument
4226 is supplied, then the user is prompted for the MAX number. Consider the
4227 following code fragment:
4233 buf buf ==> generate-numbers ==> buf buf004
4239 (interactive "NMAX: ")
4240 (verilog-insert-1 "%3.3d" max))
4242 (defun verilog-mark-defun ()
4243 "Mark the current Verilog function (or procedure).
4244 This puts the mark at the end, and point at the beginning."
4246 (if (featurep 'xemacs)
4249 (verilog-end-of-defun)
4251 (verilog-beg-of-defun)
4252 (if (fboundp 'zmacs-activate-region)
4253 (zmacs-activate-region)))
4256 (defun verilog-comment-region (start end)
4257 ;; checkdoc-params: (start end)
4258 "Put the region into a Verilog comment.
4259 The comments that are in this area are \"deformed\":
4260 `*)' becomes `!(*' and `}' becomes `!{'.
4261 These deformed comments are returned to normal if you use
4262 \\[verilog-uncomment-region] to undo the commenting.
4264 The commented area starts with `verilog-exclude-str-start', and ends with
4265 `verilog-exclude-str-end'. But if you change these variables,
4266 \\[verilog-uncomment-region] won't recognize the comments."
4269 ;; Insert start and endcomments
4271 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
4272 (not (save-excursion (skip-chars-backward " \t") (bolp))))
4274 (beginning-of-line))
4275 (insert verilog-exclude-str-end)
4280 (insert verilog-exclude-str-start)
4282 ;; Replace end-comments within commented area
4285 (while (re-search-backward "\\*/" start t)
4286 (replace-match "*-/" t t)))
4288 (let ((s+1 (1+ start)))
4289 (while (re-search-backward "/\\*" s+1 t)
4290 (replace-match "/-*" t t))))))
4292 (defun verilog-uncomment-region ()
4293 "Uncomment a commented area; change deformed comments back to normal.
4294 This command does nothing if the pointer is not in a commented
4295 area. See also `verilog-comment-region'."
4298 (let ((start (point))
4300 ;; Find the boundaries of the comment
4302 (setq start (progn (search-backward verilog-exclude-str-start nil t)
4304 (setq end (progn (search-forward verilog-exclude-str-end nil t)
4306 ;; Check if we're really inside a comment
4307 (if (or (equal start (point)) (<= end (point)))
4308 (message "Not standing within commented area.")
4310 ;; Remove endcomment
4313 (let ((pos (point)))
4315 (delete-region pos (1+ (point))))
4316 ;; Change comments back to normal
4318 (while (re-search-backward "\\*-/" start t)
4319 (replace-match "*/" t t)))
4321 (while (re-search-backward "/-\\*" start t)
4322 (replace-match "/*" t t)))
4323 ;; Remove start comment
4326 (let ((pos (point)))
4328 (delete-region pos (1+ (point)))))))))
4330 (defun verilog-beg-of-defun ()
4331 "Move backward to the beginning of the current function or procedure."
4333 (verilog-re-search-backward verilog-defun-re nil 'move))
4335 (defun verilog-beg-of-defun-quick ()
4336 "Move backward to the beginning of the current function or procedure.
4337 Uses `verilog-scan' cache."
4339 (verilog-re-search-backward-quick verilog-defun-re nil 'move))
4341 (defun verilog-end-of-defun ()
4342 "Move forward to the end of the current function or procedure."
4344 (verilog-re-search-forward verilog-end-defun-re nil 'move))
4346 (defun verilog-get-end-of-defun ()
4348 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
4351 (error "%s: Can't find endmodule" (verilog-point-text))
4354 (defun verilog-label-be ()
4355 "Label matching begin ... end, fork ... join and case ... endcase statements."
4358 (case-fold-search nil)
4361 (verilog-beg-of-defun)
4364 (verilog-end-of-defun)
4366 (goto-char (marker-position b))
4368 (message "Relabeling module..."))
4370 (> (marker-position e) (point))
4371 (verilog-re-search-forward
4372 verilog-auto-end-comment-lines-re
4374 (goto-char (match-beginning 0))
4375 (let ((indent-str (verilog-indent-line)))
4376 (verilog-set-auto-endcomments indent-str 't)
4378 (delete-horizontal-space))
4380 (if (= 9 (% cnt 10))
4381 (message "%d..." cnt)))
4386 (message "%d lines auto commented" cnt))))
4388 (defun verilog-beg-of-statement ()
4389 "Move backward to beginning of statement."
4391 ;; Move back token by token until we see the end
4392 ;; of some earlier line.
4395 ;; If the current point does not begin a new
4396 ;; statement, as in the character ahead of us is a ';', or SOF
4397 ;; or the string after us unambiguously starts a statement,
4398 ;; or the token before us unambiguously ends a statement,
4399 ;; then move back a token and test again.
4401 ;; stop if beginning of buffer
4403 ;; stop if looking at a pre-processor directive
4404 (looking-at "`\\w+")
4405 ;; stop if we find a ;
4406 (= (preceding-char) ?\;)
4407 ;; stop if we see a named coverpoint
4408 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
4409 ;; keep going if we are in the middle of a word
4410 (not (or (looking-at "\\<") (forward-word-strictly -1)))
4411 ;; stop if we see an assertion (perhaps labeled)
4413 (looking-at "\\(\\w+\\W*:\\W*\\)?\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
4417 (verilog-backward-token)
4418 (if (and (looking-at verilog-label-re)
4419 (not (looking-at verilog-end-block-re)))
4422 ;; stop if we see an extended complete reg, perhaps a complete one
4424 (looking-at verilog-complete-reg)
4426 (while (and (looking-at verilog-extended-complete-re)
4427 (progn (setq p (point))
4428 (verilog-backward-token)
4431 ;; stop if we see a complete reg (previous found extended ones)
4432 (looking-at verilog-basic-complete-re)
4433 ;; stop if previous token is an ender
4435 (verilog-backward-token)
4436 (looking-at verilog-end-block-re))))
4437 (verilog-backward-syntactic-ws)
4438 (verilog-backward-token))
4439 ;; Now point is where the previous line ended.
4440 (verilog-forward-syntactic-ws)
4441 ;; Skip forward over any preprocessor directives, as they have wacky indentation
4442 (if (looking-at verilog-preprocessor-re)
4443 (progn (goto-char (match-end 0))
4444 (verilog-forward-syntactic-ws)))))
4446 (defun verilog-beg-of-statement-1 ()
4447 "Move backward to beginning of statement."
4449 (if (verilog-in-comment-p)
4450 (verilog-backward-syntactic-ws))
4453 (while (not (looking-at verilog-complete-reg))
4455 (verilog-backward-syntactic-ws)
4457 (= (preceding-char) ?\;)
4459 (verilog-backward-token)
4460 (looking-at verilog-ends-re)))
4464 (verilog-forward-syntactic-ws)))
4467 ;; (not (looking-at verilog-complete-reg))
4469 ;; (not (= (preceding-char) ?\;)))
4470 ;; (verilog-backward-token)
4471 ;; (verilog-backward-syntactic-ws)
4472 ;; (setq pt (point)))
4474 ;; ;(verilog-forward-syntactic-ws)
4476 (defun verilog-end-of-statement ()
4477 "Move forward to end of current statement."
4481 ((verilog-in-directive-p)
4485 ((looking-at verilog-beg-block-re)
4486 (verilog-forward-sexp))
4488 ((equal (char-after) ?\})
4491 ;; Skip to end of statement
4492 ((condition-case nil
4497 (verilog-skip-forward-comment-or-string)
4500 (cond ((looking-at "[ \t]*;")
4501 (skip-chars-forward "^;")
4503 (throw 'found (point)))
4506 (looking-at verilog-beg-block-re))
4507 (goto-char (match-beginning 0))
4509 ((looking-at "[ \t]*)")
4510 (throw 'found (point)))
4512 (throw 'found (point)))
4518 ;; Skip a whole block
4521 (verilog-re-search-forward verilog-end-statement-re nil 'move)
4522 (setq nest (if (match-end 1)
4526 (throw 'found (point)))
4528 (throw 'found (verilog-end-of-statement))))))
4531 (defun verilog-in-case-region-p ()
4532 "Return true if in a case region.
4533 More specifically, point @ in the line foo : @ begin"
4537 (progn (verilog-forward-syntactic-ws)
4538 (looking-at "\\<begin\\>"))
4539 (progn (verilog-backward-syntactic-ws)
4540 (= (preceding-char) ?\:)))
4544 (verilog-re-search-backward
4545 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
4546 "\\(\\<endcase\\>\\)\\>")
4550 (setq nest (1+ nest)))
4554 (setq nest (1- nest)))
4556 (throw 'found (= nest 0)))))))
4559 (defun verilog-backward-up-list (arg)
4560 "Call `backward-up-list' ARG, ignoring comments."
4561 (let ((parse-sexp-ignore-comments t))
4562 (backward-up-list arg)))
4564 (defun verilog-forward-sexp-cmt (arg)
4565 "Call `forward-sexp' ARG, inside comments."
4566 (let ((parse-sexp-ignore-comments nil))
4567 (forward-sexp arg)))
4569 (defun verilog-forward-sexp-ign-cmt (arg)
4570 "Call `forward-sexp' ARG, ignoring comments."
4571 (let ((parse-sexp-ignore-comments t))
4572 (forward-sexp arg)))
4574 (defun verilog-in-generate-region-p ()
4575 "Return true if in a generate region.
4576 More specifically, after a generate and before an endgenerate."
4583 (verilog-re-search-backward
4584 "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
4586 ((match-end 1) ; module - we have crawled out
4588 ((match-end 2) ; generate
4589 (setq nest (1- nest)))
4590 ((match-end 3) ; endgenerate
4591 (setq nest (1+ nest))))))))
4592 (= nest 0) )) ; return nest
4594 (defun verilog-in-fork-region-p ()
4595 "Return true if between a fork and join."
4597 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
4602 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
4604 ((match-end 1) ; fork
4605 (setq nest (1- nest)))
4606 ((match-end 2) ; join
4607 (setq nest (1+ nest)))))))
4608 (= nest 0) )) ; return nest
4610 (defun verilog-in-deferred-immediate-final-p ()
4611 "Return true if inside an `assert/assume/cover final' statement."
4613 (and (looking-at "final")
4614 (verilog-looking-back "\\<\\(?:assert\\|assume\\|cover\\)\\>\\s-+" nil))
4617 (defun verilog-backward-case-item (lim)
4618 "Skip backward to nearest enclosing case item.
4619 Limit search to point LIM."
4625 (verilog-re-search-backward verilog-endcomment-reason-re
4628 ;; Try to find the real :
4629 (if (save-excursion (search-backward ":" lim1 t))
4635 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
4639 (setq colon (1+ colon))
4641 (error "%s: unbalanced [" (verilog-point-text))))
4643 (setq colon (1- colon)))
4646 (setq colon (1+ colon)))))
4647 ;; Skip back to beginning of case item
4648 (skip-chars-backward "\t ")
4649 (verilog-skip-backward-comment-or-string)
4654 (verilog-re-search-backward
4655 "\\<\\(randcase\\|case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
4659 (goto-char (match-end 1))
4660 (verilog-forward-ws&directives)
4661 (if (looking-at "(")
4664 (verilog-forward-ws&directives)))
4667 (goto-char (match-end 0))
4668 (verilog-forward-ws&directives)
4670 (error "Malformed case item"))))
4671 (setq str (buffer-substring b e))
4675 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4676 (setq str (concat (substring str 0 e) "...")))
4680 ;;; Other functions:
4683 (defun verilog-kill-existing-comment ()
4684 "Kill auto comment on this line."
4692 (search-forward "//" e t))))
4694 (delete-region (- b 2) e)))))
4696 (defconst verilog-directive-nest-re
4697 (concat "\\(`else\\>\\)\\|"
4698 "\\(`endif\\>\\)\\|"
4700 "\\(`ifdef\\>\\)\\|"
4701 "\\(`ifndef\\>\\)\\|"
4704 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
4705 "Add ending comment with given INDENT-STR.
4706 With KILL-EXISTING-COMMENT, remove what was there before.
4707 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
4708 Insert `// case expr ' if this line ends a case block.
4709 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
4710 Insert `// NAME ' if this line ends a function, task, module,
4711 primitive or interface named NAME."
4714 (; Comment close preprocessor directives
4716 (looking-at "\\(`endif\\)\\|\\(`else\\)")
4717 (or kill-existing-comment
4718 (not (save-excursion
4720 (search-backward "//" (point-at-bol) t)))))
4723 (else (if (match-end 2) "!" " ")))
4725 (if kill-existing-comment
4726 (verilog-kill-existing-comment))
4727 (delete-horizontal-space)
4730 (while (and (/= nest 0)
4731 (verilog-re-search-backward verilog-directive-nest-re nil 'move))
4733 ((match-end 1) ; `else
4736 ((match-end 2) ; `endif
4737 (setq nest (1+ nest)))
4738 ((match-end 3) ; `if
4739 (setq nest (1- nest)))
4740 ((match-end 4) ; `ifdef
4741 (setq nest (1- nest)))
4742 ((match-end 5) ; `ifndef
4743 (setq nest (1- nest)))
4744 ((match-end 6) ; `elsif
4755 (skip-chars-forward "^ \t")
4756 (verilog-forward-syntactic-ws)
4759 (skip-chars-forward "a-zA-Z0-9_")
4762 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
4763 (insert (concat " // " else m " " (buffer-substring b e))))
4765 (insert " // unmatched `else, `elsif or `endif")
4768 (; Comment close case/class/function/task/module and named block
4769 (and (looking-at "\\<end")
4770 (or kill-existing-comment
4771 (not (save-excursion
4773 (search-backward "//" (point-at-bol) t)))))
4774 (let ((type (car indent-str)))
4775 (unless (eq type 'declaration)
4776 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ; ignore named ends
4777 (if (looking-at verilog-end-block-ordered-re)
4779 (;- This is a case block; search back for the start of this case
4780 (match-end 1) ; of verilog-end-block-ordered-re
4783 (str "UNMATCHED!!"))
4785 (verilog-leap-to-head)
4787 ((looking-at "\\<randcase\\>")
4788 (setq str "randcase")
4790 ((looking-at "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
4791 (goto-char (match-end 0))
4792 (setq str (concat (match-string 0) " " (verilog-get-expr)))
4796 (if kill-existing-comment
4797 (verilog-kill-existing-comment))
4798 (delete-horizontal-space)
4799 (insert (concat " // " str ))
4800 (if err (ding 't))))
4802 (;- This is a begin..end block
4803 (match-end 2) ; of verilog-end-block-ordered-re
4804 (let ((str " // UNMATCHED !!")
4810 (verilog-leap-to-head)
4811 (setq there (point))
4812 (if (not (match-end 0))
4816 (if kill-existing-comment
4817 (verilog-kill-existing-comment))
4818 (delete-horizontal-space)
4822 (save-excursion (verilog-beg-of-defun) (point)))
4825 (;-- handle named block differently
4826 (looking-at verilog-named-block-re)
4827 (search-forward ":")
4828 (setq there (point))
4829 (setq str (verilog-get-expr))
4831 (setq str (concat " // block: " str )))
4833 ((verilog-in-case-region-p) ;-- handle case item differently
4835 (setq str (verilog-backward-case-item lim))
4836 (setq there (point))
4838 (setq str (concat " // case: " str )))
4840 (;- try to find "reason" for this begin
4844 ;; (verilog-backward-token)
4845 (verilog-beg-of-statement)
4849 ((looking-at verilog-endcomment-reason-re)
4850 (setq there (match-end 0))
4851 (setq cntx (concat (match-string 0) " "))
4857 (if (and (verilog-continued-line)
4858 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
4860 (goto-char (match-end 0))
4861 (setq there (point))
4863 (concat " // " (match-string 0) " " (verilog-get-expr))))
4869 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4871 (while (verilog-re-search-backward reg nil 'move)
4873 ((match-end 1) ; begin
4874 (setq nest (1- nest)))
4875 ((match-end 2) ; end
4876 (setq nest (1+ nest)))
4880 (goto-char (match-end 0))
4881 (setq there (point))
4883 (setq str (verilog-get-expr))
4884 (setq str (concat " // else: !if" str ))
4889 (goto-char (match-end 0))
4890 (setq there (point))
4892 (setq str (verilog-get-expr))
4893 (setq str (concat " // else: !assert " str ))
4894 (throw 'skip 1)))))))))
4899 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4901 (while (verilog-re-search-backward reg nil 'move)
4903 ((match-end 1) ; begin
4904 (setq nest (1- nest)))
4905 ((match-end 2) ; end
4906 (setq nest (1+ nest)))
4910 (goto-char (match-end 0))
4911 (setq there (point))
4913 (setq str (verilog-get-expr))
4914 (setq str (concat " // else: !if" str ))
4919 (goto-char (match-end 0))
4920 (setq there (point))
4922 (setq str (verilog-get-expr))
4923 (setq str (concat " // else: !assert " str ))
4924 (throw 'skip 1)))))))))
4926 (; always, always_comb, always_latch w/o @...
4928 (goto-char (match-end 0))
4929 (setq there (point))
4931 (setq str (concat " // " cntx )))
4933 (;- task/function/initial et cetera
4936 (goto-char (match-end 0))
4937 (setq there (point))
4939 (setq str (concat " // " cntx (verilog-get-expr))))
4942 (setq str " // auto-endcomment confused "))))
4945 (verilog-in-case-region-p) ;-- handle case item differently
4947 (setq there (point))
4949 (setq str (verilog-backward-case-item lim))))
4951 (setq str (concat " // case: " str )))
4953 ((verilog-in-fork-region-p)
4955 (setq str " // fork branch" ))
4957 ((looking-at "\\<end\\>")
4959 (forward-word-strictly 1)
4960 (verilog-forward-syntactic-ws)
4962 (setq str (verilog-get-expr))
4963 (setq str (concat " // " cntx str )))
4968 (if kill-existing-comment
4969 (verilog-kill-existing-comment))
4970 (delete-horizontal-space)
4972 (> (count-lines here there) verilog-minimum-comment-distance))
4976 (;- this is endclass, which can be nested
4977 (match-end 11) ; of verilog-end-block-ordered-re
4980 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
4984 (while (verilog-re-search-backward reg nil 'move)
4986 ((match-end 3) ; endclass
4988 (setq string "unmatched endclass")
4991 ((match-end 2) ; endclass
4992 (setq nest (1+ nest)))
4994 ((match-end 1) ; class
4995 (setq nest (1- nest))
4998 (goto-char (match-end 0))
5001 (skip-chars-forward "^ \t")
5002 (verilog-forward-ws&directives)
5005 (skip-chars-forward "a-zA-Z0-9_")
5007 (setq string (buffer-substring b e)))
5011 (if kill-existing-comment
5012 (verilog-kill-existing-comment))
5013 (delete-horizontal-space)
5014 (insert (concat " // " string ))))
5016 (; - this is end{function,generate,task,module,primitive,table,generate}
5017 ;; - which can not be nested.
5019 (let (string reg (name-re nil))
5021 (if kill-existing-comment
5023 (verilog-kill-existing-comment)))
5024 (delete-horizontal-space)
5027 ((match-end 5) ; of verilog-end-block-ordered-re
5028 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
5029 (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
5030 ((match-end 6) ; of verilog-end-block-ordered-re
5031 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
5032 (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
5033 ((match-end 7) ; of verilog-end-block-ordered-re
5034 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
5035 ((match-end 8) ; of verilog-end-block-ordered-re
5036 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5037 ((match-end 9) ; of verilog-end-block-ordered-re
5038 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
5039 ((match-end 10) ; of verilog-end-block-ordered-re
5040 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5041 ((match-end 11) ; of verilog-end-block-ordered-re
5042 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5043 ((match-end 12) ; of verilog-end-block-ordered-re
5044 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5045 ((match-end 13) ; of verilog-end-block-ordered-re
5046 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5047 ((match-end 14) ; of verilog-end-block-ordered-re
5048 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5049 ((match-end 15) ; of verilog-end-block-ordered-re
5050 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
5051 ((match-end 16) ; of verilog-end-block-ordered-re
5052 (setq reg "\\(\\<property\\>\\)\\|\\<endproperty\\>"))
5054 (t (error "Problem in verilog-set-auto-endcomments")))
5057 (verilog-re-search-backward reg nil 'move)
5061 (skip-chars-forward "^ \t")
5062 (verilog-forward-ws&directives)
5063 (if (looking-at "static\\|automatic")
5065 (goto-char (match-end 0))
5066 (verilog-forward-ws&directives)))
5067 (if (and name-re (verilog-re-search-forward name-re nil 'move))
5069 (goto-char (match-beginning 0))
5070 (verilog-forward-ws&directives)))
5073 (skip-chars-forward "a-zA-Z0-9_")
5075 (setq string (buffer-substring b e)))
5078 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
5080 (insert (concat " // " string )))
5083 (defun verilog-get-expr()
5084 "Grab expression at point, e.g., case ( a | b & (c ^d))."
5086 (verilog-forward-syntactic-ws)
5087 (skip-chars-forward " \t")
5093 (verilog-forward-syntactic-ws)
5094 (if (looking-at "(")
5097 (while (and (/= par 0)
5098 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
5101 (setq par (1+ par)))
5103 (setq par (1- par)))))))
5107 (while (and (/= par 0)
5108 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
5111 (setq par (1+ par)))
5113 (setq par (1- par)))))
5117 (while (and (/= par 0)
5118 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
5121 (setq par (1+ par)))
5123 (setq par (1- par)))))
5124 (verilog-forward-syntactic-ws)
5125 (skip-chars-forward "^ \t\n\f")
5127 ((looking-at "/[/\\*]")
5130 (skip-chars-forward "^: \t\n\f")
5132 (str (buffer-substring b e)))
5133 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
5134 (setq str (concat (substring str 0 e) "...")))
5137 (defun verilog-expand-vector ()
5138 "Take a signal vector on the current line and expand it to multiple lines.
5139 Useful for creating tri's and other expanded fields."
5141 (verilog-expand-vector-internal "[" "]"))
5143 (defun verilog-expand-vector-internal (bra ket)
5144 "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
5147 (let ((signal-string (buffer-substring (point)
5149 (end-of-line) (point)))))
5153 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
5155 "\\(.*\\)$") signal-string)
5156 (let* ((sig-head (match-string 1 signal-string))
5157 (vec-start (string-to-number (match-string 2 signal-string)))
5158 (vec-end (if (= (match-beginning 3) (match-end 3))
5161 (substring signal-string (1+ (match-beginning 3))
5164 (if (= (match-beginning 4) (match-end 4))
5167 (substring signal-string (+ 2 (match-beginning 4))
5169 (sig-tail (match-string 5 signal-string))
5174 (let ((tmp vec-start))
5175 (setq vec-start vec-end
5177 vec-range (- vec-range))))
5178 (if (< vec-end vec-start)
5179 (while (<= vec-end vec-start)
5180 (setq vec (append vec (list vec-start)))
5181 (setq vec-start (- vec-start vec-range)))
5182 (while (<= vec-start vec-end)
5183 (setq vec (append vec (list vec-start)))
5184 (setq vec-start (+ vec-start vec-range))))
5186 ;; Delete current line
5187 (delete-region (point) (progn (forward-line 0) (point)))
5191 (insert (concat sig-head bra
5192 (int-to-string (car vec)) ket sig-tail "\n"))
5193 (setq vec (cdr vec)))
5198 (defun verilog-strip-comments ()
5199 "Strip all comments from the Verilog code."
5201 (goto-char (point-min))
5202 (while (re-search-forward "//" nil t)
5203 (if (verilog-within-string)
5204 (re-search-forward "\"" nil t)
5205 (if (verilog-in-star-comment-p)
5206 (re-search-forward "\\*/" nil t)
5207 (let ((bpt (- (point) 2)))
5209 (delete-region bpt (point))))))
5211 (goto-char (point-min))
5212 (while (re-search-forward "/\\*" nil t)
5213 (if (verilog-within-string)
5214 (re-search-forward "\"" nil t)
5215 (let ((bpt (- (point) 2)))
5216 (re-search-forward "\\*/")
5217 (delete-region bpt (point))))))
5219 (defun verilog-one-line ()
5220 "Convert structural Verilog instances to occupy one line."
5222 (goto-char (point-min))
5223 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
5224 (replace-match "\\1 " nil nil)))
5226 (defun verilog-linter-name ()
5227 "Return name of linter, either surelint or verilint."
5228 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
5230 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
5232 (cond ((equal compile-word1 "surelint") `surelint)
5233 ((equal compile-word1 "verilint") `verilint)
5234 ((equal lint-word1 "surelint") `surelint)
5235 ((equal lint-word1 "verilint") `verilint)
5236 (t `surelint)))) ; back compatibility
5238 (defun verilog-lint-off ()
5239 "Convert a Verilog linter warning line into a disable statement.
5241 pci_bfm_null.v, line 46: Unused input: pci_rst_
5242 becomes a comment for the appropriate tool.
5244 The first word of the `compile-command' or `verilog-linter'
5245 variables is used to determine which product is being used.
5247 See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
5249 (let ((linter (verilog-linter-name)))
5250 (cond ((equal linter `surelint)
5251 (verilog-surelint-off))
5252 ((equal linter `verilint)
5253 (verilog-verilint-off))
5254 (t (error "Linter name not set")))))
5256 (defvar compilation-last-buffer)
5257 (defvar next-error-last-buffer)
5259 (defun verilog-surelint-off ()
5260 "Convert a SureLint warning line into a disable statement.
5261 Run from Verilog source window; assumes there is a *compile* buffer
5262 with point set appropriately.
5265 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
5267 // surefire lint_line_off UDDONX"
5269 (let ((buff (if (boundp 'next-error-last-buffer)
5270 next-error-last-buffer
5271 compilation-last-buffer)))
5272 (when (buffer-live-p buff)
5274 (switch-to-buffer buff)
5277 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
5278 (let* ((code (match-string 2))
5279 (file (match-string 3))
5280 (line (match-string 4))
5281 (buffer (get-file-buffer file))
5286 (and (file-exists-p file)
5287 (find-file-noselect file)))
5289 (let* ((pop-up-windows t))
5290 (let ((name (expand-file-name
5292 (format "Find this error in: (default %s) "
5295 (if (file-directory-p name)
5296 (setq name (expand-file-name filename name)))
5298 (and (file-exists-p name)
5299 (find-file-noselect name))))))))
5300 (switch-to-buffer buffer)
5301 (goto-char (point-min))
5302 (forward-line (- (string-to-number line)))
5306 ((verilog-in-slash-comment-p)
5307 (re-search-backward "//")
5309 ((looking-at "// surefire lint_off_line ")
5310 (goto-char (match-end 0))
5311 (let ((lim (point-at-eol)))
5312 (if (re-search-forward code lim 'move)
5314 (insert (concat " " code)))))
5317 ((verilog-in-star-comment-p)
5318 (re-search-backward "/\\*")
5319 (insert (format " // surefire lint_off_line %6s" code )))
5321 (insert (format " // surefire lint_off_line %6s" code ))
5324 (defun verilog-verilint-off ()
5325 "Convert a Verilint warning line into a disable statement.
5328 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
5330 //Verilint 240 off // WARNING: Unused input"
5334 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
5335 (replace-match (format
5336 ;; %3s makes numbers 1-999 line up nicely
5337 "\\1//Verilint %3s off // WARNING: \\3"
5340 (verilog-indent-line))))
5342 (defun verilog-auto-save-compile ()
5343 "Update automatics with \\[verilog-auto], save the buffer, and compile."
5345 (verilog-auto) ; Always do it for safety
5347 (compile compile-command))
5349 (defun verilog-preprocess (&optional command filename)
5350 "Preprocess the buffer, similar to `compile', but put output in Verilog-Mode.
5351 Takes optional COMMAND or defaults to `verilog-preprocessor', and
5352 FILENAME to find directory to run in, or defaults to `buffer-file-name'."
5355 (let ((default (verilog-expand-command verilog-preprocessor)))
5356 (set (make-local-variable `verilog-preprocessor)
5357 (read-from-minibuffer "Run Preprocessor (like this): "
5359 'verilog-preprocess-history default)))))
5360 (unless command (setq command (verilog-expand-command verilog-preprocessor)))
5361 (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
5362 (dir (file-name-directory (or filename buffer-file-name)))
5363 (cmd (concat "cd " dir "; " command)))
5364 (with-output-to-temp-buffer "*Verilog-Preprocessed*"
5365 (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
5366 (insert (concat "// " cmd "\n"))
5367 (call-process shell-file-name nil t nil shell-command-switch cmd)
5369 ;; Without this force, it takes a few idle seconds
5370 ;; to get the color, which is very jarring
5371 (unless (fboundp 'font-lock-ensure)
5372 ;; We should use font-lock-ensure in preference to
5373 ;; font-lock-fontify-buffer, but IIUC the problem this is supposed to
5374 ;; solve only appears in Emacsen older than font-lock-ensure anyway.
5375 ;; So avoid bytecomp's interactive-only by going through intern.
5376 (when fontlocked (funcall (intern "font-lock-fontify-buffer"))))))))
5381 (defun verilog-warn (string &rest args)
5382 "Print a warning with `format' using STRING and optional ARGS."
5383 (apply 'message (concat "%%Warning: " string) args))
5385 (defun verilog-warn-error (string &rest args)
5386 "Call `error' using STRING and optional ARGS.
5387 If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead."
5388 (if verilog-warn-fatal
5389 (apply 'error string args)
5390 (apply 'verilog-warn string args)))
5392 (defmacro verilog-batch-error-wrapper (&rest body)
5393 "Execute BODY and add error prefix to any errors found.
5394 This lets programs calling batch mode to easily extract error messages."
5395 `(let ((verilog-warn-fatal nil))
5399 (error "%%Error: %s%s" (error-message-string err)
5400 (if (featurep 'xemacs) "\n" "")))))) ; XEmacs forgets to add a newline
5402 (defun verilog-batch-execute-func (funref &optional no-save)
5403 "Internal processing of a batch command.
5404 Runs FUNREF on all command arguments.
5405 Save the result unless optional NO-SAVE is t."
5406 (verilog-batch-error-wrapper
5407 ;; Setting global variables like that is *VERY NASTY* !!! --Stef
5408 ;; However, this function is called only when Emacs is being used as
5409 ;; a standalone language instead of as an editor, so we'll live.
5411 ;; General globals needed
5412 (setq make-backup-files nil)
5413 (setq-default make-backup-files nil)
5414 (setq enable-local-variables t)
5415 (setq enable-local-eval t)
5416 (setq create-lockfiles nil)
5417 ;; Make sure any sub-files we read get proper mode
5418 (setq-default major-mode 'verilog-mode)
5419 ;; Ditto files already read in
5420 ;; Remember buffer list, so don't later pickup any verilog-getopt files
5421 (let ((orig-buffer-list (buffer-list)))
5423 (when (buffer-file-name buf)
5424 (with-current-buffer buf
5426 (verilog-auto-reeval-locals)
5427 (verilog-getopt-flags))))
5429 ;; Process the files
5430 (mapcar (lambda (buf)
5431 (when (buffer-file-name buf)
5433 (if (not (file-exists-p (buffer-file-name buf)))
5435 "File not found: %s" (buffer-file-name buf)))
5436 (message "Processing %s" (buffer-file-name buf))
5439 (when (and (not no-save)
5440 (buffer-modified-p)) ; Avoid "no changes to be saved"
5442 orig-buffer-list))))
5444 (defun verilog-batch-auto ()
5445 "For use with --batch, perform automatic expansions as a stand-alone tool.
5446 This sets up the appropriate Verilog mode environment, updates automatics
5447 with \\[verilog-auto] on all command-line files, and saves the buffers.
5448 For proper results, multiple filenames need to be passed on the command
5449 line in bottom-up order."
5450 (unless noninteractive
5451 (error "Use verilog-batch-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5452 (verilog-batch-execute-func `verilog-auto))
5454 (defun verilog-batch-delete-auto ()
5455 "For use with --batch, perform automatic deletion as a stand-alone tool.
5456 This sets up the appropriate Verilog mode environment, deletes automatics
5457 with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
5458 (unless noninteractive
5459 (error "Use verilog-batch-delete-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5460 (verilog-batch-execute-func `verilog-delete-auto))
5462 (defun verilog-batch-delete-trailing-whitespace ()
5463 "For use with --batch, perform whitespace deletion as a stand-alone tool.
5464 This sets up the appropriate Verilog mode environment, removes
5465 whitespace with \\[verilog-delete-trailing-whitespace] on all
5466 command-line files, and saves the buffers."
5467 (unless noninteractive
5468 (error "Use verilog-batch-delete-trailing-whitespace only with --batch")) ; Otherwise we'd mess up buffer modes
5469 (verilog-batch-execute-func `verilog-delete-trailing-whitespace))
5471 (defun verilog-batch-diff-auto ()
5472 "For use with --batch, perform automatic differences as a stand-alone tool.
5473 This sets up the appropriate Verilog mode environment, expand automatics
5474 with \\[verilog-diff-auto] on all command-line files, and reports an error
5475 if any differences are observed. This is appropriate for adding to regressions
5476 to insure automatics are always properly maintained."
5477 (unless noninteractive
5478 (error "Use verilog-batch-diff-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5479 (verilog-batch-execute-func `verilog-diff-auto t))
5481 (defun verilog-batch-inject-auto ()
5482 "For use with --batch, perform automatic injection as a stand-alone tool.
5483 This sets up the appropriate Verilog mode environment, injects new automatics
5484 with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
5485 For proper results, multiple filenames need to be passed on the command
5486 line in bottom-up order."
5487 (unless noninteractive
5488 (error "Use verilog-batch-inject-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5489 (verilog-batch-execute-func `verilog-inject-auto))
5491 (defun verilog-batch-indent ()
5492 "For use with --batch, reindent an entire file as a stand-alone tool.
5493 This sets up the appropriate Verilog mode environment, calls
5494 \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
5495 (unless noninteractive
5496 (error "Use verilog-batch-indent only with --batch")) ; Otherwise we'd mess up buffer modes
5497 (verilog-batch-execute-func `verilog-indent-buffer))
5501 (defconst verilog-indent-alist
5502 '((block . (+ ind verilog-indent-level))
5503 (case . (+ ind verilog-case-indent))
5504 (cparenexp . (+ ind verilog-indent-level))
5505 (cexp . (+ ind verilog-cexp-indent))
5506 (defun . verilog-indent-level-module)
5507 (declaration . verilog-indent-level-declaration)
5508 (directive . (verilog-calculate-indent-directive))
5509 (tf . verilog-indent-level)
5510 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
5513 (comment . (verilog-comment-indent))
5517 (defun verilog-continued-line-1 (lim)
5518 "Return true if this is a continued line.
5519 Set point to where line starts. Limit search to point LIM."
5520 (let ((continued 't))
5521 (if (eq 0 (forward-line -1))
5524 (verilog-backward-ws&directives lim)
5526 (setq continued nil)
5527 (setq continued (verilog-backward-token))))
5528 (setq continued nil))
5531 (defun verilog-calculate-indent ()
5532 "Calculate the indent of the current Verilog line.
5533 Examine previous lines. Once a line is found that is definitive as to the
5534 type of the current line, return that lines' indent level and its type.
5535 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5537 (let* ((starting_position (point))
5538 (case-fold-search nil)
5540 (begin (looking-at "[ \t]*begin\\>"))
5541 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
5543 (type (catch 'nesting
5544 ;; Keep working backwards until we can figure out
5545 ;; what type of statement this is.
5546 ;; Basically we need to figure out
5547 ;; 1) if this is a continuation of the previous line;
5548 ;; 2) are we in a block scope (begin..end)
5550 ;; if we are in a comment, done.
5551 (if (verilog-in-star-comment-p)
5552 (throw 'nesting 'comment))
5554 ;; if we have a directive, done.
5555 (if (save-excursion (beginning-of-line)
5556 (and (looking-at verilog-directive-re-1)
5557 (not (or (looking-at "[ \t]*`[ou]vm_")
5558 (looking-at "[ \t]*`vmm_")))))
5559 (throw 'nesting 'directive))
5560 ;; indent structs as if there were module level
5561 (setq structres (verilog-in-struct-nested-p))
5562 (cond ((not structres) nil)
5563 ;;((and structres (equal (char-after) ?\})) (throw 'nesting 'struct-close))
5564 ((> structres 0) (throw 'nesting 'nested-struct))
5565 ((= structres 0) (throw 'nesting 'block))
5568 ;; if we are in a parenthesized list, and the user likes to indent these, return.
5569 ;; unless we are in the newfangled coverpoint or constraint blocks
5571 verilog-indent-lists
5573 (not (verilog-in-coverage-p))
5576 (throw 'nesting 'block)))
5578 ;; See if we are continuing a previous line
5580 ;; trap out if we crawl off the top of the buffer
5581 (if (bobp) (throw 'nesting 'cpp))
5583 (if (and (verilog-continued-line-1 lim)
5584 (or (not (verilog-in-coverage-p))
5585 (looking-at verilog-in-constraint-re) )) ; may still get hosed if concat in constraint
5588 (not (looking-at verilog-complete-reg))
5589 (verilog-continued-line-1 lim))
5590 (progn (goto-char sp)
5591 (throw 'nesting 'cexp))
5594 (if (and (verilog-in-coverage-p)
5595 (looking-at verilog-in-constraint-re))
5598 (skip-chars-forward " \t")
5599 (throw 'nesting 'constraint)))
5601 (not verilog-indent-begin-after-if)
5602 (looking-at verilog-no-indent-begin-re))
5605 (skip-chars-forward " \t")
5606 (throw 'nesting 'statement))
5608 (throw 'nesting 'cexp))))
5609 ;; not a continued line
5610 (goto-char starting_position))
5612 (if (looking-at "\\<else\\>")
5613 ;; search back for governing if, striding across begin..end pairs
5616 (while (verilog-re-search-backward verilog-ends-re nil 'move)
5618 ((match-end 1) ; else, we're in deep
5619 (setq elsec (1+ elsec)))
5621 (setq elsec (1- elsec))
5623 (if verilog-align-ifelse
5624 (throw 'nesting 'statement)
5625 (progn ; back up to first word on this line
5627 (verilog-forward-syntactic-ws)
5628 (throw 'nesting 'statement)))))
5629 ((match-end 3) ; assert block
5630 (setq elsec (1- elsec))
5631 (verilog-beg-of-statement) ; doesn't get to beginning
5632 (if (looking-at verilog-property-re)
5633 (throw 'nesting 'statement) ; We don't need an endproperty for these
5634 (throw 'nesting 'block) ; We still need an endproperty
5637 ;; try to leap back to matching outward block by striding across
5638 ;; indent level changing tokens then immediately
5639 ;; previous line governs indentation.
5640 (let (( reg) (nest 1))
5641 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
5643 ((match-end 4) ; end
5644 ;; Search back for matching begin
5645 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
5646 ((match-end 5) ; endcase
5647 ;; Search back for matching case
5648 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5649 ((match-end 6) ; endfunction
5650 ;; Search back for matching function
5651 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5652 ((match-end 7) ; endtask
5653 ;; Search back for matching task
5654 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
5655 ((match-end 8) ; endspecify
5656 ;; Search back for matching specify
5657 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5658 ((match-end 9) ; endtable
5659 ;; Search back for matching table
5660 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5661 ((match-end 10) ; endgenerate
5662 ;; Search back for matching generate
5663 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5664 ((match-end 11) ; joins
5665 ;; Search back for matching fork
5666 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
5667 ((match-end 12) ; class
5668 ;; Search back for matching class
5669 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5670 ((match-end 13) ; covergroup
5671 ;; Search back for matching covergroup
5672 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
5674 (while (verilog-re-search-backward reg nil 'move)
5676 ((match-end 1) ; begin
5677 (setq nest (1- nest))
5680 ((match-end 2) ; end
5681 (setq nest (1+ nest)))))
5683 (throw 'nesting (verilog-calc-1)))
5687 ;; Return type of block and indent level.
5690 (if (> par 0) ; Unclosed Parenthesis
5691 (list 'cparenexp par)
5694 (list type (verilog-case-indent-level)))
5695 ((eq type 'statement)
5696 (list type (current-column)))
5699 ((eq type 'constraint)
5700 (list 'block (current-column)))
5701 ((eq type 'nested-struct)
5702 (list 'block structres))
5704 (list type (verilog-current-indent-level))))))))
5706 (defun verilog-wai ()
5707 "Show matching nesting block for debugging."
5710 (let* ((type (verilog-calc-1))
5712 ;; Return type of block and indent level.
5716 verilog-indent-lists
5717 (not(or (verilog-in-coverage-p)
5718 (verilog-in-struct-p)))
5723 (setq depth (verilog-case-indent-level)))
5724 ((eq type 'statement)
5725 (setq depth (current-column)))
5729 (setq depth (verilog-current-indent-level)))))
5730 (message "You are at nesting %s depth %d" type depth))))
5732 (defun verilog-calc-1 ()
5734 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)"))
5735 (inconstraint (verilog-in-coverage-p)))
5736 (while (verilog-re-search-backward re nil 'move)
5739 ((equal (char-after) ?\{)
5740 ;; block type returned based on outer constraint { or inner
5741 (if (verilog-at-constraint-p)
5743 (beginning-of-line nil)
5744 (skip-chars-forward " \t")
5745 (throw 'nesting 'constraint))
5747 (throw 'nesting 'statement)))))
5748 ((equal (char-after) ?\})
5750 (there (verilog-at-close-constraint-p)))
5751 (if there ; we are at the } that closes a constraint. Find the { that opens it
5753 (if (> (verilog-in-paren-count) 0)
5755 (setq par-pos (verilog-parenthesis-depth))
5760 (backward-char 1)))))))
5762 ((looking-at verilog-beg-block-re-ordered)
5764 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
5765 (let ((here (point)))
5766 (verilog-beg-of-statement)
5767 (if (looking-at verilog-extended-case-re)
5768 (throw 'nesting 'case)
5770 (throw 'nesting 'case))
5772 ((match-end 4) ; *sigh* could be "disable fork"
5773 (let ((here (point)))
5774 (verilog-beg-of-statement)
5775 (if (looking-at verilog-disable-fork-re)
5776 t ; this is a normal statement
5777 (progn ; or is fork, starts a new block
5779 (throw 'nesting 'block)))))
5781 ((match-end 17) ; *sigh* might be a clocking declaration
5782 (let ((here (point)))
5783 (cond ((verilog-in-paren)
5784 t) ; this is a normal statement
5786 (verilog-beg-of-statement)
5787 (looking-at verilog-default-clocking-re))
5788 t) ; default clocking, normal statement
5790 (goto-char here) ; or is clocking, starts a new block
5791 (throw 'nesting 'block)))))
5793 ;; need to consider typedef struct here...
5794 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
5795 ;; *sigh* These words have an optional prefix:
5796 ;; extern {virtual|protected}? function a();
5797 ;; typedef class foo;
5798 ;; and we don't want to confuse this with
5803 (verilog-beg-of-statement)
5805 ((looking-at verilog-dpi-import-export-re)
5806 (throw 'continue 'foo))
5807 ((looking-at "\\<pure\\>\\s-+\\<virtual\\>\\s-+\\(?:\\<\\(local\\|protected\\|static\\)\\>\\s-+\\)?\\<\\(function\\|task\\)\\>\\s-+")
5808 (throw 'nesting 'statement))
5809 ((looking-at verilog-beg-block-re-ordered)
5810 (throw 'nesting 'block))
5812 (throw 'nesting 'defun))))
5815 ((looking-at "\\<property\\>")
5817 ;; {assert|assume|cover} property (); are complete
5818 ;; and could also be labeled: - foo: assert property
5820 ;; property ID () ... needs end_property
5821 (verilog-beg-of-statement)
5822 (if (looking-at verilog-property-re)
5823 (throw 'continue 'statement) ; We don't need an endproperty for these
5824 (throw 'nesting 'block) ;We still need an endproperty
5827 (t (throw 'nesting 'block))))
5829 ((looking-at verilog-end-block-re)
5830 (verilog-leap-to-head)
5831 (if (verilog-in-case-region-p)
5833 (verilog-leap-to-case-head)
5834 (if (looking-at verilog-extended-case-re)
5835 (throw 'nesting 'case)))))
5837 ((looking-at verilog-defun-level-re)
5838 (if (looking-at verilog-defun-level-generate-only-re)
5839 (if (or (verilog-in-generate-region-p)
5840 (verilog-in-deferred-immediate-final-p))
5841 (throw 'continue 'foo) ; always block in a generate - keep looking
5842 (throw 'nesting 'defun))
5843 (throw 'nesting 'defun)))
5845 ((looking-at verilog-cpp-level-re)
5846 (throw 'nesting 'cpp))
5849 (throw 'nesting 'cpp)))))
5851 (throw 'nesting 'cpp))))
5853 (defun verilog-calculate-indent-directive ()
5854 "Return indentation level for directive.
5855 For speed, the searcher looks at the last directive, not the indent
5856 of the appropriate enclosing block."
5857 (let ((base -1) ; Indent of the line that determines our indentation
5858 (ind 0)) ; Relative offset caused by other directives (like `endif on same line as `else)
5859 ;; Start at current location, scan back for another directive
5863 (while (and (< base 0)
5864 (verilog-re-search-backward verilog-directive-re nil t))
5865 (cond ((save-excursion (skip-chars-backward " \t") (bolp))
5866 (setq base (current-indentation))))
5867 (cond ((and (looking-at verilog-directive-end) (< base 0)) ; Only matters when not at BOL
5868 (setq ind (- ind verilog-indent-level-directive)))
5869 ((and (looking-at verilog-directive-middle) (>= base 0)) ; Only matters when at BOL
5870 (setq ind (+ ind verilog-indent-level-directive)))
5871 ((looking-at verilog-directive-begin)
5872 (setq ind (+ ind verilog-indent-level-directive)))))
5873 ;; Adjust indent to starting indent of critical line
5874 (setq ind (max 0 (+ ind base))))
5878 (skip-chars-forward " \t")
5879 (cond ((or (looking-at verilog-directive-middle)
5880 (looking-at verilog-directive-end))
5881 (setq ind (max 0 (- ind verilog-indent-level-directive))))))
5884 (defun verilog-leap-to-case-head ()
5887 (verilog-re-search-backward
5889 "\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
5890 "\\|\\(\\<endcase\\>\\)" )
5894 (let ((here (point)))
5895 (verilog-beg-of-statement)
5896 (unless (looking-at verilog-extended-case-re)
5898 (setq nest (1- nest)))
5900 (setq nest (1+ nest)))
5905 (defun verilog-leap-to-head ()
5906 "Move point to the head of this block.
5907 Jump from end to matching begin, from endcase to matching case, and so on."
5913 ((looking-at "\\<end\\>")
5914 ;; 1: Search back for matching begin
5915 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
5916 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
5917 ((looking-at "\\<endtask\\>")
5918 ;; 2: Search back for matching task
5919 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\<\\(virtual\\|protected\\|static\\)\\>\\s-+\\)+\\<task\\>\\)")
5921 ((looking-at "\\<endcase\\>")
5923 (verilog-leap-to-case-head) )
5924 (setq reg nil) ; to force skip
5927 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
5928 ;; 4: Search back for matching fork
5929 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5930 ((looking-at "\\<endclass\\>")
5931 ;; 5: Search back for matching class
5932 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5933 ((looking-at "\\<endtable\\>")
5934 ;; 6: Search back for matching table
5935 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5936 ((looking-at "\\<endspecify\\>")
5937 ;; 7: Search back for matching specify
5938 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5939 ((looking-at "\\<endfunction\\>")
5940 ;; 8: Search back for matching function
5941 (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\<\\(virtual\\|protected\\|static\\)\\>\\s-+\\)+\\<function\\>\\)")
5943 ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5944 ((looking-at "\\<endgenerate\\>")
5945 ;; 8: Search back for matching generate
5946 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5947 ((looking-at "\\<endgroup\\>")
5948 ;; 10: Search back for matching covergroup
5949 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
5950 ((looking-at "\\<endproperty\\>")
5951 ;; 11: Search back for matching property
5952 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
5953 ((looking-at verilog-uvm-end-re)
5954 ;; 12: Search back for matching sequence
5955 (setq reg (concat "\\(" verilog-uvm-begin-re "\\|" verilog-uvm-end-re "\\)")))
5956 ((looking-at verilog-ovm-end-re)
5957 ;; 12: Search back for matching sequence
5958 (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
5959 ((looking-at verilog-vmm-end-re)
5960 ;; 12: Search back for matching sequence
5961 (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
5962 ((looking-at "\\<endinterface\\>")
5963 ;; 12: Search back for matching interface
5964 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
5965 ((looking-at "\\<endsequence\\>")
5966 ;; 12: Search back for matching sequence
5967 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
5968 ((looking-at "\\<endclocking\\>")
5969 ;; 12: Search back for matching clocking
5970 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
5973 (if (eq nesting 'yes)
5975 (while (verilog-re-search-backward reg nil 'move)
5977 ((match-end 1) ; begin
5978 (if (looking-at "fork")
5979 (let ((here (point)))
5980 (verilog-beg-of-statement)
5981 (unless (looking-at verilog-disable-fork-re)
5983 (setq nest (1- nest))))
5984 (setq nest (1- nest)))
5986 ;; Now previous line describes syntax
5991 ((match-end 2) ; end
5992 (setq nest (1+ nest)))
5994 ;; endcase, jump to case
5996 (setq nest (1+ nest))
5998 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
6000 ;; join, jump to fork
6002 (setq nest (1+ nest))
6004 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
6008 (verilog-re-search-backward reg nil 'move)
6009 (match-end 1)) ; task -> could be virtual and/or protected
6011 (verilog-beg-of-statement)
6013 (throw 'skip 1)))))))
6015 (defun verilog-continued-line ()
6016 "Return true if this is a continued line.
6017 Set point to where line starts."
6018 (let ((continued 't))
6019 (if (eq 0 (forward-line -1))
6022 (verilog-backward-ws&directives)
6024 (setq continued nil)
6025 (while (and continued
6027 (skip-chars-backward " \t")
6029 (setq continued (verilog-backward-token)))))
6030 (setq continued nil))
6033 (defun verilog-backward-token ()
6034 "Step backward token, returning true if this is a continued line."
6036 (verilog-backward-syntactic-ws)
6040 (;-- Anything ending in a ; is complete
6041 (= (preceding-char) ?\;)
6043 (; If a "}" is prefixed by a ";", then this is a complete statement
6044 ;; i.e.: constraint foo { a = b; }
6045 (= (preceding-char) ?\})
6048 (not(verilog-at-close-constraint-p))))
6049 (;-- constraint foo { a = b }
6050 ;; is a complete statement. *sigh*
6051 (= (preceding-char) ?\{)
6054 (not (verilog-at-constraint-p))))
6056 (= (preceding-char) ?\")
6058 (verilog-skip-backward-comment-or-string)
6062 (= (preceding-char) ?\])
6064 (verilog-backward-open-bracket)
6067 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
6068 ;; also could be simply '@(foo)'
6070 ;; (b, ... which ISN'T complete
6071 ;; Do we need this???
6072 (= (preceding-char) ?\))
6075 (verilog-backward-up-list 1)
6076 (verilog-backward-syntactic-ws)
6077 (let ((back (point)))
6078 (forward-word-strictly -1)
6081 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
6082 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
6083 ((looking-at verilog-uvm-statement-re)
6085 ((looking-at verilog-uvm-begin-re)
6087 ((looking-at verilog-uvm-end-re)
6089 ((looking-at verilog-ovm-statement-re)
6091 ((looking-at verilog-ovm-begin-re)
6093 ((looking-at verilog-ovm-end-re)
6095 ;; JBA find VMM macros
6096 ((looking-at verilog-vmm-statement-re)
6098 ((looking-at verilog-vmm-begin-re)
6100 ((looking-at verilog-vmm-end-re)
6102 ;; JBA trying to catch macro lines with no ; at end
6103 ((looking-at "\\<`")
6108 ((= (preceding-char) ?\@)
6111 (verilog-backward-token)
6112 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
6113 ((= (preceding-char) ?\#)
6117 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
6119 (forward-word-strictly -1)
6120 (while (or (= (preceding-char) ?\_)
6121 (= (preceding-char) ?\@)
6122 (= (preceding-char) ?\.))
6123 (forward-word-strictly -1))
6125 ((looking-at "\\<else\\>")
6127 ((looking-at verilog-behavioral-block-beg-re)
6129 ((looking-at verilog-indent-re)
6134 (verilog-backward-syntactic-ws)
6136 ((= (preceding-char) ?\:)
6138 (verilog-backward-syntactic-ws)
6140 (if (looking-at verilog-nameable-item-re )
6143 ((= (preceding-char) ?\#)
6146 ((= (preceding-char) ?\`)
6154 (defun verilog-backward-syntactic-ws ()
6155 "Move backwards putting point after first non-whitespace non-comment."
6156 (verilog-skip-backward-comments)
6157 (forward-comment (- (buffer-size))))
6159 (defun verilog-backward-syntactic-ws-quick ()
6160 "As with `verilog-backward-syntactic-ws' but use `verilog-scan' cache."
6161 (while (cond ((bobp)
6163 ((< (skip-syntax-backward " ") 0)
6165 ((eq (preceding-char) ?\n) ; \n's terminate // so aren't space syntax
6168 ((or (verilog-inside-comment-or-string-p (1- (point)))
6169 (verilog-inside-comment-or-string-p (point)))
6170 (re-search-backward "[/\"]" nil t) ; Only way a comment or quote can begin
6173 (defun verilog-forward-syntactic-ws ()
6174 (verilog-skip-forward-comment-p)
6175 (forward-comment (buffer-size)))
6177 (defun verilog-backward-ws&directives (&optional bound)
6178 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
6179 Optional BOUND limits search."
6181 (let* ((bound (or bound (point-min)))
6184 (if (< bound (point))
6186 (let ((state (save-excursion (verilog-syntax-ppss))))
6188 ((nth 7 state) ; in // comment
6189 (verilog-re-search-backward "//" nil 'move)
6190 (skip-chars-backward "/"))
6191 ((nth 4 state) ; in /* */ comment
6192 (verilog-re-search-backward "/\\*" nil 'move))))
6193 (narrow-to-region bound (point))
6194 (while (/= here (point))
6196 (verilog-skip-backward-comments)
6200 ;; for as long as we're right after a continued line, keep moving up
6201 (while (and (verilog-looking-back "\\\\[\n\r\f]" nil)
6204 ((and verilog-highlight-translate-off
6205 (verilog-within-translate-off))
6206 (verilog-back-to-start-translate-off (point-min)))
6207 ((looking-at verilog-directive-re-1)
6211 (if p (goto-char p))))))))
6213 (defun verilog-forward-ws&directives (&optional bound)
6214 "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
6215 Optional BOUND limits search."
6217 (let* ((bound (or bound (point-max)))
6220 (if (> bound (point))
6222 (let ((state (save-excursion (verilog-syntax-ppss))))
6224 ((nth 7 state) ; in // comment
6227 (skip-chars-forward " \t\n\f")
6229 ((nth 4 state) ; in /* */ comment
6230 (verilog-re-search-forward "\\*/\\s-*" nil 'move))))
6231 (narrow-to-region (point) bound)
6232 (while (/= here (point))
6235 (forward-comment (buffer-size))
6236 (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ; Attribute
6237 (goto-char (match-end 0)))
6240 (if (looking-at verilog-directive-re-1)
6243 (beginning-of-line 2))))))))
6245 (defun verilog-in-comment-p ()
6246 "Return true if in a star or // comment."
6247 (let ((state (save-excursion (verilog-syntax-ppss))))
6248 (or (nth 4 state) (nth 7 state))))
6250 (defun verilog-in-star-comment-p ()
6251 "Return true if in a star comment."
6252 (let ((state (save-excursion (verilog-syntax-ppss))))
6254 (nth 4 state) ; t if in a comment of style a // or b /**/
6256 (nth 7 state) ; t if in a comment of style b /**/
6259 (defun verilog-in-slash-comment-p ()
6260 "Return true if in a slash comment."
6261 (let ((state (save-excursion (verilog-syntax-ppss))))
6264 (defun verilog-in-comment-or-string-p ()
6265 "Return true if in a string or comment."
6266 (let ((state (save-excursion (verilog-syntax-ppss))))
6267 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
6269 (defun verilog-in-attribute-p ()
6270 "Return true if point is in an attribute (* [] attribute *)."
6273 (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
6276 (progn (goto-char (match-end 1))
6277 (not (looking-at "\\s-*)")))
6280 (progn (goto-char (match-beginning 2))
6281 (not (looking-at "(\\s-*")))
6285 (defun verilog-in-parameter-p ()
6286 "Return true if point is in a parameter assignment #( p1=1, p2=5)."
6289 (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move)
6290 (numberp (match-beginning 1)))))
6292 (defun verilog-in-escaped-name-p ()
6293 "Return true if in an escaped name."
6296 (skip-chars-backward "^ \t\n\f")
6297 (if (equal (char-after (point) ) ?\\ )
6301 (defun verilog-in-directive-p ()
6302 "Return true if in a directive."
6305 (looking-at verilog-directive-re-1)))
6307 (defun verilog-in-parenthesis-p ()
6308 "Return true if in a ( ) expression (but not { } or [ ])."
6311 (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move)
6312 (numberp (match-beginning 1)))))
6314 (defun verilog-in-paren ()
6315 "Return true if in a parenthetical expression.
6316 May cache result using `verilog-syntax-ppss'."
6317 (let ((state (save-excursion (verilog-syntax-ppss))))
6318 (> (nth 0 state) 0 )))
6320 (defun verilog-in-paren-count ()
6321 "Return paren depth, floor to 0.
6322 May cache result using `verilog-syntax-ppss'."
6323 (let ((state (save-excursion (verilog-syntax-ppss))))
6324 (if (> (nth 0 state) 0)
6328 (defun verilog-in-paren-quick ()
6329 "Return true if in a parenthetical expression.
6330 Always starts from `point-min', to allow inserts with hooks disabled."
6331 ;; The -quick refers to its use alongside the other -quick functions,
6332 ;; not that it's likely to be faster than verilog-in-paren.
6333 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
6334 (> (nth 0 state) 0 )))
6336 (defun verilog-in-struct-p ()
6337 "Return true if in a struct declaration."
6340 (if (verilog-in-paren)
6342 (verilog-backward-up-list 1)
6343 (verilog-at-struct-p)
6347 (defun verilog-in-struct-nested-p ()
6348 "Return nil for not in struct.
6349 Return 0 for in non-nested struct.
6350 Return >0 for nested struct."
6354 (if (verilog-in-paren)
6356 (verilog-backward-up-list 1)
6357 (setq col (verilog-at-struct-mv-p))
6359 (if (verilog-in-struct-p) (current-column) 0)))
6362 (defun verilog-in-coverage-p ()
6363 "Return true if in a constraint or coverpoint expression."
6366 (if (verilog-in-paren)
6368 (verilog-backward-up-list 1)
6369 (verilog-at-constraint-p)
6373 (defun verilog-at-close-constraint-p ()
6374 "If at the } that closes a constraint or covergroup, return true."
6376 (equal (char-after) ?\})
6377 (verilog-in-coverage-p))
6380 (verilog-backward-ws&directives)
6381 (if (or (equal (char-before) ?\;)
6382 (equal (char-before) ?\}) ; can end with inner constraint { } block or ;
6383 (equal (char-before) ?\{)) ; empty constraint block
6387 (defun verilog-at-constraint-p ()
6388 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
6392 (equal (char-after) ?\{)
6393 (ignore-errors (forward-list))
6394 (progn (backward-char 1)
6395 (verilog-backward-ws&directives)
6397 (or (equal (char-before) ?\{) ; empty case
6398 (equal (char-before) ?\;)
6399 (equal (char-before) ?\}))
6400 ;; skip what looks like bus repetition operator {#{
6401 (not (string-match "^{\\s-*[0-9]+\\s-*{" (buffer-substring p (point)))))))))
6403 (let ( (pt (point)) (pass 0))
6404 (verilog-backward-ws&directives)
6405 (verilog-backward-token)
6406 (if (looking-at (concat "\\<constraint\\|coverpoint\\|cross\\|with\\>\\|" verilog-in-constraint-re))
6407 (progn (setq pass 1)
6408 (if (looking-at "\\<with\\>")
6409 (progn (verilog-backward-ws&directives)
6410 (beginning-of-line) ; 1
6411 (verilog-forward-ws&directives)
6413 (verilog-beg-of-statement)
6415 ;; if first word token not keyword, it maybe the instance name
6416 ;; check next word token
6417 (if (looking-at "\\<\\w+\\>\\|\\s-*(\\s-*\\S-+")
6418 (progn (verilog-beg-of-statement)
6419 (if (looking-at (concat "\\<\\(constraint\\|"
6420 "\\(?:\\w+\\s-*:\\s-*\\)?\\(coverpoint\\|cross\\)"
6421 "\\|with\\)\\>\\|" verilog-in-constraint-re))
6424 (progn (goto-char pt) nil) 1)))
6428 (defun verilog-at-struct-p ()
6429 "If at the { of a struct, return true, not moving point."
6431 (if (and (equal (char-after) ?\{)
6432 (verilog-backward-token))
6433 (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6436 (defun verilog-at-struct-mv-p ()
6437 "If at the { of a struct, return true, moving point to struct."
6439 (if (and (equal (char-after) ?\{)
6440 (verilog-backward-token))
6441 (if (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6442 (progn (verilog-beg-of-statement) (point))
6443 (progn (goto-char pt) nil))
6444 (progn (goto-char pt) nil))))
6446 (defun verilog-at-close-struct-p ()
6447 "If at the } that closes a struct, return true."
6449 (equal (char-after) ?\})
6450 (verilog-in-struct-p))
6453 (if (looking-at "}\\(?:\\s-*\\w+\\s-*\\)?;") 1))
6457 (defun verilog-parenthesis-depth ()
6458 "Return non zero if in parenthetical-expression."
6459 (save-excursion (nth 1 (verilog-syntax-ppss))))
6462 (defun verilog-skip-forward-comment-or-string ()
6463 "Return true if in a string or comment."
6464 (let ((state (save-excursion (verilog-syntax-ppss))))
6466 ((nth 3 state) ;Inside string
6467 (search-forward "\"")
6469 ((nth 7 state) ;Inside // comment
6472 ((nth 4 state) ;Inside any comment (hence /**/)
6473 (search-forward "*/"))
6477 (defun verilog-skip-backward-comment-or-string ()
6478 "Return true if in a string or comment."
6479 (let ((state (save-excursion (verilog-syntax-ppss))))
6481 ((nth 3 state) ;Inside string
6482 (search-backward "\"")
6484 ((nth 7 state) ;Inside // comment
6485 (search-backward "//")
6486 (skip-chars-backward "/")
6488 ((nth 4 state) ;Inside /* */ comment
6489 (search-backward "/*")
6494 (defun verilog-skip-backward-comments ()
6495 "Return true if a comment was skipped."
6499 (let ((state (save-excursion (verilog-syntax-ppss))))
6501 ((nth 7 state) ;Inside // comment
6502 (search-backward "//")
6503 (skip-chars-backward "/")
6504 (skip-chars-backward " \t\n\f")
6506 ((nth 4 state) ;Inside /* */ comment
6507 (search-backward "/*")
6508 (skip-chars-backward " \t\n\f")
6511 (= (char-before) ?\/)
6512 (= (char-before (1- (point))) ?\*))
6513 (goto-char (- (point) 2))
6514 t) ; Let nth 4 state handle the rest
6516 ;;(verilog-looking-back "\\*)" nil) ;; super slow, use two char-before instead
6517 (= (char-before) ?\))
6518 (= (char-before (1- (point))) ?\*)
6519 (not (verilog-looking-back "(\\s-*\\*)" nil))) ;; slow but unlikely to be called
6520 (goto-char (- (point) 2))
6521 (if (search-backward "(*" nil t)
6523 (skip-chars-backward " \t\n\f")
6526 (goto-char (+ (point) 2))
6529 (/= (skip-chars-backward " \t\n\f") 0))))))))
6531 (defun verilog-skip-forward-comment-p ()
6532 "If in comment, move to end and return true."
6534 (state (save-excursion (verilog-syntax-ppss)))
6536 ((nth 3 state) ;Inside string
6538 ((nth 7 state) ;Inside // comment
6542 ((nth 4 state) ;Inside /* comment
6543 (search-forward "*/")
6545 ((verilog-in-attribute-p) ;Inside (* attribute
6546 (search-forward "*)" nil t)
6549 (skip-chars-forward " \t\n\f")
6552 ((looking-at "\\/\\*")
6555 (goto-char (match-end 0))
6556 (if (search-forward "*/" nil t)
6558 (skip-chars-forward " \t\n\f")
6563 ((and (looking-at "(\\*") ; attribute start, but not an event (*) or (* )
6564 (not (looking-at "(\\*\\s-*)")))
6567 (goto-char (match-end 0))
6568 (if (search-forward "*)" nil t)
6570 (skip-chars-forward " \t\n\f")
6578 (defun verilog-indent-line-relative ()
6579 "Cheap version of indent line.
6580 Only look at a few lines to determine indent level."
6584 (if (looking-at "^[ \t]*$")
6585 (cond ;- A blank line; No need to be too smart.
6587 (setq indent-str (list 'cpp 0)))
6588 ((verilog-continued-line)
6589 (let ((sp1 (point)))
6590 (if (verilog-continued-line)
6594 (list 'statement (verilog-current-indent-level))))
6596 (setq indent-str (list 'block (verilog-current-indent-level)))))
6599 (setq indent-str (verilog-calculate-indent))))
6600 (progn (skip-chars-forward " \t")
6601 (setq indent-str (verilog-calculate-indent))))
6602 (verilog-do-indent indent-str)))
6604 (defun verilog-indent-line ()
6605 "Indent for special part of code."
6606 (verilog-do-indent (verilog-calculate-indent)))
6608 (defun verilog-do-indent (indent-str)
6609 (let ((type (car indent-str))
6610 (ind (car (cdr indent-str))))
6612 (; handle continued exp
6614 (let ((here (point)))
6615 (verilog-backward-syntactic-ws)
6618 (= (preceding-char) ?\,)
6620 (verilog-beg-of-statement-1)
6621 (looking-at verilog-declaration-re)))
6626 (verilog-beg-of-statement-1)
6628 (if (looking-at verilog-declaration-re)
6629 (progn ; we have multiple words
6630 (goto-char (match-end 0))
6631 (skip-chars-forward " \t")
6633 ((and verilog-indent-declaration-macros
6634 (= (following-char) ?\`))
6637 (forward-word-strictly 1)
6638 (skip-chars-forward " \t")))
6639 ((= (following-char) ?\[)
6642 (verilog-backward-up-list -1)
6643 (skip-chars-forward " \t"))))
6647 (+ (current-column) verilog-cexp-indent))))))
6649 (indent-line-to val)
6650 (if (and (not verilog-indent-lists)
6652 (verilog-pretty-declarations-auto))
6654 ((= (preceding-char) ?\) )
6656 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6657 (indent-line-to val)))
6661 (verilog-beg-of-statement-1)
6662 (if (and (< (point) here)
6663 (verilog-re-search-forward "=[ \\t]*" here 'move)
6664 ;; not at a |=>, #=#, or [=n] operator
6665 (not (string-match "\\[=.\\|#=#\\||=>"
6666 (or (buffer-substring (- (point) 2) (1+ (point)))
6667 "")))) ; don't let buffer over/under-run spoil the party
6668 (setq val (current-column))
6669 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
6671 (indent-line-to val))))))
6673 (; handle inside parenthetical expressions
6674 (eq type 'cparenexp)
6676 (val (save-excursion
6677 (verilog-backward-up-list 1)
6679 (if verilog-indent-lists
6680 (skip-chars-forward " \t")
6681 (verilog-forward-syntactic-ws))
6685 (decl (save-excursion
6687 (verilog-forward-syntactic-ws)
6689 (looking-at verilog-declaration-re))))
6690 (indent-line-to val)
6692 (verilog-pretty-declarations-auto))))
6694 (;-- Handle the ends
6696 (looking-at verilog-end-block-re)
6697 (verilog-at-close-constraint-p)
6698 (verilog-at-close-struct-p))
6699 (let ((val (if (eq type 'statement)
6700 (- ind verilog-indent-level)
6702 (indent-line-to val)))
6704 (;-- Case -- maybe line 'em up
6705 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
6708 ((looking-at "\\<endcase\\>")
6709 (indent-line-to ind))
6711 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6712 (indent-line-to val))))))
6715 (and (eq type 'defun)
6716 (looking-at verilog-zero-indent-re))
6723 (looking-at verilog-declaration-re)
6724 ;; Do not consider "virtual function", "virtual task", "virtual class"
6726 (not (looking-at (concat verilog-declaration-re
6727 "\\s-+\\(function\\|task\\|class\\)\\b"))))
6728 (verilog-indent-declaration ind))
6730 (;-- form feeds - ignored as bug in indent-line-to in < 24.5
6733 (;-- Everything else
6735 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6736 (indent-line-to val))))
6738 (if (looking-at "[ \t]+$")
6739 (skip-chars-forward " \t"))
6740 indent-str ; Return indent data
6743 (defun verilog-current-indent-level ()
6744 "Return the indent-level of the current statement."
6748 (setq par-pos (verilog-parenthesis-depth))
6752 (setq par-pos (verilog-parenthesis-depth)))
6753 (skip-chars-forward " \t")
6756 (defun verilog-case-indent-level ()
6757 "Return the indent-level of the current statement.
6758 Do not count named blocks or case-statements."
6760 (skip-chars-forward " \t")
6762 ((looking-at verilog-named-block-re)
6764 ((and (not (looking-at verilog-extended-case-re))
6765 (looking-at "^[^:;]+[ \t]*:"))
6766 (verilog-re-search-forward ":" nil t)
6767 (skip-chars-forward " \t")
6770 (current-column)))))
6772 (defun verilog-indent-comment ()
6773 "Indent current line as comment."
6776 ((verilog-in-star-comment-p)
6778 (re-search-backward "/\\*" nil t)
6779 (1+(current-column))))
6784 (re-search-backward "//" nil t)
6785 (current-column))))))
6786 (indent-line-to stcol)
6789 (defun verilog-more-comment ()
6790 "Make more comment lines like the previous."
6794 ((verilog-in-star-comment-p)
6797 (re-search-backward "/\\*" nil t)
6798 (1+(current-column))))
6803 (re-search-backward "//" nil t)
6804 (current-column))))))
6810 (skip-chars-forward " \t")
6811 (looking-at "\\*")))
6814 (defun verilog-comment-indent (&optional _arg)
6815 "Return the column number the line should be indented to.
6816 _ARG is ignored, for `comment-indent-function' compatibility."
6818 ((verilog-in-star-comment-p)
6820 (re-search-backward "/\\*" nil t)
6821 (1+(current-column))))
6826 (re-search-backward "//" nil t)
6827 (current-column)))))
6831 (defun verilog-pretty-declarations-auto (&optional quiet)
6832 "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'."
6833 (when (or (eq 'all verilog-auto-lineup)
6834 (eq 'declarations verilog-auto-lineup))
6835 (verilog-pretty-declarations quiet)))
6837 (defun verilog-pretty-declarations (&optional quiet)
6838 "Line up declarations around point.
6839 Be verbose about progress unless optional QUIET set."
6841 (let* ((m1 (make-marker))
6855 ;; (verilog-beg-of-statement-1)
6857 (verilog-forward-syntactic-ws)
6858 (and (not (verilog-in-directive-p)) ; could have `define input foo
6859 (looking-at verilog-declaration-re)))
6861 (if (verilog-parenthesis-depth)
6862 ;; in an argument list or parameter block
6863 (setq el (verilog-backward-up-list -1)
6866 (verilog-backward-up-list 1)
6867 (forward-line) ; ignore ( input foo,
6868 (verilog-re-search-forward verilog-declaration-re el 'move)
6869 (goto-char (match-beginning 0))
6870 (skip-chars-backward " \t")
6872 startpos (set-marker (make-marker) start)
6875 (verilog-backward-up-list -1)
6877 (verilog-backward-syntactic-ws)
6879 endpos (set-marker (make-marker) end)
6883 (skip-chars-forward " \t")
6885 ;; in a declaration block (not in argument list)
6888 (verilog-beg-of-statement-1)
6889 (while (and (looking-at verilog-declaration-re)
6891 (skip-chars-backward " \t")
6894 (verilog-backward-syntactic-ws)
6896 (verilog-beg-of-statement-1))
6898 startpos (set-marker (make-marker) start)
6901 (verilog-end-of-statement)
6902 (setq e (point)) ;Might be on last line
6903 (verilog-forward-syntactic-ws)
6904 (while (looking-at verilog-declaration-re)
6905 (verilog-end-of-statement)
6907 (verilog-forward-syntactic-ws))
6909 endpos (set-marker (make-marker) end)
6912 (verilog-do-indent (verilog-calculate-indent))
6913 (verilog-forward-ws&directives)
6915 ;; OK, start and end are set
6916 (goto-char (marker-position startpos))
6917 (if (and (not quiet)
6918 (> (- end start) 100))
6919 (message "Lining up declarations..(please stand by)"))
6920 ;; Get the beginning of line indent first
6921 (while (progn (setq e (marker-position endpos))
6924 ((save-excursion (skip-chars-backward " \t")
6926 (verilog-forward-ws&directives)
6927 (indent-line-to base-ind)
6928 (verilog-forward-ws&directives)
6930 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6933 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6936 ;; Now find biggest prefix
6937 (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
6938 ;; Now indent each line.
6939 (goto-char (marker-position startpos))
6940 (while (progn (setq e (marker-position endpos))
6941 (setq r (- e (point)))
6944 (unless quiet (message "%d" r))
6945 ;; (verilog-do-indent (verilog-calculate-indent)))
6946 (verilog-forward-ws&directives)
6948 ((or (and verilog-indent-declaration-macros
6949 (looking-at verilog-declaration-re-2-macro))
6950 (looking-at verilog-declaration-re-2-no-macro))
6951 (let ((p (match-end 0)))
6953 (if (verilog-re-search-forward "[[#`]" p 'move)
6957 (goto-char (marker-position m1))
6963 ((verilog-continued-line-1 (marker-position startpos))
6965 (indent-line-to ind))
6966 ((verilog-in-struct-p)
6967 ;; could have a declaration of a user defined item
6969 (verilog-end-of-statement))
6970 (t ; Must be comment or white space
6972 (verilog-forward-ws&directives)
6975 (unless quiet (message "")))))))
6977 (defun verilog-pretty-expr (&optional quiet _myre)
6978 "Line up expressions around point, optionally QUIET with regexp _MYRE ignored."
6980 (if (not (verilog-in-comment-or-string-p))
6982 (let ( (rexp (concat "^\\s-*" verilog-complete-reg))
6983 (rexp1 (concat "^\\s-*" verilog-basic-complete-re)))
6985 (if (and (not (looking-at rexp ))
6986 (looking-at verilog-assignment-operation-re)
6988 (goto-char (match-end 2))
6989 (and (not (verilog-in-attribute-p))
6990 (not (verilog-in-parameter-p))
6991 (not (verilog-in-comment-or-string-p)))))
6992 (let* ((here (point))
6998 (verilog-backward-syntactic-ws)
7000 (while (and (not (looking-at rexp1))
7001 (looking-at verilog-assignment-operation-re)
7005 (verilog-backward-syntactic-ws)
7007 ) ;Ack, need to grok `define
7013 (setq e (point)) ;Might be on last line
7014 (verilog-forward-syntactic-ws)
7017 (not (looking-at rexp1 ))
7018 (looking-at verilog-assignment-operation-re)
7021 (not (eq e (point)))))
7023 (verilog-forward-syntactic-ws)
7027 (endpos (set-marker (make-marker) end))
7031 (verilog-do-indent (verilog-calculate-indent))
7032 (if (and (not quiet)
7033 (> (- end start) 100))
7034 (message "Lining up expressions..(please stand by)"))
7036 ;; Set indent to minimum throughout region
7037 (while (< (point) (marker-position endpos))
7039 (verilog-just-one-space verilog-assignment-operation-re)
7041 (verilog-do-indent (verilog-calculate-indent))
7043 (verilog-forward-syntactic-ws)
7046 ;; Now find biggest prefix
7047 (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))
7049 ;; Now indent each line.
7051 (while (progn (setq e (marker-position endpos))
7052 (setq r (- e (point)))
7055 (if (not quiet) (message "%d" r))
7057 ((looking-at verilog-assignment-operation-re)
7058 (goto-char (match-beginning 2))
7059 (if (not (or (verilog-in-parenthesis-p) ; leave attributes and comparisons alone
7060 (verilog-in-coverage-p)))
7061 (if (eq (char-after) ?=)
7062 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
7066 ((verilog-continued-line-1 start)
7068 (indent-line-to ind))
7069 (t ; Must be comment or white space
7071 (verilog-forward-ws&directives)
7075 (unless quiet (message ""))
7078 (defun verilog-just-one-space (myre)
7079 "Remove extra spaces around regular expression MYRE."
7081 (if (and (not(looking-at verilog-complete-reg))
7083 (let ((p1 (match-end 1))
7089 (just-one-space)))))
7091 (defun verilog-indent-declaration (baseind)
7092 "Indent current lines as declaration.
7093 Line up the variable names based on previous declaration's indentation.
7094 BASEIND is the base indent to offset everything."
7096 (let ((pos (point-marker))
7097 (lim (save-excursion
7098 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
7099 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
7105 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
7106 (indent-line-to val)
7108 ;; Use previous declaration (in this module) as template.
7109 (if (or (eq 'all verilog-auto-lineup)
7110 (eq 'declarations verilog-auto-lineup))
7111 (if (verilog-re-search-backward
7112 (or (and verilog-indent-declaration-macros
7113 verilog-declaration-re-1-macro)
7114 verilog-declaration-re-1-no-macro) lim t)
7116 (goto-char (match-end 0))
7117 (skip-chars-forward " \t")
7118 (setq ind (current-column))
7122 (eval (cdr (assoc 'declaration verilog-indent-alist)))))
7123 (indent-line-to val)
7124 (if (and verilog-indent-declaration-macros
7125 (looking-at verilog-declaration-re-2-macro))
7126 (let ((p (match-end 0)))
7128 (if (verilog-re-search-forward "[[#`]" p 'move)
7132 (goto-char (marker-position m1))
7135 (if (/= (current-column) ind)
7139 (if (looking-at verilog-declaration-re-2-no-macro)
7140 (let ((p (match-end 0)))
7142 (if (verilog-re-search-forward "[[`#]" p 'move)
7146 (goto-char (marker-position m1))
7149 (if (/= (current-column) ind)
7152 (indent-to ind))))))))))
7155 (defun verilog-get-lineup-indent (b edpos)
7156 "Return the indent level that will line up several lines within the region.
7157 Region is defined by B and EDPOS."
7161 ;; Get rightmost position
7162 (while (progn (setq e (marker-position edpos))
7164 (if (verilog-re-search-forward
7165 (or (and verilog-indent-declaration-macros
7166 verilog-declaration-re-1-macro)
7167 verilog-declaration-re-1-no-macro) e 'move)
7169 (goto-char (match-end 0))
7170 (verilog-backward-syntactic-ws)
7171 (if (> (current-column) ind)
7172 (setq ind (current-column)))
7173 (goto-char (match-end 0)))))
7176 ;; No lineup-string found
7179 (verilog-backward-syntactic-ws)
7180 ;;(skip-chars-backward " \t")
7181 (1+ (current-column))))))
7183 (defun verilog-get-lineup-indent-2 (myre b edpos)
7184 "Return the indent level that will line up several lines within the region."
7188 ;; Get rightmost position
7189 (while (progn (setq e (marker-position edpos))
7191 (if (and (verilog-re-search-forward myre e 'move)
7192 (not (verilog-in-attribute-p))) ; skip attribute exprs
7194 (goto-char (match-beginning 2))
7195 (verilog-backward-syntactic-ws)
7196 (if (> (current-column) ind)
7197 (setq ind (current-column)))
7198 (goto-char (match-end 0)))
7202 ;; No lineup-string found
7205 (skip-chars-backward " \t")
7206 (1+ (current-column))))))
7208 (defun verilog-comment-depth (type val)
7209 "A useful mode debugging aide. TYPE and VAL are comments for insertion."
7216 (if (re-search-backward " /\\* [#-]# [a-zA-Z]+ [0-9]+ ## \\*/" b t)
7218 (replace-match " /* -# ## */")
7222 (insert " /* ## ## */"))))
7225 (format "%s %d" type val))))
7230 (defvar verilog-str nil)
7231 (defvar verilog-all nil)
7232 (defvar verilog-pred nil)
7233 (defvar verilog-buffer-to-use nil)
7234 (defvar verilog-flag nil)
7235 (defvar verilog-toggle-completions nil
7236 "True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
7237 Repeated use of \\[verilog-complete-word] will show you all of them.
7238 Normally, when there is more than one possible completion,
7239 it displays a list of all possible completions.")
7240 (when (boundp 'completion-cycle-threshold)
7241 (make-obsolete-variable
7242 'verilog-toggle-completions 'completion-cycle-threshold "26.1"))
7245 (defvar verilog-type-keywords
7247 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
7248 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
7249 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
7250 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
7251 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
7252 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
7254 "Keywords for types used when completing a word in a declaration or parmlist.
7255 \(integer, real, reg...)")
7257 (defvar verilog-cpp-keywords
7258 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
7260 "Keywords to complete when at first word of a line in declarative scope.
7261 \(initial, always, begin, assign...)
7262 The procedures and variables defined within the Verilog program
7263 will be completed at runtime and should not be added to this list.")
7265 (defvar verilog-defun-keywords
7268 "always" "always_comb" "always_ff" "always_latch" "assign"
7269 "begin" "end" "generate" "endgenerate" "module" "endmodule"
7270 "specify" "endspecify" "function" "endfunction" "initial" "final"
7271 "task" "endtask" "primitive" "endprimitive"
7273 verilog-type-keywords)
7274 "Keywords to complete when at first word of a line in declarative scope.
7275 \(initial, always, begin, assign...)
7276 The procedures and variables defined within the Verilog program
7277 will be completed at runtime and should not be added to this list.")
7279 (defvar verilog-block-keywords
7281 "begin" "break" "case" "continue" "else" "end" "endfunction"
7282 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
7283 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
7285 "Keywords to complete when at first word of a line in behavioral scope.
7286 \(begin, if, then, else, for, fork...)
7287 The procedures and variables defined within the Verilog program
7288 will be completed at runtime and should not be added to this list.")
7290 (defvar verilog-tf-keywords
7291 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
7292 "Keywords to complete when at first word of a line in a task or function.
7293 \(begin, if, then, else, for, fork.)
7294 The procedures and variables defined within the Verilog program
7295 will be completed at runtime and should not be added to this list.")
7297 (defvar verilog-case-keywords
7298 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
7299 "Keywords to complete when at first word of a line in case scope.
7300 \(begin, if, then, else, for, fork...)
7301 The procedures and variables defined within the Verilog program
7302 will be completed at runtime and should not be added to this list.")
7304 (defvar verilog-separator-keywords
7305 '("else" "then" "begin")
7306 "Keywords to complete when NOT standing at the first word of a statement.
7307 \(else, then, begin...)
7308 Variables and function names defined within the Verilog program
7309 will be completed at runtime and should not be added to this list.")
7311 (defvar verilog-gate-ios
7312 ;; All these have an implied {"input"...} at the end
7326 ("pulldown" "output")
7331 ("rtran" "inout" "inout")
7332 ("rtranif0" "inout" "inout")
7333 ("rtranif1" "inout" "inout")
7334 ("tran" "inout" "inout")
7335 ("tranif0" "inout" "inout")
7336 ("tranif1" "inout" "inout")
7339 "Map of direction for each positional argument to each gate primitive.")
7341 (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
7342 "Keywords for gate primitives.")
7344 (defun verilog-string-diff (str1 str2)
7345 "Return index of first letter where STR1 and STR2 differs."
7349 (if (or (> (1+ diff) (length str1))
7350 (> (1+ diff) (length str2)))
7352 (or (equal (aref str1 diff) (aref str2 diff))
7354 (setq diff (1+ diff))))))
7356 ;; Calculate all possible completions for functions if argument is `function',
7357 ;; completions for procedures if argument is `procedure' or both functions and
7358 ;; procedures otherwise.
7360 (defun verilog-func-completion (type)
7361 "Build regular expression for module/task/function names.
7362 TYPE is `module', `tf' for task or function, or t if unknown."
7363 (if (string= verilog-str "")
7364 (setq verilog-str "[a-zA-Z_]"))
7365 (let ((verilog-str (concat (cond
7366 ((eq type 'module) "\\<\\(module\\)\\s +")
7367 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
7368 (t "\\<\\(task\\|function\\|module\\)\\s +"))
7369 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
7372 (if (not (looking-at verilog-defun-re))
7373 (verilog-re-search-backward verilog-defun-re nil t))
7376 ;; Search through all reachable functions
7377 (goto-char (point-min))
7378 (while (verilog-re-search-forward verilog-str (point-max) t)
7379 (progn (setq match (buffer-substring (match-beginning 2)
7381 (if (or (null verilog-pred)
7382 (funcall verilog-pred match))
7383 (setq verilog-all (cons match verilog-all)))))
7384 (if (match-beginning 0)
7385 (goto-char (match-beginning 0)))))
7387 (defun verilog-get-completion-decl (end)
7388 "Macro for searching through current declaration (var, type or const)
7389 for matches of `str' and adding the occurrence tp `all' through point END."
7390 (let ((re (or (and verilog-indent-declaration-macros
7391 verilog-declaration-re-2-macro)
7392 verilog-declaration-re-2-no-macro))
7395 (while (and (< (point) end)
7396 (verilog-re-search-forward re end t))
7397 ;; Traverse current line
7398 (setq decl-end (save-excursion (verilog-declaration-end)))
7399 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
7400 (not (match-end 1)))
7401 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
7402 (if (string-match (concat "\\<" verilog-str) match)
7403 (if (or (null verilog-pred)
7404 (funcall verilog-pred match))
7405 (setq verilog-all (cons match verilog-all)))))
7409 (defun verilog-var-completion ()
7410 "Calculate all possible completions for variables (or constants)."
7411 (let ((start (point)))
7412 ;; Search for all reachable var declarations
7413 (verilog-beg-of-defun)
7415 ;; Check var declarations
7416 (verilog-get-completion-decl start))))
7418 (defun verilog-keyword-completion (keyword-list)
7419 "Give list of all possible completions of keywords in KEYWORD-LIST."
7421 (if (string-match (concat "\\<" verilog-str) s)
7422 (if (or (null verilog-pred)
7423 (funcall verilog-pred s))
7424 (setq verilog-all (cons s verilog-all)))))
7428 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
7429 "Function passed to `completing-read', `try-completion' or `all-completions'.
7430 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
7431 must be a function to be called for every match to check if this should
7432 really be a match. If VERILOG-FLAG is t, the function returns a list of
7433 all possible completions. If VERILOG-FLAG is nil it returns a string,
7434 the longest possible completion, or t if VERILOG-STR is an exact match.
7435 If VERILOG-FLAG is `lambda', the function returns t if VERILOG-STR is an
7436 exact match, nil otherwise."
7438 (let ((verilog-all nil))
7439 ;; Set buffer to use for searching labels. This should be set
7440 ;; within functions which use verilog-completions
7441 (set-buffer verilog-buffer-to-use)
7443 ;; Determine what should be completed
7444 (let ((state (car (verilog-calculate-indent))))
7445 (cond ((eq state 'defun)
7446 (save-excursion (verilog-var-completion))
7447 (verilog-func-completion 'module)
7448 (verilog-keyword-completion verilog-defun-keywords))
7450 ((eq state 'behavioral)
7451 (save-excursion (verilog-var-completion))
7452 (verilog-func-completion 'module)
7453 (verilog-keyword-completion verilog-defun-keywords))
7456 (save-excursion (verilog-var-completion))
7457 (verilog-func-completion 'tf)
7458 (verilog-keyword-completion verilog-block-keywords))
7461 (save-excursion (verilog-var-completion))
7462 (verilog-func-completion 'tf)
7463 (verilog-keyword-completion verilog-case-keywords))
7466 (save-excursion (verilog-var-completion))
7467 (verilog-func-completion 'tf)
7468 (verilog-keyword-completion verilog-tf-keywords))
7471 (save-excursion (verilog-var-completion))
7472 (verilog-keyword-completion verilog-cpp-keywords))
7474 ((eq state 'cparenexp)
7475 (save-excursion (verilog-var-completion)))
7478 (save-excursion (verilog-var-completion))
7479 (verilog-func-completion 'both)
7480 (verilog-keyword-completion verilog-separator-keywords))))
7482 ;; Now we have built a list of all matches. Give response to caller
7483 (verilog-completion-response))))
7485 (defun verilog-completion-response ()
7486 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
7487 ;; This was not called by all-completions
7488 (if (null verilog-all)
7489 ;; Return nil if there was no matching label
7491 ;; Get longest string common in the labels
7492 ;; FIXME: Why not use `try-completion'?
7493 (let* ((elm (cdr verilog-all))
7494 (match (car verilog-all))
7495 (min (length match))
7497 (if (string= match verilog-str)
7498 ;; Return t if first match was an exact match
7500 (while (not (null elm))
7501 ;; Find longest common string
7502 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
7505 (setq match (substring match 0 min))))
7506 ;; Terminate with match=t if this is an exact match
7507 (if (string= (car elm) verilog-str)
7511 (setq elm (cdr elm)))))
7512 ;; If this is a test just for exact match, return nil ot t
7513 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
7516 ;; If flag is t, this was called by all-completions. Return
7517 ;; list of all possible completions
7521 (defvar verilog-last-word-numb 0)
7522 (defvar verilog-last-word-shown nil)
7523 (defvar verilog-last-completions nil)
7525 (defun verilog-completion-at-point ()
7526 "Used as an element of `completion-at-point-functions'.
7527 \(See also `verilog-type-keywords' and
7528 `verilog-separator-keywords'.)"
7529 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7530 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7531 (verilog-str (buffer-substring b e))
7532 ;; The following variable is used in verilog-completion
7533 (verilog-buffer-to-use (current-buffer))
7534 (allcomp (if (and verilog-toggle-completions
7535 (string= verilog-last-word-shown verilog-str))
7536 verilog-last-completions
7537 (all-completions verilog-str 'verilog-completion))))
7538 (list b e allcomp)))
7540 (defun verilog-complete-word ()
7541 "Complete word at current point.
7542 \(See also `verilog-toggle-completions', `verilog-type-keywords',
7543 and `verilog-separator-keywords'.)"
7544 ;; NOTE: This is just a fallback for Emacs versions lacking
7545 ;; `completion-at-point'.
7547 (let* ((comp-info (verilog-completion-at-point))
7548 (b (nth 0 comp-info))
7549 (e (nth 1 comp-info))
7550 (verilog-str (buffer-substring b e))
7551 (allcomp (nth 2 comp-info))
7552 (match (if verilog-toggle-completions
7554 verilog-str (mapcar (lambda (elm)
7555 (cons elm 0)) allcomp)))))
7556 ;; Delete old string
7559 ;; Toggle-completions inserts whole labels
7560 (if verilog-toggle-completions
7562 ;; Update entry number in list
7563 (setq verilog-last-completions allcomp
7564 verilog-last-word-numb
7565 (if (>= verilog-last-word-numb (1- (length allcomp)))
7567 (1+ verilog-last-word-numb)))
7568 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
7569 ;; Display next match or same string if no match was found
7570 (if (not (null allcomp))
7571 (insert "" verilog-last-word-shown)
7572 (insert "" verilog-str)
7573 (message "(No match)")))
7574 ;; The other form of completion does not necessarily do that.
7576 ;; Insert match if found, or the original string if no match
7577 (if (or (null match) (equal match 't))
7578 (progn (insert "" verilog-str)
7579 (message "(No match)"))
7581 ;; Give message about current status of completion
7582 (cond ((equal match 't)
7583 (if (not (null (cdr allcomp)))
7584 (message "(Complete but not unique)")
7585 (message "(Sole completion)")))
7586 ;; Display buffer if the current completion didn't help
7587 ;; on completing the label.
7588 ((and (not (null (cdr allcomp))) (= (length verilog-str)
7590 (with-output-to-temp-buffer "*Completions*"
7591 (display-completion-list allcomp))
7592 ;; Wait for a key press. Then delete *Completion* window
7593 (momentary-string-display "" (point))
7594 (delete-window (get-buffer-window (get-buffer "*Completions*")))
7597 (defun verilog-show-completions ()
7598 "Show all possible completions at current point."
7599 ;; NOTE: This is just a fallback for Emacs versions lacking
7600 ;; `completion-help-at-point'.
7602 ;; Show possible completions in a temporary buffer.
7603 (with-output-to-temp-buffer "*Completions*"
7604 (display-completion-list (nth 2 (verilog-completion-at-point))))
7605 ;; Wait for a key press. Then delete *Completion* window
7606 (momentary-string-display "" (point))
7607 (delete-window (get-buffer-window (get-buffer "*Completions*"))))
7609 (defun verilog-get-default-symbol ()
7610 "Return symbol around current point as a string."
7612 (buffer-substring (progn
7613 (skip-chars-backward " \t")
7614 (skip-chars-backward "a-zA-Z0-9_")
7617 (skip-chars-forward "a-zA-Z0-9_")
7620 (defun verilog-build-defun-re (str &optional arg)
7621 "Return function/task/module starting with STR as regular expression.
7622 With optional second ARG non-nil, STR is the complete name of the instruction."
7624 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
7625 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
7627 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
7628 "Function passed to `completing-read', `try-completion' or `all-completions'.
7629 Returns a completion on any function name based on VERILOG-STR prefix. If
7630 VERILOG-PRED is non-nil, it must be a function to be called for every match
7631 to check if this should really be a match. If VERILOG-FLAG is t, the
7632 function returns a list of all possible completions. If it is nil it
7633 returns a string, the longest possible completion, or t if VERILOG-STR is
7634 an exact match. If VERILOG-FLAG is `lambda', the function returns t if
7635 VERILOG-STR is an exact match, nil otherwise."
7637 (let ((verilog-all nil)
7640 ;; Set buffer to use for searching labels. This should be set
7641 ;; within functions which use verilog-completions
7642 (set-buffer verilog-buffer-to-use)
7644 (let ((verilog-str verilog-str))
7645 ;; Build regular expression for functions
7646 (if (string= verilog-str "")
7647 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
7648 (setq verilog-str (verilog-build-defun-re verilog-str)))
7649 (goto-char (point-min))
7651 ;; Build a list of all possible completions
7652 (while (verilog-re-search-forward verilog-str nil t)
7653 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
7654 (if (or (null verilog-pred)
7655 (funcall verilog-pred match))
7656 (setq verilog-all (cons match verilog-all)))))
7658 ;; Now we have built a list of all matches. Give response to caller
7659 (verilog-completion-response))))
7661 (defun verilog-goto-defun ()
7662 "Move to specified Verilog module/interface/task/function.
7663 The default is a name found in the buffer around point.
7664 If search fails, other files are checked based on
7665 `verilog-library-flags'."
7667 (let* ((default (verilog-get-default-symbol))
7668 ;; The following variable is used in verilog-comp-function
7669 (verilog-buffer-to-use (current-buffer))
7670 (label (if (not (string= default ""))
7671 ;; Do completion with default
7672 (completing-read (concat "Goto-Label: (default "
7674 'verilog-comp-defun nil nil "")
7675 ;; There is no default value. Complete without it
7676 (completing-read "Goto-Label: "
7677 'verilog-comp-defun nil nil "")))
7679 ;; Make sure library paths are correct, in case need to resolve module
7680 (verilog-auto-reeval-locals)
7681 (verilog-getopt-flags)
7682 ;; If there was no response on prompt, use default value
7683 (if (string= label "")
7684 (setq label default))
7685 ;; Goto right place in buffer if label is not an empty string
7686 (or (string= label "")
7689 (goto-char (point-min))
7691 (re-search-forward (verilog-build-defun-re label t) nil t)))
7694 (beginning-of-line))
7696 (verilog-goto-defun-file label))))
7698 ;; Eliminate compile warning
7699 (defvar occur-pos-list)
7701 (defun verilog-showscopes ()
7702 "List all scopes in this module."
7704 (let ((buffer (current-buffer))
7708 (prevpos (point-min))
7709 (final-context-start (make-marker))
7710 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
7711 (with-output-to-temp-buffer "*Occur*"
7713 (message "Searching for %s ..." regexp)
7714 ;; Find next match, but give up if prev match was at end of buffer.
7715 (while (and (not (= prevpos (point-max)))
7716 (verilog-re-search-forward regexp nil t))
7717 (goto-char (match-beginning 0))
7720 (setq linenum (+ linenum (count-lines prevpos (point)))))
7721 (setq prevpos (point))
7722 (goto-char (match-end 0))
7723 (let* ((start (save-excursion
7724 (goto-char (match-beginning 0))
7725 (forward-line (if (< nlines 0) nlines (- nlines)))
7727 (end (save-excursion
7728 (goto-char (match-end 0))
7730 (forward-line (1+ nlines))
7733 (tag (format "%3d" linenum))
7734 (empty (make-string (length tag) ?\ ))
7737 (setq tem (make-marker))
7738 (set-marker tem (point))
7739 (set-buffer standard-output)
7740 (setq occur-pos-list (cons tem occur-pos-list))
7741 (or first (zerop nlines)
7742 (insert "--------\n"))
7744 (insert-buffer-substring buffer start end)
7745 (backward-char (- end start))
7746 (setq tem (if (< nlines 0) (- nlines) nlines))
7750 (setq tem (1- tem)))
7751 (let ((this-linenum linenum))
7752 (set-marker final-context-start
7753 (+ (point) (- (match-end 0) (match-beginning 0))))
7754 (while (< (point) final-context-start)
7756 (setq tag (format "%3d" this-linenum)))
7757 (insert tag ?:)))))))
7758 (set-buffer-modified-p nil))))
7761 ;; Highlight helper functions
7762 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
7764 (defun verilog-within-translate-off ()
7765 "Return point if within translate-off region, else nil."
7766 (and (save-excursion
7768 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
7770 (equal "off" (match-string 2))
7773 (defun verilog-start-translate-off (limit)
7774 "Return point before translate-off directive if before LIMIT, else nil."
7775 (when (re-search-forward
7776 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7778 (match-beginning 0)))
7780 (defun verilog-back-to-start-translate-off (limit)
7781 "Return point before translate-off directive if before LIMIT, else nil."
7782 (when (re-search-backward
7783 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7785 (match-beginning 0)))
7787 (defun verilog-end-translate-off (limit)
7788 "Return point after translate-on directive if before LIMIT, else nil."
7790 (re-search-forward (concat
7791 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
7793 (defun verilog-match-translate-off (limit)
7794 "Match a translate-off block, setting `match-data' and returning t, else nil.
7795 Bound search by LIMIT."
7796 (when (< (point) limit)
7797 (let ((start (or (verilog-within-translate-off)
7798 (verilog-start-translate-off limit)))
7799 (case-fold-search t))
7801 (let ((end (or (verilog-end-translate-off limit) limit)))
7802 (set-match-data (list start end))
7803 (goto-char end))))))
7805 (defun verilog-font-lock-match-item (limit)
7806 "Match, and move over, any declaration item after point.
7807 Bound search by LIMIT. Adapted from
7808 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
7811 (narrow-to-region (point-min) limit)
7813 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
7815 (goto-char (match-end 1))
7816 ;; move to next item
7817 (if (looking-at "\\(\\s-*,\\)")
7818 (goto-char (match-end 1))
7823 ;; Added by Subbu Meiyappan for Header
7825 (defun verilog-header ()
7826 "Insert a standard Verilog file header.
7827 See also `verilog-sk-header' for an alternative format."
7829 (let ((start (point)))
7831 //-----------------------------------------------------------------------------
7833 // Project : <project>
7834 //-----------------------------------------------------------------------------
7835 // File : <filename>
7836 // Author : <author>
7837 // Created : <credate>
7838 // Last modified : <moddate>
7839 //-----------------------------------------------------------------------------
7842 //-----------------------------------------------------------------------------
7843 // Copyright (c) <copydate> by <company> This model is the confidential and
7844 // proprietary property of <company> and the possession or use of this
7845 // file requires a written license from <company>.
7846 //------------------------------------------------------------------------------
7847 // Modification history :
7849 //-----------------------------------------------------------------------------
7853 (search-forward "<filename>")
7854 (replace-match (buffer-name) t t)
7855 (search-forward "<author>") (replace-match "" t t)
7856 (insert (user-full-name))
7857 (insert " <" (user-login-name) "@" (system-name) ">")
7858 (search-forward "<credate>") (replace-match "" t t)
7859 (verilog-insert-date)
7860 (search-forward "<moddate>") (replace-match "" t t)
7861 (verilog-insert-date)
7862 (search-forward "<copydate>") (replace-match "" t t)
7863 (verilog-insert-year)
7864 (search-forward "<modhist>") (replace-match "" t t)
7865 (verilog-insert-date)
7866 (insert " : created")
7869 (setq string (read-string "title: "))
7870 (search-forward "<title>")
7871 (replace-match string t t)
7872 (setq string (read-string "project: " verilog-project))
7873 (setq verilog-project string)
7874 (search-forward "<project>")
7875 (replace-match string t t)
7876 (setq string (read-string "Company: " verilog-company))
7877 (setq verilog-company string)
7878 (search-forward "<company>")
7879 (replace-match string t t)
7880 (search-forward "<company>")
7881 (replace-match string t t)
7882 (search-forward "<company>")
7883 (replace-match string t t)
7884 (search-backward "<description>")
7885 (replace-match "" t t))))
7887 ;; verilog-header Uses the verilog-insert-date function
7889 (defun verilog-insert-date ()
7890 "Insert date from the system."
7892 (if verilog-date-scientific-format
7893 (insert (format-time-string "%Y/%m/%d"))
7894 (insert (format-time-string "%d.%m.%Y"))))
7896 (defun verilog-insert-year ()
7897 "Insert year from the system."
7899 (insert (format-time-string "%Y")))
7902 ;;; Signal list parsing:
7905 ;; Elements of a signal list
7906 ;; Unfortunately we use 'assoc' on this, so can't be a vector
7907 (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
7908 (list name bits comment mem enum signed type multidim modport))
7909 (defsubst verilog-sig-name (sig)
7911 (defsubst verilog-sig-bits (sig) ; First element of packed array (pre signal-name)
7913 (defsubst verilog-sig-comment (sig)
7915 (defsubst verilog-sig-memory (sig) ; Unpacked array (post signal-name)
7917 (defsubst verilog-sig-enum (sig)
7919 (defsubst verilog-sig-signed (sig)
7921 (defsubst verilog-sig-type (sig)
7923 (defsubst verilog-sig-type-set (sig type)
7924 (setcar (nthcdr 6 sig) type))
7925 (defsubst verilog-sig-multidim (sig) ; Second and additional elements of packed array
7927 (defsubst verilog-sig-multidim-string (sig)
7928 (if (verilog-sig-multidim sig)
7929 (let ((str "") (args (verilog-sig-multidim sig)))
7931 (setq str (concat (car args) str))
7932 (setq args (cdr args)))
7934 (defsubst verilog-sig-modport (sig)
7936 (defsubst verilog-sig-width (sig)
7937 (verilog-make-width-expression (verilog-sig-bits sig)))
7939 (defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
7940 (vector outputs-del outputs-imm temps inputs))
7941 (defsubst verilog-alw-get-outputs-delayed (sigs)
7943 (defsubst verilog-alw-get-outputs-immediate (sigs)
7945 (defsubst verilog-alw-get-temps (sigs)
7947 (defsubst verilog-alw-get-inputs (sigs)
7949 (defsubst verilog-alw-get-uses-delayed (sigs)
7952 (defsubst verilog-modport-new (name clockings decls)
7953 (list name clockings decls))
7954 (defsubst verilog-modport-name (sig)
7956 (defsubst verilog-modport-clockings (sig)
7957 (nth 1 sig)) ; Returns list of names
7958 (defsubst verilog-modport-clockings-add (sig val)
7959 (setcar (nthcdr 1 sig) (cons val (nth 1 sig))))
7960 (defsubst verilog-modport-decls (sig)
7961 (nth 2 sig)) ; Returns verilog-decls-* structure
7962 (defsubst verilog-modport-decls-set (sig val)
7963 (setcar (nthcdr 2 sig) val))
7965 (defsubst verilog-modi-new (name fob pt type)
7966 (vector name fob pt type))
7967 (defsubst verilog-modi-name (modi)
7969 (defsubst verilog-modi-file-or-buffer (modi)
7971 (defsubst verilog-modi-get-point (modi)
7973 (defsubst verilog-modi-get-type (modi) ; "module" or "interface"
7975 (defsubst verilog-modi-get-decls (modi)
7976 (verilog-modi-cache-results modi 'verilog-read-decls))
7977 (defsubst verilog-modi-get-sub-decls (modi)
7978 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
7980 ;; Signal reading for given module
7981 ;; Note these all take modi's - as returned from verilog-modi-current
7982 (defsubst verilog-decls-new (out inout in vars modports assigns consts gparams interfaces)
7983 (vector out inout in vars modports assigns consts gparams interfaces))
7984 (defsubst verilog-decls-append (a b)
7985 (cond ((not a) b) ((not b) a)
7986 (t (vector (append (aref a 0) (aref b 0)) (append (aref a 1) (aref b 1))
7987 (append (aref a 2) (aref b 2)) (append (aref a 3) (aref b 3))
7988 (append (aref a 4) (aref b 4)) (append (aref a 5) (aref b 5))
7989 (append (aref a 6) (aref b 6)) (append (aref a 7) (aref b 7))
7990 (append (aref a 8) (aref b 8))))))
7991 (defsubst verilog-decls-get-outputs (decls)
7993 (defsubst verilog-decls-get-inouts (decls)
7995 (defsubst verilog-decls-get-inputs (decls)
7997 (defsubst verilog-decls-get-vars (decls)
7999 (defsubst verilog-decls-get-modports (decls) ; Also for clocking blocks; contains another verilog-decls struct
8000 (aref decls 4)) ; Returns verilog-modport* structure
8001 (defsubst verilog-decls-get-assigns (decls)
8003 (defsubst verilog-decls-get-consts (decls)
8005 (defsubst verilog-decls-get-gparams (decls)
8007 (defsubst verilog-decls-get-interfaces (decls)
8011 (defsubst verilog-subdecls-new (out inout in intf intfd)
8012 (vector out inout in intf intfd))
8013 (defsubst verilog-subdecls-get-outputs (subdecls)
8015 (defsubst verilog-subdecls-get-inouts (subdecls)
8017 (defsubst verilog-subdecls-get-inputs (subdecls)
8019 (defsubst verilog-subdecls-get-interfaces (subdecls)
8021 (defsubst verilog-subdecls-get-interfaced (subdecls)
8024 (defun verilog-signals-from-signame (signame-list)
8025 "Return signals in standard form from SIGNAME-LIST, a simple list of names."
8026 (mapcar (lambda (name) (verilog-sig-new name nil nil nil nil nil nil nil nil))
8029 (defun verilog-signals-in (in-list not-list)
8030 "Return list of signals in IN-LIST that are also in NOT-LIST.
8031 Also remove any duplicates in IN-LIST.
8032 Signals must be in standard (base vector) form."
8033 ;; This function is hot, so implemented as O(1)
8034 (cond ((eval-when-compile (fboundp 'make-hash-table))
8035 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
8036 (ht-not (make-hash-table :test 'equal :rehash-size 4.0))
8039 (puthash (car (car not-list)) t ht-not)
8040 (setq not-list (cdr not-list)))
8042 (when (and (gethash (verilog-sig-name (car in-list)) ht-not)
8043 (not (gethash (verilog-sig-name (car in-list)) ht)))
8044 (setq out-list (cons (car in-list) out-list))
8045 (puthash (verilog-sig-name (car in-list)) t ht))
8046 (setq in-list (cdr in-list)))
8047 (nreverse out-list)))
8048 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
8052 (if (and (assoc (verilog-sig-name (car in-list)) not-list)
8053 (not (assoc (verilog-sig-name (car in-list)) out-list)))
8054 (setq out-list (cons (car in-list) out-list)))
8055 (setq in-list (cdr in-list)))
8056 (nreverse out-list)))))
8057 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("C" "")))
8059 (defun verilog-signals-not-in (in-list not-list)
8060 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
8061 Also remove any duplicates in IN-LIST.
8062 Signals must be in standard (base vector) form."
8063 ;; This function is hot, so implemented as O(1)
8064 (cond ((eval-when-compile (fboundp 'make-hash-table))
8065 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
8068 (puthash (car (car not-list)) t ht)
8069 (setq not-list (cdr not-list)))
8071 (when (not (gethash (verilog-sig-name (car in-list)) ht))
8072 (setq out-list (cons (car in-list) out-list))
8073 (puthash (verilog-sig-name (car in-list)) t ht))
8074 (setq in-list (cdr in-list)))
8075 (nreverse out-list)))
8076 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
8080 (if (and (not (assoc (verilog-sig-name (car in-list)) not-list))
8081 (not (assoc (verilog-sig-name (car in-list)) out-list)))
8082 (setq out-list (cons (car in-list) out-list)))
8083 (setq in-list (cdr in-list)))
8084 (nreverse out-list)))))
8085 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
8087 (defun verilog-signals-not-in-struct (in-list not-list)
8088 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
8089 Also remove any duplicates in IN-LIST.
8090 Any structure in not-list will remove all members in in-list.
8091 Signals must be in standard (base vector) form."
8092 (cond ((eval-when-compile (fboundp 'make-hash-table))
8093 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
8096 (puthash (car (car not-list)) t ht)
8097 (setq not-list (cdr not-list)))
8099 (setq nm (verilog-sig-name (car in-list)))
8100 (when (not (gethash nm ht))
8102 (while (string-match "^\\([^\\].*\\)\\.[^.]+$" nm)
8103 (setq nm (match-string 1 nm))
8104 (setq addit (and addit
8105 (not (gethash nm ht)))))
8107 (setq out-list (cons (car in-list) out-list))
8108 (puthash (verilog-sig-name (car in-list)) t ht)))
8109 (setq in-list (cdr in-list)))
8110 (nreverse out-list)))
8111 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
8113 (let (out-list addit nm)
8115 (setq nm (verilog-sig-name (car in-list)))
8116 (when (and (not (assoc nm not-list))
8117 (not (assoc nm out-list)))
8119 (while (string-match "^\\([^\\].*\\)\\.[^.]+$" nm)
8120 (setq nm (match-string 1 nm))
8121 (setq addit (and addit
8122 (not (assoc nm not-list)))))
8124 (setq out-list (cons (car in-list) out-list))))
8125 (setq in-list (cdr in-list)))
8126 (nreverse out-list)))))
8127 ;;(verilog-signals-not-in-struct '(("A" "") ("B" "") ("DEL.SUB.A" "[2:3]")) '(("DEL.SUB" "") ("EXT" "")))
8129 (defun verilog-signals-memory (in-list)
8130 "Return list of signals in IN-LIST that are memorized (multidimensional)."
8133 (if (nth 3 (car in-list))
8134 (setq out-list (cons (car in-list) out-list)))
8135 (setq in-list (cdr in-list)))
8137 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
8139 (defun verilog-signals-sort-compare (a b)
8140 "Compare signal A and B for sorting."
8141 (string< (verilog-sig-name a) (verilog-sig-name b)))
8143 (defun verilog-signals-not-params (in-list)
8144 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
8147 ;; Namespace intentionally short for AUTOs and compatibility
8148 (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
8149 (setq out-list (cons (car in-list) out-list)))
8150 (setq in-list (cdr in-list)))
8151 (nreverse out-list)))
8153 (defun verilog-signals-with (func in-list)
8154 "Return list of signals where FUNC is true executed on each signal in IN-LIST."
8157 (when (funcall func (car in-list))
8158 (setq out-list (cons (car in-list) out-list)))
8159 (setq in-list (cdr in-list)))
8160 (nreverse out-list)))
8162 (defun verilog-signals-combine-bus (in-list)
8163 "Return a list of signals in IN-LIST, with buses combined.
8164 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
8168 sig highbit lowbit ; Temp information about current signal
8169 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
8170 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
8173 ;; Shove signals so duplicated signals will be adjacent
8174 (setq in-list (sort in-list `verilog-signals-sort-compare))
8176 (setq sig (car in-list))
8177 ;; No current signal; form from existing details
8179 (setq sv-name (verilog-sig-name sig)
8182 sv-comment (verilog-sig-comment sig)
8183 sv-memory (verilog-sig-memory sig)
8184 sv-enum (verilog-sig-enum sig)
8185 sv-signed (verilog-sig-signed sig)
8186 sv-type (verilog-sig-type sig)
8187 sv-multidim (verilog-sig-multidim sig)
8188 sv-modport (verilog-sig-modport sig)
8191 ;; Extract bus details
8192 (setq bus (verilog-sig-bits sig))
8193 (setq bus (and bus (verilog-simplify-range-expression bus)))
8195 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
8196 (setq highbit (string-to-number (match-string 1 bus))
8197 lowbit (string-to-number
8198 (match-string 2 bus))))
8199 (and (string-match "\\[\\([0-9]+\\)\\]" bus)
8200 (setq highbit (string-to-number (match-string 1 bus))
8202 ;; Combine bits in bus
8204 (setq sv-highbit (max highbit sv-highbit)
8205 sv-lowbit (min lowbit sv-lowbit))
8206 (setq sv-highbit highbit
8209 ;; String, probably something like `preproc:0
8210 (setq sv-busstring bus)))
8211 ;; Peek ahead to next signal
8212 (setq in-list (cdr in-list))
8213 (setq sig (car in-list))
8214 (cond ((and sig (equal sv-name (verilog-sig-name sig)))
8215 ;; Combine with this signal
8216 (when (and sv-busstring
8217 (not (equal sv-busstring (verilog-sig-bits sig))))
8218 (when nil ; Debugging
8219 (message (concat "Warning, can't merge into single bus `%s%s'"
8220 ", the AUTOs may be wrong")
8222 (setq buswarn ", Couldn't Merge"))
8223 (if (verilog-sig-comment sig) (setq combo ", ..."))
8224 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
8225 sv-enum (or sv-enum (verilog-sig-enum sig))
8226 sv-signed (or sv-signed (verilog-sig-signed sig))
8227 sv-type (or sv-type (verilog-sig-type sig))
8228 sv-multidim (or sv-multidim (verilog-sig-multidim sig))
8229 sv-modport (or sv-modport (verilog-sig-modport sig))))
8230 ;; Doesn't match next signal, add to queue, zero in prep for next
8231 ;; Note sig may also be nil for the last signal in the list
8234 (cons (verilog-sig-new
8238 (concat "[" (int-to-string sv-highbit) ":"
8239 (int-to-string sv-lowbit) "]")))
8240 (concat sv-comment combo buswarn)
8241 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
8247 (defun verilog-sig-tieoff (sig)
8248 "Return tieoff expression for given SIG, with appropriate width.
8249 Tieoff value uses `verilog-active-low-regexp' and
8250 `verilog-auto-reset-widths'."
8252 (if (and verilog-active-low-regexp
8253 (verilog-string-match-fold verilog-active-low-regexp (verilog-sig-name sig)))
8255 (cond ((not verilog-auto-reset-widths)
8257 ((equal verilog-auto-reset-widths 'unbased)
8259 ;; Else presume verilog-auto-reset-widths is true
8261 (let* ((width (verilog-sig-width sig)))
8264 ((string-match "^[0-9]+$" width)
8265 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0")))
8267 (concat "{" width "{1'b0}}"))))))))
8273 (defun verilog-decls-princ (decls &optional header prefix)
8274 "For debug, dump the `verilog-read-decls' structure DECLS.
8275 Use optional HEADER and PREFIX."
8277 (if header (princ header))
8278 (setq prefix (or prefix ""))
8279 (verilog-signals-princ (verilog-decls-get-outputs decls)
8280 (concat prefix "Outputs:\n") (concat prefix " "))
8281 (verilog-signals-princ (verilog-decls-get-inouts decls)
8282 (concat prefix "Inout:\n") (concat prefix " "))
8283 (verilog-signals-princ (verilog-decls-get-inputs decls)
8284 (concat prefix "Inputs:\n") (concat prefix " "))
8285 (verilog-signals-princ (verilog-decls-get-vars decls)
8286 (concat prefix "Vars:\n") (concat prefix " "))
8287 (verilog-signals-princ (verilog-decls-get-assigns decls)
8288 (concat prefix "Assigns:\n") (concat prefix " "))
8289 (verilog-signals-princ (verilog-decls-get-consts decls)
8290 (concat prefix "Consts:\n") (concat prefix " "))
8291 (verilog-signals-princ (verilog-decls-get-gparams decls)
8292 (concat prefix "Gparams:\n") (concat prefix " "))
8293 (verilog-signals-princ (verilog-decls-get-interfaces decls)
8294 (concat prefix "Interfaces:\n") (concat prefix " "))
8295 (verilog-modport-princ (verilog-decls-get-modports decls)
8296 (concat prefix "Modports:\n") (concat prefix " "))
8299 (defun verilog-signals-princ (signals &optional header prefix)
8300 "For debug, dump internal SIGNALS structures, with HEADER and PREFIX."
8302 (if header (princ header))
8304 (let ((sig (car signals)))
8305 (setq signals (cdr signals))
8307 (princ "\"") (princ (verilog-sig-name sig)) (princ "\"")
8308 (princ " bits=") (princ (verilog-sig-bits sig))
8309 (princ " cmt=") (princ (verilog-sig-comment sig))
8310 (princ " mem=") (princ (verilog-sig-memory sig))
8311 (princ " enum=") (princ (verilog-sig-enum sig))
8312 (princ " sign=") (princ (verilog-sig-signed sig))
8313 (princ " type=") (princ (verilog-sig-type sig))
8314 (princ " dim=") (princ (verilog-sig-multidim sig))
8315 (princ " modp=") (princ (verilog-sig-modport sig))
8318 (defun verilog-modport-princ (modports &optional header prefix)
8319 "For debug, dump internal MODPORTS structures, with HEADER and PREFIX."
8321 (if header (princ header))
8323 (let ((sig (car modports)))
8324 (setq modports (cdr modports))
8326 (princ "\"") (princ (verilog-modport-name sig)) (princ "\"")
8327 (princ " clockings=") (princ (verilog-modport-clockings sig))
8329 (verilog-decls-princ (verilog-modport-decls sig)
8330 (concat prefix " syms:\n")
8331 (concat prefix " "))))))
8334 ;; Port/Wire/Etc Reading
8337 (defun verilog-read-inst-backward-name ()
8338 "Internal. Move point back to beginning of inst-name."
8339 (verilog-backward-open-paren)
8342 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_$]\\|\\]\\)" nil nil) ; ] isn't word boundary
8343 (cond ((looking-at ")")
8344 (verilog-backward-open-paren))
8345 (t (setq done t)))))
8346 (while (looking-at "\\]")
8347 (verilog-backward-open-bracket)
8348 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|\\]\\)" nil nil))
8349 (skip-chars-backward "a-zA-Z0-9`_$"))
8351 (defun verilog-read-inst-module-matcher ()
8352 "Set match data 0 with module_name when point is inside instantiation."
8353 (verilog-read-inst-backward-name)
8354 ;; Skip over instantiation name
8355 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|)\\)" nil nil) ; ) isn't word boundary
8356 ;; Check for parameterized instantiations
8357 (when (looking-at ")")
8358 (verilog-backward-open-paren)
8359 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_$]" nil nil))
8360 (skip-chars-backward "a-zA-Z0-9'_$")
8361 ;; #1 is legal syntax for gate primitives
8362 (when (save-excursion
8363 (verilog-backward-syntactic-ws-quick)
8364 (eq ?# (char-before)))
8365 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_$]" nil nil)
8366 (skip-chars-backward "a-zA-Z0-9'_$"))
8367 (looking-at "[a-zA-Z0-9`_$]+")
8368 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8369 (buffer-substring-no-properties (match-beginning 0) (match-end 0))
8370 ;; Caller assumes match-beginning/match-end is still set
8373 (defun verilog-read-inst-module ()
8374 "Return module_name when point is inside instantiation."
8376 (verilog-read-inst-module-matcher)))
8378 (defun verilog-read-inst-name ()
8379 "Return instance_name when point is inside instantiation."
8381 (verilog-read-inst-backward-name)
8382 (looking-at "[a-zA-Z0-9`_$]+")
8383 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8384 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
8386 (defun verilog-read-module-name ()
8387 "Return module name when after its ( or ;."
8389 (re-search-backward "[(;]")
8390 ;; Due to "module x import y (" we must search for declaration begin
8391 (verilog-re-search-backward-quick verilog-defun-re nil nil)
8392 (goto-char (match-end 0))
8393 (verilog-re-search-forward-quick "\\b[a-zA-Z0-9`_$]+" nil nil)
8394 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8395 (verilog-symbol-detick
8396 (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
8398 (defun verilog-read-inst-param-value ()
8399 "Return list of parameters and values when point is inside instantiation."
8401 (verilog-read-inst-backward-name)
8402 ;; Skip over instantiation name
8403 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|)\\)" nil nil) ; ) isn't word boundary
8404 ;; If there are parameterized instantiations
8405 (when (looking-at ")")
8406 (let ((end-pt (point))
8408 param-name paren-beg-pt param-value)
8409 (verilog-backward-open-paren)
8410 (while (verilog-re-search-forward-quick "\\." end-pt t)
8411 (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_$]\\)" nil nil)
8412 (skip-chars-backward "a-zA-Z0-9'_$")
8413 (looking-at "[a-zA-Z0-9`_$]+")
8414 (setq param-name (buffer-substring-no-properties
8415 (match-beginning 0) (match-end 0)))
8416 (verilog-re-search-forward-quick "(" nil nil)
8417 (setq paren-beg-pt (point))
8418 (verilog-forward-close-paren)
8419 (setq param-value (verilog-string-remove-spaces
8420 (buffer-substring-no-properties
8421 paren-beg-pt (1- (point)))))
8422 (setq params (cons (list param-name param-value) params)))
8425 (defun verilog-read-auto-params (num-param &optional max-param)
8426 "Return parameter list inside auto.
8427 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
8430 ;; /*AUTOPUNT("parameter", "parameter")*/
8432 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
8433 (setq olist (cons (match-string 1) olist))
8434 (goto-char (match-end 0))))
8435 (or (eq nil num-param)
8436 (<= num-param (length olist))
8437 (error "%s: Expected %d parameters" (verilog-point-text) num-param))
8438 (if (eq max-param nil) (setq max-param num-param))
8439 (or (eq nil max-param)
8440 (>= max-param (length olist))
8441 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
8444 (defun verilog-read-decls ()
8445 "Compute signal declaration information for the current module at point.
8446 Return an array of [outputs inouts inputs wire reg assign const]."
8447 (let ((end-mod-point (or (verilog-get-end-of-defun) (point-max)))
8448 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
8449 in-modport in-clocking in-ign-to-semi ptype ign-prop
8450 sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
8451 sigs-gparam sigs-intf sigs-modports
8452 vec expect-signal keywd last-keywd newsig rvalue enum io
8453 signed typedefed multidim
8456 ;;(if dbg (setq dbg (concat dbg (format "\n\nverilog-read-decls START PT %s END %s\n" (point) end-mod-point))))
8458 (verilog-beg-of-defun-quick)
8459 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
8460 (while (< (point) end-mod-point)
8461 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
8464 (when (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8465 (setq enum (match-string 2)))
8466 (search-forward "\n"))
8467 ((looking-at "/\\*")
8469 (when (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8470 (setq enum (match-string 2)))
8471 (or (search-forward "*/")
8472 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8473 ((looking-at "(\\*")
8474 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8476 (or (search-forward "*)")
8477 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8478 ((eq ?\" (following-char))
8479 (or (re-search-forward "[^\\]\"" nil t) ; don't forward-char first, since we look for a non backslash first
8480 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
8481 ((eq ?\; (following-char))
8482 (cond (in-ign-to-semi ; Such as inside a "import ...;" in a module header
8483 (setq in-ign-to-semi nil rvalue nil))
8484 ((and in-modport (not (eq in-modport t))) ; end of a modport declaration
8485 (verilog-modport-decls-set
8487 (verilog-decls-new sigs-out sigs-inout sigs-in
8488 nil nil nil nil nil nil))
8489 ;; Pop from varstack to restore state to pre-clocking
8490 (setq tmp (car varstack)
8491 varstack (cdr varstack)
8492 sigs-out (aref tmp 0)
8493 sigs-inout (aref tmp 1)
8494 sigs-in (aref tmp 2))
8495 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
8496 v2kargs-ok nil in-modport nil ign-prop nil))
8498 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
8499 v2kargs-ok nil in-modport nil ign-prop nil)))
8501 ((eq ?= (following-char))
8502 (setq rvalue t newsig nil)
8504 ((and (eq ?, (following-char))
8505 (eq paren sig-paren))
8508 ;; ,'s can occur inside {} & funcs
8509 ((looking-at "[{(]")
8510 (setq paren (1+ paren))
8512 ((looking-at "[})]")
8513 (setq paren (1- paren))
8515 (when (< paren sig-paren)
8516 (setq expect-signal nil rvalue nil))) ; ) that ends variables inside v2k arg list
8517 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
8518 (goto-char (match-end 0))
8519 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
8520 (setcar (cdr (cdr (cdr newsig)))
8521 (if (verilog-sig-memory newsig)
8522 (concat (verilog-sig-memory newsig) (match-string 1))
8523 (match-string-no-properties 1))))
8524 (vec ; Multidimensional
8525 (setq multidim (cons vec multidim))
8526 (setq vec (verilog-string-replace-matches
8527 "\\s-+" "" nil nil (match-string-no-properties 1))))
8529 (setq vec (verilog-string-replace-matches
8530 "\\s-+" "" nil nil (match-string-no-properties 1))))))
8531 ;; Normal or escaped identifier -- note we remember the \ if escaped
8532 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8533 (goto-char (match-end 0))
8534 (setq last-keywd keywd
8535 keywd (match-string-no-properties 1))
8536 (when (string-match "^\\\\" (match-string 1))
8537 (setq keywd (concat keywd " "))) ; Escaped ID needs space at end
8538 ;; Add any :: package names to same identifier
8539 ;; '*' here is for "import x::*"
8540 (while (looking-at "\\s-*::\\s-*\\(\\*\\|[a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8541 (goto-char (match-end 0))
8542 (setq keywd (concat keywd "::" (match-string 1)))
8543 (when (string-match "^\\\\" (match-string 1))
8544 (setq keywd (concat keywd " ")))) ; Escaped ID needs space at end
8545 (cond ((equal keywd "input")
8546 (setq vec nil enum nil rvalue nil newsig nil signed nil
8547 typedefed nil multidim nil ptype nil modport nil
8548 expect-signal 'sigs-in io t sig-paren paren))
8549 ((equal keywd "output")
8550 (setq vec nil enum nil rvalue nil newsig nil signed nil
8551 typedefed nil multidim nil ptype nil modport nil
8552 expect-signal 'sigs-out io t sig-paren paren))
8553 ((equal keywd "inout")
8554 (setq vec nil enum nil rvalue nil newsig nil signed nil
8555 typedefed nil multidim nil ptype nil modport nil
8556 expect-signal 'sigs-inout io t sig-paren paren))
8557 ((equal keywd "parameter")
8558 (setq vec nil enum nil rvalue nil signed nil
8559 typedefed nil multidim nil ptype nil modport nil
8560 expect-signal 'sigs-gparam io t sig-paren paren))
8561 ((member keywd '("wire" "reg" ; Fast
8563 "tri" "tri0" "tri1" "triand" "trior" "trireg"
8564 "uwire" "wand" "wor"
8565 ;; integer_atom_type
8566 "byte" "shortint" "int" "longint" "integer" "time"
8568 ;; integer_vector_type - "reg" above
8571 "shortreal" "real" "realtime"
8573 "string" "event" "chandle"))
8576 (if typedefed (concat typedefed " " keywd) keywd)))
8577 (t (setq vec nil enum nil rvalue nil signed nil
8578 typedefed nil multidim nil sig-paren paren
8579 expect-signal 'sigs-var modport nil))))
8580 ((equal keywd "assign")
8581 (setq vec nil enum nil rvalue nil signed nil
8582 typedefed nil multidim nil ptype nil modport nil
8583 expect-signal 'sigs-assign sig-paren paren))
8584 ((member keywd '("localparam" "genvar"))
8585 (setq vec nil enum nil rvalue nil signed nil
8586 typedefed nil multidim nil ptype nil modport nil
8587 expect-signal 'sigs-const sig-paren paren))
8588 ((member keywd '("signed" "unsigned"))
8589 (setq signed keywd))
8590 ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
8592 ((member keywd '("class" "covergroup" "function"
8593 "property" "randsequence" "sequence" "task"))
8595 (setq functask (1+ functask))))
8596 ((member keywd '("endclass" "endgroup" "endfunction"
8597 "endproperty" "endsequence" "endtask"))
8598 (setq functask (1- functask)))
8599 ((equal keywd "modport")
8600 (setq in-modport t))
8601 ((and (equal keywd "clocking")
8602 (not (equal last-keywd "default")))
8603 (setq in-clocking t))
8604 ((equal keywd "import")
8605 (when v2kargs-ok ; import in module header, not a modport import
8606 (setq in-ign-to-semi t rvalue t)))
8607 ((equal keywd "type")
8609 ((equal keywd "var"))
8610 ;; Ifdef? Ignore name of define
8611 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8615 (verilog-typedef-name-p keywd))
8618 (if typedefed (concat typedefed " " keywd) keywd)))
8619 (t (setq vec nil enum nil rvalue nil signed nil
8620 typedefed keywd ; Have a type
8621 multidim nil sig-paren paren
8622 expect-signal 'sigs-var modport nil))))
8623 ;; Interface with optional modport in v2k arglist?
8624 ;; Skip over parsing modport, and take the interface name as the type
8628 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
8629 (when (match-end 2) (goto-char (match-end 2)))
8630 (setq vec nil enum nil rvalue nil signed nil
8631 typedefed keywd multidim nil ptype nil modport (match-string 2)
8632 newsig nil sig-paren paren
8633 expect-signal 'sigs-intf io t ))
8634 ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
8635 ((looking-at "\\s-*\\.")
8636 (goto-char (match-end 0))
8638 (setq expect-signal nil)))
8639 ;; "modport <keywd>"
8640 ((and (eq in-modport t)
8641 (not (member keywd verilog-keywords)))
8642 (setq in-modport (verilog-modport-new keywd nil nil))
8643 (setq sigs-modports (cons in-modport sigs-modports))
8644 ;; Push old sig values to stack and point to new signal list
8645 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8647 (setq sigs-in nil sigs-inout nil sigs-out nil))
8648 ;; "modport x (clocking <keywd>)"
8649 ((and in-modport in-clocking)
8650 (verilog-modport-clockings-add in-modport keywd)
8651 (setq in-clocking nil))
8654 (equal keywd "endclocking"))
8655 (unless (eq in-clocking t)
8656 (verilog-modport-decls-set
8658 (verilog-decls-new sigs-out sigs-inout sigs-in
8659 nil nil nil nil nil nil))
8660 ;; Pop from varstack to restore state to pre-clocking
8661 (setq tmp (car varstack)
8662 varstack (cdr varstack)
8663 sigs-out (aref tmp 0)
8664 sigs-inout (aref tmp 1)
8665 sigs-in (aref tmp 2)))
8666 (setq in-clocking nil))
8667 ;; "clocking <keywd>"
8668 ((and (eq in-clocking t)
8669 (not (member keywd verilog-keywords)))
8670 (setq in-clocking (verilog-modport-new keywd nil nil))
8671 (setq sigs-modports (cons in-clocking sigs-modports))
8672 ;; Push old sig values to stack and point to new signal list
8673 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8675 (setq sigs-in nil sigs-inout nil sigs-out nil))
8676 ;; New signal, maybe?
8680 (not (member keywd verilog-keywords)))
8681 ;; Add new signal to expect-signal's variable
8682 ;;(if dbg (setq dbg (concat dbg (format "Pt %s New sig %s'\n" (point) keywd))))
8683 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
8684 (set expect-signal (cons newsig
8685 (symbol-value expect-signal))))))
8688 (skip-syntax-forward " "))
8690 (setq tmp (verilog-decls-new (nreverse sigs-out)
8691 (nreverse sigs-inout)
8694 (nreverse sigs-modports)
8695 (nreverse sigs-assign)
8696 (nreverse sigs-const)
8697 (nreverse sigs-gparam)
8698 (nreverse sigs-intf)))
8699 ;;(if dbg (verilog-decls-princ tmp))
8702 (defvar verilog-read-sub-decls-in-interfaced nil
8703 "For `verilog-read-sub-decls', process next signal as under interfaced block.")
8705 (defvar verilog-read-sub-decls-gate-ios nil
8706 "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
8709 ;; Prevent compile warnings; these are let's, not globals
8710 ;; Do not remove the eval-when-compile
8711 ;; - we want an error when we are debugging this code if they are refed.
8719 (defvar sigs-out-unk)
8721 ;; These are known to be from other packages and may not be defined
8722 (defvar diff-command)
8723 ;; There are known to be from newer versions of Emacs
8724 (defvar create-lockfiles)
8725 (defvar which-func-modes))
8727 (defun verilog-read-sub-decls-type (par-values portdata)
8728 "For `verilog-read-sub-decls-line', decode a signal type."
8729 (let* ((type (verilog-sig-type portdata))
8730 (pvassoc (assoc type par-values)))
8731 (cond ((member type '("wire" "reg")) nil)
8732 (pvassoc (nth 1 pvassoc))
8735 (defun verilog-read-sub-decls-sig (submoddecls par-values comment port sig vec multidim mem)
8736 "For `verilog-read-sub-decls-line', add a signal."
8737 ;; sig eq t to indicate .name syntax
8738 ;;(message "vrsds: %s(%S)" port sig)
8739 (let ((dotname (eq sig t))
8742 (setq port (verilog-symbol-detick-denumber port))
8743 (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
8744 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
8745 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
8746 (if mem (setq mem (verilog-symbol-detick-denumber mem)))
8747 (unless (or (not sig)
8748 (equal sig "")) ; Ignore .foo(1'b1) assignments
8749 (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
8750 (equal "inout" verilog-read-sub-decls-gate-ios))
8752 (cons (verilog-sig-new
8754 (if dotname (verilog-sig-bits portdata) vec)
8755 (concat "To/From " comment)
8758 (verilog-sig-signed portdata)
8759 (verilog-read-sub-decls-type par-values portdata)
8762 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
8763 (equal "output" verilog-read-sub-decls-gate-ios))
8765 (cons (verilog-sig-new
8767 (if dotname (verilog-sig-bits portdata) vec)
8768 (concat "From " comment)
8771 (verilog-sig-signed portdata)
8772 ;; Though ok in SV, in V2K code, propagating the
8773 ;; "reg" in "output reg" upwards isn't legal.
8774 ;; Also for backwards compatibility we don't propagate
8775 ;; "input wire" upwards.
8776 ;; See also `verilog-signals-edit-wire-reg'.
8777 (verilog-read-sub-decls-type par-values portdata)
8780 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
8781 (equal "input" verilog-read-sub-decls-gate-ios))
8783 (cons (verilog-sig-new
8785 (if dotname (verilog-sig-bits portdata) vec)
8786 (concat "To " comment)
8789 (verilog-sig-signed portdata)
8790 (verilog-read-sub-decls-type par-values portdata)
8793 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
8795 (cons (verilog-sig-new
8797 (if dotname (verilog-sig-bits portdata) vec)
8798 (concat "To/From " comment)
8801 (verilog-sig-signed portdata)
8802 (verilog-read-sub-decls-type par-values portdata)
8805 ((setq portdata (and verilog-read-sub-decls-in-interfaced
8806 (assoc port (verilog-decls-get-vars submoddecls))))
8808 (cons (verilog-sig-new
8810 (if dotname (verilog-sig-bits portdata) vec)
8811 (concat "To/From " comment)
8814 (verilog-sig-signed portdata)
8815 (verilog-read-sub-decls-type par-values portdata)
8818 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
8821 (defun verilog-read-sub-decls-expr (submoddecls par-values comment port expr)
8822 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
8823 ;;(message "vrsde: `%s'" expr)
8824 ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
8825 (setq expr (verilog-string-replace-matches "/\\*\\(\\.?\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
8826 ;; Remove front operators
8827 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8830 ;; {..., a, b} requires us to recurse on a,b
8831 ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
8832 ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
8833 (unless verilog-auto-ignore-concat
8834 (let ((mlst (split-string (match-string 1 expr) "[{},]"))
8836 (while (setq mstr (pop mlst))
8837 (verilog-read-sub-decls-expr submoddecls par-values comment port mstr)))))
8839 (let (sig vec multidim mem)
8840 ;; Remove leading reduction operators, etc
8841 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8842 ;;(message "vrsde-ptop: `%s'" expr)
8843 (cond ; Find \signal. Final space is part of escaped signal name
8844 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
8845 ;;(message "vrsde-s: `%s'" (match-string 1 expr))
8846 (setq sig (match-string 1 expr)
8847 expr (substring expr (match-end 0))))
8849 ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
8850 ;;(message "vrsde-s: `%s'" (match-string 1 expr))
8851 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
8852 expr (substring expr (match-end 0)))))
8853 ;; Find [vector] or [multi][multi][multi][vector]
8854 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
8855 ;;(message "vrsde-v: `%s'" (match-string 1 expr))
8856 (when vec (setq multidim (cons vec multidim)))
8857 (setq vec (match-string 1 expr)
8858 expr (substring expr (match-end 0))))
8859 ;; Find .[unpacked_memory] or .[unpacked][unpacked]...
8860 (while (string-match "^\\s-*\\.\\(\\(\\[[^]]+\\]\\)+\\)" expr)
8861 ;;(message "vrsde-m: `%s'" (match-string 1 expr))
8862 (setq mem (match-string 1 expr)
8863 expr (substring expr (match-end 0))))
8864 ;; If found signal, and nothing unrecognized, add the signal
8865 ;;(message "vrsde-rem: `%s'" expr)
8866 (when (and sig (string-match "^\\s-*$" expr))
8867 (verilog-read-sub-decls-sig submoddecls par-values comment port sig vec multidim mem))))))
8869 (defun verilog-read-sub-decls-line (submoddecls par-values comment)
8870 "For `verilog-read-sub-decls', read lines of port defs until none match.
8871 Inserts the list of signals found, using submodi to look up each port."
8877 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
8878 (setq port (match-string-no-properties 1))
8879 (goto-char (match-end 0)))
8881 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
8882 (setq port (concat (match-string-no-properties 1) " ")) ; escaped id's need trailing space
8883 (goto-char (match-end 0)))
8885 ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
8886 (verilog-read-sub-decls-sig
8887 submoddecls par-values comment (match-string-no-properties 1) t ; sig==t for .name
8888 nil nil nil) ; vec multidim mem
8891 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
8892 (verilog-read-sub-decls-sig
8893 submoddecls par-values comment (concat (match-string-no-properties 1) " ") t ; sig==t for .name
8894 nil nil nil) ; vec multidim mem
8897 ((looking-at "\\s-*\\.[^(]*(")
8898 (setq port nil) ; skip this line
8899 (goto-char (match-end 0)))
8901 (setq port nil done t))) ; Unknown, ignore rest of line
8902 ;; Get signal name. Point is at the first-non-space after (
8903 ;; We intentionally ignore (non-escaped) signals with .s in them
8904 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
8906 (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
8907 (verilog-read-sub-decls-sig
8908 submoddecls par-values comment port
8909 (verilog-string-remove-spaces (match-string-no-properties 1)) ; sig
8910 nil nil nil)) ; vec multidim mem
8912 ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
8913 (verilog-read-sub-decls-sig
8914 submoddecls par-values comment port
8915 (verilog-string-remove-spaces (match-string-no-properties 1)) ; sig
8916 (match-string-no-properties 2) nil nil)) ; vec multidim mem
8917 ;; Fastpath was above looking-at's.
8918 ;; For something more complicated invoke a parser
8919 ((looking-at "[^)]+")
8920 (verilog-read-sub-decls-expr
8921 submoddecls par-values comment port
8922 (buffer-substring-no-properties
8923 (point) (1- (progn (search-backward "(") ; start at (
8924 (verilog-forward-sexp-ign-cmt 1)
8925 (point)))))))) ; expr
8927 (forward-line 1)))))
8928 ;;(verilog-read-sub-decls-line (verilog-subdecls-new nil nil nil nil nil) nil "Cmt")
8930 (defun verilog-read-sub-decls-gate (submoddecls par-values comment submod end-inst-point)
8931 "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
8932 Inserts the list of signals found."
8934 (let ((iolist (cdr (assoc submod verilog-gate-ios))))
8935 (while (< (point) end-inst-point)
8936 ;; Get primitive's signal name, as will never have port, and no trailing )
8937 (cond ((looking-at "//")
8938 (search-forward "\n"))
8939 ((looking-at "/\\*")
8940 (or (search-forward "*/")
8941 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8942 ((looking-at "(\\*")
8943 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8945 (or (search-forward "*)")
8946 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8947 ;; On pins, parse and advance to next pin
8948 ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
8949 ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
8950 (goto-char (match-end 0))
8951 (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
8952 iolist (cdr iolist))
8953 (verilog-read-sub-decls-expr
8954 submoddecls par-values comment "primitive_port"
8958 (skip-syntax-forward " ")))))))
8960 (defun verilog-read-sub-decls ()
8961 "Internally parse signals going to modules under this module.
8962 Return an array of [ outputs inouts inputs ] signals for modules that are
8963 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
8964 is an output, then SIG will be included in the list.
8966 This only works on instantiations created with /*AUTOINST*/ converted by
8967 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
8968 component library to determine connectivity of the design.
8970 One work around for this problem is to manually create // Inputs and //
8971 Outputs comments above subcell signals, for example:
8979 (let ((end-mod-point (verilog-get-end-of-defun))
8980 st-point end-inst-point par-values
8981 ;; below 3 modified by verilog-read-sub-decls-line
8982 sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
8983 (verilog-beg-of-defun-quick)
8984 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
8986 (goto-char (match-beginning 0))
8987 (setq par-values (and verilog-auto-inst-param-value
8988 verilog-auto-inst-param-value-type
8989 (verilog-read-inst-param-value)))
8990 (unless (verilog-inside-comment-or-string-p)
8991 ;; Attempt to snarf a comment
8992 (let* ((submod (verilog-read-inst-module))
8993 (inst (verilog-read-inst-name))
8994 (subprim (member submod verilog-gate-keywords))
8995 (comment (concat inst " of " submod ".v"))
8996 submodi submoddecls)
8999 (setq submodi `primitive
9000 submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
9001 comment (concat inst " of " submod))
9002 (verilog-backward-open-paren)
9003 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
9007 (verilog-read-sub-decls-gate submoddecls par-values comment submod end-inst-point))
9010 (when (setq submodi (verilog-modi-lookup submod t))
9011 (setq submoddecls (verilog-modi-get-decls submodi)
9012 verilog-read-sub-decls-gate-ios nil)
9013 (verilog-backward-open-paren)
9014 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
9017 ;; This could have used a list created by verilog-auto-inst
9018 ;; However I want it to be runnable even on user's manually added signals
9019 (let ((verilog-read-sub-decls-in-interfaced t))
9020 (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
9021 (verilog-read-sub-decls-line submoddecls par-values comment))) ; Modifies sigs-ifd
9022 (goto-char st-point)
9023 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
9024 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-out
9025 (goto-char st-point)
9026 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
9027 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-out
9028 (goto-char st-point)
9029 (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
9030 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-inout
9031 (goto-char st-point)
9032 (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
9033 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-in
9035 ;; Combine duplicate bits
9036 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
9037 (verilog-subdecls-new
9038 (verilog-signals-combine-bus (nreverse sigs-out))
9039 (verilog-signals-combine-bus (nreverse sigs-inout))
9040 (verilog-signals-combine-bus (nreverse sigs-in))
9041 (verilog-signals-combine-bus (nreverse sigs-intf))
9042 (verilog-signals-combine-bus (nreverse sigs-intfd))))))
9044 (defun verilog-read-inst-pins ()
9045 "Return an array of [ pins ] for the current instantiation at point.
9046 For example if declare A A (.B(SIG)) then B will be included in the list."
9048 (let ((end-mod-point (point)) ; presume at /*AUTOINST*/ point
9050 (verilog-backward-open-paren)
9051 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
9052 (setq pin (match-string 1))
9053 (unless (verilog-inside-comment-or-string-p)
9054 (setq pins (cons (list pin) pins))
9055 (when (looking-at "(")
9056 (verilog-forward-sexp-ign-cmt 1))))
9059 (defun verilog-read-arg-pins ()
9060 "Return an array of [ pins ] for the current argument declaration at point."
9062 (let ((end-mod-point (point)) ; presume at /*AUTOARG*/ point
9064 (verilog-backward-open-paren)
9065 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
9066 (setq pin (match-string 1))
9067 (unless (verilog-inside-comment-or-string-p)
9068 (setq pins (cons (list pin) pins))))
9071 (defun verilog-read-auto-constants (beg end-mod-point)
9072 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
9075 (let (sig-list tpl-end-pt)
9077 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
9078 (if (not (looking-at "\\s *("))
9079 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
9080 (search-forward "(" end-mod-point)
9081 (setq tpl-end-pt (save-excursion
9083 (verilog-forward-sexp-cmt 1) ; Moves to paren that closes argdecl's
9086 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
9087 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
9090 (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
9091 (make-variable-buffer-local 'verilog-cache-has-lisp)
9093 (defun verilog-read-auto-lisp-present ()
9094 "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
9096 (goto-char (point-min))
9097 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
9099 (defun verilog-read-auto-lisp (start end)
9100 "Look for and evaluate an AUTO_LISP between START and END.
9101 Must call `verilog-read-auto-lisp-present' before this function."
9102 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
9103 (when verilog-cache-has-lisp
9106 (while (re-search-forward "\\<AUTO_LISP(" end t)
9108 (let* ((beg-pt (prog1 (point)
9109 (verilog-forward-sexp-cmt 1))) ; Closing paren
9111 (verilog-in-hooks t))
9112 (eval-region beg-pt end-pt nil))))))
9114 (defun verilog-read-always-signals-recurse
9115 (exit-keywd rvalue temp-next)
9116 "Recursive routine for parentheses/bracket matching.
9117 EXIT-KEYWD is expression to stop at, nil if top level.
9118 RVALUE is true if at right hand side of equal.
9119 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
9120 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ; true if after a ; we are looking for rvalue
9121 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
9123 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
9124 (while (not (or (eobp) gotend))
9127 (search-forward "\n"))
9128 ((looking-at "/\\*")
9129 (or (search-forward "*/")
9130 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
9131 ((looking-at "(\\*")
9132 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
9134 (or (search-forward "*)")
9135 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
9136 (t (setq keywd (buffer-substring-no-properties
9138 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
9141 sig-last-tolk sig-tolk
9143 ;;(if dbg (setq dbg (concat dbg (format "\tPt=%S %S\trv=%S in=%S ee=%S gs=%S\n" (point) keywd rvalue ignore-next end-else-check got-sig))))
9146 (or (re-search-forward "[^\\]\"" nil t)
9147 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
9148 ;; else at top level loop, keep parsing
9149 ((and end-else-check (equal keywd "else"))
9150 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
9151 ;; no forward movement, want to see else in lower loop
9152 (setq end-else-check nil))
9153 ;; End at top level loop
9154 ((and end-else-check (looking-at "[^ \t\n\f]"))
9155 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
9158 ((and exit-keywd (and (equal keywd exit-keywd)
9159 (not (looking-at "::"))))
9161 (forward-char (length keywd)))
9162 ;; Standard tokens...
9164 (setq ignore-next nil rvalue semi-rvalue)
9165 ;; Final statement at top level loop?
9166 (when (not exit-keywd)
9167 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
9168 (setq end-else-check t))
9171 (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
9172 (goto-char (match-end 0))
9174 ((equal keywd ":") ; Case statement, begin/end label, x?y:z
9175 (cond ((looking-at "::")
9176 (forward-char 1)) ; Another forward-char below
9177 ((equal "endcase" exit-keywd) ; case x: y=z; statement next
9178 (setq ignore-next nil rvalue nil))
9179 ((equal "?" exit-keywd) ; x?y:z rvalue
9181 ((equal "]" exit-keywd) ; [x:y] rvalue
9183 (got-sig ; label: statement
9184 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
9185 ((not rvalue) ; begin label
9186 (setq ignore-next t rvalue nil)))
9190 ;;(if dbg (setq dbg (concat dbg (format "\t\tequal got-sig=%S got-list=%s\n" got-sig got-list))))
9191 (set got-list (cons got-sig (symbol-value got-list)))
9194 (if (eq (char-before) ?< )
9195 (setq sigs-out-d (append sigs-out-d sigs-out-unk)
9197 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
9199 (setq ignore-next nil rvalue t)
9203 (verilog-read-always-signals-recurse ":" rvalue nil))
9206 (verilog-read-always-signals-recurse "]" t nil))
9209 (cond (sig-last-tolk ; Function call; zap last signal
9210 (setq got-sig nil)))
9211 (cond ((equal last-keywd "for")
9212 ;; temp-next: Variables on LHS are lvalues, but generally we want
9213 ;; to ignore them, assuming they are loop increments
9214 (verilog-read-always-signals-recurse ";" nil t)
9215 (verilog-read-always-signals-recurse ";" t nil)
9216 (verilog-read-always-signals-recurse ")" nil nil))
9217 (t (verilog-read-always-signals-recurse ")" t nil))))
9218 ((equal keywd "begin")
9219 (skip-syntax-forward "w_")
9220 (verilog-read-always-signals-recurse "end" nil nil)
9221 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
9222 (setq ignore-next nil rvalue semi-rvalue)
9223 (if (not exit-keywd) (setq end-else-check t)))
9224 ((member keywd '("case" "casex" "casez" "randcase"))
9225 (skip-syntax-forward "w_")
9226 (verilog-read-always-signals-recurse "endcase" t nil)
9227 (setq ignore-next nil rvalue semi-rvalue)
9228 (if (not exit-keywd) (setq gotend t))) ; top level begin/end
9229 ((string-match "^[$`a-zA-Z_]" keywd) ; not exactly word constituent
9230 (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
9231 (setq ignore-next t))
9233 (member keywd verilog-keywords)
9234 (string-match "^\\$" keywd)) ; PLI task
9235 (setq ignore-next nil))
9237 (setq keywd (verilog-symbol-detick-denumber keywd))
9239 (set got-list (cons got-sig (symbol-value got-list)))
9240 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
9242 (setq got-list (cond (temp-next 'sigs-temp)
9245 got-sig (if (or (not keywd)
9246 (assoc keywd (symbol-value got-list)))
9247 nil (list keywd nil nil))
9250 (skip-chars-forward "a-zA-Z0-9$_.%`"))
9253 ;; End of non-comment token
9254 (setq last-keywd keywd)))
9255 (skip-syntax-forward " "))
9256 ;; Append the final pending signal
9258 ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
9259 (set got-list (cons got-sig (symbol-value got-list)))
9261 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
9264 (defun verilog-read-always-signals ()
9265 "Parse always block at point and return list of (outputs inout inputs)."
9268 sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
9269 (verilog-read-always-signals-recurse nil nil nil)
9270 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
9272 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*") (delete-region (point-min) (point-max)) (insert dbg) (setq dbg "")))
9273 ;; Return what was found
9274 (verilog-alw-new sigs-out-d sigs-out-i sigs-temp sigs-in))))
9276 (defun verilog-read-instants ()
9277 "Parse module at point and return list of ( ( file instance ) ... )."
9278 (verilog-beg-of-defun-quick)
9279 (let* ((end-mod-point (verilog-get-end-of-defun))
9281 (instants-list nil))
9283 (while (< (point) end-mod-point)
9284 ;; Stay at level 0, no comments
9286 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
9287 (or (> (car state) 0) ; in parens
9288 (nth 5 state) ; comment
9292 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
9293 ;;(if (looking-at "^\\(.+\\)$")
9294 (let ((module (match-string 1))
9295 (instant (match-string 2)))
9296 (if (not (member module verilog-keywords))
9297 (setq instants-list (cons (list module instant) instants-list)))))
9302 (defun verilog-read-auto-template-middle ()
9303 "With point in middle of an AUTO_TEMPLATE, parse it.
9304 Returns REGEXP and list of ( (signal_name connection_name)... )."
9307 (let ((tpl-regexp "\\([0-9]+\\)")
9308 (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
9310 tpl-sig-list tpl-wild-list tpl-end-pt rep)
9312 ;; We reserve @"..." for future lisp expressions that evaluate
9313 ;; once-per-AUTOINST
9314 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
9315 (setq tpl-regexp (match-string 1))
9316 (goto-char (match-end 0)))
9317 (search-forward "(")
9318 ;; Parse lines in the template
9319 (when (or verilog-auto-inst-template-numbers
9320 verilog-auto-template-warn-unused)
9322 (let ((pre-pt (point)))
9323 (goto-char (point-min))
9324 (while (search-forward "AUTO_TEMPLATE" pre-pt t)
9325 (setq templateno (1+ templateno)))
9326 (while (< (point) pre-pt)
9328 (setq lineno (1+ lineno))))))
9329 (setq tpl-end-pt (save-excursion
9331 (verilog-forward-sexp-cmt 1) ; Moves to paren that closes argdecl's
9335 (while (< (point) tpl-end-pt)
9336 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
9339 (match-string-no-properties 1)
9340 (match-string-no-properties 2)
9343 (goto-char (match-end 0)))
9346 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
9347 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
9348 (setq rep (match-string-no-properties 3))
9349 (goto-char (match-end 0))
9353 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
9359 ((looking-at "[ \t\f]+")
9360 (goto-char (match-end 0)))
9362 (setq lineno (1+ lineno))
9363 (goto-char (match-end 0)))
9365 (search-forward "\n")
9366 (setq lineno (1+ lineno)))
9367 ((looking-at "/\\*")
9369 (or (search-forward "*/")
9370 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
9372 (error "%s: AUTO_TEMPLATE parsing error: %s"
9373 (verilog-point-text)
9374 (progn (looking-at ".*$") (match-string 0))))))
9377 (list tpl-sig-list tpl-wild-list)))))
9379 (defun verilog-read-auto-template (module)
9380 "Look for an auto_template for the instantiation of the given MODULE.
9381 If found returns `verilog-read-auto-template-inside' structure."
9385 ;; Note this search is expensive, as we hunt from mod-begin to point
9386 ;; for every instantiation. Likewise in verilog-read-auto-lisp.
9387 ;; So, we look first for an exact string rather than a slow regexp.
9388 ;; Someday we may keep a cache of every template, but this would also
9389 ;; need to record the relative position of each AUTOINST, as multiple
9390 ;; templates exist for each module, and we're inserting lines.
9392 ;; See also regexp in `verilog-auto-template-lint'
9393 (verilog-re-search-backward-substr
9395 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
9396 ;; Also try forward of this AUTOINST
9397 ;; This is for historical support; this isn't speced as working
9400 (verilog-re-search-forward-substr
9402 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
9403 (goto-char (match-end 0))
9404 (verilog-read-auto-template-middle))
9405 ;; If no template found
9406 (t (vector "" nil))))))
9407 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
9409 (defvar verilog-auto-template-hits nil "Successful lookups with `verilog-read-auto-template-hit'.")
9410 (make-variable-buffer-local 'verilog-auto-template-hits)
9412 (defun verilog-read-auto-template-init ()
9413 "Initialize `verilog-read-auto-template'."
9414 (when (eval-when-compile (fboundp 'make-hash-table)) ; else feature not allowed
9415 (when verilog-auto-template-warn-unused
9416 (setq verilog-auto-template-hits
9417 (make-hash-table :test 'equal :rehash-size 4.0)))))
9419 (defun verilog-read-auto-template-hit (tpl-ass)
9420 "Record that TPL-ASS template from `verilog-read-auto-template' was used."
9421 (when (eval-when-compile (fboundp 'make-hash-table)) ; else feature not allowed
9422 (when verilog-auto-template-warn-unused
9423 (unless verilog-auto-template-hits
9424 (verilog-read-auto-template-init))
9425 (puthash (vector (nth 2 tpl-ass) (nth 3 tpl-ass)) t
9426 verilog-auto-template-hits))))
9428 (defun verilog-set-define (defname defvalue &optional buffer enumname)
9429 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
9430 Optionally associate it with the specified enumeration ENUMNAME."
9431 (with-current-buffer (or buffer (current-buffer))
9432 ;; Namespace intentionally short for AUTOs and compatibility
9433 (let ((mac (intern (concat "vh-" defname))))
9434 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
9435 ;; Need to define to a constant if no value given
9436 (set (make-local-variable mac)
9437 (if (equal defvalue "") "1" defvalue)))
9439 ;; Namespace intentionally short for AUTOs and compatibility
9440 (let ((enumvar (intern (concat "venum-" enumname))))
9441 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
9442 (unless (boundp enumvar) (set enumvar nil))
9443 (add-to-list (make-local-variable enumvar) defname)))))
9445 (defun verilog-read-defines (&optional filename recurse subcall)
9446 "Read \\=`defines and parameters for the current file, or optional FILENAME.
9447 If the filename is provided, `verilog-library-flags' will be used to
9448 resolve it. If optional RECURSE is non-nil, recurse through \\=`includes.
9450 Localparams must be simple assignments to constants, or have their own
9451 \"localparam\" label rather than a list of localparams. Thus:
9453 localparam X = 5, Y = 10; // Ok
9454 localparam X = {1\\='b1, 2\\='h2}; // Ok
9455 localparam X = {1\\='b1, 2\\='h2}, Y = 10; // Bad, make into 2 localparam lines
9457 Defines must be simple text substitutions, one on a line, starting
9458 at the beginning of the line. Any ifdefs or multiline comments around the
9461 Defines are stored inside Emacs variables using the name
9464 Localparams define what symbols are constants so that AUTOSENSE
9465 will not include them in sensitivity lists. However any
9466 parameters in the include file are not considered ports in the
9467 including file, thus will not appear in AUTOINSTPARAM lists for a
9470 The file variables feature can be used to set defines that
9471 `verilog-mode' can see; put at the *END* of your file something
9475 // vh-macro:\"macro_definition\"
9478 If macros are defined earlier in the same file and you want their values,
9479 you can read them automatically with:
9482 // verilog-auto-read-includes:t
9485 Or a more specific alternative example, which requires having
9486 `enable-local-eval' non-nil:
9489 // eval:(verilog-read-defines)
9490 // eval:(verilog-read-defines \"group_standard_includes.v\")
9493 Note these are only read when the file is first visited, you must use
9494 \\[find-alternate-file] RET to have these take effect after editing them!
9496 If you want to disable the \"Process `eval' or hook local variables\"
9497 warning message, you need to add to your init file:
9499 (setq enable-local-eval t)"
9500 (let ((origbuf (current-buffer)))
9502 (unless subcall (verilog-getopt-flags))
9504 (let ((fns (verilog-library-filenames filename (buffer-file-name))))
9506 (set-buffer (find-file-noselect (car fns)))
9507 (error "%s: Can't find verilog-read-defines file: %s"
9508 (verilog-point-text) filename))))
9510 (goto-char (point-min))
9511 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9512 (let ((inc (verilog-string-replace-matches
9513 "\"" "" nil nil (match-string-no-properties 1))))
9514 (unless (verilog-inside-comment-or-string-p)
9515 (verilog-read-defines inc recurse t)))))
9517 ;; note we don't use verilog-re... it's faster this way, and that
9518 ;; function has problems when comments are at the end of the define
9519 (goto-char (point-min))
9520 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
9521 (let ((defname (match-string-no-properties 1))
9522 (defvalue (match-string-no-properties 2)))
9523 (unless (verilog-inside-comment-or-string-p (match-beginning 0))
9524 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
9525 (verilog-set-define defname defvalue origbuf))))
9526 ;; Hack: Read parameters
9527 (goto-char (point-min))
9528 (while (re-search-forward
9529 "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
9531 ;; The primary way of getting defines is verilog-read-decls
9532 ;; However, that isn't called yet for included files, so we'll add another scheme
9533 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
9534 (setq enumname (match-string-no-properties 2)))
9535 (forward-comment 99999)
9536 (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
9537 "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
9538 (unless (verilog-inside-comment-or-string-p (match-beginning 0))
9539 (verilog-set-define (match-string-no-properties 1)
9540 (match-string-no-properties 2) origbuf enumname))
9541 (goto-char (match-end 0))
9542 (forward-comment 99999)))))))
9544 (defun verilog-read-includes ()
9545 "Read \\=`includes for the current file.
9546 This will find all of the \\=`includes which are at the beginning of lines,
9547 ignoring any ifdefs or multiline comments around them.
9548 `verilog-read-defines' is then performed on the current and each included
9551 It is often useful put at the *END* of your file something like:
9554 // verilog-auto-read-includes:t
9557 Or the equivalent longer version, which requires having
9558 `enable-local-eval' non-nil:
9561 // eval:(verilog-read-defines)
9562 // eval:(verilog-read-includes)
9565 Note includes are only read when the file is first visited, you must use
9566 \\[find-alternate-file] RET to have these take effect after editing them!
9568 It is good to get in the habit of including all needed files in each .v
9569 file that needs it, rather than waiting for compile time. This will aid
9570 this process, Verilint, and readability. To prevent defining the same
9571 variable over and over when many modules are compiled together, put a test
9572 around the inside each include file:
9574 foo.v (an include file):
9575 \\=`ifdef _FOO_V // include if not already included
9578 ... contents of file
9579 \\=`endif // _FOO_V"
9580 ;;slow: (verilog-read-defines nil t)
9582 (verilog-getopt-flags)
9583 (goto-char (point-min))
9584 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9585 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
9586 (verilog-read-defines inc nil t)))))
9588 (defun verilog-read-signals (&optional start end)
9589 "Return a simple list of all possible signals in the file.
9590 Bounded by optional region from START to END. Overly aggressive but fast.
9591 Some macros and such are also found and included. For dinotrace.el."
9592 (let (sigs-all keywd)
9593 (progn;save-excursion
9594 (goto-char (or start (point-min)))
9595 (setq end (or end (point-max)))
9596 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
9600 (search-forward "\n"))
9601 ((looking-at "/\\*")
9602 (search-forward "*/"))
9603 ((looking-at "(\\*")
9604 (or (looking-at "(\\*\\s-*)") ; It's an "always @ (*)"
9605 (search-forward "*)")))
9606 ((eq ?\" (following-char))
9607 (re-search-forward "[^\\]\"")) ; don't forward-char first, since we look for a non backslash first
9608 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
9609 (goto-char (match-end 0))
9610 (setq keywd (match-string-no-properties 1))
9611 (or (member keywd verilog-keywords)
9612 (member keywd sigs-all)
9613 (setq sigs-all (cons keywd sigs-all))))
9614 (t (forward-char 1))))
9619 ;; Argument file parsing
9622 (defun verilog-getopt (arglist)
9623 "Parse -f, -v etc arguments in ARGLIST list or string."
9624 (unless (listp arglist) (setq arglist (list arglist)))
9625 (let ((space-args '())
9627 ;; Split on spaces, so users can pass whole command lines
9629 (setq arg (car arglist)
9630 arglist (cdr arglist))
9631 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
9632 (setq space-args (append space-args
9633 (list (match-string-no-properties 1 arg))))
9634 (setq arg (match-string 2 arg))))
9637 (setq arg (car space-args)
9638 space-args (cdr space-args))
9642 (setq next-param arg))
9644 (setq next-param arg))
9646 (setq next-param arg))
9647 ;; +libext+(ext1)+(ext2)...
9648 ((string-match "^\\+libext\\+\\(.*\\)" arg)
9649 (setq arg (match-string 1 arg))
9650 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
9651 (verilog-add-list-unique `verilog-library-extensions
9652 (match-string 1 arg))
9653 (setq arg (match-string 2 arg))))
9655 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ; -Ddefine=val
9656 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ; -Ddefine
9657 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ; +define+val
9658 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ; +define+define
9659 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
9661 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ; +incdir+dir
9662 (string-match "^-I\\(.*\\)" arg)) ; -Idir
9663 (verilog-add-list-unique `verilog-library-directories
9664 (match-string 1 (substitute-in-file-name arg))))
9666 ((equal "+librescan" arg))
9667 ((string-match "^-U\\(.*\\)" arg)) ; -Udefine
9668 ;; Second parameters
9669 ((equal next-param "-f")
9670 (setq next-param nil)
9671 (verilog-getopt-file (substitute-in-file-name arg)))
9672 ((equal next-param "-v")
9673 (setq next-param nil)
9674 (verilog-add-list-unique `verilog-library-files
9675 (substitute-in-file-name arg)))
9676 ((equal next-param "-y")
9677 (setq next-param nil)
9678 (verilog-add-list-unique `verilog-library-directories
9679 (substitute-in-file-name arg)))
9681 ((string-match "^[^-+]" arg)
9682 (verilog-add-list-unique `verilog-library-files
9683 (substitute-in-file-name arg)))
9684 ;; Default - ignore; no warning
9686 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
9688 (defun verilog-getopt-file (filename)
9689 "Read Verilog options from the specified FILENAME."
9691 (let ((fns (verilog-library-filenames filename (buffer-file-name)))
9692 (orig-buffer (current-buffer))
9695 (set-buffer (find-file-noselect (car fns)))
9696 (error "%s: Can't find verilog-getopt-file -f file: %s"
9697 (verilog-point-text) filename))
9698 (goto-char (point-min))
9700 (setq line (buffer-substring (point) (point-at-eol)))
9702 (when (string-match "//" line)
9703 (setq line (substring line 0 (match-beginning 0))))
9704 (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
9705 (verilog-getopt line))))))
9707 (defun verilog-getopt-flags ()
9708 "Convert `verilog-library-flags' into standard library variables."
9709 ;; If the flags are local, then all the outputs should be local also
9710 (when (local-variable-p `verilog-library-flags (current-buffer))
9711 (mapc 'make-local-variable '(verilog-library-extensions
9712 verilog-library-directories
9713 verilog-library-files
9714 verilog-library-flags)))
9715 ;; Allow user to customize
9716 (verilog-run-hooks 'verilog-before-getopt-flags-hook)
9717 ;; Process arguments
9718 (verilog-getopt verilog-library-flags)
9719 ;; Allow user to customize
9720 (verilog-run-hooks 'verilog-getopt-flags-hook))
9722 (defun verilog-add-list-unique (varref object)
9723 "Append to VARREF list the given OBJECT,
9724 unless it is already a member of the variable's list."
9725 (unless (member object (symbol-value varref))
9726 (set varref (append (symbol-value varref) (list object))))
9728 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
9730 (defun verilog-current-flags ()
9731 "Convert `verilog-library-flags' and similar variables to command line.
9732 Used for __FLAGS__ in `verilog-expand-command'."
9733 (let ((cmd (mapconcat `concat verilog-library-flags " ")))
9734 (when (equal cmd "")
9736 "+libext+" (mapconcat `concat verilog-library-extensions "+")
9737 (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
9738 verilog-library-directories "")
9739 (mapconcat (lambda (i) (concat " -v " i))
9740 verilog-library-files ""))))
9742 ;;(verilog-current-flags)
9745 ;;; Cached directory support:
9748 (defvar verilog-dir-cache-preserving nil
9749 "If true, the directory cache is enabled, and file system changes are ignored.
9750 See `verilog-dir-exists-p' and `verilog-dir-files'.")
9752 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
9753 (defvar verilog-dir-cache-list nil
9754 "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
9755 (defvar verilog-dir-cache-lib-filenames nil
9756 "Cached data for `verilog-library-filenames'.")
9758 (defmacro verilog-preserve-dir-cache (&rest body)
9759 "Execute the BODY forms, allowing directory cache preservation within BODY.
9760 This means that changes inside BODY made to the file system will not be
9761 seen by the `verilog-dir-files' and related functions."
9762 `(let ((verilog-dir-cache-preserving (current-buffer))
9763 verilog-dir-cache-list
9764 verilog-dir-cache-lib-filenames)
9767 (defun verilog-dir-files (dirname)
9768 "Return all filenames in the DIRNAME directory.
9769 Relative paths depend on the `default-directory'.
9770 Results are cached if inside `verilog-preserve-dir-cache'."
9771 (unless verilog-dir-cache-preserving
9772 (setq verilog-dir-cache-list nil)) ; Cache disabled
9773 ;; We don't use expand-file-name on the dirname to make key, as it's slow
9774 (let* ((cache-key (list dirname default-directory))
9775 (fass (assoc cache-key verilog-dir-cache-list))
9777 (cond (fass ; Return data from cache hit
9780 (setq exp-dirname (expand-file-name dirname)
9781 data (and (file-directory-p exp-dirname)
9782 (directory-files exp-dirname nil nil nil)))
9783 ;; Note we also encache nil for non-existing dirs.
9784 (setq verilog-dir-cache-list (cons (list cache-key data)
9785 verilog-dir-cache-list))
9787 ;; Miss-and-hit test:
9788 ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
9789 ;; (prin1 (verilog-dir-files ".")) nil)
9791 (defun verilog-dir-file-exists-p (filename)
9792 "Return true if FILENAME exists.
9793 Like `file-exists-p' but results are cached if inside
9794 `verilog-preserve-dir-cache'."
9795 (let* ((dirname (file-name-directory filename))
9796 ;; Correct for file-name-nondirectory returning same if no slash.
9797 (dirnamed (if (or (not dirname) (equal dirname filename))
9798 default-directory dirname))
9799 (flist (verilog-dir-files dirnamed)))
9801 (member (file-name-nondirectory filename) flist)
9803 ;;(verilog-dir-file-exists-p "verilog-mode.el")
9804 ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
9807 ;;; Module name lookup:
9810 (defun verilog-module-inside-filename-p (module filename)
9811 "Return modi if MODULE is specified inside FILENAME, else nil.
9812 Allows version control to check out the file if need be."
9813 (and (or (file-exists-p filename)
9814 (and (fboundp 'vc-backend)
9815 (vc-backend filename)))
9817 (with-current-buffer (find-file-noselect filename)
9819 (goto-char (point-min))
9821 ;; It may be tempting to look for verilog-defun-re,
9822 ;; don't, it slows things down a lot!
9823 (verilog-re-search-forward-quick "\\<\\(module\\|interface\\|program\\)\\>" nil t)
9824 (setq type (match-string-no-properties 0))
9825 (verilog-re-search-forward-quick "[(;]" nil t))
9826 (if (equal module (verilog-read-module-name))
9827 (setq modi (verilog-modi-new module filename (point) type))))
9830 (defun verilog-is-number (symbol)
9831 "Return true if SYMBOL is number-like."
9832 (or (string-match "^[0-9 \t:]+$" symbol)
9833 (string-match "^[---]*[0-9]+$" symbol)
9834 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
9836 (defun verilog-symbol-detick (symbol wing-it)
9837 "Return an expanded SYMBOL name without any defines.
9838 If the variable vh-{symbol} is defined, return that value.
9839 If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
9840 (while (and symbol (string-match "^`" symbol))
9841 (setq symbol (substring symbol 1))
9843 ;; Namespace intentionally short for AUTOs and compatibility
9844 (if (boundp (intern (concat "vh-" symbol)))
9845 ;; Emacs has a bug where boundp on a buffer-local
9846 ;; variable in only one buffer returns t in another.
9847 ;; This can confuse, so check for nil.
9848 ;; Namespace intentionally short for AUTOs and compatibility
9849 (let ((val (eval (intern (concat "vh-" symbol)))))
9851 (if wing-it symbol nil)
9853 (if wing-it symbol nil))))
9855 ;;(verilog-symbol-detick "`mod" nil)
9857 (defun verilog-symbol-detick-denumber (symbol)
9858 "Return SYMBOL with defines converted and any numbers dropped to nil."
9859 (when (string-match "^`" symbol)
9860 ;; This only will work if the define is a simple signal, not
9861 ;; something like a[b]. Sorry, it should be substituted into the parser
9863 (verilog-string-replace-matches
9864 "\\[[^0-9: \t]+\\]" "" nil nil
9865 (or (verilog-symbol-detick symbol nil)
9866 (if verilog-auto-sense-defines-constant
9869 (if (verilog-is-number symbol)
9873 (defun verilog-symbol-detick-text (text)
9874 "Return TEXT without any known defines.
9875 If the variable vh-{symbol} is defined, substitute that value."
9876 (let ((ok t) symbol val)
9877 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
9878 (setq symbol (match-string 1 text))
9881 ;; Namespace intentionally short for AUTOs and compatibility
9882 (boundp (intern (concat "vh-" symbol)))
9883 ;; Emacs has a bug where boundp on a buffer-local
9884 ;; variable in only one buffer returns t in another.
9885 ;; This can confuse, so check for nil.
9886 ;; Namespace intentionally short for AUTOs and compatibility
9887 (setq val (eval (intern (concat "vh-" symbol)))))
9888 (setq text (replace-match val nil nil text)))
9889 (t (setq ok nil)))))
9891 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
9893 (defun verilog-expand-dirnames (&optional dirnames)
9894 "Return a list of existing directories given a list of wildcarded DIRNAMES.
9895 Or, just the existing dirnames themselves if there are no wildcards."
9896 ;; Note this function is performance critical.
9897 ;; Do not call anything that requires disk access that cannot be cached.
9900 (error "`verilog-library-directories' should include at least `.'"))
9901 (setq dirnames (reverse dirnames)) ; not nreverse
9903 pattern dirfile dirfiles dirname root filename rest basefile)
9905 (setq dirname (substitute-in-file-name (car dirnames))
9906 dirnames (cdr dirnames))
9907 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ; root
9908 "\\([^/\\]*[*?][^/\\]*\\)" ; filename with *?
9911 (setq root (match-string 1 dirname)
9912 filename (match-string 2 dirname)
9913 rest (match-string 3 dirname)
9915 ;; now replace those * and ? with .+ and .
9916 ;; use ^ and /> to get only whole file names
9917 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
9918 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
9919 pattern (concat "^" pattern "$")
9920 dirfiles (verilog-dir-files root))
9922 (setq basefile (car dirfiles)
9923 dirfile (expand-file-name (concat root basefile rest))
9924 dirfiles (cdr dirfiles))
9925 (if (and (string-match pattern basefile)
9926 ;; Don't allow abc/*/rtl to match abc/rtl via ..
9927 (not (equal basefile "."))
9928 (not (equal basefile ".."))
9929 (file-directory-p dirfile))
9930 (setq dirlist (cons dirfile dirlist)))))
9933 (if (file-directory-p dirname)
9934 (setq dirlist (cons dirname dirlist))))))
9936 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
9938 (defun verilog-library-filenames (filename &optional current check-ext)
9939 "Return a search path to find the given FILENAME or module name.
9940 Uses the optional CURRENT filename or variable `buffer-file-name', plus
9941 `verilog-library-directories' and `verilog-library-extensions'
9942 variables to build the path. With optional CHECK-EXT also check
9943 `verilog-library-extensions'."
9944 (unless current (setq current (buffer-file-name)))
9945 (unless verilog-dir-cache-preserving
9946 (setq verilog-dir-cache-lib-filenames nil))
9947 (let* ((cache-key (list filename current check-ext))
9948 (fass (assoc cache-key verilog-dir-cache-lib-filenames))
9949 chkdirs chkdir chkexts fn outlist)
9950 (cond (fass ; Return data from cache hit
9953 ;; Note this expand can't be easily cached, as we need to
9954 ;; pick up buffer-local variables for newly read sub-module files
9955 (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
9957 (setq chkdir (expand-file-name (car chkdirs)
9958 (file-name-directory current))
9959 chkexts (if check-ext verilog-library-extensions `("")))
9961 (setq fn (expand-file-name (concat filename (car chkexts))
9963 ;;(message "Check for %s" fn)
9964 (if (verilog-dir-file-exists-p fn)
9965 (setq outlist (cons (expand-file-name
9966 fn (file-name-directory current))
9968 (setq chkexts (cdr chkexts)))
9969 (setq chkdirs (cdr chkdirs)))
9970 (setq outlist (nreverse outlist))
9971 (setq verilog-dir-cache-lib-filenames
9972 (cons (list cache-key outlist)
9973 verilog-dir-cache-lib-filenames))
9976 (defun verilog-module-filenames (module current)
9977 "Return a search path to find the given MODULE name.
9978 Uses the CURRENT filename, `verilog-library-extensions',
9979 `verilog-library-directories' and `verilog-library-files'
9980 variables to build the path."
9981 ;; Return search locations for it
9982 (append (list current) ; first, current buffer
9983 (verilog-library-filenames module current t)
9984 ;; Finally any libraries; fixed up if using e.g. tramp
9985 (mapcar (lambda (fname)
9986 (if (file-name-absolute-p fname)
9987 (concat (file-remote-p current) fname)
9989 verilog-library-files)))
9992 ;; Module Information
9994 ;; Many of these functions work on "modi" a module information structure
9995 ;; A modi is: [module-name-string file-name begin-point]
9997 (defvar verilog-cache-enabled t
9998 "Non-nil enables caching of signals, etc. Set to nil for debugging to make things SLOW!")
10000 (defvar verilog-modi-cache-list nil
10001 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
10002 For speeding up verilog-modi-get-* commands.
10004 (make-variable-buffer-local 'verilog-modi-cache-list)
10006 (defvar verilog-modi-cache-preserve-tick nil
10007 "Modification tick after which the cache is still considered valid.
10008 Use `verilog-preserve-modi-cache' to set it.")
10009 (defvar verilog-modi-cache-preserve-buffer nil
10010 "Modification tick after which the cache is still considered valid.
10011 Use `verilog-preserve-modi-cache' to set it.")
10012 (defvar verilog-modi-cache-current-enable nil
10013 "Non-nil means allow caching `verilog-modi-current', set by let().")
10014 (defvar verilog-modi-cache-current nil
10015 "Currently active `verilog-modi-current', if any, set by let().")
10016 (defvar verilog-modi-cache-current-max nil
10017 "Current endmodule point for `verilog-modi-cache-current', if any.")
10019 (defun verilog-modi-current ()
10020 "Return the modi structure for the module currently at point, possibly cached."
10021 (cond ((and verilog-modi-cache-current
10022 (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
10023 (<= (point) verilog-modi-cache-current-max))
10024 ;; Slow assertion, for debugging the cache:
10025 ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
10026 verilog-modi-cache-current)
10027 (verilog-modi-cache-current-enable
10028 (setq verilog-modi-cache-current (verilog-modi-current-get)
10029 verilog-modi-cache-current-max
10030 ;; The cache expires when we pass "endmodule" as then the
10031 ;; current modi may change to the next module
10032 ;; This relies on the AUTOs generally inserting, not deleting text
10034 (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
10035 verilog-modi-cache-current)
10037 (verilog-modi-current-get))))
10039 (defun verilog-modi-current-get ()
10040 "Return the modi structure for the module currently at point."
10041 (let* (name type pt)
10042 ;; read current module's name
10044 (verilog-re-search-backward-quick verilog-defun-re nil nil)
10045 (setq type (match-string-no-properties 0))
10046 (verilog-re-search-forward-quick "(" nil nil)
10047 (setq name (verilog-read-module-name))
10049 ;; return modi - note this vector built two places
10050 (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
10052 (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
10053 (make-variable-buffer-local 'verilog-modi-lookup-cache)
10054 (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
10055 (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
10057 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
10058 "Find the file and point at which MODULE is defined.
10059 If ALLOW-CACHE is set, check and remember cache of previous lookups.
10060 Return modi if successful, else print message unless IGNORE-ERROR is true."
10061 (let* ((current (or (buffer-file-name) (current-buffer)))
10064 ;;(message "verilog-modi-lookup: %s" module)
10065 (cond ((and verilog-modi-lookup-cache
10066 verilog-cache-enabled
10068 (setq modi (gethash module verilog-modi-lookup-cache))
10069 (equal verilog-modi-lookup-last-current current)
10070 ;; If hit is in current buffer, then tick must match
10071 (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
10072 (not (equal current (verilog-modi-file-or-buffer modi)))))
10073 ;;(message "verilog-modi-lookup: HIT %S" modi)
10076 (t (let* ((realname (verilog-symbol-detick module t))
10077 (orig-filenames (verilog-module-filenames realname current))
10078 (filenames orig-filenames)
10080 (while (and filenames (not mif))
10081 (if (not (setq mif (verilog-module-inside-filename-p realname (car filenames))))
10082 (setq filenames (cdr filenames))))
10083 ;; mif has correct form to become later elements of modi
10085 (or mif ignore-error
10088 "%s: Can't locate `%s' module definition%s"
10089 "\n Check the verilog-library-directories variable."
10090 "\n I looked in (if not listed, doesn't exist):\n\t%s")
10091 (verilog-point-text) module
10092 (if (not (equal module realname))
10093 (concat " (Expanded macro to " realname ")")
10095 (mapconcat 'concat orig-filenames "\n\t")))
10096 (when (eval-when-compile (fboundp 'make-hash-table))
10097 (unless verilog-modi-lookup-cache
10098 (setq verilog-modi-lookup-cache
10099 (make-hash-table :test 'equal :rehash-size 4.0)))
10100 (puthash module modi verilog-modi-lookup-cache))
10101 (setq verilog-modi-lookup-last-current current
10102 verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
10105 (defun verilog-modi-filename (modi)
10106 "Filename of MODI, or name of buffer if it's never been saved."
10107 (if (bufferp (verilog-modi-file-or-buffer modi))
10108 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
10109 (buffer-name (verilog-modi-file-or-buffer modi)))
10110 (verilog-modi-file-or-buffer modi)))
10112 (defun verilog-modi-goto (modi)
10113 "Move point/buffer to specified MODI."
10114 (or modi (error "Passed unfound modi to goto, check earlier"))
10115 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
10116 (verilog-modi-file-or-buffer modi)
10117 (find-file-noselect (verilog-modi-file-or-buffer modi))))
10118 (or (equal major-mode `verilog-mode) ; Put into Verilog mode to get syntax
10120 (goto-char (verilog-modi-get-point modi)))
10122 (defun verilog-goto-defun-file (module)
10123 "Move point to the file at which a given MODULE is defined."
10124 (interactive "sGoto File for Module: ")
10125 (let* ((modi (verilog-modi-lookup module nil)))
10127 (verilog-modi-goto modi)
10128 (switch-to-buffer (current-buffer)))))
10130 (defun verilog-modi-cache-results (modi function)
10131 "Run on MODI the given FUNCTION. Locate the module in a file.
10132 Cache the output of function so next call may have faster access."
10134 (save-excursion ; Cache is buffer-local so can't avoid this.
10135 (verilog-modi-goto modi)
10136 (if (and (setq fass (assoc (list modi function)
10137 verilog-modi-cache-list))
10138 ;; Destroy caching when incorrect; Modified or file changed
10139 (not (and verilog-cache-enabled
10140 (or (equal (buffer-chars-modified-tick) (nth 1 fass))
10141 (and verilog-modi-cache-preserve-tick
10142 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
10143 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
10144 (equal (visited-file-modtime) (nth 2 fass)))))
10145 (setq verilog-modi-cache-list nil
10148 ;; Return data from cache hit
10152 ;; Clear then restore any highlighting to make emacs19 happy
10153 (let ((func-returns
10154 (verilog-save-font-no-change-functions
10155 (funcall function))))
10156 ;; Cache for next time
10157 (setq verilog-modi-cache-list
10158 (cons (list (list modi function)
10159 (buffer-chars-modified-tick)
10160 (visited-file-modtime)
10162 verilog-modi-cache-list))
10165 (defun verilog-modi-cache-add (modi function element sig-list)
10166 "Add function return results to the module cache.
10167 Update MODI's cache for given FUNCTION so that the return ELEMENT of that
10168 function now contains the additional SIG-LIST parameters."
10171 (verilog-modi-goto modi)
10172 (if (setq fass (assoc (list modi function)
10173 verilog-modi-cache-list))
10174 (let ((func-returns (nth 3 fass)))
10175 (aset func-returns element
10176 (append sig-list (aref func-returns element))))))))
10178 (defmacro verilog-preserve-modi-cache (&rest body)
10179 "Execute the BODY forms, allowing cache preservation within BODY.
10180 This means that changes to the buffer will not result in the cache being
10181 flushed. If the changes affect the modsig state, they must call the
10182 modsig-cache-add-* function, else the results of later calls may be
10183 incorrect. Without this, changes are assumed to be adding/removing signals
10184 and invalidating the cache."
10185 `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
10186 (verilog-modi-cache-preserve-buffer (current-buffer)))
10190 (defun verilog-modi-modport-lookup-one (modi name &optional ignore-error)
10191 "Given a MODI, return the declarations related to the given modport NAME.
10192 Report errors unless optional IGNORE-ERROR."
10193 ;; Recursive routine - see below
10194 (let* ((realname (verilog-symbol-detick name t))
10195 (modport (assoc name (verilog-decls-get-modports (verilog-modi-get-decls modi)))))
10196 (or modport ignore-error
10197 (error "%s: Can't locate `%s' modport definition%s"
10198 (verilog-point-text) name
10199 (if (not (equal name realname))
10200 (concat " (Expanded macro to " realname ")")
10202 (let* ((decls (verilog-modport-decls modport))
10203 (clks (verilog-modport-clockings modport)))
10204 ;; Now expand any clocking's
10206 (setq decls (verilog-decls-append
10208 (verilog-modi-modport-lookup-one modi (car clks) ignore-error)))
10209 (setq clks (cdr clks)))
10212 (defun verilog-modi-modport-lookup (modi name-re &optional ignore-error)
10213 "Given a MODI, return the declarations related to the given modport NAME-RE.
10214 If the modport points to any clocking blocks, expand the signals to include
10215 those clocking block's signals."
10216 ;; Recursive routine - see below
10217 (let* ((mod-decls (verilog-modi-get-decls modi))
10218 (clks (verilog-decls-get-modports mod-decls))
10219 (name-re (concat "^" name-re "$"))
10220 (decls (verilog-decls-new nil nil nil nil nil nil nil nil nil)))
10221 ;; Pull in all modports
10223 (when (string-match name-re (verilog-modport-name (car clks)))
10224 (setq decls (verilog-decls-append
10226 (verilog-modi-modport-lookup-one modi (verilog-modport-name (car clks)) ignore-error))))
10227 (setq clks (cdr clks)))
10230 (defun verilog-signals-matching-enum (in-list enum)
10231 "Return all signals in IN-LIST matching the given ENUM."
10234 (if (equal (verilog-sig-enum (car in-list)) enum)
10235 (setq out-list (cons (car in-list) out-list)))
10236 (setq in-list (cdr in-list)))
10238 ;; Namespace intentionally short for AUTOs and compatibility
10239 (let* ((enumvar (intern (concat "venum-" enum)))
10240 (enumlist (and (boundp enumvar) (eval enumvar))))
10242 (add-to-list 'out-list (list (car enumlist)))
10243 (setq enumlist (cdr enumlist))))
10244 (nreverse out-list)))
10246 (defun verilog-signals-matching-regexp (in-list regexp)
10247 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
10248 (if (or (not regexp) (equal regexp ""))
10250 (let ((case-fold-search verilog-case-fold)
10253 (if (string-match regexp (verilog-sig-name (car in-list)))
10254 (setq out-list (cons (car in-list) out-list)))
10255 (setq in-list (cdr in-list)))
10256 (nreverse out-list))))
10258 (defun verilog-signals-not-matching-regexp (in-list regexp)
10259 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
10260 (if (or (not regexp) (equal regexp ""))
10262 (let ((case-fold-search verilog-case-fold)
10265 (if (not (string-match regexp (verilog-sig-name (car in-list))))
10266 (setq out-list (cons (car in-list) out-list)))
10267 (setq in-list (cdr in-list)))
10268 (nreverse out-list))))
10270 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
10271 "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
10273 (if (or (not regexp) (equal regexp ""))
10275 (let (out-list to-match)
10277 ;; Note verilog-insert-one-definition matches on this order
10278 (setq to-match (concat
10280 " " (verilog-sig-signed (car in-list))
10281 " " (verilog-sig-multidim (car in-list))
10282 (verilog-sig-bits (car in-list))))
10283 (if (string-match regexp to-match)
10284 (setq out-list (cons (car in-list) out-list)))
10285 (setq in-list (cdr in-list)))
10286 (nreverse out-list))))
10288 (defun verilog-signals-edit-wire-reg (in-list)
10289 "Return all signals in IN-LIST with wire/reg data types made blank."
10290 (mapcar (lambda (sig)
10291 (when (member (verilog-sig-type sig) '("wire" "reg"))
10292 (verilog-sig-type-set sig nil))
10296 (defun verilog-decls-get-signals (decls)
10297 "Return all declared signals in DECLS, excluding `assign' statements."
10299 (verilog-decls-get-outputs decls)
10300 (verilog-decls-get-inouts decls)
10301 (verilog-decls-get-inputs decls)
10302 (verilog-decls-get-vars decls)
10303 (verilog-decls-get-consts decls)
10304 (verilog-decls-get-gparams decls)))
10306 (defun verilog-decls-get-ports (decls)
10308 (verilog-decls-get-outputs decls)
10309 (verilog-decls-get-inouts decls)
10310 (verilog-decls-get-inputs decls)))
10312 (defun verilog-decls-get-iovars (decls)
10314 (verilog-decls-get-vars decls)
10315 (verilog-decls-get-outputs decls)
10316 (verilog-decls-get-inouts decls)
10317 (verilog-decls-get-inputs decls)))
10319 (defsubst verilog-modi-cache-add-outputs (modi sig-list)
10320 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
10321 (defsubst verilog-modi-cache-add-inouts (modi sig-list)
10322 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
10323 (defsubst verilog-modi-cache-add-inputs (modi sig-list)
10324 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
10325 (defsubst verilog-modi-cache-add-vars (modi sig-list)
10326 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
10327 (defsubst verilog-modi-cache-add-gparams (modi sig-list)
10328 (verilog-modi-cache-add modi 'verilog-read-decls 7 sig-list))
10331 ;;; Auto creation utilities:
10334 (defun verilog-auto-re-search-do (search-for func)
10335 "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
10336 (goto-char (point-min))
10337 (while (verilog-re-search-forward-quick search-for nil t)
10340 (defun verilog-insert-one-definition (sig type indent-pt)
10341 "Print out a definition for SIG of the given TYPE,
10342 with appropriate INDENT-PT indentation."
10343 (indent-to indent-pt)
10344 ;; Note verilog-signals-matching-dir-re matches on this order
10346 (when (verilog-sig-modport sig)
10347 (insert "." (verilog-sig-modport sig)))
10348 (when (verilog-sig-signed sig)
10349 (insert " " (verilog-sig-signed sig)))
10350 (when (verilog-sig-multidim sig)
10351 (insert " " (verilog-sig-multidim-string sig)))
10352 (when (verilog-sig-bits sig)
10353 (insert " " (verilog-sig-bits sig)))
10354 (indent-to (max 24 (+ indent-pt 16)))
10355 (unless (= (char-syntax (preceding-char)) ?\ )
10356 (insert " ")) ; Need space between "]name" if indent-to did nothing
10357 (insert (verilog-sig-name sig))
10358 (when (verilog-sig-memory sig)
10359 (insert " " (verilog-sig-memory sig))))
10361 (defun verilog-insert-definition (modi sigs direction indent-pt v2k &optional dont-sort)
10362 "Print out a definition for MODI's list of SIGS of the given DIRECTION,
10363 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
10364 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output.
10365 When MODI is non-null, also add to modi-cache, for tracking."
10367 (cond ((equal direction "wire")
10368 (verilog-modi-cache-add-vars modi sigs))
10369 ((equal direction "reg")
10370 (verilog-modi-cache-add-vars modi sigs))
10371 ((equal direction "output")
10372 (verilog-modi-cache-add-outputs modi sigs)
10373 (when verilog-auto-declare-nettype
10374 (verilog-modi-cache-add-vars modi sigs)))
10375 ((equal direction "input")
10376 (verilog-modi-cache-add-inputs modi sigs)
10377 (when verilog-auto-declare-nettype
10378 (verilog-modi-cache-add-vars modi sigs)))
10379 ((equal direction "inout")
10380 (verilog-modi-cache-add-inouts modi sigs)
10381 (when verilog-auto-declare-nettype
10382 (verilog-modi-cache-add-vars modi sigs)))
10383 ((equal direction "interface"))
10384 ((equal direction "parameter")
10385 (verilog-modi-cache-add-gparams modi sigs))
10387 (error "Unsupported verilog-insert-definition direction: `%s'" direction))))
10389 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
10391 (let ((sig (car sigs)))
10392 (verilog-insert-one-definition
10394 ;; Want "type x" or "output type x", not "wire type x"
10395 (cond ((and (equal "wire" verilog-auto-wire-type)
10396 (or (not (verilog-sig-type sig))
10397 (equal "logic" (verilog-sig-type sig))))
10398 (if (member direction '("input" "output" "inout"))
10402 ((or (verilog-sig-type sig)
10403 verilog-auto-wire-type)
10405 (when (member direction '("input" "output" "inout"))
10406 (concat direction " "))
10407 (or (verilog-sig-type sig)
10408 verilog-auto-wire-type)))
10410 ((and verilog-auto-declare-nettype
10411 (member direction '("input" "output" "inout")))
10412 (concat direction " " verilog-auto-declare-nettype))
10416 (insert (if v2k "," ";"))
10417 (if (or (not verilog-auto-wire-comment)
10418 (not (verilog-sig-comment sig))
10419 (equal "" (verilog-sig-comment sig)))
10421 (indent-to (max 48 (+ indent-pt 40)))
10422 (verilog-insert "// " (verilog-sig-comment sig) "\n"))
10423 (setq sigs (cdr sigs)))))
10426 (if (not (boundp 'indent-pt))
10427 (defvar indent-pt nil "Local used by `verilog-insert-indent'.")))
10429 (defun verilog-insert-indent (&rest stuff)
10430 "Indent to position stored in local `indent-pt' variable, then insert STUFF.
10431 Presumes that any newlines end a list element."
10432 (let ((need-indent t))
10434 (if need-indent (indent-to indent-pt))
10435 (setq need-indent nil)
10436 (verilog-insert (car stuff))
10437 (setq need-indent (string-match "\n$" (car stuff))
10438 stuff (cdr stuff)))))
10439 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
10441 (defun verilog-forward-or-insert-line ()
10442 "Move forward a line, unless at EOB, then insert a newline."
10443 (if (eobp) (insert "\n")
10446 (defun verilog-repair-open-comma ()
10447 "Insert comma if previous argument is other than an open parenthesis or endif."
10448 ;; We can't just search backward for ) as it might be inside another expression.
10449 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
10451 (verilog-backward-syntactic-ws-quick)
10452 (when (and (not (save-excursion ; Not beginning (, or existing ,
10454 (looking-at "[(,]")))
10455 (not (save-excursion ; Not `endif, or user define
10457 (skip-chars-backward "[a-zA-Z0-9_`]")
10458 (looking-at "`"))))
10461 (defun verilog-repair-close-comma ()
10462 "If point is at a comma followed by a close parenthesis, fix it.
10463 This repairs those mis-inserted by an AUTOARG."
10464 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
10466 (verilog-forward-close-paren)
10468 (verilog-backward-syntactic-ws-quick)
10470 (when (looking-at ",")
10473 (defun verilog-make-width-expression (range-exp)
10474 "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
10475 ;; strip off the []
10476 (cond ((not range-exp)
10479 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
10480 (setq range-exp (match-string 1 range-exp)))
10481 (cond ((not range-exp)
10483 ;; [#:#] We can compute a numeric result
10484 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
10487 (1+ (abs (- (string-to-number (match-string 1 range-exp))
10488 (string-to-number (match-string 2 range-exp)))))))
10489 ;; [PARAM-1:0] can just return PARAM
10490 ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
10491 (match-string 1 range-exp))
10492 ;; [arbitrary] need math
10493 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
10494 (concat "(1+(" (match-string 1 range-exp) ")"
10495 (if (equal "0" (match-string 2 range-exp))
10496 "" ; Don't bother with -(0)
10497 (concat "-(" (match-string 2 range-exp) ")"))
10500 ;;(verilog-make-width-expression "`A:`B")
10502 (defun verilog-simplify-range-expression (expr)
10503 "Return a simplified range expression with constants eliminated from EXPR."
10504 ;; Note this is always called with brackets; ie [z] or [z:z]
10505 (if (not (string-match "[---+*()]" expr))
10506 expr ; short-circuit
10509 (while (not (equal last-pass out))
10510 (setq last-pass out)
10511 ;; Prefix regexp needs beginning of match, or some symbol of
10512 ;; lesser or equal precedence. We assume the [:]'s exist in expr.
10514 (while (string-match
10515 (concat "\\([[({:*+-]\\)" ; - must be last
10516 "(\\<\\([0-9A-Za-z_]+\\))"
10519 (setq out (replace-match "\\1\\2\\3" nil nil out)))
10520 (while (string-match
10521 (concat "\\([[({:*+-]\\)" ; - must be last
10522 "\\$clog2\\s *(\\<\\([0-9]+\\))"
10525 (setq out (replace-match
10527 (match-string 1 out)
10528 (int-to-string (verilog-clog2 (string-to-number (match-string 2 out))))
10529 (match-string 3 out))
10531 ;; For precedence do * before +/-
10532 (while (string-match
10533 (concat "\\([[({:*+-]\\)"
10534 "\\([0-9]+\\)\\s *\\([*]\\)\\s *\\([0-9]+\\)"
10537 (setq out (replace-match
10538 (concat (match-string 1 out)
10539 (int-to-string (* (string-to-number (match-string 2 out))
10540 (string-to-number (match-string 4 out))))
10541 (match-string 5 out))
10543 (while (string-match
10544 (concat "\\([[({:+-]\\)" ; No * here as higher prec
10545 "\\([0-9]+\\)\\s *\\([---+]\\)\\s *\\([0-9]+\\)"
10548 (let ((pre (match-string 1 out))
10549 (lhs (string-to-number (match-string 2 out)))
10550 (rhs (string-to-number (match-string 4 out)))
10551 (post (match-string 5 out))
10553 (when (equal pre "-")
10554 (setq lhs (- lhs)))
10555 (setq val (if (equal (match-string 3 out) "-")
10559 (concat (if (and (equal pre "-")
10561 "" ; Not "--20" but just "-20"
10563 (int-to-string val)
10568 ;;(verilog-simplify-range-expression "[1:3]") ; 1
10569 ;;(verilog-simplify-range-expression "[(1):3]") ; 1
10570 ;;(verilog-simplify-range-expression "[(((16)+1)+1+(1+1))]") ; 20
10571 ;;(verilog-simplify-range-expression "[(2*3+6*7)]") ; 48
10572 ;;(verilog-simplify-range-expression "[(FOO*4-1*2)]") ; FOO*4-2
10573 ;;(verilog-simplify-range-expression "[(FOO*4+1-1)]") ; FOO*4+0
10574 ;;(verilog-simplify-range-expression "[(func(BAR))]") ; func(BAR)
10575 ;;(verilog-simplify-range-expression "[FOO-1+1-1+1]") ; FOO-0
10576 ;;(verilog-simplify-range-expression "[$clog2(2)]") ; 1
10577 ;;(verilog-simplify-range-expression "[$clog2(7)]") ; 3
10579 (defun verilog-clog2 (value)
10580 "Compute $clog2 - ceiling log2 of VALUE."
10583 (ceiling (/ (log value) (log 2)))))
10585 (defun verilog-typedef-name-p (variable-name)
10586 "Return true if the VARIABLE-NAME is a type definition."
10587 (when verilog-typedef-regexp
10588 (verilog-string-match-fold verilog-typedef-regexp variable-name)))
10593 (defun verilog-delete-autos-lined ()
10594 "Delete autos that occupy multiple lines, between begin and end comments."
10595 ;; The newline must not have a comment property, so we must
10596 ;; delete the end auto's newline, not the first newline
10598 (let ((pt (point)))
10600 (looking-at "\\s-*// Beginning")
10601 (search-forward "// End of automatic" nil t))
10605 (delete-region pt (point)))))
10607 (defun verilog-delete-empty-auto-pair ()
10608 "Delete begin/end auto pair at point, if empty."
10610 (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
10611 "\\s-*// End of automatics\n"))
10612 (delete-region (point) (save-excursion (forward-line 2) (point)))))
10614 (defun verilog-forward-close-paren ()
10615 "Find the close parenthesis that match the current point.
10616 Ignore other close parenthesis with matching open parens."
10618 (while (> parens 0)
10619 (unless (verilog-re-search-forward-quick "[()]" nil t)
10620 (error "%s: Mismatching ()" (verilog-point-text)))
10621 (cond ((= (preceding-char) ?\( )
10622 (setq parens (1+ parens)))
10623 ((= (preceding-char) ?\) )
10624 (setq parens (1- parens)))))))
10626 (defun verilog-backward-open-paren ()
10627 "Find the open parenthesis that match the current point.
10628 Ignore other open parenthesis with matching close parens."
10630 (while (> parens 0)
10631 (unless (verilog-re-search-backward-quick "[()]" nil t)
10632 (error "%s: Mismatching ()" (verilog-point-text)))
10633 (cond ((= (following-char) ?\) )
10634 (setq parens (1+ parens)))
10635 ((= (following-char) ?\( )
10636 (setq parens (1- parens)))))))
10638 (defun verilog-backward-open-bracket ()
10639 "Find the open bracket that match the current point.
10640 Ignore other open bracket with matching close bracket."
10642 (while (> parens 0)
10643 (unless (verilog-re-search-backward-quick "[][]" nil t)
10644 (error "%s: Mismatching []" (verilog-point-text)))
10645 (cond ((= (following-char) ?\] )
10646 (setq parens (1+ parens)))
10647 ((= (following-char) ?\[ )
10648 (setq parens (1- parens)))))))
10650 (defun verilog-delete-to-paren ()
10651 "Delete the automatic inst/sense/arg created by autos.
10652 Deletion stops at the matching end parenthesis, outside comments."
10653 (delete-region (point)
10655 (verilog-backward-open-paren)
10656 (verilog-forward-sexp-ign-cmt 1) ; Moves to paren that closes argdecl's
10660 (defun verilog-auto-star-safe ()
10661 "Return if a .* AUTOINST is safe to delete or expand.
10662 It was created by the AUTOS themselves, or by the user."
10663 (and verilog-auto-star-expand
10665 (concat "[ \t\n\f,]*\\([)]\\|// " verilog-inst-comment-re "\\)"))))
10667 (defun verilog-delete-auto-star-all ()
10668 "Delete a .* AUTOINST, if it is safe."
10669 (when (verilog-auto-star-safe)
10670 (verilog-delete-to-paren)))
10672 (defun verilog-delete-auto-star-implicit ()
10673 "Delete all .* implicit connections created by `verilog-auto-star'.
10674 This function will be called automatically at save unless
10675 `verilog-auto-star-save' is set, any non-templated expanded pins will be
10678 (let (paren-pt indent have-close-paren)
10680 (goto-char (point-min))
10681 ;; We need to match these even outside of comments.
10682 ;; For reasonable performance, we don't check if inside comments, sorry.
10683 (while (re-search-forward "// Implicit \\.\\*" nil t)
10684 (setq paren-pt (point))
10685 (beginning-of-line)
10686 (setq have-close-paren
10688 (when (search-forward ");" paren-pt t)
10689 (setq indent (current-indentation))
10691 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
10692 (when have-close-paren
10693 ;; Delete extra commentary
10697 (looking-at (concat "\\s *//\\s *" verilog-inst-comment-re "\n")))
10698 (delete-region (match-beginning 0) (match-end 0))))
10699 ;; If it is simple, we can put the ); on the same line as the last text
10700 (let ((rtn-pt (point)))
10702 (while (progn (backward-char 1)
10703 (looking-at "[ \t\n\f]")))
10704 (when (looking-at ",")
10705 (delete-region (+ 1 (point)) rtn-pt))))
10707 (indent-to indent))
10709 ;; Still need to kill final comma - always is one as we put one after the .*
10710 (re-search-backward ",")
10711 (delete-char 1))))))
10713 (defun verilog-delete-auto-buffer ()
10714 "Perform `verilog-delete-auto' on the current buffer.
10715 Intended for internal use inside a `verilog-save-font-no-change-functions' block."
10716 ;; Allow user to customize
10717 (verilog-run-hooks 'verilog-before-delete-auto-hook)
10719 ;; Remove those that have multi-line insertions, possibly with parameters
10720 ;; We allow anything beginning with AUTO, so that users can add their own
10722 (verilog-auto-re-search-do
10723 (concat "/\\*AUTO[A-Za-z0-9_]+"
10724 ;; Optional parens or quoted parameter or .* for (((...)))
10725 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
10727 'verilog-delete-autos-lined)
10728 ;; Remove those that are in parenthesis
10729 (verilog-auto-re-search-do
10732 (verilog-regexp-words
10733 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
10736 'verilog-delete-to-paren)
10737 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
10738 (verilog-auto-re-search-do "\\.\\*"
10739 'verilog-delete-auto-star-all)
10740 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
10741 (goto-char (point-min))
10742 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
10743 (replace-match ""))
10746 (verilog-run-hooks 'verilog-delete-auto-hook))
10748 (defun verilog-delete-auto ()
10749 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
10750 Use \\[verilog-auto] to re-insert the updated AUTOs.
10752 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
10753 called before and after this function, respectively."
10756 (if (buffer-file-name)
10757 (find-file-noselect (buffer-file-name))) ; To check we have latest version
10758 (verilog-save-font-no-change-functions
10759 (verilog-save-scan-cache
10760 (verilog-delete-auto-buffer)))))
10766 (defun verilog-inject-auto ()
10767 "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
10769 Any always @ blocks with sensitivity lists that match computed lists will
10770 be replaced with /*AS*/ comments.
10772 Any cells will get /*AUTOINST*/ added to the end of the pin list.
10773 Pins with have identical names will be deleted.
10775 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
10776 support adding new ports. You may wish to delete older ports yourself.
10780 module ExampInject (i, o);
10786 InstModule instName
10791 Typing \\[verilog-inject-auto] will make this into:
10793 module ExampInject (i, o/*AUTOARG*/
10798 always @ (/*AS*/i or j)
10800 InstModule instName
10809 (defun verilog-inject-arg ()
10810 "Inject AUTOARG into new code. See `verilog-inject-auto'."
10811 ;; Presume one module per file.
10813 (goto-char (point-min))
10814 (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
10815 (let ((endmodp (save-excursion
10816 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
10818 ;; See if there's already a comment .. inside a comment so not verilog-re-search
10819 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
10820 (verilog-re-search-forward-quick ";" nil t)
10822 (verilog-backward-syntactic-ws-quick)
10823 (backward-char 1) ; Moves to paren that closes argdecl's
10824 (when (looking-at ")")
10825 (verilog-insert "/*AUTOARG*/")))))))
10827 (defun verilog-inject-sense ()
10828 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
10830 (goto-char (point-min))
10831 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
10832 (let* ((start-pt (point))
10833 (modi (verilog-modi-current))
10834 (moddecls (verilog-modi-get-decls modi))
10838 (verilog-forward-sexp-ign-cmt 1)
10839 (backward-char 1) ; End )
10840 (when (not (verilog-re-search-backward-quick "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
10841 (setq pre-sigs (verilog-signals-from-signame
10842 (verilog-read-signals start-pt (point)))
10843 got-sigs (verilog-auto-sense-sigs moddecls nil))
10844 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
10845 (verilog-signals-not-in got-sigs pre-sigs)))
10846 (delete-region start-pt (point))
10847 (verilog-insert "/*AS*/")))))))
10849 (defun verilog-inject-inst ()
10850 "Inject AUTOINST into new code. See `verilog-inject-auto'."
10852 (goto-char (point-min))
10853 ;; It's hard to distinguish modules; we'll instead search for pins.
10854 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_$]+\\s *(\\s *[a-zA-Z0-9`_$]+\\s *)" nil t)
10855 (verilog-backward-open-paren) ; Inst start
10857 ((= (preceding-char) ?\#) ; #(...) parameter section, not pin. Skip.
10859 (verilog-forward-close-paren)) ; Parameters done
10862 (let ((indent-pt (+ (current-column)))
10863 (end-pt (save-excursion (verilog-forward-close-paren) (point))))
10864 (cond ((verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
10865 (goto-char end-pt)) ; Already there, continue search with next instance
10867 ;; Delete identical interconnect
10868 (let ((case-fold-search nil)) ; So we don't convert upper-to-lower, etc
10869 (while (verilog-re-search-forward-quick "\\.\\s *\\([a-zA-Z0-9`_$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
10870 (delete-region (match-beginning 0) (match-end 0))
10871 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ; Keep it correct
10872 (while (or (looking-at "[ \t\n\f,]+")
10873 (looking-at "//[^\n]*"))
10874 (delete-region (match-beginning 0) (match-end 0))
10875 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
10876 (verilog-forward-close-paren)
10878 ;; Not verilog-re-search, as we don't want to strip comments
10879 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
10880 (delete-region (match-beginning 0) (match-end 0)))
10881 (verilog-insert "\n")
10882 (verilog-insert-indent "/*AUTOINST*/")))))))))
10888 (defun verilog-diff-buffers-p (b1 b2 &optional whitespace regexp)
10889 "Return nil if buffers B1 and B2 have same contents.
10890 Else, return point in B1 that first mismatches.
10891 If optional WHITESPACE true, ignore whitespace.
10892 If optional REGEXP, ignore differences matching it."
10894 (let* ((case-fold-search nil) ; compare-buffer-substrings cares
10895 (p1 (with-current-buffer b1 (goto-char (point-min))))
10896 (p2 (with-current-buffer b2 (goto-char (point-min))))
10897 (maxp1 (with-current-buffer b1 (point-max)))
10898 (maxp2 (with-current-buffer b2 (point-max)))
10901 (while (not (and (eq p1 op1) (eq p2 op2)))
10902 ;; If both windows have whitespace optionally skip over it.
10904 ;; skip-syntax-* doesn't count \n
10905 (with-current-buffer b1
10907 (skip-chars-forward " \t\n\r\f\v")
10909 (with-current-buffer b2
10911 (skip-chars-forward " \t\n\r\f\v")
10912 (setq p2 (point))))
10914 (with-current-buffer b1
10916 (when (looking-at regexp)
10917 (setq p1 (match-end 0))))
10918 (with-current-buffer b2
10920 (when (looking-at regexp)
10921 (setq p2 (match-end 0)))))
10922 (setq size (min (- maxp1 p1) (- maxp2 p2)))
10923 (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
10924 b1 p1 (+ size p1)))
10925 (setq progress (if (zerop progress) size (1- (abs progress))))
10926 (setq op1 p1 op2 p2
10928 p2 (+ p2 progress)))
10930 (if (and (eq p1 maxp1) (eq p2 maxp2))
10933 (defun verilog-diff-file-with-buffer (f1 b2 &optional whitespace show)
10934 "View the differences between file F1 and buffer B2.
10935 This requires the external program `diff-command' to be in your `exec-path',
10936 and uses `diff-switches' in which you may want to have \"-u\" flag.
10937 Ignores WHITESPACE if t, and writes output to stdout if SHOW."
10938 ;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
10939 ;; call `diff' as `diff' has different calling semantics on different
10940 ;; versions of Emacs.
10941 (if (not (file-exists-p f1))
10942 (message "Buffer `%s' has no associated file on disk" (buffer-name b2))
10943 (with-temp-buffer "*Verilog-Diff*"
10944 (let ((outbuf (current-buffer))
10945 (f2 (make-temp-file "vm-diff-auto-")))
10948 (with-current-buffer b2
10951 (write-region (point-min) (point-max) f2 nil 'nomessage)))
10952 (call-process diff-command nil outbuf t
10953 diff-switches ; User may want -u in diff-switches
10954 (if whitespace "-b" "")
10956 ;; Print out results. Alternatively we could have call-processed
10957 ;; ourself, but this way we can reuse diff switches
10959 (with-current-buffer outbuf (message "%s" (buffer-string))))))
10961 (when (file-exists-p f2)
10962 (delete-file f2))))))
10964 (defun verilog-diff-report (b1 b2 diffpt)
10965 "Report differences detected with `verilog-diff-auto'.
10966 Differences are between buffers B1 and B2, starting at point
10967 DIFFPT. This function is called via `verilog-diff-function'."
10968 (let ((name1 (with-current-buffer b1 (buffer-file-name))))
10969 (verilog-warn-error "%s:%d: Difference in AUTO expansion found"
10970 name1 (with-current-buffer b1
10971 (count-lines (point-min) diffpt)))
10972 (cond (noninteractive
10973 (verilog-diff-file-with-buffer name1 b2 t t))
10975 (ediff-buffers b1 b2)))))
10977 (defun verilog-diff-auto ()
10978 "Expand AUTOs in a temporary buffer and indicate any change.
10979 Whitespace is ignored when detecting differences, but once a
10980 difference is detected, whitespace differences may be shown.
10982 To call this from the command line, see \\[verilog-batch-diff-auto].
10984 The action on differences is selected with
10985 `verilog-diff-function'. The default is `verilog-diff-report'
10986 which will report an error and run `ediff' in interactive mode,
10987 or `diff' in batch mode."
10989 (let ((b1 (current-buffer)) b2 diffpt
10990 (name1 (buffer-file-name))
10991 (newname "*Verilog-Diff*"))
10993 (when (get-buffer newname)
10994 (kill-buffer newname))
10995 (setq b2 (let (buffer-file-name) ; Else clone is upset
10996 (clone-buffer newname)))
10997 (with-current-buffer b2
10998 ;; auto requires the filename, but can't have same filename in two
10999 ;; buffers; so override both b1 and b2's names
11000 (let ((buffer-file-name name1))
11003 (with-current-buffer b1 (setq buffer-file-name nil))
11005 (when (not verilog-auto-star-save)
11006 (verilog-delete-auto-star-implicit)))
11007 ;; Restore name if unwind
11008 (with-current-buffer b1 (setq buffer-file-name name1)))))
11010 (setq diffpt (verilog-diff-buffers-p b1 b2 t verilog-diff-ignore-regexp))
11011 (cond ((not diffpt)
11012 (unless noninteractive (message "AUTO expansion identical"))
11013 (kill-buffer newname)) ; Nice to cleanup after oneself
11015 (funcall verilog-diff-function b1 b2 diffpt)))
11016 ;; Return result of compare
11023 (defun verilog-auto-save-check ()
11024 "On saving see if we need auto update."
11025 (cond ((not verilog-auto-save-policy)) ; disabled
11026 ((not (save-excursion
11028 (let ((case-fold-search nil))
11029 (goto-char (point-min))
11030 (re-search-forward "AUTO" nil t))))))
11031 ((eq verilog-auto-save-policy 'force)
11033 ((not (buffer-modified-p)))
11034 ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
11035 ((eq verilog-auto-save-policy 'detect)
11038 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
11040 ;; Don't ask again if didn't update
11041 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
11042 (when (not verilog-auto-star-save)
11043 (verilog-delete-auto-star-implicit))
11044 nil) ; Always return nil -- we don't write the file ourselves
11046 (defun verilog-auto-read-locals ()
11047 "Return file local variable segment at bottom of file."
11049 (goto-char (point-max))
11050 (if (re-search-backward "Local Variables:" nil t)
11051 (buffer-substring-no-properties (point) (point-max))
11054 (defun verilog-auto-reeval-locals (&optional force)
11055 "Read file local variable segment at bottom of file if it has changed.
11056 If FORCE, always reread it."
11057 (let ((curlocal (verilog-auto-read-locals)))
11058 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
11059 (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
11060 ;; Note this may cause this function to be recursively invoked,
11061 ;; because hack-local-variables may call (verilog-mode)
11062 ;; The above when statement will prevent it from recursing forever.
11063 (hack-local-variables)
11069 (defun verilog-auto-arg-ports (sigs message indent-pt)
11070 "Print a list of ports for AUTOARG.
11071 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
11073 (when verilog-auto-arg-sort
11074 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
11076 (indent-to indent-pt)
11080 (indent-to indent-pt)
11082 (cond ((equal verilog-auto-arg-format 'single)
11084 (indent-to indent-pt)
11086 ;; verilog-auto-arg-format 'packed
11087 ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
11089 (indent-to indent-pt)
11094 (insert (verilog-sig-name (car sigs)) ",")
11095 (setq sigs (cdr sigs))))))
11097 (defun verilog-auto-arg ()
11098 "Expand AUTOARG statements.
11099 Replace the argument declarations at the beginning of the
11100 module with ones automatically derived from input and output
11101 statements. This can be dangerous if the module is instantiated
11102 using position-based connections, so use only name-based when
11103 instantiating the resulting module. Long lines are split based
11104 on the `fill-column', see \\[set-fill-column].
11107 Concatenation and outputting partial buses is not supported.
11109 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11113 module ExampArg (/*AUTOARG*/);
11118 Typing \\[verilog-auto] will make this into:
11120 module ExampArg (/*AUTOARG*/
11130 The argument declarations may be printed in declaration order to
11131 best suit order based instantiations, or alphabetically, based on
11132 the `verilog-auto-arg-sort' variable.
11134 Formatting is controlled with `verilog-auto-arg-format' variable.
11136 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
11137 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
11138 conservative guess on adding a comma for the first signal, if you have
11139 any ifdefs or complicated expressions before the AUTOARG you will need
11140 to choose the comma yourself.
11142 Avoid declaring ports manually, as it makes code harder to maintain."
11144 (let* ((modi (verilog-modi-current))
11145 (moddecls (verilog-modi-get-decls modi))
11146 (skip-pins (aref (verilog-read-arg-pins) 0)))
11147 (verilog-repair-open-comma)
11148 (verilog-auto-arg-ports (verilog-signals-not-in
11149 (verilog-decls-get-outputs moddecls)
11152 verilog-indent-level-declaration)
11153 (verilog-auto-arg-ports (verilog-signals-not-in
11154 (verilog-decls-get-inouts moddecls)
11157 verilog-indent-level-declaration)
11158 (verilog-auto-arg-ports (verilog-signals-not-in
11159 (verilog-decls-get-inputs moddecls)
11162 verilog-indent-level-declaration)
11163 (verilog-repair-close-comma)
11164 (unless (eq (char-before) ?/ )
11166 (indent-to verilog-indent-level-declaration))))
11168 (defun verilog-auto-assign-modport ()
11169 "Expand AUTOASSIGNMODPORT statements, as part of \\[verilog-auto].
11170 Take input/output/inout statements from the specified interface
11171 and modport and use to build assignments into the modport, for
11172 making verification modules that connect to UVM interfaces.
11174 The first parameter is the name of an interface.
11176 The second parameter is a regexp of modports to read from in
11179 The third parameter is the instance name to use to dot reference into.
11181 The optional fourth parameter is a regular expression, and only
11182 signals matching the regular expression will be included.
11186 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
11188 Inouts are not supported, as assignments must be unidirectional.
11190 If a signal is part of the interface header and in both a
11191 modport and the interface itself, it will not be listed. (As
11192 this would result in a syntax error when the connections are
11195 See the example in `verilog-auto-inout-modport'."
11197 (let* ((params (verilog-read-auto-params 3 4))
11198 (submod (nth 0 params))
11199 (modport-re (nth 1 params))
11200 (inst-name (nth 2 params))
11201 (regexp (nth 3 params))
11202 direction-re submodi) ; direction argument not supported until requested
11203 ;; Lookup position, etc of co-module
11204 ;; Note this may raise an error
11205 (when (setq submodi (verilog-modi-lookup submod t))
11206 (let* ((indent-pt (current-indentation))
11207 (submoddecls (verilog-modi-get-decls submodi))
11208 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
11209 (sig-list-i (verilog-signals-in ; Decls doesn't have data types, must resolve
11210 (verilog-decls-get-vars submoddecls)
11211 (verilog-signals-not-in
11212 (verilog-decls-get-inputs submodportdecls)
11213 (verilog-decls-get-ports submoddecls))))
11214 (sig-list-o (verilog-signals-in ; Decls doesn't have data types, must resolve
11215 (verilog-decls-get-vars submoddecls)
11216 (verilog-signals-not-in
11217 (verilog-decls-get-outputs submodportdecls)
11218 (verilog-decls-get-ports submoddecls)))))
11220 (setq sig-list-i (verilog-signals-edit-wire-reg
11221 (verilog-signals-matching-dir-re
11222 (verilog-signals-matching-regexp sig-list-i regexp)
11223 "input" direction-re))
11224 sig-list-o (verilog-signals-edit-wire-reg
11225 (verilog-signals-matching-dir-re
11226 (verilog-signals-matching-regexp sig-list-o regexp)
11227 "output" direction-re)))
11228 (setq sig-list-i (sort (copy-alist sig-list-i) `verilog-signals-sort-compare))
11229 (setq sig-list-o (sort (copy-alist sig-list-o) `verilog-signals-sort-compare))
11230 (when (or sig-list-i sig-list-o)
11231 (verilog-insert-indent "// Beginning of automatic assignments from modport\n")
11232 ;; Don't sort them so an upper AUTOINST will match the main module
11233 (let ((sigs sig-list-o))
11235 (verilog-insert-indent "assign " (verilog-sig-name (car sigs))
11237 "." (verilog-sig-name (car sigs)) ";\n")
11238 (setq sigs (cdr sigs))))
11239 (let ((sigs sig-list-i))
11241 (verilog-insert-indent "assign " inst-name
11242 "." (verilog-sig-name (car sigs))
11243 " = " (verilog-sig-name (car sigs)) ";\n")
11244 (setq sigs (cdr sigs))))
11245 (verilog-insert-indent "// End of automatics\n")))))))
11247 (defun verilog-auto-inst-port-map (_port-st)
11250 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
11251 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
11252 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
11253 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
11254 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
11255 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
11256 (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
11257 (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
11259 (defun verilog-auto-inst-port (port-st indent-pt moddecls tpl-list tpl-num for-star par-values)
11260 "Print out an instantiation connection for this PORT-ST.
11261 Insert to INDENT-PT, use template TPL-LIST.
11262 @ are instantiation numbers, replaced with TPL-NUM.
11263 @\"(expression @)\" are evaluated, with @ as a variable.
11264 If FOR-STAR add comment it is a .* expansion.
11265 If PAR-VALUES replace final strings with these parameter values."
11266 (let* ((port (verilog-sig-name port-st))
11267 (tpl-ass (or (assoc port (car tpl-list))
11268 (verilog-auto-inst-port-map port-st)))
11269 ;; vl-* are documented for user use
11270 (vl-name (verilog-sig-name port-st))
11271 (vl-width (verilog-sig-width port-st))
11272 (vl-modport (verilog-sig-modport port-st))
11273 (vl-memory (verilog-sig-memory port-st))
11274 (vl-mbits (if (verilog-sig-multidim port-st)
11275 (verilog-sig-multidim-string port-st) ""))
11276 (vl-bits (if (or verilog-auto-inst-vector
11277 (not (assoc port (verilog-decls-get-signals moddecls)))
11278 (not (equal (verilog-sig-bits port-st)
11280 (assoc port (verilog-decls-get-signals moddecls))))))
11281 (or (verilog-sig-bits port-st) "")
11283 (case-fold-search nil)
11284 (check-values par-values)
11286 ;; Replace parameters in bit-width
11287 (when (and check-values
11288 (not (equal vl-bits "")))
11289 (while check-values
11290 (setq vl-bits (verilog-string-replace-matches
11291 (concat "\\<" (nth 0 (car check-values)) "\\>")
11292 (concat "(" (nth 1 (car check-values)) ")")
11294 vl-mbits (verilog-string-replace-matches
11295 (concat "\\<" (nth 0 (car check-values)) "\\>")
11296 (concat "(" (nth 1 (car check-values)) ")")
11298 vl-memory (when vl-memory
11299 (verilog-string-replace-matches
11300 (concat "\\<" (nth 0 (car check-values)) "\\>")
11301 (concat "(" (nth 1 (car check-values)) ")")
11303 check-values (cdr check-values)))
11304 (setq vl-bits (verilog-simplify-range-expression vl-bits)
11305 vl-mbits (verilog-simplify-range-expression vl-mbits)
11306 vl-memory (when vl-memory (verilog-simplify-range-expression vl-memory))
11307 vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
11308 ;; Default net value if not found
11309 (setq dflt-bits (if (or (and (verilog-sig-bits port-st)
11310 (verilog-sig-multidim port-st))
11311 (verilog-sig-memory port-st))
11312 (concat "/*" vl-mbits vl-bits
11313 ;; .[ used to separate packed from unpacked
11314 (if vl-memory "." "")
11315 (if vl-memory vl-memory "")
11318 tpl-net (concat port
11319 (if (and vl-modport
11320 ;; .modport cannot be added if attachment is
11321 ;; already declared as modport, VCS croaks
11322 (let ((sig (assoc port (verilog-decls-get-interfaces moddecls))))
11323 (not (and sig (verilog-sig-modport sig)))))
11324 (concat "." vl-modport) "")
11327 (cond (tpl-ass ; Template of exact port name
11328 (setq tpl-net (nth 1 tpl-ass)))
11329 ((nth 1 tpl-list) ; Wildcards in template, search them
11330 (let ((wildcards (nth 1 tpl-list)))
11332 (when (string-match (nth 0 (car wildcards)) port)
11333 (setq tpl-ass (car wildcards) ; so allow @ parsing
11334 tpl-net (replace-match (nth 1 (car wildcards))
11336 (setq wildcards (cdr wildcards))))))
11337 ;; Parse Templated variable
11339 ;; Evaluate @"(lispcode)"
11340 (when (string-match "@\".*[^\\]\"" tpl-net)
11341 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
11344 (substring tpl-net 0 (match-beginning 0))
11346 (let* ((expr (match-string 1 tpl-net))
11349 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
11350 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
11351 (prin1 (eval (car (read-from-string expr)))
11352 (lambda (_ch) ())))))
11353 (if (numberp value) (setq value (number-to-string value)))
11355 (substring tpl-net (match-end 0))))))
11356 ;; Replace @ and [] magic variables in final output
11357 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
11358 (setq tpl-net (verilog-string-replace-matches "\\[\\]\\[\\]" dflt-bits nil nil tpl-net))
11359 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
11361 (indent-to indent-pt)
11363 (unless (and verilog-auto-inst-dot-name
11364 (equal port tpl-net))
11365 (indent-to verilog-auto-inst-column)
11366 (insert "(" tpl-net ")"))
11369 (verilog-read-auto-template-hit tpl-ass)
11370 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
11371 verilog-auto-inst-column))
11372 ;; verilog-insert requires the complete comment in one call - including the newline
11373 (cond ((equal verilog-auto-inst-template-numbers `lhs)
11374 (verilog-insert " // Templated"
11375 " LHS: " (nth 0 tpl-ass)
11377 (verilog-auto-inst-template-numbers
11378 (verilog-insert " // Templated"
11379 " T" (int-to-string (nth 2 tpl-ass))
11380 " L" (int-to-string (nth 3 tpl-ass))
11383 (verilog-insert " // Templated\n"))))
11385 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
11386 verilog-auto-inst-column))
11387 (verilog-insert " // Implicit .*\n"))
11390 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
11391 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
11392 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
11394 (defun verilog-auto-inst-port-list (sig-list indent-pt moddecls tpl-list tpl-num for-star par-values)
11395 "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
11396 (when verilog-auto-inst-sort
11397 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)))
11398 (mapc (lambda (port)
11399 (verilog-auto-inst-port port indent-pt moddecls
11400 tpl-list tpl-num for-star par-values))
11403 (defun verilog-auto-inst-first ()
11404 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
11405 ;; Do we need a trailing comma?
11406 ;; There maybe an ifdef or something similar before us. What a mess. Thus
11407 ;; to avoid trouble we only insert on preceding ) or *.
11408 ;; Insert first port on new line
11409 (insert "\n") ; Must insert before search, so point will move forward if insert comma
11411 (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
11412 (when (looking-at ")\\|\\*") ; Generally don't insert, unless we are fairly sure
11416 (defun verilog-auto-star ()
11417 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
11419 If `verilog-auto-star-expand' is set, .* pins are treated if they were
11420 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
11421 will also ignore any .* that are not last in your pin list (this prevents
11422 it from deleting pins following the .* when it expands the AUTOINST.)
11424 On writing your file, unless `verilog-auto-star-save' is set, any
11425 non-templated expanded pins will be removed. You may do this at any time
11426 with \\[verilog-delete-auto-star-implicit].
11428 If you are converting a module to use .* for the first time, you may wish
11429 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
11431 See `verilog-auto-inst' for examples, templates, and more information."
11432 (when (verilog-auto-star-safe)
11433 (verilog-auto-inst)))
11435 (defun verilog-auto-inst ()
11436 "Expand AUTOINST statements, as part of \\[verilog-auto].
11437 Replace the pin connections to an instantiation or interface
11438 declaration with ones automatically derived from the module or
11439 interface header of the instantiated item.
11441 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
11442 and delete them before saving unless `verilog-auto-star-save' is set.
11443 See `verilog-auto-star' for more information.
11445 The pins are printed in declaration order or alphabetically,
11446 based on the `verilog-auto-inst-sort' variable.
11449 Module names must be resolvable to filenames by adding a
11450 `verilog-library-extensions', and being found in the same directory, or
11451 by changing the variable `verilog-library-flags' or
11452 `verilog-library-directories'. Macros `modname are translated through the
11453 vh-{name} Emacs variable, if that is not found, it just ignores the \\=`.
11455 In templates you must have one signal per line, ending in a ), or ));,
11456 and have proper () nesting, including a final ); to end the template.
11458 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11460 SystemVerilog multidimensional input/output has only experimental support.
11462 SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
11464 Parameters referenced by the instantiation will remain symbolic, unless
11465 `verilog-auto-inst-param-value' is set.
11467 Gate primitives (and/or) may have AUTOINST for the purpose of
11468 AUTOWIRE declarations, etc. Gates are the only case when
11469 position based connections are passed.
11471 The array part of arrayed instances are ignored; this may
11472 result in undesirable default AUTOINST connections; use a
11475 For example, first take the submodule InstModule.v:
11477 module InstModule (o,i);
11480 wire [31:0] o = {32{i}};
11483 This is then used in an upper level module:
11485 module ExampInst (o,i);
11488 InstModule instName
11492 Typing \\[verilog-auto] will make this into:
11494 module ExampInst (o,i);
11497 InstModule instName
11505 Where the list of inputs and outputs came from the inst module.
11509 Unless you are instantiating a module multiple times, or the module is
11510 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
11511 It just makes for unmaintainable code. To sanitize signal names, try
11512 vrename from URL `http://www.veripool.org'.
11514 When you need to violate this suggestion there are two ways to list
11515 exceptions, placing them before the AUTOINST, or using templates.
11517 Any ports defined before the /*AUTOINST*/ are not included in the list of
11518 automatics. This is similar to making a template as described below, but
11519 is restricted to simple connections just like you normally make. Also note
11520 that any signals before the AUTOINST will only be picked up by AUTOWIRE if
11521 you have the appropriate // Input or // Output comment, and exactly the
11522 same line formatting as AUTOINST itself uses.
11524 InstModule instName
11526 .i (my_i_dont_mess_with_it),
11534 For multiple instantiations based upon a single template, create a
11535 commented out template:
11537 /* InstModule AUTO_TEMPLATE (
11542 Templates go ABOVE the instantiation(s). When an instantiation is
11543 expanded `verilog-mode' simply searches up for the closest template.
11544 Thus you can have multiple templates for the same module, just alternate
11545 between the template for an instantiation and the instantiation itself.
11546 (For backward compatibility if no template is found above, it
11547 will also look below, but do not use this behavior in new designs.)
11549 The module name must be the same as the name of the module in the
11550 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
11551 words and capitalized. Only signals that must be different for each
11552 instantiation need to be listed.
11554 Inside a template, a [] in a connection name (with nothing else
11555 inside the brackets) will be replaced by the same bus subscript
11556 as it is being connected to, or the [] will be removed if it is
11557 a single bit signal.
11559 Inside a template, a [][] in a connection name will behave
11560 similarly to a [] for scalar or single-dimensional connection;
11561 for a multidimensional connection it will print a comment
11562 similar to that printed when a template is not used. Generally
11563 it is a good idea to do this for all connections in a template,
11564 as then they will work for any width signal, and with AUTOWIRE.
11565 See PTL_BUS becoming PTL_BUSNEW below.
11567 Inside a template, a [] in a connection name (with nothing else inside
11568 the brackets) will be replaced by the same bus subscript as it is being
11569 connected to, or the [] will be removed if it is a single bit signal.
11570 Generally it is a good idea to do this for all connections in a template,
11571 as then they will work for any width signal, and with AUTOWIRE. See
11572 PTL_BUS becoming PTL_BUSNEW below.
11574 If you have a complicated template, set `verilog-auto-inst-template-numbers'
11575 to see which regexps are matching. Don't leave that mode set after
11576 debugging is completed though, it will result in lots of extra differences
11577 and merge conflicts.
11579 Setting `verilog-auto-template-warn-unused' will report errors
11580 if any template lines are unused.
11584 /* InstModule AUTO_TEMPLATE (
11585 .ptl_bus (ptl_busnew[]),
11588 InstModule ms2m (/*AUTOINST*/);
11590 Typing \\[verilog-auto] will make this into:
11592 InstModule ms2m (/*AUTOINST*/
11594 .NotInTemplate (NotInTemplate),
11595 .ptl_bus (ptl_busnew[3:0]), // Templated
11599 Multiple Module Templates:
11601 The same template lines can be applied to multiple modules with
11602 the syntax as follows:
11604 /* InstModuleA AUTO_TEMPLATE
11605 InstModuleB AUTO_TEMPLATE
11606 InstModuleC AUTO_TEMPLATE
11607 InstModuleD AUTO_TEMPLATE (
11608 .ptl_bus (ptl_busnew[]),
11612 Note there is only one AUTO_TEMPLATE opening parenthesis.
11616 It is common to instantiate a cell multiple times, so templates make it
11617 trivial to substitute part of the cell name into the connection name.
11619 /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
11621 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
11625 If no regular expression is provided immediately after the AUTO_TEMPLATE
11626 keyword, then the @ character in any connection names will be replaced
11627 with the instantiation number; the first digits found in the cell's
11628 instantiation name.
11630 If a regular expression is provided, the @ character will be replaced
11631 with the first () grouping that matches against the cell name. Using a
11632 regexp of `\\([0-9]+\\)' provides identical values for @ as when no
11633 regexp is provided. If you use multiple layers of parenthesis,
11634 `test\\([^0-9]+\\)_\\([0-9]+\\)' would replace @ with non-number
11635 characters after test and before _, whereas
11636 `\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)' would replace @ with the entire
11641 /* InstModule AUTO_TEMPLATE (
11642 .ptl_mapvalidx (ptl_mapvalid[@]),
11643 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
11646 InstModule ms2m (/*AUTOINST*/);
11648 Typing \\[verilog-auto] will make this into:
11650 InstModule ms2m (/*AUTOINST*/
11652 .ptl_mapvalidx (ptl_mapvalid[2]),
11653 .ptl_mapvalidp1x (ptl_mapvalid[3]));
11655 Note the @ character was replaced with the 2 from \"ms2m\".
11657 Alternatively, using a regular expression for @:
11659 /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
11660 .ptl_mapvalidx (@_ptl_mapvalid),
11661 .ptl_mapvalidp1x (ptl_mapvalid_@),
11664 InstModule ms2_FOO (/*AUTOINST*/);
11665 InstModule ms2_BAR (/*AUTOINST*/);
11667 Typing \\[verilog-auto] will make this into:
11669 InstModule ms2_FOO (/*AUTOINST*/
11671 .ptl_mapvalidx (FOO_ptl_mapvalid),
11672 .ptl_mapvalidp1x (ptl_mapvalid_FOO));
11673 InstModule ms2_BAR (/*AUTOINST*/
11675 .ptl_mapvalidx (BAR_ptl_mapvalid),
11676 .ptl_mapvalidp1x (ptl_mapvalid_BAR));
11681 A template entry of the form
11683 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
11685 will apply an Emacs style regular expression search for any port beginning
11686 in pci_req followed by numbers and ending in _l and connecting that to
11687 the pci_req_jtag_[] net, with the bus subscript coming from what matches
11688 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
11690 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
11691 does the same thing. (Note a @ in the connection/replacement text is
11692 completely different -- still use \\1 there!) Thus this is the same as
11693 the above template:
11695 .pci_req@_l (pci_req_jtag_[\\1]),
11697 Here's another example to remove the _l, useful when naming conventions
11698 specify _ alone to mean active low. Note the use of [] to keep the bus
11701 .\\(.*\\)_l (\\1_[]),
11705 First any regular expression template is expanded.
11707 If the syntax @\"( ... )\" is found in a connection, the expression in
11708 quotes will be evaluated as a Lisp expression, with @ replaced by the
11709 instantiation number. The MAPVALIDP1X example above would put @+1 modulo
11710 4 into the brackets. Quote all double-quotes inside the expression with
11711 a leading backslash (\\\"...\\\"); or if the Lisp template is also a
11712 regexp template backslash the backslash quote (\\\\\"...\\\\\").
11714 There are special variables defined that are useful in these
11717 vl-name Name portion of the input/output port.
11718 vl-bits Bus bits portion of the input/output port (`[2:0]').
11719 vl-mbits Multidimensional array bits for port (`[2:0][3:0]').
11720 vl-width Width of the input/output port (`3' for [2:0]).
11721 May be a (...) expression if bits isn't a constant.
11722 vl-dir Direction of the pin input/output/inout/interface.
11723 vl-modport The modport, if an interface with a modport.
11724 vl-cell-type Module name/type of the cell (`InstModule').
11725 vl-cell-name Instance name of the cell (`instName').
11727 Normal Lisp variables may be used in expressions. See
11728 `verilog-read-defines' which can set vh-{definename} variables for use
11729 here. Also, any comments of the form:
11731 /*AUTO_LISP(setq foo 1)*/
11733 will evaluate any Lisp expression inside the parenthesis between the
11734 beginning of the buffer and the point of the AUTOINST. This allows
11735 functions to be defined or variables to be changed between instantiations.
11736 (See also `verilog-auto-insert-lisp' if you want the output from your
11737 lisp function to be inserted.)
11739 Note that when using lisp expressions errors may occur when @ is not a
11740 number; you may need to use the standard Emacs Lisp functions
11741 `number-to-string' and `string-to-number'.
11743 After the evaluation is completed, @ substitution and [] substitution
11746 For more information see the \\[verilog-faq] and forums at URL
11747 `http://www.veripool.org'."
11750 (let* ((pt (point))
11751 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
11752 (indent-pt (save-excursion (verilog-backward-open-paren)
11753 (1+ (current-column))))
11754 (verilog-auto-inst-column (max verilog-auto-inst-column
11755 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11756 (modi (verilog-modi-current))
11757 (moddecls (verilog-modi-get-decls modi))
11758 submod submodi submoddecls
11759 inst skip-pins tpl-list tpl-num did-first par-values)
11761 ;; Find module name that is instantiated
11762 (setq submod (verilog-read-inst-module)
11763 inst (verilog-read-inst-name)
11764 vl-cell-type submod
11766 skip-pins (aref (verilog-read-inst-pins) 0))
11768 ;; Parse any AUTO_LISP() before here
11769 (verilog-read-auto-lisp (point-min) pt)
11771 ;; Read parameters (after AUTO_LISP)
11772 (setq par-values (and verilog-auto-inst-param-value
11773 (verilog-read-inst-param-value)))
11775 ;; Lookup position, etc of submodule
11776 ;; Note this may raise an error
11777 (when (and (not (member submod verilog-gate-keywords))
11778 (setq submodi (verilog-modi-lookup submod t)))
11779 (setq submoddecls (verilog-modi-get-decls submodi))
11780 ;; If there's a number in the instantiation, it may be an argument to the
11781 ;; automatic variable instantiation program.
11782 (let* ((tpl-info (verilog-read-auto-template submod))
11783 (tpl-regexp (aref tpl-info 0)))
11784 (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
11785 (match-string 1 inst)
11787 tpl-list (aref tpl-info 1)))
11788 ;; Find submodule's signals and dump
11789 (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
11790 (verilog-signals-not-in
11791 (verilog-decls-get-vars submoddecls)
11793 (vl-dir "interfaced"))
11794 (when (and sig-list
11795 verilog-auto-inst-interfaced-ports)
11796 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11797 ;; Note these are searched for in verilog-read-sub-decls.
11798 (verilog-insert-indent "// Interfaced\n")
11799 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11800 tpl-list tpl-num for-star par-values)))
11801 (let ((sig-list (verilog-signals-not-in
11802 (verilog-decls-get-interfaces submoddecls)
11804 (vl-dir "interface"))
11806 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11807 ;; Note these are searched for in verilog-read-sub-decls.
11808 (verilog-insert-indent "// Interfaces\n")
11809 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11810 tpl-list tpl-num for-star par-values)))
11811 (let ((sig-list (verilog-signals-not-in
11812 (verilog-decls-get-outputs submoddecls)
11816 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11817 (verilog-insert-indent "// Outputs\n")
11818 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11819 tpl-list tpl-num for-star par-values)))
11820 (let ((sig-list (verilog-signals-not-in
11821 (verilog-decls-get-inouts submoddecls)
11825 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11826 (verilog-insert-indent "// Inouts\n")
11827 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11828 tpl-list tpl-num for-star par-values)))
11829 (let ((sig-list (verilog-signals-not-in
11830 (verilog-decls-get-inputs submoddecls)
11834 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11835 (verilog-insert-indent "// Inputs\n")
11836 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11837 tpl-list tpl-num for-star par-values)))
11841 (re-search-backward "," pt t)
11844 (search-forward "\n") ; Added by inst-port
11846 (if (search-forward ")" nil t) ; From user, moved up a line
11848 (if (search-forward ";" nil t) ; Don't error if user had syntax error and forgot it
11849 (delete-char -1)))))))))
11851 (defun verilog-auto-inst-param ()
11852 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
11853 Replace the parameter connections to an instantiation with ones
11854 automatically derived from the module header of the instantiated netlist.
11856 See \\[verilog-auto-inst] for limitations, and templates to customize the
11859 For example, first take the submodule InstModule.v:
11861 module InstModule (o,i);
11865 This is then used in an upper level module:
11867 module ExampInst (o,i);
11869 InstModule #(/*AUTOINSTPARAM*/)
11870 instName (/*AUTOINST*/);
11873 Typing \\[verilog-auto] will make this into:
11875 module ExampInst (o,i);
11878 InstModule #(/*AUTOINSTPARAM*/
11881 instName (/*AUTOINST*/);
11884 Where the list of parameter connections come from the inst module.
11888 You can customize the parameter connections using AUTO_TEMPLATEs,
11889 just as you would with \\[verilog-auto-inst]."
11892 (let* ((pt (point))
11893 (indent-pt (save-excursion (verilog-backward-open-paren)
11894 (1+ (current-column))))
11895 (verilog-auto-inst-column (max verilog-auto-inst-column
11896 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11897 (modi (verilog-modi-current))
11898 (moddecls (verilog-modi-get-decls modi))
11899 submod submodi submoddecls
11900 inst skip-pins tpl-list tpl-num did-first)
11901 ;; Find module name that is instantiated
11902 (setq submod (save-excursion
11903 ;; Get to the point where AUTOINST normally is to read the module
11904 (verilog-re-search-forward-quick "[(;]" nil nil)
11905 (verilog-read-inst-module))
11906 inst (save-excursion
11907 ;; Get to the point where AUTOINST normally is to read the module
11908 (verilog-re-search-forward-quick "[(;]" nil nil)
11909 (verilog-read-inst-name))
11910 vl-cell-type submod
11912 skip-pins (aref (verilog-read-inst-pins) 0))
11914 ;; Parse any AUTO_LISP() before here
11915 (verilog-read-auto-lisp (point-min) pt)
11917 ;; Lookup position, etc of submodule
11918 ;; Note this may raise an error
11919 (when (setq submodi (verilog-modi-lookup submod t))
11920 (setq submoddecls (verilog-modi-get-decls submodi))
11921 ;; If there's a number in the instantiation, it may be an argument to the
11922 ;; automatic variable instantiation program.
11923 (let* ((tpl-info (verilog-read-auto-template submod))
11924 (tpl-regexp (aref tpl-info 0)))
11925 (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
11926 (match-string 1 inst)
11928 tpl-list (aref tpl-info 1)))
11929 ;; Find submodule's signals and dump
11930 (let ((sig-list (verilog-signals-not-in
11931 (verilog-decls-get-gparams submoddecls)
11933 (vl-dir "parameter"))
11935 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11936 ;; Note these are searched for in verilog-read-sub-decls.
11937 (verilog-insert-indent "// Parameters\n")
11938 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11939 tpl-list tpl-num nil nil)))
11943 (re-search-backward "," pt t)
11946 (search-forward "\n") ; Added by inst-port
11948 (if (search-forward ")" nil t) ; From user, moved up a line
11949 (delete-char -1)))))))))
11951 (defun verilog-auto-reg ()
11952 "Expand AUTOREG statements, as part of \\[verilog-auto].
11953 Make reg statements for any output that isn't already declared,
11954 and isn't a wire output from a block. `verilog-auto-wire-type'
11955 may be used to change the datatype of the declarations.
11958 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11960 This does NOT work on memories, declare those yourself.
11964 module ExampReg (o,i);
11971 Typing \\[verilog-auto] will make this into:
11973 module ExampReg (o,i);
11977 // Beginning of automatic regs (for this module's undeclared outputs)
11979 // End of automatics
11983 ;; Point must be at insertion point.
11984 (let* ((indent-pt (current-indentation))
11985 (modi (verilog-modi-current))
11986 (moddecls (verilog-modi-get-decls modi))
11987 (modsubdecls (verilog-modi-get-sub-decls modi))
11988 (sig-list (verilog-signals-not-in
11989 (verilog-decls-get-outputs moddecls)
11990 (append (verilog-signals-with ; ignore typed signals
11992 (verilog-decls-get-outputs moddecls))
11993 (verilog-decls-get-vars moddecls)
11994 (verilog-decls-get-assigns moddecls)
11995 (verilog-decls-get-consts moddecls)
11996 (verilog-decls-get-gparams moddecls)
11997 (verilog-subdecls-get-interfaced modsubdecls)
11998 (verilog-subdecls-get-outputs modsubdecls)
11999 (verilog-subdecls-get-inouts modsubdecls)))))
12001 (verilog-forward-or-insert-line)
12002 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
12003 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
12004 (verilog-insert-indent "// End of automatics\n")))))
12006 (defun verilog-auto-reg-input ()
12007 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
12008 Make reg statements instantiation inputs that aren't already declared.
12009 This is useful for making a top level shell for testing the module that is
12010 to be instantiated.
12013 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
12015 This does NOT work on memories, declare those yourself.
12017 An example (see `verilog-auto-inst' for what else is going on here):
12019 module ExampRegInput (o,i);
12023 InstModule instName
12027 Typing \\[verilog-auto] will make this into:
12029 module ExampRegInput (o,i);
12033 // Beginning of automatic reg inputs (for undeclared ...
12034 reg [31:0] iv; // From inst of inst.v
12035 // End of automatics
12036 InstModule instName
12044 ;; Point must be at insertion point.
12045 (let* ((indent-pt (current-indentation))
12046 (modi (verilog-modi-current))
12047 (moddecls (verilog-modi-get-decls modi))
12048 (modsubdecls (verilog-modi-get-sub-decls modi))
12049 (sig-list (verilog-signals-combine-bus
12050 (verilog-signals-not-in
12051 (append (verilog-subdecls-get-inputs modsubdecls)
12052 (verilog-subdecls-get-inouts modsubdecls))
12053 (append (verilog-decls-get-signals moddecls)
12054 (verilog-decls-get-assigns moddecls))))))
12056 (verilog-forward-or-insert-line)
12057 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
12058 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
12059 (verilog-insert-indent "// End of automatics\n")))))
12061 (defun verilog-auto-logic-setup ()
12062 "Prepare variables due to AUTOLOGIC."
12063 (unless verilog-auto-wire-type
12064 (set (make-local-variable 'verilog-auto-wire-type)
12067 (defun verilog-auto-logic ()
12068 "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
12069 Make wire statements using the SystemVerilog logic keyword.
12070 This is currently equivalent to:
12074 with the below at the bottom of the file
12076 // Local Variables:
12077 // verilog-auto-logic-type:\"logic\"
12080 In the future AUTOLOGIC may declare additional identifiers,
12081 while AUTOWIRE will not."
12083 (verilog-auto-logic-setup)
12084 (verilog-auto-wire)))
12086 (defun verilog-auto-wire ()
12087 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
12088 Make wire statements for instantiations outputs that aren't
12089 already declared. `verilog-auto-wire-type' may be used to change
12090 the datatype of the declarations.
12093 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
12094 and all buses must have widths, such as those from AUTOINST, or using []
12097 This does NOT work on memories or SystemVerilog .name connections,
12098 declare those yourself.
12100 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
12101 determine how to bus together. This occurs when you have ports with
12102 non-numeric or non-sequential bus subscripts. If Verilog mode
12103 mis-guessed, you'll have to declare them yourself.
12105 An example (see `verilog-auto-inst' for what else is going on here):
12107 module ExampWire (o,i);
12111 InstModule instName
12115 Typing \\[verilog-auto] will make this into:
12117 module ExampWire (o,i);
12121 // Beginning of automatic wires
12122 wire [31:0] ov; // From inst of inst.v
12123 // End of automatics
12124 InstModule instName
12133 ;; Point must be at insertion point.
12134 (let* ((indent-pt (current-indentation))
12135 (modi (verilog-modi-current))
12136 (moddecls (verilog-modi-get-decls modi))
12137 (modsubdecls (verilog-modi-get-sub-decls modi))
12138 (sig-list (verilog-signals-combine-bus
12139 (verilog-signals-not-in
12140 (append (verilog-subdecls-get-outputs modsubdecls)
12141 (verilog-subdecls-get-inouts modsubdecls))
12142 (verilog-decls-get-signals moddecls)))))
12144 (verilog-forward-or-insert-line)
12145 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
12146 (verilog-insert-definition modi sig-list "wire" indent-pt nil)
12147 (verilog-insert-indent "// End of automatics\n")
12148 ;; We used to optionally call verilog-pretty-declarations and
12149 ;; verilog-pretty-expr here, but it's too slow on huge modules,
12150 ;; plus makes everyone's module change. Finally those call
12151 ;; syntax-ppss which is broken when change hooks are disabled.
12154 (defun verilog-auto-output ()
12155 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
12156 Make output statements for any output signal from an /*AUTOINST*/ that
12157 isn't an input to another AUTOINST. This is useful for modules which
12158 only instantiate other modules.
12161 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
12163 If placed inside the parenthesis of a module declaration, it creates
12164 Verilog 2001 style, else uses Verilog 1995 style.
12166 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
12167 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
12169 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
12171 Types are added to declarations if an AUTOLOGIC or
12172 `verilog-auto-wire-type' is set to logic.
12174 Signals matching `verilog-auto-output-ignore-regexp' are not included.
12176 An example (see `verilog-auto-inst' for what else is going on here):
12178 module ExampOutput (ov,i);
12181 InstModule instName
12185 Typing \\[verilog-auto] will make this into:
12187 module ExampOutput (ov,i);
12190 // Beginning of automatic outputs (from unused autoinst outputs)
12191 output [31:0] ov; // From inst of inst.v
12192 // End of automatics
12193 InstModule instName
12201 You may also provide an optional regular expression, in which case only
12202 signals matching the regular expression will be included. For example the
12203 same expansion will result from only extracting outputs starting with ov:
12205 /*AUTOOUTPUT(\"^ov\")*/"
12207 ;; Point must be at insertion point.
12208 (let* ((indent-pt (current-indentation))
12209 (params (verilog-read-auto-params 0 1))
12210 (regexp (nth 0 params))
12211 (v2k (verilog-in-paren-quick))
12212 (modi (verilog-modi-current))
12213 (moddecls (verilog-modi-get-decls modi))
12214 (modsubdecls (verilog-modi-get-sub-decls modi))
12215 (sig-list (verilog-signals-not-in
12216 (verilog-subdecls-get-outputs modsubdecls)
12217 (append (verilog-decls-get-outputs moddecls)
12218 (verilog-decls-get-inouts moddecls)
12219 (verilog-decls-get-inputs moddecls)
12220 (verilog-subdecls-get-inputs modsubdecls)
12221 (verilog-subdecls-get-inouts modsubdecls)))))
12223 (setq sig-list (verilog-signals-matching-regexp
12225 (setq sig-list (verilog-signals-not-matching-regexp
12226 sig-list verilog-auto-output-ignore-regexp))
12227 (verilog-forward-or-insert-line)
12228 (when v2k (verilog-repair-open-comma))
12230 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
12231 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
12232 (verilog-insert-indent "// End of automatics\n"))
12233 (when v2k (verilog-repair-close-comma)))))
12235 (defun verilog-auto-output-every ()
12236 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
12237 Make output statements for any signals that aren't primary inputs or
12238 outputs already. This makes every signal in the design an output. This is
12239 useful to get Synopsys to preserve every signal in the design, since it
12240 won't optimize away the outputs.
12244 module ExampOutputEvery (o,i,tempa,tempb);
12247 /*AUTOOUTPUTEVERY*/
12249 wire tempb = tempa;
12253 Typing \\[verilog-auto] will make this into:
12255 module ExampOutputEvery (o,i,tempa,tempb);
12258 /*AUTOOUTPUTEVERY*/
12259 // Beginning of automatic outputs (every signal)
12262 // End of automatics
12264 wire tempb = tempa;
12268 You may also provide an optional regular expression, in which case only
12269 signals matching the regular expression will be included. For example the
12270 same expansion will result from only extracting outputs starting with ov:
12272 /*AUTOOUTPUTEVERY(\"^ov\")*/"
12274 ;;Point must be at insertion point
12275 (let* ((indent-pt (current-indentation))
12276 (params (verilog-read-auto-params 0 1))
12277 (regexp (nth 0 params))
12278 (v2k (verilog-in-paren-quick))
12279 (modi (verilog-modi-current))
12280 (moddecls (verilog-modi-get-decls modi))
12281 (sig-list (verilog-signals-combine-bus
12282 (verilog-signals-not-in
12283 (verilog-decls-get-signals moddecls)
12284 (verilog-decls-get-ports moddecls)))))
12286 (setq sig-list (verilog-signals-matching-regexp
12288 (setq sig-list (verilog-signals-not-matching-regexp
12289 sig-list verilog-auto-output-ignore-regexp))
12290 (verilog-forward-or-insert-line)
12291 (when v2k (verilog-repair-open-comma))
12293 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
12294 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
12295 (verilog-insert-indent "// End of automatics\n"))
12296 (when v2k (verilog-repair-close-comma)))))
12298 (defun verilog-auto-input ()
12299 "Expand AUTOINPUT statements, as part of \\[verilog-auto].
12300 Make input statements for any input signal into an /*AUTOINST*/ that
12301 isn't declared elsewhere inside the module. This is useful for modules which
12302 only instantiate other modules.
12305 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
12307 If placed inside the parenthesis of a module declaration, it creates
12308 Verilog 2001 style, else uses Verilog 1995 style.
12310 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
12311 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
12313 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
12315 Types are added to declarations if an AUTOLOGIC or
12316 `verilog-auto-wire-type' is set to logic.
12318 Signals matching `verilog-auto-input-ignore-regexp' are not included.
12320 An example (see `verilog-auto-inst' for what else is going on here):
12322 module ExampInput (ov,i);
12325 InstModule instName
12329 Typing \\[verilog-auto] will make this into:
12331 module ExampInput (ov,i);
12334 // Beginning of automatic inputs (from unused autoinst inputs)
12335 input i; // From inst of inst.v
12336 // End of automatics
12337 InstModule instName
12345 You may also provide an optional regular expression, in which case only
12346 signals matching the regular expression will be included. For example the
12347 same expansion will result from only extracting inputs starting with i:
12349 /*AUTOINPUT(\"^i\")*/"
12351 (let* ((indent-pt (current-indentation))
12352 (params (verilog-read-auto-params 0 1))
12353 (regexp (nth 0 params))
12354 (v2k (verilog-in-paren-quick))
12355 (modi (verilog-modi-current))
12356 (moddecls (verilog-modi-get-decls modi))
12357 (modsubdecls (verilog-modi-get-sub-decls modi))
12358 (sig-list (verilog-signals-not-in
12359 (verilog-subdecls-get-inputs modsubdecls)
12360 (append (verilog-decls-get-inputs moddecls)
12361 (verilog-decls-get-inouts moddecls)
12362 (verilog-decls-get-outputs moddecls)
12363 (verilog-decls-get-vars moddecls)
12364 (verilog-decls-get-consts moddecls)
12365 (verilog-decls-get-gparams moddecls)
12366 (verilog-subdecls-get-interfaced modsubdecls)
12367 (verilog-subdecls-get-outputs modsubdecls)
12368 (verilog-subdecls-get-inouts modsubdecls)))))
12370 (setq sig-list (verilog-signals-matching-regexp
12372 (setq sig-list (verilog-signals-not-matching-regexp
12373 sig-list verilog-auto-input-ignore-regexp))
12374 (verilog-forward-or-insert-line)
12375 (when v2k (verilog-repair-open-comma))
12377 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
12378 (verilog-insert-definition modi sig-list "input" indent-pt v2k)
12379 (verilog-insert-indent "// End of automatics\n"))
12380 (when v2k (verilog-repair-close-comma)))))
12382 (defun verilog-auto-inout ()
12383 "Expand AUTOINOUT statements, as part of \\[verilog-auto].
12384 Make inout statements for any inout signal in an /*AUTOINST*/ that
12385 isn't declared elsewhere inside the module.
12388 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
12390 If placed inside the parenthesis of a module declaration, it creates
12391 Verilog 2001 style, else uses Verilog 1995 style.
12393 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
12394 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
12396 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
12398 Types are added to declarations if an AUTOLOGIC or
12399 `verilog-auto-wire-type' is set to logic.
12401 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
12403 An example (see `verilog-auto-inst' for what else is going on here):
12405 module ExampInout (ov,i);
12408 InstModule instName
12412 Typing \\[verilog-auto] will make this into:
12414 module ExampInout (ov,i);
12417 // Beginning of automatic inouts (from unused autoinst inouts)
12418 inout [31:0] ov; // From inst of inst.v
12419 // End of automatics
12420 InstModule instName
12428 You may also provide an optional regular expression, in which case only
12429 signals matching the regular expression will be included. For example the
12430 same expansion will result from only extracting inouts starting with i:
12432 /*AUTOINOUT(\"^i\")*/"
12434 ;; Point must be at insertion point.
12435 (let* ((indent-pt (current-indentation))
12436 (params (verilog-read-auto-params 0 1))
12437 (regexp (nth 0 params))
12438 (v2k (verilog-in-paren-quick))
12439 (modi (verilog-modi-current))
12440 (moddecls (verilog-modi-get-decls modi))
12441 (modsubdecls (verilog-modi-get-sub-decls modi))
12442 (sig-list (verilog-signals-not-in
12443 (verilog-subdecls-get-inouts modsubdecls)
12444 (append (verilog-decls-get-outputs moddecls)
12445 (verilog-decls-get-inouts moddecls)
12446 (verilog-decls-get-inputs moddecls)
12447 (verilog-subdecls-get-inputs modsubdecls)
12448 (verilog-subdecls-get-outputs modsubdecls)))))
12450 (setq sig-list (verilog-signals-matching-regexp
12452 (setq sig-list (verilog-signals-not-matching-regexp
12453 sig-list verilog-auto-inout-ignore-regexp))
12454 (verilog-forward-or-insert-line)
12455 (when v2k (verilog-repair-open-comma))
12457 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
12458 (verilog-insert-definition modi sig-list "inout" indent-pt v2k)
12459 (verilog-insert-indent "// End of automatics\n"))
12460 (when v2k (verilog-repair-close-comma)))))
12462 (defun verilog-auto-inout-module (&optional complement all-in)
12463 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
12464 Take input/output/inout statements from the specified module and insert
12465 into the current module. This is useful for making null templates and
12466 shell modules which need to have identical I/O with another module.
12467 Any I/O which are already defined in this module will not be redefined.
12468 For the complement of this function, see `verilog-auto-inout-comp',
12469 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12472 If placed inside the parenthesis of a module declaration, it creates
12473 Verilog 2001 style, else uses Verilog 1995 style.
12475 Concatenation and outputting partial buses is not supported.
12477 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12479 Signals are not inserted in the same order as in the original module,
12480 though they will appear to be in the same order to an AUTOINST
12481 instantiating either module.
12483 Signals declared as \"output reg\" or \"output wire\" etc will
12484 lose the wire/reg declaration so that shell modules may
12485 generate those outputs differently. However, \"output logic\"
12490 module ExampShell (/*AUTOARG*/);
12491 /*AUTOINOUTMODULE(\"ExampMain\")*/
12494 module ExampMain (i,o,io);
12500 Typing \\[verilog-auto] will make this into:
12502 module ExampShell (/*AUTOARG*/i,o,io);
12503 /*AUTOINOUTMODULE(\"ExampMain\")*/
12504 // Beginning of automatic in/out/inouts (from specific module)
12508 // End of automatics
12511 You may also provide an optional regular expression, in which case only
12512 signals matching the regular expression will be included. For example the
12513 same expansion will result from only extracting signals starting with i:
12515 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
12517 You may also provide an optional third argument regular
12518 expression, in which case only signals which have that pin
12519 direction and data type matching that regular expression will be
12520 included. This matches against everything before the signal name
12521 in the declaration, for example against \"input\" (single
12522 bit), \"output logic\" (direction and type) or
12523 \"output [1:0]\" (direction and implicit type). You also
12524 probably want to skip spaces in your regexp.
12526 For example, the below will result in matching the output \"o\"
12527 against the previous example's module:
12529 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/
12531 You may also provide an optional fourth argument regular
12532 expression, which if not \"\" only signals which do NOT match
12533 that expression are included."
12534 ;; Beware spacing of quotes in above as can mess up Emacs indenter
12536 (let* ((params (verilog-read-auto-params 1 4))
12537 (submod (nth 0 params))
12538 (regexp (nth 1 params))
12539 (direction-re (nth 2 params))
12540 (not-re (nth 3 params))
12542 ;; Lookup position, etc of co-module
12543 ;; Note this may raise an error
12544 (when (setq submodi (verilog-modi-lookup submod t))
12545 (let* ((indent-pt (current-indentation))
12546 (v2k (verilog-in-paren-quick))
12547 (modi (verilog-modi-current))
12548 (moddecls (verilog-modi-get-decls modi))
12549 (submoddecls (verilog-modi-get-decls submodi))
12550 (sig-list-i (verilog-signals-not-in
12553 (verilog-decls-get-inputs submoddecls)
12554 (verilog-decls-get-inouts submoddecls)
12555 (verilog-decls-get-outputs submoddecls)))
12557 (verilog-decls-get-outputs submoddecls))
12558 (t (verilog-decls-get-inputs submoddecls)))
12559 (append (verilog-decls-get-inputs moddecls))))
12560 (sig-list-o (verilog-signals-not-in
12563 (verilog-decls-get-inputs submoddecls))
12564 (t (verilog-decls-get-outputs submoddecls)))
12565 (append (verilog-decls-get-outputs moddecls))))
12566 (sig-list-io (verilog-signals-not-in
12568 (t (verilog-decls-get-inouts submoddecls)))
12569 (append (verilog-decls-get-inouts moddecls))))
12570 (sig-list-if (verilog-signals-not-in
12571 (verilog-decls-get-interfaces submoddecls)
12572 (append (verilog-decls-get-interfaces moddecls)))))
12574 (setq sig-list-i (verilog-signals-edit-wire-reg
12575 (verilog-signals-not-matching-regexp
12576 (verilog-signals-matching-dir-re
12577 (verilog-signals-matching-regexp sig-list-i regexp)
12578 "input" direction-re) not-re))
12579 sig-list-o (verilog-signals-edit-wire-reg
12580 (verilog-signals-not-matching-regexp
12581 (verilog-signals-matching-dir-re
12582 (verilog-signals-matching-regexp sig-list-o regexp)
12583 "output" direction-re) not-re))
12584 sig-list-io (verilog-signals-edit-wire-reg
12585 (verilog-signals-not-matching-regexp
12586 (verilog-signals-matching-dir-re
12587 (verilog-signals-matching-regexp sig-list-io regexp)
12588 "inout" direction-re) not-re))
12589 sig-list-if (verilog-signals-not-matching-regexp
12590 (verilog-signals-matching-dir-re
12591 (verilog-signals-matching-regexp sig-list-if regexp)
12592 "interface" direction-re) not-re))
12593 (when v2k (verilog-repair-open-comma))
12594 (when (or sig-list-i sig-list-o sig-list-io sig-list-if)
12595 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
12596 ;; Don't sort them so an upper AUTOINST will match the main module
12597 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12598 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12599 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12600 (verilog-insert-definition modi sig-list-if "interface" indent-pt v2k t)
12601 (verilog-insert-indent "// End of automatics\n"))
12602 (when v2k (verilog-repair-close-comma)))))))
12604 (defun verilog-auto-inout-comp ()
12605 "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
12606 Take input/output/inout statements from the specified module and
12607 insert the inverse into the current module (inputs become outputs
12608 and vice-versa.) This is useful for making test and stimulus
12609 modules which need to have complementing I/O with another module.
12610 Any I/O which are already defined in this module will not be
12611 redefined. For the complement of this function, see
12612 `verilog-auto-inout-module'.
12615 If placed inside the parenthesis of a module declaration, it creates
12616 Verilog 2001 style, else uses Verilog 1995 style.
12618 Concatenation and outputting partial buses is not supported.
12620 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12622 Signals are not inserted in the same order as in the original module,
12623 though they will appear to be in the same order to an AUTOINST
12624 instantiating either module.
12628 module ExampShell (/*AUTOARG*/);
12629 /*AUTOINOUTCOMP(\"ExampMain\")*/
12632 module ExampMain (i,o,io);
12638 Typing \\[verilog-auto] will make this into:
12640 module ExampShell (/*AUTOARG*/i,o,io);
12641 /*AUTOINOUTCOMP(\"ExampMain\")*/
12642 // Beginning of automatic in/out/inouts (from specific module)
12646 // End of automatics
12649 You may also provide an optional regular expression, in which case only
12650 signals matching the regular expression will be included. For example the
12651 same expansion will result from only extracting signals starting with i:
12653 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/
12655 You may also provide an optional third argument regular
12656 expression, in which case only signals which have that pin
12657 direction and data type matching that regular expression will be
12658 included. This matches against everything before the signal name
12659 in the declaration, for example against \"input\" (single
12660 bit), \"output logic\" (direction and type)
12661 or \"output [1:0]\" (direction and implicit type). You also
12662 probably want to skip spaces in your regexp.
12664 For example, the below will result in matching the output \"o\"
12665 against the previous example's module:
12667 /*AUTOINOUTCOMP(\"ExampMain\",\"\",\"^output.*\")*/
12669 You may also provide an optional fourth argument regular
12670 expression, which if not \"\" only signals which do NOT match
12671 that expression are included."
12672 ;; Beware spacing of quotes in above as can mess up Emacs indenter
12673 (verilog-auto-inout-module t nil))
12675 (defun verilog-auto-inout-in ()
12676 "Expand AUTOINOUTIN statements, as part of \\[verilog-auto].
12677 Take input/output/inout statements from the specified module and
12678 insert them as all inputs into the current module. This is
12679 useful for making monitor modules which need to see all signals
12680 as inputs based on another module. Any I/O which are already
12681 defined in this module will not be redefined. See also
12682 `verilog-auto-inout-module'.
12685 If placed inside the parenthesis of a module declaration, it creates
12686 Verilog 2001 style, else uses Verilog 1995 style.
12688 Concatenation and outputting partial buses is not supported.
12690 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12692 Signals are not inserted in the same order as in the original module,
12693 though they will appear to be in the same order to an AUTOINST
12694 instantiating either module.
12698 module ExampShell (/*AUTOARG*/);
12699 /*AUTOINOUTIN(\"ExampMain\")*/
12702 module ExampMain (i,o,io);
12708 Typing \\[verilog-auto] will make this into:
12710 module ExampShell (/*AUTOARG*/i,o,io);
12711 /*AUTOINOUTIN(\"ExampMain\")*/
12712 // Beginning of automatic in/out/inouts (from specific module)
12716 // End of automatics
12719 You may also provide an optional regular expression, in which case only
12720 signals matching the regular expression will be included. For example the
12721 same expansion will result from only extracting signals starting with i:
12723 /*AUTOINOUTIN(\"ExampMain\",\"^i\")*/"
12724 (verilog-auto-inout-module nil t))
12726 (defun verilog-auto-inout-param ()
12727 "Expand AUTOINOUTPARAM statements, as part of \\[verilog-auto].
12728 Take input/output/inout statements from the specified module and insert
12729 into the current module. This is useful for making null templates and
12730 shell modules which need to have identical I/O with another module.
12731 Any I/O which are already defined in this module will not be redefined.
12732 For the complement of this function, see `verilog-auto-inout-comp',
12733 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12736 If placed inside the parenthesis of a module declaration, it creates
12737 Verilog 2001 style, else uses Verilog 1995 style.
12739 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12741 Parameters are inserted in the same order as in the original module.
12743 Parameters do not have values, which is SystemVerilog 2009 syntax.
12747 module ExampShell ();
12748 /*AUTOINOUTPARAM(\"ExampMain\")*/
12751 module ExampMain ();
12752 parameter PARAM = 22;
12755 Typing \\[verilog-auto] will make this into:
12757 module ExampShell (/*AUTOARG*/i,o,io);
12758 /*AUTOINOUTPARAM(\"ExampMain\")*/
12759 // Beginning of automatic parameters (from specific module)
12761 // End of automatics
12764 You may also provide an optional regular expression, in which case only
12765 parameters matching the regular expression will be included. For example the
12766 same expansion will result from only extracting parameters starting with i:
12768 /*AUTOINOUTPARAM(\"ExampMain\",\"^i\")*/"
12770 (let* ((params (verilog-read-auto-params 1 2))
12771 (submod (nth 0 params))
12772 (regexp (nth 1 params))
12774 ;; Lookup position, etc of co-module
12775 ;; Note this may raise an error
12776 (when (setq submodi (verilog-modi-lookup submod t))
12777 (let* ((indent-pt (current-indentation))
12778 (v2k (verilog-in-paren-quick))
12779 (modi (verilog-modi-current))
12780 (moddecls (verilog-modi-get-decls modi))
12781 (submoddecls (verilog-modi-get-decls submodi))
12782 (sig-list-p (verilog-signals-not-in
12783 (verilog-decls-get-gparams submoddecls)
12784 (append (verilog-decls-get-gparams moddecls)))))
12786 (setq sig-list-p (verilog-signals-matching-regexp sig-list-p regexp))
12787 (when v2k (verilog-repair-open-comma))
12789 (verilog-insert-indent "// Beginning of automatic parameters (from specific module)\n")
12790 ;; Don't sort them so an upper AUTOINST will match the main module
12791 (verilog-insert-definition modi sig-list-p "parameter" indent-pt v2k t)
12792 (verilog-insert-indent "// End of automatics\n"))
12793 (when v2k (verilog-repair-close-comma)))))))
12795 (defun verilog-auto-inout-modport ()
12796 "Expand AUTOINOUTMODPORT statements, as part of \\[verilog-auto].
12797 Take input/output/inout statements from the specified interface
12798 and modport and insert into the current module. This is useful
12799 for making verification modules that connect to UVM interfaces.
12801 The first parameter is the name of an interface.
12803 The second parameter is a regexp of modports to read from in
12806 The optional third parameter is a regular expression, and only
12807 signals matching the regular expression will be included.
12810 If placed inside the parenthesis of a module declaration, it creates
12811 Verilog 2001 style, else uses Verilog 1995 style.
12813 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
12815 As with other autos, any inputs/outputs declared in the module
12816 will suppress the AUTO from redeclaring an inputs/outputs by
12822 ( input logic clk );
12824 logic [7:0] req_dat;
12825 clocking mon_clkblk @(posedge clk);
12829 modport mp(clocking mon_clkblk);
12834 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12835 // Beginning of automatic in/out/inouts (from modport)
12836 input [7:0] req_dat,
12838 // End of automatics
12840 /*AUTOASSIGNMODPORT(\"ExampIf\" \"mp\")*/
12843 Typing \\[verilog-auto] will make this into:
12848 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12849 // Beginning of automatic in/out/inouts (from modport)
12852 // End of automatics
12855 If the modport is part of a UVM monitor/driver class, this
12856 creates a wrapper module that may be used to instantiate the
12857 driver/monitor using AUTOINST in the testbench."
12859 (let* ((params (verilog-read-auto-params 2 3))
12860 (submod (nth 0 params))
12861 (modport-re (nth 1 params))
12862 (regexp (nth 2 params))
12863 direction-re submodi) ; direction argument not supported until requested
12864 ;; Lookup position, etc of co-module
12865 ;; Note this may raise an error
12866 (when (setq submodi (verilog-modi-lookup submod t))
12867 (let* ((indent-pt (current-indentation))
12868 (v2k (verilog-in-paren-quick))
12869 (modi (verilog-modi-current))
12870 (moddecls (verilog-modi-get-decls modi))
12871 (submoddecls (verilog-modi-get-decls submodi))
12872 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
12873 (sig-list-i (verilog-signals-in ; Decls doesn't have data types, must resolve
12874 (verilog-decls-get-vars submoddecls)
12875 (verilog-signals-not-in
12876 (verilog-decls-get-inputs submodportdecls)
12877 (append (verilog-decls-get-ports submoddecls)
12878 (verilog-decls-get-ports moddecls)))))
12879 (sig-list-o (verilog-signals-in ; Decls doesn't have data types, must resolve
12880 (verilog-decls-get-vars submoddecls)
12881 (verilog-signals-not-in
12882 (verilog-decls-get-outputs submodportdecls)
12883 (append (verilog-decls-get-ports submoddecls)
12884 (verilog-decls-get-ports moddecls)))))
12885 (sig-list-io (verilog-signals-in ; Decls doesn't have data types, must resolve
12886 (verilog-decls-get-vars submoddecls)
12887 (verilog-signals-not-in
12888 (verilog-decls-get-inouts submodportdecls)
12889 (append (verilog-decls-get-ports submoddecls)
12890 (verilog-decls-get-ports moddecls))))))
12892 (setq sig-list-i (verilog-signals-edit-wire-reg
12893 (verilog-signals-matching-dir-re
12894 (verilog-signals-matching-regexp sig-list-i regexp)
12895 "input" direction-re))
12896 sig-list-o (verilog-signals-edit-wire-reg
12897 (verilog-signals-matching-dir-re
12898 (verilog-signals-matching-regexp sig-list-o regexp)
12899 "output" direction-re))
12900 sig-list-io (verilog-signals-edit-wire-reg
12901 (verilog-signals-matching-dir-re
12902 (verilog-signals-matching-regexp sig-list-io regexp)
12903 "inout" direction-re)))
12904 (when v2k (verilog-repair-open-comma))
12905 (when (or sig-list-i sig-list-o sig-list-io)
12906 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from modport)\n")
12907 ;; Don't sort them so an upper AUTOINST will match the main module
12908 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12909 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12910 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12911 (verilog-insert-indent "// End of automatics\n"))
12912 (when v2k (verilog-repair-close-comma)))))))
12914 (defun verilog-auto-insert-lisp ()
12915 "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
12916 The Lisp code provided is called before other AUTOS are expanded,
12917 and the Lisp code generally will call `insert' to insert text
12918 into the current file beginning on the line after the
12921 See also AUTOINSERTLAST and `verilog-auto-insert-last' which
12922 executes after (as opposed to before) other AUTOs.
12924 See also AUTO_LISP, which takes a Lisp expression and evaluates
12925 it during `verilog-auto-inst' but does not insert any text.
12929 module ExampInsertLisp;
12930 /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
12933 // For this example we declare the function in the
12934 // module's file itself. Often you'd define it instead
12935 // in a site-start.el or init file.
12939 (defun my-verilog-insert-hello (who)
12940 (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
12944 Typing \\[verilog-auto] will call my-verilog-insert-hello and
12945 expand the above into:
12947 // Beginning of automatic insert lisp
12948 initial $write(\"hello world\");
12949 // End of automatics
12951 You can also call an external program and insert the returned
12954 /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
12955 // Beginning of automatic insert lisp
12957 // End of automatics"
12959 ;; Point is at end of /*AUTO...*/
12960 (let* ((indent-pt (current-indentation))
12961 (cmd-end-pt (save-excursion (search-backward ")")
12963 (point))) ; Closing paren
12964 (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
12965 (backward-sexp 1) ; Inside comment
12966 (point))) ; Beginning paren
12967 (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
12968 (verilog-forward-or-insert-line)
12969 ;; Some commands don't move point (like insert-file) so we always
12970 ;; add the begin/end comments, then delete it if not needed
12971 (verilog-insert-indent "// Beginning of automatic insert lisp\n")
12972 (verilog-insert-indent "// End of automatics\n")
12976 (setq verilog-scan-cache-tick nil) ; Clear cache; inserted unknown text
12977 (verilog-delete-empty-auto-pair))))
12979 (defun verilog-auto-insert-last ()
12980 "Expand AUTOINSERTLAST statements, as part of \\[verilog-auto].
12981 The Lisp code provided is called after all other AUTOS have been
12982 expanded, and the Lisp code generally will call `insert' to
12983 insert text into the current file beginning on the line after the
12986 Other than when called (after AUTOs are expanded), the functionality
12987 is otherwise identical to AUTOINSERTLISP and `verilog-auto-insert-lisp' which
12988 executes before (as opposed to after) other AUTOs.
12990 See `verilog-auto-insert-lisp' for examples."
12991 (verilog-auto-insert-lisp))
12993 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
12994 "Return list of signals for current AUTOSENSE block."
12995 (let* ((sigss (save-excursion
12996 (search-forward ")")
12997 (verilog-read-always-signals)))
12998 (sig-list (verilog-signals-not-params
12999 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
13000 (append (and (not verilog-auto-sense-include-inputs)
13001 (verilog-alw-get-outputs-delayed sigss))
13002 (and (not verilog-auto-sense-include-inputs)
13003 (verilog-alw-get-outputs-immediate sigss))
13004 (verilog-alw-get-temps sigss)
13005 (verilog-decls-get-consts moddecls)
13006 (verilog-decls-get-gparams moddecls)
13010 (defun verilog-auto-sense ()
13011 "Expand AUTOSENSE statements, as part of \\[verilog-auto].
13012 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
13013 with one automatically derived from all inputs declared in the always
13014 statement. Signals that are generated within the same always block are NOT
13015 placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
13016 Long lines are split based on the `fill-column', see \\[set-fill-column].
13019 Verilog does not allow memories (multidimensional arrays) in sensitivity
13020 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
13023 AUTOSENSE cannot always determine if a \\=`define is a constant or a signal
13024 (it could be in an include file for example). If a \\=`define or other signal
13025 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
13026 declaration anywhere in the module (parenthesis are required):
13028 /* AUTO_CONSTANT ( \\=`this_is_really_constant_dont_autosense_it ) */
13030 Better yet, use a parameter, which will be understood to be constant
13034 If AUTOSENSE makes a mistake, please report it. (First try putting
13035 a begin/end after your always!) As a workaround, if a signal that
13036 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
13037 If a signal should be in the sensitivity list wasn't, placing it before
13038 the /*AUTOSENSE*/ comment will prevent it from being deleted when the
13039 autos are updated (or added if it occurs there already).
13043 always @ (/*AS*/) begin
13044 /* AUTO_CONSTANT (\\=`constant) */
13045 outin = ina | inb | \\=`constant;
13049 Typing \\[verilog-auto] will make this into:
13051 always @ (/*AS*/ina or inb) begin
13052 /* AUTO_CONSTANT (\\=`constant) */
13053 outin = ina | inb | \\=`constant;
13057 Note in Verilog 2001, you can often get the same result from the new @*
13058 operator. (This was added to the language in part due to AUTOSENSE!)
13061 outin = ina | inb | \\=`constant;
13066 (let* ((start-pt (save-excursion
13067 (verilog-re-search-backward-quick "(" nil t)
13069 (indent-pt (save-excursion
13070 (or (and (goto-char start-pt) (1+ (current-column)))
13071 (current-indentation))))
13072 (modi (verilog-modi-current))
13073 (moddecls (verilog-modi-get-decls modi))
13074 (sig-memories (verilog-signals-memory
13075 (verilog-decls-get-vars moddecls)))
13076 sig-list not-first presense-sigs)
13077 ;; Read signals in always, eliminate outputs from sense list
13078 (setq presense-sigs (verilog-signals-from-signame
13080 (verilog-read-signals start-pt (point)))))
13081 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
13083 (let ((tlen (length sig-list)))
13084 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
13085 (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
13086 (if (and presense-sigs ; Add a "or" if not "(.... or /*AUTOSENSE*/"
13087 (save-excursion (goto-char (point))
13088 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
13089 (verilog-re-search-backward-quick "\\s-" start-pt t)
13090 (while (looking-at "\\s-`endif")
13091 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
13092 (verilog-re-search-backward-quick "\\s-" start-pt t))
13093 (not (looking-at "\\s-or\\b"))))
13094 (setq not-first t))
13095 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
13097 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
13099 (indent-to indent-pt)
13100 (if not-first (insert "or ")))
13101 (not-first (insert " or ")))
13102 (insert (verilog-sig-name (car sig-list)))
13103 (setq sig-list (cdr sig-list)
13106 (defun verilog-auto-reset ()
13107 "Expand AUTORESET statements, as part of \\[verilog-auto].
13108 Replace the /*AUTORESET*/ comment with code to initialize all
13109 registers set elsewhere in the always block.
13112 AUTORESET will not clear memories.
13114 AUTORESET uses <= if the signal has a <= assignment in the block,
13117 If <= is used, all = assigned variables are ignored if
13118 `verilog-auto-reset-blocking-in-non' is nil; they are presumed
13121 /*AUTORESET*/ presumes that any signals mentioned between the previous
13122 begin/case/if statement and the AUTORESET comment are being reset manually
13123 and should not be automatically reset. This includes omitting any signals
13124 used on the right hand side of assignments.
13126 By default, AUTORESET will include the width of the signal in the
13127 autos, SystemVerilog designs may want to change this. To control
13128 this behavior, see `verilog-auto-reset-widths'. In some cases
13129 AUTORESET must use a \\='0 assignment and it will print NOWIDTH; use
13130 `verilog-auto-reset-widths' unbased to prevent this.
13132 AUTORESET ties signals to deasserted, which is presumed to be zero.
13133 Signals that match `verilog-active-low-regexp' will be deasserted by tying
13136 AUTORESET may try to reset arrays or structures that cannot be
13137 reset by a simple assignment, resulting in compile errors. This
13138 is a feature to be taken as a hint that you need to reset these
13139 signals manually (or put them into a \"\\=`ifdef NEVER signal<=\\=`0;
13140 \\=`endif\" so Verilog-Mode ignores them.)
13144 always @(posedge clk or negedge reset_l) begin
13145 if (!reset_l) begin
13156 Typing \\[verilog-auto] will make this into:
13158 always @(posedge core_clk or negedge reset_l) begin
13159 if (!reset_l) begin
13162 // Beginning of autoreset for uninitialized flops
13164 b = 0; // if `verilog-auto-reset-blocking-in-non' true
13165 // End of automatics
13177 (let* ((indent-pt (current-indentation))
13178 (modi (verilog-modi-current))
13179 (moddecls (verilog-modi-get-decls modi))
13180 (all-list (verilog-decls-get-signals moddecls))
13181 sigss sig-list dly-list prereset-sigs)
13182 ;; Read signals in always, eliminate outputs from reset list
13183 (setq prereset-sigs (verilog-signals-from-signame
13185 (verilog-read-signals
13187 (verilog-re-search-backward-quick
13188 "\\(@\\|\\<\\(begin\\|if\\|case[xz]?\\|always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
13192 (verilog-re-search-backward-quick "\\(@\\|\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
13193 (setq sigss (verilog-read-always-signals)))
13194 (setq dly-list (verilog-alw-get-outputs-delayed sigss))
13195 (setq sig-list (verilog-signals-not-in-struct
13197 (verilog-alw-get-outputs-delayed sigss)
13198 (when (or (not (verilog-alw-get-uses-delayed sigss))
13199 verilog-auto-reset-blocking-in-non)
13200 (verilog-alw-get-outputs-immediate sigss)))
13202 (verilog-alw-get-temps sigss)
13204 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
13207 (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
13209 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ; As sig-list has no widths
13211 (indent-to indent-pt)
13212 (insert (verilog-sig-name sig)
13213 (if (assoc (verilog-sig-name sig) dly-list)
13214 (concat " <= " verilog-assignment-delay)
13216 (verilog-sig-tieoff sig)
13218 (setq sig-list (cdr sig-list))))
13219 (verilog-insert-indent "// End of automatics")))))
13221 (defun verilog-auto-tieoff ()
13222 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
13223 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
13224 signals to deasserted.
13226 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
13227 input/output list as another module, but no internals. Specifically, it
13228 finds all outputs in the module, and if that input is not otherwise declared
13229 as a register or wire, creates a tieoff.
13231 AUTORESET ties signals to deasserted, which is presumed to be zero.
13232 Signals that match `verilog-active-low-regexp' will be deasserted by tying
13235 You can add signals you do not want included in AUTOTIEOFF with
13236 `verilog-auto-tieoff-ignore-regexp'.
13238 `verilog-auto-wire-type' may be used to change the datatype of
13241 `verilog-auto-reset-widths' may be used to change how the tieoff
13242 value's width is generated.
13244 An example of making a stub for another module:
13246 module ExampStub (/*AUTOINST*/);
13247 /*AUTOINOUTPARAM(\"Foo\")*/
13248 /*AUTOINOUTMODULE(\"Foo\")*/
13250 // verilator lint_off UNUSED
13251 wire _unused_ok = &{1\\='b0,
13254 // verilator lint_on UNUSED
13257 Typing \\[verilog-auto] will make this into:
13259 module ExampStub (/*AUTOINST*/...);
13260 /*AUTOINOUTPARAM(\"Foo\")*/
13261 /*AUTOINOUTMODULE(\"Foo\")*/
13262 // Beginning of autotieoff
13264 // End of automatics
13267 // Beginning of autotieoff
13268 wire [2:0] foo = 3\\='b0;
13269 // End of automatics
13275 (let* ((indent-pt (current-indentation))
13276 (modi (verilog-modi-current))
13277 (moddecls (verilog-modi-get-decls modi))
13278 (modsubdecls (verilog-modi-get-sub-decls modi))
13279 (sig-list (verilog-signals-not-in
13280 (verilog-decls-get-outputs moddecls)
13281 (append (verilog-decls-get-vars moddecls)
13282 (verilog-decls-get-assigns moddecls)
13283 (verilog-decls-get-consts moddecls)
13284 (verilog-decls-get-gparams moddecls)
13285 (verilog-subdecls-get-interfaced modsubdecls)
13286 (verilog-subdecls-get-outputs modsubdecls)
13287 (verilog-subdecls-get-inouts modsubdecls)))))
13288 (setq sig-list (verilog-signals-not-matching-regexp
13289 sig-list verilog-auto-tieoff-ignore-regexp))
13291 (verilog-forward-or-insert-line)
13292 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
13293 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
13294 (verilog-modi-cache-add-vars modi sig-list) ; Before we trash list
13296 (let ((sig (car sig-list)))
13297 (cond ((equal verilog-auto-tieoff-declaration "assign")
13298 (indent-to indent-pt)
13299 (insert "assign " (verilog-sig-name sig)))
13301 (verilog-insert-one-definition sig verilog-auto-tieoff-declaration indent-pt)))
13302 (indent-to (max 48 (+ indent-pt 40)))
13303 (insert "= " (verilog-sig-tieoff sig)
13305 (setq sig-list (cdr sig-list))))
13306 (verilog-insert-indent "// End of automatics\n")))))
13308 (defun verilog-auto-undef ()
13309 "Expand AUTOUNDEF statements, as part of \\[verilog-auto].
13310 Take any \\=`defines since the last AUTOUNDEF in the current file
13311 and create \\=`undefs for them. This is used to insure that
13312 file-local defines do not pollute the global \\=`define name space.
13315 AUTOUNDEF presumes any identifier following \\=`define is the
13316 name of a define. Any \\=`ifdefs are ignored.
13318 AUTOUNDEF suppresses creating an \\=`undef for any define that was
13319 \\=`undefed before the AUTOUNDEF. This may be used to work around
13320 the ignoring of \\=`ifdefs as shown below.
13325 \\=`define M_BAR(x)
13329 \\=`undef M_BAZ // Emacs will see this and not \\=`undef M_BAZ
13334 Typing \\[verilog-auto] will make this into:
13338 // Beginning of automatic undefs
13341 // End of automatics
13343 You may also provide an optional regular expression, in which case only
13344 defines the regular expression will be undefed."
13346 (let* ((params (verilog-read-auto-params 0 1))
13347 (regexp (nth 0 params))
13348 (indent-pt (current-indentation))
13352 ;; Scan from start of file, or last AUTOUNDEF
13353 (or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
13354 (goto-char (point-min)))
13355 (while (verilog-re-search-forward-quick
13356 "`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
13357 (cond ((equal (match-string-no-properties 1) "define")
13358 (setq def (match-string-no-properties 2))
13359 (when (and (or (not regexp)
13360 (string-match regexp def))
13361 (not (member def defs))) ; delete-dups not in 21.1
13362 (setq defs (cons def defs))))
13364 (setq defs (delete (match-string-no-properties 2) defs))))))
13366 (setq defs (sort defs 'string<))
13368 (verilog-forward-or-insert-line)
13369 (verilog-insert-indent "// Beginning of automatic undefs\n")
13371 (verilog-insert-indent "`undef " (car defs) "\n")
13372 (setq defs (cdr defs)))
13373 (verilog-insert-indent "// End of automatics\n")))))
13375 (defun verilog-auto-unused ()
13376 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
13377 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
13378 input and inout signals.
13380 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
13381 input/output list as another module, but no internals. Specifically, it
13382 finds all inputs and inouts in the module, and if that input is not otherwise
13383 used, adds it to a comma separated list.
13385 The comma separated list is intended to be used to create a _unused_ok
13386 signal. Using the exact name \"_unused_ok\" for name of the temporary
13387 signal is recommended as it will insure maximum forward compatibility, it
13388 also makes lint warnings easy to understand; ignore any unused warnings
13389 with \"unused\" in the signal name.
13391 To reduce simulation time, the _unused_ok signal should be forced to a
13392 constant to prevent wiggling. The easiest thing to do is use a
13393 reduction-and with 1\\='b0 as shown.
13395 This way all unused signals are in one place, making it convenient to add
13396 your tool's specific pragmas around the assignment to disable any unused
13399 You can add signals you do not want included in AUTOUNUSED with
13400 `verilog-auto-unused-ignore-regexp'.
13402 An example of making a stub for another module:
13404 module ExampStub (/*AUTOINST*/);
13405 /*AUTOINOUTPARAM(\"Examp\")*/
13406 /*AUTOINOUTMODULE(\"Examp\")*/
13408 // verilator lint_off UNUSED
13409 wire _unused_ok = &{1\\='b0,
13412 // verilator lint_on UNUSED
13415 Typing \\[verilog-auto] will make this into:
13418 // verilator lint_off UNUSED
13419 wire _unused_ok = &{1\\='b0,
13421 // Beginning of automatics
13425 // End of automatics
13427 // verilator lint_on UNUSED
13432 (let* ((indent-pt (progn (search-backward "/*") (current-column)))
13433 (modi (verilog-modi-current))
13434 (moddecls (verilog-modi-get-decls modi))
13435 (modsubdecls (verilog-modi-get-sub-decls modi))
13436 (sig-list (verilog-signals-not-in
13437 (append (verilog-decls-get-inputs moddecls)
13438 (verilog-decls-get-inouts moddecls))
13439 (append (verilog-subdecls-get-inputs modsubdecls)
13440 (verilog-subdecls-get-inouts modsubdecls)))))
13441 (setq sig-list (verilog-signals-not-matching-regexp
13442 sig-list verilog-auto-unused-ignore-regexp))
13444 (verilog-forward-or-insert-line)
13445 (verilog-insert-indent "// Beginning of automatic unused inputs\n")
13446 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
13448 (let ((sig (car sig-list)))
13449 (indent-to indent-pt)
13450 (insert (verilog-sig-name sig) ",\n")
13451 (setq sig-list (cdr sig-list))))
13452 (verilog-insert-indent "// End of automatics\n")))))
13454 (defun verilog-enum-ascii (signm elim-regexp)
13455 "Convert an enum name SIGNM to an ascii string for insertion.
13456 Remove user provided prefix ELIM-REGEXP."
13457 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
13458 (let ((case-fold-search t))
13459 ;; All upper becomes all lower for readability
13460 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
13462 (defun verilog-auto-ascii-enum ()
13463 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
13464 Create a register to contain the ASCII decode of an enumerated signal type.
13465 This will allow trace viewers to show the ASCII name of states.
13467 First, parameters are built into an enumeration using the synopsys enum
13468 comment. The comment must be between the keyword and the symbol.
13469 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
13471 Next, registers which that enum applies to are also tagged with the same
13474 Finally, an AUTOASCIIENUM command is used.
13476 The first parameter is the name of the signal to be decoded.
13478 The second parameter is the name to store the ASCII code into. For the
13479 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
13480 a signal that is just for simulation, and the magic characters _ascii
13481 tell viewers like Dinotrace to display in ASCII format.
13483 The third optional parameter is a string which will be removed
13484 from the state names. It defaults to \"\" which removes nothing.
13486 The fourth optional parameter is \"onehot\" to force one-hot
13487 decoding. If unspecified, if and only if the first parameter
13488 width is 2^(number of states in enum) and does NOT match the
13489 width of the enum, the signal is assumed to be a one-hot
13490 decode. Otherwise, it's a normal encoded state vector.
13492 `verilog-auto-wire-type' may be used to change the datatype of
13495 \"auto enum\" may be used in place of \"synopsys enum\".
13499 //== State enumeration
13500 parameter [2:0] // synopsys enum state_info
13501 SM_IDLE = 3\\='b000,
13502 SM_SEND = 3\\='b001,
13503 SM_WAIT1 = 3\\='b010;
13504 //== State variables
13505 reg [2:0] /* synopsys enum state_info */
13506 state_r; /* synopsys state_vector state_r */
13507 reg [2:0] /* synopsys enum state_info */
13510 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
13512 Typing \\[verilog-auto] will make this into:
13514 ... same front matter ...
13516 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
13517 // Beginning of automatic ASCII enum decoding
13518 reg [39:0] state_ascii_r; // Decode of state_r
13519 always @(state_r) begin
13521 SM_IDLE: state_ascii_r = \"idle \";
13522 SM_SEND: state_ascii_r = \"send \";
13523 SM_WAIT1: state_ascii_r = \"wait1\";
13524 default: state_ascii_r = \"%Erro\";
13527 // End of automatics"
13529 (let* ((params (verilog-read-auto-params 2 4))
13530 (undecode-name (nth 0 params))
13531 (ascii-name (nth 1 params))
13532 (elim-regexp (and (nth 2 params)
13533 (not (equal (nth 2 params) ""))
13535 (one-hot-flag (nth 3 params))
13537 (indent-pt (current-indentation))
13538 (modi (verilog-modi-current))
13539 (moddecls (verilog-modi-get-decls modi))
13541 (sig-list-consts (append (verilog-decls-get-consts moddecls)
13542 (verilog-decls-get-gparams moddecls)))
13543 (sig-list-all (verilog-decls-get-iovars moddecls))
13545 (undecode-sig (or (assoc undecode-name sig-list-all)
13546 (error "%s: Signal `%s' not found in design"
13547 (verilog-point-text) undecode-name)))
13548 (undecode-enum (or (verilog-sig-enum undecode-sig)
13549 (error "%s: Signal `%s' does not have an enum tag"
13550 (verilog-point-text) undecode-name)))
13552 (enum-sigs (verilog-signals-not-in
13553 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
13554 (error "%s: No state definitions for `%s'"
13555 (verilog-point-text) undecode-enum))
13559 (string-match "onehot" (or one-hot-flag ""))
13560 (and ; width(enum) != width(sig)
13561 (or (not (verilog-sig-bits (car enum-sigs)))
13562 (not (equal (verilog-sig-width (car enum-sigs))
13563 (verilog-sig-width undecode-sig))))
13564 ;; count(enums) == width(sig)
13565 (equal (number-to-string (length enum-sigs))
13566 (verilog-sig-width undecode-sig)))))
13570 ;; Find number of ascii chars needed
13571 (let ((tmp-sigs enum-sigs))
13573 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
13574 ascii-chars (max ascii-chars (length (verilog-enum-ascii
13575 (verilog-sig-name (car tmp-sigs))
13577 tmp-sigs (cdr tmp-sigs))))
13579 (verilog-forward-or-insert-line)
13580 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
13581 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
13582 (concat "Decode of " undecode-name) nil nil))))
13583 (verilog-insert-definition modi decode-sig-list "reg" indent-pt nil))
13585 (verilog-insert-indent "always @(" undecode-name ") begin\n")
13586 (setq indent-pt (+ indent-pt verilog-indent-level))
13587 (verilog-insert-indent "case ({" undecode-name "})\n")
13588 (setq indent-pt (+ indent-pt verilog-case-indent))
13590 (let ((tmp-sigs enum-sigs)
13591 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
13592 (+ (if one-hot 9 1) (max 8 enum-chars))
13593 ascii-name ascii-chars))
13594 (errname (substring "%Error" 0 (min 6 ascii-chars))))
13596 (verilog-insert-indent
13599 (concat (if one-hot "(")
13600 ;; Use enum-sigs length as that's numeric
13601 ;; verilog-sig-width undecode-sig might not be.
13602 (if one-hot (number-to-string (length enum-sigs)))
13603 ;; We use a shift instead of var[index]
13604 ;; so that a non-one hot value will show as error.
13605 (if one-hot "'b1<<")
13606 (verilog-sig-name (car tmp-sigs))
13607 (if one-hot ")") ":")
13608 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
13610 (setq tmp-sigs (cdr tmp-sigs)))
13611 (verilog-insert-indent (format chrfmt "default:" errname)))
13613 (setq indent-pt (- indent-pt verilog-case-indent))
13614 (verilog-insert-indent "endcase\n")
13615 (setq indent-pt (- indent-pt verilog-indent-level))
13616 (verilog-insert-indent "end\n"
13617 "// End of automatics\n"))))
13619 (defun verilog-auto-templated-rel ()
13620 "Replace Templated relative line numbers with absolute line numbers.
13621 Internal use only. This hacks around the line numbers in AUTOINST Templates
13622 being different from the final output's line numbering."
13623 (let ((templateno 0) (template-line (list 0)) (buf-line 1))
13624 ;; Find line number each template is on
13625 ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
13626 (goto-char (point-min))
13627 (while (not (eobp))
13628 (when (looking-at ".*AUTO_TEMPLATE")
13629 (setq templateno (1+ templateno))
13630 (setq template-line (cons buf-line template-line)))
13631 (setq buf-line (1+ buf-line))
13633 (setq template-line (nreverse template-line))
13634 ;; Replace T# L# with absolute line number
13635 (goto-char (point-min))
13636 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
13638 (concat " Templated "
13639 (int-to-string (+ (nth (string-to-number (match-string 1))
13641 (string-to-number (match-string 2)))))
13644 (defun verilog-auto-template-lint ()
13645 "Check AUTO_TEMPLATEs for unused lines.
13646 Enable with `verilog-auto-template-warn-unused'."
13647 (let ((name1 (or (buffer-file-name) (buffer-name))))
13649 (goto-char (point-min))
13650 (while (re-search-forward
13651 "^\\s-*/?\\*?\\s-*[a-zA-Z0-9`_$]+\\s-+AUTO_TEMPLATE" nil t)
13652 (let* ((tpl-info (verilog-read-auto-template-middle))
13653 (tpl-list (aref tpl-info 1))
13654 (tlines (append (nth 0 tpl-list) (nth 1 tpl-list)))
13657 (setq tpl-ass (car tlines)
13658 tlines (cdr tlines))
13660 (unless (or (not (eval-when-compile (fboundp 'make-hash-table))) ; Not supported, no warning
13661 (not verilog-auto-template-hits)
13662 (gethash (vector (nth 2 tpl-ass) (nth 3 tpl-ass))
13663 verilog-auto-template-hits))
13664 (verilog-warn-error "%s:%d: AUTO_TEMPLATE line unused: \".%s (%s)\""
13666 (+ (elt tpl-ass 3) ; Template line number
13667 (count-lines (point-min) (point)))
13668 (elt tpl-ass 0) (elt tpl-ass 1))
13672 ;;; Auto top level:
13675 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing an arg
13676 "Expand AUTO statements.
13677 Look for any /*AUTO...*/ commands in the code, as used in
13678 instantiations or argument headers. Update the list of signals
13679 following the /*AUTO...*/ command.
13681 Use \\[verilog-delete-auto] to remove the AUTOs.
13683 Use \\[verilog-diff-auto] to see differences in AUTO expansion.
13685 Use \\[verilog-inject-auto] to insert AUTOs for the first time.
13687 Use \\[verilog-faq] for a pointer to frequently asked questions.
13689 For new users, we recommend setting `verilog-case-fold' to nil
13690 and `verilog-auto-arg-sort' to t.
13692 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
13693 called before and after this function, respectively.
13696 module ModuleName (/*AUTOARG*/);
13701 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
13703 You can also update the AUTOs from the shell using:
13704 emacs --batch <filenames.v> -f verilog-batch-auto
13705 Or fix indentation with:
13706 emacs --batch <filenames.v> -f verilog-batch-indent
13707 Likewise, you can delete or inject AUTOs with:
13708 emacs --batch <filenames.v> -f verilog-batch-delete-auto
13709 emacs --batch <filenames.v> -f verilog-batch-inject-auto
13710 Or check if AUTOs have the same expansion
13711 emacs --batch <filenames.v> -f verilog-batch-diff-auto
13713 Using \\[describe-function], see also:
13714 `verilog-auto-arg' for AUTOARG module instantiations
13715 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
13716 `verilog-auto-assign-modport' for AUTOASSIGNMODPORT assignment to/from modport
13717 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
13718 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
13719 `verilog-auto-inout-in' for AUTOINOUTIN inputs for all i/o
13720 `verilog-auto-inout-modport' for AUTOINOUTMODPORT i/o from an interface modport
13721 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
13722 `verilog-auto-inout-param' for AUTOINOUTPARAM copying params from elsewhere
13723 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
13724 `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
13725 `verilog-auto-insert-last' for AUTOINSERTLAST insert code from lisp function
13726 `verilog-auto-inst' for AUTOINST instantiation pins
13727 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
13728 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
13729 `verilog-auto-logic' for AUTOLOGIC declaring logic signals
13730 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
13731 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
13732 `verilog-auto-reg' for AUTOREG registers
13733 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
13734 `verilog-auto-reset' for AUTORESET flop resets
13735 `verilog-auto-sense' for AUTOSENSE or AS always sensitivity lists
13736 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
13737 `verilog-auto-undef' for AUTOUNDEF \\=`undef of local \\=`defines
13738 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
13739 `verilog-auto-wire' for AUTOWIRE instantiation wires
13741 `verilog-read-defines' for reading \\=`define values
13742 `verilog-read-includes' for reading \\=`includes
13744 If you have bugs with these autos, please file an issue at
13745 URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
13746 Wilson Snyder (wsnyder@wsnyder.org)."
13748 (unless noninteractive (message "Updating AUTOs..."))
13749 (if (fboundp 'dinotrace-unannotate-all)
13750 (dinotrace-unannotate-all))
13751 ;; Disable change hooks for speed
13752 ;; This let can't be part of above let; must restore
13753 ;; after-change-functions before font-lock resumes
13754 (verilog-save-font-no-change-functions
13755 (let ((oldbuf (if (not (buffer-modified-p))
13757 (case-fold-search verilog-case-fold)
13758 ;; Cache directories; we don't write new files, so can't change
13759 (verilog-dir-cache-preserving t)
13760 ;; Cache current module
13761 (verilog-modi-cache-current-enable t)
13762 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
13763 verilog-modi-cache-current)
13764 (verilog-save-scan-cache
13766 ;; Wipe cache; otherwise if we AUTOed a block above this one,
13767 ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
13768 (setq verilog-modi-cache-list nil)
13770 (verilog-read-auto-template-init)
13771 ;; If we're not in verilog-mode, change syntax table so parsing works right
13772 (unless (eq major-mode `verilog-mode) (verilog-mode))
13773 ;; Allow user to customize
13774 (verilog-run-hooks 'verilog-before-auto-hook)
13775 ;; Try to save the user from needing to revert-file to reread file local-variables
13776 (verilog-auto-reeval-locals)
13777 (verilog-read-auto-lisp-present)
13778 (verilog-read-auto-lisp (point-min) (point-max))
13779 (verilog-getopt-flags)
13780 ;; From here on out, we can cache anything we read from disk
13781 (verilog-preserve-dir-cache
13782 ;; These two may seem obvious to do always, but on large includes it can be way too slow
13783 (when verilog-auto-read-includes
13784 (verilog-read-includes)
13785 (verilog-read-defines nil nil t))
13786 ;; Setup variables due to SystemVerilog expansion
13787 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic-setup)
13788 ;; This particular ordering is important
13789 ;; INST: Lower modules correct, no internal dependencies, FIRST
13790 (verilog-preserve-modi-cache
13791 ;; Clear existing autos else we'll be screwed by existing ones
13792 (verilog-delete-auto-buffer)
13793 ;; Injection if appropriate
13795 (verilog-inject-inst)
13796 (verilog-inject-sense)
13797 (verilog-inject-arg))
13799 ;; Do user inserts first, so their code can insert AUTOs
13800 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
13801 'verilog-auto-insert-lisp)
13802 ;; Expand instances before need the signals the instances input/output
13803 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
13804 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
13805 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
13806 ;; Must be done before autoin/out as creates a reg
13807 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM(.*?)\\*/" 'verilog-auto-ascii-enum)
13809 ;; first in/outs from other files
13810 (verilog-auto-re-search-do "/\\*AUTOINOUTMODPORT(.*?)\\*/" 'verilog-auto-inout-modport)
13811 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE(.*?)\\*/" 'verilog-auto-inout-module)
13812 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP(.*?)\\*/" 'verilog-auto-inout-comp)
13813 (verilog-auto-re-search-do "/\\*AUTOINOUTIN(.*?)\\*/" 'verilog-auto-inout-in)
13814 (verilog-auto-re-search-do "/\\*AUTOINOUTPARAM(.*?)\\*/" 'verilog-auto-inout-param)
13815 ;; next in/outs which need previous sucked inputs first
13816 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((.*?)\\)?\\*/" 'verilog-auto-output)
13817 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((.*?)\\)?\\*/" 'verilog-auto-input)
13818 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((.*?)\\)?\\*/" 'verilog-auto-inout)
13819 ;; Then tie off those in/outs
13820 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
13821 ;; These can be anywhere after AUTOINSERTLISP
13822 (verilog-auto-re-search-do "/\\*AUTOUNDEF\\((.*?)\\)?\\*/" 'verilog-auto-undef)
13823 ;; Wires/regs must be after inputs/outputs
13824 (verilog-auto-re-search-do "/\\*AUTOASSIGNMODPORT(.*?)\\*/" 'verilog-auto-assign-modport)
13825 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
13826 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
13827 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
13828 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
13829 ;; outputevery needs AUTOOUTPUTs done first
13830 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\((.*?)\\)?\\*/" 'verilog-auto-output-every)
13831 ;; Doesn't matter when done, but combine it with a common changer
13832 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
13833 ;; After AUTOREG*, as they may have set signal widths
13834 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
13835 ;; After we've created all new variables
13836 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
13837 ;; Must be after all inputs outputs are generated
13838 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
13840 (verilog-auto-re-search-do "/\\*AUTOINSERTLAST(.*?)\\*/" 'verilog-auto-insert-last)
13841 ;; Fix line numbers (comments only)
13842 (when verilog-auto-inst-template-numbers
13843 (verilog-auto-templated-rel))
13844 (when verilog-auto-template-warn-unused
13845 (verilog-auto-template-lint))))
13847 (verilog-run-hooks 'verilog-auto-hook)
13849 (when verilog-auto-delete-trailing-whitespace
13850 (verilog-delete-trailing-whitespace))
13852 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
13854 ;; If end result is same as when started, clear modified flag
13855 (cond ((and oldbuf (equal oldbuf (buffer-string)))
13856 (verilog-restore-buffer-modified-p nil)
13857 (unless noninteractive (message "Updating AUTOs...done (no changes)")))
13858 (t (unless noninteractive (message "Updating AUTOs...done"))))
13859 ;; End of save-cache
13865 (defvar verilog-template-map
13866 (let ((map (make-sparse-keymap)))
13867 (define-key map "a" 'verilog-sk-always)
13868 (define-key map "b" 'verilog-sk-begin)
13869 (define-key map "c" 'verilog-sk-case)
13870 (define-key map "f" 'verilog-sk-for)
13871 (define-key map "g" 'verilog-sk-generate)
13872 (define-key map "h" 'verilog-sk-header)
13873 (define-key map "i" 'verilog-sk-initial)
13874 (define-key map "j" 'verilog-sk-fork)
13875 (define-key map "m" 'verilog-sk-module)
13876 (define-key map "o" 'verilog-sk-ovm-class)
13877 (define-key map "p" 'verilog-sk-primitive)
13878 (define-key map "r" 'verilog-sk-repeat)
13879 (define-key map "s" 'verilog-sk-specify)
13880 (define-key map "t" 'verilog-sk-task)
13881 (define-key map "u" 'verilog-sk-uvm-object)
13882 (define-key map "w" 'verilog-sk-while)
13883 (define-key map "x" 'verilog-sk-casex)
13884 (define-key map "z" 'verilog-sk-casez)
13885 (define-key map "?" 'verilog-sk-if)
13886 (define-key map ":" 'verilog-sk-else-if)
13887 (define-key map "/" 'verilog-sk-comment)
13888 (define-key map "A" 'verilog-sk-assign)
13889 (define-key map "F" 'verilog-sk-function)
13890 (define-key map "I" 'verilog-sk-input)
13891 (define-key map "O" 'verilog-sk-output)
13892 (define-key map "S" 'verilog-sk-state-machine)
13893 (define-key map "=" 'verilog-sk-inout)
13894 (define-key map "U" 'verilog-sk-uvm-component)
13895 (define-key map "W" 'verilog-sk-wire)
13896 (define-key map "R" 'verilog-sk-reg)
13897 (define-key map "D" 'verilog-sk-define-signal)
13899 "Keymap used in Verilog mode for smart template operations.")
13903 ;; Place the templates into Verilog Mode. They may be inserted under any key.
13904 ;; C-c C-t will be the default. If you use templates a lot, you
13905 ;; may want to consider moving the binding to another key in your init
13908 ;; Note \C-c and letter are reserved for users
13909 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
13911 ;; ---- statement skeletons ------------------------------------------
13913 (define-skeleton verilog-sk-prompt-condition
13914 "Prompt for the loop condition."
13915 "[condition]: " str )
13917 (define-skeleton verilog-sk-prompt-init
13918 "Prompt for the loop init statement."
13919 "[initial statement]: " str )
13921 (define-skeleton verilog-sk-prompt-inc
13922 "Prompt for the loop increment statement."
13923 "[increment statement]: " str )
13925 (define-skeleton verilog-sk-prompt-name
13926 "Prompt for the name of something."
13929 (define-skeleton verilog-sk-prompt-clock
13930 "Prompt for the name of something."
13931 "name and edge of clock(s): " str)
13933 (defvar verilog-sk-reset nil)
13934 (defun verilog-sk-prompt-reset ()
13935 "Prompt for the name of a state machine reset."
13936 (setq verilog-sk-reset (read-string "name of reset: " "rst")))
13939 (define-skeleton verilog-sk-prompt-state-selector
13940 "Prompt for the name of a state machine selector."
13941 "name of selector (eg {a,b,c,d}): " str )
13943 (define-skeleton verilog-sk-prompt-output
13944 "Prompt for the name of something."
13947 (define-skeleton verilog-sk-prompt-msb
13948 "Prompt for most significant bit specification."
13949 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
13951 (define-skeleton verilog-sk-prompt-lsb
13952 "Prompt for least significant bit specification."
13955 (defvar verilog-sk-p nil)
13956 (define-skeleton verilog-sk-prompt-width
13957 "Prompt for a width specification."
13960 (setq verilog-sk-p (point))
13961 (verilog-sk-prompt-msb)
13962 (if (> (point) verilog-sk-p) "] " " ")))
13964 (defun verilog-sk-header ()
13965 "Insert a descriptive header at the top of the file.
13966 See also `verilog-header' for an alternative format."
13969 (goto-char (point-min))
13970 (verilog-sk-header-tmpl)))
13972 (define-skeleton verilog-sk-header-tmpl
13973 "Insert a comment block containing the module title, author, etc."
13975 "// -*- Mode: Verilog -*-"
13976 "\n// Filename : " (buffer-name)
13977 "\n// Description : " str
13978 "\n// Author : " (user-full-name)
13979 "\n// Created On : " (current-time-string)
13980 "\n// Last Modified By: " (user-full-name)
13981 "\n// Last Modified On: " (current-time-string)
13982 "\n// Update Count : 0"
13983 "\n// Status : Unknown, Use with caution!"
13986 (define-skeleton verilog-sk-module
13987 "Insert a module definition."
13989 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
13991 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
13993 ;; ------------------------------------------------------------------------
13994 ;; Define a default OVM class, with macros and new()
13995 ;; ------------------------------------------------------------------------
13997 (define-skeleton verilog-sk-ovm-class
13998 "Insert a class definition"
14000 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
14002 > "`ovm_object_utils_begin(" name ")" \n
14003 > (- verilog-indent-level) " `ovm_object_utils_end" \n
14005 > "function new(string name=\"" name "\");" \n
14006 > "super.new(name);" \n
14007 > (- verilog-indent-level) "endfunction" \n
14009 > "endclass" (progn (electric-verilog-terminate-line) nil))
14011 (define-skeleton verilog-sk-uvm-object
14012 "Insert a class definition"
14014 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
14016 > "`uvm_object_utils_begin(" name ")" \n
14017 > (- verilog-indent-level) "`uvm_object_utils_end" \n
14019 > "function new(string name=\"" name "\");" \n
14020 > "super.new(name);" \n
14021 > (- verilog-indent-level) "endfunction" \n
14023 > "endclass" (progn (electric-verilog-terminate-line) nil))
14025 (define-skeleton verilog-sk-uvm-component
14026 "Insert a class definition"
14028 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
14030 > "`uvm_component_utils_begin(" name ")" \n
14031 > (- verilog-indent-level) "`uvm_component_utils_end" \n
14033 > "function new(string name=\"\", uvm_component parent);" \n
14034 > "super.new(name, parent);" \n
14035 > (- verilog-indent-level) "endfunction" \n
14037 > "endclass" (progn (electric-verilog-terminate-line) nil))
14039 (define-skeleton verilog-sk-primitive
14040 "Insert a task definition."
14042 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
14044 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
14046 (define-skeleton verilog-sk-task
14047 "Insert a task definition."
14049 > "task " '(verilog-sk-prompt-name) & ?\; \n
14053 > (- verilog-indent-level-behavioral) "end" \n
14054 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
14056 (define-skeleton verilog-sk-function
14057 "Insert a function definition."
14059 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?\; \n
14063 > (- verilog-indent-level-behavioral) "end" \n
14064 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
14066 (define-skeleton verilog-sk-always
14067 "Insert always block. Uses the minibuffer to prompt
14068 for sensitivity list."
14070 > "always @ ( /*AUTOSENSE*/ ) begin\n"
14072 > (- verilog-indent-level-behavioral) "end" \n >
14075 (define-skeleton verilog-sk-initial
14076 "Insert an initial block."
14078 > "initial begin\n"
14080 > (- verilog-indent-level-behavioral) "end" \n > )
14082 (define-skeleton verilog-sk-specify
14083 "Insert specify block. "
14087 > (- verilog-indent-level-behavioral) "endspecify" \n > )
14089 (define-skeleton verilog-sk-generate
14090 "Insert generate block. "
14094 > (- verilog-indent-level-behavioral) "endgenerate" \n > )
14096 (define-skeleton verilog-sk-begin
14097 "Insert begin end block. Uses the minibuffer to prompt for name."
14099 > "begin" '(verilog-sk-prompt-name) \n
14101 > (- verilog-indent-level-behavioral) "end" )
14103 (define-skeleton verilog-sk-fork
14104 "Insert a fork join block."
14109 > (- verilog-indent-level-behavioral) "end" \n
14112 > (- verilog-indent-level-behavioral) "end" \n
14113 > (- verilog-indent-level-behavioral) "join" \n
14117 (define-skeleton verilog-sk-case
14118 "Build skeleton case statement, prompting for the selector expression,
14119 and the case items."
14120 "[selector expression]: "
14121 > "case (" str ") " \n
14122 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
14123 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
14125 (define-skeleton verilog-sk-casex
14126 "Build skeleton casex statement, prompting for the selector expression,
14127 and the case items."
14128 "[selector expression]: "
14129 > "casex (" str ") " \n
14130 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
14131 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
14133 (define-skeleton verilog-sk-casez
14134 "Build skeleton casez statement, prompting for the selector expression,
14135 and the case items."
14136 "[selector expression]: "
14137 > "casez (" str ") " \n
14138 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
14139 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
14141 (define-skeleton verilog-sk-if
14142 "Insert a skeleton if statement."
14143 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
14145 > (- verilog-indent-level-behavioral) "end " \n )
14147 (define-skeleton verilog-sk-else-if
14148 "Insert a skeleton else if statement."
14149 > (verilog-indent-line) "else if ("
14150 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
14152 > "end" (progn (electric-verilog-terminate-line) nil))
14154 (define-skeleton verilog-sk-datadef
14155 "Common routine to get data definition."
14157 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
14159 (define-skeleton verilog-sk-input
14160 "Insert an input definition."
14162 > "input [" '(verilog-sk-datadef))
14164 (define-skeleton verilog-sk-output
14165 "Insert an output definition."
14167 > "output [" '(verilog-sk-datadef))
14169 (define-skeleton verilog-sk-inout
14170 "Insert an inout definition."
14172 > "inout [" '(verilog-sk-datadef))
14174 (defvar verilog-sk-signal nil)
14175 (define-skeleton verilog-sk-def-reg
14176 "Insert a reg definition."
14178 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations-auto) )
14180 (defun verilog-sk-define-signal ()
14181 "Insert a definition of signal under point at top of module."
14183 (let* ((sig-re "[a-zA-Z0-9_]*")
14184 (v1 (buffer-substring
14186 (skip-chars-backward sig-re)
14189 (skip-chars-forward sig-re)
14191 (if (not (member v1 verilog-keywords))
14193 (setq verilog-sk-signal v1)
14194 (verilog-beg-of-defun)
14195 (verilog-end-of-statement)
14196 (verilog-forward-syntactic-ws)
14197 (verilog-sk-def-reg)
14198 (message "signal at point is %s" v1))
14199 (message "object at point (%s) is a keyword" v1))))
14201 (define-skeleton verilog-sk-wire
14202 "Insert a wire definition."
14204 > "wire [" '(verilog-sk-datadef))
14206 (define-skeleton verilog-sk-reg
14207 "Insert a reg definition."
14209 > "reg [" '(verilog-sk-datadef))
14211 (define-skeleton verilog-sk-assign
14212 "Insert a skeleton assign statement."
14214 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
14216 (define-skeleton verilog-sk-while
14217 "Insert a skeleton while loop statement."
14219 > "while (" '(verilog-sk-prompt-condition) ") begin" \n
14221 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
14223 (define-skeleton verilog-sk-repeat
14224 "Insert a skeleton repeat loop statement."
14226 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
14228 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
14230 (define-skeleton verilog-sk-for
14231 "Insert a skeleton while loop statement."
14234 '(verilog-sk-prompt-init) "; "
14235 '(verilog-sk-prompt-condition) "; "
14236 '(verilog-sk-prompt-inc)
14239 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
14241 (define-skeleton verilog-sk-comment
14242 "Inserts three comment lines, making a display comment."
14248 (define-skeleton verilog-sk-state-machine
14249 "Insert a state machine definition."
14250 "Name of state variable: "
14251 '(setq input "state")
14252 > "// State registers for " str | -23 \n
14253 '(setq verilog-sk-state str)
14254 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?\; \n
14257 > "// State FF for " verilog-sk-state \n
14258 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
14259 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
14260 > verilog-sk-state " = next_" verilog-sk-state ?\; \n
14261 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
14263 > "// Next State Logic for " verilog-sk-state \n
14264 > "always @ ( /*AUTOSENSE*/ ) begin\n"
14265 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
14266 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
14267 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
14268 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
14272 ;; Include file loading with mouse/return event
14274 ;; idea & first impl.: M. Rouat (eldo-mode.el)
14275 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
14277 (if (featurep 'xemacs)
14278 (require 'overlay))
14280 (defconst verilog-include-file-regexp
14281 "^`include\\s-+\"\\([^\n\"]*\\)\""
14282 "Regexp that matches the include file.")
14284 (defvar verilog-mode-mouse-map
14285 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
14286 (set-keymap-parent map verilog-mode-map)
14287 ;; mouse button bindings
14288 (define-key map "\r" 'verilog-load-file-at-point)
14289 (if (featurep 'xemacs)
14290 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
14291 (define-key map [mouse-2] 'verilog-load-file-at-mouse))
14292 (if (featurep 'xemacs)
14293 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
14294 (define-key map [S-mouse-2] 'mouse-yank-at-click))
14296 "Map containing mouse bindings for `verilog-mode'.")
14299 (defun verilog-highlight-region (beg end _old-len)
14300 "Colorize included files and modules in the (changed?) region.
14301 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
14302 (when (or verilog-highlight-includes
14303 verilog-highlight-modules)
14305 (save-match-data ; A query-replace may call this function - do not disturb
14306 (verilog-save-buffer-state
14307 (verilog-save-scan-cache
14310 (setq end-point (point-at-eol))
14312 (beginning-of-line) ; scan entire line
14313 ;; delete overlays existing on this line
14314 (let ((overlays (overlays-in (point) end-point)))
14317 (overlay-get (car overlays) 'detachable)
14318 (or (overlay-get (car overlays) 'verilog-include-file)
14319 (overlay-get (car overlays) 'verilog-inst-module)))
14320 (delete-overlay (car overlays)))
14321 (setq overlays (cdr overlays))))
14323 ;; make new include overlays
14324 (when verilog-highlight-includes
14325 (while (search-forward-regexp verilog-include-file-regexp end-point t)
14326 (goto-char (match-beginning 1))
14327 (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
14328 (overlay-put ov 'start-closed 't)
14329 (overlay-put ov 'end-closed 't)
14330 (overlay-put ov 'evaporate 't)
14331 (overlay-put ov 'verilog-include-file 't)
14332 (overlay-put ov 'mouse-face 'highlight)
14333 (overlay-put ov 'local-map verilog-mode-mouse-map))))
14335 ;; make new module overlays
14337 ;; This scanner is syntax-fragile, so don't get bent
14338 (when verilog-highlight-modules
14339 (condition-case nil
14340 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
14342 (goto-char (match-beginning 0))
14343 (unless (verilog-inside-comment-or-string-p)
14344 (verilog-read-inst-module-matcher) ; sets match 0
14345 (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
14346 (overlay-put ov 'start-closed 't)
14347 (overlay-put ov 'end-closed 't)
14348 (overlay-put ov 'evaporate 't)
14349 (overlay-put ov 'verilog-inst-module 't)
14350 (overlay-put ov 'mouse-face 'highlight)
14351 (overlay-put ov 'local-map verilog-mode-mouse-map)))))
14354 ;; Future highlights:
14355 ;; variables - make an Occur buffer of where referenced
14356 ;; pins - make an Occur buffer of the sig in the declaration module
14359 (defun verilog-highlight-buffer ()
14360 "Colorize included files and modules across the whole buffer."
14361 ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
14363 ;; delete and remake overlays
14364 (verilog-highlight-region (point-min) (point-max) nil))
14366 ;; Deprecated, but was interactive, so we'll keep it around
14367 (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
14369 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
14370 ;; so define this function to do more or less the same as ffap-at-mouse
14371 ;; but first resolve filename...
14372 (defun verilog-load-file-at-mouse (event)
14373 "Load file under button 2 click's EVENT.
14374 Files are checked based on `verilog-library-flags'."
14376 (save-excursion ; implement a Verilog specific ffap-at-mouse
14377 (mouse-set-point event)
14378 (verilog-load-file-at-point t)))
14380 ;; ffap isn't usable for Verilog mode. It uses library paths.
14381 ;; so define this function to do more or less the same as ffap
14382 ;; but first resolve filename...
14383 (defun verilog-load-file-at-point (&optional warn)
14384 "Load file under point.
14385 If WARN, throw warning if not found.
14386 Files are checked based on `verilog-library-flags'."
14388 (save-excursion ; implement a Verilog specific ffap
14389 (let ((overlays (overlays-in (point) (point)))
14391 (while (and overlays (not hit))
14392 (when (overlay-get (car overlays) 'verilog-inst-module)
14393 (verilog-goto-defun-file (buffer-substring
14394 (overlay-start (car overlays))
14395 (overlay-end (car overlays))))
14397 (setq overlays (cdr overlays)))
14399 (beginning-of-line)
14400 (when (and (not hit)
14401 (looking-at verilog-include-file-regexp))
14402 (if (and (car (verilog-library-filenames
14403 (match-string 1) (buffer-file-name)))
14404 (file-readable-p (car (verilog-library-filenames
14405 (match-string 1) (buffer-file-name)))))
14406 (find-file (car (verilog-library-filenames
14407 (match-string 1) (buffer-file-name))))
14410 "File `%s' isn't readable, use shift-mouse2 to paste in this field"
14411 (match-string 1))))))))
14417 (defun verilog-faq ()
14418 "Tell the user their current version, and where to get the FAQ etc."
14420 (with-output-to-temp-buffer "*verilog-mode help*"
14421 (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
14423 (princ "For new releases, see http://www.verilog.com\n")
14425 (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
14427 (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
14430 (autoload 'reporter-submit-bug-report "reporter")
14431 (defvar reporter-prompt-for-summary-p)
14433 (defun verilog-submit-bug-report ()
14434 "Submit via mail a bug report on verilog-mode.el."
14436 (let ((reporter-prompt-for-summary-p t))
14437 (reporter-submit-bug-report
14438 "mac@verilog.com, wsnyder@wsnyder.org"
14439 (concat "verilog-mode v" verilog-mode-version)
14441 verilog-active-low-regexp
14442 verilog-after-save-font-hook
14443 verilog-align-ifelse
14444 verilog-assignment-delay
14445 verilog-auto-arg-sort
14446 verilog-auto-declare-nettype
14447 verilog-auto-delete-trailing-whitespace
14448 verilog-auto-endcomments
14450 verilog-auto-ignore-concat
14451 verilog-auto-indent-on-newline
14452 verilog-auto-inout-ignore-regexp
14453 verilog-auto-input-ignore-regexp
14454 verilog-auto-inst-column
14455 verilog-auto-inst-dot-name
14456 verilog-auto-inst-interfaced-ports
14457 verilog-auto-inst-param-value
14458 verilog-auto-inst-sort
14459 verilog-auto-inst-template-numbers
14460 verilog-auto-inst-vector
14461 verilog-auto-lineup
14462 verilog-auto-newline
14463 verilog-auto-output-ignore-regexp
14464 verilog-auto-read-includes
14465 verilog-auto-reset-blocking-in-non
14466 verilog-auto-reset-widths
14467 verilog-auto-save-policy
14468 verilog-auto-sense-defines-constant
14469 verilog-auto-sense-include-inputs
14470 verilog-auto-star-expand
14471 verilog-auto-star-save
14472 verilog-auto-template-warn-unused
14473 verilog-auto-tieoff-declaration
14474 verilog-auto-tieoff-ignore-regexp
14475 verilog-auto-unused-ignore-regexp
14476 verilog-auto-wire-type
14477 verilog-before-auto-hook
14478 verilog-before-delete-auto-hook
14479 verilog-before-getopt-flags-hook
14480 verilog-before-save-font-hook
14481 verilog-cache-enabled
14483 verilog-case-indent
14484 verilog-cexp-indent
14487 verilog-delete-auto-hook
14488 verilog-getopt-flags-hook
14489 verilog-highlight-grouping-keywords
14490 verilog-highlight-includes
14491 verilog-highlight-modules
14492 verilog-highlight-p1800-keywords
14493 verilog-highlight-translate-off
14494 verilog-indent-begin-after-if
14495 verilog-indent-declaration-macros
14496 verilog-indent-level
14497 verilog-indent-level-behavioral
14498 verilog-indent-level-declaration
14499 verilog-indent-level-directive
14500 verilog-indent-level-module
14501 verilog-indent-lists
14502 verilog-library-directories
14503 verilog-library-extensions
14504 verilog-library-files
14505 verilog-library-flags
14507 verilog-minimum-comment-distance
14509 verilog-mode-release-emacs
14510 verilog-mode-version
14511 verilog-preprocessor
14513 verilog-tab-always-indent
14514 verilog-tab-to-comment
14515 verilog-typedef-regexp
14521 I want to report a bug.
14523 Before I go further, I want to say that Verilog mode has changed my life.
14524 I save so much time, my files are colored nicely, my co workers respect
14525 my coding ability... until now. I'd really appreciate anything you
14526 could do to help me out with this minor deficiency in the product.
14528 I've taken a look at the Verilog-Mode FAQ at
14529 http://www.veripool.org/verilog-mode-faq.html.
14531 And, I've considered filing the bug on the issue tracker at
14532 http://www.veripool.org/verilog-mode-bugs
14533 since I realize that public bugs are easier for you to track,
14534 and for others to search, but would prefer to email.
14536 So, to reproduce the bug, start a fresh Emacs via " invocation-name "
14537 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
14538 the code included below.
14540 Given those lines, I expected [[Fill in here]] to happen;
14541 but instead, [[Fill in here]] happens!.
14543 == The code: =="))))
14545 (provide 'verilog-mode)
14547 ;; Local Variables:
14548 ;; checkdoc-permit-comma-termination-flag:t
14549 ;; checkdoc-force-docstrings-flag:nil
14550 ;; indent-tabs-mode:nil
14553 ;;; verilog-mode.el ends here