1 ;; verilog-mode.el --- major mode for editing verilog source in Emacs
3 ;; Copyright (C) 1996-2013 Free Software Foundation, Inc.
5 ;; Author: Michael McNamara (mac@verilog.com),
6 ;; Wilson Snyder (wsnyder@wsnyder.org)
7 ;; Please see our web sites:
8 ;; http://www.verilog.com
9 ;; http://www.veripool.org
11 ;; Keywords: languages
13 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
14 ;; file on 19/3/2008, and the maintainer agreed that when a bug is
15 ;; filed in the Emacs bug reporting system against this file, a copy
16 ;; of the bug report be sent to the maintainer's email address.
18 ;; This code supports Emacs 21.1 and later
19 ;; And XEmacs 21.1 and later
20 ;; Please do not make changes that break Emacs 21. Thanks!
24 ;; This file is part of GNU Emacs.
26 ;; GNU Emacs is free software: you can redistribute it and/or modify
27 ;; it under the terms of the GNU General Public License as published by
28 ;; the Free Software Foundation, either version 3 of the License, or
29 ;; (at your option) any later version.
31 ;; GNU Emacs is distributed in the hope that it will be useful,
32 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ;; GNU General Public License for more details.
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
41 ;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs
46 ;; A major mode for editing Verilog HDL source code. When you have
47 ;; entered Verilog mode, you may get more info by pressing C-h m. You
48 ;; may also get online help describing various functions by: C-h f
49 ;; <Name of function you want described>
51 ;; KNOWN BUGS / BUG REPORTS
52 ;; =======================
54 ;; Verilog is a rapidly evolving language, and hence this mode is
55 ;; under continuous development. Hence this is beta code, and likely
56 ;; has bugs. Please report any issues to the issue tracker at
57 ;; 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 I 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"
120 ;; See commit history at http://www.veripool.org/verilog-mode.html
121 ;; (This section is required to appease checkdoc.)
125 ;; This variable will always hold the version number of the mode
126 (defconst verilog-mode-version
(substring "$$Revision: 820 $$" 12 -
3)
127 "Version of this Verilog mode.")
128 (defconst verilog-mode-release-date
(substring "$$Date: 2012-09-17 20:43:10 -0400 (Mon, 17 Sep 2012) $$" 8 -
3)
129 "Release date of this Verilog mode.")
130 (defconst verilog-mode-release-emacs t
131 "If non-nil, this version of Verilog mode was released with Emacs itself.")
133 (defun verilog-version ()
134 "Inform caller of the version of this file."
136 (message "Using verilog-mode version %s" verilog-mode-version
))
138 ;; Insure we have certain packages, and deal with it if we don't
139 ;; Be sure to note which Emacs flavor and version added each feature.
141 ;; Provide stuff if we are XEmacs
142 (when (featurep 'xemacs
)
147 (require 'regexp-opt
)
149 ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
156 (defmacro when
(cond &rest body
)
157 (list 'if cond
(cons 'progn body
))))
160 (if (fboundp 'unless
)
162 (defmacro unless
(cond &rest body
)
163 (cons 'if
(cons cond
(cons nil body
)))))
166 (if (fboundp 'store-match-data
)
168 (defmacro store-match-data
(&rest args
) nil
))
171 (if (fboundp 'char-before
)
173 (defmacro char-before
(&rest body
)
174 (char-after (1- (point)))))
179 (defsubst point-at-bol
(&optional N
)
180 (save-excursion (beginning-of-line N
) (point))))
185 (defsubst point-at-eol
(&optional N
)
186 (save-excursion (end-of-line N
) (point))))
192 (if (fboundp 'match-string-no-properties
)
194 (defsubst match-string-no-properties
(num &optional string
)
195 "Return string of text matched by last search, without text properties.
196 NUM specifies which parenthesized expression in the last regexp.
197 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
198 Zero means the entire text matched by the whole regexp or whole string.
199 STRING should be given if the last search was by `string-match' on STRING."
200 (if (match-beginning num
)
204 (match-beginning num
) (match-end num
))))
205 (set-text-properties 0 (length result
) nil result
)
207 (buffer-substring-no-properties (match-beginning num
)
212 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
213 nil
;; We've got what we needed
214 ;; We have the old custom-library, hack around it!
215 (defmacro defgroup
(&rest args
) nil
)
216 (defmacro customize
(&rest args
)
218 "Sorry, Customize is not available with this version of Emacs"))
219 (defmacro defcustom
(var value doc
&rest args
)
220 `(defvar ,var
,value
,doc
))
222 (if (fboundp 'defface
)
224 (defmacro defface
(var values doc
&rest args
)
228 (if (and (featurep 'custom
) (fboundp 'customize-group
))
229 nil
;; We've got what we needed
230 ;; We have an intermediate custom-library, hack around it!
231 (defmacro customize-group
(var &rest args
)
235 (unless (boundp 'inhibit-point-motion-hooks
)
236 (defvar inhibit-point-motion-hooks nil
))
237 (unless (boundp 'deactivate-mark
)
238 (defvar deactivate-mark nil
))
241 ;; OK, do this stuff if we are NOT XEmacs:
242 (unless (featurep 'xemacs
)
243 (unless (fboundp 'region-active-p
)
244 (defmacro region-active-p
()
245 `(and transient-mark-mode mark-active
))))
248 ;; Provide a regular expression optimization routine, using regexp-opt
249 ;; if provided by the user's elisp libraries
251 ;; The below were disabled when GNU Emacs 22 was released;
252 ;; perhaps some still need to be there to support Emacs 21.
253 (if (featurep 'xemacs
)
254 (if (fboundp 'regexp-opt
)
255 ;; regexp-opt is defined, does it take 3 or 2 arguments?
256 (if (fboundp 'function-max-args
)
257 (let ((args (function-max-args `regexp-opt
)))
259 ((eq args
3) ;; It takes 3
260 (condition-case nil
; Hide this defun from emacses
261 ;with just a two input regexp
262 (defun verilog-regexp-opt (a b
)
263 "Deal with differing number of required arguments for `regexp-opt'.
264 Call 'regexp-opt' on A and B."
268 ((eq args
2) ;; It takes 2
269 (defun verilog-regexp-opt (a b
)
270 "Call 'regexp-opt' on A and B."
274 ;; We can't tell; assume it takes 2
275 (defun verilog-regexp-opt (a b
)
276 "Call 'regexp-opt' on A and B."
279 ;; There is no regexp-opt, provide our own
280 (defun verilog-regexp-opt (strings &optional paren shy
)
281 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
282 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
)))
285 (defalias 'verilog-regexp-opt
'regexp-opt
)))
288 ;; Both xemacs and emacs
290 (require 'diff
) ;; diff-command and diff-switches
293 (require 'compile
) ;; compilation-error-regexp-alist-alist
296 (unless (fboundp 'buffer-chars-modified-tick
) ;; Emacs 22 added
297 (defmacro buffer-chars-modified-tick
() (buffer-modified-tick)))
299 ;; Added in Emacs 24.1
301 (unless (fboundp 'prog-mode
)
302 (define-derived-mode prog-mode fundamental-mode
"Prog"))
306 (defun verilog-regexp-words (a)
307 "Call 'regexp-opt' with word delimiters for the words A."
308 (concat "\\<" (verilog-regexp-opt a t
) "\\>")))
309 (defun verilog-regexp-words (a)
310 "Call 'regexp-opt' with word delimiters for the words A."
311 ;; The FAQ references this function, so user LISP sometimes calls it
312 (concat "\\<" (verilog-regexp-opt a t
) "\\>"))
314 (defun verilog-easy-menu-filter (menu)
315 "Filter `easy-menu-define' MENU to support new features."
316 (cond ((not (featurep 'xemacs
))
317 menu
) ;; GNU Emacs - passthru
318 ;; XEmacs doesn't support :help. Strip it.
319 ;; Recursively filter the a submenu
321 (mapcar 'verilog-easy-menu-filter menu
))
322 ;; Look for [:help "blah"] and remove
324 (let ((i 0) (out []))
325 (while (< i
(length menu
))
326 (if (equal `:help
(aref menu i
))
328 (setq out
(vconcat out
(vector (aref menu i
)))
331 (t menu
))) ;; Default - ok
332 ;;(verilog-easy-menu-filter
333 ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
334 ;; "----" ["MB" nil :help "Help MB"]))
336 (defun verilog-define-abbrev (table name expansion
&optional hook
)
337 "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
338 Provides SYSTEM-FLAG in newer Emacs."
340 (define-abbrev table name expansion hook
0 t
)
342 (define-abbrev table name expansion hook
))))
344 (defun verilog-customize ()
345 "Customize variables and other settings used by Verilog-Mode."
347 (customize-group 'verilog-mode
))
349 (defun verilog-font-customize ()
350 "Customize fonts used by Verilog-Mode."
352 (if (fboundp 'customize-apropos
)
353 (customize-apropos "font-lock-*" 'faces
)))
355 (defun verilog-booleanp (value)
356 "Return t if VALUE is boolean.
357 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
358 This function may be removed when Emacs 21 is no longer supported."
359 (or (equal value t
) (equal value nil
)))
361 (defun verilog-insert-last-command-event ()
362 "Insert the `last-command-event'."
363 (insert (if (featurep 'xemacs
)
364 ;; XEmacs 21.5 doesn't like last-command-event
366 ;; And GNU Emacs 22 has obsoleted last-command-char
367 last-command-event
)))
369 (defvar verilog-no-change-functions nil
370 "True if `after-change-functions' is disabled.
371 Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")
373 (defvar verilog-in-hooks nil
374 "True when within a `verilog-run-hooks' block.")
376 (defmacro verilog-run-hooks
(&rest hooks
)
377 "Run each hook in HOOKS using `run-hooks'.
378 Set `verilog-in-hooks' during this time, to assist AUTO caches."
379 `(let ((verilog-in-hooks t
))
380 (run-hooks ,@hooks
)))
382 (defun verilog-syntax-ppss (&optional pos
)
383 (when verilog-no-change-functions
385 (verilog-scan-cache-flush)
386 ;; else don't let the AUTO code itself get away with flushing the cache,
387 ;; as that'll make things very slow
389 (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
390 (verilog-point-text))))
391 (if (fboundp 'syntax-ppss
)
393 (parse-partial-sexp (point-min) (or pos
(point)))))
395 (defgroup verilog-mode nil
396 "Major mode for Verilog source code."
400 ; (defgroup verilog-mode-fonts nil
401 ; "Facilitates easy customization fonts used in Verilog source text"
402 ; :link '(customize-apropos "font-lock-*" 'faces)
403 ; :group 'verilog-mode)
405 (defgroup verilog-mode-indent nil
406 "Customize indentation and highlighting of Verilog source text."
407 :group
'verilog-mode
)
409 (defgroup verilog-mode-actions nil
410 "Customize actions on Verilog source text."
411 :group
'verilog-mode
)
413 (defgroup verilog-mode-auto nil
414 "Customize AUTO actions when expanding Verilog source text."
415 :group
'verilog-mode
)
417 (defvar verilog-debug nil
418 "Non-nil means enable debug messages for `verilog-mode' internals.")
420 (defvar verilog-warn-fatal nil
421 "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
423 (defcustom verilog-linter
424 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
425 "Unix program and arguments to call to run a lint checker on Verilog source.
426 Depending on the `verilog-set-compile-command', this may be invoked when
427 you type \\[compile]. When the compile completes, \\[next-error] will take
428 you to the next lint error."
430 :group
'verilog-mode-actions
)
431 ;; We don't mark it safe, as it's used as a shell command
433 (defcustom verilog-coverage
434 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
435 "Program and arguments to use to annotate for coverage Verilog source.
436 Depending on the `verilog-set-compile-command', this may be invoked when
437 you type \\[compile]. When the compile completes, \\[next-error] will take
438 you to the next lint error."
440 :group
'verilog-mode-actions
)
441 ;; We don't mark it safe, as it's used as a shell command
443 (defcustom verilog-simulator
444 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
445 "Program and arguments to use to interpret Verilog source.
446 Depending on the `verilog-set-compile-command', this may be invoked when
447 you type \\[compile]. When the compile completes, \\[next-error] will take
448 you to the next lint error."
450 :group
'verilog-mode-actions
)
451 ;; We don't mark it safe, as it's used as a shell command
453 (defcustom verilog-compiler
454 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
455 "Program and arguments to use to compile Verilog source.
456 Depending on the `verilog-set-compile-command', this may be invoked when
457 you type \\[compile]. When the compile completes, \\[next-error] will take
458 you to the next lint error."
460 :group
'verilog-mode-actions
)
461 ;; We don't mark it safe, as it's used as a shell command
463 (defcustom verilog-preprocessor
464 ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
465 "vppreproc __FLAGS__ __FILE__"
466 "Program and arguments to use to preprocess Verilog source.
467 This is invoked with `verilog-preprocess', and depending on the
468 `verilog-set-compile-command', may also be invoked when you type
469 \\[compile]. When the compile completes, \\[next-error] will
470 take you to the next lint error."
472 :group
'verilog-mode-actions
)
473 ;; We don't mark it safe, as it's used as a shell command
475 (defvar verilog-preprocess-history nil
476 "History for `verilog-preprocess'.")
478 (defvar verilog-tool
'verilog-linter
479 "Which tool to use for building compiler-command.
480 Either nil, `verilog-linter, `verilog-compiler,
481 `verilog-coverage, `verilog-preprocessor, or `verilog-simulator.
482 Alternatively use the \"Choose Compilation Action\" menu. See
483 `verilog-set-compile-command' for more information.")
485 (defcustom verilog-highlight-translate-off nil
486 "Non-nil means background-highlight code excluded from translation.
487 That is, all code between \"// synopsys translate_off\" and
488 \"// synopsys translate_on\" is highlighted using a different background color
489 \(face `verilog-font-lock-translate-off-face').
491 Note: This will slow down on-the-fly fontification (and thus editing).
493 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
494 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
496 :group
'verilog-mode-indent
)
497 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
498 (put 'verilog-highlight-translate-off
'safe-local-variable
'verilog-booleanp
)
500 (defcustom verilog-auto-lineup
'declarations
501 "Type of statements to lineup across multiple lines.
502 If 'all' is selected, then all line ups described below are done.
504 If 'declaration', then just declarations are lined up with any
505 preceding declarations, taking into account widths and the like,
506 so or example the code:
513 If 'assignment', then assignments are lined up with any preceding
514 assignments, so for example the code
515 a_long_variable <= b + c;
518 a_long_variable <= b + c;
521 In order to speed up editing, large blocks of statements are lined up
522 only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
523 are lineup only when \\[verilog-pretty-declarations] is typed."
525 :type
'(radio (const :tag
"Line up Assignments and Declarations" all
)
526 (const :tag
"Line up Assignment statements" assignments
)
527 (const :tag
"Line up Declarations" declarations
)
528 (function :tag
"Other"))
529 :group
'verilog-mode-indent
)
530 (put 'verilog-auto-lineup
'safe-local-variable
531 '(lambda (x) (memq x
'(nil all assignments declarations
))))
533 (defcustom verilog-indent-level
3
534 "Indentation of Verilog statements with respect to containing block."
535 :group
'verilog-mode-indent
537 (put 'verilog-indent-level
'safe-local-variable
'integerp
)
539 (defcustom verilog-indent-level-module
3
540 "Indentation of Module level Verilog statements (eg always, initial).
541 Set to 0 to get initial and always statements lined up on the left side of
543 :group
'verilog-mode-indent
545 (put 'verilog-indent-level-module
'safe-local-variable
'integerp
)
547 (defcustom verilog-indent-level-declaration
3
548 "Indentation of declarations with respect to containing block.
549 Set to 0 to get them list right under containing block."
550 :group
'verilog-mode-indent
552 (put 'verilog-indent-level-declaration
'safe-local-variable
'integerp
)
554 (defcustom verilog-indent-declaration-macros nil
555 "How to treat macro expansions in a declaration.
560 If non nil, treat as:
564 :group
'verilog-mode-indent
566 (put 'verilog-indent-declaration-macros
'safe-local-variable
'verilog-booleanp
)
568 (defcustom verilog-indent-lists t
569 "How to treat indenting items in a list.
570 If t (the default), indent as:
571 always @( posedge a or
575 always @( posedge a or
577 :group
'verilog-mode-indent
579 (put 'verilog-indent-lists
'safe-local-variable
'verilog-booleanp
)
581 (defcustom verilog-indent-level-behavioral
3
582 "Absolute indentation of first begin in a task or function block.
583 Set to 0 to get such code to start at the left side of the screen."
584 :group
'verilog-mode-indent
586 (put 'verilog-indent-level-behavioral
'safe-local-variable
'integerp
)
588 (defcustom verilog-indent-level-directive
1
589 "Indentation to add to each level of `ifdef declarations.
590 Set to 0 to have all directives start at the left side of the screen."
591 :group
'verilog-mode-indent
593 (put 'verilog-indent-level-directive
'safe-local-variable
'integerp
)
595 (defcustom verilog-cexp-indent
2
596 "Indentation of Verilog statements split across lines."
597 :group
'verilog-mode-indent
599 (put 'verilog-cexp-indent
'safe-local-variable
'integerp
)
601 (defcustom verilog-case-indent
2
602 "Indentation for case statements."
603 :group
'verilog-mode-indent
605 (put 'verilog-case-indent
'safe-local-variable
'integerp
)
607 (defcustom verilog-auto-newline t
608 "Non-nil means automatically newline after semicolons."
609 :group
'verilog-mode-indent
611 (put 'verilog-auto-newline
'safe-local-variable
'verilog-booleanp
)
613 (defcustom verilog-auto-indent-on-newline t
614 "Non-nil means automatically indent line after newline."
615 :group
'verilog-mode-indent
617 (put 'verilog-auto-indent-on-newline
'safe-local-variable
'verilog-booleanp
)
619 (defcustom verilog-tab-always-indent t
620 "Non-nil means TAB should always re-indent the current line.
621 A nil value means TAB will only reindent when at the beginning of the line."
622 :group
'verilog-mode-indent
624 (put 'verilog-tab-always-indent
'safe-local-variable
'verilog-booleanp
)
626 (defcustom verilog-tab-to-comment nil
627 "Non-nil means TAB moves to the right hand column in preparation for a comment."
628 :group
'verilog-mode-actions
630 (put 'verilog-tab-to-comment
'safe-local-variable
'verilog-booleanp
)
632 (defcustom verilog-indent-begin-after-if t
633 "Non-nil means indent begin statements following if, else, while, etc.
634 Otherwise, line them up."
635 :group
'verilog-mode-indent
637 (put 'verilog-indent-begin-after-if
'safe-local-variable
'verilog-booleanp
)
639 (defcustom verilog-align-ifelse nil
640 "Non-nil means align `else' under matching `if'.
641 Otherwise else is lined up with first character on line holding matching if."
642 :group
'verilog-mode-indent
644 (put 'verilog-align-ifelse
'safe-local-variable
'verilog-booleanp
)
646 (defcustom verilog-minimum-comment-distance
10
647 "Minimum distance (in lines) between begin and end required before a comment.
648 Setting this variable to zero results in every end acquiring a comment; the
649 default avoids too many redundant comments in tight quarters."
650 :group
'verilog-mode-indent
652 (put 'verilog-minimum-comment-distance
'safe-local-variable
'integerp
)
654 (defcustom verilog-highlight-p1800-keywords nil
655 "Non-nil means highlight words newly reserved by IEEE-1800.
656 These will appear in `verilog-font-lock-p1800-face' in order to gently
657 suggest changing where these words are used as variables to something else.
658 A nil value means highlight these words as appropriate for the SystemVerilog
659 IEEE-1800 standard. Note that changing this will require restarting Emacs
660 to see the effect as font color choices are cached by Emacs."
661 :group
'verilog-mode-indent
663 (put 'verilog-highlight-p1800-keywords
'safe-local-variable
'verilog-booleanp
)
665 (defcustom verilog-highlight-grouping-keywords nil
666 "Non-nil means highlight grouping keywords 'begin' and 'end' more dramatically.
667 If false, these words are in the `font-lock-type-face'; if True then they are in
668 `verilog-font-lock-ams-face'. Some find that special highlighting on these
669 grouping constructs allow the structure of the code to be understood at a glance."
670 :group
'verilog-mode-indent
672 (put 'verilog-highlight-grouping-keywords
'safe-local-variable
'verilog-booleanp
)
674 (defcustom verilog-highlight-modules nil
675 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
676 When true, mousing over module names will allow jumping to the
677 module definition. If false, this is not supported. Setting
678 this is experimental, and may lead to bad performance."
679 :group
'verilog-mode-indent
681 (put 'verilog-highlight-modules
'safe-local-variable
'verilog-booleanp
)
683 (defcustom verilog-highlight-includes t
684 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
685 When true, mousing over include file names will allow jumping to the
686 file referenced. If false, this is not supported."
687 :group
'verilog-mode-indent
689 (put 'verilog-highlight-includes
'safe-local-variable
'verilog-booleanp
)
691 (defcustom verilog-auto-declare-nettype nil
692 "Non-nil specifies the data type to use with `verilog-auto-input' etc.
693 Set this to \"wire\" if the Verilog code uses \"`default_nettype
694 none\". Note using `default_nettype none isn't recommended practice; this
695 mode is experimental."
696 :version
"24.1" ;; rev670
697 :group
'verilog-mode-actions
699 (put 'verilog-auto-declare-nettype
'safe-local-variable
`stringp
)
701 (defcustom verilog-auto-wire-type nil
702 "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
703 Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'."
704 :version
"24.1" ;; rev673
705 :group
'verilog-mode-actions
707 (put 'verilog-auto-wire-type
'safe-local-variable
`stringp
)
709 (defcustom verilog-auto-endcomments t
710 "Non-nil means insert a comment /* ... */ after 'end's.
711 The name of the function or case will be set between the braces."
712 :group
'verilog-mode-actions
714 (put 'verilog-auto-endcomments
'safe-local-variable
'verilog-booleanp
)
716 (defcustom verilog-auto-delete-trailing-whitespace nil
717 "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
718 :version
"24.1" ;; rev703
719 :group
'verilog-mode-actions
721 (put 'verilog-auto-delete-trailing-whitespace
'safe-local-variable
'verilog-booleanp
)
723 (defcustom verilog-auto-ignore-concat nil
724 "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
725 This will exclude signals referenced as pin connections in {...}
726 from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
727 for backward compatibility only and not set in new designs; it
728 may be removed in future versions."
729 :group
'verilog-mode-actions
731 (put 'verilog-auto-ignore-concat
'safe-local-variable
'verilog-booleanp
)
733 (defcustom verilog-auto-read-includes nil
734 "Non-nil means to automatically read includes before AUTOs.
735 This will do a `verilog-read-defines' and `verilog-read-includes' before
736 each AUTO expansion. This makes it easier to embed defines and includes,
737 but can result in very slow reading times if there are many or large
739 :group
'verilog-mode-actions
741 (put 'verilog-auto-read-includes
'safe-local-variable
'verilog-booleanp
)
743 (defcustom verilog-auto-save-policy nil
744 "Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
745 A value of `force' will always do a \\[verilog-auto] automatically if
746 needed on every save. A value of `detect' will do \\[verilog-auto]
747 automatically when it thinks necessary. A value of `ask' will query the
748 user when it thinks updating is needed.
750 You should not rely on the 'ask or 'detect policies, they are safeguards
751 only. They do not detect when AUTOINSTs need to be updated because a
752 sub-module's port list has changed."
753 :group
'verilog-mode-actions
754 :type
'(choice (const nil
) (const ask
) (const detect
) (const force
)))
756 (defcustom verilog-auto-star-expand t
757 "Non-nil means to expand SystemVerilog .* instance ports.
758 They will be expanded in the same way as if there was an AUTOINST in the
759 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
760 :group
'verilog-mode-actions
762 (put 'verilog-auto-star-expand
'safe-local-variable
'verilog-booleanp
)
764 (defcustom verilog-auto-star-save nil
765 "Non-nil means save to disk SystemVerilog .* instance expansions.
766 A nil value indicates direct connections will be removed before saving.
767 Only meaningful to those created due to `verilog-auto-star-expand' being set.
769 Instead of setting this, you may want to use /*AUTOINST*/, which will
771 :group
'verilog-mode-actions
773 (put 'verilog-auto-star-save
'safe-local-variable
'verilog-booleanp
)
775 (defvar verilog-auto-update-tick nil
776 "Modification tick at which autos were last performed.")
778 (defvar verilog-auto-last-file-locals nil
779 "Text from file-local-variables during last evaluation.")
781 (defvar verilog-diff-function
'verilog-diff-report
782 "Function to run when `verilog-diff-auto' detects differences.
783 Function takes three arguments, the original buffer, the
784 difference buffer, and the point in original buffer with the
789 (defvar verilog-error-regexp-added nil
)
791 (defvar verilog-error-regexp-emacs-alist
794 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
796 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
798 ".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
800 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
802 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
805 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
806 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
808 "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
810 "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
812 "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
814 "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
816 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
818 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
820 "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
822 "List of regexps for Verilog compilers.
823 See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
825 (defvar verilog-error-regexp-xemacs-alist
826 ;; Emacs form is '((v-tool "re" 1 2) ...)
827 ;; XEmacs form is '(verilog ("re" 1 2) ...)
828 ;; So we can just map from Emacs to XEmacs
829 (cons 'verilog
(mapcar 'cdr verilog-error-regexp-emacs-alist
))
830 "List of regexps for Verilog compilers.
831 See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
833 (defvar verilog-error-font-lock-keywords
836 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
837 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
839 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t
)
840 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t
)
841 ;; verilog-IES (nc-verilog)
842 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t
)
843 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t
)
844 ;; verilog-surefire-1
845 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t
)
846 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t
)
847 ;; verilog-surefire-2
848 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t
)
849 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t
)
852 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
853 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
855 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
856 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
858 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t
)
859 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t
)
861 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
862 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
864 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
865 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t
)
867 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t
)
868 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
870 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t
)
871 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t
)
873 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t
)
874 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t
)
876 "Keywords to also highlight in Verilog *compilation* buffers.
877 Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
879 (defcustom verilog-library-flags
'("")
880 "List of standard Verilog arguments to use for /*AUTOINST*/.
881 These arguments are used to find files for `verilog-auto', and match
882 the flags accepted by a standard Verilog-XL simulator.
884 -f filename Reads more `verilog-library-flags' from the filename.
885 +incdir+dir Adds the directory to `verilog-library-directories'.
886 -Idir Adds the directory to `verilog-library-directories'.
887 -y dir Adds the directory to `verilog-library-directories'.
888 +libext+.v Adds the extensions to `verilog-library-extensions'.
889 -v filename Adds the filename to `verilog-library-files'.
891 filename Adds the filename to `verilog-library-files'.
892 This is not recommended, -v is a better choice.
894 You might want these defined in each file; put at the *END* of your file
898 // verilog-library-flags:(\"-y dir -y otherdir\")
901 Verilog-mode attempts to detect changes to this local variable, but they
902 are only insured to be correct when the file is first visited. Thus if you
903 have problems, use \\[find-alternate-file] RET to have these take effect.
905 See also the variables mentioned above."
906 :group
'verilog-mode-auto
907 :type
'(repeat string
))
908 (put 'verilog-library-flags
'safe-local-variable
'listp
)
910 (defcustom verilog-library-directories
'(".")
911 "List of directories when looking for files for /*AUTOINST*/.
912 The directory may be relative to the current file, or absolute.
913 Environment variables are also expanded in the directory names.
914 Having at least the current directory is a good idea.
916 You might want these defined in each file; put at the *END* of your file
920 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
923 Verilog-mode attempts to detect changes to this local variable, but they
924 are only insured to be correct when the file is first visited. Thus if you
925 have problems, use \\[find-alternate-file] RET to have these take effect.
927 See also `verilog-library-flags', `verilog-library-files'
928 and `verilog-library-extensions'."
929 :group
'verilog-mode-auto
930 :type
'(repeat file
))
931 (put 'verilog-library-directories
'safe-local-variable
'listp
)
933 (defcustom verilog-library-files
'()
934 "List of files to search for modules.
935 AUTOINST will use this when it needs to resolve a module name.
936 This is a complete path, usually to a technology file with many standard
939 You might want these defined in each file; put at the *END* of your file
943 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
946 Verilog-mode attempts to detect changes to this local variable, but they
947 are only insured to be correct when the file is first visited. Thus if you
948 have problems, use \\[find-alternate-file] RET to have these take effect.
950 See also `verilog-library-flags', `verilog-library-directories'."
951 :group
'verilog-mode-auto
952 :type
'(repeat directory
))
953 (put 'verilog-library-files
'safe-local-variable
'listp
)
955 (defcustom verilog-library-extensions
'(".v" ".sv")
956 "List of extensions to use when looking for files for /*AUTOINST*/.
957 See also `verilog-library-flags', `verilog-library-directories'."
958 :type
'(repeat string
)
959 :group
'verilog-mode-auto
)
960 (put 'verilog-library-extensions
'safe-local-variable
'listp
)
962 (defcustom verilog-active-low-regexp nil
963 "If set, treat signals matching this regexp as active low.
964 This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
965 you will probably also need `verilog-auto-reset-widths' set."
966 :group
'verilog-mode-auto
968 (put 'verilog-active-low-regexp
'safe-local-variable
'stringp
)
970 (defcustom verilog-auto-sense-include-inputs nil
971 "Non-nil means AUTOSENSE should include all inputs.
972 If nil, only inputs that are NOT output signals in the same block are
974 :group
'verilog-mode-auto
976 (put 'verilog-auto-sense-include-inputs
'safe-local-variable
'verilog-booleanp
)
978 (defcustom verilog-auto-sense-defines-constant nil
979 "Non-nil means AUTOSENSE should assume all defines represent constants.
980 When true, the defines will not be included in sensitivity lists. To
981 maintain compatibility with other sites, this should be set at the bottom
982 of each Verilog file that requires it, rather than being set globally."
983 :group
'verilog-mode-auto
985 (put 'verilog-auto-sense-defines-constant
'safe-local-variable
'verilog-booleanp
)
987 (defcustom verilog-auto-reset-blocking-in-non t
988 "Non-nil means AUTORESET will reset blocking statements.
989 When true, AUTORESET will reset in blocking statements those
990 signals which were assigned with blocking assignments (=) even in
991 a block with non-blocking assignments (<=).
993 If nil, all blocking assigned signals are ignored when any
994 non-blocking assignment is in the AUTORESET block. This allows
995 blocking assignments to be used for temporary values and not have
996 those temporaries reset. See example in `verilog-auto-reset'."
997 :version
"24.1" ;; rev718
999 :group
'verilog-mode-auto
)
1000 (put 'verilog-auto-reset-blocking-in-non
'safe-local-variable
'verilog-booleanp
)
1002 (defcustom verilog-auto-reset-widths t
1003 "True means AUTORESET should determine the width of signals.
1004 This is then used to set the width of the zero (32'h0 for example). This
1005 is required by some lint tools that aren't smart enough to ignore widths of
1006 the constant zero. This may result in ugly code when parameters determine
1007 the MSB or LSB of a signal inside an AUTORESET.
1009 If nil, AUTORESET uses \"0\" as the constant.
1011 If 'unbased', AUTORESET used the unbased unsized literal \"'0\"
1012 as the constant. This setting is strongly recommended for
1013 SystemVerilog designs."
1015 :group
'verilog-mode-auto
)
1016 (put 'verilog-auto-reset-widths
'safe-local-variable
1017 '(lambda (x) (memq x
'(nil t unbased
))))
1019 (defcustom verilog-assignment-delay
""
1020 "Text used for delays in delayed assignments. Add a trailing space if set."
1021 :group
'verilog-mode-auto
1023 (put 'verilog-assignment-delay
'safe-local-variable
'stringp
)
1025 (defcustom verilog-auto-arg-sort nil
1026 "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
1027 Declaration order is advantageous with order based instantiations
1028 and is the default for backward compatibility. Sorted order
1029 reduces changes when declarations are moved around in a file, and
1030 it's bad practice to rely on order based instantiations anyhow.
1032 See also `verilog-auto-inst-sort'."
1033 :group
'verilog-mode-auto
1035 (put 'verilog-auto-arg-sort
'safe-local-variable
'verilog-booleanp
)
1037 (defcustom verilog-auto-inst-dot-name nil
1038 "Non-nil means when creating ports with AUTOINST, use .name syntax.
1039 This will use \".port\" instead of \".port(port)\" when possible.
1040 This is only legal in SystemVerilog files, and will confuse older
1041 simulators. Setting `verilog-auto-inst-vector' to nil may also
1042 be desirable to increase how often .name will be used."
1043 :group
'verilog-mode-auto
1045 (put 'verilog-auto-inst-dot-name
'safe-local-variable
'verilog-booleanp
)
1047 (defcustom verilog-auto-inst-param-value nil
1048 "Non-nil means AUTOINST will replace parameters with the parameter value.
1049 If nil, leave parameters as symbolic names.
1051 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
1052 listed as such there (as when the default value is acceptable), it will not
1053 be replaced, and will remain symbolic.
1055 For example, imagine a submodule uses parameters to declare the size of its
1056 inputs. This is then used by an upper module:
1058 module InstModule (o,i);
1060 input [WIDTH-1:0] i;
1070 Note even though PARAM=10, the AUTOINST has left the parameter as a
1071 symbolic name. If `verilog-auto-inst-param-value' is set, this will
1080 :group
'verilog-mode-auto
1082 (put 'verilog-auto-inst-param-value
'safe-local-variable
'verilog-booleanp
)
1084 (defcustom verilog-auto-inst-sort nil
1085 "Non-nil means AUTOINST signals will be sorted, not in declaration order.
1086 Also affects AUTOINSTPARAM. Declaration order is the default for
1087 backward compatibility, and as some teams prefer signals that are
1088 declared together to remain together. Sorted order reduces
1089 changes when declarations are moved around in a file.
1091 See also `verilog-auto-arg-sort'."
1092 :version
"24.1" ;; rev688
1093 :group
'verilog-mode-auto
1095 (put 'verilog-auto-inst-sort
'safe-local-variable
'verilog-booleanp
)
1097 (defcustom verilog-auto-inst-vector t
1098 "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
1099 If nil, skip the subscript when it matches the entire bus as declared in
1100 the module (AUTOWIRE signals always are subscripted, you must manually
1101 declare the wire to have the subscripts removed.) Setting this to nil may
1102 speed up some simulators, but is less general and harder to read, so avoid."
1103 :group
'verilog-mode-auto
1105 (put 'verilog-auto-inst-vector
'safe-local-variable
'verilog-booleanp
)
1107 (defcustom verilog-auto-inst-template-numbers nil
1108 "If true, when creating templated ports with AUTOINST, add a comment.
1110 If t, the comment will add the line number of the template that
1111 was used for that port declaration. This setting is suggested
1112 only for debugging use, as regular use may cause a large numbers
1115 If 'lhs', the comment will show the left hand side of the
1116 AUTO_TEMPLATE rule that is matched. This is less precise than
1117 numbering (t) when multiple rules have the same pin name, but
1118 won't merge conflict."
1119 :group
'verilog-mode-auto
1120 :type
'(choice (const nil
) (const t
) (const lhs
)))
1121 (put 'verilog-auto-inst-template-numbers
'safe-local-variable
1122 '(lambda (x) (memq x
'(nil t lhs
))))
1124 (defcustom verilog-auto-inst-column
40
1125 "Indent-to column number for net name part of AUTOINST created pin."
1126 :group
'verilog-mode-indent
1128 (put 'verilog-auto-inst-column
'safe-local-variable
'integerp
)
1130 (defcustom verilog-auto-inst-interfaced-ports nil
1131 "Non-nil means include interfaced ports in AUTOINST expansions."
1132 :group
'verilog-mode-auto
1135 (put 'verilog-auto-inst-interfaced-ports
'safe-local-variable
'verilog-booleanp
)
1137 (defcustom verilog-auto-input-ignore-regexp nil
1138 "If set, when creating AUTOINPUT list, ignore signals matching this regexp.
1139 See the \\[verilog-faq] for examples on using this."
1140 :group
'verilog-mode-auto
1142 (put 'verilog-auto-input-ignore-regexp
'safe-local-variable
'stringp
)
1144 (defcustom verilog-auto-inout-ignore-regexp nil
1145 "If set, when creating AUTOINOUT list, ignore signals matching this regexp.
1146 See the \\[verilog-faq] for examples on using this."
1147 :group
'verilog-mode-auto
1149 (put 'verilog-auto-inout-ignore-regexp
'safe-local-variable
'stringp
)
1151 (defcustom verilog-auto-output-ignore-regexp nil
1152 "If set, when creating AUTOOUTPUT list, ignore signals matching this regexp.
1153 See the \\[verilog-faq] for examples on using this."
1154 :group
'verilog-mode-auto
1156 (put 'verilog-auto-output-ignore-regexp
'safe-local-variable
'stringp
)
1158 (defcustom verilog-auto-template-warn-unused nil
1159 "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
1160 This feature is not supported before Emacs 21.1 or XEmacs 21.4."
1161 :group
'verilog-mode-auto
1164 (put 'verilog-auto-template-warn-unused
'safe-local-variable
'verilog-booleanp
)
1166 (defcustom verilog-auto-tieoff-declaration
"wire"
1167 "Data type used for the declaration for AUTOTIEOFF.
1168 If \"wire\" then create a wire, if \"assign\" create an
1169 assignment, else the data type for variable creation."
1170 :version
"24.1" ;; rev713
1171 :group
'verilog-mode-auto
1173 (put 'verilog-auto-tieoff-declaration
'safe-local-variable
'stringp
)
1175 (defcustom verilog-auto-tieoff-ignore-regexp nil
1176 "If set, when creating AUTOTIEOFF list, ignore signals matching this regexp.
1177 See the \\[verilog-faq] for examples on using this."
1178 :group
'verilog-mode-auto
1180 (put 'verilog-auto-tieoff-ignore-regexp
'safe-local-variable
'stringp
)
1182 (defcustom verilog-auto-unused-ignore-regexp nil
1183 "If set, when creating AUTOUNUSED list, ignore signals matching this regexp.
1184 See the \\[verilog-faq] for examples on using this."
1185 :group
'verilog-mode-auto
1187 (put 'verilog-auto-unused-ignore-regexp
'safe-local-variable
'stringp
)
1189 (defcustom verilog-typedef-regexp nil
1190 "If non-nil, regular expression that matches Verilog-2001 typedef names.
1191 For example, \"_t$\" matches typedefs named with _t, as in the C language."
1192 :group
'verilog-mode-auto
1194 (put 'verilog-typedef-regexp
'safe-local-variable
'stringp
)
1196 (defcustom verilog-mode-hook
'verilog-set-compile-command
1197 "Hook run after Verilog mode is loaded."
1199 :group
'verilog-mode
)
1201 (defcustom verilog-auto-hook nil
1202 "Hook run after `verilog-mode' updates AUTOs."
1203 :group
'verilog-mode-auto
1206 (defcustom verilog-before-auto-hook nil
1207 "Hook run before `verilog-mode' updates AUTOs."
1208 :group
'verilog-mode-auto
1211 (defcustom verilog-delete-auto-hook nil
1212 "Hook run after `verilog-mode' deletes AUTOs."
1213 :group
'verilog-mode-auto
1216 (defcustom verilog-before-delete-auto-hook nil
1217 "Hook run before `verilog-mode' deletes AUTOs."
1218 :group
'verilog-mode-auto
1221 (defcustom verilog-getopt-flags-hook nil
1222 "Hook run after `verilog-getopt-flags' determines the Verilog option lists."
1223 :group
'verilog-mode-auto
1226 (defcustom verilog-before-getopt-flags-hook nil
1227 "Hook run before `verilog-getopt-flags' determines the Verilog option lists."
1228 :group
'verilog-mode-auto
1231 (defcustom verilog-before-save-font-hook nil
1232 "Hook run before `verilog-save-font-mods' removes highlighting."
1233 :group
'verilog-mode-auto
1237 (defcustom verilog-after-save-font-hook nil
1238 "Hook run after `verilog-save-font-mods' restores highlighting."
1239 :group
'verilog-mode-auto
1243 (defvar verilog-imenu-generic-expression
1244 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
1245 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
1246 "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
1249 ;; provide a verilog-header function.
1250 ;; Customization variables:
1252 (defvar verilog-date-scientific-format nil
1253 "If non-nil, dates are written in scientific format (e.g. 1997/09/17).
1254 If nil, in European format (e.g. 17.09.1997). The brain-dead American
1255 format (e.g. 09/17/1997) is not supported.")
1257 (defvar verilog-company nil
1258 "Default name of Company for Verilog header.
1259 If set will become buffer local.")
1260 (make-variable-buffer-local 'verilog-company
)
1262 (defvar verilog-project nil
1263 "Default name of Project for Verilog header.
1264 If set will become buffer local.")
1265 (make-variable-buffer-local 'verilog-project
)
1267 (defvar verilog-mode-map
1268 (let ((map (make-sparse-keymap)))
1269 (define-key map
";" 'electric-verilog-semi
)
1270 (define-key map
[(control 59)] 'electric-verilog-semi-with-comment
)
1271 (define-key map
":" 'electric-verilog-colon
)
1272 ;;(define-key map "=" 'electric-verilog-equal)
1273 (define-key map
"\`" 'electric-verilog-tick
)
1274 (define-key map
"\t" 'electric-verilog-tab
)
1275 (define-key map
"\r" 'electric-verilog-terminate-line
)
1276 ;; backspace/delete key bindings
1277 (define-key map
[backspace] 'backward-delete-char-untabify)
1278 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
1279 (define-key map [delete] 'delete-char)
1280 (define-key map [(meta delete)] 'kill-word))
1281 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
1282 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
1283 (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
1284 (define-key map "\M-\t" 'verilog-complete-word)
1285 (define-key map "\M-?" 'verilog-show-completions)
1286 ;; Note \C-c and letter are reserved for users
1287 (define-key map "\C-c\`" 'verilog-lint-off)
1288 (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit)
1289 (define-key map "\C-c\?" 'verilog-diff-auto)
1290 (define-key map "\C-c\C-r" 'verilog-label-be)
1291 (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
1292 (define-key map "\C-c=" 'verilog-pretty-expr)
1293 (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
1294 (define-key map "\M-*" 'verilog-star-comment)
1295 (define-key map "\C-c\C-c" 'verilog-comment-region)
1296 (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1297 (when (featurep 'xemacs)
1298 (define-key map [(meta control h)] 'verilog-mark-defun)
1299 (define-key map "\M-\C-a" 'verilog-beg-of-defun)
1300 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1301 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1302 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1303 (define-key map "\C-c\C-a" 'verilog-auto)
1304 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1305 (define-key map "\C-c\C-p" 'verilog-preprocess)
1306 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1307 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1308 (define-key map "\C-c\C-h" 'verilog-header)
1310 "Keymap used in Verilog mode.")
1314 verilog-menu verilog-mode-map "Menu for Verilog mode"
1315 (verilog-easy-menu-filter
1317 ("Choose Compilation Action"
1320 (setq verilog-tool nil)
1321 (verilog-set-compile-command))
1323 :selected (equal verilog-tool nil)
1324 :help "When invoking compilation, use compile-command"]
1327 (setq verilog-tool 'verilog-linter)
1328 (verilog-set-compile-command))
1330 :selected (equal verilog-tool `verilog-linter)
1331 :help "When invoking compilation, use lint checker"]
1334 (setq verilog-tool 'verilog-coverage)
1335 (verilog-set-compile-command))
1337 :selected (equal verilog-tool `verilog-coverage)
1338 :help "When invoking compilation, annotate for coverage"]
1341 (setq verilog-tool 'verilog-simulator)
1342 (verilog-set-compile-command))
1344 :selected (equal verilog-tool `verilog-simulator)
1345 :help "When invoking compilation, interpret Verilog source"]
1348 (setq verilog-tool 'verilog-compiler)
1349 (verilog-set-compile-command))
1351 :selected (equal verilog-tool `verilog-compiler)
1352 :help "When invoking compilation, compile Verilog source"]
1355 (setq verilog-tool 'verilog-preprocessor)
1356 (verilog-set-compile-command))
1358 :selected (equal verilog-tool `verilog-preprocessor)
1359 :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1362 ["Beginning of function" verilog-beg-of-defun
1364 :help "Move backward to the beginning of the current function or procedure"]
1365 ["End of function" verilog-end-of-defun
1367 :help "Move forward to the end of the current function or procedure"]
1368 ["Mark function" verilog-mark-defun
1370 :help "Mark the current Verilog function or procedure"]
1371 ["Goto function/module" verilog-goto-defun
1372 :help "Move to specified Verilog module/task/function"]
1373 ["Move to beginning of block" electric-verilog-backward-sexp
1374 :help "Move backward over one balanced expression"]
1375 ["Move to end of block" electric-verilog-forward-sexp
1376 :help "Move forward over one balanced expression"]
1379 ["Comment Region" verilog-comment-region
1380 :help "Put marked area into a comment"]
1381 ["UnComment Region" verilog-uncomment-region
1382 :help "Uncomment an area commented with Comment Region"]
1383 ["Multi-line comment insert" verilog-star-comment
1384 :help "Insert Verilog /* */ comment at point"]
1385 ["Lint error to comment" verilog-lint-off
1386 :help "Convert a Verilog linter warning line into a disable statement"]
1390 :help "Perform compilation-action (above) on the current buffer"]
1391 ["AUTO, Save, Compile" verilog-auto-save-compile
1392 :help "Recompute AUTOs, save buffer, and compile"]
1393 ["Next Compile Error" next-error
1394 :help "Visit next compilation error message and corresponding source code"]
1395 ["Ignore Lint Warning at point" verilog-lint-off
1396 :help "Convert a Verilog linter warning line into a disable statement"]
1398 ["Line up declarations around point" verilog-pretty-declarations
1399 :help "Line up declarations around point"]
1400 ["Line up equations around point" verilog-pretty-expr
1401 :help "Line up expressions around point"]
1402 ["Redo/insert comments on every end" verilog-label-be
1403 :help "Label matching begin ... end statements"]
1404 ["Expand [x:y] vector line" verilog-expand-vector
1405 :help "Take a signal vector on the current line and expand it to multiple lines"]
1406 ["Insert begin-end block" verilog-insert-block
1407 :help "Insert begin ... end"]
1408 ["Complete word" verilog-complete-word
1409 :help "Complete word at point"]
1411 ["Recompute AUTOs" verilog-auto
1412 :help "Expand AUTO meta-comment statements"]
1413 ["Kill AUTOs" verilog-delete-auto
1414 :help "Remove AUTO expansions"]
1415 ["Diff AUTOs" verilog-diff-auto
1416 :help "Show differences in AUTO expansions"]
1417 ["Inject AUTOs" verilog-inject-auto
1418 :help "Inject AUTOs into legacy non-AUTO buffer"]
1420 ["AUTO General" (describe-function 'verilog-auto)
1421 :help "Help introduction on AUTOs"]
1422 ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
1423 :help "Help on verilog-library-flags"]
1424 ["AUTO Library Path" (describe-variable 'verilog-library-directories)
1425 :help "Help on verilog-library-directories"]
1426 ["AUTO Library Files" (describe-variable 'verilog-library-files)
1427 :help "Help on verilog-library-files"]
1428 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
1429 :help "Help on verilog-library-extensions"]
1430 ["AUTO `define Reading" (describe-function 'verilog-read-defines)
1431 :help "Help on reading `defines"]
1432 ["AUTO `include Reading" (describe-function 'verilog-read-includes)
1433 :help "Help on parsing `includes"]
1434 ["AUTOARG" (describe-function 'verilog-auto-arg)
1435 :help "Help on AUTOARG - declaring module port list"]
1436 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
1437 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1438 ["AUTOASSIGNMODPORT" (describe-function 'verilog-auto-assign-modport)
1439 :help "Help on AUTOASSIGNMODPORT - creating assignments to/from modports"]
1440 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
1441 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1442 ["AUTOINOUTIN" (describe-function 'verilog-auto-inout-in)
1443 :help "Help on AUTOINOUTIN - copying i/o from another file as all inputs"]
1444 ["AUTOINOUTMODPORT" (describe-function 'verilog-auto-inout-modport)
1445 :help "Help on AUTOINOUTMODPORT - copying i/o from an interface modport"]
1446 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1447 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1448 ["AUTOINOUTPARAM" (describe-function 'verilog-auto-inout-param)
1449 :help "Help on AUTOINOUTPARAM - copying parameters from another file"]
1450 ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
1451 :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
1452 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1453 :help "Help on AUTOINOUT - adding inouts from cells"]
1454 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1455 :help "Help on AUTOINPUT - adding inputs from cells"]
1456 ["AUTOINST" (describe-function 'verilog-auto-inst)
1457 :help "Help on AUTOINST - adding pins for cells"]
1458 ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
1459 :help "Help on expanding Verilog-2001 .* pins"]
1460 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
1461 :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
1462 ["AUTOLOGIC" (describe-function 'verilog-auto-logic)
1463 :help "Help on AUTOLOGIC - declaring logic signals"]
1464 ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
1465 :help "Help on AUTOOUTPUT - adding outputs from cells"]
1466 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
1467 :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
1468 ["AUTOREG" (describe-function 'verilog-auto-reg)
1469 :help "Help on AUTOREG - declaring registers for non-wires"]
1470 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
1471 :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
1472 ["AUTORESET" (describe-function 'verilog-auto-reset)
1473 :help "Help on AUTORESET - resetting always blocks"]
1474 ["AUTOSENSE" (describe-function 'verilog-auto-sense)
1475 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1476 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1477 :help "Help on AUTOTIEOFF - tying off unused outputs"]
1478 ["AUTOUNDEF" (describe-function 'verilog-auto-undef)
1479 :help "Help on AUTOUNDEF - undefine all local defines"]
1480 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1481 :help "Help on AUTOUNUSED - terminating unused inputs"]
1482 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
1483 :help "Help on AUTOWIRE - declaring wires for cells"]
1486 ["Submit bug report" verilog-submit-bug-report
1487 :help "Submit via mail a bug report on verilog-mode.el"]
1488 ["Version and FAQ" verilog-faq
1489 :help "Show the current version, and where to get the FAQ etc"]
1490 ["Customize Verilog Mode..." verilog-customize
1491 :help "Customize variables and other settings used by Verilog-Mode"]
1492 ["Customize Verilog Fonts & Colors" verilog-font-customize
1493 :help "Customize fonts used by Verilog-Mode."])))
1496 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1497 (verilog-easy-menu-filter
1499 ["Header" verilog-sk-header
1500 :help "Insert a header block at the top of file"]
1501 ["Comment" verilog-sk-comment
1502 :help "Insert a comment block"]
1504 ["Module" verilog-sk-module
1505 :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
1506 ["OVM Class" verilog-sk-ovm-class
1507 :help "Insert an OVM class block"]
1508 ["UVM Class" verilog-sk-uvm-class
1509 :help "Insert an UVM class block"]
1510 ["Primitive" verilog-sk-primitive
1511 :help "Insert a primitive .. (.. );.. endprimitive block"]
1513 ["Input" verilog-sk-input
1514 :help "Insert an input declaration"]
1515 ["Output" verilog-sk-output
1516 :help "Insert an output declaration"]
1517 ["Inout" verilog-sk-inout
1518 :help "Insert an inout declaration"]
1519 ["Wire" verilog-sk-wire
1520 :help "Insert a wire declaration"]
1521 ["Reg" verilog-sk-reg
1522 :help "Insert a register declaration"]
1523 ["Define thing under point as a register" verilog-sk-define-signal
1524 :help "Define signal under point as a register at the top of the module"]
1526 ["Initial" verilog-sk-initial
1527 :help "Insert an initial begin .. end block"]
1528 ["Always" verilog-sk-always
1529 :help "Insert an always @(AS) begin .. end block"]
1530 ["Function" verilog-sk-function
1531 :help "Insert a function .. begin .. end endfunction block"]
1532 ["Task" verilog-sk-task
1533 :help "Insert a task .. begin .. end endtask block"]
1534 ["Specify" verilog-sk-specify
1535 :help "Insert a specify .. endspecify block"]
1536 ["Generate" verilog-sk-generate
1537 :help "Insert a generate .. endgenerate block"]
1539 ["Begin" verilog-sk-begin
1540 :help "Insert a begin .. end block"]
1542 :help "Insert an if (..) begin .. end block"]
1543 ["(if) else" verilog-sk-else-if
1544 :help "Insert an else if (..) begin .. end block"]
1545 ["For" verilog-sk-for
1546 :help "Insert a for (...) begin .. end block"]
1547 ["While" verilog-sk-while
1548 :help "Insert a while (...) begin .. end block"]
1549 ["Fork" verilog-sk-fork
1550 :help "Insert a fork begin .. end .. join block"]
1551 ["Repeat" verilog-sk-repeat
1552 :help "Insert a repeat (..) begin .. end block"]
1553 ["Case" verilog-sk-case
1554 :help "Insert a case block, prompting for details"]
1555 ["Casex" verilog-sk-casex
1556 :help "Insert a casex (...) item: begin.. end endcase block"]
1557 ["Casez" verilog-sk-casez
1558 :help "Insert a casez (...) item: begin.. end endcase block"])))
1560 (defvar verilog-mode-abbrev-table nil
1561 "Abbrev table in use in Verilog-mode buffers.")
1563 (define-abbrev-table 'verilog-mode-abbrev-table ())
1564 (verilog-define-abbrev verilog-mode-abbrev-table "class" "" 'verilog-sk-ovm-class)
1565 (verilog-define-abbrev verilog-mode-abbrev-table "always" "" 'verilog-sk-always)
1566 (verilog-define-abbrev verilog-mode-abbrev-table "begin" nil `verilog-sk-begin)
1567 (verilog-define-abbrev verilog-mode-abbrev-table "case" "" `verilog-sk-case)
1568 (verilog-define-abbrev verilog-mode-abbrev-table "for" "" `verilog-sk-for)
1569 (verilog-define-abbrev verilog-mode-abbrev-table "generate" "" `verilog-sk-generate)
1570 (verilog-define-abbrev verilog-mode-abbrev-table "initial" "" `verilog-sk-initial)
1571 (verilog-define-abbrev verilog-mode-abbrev-table "fork" "" `verilog-sk-fork)
1572 (verilog-define-abbrev verilog-mode-abbrev-table "module" "" `verilog-sk-module)
1573 (verilog-define-abbrev verilog-mode-abbrev-table "primitive" "" `verilog-sk-primitive)
1574 (verilog-define-abbrev verilog-mode-abbrev-table "repeat" "" `verilog-sk-repeat)
1575 (verilog-define-abbrev verilog-mode-abbrev-table "specify" "" `verilog-sk-specify)
1576 (verilog-define-abbrev verilog-mode-abbrev-table "task" "" `verilog-sk-task)
1577 (verilog-define-abbrev verilog-mode-abbrev-table "while" "" `verilog-sk-while)
1578 (verilog-define-abbrev verilog-mode-abbrev-table "casex" "" `verilog-sk-casex)
1579 (verilog-define-abbrev verilog-mode-abbrev-table "casez" "" `verilog-sk-casez)
1580 (verilog-define-abbrev verilog-mode-abbrev-table "if" "" `verilog-sk-if)
1581 (verilog-define-abbrev verilog-mode-abbrev-table "else if" "" `verilog-sk-else-if)
1582 (verilog-define-abbrev verilog-mode-abbrev-table "assign" "" `verilog-sk-assign)
1583 (verilog-define-abbrev verilog-mode-abbrev-table "function" "" `verilog-sk-function)
1584 (verilog-define-abbrev verilog-mode-abbrev-table "input" "" `verilog-sk-input)
1585 (verilog-define-abbrev verilog-mode-abbrev-table "output" "" `verilog-sk-output)
1586 (verilog-define-abbrev verilog-mode-abbrev-table "inout" "" `verilog-sk-inout)
1587 (verilog-define-abbrev verilog-mode-abbrev-table "wire" "" `verilog-sk-wire)
1588 (verilog-define-abbrev verilog-mode-abbrev-table "reg" "" `verilog-sk-reg)
1594 (defsubst verilog-within-string ()
1595 (nth 3 (parse-partial-sexp (point-at-bol) (point))))
1597 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1598 "Replace occurrences of FROM-STRING with TO-STRING.
1599 FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace.
1600 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1601 will break, as the o's continuously replace. xa -> x works ok though."
1602 ;; Hopefully soon to an Emacs built-in
1603 ;; Also note \ in the replacement prevent multiple replacements; IE
1604 ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
1605 ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
1607 (while (string-match from-string string start)
1608 (setq string (replace-match to-string fixedcase literal string)
1609 start (min (length string) (+ (match-beginning 0) (length to-string)))))
1612 (defsubst verilog-string-remove-spaces (string)
1613 "Remove spaces surrounding STRING."
1615 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
1616 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
1619 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
1620 ; checkdoc-params: (REGEXP BOUND NOERROR)
1621 "Like `re-search-forward', but skips over match in comments or strings."
1622 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1624 (re-search-forward REGEXP BOUND NOERROR)
1625 (setq mdata (match-data))
1626 (and (verilog-skip-forward-comment-or-string)
1628 (setq mdata '(nil nil))
1632 (store-match-data mdata)
1635 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
1636 ; checkdoc-params: (REGEXP BOUND NOERROR)
1637 "Like `re-search-backward', but skips over match in comments or strings."
1638 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1640 (re-search-backward REGEXP BOUND NOERROR)
1641 (setq mdata (match-data))
1642 (and (verilog-skip-backward-comment-or-string)
1644 (setq mdata '(nil nil))
1648 (store-match-data mdata)
1651 (defsubst verilog-re-search-forward-quick (regexp bound noerror)
1652 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
1653 but trashes match data and is faster for REGEXP that doesn't match often.
1654 This uses `verilog-scan' and text properties to ignore comments,
1655 so there may be a large up front penalty for the first search."
1657 (while (and (not pt)
1658 (re-search-forward regexp bound noerror))
1659 (if (verilog-inside-comment-or-string-p)
1660 (re-search-forward "[/\"\n]" nil t) ;; Only way a comment or quote can end
1661 (setq pt (match-end 0))))
1664 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
1665 ; checkdoc-params: (REGEXP BOUND NOERROR)
1666 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
1667 but trashes match data and is faster for REGEXP that doesn't match often.
1668 This uses `verilog-scan' and text properties to ignore comments,
1669 so there may be a large up front penalty for the first search."
1671 (while (and (not pt)
1672 (re-search-backward regexp bound noerror))
1673 (if (verilog-inside-comment-or-string-p)
1674 (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
1675 (setq pt (match-beginning 0))))
1678 (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
1679 "Like `re-search-forward', but first search for SUBSTR constant.
1680 Then searched for the normal REGEXP (which contains SUBSTR), with given
1681 BOUND and NOERROR. The REGEXP must fit within a single line.
1682 This speeds up complicated regexp matches."
1683 ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
1684 ;; thus require matches to be on one line, and use beginning-of-line.
1686 (while (and (not done)
1687 (search-forward substr bound noerror))
1690 (setq done (re-search-forward regexp (point-at-eol) noerror)))
1691 (unless (and (<= (match-beginning 0) (point))
1692 (>= (match-end 0) (point)))
1694 (when done (goto-char done))
1696 ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1698 (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
1699 "Like `re-search-backward', but first search for SUBSTR constant.
1700 Then searched for the normal REGEXP (which contains SUBSTR), with given
1701 BOUND and NOERROR. The REGEXP must fit within a single line.
1702 This speeds up complicated regexp matches."
1703 ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
1704 ;; thus require matches to be on one line, and use beginning-of-line.
1706 (while (and (not done)
1707 (search-backward substr bound noerror))
1710 (setq done (re-search-backward regexp (point-at-bol) noerror)))
1711 (unless (and (<= (match-beginning 0) (point))
1712 (>= (match-end 0) (point)))
1714 (when done (goto-char done))
1716 ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1718 (defun verilog-delete-trailing-whitespace ()
1719 "Delete trailing spaces or tabs, but not newlines nor linefeeds.
1720 Also add missing final newline.
1722 To call this from the command line, see \\[verilog-batch-diff-auto].
1724 To call on \\[verilog-auto], set `verilog-auto-delete-trailing-whitespace'."
1725 ;; Similar to `delete-trailing-whitespace' but that's not present in XEmacs
1727 (goto-char (point-min))
1728 (while (re-search-forward "[ \t]+$" nil t) ;; Not syntactic WS as no formfeed
1729 (replace-match "" nil nil))
1730 (goto-char (point-max))
1731 (unless (bolp) (insert "\n"))))
1733 (defvar compile-command)
1735 ;; compilation program
1736 (defun verilog-set-compile-command ()
1737 "Function to compute shell command to compile Verilog.
1739 This reads `verilog-tool' and sets `compile-command'. This specifies the
1740 program that executes when you type \\[compile] or
1741 \\[verilog-auto-save-compile].
1743 By default `verilog-tool' uses a Makefile if one exists in the
1744 current directory. If not, it is set to the `verilog-linter',
1745 `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
1746 or `verilog-simulator' variables, as selected with the Verilog ->
1747 \"Choose Compilation Action\" menu.
1749 You should set `verilog-tool' or the other variables to the path and
1750 arguments for your Verilog simulator. For example:
1753 \"(cd /tmp; surecov %s)\".
1755 In the former case, the path to the current buffer is concat'ed to the
1756 value of `verilog-tool'; in the later, the path to the current buffer is
1757 substituted for the %s.
1759 Where __FLAGS__ appears in the string `verilog-current-flags'
1760 will be substituted.
1762 Where __FILE__ appears in the string, the variable
1763 `buffer-file-name' of the current buffer, without the directory
1764 portion, will be substituted."
1767 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1768 (file-exists-p "Makefile"))
1769 (set (make-local-variable 'compile-command) "make "))
1771 (set (make-local-variable 'compile-command)
1773 (if (string-match "%s" (eval verilog-tool))
1774 (format (eval verilog-tool) (or buffer-file-name ""))
1775 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1777 (verilog-modify-compile-command))
1779 (defun verilog-expand-command (command)
1780 "Replace meta-information in COMMAND and return it.
1781 Where __FLAGS__ appears in the string `verilog-current-flags'
1782 will be substituted. Where __FILE__ appears in the string, the
1783 current buffer's file-name, without the directory portion, will
1785 (setq command (verilog-string-replace-matches
1786 ;; Note \\b only works if under verilog syntax table
1787 "\\b__FLAGS__\\b" (verilog-current-flags)
1789 (setq command (verilog-string-replace-matches
1790 "\\b__FILE__\\b" (file-name-nondirectory
1791 (or (buffer-file-name) ""))
1795 (defun verilog-modify-compile-command ()
1796 "Update `compile-command' using `verilog-expand-command'."
1798 (stringp compile-command)
1799 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1800 (set (make-local-variable 'compile-command)
1801 (verilog-expand-command compile-command))))
1803 (if (featurep 'xemacs)
1804 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1805 (defun verilog-error-regexp-add-xemacs ()
1806 "Teach XEmacs about verilog errors.
1807 Called by `compilation-mode-hook'. This allows \\[next-error] to
1810 (if (boundp 'compilation-error-regexp-systems-alist)
1812 (not (equal compilation-error-regexp-systems-list 'all))
1813 (not (member compilation-error-regexp-systems-list 'verilog)))
1814 (push 'verilog compilation-error-regexp-systems-list)))
1815 (if (boundp 'compilation-error-regexp-alist-alist)
1816 (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
1817 (setcdr compilation-error-regexp-alist-alist
1818 (cons verilog-error-regexp-xemacs-alist
1819 (cdr compilation-error-regexp-alist-alist)))))
1820 (if (boundp 'compilation-font-lock-keywords)
1822 (set (make-local-variable 'compilation-font-lock-keywords)
1823 verilog-error-font-lock-keywords)
1824 (font-lock-set-defaults)))
1825 ;; Need to re-run compilation-error-regexp builder
1826 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
1827 (compilation-build-compilation-error-regexp-alist))
1830 ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
1831 (defun verilog-error-regexp-add-emacs ()
1832 "Tell Emacs compile that we are Verilog.
1833 Called by `compilation-mode-hook'. This allows \\[next-error] to
1836 (if (boundp 'compilation-error-regexp-alist-alist)
1838 (if (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
1841 (push (car item) compilation-error-regexp-alist)
1842 (push item compilation-error-regexp-alist-alist)
1844 verilog-error-regexp-emacs-alist)))))
1846 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
1847 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
1849 (defconst verilog-directive-re
1851 (verilog-regexp-words
1853 "`case" "`default" "`define" "`else" "`elsif" "`endfor" "`endif"
1854 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
1855 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
1856 "`time_scale" "`undef" "`while" ))))
1858 (defconst verilog-directive-re-1
1859 (concat "[ \t]*" verilog-directive-re))
1861 (defconst verilog-directive-begin
1862 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
1864 (defconst verilog-directive-middle
1865 "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
1867 (defconst verilog-directive-end
1868 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
1870 (defconst verilog-ovm-begin-re
1874 "`ovm_component_utils_begin"
1875 "`ovm_component_param_utils_begin"
1876 "`ovm_field_utils_begin"
1877 "`ovm_object_utils_begin"
1878 "`ovm_object_param_utils_begin"
1879 "`ovm_sequence_utils_begin"
1880 "`ovm_sequencer_utils_begin"
1883 (defconst verilog-ovm-end-re
1887 "`ovm_component_utils_end"
1888 "`ovm_field_utils_end"
1889 "`ovm_object_utils_end"
1890 "`ovm_sequence_utils_end"
1891 "`ovm_sequencer_utils_end"
1894 (defconst verilog-uvm-begin-re
1898 "`uvm_component_utils_begin"
1899 "`uvm_component_param_utils_begin"
1900 "`uvm_field_utils_begin"
1901 "`uvm_object_utils_begin"
1902 "`uvm_object_param_utils_begin"
1903 "`uvm_sequence_utils_begin"
1904 "`uvm_sequencer_utils_begin"
1907 (defconst verilog-uvm-end-re
1911 "`uvm_component_utils_end"
1912 "`uvm_field_utils_end"
1913 "`uvm_object_utils_end"
1914 "`uvm_sequence_utils_end"
1915 "`uvm_sequencer_utils_end"
1918 (defconst verilog-vmm-begin-re
1922 "`vmm_data_member_begin"
1923 "`vmm_env_member_begin"
1924 "`vmm_scenario_member_begin"
1925 "`vmm_subenv_member_begin"
1926 "`vmm_xactor_member_begin"
1929 (defconst verilog-vmm-end-re
1933 "`vmm_data_member_end"
1934 "`vmm_env_member_end"
1935 "`vmm_scenario_member_end"
1936 "`vmm_subenv_member_end"
1937 "`vmm_xactor_member_end"
1940 (defconst verilog-vmm-statement-re
1944 ;; "`vmm_xactor_member_enum_array"
1945 "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
1946 ;; "`vmm_xactor_member_scalar_array"
1947 ;; "`vmm_xactor_member_scalar"
1950 (defconst verilog-ovm-statement-re
1959 "`ovm_analysis_imp_decl"
1960 "`ovm_blocking_get_imp_decl"
1961 "`ovm_blocking_get_peek_imp_decl"
1962 "`ovm_blocking_master_imp_decl"
1963 "`ovm_blocking_peek_imp_decl"
1964 "`ovm_blocking_put_imp_decl"
1965 "`ovm_blocking_slave_imp_decl"
1966 "`ovm_blocking_transport_imp_decl"
1967 "`ovm_component_registry"
1968 "`ovm_component_registry_param"
1969 "`ovm_component_utils"
1972 "`ovm_declare_sequence_lib"
1979 "`ovm_field_aa_int_byte"
1980 "`ovm_field_aa_int_byte_unsigned"
1981 "`ovm_field_aa_int_int"
1982 "`ovm_field_aa_int_int_unsigned"
1983 "`ovm_field_aa_int_integer"
1984 "`ovm_field_aa_int_integer_unsigned"
1985 "`ovm_field_aa_int_key"
1986 "`ovm_field_aa_int_longint"
1987 "`ovm_field_aa_int_longint_unsigned"
1988 "`ovm_field_aa_int_shortint"
1989 "`ovm_field_aa_int_shortint_unsigned"
1990 "`ovm_field_aa_int_string"
1991 "`ovm_field_aa_object_int"
1992 "`ovm_field_aa_object_string"
1993 "`ovm_field_aa_string_int"
1994 "`ovm_field_aa_string_string"
1995 "`ovm_field_array_int"
1996 "`ovm_field_array_object"
1997 "`ovm_field_array_string"
2002 "`ovm_field_queue_int"
2003 "`ovm_field_queue_object"
2004 "`ovm_field_queue_string"
2005 "`ovm_field_sarray_int"
2010 "`ovm_get_peek_imp_decl"
2017 "`ovm_master_imp_decl"
2019 "`ovm_non_blocking_transport_imp_decl"
2020 "`ovm_nonblocking_get_imp_decl"
2021 "`ovm_nonblocking_get_peek_imp_decl"
2022 "`ovm_nonblocking_master_imp_decl"
2023 "`ovm_nonblocking_peek_imp_decl"
2024 "`ovm_nonblocking_put_imp_decl"
2025 "`ovm_nonblocking_slave_imp_decl"
2026 "`ovm_object_registry"
2027 "`ovm_object_registry_param"
2029 "`ovm_peek_imp_decl"
2030 "`ovm_phase_func_decl"
2031 "`ovm_phase_task_decl"
2032 "`ovm_print_aa_int_object"
2033 "`ovm_print_aa_string_int"
2034 "`ovm_print_aa_string_object"
2035 "`ovm_print_aa_string_string"
2036 "`ovm_print_array_int"
2037 "`ovm_print_array_object"
2038 "`ovm_print_array_string"
2039 "`ovm_print_object_queue"
2040 "`ovm_print_queue_int"
2041 "`ovm_print_string_queue"
2044 "`ovm_rand_send_with"
2046 "`ovm_sequence_utils"
2047 "`ovm_slave_imp_decl"
2048 "`ovm_transport_imp_decl"
2049 "`ovm_update_sequence_lib"
2050 "`ovm_update_sequence_lib_and_item"
2053 "`static_message") nil )))
2055 (defconst verilog-uvm-statement-re
2060 "`uvm_analysis_imp_decl"
2061 "`uvm_blocking_get_imp_decl"
2062 "`uvm_blocking_get_peek_imp_decl"
2063 "`uvm_blocking_master_imp_decl"
2064 "`uvm_blocking_peek_imp_decl"
2065 "`uvm_blocking_put_imp_decl"
2066 "`uvm_blocking_slave_imp_decl"
2067 "`uvm_blocking_transport_imp_decl"
2068 "`uvm_component_param_utils"
2069 "`uvm_component_registry"
2070 "`uvm_component_registry_param"
2071 "`uvm_component_utils"
2074 "`uvm_create_seq" ;; Undocumented in 1.1
2075 "`uvm_declare_p_sequencer"
2076 "`uvm_declare_sequence_lib" ;; Deprecated in 1.1
2079 "`uvm_do_callbacks_exit_on"
2080 "`uvm_do_obj_callbacks"
2081 "`uvm_do_obj_callbacks_exit_on"
2084 "`uvm_do_on_pri_with"
2088 "`uvm_do_seq" ;; Undocumented in 1.1
2089 "`uvm_do_seq_with" ;; Undocumented in 1.1
2092 "`uvm_error_context"
2094 "`uvm_fatal_context"
2095 "`uvm_field_aa_int_byte"
2096 "`uvm_field_aa_int_byte_unsigned"
2097 "`uvm_field_aa_int_enum"
2098 "`uvm_field_aa_int_int"
2099 "`uvm_field_aa_int_int_unsigned"
2100 "`uvm_field_aa_int_integer"
2101 "`uvm_field_aa_int_integer_unsigned"
2102 "`uvm_field_aa_int_key"
2103 "`uvm_field_aa_int_longint"
2104 "`uvm_field_aa_int_longint_unsigned"
2105 "`uvm_field_aa_int_shortint"
2106 "`uvm_field_aa_int_shortint_unsigned"
2107 "`uvm_field_aa_int_string"
2108 "`uvm_field_aa_object_int"
2109 "`uvm_field_aa_object_string"
2110 "`uvm_field_aa_string_int"
2111 "`uvm_field_aa_string_string"
2112 "`uvm_field_array_enum"
2113 "`uvm_field_array_int"
2114 "`uvm_field_array_object"
2115 "`uvm_field_array_string"
2120 "`uvm_field_queue_enum"
2121 "`uvm_field_queue_int"
2122 "`uvm_field_queue_object"
2123 "`uvm_field_queue_string"
2125 "`uvm_field_sarray_enum"
2126 "`uvm_field_sarray_int"
2127 "`uvm_field_sarray_object"
2128 "`uvm_field_sarray_string"
2131 "`uvm_file" ;; Undocumented in 1.1, use `__FILE__
2133 "`uvm_get_peek_imp_decl"
2136 "`uvm_line" ;; Undocumented in 1.1, use `__LINE__
2137 "`uvm_master_imp_decl"
2138 "`uvm_non_blocking_transport_imp_decl" ;; Deprecated in 1.1
2139 "`uvm_nonblocking_get_imp_decl"
2140 "`uvm_nonblocking_get_peek_imp_decl"
2141 "`uvm_nonblocking_master_imp_decl"
2142 "`uvm_nonblocking_peek_imp_decl"
2143 "`uvm_nonblocking_put_imp_decl"
2144 "`uvm_nonblocking_slave_imp_decl"
2145 "`uvm_nonblocking_transport_imp_decl"
2146 "`uvm_object_param_utils"
2147 "`uvm_object_registry"
2148 "`uvm_object_registry_param" ;; Undocumented in 1.1
2162 "`uvm_peek_imp_decl"
2165 "`uvm_rand_send_pri"
2166 "`uvm_rand_send_pri_with"
2167 "`uvm_rand_send_with"
2168 "`uvm_record_attribute"
2173 "`uvm_sequence_utils" ;; Deprecated in 1.1
2174 "`uvm_set_super_type"
2175 "`uvm_slave_imp_decl"
2176 "`uvm_transport_imp_decl"
2178 "`uvm_unpack_arrayN"
2184 "`uvm_unpack_queueN"
2186 "`uvm_unpack_sarray"
2187 "`uvm_unpack_sarrayN"
2188 "`uvm_unpack_string"
2189 "`uvm_update_sequence_lib" ;; Deprecated in 1.1
2190 "`uvm_update_sequence_lib_and_item" ;; Deprecated in 1.1
2192 "`uvm_warning_context") nil )))
2196 ;; Regular expressions used to calculate indent, etc.
2198 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
2205 (defconst verilog-assignment-operator-re
2209 ;; blocking assignment_operator
2210 "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
2211 ;; non blocking assignment operator
2214 "==" "!=" "===" "!===" "<=" ">=" "==\?" "!=\?"
2219 ;; Is this a legal verilog operator?
2223 (defconst verilog-assignment-operation-re
2225 ; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)"
2226 ; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)"
2227 "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" ))
2229 (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
2230 (defconst verilog-property-re
2231 (concat "\\(" verilog-label-re "\\)?"
2232 "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
2233 ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
2235 (defconst verilog-no-indent-begin-re
2236 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>")
2238 (defconst verilog-ends-re
2239 ;; Parenthesis indicate type of keyword found
2241 "\\(\\<else\\>\\)\\|" ; 1
2242 "\\(\\<if\\>\\)\\|" ; 2
2243 "\\(\\<assert\\>\\)\\|" ; 3
2244 "\\(\\<end\\>\\)\\|" ; 3.1
2245 "\\(\\<endcase\\>\\)\\|" ; 4
2246 "\\(\\<endfunction\\>\\)\\|" ; 5
2247 "\\(\\<endtask\\>\\)\\|" ; 6
2248 "\\(\\<endspecify\\>\\)\\|" ; 7
2249 "\\(\\<endtable\\>\\)\\|" ; 8
2250 "\\(\\<endgenerate\\>\\)\\|" ; 9
2251 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
2252 "\\(\\<endclass\\>\\)\\|" ; 11
2253 "\\(\\<endgroup\\>\\)\\|" ; 12
2255 "\\(\\<`vmm_data_member_end\\>\\)\\|"
2256 "\\(\\<`vmm_env_member_end\\>\\)\\|"
2257 "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
2258 "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
2259 "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
2261 "\\(\\<`ovm_component_utils_end\\>\\)\\|"
2262 "\\(\\<`ovm_field_utils_end\\>\\)\\|"
2263 "\\(\\<`ovm_object_utils_end\\>\\)\\|"
2264 "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
2265 "\\(\\<`ovm_sequencer_utils_end\\>\\)"
2267 "\\(\\<`uvm_component_utils_end\\>\\)\\|"
2268 "\\(\\<`uvm_field_utils_end\\>\\)\\|"
2269 "\\(\\<`uvm_object_utils_end\\>\\)\\|"
2270 "\\(\\<`uvm_sequence_utils_end\\>\\)\\|"
2271 "\\(\\<`uvm_sequencer_utils_end\\>\\)"
2274 (defconst verilog-auto-end-comment-lines-re
2275 ;; Matches to names in this list cause auto-end-commenting
2277 verilog-directive-re "\\)\\|\\("
2279 (verilog-regexp-words
2307 ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
2308 ;;; verilog-end-block-ordered-re matches exactly the same strings.
2309 (defconst verilog-end-block-ordered-re
2310 ;; Parenthesis indicate type of keyword found
2311 (concat "\\(\\<endcase\\>\\)\\|" ; 1
2312 "\\(\\<end\\>\\)\\|" ; 2
2313 "\\(\\<end" ; 3, but not used
2314 "\\(" ; 4, but not used
2315 "\\(function\\)\\|" ; 5
2317 "\\(module\\)\\|" ; 7
2318 "\\(primitive\\)\\|" ; 8
2319 "\\(interface\\)\\|" ; 9
2320 "\\(package\\)\\|" ; 10
2321 "\\(class\\)\\|" ; 11
2322 "\\(group\\)\\|" ; 12
2323 "\\(program\\)\\|" ; 13
2324 "\\(sequence\\)\\|" ; 14
2325 "\\(clocking\\)\\|" ; 15
2327 (defconst verilog-end-block-re
2329 (verilog-regexp-words
2331 `("end" ;; closes begin
2332 "endcase" ;; closes any of case, casex casez or randcase
2333 "join" "join_any" "join_none" ;; closes fork
2348 "`ovm_component_utils_end"
2349 "`ovm_field_utils_end"
2350 "`ovm_object_utils_end"
2351 "`ovm_sequence_utils_end"
2352 "`ovm_sequencer_utils_end"
2354 "`uvm_component_utils_end"
2355 "`uvm_field_utils_end"
2356 "`uvm_object_utils_end"
2357 "`uvm_sequence_utils_end"
2358 "`uvm_sequencer_utils_end"
2360 "`vmm_data_member_end"
2361 "`vmm_env_member_end"
2362 "`vmm_scenario_member_end"
2363 "`vmm_subenv_member_end"
2364 "`vmm_xactor_member_end"
2368 (defconst verilog-endcomment-reason-re
2369 ;; Parenthesis indicate type of keyword found
2371 "\\(\\<begin\\>\\)\\|" ; 1
2372 "\\(\\<else\\>\\)\\|" ; 2
2373 "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
2374 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" ; 4
2375 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" ; 5
2376 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" ; 6
2377 "\\(\\<fork\\>\\)\\|" ; 7
2378 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
2380 verilog-property-re "\\|"
2381 "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
2382 "\\(\\<clocking\\>\\)\\|"
2383 "\\(\\<task\\>\\)\\|"
2384 "\\(\\<function\\>\\)\\|"
2385 "\\(\\<initial\\>\\)\\|"
2386 "\\(\\<interface\\>\\)\\|"
2387 "\\(\\<package\\>\\)\\|"
2388 "\\(\\<final\\>\\)\\|"
2390 "\\(\\<while\\>\\)\\|"
2391 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
2392 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
2395 (defconst verilog-named-block-re "begin[ \t]*:")
2397 ;; These words begin a block which can occur inside a module which should be indented,
2398 ;; and closed with the respective word from the end-block list
2400 (defconst verilog-beg-block-re
2402 (verilog-regexp-words
2404 "case" "casex" "casez" "randcase"
2414 "`ovm_component_utils_begin"
2415 "`ovm_component_param_utils_begin"
2416 "`ovm_field_utils_begin"
2417 "`ovm_object_utils_begin"
2418 "`ovm_object_param_utils_begin"
2419 "`ovm_sequence_utils_begin"
2420 "`ovm_sequencer_utils_begin"
2422 "`uvm_component_utils_begin"
2423 "`uvm_component_param_utils_begin"
2424 "`uvm_field_utils_begin"
2425 "`uvm_object_utils_begin"
2426 "`uvm_object_param_utils_begin"
2427 "`uvm_sequence_utils_begin"
2428 "`uvm_sequencer_utils_begin"
2430 "`vmm_data_member_begin"
2431 "`vmm_env_member_begin"
2432 "`vmm_scenario_member_begin"
2433 "`vmm_subenv_member_begin"
2434 "`vmm_xactor_member_begin"
2436 ;; These are the same words, in a specific order in the regular
2437 ;; expression so that matching will work nicely for
2438 ;; verilog-forward-sexp and verilog-calc-indent
2439 (defconst verilog-beg-block-re-ordered
2440 ( concat "\\(\\<begin\\>\\)" ;1
2441 "\\|\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
2442 "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
2443 "\\|\\(\\<class\\>\\)" ;6
2444 "\\|\\(\\<table\\>\\)" ;7
2445 "\\|\\(\\<specify\\>\\)" ;8
2446 "\\|\\(\\<function\\>\\)" ;9
2447 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<function\\>\\)" ;10
2448 "\\|\\(\\<task\\>\\)" ;14
2449 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;15
2450 "\\|\\(\\<generate\\>\\)" ;18
2451 "\\|\\(\\<covergroup\\>\\)" ;16 20
2452 "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17 21
2453 "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25
2454 "\\|\\(\\<clocking\\>\\)" ;22 27
2455 "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;28
2456 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
2460 (defconst verilog-end-block-ordered-rry
2461 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2462 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
2463 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2464 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
2465 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
2466 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
2467 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
2468 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
2469 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
2470 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
2471 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
2472 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
2473 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
2476 (defconst verilog-nameable-item-re
2478 (verilog-regexp-words
2481 "join" "join_any" "join_none"
2498 (defconst verilog-declaration-opener
2500 (verilog-regexp-words
2501 `("module" "begin" "task" "function"))))
2503 (defconst verilog-declaration-prefix-re
2505 (verilog-regexp-words
2508 "inout" "input" "output" "ref"
2510 "const" "static" "protected" "local"
2512 "localparam" "parameter" "var"
2516 (defconst verilog-declaration-core-re
2518 (verilog-regexp-words
2520 ;; port direction (by themselves)
2521 "inout" "input" "output"
2522 ;; integer_atom_type
2523 "byte" "shortint" "int" "longint" "integer" "time"
2524 ;; integer_vector_type
2527 "shortreal" "real" "realtime"
2529 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
2531 "string" "event" "chandle" "virtual" "enum" "genvar"
2534 "mailbox" "semaphore"
2536 (defconst verilog-declaration-re
2537 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
2538 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
2539 (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?")
2540 (defconst verilog-optional-signed-range-re
2542 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
2543 (defconst verilog-macroexp-re "`\\sw+")
2545 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
2546 (defconst verilog-declaration-re-2-no-macro
2547 (concat "\\s-*" verilog-declaration-re
2548 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2550 (defconst verilog-declaration-re-2-macro
2551 (concat "\\s-*" verilog-declaration-re
2552 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2553 "\\|\\(" verilog-macroexp-re "\\)"
2555 (defconst verilog-declaration-re-1-macro
2556 (concat "^" verilog-declaration-re-2-macro))
2558 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
2560 (defconst verilog-defun-re
2561 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
2562 (defconst verilog-end-defun-re
2563 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
2564 (defconst verilog-zero-indent-re
2565 (concat verilog-defun-re "\\|" verilog-end-defun-re))
2566 (defconst verilog-inst-comment-re
2567 (eval-when-compile (verilog-regexp-words `("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced"))))
2569 (defconst verilog-behavioral-block-beg-re
2570 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
2571 "function" "task"))))
2572 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
2573 (defconst verilog-indent-re
2575 (verilog-regexp-words
2578 "always" "always_latch" "always_ff" "always_comb"
2580 ; "unique" "priority"
2581 "case" "casex" "casez" "randcase" "endcase"
2583 "clocking" "endclocking"
2584 "config" "endconfig"
2585 "covergroup" "endgroup"
2586 "fork" "join" "join_any" "join_none"
2587 "function" "endfunction"
2589 "generate" "endgenerate"
2591 "interface" "endinterface"
2592 "module" "macromodule" "endmodule"
2593 "package" "endpackage"
2594 "primitive" "endprimitive"
2595 "program" "endprogram"
2596 "property" "endproperty"
2597 "sequence" "randsequence" "endsequence"
2598 "specify" "endspecify"
2605 "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
2606 "`while" "`endwhile"
2611 "`protect" "`endprotect"
2612 "`switch" "`endswitch"
2616 "`ovm_component_utils_begin"
2617 "`ovm_component_param_utils_begin"
2618 "`ovm_field_utils_begin"
2619 "`ovm_object_utils_begin"
2620 "`ovm_object_param_utils_begin"
2621 "`ovm_sequence_utils_begin"
2622 "`ovm_sequencer_utils_begin"
2624 "`ovm_component_utils_end"
2625 "`ovm_field_utils_end"
2626 "`ovm_object_utils_end"
2627 "`ovm_sequence_utils_end"
2628 "`ovm_sequencer_utils_end"
2630 "`uvm_component_utils_begin"
2631 "`uvm_component_param_utils_begin"
2632 "`uvm_field_utils_begin"
2633 "`uvm_object_utils_begin"
2634 "`uvm_object_param_utils_begin"
2635 "`uvm_sequence_utils_begin"
2636 "`uvm_sequencer_utils_begin"
2638 "`uvm_component_utils_end" ;; Typo in spec, it's not uvm_component_end
2639 "`uvm_field_utils_end"
2640 "`uvm_object_utils_end"
2641 "`uvm_sequence_utils_end"
2642 "`uvm_sequencer_utils_end"
2644 "`vmm_data_member_begin"
2645 "`vmm_env_member_begin"
2646 "`vmm_scenario_member_begin"
2647 "`vmm_subenv_member_begin"
2648 "`vmm_xactor_member_begin"
2650 "`vmm_data_member_end"
2651 "`vmm_env_member_end"
2652 "`vmm_scenario_member_end"
2653 "`vmm_subenv_member_end"
2654 "`vmm_xactor_member_end"
2657 (defconst verilog-defun-level-not-generate-re
2659 (verilog-regexp-words
2660 `( "module" "macromodule" "primitive" "class" "program"
2661 "interface" "package" "config"))))
2663 (defconst verilog-defun-level-re
2665 (verilog-regexp-words
2667 `( "module" "macromodule" "primitive" "class" "program"
2668 "interface" "package" "config")
2669 `( "initial" "final" "always" "always_comb" "always_ff"
2670 "always_latch" "endtask" "endfunction" )))))
2672 (defconst verilog-defun-level-generate-only-re
2674 (verilog-regexp-words
2675 `( "initial" "final" "always" "always_comb" "always_ff"
2676 "always_latch" "endtask" "endfunction" ))))
2678 (defconst verilog-cpp-level-re
2680 (verilog-regexp-words
2682 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2684 (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
2685 (defconst verilog-extended-case-re "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
2686 (defconst verilog-extended-complete-re
2687 (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
2688 "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
2689 "\\|\\(\\(\\<import\\>\\s-+\\)?\\(\"DPI-C\"\\s-+\\)?\\(\\<pure\\>\\s-+\\)?\\(function\\>\\|task\\>\\)\\)"
2690 "\\|" verilog-extended-case-re ))
2691 (defconst verilog-basic-complete-re
2693 (verilog-regexp-words
2695 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
2696 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
2697 "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
2699 (defconst verilog-complete-reg
2701 verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)"))
2703 (defconst verilog-end-statement-re
2704 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
2705 verilog-end-block-re "\\)"))
2707 (defconst verilog-endcase-re
2708 (concat verilog-extended-case-re "\\|"
2713 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
2714 "String used to mark beginning of excluded text.")
2715 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
2716 "String used to mark end of excluded text.")
2717 (defconst verilog-preprocessor-re
2719 (verilog-regexp-words
2721 "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else"
2724 (defconst verilog-keywords
2725 '( "`case" "`default" "`define" "`else" "`endfor" "`endif"
2726 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
2727 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
2728 "`time_scale" "`undef" "`while"
2730 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
2731 "assert" "assign" "assume" "automatic" "before" "begin" "bind"
2732 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
2733 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
2734 "config" "const" "constraint" "context" "continue" "cover"
2735 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
2736 "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
2737 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
2738 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
2739 "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
2740 "endtask" "enum" "event" "expect" "export" "extends" "extern"
2741 "final" "first_match" "for" "force" "foreach" "forever" "fork"
2742 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
2743 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
2744 "include" "initial" "inout" "input" "inside" "instance" "int"
2745 "integer" "interface" "intersect" "join" "join_any" "join_none"
2746 "large" "liblist" "library" "local" "localparam" "logic"
2747 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
2748 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
2749 "notif0" "notif1" "null" "or" "output" "package" "packed"
2750 "parameter" "pmos" "posedge" "primitive" "priority" "program"
2751 "property" "protected" "pull0" "pull1" "pulldown" "pullup"
2752 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2753 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
2754 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
2755 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
2756 "showcancelled" "signed" "small" "solve" "specify" "specparam"
2757 "static" "string" "strong0" "strong1" "struct" "super" "supply0"
2758 "supply1" "table" "tagged" "task" "this" "throughout" "time"
2759 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
2760 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
2761 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
2762 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
2763 "wire" "with" "within" "wor" "xnor" "xor"
2765 "accept_on" "checker" "endchecker" "eventually" "global" "implies"
2766 "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
2767 "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
2768 "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
2770 "List of Verilog keywords.")
2772 (defconst verilog-comment-start-regexp "//\\|/\\*"
2773 "Dual comment value for `comment-start-regexp'.")
2775 (defvar verilog-mode-syntax-table
2776 (let ((table (make-syntax-table)))
2777 ;; Populate the syntax TABLE.
2778 (modify-syntax-entry ?\\ "\\" table)
2779 (modify-syntax-entry ?+ "." table)
2780 (modify-syntax-entry ?- "." table)
2781 (modify-syntax-entry ?= "." table)
2782 (modify-syntax-entry ?% "." table)
2783 (modify-syntax-entry ?< "." table)
2784 (modify-syntax-entry ?> "." table)
2785 (modify-syntax-entry ?& "." table)
2786 (modify-syntax-entry ?| "." table)
2787 (modify-syntax-entry ?` "w" table)
2788 (modify-syntax-entry ?_ "w" table)
2789 (modify-syntax-entry ?\' "." table)
2791 ;; Set up TABLE to handle block and line style comments.
2792 (if (featurep 'xemacs)
2794 ;; XEmacs (formerly Lucid) has the best implementation
2795 (modify-syntax-entry ?/ ". 1456" table)
2796 (modify-syntax-entry ?* ". 23" table)
2797 (modify-syntax-entry ?\n "> b" table))
2798 ;; Emacs does things differently, but we can work with it
2799 (modify-syntax-entry ?/ ". 124b" table)
2800 (modify-syntax-entry ?* ". 23" table)
2801 (modify-syntax-entry ?\n "> b" table))
2803 "Syntax table used in Verilog mode buffers.")
2805 (defvar verilog-font-lock-keywords nil
2806 "Default highlighting for Verilog mode.")
2808 (defvar verilog-font-lock-keywords-1 nil
2809 "Subdued level highlighting for Verilog mode.")
2811 (defvar verilog-font-lock-keywords-2 nil
2812 "Medium level highlighting for Verilog mode.
2813 See also `verilog-font-lock-extra-types'.")
2815 (defvar verilog-font-lock-keywords-3 nil
2816 "Gaudy level highlighting for Verilog mode.
2817 See also `verilog-font-lock-extra-types'.")
2819 (defvar verilog-font-lock-translate-off-face
2820 'verilog-font-lock-translate-off-face
2821 "Font to use for translated off regions.")
2822 (defface verilog-font-lock-translate-off-face
2825 (:background "gray90" :italic t ))
2828 (:background "gray10" :italic t ))
2829 (((class grayscale) (background light))
2830 (:foreground "DimGray" :italic t))
2831 (((class grayscale) (background dark))
2832 (:foreground "LightGray" :italic t))
2834 "Font lock mode face used to background highlight translate-off regions."
2835 :group 'font-lock-highlighting-faces)
2837 (defvar verilog-font-lock-p1800-face
2838 'verilog-font-lock-p1800-face
2839 "Font to use for p1800 keywords.")
2840 (defface verilog-font-lock-p1800-face
2843 (:foreground "DarkOrange3" :bold t ))
2846 (:foreground "orange1" :bold t ))
2848 "Font lock mode face used to highlight P1800 keywords."
2849 :group 'font-lock-highlighting-faces)
2851 (defvar verilog-font-lock-ams-face
2852 'verilog-font-lock-ams-face
2853 "Font to use for Analog/Mixed Signal keywords.")
2854 (defface verilog-font-lock-ams-face
2857 (:foreground "Purple" :bold t ))
2860 (:foreground "orange1" :bold t ))
2862 "Font lock mode face used to highlight AMS keywords."
2863 :group 'font-lock-highlighting-faces)
2865 (defvar verilog-font-grouping-keywords-face
2866 'verilog-font-lock-grouping-keywords-face
2867 "Font to use for Verilog Grouping Keywords (such as begin..end).")
2868 (defface verilog-font-lock-grouping-keywords-face
2871 (:foreground "red4" :bold t ))
2874 (:foreground "red4" :bold t ))
2876 "Font lock mode face used to highlight verilog grouping keywords."
2877 :group 'font-lock-highlighting-faces)
2879 (let* ((verilog-type-font-keywords
2883 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
2884 "event" "genvar" "inout" "input" "integer" "localparam"
2885 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or"
2886 "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
2887 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
2888 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
2889 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
2890 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
2891 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
2894 (verilog-pragma-keywords
2897 '("surefire" "auto" "synopsys" "rtl_synthesis" "verilint" "leda" "0in"
2900 (verilog-1800-2005-keywords
2903 '("alias" "assert" "assume" "automatic" "before" "bind"
2904 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
2905 "clocking" "config" "const" "constraint" "context" "continue"
2906 "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
2907 "dist" "do" "edge" "endclass" "endclocking" "endconfig"
2908 "endgroup" "endprogram" "endproperty" "endsequence" "enum"
2909 "expect" "export" "extends" "extern" "first_match" "foreach"
2910 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
2911 "illegal_bins" "import" "incdir" "include" "inside" "instance"
2912 "int" "intersect" "large" "liblist" "library" "local" "longint"
2913 "matches" "medium" "modport" "new" "noshowcancelled" "null"
2914 "packed" "program" "property" "protected" "pull0" "pull1"
2915 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2916 "randcase" "randsequence" "ref" "release" "return" "scalared"
2917 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
2918 "specparam" "static" "string" "strong0" "strong1" "struct"
2919 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
2920 "type" "union" "unsigned" "use" "var" "virtual" "void"
2921 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
2924 (verilog-1800-2009-keywords
2927 '("accept_on" "checker" "endchecker" "eventually" "global"
2928 "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
2929 "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
2930 "sync_accept_on" "sync_reject_on" "unique0" "until"
2931 "until_with" "untyped" "weak" ) nil )))
2933 (verilog-ams-keywords
2936 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
2937 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
2938 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
2939 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
2940 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
2941 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
2942 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
2943 "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
2944 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
2945 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
2946 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
2948 (verilog-font-keywords
2952 "assign" "case" "casex" "casez" "randcase" "deassign"
2953 "default" "disable" "else" "endcase" "endfunction"
2954 "endgenerate" "endinterface" "endmodule" "endprimitive"
2955 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
2956 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
2957 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
2958 "package" "endpackage" "always" "always_comb" "always_ff"
2959 "always_latch" "posedge" "primitive" "priority" "release"
2960 "repeat" "specify" "table" "task" "unique" "wait" "while"
2961 "class" "program" "endclass" "endprogram"
2964 (verilog-font-grouping-keywords
2967 '( "begin" "end" ) nil ))))
2969 (setq verilog-font-lock-keywords
2971 ;; Fontify all builtin keywords
2972 (concat "\\<\\(" verilog-font-keywords "\\|"
2973 ;; And user/system tasks and functions
2974 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
2976 ;; Fontify all types
2977 (if verilog-highlight-grouping-keywords
2978 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2979 'verilog-font-lock-ams-face)
2980 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2981 'font-lock-type-face))
2982 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
2983 'font-lock-type-face)
2984 ;; Fontify IEEE-1800-2005 keywords appropriately
2985 (if verilog-highlight-p1800-keywords
2986 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
2987 'verilog-font-lock-p1800-face)
2988 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
2989 'font-lock-type-face))
2990 ;; Fontify IEEE-1800-2009 keywords appropriately
2991 (if verilog-highlight-p1800-keywords
2992 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
2993 'verilog-font-lock-p1800-face)
2994 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
2995 'font-lock-type-face))
2996 ;; Fontify Verilog-AMS keywords
2997 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
2998 'verilog-font-lock-ams-face)))
3000 (setq verilog-font-lock-keywords-1
3001 (append verilog-font-lock-keywords
3003 ;; Fontify module definitions
3005 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
3006 '(1 font-lock-keyword-face)
3007 '(3 font-lock-function-name-face 'prepend))
3008 ;; Fontify function definitions
3010 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
3011 '(1 font-lock-keyword-face)
3012 '(3 font-lock-constant-face prepend))
3013 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
3014 (1 font-lock-keyword-face)
3015 (2 font-lock-constant-face append))
3016 '("\\<function\\>\\s-+\\(\\sw+\\)"
3017 1 'font-lock-constant-face append))))
3019 (setq verilog-font-lock-keywords-2
3020 (append verilog-font-lock-keywords-1
3023 (concat "\\(//\\s-*\\(" verilog-pragma-keywords "\\)\\s-.*\\)")
3024 ;; Fontify escaped names
3025 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
3026 ;; Fontify macro definitions/ uses
3027 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
3028 'font-lock-preprocessor-face
3029 'font-lock-type-face))
3030 ;; Fontify delays/numbers
3031 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
3032 0 font-lock-type-face append)
3033 ;; Fontify instantiation names
3034 '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
3037 (setq verilog-font-lock-keywords-3
3038 (append verilog-font-lock-keywords-2
3039 (when verilog-highlight-translate-off
3041 ;; Fontify things in translate off regions
3042 '(verilog-match-translate-off
3043 (0 'verilog-font-lock-translate-off-face prepend))
3047 ;; Buffer state preservation
3049 (defmacro verilog-save-buffer-state (&rest body)
3050 "Execute BODY forms, saving state around insignificant change.
3051 Changes in text properties like `face' or `syntax-table' are
3052 considered insignificant. This macro allows text properties to
3053 be changed, even in a read-only buffer.
3055 A change is considered significant if it affects the buffer text
3056 in any way that isn't completely restored again. Any
3057 user-visible changes to the buffer must not be within a
3058 `verilog-save-buffer-state'."
3059 ;; From c-save-buffer-state
3060 `(let* ((modified (buffer-modified-p))
3061 (buffer-undo-list t)
3062 (inhibit-read-only t)
3063 (inhibit-point-motion-hooks t)
3064 (verilog-no-change-functions t)
3065 before-change-functions
3066 after-change-functions
3068 buffer-file-name ; Prevent primitives checking
3069 buffer-file-truename) ; for file modification
3074 (set-buffer-modified-p nil)))))
3076 (defmacro verilog-save-no-change-functions (&rest body)
3077 "Execute BODY forms, disabling all change hooks in BODY.
3078 For insignificant changes, see instead `verilog-save-buffer-state'."
3079 `(let* ((inhibit-point-motion-hooks t)
3080 (verilog-no-change-functions t)
3081 before-change-functions
3082 after-change-functions)
3085 (defvar verilog-save-font-mod-hooked nil
3086 "Local variable when inside a `verilog-save-font-mods' block.")
3087 (make-variable-buffer-local 'verilog-save-font-mod-hooked)
3089 (defmacro verilog-save-font-mods (&rest body)
3090 "Execute BODY forms, disabling text modifications to allow performing BODY.
3091 Includes temporary disabling of `font-lock' to restore the buffer
3092 to full text form for parsing. Additional actions may be specified with
3093 `verilog-before-save-font-hook' and `verilog-after-save-font-hook'."
3094 ;; Before version 20, match-string with font-lock returns a
3095 ;; vector that is not equal to the string. IE if on "input"
3096 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
3097 `(let* ((hooked (unless verilog-save-font-mod-hooked
3098 (verilog-run-hooks 'verilog-before-save-font-hook)
3100 (verilog-save-font-mod-hooked t)
3101 (fontlocked (when (and (boundp 'font-lock-mode) font-lock-mode)
3107 (when fontlocked (font-lock-mode t))
3108 (when hooked (verilog-run-hooks 'verilog-after-save-font-hook)))))
3111 ;; Comment detection and caching
3113 (defvar verilog-scan-cache-preserving nil
3114 "If set, the specified buffer's comment properties are static.
3115 Buffer changes will be ignored. See `verilog-inside-comment-or-string-p'
3116 and `verilog-scan'.")
3118 (defvar verilog-scan-cache-tick nil
3119 "Modification tick at which `verilog-scan' was last completed.")
3120 (make-variable-buffer-local 'verilog-scan-cache-tick)
3122 (defun verilog-scan-cache-flush ()
3123 "Flush the `verilog-scan' cache."
3124 (setq verilog-scan-cache-tick nil))
3126 (defun verilog-scan-cache-ok-p ()
3127 "Return t iff the scan cache is up to date."
3128 (or (and verilog-scan-cache-preserving
3129 (eq verilog-scan-cache-preserving (current-buffer))
3130 verilog-scan-cache-tick)
3131 (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
3133 (defmacro verilog-save-scan-cache (&rest body)
3134 "Execute the BODY forms, allowing scan cache preservation within BODY.
3135 This requires that insertions must use `verilog-insert'."
3136 ;; If the buffer is out of date, trash it, as we'll not check later the tick
3137 ;; Note this must work properly if there's multiple layers of calls
3138 ;; to verilog-save-scan-cache even with differing ticks.
3140 (unless (verilog-scan-cache-ok-p) ;; Must be before let
3141 (setq verilog-scan-cache-tick nil))
3142 (let* ((verilog-scan-cache-preserving (current-buffer)))
3145 (defun verilog-scan-region (beg end)
3146 "Parse between BEG and END for `verilog-inside-comment-or-string-p'.
3147 This creates v-cmts properties where comments are in force."
3148 ;; Why properties and not overlays? Overlays have much slower non O(1)
3150 ;; This function is warm - called on every verilog-insert
3153 (verilog-save-buffer-state
3156 (while (< (point) end)
3157 (cond ((looking-at "//")
3159 (or (search-forward "\n" end t)
3161 ;; "1+": The leading // or /* itself isn't considered as
3162 ;; being "inside" the comment, so that a (search-backward)
3163 ;; that lands at the start of the // won't mis-indicate
3164 ;; it's inside a comment. Also otherwise it would be
3165 ;; hard to find a commented out /*AS*/ vs one that isn't
3166 (put-text-property (1+ pt) (point) 'v-cmts t))
3167 ((looking-at "/\\*")
3169 (or (search-forward "*/" end t)
3170 ;; No error - let later code indicate it so we can
3171 ;; use inside functions on-the-fly
3172 ;;(error "%s: Unmatched /* */, at char %d"
3173 ;; (verilog-point-text) (point))
3175 (put-text-property (1+ pt) (point) 'v-cmts t))
3178 (or (re-search-forward "[^\\]\"" end t) ;; don't forward-char first, since we look for a non backslash first
3179 ;; No error - let later code indicate it so we can
3181 (put-text-property (1+ pt) (point) 'v-cmts t))
3184 (if (re-search-forward "[/\"]" end t)
3186 (goto-char end))))))))))
3188 (defun verilog-scan ()
3189 "Parse the buffer, marking all comments with properties.
3190 Also assumes any text inserted since `verilog-scan-cache-tick'
3191 either is ok to parse as a non-comment, or `verilog-insert' was used."
3192 ;; See also `verilog-scan-debug' and `verilog-scan-and-debug'
3193 (unless (verilog-scan-cache-ok-p)
3195 (verilog-save-buffer-state
3197 (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
3198 verilog-scan-cache-preserving verilog-scan-cache-tick
3199 (buffer-chars-modified-tick)))
3200 (remove-text-properties (point-min) (point-max) '(v-cmts nil))
3201 (verilog-scan-region (point-min) (point-max))
3202 (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
3203 (when verilog-debug (message "Scanning... done"))))))
3205 (defun verilog-scan-debug ()
3206 "For debugging, show with display face results of `verilog-scan'."
3208 ;;(if dbg (setq dbg (concat dbg (format "verilog-scan-debug\n"))))
3210 (goto-char (point-min))
3211 (remove-text-properties (point-min) (point-max) '(face nil))
3213 (cond ((get-text-property (point) 'v-cmts)
3214 (put-text-property (point) (1+ (point)) `face 'underline)
3215 ;;(if dbg (setq dbg (concat dbg (format " v-cmts at %S\n" (point)))))
3218 (goto-char (or (next-property-change (point)) (point-max))))))))
3220 (defun verilog-scan-and-debug ()
3221 "For debugging, run `verilog-scan' and `verilog-scan-debug'."
3222 (let (verilog-scan-cache-preserving
3223 verilog-scan-cache-tick)
3224 (goto-char (point-min))
3226 (verilog-scan-debug)))
3228 (defun verilog-inside-comment-or-string-p (&optional pos)
3229 "Check if optional point POS is inside a comment.
3230 This may require a slow pre-parse of the buffer with `verilog-scan'
3231 to establish comment properties on all text."
3232 ;; This function is very hot
3235 (and (>= pos (point-min))
3236 (get-text-property pos 'v-cmts))
3237 (get-text-property (point) 'v-cmts)))
3239 (defun verilog-insert (&rest stuff)
3240 "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
3241 Any insert that includes a comment must have the entire comment
3242 inserted using a single call to `verilog-insert'."
3245 (insert (car stuff))
3246 (setq stuff (cdr stuff)))
3247 (verilog-scan-region pt (point))))
3251 (defun verilog-declaration-end ()
3252 (search-forward ";"))
3254 (defun verilog-point-text (&optional pointnum)
3255 "Return text describing where POINTNUM or current point is (for errors).
3256 Use filename, if current buffer being edited shorten to just buffer name."
3257 (concat (or (and (equal (window-buffer (selected-window)) (current-buffer))
3261 ":" (int-to-string (1+ (count-lines (point-min) (or pointnum (point)))))))
3263 (defun electric-verilog-backward-sexp ()
3264 "Move backward over one balanced expression."
3266 ;; before that see if we are in a comment
3267 (verilog-backward-sexp))
3269 (defun electric-verilog-forward-sexp ()
3270 "Move forward over one balanced expression."
3272 ;; before that see if we are in a comment
3273 (verilog-forward-sexp))
3275 ;;;used by hs-minor-mode
3276 (defun verilog-forward-sexp-function (arg)
3278 (verilog-backward-sexp)
3279 (verilog-forward-sexp)))
3282 (defun verilog-backward-sexp ()
3287 (if (not (looking-at "\\<"))
3290 ((verilog-skip-backward-comment-or-string))
3291 ((looking-at "\\<else\\>")
3293 verilog-end-block-re
3294 "\\|\\(\\<else\\>\\)"
3295 "\\|\\(\\<if\\>\\)"))
3296 (while (and (not found)
3297 (verilog-re-search-backward reg nil 'move))
3299 ((match-end 1) ; matched verilog-end-block-re
3300 ; try to leap back to matching outward block by striding across
3301 ; indent level changing tokens then immediately
3302 ; previous line governs indentation.
3303 (verilog-leap-to-head))
3304 ((match-end 2) ; else, we're in deep
3305 (setq elsec (1+ elsec)))
3306 ((match-end 3) ; found it
3307 (setq elsec (1- elsec))
3309 ;; Now previous line describes syntax
3310 (setq found 't))))))
3311 ((looking-at verilog-end-block-re)
3312 (verilog-leap-to-head))
3313 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
3316 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
3318 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
3320 (verilog-re-search-backward "\\<class\\>" nil 'move))
3322 (verilog-re-search-backward "\\<program\\>" nil 'move))
3324 (verilog-re-search-backward "\\<interface\\>" nil 'move))
3326 (verilog-re-search-backward "\\<package\\>" nil 'move))
3329 (backward-sexp 1))))
3334 (defun verilog-forward-sexp ()
3339 (if (not (looking-at "\\<"))
3342 ((verilog-skip-forward-comment-or-string)
3343 (verilog-forward-syntactic-ws))
3344 ((looking-at verilog-beg-block-re-ordered)
3347 ;; Search forward for matching end
3348 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
3350 ;; Search forward for matching endcase
3351 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
3352 (setq md 3) ;; ender is third item in regexp
3355 ;; might be "disable fork" or "wait fork"
3359 (looking-at verilog-disable-fork-re)
3360 (and (looking-at "fork")
3362 (setq here (point)) ;; sometimes a fork is just a fork
3364 (looking-at verilog-disable-fork-re))))
3365 (progn ;; it is a disable fork; ignore it
3366 (goto-char (match-end 0))
3369 (progn ;; it is a nice simple fork
3370 (goto-char here) ;; return from looking for "disable fork"
3371 ;; Search forward for matching join
3372 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))))
3374 ;; Search forward for matching endclass
3375 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
3378 ;; Search forward for matching endtable
3379 (setq reg "\\<endtable\\>" )
3382 ;; Search forward for matching endspecify
3383 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
3385 ;; Search forward for matching endfunction
3386 (setq reg "\\<endfunction\\>" )
3389 ;; Search forward for matching endfunction
3390 (setq reg "\\<endfunction\\>" )
3393 ;; Search forward for matching endtask
3394 (setq reg "\\<endtask\\>" )
3397 ;; Search forward for matching endtask
3398 (setq reg "\\<endtask\\>" )
3401 ;; Search forward for matching endgenerate
3402 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
3404 ;; Search forward for matching endgroup
3405 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
3407 ;; Search forward for matching endproperty
3408 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
3410 ;; Search forward for matching endsequence
3411 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
3412 (setq md 3)) ; 3 to get to endsequence in the reg above
3414 ;; Search forward for matching endclocking
3415 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
3422 (while (verilog-re-search-forward reg nil 'move)
3424 ((match-end md) ; a closer in regular expression, so we are climbing out
3425 (setq depth (1- depth))
3426 (if (= 0 depth) ; we are out!
3428 ((match-end 1) ; an opener in the r-e, so we are in deeper now
3429 (setq here (point)) ; remember where we started
3430 (goto-char (match-beginning 1))
3433 (looking-at verilog-disable-fork-re)
3434 (and (looking-at "fork")
3437 (looking-at verilog-disable-fork-re))))
3438 (progn ;; it is a disable fork; another false alarm
3439 (goto-char (match-end 0)))
3440 (progn ;; it is a simple fork (or has nothing to do with fork)
3442 (setq depth (1+ depth))))))))))
3443 (if (verilog-re-search-forward reg nil 'move)
3444 (throw 'skip 1))))))
3446 ((looking-at (concat
3447 "\\(\\<\\(macro\\)?module\\>\\)\\|"
3448 "\\(\\<primitive\\>\\)\\|"
3449 "\\(\\<class\\>\\)\\|"
3450 "\\(\\<program\\>\\)\\|"
3451 "\\(\\<interface\\>\\)\\|"
3452 "\\(\\<package\\>\\)"))
3455 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
3457 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
3459 (verilog-re-search-forward "\\<endclass\\>" nil 'move))
3461 (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
3463 (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
3465 (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
3468 (if (= (following-char) ?\) )
3470 (forward-sexp 1)))))
3473 (if (= (following-char) ?\) )
3475 (forward-sexp 1))))))
3477 (defun verilog-declaration-beg ()
3478 (verilog-re-search-backward verilog-declaration-re (bobp) t))
3484 (defvar verilog-which-tool 1)
3486 (define-derived-mode verilog-mode prog-mode "Verilog"
3487 "Major mode for editing Verilog code.
3488 \\<verilog-mode-map>
3489 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
3490 AUTOs can improve coding efficiency.
3492 Use \\[verilog-faq] for a pointer to frequently asked questions.
3494 NEWLINE, TAB indents for Verilog code.
3495 Delete converts tabs to spaces as it moves back.
3497 Supports highlighting.
3499 Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
3500 with no args, if that value is non-nil.
3502 Variables controlling indentation/edit style:
3504 variable `verilog-indent-level' (default 3)
3505 Indentation of Verilog statements with respect to containing block.
3506 `verilog-indent-level-module' (default 3)
3507 Absolute indentation of Module level Verilog statements.
3508 Set to 0 to get initial and always statements lined up
3509 on the left side of your screen.
3510 `verilog-indent-level-declaration' (default 3)
3511 Indentation of declarations with respect to containing block.
3512 Set to 0 to get them list right under containing block.
3513 `verilog-indent-level-behavioral' (default 3)
3514 Indentation of first begin in a task or function block
3515 Set to 0 to get such code to lined up underneath the task or
3517 `verilog-indent-level-directive' (default 1)
3518 Indentation of `ifdef/`endif blocks.
3519 `verilog-cexp-indent' (default 1)
3520 Indentation of Verilog statements broken across lines i.e.:
3523 `verilog-case-indent' (default 2)
3524 Indentation for case statements.
3525 `verilog-auto-newline' (default nil)
3526 Non-nil means automatically newline after semicolons and the punctuation
3528 `verilog-auto-indent-on-newline' (default t)
3529 Non-nil means automatically indent line after newline.
3530 `verilog-tab-always-indent' (default t)
3531 Non-nil means TAB in Verilog mode should always reindent the current line,
3532 regardless of where in the line point is when the TAB command is used.
3533 `verilog-indent-begin-after-if' (default t)
3534 Non-nil means to indent begin statements following a preceding
3535 if, else, while, for and repeat statements, if any. Otherwise,
3536 the begin is lined up with the preceding token. If t, you get:
3538 begin // amount of indent based on `verilog-cexp-indent'
3542 `verilog-auto-endcomments' (default t)
3543 Non-nil means a comment /* ... */ is set after the ends which ends
3544 cases, tasks, functions and modules.
3545 The type and name of the object will be set between the braces.
3546 `verilog-minimum-comment-distance' (default 10)
3547 Minimum distance (in lines) between begin and end required before a comment
3548 will be inserted. Setting this variable to zero results in every
3549 end acquiring a comment; the default avoids too many redundant
3550 comments in tight quarters.
3551 `verilog-auto-lineup' (default 'declarations)
3552 List of contexts where auto lineup of code should be done.
3554 Variables controlling other actions:
3556 `verilog-linter' (default surelint)
3557 Unix program to call to run the lint checker. This is the default
3558 command for \\[compile-command] and \\[verilog-auto-save-compile].
3560 See \\[customize] for the complete list of variables.
3562 AUTO expansion functions are, in part:
3564 \\[verilog-auto] Expand AUTO statements.
3565 \\[verilog-delete-auto] Remove the AUTOs.
3566 \\[verilog-inject-auto] Insert AUTOs for the first time.
3568 Some other functions are:
3570 \\[verilog-complete-word] Complete word with appropriate possibilities.
3571 \\[verilog-mark-defun] Mark function.
3572 \\[verilog-beg-of-defun] Move to beginning of current function.
3573 \\[verilog-end-of-defun] Move to end of current function.
3574 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
3576 \\[verilog-comment-region] Put marked area in a comment.
3577 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
3578 \\[verilog-insert-block] Insert begin ... end.
3579 \\[verilog-star-comment] Insert /* ... */.
3581 \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
3582 \\[verilog-sk-begin] Insert a begin .. end block.
3583 \\[verilog-sk-case] Insert a case block, prompting for details.
3584 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
3585 \\[verilog-sk-generate] Insert a generate .. endgenerate block.
3586 \\[verilog-sk-header] Insert a header block at the top of file.
3587 \\[verilog-sk-initial] Insert an initial begin .. end block.
3588 \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
3589 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
3590 \\[verilog-sk-ovm-class] Insert an OVM Class block.
3591 \\[verilog-sk-uvm-class] Insert an UVM Class block.
3592 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
3593 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
3594 \\[verilog-sk-specify] Insert a specify .. endspecify block.
3595 \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
3596 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
3597 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
3598 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
3599 \\[verilog-sk-if] Insert an if (..) begin .. end block.
3600 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
3601 \\[verilog-sk-comment] Insert a comment block.
3602 \\[verilog-sk-assign] Insert an assign .. = ..; statement.
3603 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
3604 \\[verilog-sk-input] Insert an input declaration, prompting for details.
3605 \\[verilog-sk-output] Insert an output declaration, prompting for details.
3606 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
3607 \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
3608 \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
3609 \\[verilog-sk-reg] Insert a register declaration, prompting for details.
3610 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
3612 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
3613 Key bindings specific to `verilog-mode-map' are:
3615 \\{verilog-mode-map}"
3616 :abbrev-table verilog-mode-abbrev-table
3617 (set (make-local-variable 'beginning-of-defun-function)
3618 'verilog-beg-of-defun)
3619 (set (make-local-variable 'end-of-defun-function)
3620 'verilog-end-of-defun)
3621 (set-syntax-table verilog-mode-syntax-table)
3622 (set (make-local-variable 'indent-line-function)
3623 #'verilog-indent-line-relative)
3624 (setq comment-indent-function 'verilog-comment-indent)
3625 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
3626 (set (make-local-variable 'comment-start) "// ")
3627 (set (make-local-variable 'comment-end) "")
3628 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
3629 (set (make-local-variable 'comment-multi-line) nil)
3630 ;; Set up for compilation
3631 (setq verilog-which-tool 1)
3632 (setq verilog-tool 'verilog-linter)
3633 (verilog-set-compile-command)
3634 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables
3635 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
3638 (when (featurep 'xemacs)
3639 (easy-menu-add verilog-stmt-menu)
3640 (easy-menu-add verilog-menu)
3641 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
3643 ;; Stuff for GNU Emacs
3644 (set (make-local-variable 'font-lock-defaults)
3645 `((verilog-font-lock-keywords
3646 verilog-font-lock-keywords-1
3647 verilog-font-lock-keywords-2
3648 verilog-font-lock-keywords-3)
3650 ,(if (functionp 'syntax-ppss)
3651 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
3652 ;; font-lock-beginning-of-syntax-function, so
3653 ;; font-lock-beginning-of-syntax-function, can't use
3654 ;; verilog-beg-of-defun.
3656 'verilog-beg-of-defun)))
3657 ;;------------------------------------------------------------
3658 ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
3659 ;; all buffer local:
3660 (unless noninteractive ;; Else can't see the result, and change hooks are slow
3661 (when (featurep 'xemacs)
3662 (make-local-hook 'font-lock-mode-hook)
3663 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
3664 (make-local-hook 'after-change-functions))
3665 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
3666 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
3667 (add-hook 'after-change-functions 'verilog-highlight-region t t))
3669 ;; Tell imenu how to handle Verilog.
3670 (set (make-local-variable 'imenu-generic-expression)
3671 verilog-imenu-generic-expression)
3672 ;; Tell which-func-modes that imenu knows about verilog
3673 (when (and (boundp 'which-func-modes) (listp which-func-modes))
3674 (add-to-list 'which-func-modes 'verilog-mode))
3676 (when (boundp 'hs-special-modes-alist)
3677 (unless (assq 'verilog-mode hs-special-modes-alist)
3678 (setq hs-special-modes-alist
3679 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
3680 verilog-forward-sexp-function)
3681 hs-special-modes-alist))))
3684 (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local)
3685 ;; verilog-mode-hook call added by define-derived-mode
3690 ;; Electric functions
3692 (defun electric-verilog-terminate-line (&optional arg)
3693 "Terminate line and indent next line.
3694 With optional ARG, remove existing end of line comments."
3696 ;; before that see if we are in a comment
3697 (let ((state (save-excursion (verilog-syntax-ppss))))
3699 ((nth 7 state) ; Inside // comment
3702 (delete-horizontal-space)
3707 (beginning-of-line)))
3708 (verilog-indent-line))
3709 ((nth 4 state) ; Inside any comment (hence /**/)
3711 (verilog-more-comment))
3713 ;; First, check if current line should be indented
3715 (delete-horizontal-space)
3717 (skip-chars-forward " \t")
3718 (if (looking-at verilog-auto-end-comment-lines-re)
3719 (let ((indent-str (verilog-indent-line)))
3720 ;; Maybe we should set some endcomments
3721 (if verilog-auto-endcomments
3722 (verilog-set-auto-endcomments indent-str arg))
3724 (delete-horizontal-space)
3731 (delete-horizontal-space)
3733 ;; see if we should line up assignments
3735 (if (or (eq 'all verilog-auto-lineup)
3736 (eq 'assignments verilog-auto-lineup))
3737 (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
3741 (if verilog-auto-indent-on-newline
3742 (verilog-indent-line)))
3746 (defun electric-verilog-terminate-and-indent ()
3747 "Insert a newline and indent for the next statement."
3749 (electric-verilog-terminate-line 1))
3751 (defun electric-verilog-semi ()
3752 "Insert `;' character and reindent the line."
3754 (verilog-insert-last-command-event)
3756 (if (or (verilog-in-comment-or-string-p)
3757 (verilog-in-escaped-name-p))
3761 (verilog-forward-ws&directives)
3762 (verilog-indent-line))
3763 (if (and verilog-auto-newline
3764 (not (verilog-parenthesis-depth)))
3765 (electric-verilog-terminate-line))))
3767 (defun electric-verilog-semi-with-comment ()
3768 "Insert `;' character, reindent the line and indent for comment."
3773 (verilog-indent-line))
3774 (indent-for-comment))
3776 (defun electric-verilog-colon ()
3777 "Insert `:' and do all indentations except line indent on this line."
3779 (verilog-insert-last-command-event)
3780 ;; Do nothing if within string.
3782 (verilog-within-string)
3783 (not (verilog-in-case-region-p)))
3787 (lim (progn (verilog-beg-of-statement) (point))))
3789 (verilog-backward-case-item lim)
3790 (verilog-indent-line)))
3791 ;; (let ((verilog-tab-always-indent nil))
3792 ;; (verilog-indent-line))
3795 ;;(defun electric-verilog-equal ()
3796 ;; "Insert `=', and do indentation if within block."
3798 ;; (verilog-insert-last-command-event)
3799 ;; Could auto line up expressions, but not yet
3800 ;; (if (eq (car (verilog-calculate-indent)) 'block)
3801 ;; (let ((verilog-tab-always-indent nil))
3802 ;; (verilog-indent-command)))
3805 (defun electric-verilog-tick ()
3806 "Insert back-tick, and indent to column 0 if this is a CPP directive."
3808 (verilog-insert-last-command-event)
3810 (if (verilog-in-directive-p)
3811 (verilog-indent-line))))
3813 (defun electric-verilog-tab ()
3814 "Function called when TAB is pressed in Verilog mode."
3816 ;; If verilog-tab-always-indent, indent the beginning of the line.
3818 ;; The region is active, indent it.
3819 ((and (region-active-p)
3820 (not (eq (region-beginning) (region-end))))
3821 (indent-region (region-beginning) (region-end) nil))
3822 ((or verilog-tab-always-indent
3824 (skip-chars-backward " \t")
3826 (let* ((oldpnt (point))
3830 (skip-chars-forward " \t")
3831 (verilog-indent-line)
3832 (back-to-indentation)
3834 (if (< (point) boi-point)
3835 (back-to-indentation)
3836 (cond ((not verilog-tab-to-comment))
3840 (indent-for-comment)
3841 (when (and (eolp) (= oldpnt (point)))
3842 ; kill existing comment
3844 (re-search-forward comment-start-skip oldpnt 'move)
3845 (goto-char (match-beginning 0))
3846 (skip-chars-backward " \t")
3847 (kill-region (point) oldpnt)))))))
3848 (t (progn (insert "\t")))))
3853 ;; Interactive functions
3856 (defun verilog-indent-buffer ()
3857 "Indent-region the entire buffer as Verilog code.
3858 To call this from the command line, see \\[verilog-batch-indent]."
3861 (indent-region (point-min) (point-max) nil))
3863 (defun verilog-insert-block ()
3864 "Insert Verilog begin ... end; block in the code with right indentation."
3866 (verilog-indent-line)
3868 (electric-verilog-terminate-line)
3870 (electric-verilog-terminate-line)
3873 (verilog-indent-line)))
3875 (defun verilog-star-comment ()
3876 "Insert Verilog star comment at point."
3878 (verilog-indent-line)
3886 (defun verilog-insert-1 (fmt max)
3887 "Use format string FMT to insert integers 0 to MAX - 1.
3888 Inserts one integer per line, at the current column. Stops early
3889 if it reaches the end of the buffer."
3890 (let ((col (current-column))
3894 (insert (format fmt n))
3896 ;; Note that this function does not bother to check for lines
3897 ;; shorter than col.
3901 (move-to-column col))))))
3903 (defun verilog-insert-indices (max)
3904 "Insert a set of indices into a rectangle.
3905 The upper left corner is defined by point. Indices begin with 0
3906 and extend to the MAX - 1. If no prefix arg is given, the user
3907 is prompted for a value. The indices are surrounded by square
3908 brackets \[]. For example, the following code with the point
3909 located after the first 'a' gives:
3915 a = b ==> insert-indices ==> a[ 4] = b
3921 (interactive "NMAX: ")
3922 (verilog-insert-1 "[%3d]" max))
3924 (defun verilog-generate-numbers (max)
3925 "Insert a set of generated numbers into a rectangle.
3926 The upper left corner is defined by point. The numbers are padded to three
3927 digits, starting with 000 and extending to (MAX - 1). If no prefix argument
3928 is supplied, then the user is prompted for the MAX number. Consider the
3929 following code fragment:
3935 buf buf ==> generate-numbers ==> buf buf004
3941 (interactive "NMAX: ")
3942 (verilog-insert-1 "%3.3d" max))
3944 (defun verilog-mark-defun ()
3945 "Mark the current Verilog function (or procedure).
3946 This puts the mark at the end, and point at the beginning."
3948 (if (featurep 'xemacs)
3951 (verilog-end-of-defun)
3953 (verilog-beg-of-defun)
3954 (if (fboundp 'zmacs-activate-region)
3955 (zmacs-activate-region)))
3958 (defun verilog-comment-region (start end)
3959 ; checkdoc-params: (start end)
3960 "Put the region into a Verilog comment.
3961 The comments that are in this area are \"deformed\":
3962 `*)' becomes `!(*' and `}' becomes `!{'.
3963 These deformed comments are returned to normal if you use
3964 \\[verilog-uncomment-region] to undo the commenting.
3966 The commented area starts with `verilog-exclude-str-start', and ends with
3967 `verilog-exclude-str-end'. But if you change these variables,
3968 \\[verilog-uncomment-region] won't recognize the comments."
3971 ;; Insert start and endcomments
3973 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
3974 (not (save-excursion (skip-chars-backward " \t") (bolp))))
3976 (beginning-of-line))
3977 (insert verilog-exclude-str-end)
3982 (insert verilog-exclude-str-start)
3984 ;; Replace end-comments within commented area
3987 (while (re-search-backward "\\*/" start t)
3988 (replace-match "*-/" t t)))
3990 (let ((s+1 (1+ start)))
3991 (while (re-search-backward "/\\*" s+1 t)
3992 (replace-match "/-*" t t))))))
3994 (defun verilog-uncomment-region ()
3995 "Uncomment a commented area; change deformed comments back to normal.
3996 This command does nothing if the pointer is not in a commented
3997 area. See also `verilog-comment-region'."
4000 (let ((start (point))
4002 ;; Find the boundaries of the comment
4004 (setq start (progn (search-backward verilog-exclude-str-start nil t)
4006 (setq end (progn (search-forward verilog-exclude-str-end nil t)
4008 ;; Check if we're really inside a comment
4009 (if (or (equal start (point)) (<= end (point)))
4010 (message "Not standing within commented area.")
4012 ;; Remove endcomment
4015 (let ((pos (point)))
4017 (delete-region pos (1+ (point))))
4018 ;; Change comments back to normal
4020 (while (re-search-backward "\\*-/" start t)
4021 (replace-match "*/" t t)))
4023 (while (re-search-backward "/-\\*" start t)
4024 (replace-match "/*" t t)))
4025 ;; Remove start comment
4028 (let ((pos (point)))
4030 (delete-region pos (1+ (point)))))))))
4032 (defun verilog-beg-of-defun ()
4033 "Move backward to the beginning of the current function or procedure."
4035 (verilog-re-search-backward verilog-defun-re nil 'move))
4037 (defun verilog-beg-of-defun-quick ()
4038 "Move backward to the beginning of the current function or procedure.
4039 Uses `verilog-scan' cache."
4041 (verilog-re-search-backward-quick verilog-defun-re nil 'move))
4043 (defun verilog-end-of-defun ()
4044 "Move forward to the end of the current function or procedure."
4046 (verilog-re-search-forward verilog-end-defun-re nil 'move))
4048 (defun verilog-get-beg-of-defun (&optional warn)
4050 (cond ((verilog-re-search-forward-quick verilog-defun-re nil t)
4053 (error "%s: Can't find module beginning" (verilog-point-text))
4055 (defun verilog-get-end-of-defun (&optional warn)
4057 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
4060 (error "%s: Can't find endmodule" (verilog-point-text))
4063 (defun verilog-label-be (&optional arg)
4064 "Label matching begin ... end, fork ... join and case ... endcase statements.
4065 With ARG, first kill any existing labels."
4070 (verilog-beg-of-defun)
4073 (verilog-end-of-defun)
4075 (goto-char (marker-position b))
4077 (message "Relabeling module..."))
4079 (> (marker-position e) (point))
4080 (verilog-re-search-forward
4082 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>"
4083 "\\|\\(`endif\\)\\|\\(`else\\)")
4085 (goto-char (match-beginning 0))
4086 (let ((indent-str (verilog-indent-line)))
4087 (verilog-set-auto-endcomments indent-str 't)
4089 (delete-horizontal-space))
4091 (if (= 9 (% cnt 10))
4092 (message "%d..." cnt)))
4097 (message "%d lines auto commented" cnt))))
4099 (defun verilog-beg-of-statement ()
4100 "Move backward to beginning of statement."
4102 ;; Move back token by token until we see the end
4103 ;; of some earlier line.
4106 ;; If the current point does not begin a new
4107 ;; statement, as in the character ahead of us is a ';', or SOF
4108 ;; or the string after us unambiguously starts a statement,
4109 ;; or the token before us unambiguously ends a statement,
4110 ;; then move back a token and test again.
4112 ;; stop if beginning of buffer
4114 ;; stop if we find a ;
4115 (= (preceding-char) ?\;)
4116 ;; stop if we see a named coverpoint
4117 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
4118 ;; keep going if we are in the middle of a word
4119 (not (or (looking-at "\\<") (forward-word -1)))
4120 ;; stop if we see an assertion (perhaps labeled)
4122 (looking-at "\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
4126 (verilog-backward-token)
4127 (if (looking-at verilog-label-re)
4130 ;; stop if we see an extended complete reg, perhaps a complete one
4132 (looking-at verilog-complete-reg)
4134 (while (and (looking-at verilog-extended-complete-re)
4135 (progn (setq p (point))
4136 (verilog-backward-token)
4139 ;; stop if we see a complete reg (previous found extended ones)
4140 (looking-at verilog-basic-complete-re)
4141 ;; stop if previous token is an ender
4143 (verilog-backward-token)
4145 (looking-at verilog-end-block-re)
4146 (looking-at verilog-preprocessor-re))))) ;; end of test
4147 (verilog-backward-syntactic-ws)
4148 (verilog-backward-token))
4149 ;; Now point is where the previous line ended.
4150 (verilog-forward-syntactic-ws)))
4152 (defun verilog-beg-of-statement-1 ()
4153 "Move backward to beginning of statement."
4155 (if (verilog-in-comment-p)
4156 (verilog-backward-syntactic-ws))
4159 (while (not (looking-at verilog-complete-reg))
4161 (verilog-backward-syntactic-ws)
4163 (= (preceding-char) ?\;)
4165 (verilog-backward-token)
4166 (looking-at verilog-ends-re)))
4170 (verilog-backward-token))))
4171 (verilog-forward-syntactic-ws)))
4174 ; (not (looking-at verilog-complete-reg))
4176 ; (not (= (preceding-char) ?\;)))
4177 ; (verilog-backward-token)
4178 ; (verilog-backward-syntactic-ws)
4179 ; (setq pt (point)))
4181 ; ;(verilog-forward-syntactic-ws)
4183 (defun verilog-end-of-statement ()
4184 "Move forward to end of current statement."
4188 ((verilog-in-directive-p)
4192 ((looking-at verilog-beg-block-re)
4193 (verilog-forward-sexp))
4195 ((equal (char-after) ?\})
4198 ;; Skip to end of statement
4199 ((condition-case nil
4204 (verilog-skip-forward-comment-or-string)
4207 (cond ((looking-at "[ \t]*;")
4208 (skip-chars-forward "^;")
4210 (throw 'found (point)))
4213 (looking-at verilog-beg-block-re))
4214 (goto-char (match-beginning 0))
4216 ((looking-at "[ \t]*)")
4217 (throw 'found (point)))
4219 (throw 'found (point)))
4225 ;; Skip a whole block
4228 (verilog-re-search-forward verilog-end-statement-re nil 'move)
4229 (setq nest (if (match-end 1)
4233 (throw 'found (point)))
4235 (throw 'found (verilog-end-of-statement))))))
4238 (defun verilog-in-case-region-p ()
4239 "Return true if in a case region.
4240 More specifically, point @ in the line foo : @ begin"
4244 (progn (verilog-forward-syntactic-ws)
4245 (looking-at "\\<begin\\>"))
4246 (progn (verilog-backward-syntactic-ws)
4247 (= (preceding-char) ?\:)))
4251 (verilog-re-search-backward
4252 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
4253 "\\(\\<endcase\\>\\)\\>")
4257 (setq nest (1+ nest)))
4261 (setq nest (1- nest)))
4263 (throw 'found (= nest 0)))))))
4266 (defun verilog-backward-up-list (arg)
4267 "Call `backward-up-list' ARG, ignoring comments."
4268 (let ((parse-sexp-ignore-comments t))
4269 (backward-up-list arg)))
4271 (defun verilog-forward-sexp-cmt (arg)
4272 "Call `forward-sexp' ARG, inside comments."
4273 (let ((parse-sexp-ignore-comments nil))
4274 (forward-sexp arg)))
4276 (defun verilog-forward-sexp-ign-cmt (arg)
4277 "Call `forward-sexp' ARG, ignoring comments."
4278 (let ((parse-sexp-ignore-comments t))
4279 (forward-sexp arg)))
4281 (defun verilog-in-generate-region-p ()
4282 "Return true if in a generate region.
4283 More specifically, after a generate and before an endgenerate."
4290 (verilog-re-search-backward
4291 "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
4293 ((match-end 1) ; module - we have crawled out
4295 ((match-end 2) ; generate
4296 (setq nest (1- nest)))
4297 ((match-end 3) ; endgenerate
4298 (setq nest (1+ nest))))))))
4299 (= nest 0) )) ; return nest
4301 (defun verilog-in-fork-region-p ()
4302 "Return true if between a fork and join."
4304 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
4309 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
4311 ((match-end 1) ; fork
4312 (setq nest (1- nest)))
4313 ((match-end 2) ; join
4314 (setq nest (1+ nest)))))))
4315 (= nest 0) )) ; return nest
4317 (defun verilog-backward-case-item (lim)
4318 "Skip backward to nearest enclosing case item.
4319 Limit search to point LIM."
4325 (verilog-re-search-backward verilog-endcomment-reason-re
4328 ;; Try to find the real :
4329 (if (save-excursion (search-backward ":" lim1 t))
4335 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
4339 (setq colon (1+ colon))
4341 (error "%s: unbalanced [" (verilog-point-text))))
4343 (setq colon (1- colon)))
4346 (setq colon (1+ colon)))))
4347 ;; Skip back to beginning of case item
4348 (skip-chars-backward "\t ")
4349 (verilog-skip-backward-comment-or-string)
4354 (verilog-re-search-backward
4355 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
4359 (goto-char (match-end 1))
4360 (verilog-forward-ws&directives)
4361 (if (looking-at "(")
4364 (verilog-forward-ws&directives)))
4367 (goto-char (match-end 0))
4368 (verilog-forward-ws&directives)
4370 (error "Malformed case item"))))
4371 (setq str (buffer-substring b e))
4375 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4376 (setq str (concat (substring str 0 e) "...")))
4385 (defun verilog-kill-existing-comment ()
4386 "Kill auto comment on this line."
4394 (search-forward "//" e t))))
4396 (delete-region (- b 2) e)))))
4398 (defconst verilog-directive-nest-re
4399 (concat "\\(`else\\>\\)\\|"
4400 "\\(`endif\\>\\)\\|"
4402 "\\(`ifdef\\>\\)\\|"
4403 "\\(`ifndef\\>\\)\\|"
4405 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
4406 "Add ending comment with given INDENT-STR.
4407 With KILL-EXISTING-COMMENT, remove what was there before.
4408 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
4409 Insert `// case expr ' if this line ends a case block.
4410 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
4411 Insert `// NAME ' if this line ends a function, task, module,
4412 primitive or interface named NAME."
4415 (; Comment close preprocessor directives
4417 (looking-at "\\(`endif\\)\\|\\(`else\\)")
4418 (or kill-existing-comment
4419 (not (save-excursion
4421 (search-backward "//" (point-at-bol) t)))))
4424 (else (if (match-end 2) "!" " ")))
4426 (if kill-existing-comment
4427 (verilog-kill-existing-comment))
4428 (delete-horizontal-space)
4431 (while (and (/= nest 0)
4432 (verilog-re-search-backward verilog-directive-nest-re nil 'move))
4434 ((match-end 1) ; `else
4437 ((match-end 2) ; `endif
4438 (setq nest (1+ nest)))
4439 ((match-end 3) ; `if
4440 (setq nest (1- nest)))
4441 ((match-end 4) ; `ifdef
4442 (setq nest (1- nest)))
4443 ((match-end 5) ; `ifndef
4444 (setq nest (1- nest)))
4445 ((match-end 6) ; `elsif
4456 (skip-chars-forward "^ \t")
4457 (verilog-forward-syntactic-ws)
4460 (skip-chars-forward "a-zA-Z0-9_")
4463 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
4464 (insert (concat " // " else m " " (buffer-substring b e))))
4466 (insert " // unmatched `else, `elsif or `endif")
4469 (; Comment close case/class/function/task/module and named block
4470 (and (looking-at "\\<end")
4471 (or kill-existing-comment
4472 (not (save-excursion
4474 (search-backward "//" (point-at-bol) t)))))
4475 (let ((type (car indent-str)))
4476 (unless (eq type 'declaration)
4477 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends
4478 (if (looking-at verilog-end-block-ordered-re)
4480 (;- This is a case block; search back for the start of this case
4481 (match-end 1) ;; of verilog-end-block-ordered-re
4484 (str "UNMATCHED!!"))
4486 (verilog-leap-to-head)
4488 ((looking-at "\\<randcase\\>")
4489 (setq str "randcase")
4491 ((looking-at "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
4492 (goto-char (match-end 0))
4493 (setq str (concat (match-string 0) " " (verilog-get-expr)))
4497 (if kill-existing-comment
4498 (verilog-kill-existing-comment))
4499 (delete-horizontal-space)
4500 (insert (concat " // " str ))
4501 (if err (ding 't))))
4503 (;- This is a begin..end block
4504 (match-end 2) ;; of verilog-end-block-ordered-re
4505 (let ((str " // UNMATCHED !!")
4511 (verilog-leap-to-head)
4512 (setq there (point))
4513 (if (not (match-end 0))
4517 (if kill-existing-comment
4518 (verilog-kill-existing-comment))
4519 (delete-horizontal-space)
4523 (save-excursion (verilog-beg-of-defun) (point)))
4526 (;-- handle named block differently
4527 (looking-at verilog-named-block-re)
4528 (search-forward ":")
4529 (setq there (point))
4530 (setq str (verilog-get-expr))
4532 (setq str (concat " // block: " str )))
4534 ((verilog-in-case-region-p) ;-- handle case item differently
4536 (setq str (verilog-backward-case-item lim))
4537 (setq there (point))
4539 (setq str (concat " // case: " str )))
4541 (;- try to find "reason" for this begin
4545 ;; (verilog-backward-token)
4546 (verilog-beg-of-statement)
4550 ((looking-at verilog-endcomment-reason-re)
4551 (setq there (match-end 0))
4552 (setq cntx (concat (match-string 0) " "))
4558 (if (and (verilog-continued-line)
4559 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
4561 (goto-char (match-end 0))
4562 (setq there (point))
4564 (concat " // " (match-string 0) " " (verilog-get-expr))))
4570 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4572 (while (verilog-re-search-backward reg nil 'move)
4574 ((match-end 1) ; begin
4575 (setq nest (1- nest)))
4576 ((match-end 2) ; end
4577 (setq nest (1+ nest)))
4581 (goto-char (match-end 0))
4582 (setq there (point))
4584 (setq str (verilog-get-expr))
4585 (setq str (concat " // else: !if" str ))
4590 (goto-char (match-end 0))
4591 (setq there (point))
4593 (setq str (verilog-get-expr))
4594 (setq str (concat " // else: !assert " str ))
4595 (throw 'skip 1)))))))))
4600 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4602 (while (verilog-re-search-backward reg nil 'move)
4604 ((match-end 1) ; begin
4605 (setq nest (1- nest)))
4606 ((match-end 2) ; end
4607 (setq nest (1+ nest)))
4611 (goto-char (match-end 0))
4612 (setq there (point))
4614 (setq str (verilog-get-expr))
4615 (setq str (concat " // else: !if" str ))
4620 (goto-char (match-end 0))
4621 (setq there (point))
4623 (setq str (verilog-get-expr))
4624 (setq str (concat " // else: !assert " str ))
4625 (throw 'skip 1)))))))))
4627 (; always_comb, always_ff, always_latch
4628 (or (match-end 4) (match-end 5) (match-end 6))
4629 (goto-char (match-end 0))
4630 (setq there (point))
4632 (setq str (concat " // " cntx )))
4634 (;- task/function/initial et cetera
4637 (goto-char (match-end 0))
4638 (setq there (point))
4640 (setq str (concat " // " cntx (verilog-get-expr))))
4643 (setq str " // auto-endcomment confused "))))
4646 (verilog-in-case-region-p) ;-- handle case item differently
4648 (setq there (point))
4650 (setq str (verilog-backward-case-item lim))))
4652 (setq str (concat " // case: " str )))
4654 ((verilog-in-fork-region-p)
4656 (setq str " // fork branch" ))
4658 ((looking-at "\\<end\\>")
4661 (verilog-forward-syntactic-ws)
4663 (setq str (verilog-get-expr))
4664 (setq str (concat " // " cntx str )))
4669 (if kill-existing-comment
4670 (verilog-kill-existing-comment))
4671 (delete-horizontal-space)
4673 (> (count-lines here there) verilog-minimum-comment-distance))
4677 (;- this is endclass, which can be nested
4678 (match-end 11) ;; of verilog-end-block-ordered-re
4681 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
4685 (while (verilog-re-search-backward reg nil 'move)
4687 ((match-end 3) ; endclass
4689 (setq string "unmatched endclass")
4692 ((match-end 2) ; endclass
4693 (setq nest (1+ nest)))
4695 ((match-end 1) ; class
4696 (setq nest (1- nest))
4699 (goto-char (match-end 0))
4702 (skip-chars-forward "^ \t")
4703 (verilog-forward-ws&directives)
4706 (skip-chars-forward "a-zA-Z0-9_")
4708 (setq string (buffer-substring b e)))
4712 (insert (concat " // " string ))))
4714 (;- this is end{function,generate,task,module,primitive,table,generate}
4715 ;- which can not be nested.
4717 (let (string reg (name-re nil))
4719 (if kill-existing-comment
4721 (verilog-kill-existing-comment)))
4722 (delete-horizontal-space)
4725 ((match-end 5) ;; of verilog-end-block-ordered-re
4726 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4727 (setq name-re "\\w+\\s-*("))
4728 ((match-end 6) ;; of verilog-end-block-ordered-re
4729 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4730 (setq name-re "\\w+\\s-*("))
4731 ((match-end 7) ;; of verilog-end-block-ordered-re
4732 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
4733 ((match-end 8) ;; of verilog-end-block-ordered-re
4734 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4735 ((match-end 9) ;; of verilog-end-block-ordered-re
4736 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
4737 ((match-end 10) ;; of verilog-end-block-ordered-re
4738 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4739 ((match-end 11) ;; of verilog-end-block-ordered-re
4740 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4741 ((match-end 12) ;; of verilog-end-block-ordered-re
4742 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4743 ((match-end 13) ;; of verilog-end-block-ordered-re
4744 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4745 ((match-end 14) ;; of verilog-end-block-ordered-re
4746 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4747 ((match-end 15) ;; of verilog-end-block-ordered-re
4748 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
4750 (t (error "Problem in verilog-set-auto-endcomments")))
4753 (verilog-re-search-backward reg nil 'move)
4757 (skip-chars-forward "^ \t")
4758 (verilog-forward-ws&directives)
4759 (if (looking-at "static\\|automatic")
4761 (goto-char (match-end 0))
4762 (verilog-forward-ws&directives)))
4763 (if (and name-re (verilog-re-search-forward name-re nil 'move))
4765 (goto-char (match-beginning 0))
4766 (verilog-forward-ws&directives)))
4769 (skip-chars-forward "a-zA-Z0-9_")
4771 (setq string (buffer-substring b e)))
4774 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
4776 (insert (concat " // " string )))
4779 (defun verilog-get-expr()
4780 "Grab expression at point, e.g, case ( a | b & (c ^d))."
4782 (verilog-forward-syntactic-ws)
4783 (skip-chars-forward " \t")
4789 (verilog-forward-syntactic-ws)
4790 (if (looking-at "(")
4793 (while (and (/= par 0)
4794 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4797 (setq par (1+ par)))
4799 (setq par (1- par)))))))
4803 (while (and (/= par 0)
4804 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4807 (setq par (1+ par)))
4809 (setq par (1- par)))))
4813 (while (and (/= par 0)
4814 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
4817 (setq par (1+ par)))
4819 (setq par (1- par)))))
4820 (verilog-forward-syntactic-ws)
4821 (skip-chars-forward "^ \t\n\f")
4823 ((looking-at "/[/\\*]")
4826 (skip-chars-forward "^: \t\n\f")
4828 (str (buffer-substring b e)))
4829 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4830 (setq str (concat (substring str 0 e) "...")))
4833 (defun verilog-expand-vector ()
4834 "Take a signal vector on the current line and expand it to multiple lines.
4835 Useful for creating tri's and other expanded fields."
4837 (verilog-expand-vector-internal "[" "]"))
4839 (defun verilog-expand-vector-internal (bra ket)
4840 "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
4843 (let ((signal-string (buffer-substring (point)
4845 (end-of-line) (point)))))
4849 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
4851 "\\(.*\\)$") signal-string)
4852 (let* ((sig-head (match-string 1 signal-string))
4853 (vec-start (string-to-number (match-string 2 signal-string)))
4854 (vec-end (if (= (match-beginning 3) (match-end 3))
4857 (substring signal-string (1+ (match-beginning 3))
4860 (if (= (match-beginning 4) (match-end 4))
4863 (substring signal-string (+ 2 (match-beginning 4))
4865 (sig-tail (match-string 5 signal-string))
4870 (let ((tmp vec-start))
4871 (setq vec-start vec-end
4873 vec-range (- vec-range))))
4874 (if (< vec-end vec-start)
4875 (while (<= vec-end vec-start)
4876 (setq vec (append vec (list vec-start)))
4877 (setq vec-start (- vec-start vec-range)))
4878 (while (<= vec-start vec-end)
4879 (setq vec (append vec (list vec-start)))
4880 (setq vec-start (+ vec-start vec-range))))
4882 ;; Delete current line
4883 (delete-region (point) (progn (forward-line 0) (point)))
4887 (insert (concat sig-head bra
4888 (int-to-string (car vec)) ket sig-tail "\n"))
4889 (setq vec (cdr vec)))
4894 (defun verilog-strip-comments ()
4895 "Strip all comments from the Verilog code."
4897 (goto-char (point-min))
4898 (while (re-search-forward "//" nil t)
4899 (if (verilog-within-string)
4900 (re-search-forward "\"" nil t)
4901 (if (verilog-in-star-comment-p)
4902 (re-search-forward "\*/" nil t)
4903 (let ((bpt (- (point) 2)))
4905 (delete-region bpt (point))))))
4907 (goto-char (point-min))
4908 (while (re-search-forward "/\\*" nil t)
4909 (if (verilog-within-string)
4910 (re-search-forward "\"" nil t)
4911 (let ((bpt (- (point) 2)))
4912 (re-search-forward "\\*/")
4913 (delete-region bpt (point))))))
4915 (defun verilog-one-line ()
4916 "Convert structural Verilog instances to occupy one line."
4918 (goto-char (point-min))
4919 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
4920 (replace-match "\\1 " nil nil)))
4922 (defun verilog-linter-name ()
4923 "Return name of linter, either surelint or verilint."
4924 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4926 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4928 (cond ((equal compile-word1 "surelint") `surelint)
4929 ((equal compile-word1 "verilint") `verilint)
4930 ((equal lint-word1 "surelint") `surelint)
4931 ((equal lint-word1 "verilint") `verilint)
4932 (t `surelint)))) ;; back compatibility
4934 (defun verilog-lint-off ()
4935 "Convert a Verilog linter warning line into a disable statement.
4937 pci_bfm_null.v, line 46: Unused input: pci_rst_
4938 becomes a comment for the appropriate tool.
4940 The first word of the `compile-command' or `verilog-linter'
4941 variables is used to determine which product is being used.
4943 See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
4945 (let ((linter (verilog-linter-name)))
4946 (cond ((equal linter `surelint)
4947 (verilog-surelint-off))
4948 ((equal linter `verilint)
4949 (verilog-verilint-off))
4950 (t (error "Linter name not set")))))
4952 (defvar compilation-last-buffer)
4953 (defvar next-error-last-buffer)
4955 (defun verilog-surelint-off ()
4956 "Convert a SureLint warning line into a disable statement.
4957 Run from Verilog source window; assumes there is a *compile* buffer
4958 with point set appropriately.
4961 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
4963 // surefire lint_line_off UDDONX"
4965 (let ((buff (if (boundp 'next-error-last-buffer)
4966 next-error-last-buffer
4967 compilation-last-buffer)))
4968 (when (buffer-live-p buff)
4970 (switch-to-buffer buff)
4973 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
4974 (let* ((code (match-string 2))
4975 (file (match-string 3))
4976 (line (match-string 4))
4977 (buffer (get-file-buffer file))
4982 (and (file-exists-p file)
4983 (find-file-noselect file)))
4985 (let* ((pop-up-windows t))
4986 (let ((name (expand-file-name
4988 (format "Find this error in: (default %s) "
4991 (if (file-directory-p name)
4992 (setq name (expand-file-name filename name)))
4994 (and (file-exists-p name)
4995 (find-file-noselect name))))))))
4996 (switch-to-buffer buffer)
4997 (goto-char (point-min))
4998 (forward-line (- (string-to-number line)))
5002 ((verilog-in-slash-comment-p)
5003 (re-search-backward "//")
5005 ((looking-at "// surefire lint_off_line ")
5006 (goto-char (match-end 0))
5007 (let ((lim (point-at-eol)))
5008 (if (re-search-forward code lim 'move)
5010 (insert (concat " " code)))))
5013 ((verilog-in-star-comment-p)
5014 (re-search-backward "/\*")
5015 (insert (format " // surefire lint_off_line %6s" code )))
5017 (insert (format " // surefire lint_off_line %6s" code ))
5020 (defun verilog-verilint-off ()
5021 "Convert a Verilint warning line into a disable statement.
5024 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
5026 //Verilint 240 off // WARNING: Unused input"
5030 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
5031 (replace-match (format
5032 ;; %3s makes numbers 1-999 line up nicely
5033 "\\1//Verilint %3s off // WARNING: \\3"
5036 (verilog-indent-line))))
5038 (defun verilog-auto-save-compile ()
5039 "Update automatics with \\[verilog-auto], save the buffer, and compile."
5041 (verilog-auto) ; Always do it for safety
5043 (compile compile-command))
5045 (defun verilog-preprocess (&optional command filename)
5046 "Preprocess the buffer, similar to `compile', but put output in Verilog-Mode.
5047 Takes optional COMMAND or defaults to `verilog-preprocessor', and
5048 FILENAME to find directory to run in, or defaults to `buffer-file-name`."
5051 (let ((default (verilog-expand-command verilog-preprocessor)))
5052 (set (make-local-variable `verilog-preprocessor)
5053 (read-from-minibuffer "Run Preprocessor (like this): "
5055 'verilog-preprocess-history default)))))
5056 (unless command (setq command (verilog-expand-command verilog-preprocessor)))
5057 (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
5058 (dir (file-name-directory (or filename buffer-file-name)))
5059 (cmd (concat "cd " dir "; " command)))
5060 (with-output-to-temp-buffer "*Verilog-Preprocessed*"
5061 (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
5062 (insert (concat "// " cmd "\n"))
5063 (call-process shell-file-name nil t nil shell-command-switch cmd)
5065 ;; Without this force, it takes a few idle seconds
5066 ;; to get the color, which is very jarring
5067 (when fontlocked (font-lock-fontify-buffer))))))
5074 (defun verilog-warn (string &rest args)
5075 "Print a warning with `format' using STRING and optional ARGS."
5076 (apply 'message (concat "%%Warning: " string) args))
5078 (defun verilog-warn-error (string &rest args)
5079 "Call `error' using STRING and optional ARGS.
5080 If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead."
5081 (if verilog-warn-fatal
5082 (apply 'error string args)
5083 (apply 'verilog-warn string args)))
5085 (defmacro verilog-batch-error-wrapper (&rest body)
5086 "Execute BODY and add error prefix to any errors found.
5087 This lets programs calling batch mode to easily extract error messages."
5088 `(let ((verilog-warn-fatal nil))
5092 (error "%%Error: %s%s" (error-message-string err)
5093 (if (featurep 'xemacs) "\n" "")))))) ;; XEmacs forgets to add a newline
5095 (defun verilog-batch-execute-func (funref &optional no-save)
5096 "Internal processing of a batch command.
5097 Runs FUNREF on all command arguments.
5098 Save the result unless optional NO-SAVE is t."
5099 (verilog-batch-error-wrapper
5100 ;; Setting global variables like that is *VERY NASTY* !!! --Stef
5101 ;; However, this function is called only when Emacs is being used as
5102 ;; a standalone language instead of as an editor, so we'll live.
5104 ;; General globals needed
5105 (setq make-backup-files nil)
5106 (setq-default make-backup-files nil)
5107 (setq enable-local-variables t)
5108 (setq enable-local-eval t)
5109 ;; Make sure any sub-files we read get proper mode
5110 (setq-default major-mode 'verilog-mode)
5111 ;; Ditto files already read in
5113 (when (buffer-file-name buf)
5114 (with-current-buffer buf
5117 ;; Process the files
5118 (mapcar (lambda (buf)
5119 (when (buffer-file-name buf)
5121 (if (not (file-exists-p (buffer-file-name buf)))
5123 (concat "File not found: " (buffer-file-name buf))))
5124 (message (concat "Processing " (buffer-file-name buf)))
5127 (unless no-save (save-buffer)))))
5130 (defun verilog-batch-auto ()
5131 "For use with --batch, perform automatic expansions as a stand-alone tool.
5132 This sets up the appropriate Verilog mode environment, updates automatics
5133 with \\[verilog-auto] on all command-line files, and saves the buffers.
5134 For proper results, multiple filenames need to be passed on the command
5135 line in bottom-up order."
5136 (unless noninteractive
5137 (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5138 (verilog-batch-execute-func `verilog-auto))
5140 (defun verilog-batch-delete-auto ()
5141 "For use with --batch, perform automatic deletion as a stand-alone tool.
5142 This sets up the appropriate Verilog mode environment, deletes automatics
5143 with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
5144 (unless noninteractive
5145 (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5146 (verilog-batch-execute-func `verilog-delete-auto))
5148 (defun verilog-batch-delete-trailing-whitespace ()
5149 "For use with --batch, perform whitespace deletion as a stand-alone tool.
5150 This sets up the appropriate Verilog mode environment, removes
5151 whitespace with \\[verilog-delete-trailing-whitespace] on all
5152 command-line files, and saves the buffers."
5153 (unless noninteractive
5154 (error "Use verilog-batch-delete-trailing-whitespace only with --batch")) ;; Otherwise we'd mess up buffer modes
5155 (verilog-batch-execute-func `verilog-delete-trailing-whitespace))
5157 (defun verilog-batch-diff-auto ()
5158 "For use with --batch, perform automatic differences as a stand-alone tool.
5159 This sets up the appropriate Verilog mode environment, expand automatics
5160 with \\[verilog-diff-auto] on all command-line files, and reports an error
5161 if any differences are observed. This is appropriate for adding to regressions
5162 to insure automatics are always properly maintained."
5163 (unless noninteractive
5164 (error "Use verilog-batch-diff-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5165 (verilog-batch-execute-func `verilog-diff-auto t))
5167 (defun verilog-batch-inject-auto ()
5168 "For use with --batch, perform automatic injection as a stand-alone tool.
5169 This sets up the appropriate Verilog mode environment, injects new automatics
5170 with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
5171 For proper results, multiple filenames need to be passed on the command
5172 line in bottom-up order."
5173 (unless noninteractive
5174 (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5175 (verilog-batch-execute-func `verilog-inject-auto))
5177 (defun verilog-batch-indent ()
5178 "For use with --batch, reindent an entire file as a stand-alone tool.
5179 This sets up the appropriate Verilog mode environment, calls
5180 \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
5181 (unless noninteractive
5182 (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes
5183 (verilog-batch-execute-func `verilog-indent-buffer))
5189 (defconst verilog-indent-alist
5190 '((block . (+ ind verilog-indent-level))
5191 (case . (+ ind verilog-case-indent))
5192 (cparenexp . (+ ind verilog-indent-level))
5193 (cexp . (+ ind verilog-cexp-indent))
5194 (defun . verilog-indent-level-module)
5195 (declaration . verilog-indent-level-declaration)
5196 (directive . (verilog-calculate-indent-directive))
5197 (tf . verilog-indent-level)
5198 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
5201 (comment . (verilog-comment-indent))
5205 (defun verilog-continued-line-1 (lim)
5206 "Return true if this is a continued line.
5207 Set point to where line starts. Limit search to point LIM."
5208 (let ((continued 't))
5209 (if (eq 0 (forward-line -1))
5212 (verilog-backward-ws&directives lim)
5214 (setq continued nil)
5215 (setq continued (verilog-backward-token))))
5216 (setq continued nil))
5219 (defun verilog-calculate-indent ()
5220 "Calculate the indent of the current Verilog line.
5221 Examine previous lines. Once a line is found that is definitive as to the
5222 type of the current line, return that lines' indent level and its type.
5223 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5225 (let* ((starting_position (point))
5227 (begin (looking-at "[ \t]*begin\\>"))
5228 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
5229 (type (catch 'nesting
5230 ;; Keep working backwards until we can figure out
5231 ;; what type of statement this is.
5232 ;; Basically we need to figure out
5233 ;; 1) if this is a continuation of the previous line;
5234 ;; 2) are we in a block scope (begin..end)
5236 ;; if we are in a comment, done.
5237 (if (verilog-in-star-comment-p)
5238 (throw 'nesting 'comment))
5240 ;; if we have a directive, done.
5241 (if (save-excursion (beginning-of-line)
5242 (and (looking-at verilog-directive-re-1)
5243 (not (or (looking-at "[ \t]*`[ou]vm_")
5244 (looking-at "[ \t]*`vmm_")))))
5245 (throw 'nesting 'directive))
5246 ;; indent structs as if there were module level
5247 (if (verilog-in-struct-p)
5248 (throw 'nesting 'block))
5250 ;; if we are in a parenthesized list, and the user likes to indent these, return.
5251 ;; unless we are in the newfangled coverpoint or constraint blocks
5253 verilog-indent-lists
5255 (not (verilog-in-coverage-p))
5258 (throw 'nesting 'block)))
5260 ;; See if we are continuing a previous line
5262 ;; trap out if we crawl off the top of the buffer
5263 (if (bobp) (throw 'nesting 'cpp))
5265 (if (verilog-continued-line-1 lim)
5268 (not (looking-at verilog-complete-reg))
5269 (verilog-continued-line-1 lim))
5270 (progn (goto-char sp)
5271 (throw 'nesting 'cexp))
5276 (not verilog-indent-begin-after-if)
5277 (looking-at verilog-no-indent-begin-re))
5280 (skip-chars-forward " \t")
5281 (throw 'nesting 'statement))
5283 (throw 'nesting 'cexp))))
5284 ;; not a continued line
5285 (goto-char starting_position))
5287 (if (looking-at "\\<else\\>")
5288 ;; search back for governing if, striding across begin..end pairs
5291 (while (verilog-re-search-backward verilog-ends-re nil 'move)
5293 ((match-end 1) ; else, we're in deep
5294 (setq elsec (1+ elsec)))
5296 (setq elsec (1- elsec))
5298 (if verilog-align-ifelse
5299 (throw 'nesting 'statement)
5300 (progn ;; back up to first word on this line
5302 (verilog-forward-syntactic-ws)
5303 (throw 'nesting 'statement)))))
5304 ((match-end 3) ; assert block
5305 (setq elsec (1- elsec))
5306 (verilog-beg-of-statement) ;; doesn't get to beginning
5307 (if (looking-at verilog-property-re)
5308 (throw 'nesting 'statement) ; We don't need an endproperty for these
5309 (throw 'nesting 'block) ;We still need an endproperty
5312 ; try to leap back to matching outward block by striding across
5313 ; indent level changing tokens then immediately
5314 ; previous line governs indentation.
5315 (let (( reg) (nest 1))
5316 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
5318 ((match-end 4) ; end
5319 ;; Search back for matching begin
5320 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
5321 ((match-end 5) ; endcase
5322 ;; Search back for matching case
5323 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5324 ((match-end 6) ; endfunction
5325 ;; Search back for matching function
5326 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5327 ((match-end 7) ; endtask
5328 ;; Search back for matching task
5329 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
5330 ((match-end 8) ; endspecify
5331 ;; Search back for matching specify
5332 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5333 ((match-end 9) ; endtable
5334 ;; Search back for matching table
5335 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5336 ((match-end 10) ; endgenerate
5337 ;; Search back for matching generate
5338 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5339 ((match-end 11) ; joins
5340 ;; Search back for matching fork
5341 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
5342 ((match-end 12) ; class
5343 ;; Search back for matching class
5344 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5345 ((match-end 13) ; covergroup
5346 ;; Search back for matching covergroup
5347 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
5349 (while (verilog-re-search-backward reg nil 'move)
5351 ((match-end 1) ; begin
5352 (setq nest (1- nest))
5355 ((match-end 2) ; end
5356 (setq nest (1+ nest)))))
5358 (throw 'nesting (verilog-calc-1)))
5362 ;; Return type of block and indent level.
5365 (if (> par 0) ; Unclosed Parenthesis
5366 (list 'cparenexp par)
5369 (list type (verilog-case-indent-level)))
5370 ((eq type 'statement)
5371 (list type (current-column)))
5375 (list type (verilog-current-indent-level))))))))
5377 (defun verilog-wai ()
5378 "Show matching nesting block for debugging."
5381 (let* ((type (verilog-calc-1))
5383 ;; Return type of block and indent level.
5387 verilog-indent-lists
5388 (not(or (verilog-in-coverage-p)
5389 (verilog-in-struct-p)))
5394 (setq depth (verilog-case-indent-level)))
5395 ((eq type 'statement)
5396 (setq depth (current-column)))
5400 (setq depth (verilog-current-indent-level)))))
5401 (message "You are at nesting %s depth %d" type depth))))
5402 (defun verilog-calc-1 ()
5404 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)")))
5405 (while (verilog-re-search-backward re nil 'move)
5408 ((equal (char-after) ?\{)
5409 (if (verilog-at-constraint-p)
5410 (throw 'nesting 'block)))
5412 ((equal (char-after) ?\})
5413 (let ((there (verilog-at-close-constraint-p)))
5414 (if there ;; we are at the } that closes a constraint. Find the { that opens it
5418 (verilog-beg-of-statement)))))
5420 ((looking-at verilog-beg-block-re-ordered)
5422 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
5423 (let ((here (point)))
5424 (verilog-beg-of-statement)
5425 (if (looking-at verilog-extended-case-re)
5426 (throw 'nesting 'case)
5428 (throw 'nesting 'case))
5430 ((match-end 4) ; *sigh* could be "disable fork"
5431 (let ((here (point)))
5432 (verilog-beg-of-statement)
5433 (if (looking-at verilog-disable-fork-re)
5434 t ; this is a normal statement
5435 (progn ; or is fork, starts a new block
5437 (throw 'nesting 'block)))))
5439 ((match-end 27) ; *sigh* might be a clocking declaration
5440 (let ((here (point)))
5441 (if (verilog-in-paren)
5442 t ; this is a normal statement
5443 (progn ; or is fork, starts a new block
5445 (throw 'nesting 'block)))))
5447 ;; need to consider typedef struct here...
5448 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
5449 ; *sigh* These words have an optional prefix:
5450 ; extern {virtual|protected}? function a();
5451 ; typedef class foo;
5452 ; and we don't want to confuse this with
5457 (verilog-beg-of-statement)
5458 (if (looking-at verilog-beg-block-re-ordered)
5459 (throw 'nesting 'block)
5460 (throw 'nesting 'defun)))
5463 ((looking-at "\\<property\\>")
5465 ; {assert|assume|cover} property (); are complete
5466 ; and could also be labeled: - foo: assert property
5468 ; property ID () ... needs end_property
5469 (verilog-beg-of-statement)
5470 (if (looking-at verilog-property-re)
5471 (throw 'continue 'statement) ; We don't need an endproperty for these
5472 (throw 'nesting 'block) ;We still need an endproperty
5475 (t (throw 'nesting 'block))))
5477 ((looking-at verilog-end-block-re)
5478 (verilog-leap-to-head)
5479 (if (verilog-in-case-region-p)
5481 (verilog-leap-to-case-head)
5482 (if (looking-at verilog-extended-case-re)
5483 (throw 'nesting 'case)))))
5485 ((looking-at verilog-defun-level-re)
5486 (if (looking-at verilog-defun-level-generate-only-re)
5487 (if (verilog-in-generate-region-p)
5488 (throw 'continue 'foo) ; always block in a generate - keep looking
5489 (throw 'nesting 'defun))
5490 (throw 'nesting 'defun)))
5492 ((looking-at verilog-cpp-level-re)
5493 (throw 'nesting 'cpp))
5496 (throw 'nesting 'cpp)))))
5498 (throw 'nesting 'cpp))))
5500 (defun verilog-calculate-indent-directive ()
5501 "Return indentation level for directive.
5502 For speed, the searcher looks at the last directive, not the indent
5503 of the appropriate enclosing block."
5504 (let ((base -1) ;; Indent of the line that determines our indentation
5505 (ind 0)) ;; Relative offset caused by other directives (like `endif on same line as `else)
5506 ;; Start at current location, scan back for another directive
5510 (while (and (< base 0)
5511 (verilog-re-search-backward verilog-directive-re nil t))
5512 (cond ((save-excursion (skip-chars-backward " \t") (bolp))
5513 (setq base (current-indentation))))
5514 (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL
5515 (setq ind (- ind verilog-indent-level-directive)))
5516 ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL
5517 (setq ind (+ ind verilog-indent-level-directive)))
5518 ((looking-at verilog-directive-begin)
5519 (setq ind (+ ind verilog-indent-level-directive)))))
5520 ;; Adjust indent to starting indent of critical line
5521 (setq ind (max 0 (+ ind base))))
5525 (skip-chars-forward " \t")
5526 (cond ((or (looking-at verilog-directive-middle)
5527 (looking-at verilog-directive-end))
5528 (setq ind (max 0 (- ind verilog-indent-level-directive))))))
5531 (defun verilog-leap-to-case-head ()
5534 (verilog-re-search-backward
5536 "\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
5537 "\\|\\(\\<endcase\\>\\)" )
5541 (let ((here (point)))
5542 (verilog-beg-of-statement)
5543 (unless (looking-at verilog-extended-case-re)
5545 (setq nest (1- nest)))
5547 (setq nest (1+ nest)))
5552 (defun verilog-leap-to-head ()
5553 "Move point to the head of this block.
5554 Jump from end to matching begin, from endcase to matching case, and so on."
5560 ((looking-at "\\<end\\>")
5561 ;; 1: Search back for matching begin
5562 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
5563 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
5564 ((looking-at "\\<endtask\\>")
5565 ;; 2: Search back for matching task
5566 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)")
5568 ((looking-at "\\<endcase\\>")
5570 (verilog-leap-to-case-head) )
5571 (setq reg nil) ; to force skip
5574 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
5575 ;; 4: Search back for matching fork
5576 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5577 ((looking-at "\\<endclass\\>")
5578 ;; 5: Search back for matching class
5579 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5580 ((looking-at "\\<endtable\\>")
5581 ;; 6: Search back for matching table
5582 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5583 ((looking-at "\\<endspecify\\>")
5584 ;; 7: Search back for matching specify
5585 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5586 ((looking-at "\\<endfunction\\>")
5587 ;; 8: Search back for matching function
5588 (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<function\\>\\)")
5590 ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5591 ((looking-at "\\<endgenerate\\>")
5592 ;; 8: Search back for matching generate
5593 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5594 ((looking-at "\\<endgroup\\>")
5595 ;; 10: Search back for matching covergroup
5596 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
5597 ((looking-at "\\<endproperty\\>")
5598 ;; 11: Search back for matching property
5599 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
5600 ((looking-at verilog-uvm-end-re)
5601 ;; 12: Search back for matching sequence
5602 (setq reg (concat "\\(" verilog-uvm-begin-re "\\|" verilog-uvm-end-re "\\)")))
5603 ((looking-at verilog-ovm-end-re)
5604 ;; 12: Search back for matching sequence
5605 (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
5606 ((looking-at verilog-vmm-end-re)
5607 ;; 12: Search back for matching sequence
5608 (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
5609 ((looking-at "\\<endinterface\\>")
5610 ;; 12: Search back for matching interface
5611 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
5612 ((looking-at "\\<endsequence\\>")
5613 ;; 12: Search back for matching sequence
5614 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
5615 ((looking-at "\\<endclocking\\>")
5616 ;; 12: Search back for matching clocking
5617 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
5620 (if (eq nesting 'yes)
5622 (while (verilog-re-search-backward reg nil 'move)
5624 ((match-end 1) ; begin
5625 (if (looking-at "fork")
5626 (let ((here (point)))
5627 (verilog-beg-of-statement)
5628 (unless (looking-at verilog-disable-fork-re)
5630 (setq nest (1- nest))))
5631 (setq nest (1- nest)))
5633 ;; Now previous line describes syntax
5638 ((match-end 2) ; end
5639 (setq nest (1+ nest)))
5641 ;; endcase, jump to case
5643 (setq nest (1+ nest))
5645 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5647 ;; join, jump to fork
5649 (setq nest (1+ nest))
5651 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5655 (verilog-re-search-backward reg nil 'move)
5656 (match-end 1)) ; task -> could be virtual and/or protected
5658 (verilog-beg-of-statement)
5660 (throw 'skip 1)))))))
5662 (defun verilog-continued-line ()
5663 "Return true if this is a continued line.
5664 Set point to where line starts."
5665 (let ((continued 't))
5666 (if (eq 0 (forward-line -1))
5669 (verilog-backward-ws&directives)
5671 (setq continued nil)
5672 (while (and continued
5674 (skip-chars-backward " \t")
5676 (setq continued (verilog-backward-token)))))
5677 (setq continued nil))
5680 (defun verilog-backward-token ()
5681 "Step backward token, returning true if this is a continued line."
5683 (verilog-backward-syntactic-ws)
5687 (;-- Anything ending in a ; is complete
5688 (= (preceding-char) ?\;)
5690 (; If a "}" is prefixed by a ";", then this is a complete statement
5691 ; i.e.: constraint foo { a = b; }
5692 (= (preceding-char) ?\})
5695 (not(verilog-at-close-constraint-p))))
5696 (;-- constraint foo { a = b }
5697 ; is a complete statement. *sigh*
5698 (= (preceding-char) ?\{)
5701 (not (verilog-at-constraint-p))))
5703 (= (preceding-char) ?\")
5705 (verilog-skip-backward-comment-or-string)
5709 (= (preceding-char) ?\])
5711 (verilog-backward-open-bracket)
5714 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
5715 ; also could be simply '@(foo)'
5717 ; (b, ... which ISN'T complete
5718 ;;;; Do we need this???
5719 (= (preceding-char) ?\))
5722 (verilog-backward-up-list 1)
5723 (verilog-backward-syntactic-ws)
5724 (let ((back (point)))
5728 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
5729 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
5730 ((looking-at verilog-uvm-statement-re)
5732 ((looking-at verilog-uvm-begin-re)
5734 ((looking-at verilog-uvm-end-re)
5736 ((looking-at verilog-ovm-statement-re)
5738 ((looking-at verilog-ovm-begin-re)
5740 ((looking-at verilog-ovm-end-re)
5742 ;; JBA find VMM macros
5743 ((looking-at verilog-vmm-statement-re)
5745 ((looking-at verilog-vmm-begin-re)
5747 ((looking-at verilog-vmm-end-re)
5749 ;; JBA trying to catch macro lines with no ; at end
5750 ((looking-at "\\<`")
5755 ((= (preceding-char) ?\@)
5758 (verilog-backward-token)
5759 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
5760 ((= (preceding-char) ?\#)
5764 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
5767 (while (= (preceding-char) ?\_)
5770 ((looking-at "\\<else\\>")
5772 ((looking-at verilog-behavioral-block-beg-re)
5774 ((looking-at verilog-indent-re)
5779 (verilog-backward-syntactic-ws)
5781 ((= (preceding-char) ?\:)
5783 (verilog-backward-syntactic-ws)
5785 (if (looking-at verilog-nameable-item-re )
5788 ((= (preceding-char) ?\#)
5791 ((= (preceding-char) ?\`)
5799 (defun verilog-backward-syntactic-ws ()
5800 "Move backwards putting point after first non-whitespace non-comment."
5801 (verilog-skip-backward-comments)
5802 (forward-comment (- (buffer-size))))
5804 (defun verilog-backward-syntactic-ws-quick ()
5805 "As with `verilog-backward-syntactic-ws' but use `verilog-scan' cache."
5806 (while (cond ((bobp)
5808 ((> (skip-syntax-backward " ") 0)
5810 ((eq (preceding-char) ?\n) ;; \n's terminate // so aren't space syntax
5813 ((or (verilog-inside-comment-or-string-p (1- (point)))
5814 (verilog-inside-comment-or-string-p (point)))
5815 (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
5818 (defun verilog-forward-syntactic-ws ()
5819 (verilog-skip-forward-comment-p)
5820 (forward-comment (buffer-size)))
5822 (defun verilog-backward-ws&directives (&optional bound)
5823 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
5824 Optional BOUND limits search."
5826 (let* ((bound (or bound (point-min)))
5829 (if (< bound (point))
5831 (let ((state (save-excursion (verilog-syntax-ppss))))
5833 ((nth 7 state) ;; in // comment
5834 (verilog-re-search-backward "//" nil 'move)
5835 (skip-chars-backward "/"))
5836 ((nth 4 state) ;; in /* */ comment
5837 (verilog-re-search-backward "/\*" nil 'move))))
5838 (narrow-to-region bound (point))
5839 (while (/= here (point))
5841 (verilog-skip-backward-comments)
5846 ((and verilog-highlight-translate-off
5847 (verilog-within-translate-off))
5848 (verilog-back-to-start-translate-off (point-min)))
5849 ((looking-at verilog-directive-re-1)
5853 (if p (goto-char p))))))))
5855 (defun verilog-forward-ws&directives (&optional bound)
5856 "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
5857 Optional BOUND limits search."
5859 (let* ((bound (or bound (point-max)))
5862 (if (> bound (point))
5864 (let ((state (save-excursion (verilog-syntax-ppss))))
5866 ((nth 7 state) ;; in // comment
5869 (skip-chars-forward " \t\n\f")
5871 ((nth 4 state) ;; in /* */ comment
5872 (verilog-re-search-forward "\*\/\\s-*" nil 'move))))
5873 (narrow-to-region (point) bound)
5874 (while (/= here (point))
5877 (forward-comment (buffer-size))
5878 (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ;; Attribute
5879 (goto-char (match-end 0)))
5882 (if (looking-at verilog-directive-re-1)
5885 (beginning-of-line 2))))))))
5887 (defun verilog-in-comment-p ()
5888 "Return true if in a star or // comment."
5889 (let ((state (save-excursion (verilog-syntax-ppss))))
5890 (or (nth 4 state) (nth 7 state))))
5892 (defun verilog-in-star-comment-p ()
5893 "Return true if in a star comment."
5894 (let ((state (save-excursion (verilog-syntax-ppss))))
5896 (nth 4 state) ; t if in a comment of style a // or b /**/
5898 (nth 7 state) ; t if in a comment of style b /**/
5901 (defun verilog-in-slash-comment-p ()
5902 "Return true if in a slash comment."
5903 (let ((state (save-excursion (verilog-syntax-ppss))))
5906 (defun verilog-in-comment-or-string-p ()
5907 "Return true if in a string or comment."
5908 (let ((state (save-excursion (verilog-syntax-ppss))))
5909 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
5911 (defun verilog-in-attribute-p ()
5912 "Return true if point is in an attribute (* [] attribute *)."
5915 (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
5916 (numberp (match-beginning 1)))))
5918 (defun verilog-in-parameter-p ()
5919 "Return true if point is in a parameter assignment #( p1=1, p2=5)."
5922 (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move)
5923 (numberp (match-beginning 1)))))
5925 (defun verilog-in-escaped-name-p ()
5926 "Return true if in an escaped name."
5929 (skip-chars-backward "^ \t\n\f")
5930 (if (equal (char-after (point) ) ?\\ )
5933 (defun verilog-in-directive-p ()
5934 "Return true if in a directive."
5937 (looking-at verilog-directive-re-1)))
5939 (defun verilog-in-parenthesis-p ()
5940 "Return true if in a ( ) expression (but not { } or [ ])."
5943 (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move)
5944 (numberp (match-beginning 1)))))
5946 (defun verilog-in-paren ()
5947 "Return true if in a parenthetical expression.
5948 May cache result using `verilog-syntax-ppss'."
5949 (let ((state (save-excursion (verilog-syntax-ppss))))
5950 (> (nth 0 state) 0 )))
5952 (defun verilog-in-paren-quick ()
5953 "Return true if in a parenthetical expression.
5954 Always starts from `point-min', to allow inserts with hooks disabled."
5955 ;; The -quick refers to its use alongside the other -quick functions,
5956 ;; not that it's likely to be faster than verilog-in-paren.
5957 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
5958 (> (nth 0 state) 0 )))
5960 (defun verilog-in-struct-p ()
5961 "Return true if in a struct declaration."
5964 (if (verilog-in-paren)
5966 (verilog-backward-up-list 1)
5967 (verilog-at-struct-p)
5971 (defun verilog-in-coverage-p ()
5972 "Return true if in a constraint or coverpoint expression."
5975 (if (verilog-in-paren)
5977 (verilog-backward-up-list 1)
5978 (verilog-at-constraint-p)
5981 (defun verilog-at-close-constraint-p ()
5982 "If at the } that closes a constraint or covergroup, return true."
5984 (equal (char-after) ?\})
5988 (verilog-backward-ws&directives)
5989 (if (equal (char-before) ?\;)
5993 (defun verilog-at-constraint-p ()
5994 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
5997 (equal (char-after) ?\{)
5999 (progn (backward-char 1)
6000 (verilog-backward-ws&directives)
6001 (equal (char-before) ?\;))))
6003 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move)
6007 (defun verilog-at-struct-p ()
6008 "If at the { of a struct, return true, moving point to struct."
6010 (if (and (equal (char-after) ?\{)
6011 (verilog-backward-token))
6012 (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6015 (defun verilog-parenthesis-depth ()
6016 "Return non zero if in parenthetical-expression."
6017 (save-excursion (nth 1 (verilog-syntax-ppss))))
6020 (defun verilog-skip-forward-comment-or-string ()
6021 "Return true if in a string or comment."
6022 (let ((state (save-excursion (verilog-syntax-ppss))))
6024 ((nth 3 state) ;Inside string
6025 (search-forward "\"")
6027 ((nth 7 state) ;Inside // comment
6030 ((nth 4 state) ;Inside any comment (hence /**/)
6031 (search-forward "*/"))
6035 (defun verilog-skip-backward-comment-or-string ()
6036 "Return true if in a string or comment."
6037 (let ((state (save-excursion (verilog-syntax-ppss))))
6039 ((nth 3 state) ;Inside string
6040 (search-backward "\"")
6042 ((nth 7 state) ;Inside // comment
6043 (search-backward "//")
6044 (skip-chars-backward "/")
6046 ((nth 4 state) ;Inside /* */ comment
6047 (search-backward "/*")
6052 (defun verilog-skip-backward-comments ()
6053 "Return true if a comment was skipped."
6057 (let ((state (save-excursion (verilog-syntax-ppss))))
6059 ((nth 7 state) ;Inside // comment
6060 (search-backward "//")
6061 (skip-chars-backward "/")
6062 (skip-chars-backward " \t\n\f")
6064 ((nth 4 state) ;Inside /* */ comment
6065 (search-backward "/*")
6066 (skip-chars-backward " \t\n\f")
6069 (= (char-before) ?\/)
6070 (= (char-before (1- (point))) ?\*))
6071 (goto-char (- (point) 2))
6072 t) ;; Let nth 4 state handle the rest
6074 (= (char-before) ?\))
6075 (= (char-before (1- (point))) ?\*))
6076 (goto-char (- (point) 2))
6077 (if (search-backward "(*" nil t)
6079 (skip-chars-backward " \t\n\f")
6082 (goto-char (+ (point) 2))
6085 (/= (skip-chars-backward " \t\n\f") 0))))))))
6087 (defun verilog-skip-forward-comment-p ()
6088 "If in comment, move to end and return true."
6090 (state (save-excursion (verilog-syntax-ppss)))
6092 ((nth 3 state) ;Inside string
6094 ((nth 7 state) ;Inside // comment
6098 ((nth 4 state) ;Inside /* comment
6099 (search-forward "*/")
6101 ((verilog-in-attribute-p) ;Inside (* attribute
6102 (search-forward "*)" nil t)
6105 (skip-chars-forward " \t\n\f")
6108 ((looking-at "\\/\\*")
6111 (goto-char (match-end 0))
6112 (if (search-forward "*/" nil t)
6114 (skip-chars-forward " \t\n\f")
6119 ((looking-at "(\\*")
6122 (goto-char (match-end 0))
6123 (if (search-forward "*)" nil t)
6125 (skip-chars-forward " \t\n\f")
6133 (defun verilog-indent-line-relative ()
6134 "Cheap version of indent line.
6135 Only look at a few lines to determine indent level."
6139 (if (looking-at "^[ \t]*$")
6140 (cond ;- A blank line; No need to be too smart.
6142 (setq indent-str (list 'cpp 0)))
6143 ((verilog-continued-line)
6144 (let ((sp1 (point)))
6145 (if (verilog-continued-line)
6149 (list 'statement (verilog-current-indent-level))))
6151 (setq indent-str (list 'block (verilog-current-indent-level)))))
6154 (setq indent-str (verilog-calculate-indent))))
6155 (progn (skip-chars-forward " \t")
6156 (setq indent-str (verilog-calculate-indent))))
6157 (verilog-do-indent indent-str)))
6159 (defun verilog-indent-line ()
6160 "Indent for special part of code."
6161 (verilog-do-indent (verilog-calculate-indent)))
6163 (defun verilog-do-indent (indent-str)
6164 (let ((type (car indent-str))
6165 (ind (car (cdr indent-str))))
6167 (; handle continued exp
6169 (let ((here (point)))
6170 (verilog-backward-syntactic-ws)
6173 (= (preceding-char) ?\,)
6174 (= (preceding-char) ?\])
6176 (verilog-beg-of-statement-1)
6177 (looking-at verilog-declaration-re)))
6182 (verilog-beg-of-statement-1)
6184 (if (looking-at verilog-declaration-re)
6185 (progn ;; we have multiple words
6186 (goto-char (match-end 0))
6187 (skip-chars-forward " \t")
6189 ((and verilog-indent-declaration-macros
6190 (= (following-char) ?\`))
6194 (skip-chars-forward " \t")))
6195 ((= (following-char) ?\[)
6198 (verilog-backward-up-list -1)
6199 (skip-chars-forward " \t"))))
6203 (+ (current-column) verilog-cexp-indent))))))
6205 (indent-line-to val)
6206 (if (and (not verilog-indent-lists)
6208 (verilog-pretty-declarations-auto))
6210 ((= (preceding-char) ?\) )
6212 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6213 (indent-line-to val)))
6217 (verilog-beg-of-statement-1)
6218 (if (and (< (point) here)
6219 (verilog-re-search-forward "=[ \\t]*" here 'move))
6220 (setq val (current-column))
6221 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
6223 (indent-line-to val))))))
6225 (; handle inside parenthetical expressions
6226 (eq type 'cparenexp)
6228 (val (save-excursion
6229 (verilog-backward-up-list 1)
6231 (if verilog-indent-lists
6232 (skip-chars-forward " \t")
6233 (verilog-forward-syntactic-ws))
6237 (decl (save-excursion
6239 (verilog-forward-syntactic-ws)
6241 (looking-at verilog-declaration-re))))
6242 (indent-line-to val)
6244 (verilog-pretty-declarations-auto))))
6246 (;-- Handle the ends
6248 (looking-at verilog-end-block-re )
6249 (verilog-at-close-constraint-p))
6250 (let ((val (if (eq type 'statement)
6251 (- ind verilog-indent-level)
6253 (indent-line-to val)))
6255 (;-- Case -- maybe line 'em up
6256 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
6259 ((looking-at "\\<endcase\\>")
6260 (indent-line-to ind))
6262 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6263 (indent-line-to val))))))
6266 (and (eq type 'defun)
6267 (looking-at verilog-zero-indent-re))
6274 (looking-at verilog-declaration-re))
6275 (verilog-indent-declaration ind))
6277 (;-- Everything else
6279 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6280 (indent-line-to val))))
6282 (if (looking-at "[ \t]+$")
6283 (skip-chars-forward " \t"))
6284 indent-str ; Return indent data
6287 (defun verilog-current-indent-level ()
6288 "Return the indent-level of the current statement."
6292 (setq par-pos (verilog-parenthesis-depth))
6296 (setq par-pos (verilog-parenthesis-depth)))
6297 (skip-chars-forward " \t")
6300 (defun verilog-case-indent-level ()
6301 "Return the indent-level of the current statement.
6302 Do not count named blocks or case-statements."
6304 (skip-chars-forward " \t")
6306 ((looking-at verilog-named-block-re)
6308 ((and (not (looking-at verilog-extended-case-re))
6309 (looking-at "^[^:;]+[ \t]*:"))
6310 (verilog-re-search-forward ":" nil t)
6311 (skip-chars-forward " \t")
6314 (current-column)))))
6316 (defun verilog-indent-comment ()
6317 "Indent current line as comment."
6320 ((verilog-in-star-comment-p)
6322 (re-search-backward "/\\*" nil t)
6323 (1+(current-column))))
6328 (re-search-backward "//" nil t)
6329 (current-column))))))
6330 (indent-line-to stcol)
6333 (defun verilog-more-comment ()
6334 "Make more comment lines like the previous."
6338 ((verilog-in-star-comment-p)
6341 (re-search-backward "/\\*" nil t)
6342 (1+(current-column))))
6347 (re-search-backward "//" nil t)
6348 (current-column))))))
6354 (skip-chars-forward " \t")
6358 (defun verilog-comment-indent (&optional arg)
6359 "Return the column number the line should be indented to.
6360 ARG is ignored, for `comment-indent-function' compatibility."
6362 ((verilog-in-star-comment-p)
6364 (re-search-backward "/\\*" nil t)
6365 (1+(current-column))))
6370 (re-search-backward "//" nil t)
6371 (current-column)))))
6375 (defun verilog-pretty-declarations-auto (&optional quiet)
6376 "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'."
6377 (when (or (eq 'all verilog-auto-lineup)
6378 (eq 'declarations verilog-auto-lineup))
6379 (verilog-pretty-declarations quiet)))
6381 (defun verilog-pretty-declarations (&optional quiet)
6382 "Line up declarations around point.
6383 Be verbose about progress unless optional QUIET set."
6385 (let* ((m1 (make-marker))
6399 ; (verilog-beg-of-statement-1)
6401 (verilog-forward-syntactic-ws)
6402 (and (not (verilog-in-directive-p)) ;; could have `define input foo
6403 (looking-at verilog-declaration-re)))
6405 (if (verilog-parenthesis-depth)
6406 ;; in an argument list or parameter block
6407 (setq el (verilog-backward-up-list -1)
6410 (verilog-backward-up-list 1)
6411 (forward-line) ;; ignore ( input foo,
6412 (verilog-re-search-forward verilog-declaration-re el 'move)
6413 (goto-char (match-beginning 0))
6414 (skip-chars-backward " \t")
6416 startpos (set-marker (make-marker) start)
6419 (verilog-backward-up-list -1)
6421 (verilog-backward-syntactic-ws)
6423 endpos (set-marker (make-marker) end)
6427 (skip-chars-forward " \t")
6430 ;; in a declaration block (not in argument list)
6433 (verilog-beg-of-statement-1)
6434 (while (and (looking-at verilog-declaration-re)
6436 (skip-chars-backward " \t")
6439 (verilog-backward-syntactic-ws)
6441 (verilog-beg-of-statement-1))
6443 startpos (set-marker (make-marker) start)
6446 (verilog-end-of-statement)
6447 (setq e (point)) ;Might be on last line
6448 (verilog-forward-syntactic-ws)
6449 (while (looking-at verilog-declaration-re)
6450 (verilog-end-of-statement)
6452 (verilog-forward-syntactic-ws))
6454 endpos (set-marker (make-marker) end)
6457 (verilog-do-indent (verilog-calculate-indent))
6458 (verilog-forward-ws&directives)
6460 ;; OK, start and end are set
6461 (goto-char (marker-position startpos))
6462 (if (and (not quiet)
6463 (> (- end start) 100))
6464 (message "Lining up declarations..(please stand by)"))
6465 ;; Get the beginning of line indent first
6466 (while (progn (setq e (marker-position endpos))
6469 ((save-excursion (skip-chars-backward " \t")
6471 (verilog-forward-ws&directives)
6472 (indent-line-to base-ind)
6473 (verilog-forward-ws&directives)
6475 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6478 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6481 ;; Now find biggest prefix
6482 (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
6483 ;; Now indent each line.
6484 (goto-char (marker-position startpos))
6485 (while (progn (setq e (marker-position endpos))
6486 (setq r (- e (point)))
6489 (unless quiet (message "%d" r))
6490 ;;(verilog-do-indent (verilog-calculate-indent)))
6491 (verilog-forward-ws&directives)
6493 ((or (and verilog-indent-declaration-macros
6494 (looking-at verilog-declaration-re-2-macro))
6495 (looking-at verilog-declaration-re-2-no-macro))
6496 (let ((p (match-end 0)))
6498 (if (verilog-re-search-forward "[[#`]" p 'move)
6502 (goto-char (marker-position m1))
6508 ((verilog-continued-line-1 (marker-position startpos))
6510 (indent-line-to ind))
6511 ((verilog-in-struct-p)
6512 ;; could have a declaration of a user defined item
6514 (verilog-end-of-statement))
6515 (t ; Must be comment or white space
6517 (verilog-forward-ws&directives)
6520 (unless quiet (message "")))))))
6522 (defun verilog-pretty-expr (&optional quiet myre)
6523 "Line up expressions around point, optionally QUIET with regexp MYRE ignored."
6525 (if (not (verilog-in-comment-or-string-p))
6527 (let ( (rexp (concat "^\\s-*" verilog-complete-reg))
6528 (rexp1 (concat "^\\s-*" verilog-basic-complete-re)))
6530 (if (and (not (looking-at rexp ))
6531 (looking-at verilog-assignment-operation-re)
6533 (goto-char (match-end 2))
6534 (and (not (verilog-in-attribute-p))
6535 (not (verilog-in-parameter-p))
6536 (not (verilog-in-comment-or-string-p)))))
6537 (let* ((here (point))
6543 (verilog-backward-syntactic-ws)
6545 (while (and (not (looking-at rexp1))
6546 (looking-at verilog-assignment-operation-re)
6550 (verilog-backward-syntactic-ws)
6552 ) ;Ack, need to grok `define
6558 (setq e (point)) ;Might be on last line
6559 (verilog-forward-syntactic-ws)
6562 (not (looking-at rexp1 ))
6563 (looking-at verilog-assignment-operation-re)
6566 (not (eq e (point)))))
6568 (verilog-forward-syntactic-ws)
6572 (endpos (set-marker (make-marker) end))
6576 (verilog-do-indent (verilog-calculate-indent))
6577 (if (and (not quiet)
6578 (> (- end start) 100))
6579 (message "Lining up expressions..(please stand by)"))
6581 ;; Set indent to minimum throughout region
6582 (while (< (point) (marker-position endpos))
6584 (verilog-just-one-space verilog-assignment-operation-re)
6586 (verilog-do-indent (verilog-calculate-indent))
6588 (verilog-forward-syntactic-ws)
6591 ;; Now find biggest prefix
6592 (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))
6594 ;; Now indent each line.
6596 (while (progn (setq e (marker-position endpos))
6597 (setq r (- e (point)))
6600 (if (not quiet) (message "%d" r))
6602 ((looking-at verilog-assignment-operation-re)
6603 (goto-char (match-beginning 2))
6604 (if (not (or (verilog-in-parenthesis-p) ;; leave attributes and comparisons alone
6605 (verilog-in-coverage-p)))
6606 (if (eq (char-after) ?=)
6607 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
6611 ((verilog-continued-line-1 start)
6613 (indent-line-to ind))
6614 (t ; Must be comment or white space
6616 (verilog-forward-ws&directives)
6620 (unless quiet (message ""))
6623 (defun verilog-just-one-space (myre)
6624 "Remove extra spaces around regular expression MYRE."
6626 (if (and (not(looking-at verilog-complete-reg))
6628 (let ((p1 (match-end 1))
6634 (just-one-space)))))
6636 (defun verilog-indent-declaration (baseind)
6637 "Indent current lines as declaration.
6638 Line up the variable names based on previous declaration's indentation.
6639 BASEIND is the base indent to offset everything."
6641 (let ((pos (point-marker))
6642 (lim (save-excursion
6643 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
6644 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
6650 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6651 (indent-line-to val)
6653 ;; Use previous declaration (in this module) as template.
6654 (if (or (eq 'all verilog-auto-lineup)
6655 (eq 'declarations verilog-auto-lineup))
6656 (if (verilog-re-search-backward
6657 (or (and verilog-indent-declaration-macros
6658 verilog-declaration-re-1-macro)
6659 verilog-declaration-re-1-no-macro) lim t)
6661 (goto-char (match-end 0))
6662 (skip-chars-forward " \t")
6663 (setq ind (current-column))
6667 (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6668 (indent-line-to val)
6669 (if (and verilog-indent-declaration-macros
6670 (looking-at verilog-declaration-re-2-macro))
6671 (let ((p (match-end 0)))
6673 (if (verilog-re-search-forward "[[#`]" p 'move)
6677 (goto-char (marker-position m1))
6680 (if (/= (current-column) ind)
6684 (if (looking-at verilog-declaration-re-2-no-macro)
6685 (let ((p (match-end 0)))
6687 (if (verilog-re-search-forward "[[`#]" p 'move)
6691 (goto-char (marker-position m1))
6694 (if (/= (current-column) ind)
6697 (indent-to ind))))))))))
6700 (defun verilog-get-lineup-indent (b edpos)
6701 "Return the indent level that will line up several lines within the region.
6702 Region is defined by B and EDPOS."
6706 ;; Get rightmost position
6707 (while (progn (setq e (marker-position edpos))
6709 (if (verilog-re-search-forward
6710 (or (and verilog-indent-declaration-macros
6711 verilog-declaration-re-1-macro)
6712 verilog-declaration-re-1-no-macro) e 'move)
6714 (goto-char (match-end 0))
6715 (verilog-backward-syntactic-ws)
6716 (if (> (current-column) ind)
6717 (setq ind (current-column)))
6718 (goto-char (match-end 0)))))
6721 ;; No lineup-string found
6724 (verilog-backward-syntactic-ws)
6725 ;;(skip-chars-backward " \t")
6726 (1+ (current-column))))))
6728 (defun verilog-get-lineup-indent-2 (myre b edpos)
6729 "Return the indent level that will line up several lines within the region."
6733 ;; Get rightmost position
6734 (while (progn (setq e (marker-position edpos))
6736 (if (and (verilog-re-search-forward myre e 'move)
6737 (not (verilog-in-attribute-p))) ;; skip attribute exprs
6739 (goto-char (match-beginning 2))
6740 (verilog-backward-syntactic-ws)
6741 (if (> (current-column) ind)
6742 (setq ind (current-column)))
6743 (goto-char (match-end 0)))
6747 ;; No lineup-string found
6750 (skip-chars-backward " \t")
6751 (1+ (current-column))))))
6753 (defun verilog-comment-depth (type val)
6754 "A useful mode debugging aide. TYPE and VAL are comments for insertion."
6762 (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t)
6764 (replace-match " /* -# ## */")
6768 (insert " /* ## ## */"))))
6771 (format "%s %d" type val))))
6777 (defvar verilog-str nil)
6778 (defvar verilog-all nil)
6779 (defvar verilog-pred nil)
6780 (defvar verilog-buffer-to-use nil)
6781 (defvar verilog-flag nil)
6782 (defvar verilog-toggle-completions nil
6783 "True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
6784 Repeated use of \\[verilog-complete-word] will show you all of them.
6785 Normally, when there is more than one possible completion,
6786 it displays a list of all possible completions.")
6789 (defvar verilog-type-keywords
6791 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
6792 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
6793 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
6794 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
6795 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
6796 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
6798 "Keywords for types used when completing a word in a declaration or parmlist.
6799 \(integer, real, reg...)")
6801 (defvar verilog-cpp-keywords
6802 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
6804 "Keywords to complete when at first word of a line in declarative scope.
6805 \(initial, always, begin, assign...)
6806 The procedures and variables defined within the Verilog program
6807 will be completed at runtime and should not be added to this list.")
6809 (defvar verilog-defun-keywords
6812 "always" "always_comb" "always_ff" "always_latch" "assign"
6813 "begin" "end" "generate" "endgenerate" "module" "endmodule"
6814 "specify" "endspecify" "function" "endfunction" "initial" "final"
6815 "task" "endtask" "primitive" "endprimitive"
6817 verilog-type-keywords)
6818 "Keywords to complete when at first word of a line in declarative scope.
6819 \(initial, always, begin, assign...)
6820 The procedures and variables defined within the Verilog program
6821 will be completed at runtime and should not be added to this list.")
6823 (defvar verilog-block-keywords
6825 "begin" "break" "case" "continue" "else" "end" "endfunction"
6826 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
6827 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
6829 "Keywords to complete when at first word of a line in behavioral scope.
6830 \(begin, if, then, else, for, fork...)
6831 The procedures and variables defined within the Verilog program
6832 will be completed at runtime and should not be added to this list.")
6834 (defvar verilog-tf-keywords
6835 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
6836 "Keywords to complete when at first word of a line in a task or function.
6837 \(begin, if, then, else, for, fork.)
6838 The procedures and variables defined within the Verilog program
6839 will be completed at runtime and should not be added to this list.")
6841 (defvar verilog-case-keywords
6842 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
6843 "Keywords to complete when at first word of a line in case scope.
6844 \(begin, if, then, else, for, fork...)
6845 The procedures and variables defined within the Verilog program
6846 will be completed at runtime and should not be added to this list.")
6848 (defvar verilog-separator-keywords
6849 '("else" "then" "begin")
6850 "Keywords to complete when NOT standing at the first word of a statement.
6851 \(else, then, begin...)
6852 Variables and function names defined within the Verilog program
6853 will be completed at runtime and should not be added to this list.")
6855 (defvar verilog-gate-ios
6856 ;; All these have an implied {"input"...} at the end
6870 ("pulldown" "output")
6875 ("rtran" "inout" "inout")
6876 ("rtranif0" "inout" "inout")
6877 ("rtranif1" "inout" "inout")
6878 ("tran" "inout" "inout")
6879 ("tranif0" "inout" "inout")
6880 ("tranif1" "inout" "inout")
6883 "Map of direction for each positional argument to each gate primitive.")
6885 (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
6886 "Keywords for gate primitives.")
6888 (defun verilog-string-diff (str1 str2)
6889 "Return index of first letter where STR1 and STR2 differs."
6893 (if (or (> (1+ diff) (length str1))
6894 (> (1+ diff) (length str2)))
6896 (or (equal (aref str1 diff) (aref str2 diff))
6898 (setq diff (1+ diff))))))
6900 ;; Calculate all possible completions for functions if argument is `function',
6901 ;; completions for procedures if argument is `procedure' or both functions and
6902 ;; procedures otherwise.
6904 (defun verilog-func-completion (type)
6905 "Build regular expression for module/task/function names.
6906 TYPE is 'module, 'tf for task or function, or t if unknown."
6907 (if (string= verilog-str "")
6908 (setq verilog-str "[a-zA-Z_]"))
6909 (let ((verilog-str (concat (cond
6910 ((eq type 'module) "\\<\\(module\\)\\s +")
6911 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
6912 (t "\\<\\(task\\|function\\|module\\)\\s +"))
6913 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
6916 (if (not (looking-at verilog-defun-re))
6917 (verilog-re-search-backward verilog-defun-re nil t))
6920 ;; Search through all reachable functions
6921 (goto-char (point-min))
6922 (while (verilog-re-search-forward verilog-str (point-max) t)
6923 (progn (setq match (buffer-substring (match-beginning 2)
6925 (if (or (null verilog-pred)
6926 (funcall verilog-pred match))
6927 (setq verilog-all (cons match verilog-all)))))
6928 (if (match-beginning 0)
6929 (goto-char (match-beginning 0)))))
6931 (defun verilog-get-completion-decl (end)
6932 "Macro for searching through current declaration (var, type or const)
6933 for matches of `str' and adding the occurrence tp `all' through point END."
6934 (let ((re (or (and verilog-indent-declaration-macros
6935 verilog-declaration-re-2-macro)
6936 verilog-declaration-re-2-no-macro))
6939 (while (and (< (point) end)
6940 (verilog-re-search-forward re end t))
6941 ;; Traverse current line
6942 (setq decl-end (save-excursion (verilog-declaration-end)))
6943 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
6944 (not (match-end 1)))
6945 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
6946 (if (string-match (concat "\\<" verilog-str) match)
6947 (if (or (null verilog-pred)
6948 (funcall verilog-pred match))
6949 (setq verilog-all (cons match verilog-all)))))
6953 (defun verilog-type-completion ()
6954 "Calculate all possible completions for types."
6955 (let ((start (point))
6957 ;; Search for all reachable type declarations
6958 (while (or (verilog-beg-of-defun)
6959 (setq goon (not goon)))
6961 (if (and (< start (prog1 (save-excursion (verilog-end-of-defun)
6964 (verilog-re-search-forward
6965 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
6967 (not (match-end 1)))
6968 ;; Check current type declaration
6969 (verilog-get-completion-decl start))))))
6971 (defun verilog-var-completion ()
6972 "Calculate all possible completions for variables (or constants)."
6973 (let ((start (point)))
6974 ;; Search for all reachable var declarations
6975 (verilog-beg-of-defun)
6977 ;; Check var declarations
6978 (verilog-get-completion-decl start))))
6980 (defun verilog-keyword-completion (keyword-list)
6981 "Give list of all possible completions of keywords in KEYWORD-LIST."
6983 (if (string-match (concat "\\<" verilog-str) s)
6984 (if (or (null verilog-pred)
6985 (funcall verilog-pred s))
6986 (setq verilog-all (cons s verilog-all)))))
6990 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
6991 "Function passed to `completing-read', `try-completion' or `all-completions'.
6992 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
6993 must be a function to be called for every match to check if this should
6994 really be a match. If VERILOG-FLAG is t, the function returns a list of
6995 all possible completions. If VERILOG-FLAG is nil it returns a string,
6996 the longest possible completion, or t if VERILOG-STR is an exact match.
6997 If VERILOG-FLAG is 'lambda, the function returns t if VERILOG-STR is an
6998 exact match, nil otherwise."
7000 (let ((verilog-all nil))
7001 ;; Set buffer to use for searching labels. This should be set
7002 ;; within functions which use verilog-completions
7003 (set-buffer verilog-buffer-to-use)
7005 ;; Determine what should be completed
7006 (let ((state (car (verilog-calculate-indent))))
7007 (cond ((eq state 'defun)
7008 (save-excursion (verilog-var-completion))
7009 (verilog-func-completion 'module)
7010 (verilog-keyword-completion verilog-defun-keywords))
7012 ((eq state 'behavioral)
7013 (save-excursion (verilog-var-completion))
7014 (verilog-func-completion 'module)
7015 (verilog-keyword-completion verilog-defun-keywords))
7018 (save-excursion (verilog-var-completion))
7019 (verilog-func-completion 'tf)
7020 (verilog-keyword-completion verilog-block-keywords))
7023 (save-excursion (verilog-var-completion))
7024 (verilog-func-completion 'tf)
7025 (verilog-keyword-completion verilog-case-keywords))
7028 (save-excursion (verilog-var-completion))
7029 (verilog-func-completion 'tf)
7030 (verilog-keyword-completion verilog-tf-keywords))
7033 (save-excursion (verilog-var-completion))
7034 (verilog-keyword-completion verilog-cpp-keywords))
7036 ((eq state 'cparenexp)
7037 (save-excursion (verilog-var-completion)))
7040 (save-excursion (verilog-var-completion))
7041 (verilog-func-completion 'both)
7042 (verilog-keyword-completion verilog-separator-keywords))))
7044 ;; Now we have built a list of all matches. Give response to caller
7045 (verilog-completion-response))))
7047 (defun verilog-completion-response ()
7048 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
7049 ;; This was not called by all-completions
7050 (if (null verilog-all)
7051 ;; Return nil if there was no matching label
7053 ;; Get longest string common in the labels
7054 (let* ((elm (cdr verilog-all))
7055 (match (car verilog-all))
7056 (min (length match))
7058 (if (string= match verilog-str)
7059 ;; Return t if first match was an exact match
7061 (while (not (null elm))
7062 ;; Find longest common string
7063 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
7066 (setq match (substring match 0 min))))
7067 ;; Terminate with match=t if this is an exact match
7068 (if (string= (car elm) verilog-str)
7072 (setq elm (cdr elm)))))
7073 ;; If this is a test just for exact match, return nil ot t
7074 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
7077 ;; If flag is t, this was called by all-completions. Return
7078 ;; list of all possible completions
7082 (defvar verilog-last-word-numb 0)
7083 (defvar verilog-last-word-shown nil)
7084 (defvar verilog-last-completions nil)
7086 (defun verilog-complete-word ()
7087 "Complete word at current point.
7088 \(See also `verilog-toggle-completions', `verilog-type-keywords',
7089 and `verilog-separator-keywords'.)"
7091 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7092 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7093 (verilog-str (buffer-substring b e))
7094 ;; The following variable is used in verilog-completion
7095 (verilog-buffer-to-use (current-buffer))
7096 (allcomp (if (and verilog-toggle-completions
7097 (string= verilog-last-word-shown verilog-str))
7098 verilog-last-completions
7099 (all-completions verilog-str 'verilog-completion)))
7100 (match (if verilog-toggle-completions
7102 verilog-str (mapcar (lambda (elm)
7103 (cons elm 0)) allcomp)))))
7104 ;; Delete old string
7107 ;; Toggle-completions inserts whole labels
7108 (if verilog-toggle-completions
7110 ;; Update entry number in list
7111 (setq verilog-last-completions allcomp
7112 verilog-last-word-numb
7113 (if (>= verilog-last-word-numb (1- (length allcomp)))
7115 (1+ verilog-last-word-numb)))
7116 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
7117 ;; Display next match or same string if no match was found
7118 (if (not (null allcomp))
7119 (insert "" verilog-last-word-shown)
7120 (insert "" verilog-str)
7121 (message "(No match)")))
7122 ;; The other form of completion does not necessarily do that.
7124 ;; Insert match if found, or the original string if no match
7125 (if (or (null match) (equal match 't))
7126 (progn (insert "" verilog-str)
7127 (message "(No match)"))
7129 ;; Give message about current status of completion
7130 (cond ((equal match 't)
7131 (if (not (null (cdr allcomp)))
7132 (message "(Complete but not unique)")
7133 (message "(Sole completion)")))
7134 ;; Display buffer if the current completion didn't help
7135 ;; on completing the label.
7136 ((and (not (null (cdr allcomp))) (= (length verilog-str)
7138 (with-output-to-temp-buffer "*Completions*"
7139 (display-completion-list allcomp))
7140 ;; Wait for a key press. Then delete *Completion* window
7141 (momentary-string-display "" (point))
7142 (delete-window (get-buffer-window (get-buffer "*Completions*")))
7145 (defun verilog-show-completions ()
7146 "Show all possible completions at current point."
7148 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7149 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7150 (verilog-str (buffer-substring b e))
7151 ;; The following variable is used in verilog-completion
7152 (verilog-buffer-to-use (current-buffer))
7153 (allcomp (if (and verilog-toggle-completions
7154 (string= verilog-last-word-shown verilog-str))
7155 verilog-last-completions
7156 (all-completions verilog-str 'verilog-completion))))
7157 ;; Show possible completions in a temporary buffer.
7158 (with-output-to-temp-buffer "*Completions*"
7159 (display-completion-list allcomp))
7160 ;; Wait for a key press. Then delete *Completion* window
7161 (momentary-string-display "" (point))
7162 (delete-window (get-buffer-window (get-buffer "*Completions*")))))
7165 (defun verilog-get-default-symbol ()
7166 "Return symbol around current point as a string."
7168 (buffer-substring (progn
7169 (skip-chars-backward " \t")
7170 (skip-chars-backward "a-zA-Z0-9_")
7173 (skip-chars-forward "a-zA-Z0-9_")
7176 (defun verilog-build-defun-re (str &optional arg)
7177 "Return function/task/module starting with STR as regular expression.
7178 With optional second ARG non-nil, STR is the complete name of the instruction."
7180 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
7181 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
7183 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
7184 "Function passed to `completing-read', `try-completion' or `all-completions'.
7185 Returns a completion on any function name based on VERILOG-STR prefix. If
7186 VERILOG-PRED is non-nil, it must be a function to be called for every match
7187 to check if this should really be a match. If VERILOG-FLAG is t, the
7188 function returns a list of all possible completions. If it is nil it
7189 returns a string, the longest possible completion, or t if VERILOG-STR is
7190 an exact match. If VERILOG-FLAG is 'lambda, the function returns t if
7191 VERILOG-STR is an exact match, nil otherwise."
7193 (let ((verilog-all nil)
7196 ;; Set buffer to use for searching labels. This should be set
7197 ;; within functions which use verilog-completions
7198 (set-buffer verilog-buffer-to-use)
7200 (let ((verilog-str verilog-str))
7201 ;; Build regular expression for functions
7202 (if (string= verilog-str "")
7203 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
7204 (setq verilog-str (verilog-build-defun-re verilog-str)))
7205 (goto-char (point-min))
7207 ;; Build a list of all possible completions
7208 (while (verilog-re-search-forward verilog-str nil t)
7209 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
7210 (if (or (null verilog-pred)
7211 (funcall verilog-pred match))
7212 (setq verilog-all (cons match verilog-all)))))
7214 ;; Now we have built a list of all matches. Give response to caller
7215 (verilog-completion-response))))
7217 (defun verilog-goto-defun ()
7218 "Move to specified Verilog module/interface/task/function.
7219 The default is a name found in the buffer around point.
7220 If search fails, other files are checked based on
7221 `verilog-library-flags'."
7223 (let* ((default (verilog-get-default-symbol))
7224 ;; The following variable is used in verilog-comp-function
7225 (verilog-buffer-to-use (current-buffer))
7226 (label (if (not (string= default ""))
7227 ;; Do completion with default
7228 (completing-read (concat "Goto-Label: (default "
7230 'verilog-comp-defun nil nil "")
7231 ;; There is no default value. Complete without it
7232 (completing-read "Goto-Label: "
7233 'verilog-comp-defun nil nil "")))
7235 ;; Make sure library paths are correct, in case need to resolve module
7236 (verilog-auto-reeval-locals)
7237 (verilog-getopt-flags)
7238 ;; If there was no response on prompt, use default value
7239 (if (string= label "")
7240 (setq label default))
7241 ;; Goto right place in buffer if label is not an empty string
7242 (or (string= label "")
7245 (goto-char (point-min))
7247 (re-search-forward (verilog-build-defun-re label t) nil t)))
7250 (beginning-of-line))
7252 (verilog-goto-defun-file label))))
7254 ;; Eliminate compile warning
7255 (defvar occur-pos-list)
7257 (defun verilog-showscopes ()
7258 "List all scopes in this module."
7260 (let ((buffer (current-buffer))
7264 (prevpos (point-min))
7265 (final-context-start (make-marker))
7266 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
7267 (with-output-to-temp-buffer "*Occur*"
7269 (message (format "Searching for %s ..." regexp))
7270 ;; Find next match, but give up if prev match was at end of buffer.
7271 (while (and (not (= prevpos (point-max)))
7272 (verilog-re-search-forward regexp nil t))
7273 (goto-char (match-beginning 0))
7276 (setq linenum (+ linenum (count-lines prevpos (point)))))
7277 (setq prevpos (point))
7278 (goto-char (match-end 0))
7279 (let* ((start (save-excursion
7280 (goto-char (match-beginning 0))
7281 (forward-line (if (< nlines 0) nlines (- nlines)))
7283 (end (save-excursion
7284 (goto-char (match-end 0))
7286 (forward-line (1+ nlines))
7289 (tag (format "%3d" linenum))
7290 (empty (make-string (length tag) ?\ ))
7293 (setq tem (make-marker))
7294 (set-marker tem (point))
7295 (set-buffer standard-output)
7296 (setq occur-pos-list (cons tem occur-pos-list))
7297 (or first (zerop nlines)
7298 (insert "--------\n"))
7300 (insert-buffer-substring buffer start end)
7301 (backward-char (- end start))
7302 (setq tem (if (< nlines 0) (- nlines) nlines))
7306 (setq tem (1- tem)))
7307 (let ((this-linenum linenum))
7308 (set-marker final-context-start
7309 (+ (point) (- (match-end 0) (match-beginning 0))))
7310 (while (< (point) final-context-start)
7312 (setq tag (format "%3d" this-linenum)))
7313 (insert tag ?:)))))))
7314 (set-buffer-modified-p nil))))
7317 ;; Highlight helper functions
7318 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
7319 (defun verilog-within-translate-off ()
7320 "Return point if within translate-off region, else nil."
7321 (and (save-excursion
7323 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
7325 (equal "off" (match-string 2))
7328 (defun verilog-start-translate-off (limit)
7329 "Return point before translate-off directive if before LIMIT, else nil."
7330 (when (re-search-forward
7331 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7333 (match-beginning 0)))
7335 (defun verilog-back-to-start-translate-off (limit)
7336 "Return point before translate-off directive if before LIMIT, else nil."
7337 (when (re-search-backward
7338 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7340 (match-beginning 0)))
7342 (defun verilog-end-translate-off (limit)
7343 "Return point after translate-on directive if before LIMIT, else nil."
7345 (re-search-forward (concat
7346 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
7348 (defun verilog-match-translate-off (limit)
7349 "Match a translate-off block, setting `match-data' and returning t, else nil.
7350 Bound search by LIMIT."
7351 (when (< (point) limit)
7352 (let ((start (or (verilog-within-translate-off)
7353 (verilog-start-translate-off limit)))
7354 (case-fold-search t))
7356 (let ((end (or (verilog-end-translate-off limit) limit)))
7357 (set-match-data (list start end))
7358 (goto-char end))))))
7360 (defun verilog-font-lock-match-item (limit)
7361 "Match, and move over, any declaration item after point.
7362 Bound search by LIMIT. Adapted from
7363 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
7366 (narrow-to-region (point-min) limit)
7368 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
7370 (goto-char (match-end 1))
7371 ;; move to next item
7372 (if (looking-at "\\(\\s-*,\\)")
7373 (goto-char (match-end 1))
7378 ;; Added by Subbu Meiyappan for Header
7380 (defun verilog-header ()
7381 "Insert a standard Verilog file header.
7382 See also `verilog-sk-header' for an alternative format."
7384 (let ((start (point)))
7386 //-----------------------------------------------------------------------------
7388 // Project : <project>
7389 //-----------------------------------------------------------------------------
7390 // File : <filename>
7391 // Author : <author>
7392 // Created : <credate>
7393 // Last modified : <moddate>
7394 //-----------------------------------------------------------------------------
7397 //-----------------------------------------------------------------------------
7398 // Copyright (c) <copydate> by <company> This model is the confidential and
7399 // proprietary property of <company> and the possession or use of this
7400 // file requires a written license from <company>.
7401 //------------------------------------------------------------------------------
7402 // Modification history :
7404 //-----------------------------------------------------------------------------
7408 (search-forward "<filename>")
7409 (replace-match (buffer-name) t t)
7410 (search-forward "<author>") (replace-match "" t t)
7411 (insert (user-full-name))
7412 (insert " <" (user-login-name) "@" (system-name) ">")
7413 (search-forward "<credate>") (replace-match "" t t)
7414 (verilog-insert-date)
7415 (search-forward "<moddate>") (replace-match "" t t)
7416 (verilog-insert-date)
7417 (search-forward "<copydate>") (replace-match "" t t)
7418 (verilog-insert-year)
7419 (search-forward "<modhist>") (replace-match "" t t)
7420 (verilog-insert-date)
7421 (insert " : created")
7424 (setq string (read-string "title: "))
7425 (search-forward "<title>")
7426 (replace-match string t t)
7427 (setq string (read-string "project: " verilog-project))
7428 (setq verilog-project string)
7429 (search-forward "<project>")
7430 (replace-match string t t)
7431 (setq string (read-string "Company: " verilog-company))
7432 (setq verilog-company string)
7433 (search-forward "<company>")
7434 (replace-match string t t)
7435 (search-forward "<company>")
7436 (replace-match string t t)
7437 (search-forward "<company>")
7438 (replace-match string t t)
7439 (search-backward "<description>")
7440 (replace-match "" t t))))
7442 ;; verilog-header Uses the verilog-insert-date function
7444 (defun verilog-insert-date ()
7445 "Insert date from the system."
7447 (if verilog-date-scientific-format
7448 (insert (format-time-string "%Y/%m/%d"))
7449 (insert (format-time-string "%d.%m.%Y"))))
7451 (defun verilog-insert-year ()
7452 "Insert year from the system."
7454 (insert (format-time-string "%Y")))
7458 ;; Signal list parsing
7461 ;; Elements of a signal list
7462 ;; Unfortunately we use 'assoc' on this, so can't be a vector
7463 (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
7464 (list name bits comment mem enum signed type multidim modport))
7465 (defsubst verilog-sig-name (sig)
7467 (defsubst verilog-sig-bits (sig)
7469 (defsubst verilog-sig-comment (sig)
7471 (defsubst verilog-sig-memory (sig)
7473 (defsubst verilog-sig-enum (sig)
7475 (defsubst verilog-sig-signed (sig)
7477 (defsubst verilog-sig-type (sig)
7479 (defsubst verilog-sig-type-set (sig type)
7480 (setcar (nthcdr 6 sig) type))
7481 (defsubst verilog-sig-multidim (sig)
7483 (defsubst verilog-sig-multidim-string (sig)
7484 (if (verilog-sig-multidim sig)
7485 (let ((str "") (args (verilog-sig-multidim sig)))
7487 (setq str (concat str (car args)))
7488 (setq args (cdr args)))
7490 (defsubst verilog-sig-modport (sig)
7492 (defsubst verilog-sig-width (sig)
7493 (verilog-make-width-expression (verilog-sig-bits sig)))
7495 (defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
7496 (vector outputs-del outputs-imm temps inputs))
7497 (defsubst verilog-alw-get-outputs-delayed (sigs)
7499 (defsubst verilog-alw-get-outputs-immediate (sigs)
7501 (defsubst verilog-alw-get-temps (sigs)
7503 (defsubst verilog-alw-get-inputs (sigs)
7505 (defsubst verilog-alw-get-uses-delayed (sigs)
7508 (defsubst verilog-modport-new (name clockings decls)
7509 (list name clockings decls))
7510 (defsubst verilog-modport-name (sig)
7512 (defsubst verilog-modport-clockings (sig)
7513 (nth 1 sig)) ;; Returns list of names
7514 (defsubst verilog-modport-clockings-add (sig val)
7515 (setcar (nthcdr 1 sig) (cons val (nth 1 sig))))
7516 (defsubst verilog-modport-decls (sig)
7517 (nth 2 sig)) ;; Returns verilog-decls-* structure
7518 (defsubst verilog-modport-decls-set (sig val)
7519 (setcar (nthcdr 2 sig) val))
7521 (defsubst verilog-modi-new (name fob pt type)
7522 (vector name fob pt type))
7523 (defsubst verilog-modi-name (modi)
7525 (defsubst verilog-modi-file-or-buffer (modi)
7527 (defsubst verilog-modi-get-point (modi)
7529 (defsubst verilog-modi-get-type (modi) ;; "module" or "interface"
7531 (defsubst verilog-modi-get-decls (modi)
7532 (verilog-modi-cache-results modi 'verilog-read-decls))
7533 (defsubst verilog-modi-get-sub-decls (modi)
7534 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
7536 ;; Signal reading for given module
7537 ;; Note these all take modi's - as returned from verilog-modi-current
7538 (defsubst verilog-decls-new (out inout in vars modports assigns consts gparams interfaces)
7539 (vector out inout in vars modports assigns consts gparams interfaces))
7540 (defsubst verilog-decls-append (a b)
7541 (cond ((not a) b) ((not b) a)
7542 (t (vector (append (aref a 0) (aref b 0)) (append (aref a 1) (aref b 1))
7543 (append (aref a 2) (aref b 2)) (append (aref a 3) (aref b 3))
7544 (append (aref a 4) (aref b 4)) (append (aref a 5) (aref b 5))
7545 (append (aref a 6) (aref b 6)) (append (aref a 7) (aref b 7))
7546 (append (aref a 8) (aref b 8))))))
7547 (defsubst verilog-decls-get-outputs (decls)
7549 (defsubst verilog-decls-get-inouts (decls)
7551 (defsubst verilog-decls-get-inputs (decls)
7553 (defsubst verilog-decls-get-vars (decls)
7555 (defsubst verilog-decls-get-modports (decls) ;; Also for clocking blocks; contains another verilog-decls struct
7556 (aref decls 4)) ;; Returns verilog-modport* structure
7557 (defsubst verilog-decls-get-assigns (decls)
7559 (defsubst verilog-decls-get-consts (decls)
7561 (defsubst verilog-decls-get-gparams (decls)
7563 (defsubst verilog-decls-get-interfaces (decls)
7567 (defsubst verilog-subdecls-new (out inout in intf intfd)
7568 (vector out inout in intf intfd))
7569 (defsubst verilog-subdecls-get-outputs (subdecls)
7571 (defsubst verilog-subdecls-get-inouts (subdecls)
7573 (defsubst verilog-subdecls-get-inputs (subdecls)
7575 (defsubst verilog-subdecls-get-interfaces (subdecls)
7577 (defsubst verilog-subdecls-get-interfaced (subdecls)
7580 (defun verilog-signals-from-signame (signame-list)
7581 "Return signals in standard form from SIGNAME-LIST, a simple list of names."
7582 (mapcar (lambda (name) (verilog-sig-new name nil nil nil nil nil nil nil nil))
7585 (defun verilog-signals-in (in-list not-list)
7586 "Return list of signals in IN-LIST that are also in NOT-LIST.
7587 Also remove any duplicates in IN-LIST.
7588 Signals must be in standard (base vector) form."
7589 ;; This function is hot, so implemented as O(1)
7590 (cond ((eval-when-compile (fboundp 'make-hash-table))
7591 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
7592 (ht-not (make-hash-table :test 'equal :rehash-size 4.0))
7595 (puthash (car (car not-list)) t ht-not)
7596 (setq not-list (cdr not-list)))
7598 (when (and (gethash (verilog-sig-name (car in-list)) ht-not)
7599 (not (gethash (verilog-sig-name (car in-list)) ht)))
7600 (setq out-list (cons (car in-list) out-list))
7601 (puthash (verilog-sig-name (car in-list)) t ht))
7602 (setq in-list (cdr in-list)))
7603 (nreverse out-list)))
7604 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
7608 (if (and (assoc (verilog-sig-name (car in-list)) not-list)
7609 (not (assoc (verilog-sig-name (car in-list)) out-list)))
7610 (setq out-list (cons (car in-list) out-list)))
7611 (setq in-list (cdr in-list)))
7612 (nreverse out-list)))))
7613 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("C" "")))
7615 (defun verilog-signals-not-in (in-list not-list)
7616 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
7617 Also remove any duplicates in IN-LIST.
7618 Signals must be in standard (base vector) form."
7619 ;; This function is hot, so implemented as O(1)
7620 (cond ((eval-when-compile (fboundp 'make-hash-table))
7621 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
7624 (puthash (car (car not-list)) t ht)
7625 (setq not-list (cdr not-list)))
7627 (when (not (gethash (verilog-sig-name (car in-list)) ht))
7628 (setq out-list (cons (car in-list) out-list))
7629 (puthash (verilog-sig-name (car in-list)) t ht))
7630 (setq in-list (cdr in-list)))
7631 (nreverse out-list)))
7632 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
7636 (if (and (not (assoc (verilog-sig-name (car in-list)) not-list))
7637 (not (assoc (verilog-sig-name (car in-list)) out-list)))
7638 (setq out-list (cons (car in-list) out-list)))
7639 (setq in-list (cdr in-list)))
7640 (nreverse out-list)))))
7641 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
7643 (defun verilog-signals-memory (in-list)
7644 "Return list of signals in IN-LIST that are memorized (multidimensional)."
7647 (if (nth 3 (car in-list))
7648 (setq out-list (cons (car in-list) out-list)))
7649 (setq in-list (cdr in-list)))
7651 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
7653 (defun verilog-signals-sort-compare (a b)
7654 "Compare signal A and B for sorting."
7655 (string< (verilog-sig-name a) (verilog-sig-name b)))
7657 (defun verilog-signals-not-params (in-list)
7658 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
7661 (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
7662 (setq out-list (cons (car in-list) out-list)))
7663 (setq in-list (cdr in-list)))
7664 (nreverse out-list)))
7666 (defun verilog-signals-with (func in-list)
7667 "Return IN-LIST with only signals where FUNC passed each signal is true."
7670 (when (funcall func (car in-list))
7671 (setq out-list (cons (car in-list) out-list)))
7672 (setq in-list (cdr in-list)))
7673 (nreverse out-list)))
7675 (defun verilog-signals-combine-bus (in-list)
7676 "Return a list of signals in IN-LIST, with buses combined.
7677 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
7680 sig highbit lowbit ; Temp information about current signal
7681 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
7682 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
7685 ;; Shove signals so duplicated signals will be adjacent
7686 (setq in-list (sort in-list `verilog-signals-sort-compare))
7688 (setq sig (car in-list))
7689 ;; No current signal; form from existing details
7691 (setq sv-name (verilog-sig-name sig)
7694 sv-comment (verilog-sig-comment sig)
7695 sv-memory (verilog-sig-memory sig)
7696 sv-enum (verilog-sig-enum sig)
7697 sv-signed (verilog-sig-signed sig)
7698 sv-type (verilog-sig-type sig)
7699 sv-multidim (verilog-sig-multidim sig)
7700 sv-modport (verilog-sig-modport sig)
7703 ;; Extract bus details
7704 (setq bus (verilog-sig-bits sig))
7705 (setq bus (and bus (verilog-simplify-range-expression bus)))
7707 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
7708 (setq highbit (string-to-number (match-string 1 bus))
7709 lowbit (string-to-number
7710 (match-string 2 bus))))
7711 (and (string-match "\\[\\([0-9]+\\)\\]" bus)
7712 (setq highbit (string-to-number (match-string 1 bus))
7714 ;; Combine bits in bus
7716 (setq sv-highbit (max highbit sv-highbit)
7717 sv-lowbit (min lowbit sv-lowbit))
7718 (setq sv-highbit highbit
7721 ;; String, probably something like `preproc:0
7722 (setq sv-busstring bus)))
7723 ;; Peek ahead to next signal
7724 (setq in-list (cdr in-list))
7725 (setq sig (car in-list))
7726 (cond ((and sig (equal sv-name (verilog-sig-name sig)))
7727 ;; Combine with this signal
7728 (when (and sv-busstring
7729 (not (equal sv-busstring (verilog-sig-bits sig))))
7730 (when nil ;; Debugging
7731 (message (concat "Warning, can't merge into single bus "
7733 ", the AUTOs may be wrong")))
7734 (setq buswarn ", Couldn't Merge"))
7735 (if (verilog-sig-comment sig) (setq combo ", ..."))
7736 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
7737 sv-enum (or sv-enum (verilog-sig-enum sig))
7738 sv-signed (or sv-signed (verilog-sig-signed sig))
7739 sv-type (or sv-type (verilog-sig-type sig))
7740 sv-multidim (or sv-multidim (verilog-sig-multidim sig))
7741 sv-modport (or sv-modport (verilog-sig-modport sig))))
7742 ;; Doesn't match next signal, add to queue, zero in prep for next
7743 ;; Note sig may also be nil for the last signal in the list
7746 (cons (verilog-sig-new
7750 (concat "[" (int-to-string sv-highbit) ":"
7751 (int-to-string sv-lowbit) "]")))
7752 (concat sv-comment combo buswarn)
7753 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
7759 (defun verilog-sig-tieoff (sig)
7760 "Return tieoff expression for given SIG, with appropriate width.
7761 Tieoff value uses `verilog-active-low-regexp' and
7762 `verilog-auto-reset-widths'."
7764 (if (and verilog-active-low-regexp
7765 (string-match verilog-active-low-regexp (verilog-sig-name sig)))
7767 (cond ((not verilog-auto-reset-widths)
7769 ((equal verilog-auto-reset-widths 'unbased)
7771 ;; Else presume verilog-auto-reset-widths is true
7773 (let* ((width (verilog-sig-width sig)))
7774 (if (string-match "^[0-9]+$" width)
7775 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0"))
7776 (concat "{" width "{1'b0}}")))))))
7782 (defun verilog-decls-princ (decls &optional header prefix)
7783 "For debug, dump the `verilog-read-decls' structure DECLS."
7785 (if header (princ header))
7786 (setq prefix (or prefix ""))
7787 (verilog-signals-princ (verilog-decls-get-outputs decls)
7788 (concat prefix "Outputs:\n") (concat prefix " "))
7789 (verilog-signals-princ (verilog-decls-get-inouts decls)
7790 (concat prefix "Inout:\n") (concat prefix " "))
7791 (verilog-signals-princ (verilog-decls-get-inputs decls)
7792 (concat prefix "Inputs:\n") (concat prefix " "))
7793 (verilog-signals-princ (verilog-decls-get-vars decls)
7794 (concat prefix "Vars:\n") (concat prefix " "))
7795 (verilog-signals-princ (verilog-decls-get-assigns decls)
7796 (concat prefix "Assigns:\n") (concat prefix " "))
7797 (verilog-signals-princ (verilog-decls-get-consts decls)
7798 (concat prefix "Consts:\n") (concat prefix " "))
7799 (verilog-signals-princ (verilog-decls-get-gparams decls)
7800 (concat prefix "Gparams:\n") (concat prefix " "))
7801 (verilog-signals-princ (verilog-decls-get-interfaces decls)
7802 (concat prefix "Interfaces:\n") (concat prefix " "))
7803 (verilog-modport-princ (verilog-decls-get-modports decls)
7804 (concat prefix "Modports:\n") (concat prefix " "))
7807 (defun verilog-signals-princ (signals &optional header prefix)
7808 "For debug, dump internal SIGNALS structures, with HEADER and PREFIX."
7810 (if header (princ header))
7812 (let ((sig (car signals)))
7813 (setq signals (cdr signals))
7815 (princ "\"") (princ (verilog-sig-name sig)) (princ "\"")
7816 (princ " bits=") (princ (verilog-sig-bits sig))
7817 (princ " cmt=") (princ (verilog-sig-comment sig))
7818 (princ " mem=") (princ (verilog-sig-memory sig))
7819 (princ " enum=") (princ (verilog-sig-enum sig))
7820 (princ " sign=") (princ (verilog-sig-signed sig))
7821 (princ " type=") (princ (verilog-sig-type sig))
7822 (princ " dim=") (princ (verilog-sig-multidim sig))
7823 (princ " modp=") (princ (verilog-sig-modport sig))
7826 (defun verilog-modport-princ (modports &optional header prefix)
7827 "For debug, dump internal MODPORT structures, with HEADER and PREFIX."
7829 (if header (princ header))
7831 (let ((sig (car modports)))
7832 (setq modports (cdr modports))
7834 (princ "\"") (princ (verilog-modport-name sig)) (princ "\"")
7835 (princ " clockings=") (princ (verilog-modport-clockings sig))
7837 (verilog-decls-princ (verilog-modport-decls sig)
7838 (concat prefix " syms:\n")
7839 (concat prefix " "))))))
7842 ;; Port/Wire/Etc Reading
7845 (defun verilog-read-inst-backward-name ()
7846 "Internal. Move point back to beginning of inst-name."
7847 (verilog-backward-open-paren)
7850 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary
7851 (cond ((looking-at ")")
7852 (verilog-backward-open-paren))
7853 (t (setq done t)))))
7854 (while (looking-at "\\]")
7855 (verilog-backward-open-bracket)
7856 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil))
7857 (skip-chars-backward "a-zA-Z0-9`_$"))
7859 (defun verilog-read-inst-module-matcher ()
7860 "Set match data 0 with module_name when point is inside instantiation."
7861 (verilog-read-inst-backward-name)
7862 ;; Skip over instantiation name
7863 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
7864 ;; Check for parameterized instantiations
7865 (when (looking-at ")")
7866 (verilog-backward-open-paren)
7867 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil))
7868 (skip-chars-backward "a-zA-Z0-9'_$")
7869 (looking-at "[a-zA-Z0-9`_\$]+")
7870 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7871 (buffer-substring-no-properties (match-beginning 0) (match-end 0))
7872 ;; Caller assumes match-beginning/match-end is still set
7875 (defun verilog-read-inst-module ()
7876 "Return module_name when point is inside instantiation."
7878 (verilog-read-inst-module-matcher)))
7880 (defun verilog-read-inst-name ()
7881 "Return instance_name when point is inside instantiation."
7883 (verilog-read-inst-backward-name)
7884 (looking-at "[a-zA-Z0-9`_\$]+")
7885 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7886 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
7888 (defun verilog-read-module-name ()
7889 "Return module name when after its ( or ;."
7891 (re-search-backward "[(;]")
7892 ;; Due to "module x import y (" we must search for declaration begin
7893 (verilog-re-search-backward-quick verilog-defun-re nil nil)
7894 (goto-char (match-end 0))
7895 (verilog-re-search-forward-quick "\\b[a-zA-Z0-9`_\$]+" nil nil)
7896 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7897 (verilog-symbol-detick
7898 (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
7900 (defun verilog-read-inst-param-value ()
7901 "Return list of parameters and values when point is inside instantiation."
7903 (verilog-read-inst-backward-name)
7904 ;; Skip over instantiation name
7905 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
7906 ;; If there are parameterized instantiations
7907 (when (looking-at ")")
7908 (let ((end-pt (point))
7910 param-name paren-beg-pt param-value)
7911 (verilog-backward-open-paren)
7912 (while (verilog-re-search-forward-quick "\\." end-pt t)
7913 (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_\$]\\)" nil nil)
7914 (skip-chars-backward "a-zA-Z0-9'_$")
7915 (looking-at "[a-zA-Z0-9`_\$]+")
7916 (setq param-name (buffer-substring-no-properties
7917 (match-beginning 0) (match-end 0)))
7918 (verilog-re-search-forward-quick "(" nil nil)
7919 (setq paren-beg-pt (point))
7920 (verilog-forward-close-paren)
7921 (setq param-value (verilog-string-remove-spaces
7922 (buffer-substring-no-properties
7923 paren-beg-pt (1- (point)))))
7924 (setq params (cons (list param-name param-value) params)))
7927 (defun verilog-read-auto-params (num-param &optional max-param)
7928 "Return parameter list inside auto.
7929 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
7932 ;; /*AUTOPUNT("parameter", "parameter")*/
7934 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
7935 (setq olist (cons (match-string 1) olist))
7936 (goto-char (match-end 0))))
7937 (or (eq nil num-param)
7938 (<= num-param (length olist))
7939 (error "%s: Expected %d parameters" (verilog-point-text) num-param))
7940 (if (eq max-param nil) (setq max-param num-param))
7941 (or (eq nil max-param)
7942 (>= max-param (length olist))
7943 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
7946 (defun verilog-read-decls ()
7947 "Compute signal declaration information for the current module at point.
7948 Return an array of [outputs inouts inputs wire reg assign const]."
7949 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
7950 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
7951 in-modport in-clocking ptype ign-prop
7952 sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
7953 sigs-gparam sigs-intf sigs-modports
7954 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
7958 (verilog-beg-of-defun-quick)
7959 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
7960 (while (< (point) end-mod-point)
7961 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
7964 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7965 (setq enum (match-string 2)))
7966 (search-forward "\n"))
7967 ((looking-at "/\\*")
7969 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7970 (setq enum (match-string 2)))
7971 (or (search-forward "*/")
7972 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
7973 ((looking-at "(\\*")
7974 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
7976 (or (search-forward "*)")
7977 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
7978 ((eq ?\" (following-char))
7979 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first
7980 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
7981 ((eq ?\; (following-char))
7982 (when (and in-modport (not (eq in-modport t))) ;; end of a modport declaration
7983 (verilog-modport-decls-set
7985 (verilog-decls-new sigs-out sigs-inout sigs-in
7986 nil nil nil nil nil nil))
7987 ;; Pop from varstack to restore state to pre-clocking
7988 (setq tmp (car varstack)
7989 varstack (cdr varstack)
7990 sigs-out (aref tmp 0)
7991 sigs-inout (aref tmp 1)
7992 sigs-in (aref tmp 2)))
7993 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
7994 v2kargs-ok nil in-modport nil ign-prop nil)
7996 ((eq ?= (following-char))
7997 (setq rvalue t newsig nil)
7999 ((and (eq ?, (following-char))
8000 (eq paren sig-paren))
8003 ;; ,'s can occur inside {} & funcs
8004 ((looking-at "[{(]")
8005 (setq paren (1+ paren))
8007 ((looking-at "[})]")
8008 (setq paren (1- paren))
8010 (when (< paren sig-paren)
8011 (setq expect-signal nil))) ; ) that ends variables inside v2k arg list
8012 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
8013 (goto-char (match-end 0))
8014 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
8015 (setcar (cdr (cdr (cdr newsig)))
8016 (if (verilog-sig-memory newsig)
8017 (concat (verilog-sig-memory newsig) (match-string 1))
8019 (vec ;; Multidimensional
8020 (setq multidim (cons vec multidim))
8021 (setq vec (verilog-string-replace-matches
8022 "\\s-+" "" nil nil (match-string 1))))
8024 (setq vec (verilog-string-replace-matches
8025 "\\s-+" "" nil nil (match-string 1))))))
8026 ;; Normal or escaped identifier -- note we remember the \ if escaped
8027 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8028 (goto-char (match-end 0))
8029 (setq keywd (match-string 1))
8030 (when (string-match "^\\\\" (match-string 1))
8031 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end
8032 ;; Add any :: package names to same identifier
8033 (while (looking-at "\\s-*::\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8034 (goto-char (match-end 0))
8035 (setq keywd (concat keywd "::" (match-string 1)))
8036 (when (string-match "^\\\\" (match-string 1))
8037 (setq keywd (concat keywd " ")))) ;; Escaped ID needs space at end
8038 (cond ((equal keywd "input")
8039 (setq vec nil enum nil rvalue nil newsig nil signed nil
8040 typedefed nil multidim nil ptype nil modport nil
8041 expect-signal 'sigs-in io t sig-paren paren))
8042 ((equal keywd "output")
8043 (setq vec nil enum nil rvalue nil newsig nil signed nil
8044 typedefed nil multidim nil ptype nil modport nil
8045 expect-signal 'sigs-out io t sig-paren paren))
8046 ((equal keywd "inout")
8047 (setq vec nil enum nil rvalue nil newsig nil signed nil
8048 typedefed nil multidim nil ptype nil modport nil
8049 expect-signal 'sigs-inout io t sig-paren paren))
8050 ((equal keywd "parameter")
8051 (setq vec nil enum nil rvalue nil signed nil
8052 typedefed nil multidim nil ptype nil modport nil
8053 expect-signal 'sigs-gparam io t sig-paren paren))
8054 ((member keywd '("wire" "reg" ; Fast
8056 "tri" "tri0" "tri1" "triand" "trior" "trireg"
8057 "uwire" "wand" "wor"
8058 ;; integer_atom_type
8059 "byte" "shortint" "int" "longint" "integer" "time"
8061 ;; integer_vector_type - "reg" above
8064 "shortreal" "real" "realtime"
8066 "string" "event" "chandle"))
8069 (if typedefed (concat typedefed " " keywd) keywd)))
8070 (t (setq vec nil enum nil rvalue nil signed nil
8071 typedefed nil multidim nil sig-paren paren
8072 expect-signal 'sigs-var modport nil))))
8073 ((equal keywd "assign")
8074 (setq vec nil enum nil rvalue nil signed nil
8075 typedefed nil multidim nil ptype nil modport nil
8076 expect-signal 'sigs-assign sig-paren paren))
8077 ((member keywd '("localparam" "genvar"))
8079 (setq vec nil enum nil rvalue nil signed nil
8080 typedefed nil multidim nil ptype nil modport nil
8081 expect-signal 'sigs-const sig-paren paren)))
8082 ((member keywd '("signed" "unsigned"))
8083 (setq signed keywd))
8084 ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
8086 ((member keywd '("class" "covergroup" "function"
8087 "property" "randsequence" "sequence" "task"))
8089 (setq functask (1+ functask))))
8090 ((member keywd '("endclass" "endgroup" "endfunction"
8091 "endproperty" "endsequence" "endtask"))
8092 (setq functask (1- functask)))
8093 ((equal keywd "modport")
8094 (setq in-modport t))
8095 ((equal keywd "clocking")
8096 (setq in-clocking t))
8097 ((equal keywd "type")
8099 ;; Ifdef? Ignore name of define
8100 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8104 (verilog-typedef-name-p keywd))
8105 (setq typedefed keywd))
8106 ;; Interface with optional modport in v2k arglist?
8107 ;; Skip over parsing modport, and take the interface name as the type
8111 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
8112 (when (match-end 2) (goto-char (match-end 2)))
8113 (setq vec nil enum nil rvalue nil signed nil
8114 typedefed keywd multidim nil ptype nil modport (match-string 2)
8115 newsig nil sig-paren paren
8116 expect-signal 'sigs-intf io t ))
8117 ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
8118 ((looking-at "\\s-*\\.")
8119 (goto-char (match-end 0))
8121 (setq expect-signal nil)))
8122 ;; "modport <keywd>"
8123 ((and (eq in-modport t)
8124 (not (member keywd verilog-keywords)))
8125 (setq in-modport (verilog-modport-new keywd nil nil))
8126 (setq sigs-modports (cons in-modport sigs-modports))
8127 ;; Push old sig values to stack and point to new signal list
8128 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8130 (setq sigs-in nil sigs-inout nil sigs-out nil))
8131 ;; "modport x (clocking <keywd>)"
8132 ((and in-modport in-clocking)
8133 (verilog-modport-clockings-add in-modport keywd)
8134 (setq in-clocking nil))
8137 (equal keywd "endclocking"))
8138 (unless (eq in-clocking t)
8139 (verilog-modport-decls-set
8141 (verilog-decls-new sigs-out sigs-inout sigs-in
8142 nil nil nil nil nil nil))
8143 ;; Pop from varstack to restore state to pre-clocking
8144 (setq tmp (car varstack)
8145 varstack (cdr varstack)
8146 sigs-out (aref tmp 0)
8147 sigs-inout (aref tmp 1)
8148 sigs-in (aref tmp 2)))
8149 (setq in-clocking nil))
8150 ;; "clocking <keywd>"
8151 ((and (eq in-clocking t)
8152 (not (member keywd verilog-keywords)))
8153 (setq in-clocking (verilog-modport-new keywd nil nil))
8154 (setq sigs-modports (cons in-clocking sigs-modports))
8155 ;; Push old sig values to stack and point to new signal list
8156 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8158 (setq sigs-in nil sigs-inout nil sigs-out nil))
8159 ;; New signal, maybe?
8163 (not (member keywd verilog-keywords)))
8164 ;; Add new signal to expect-signal's variable
8165 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
8166 (set expect-signal (cons newsig
8167 (symbol-value expect-signal))))))
8170 (skip-syntax-forward " "))
8172 (setq tmp (verilog-decls-new (nreverse sigs-out)
8173 (nreverse sigs-inout)
8176 (nreverse sigs-modports)
8177 (nreverse sigs-assign)
8178 (nreverse sigs-const)
8179 (nreverse sigs-gparam)
8180 (nreverse sigs-intf)))
8181 ;;(if dbg (verilog-decls-princ tmp))
8184 (defvar verilog-read-sub-decls-in-interfaced nil
8185 "For `verilog-read-sub-decls', process next signal as under interfaced block.")
8187 (defvar verilog-read-sub-decls-gate-ios nil
8188 "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
8191 ;; Prevent compile warnings; these are let's, not globals
8192 ;; Do not remove the eval-when-compile
8193 ;; - we want an error when we are debugging this code if they are refed.
8198 (defvar sigs-intfd))
8200 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
8201 "For `verilog-read-sub-decls-line', add a signal."
8202 ;; sig eq t to indicate .name syntax
8203 ;;(message "vrsds: %s(%S)" port sig)
8204 (let ((dotname (eq sig t))
8207 (setq port (verilog-symbol-detick-denumber port))
8208 (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
8209 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
8210 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
8211 (unless (or (not sig)
8212 (equal sig "")) ;; Ignore .foo(1'b1) assignments
8213 (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
8214 (equal "inout" verilog-read-sub-decls-gate-ios))
8216 (cons (verilog-sig-new
8218 (if dotname (verilog-sig-bits portdata) vec)
8219 (concat "To/From " comment)
8220 (verilog-sig-memory portdata)
8222 (verilog-sig-signed portdata)
8223 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8224 (verilog-sig-type portdata))
8227 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
8228 (equal "output" verilog-read-sub-decls-gate-ios))
8230 (cons (verilog-sig-new
8232 (if dotname (verilog-sig-bits portdata) vec)
8233 (concat "From " comment)
8234 (verilog-sig-memory portdata)
8236 (verilog-sig-signed portdata)
8237 ;; Though ok in SV, in V2K code, propagating the
8238 ;; "reg" in "output reg" upwards isn't legal.
8239 ;; Also for backwards compatibility we don't propagate
8240 ;; "input wire" upwards.
8241 ;; See also `verilog-signals-edit-wire-reg'.
8242 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8243 (verilog-sig-type portdata))
8246 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
8247 (equal "input" verilog-read-sub-decls-gate-ios))
8249 (cons (verilog-sig-new
8251 (if dotname (verilog-sig-bits portdata) vec)
8252 (concat "To " comment)
8253 (verilog-sig-memory portdata)
8255 (verilog-sig-signed portdata)
8256 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8257 (verilog-sig-type portdata))
8260 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
8262 (cons (verilog-sig-new
8264 (if dotname (verilog-sig-bits portdata) vec)
8265 (concat "To/From " comment)
8266 (verilog-sig-memory portdata)
8268 (verilog-sig-signed portdata)
8269 (verilog-sig-type portdata)
8272 ((setq portdata (and verilog-read-sub-decls-in-interfaced
8273 (assoc port (verilog-decls-get-vars submoddecls))))
8275 (cons (verilog-sig-new
8277 (if dotname (verilog-sig-bits portdata) vec)
8278 (concat "To/From " comment)
8279 (verilog-sig-memory portdata)
8281 (verilog-sig-signed portdata)
8282 (verilog-sig-type portdata)
8285 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
8288 (defun verilog-read-sub-decls-expr (submoddecls comment port expr)
8289 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
8290 ;;(message "vrsde: '%s'" expr)
8291 ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
8292 (setq expr (verilog-string-replace-matches "/\\*\\(\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
8293 ;; Remove front operators
8294 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8297 ;; {..., a, b} requires us to recurse on a,b
8298 ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
8299 ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
8300 (unless verilog-auto-ignore-concat
8301 (let ((mlst (split-string (match-string 1 expr) "[{},]"))
8303 (while (setq mstr (pop mlst))
8304 (verilog-read-sub-decls-expr submoddecls comment port mstr)))))
8306 (let (sig vec multidim)
8307 ;; Remove leading reduction operators, etc
8308 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8309 ;;(message "vrsde-ptop: '%s'" expr)
8310 (cond ;; Find \signal. Final space is part of escaped signal name
8311 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
8312 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
8313 (setq sig (match-string 1 expr)
8314 expr (substring expr (match-end 0))))
8316 ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
8317 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
8318 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
8319 expr (substring expr (match-end 0)))))
8320 ;; Find [vector] or [multi][multi][multi][vector]
8321 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
8322 ;;(message "vrsde-v: '%s'" (match-string 1 expr))
8323 (when vec (setq multidim (cons vec multidim)))
8324 (setq vec (match-string 1 expr)
8325 expr (substring expr (match-end 0))))
8326 ;; If found signal, and nothing unrecognized, add the signal
8327 ;;(message "vrsde-rem: '%s'" expr)
8328 (when (and sig (string-match "^\\s-*$" expr))
8329 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))))
8331 (defun verilog-read-sub-decls-line (submoddecls comment)
8332 "For `verilog-read-sub-decls', read lines of port defs until none match.
8333 Inserts the list of signals found, using submodi to look up each port."
8339 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
8340 (setq port (match-string 1))
8341 (goto-char (match-end 0)))
8343 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
8344 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space
8345 (goto-char (match-end 0)))
8347 ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
8348 (verilog-read-sub-decls-sig
8349 submoddecls comment (match-string 1) t ; sig==t for .name
8350 nil nil) ; vec multidim
8353 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
8354 (verilog-read-sub-decls-sig
8355 submoddecls comment (concat (match-string 1) " ") t ; sig==t for .name
8356 nil nil) ; vec multidim
8359 ((looking-at "\\s-*\\.[^(]*(")
8360 (setq port nil) ;; skip this line
8361 (goto-char (match-end 0)))
8363 (setq port nil done t))) ;; Unknown, ignore rest of line
8364 ;; Get signal name. Point is at the first-non-space after (
8365 ;; We intentionally ignore (non-escaped) signals with .s in them
8366 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
8368 (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
8369 (verilog-read-sub-decls-sig
8370 submoddecls comment port
8371 (verilog-string-remove-spaces (match-string 1)) ; sig
8372 nil nil)) ; vec multidim
8374 ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
8375 (verilog-read-sub-decls-sig
8376 submoddecls comment port
8377 (verilog-string-remove-spaces (match-string 1)) ; sig
8378 (match-string 2) nil)) ; vec multidim
8379 ;; Fastpath was above looking-at's.
8380 ;; For something more complicated invoke a parser
8381 ((looking-at "[^)]+")
8382 (verilog-read-sub-decls-expr
8383 submoddecls comment port
8385 (point) (1- (progn (search-backward "(") ; start at (
8386 (verilog-forward-sexp-ign-cmt 1)
8387 (point)))))))) ; expr
8389 (forward-line 1)))))
8391 (defun verilog-read-sub-decls-gate (submoddecls comment submod end-inst-point)
8392 "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
8393 Inserts the list of signals found."
8395 (let ((iolist (cdr (assoc submod verilog-gate-ios))))
8396 (while (< (point) end-inst-point)
8397 ;; Get primitive's signal name, as will never have port, and no trailing )
8398 (cond ((looking-at "//")
8399 (search-forward "\n"))
8400 ((looking-at "/\\*")
8401 (or (search-forward "*/")
8402 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8403 ((looking-at "(\\*")
8404 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8406 (or (search-forward "*)")
8407 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8408 ;; On pins, parse and advance to next pin
8409 ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
8410 ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
8411 (goto-char (match-end 0))
8412 (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
8413 iolist (cdr iolist))
8414 (verilog-read-sub-decls-expr
8415 submoddecls comment "primitive_port"
8419 (skip-syntax-forward " ")))))))
8421 (defun verilog-read-sub-decls ()
8422 "Internally parse signals going to modules under this module.
8423 Return an array of [ outputs inouts inputs ] signals for modules that are
8424 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
8425 is an output, then SIG will be included in the list.
8427 This only works on instantiations created with /*AUTOINST*/ converted by
8428 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
8429 component library to determine connectivity of the design.
8431 One work around for this problem is to manually create // Inputs and //
8432 Outputs comments above subcell signals, for example:
8440 (let ((end-mod-point (verilog-get-end-of-defun t))
8441 st-point end-inst-point
8442 ;; below 3 modified by verilog-read-sub-decls-line
8443 sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
8444 (verilog-beg-of-defun-quick)
8445 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
8447 (goto-char (match-beginning 0))
8448 (unless (verilog-inside-comment-or-string-p)
8449 ;; Attempt to snarf a comment
8450 (let* ((submod (verilog-read-inst-module))
8451 (inst (verilog-read-inst-name))
8452 (subprim (member submod verilog-gate-keywords))
8453 (comment (concat inst " of " submod ".v"))
8454 submodi submoddecls)
8457 (setq submodi `primitive
8458 submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
8459 comment (concat inst " of " submod))
8460 (verilog-backward-open-paren)
8461 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
8465 (verilog-read-sub-decls-gate submoddecls comment submod end-inst-point))
8468 (when (setq submodi (verilog-modi-lookup submod t))
8469 (setq submoddecls (verilog-modi-get-decls submodi)
8470 verilog-read-sub-decls-gate-ios nil)
8471 (verilog-backward-open-paren)
8472 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
8475 ;; This could have used a list created by verilog-auto-inst
8476 ;; However I want it to be runnable even on user's manually added signals
8477 (let ((verilog-read-sub-decls-in-interfaced t))
8478 (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
8479 (verilog-read-sub-decls-line submoddecls comment))) ;; Modifies sigs-ifd
8480 (goto-char st-point)
8481 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
8482 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
8483 (goto-char st-point)
8484 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
8485 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
8486 (goto-char st-point)
8487 (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
8488 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout
8489 (goto-char st-point)
8490 (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
8491 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-in
8493 ;; Combine duplicate bits
8494 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
8495 (verilog-subdecls-new
8496 (verilog-signals-combine-bus (nreverse sigs-out))
8497 (verilog-signals-combine-bus (nreverse sigs-inout))
8498 (verilog-signals-combine-bus (nreverse sigs-in))
8499 (verilog-signals-combine-bus (nreverse sigs-intf))
8500 (verilog-signals-combine-bus (nreverse sigs-intfd))))))
8502 (defun verilog-read-inst-pins ()
8503 "Return an array of [ pins ] for the current instantiation at point.
8504 For example if declare A A (.B(SIG)) then B will be included in the list."
8506 (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point
8508 (verilog-backward-open-paren)
8509 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
8510 (setq pin (match-string 1))
8511 (unless (verilog-inside-comment-or-string-p)
8512 (setq pins (cons (list pin) pins))
8513 (when (looking-at "(")
8514 (verilog-forward-sexp-ign-cmt 1))))
8517 (defun verilog-read-arg-pins ()
8518 "Return an array of [ pins ] for the current argument declaration at point."
8520 (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point
8522 (verilog-backward-open-paren)
8523 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
8524 (setq pin (match-string 1))
8525 (unless (verilog-inside-comment-or-string-p)
8526 (setq pins (cons (list pin) pins))))
8529 (defun verilog-read-auto-constants (beg end-mod-point)
8530 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
8533 (let (sig-list tpl-end-pt)
8535 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
8536 (if (not (looking-at "\\s *("))
8537 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
8538 (search-forward "(" end-mod-point)
8539 (setq tpl-end-pt (save-excursion
8541 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8544 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
8545 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
8548 (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
8549 (make-variable-buffer-local 'verilog-cache-has-lisp)
8551 (defun verilog-read-auto-lisp-present ()
8552 "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
8554 (goto-char (point-min))
8555 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
8557 (defun verilog-read-auto-lisp (start end)
8558 "Look for and evaluate an AUTO_LISP between START and END.
8559 Must call `verilog-read-auto-lisp-present' before this function."
8560 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
8561 (when verilog-cache-has-lisp
8564 (while (re-search-forward "\\<AUTO_LISP(" end t)
8566 (let* ((beg-pt (prog1 (point)
8567 (verilog-forward-sexp-cmt 1))) ;; Closing paren
8569 (verilog-in-hooks t))
8570 (eval-region beg-pt end-pt nil))))))
8573 ;; Prevent compile warnings; these are let's, not globals
8574 ;; Do not remove the eval-when-compile
8575 ;; - we want an error when we are debugging this code if they are refed.
8579 (defvar sigs-out-unk)
8581 (defvar vector-skip-list))
8583 (defun verilog-read-always-signals-recurse
8584 (exit-keywd rvalue temp-next)
8585 "Recursive routine for parentheses/bracket matching.
8586 EXIT-KEYWD is expression to stop at, nil if top level.
8587 RVALUE is true if at right hand side of equal.
8588 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
8589 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue
8590 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
8592 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
8593 (while (not (or (eobp) gotend))
8596 (search-forward "\n"))
8597 ((looking-at "/\\*")
8598 (or (search-forward "*/")
8599 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8600 ((looking-at "(\\*")
8601 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8603 (or (search-forward "*)")
8604 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8605 (t (setq keywd (buffer-substring-no-properties
8607 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
8610 sig-last-tolk sig-tolk
8612 ;;(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))))
8615 (or (re-search-forward "[^\\]\"" nil t)
8616 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
8617 ;; else at top level loop, keep parsing
8618 ((and end-else-check (equal keywd "else"))
8619 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
8620 ;; no forward movement, want to see else in lower loop
8621 (setq end-else-check nil))
8622 ;; End at top level loop
8623 ((and end-else-check (looking-at "[^ \t\n\f]"))
8624 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
8627 ((and exit-keywd (equal keywd exit-keywd))
8629 (forward-char (length keywd)))
8630 ;; Standard tokens...
8632 (setq ignore-next nil rvalue semi-rvalue)
8633 ;; Final statement at top level loop?
8634 (when (not exit-keywd)
8635 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
8636 (setq end-else-check t))
8639 (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
8640 (goto-char (match-end 0))
8642 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z
8643 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next
8644 (setq ignore-next nil rvalue nil))
8645 ((equal "?" exit-keywd) ;; x?y:z rvalue
8647 ((equal "]" exit-keywd) ;; [x:y] rvalue
8649 (got-sig ;; label: statement
8650 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
8651 ((not rvalue) ;; begin label
8652 (setq ignore-next t rvalue nil)))
8656 ;;(if dbg (setq dbg (concat dbg (format "\t\tequal got-sig=%S got-list=%s\n" got-sig got-list))))
8657 (set got-list (cons got-sig (symbol-value got-list)))
8660 (if (eq (char-before) ?< )
8661 (setq sigs-out-d (append sigs-out-d sigs-out-unk)
8663 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
8665 (setq ignore-next nil rvalue t)
8669 (verilog-read-always-signals-recurse ":" rvalue nil))
8672 (verilog-read-always-signals-recurse "]" t nil))
8675 (cond (sig-last-tolk ;; Function call; zap last signal
8676 (setq got-sig nil)))
8677 (cond ((equal last-keywd "for")
8678 ;; temp-next: Variables on LHS are lvalues, but generally we want
8679 ;; to ignore them, assuming they are loop increments
8680 (verilog-read-always-signals-recurse ";" nil t)
8681 (verilog-read-always-signals-recurse ";" t nil)
8682 (verilog-read-always-signals-recurse ")" nil nil))
8683 (t (verilog-read-always-signals-recurse ")" t nil))))
8684 ((equal keywd "begin")
8685 (skip-syntax-forward "w_")
8686 (verilog-read-always-signals-recurse "end" nil nil)
8687 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
8688 (setq ignore-next nil rvalue semi-rvalue)
8689 (if (not exit-keywd) (setq end-else-check t)))
8690 ((member keywd '("case" "casex" "casez"))
8691 (skip-syntax-forward "w_")
8692 (verilog-read-always-signals-recurse "endcase" t nil)
8693 (setq ignore-next nil rvalue semi-rvalue)
8694 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end
8695 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent
8696 (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8697 (setq ignore-next t))
8699 (member keywd verilog-keywords)
8700 (string-match "^\\$" keywd)) ;; PLI task
8701 (setq ignore-next nil))
8703 (setq keywd (verilog-symbol-detick-denumber keywd))
8705 (set got-list (cons got-sig (symbol-value got-list)))
8706 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
8708 (setq got-list (cond (temp-next 'sigs-temp)
8711 got-sig (if (or (not keywd)
8712 (assoc keywd (symbol-value got-list)))
8713 nil (list keywd nil nil))
8716 (skip-chars-forward "a-zA-Z0-9$_.%`"))
8719 ;; End of non-comment token
8720 (setq last-keywd keywd)))
8721 (skip-syntax-forward " "))
8722 ;; Append the final pending signal
8724 ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
8725 (set got-list (cons got-sig (symbol-value got-list)))
8727 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
8730 (defun verilog-read-always-signals ()
8731 "Parse always block at point and return list of (outputs inout inputs)."
8734 sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
8735 (search-forward ")")
8736 (verilog-read-always-signals-recurse nil nil nil)
8737 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
8739 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))
8740 ;; Return what was found
8741 (verilog-alw-new sigs-out-d sigs-out-i sigs-temp sigs-in))))
8743 (defun verilog-read-instants ()
8744 "Parse module at point and return list of ( ( file instance ) ... )."
8745 (verilog-beg-of-defun-quick)
8746 (let* ((end-mod-point (verilog-get-end-of-defun t))
8748 (instants-list nil))
8750 (while (< (point) end-mod-point)
8751 ;; Stay at level 0, no comments
8753 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
8754 (or (> (car state) 0) ; in parens
8755 (nth 5 state) ; comment
8759 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
8760 ;;(if (looking-at "^\\(.+\\)$")
8761 (let ((module (match-string 1))
8762 (instant (match-string 2)))
8763 (if (not (member module verilog-keywords))
8764 (setq instants-list (cons (list module instant) instants-list)))))
8769 (defun verilog-read-auto-template-middle ()
8770 "With point in middle of an AUTO_TEMPLATE, parse it.
8771 Returns REGEXP and list of ( (signal_name connection_name)... )."
8774 (let ((tpl-regexp "\\([0-9]+\\)")
8775 (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
8777 tpl-sig-list tpl-wild-list tpl-end-pt rep)
8779 ;; We reserve @"..." for future lisp expressions that evaluate
8780 ;; once-per-AUTOINST
8781 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
8782 (setq tpl-regexp (match-string 1))
8783 (goto-char (match-end 0)))
8784 (search-forward "(")
8785 ;; Parse lines in the template
8786 (when (or verilog-auto-inst-template-numbers
8787 verilog-auto-template-warn-unused)
8789 (let ((pre-pt (point)))
8790 (goto-char (point-min))
8791 (while (search-forward "AUTO_TEMPLATE" pre-pt t)
8792 (setq templateno (1+ templateno)))
8793 (while (< (point) pre-pt)
8795 (setq lineno (1+ lineno))))))
8796 (setq tpl-end-pt (save-excursion
8798 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8802 (while (< (point) tpl-end-pt)
8803 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8806 (match-string-no-properties 1)
8807 (match-string-no-properties 2)
8810 (goto-char (match-end 0)))
8813 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
8814 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8815 (setq rep (match-string-no-properties 3))
8816 (goto-char (match-end 0))
8820 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
8826 ((looking-at "[ \t\f]+")
8827 (goto-char (match-end 0)))
8829 (setq lineno (1+ lineno))
8830 (goto-char (match-end 0)))
8832 (search-forward "\n")
8833 (setq lineno (1+ lineno)))
8834 ((looking-at "/\\*")
8836 (or (search-forward "*/")
8837 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8839 (error "%s: AUTO_TEMPLATE parsing error: %s"
8840 (verilog-point-text)
8841 (progn (looking-at ".*$") (match-string 0))))))
8844 (list tpl-sig-list tpl-wild-list)))))
8846 (defun verilog-read-auto-template (module)
8847 "Look for an auto_template for the instantiation of the given MODULE.
8848 If found returns `verilog-read-auto-template-inside' structure."
8852 ;; Note this search is expensive, as we hunt from mod-begin to point
8853 ;; for every instantiation. Likewise in verilog-read-auto-lisp.
8854 ;; So, we look first for an exact string rather than a slow regexp.
8855 ;; Someday we may keep a cache of every template, but this would also
8856 ;; need to record the relative position of each AUTOINST, as multiple
8857 ;; templates exist for each module, and we're inserting lines.
8859 ;; See also regexp in `verilog-auto-template-lint'
8860 (verilog-re-search-backward-substr
8862 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
8863 ;; Also try forward of this AUTOINST
8864 ;; This is for historical support; this isn't speced as working
8867 (verilog-re-search-forward-substr
8869 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
8870 (goto-char (match-end 0))
8871 (verilog-read-auto-template-middle))
8872 ;; If no template found
8873 (t (vector "" nil))))))
8874 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
8876 (defvar verilog-auto-template-hits nil "Successful lookups with `verilog-read-auto-template-hit'.")
8877 (make-variable-buffer-local 'verilog-auto-template-hits)
8879 (defun verilog-read-auto-template-hit (tpl-ass)
8880 "Record that TPL-ASS template from `verilog-read-auto-template' was used."
8881 (when (eval-when-compile (fboundp 'make-hash-table)) ;; else feature not allowed
8882 (when verilog-auto-template-warn-unused
8883 (unless verilog-auto-template-hits
8884 (setq verilog-auto-template-hits
8885 (make-hash-table :test 'equal :rehash-size 4.0)))
8886 (puthash (vector (nth 2 tpl-ass) (nth 3 tpl-ass)) t
8887 verilog-auto-template-hits))))
8889 (defun verilog-set-define (defname defvalue &optional buffer enumname)
8890 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
8891 Optionally associate it with the specified enumeration ENUMNAME."
8892 (with-current-buffer (or buffer (current-buffer))
8893 (let ((mac (intern (concat "vh-" defname))))
8894 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
8895 ;; Need to define to a constant if no value given
8896 (set (make-local-variable mac)
8897 (if (equal defvalue "") "1" defvalue)))
8899 (let ((enumvar (intern (concat "venum-" enumname))))
8900 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
8901 (unless (boundp enumvar) (set enumvar nil))
8902 (add-to-list (make-local-variable enumvar) defname)))))
8904 (defun verilog-read-defines (&optional filename recurse subcall)
8905 "Read `defines and parameters for the current file, or optional FILENAME.
8906 If the filename is provided, `verilog-library-flags' will be used to
8907 resolve it. If optional RECURSE is non-nil, recurse through `includes.
8909 Parameters must be simple assignments to constants, or have their own
8910 \"parameter\" label rather than a list of parameters. Thus:
8912 parameter X = 5, Y = 10; // Ok
8913 parameter X = {1'b1, 2'h2}; // Ok
8914 parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines
8916 Defines must be simple text substitutions, one on a line, starting
8917 at the beginning of the line. Any ifdefs or multiline comments around the
8920 Defines are stored inside Emacs variables using the name vh-{definename}.
8922 This function is useful for setting vh-* variables. The file variables
8923 feature can be used to set defines that `verilog-mode' can see; put at the
8924 *END* of your file something like:
8927 // vh-macro:\"macro_definition\"
8930 If macros are defined earlier in the same file and you want their values,
8931 you can read them automatically (provided `enable-local-eval' is on):
8934 // eval:(verilog-read-defines)
8935 // eval:(verilog-read-defines \"group_standard_includes.v\")
8938 Note these are only read when the file is first visited, you must use
8939 \\[find-alternate-file] RET to have these take effect after editing them!
8941 If you want to disable the \"Process `eval' or hook local variables\"
8942 warning message, you need to add to your init file:
8944 (setq enable-local-eval t)"
8945 (let ((origbuf (current-buffer)))
8947 (unless subcall (verilog-getopt-flags))
8949 (let ((fns (verilog-library-filenames filename (buffer-file-name))))
8951 (set-buffer (find-file-noselect (car fns)))
8952 (error (concat (verilog-point-text)
8953 ": Can't find verilog-read-defines file: " filename)))))
8955 (goto-char (point-min))
8956 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
8957 (let ((inc (verilog-string-replace-matches
8958 "\"" "" nil nil (match-string-no-properties 1))))
8959 (unless (verilog-inside-comment-or-string-p)
8960 (verilog-read-defines inc recurse t)))))
8962 ;; note we don't use verilog-re... it's faster this way, and that
8963 ;; function has problems when comments are at the end of the define
8964 (goto-char (point-min))
8965 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
8966 (let ((defname (match-string-no-properties 1))
8967 (defvalue (match-string-no-properties 2)))
8968 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
8969 (verilog-set-define defname defvalue origbuf)))
8970 ;; Hack: Read parameters
8971 (goto-char (point-min))
8972 (while (re-search-forward
8973 "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
8975 ;; The primary way of getting defines is verilog-read-decls
8976 ;; However, that isn't called yet for included files, so we'll add another scheme
8977 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8978 (setq enumname (match-string-no-properties 2)))
8979 (forward-comment 99999)
8980 (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
8981 "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
8982 (verilog-set-define (match-string-no-properties 1)
8983 (match-string-no-properties 2) origbuf enumname)
8984 (goto-char (match-end 0))
8985 (forward-comment 99999)))))))
8987 (defun verilog-read-includes ()
8988 "Read `includes for the current file.
8989 This will find all of the `includes which are at the beginning of lines,
8990 ignoring any ifdefs or multiline comments around them.
8991 `verilog-read-defines' is then performed on the current and each included
8994 It is often useful put at the *END* of your file something like:
8997 // eval:(verilog-read-defines)
8998 // eval:(verilog-read-includes)
9001 Note includes are only read when the file is first visited, you must use
9002 \\[find-alternate-file] RET to have these take effect after editing them!
9004 It is good to get in the habit of including all needed files in each .v
9005 file that needs it, rather than waiting for compile time. This will aid
9006 this process, Verilint, and readability. To prevent defining the same
9007 variable over and over when many modules are compiled together, put a test
9008 around the inside each include file:
9010 foo.v (an include file):
9011 `ifdef _FOO_V // include if not already included
9014 ... contents of file
9016 ;;slow: (verilog-read-defines nil t))
9018 (verilog-getopt-flags)
9019 (goto-char (point-min))
9020 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9021 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
9022 (verilog-read-defines inc nil t)))))
9024 (defun verilog-read-signals (&optional start end)
9025 "Return a simple list of all possible signals in the file.
9026 Bounded by optional region from START to END. Overly aggressive but fast.
9027 Some macros and such are also found and included. For dinotrace.el."
9028 (let (sigs-all keywd)
9029 (progn;save-excursion
9030 (goto-char (or start (point-min)))
9031 (setq end (or end (point-max)))
9032 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
9036 (search-forward "\n"))
9037 ((looking-at "/\\*")
9038 (search-forward "*/"))
9039 ((looking-at "(\\*")
9040 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
9041 (search-forward "*)")))
9042 ((eq ?\" (following-char))
9043 (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first
9044 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
9045 (goto-char (match-end 0))
9046 (setq keywd (match-string-no-properties 1))
9047 (or (member keywd verilog-keywords)
9048 (member keywd sigs-all)
9049 (setq sigs-all (cons keywd sigs-all))))
9050 (t (forward-char 1))))
9055 ;; Argument file parsing
9058 (defun verilog-getopt (arglist)
9059 "Parse -f, -v etc arguments in ARGLIST list or string."
9060 (unless (listp arglist) (setq arglist (list arglist)))
9061 (let ((space-args '())
9063 ;; Split on spaces, so users can pass whole command lines
9065 (setq arg (car arglist)
9066 arglist (cdr arglist))
9067 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
9068 (setq space-args (append space-args
9069 (list (match-string-no-properties 1 arg))))
9070 (setq arg (match-string 2 arg))))
9073 (setq arg (car space-args)
9074 space-args (cdr space-args))
9078 (setq next-param arg))
9080 (setq next-param arg))
9082 (setq next-param arg))
9083 ;; +libext+(ext1)+(ext2)...
9084 ((string-match "^\\+libext\\+\\(.*\\)" arg)
9085 (setq arg (match-string 1 arg))
9086 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
9087 (verilog-add-list-unique `verilog-library-extensions
9088 (match-string 1 arg))
9089 (setq arg (match-string 2 arg))))
9091 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val
9092 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine
9093 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val
9094 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define
9095 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
9097 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir
9098 (string-match "^-I\\(.*\\)" arg)) ;; -Idir
9099 (verilog-add-list-unique `verilog-library-directories
9100 (match-string 1 (substitute-in-file-name arg))))
9102 ((equal "+librescan" arg))
9103 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine
9104 ;; Second parameters
9105 ((equal next-param "-f")
9106 (setq next-param nil)
9107 (verilog-getopt-file (substitute-in-file-name arg)))
9108 ((equal next-param "-v")
9109 (setq next-param nil)
9110 (verilog-add-list-unique `verilog-library-files
9111 (substitute-in-file-name arg)))
9112 ((equal next-param "-y")
9113 (setq next-param nil)
9114 (verilog-add-list-unique `verilog-library-directories
9115 (substitute-in-file-name arg)))
9117 ((string-match "^[^-+]" arg)
9118 (verilog-add-list-unique `verilog-library-files
9119 (substitute-in-file-name arg)))
9120 ;; Default - ignore; no warning
9122 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
9124 (defun verilog-getopt-file (filename)
9125 "Read Verilog options from the specified FILENAME."
9127 (let ((fns (verilog-library-filenames filename (buffer-file-name)))
9128 (orig-buffer (current-buffer))
9131 (set-buffer (find-file-noselect (car fns)))
9132 (error (concat (verilog-point-text)
9133 ": Can't find verilog-getopt-file -f file: " filename)))
9134 (goto-char (point-min))
9136 (setq line (buffer-substring (point) (point-at-eol)))
9138 (when (string-match "//" line)
9139 (setq line (substring line 0 (match-beginning 0))))
9140 (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
9141 (verilog-getopt line))))))
9143 (defun verilog-getopt-flags ()
9144 "Convert `verilog-library-flags' into standard library variables."
9145 ;; If the flags are local, then all the outputs should be local also
9146 (when (local-variable-p `verilog-library-flags (current-buffer))
9147 (mapc 'make-local-variable '(verilog-library-extensions
9148 verilog-library-directories
9149 verilog-library-files
9150 verilog-library-flags)))
9151 ;; Allow user to customize
9152 (verilog-run-hooks 'verilog-before-getopt-flags-hook)
9153 ;; Process arguments
9154 (verilog-getopt verilog-library-flags)
9155 ;; Allow user to customize
9156 (verilog-run-hooks 'verilog-getopt-flags-hook))
9158 (defun verilog-add-list-unique (varref object)
9159 "Append to VARREF list the given OBJECT,
9160 unless it is already a member of the variable's list."
9161 (unless (member object (symbol-value varref))
9162 (set varref (append (symbol-value varref) (list object))))
9164 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
9166 (defun verilog-current-flags ()
9167 "Convert `verilog-library-flags' and similar variables to command line.
9168 Used for __FLAGS__ in `verilog-expand-command'."
9169 (let ((cmd (mapconcat `concat verilog-library-flags " ")))
9170 (when (equal cmd "")
9172 "+libext+" (mapconcat `concat verilog-library-extensions "+")
9173 (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
9174 verilog-library-directories "")
9175 (mapconcat (lambda (i) (concat " -v " i))
9176 verilog-library-files ""))))
9178 ;;(verilog-current-flags)
9182 ;; Cached directory support
9185 (defvar verilog-dir-cache-preserving nil
9186 "If set, the directory cache is enabled, and file system changes are ignored.
9187 See `verilog-dir-exists-p' and `verilog-dir-files'.")
9189 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
9190 (defvar verilog-dir-cache-list nil
9191 "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
9192 (defvar verilog-dir-cache-lib-filenames nil
9193 "Cached data for `verilog-library-filenames'.")
9195 (defmacro verilog-preserve-dir-cache (&rest body)
9196 "Execute the BODY forms, allowing directory cache preservation within BODY.
9197 This means that changes inside BODY made to the file system will not be
9198 seen by the `verilog-dir-files' and related functions."
9199 `(let ((verilog-dir-cache-preserving (current-buffer))
9200 verilog-dir-cache-list
9201 verilog-dir-cache-lib-filenames)
9204 (defun verilog-dir-files (dirname)
9205 "Return all filenames in the DIRNAME directory.
9206 Relative paths depend on the `default-directory'.
9207 Results are cached if inside `verilog-preserve-dir-cache'."
9208 (unless verilog-dir-cache-preserving
9209 (setq verilog-dir-cache-list nil)) ;; Cache disabled
9210 ;; We don't use expand-file-name on the dirname to make key, as it's slow
9211 (let* ((cache-key (list dirname default-directory))
9212 (fass (assoc cache-key verilog-dir-cache-list))
9214 (cond (fass ;; Return data from cache hit
9217 (setq exp-dirname (expand-file-name dirname)
9218 data (and (file-directory-p exp-dirname)
9219 (directory-files exp-dirname nil nil nil)))
9220 ;; Note we also encache nil for non-existing dirs.
9221 (setq verilog-dir-cache-list (cons (list cache-key data)
9222 verilog-dir-cache-list))
9224 ;; Miss-and-hit test:
9225 ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
9226 ;; (prin1 (verilog-dir-files ".")) nil)
9228 (defun verilog-dir-file-exists-p (filename)
9229 "Return true if FILENAME exists.
9230 Like `file-exists-p' but results are cached if inside
9231 `verilog-preserve-dir-cache'."
9232 (let* ((dirname (file-name-directory filename))
9233 ;; Correct for file-name-nondirectory returning same if no slash.
9234 (dirnamed (if (or (not dirname) (equal dirname filename))
9235 default-directory dirname))
9236 (flist (verilog-dir-files dirnamed)))
9238 (member (file-name-nondirectory filename) flist)
9240 ;;(verilog-dir-file-exists-p "verilog-mode.el")
9241 ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
9245 ;; Module name lookup
9248 (defun verilog-module-inside-filename-p (module filename)
9249 "Return modi if MODULE is specified inside FILENAME, else nil.
9250 Allows version control to check out the file if need be."
9251 (and (or (file-exists-p filename)
9252 (and (fboundp 'vc-backend)
9253 (vc-backend filename)))
9255 (with-current-buffer (find-file-noselect filename)
9257 (goto-char (point-min))
9259 ;; It may be tempting to look for verilog-defun-re,
9260 ;; don't, it slows things down a lot!
9261 (verilog-re-search-forward-quick "\\<\\(module\\|interface\\|program\\)\\>" nil t)
9262 (setq type (match-string-no-properties 0))
9263 (verilog-re-search-forward-quick "[(;]" nil t))
9264 (if (equal module (verilog-read-module-name))
9265 (setq modi (verilog-modi-new module filename (point) type))))
9268 (defun verilog-is-number (symbol)
9269 "Return true if SYMBOL is number-like."
9270 (or (string-match "^[0-9 \t:]+$" symbol)
9271 (string-match "^[---]*[0-9]+$" symbol)
9272 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
9274 (defun verilog-symbol-detick (symbol wing-it)
9275 "Return an expanded SYMBOL name without any defines.
9276 If the variable vh-{symbol} is defined, return that value.
9277 If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
9278 (while (and symbol (string-match "^`" symbol))
9279 (setq symbol (substring symbol 1))
9281 (if (boundp (intern (concat "vh-" symbol)))
9282 ;; Emacs has a bug where boundp on a buffer-local
9283 ;; variable in only one buffer returns t in another.
9284 ;; This can confuse, so check for nil.
9285 (let ((val (eval (intern (concat "vh-" symbol)))))
9287 (if wing-it symbol nil)
9289 (if wing-it symbol nil))))
9291 ;;(verilog-symbol-detick "`mod" nil)
9293 (defun verilog-symbol-detick-denumber (symbol)
9294 "Return SYMBOL with defines converted and any numbers dropped to nil."
9295 (when (string-match "^`" symbol)
9296 ;; This only will work if the define is a simple signal, not
9297 ;; something like a[b]. Sorry, it should be substituted into the parser
9299 (verilog-string-replace-matches
9300 "\[[^0-9: \t]+\]" "" nil nil
9301 (or (verilog-symbol-detick symbol nil)
9302 (if verilog-auto-sense-defines-constant
9305 (if (verilog-is-number symbol)
9309 (defun verilog-symbol-detick-text (text)
9310 "Return TEXT without any known defines.
9311 If the variable vh-{symbol} is defined, substitute that value."
9312 (let ((ok t) symbol val)
9313 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
9314 (setq symbol (match-string 1 text))
9317 (boundp (intern (concat "vh-" symbol)))
9318 ;; Emacs has a bug where boundp on a buffer-local
9319 ;; variable in only one buffer returns t in another.
9320 ;; This can confuse, so check for nil.
9321 (setq val (eval (intern (concat "vh-" symbol)))))
9322 (setq text (replace-match val nil nil text)))
9323 (t (setq ok nil)))))
9325 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
9327 (defun verilog-expand-dirnames (&optional dirnames)
9328 "Return a list of existing directories given a list of wildcarded DIRNAMES.
9329 Or, just the existing dirnames themselves if there are no wildcards."
9330 ;; Note this function is performance critical.
9331 ;; Do not call anything that requires disk access that cannot be cached.
9333 (unless dirnames (error "`verilog-library-directories' should include at least '.'"))
9334 (setq dirnames (reverse dirnames)) ; not nreverse
9336 pattern dirfile dirfiles dirname root filename rest basefile)
9338 (setq dirname (substitute-in-file-name (car dirnames))
9339 dirnames (cdr dirnames))
9340 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root
9341 "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *?
9344 (setq root (match-string 1 dirname)
9345 filename (match-string 2 dirname)
9346 rest (match-string 3 dirname)
9348 ;; now replace those * and ? with .+ and .
9349 ;; use ^ and /> to get only whole file names
9350 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
9351 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
9352 pattern (concat "^" pattern "$")
9353 dirfiles (verilog-dir-files root))
9355 (setq basefile (car dirfiles)
9356 dirfile (expand-file-name (concat root basefile rest))
9357 dirfiles (cdr dirfiles))
9358 (if (and (string-match pattern basefile)
9359 ;; Don't allow abc/*/rtl to match abc/rtl via ..
9360 (not (equal basefile "."))
9361 (not (equal basefile ".."))
9362 (file-directory-p dirfile))
9363 (setq dirlist (cons dirfile dirlist)))))
9366 (if (file-directory-p dirname)
9367 (setq dirlist (cons dirname dirlist))))))
9369 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
9371 (defun verilog-library-filenames (filename &optional current check-ext)
9372 "Return a search path to find the given FILENAME or module name.
9373 Uses the optional CURRENT filename or variable `buffer-file-name', plus
9374 `verilog-library-directories' and `verilog-library-extensions'
9375 variables to build the path. With optional CHECK-EXT also check
9376 `verilog-library-extensions'."
9377 (unless current (setq current (buffer-file-name)))
9378 (unless verilog-dir-cache-preserving
9379 (setq verilog-dir-cache-lib-filenames nil))
9380 (let* ((cache-key (list filename current check-ext))
9381 (fass (assoc cache-key verilog-dir-cache-lib-filenames))
9382 chkdirs chkdir chkexts fn outlist)
9383 (cond (fass ;; Return data from cache hit
9386 ;; Note this expand can't be easily cached, as we need to
9387 ;; pick up buffer-local variables for newly read sub-module files
9388 (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
9390 (setq chkdir (expand-file-name (car chkdirs)
9391 (file-name-directory current))
9392 chkexts (if check-ext verilog-library-extensions `("")))
9394 (setq fn (expand-file-name (concat filename (car chkexts))
9396 ;;(message "Check for %s" fn)
9397 (if (verilog-dir-file-exists-p fn)
9398 (setq outlist (cons (expand-file-name
9399 fn (file-name-directory current))
9401 (setq chkexts (cdr chkexts)))
9402 (setq chkdirs (cdr chkdirs)))
9403 (setq outlist (nreverse outlist))
9404 (setq verilog-dir-cache-lib-filenames
9405 (cons (list cache-key outlist)
9406 verilog-dir-cache-lib-filenames))
9409 (defun verilog-module-filenames (module current)
9410 "Return a search path to find the given MODULE name.
9411 Uses the CURRENT filename, `verilog-library-extensions',
9412 `verilog-library-directories' and `verilog-library-files'
9413 variables to build the path."
9414 ;; Return search locations for it
9415 (append (list current) ; first, current buffer
9416 (verilog-library-filenames module current t)
9417 verilog-library-files)) ; finally, any libraries
9420 ;; Module Information
9422 ;; Many of these functions work on "modi" a module information structure
9423 ;; A modi is: [module-name-string file-name begin-point]
9425 (defvar verilog-cache-enabled t
9426 "Non-nil enables caching of signals, etc. Set to nil for debugging to make things SLOW!")
9428 (defvar verilog-modi-cache-list nil
9429 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
9430 For speeding up verilog-modi-get-* commands.
9432 (make-variable-buffer-local 'verilog-modi-cache-list)
9434 (defvar verilog-modi-cache-preserve-tick nil
9435 "Modification tick after which the cache is still considered valid.
9436 Use `verilog-preserve-modi-cache' to set it.")
9437 (defvar verilog-modi-cache-preserve-buffer nil
9438 "Modification tick after which the cache is still considered valid.
9439 Use `verilog-preserve-modi-cache' to set it.")
9440 (defvar verilog-modi-cache-current-enable nil
9441 "Non-nil means allow caching `verilog-modi-current', set by let().")
9442 (defvar verilog-modi-cache-current nil
9443 "Currently active `verilog-modi-current', if any, set by let().")
9444 (defvar verilog-modi-cache-current-max nil
9445 "Current endmodule point for `verilog-modi-cache-current', if any.")
9447 (defun verilog-modi-current ()
9448 "Return the modi structure for the module currently at point, possibly cached."
9449 (cond ((and verilog-modi-cache-current
9450 (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
9451 (<= (point) verilog-modi-cache-current-max))
9452 ;; Slow assertion, for debugging the cache:
9453 ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
9454 verilog-modi-cache-current)
9455 (verilog-modi-cache-current-enable
9456 (setq verilog-modi-cache-current (verilog-modi-current-get)
9457 verilog-modi-cache-current-max
9458 ;; The cache expires when we pass "endmodule" as then the
9459 ;; current modi may change to the next module
9460 ;; This relies on the AUTOs generally inserting, not deleting text
9462 (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
9463 verilog-modi-cache-current)
9465 (verilog-modi-current-get))))
9467 (defun verilog-modi-current-get ()
9468 "Return the modi structure for the module currently at point."
9469 (let* (name type pt)
9470 ;; read current module's name
9472 (verilog-re-search-backward-quick verilog-defun-re nil nil)
9473 (setq type (match-string-no-properties 0))
9474 (verilog-re-search-forward-quick "(" nil nil)
9475 (setq name (verilog-read-module-name))
9477 ;; return modi - note this vector built two places
9478 (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
9480 (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
9481 (make-variable-buffer-local 'verilog-modi-lookup-cache)
9482 (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
9483 (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
9485 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
9486 "Find the file and point at which MODULE is defined.
9487 If ALLOW-CACHE is set, check and remember cache of previous lookups.
9488 Return modi if successful, else print message unless IGNORE-ERROR is true."
9489 (let* ((current (or (buffer-file-name) (current-buffer)))
9492 ;;(message "verilog-modi-lookup: %s" module)
9493 (cond ((and verilog-modi-lookup-cache
9494 verilog-cache-enabled
9496 (setq modi (gethash module verilog-modi-lookup-cache))
9497 (equal verilog-modi-lookup-last-current current)
9498 ;; Iff hit is in current buffer, then tick must match
9499 (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
9500 (not (equal current (verilog-modi-file-or-buffer modi)))))
9501 ;;(message "verilog-modi-lookup: HIT %S" modi)
9504 (t (let* ((realname (verilog-symbol-detick module t))
9505 (orig-filenames (verilog-module-filenames realname current))
9506 (filenames orig-filenames)
9508 (while (and filenames (not mif))
9509 (if (not (setq mif (verilog-module-inside-filename-p realname (car filenames))))
9510 (setq filenames (cdr filenames))))
9511 ;; mif has correct form to become later elements of modi
9512 (cond (mif (setq modi mif))
9515 (error (concat (verilog-point-text)
9516 ": Can't locate " module " module definition"
9517 (if (not (equal module realname))
9518 (concat " (Expanded macro to " realname ")")
9520 "\n Check the verilog-library-directories variable."
9521 "\n I looked in (if not listed, doesn't exist):\n\t"
9522 (mapconcat 'concat orig-filenames "\n\t"))))))
9523 (when (eval-when-compile (fboundp 'make-hash-table))
9524 (unless verilog-modi-lookup-cache
9525 (setq verilog-modi-lookup-cache
9526 (make-hash-table :test 'equal :rehash-size 4.0)))
9527 (puthash module modi verilog-modi-lookup-cache))
9528 (setq verilog-modi-lookup-last-current current
9529 verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
9532 (defun verilog-modi-filename (modi)
9533 "Filename of MODI, or name of buffer if it's never been saved."
9534 (if (bufferp (verilog-modi-file-or-buffer modi))
9535 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
9536 (buffer-name (verilog-modi-file-or-buffer modi)))
9537 (verilog-modi-file-or-buffer modi)))
9539 (defun verilog-modi-goto (modi)
9540 "Move point/buffer to specified MODI."
9541 (or modi (error "Passed unfound modi to goto, check earlier"))
9542 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
9543 (verilog-modi-file-or-buffer modi)
9544 (find-file-noselect (verilog-modi-file-or-buffer modi))))
9545 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax
9547 (goto-char (verilog-modi-get-point modi)))
9549 (defun verilog-goto-defun-file (module)
9550 "Move point to the file at which a given MODULE is defined."
9551 (interactive "sGoto File for Module: ")
9552 (let* ((modi (verilog-modi-lookup module nil)))
9554 (verilog-modi-goto modi)
9555 (switch-to-buffer (current-buffer)))))
9557 (defun verilog-modi-cache-results (modi function)
9558 "Run on MODI the given FUNCTION. Locate the module in a file.
9559 Cache the output of function so next call may have faster access."
9561 (save-excursion ;; Cache is buffer-local so can't avoid this.
9562 (verilog-modi-goto modi)
9563 (if (and (setq fass (assoc (list modi function)
9564 verilog-modi-cache-list))
9565 ;; Destroy caching when incorrect; Modified or file changed
9566 (not (and verilog-cache-enabled
9567 (or (equal (buffer-chars-modified-tick) (nth 1 fass))
9568 (and verilog-modi-cache-preserve-tick
9569 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
9570 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
9571 (equal (visited-file-modtime) (nth 2 fass)))))
9572 (setq verilog-modi-cache-list nil
9575 ;; Return data from cache hit
9579 ;; Clear then restore any highlighting to make emacs19 happy
9581 (verilog-save-font-mods
9582 (setq func-returns (funcall function)))
9583 ;; Cache for next time
9584 (setq verilog-modi-cache-list
9585 (cons (list (list modi function)
9586 (buffer-chars-modified-tick)
9587 (visited-file-modtime)
9589 verilog-modi-cache-list))
9592 (defun verilog-modi-cache-add (modi function element sig-list)
9593 "Add function return results to the module cache.
9594 Update MODI's cache for given FUNCTION so that the return ELEMENT of that
9595 function now contains the additional SIG-LIST parameters."
9598 (verilog-modi-goto modi)
9599 (if (setq fass (assoc (list modi function)
9600 verilog-modi-cache-list))
9601 (let ((func-returns (nth 3 fass)))
9602 (aset func-returns element
9603 (append sig-list (aref func-returns element))))))))
9605 (defmacro verilog-preserve-modi-cache (&rest body)
9606 "Execute the BODY forms, allowing cache preservation within BODY.
9607 This means that changes to the buffer will not result in the cache being
9608 flushed. If the changes affect the modsig state, they must call the
9609 modsig-cache-add-* function, else the results of later calls may be
9610 incorrect. Without this, changes are assumed to be adding/removing signals
9611 and invalidating the cache."
9612 `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
9613 (verilog-modi-cache-preserve-buffer (current-buffer)))
9617 (defun verilog-modi-modport-lookup-one (modi name &optional ignore-error)
9618 "Given a MODI, return the declarations related to the given modport NAME."
9619 ;; Recursive routine - see below
9620 (let* ((realname (verilog-symbol-detick name t))
9621 (modport (assoc name (verilog-decls-get-modports (verilog-modi-get-decls modi)))))
9622 (or modport ignore-error
9623 (error (concat (verilog-point-text)
9624 ": Can't locate " name " modport definition"
9625 (if (not (equal name realname))
9626 (concat " (Expanded macro to " realname ")")
9628 (let* ((decls (verilog-modport-decls modport))
9629 (clks (verilog-modport-clockings modport)))
9630 ;; Now expand any clocking's
9632 (setq decls (verilog-decls-append
9634 (verilog-modi-modport-lookup-one modi (car clks) ignore-error)))
9635 (setq clks (cdr clks)))
9638 (defun verilog-modi-modport-lookup (modi name-re &optional ignore-error)
9639 "Given a MODI, return the declarations related to the given modport NAME-RE.
9640 If the modport points to any clocking blocks, expand the signals to include
9641 those clocking block's signals."
9642 ;; Recursive routine - see below
9643 (let* ((mod-decls (verilog-modi-get-decls modi))
9644 (clks (verilog-decls-get-modports mod-decls))
9645 (name-re (concat "^" name-re "$"))
9646 (decls (verilog-decls-new nil nil nil nil nil nil nil nil nil)))
9647 ;; Pull in all modports
9649 (when (string-match name-re (verilog-modport-name (car clks)))
9650 (setq decls (verilog-decls-append
9652 (verilog-modi-modport-lookup-one modi (verilog-modport-name (car clks)) ignore-error))))
9653 (setq clks (cdr clks)))
9656 (defun verilog-signals-matching-enum (in-list enum)
9657 "Return all signals in IN-LIST matching the given ENUM."
9660 (if (equal (verilog-sig-enum (car in-list)) enum)
9661 (setq out-list (cons (car in-list) out-list)))
9662 (setq in-list (cdr in-list)))
9664 (let* ((enumvar (intern (concat "venum-" enum)))
9665 (enumlist (and (boundp enumvar) (eval enumvar))))
9667 (add-to-list 'out-list (list (car enumlist)))
9668 (setq enumlist (cdr enumlist))))
9669 (nreverse out-list)))
9671 (defun verilog-signals-matching-regexp (in-list regexp)
9672 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
9673 (if (or (not regexp) (equal regexp ""))
9677 (if (string-match regexp (verilog-sig-name (car in-list)))
9678 (setq out-list (cons (car in-list) out-list)))
9679 (setq in-list (cdr in-list)))
9680 (nreverse out-list))))
9682 (defun verilog-signals-not-matching-regexp (in-list regexp)
9683 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
9684 (if (or (not regexp) (equal regexp ""))
9688 (if (not (string-match regexp (verilog-sig-name (car in-list))))
9689 (setq out-list (cons (car in-list) out-list)))
9690 (setq in-list (cdr in-list)))
9691 (nreverse out-list))))
9693 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
9694 "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
9696 (if (or (not regexp) (equal regexp ""))
9698 (let (out-list to-match)
9700 ;; Note verilog-insert-one-definition matches on this order
9701 (setq to-match (concat
9703 " " (verilog-sig-signed (car in-list))
9704 " " (verilog-sig-multidim (car in-list))
9705 (verilog-sig-bits (car in-list))))
9706 (if (string-match regexp to-match)
9707 (setq out-list (cons (car in-list) out-list)))
9708 (setq in-list (cdr in-list)))
9709 (nreverse out-list))))
9711 (defun verilog-signals-edit-wire-reg (in-list)
9712 "Return all signals in IN-LIST with wire/reg data types made blank."
9713 (mapcar (lambda (sig)
9714 (when (member (verilog-sig-type sig) '("wire" "reg"))
9715 (verilog-sig-type-set sig nil))
9719 (defun verilog-decls-get-signals (decls)
9720 "Return all declared signals in DECLS, excluding 'assign' statements."
9722 (verilog-decls-get-outputs decls)
9723 (verilog-decls-get-inouts decls)
9724 (verilog-decls-get-inputs decls)
9725 (verilog-decls-get-vars decls)
9726 (verilog-decls-get-consts decls)
9727 (verilog-decls-get-gparams decls)))
9729 (defun verilog-decls-get-ports (decls)
9731 (verilog-decls-get-outputs decls)
9732 (verilog-decls-get-inouts decls)
9733 (verilog-decls-get-inputs decls)))
9735 (defun verilog-decls-get-iovars (decls)
9737 (verilog-decls-get-vars decls)
9738 (verilog-decls-get-outputs decls)
9739 (verilog-decls-get-inouts decls)
9740 (verilog-decls-get-inputs decls)))
9742 (defsubst verilog-modi-cache-add-outputs (modi sig-list)
9743 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
9744 (defsubst verilog-modi-cache-add-inouts (modi sig-list)
9745 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
9746 (defsubst verilog-modi-cache-add-inputs (modi sig-list)
9747 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
9748 (defsubst verilog-modi-cache-add-vars (modi sig-list)
9749 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
9750 (defsubst verilog-modi-cache-add-gparams (modi sig-list)
9751 (verilog-modi-cache-add modi 'verilog-read-decls 7 sig-list))
9755 ;; Auto creation utilities
9758 (defun verilog-auto-re-search-do (search-for func)
9759 "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
9760 (goto-char (point-min))
9761 (while (verilog-re-search-forward-quick search-for nil t)
9764 (defun verilog-insert-one-definition (sig type indent-pt)
9765 "Print out a definition for SIG of the given TYPE,
9766 with appropriate INDENT-PT indentation."
9767 (indent-to indent-pt)
9768 ;; Note verilog-signals-matching-dir-re matches on this order
9770 (when (verilog-sig-modport sig)
9771 (insert "." (verilog-sig-modport sig)))
9772 (when (verilog-sig-signed sig)
9773 (insert " " (verilog-sig-signed sig)))
9774 (when (verilog-sig-multidim sig)
9775 (insert " " (verilog-sig-multidim-string sig)))
9776 (when (verilog-sig-bits sig)
9777 (insert " " (verilog-sig-bits sig)))
9778 (indent-to (max 24 (+ indent-pt 16)))
9779 (unless (= (char-syntax (preceding-char)) ?\ )
9780 (insert " ")) ; Need space between "]name" if indent-to did nothing
9781 (insert (verilog-sig-name sig))
9782 (when (verilog-sig-memory sig)
9783 (insert " " (verilog-sig-memory sig))))
9785 (defun verilog-insert-definition (modi sigs direction indent-pt v2k &optional dont-sort)
9786 "Print out a definition for MODI's list of SIGS of the given DIRECTION,
9787 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
9788 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output.
9789 When MODI is non-null, also add to modi-cache, for tracking."
9791 (cond ((equal direction "wire")
9792 (verilog-modi-cache-add-vars modi sigs))
9793 ((equal direction "reg")
9794 (verilog-modi-cache-add-vars modi sigs))
9795 ((equal direction "output")
9796 (verilog-modi-cache-add-outputs modi sigs)
9797 (when verilog-auto-declare-nettype
9798 (verilog-modi-cache-add-vars modi sigs)))
9799 ((equal direction "input")
9800 (verilog-modi-cache-add-inputs modi sigs)
9801 (when verilog-auto-declare-nettype
9802 (verilog-modi-cache-add-vars modi sigs)))
9803 ((equal direction "inout")
9804 (verilog-modi-cache-add-inouts modi sigs)
9805 (when verilog-auto-declare-nettype
9806 (verilog-modi-cache-add-vars modi sigs)))
9807 ((equal direction "interface"))
9808 ((equal direction "parameter")
9809 (verilog-modi-cache-add-gparams modi sigs))
9811 (error "Unsupported verilog-insert-definition direction: %s" direction))))
9813 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
9815 (let ((sig (car sigs)))
9816 (verilog-insert-one-definition
9818 ;; Want "type x" or "output type x", not "wire type x"
9819 (cond ((or (verilog-sig-type sig)
9820 verilog-auto-wire-type)
9822 (when (member direction '("input" "output" "inout"))
9823 (concat direction " "))
9824 (or (verilog-sig-type sig)
9825 verilog-auto-wire-type)))
9826 ((and verilog-auto-declare-nettype
9827 (member direction '("input" "output" "inout")))
9828 (concat direction " " verilog-auto-declare-nettype))
9832 (insert (if v2k "," ";"))
9833 (if (or (not (verilog-sig-comment sig))
9834 (equal "" (verilog-sig-comment sig)))
9836 (indent-to (max 48 (+ indent-pt 40)))
9837 (verilog-insert "// " (verilog-sig-comment sig) "\n"))
9838 (setq sigs (cdr sigs)))))
9841 (if (not (boundp 'indent-pt))
9842 (defvar indent-pt nil "Local used by insert-indent")))
9844 (defun verilog-insert-indent (&rest stuff)
9845 "Indent to position stored in local `indent-pt' variable, then insert STUFF.
9846 Presumes that any newlines end a list element."
9847 (let ((need-indent t))
9849 (if need-indent (indent-to indent-pt))
9850 (setq need-indent nil)
9851 (verilog-insert (car stuff))
9852 (setq need-indent (string-match "\n$" (car stuff))
9853 stuff (cdr stuff)))))
9854 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
9856 (defun verilog-forward-or-insert-line ()
9857 "Move forward a line, unless at EOB, then insert a newline."
9858 (if (eobp) (insert "\n")
9861 (defun verilog-repair-open-comma ()
9862 "Insert comma if previous argument is other than an open parenthesis or endif."
9863 ;; We can't just search backward for ) as it might be inside another expression.
9864 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
9866 (verilog-backward-syntactic-ws-quick)
9867 (when (and (not (save-excursion ;; Not beginning (, or existing ,
9869 (looking-at "[(,]")))
9870 (not (save-excursion ;; Not `endif, or user define
9872 (skip-chars-backward "[a-zA-Z0-9_`]")
9876 (defun verilog-repair-close-comma ()
9877 "If point is at a comma followed by a close parenthesis, fix it.
9878 This repairs those mis-inserted by an AUTOARG."
9879 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
9881 (verilog-forward-close-paren)
9883 (verilog-backward-syntactic-ws-quick)
9885 (when (looking-at ",")
9888 (defun verilog-get-list (start end)
9889 "Return the elements of a comma separated list between START and END."
9891 (let ((my-list (list))
9894 (while (< (point) end)
9895 (when (re-search-forward "\\([^,{]+\\)" end t)
9896 (setq my-string (verilog-string-remove-spaces (match-string 1)))
9897 (setq my-list (nconc my-list (list my-string) ))
9898 (goto-char (match-end 0))))
9901 (defun verilog-make-width-expression (range-exp)
9902 "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
9904 (cond ((not range-exp)
9907 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
9908 (setq range-exp (match-string 1 range-exp)))
9909 (cond ((not range-exp)
9911 ;; [#:#] We can compute a numeric result
9912 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
9915 (1+ (abs (- (string-to-number (match-string 1 range-exp))
9916 (string-to-number (match-string 2 range-exp)))))))
9917 ;; [PARAM-1:0] can just return PARAM
9918 ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
9919 (match-string 1 range-exp))
9920 ;; [arbitrary] need math
9921 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
9922 (concat "(1+(" (match-string 1 range-exp) ")"
9923 (if (equal "0" (match-string 2 range-exp))
9924 "" ;; Don't bother with -(0)
9925 (concat "-(" (match-string 2 range-exp) ")"))
9928 ;;(verilog-make-width-expression "`A:`B")
9930 (defun verilog-simplify-range-expression (expr)
9931 "Return a simplified range expression with constants eliminated from EXPR."
9932 ;; Note this is always called with brackets; ie [z] or [z:z]
9933 (if (not (string-match "[---+*()]" expr))
9934 expr ;; short-circuit
9937 (while (not (equal last-pass out))
9938 (setq last-pass out)
9939 ;; Prefix regexp needs beginning of match, or some symbol of
9940 ;; lesser or equal precedence. We assume the [:]'s exist in expr.
9942 (while (string-match
9943 (concat "\\([[({:*+-]\\)" ; - must be last
9944 "(\\<\\([0-9A-Za-z_]+\\))"
9947 (setq out (replace-match "\\1\\2\\3" nil nil out)))
9948 (while (string-match
9949 (concat "\\([[({:*+-]\\)" ; - must be last
9950 "\\$clog2\\s *(\\<\\([0-9]+\\))"
9953 (setq out (replace-match
9955 (match-string 1 out)
9956 (int-to-string (verilog-clog2 (string-to-number (match-string 2 out))))
9957 (match-string 3 out))
9959 ;; For precedence do * before +/-
9960 (while (string-match
9961 (concat "\\([[({:*+-]\\)"
9962 "\\([0-9]+\\)\\s *\\([*]\\)\\s *\\([0-9]+\\)"
9965 (setq out (replace-match
9966 (concat (match-string 1 out)
9967 (int-to-string (* (string-to-number (match-string 2 out))
9968 (string-to-number (match-string 4 out))))
9969 (match-string 5 out))
9971 (while (string-match
9972 (concat "\\([[({:+-]\\)" ; No * here as higher prec
9973 "\\([0-9]+\\)\\s *\\([---+]\\)\\s *\\([0-9]+\\)"
9976 (let ((pre (match-string 1 out))
9977 (lhs (string-to-number (match-string 2 out)))
9978 (rhs (string-to-number (match-string 4 out)))
9979 (post (match-string 5 out))
9981 (when (equal pre "-")
9983 (setq val (if (equal (match-string 3 out) "-")
9987 (concat (if (and (equal pre "-")
9989 "" ;; Not "--20" but just "-20"
9996 ;;(verilog-simplify-range-expression "[1:3]") ;; 1
9997 ;;(verilog-simplify-range-expression "[(1):3]") ;; 1
9998 ;;(verilog-simplify-range-expression "[(((16)+1)+1+(1+1))]") ;;20
9999 ;;(verilog-simplify-range-expression "[(2*3+6*7)]") ;; 48
10000 ;;(verilog-simplify-range-expression "[(FOO*4-1*2)]") ;; FOO*4-2
10001 ;;(verilog-simplify-range-expression "[(FOO*4+1-1)]") ;; FOO*4+0
10002 ;;(verilog-simplify-range-expression "[(func(BAR))]") ;; func(BAR)
10003 ;;(verilog-simplify-range-expression "[FOO-1+1-1+1]") ;; FOO-0
10004 ;;(verilog-simplify-range-expression "[$clog2(2)]") ;; 1
10005 ;;(verilog-simplify-range-expression "[$clog2(7)]") ;; 3
10007 (defun verilog-clog2 (value)
10008 "Compute $clog2 - ceiling log2 of VALUE."
10011 (ceiling (/ (log value) (log 2)))))
10013 (defun verilog-typedef-name-p (variable-name)
10014 "Return true if the VARIABLE-NAME is a type definition."
10015 (when verilog-typedef-regexp
10016 (string-match verilog-typedef-regexp variable-name)))
10022 (defun verilog-delete-autos-lined ()
10023 "Delete autos that occupy multiple lines, between begin and end comments."
10024 ;; The newline must not have a comment property, so we must
10025 ;; delete the end auto's newline, not the first newline
10027 (let ((pt (point)))
10029 (looking-at "\\s-*// Beginning")
10030 (search-forward "// End of automatic" nil t))
10034 (delete-region pt (point)))))
10036 (defun verilog-delete-empty-auto-pair ()
10037 "Delete begin/end auto pair at point, if empty."
10039 (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
10040 "\\s-*// End of automatics\n"))
10041 (delete-region (point) (save-excursion (forward-line 2) (point)))))
10043 (defun verilog-forward-close-paren ()
10044 "Find the close parenthesis that match the current point.
10045 Ignore other close parenthesis with matching open parens."
10047 (while (> parens 0)
10048 (unless (verilog-re-search-forward-quick "[()]" nil t)
10049 (error "%s: Mismatching ()" (verilog-point-text)))
10050 (cond ((= (preceding-char) ?\( )
10051 (setq parens (1+ parens)))
10052 ((= (preceding-char) ?\) )
10053 (setq parens (1- parens)))))))
10055 (defun verilog-backward-open-paren ()
10056 "Find the open parenthesis that match the current point.
10057 Ignore other open parenthesis with matching close parens."
10059 (while (> parens 0)
10060 (unless (verilog-re-search-backward-quick "[()]" nil t)
10061 (error "%s: Mismatching ()" (verilog-point-text)))
10062 (cond ((= (following-char) ?\) )
10063 (setq parens (1+ parens)))
10064 ((= (following-char) ?\( )
10065 (setq parens (1- parens)))))))
10067 (defun verilog-backward-open-bracket ()
10068 "Find the open bracket that match the current point.
10069 Ignore other open bracket with matching close bracket."
10071 (while (> parens 0)
10072 (unless (verilog-re-search-backward-quick "[][]" nil t)
10073 (error "%s: Mismatching []" (verilog-point-text)))
10074 (cond ((= (following-char) ?\] )
10075 (setq parens (1+ parens)))
10076 ((= (following-char) ?\[ )
10077 (setq parens (1- parens)))))))
10079 (defun verilog-delete-to-paren ()
10080 "Delete the automatic inst/sense/arg created by autos.
10081 Deletion stops at the matching end parenthesis, outside comments."
10082 (delete-region (point)
10084 (verilog-backward-open-paren)
10085 (verilog-forward-sexp-ign-cmt 1) ;; Moves to paren that closes argdecl's
10089 (defun verilog-auto-star-safe ()
10090 "Return if a .* AUTOINST is safe to delete or expand.
10091 It was created by the AUTOS themselves, or by the user."
10092 (and verilog-auto-star-expand
10094 (concat "[ \t\n\f,]*\\([)]\\|// " verilog-inst-comment-re "\\)"))))
10096 (defun verilog-delete-auto-star-all ()
10097 "Delete a .* AUTOINST, if it is safe."
10098 (when (verilog-auto-star-safe)
10099 (verilog-delete-to-paren)))
10101 (defun verilog-delete-auto-star-implicit ()
10102 "Delete all .* implicit connections created by `verilog-auto-star'.
10103 This function will be called automatically at save unless
10104 `verilog-auto-star-save' is set, any non-templated expanded pins will be
10107 (let (paren-pt indent have-close-paren)
10109 (goto-char (point-min))
10110 ;; We need to match these even outside of comments.
10111 ;; For reasonable performance, we don't check if inside comments, sorry.
10112 (while (re-search-forward "// Implicit \\.\\*" nil t)
10113 (setq paren-pt (point))
10114 (beginning-of-line)
10115 (setq have-close-paren
10117 (when (search-forward ");" paren-pt t)
10118 (setq indent (current-indentation))
10120 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
10121 (when have-close-paren
10122 ;; Delete extra commentary
10126 (looking-at (concat "\\s *//\\s *" verilog-inst-comment-re "\n")))
10127 (delete-region (match-beginning 0) (match-end 0))))
10128 ;; If it is simple, we can put the ); on the same line as the last text
10129 (let ((rtn-pt (point)))
10131 (while (progn (backward-char 1)
10132 (looking-at "[ \t\n\f]")))
10133 (when (looking-at ",")
10134 (delete-region (+ 1 (point)) rtn-pt))))
10136 (indent-to indent))
10138 ;; Still need to kill final comma - always is one as we put one after the .*
10139 (re-search-backward ",")
10140 (delete-char 1))))))
10142 (defun verilog-delete-auto ()
10143 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
10144 Use \\[verilog-auto] to re-insert the updated AUTOs.
10146 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
10147 called before and after this function, respectively."
10150 (if (buffer-file-name)
10151 (find-file-noselect (buffer-file-name))) ;; To check we have latest version
10152 (verilog-save-no-change-functions
10153 (verilog-save-scan-cache
10154 ;; Allow user to customize
10155 (verilog-run-hooks 'verilog-before-delete-auto-hook)
10157 ;; Remove those that have multi-line insertions, possibly with parameters
10158 ;; We allow anything beginning with AUTO, so that users can add their own
10160 (verilog-auto-re-search-do
10161 (concat "/\\*AUTO[A-Za-z0-9_]+"
10162 ;; Optional parens or quoted parameter or .* for (((...)))
10163 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
10165 'verilog-delete-autos-lined)
10166 ;; Remove those that are in parenthesis
10167 (verilog-auto-re-search-do
10170 (verilog-regexp-words
10171 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
10174 'verilog-delete-to-paren)
10175 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
10176 (verilog-auto-re-search-do "\\.\\*"
10177 'verilog-delete-auto-star-all)
10178 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
10179 (goto-char (point-min))
10180 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
10181 (replace-match ""))
10184 (verilog-run-hooks 'verilog-delete-auto-hook)))))
10190 (defun verilog-inject-auto ()
10191 "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
10193 Any always @ blocks with sensitivity lists that match computed lists will
10194 be replaced with /*AS*/ comments.
10196 Any cells will get /*AUTOINST*/ added to the end of the pin list.
10197 Pins with have identical names will be deleted.
10199 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
10200 support adding new ports. You may wish to delete older ports yourself.
10204 module ExampInject (i, o);
10210 InstModule instName
10215 Typing \\[verilog-inject-auto] will make this into:
10217 module ExampInject (i, o/*AUTOARG*/
10222 always @ (/*AS*/i or j)
10224 InstModule instName
10233 (defun verilog-inject-arg ()
10234 "Inject AUTOARG into new code. See `verilog-inject-auto'."
10235 ;; Presume one module per file.
10237 (goto-char (point-min))
10238 (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
10239 (let ((endmodp (save-excursion
10240 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
10242 ;; See if there's already a comment .. inside a comment so not verilog-re-search
10243 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
10244 (verilog-re-search-forward-quick ";" nil t)
10246 (verilog-backward-syntactic-ws-quick)
10247 (backward-char 1) ; Moves to paren that closes argdecl's
10248 (when (looking-at ")")
10249 (verilog-insert "/*AUTOARG*/")))))))
10251 (defun verilog-inject-sense ()
10252 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
10254 (goto-char (point-min))
10255 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
10256 (let* ((start-pt (point))
10257 (modi (verilog-modi-current))
10258 (moddecls (verilog-modi-get-decls modi))
10262 (verilog-forward-sexp-ign-cmt 1)
10263 (backward-char 1) ;; End )
10264 (when (not (verilog-re-search-backward-quick "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
10265 (setq pre-sigs (verilog-signals-from-signame
10266 (verilog-read-signals start-pt (point)))
10267 got-sigs (verilog-auto-sense-sigs moddecls nil))
10268 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
10269 (verilog-signals-not-in got-sigs pre-sigs)))
10270 (delete-region start-pt (point))
10271 (verilog-insert "/*AS*/")))))))
10273 (defun verilog-inject-inst ()
10274 "Inject AUTOINST into new code. See `verilog-inject-auto'."
10276 (goto-char (point-min))
10277 ;; It's hard to distinguish modules; we'll instead search for pins.
10278 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t)
10279 (verilog-backward-open-paren) ;; Inst start
10281 ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip.
10283 (verilog-forward-close-paren)) ;; Parameters done
10286 (let ((indent-pt (+ (current-column)))
10287 (end-pt (save-excursion (verilog-forward-close-paren) (point))))
10288 (cond ((verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
10289 (goto-char end-pt)) ;; Already there, continue search with next instance
10291 ;; Delete identical interconnect
10292 (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc
10293 (while (verilog-re-search-forward-quick "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
10294 (delete-region (match-beginning 0) (match-end 0))
10295 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct
10296 (while (or (looking-at "[ \t\n\f,]+")
10297 (looking-at "//[^\n]*"))
10298 (delete-region (match-beginning 0) (match-end 0))
10299 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
10300 (verilog-forward-close-paren)
10302 ;; Not verilog-re-search, as we don't want to strip comments
10303 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
10304 (delete-region (match-beginning 0) (match-end 0)))
10305 (verilog-insert "\n")
10306 (verilog-insert-indent "/*AUTOINST*/")))))))))
10312 (defun verilog-diff-buffers-p (b1 b2 &optional whitespace)
10313 "Return nil if buffers B1 and B2 have same contents.
10314 Else, return point in B1 that first mismatches.
10315 If optional WHITESPACE true, ignore whitespace."
10317 (let* ((case-fold-search nil) ;; compare-buffer-substrings cares
10318 (p1 (with-current-buffer b1 (goto-char (point-min))))
10319 (p2 (with-current-buffer b2 (goto-char (point-min))))
10320 (maxp1 (with-current-buffer b1 (point-max)))
10321 (maxp2 (with-current-buffer b2 (point-max)))
10324 (while (not (and (eq p1 op1) (eq p2 op2)))
10325 ;; If both windows have whitespace optionally skip over it.
10327 ;; skip-syntax-* doesn't count \n
10328 (with-current-buffer b1
10330 (skip-chars-forward " \t\n\r\f\v")
10332 (with-current-buffer b2
10334 (skip-chars-forward " \t\n\r\f\v")
10335 (setq p2 (point))))
10336 (setq size (min (- maxp1 p1) (- maxp2 p2)))
10337 (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
10338 b1 p1 (+ size p1)))
10339 (setq progress (if (zerop progress) size (1- (abs progress))))
10340 (setq op1 p1 op2 p2
10342 p2 (+ p2 progress)))
10344 (if (and (eq p1 maxp1) (eq p2 maxp2))
10347 (defun verilog-diff-file-with-buffer (f1 b2 &optional whitespace show)
10348 "View the differences between file F1 and buffer B2.
10349 This requires the external program `diff-command' to be in your `exec-path',
10350 and uses `diff-switches' in which you may want to have \"-u\" flag.
10351 Ignores WHITESPACE if t, and writes output to stdout if SHOW."
10352 ;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
10353 ;; call `diff' as `diff' has different calling semantics on different
10354 ;; versions of Emacs.
10355 (if (not (file-exists-p f1))
10356 (message "Buffer %s has no associated file on disc" (buffer-name b2))
10357 (with-temp-buffer "*Verilog-Diff*"
10358 (let ((outbuf (current-buffer))
10359 (f2 (make-temp-file "vm-diff-auto-")))
10362 (with-current-buffer b2
10365 (write-region (point-min) (point-max) f2 nil 'nomessage)))
10366 (call-process diff-command nil outbuf t
10367 diff-switches ;; User may want -u in diff-switches
10368 (if whitespace "-b" "")
10370 ;; Print out results. Alternatively we could have call-processed
10371 ;; ourself, but this way we can reuse diff switches
10373 (with-current-buffer outbuf (message "%s" (buffer-string))))))
10375 (when (file-exists-p f2)
10376 (delete-file f2))))))
10378 (defun verilog-diff-report (b1 b2 diffpt)
10379 "Report differences detected with `verilog-diff-auto'.
10380 Differences are between buffers B1 and B2, starting at point
10381 DIFFPT. This function is called via `verilog-diff-function'."
10382 (let ((name1 (with-current-buffer b1 (buffer-file-name))))
10383 (verilog-warn "%s:%d: Difference in AUTO expansion found"
10384 name1 (with-current-buffer b1
10385 (1+ (count-lines (point-min) (point)))))
10386 (cond (noninteractive
10387 (verilog-diff-file-with-buffer name1 b2 t t))
10389 (ediff-buffers b1 b2)))))
10391 (defun verilog-diff-auto ()
10392 "Expand AUTOs in a temporary buffer and indicate any change.
10393 Whitespace differences are ignored to determine identicalness, but
10394 once a difference is detected, whitespace differences may be shown.
10396 To call this from the command line, see \\[verilog-batch-diff-auto].
10398 The action on differences is selected with
10399 `verilog-diff-function'. The default is `verilog-diff-report'
10400 which will report an error and run `ediff' in interactive mode,
10401 or `diff' in batch mode."
10403 (let ((b1 (current-buffer)) b2 diffpt
10404 (name1 (buffer-file-name))
10405 (newname "*Verilog-Diff*"))
10407 (when (get-buffer newname)
10408 (kill-buffer newname))
10409 (setq b2 (let (buffer-file-name) ;; Else clone is upset
10410 (clone-buffer newname)))
10411 (with-current-buffer b2
10412 ;; auto requires the filename, but can't have same filename in two
10413 ;; buffers; so override both b1 and b2's names
10414 (let ((buffer-file-name name1))
10417 (with-current-buffer b1 (setq buffer-file-name nil))
10419 (when (not verilog-auto-star-save)
10420 (verilog-delete-auto-star-implicit)))
10421 ;; Restore name if unwind
10422 (with-current-buffer b1 (setq buffer-file-name name1)))))
10424 (setq diffpt (verilog-diff-buffers-p b1 b2 t))
10425 (cond ((not diffpt)
10426 (unless noninteractive (message "AUTO expansion identical"))
10427 (kill-buffer newname)) ;; Nice to cleanup after oneself
10429 (funcall verilog-diff-function b1 b2 diffpt)))
10430 ;; Return result of compare
10438 (defun verilog-auto-save-check ()
10439 "On saving see if we need auto update."
10440 (cond ((not verilog-auto-save-policy)) ; disabled
10441 ((not (save-excursion
10443 (let ((case-fold-search nil))
10444 (goto-char (point-min))
10445 (re-search-forward "AUTO" nil t))))))
10446 ((eq verilog-auto-save-policy 'force)
10448 ((not (buffer-modified-p)))
10449 ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
10450 ((eq verilog-auto-save-policy 'detect)
10453 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
10455 ;; Don't ask again if didn't update
10456 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
10457 (when (not verilog-auto-star-save)
10458 (verilog-delete-auto-star-implicit))
10459 nil) ;; Always return nil -- we don't write the file ourselves
10461 (defun verilog-auto-read-locals ()
10462 "Return file local variable segment at bottom of file."
10464 (goto-char (point-max))
10465 (if (re-search-backward "Local Variables:" nil t)
10466 (buffer-substring-no-properties (point) (point-max))
10469 (defun verilog-auto-reeval-locals (&optional force)
10470 "Read file local variable segment at bottom of file if it has changed.
10471 If FORCE, always reread it."
10472 (let ((curlocal (verilog-auto-read-locals)))
10473 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
10474 (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
10475 ;; Note this may cause this function to be recursively invoked,
10476 ;; because hack-local-variables may call (verilog-mode)
10477 ;; The above when statement will prevent it from recursing forever.
10478 (hack-local-variables)
10485 (defun verilog-auto-arg-ports (sigs message indent-pt)
10486 "Print a list of ports for an AUTOINST.
10487 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
10489 (when verilog-auto-arg-sort
10490 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
10492 (indent-to indent-pt)
10496 (indent-to indent-pt)
10498 (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
10500 (indent-to indent-pt))
10501 (t (insert space)))
10502 (insert (verilog-sig-name (car sigs)) ",")
10503 (setq sigs (cdr sigs)
10506 (defun verilog-auto-arg ()
10507 "Expand AUTOARG statements.
10508 Replace the argument declarations at the beginning of the
10509 module with ones automatically derived from input and output
10510 statements. This can be dangerous if the module is instantiated
10511 using position-based connections, so use only name-based when
10512 instantiating the resulting module. Long lines are split based
10513 on the `fill-column', see \\[set-fill-column].
10516 Concatenation and outputting partial buses is not supported.
10518 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10522 module ExampArg (/*AUTOARG*/);
10527 Typing \\[verilog-auto] will make this into:
10529 module ExampArg (/*AUTOARG*/
10539 The argument declarations may be printed in declaration order to best suit
10540 order based instantiations, or alphabetically, based on the
10541 `verilog-auto-arg-sort' variable.
10543 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
10544 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
10545 conservative guess on adding a comma for the first signal, if you have
10546 any ifdefs or complicated expressions before the AUTOARG you will need
10547 to choose the comma yourself.
10549 Avoid declaring ports manually, as it makes code harder to maintain."
10551 (let* ((modi (verilog-modi-current))
10552 (moddecls (verilog-modi-get-decls modi))
10553 (skip-pins (aref (verilog-read-arg-pins) 0)))
10554 (verilog-repair-open-comma)
10555 (verilog-auto-arg-ports (verilog-signals-not-in
10556 (verilog-decls-get-outputs moddecls)
10559 verilog-indent-level-declaration)
10560 (verilog-auto-arg-ports (verilog-signals-not-in
10561 (verilog-decls-get-inouts moddecls)
10564 verilog-indent-level-declaration)
10565 (verilog-auto-arg-ports (verilog-signals-not-in
10566 (verilog-decls-get-inputs moddecls)
10569 verilog-indent-level-declaration)
10570 (verilog-repair-close-comma)
10571 (unless (eq (char-before) ?/ )
10573 (indent-to verilog-indent-level-declaration))))
10575 (defun verilog-auto-assign-modport ()
10576 "Expand AUTOASSIGNMODPORT statements, as part of \\[verilog-auto].
10577 Take input/output/inout statements from the specified interface
10578 and modport and use to build assignments into the modport, for
10579 making verification modules that connect to UVM interfaces.
10581 The first parameter is the name of an interface.
10583 The second parameter is a regexp of modports to read from in
10586 The third parameter is the instance name to use to dot reference into.
10588 The optional fourth parameter is a regular expression, and only
10589 signals matching the regular expression will be included.
10593 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
10595 Inouts are not supported, as assignments must be unidirectional.
10597 If a signal is part of the interface header and in both a
10598 modport and the interface itself, it will not be listed. (As
10599 this would result in a syntax error when the connections are
10602 See the example in `verilog-auto-inout-modport'."
10604 (let* ((params (verilog-read-auto-params 3 4))
10605 (submod (nth 0 params))
10606 (modport-re (nth 1 params))
10607 (inst-name (nth 2 params))
10608 (regexp (nth 3 params))
10609 direction-re submodi) ;; direction argument not supported until requested
10610 ;; Lookup position, etc of co-module
10611 ;; Note this may raise an error
10612 (when (setq submodi (verilog-modi-lookup submod t))
10613 (let* ((indent-pt (current-indentation))
10614 (modi (verilog-modi-current))
10615 (submoddecls (verilog-modi-get-decls submodi))
10616 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
10617 (sig-list-i (verilog-signals-in ;; Decls doesn't have data types, must resolve
10618 (verilog-decls-get-vars submoddecls)
10619 (verilog-signals-not-in
10620 (verilog-decls-get-inputs submodportdecls)
10621 (verilog-decls-get-ports submoddecls))))
10622 (sig-list-o (verilog-signals-in ;; Decls doesn't have data types, must resolve
10623 (verilog-decls-get-vars submoddecls)
10624 (verilog-signals-not-in
10625 (verilog-decls-get-outputs submodportdecls)
10626 (verilog-decls-get-ports submoddecls)))))
10628 (setq sig-list-i (verilog-signals-edit-wire-reg
10629 (verilog-signals-matching-dir-re
10630 (verilog-signals-matching-regexp sig-list-i regexp)
10631 "input" direction-re))
10632 sig-list-o (verilog-signals-edit-wire-reg
10633 (verilog-signals-matching-dir-re
10634 (verilog-signals-matching-regexp sig-list-o regexp)
10635 "output" direction-re)))
10636 (setq sig-list-i (sort (copy-alist sig-list-i) `verilog-signals-sort-compare))
10637 (setq sig-list-o (sort (copy-alist sig-list-o) `verilog-signals-sort-compare))
10638 (when (or sig-list-i sig-list-o)
10639 (verilog-insert-indent "// Beginning of automatic assignments from modport\n")
10640 ;; Don't sort them so an upper AUTOINST will match the main module
10641 (let ((sigs sig-list-o))
10643 (verilog-insert-indent "assign " (verilog-sig-name (car sigs))
10645 "." (verilog-sig-name (car sigs)) ";\n")
10646 (setq sigs (cdr sigs))))
10647 (let ((sigs sig-list-i))
10649 (verilog-insert-indent "assign " inst-name
10650 "." (verilog-sig-name (car sigs))
10651 " = " (verilog-sig-name (car sigs)) ";\n")
10652 (setq sigs (cdr sigs))))
10653 (verilog-insert-indent "// End of automatics\n")))))))
10655 (defun verilog-auto-inst-port-map (port-st)
10658 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
10659 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
10660 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
10661 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
10662 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
10663 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
10664 (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
10665 (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
10667 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
10668 "Print out an instantiation connection for this PORT-ST.
10669 Insert to INDENT-PT, use template TPL-LIST.
10670 @ are instantiation numbers, replaced with TPL-NUM.
10671 @\"(expression @)\" are evaluated, with @ as a variable.
10672 If FOR-STAR add comment it is a .* expansion.
10673 If PAR-VALUES replace final strings with these parameter values."
10674 (let* ((port (verilog-sig-name port-st))
10675 (tpl-ass (or (assoc port (car tpl-list))
10676 (verilog-auto-inst-port-map port-st)))
10677 ;; vl-* are documented for user use
10678 (vl-name (verilog-sig-name port-st))
10679 (vl-width (verilog-sig-width port-st))
10680 (vl-modport (verilog-sig-modport port-st))
10681 (vl-mbits (if (verilog-sig-multidim port-st)
10682 (verilog-sig-multidim-string port-st) ""))
10683 (vl-bits (if (or verilog-auto-inst-vector
10684 (not (assoc port vector-skip-list))
10685 (not (equal (verilog-sig-bits port-st)
10686 (verilog-sig-bits (assoc port vector-skip-list)))))
10687 (or (verilog-sig-bits port-st) "")
10689 (case-fold-search nil)
10690 (check-values par-values)
10692 ;; Replace parameters in bit-width
10693 (when (and check-values
10694 (not (equal vl-bits "")))
10695 (while check-values
10696 (setq vl-bits (verilog-string-replace-matches
10697 (concat "\\<" (nth 0 (car check-values)) "\\>")
10698 (concat "(" (nth 1 (car check-values)) ")")
10700 vl-mbits (verilog-string-replace-matches
10701 (concat "\\<" (nth 0 (car check-values)) "\\>")
10702 (concat "(" (nth 1 (car check-values)) ")")
10704 check-values (cdr check-values)))
10705 (setq vl-bits (verilog-simplify-range-expression vl-bits)
10706 vl-mbits (verilog-simplify-range-expression vl-mbits)
10707 vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
10708 ;; Default net value if not found
10709 (setq tpl-net (concat port
10710 (if vl-modport (concat "." vl-modport) "")
10711 (if (verilog-sig-multidim port-st)
10712 (concat "/*" vl-mbits vl-bits "*/")
10713 (concat vl-bits))))
10715 (cond (tpl-ass ; Template of exact port name
10716 (setq tpl-net (nth 1 tpl-ass)))
10717 ((nth 1 tpl-list) ; Wildcards in template, search them
10718 (let ((wildcards (nth 1 tpl-list)))
10720 (when (string-match (nth 0 (car wildcards)) port)
10721 (setq tpl-ass (car wildcards) ; so allow @ parsing
10722 tpl-net (replace-match (nth 1 (car wildcards))
10724 (setq wildcards (cdr wildcards))))))
10725 ;; Parse Templated variable
10727 ;; Evaluate @"(lispcode)"
10728 (when (string-match "@\".*[^\\]\"" tpl-net)
10729 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
10732 (substring tpl-net 0 (match-beginning 0))
10734 (let* ((expr (match-string 1 tpl-net))
10737 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
10738 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
10739 (prin1 (eval (car (read-from-string expr)))
10740 (lambda (ch) ())))))
10741 (if (numberp value) (setq value (number-to-string value)))
10743 (substring tpl-net (match-end 0))))))
10744 ;; Replace @ and [] magic variables in final output
10745 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
10746 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
10748 (indent-to indent-pt)
10750 (unless (and verilog-auto-inst-dot-name
10751 (equal port tpl-net))
10752 (indent-to verilog-auto-inst-column)
10753 (insert "(" tpl-net ")"))
10756 (verilog-read-auto-template-hit tpl-ass)
10757 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
10758 verilog-auto-inst-column))
10759 ;; verilog-insert requires the complete comment in one call - including the newline
10760 (cond ((equal verilog-auto-inst-template-numbers `lhs)
10761 (verilog-insert " // Templated"
10762 " LHS: " (nth 0 tpl-ass)
10764 (verilog-auto-inst-template-numbers
10765 (verilog-insert " // Templated"
10766 " T" (int-to-string (nth 2 tpl-ass))
10767 " L" (int-to-string (nth 3 tpl-ass))
10770 (verilog-insert " // Templated\n"))))
10772 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
10773 verilog-auto-inst-column))
10774 (verilog-insert " // Implicit .\*\n")) ;For some reason the . or * must be escaped...
10777 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
10778 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
10779 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
10781 (defun verilog-auto-inst-port-list (sig-list indent-pt tpl-list tpl-num for-star par-values)
10782 "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
10783 (when verilog-auto-inst-sort
10784 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)))
10785 (mapc (lambda (port)
10786 (verilog-auto-inst-port port indent-pt
10787 tpl-list tpl-num for-star par-values))
10790 (defun verilog-auto-inst-first ()
10791 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
10792 ;; Do we need a trailing comma?
10793 ;; There maybe an ifdef or something similar before us. What a mess. Thus
10794 ;; to avoid trouble we only insert on preceding ) or *.
10795 ;; Insert first port on new line
10796 (insert "\n") ;; Must insert before search, so point will move forward if insert comma
10798 (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
10799 (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure
10803 (defun verilog-auto-star ()
10804 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
10806 If `verilog-auto-star-expand' is set, .* pins are treated if they were
10807 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
10808 will also ignore any .* that are not last in your pin list (this prevents
10809 it from deleting pins following the .* when it expands the AUTOINST.)
10811 On writing your file, unless `verilog-auto-star-save' is set, any
10812 non-templated expanded pins will be removed. You may do this at any time
10813 with \\[verilog-delete-auto-star-implicit].
10815 If you are converting a module to use .* for the first time, you may wish
10816 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
10818 See `verilog-auto-inst' for examples, templates, and more information."
10819 (when (verilog-auto-star-safe)
10820 (verilog-auto-inst)))
10822 (defun verilog-auto-inst ()
10823 "Expand AUTOINST statements, as part of \\[verilog-auto].
10824 Replace the pin connections to an instantiation or interface
10825 declaration with ones automatically derived from the module or
10826 interface header of the instantiated item.
10828 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
10829 and delete them before saving unless `verilog-auto-star-save' is set.
10830 See `verilog-auto-star' for more information.
10832 The pins are printed in declaration order or alphabetically,
10833 based on the `verilog-auto-inst-sort' variable.
10836 Module names must be resolvable to filenames by adding a
10837 `verilog-library-extensions', and being found in the same directory, or
10838 by changing the variable `verilog-library-flags' or
10839 `verilog-library-directories'. Macros `modname are translated through the
10840 vh-{name} Emacs variable, if that is not found, it just ignores the `.
10842 In templates you must have one signal per line, ending in a ), or ));,
10843 and have proper () nesting, including a final ); to end the template.
10845 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10847 SystemVerilog multidimensional input/output has only experimental support.
10849 SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
10851 Parameters referenced by the instantiation will remain symbolic, unless
10852 `verilog-auto-inst-param-value' is set.
10854 Gate primitives (and/or) may have AUTOINST for the purpose of
10855 AUTOWIRE declarations, etc. Gates are the only case when
10856 position based connections are passed.
10858 For example, first take the submodule InstModule.v:
10860 module InstModule (o,i);
10863 wire [31:0] o = {32{i}};
10866 This is then used in an upper level module:
10868 module ExampInst (o,i);
10871 InstModule instName
10875 Typing \\[verilog-auto] will make this into:
10877 module ExampInst (o,i);
10880 InstModule instName
10888 Where the list of inputs and outputs came from the inst module.
10892 Unless you are instantiating a module multiple times, or the module is
10893 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
10894 It just makes for unmaintainable code. To sanitize signal names, try
10895 vrename from URL `http://www.veripool.org'.
10897 When you need to violate this suggestion there are two ways to list
10898 exceptions, placing them before the AUTOINST, or using templates.
10900 Any ports defined before the /*AUTOINST*/ are not included in the list of
10901 automatics. This is similar to making a template as described below, but
10902 is restricted to simple connections just like you normally make. Also note
10903 that any signals before the AUTOINST will only be picked up by AUTOWIRE if
10904 you have the appropriate // Input or // Output comment, and exactly the
10905 same line formatting as AUTOINST itself uses.
10907 InstModule instName
10909 .i (my_i_dont_mess_with_it),
10917 For multiple instantiations based upon a single template, create a
10918 commented out template:
10920 /* InstModule AUTO_TEMPLATE (
10925 Templates go ABOVE the instantiation(s). When an instantiation is
10926 expanded `verilog-mode' simply searches up for the closest template.
10927 Thus you can have multiple templates for the same module, just alternate
10928 between the template for an instantiation and the instantiation itself.
10929 (For backward compatibility if no template is found above, it
10930 will also look below, but do not use this behavior in new designs.)
10932 The module name must be the same as the name of the module in the
10933 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
10934 words and capitalized. Only signals that must be different for each
10935 instantiation need to be listed.
10937 Inside a template, a [] in a connection name (with nothing else inside
10938 the brackets) will be replaced by the same bus subscript as it is being
10939 connected to, or the [] will be removed if it is a single bit signal.
10940 Generally it is a good idea to do this for all connections in a template,
10941 as then they will work for any width signal, and with AUTOWIRE. See
10942 PTL_BUS becoming PTL_BUSNEW below.
10944 If you have a complicated template, set `verilog-auto-inst-template-numbers'
10945 to see which regexps are matching. Don't leave that mode set after
10946 debugging is completed though, it will result in lots of extra differences
10947 and merge conflicts.
10949 Setting `verilog-auto-template-warn-unused' will report errors
10950 if any template lines are unused.
10954 /* InstModule AUTO_TEMPLATE (
10955 .ptl_bus (ptl_busnew[]),
10958 InstModule ms2m (/*AUTOINST*/);
10960 Typing \\[verilog-auto] will make this into:
10962 InstModule ms2m (/*AUTOINST*/
10964 .NotInTemplate (NotInTemplate),
10965 .ptl_bus (ptl_busnew[3:0]), // Templated
10969 Multiple Module Templates:
10971 The same template lines can be applied to multiple modules with
10972 the syntax as follows:
10974 /* InstModuleA AUTO_TEMPLATE
10975 InstModuleB AUTO_TEMPLATE
10976 InstModuleC AUTO_TEMPLATE
10977 InstModuleD AUTO_TEMPLATE (
10978 .ptl_bus (ptl_busnew[]),
10982 Note there is only one AUTO_TEMPLATE opening parenthesis.
10986 It is common to instantiate a cell multiple times, so templates make it
10987 trivial to substitute part of the cell name into the connection name.
10989 /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
10991 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
10995 If no regular expression is provided immediately after the AUTO_TEMPLATE
10996 keyword, then the @ character in any connection names will be replaced
10997 with the instantiation number; the first digits found in the cell's
10998 instantiation name.
11000 If a regular expression is provided, the @ character will be replaced
11001 with the first \(\) grouping that matches against the cell name. Using a
11002 regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no
11003 regexp is provided. If you use multiple layers of parenthesis,
11004 \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number
11005 characters after test and before _, whereas
11006 \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire
11011 /* InstModule AUTO_TEMPLATE (
11012 .ptl_mapvalidx (ptl_mapvalid[@]),
11013 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
11016 InstModule ms2m (/*AUTOINST*/);
11018 Typing \\[verilog-auto] will make this into:
11020 InstModule ms2m (/*AUTOINST*/
11022 .ptl_mapvalidx (ptl_mapvalid[2]),
11023 .ptl_mapvalidp1x (ptl_mapvalid[3]));
11025 Note the @ character was replaced with the 2 from \"ms2m\".
11027 Alternatively, using a regular expression for @:
11029 /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
11030 .ptl_mapvalidx (@_ptl_mapvalid),
11031 .ptl_mapvalidp1x (ptl_mapvalid_@),
11034 InstModule ms2_FOO (/*AUTOINST*/);
11035 InstModule ms2_BAR (/*AUTOINST*/);
11037 Typing \\[verilog-auto] will make this into:
11039 InstModule ms2_FOO (/*AUTOINST*/
11041 .ptl_mapvalidx (FOO_ptl_mapvalid),
11042 .ptl_mapvalidp1x (ptl_mapvalid_FOO));
11043 InstModule ms2_BAR (/*AUTOINST*/
11045 .ptl_mapvalidx (BAR_ptl_mapvalid),
11046 .ptl_mapvalidp1x (ptl_mapvalid_BAR));
11051 A template entry of the form
11053 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
11055 will apply an Emacs style regular expression search for any port beginning
11056 in pci_req followed by numbers and ending in _l and connecting that to
11057 the pci_req_jtag_[] net, with the bus subscript coming from what matches
11058 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
11060 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
11061 does the same thing. (Note a @ in the connection/replacement text is
11062 completely different -- still use \\1 there!) Thus this is the same as
11063 the above template:
11065 .pci_req@_l (pci_req_jtag_[\\1]),
11067 Here's another example to remove the _l, useful when naming conventions
11068 specify _ alone to mean active low. Note the use of [] to keep the bus
11071 .\\(.*\\)_l (\\1_[]),
11075 First any regular expression template is expanded.
11077 If the syntax @\"( ... )\" is found in a connection, the expression in
11078 quotes will be evaluated as a Lisp expression, with @ replaced by the
11079 instantiation number. The MAPVALIDP1X example above would put @+1 modulo
11080 4 into the brackets. Quote all double-quotes inside the expression with
11081 a leading backslash (\\\"...\\\"); or if the Lisp template is also a
11082 regexp template backslash the backslash quote (\\\\\"...\\\\\").
11084 There are special variables defined that are useful in these
11087 vl-name Name portion of the input/output port.
11088 vl-bits Bus bits portion of the input/output port ('[2:0]').
11089 vl-mbits Multidimensional array bits for port ('[2:0][3:0]').
11090 vl-width Width of the input/output port ('3' for [2:0]).
11091 May be a (...) expression if bits isn't a constant.
11092 vl-dir Direction of the pin input/output/inout/interface.
11093 vl-modport The modport, if an interface with a modport.
11094 vl-cell-type Module name/type of the cell ('InstModule').
11095 vl-cell-name Instance name of the cell ('instName').
11097 Normal Lisp variables may be used in expressions. See
11098 `verilog-read-defines' which can set vh-{definename} variables for use
11099 here. Also, any comments of the form:
11101 /*AUTO_LISP(setq foo 1)*/
11103 will evaluate any Lisp expression inside the parenthesis between the
11104 beginning of the buffer and the point of the AUTOINST. This allows
11105 functions to be defined or variables to be changed between instantiations.
11106 (See also `verilog-auto-insert-lisp' if you want the output from your
11107 lisp function to be inserted.)
11109 Note that when using lisp expressions errors may occur when @ is not a
11110 number; you may need to use the standard Emacs Lisp functions
11111 `number-to-string' and `string-to-number'.
11113 After the evaluation is completed, @ substitution and [] substitution
11116 For more information see the \\[verilog-faq] and forums at URL
11117 `http://www.veripool.org'."
11120 (let* ((pt (point))
11121 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
11122 (indent-pt (save-excursion (verilog-backward-open-paren)
11123 (1+ (current-column))))
11124 (verilog-auto-inst-column (max verilog-auto-inst-column
11125 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11126 (modi (verilog-modi-current))
11127 (moddecls (verilog-modi-get-decls modi))
11128 (vector-skip-list (unless verilog-auto-inst-vector
11129 (verilog-decls-get-signals moddecls)))
11130 submod submodi submoddecls
11131 inst skip-pins tpl-list tpl-num did-first par-values)
11133 ;; Find module name that is instantiated
11134 (setq submod (verilog-read-inst-module)
11135 inst (verilog-read-inst-name)
11136 vl-cell-type submod
11138 skip-pins (aref (verilog-read-inst-pins) 0))
11140 ;; Parse any AUTO_LISP() before here
11141 (verilog-read-auto-lisp (point-min) pt)
11143 ;; Read parameters (after AUTO_LISP)
11144 (setq par-values (and verilog-auto-inst-param-value
11145 (verilog-read-inst-param-value)))
11147 ;; Lookup position, etc of submodule
11148 ;; Note this may raise an error
11149 (when (and (not (member submod verilog-gate-keywords))
11150 (setq submodi (verilog-modi-lookup submod t)))
11151 (setq submoddecls (verilog-modi-get-decls submodi))
11152 ;; If there's a number in the instantiation, it may be an argument to the
11153 ;; automatic variable instantiation program.
11154 (let* ((tpl-info (verilog-read-auto-template submod))
11155 (tpl-regexp (aref tpl-info 0)))
11156 (setq tpl-num (if (string-match tpl-regexp inst)
11157 (match-string 1 inst)
11159 tpl-list (aref tpl-info 1)))
11160 ;; Find submodule's signals and dump
11161 (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
11162 (verilog-signals-not-in
11163 (verilog-decls-get-vars submoddecls)
11165 (vl-dir "interfaced"))
11166 (when (and sig-list
11167 verilog-auto-inst-interfaced-ports)
11168 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11169 ;; Note these are searched for in verilog-read-sub-decls.
11170 (verilog-insert-indent "// Interfaced\n")
11171 (verilog-auto-inst-port-list sig-list indent-pt
11172 tpl-list tpl-num for-star par-values)))
11173 (let ((sig-list (verilog-signals-not-in
11174 (verilog-decls-get-interfaces submoddecls)
11176 (vl-dir "interface"))
11178 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11179 ;; Note these are searched for in verilog-read-sub-decls.
11180 (verilog-insert-indent "// Interfaces\n")
11181 (verilog-auto-inst-port-list sig-list indent-pt
11182 tpl-list tpl-num for-star par-values)))
11183 (let ((sig-list (verilog-signals-not-in
11184 (verilog-decls-get-outputs submoddecls)
11188 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11189 (verilog-insert-indent "// Outputs\n")
11190 (verilog-auto-inst-port-list sig-list indent-pt
11191 tpl-list tpl-num for-star par-values)))
11192 (let ((sig-list (verilog-signals-not-in
11193 (verilog-decls-get-inouts submoddecls)
11197 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11198 (verilog-insert-indent "// Inouts\n")
11199 (verilog-auto-inst-port-list sig-list indent-pt
11200 tpl-list tpl-num for-star par-values)))
11201 (let ((sig-list (verilog-signals-not-in
11202 (verilog-decls-get-inputs submoddecls)
11206 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11207 (verilog-insert-indent "// Inputs\n")
11208 (verilog-auto-inst-port-list sig-list indent-pt
11209 tpl-list tpl-num for-star par-values)))
11213 (re-search-backward "," pt t)
11216 (search-forward "\n") ;; Added by inst-port
11218 (if (search-forward ")" nil t) ;; From user, moved up a line
11220 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it
11221 (delete-char -1)))))))))
11223 (defun verilog-auto-inst-param ()
11224 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
11225 Replace the parameter connections to an instantiation with ones
11226 automatically derived from the module header of the instantiated netlist.
11228 See \\[verilog-auto-inst] for limitations, and templates to customize the
11231 For example, first take the submodule InstModule.v:
11233 module InstModule (o,i);
11237 This is then used in an upper level module:
11239 module ExampInst (o,i);
11241 InstModule #(/*AUTOINSTPARAM*/)
11242 instName (/*AUTOINST*/);
11245 Typing \\[verilog-auto] will make this into:
11247 module ExampInst (o,i);
11250 InstModule #(/*AUTOINSTPARAM*/
11253 instName (/*AUTOINST*/);
11256 Where the list of parameter connections come from the inst module.
11260 You can customize the parameter connections using AUTO_TEMPLATEs,
11261 just as you would with \\[verilog-auto-inst]."
11264 (let* ((pt (point))
11265 (indent-pt (save-excursion (verilog-backward-open-paren)
11266 (1+ (current-column))))
11267 (verilog-auto-inst-column (max verilog-auto-inst-column
11268 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11269 (modi (verilog-modi-current))
11270 (moddecls (verilog-modi-get-decls modi))
11271 (vector-skip-list (unless verilog-auto-inst-vector
11272 (verilog-decls-get-signals moddecls)))
11273 submod submodi submoddecls
11274 inst skip-pins tpl-list tpl-num did-first)
11275 ;; Find module name that is instantiated
11276 (setq submod (save-excursion
11277 ;; Get to the point where AUTOINST normally is to read the module
11278 (verilog-re-search-forward-quick "[(;]" nil nil)
11279 (verilog-read-inst-module))
11280 inst (save-excursion
11281 ;; Get to the point where AUTOINST normally is to read the module
11282 (verilog-re-search-forward-quick "[(;]" nil nil)
11283 (verilog-read-inst-name))
11284 vl-cell-type submod
11286 skip-pins (aref (verilog-read-inst-pins) 0))
11288 ;; Parse any AUTO_LISP() before here
11289 (verilog-read-auto-lisp (point-min) pt)
11291 ;; Lookup position, etc of submodule
11292 ;; Note this may raise an error
11293 (when (setq submodi (verilog-modi-lookup submod t))
11294 (setq submoddecls (verilog-modi-get-decls submodi))
11295 ;; If there's a number in the instantiation, it may be an argument to the
11296 ;; automatic variable instantiation program.
11297 (let* ((tpl-info (verilog-read-auto-template submod))
11298 (tpl-regexp (aref tpl-info 0)))
11299 (setq tpl-num (if (string-match tpl-regexp inst)
11300 (match-string 1 inst)
11302 tpl-list (aref tpl-info 1)))
11303 ;; Find submodule's signals and dump
11304 (let ((sig-list (verilog-signals-not-in
11305 (verilog-decls-get-gparams submoddecls)
11307 (vl-dir "parameter"))
11309 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11310 ;; Note these are searched for in verilog-read-sub-decls.
11311 (verilog-insert-indent "// Parameters\n")
11312 (verilog-auto-inst-port-list sig-list indent-pt
11313 tpl-list tpl-num nil nil)))
11317 (re-search-backward "," pt t)
11320 (search-forward "\n") ;; Added by inst-port
11322 (if (search-forward ")" nil t) ;; From user, moved up a line
11323 (delete-char -1)))))))))
11325 (defun verilog-auto-reg ()
11326 "Expand AUTOREG statements, as part of \\[verilog-auto].
11327 Make reg statements for any output that isn't already declared,
11328 and isn't a wire output from a block. `verilog-auto-wire-type'
11329 may be used to change the datatype of the declarations.
11332 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11334 This does NOT work on memories, declare those yourself.
11338 module ExampReg (o,i);
11345 Typing \\[verilog-auto] will make this into:
11347 module ExampReg (o,i);
11351 // Beginning of automatic regs (for this module's undeclared outputs)
11353 // End of automatics
11357 ;; Point must be at insertion point.
11358 (let* ((indent-pt (current-indentation))
11359 (modi (verilog-modi-current))
11360 (moddecls (verilog-modi-get-decls modi))
11361 (modsubdecls (verilog-modi-get-sub-decls modi))
11362 (sig-list (verilog-signals-not-in
11363 (verilog-decls-get-outputs moddecls)
11364 (append (verilog-signals-with ;; ignore typed signals
11366 (verilog-decls-get-outputs moddecls))
11367 (verilog-decls-get-vars moddecls)
11368 (verilog-decls-get-assigns moddecls)
11369 (verilog-decls-get-consts moddecls)
11370 (verilog-decls-get-gparams moddecls)
11371 (verilog-subdecls-get-interfaced modsubdecls)
11372 (verilog-subdecls-get-outputs modsubdecls)
11373 (verilog-subdecls-get-inouts modsubdecls)))))
11375 (verilog-forward-or-insert-line)
11376 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
11377 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
11378 (verilog-insert-indent "// End of automatics\n")))))
11380 (defun verilog-auto-reg-input ()
11381 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
11382 Make reg statements instantiation inputs that aren't already declared.
11383 This is useful for making a top level shell for testing the module that is
11384 to be instantiated.
11387 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
11389 This does NOT work on memories, declare those yourself.
11391 An example (see `verilog-auto-inst' for what else is going on here):
11393 module ExampRegInput (o,i);
11397 InstModule instName
11401 Typing \\[verilog-auto] will make this into:
11403 module ExampRegInput (o,i);
11407 // Beginning of automatic reg inputs (for undeclared ...
11408 reg [31:0] iv; // From inst of inst.v
11409 // End of automatics
11410 InstModule instName
11418 ;; Point must be at insertion point.
11419 (let* ((indent-pt (current-indentation))
11420 (modi (verilog-modi-current))
11421 (moddecls (verilog-modi-get-decls modi))
11422 (modsubdecls (verilog-modi-get-sub-decls modi))
11423 (sig-list (verilog-signals-combine-bus
11424 (verilog-signals-not-in
11425 (append (verilog-subdecls-get-inputs modsubdecls)
11426 (verilog-subdecls-get-inouts modsubdecls))
11427 (append (verilog-decls-get-signals moddecls)
11428 (verilog-decls-get-assigns moddecls))))))
11430 (verilog-forward-or-insert-line)
11431 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
11432 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
11433 (verilog-insert-indent "// End of automatics\n")))))
11435 (defun verilog-auto-logic-setup ()
11436 "Prepare variables due to AUTOLOGIC."
11437 (unless verilog-auto-wire-type
11438 (set (make-local-variable 'verilog-auto-wire-type)
11441 (defun verilog-auto-logic ()
11442 "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
11443 Make wire statements using the SystemVerilog logic keyword.
11444 This is currently equivalent to:
11448 with the below at the bottom of the file
11450 // Local Variables:
11451 // verilog-auto-logic-type:\"logic\"
11454 In the future AUTOLOGIC may declare additional identifiers,
11455 while AUTOWIRE will not."
11457 (verilog-auto-logic-setup)
11458 (verilog-auto-wire)))
11460 (defun verilog-auto-wire ()
11461 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
11462 Make wire statements for instantiations outputs that aren't
11463 already declared. `verilog-auto-wire-type' may be used to change
11464 the datatype of the declarations.
11467 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
11468 and all buses must have widths, such as those from AUTOINST, or using []
11471 This does NOT work on memories or SystemVerilog .name connections,
11472 declare those yourself.
11474 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
11475 determine how to bus together. This occurs when you have ports with
11476 non-numeric or non-sequential bus subscripts. If Verilog mode
11477 mis-guessed, you'll have to declare them yourself.
11479 An example (see `verilog-auto-inst' for what else is going on here):
11481 module ExampWire (o,i);
11485 InstModule instName
11489 Typing \\[verilog-auto] will make this into:
11491 module ExampWire (o,i);
11495 // Beginning of automatic wires
11496 wire [31:0] ov; // From inst of inst.v
11497 // End of automatics
11498 InstModule instName
11507 ;; Point must be at insertion point.
11508 (let* ((indent-pt (current-indentation))
11509 (modi (verilog-modi-current))
11510 (moddecls (verilog-modi-get-decls modi))
11511 (modsubdecls (verilog-modi-get-sub-decls modi))
11512 (sig-list (verilog-signals-combine-bus
11513 (verilog-signals-not-in
11514 (append (verilog-subdecls-get-outputs modsubdecls)
11515 (verilog-subdecls-get-inouts modsubdecls))
11516 (verilog-decls-get-signals moddecls)))))
11518 (verilog-forward-or-insert-line)
11519 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
11520 (verilog-insert-definition modi sig-list "wire" indent-pt nil)
11521 (verilog-insert-indent "// End of automatics\n")
11522 ;; We used to optionally call verilog-pretty-declarations and
11523 ;; verilog-pretty-expr here, but it's too slow on huge modules,
11524 ;; plus makes everyone's module change. Finally those call
11525 ;; syntax-ppss which is broken when change hooks are disabled.
11528 (defun verilog-auto-output ()
11529 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
11530 Make output statements for any output signal from an /*AUTOINST*/ that
11531 isn't an input to another AUTOINST. This is useful for modules which
11532 only instantiate other modules.
11535 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11537 If placed inside the parenthesis of a module declaration, it creates
11538 Verilog 2001 style, else uses Verilog 1995 style.
11540 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11541 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11543 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11545 Signals matching `verilog-auto-output-ignore-regexp' are not included.
11547 An example (see `verilog-auto-inst' for what else is going on here):
11549 module ExampOutput (ov,i);
11552 InstModule instName
11556 Typing \\[verilog-auto] will make this into:
11558 module ExampOutput (ov,i);
11561 // Beginning of automatic outputs (from unused autoinst outputs)
11562 output [31:0] ov; // From inst of inst.v
11563 // End of automatics
11564 InstModule instName
11572 You may also provide an optional regular expression, in which case only
11573 signals matching the regular expression will be included. For example the
11574 same expansion will result from only extracting outputs starting with ov:
11576 /*AUTOOUTPUT(\"^ov\")*/"
11578 ;; Point must be at insertion point.
11579 (let* ((indent-pt (current-indentation))
11580 (params (verilog-read-auto-params 0 1))
11581 (regexp (nth 0 params))
11582 (v2k (verilog-in-paren-quick))
11583 (modi (verilog-modi-current))
11584 (moddecls (verilog-modi-get-decls modi))
11585 (modsubdecls (verilog-modi-get-sub-decls modi))
11586 (sig-list (verilog-signals-not-in
11587 (verilog-subdecls-get-outputs modsubdecls)
11588 (append (verilog-decls-get-outputs moddecls)
11589 (verilog-decls-get-inouts moddecls)
11590 (verilog-subdecls-get-inputs modsubdecls)
11591 (verilog-subdecls-get-inouts modsubdecls)))))
11593 (setq sig-list (verilog-signals-matching-regexp
11595 (setq sig-list (verilog-signals-not-matching-regexp
11596 sig-list verilog-auto-output-ignore-regexp))
11597 (verilog-forward-or-insert-line)
11598 (when v2k (verilog-repair-open-comma))
11600 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
11601 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
11602 (verilog-insert-indent "// End of automatics\n"))
11603 (when v2k (verilog-repair-close-comma)))))
11605 (defun verilog-auto-output-every ()
11606 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
11607 Make output statements for any signals that aren't primary inputs or
11608 outputs already. This makes every signal in the design an output. This is
11609 useful to get Synopsys to preserve every signal in the design, since it
11610 won't optimize away the outputs.
11614 module ExampOutputEvery (o,i,tempa,tempb);
11617 /*AUTOOUTPUTEVERY*/
11619 wire tempb = tempa;
11623 Typing \\[verilog-auto] will make this into:
11625 module ExampOutputEvery (o,i,tempa,tempb);
11628 /*AUTOOUTPUTEVERY*/
11629 // Beginning of automatic outputs (every signal)
11632 // End of automatics
11634 wire tempb = tempa;
11638 ;;Point must be at insertion point
11639 (let* ((indent-pt (current-indentation))
11640 (v2k (verilog-in-paren-quick))
11641 (modi (verilog-modi-current))
11642 (moddecls (verilog-modi-get-decls modi))
11643 (sig-list (verilog-signals-combine-bus
11644 (verilog-signals-not-in
11645 (verilog-decls-get-signals moddecls)
11646 (verilog-decls-get-ports moddecls)))))
11647 (verilog-forward-or-insert-line)
11648 (when v2k (verilog-repair-open-comma))
11650 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
11651 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
11652 (verilog-insert-indent "// End of automatics\n"))
11653 (when v2k (verilog-repair-close-comma)))))
11655 (defun verilog-auto-input ()
11656 "Expand AUTOINPUT statements, as part of \\[verilog-auto].
11657 Make input statements for any input signal into an /*AUTOINST*/ that
11658 isn't declared elsewhere inside the module. This is useful for modules which
11659 only instantiate other modules.
11662 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11664 If placed inside the parenthesis of a module declaration, it creates
11665 Verilog 2001 style, else uses Verilog 1995 style.
11667 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11668 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11670 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11672 Signals matching `verilog-auto-input-ignore-regexp' are not included.
11674 An example (see `verilog-auto-inst' for what else is going on here):
11676 module ExampInput (ov,i);
11679 InstModule instName
11683 Typing \\[verilog-auto] will make this into:
11685 module ExampInput (ov,i);
11688 // Beginning of automatic inputs (from unused autoinst inputs)
11689 input i; // From inst of inst.v
11690 // End of automatics
11691 InstModule instName
11699 You may also provide an optional regular expression, in which case only
11700 signals matching the regular expression will be included. For example the
11701 same expansion will result from only extracting inputs starting with i:
11703 /*AUTOINPUT(\"^i\")*/"
11705 (let* ((indent-pt (current-indentation))
11706 (params (verilog-read-auto-params 0 1))
11707 (regexp (nth 0 params))
11708 (v2k (verilog-in-paren-quick))
11709 (modi (verilog-modi-current))
11710 (moddecls (verilog-modi-get-decls modi))
11711 (modsubdecls (verilog-modi-get-sub-decls modi))
11712 (sig-list (verilog-signals-not-in
11713 (verilog-subdecls-get-inputs modsubdecls)
11714 (append (verilog-decls-get-inputs moddecls)
11715 (verilog-decls-get-inouts moddecls)
11716 (verilog-decls-get-vars moddecls)
11717 (verilog-decls-get-consts moddecls)
11718 (verilog-decls-get-gparams moddecls)
11719 (verilog-subdecls-get-interfaced modsubdecls)
11720 (verilog-subdecls-get-outputs modsubdecls)
11721 (verilog-subdecls-get-inouts modsubdecls)))))
11723 (setq sig-list (verilog-signals-matching-regexp
11725 (setq sig-list (verilog-signals-not-matching-regexp
11726 sig-list verilog-auto-input-ignore-regexp))
11727 (verilog-forward-or-insert-line)
11728 (when v2k (verilog-repair-open-comma))
11730 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
11731 (verilog-insert-definition modi sig-list "input" indent-pt v2k)
11732 (verilog-insert-indent "// End of automatics\n"))
11733 (when v2k (verilog-repair-close-comma)))))
11735 (defun verilog-auto-inout ()
11736 "Expand AUTOINOUT statements, as part of \\[verilog-auto].
11737 Make inout statements for any inout signal in an /*AUTOINST*/ that
11738 isn't declared elsewhere inside the module.
11741 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11743 If placed inside the parenthesis of a module declaration, it creates
11744 Verilog 2001 style, else uses Verilog 1995 style.
11746 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11747 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11749 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11751 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
11753 An example (see `verilog-auto-inst' for what else is going on here):
11755 module ExampInout (ov,i);
11758 InstModule instName
11762 Typing \\[verilog-auto] will make this into:
11764 module ExampInout (ov,i);
11767 // Beginning of automatic inouts (from unused autoinst inouts)
11768 inout [31:0] ov; // From inst of inst.v
11769 // End of automatics
11770 InstModule instName
11778 You may also provide an optional regular expression, in which case only
11779 signals matching the regular expression will be included. For example the
11780 same expansion will result from only extracting inouts starting with i:
11782 /*AUTOINOUT(\"^i\")*/"
11784 ;; Point must be at insertion point.
11785 (let* ((indent-pt (current-indentation))
11786 (params (verilog-read-auto-params 0 1))
11787 (regexp (nth 0 params))
11788 (v2k (verilog-in-paren-quick))
11789 (modi (verilog-modi-current))
11790 (moddecls (verilog-modi-get-decls modi))
11791 (modsubdecls (verilog-modi-get-sub-decls modi))
11792 (sig-list (verilog-signals-not-in
11793 (verilog-subdecls-get-inouts modsubdecls)
11794 (append (verilog-decls-get-outputs moddecls)
11795 (verilog-decls-get-inouts moddecls)
11796 (verilog-decls-get-inputs moddecls)
11797 (verilog-subdecls-get-inputs modsubdecls)
11798 (verilog-subdecls-get-outputs modsubdecls)))))
11800 (setq sig-list (verilog-signals-matching-regexp
11802 (setq sig-list (verilog-signals-not-matching-regexp
11803 sig-list verilog-auto-inout-ignore-regexp))
11804 (verilog-forward-or-insert-line)
11805 (when v2k (verilog-repair-open-comma))
11807 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
11808 (verilog-insert-definition modi sig-list "inout" indent-pt v2k)
11809 (verilog-insert-indent "// End of automatics\n"))
11810 (when v2k (verilog-repair-close-comma)))))
11812 (defun verilog-auto-inout-module (&optional complement all-in)
11813 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
11814 Take input/output/inout statements from the specified module and insert
11815 into the current module. This is useful for making null templates and
11816 shell modules which need to have identical I/O with another module.
11817 Any I/O which are already defined in this module will not be redefined.
11818 For the complement of this function, see `verilog-auto-inout-comp',
11819 and to make monitors with all inputs, see `verilog-auto-inout-in'.
11822 If placed inside the parenthesis of a module declaration, it creates
11823 Verilog 2001 style, else uses Verilog 1995 style.
11825 Concatenation and outputting partial buses is not supported.
11827 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11829 Signals are not inserted in the same order as in the original module,
11830 though they will appear to be in the same order to an AUTOINST
11831 instantiating either module.
11833 Signals declared as \"output reg\" or \"output wire\" etc will
11834 lose the wire/reg declaration so that shell modules may
11835 generate those outputs differently. However, \"output logic\"
11840 module ExampShell (/*AUTOARG*/);
11841 /*AUTOINOUTMODULE(\"ExampMain\")*/
11844 module ExampMain (i,o,io);
11850 Typing \\[verilog-auto] will make this into:
11852 module ExampShell (/*AUTOARG*/i,o,io);
11853 /*AUTOINOUTMODULE(\"ExampMain\")*/
11854 // Beginning of automatic in/out/inouts (from specific module)
11858 // End of automatics
11861 You may also provide an optional regular expression, in which case only
11862 signals matching the regular expression will be included. For example the
11863 same expansion will result from only extracting signals starting with i:
11865 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
11867 You may also provide an optional second regular expression, in
11868 which case only signals which have that pin direction and data
11869 type will be included. This matches against everything before
11870 the signal name in the declaration, for example against
11871 \"input\" (single bit), \"output logic\" (direction and type) or
11872 \"output [1:0]\" (direction and implicit type). You also
11873 probably want to skip spaces in your regexp.
11875 For example, the below will result in matching the output \"o\"
11876 against the previous example's module:
11878 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/"
11880 (let* ((params (verilog-read-auto-params 1 3))
11881 (submod (nth 0 params))
11882 (regexp (nth 1 params))
11883 (direction-re (nth 2 params))
11885 ;; Lookup position, etc of co-module
11886 ;; Note this may raise an error
11887 (when (setq submodi (verilog-modi-lookup submod t))
11888 (let* ((indent-pt (current-indentation))
11889 (v2k (verilog-in-paren-quick))
11890 (modi (verilog-modi-current))
11891 (moddecls (verilog-modi-get-decls modi))
11892 (submoddecls (verilog-modi-get-decls submodi))
11893 (sig-list-i (verilog-signals-not-in
11896 (verilog-decls-get-inputs submoddecls)
11897 (verilog-decls-get-inouts submoddecls)
11898 (verilog-decls-get-outputs submoddecls)))
11900 (verilog-decls-get-outputs submoddecls))
11901 (t (verilog-decls-get-inputs submoddecls)))
11902 (append (verilog-decls-get-inputs moddecls))))
11903 (sig-list-o (verilog-signals-not-in
11906 (verilog-decls-get-inputs submoddecls))
11907 (t (verilog-decls-get-outputs submoddecls)))
11908 (append (verilog-decls-get-outputs moddecls))))
11909 (sig-list-io (verilog-signals-not-in
11911 (t (verilog-decls-get-inouts submoddecls)))
11912 (append (verilog-decls-get-inouts moddecls))))
11913 (sig-list-if (verilog-signals-not-in
11914 (verilog-decls-get-interfaces submoddecls)
11915 (append (verilog-decls-get-interfaces moddecls)))))
11917 (setq sig-list-i (verilog-signals-edit-wire-reg
11918 (verilog-signals-matching-dir-re
11919 (verilog-signals-matching-regexp sig-list-i regexp)
11920 "input" direction-re))
11921 sig-list-o (verilog-signals-edit-wire-reg
11922 (verilog-signals-matching-dir-re
11923 (verilog-signals-matching-regexp sig-list-o regexp)
11924 "output" direction-re))
11925 sig-list-io (verilog-signals-edit-wire-reg
11926 (verilog-signals-matching-dir-re
11927 (verilog-signals-matching-regexp sig-list-io regexp)
11928 "inout" direction-re))
11929 sig-list-if (verilog-signals-matching-dir-re
11930 (verilog-signals-matching-regexp sig-list-if regexp)
11931 "interface" direction-re))
11932 (when v2k (verilog-repair-open-comma))
11933 (when (or sig-list-i sig-list-o sig-list-io)
11934 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
11935 ;; Don't sort them so an upper AUTOINST will match the main module
11936 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
11937 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
11938 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
11939 (verilog-insert-definition modi sig-list-if "interface" indent-pt v2k t)
11940 (verilog-insert-indent "// End of automatics\n"))
11941 (when v2k (verilog-repair-close-comma)))))))
11943 (defun verilog-auto-inout-comp ()
11944 "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
11945 Take input/output/inout statements from the specified module and
11946 insert the inverse into the current module (inputs become outputs
11947 and vice-versa.) This is useful for making test and stimulus
11948 modules which need to have complementing I/O with another module.
11949 Any I/O which are already defined in this module will not be
11950 redefined. For the complement of this function, see
11951 `verilog-auto-inout-module'.
11954 If placed inside the parenthesis of a module declaration, it creates
11955 Verilog 2001 style, else uses Verilog 1995 style.
11957 Concatenation and outputting partial buses is not supported.
11959 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11961 Signals are not inserted in the same order as in the original module,
11962 though they will appear to be in the same order to an AUTOINST
11963 instantiating either module.
11967 module ExampShell (/*AUTOARG*/);
11968 /*AUTOINOUTCOMP(\"ExampMain\")*/
11971 module ExampMain (i,o,io);
11977 Typing \\[verilog-auto] will make this into:
11979 module ExampShell (/*AUTOARG*/i,o,io);
11980 /*AUTOINOUTCOMP(\"ExampMain\")*/
11981 // Beginning of automatic in/out/inouts (from specific module)
11985 // End of automatics
11988 You may also provide an optional regular expression, in which case only
11989 signals matching the regular expression will be included. For example the
11990 same expansion will result from only extracting signals starting with i:
11992 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
11993 (verilog-auto-inout-module t nil))
11995 (defun verilog-auto-inout-in ()
11996 "Expand AUTOINOUTIN statements, as part of \\[verilog-auto].
11997 Take input/output/inout statements from the specified module and
11998 insert them as all inputs into the current module. This is
11999 useful for making monitor modules which need to see all signals
12000 as inputs based on another module. Any I/O which are already
12001 defined in this module will not be redefined. See also
12002 `verilog-auto-inout-module'.
12005 If placed inside the parenthesis of a module declaration, it creates
12006 Verilog 2001 style, else uses Verilog 1995 style.
12008 Concatenation and outputting partial buses is not supported.
12010 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12012 Signals are not inserted in the same order as in the original module,
12013 though they will appear to be in the same order to an AUTOINST
12014 instantiating either module.
12018 module ExampShell (/*AUTOARG*/);
12019 /*AUTOINOUTIN(\"ExampMain\")*/
12022 module ExampMain (i,o,io);
12028 Typing \\[verilog-auto] will make this into:
12030 module ExampShell (/*AUTOARG*/i,o,io);
12031 /*AUTOINOUTIN(\"ExampMain\")*/
12032 // Beginning of automatic in/out/inouts (from specific module)
12036 // End of automatics
12039 You may also provide an optional regular expression, in which case only
12040 signals matching the regular expression will be included. For example the
12041 same expansion will result from only extracting signals starting with i:
12043 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
12044 (verilog-auto-inout-module nil t))
12046 (defun verilog-auto-inout-param ()
12047 "Expand AUTOINOUTPARAM statements, as part of \\[verilog-auto].
12048 Take input/output/inout statements from the specified module and insert
12049 into the current module. This is useful for making null templates and
12050 shell modules which need to have identical I/O with another module.
12051 Any I/O which are already defined in this module will not be redefined.
12052 For the complement of this function, see `verilog-auto-inout-comp',
12053 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12056 If placed inside the parenthesis of a module declaration, it creates
12057 Verilog 2001 style, else uses Verilog 1995 style.
12059 Concatenation and outputting partial buses is not supported.
12061 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12063 Signals are not inserted in the same order as in the original module,
12064 though they will appear to be in the same order to an AUTOINST
12065 instantiating either module.
12067 Signals declared as \"output reg\" or \"output wire\" etc will
12068 lose the wire/reg declaration so that shell modules may
12069 generate those outputs differently. However, \"output logic\"
12074 module ExampShell (/*AUTOARG*/);
12075 /*AUTOINOUTMODULE(\"ExampMain\")*/
12078 module ExampMain (i,o,io);
12084 Typing \\[verilog-auto] will make this into:
12086 module ExampShell (/*AUTOARG*/i,o,io);
12087 /*AUTOINOUTMODULE(\"ExampMain\")*/
12088 // Beginning of automatic in/out/inouts (from specific module)
12092 // End of automatics
12095 You may also provide an optional regular expression, in which case only
12096 signals matching the regular expression will be included. For example the
12097 same expansion will result from only extracting signals starting with i:
12099 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
12101 You may also provide an optional second regular expression, in
12102 which case only signals which have that pin direction and data
12103 type will be included. This matches against everything before
12104 the signal name in the declaration, for example against
12105 \"input\" (single bit), \"output logic\" (direction and type) or
12106 \"output [1:0]\" (direction and implicit type). You also
12107 probably want to skip spaces in your regexp.
12109 For example, the below will result in matching the output \"o\"
12110 against the previous example's module:
12112 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/
12114 You may also provide an optional third regular expression, in
12115 which case any parameter names that match the given regexp will
12116 be included. Including parameters is off by default. To include
12117 all signals and parameters, use:
12119 /*AUTOINOUTMODULE(\"ExampMain\",\".*\",\".*\",\".*\")*/"
12121 (let* ((params (verilog-read-auto-params 1 2))
12122 (submod (nth 0 params))
12123 (regexp (nth 1 params))
12125 ;; Lookup position, etc of co-module
12126 ;; Note this may raise an error
12127 (when (setq submodi (verilog-modi-lookup submod t))
12128 (let* ((indent-pt (current-indentation))
12129 (v2k (verilog-in-paren-quick))
12130 (modi (verilog-modi-current))
12131 (moddecls (verilog-modi-get-decls modi))
12132 (submoddecls (verilog-modi-get-decls submodi))
12133 (sig-list-p (verilog-signals-not-in
12134 (verilog-decls-get-gparams submoddecls)
12135 (append (verilog-decls-get-gparams moddecls)))))
12137 (setq sig-list-p (verilog-signals-matching-regexp sig-list-p regexp))
12138 (when v2k (verilog-repair-open-comma))
12140 (verilog-insert-indent "// Beginning of automatic parameters (from specific module)\n")
12141 ;; Don't sort them so an upper AUTOINST will match the main module
12142 (verilog-insert-definition modi sig-list-p "parameter" indent-pt v2k t)
12143 (verilog-insert-indent "// End of automatics\n"))
12144 (when v2k (verilog-repair-close-comma)))))))
12146 (defun verilog-auto-inout-modport ()
12147 "Expand AUTOINOUTMODPORT statements, as part of \\[verilog-auto].
12148 Take input/output/inout statements from the specified interface
12149 and modport and insert into the current module. This is useful
12150 for making verification modules that connect to UVM interfaces.
12152 The first parameter is the name of an interface.
12154 The second parameter is a regexp of modports to read from in
12157 The optional third parameter is a regular expression, and only
12158 signals matching the regular expression will be included.
12161 If placed inside the parenthesis of a module declaration, it creates
12162 Verilog 2001 style, else uses Verilog 1995 style.
12164 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
12166 As with other autos, any inputs/outputs declared in the module
12167 will suppress the AUTO from redeclaring an input/output by
12173 ( input logic clk );
12175 logic [7:0] req_dat;
12176 clocking mon_clkblk @(posedge clk);
12180 modport mp(clocking mon_clkblk);
12185 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12186 // Beginning of automatic in/out/inouts (from modport)
12187 input [7:0] req_dat,
12189 // End of automatics
12191 /*AUTOASSIGNMODPORT(\"ExampIf\" \"mp\")*/
12194 Typing \\[verilog-auto] will make this into:
12199 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12200 // Beginning of automatic in/out/inouts (from modport)
12203 // End of automatics
12206 If the modport is part of a UVM monitor/driver class, this
12207 creates a wrapper module that may be used to instantiate the
12208 driver/monitor using AUTOINST in the testbench."
12210 (let* ((params (verilog-read-auto-params 2 3))
12211 (submod (nth 0 params))
12212 (modport-re (nth 1 params))
12213 (regexp (nth 2 params))
12214 direction-re submodi) ;; direction argument not supported until requested
12215 ;; Lookup position, etc of co-module
12216 ;; Note this may raise an error
12217 (when (setq submodi (verilog-modi-lookup submod t))
12218 (let* ((indent-pt (current-indentation))
12219 (v2k (verilog-in-paren-quick))
12220 (modi (verilog-modi-current))
12221 (moddecls (verilog-modi-get-decls modi))
12222 (submoddecls (verilog-modi-get-decls submodi))
12223 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
12224 (sig-list-i (verilog-signals-in ;; Decls doesn't have data types, must resolve
12225 (verilog-decls-get-vars submoddecls)
12226 (verilog-signals-not-in
12227 (verilog-decls-get-inputs submodportdecls)
12228 (append (verilog-decls-get-ports submoddecls)
12229 (verilog-decls-get-ports moddecls)))))
12230 (sig-list-o (verilog-signals-in ;; Decls doesn't have data types, must resolve
12231 (verilog-decls-get-vars submoddecls)
12232 (verilog-signals-not-in
12233 (verilog-decls-get-outputs submodportdecls)
12234 (append (verilog-decls-get-ports submoddecls)
12235 (verilog-decls-get-ports moddecls)))))
12236 (sig-list-io (verilog-signals-in ;; Decls doesn't have data types, must resolve
12237 (verilog-decls-get-vars submoddecls)
12238 (verilog-signals-not-in
12239 (verilog-decls-get-inouts submodportdecls)
12240 (append (verilog-decls-get-ports submoddecls)
12241 (verilog-decls-get-ports moddecls))))))
12243 (setq sig-list-i (verilog-signals-edit-wire-reg
12244 (verilog-signals-matching-dir-re
12245 (verilog-signals-matching-regexp sig-list-i regexp)
12246 "input" direction-re))
12247 sig-list-o (verilog-signals-edit-wire-reg
12248 (verilog-signals-matching-dir-re
12249 (verilog-signals-matching-regexp sig-list-o regexp)
12250 "output" direction-re))
12251 sig-list-io (verilog-signals-edit-wire-reg
12252 (verilog-signals-matching-dir-re
12253 (verilog-signals-matching-regexp sig-list-io regexp)
12254 "inout" direction-re)))
12255 (when v2k (verilog-repair-open-comma))
12256 (when (or sig-list-i sig-list-o sig-list-io)
12257 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from modport)\n")
12258 ;; Don't sort them so an upper AUTOINST will match the main module
12259 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12260 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12261 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12262 (verilog-insert-indent "// End of automatics\n"))
12263 (when v2k (verilog-repair-close-comma)))))))
12265 (defun verilog-auto-insert-lisp ()
12266 "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
12267 The Lisp code provided is called, and the Lisp code calls
12268 `insert` to insert text into the current file beginning on the
12269 line after the AUTOINSERTLISP.
12271 See also AUTO_LISP, which takes a Lisp expression and evaluates
12272 it during `verilog-auto-inst' but does not insert any text.
12276 module ExampInsertLisp;
12277 /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
12280 // For this example we declare the function in the
12281 // module's file itself. Often you'd define it instead
12282 // in a site-start.el or init file.
12286 (defun my-verilog-insert-hello (who)
12287 (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
12291 Typing \\[verilog-auto] will call my-verilog-insert-hello and
12292 expand the above into:
12294 // Beginning of automatic insert lisp
12295 initial $write(\"hello world\");
12296 // End of automatics
12298 You can also call an external program and insert the returned
12301 /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
12302 // Beginning of automatic insert lisp
12304 // End of automatics"
12306 ;; Point is at end of /*AUTO...*/
12307 (let* ((indent-pt (current-indentation))
12308 (cmd-end-pt (save-excursion (search-backward ")")
12310 (point))) ;; Closing paren
12311 (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
12312 (backward-sexp 1) ;; Inside comment
12313 (point))) ;; Beginning paren
12314 (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
12315 (verilog-forward-or-insert-line)
12316 ;; Some commands don't move point (like insert-file) so we always
12317 ;; add the begin/end comments, then delete it if not needed
12318 (verilog-insert-indent "// Beginning of automatic insert lisp\n")
12319 (verilog-insert-indent "// End of automatics\n")
12323 (setq verilog-scan-cache-tick nil) ;; Clear cache; inserted unknown text
12324 (verilog-delete-empty-auto-pair))))
12326 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
12327 "Return list of signals for current AUTOSENSE block."
12328 (let* ((sigss (verilog-read-always-signals))
12329 (sig-list (verilog-signals-not-params
12330 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
12331 (append (and (not verilog-auto-sense-include-inputs)
12332 (verilog-alw-get-outputs-delayed sigss))
12333 (and (not verilog-auto-sense-include-inputs)
12334 (verilog-alw-get-outputs-immediate sigss))
12335 (verilog-alw-get-temps sigss)
12336 (verilog-decls-get-consts moddecls)
12337 (verilog-decls-get-gparams moddecls)
12341 (defun verilog-auto-sense ()
12342 "Expand AUTOSENSE statements, as part of \\[verilog-auto].
12343 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
12344 with one automatically derived from all inputs declared in the always
12345 statement. Signals that are generated within the same always block are NOT
12346 placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
12347 Long lines are split based on the `fill-column', see \\[set-fill-column].
12350 Verilog does not allow memories (multidimensional arrays) in sensitivity
12351 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
12354 AUTOSENSE cannot always determine if a `define is a constant or a signal
12355 (it could be in an include file for example). If a `define or other signal
12356 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
12357 declaration anywhere in the module (parenthesis are required):
12359 /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */
12361 Better yet, use a parameter, which will be understood to be constant
12365 If AUTOSENSE makes a mistake, please report it. (First try putting
12366 a begin/end after your always!) As a workaround, if a signal that
12367 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
12368 If a signal should be in the sensitivity list wasn't, placing it before
12369 the /*AUTOSENSE*/ comment will prevent it from being deleted when the
12370 autos are updated (or added if it occurs there already).
12374 always @ (/*AS*/) begin
12375 /* AUTO_CONSTANT (`constant) */
12376 outin = ina | inb | `constant;
12380 Typing \\[verilog-auto] will make this into:
12382 always @ (/*AS*/ina or inb) begin
12383 /* AUTO_CONSTANT (`constant) */
12384 outin = ina | inb | `constant;
12388 Note in Verilog 2001, you can often get the same result from the new @*
12389 operator. (This was added to the language in part due to AUTOSENSE!)
12392 outin = ina | inb | `constant;
12397 (let* ((start-pt (save-excursion
12398 (verilog-re-search-backward-quick "(" nil t)
12400 (indent-pt (save-excursion
12401 (or (and (goto-char start-pt) (1+ (current-column)))
12402 (current-indentation))))
12403 (modi (verilog-modi-current))
12404 (moddecls (verilog-modi-get-decls modi))
12405 (sig-memories (verilog-signals-memory
12406 (verilog-decls-get-vars moddecls)))
12407 sig-list not-first presense-sigs)
12408 ;; Read signals in always, eliminate outputs from sense list
12409 (setq presense-sigs (verilog-signals-from-signame
12411 (verilog-read-signals start-pt (point)))))
12412 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
12414 (let ((tlen (length sig-list)))
12415 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
12416 (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
12417 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/"
12418 (save-excursion (goto-char (point))
12419 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
12420 (verilog-re-search-backward-quick "\\s-" start-pt t)
12421 (while (looking-at "\\s-`endif")
12422 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
12423 (verilog-re-search-backward-quick "\\s-" start-pt t))
12424 (not (looking-at "\\s-or\\b"))))
12425 (setq not-first t))
12426 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
12428 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
12430 (indent-to indent-pt)
12431 (if not-first (insert "or ")))
12432 (not-first (insert " or ")))
12433 (insert (verilog-sig-name (car sig-list)))
12434 (setq sig-list (cdr sig-list)
12437 (defun verilog-auto-reset ()
12438 "Expand AUTORESET statements, as part of \\[verilog-auto].
12439 Replace the /*AUTORESET*/ comment with code to initialize all
12440 registers set elsewhere in the always block.
12443 AUTORESET will not clear memories.
12445 AUTORESET uses <= if the signal has a <= assignment in the block,
12448 If <= is used, all = assigned variables are ignored if
12449 `verilog-auto-reset-blocking-in-non' is nil; they are presumed
12452 /*AUTORESET*/ presumes that any signals mentioned between the previous
12453 begin/case/if statement and the AUTORESET comment are being reset manually
12454 and should not be automatically reset. This includes omitting any signals
12455 used on the right hand side of assignments.
12457 By default, AUTORESET will include the width of the signal in the
12458 autos, SystemVerilog designs may want to change this. To control
12459 this behavior, see `verilog-auto-reset-widths'.
12461 AUTORESET ties signals to deasserted, which is presumed to be zero.
12462 Signals that match `verilog-active-low-regexp' will be deasserted by tying
12467 always @(posedge clk or negedge reset_l) begin
12468 if (!reset_l) begin
12479 Typing \\[verilog-auto] will make this into:
12481 always @(posedge core_clk or negedge reset_l) begin
12482 if (!reset_l) begin
12485 // Beginning of autoreset for uninitialized flops
12487 b = 0; // if `verilog-auto-reset-blocking-in-non' true
12488 // End of automatics
12500 (let* ((indent-pt (current-indentation))
12501 (modi (verilog-modi-current))
12502 (moddecls (verilog-modi-get-decls modi))
12503 (all-list (verilog-decls-get-signals moddecls))
12504 sigss sig-list dly-list prereset-sigs)
12505 ;; Read signals in always, eliminate outputs from reset list
12506 (setq prereset-sigs (verilog-signals-from-signame
12508 (verilog-read-signals
12510 (verilog-re-search-backward-quick "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t)
12514 (verilog-re-search-backward-quick "@" nil t)
12515 (setq sigss (verilog-read-always-signals)))
12516 (setq dly-list (verilog-alw-get-outputs-delayed sigss))
12517 (setq sig-list (verilog-signals-not-in (append
12518 (verilog-alw-get-outputs-delayed sigss)
12519 (when (or (not (verilog-alw-get-uses-delayed sigss))
12520 verilog-auto-reset-blocking-in-non)
12521 (verilog-alw-get-outputs-immediate sigss)))
12523 (verilog-alw-get-temps sigss)
12525 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
12528 (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
12530 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths
12532 (indent-to indent-pt)
12533 (insert (verilog-sig-name sig)
12534 (if (assoc (verilog-sig-name sig) dly-list)
12535 (concat " <= " verilog-assignment-delay)
12537 (verilog-sig-tieoff sig)
12539 (setq sig-list (cdr sig-list))))
12540 (verilog-insert-indent "// End of automatics")))))
12542 (defun verilog-auto-tieoff ()
12543 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
12544 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
12545 signals to deasserted.
12547 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
12548 input/output list as another module, but no internals. Specifically, it
12549 finds all outputs in the module, and if that input is not otherwise declared
12550 as a register or wire, creates a tieoff.
12552 AUTORESET ties signals to deasserted, which is presumed to be zero.
12553 Signals that match `verilog-active-low-regexp' will be deasserted by tying
12556 You can add signals you do not want included in AUTOTIEOFF with
12557 `verilog-auto-tieoff-ignore-regexp'.
12559 `verilog-auto-wire-type' may be used to change the datatype of
12562 `verilog-auto-reset-widths' may be used to change how the tieoff
12563 value's width is generated.
12565 An example of making a stub for another module:
12567 module ExampStub (/*AUTOINST*/);
12568 /*AUTOINOUTPARAM(\"Foo\")*/
12569 /*AUTOINOUTMODULE(\"Foo\")*/
12571 // verilator lint_off UNUSED
12572 wire _unused_ok = &{1'b0,
12575 // verilator lint_on UNUSED
12578 Typing \\[verilog-auto] will make this into:
12580 module ExampStub (/*AUTOINST*/...);
12581 /*AUTOINOUTPARAM(\"Foo\")*/
12582 /*AUTOINOUTMODULE(\"Foo\")*/
12583 // Beginning of autotieoff
12585 // End of automatics
12588 // Beginning of autotieoff
12589 wire [2:0] foo = 3'b0;
12590 // End of automatics
12596 (let* ((indent-pt (current-indentation))
12597 (modi (verilog-modi-current))
12598 (moddecls (verilog-modi-get-decls modi))
12599 (modsubdecls (verilog-modi-get-sub-decls modi))
12600 (sig-list (verilog-signals-not-in
12601 (verilog-decls-get-outputs moddecls)
12602 (append (verilog-decls-get-vars moddecls)
12603 (verilog-decls-get-assigns moddecls)
12604 (verilog-decls-get-consts moddecls)
12605 (verilog-decls-get-gparams moddecls)
12606 (verilog-subdecls-get-interfaced modsubdecls)
12607 (verilog-subdecls-get-outputs modsubdecls)
12608 (verilog-subdecls-get-inouts modsubdecls)))))
12609 (setq sig-list (verilog-signals-not-matching-regexp
12610 sig-list verilog-auto-tieoff-ignore-regexp))
12612 (verilog-forward-or-insert-line)
12613 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
12614 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
12615 (verilog-modi-cache-add-vars modi sig-list) ; Before we trash list
12617 (let ((sig (car sig-list)))
12618 (cond ((equal verilog-auto-tieoff-declaration "assign")
12619 (indent-to indent-pt)
12620 (insert "assign " (verilog-sig-name sig)))
12622 (verilog-insert-one-definition sig verilog-auto-tieoff-declaration indent-pt)))
12623 (indent-to (max 48 (+ indent-pt 40)))
12624 (insert "= " (verilog-sig-tieoff sig)
12626 (setq sig-list (cdr sig-list))))
12627 (verilog-insert-indent "// End of automatics\n")))))
12629 (defun verilog-auto-undef ()
12630 "Expand AUTOUNDEF statements, as part of \\[verilog-auto].
12631 Take any `defines since the last AUTOUNDEF in the current file
12632 and create `undefs for them. This is used to insure that
12633 file-local defines do not pollute the global `define name space.
12636 AUTOUNDEF presumes any identifier following `define is the
12637 name of a define. Any `ifdefs are ignored.
12639 AUTOUNDEF suppresses creating an `undef for any define that was
12640 `undefed before the AUTOUNDEF. This may be used to work around
12641 the ignoring of `ifdefs as shown below.
12650 `undef M_BAZ // Emacs will see this and not `undef M_BAZ
12655 Typing \\[verilog-auto] will make this into:
12659 // Beginning of automatic undefs
12662 // End of automatics
12664 You may also provide an optional regular expression, in which case only
12665 defines the regular expression will be undefed."
12667 (let* ((params (verilog-read-auto-params 0 1))
12668 (regexp (nth 0 params))
12669 (indent-pt (current-indentation))
12673 ;; Scan from start of file, or last AUTOUNDEF
12674 (or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
12675 (goto-char (point-min)))
12676 (while (verilog-re-search-forward-quick
12677 "`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
12678 (cond ((equal (match-string-no-properties 1) "define")
12679 (setq def (match-string-no-properties 2))
12680 (when (and (or (not regexp)
12681 (string-match regexp def))
12682 (not (member def defs))) ;; delete-dups not in 21.1
12683 (setq defs (cons def defs))))
12685 (setq defs (delete (match-string-no-properties 2) defs))))))
12687 (setq defs (sort defs 'string<))
12689 (verilog-forward-or-insert-line)
12690 (verilog-insert-indent "// Beginning of automatic undefs\n")
12692 (verilog-insert-indent "`undef " (car defs) "\n")
12693 (setq defs (cdr defs)))
12694 (verilog-insert-indent "// End of automatics\n")))))
12696 (defun verilog-auto-unused ()
12697 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
12698 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
12699 input and inout signals.
12701 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
12702 input/output list as another module, but no internals. Specifically, it
12703 finds all inputs and inouts in the module, and if that input is not otherwise
12704 used, adds it to a comma separated list.
12706 The comma separated list is intended to be used to create a _unused_ok
12707 signal. Using the exact name \"_unused_ok\" for name of the temporary
12708 signal is recommended as it will insure maximum forward compatibility, it
12709 also makes lint warnings easy to understand; ignore any unused warnings
12710 with \"unused\" in the signal name.
12712 To reduce simulation time, the _unused_ok signal should be forced to a
12713 constant to prevent wiggling. The easiest thing to do is use a
12714 reduction-and with 1'b0 as shown.
12716 This way all unused signals are in one place, making it convenient to add
12717 your tool's specific pragmas around the assignment to disable any unused
12720 You can add signals you do not want included in AUTOUNUSED with
12721 `verilog-auto-unused-ignore-regexp'.
12723 An example of making a stub for another module:
12725 module ExampStub (/*AUTOINST*/);
12726 /*AUTOINOUTPARAM(\"Examp\")*/
12727 /*AUTOINOUTMODULE(\"Examp\")*/
12729 // verilator lint_off UNUSED
12730 wire _unused_ok = &{1'b0,
12733 // verilator lint_on UNUSED
12736 Typing \\[verilog-auto] will make this into:
12739 // verilator lint_off UNUSED
12740 wire _unused_ok = &{1'b0,
12742 // Beginning of automatics
12746 // End of automatics
12748 // verilator lint_on UNUSED
12753 (let* ((indent-pt (progn (search-backward "/*") (current-column)))
12754 (modi (verilog-modi-current))
12755 (moddecls (verilog-modi-get-decls modi))
12756 (modsubdecls (verilog-modi-get-sub-decls modi))
12757 (sig-list (verilog-signals-not-in
12758 (append (verilog-decls-get-inputs moddecls)
12759 (verilog-decls-get-inouts moddecls))
12760 (append (verilog-subdecls-get-inputs modsubdecls)
12761 (verilog-subdecls-get-inouts modsubdecls)))))
12762 (setq sig-list (verilog-signals-not-matching-regexp
12763 sig-list verilog-auto-unused-ignore-regexp))
12765 (verilog-forward-or-insert-line)
12766 (verilog-insert-indent "// Beginning of automatic unused inputs\n")
12767 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
12769 (let ((sig (car sig-list)))
12770 (indent-to indent-pt)
12771 (insert (verilog-sig-name sig) ",\n")
12772 (setq sig-list (cdr sig-list))))
12773 (verilog-insert-indent "// End of automatics\n")))))
12775 (defun verilog-enum-ascii (signm elim-regexp)
12776 "Convert an enum name SIGNM to an ascii string for insertion.
12777 Remove user provided prefix ELIM-REGEXP."
12778 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
12779 (let ((case-fold-search t))
12780 ;; All upper becomes all lower for readability
12781 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
12783 (defun verilog-auto-ascii-enum ()
12784 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
12785 Create a register to contain the ASCII decode of an enumerated signal type.
12786 This will allow trace viewers to show the ASCII name of states.
12788 First, parameters are built into an enumeration using the synopsys enum
12789 comment. The comment must be between the keyword and the symbol.
12790 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
12792 Next, registers which that enum applies to are also tagged with the same
12795 Finally, an AUTOASCIIENUM command is used.
12797 The first parameter is the name of the signal to be decoded.
12799 The second parameter is the name to store the ASCII code into. For the
12800 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
12801 a signal that is just for simulation, and the magic characters _ascii
12802 tell viewers like Dinotrace to display in ASCII format.
12804 The third optional parameter is a string which will be removed
12805 from the state names. It defaults to \"\" which removes nothing.
12807 The fourth optional parameter is \"onehot\" to force one-hot
12808 decoding. If unspecified, if and only if the first parameter
12809 width is 2^(number of states in enum) and does NOT match the
12810 width of the enum, the signal is assumed to be a one-hot
12811 decode. Otherwise, it's a normal encoded state vector.
12813 `verilog-auto-wire-type' may be used to change the datatype of
12816 \"auto enum\" may be used in place of \"synopsys enum\".
12820 //== State enumeration
12821 parameter [2:0] // synopsys enum state_info
12825 //== State variables
12826 reg [2:0] /* synopsys enum state_info */
12827 state_r; /* synopsys state_vector state_r */
12828 reg [2:0] /* synopsys enum state_info */
12831 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
12833 Typing \\[verilog-auto] will make this into:
12835 ... same front matter ...
12837 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
12838 // Beginning of automatic ASCII enum decoding
12839 reg [39:0] state_ascii_r; // Decode of state_r
12840 always @(state_r) begin
12842 SM_IDLE: state_ascii_r = \"idle \";
12843 SM_SEND: state_ascii_r = \"send \";
12844 SM_WAIT1: state_ascii_r = \"wait1\";
12845 default: state_ascii_r = \"%Erro\";
12848 // End of automatics"
12850 (let* ((params (verilog-read-auto-params 2 4))
12851 (undecode-name (nth 0 params))
12852 (ascii-name (nth 1 params))
12853 (elim-regexp (and (nth 2 params)
12854 (not (equal (nth 2 params) ""))
12856 (one-hot-flag (nth 3 params))
12858 (indent-pt (current-indentation))
12859 (modi (verilog-modi-current))
12860 (moddecls (verilog-modi-get-decls modi))
12862 (sig-list-consts (append (verilog-decls-get-consts moddecls)
12863 (verilog-decls-get-gparams moddecls)))
12864 (sig-list-all (verilog-decls-get-iovars moddecls))
12866 (undecode-sig (or (assoc undecode-name sig-list-all)
12867 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
12868 (undecode-enum (or (verilog-sig-enum undecode-sig)
12869 (error "%s: Signal %s does not have an enum tag" (verilog-point-text) undecode-name)))
12871 (enum-sigs (verilog-signals-not-in
12872 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
12873 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))
12877 (string-match "onehot" (or one-hot-flag ""))
12878 (and ;; width(enum) != width(sig)
12879 (or (not (verilog-sig-bits (car enum-sigs)))
12880 (not (equal (verilog-sig-width (car enum-sigs))
12881 (verilog-sig-width undecode-sig))))
12882 ;; count(enums) == width(sig)
12883 (equal (number-to-string (length enum-sigs))
12884 (verilog-sig-width undecode-sig)))))
12888 ;; Find number of ascii chars needed
12889 (let ((tmp-sigs enum-sigs))
12891 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
12892 ascii-chars (max ascii-chars (length (verilog-enum-ascii
12893 (verilog-sig-name (car tmp-sigs))
12895 tmp-sigs (cdr tmp-sigs))))
12897 (verilog-forward-or-insert-line)
12898 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
12899 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
12900 (concat "Decode of " undecode-name) nil nil))))
12901 (verilog-insert-definition modi decode-sig-list "reg" indent-pt nil))
12903 (verilog-insert-indent "always @(" undecode-name ") begin\n")
12904 (setq indent-pt (+ indent-pt verilog-indent-level))
12905 (verilog-insert-indent "case ({" undecode-name "})\n")
12906 (setq indent-pt (+ indent-pt verilog-case-indent))
12908 (let ((tmp-sigs enum-sigs)
12909 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
12910 (+ (if one-hot 9 1) (max 8 enum-chars))
12911 ascii-name ascii-chars))
12912 (errname (substring "%Error" 0 (min 6 ascii-chars))))
12914 (verilog-insert-indent
12917 (concat (if one-hot "(")
12918 ;; Use enum-sigs length as that's numeric
12919 ;; verilog-sig-width undecode-sig might not be.
12920 (if one-hot (number-to-string (length enum-sigs)))
12921 ;; We use a shift instead of var[index]
12922 ;; so that a non-one hot value will show as error.
12923 (if one-hot "'b1<<")
12924 (verilog-sig-name (car tmp-sigs))
12925 (if one-hot ")") ":")
12926 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
12928 (setq tmp-sigs (cdr tmp-sigs)))
12929 (verilog-insert-indent (format chrfmt "default:" errname)))
12931 (setq indent-pt (- indent-pt verilog-case-indent))
12932 (verilog-insert-indent "endcase\n")
12933 (setq indent-pt (- indent-pt verilog-indent-level))
12934 (verilog-insert-indent "end\n"
12935 "// End of automatics\n"))))
12937 (defun verilog-auto-templated-rel ()
12938 "Replace Templated relative line numbers with absolute line numbers.
12939 Internal use only. This hacks around the line numbers in AUTOINST Templates
12940 being different from the final output's line numbering."
12941 (let ((templateno 0) (template-line (list 0)) (buf-line 1))
12942 ;; Find line number each template is on
12943 ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
12944 (goto-char (point-min))
12945 (while (not (eobp))
12946 (when (looking-at ".*AUTO_TEMPLATE")
12947 (setq templateno (1+ templateno))
12948 (setq template-line (cons buf-line template-line)))
12949 (setq buf-line (1+ buf-line))
12951 (setq template-line (nreverse template-line))
12952 ;; Replace T# L# with absolute line number
12953 (goto-char (point-min))
12954 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
12956 (concat " Templated "
12957 (int-to-string (+ (nth (string-to-number (match-string 1))
12959 (string-to-number (match-string 2)))))
12962 (defun verilog-auto-template-lint ()
12963 "Check AUTO_TEMPLATEs for unused lines.
12964 Enable with `verilog-auto-template-warn-unused'."
12965 (let ((name1 (or (buffer-file-name) (buffer-name))))
12967 (goto-char (point-min))
12968 (while (re-search-forward
12969 "^\\s-*/?\\*?\\s-*[a-zA-Z0-9`_$]+\\s-+AUTO_TEMPLATE" nil t)
12970 (let* ((tpl-info (verilog-read-auto-template-middle))
12971 (tpl-list (aref tpl-info 1))
12972 (tlines (append (nth 0 tpl-list) (nth 1 tpl-list)))
12975 (setq tpl-ass (car tlines)
12976 tlines (cdr tlines))
12978 (unless (or (not (eval-when-compile (fboundp 'make-hash-table))) ;; Not supported, no warning
12979 (not verilog-auto-template-hits)
12980 (gethash (vector (nth 2 tpl-ass) (nth 3 tpl-ass))
12981 verilog-auto-template-hits))
12982 (verilog-warn-error "%s:%d: AUTO_TEMPLATE line unused: \".%s (%s)\""
12984 (+ (elt tpl-ass 3) ;; Template line number
12985 (count-lines (point-min) (point)))
12986 (elt tpl-ass 0) (elt tpl-ass 1))
12994 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing an arg
12995 "Expand AUTO statements.
12996 Look for any /*AUTO...*/ commands in the code, as used in
12997 instantiations or argument headers. Update the list of signals
12998 following the /*AUTO...*/ command.
13000 Use \\[verilog-delete-auto] to remove the AUTOs.
13002 Use \\[verilog-diff-auto] to see differences in AUTO expansion.
13004 Use \\[verilog-inject-auto] to insert AUTOs for the first time.
13006 Use \\[verilog-faq] for a pointer to frequently asked questions.
13008 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
13009 called before and after this function, respectively.
13012 module ModuleName (/*AUTOARG*/);
13017 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
13019 You can also update the AUTOs from the shell using:
13020 emacs --batch <filenames.v> -f verilog-batch-auto
13021 Or fix indentation with:
13022 emacs --batch <filenames.v> -f verilog-batch-indent
13023 Likewise, you can delete or inject AUTOs with:
13024 emacs --batch <filenames.v> -f verilog-batch-delete-auto
13025 emacs --batch <filenames.v> -f verilog-batch-inject-auto
13026 Or check if AUTOs have the same expansion
13027 emacs --batch <filenames.v> -f verilog-batch-diff-auto
13029 Using \\[describe-function], see also:
13030 `verilog-auto-arg' for AUTOARG module instantiations
13031 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
13032 `verilog-auto-assign-modport' for AUTOASSIGNMODPORT assignment to/from modport
13033 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
13034 `verilog-auto-inout-in' for AUTOINOUTIN inputs for all i/o
13035 `verilog-auto-inout-modport' for AUTOINOUTMODPORT i/o from an interface modport
13036 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
13037 `verilog-auto-inout-param' for AUTOINOUTPARAM copying params from elsewhere
13038 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
13039 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
13040 `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
13041 `verilog-auto-inst' for AUTOINST instantiation pins
13042 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
13043 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
13044 `verilog-auto-logic' for AUTOLOGIC declaring logic signals
13045 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
13046 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
13047 `verilog-auto-reg' for AUTOREG registers
13048 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
13049 `verilog-auto-reset' for AUTORESET flop resets
13050 `verilog-auto-sense' for AUTOSENSE always sensitivity lists
13051 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
13052 `verilog-auto-undef' for AUTOUNDEF `undef of local `defines
13053 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
13054 `verilog-auto-wire' for AUTOWIRE instantiation wires
13056 `verilog-read-defines' for reading `define values
13057 `verilog-read-includes' for reading `includes
13059 If you have bugs with these autos, please file an issue at
13060 URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
13061 Wilson Snyder (wsnyder@wsnyder.org)."
13063 (unless noninteractive (message "Updating AUTOs..."))
13064 (if (fboundp 'dinotrace-unannotate-all)
13065 (dinotrace-unannotate-all))
13066 (verilog-save-font-mods
13067 (let ((oldbuf (if (not (buffer-modified-p))
13069 ;; Cache directories; we don't write new files, so can't change
13070 (verilog-dir-cache-preserving t)
13071 ;; Cache current module
13072 (verilog-modi-cache-current-enable t)
13073 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
13074 verilog-modi-cache-current)
13076 ;; Disable change hooks for speed
13077 ;; This let can't be part of above let; must restore
13078 ;; after-change-functions before font-lock resumes
13079 (verilog-save-no-change-functions
13080 (verilog-save-scan-cache
13082 ;; Wipe cache; otherwise if we AUTOed a block above this one,
13083 ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
13084 (setq verilog-modi-cache-list nil)
13086 (setq verilog-auto-template-hits nil)
13087 ;; If we're not in verilog-mode, change syntax table so parsing works right
13088 (unless (eq major-mode `verilog-mode) (verilog-mode))
13089 ;; Allow user to customize
13090 (verilog-run-hooks 'verilog-before-auto-hook)
13091 ;; Try to save the user from needing to revert-file to reread file local-variables
13092 (verilog-auto-reeval-locals)
13093 (verilog-read-auto-lisp-present)
13094 (verilog-read-auto-lisp (point-min) (point-max))
13095 (verilog-getopt-flags)
13096 ;; From here on out, we can cache anything we read from disk
13097 (verilog-preserve-dir-cache
13098 ;; These two may seem obvious to do always, but on large includes it can be way too slow
13099 (when verilog-auto-read-includes
13100 (verilog-read-includes)
13101 (verilog-read-defines nil nil t))
13102 ;; Setup variables due to SystemVerilog expansion
13103 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic-setup)
13104 ;; This particular ordering is important
13105 ;; INST: Lower modules correct, no internal dependencies, FIRST
13106 (verilog-preserve-modi-cache
13107 ;; Clear existing autos else we'll be screwed by existing ones
13108 (verilog-delete-auto)
13109 ;; Injection if appropriate
13111 (verilog-inject-inst)
13112 (verilog-inject-sense)
13113 (verilog-inject-arg))
13115 ;; Do user inserts first, so their code can insert AUTOs
13116 ;; We may provide an AUTOINSERTLISPLAST if another cleanup pass is needed
13117 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
13118 'verilog-auto-insert-lisp)
13119 ;; Expand instances before need the signals the instances input/output
13120 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
13121 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
13122 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
13123 ;; Doesn't matter when done, but combine it with a common changer
13124 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
13125 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
13126 ;; Must be done before autoin/out as creates a reg
13127 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM(.*?)\\*/" 'verilog-auto-ascii-enum)
13129 ;; first in/outs from other files
13130 (verilog-auto-re-search-do "/\\*AUTOINOUTMODPORT(.*?)\\*/" 'verilog-auto-inout-modport)
13131 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE(.*?)\\*/" 'verilog-auto-inout-module)
13132 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP(.*?)\\*/" 'verilog-auto-inout-comp)
13133 (verilog-auto-re-search-do "/\\*AUTOINOUTIN(.*?)\\*/" 'verilog-auto-inout-in)
13134 (verilog-auto-re-search-do "/\\*AUTOINOUTPARAM(.*?)\\*/" 'verilog-auto-inout-param)
13135 ;; next in/outs which need previous sucked inputs first
13136 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((.*?)\\)?\\*/" 'verilog-auto-output)
13137 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((.*?)\\)?\\*/" 'verilog-auto-input)
13138 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((.*?)\\)?\\*/" 'verilog-auto-inout)
13139 ;; Then tie off those in/outs
13140 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
13141 ;; These can be anywhere after AUTOINSERTLISP
13142 (verilog-auto-re-search-do "/\\*AUTOUNDEF\\((.*?)\\)?\\*/" 'verilog-auto-undef)
13143 ;; Wires/regs must be after inputs/outputs
13144 (verilog-auto-re-search-do "/\\*AUTOASSIGNMODPORT(.*?)\\*/" 'verilog-auto-assign-modport)
13145 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
13146 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
13147 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
13148 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
13149 ;; outputevery needs AUTOOUTPUTs done first
13150 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\*/" 'verilog-auto-output-every)
13151 ;; After we've created all new variables
13152 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
13153 ;; Must be after all inputs outputs are generated
13154 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
13155 ;; Fix line numbers (comments only)
13156 (when verilog-auto-inst-template-numbers
13157 (verilog-auto-templated-rel))
13158 (when verilog-auto-template-warn-unused
13159 (verilog-auto-template-lint))))
13161 (verilog-run-hooks 'verilog-auto-hook)
13163 (when verilog-auto-delete-trailing-whitespace
13164 (verilog-delete-trailing-whitespace))
13166 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
13168 ;; If end result is same as when started, clear modified flag
13169 (cond ((and oldbuf (equal oldbuf (buffer-string)))
13170 (set-buffer-modified-p nil)
13171 (unless noninteractive (message "Updating AUTOs...done (no changes)")))
13172 (t (unless noninteractive (message "Updating AUTOs...done"))))
13173 ;; End of after-change protection
13176 ;; Currently handled in verilog-save-font-mods
13181 ;; Skeleton based code insertion
13183 (defvar verilog-template-map
13184 (let ((map (make-sparse-keymap)))
13185 (define-key map "a" 'verilog-sk-always)
13186 (define-key map "b" 'verilog-sk-begin)
13187 (define-key map "c" 'verilog-sk-case)
13188 (define-key map "f" 'verilog-sk-for)
13189 (define-key map "g" 'verilog-sk-generate)
13190 (define-key map "h" 'verilog-sk-header)
13191 (define-key map "i" 'verilog-sk-initial)
13192 (define-key map "j" 'verilog-sk-fork)
13193 (define-key map "m" 'verilog-sk-module)
13194 (define-key map "o" 'verilog-sk-ovm-class)
13195 (define-key map "p" 'verilog-sk-primitive)
13196 (define-key map "r" 'verilog-sk-repeat)
13197 (define-key map "s" 'verilog-sk-specify)
13198 (define-key map "t" 'verilog-sk-task)
13199 (define-key map "u" 'verilog-sk-uvm-class)
13200 (define-key map "w" 'verilog-sk-while)
13201 (define-key map "x" 'verilog-sk-casex)
13202 (define-key map "z" 'verilog-sk-casez)
13203 (define-key map "?" 'verilog-sk-if)
13204 (define-key map ":" 'verilog-sk-else-if)
13205 (define-key map "/" 'verilog-sk-comment)
13206 (define-key map "A" 'verilog-sk-assign)
13207 (define-key map "F" 'verilog-sk-function)
13208 (define-key map "I" 'verilog-sk-input)
13209 (define-key map "O" 'verilog-sk-output)
13210 (define-key map "S" 'verilog-sk-state-machine)
13211 (define-key map "=" 'verilog-sk-inout)
13212 (define-key map "W" 'verilog-sk-wire)
13213 (define-key map "R" 'verilog-sk-reg)
13214 (define-key map "D" 'verilog-sk-define-signal)
13216 "Keymap used in Verilog mode for smart template operations.")
13220 ;; Place the templates into Verilog Mode. They may be inserted under any key.
13221 ;; C-c C-t will be the default. If you use templates a lot, you
13222 ;; may want to consider moving the binding to another key in your init
13225 ;; Note \C-c and letter are reserved for users
13226 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
13228 ;;; ---- statement skeletons ------------------------------------------
13230 (define-skeleton verilog-sk-prompt-condition
13231 "Prompt for the loop condition."
13232 "[condition]: " str )
13234 (define-skeleton verilog-sk-prompt-init
13235 "Prompt for the loop init statement."
13236 "[initial statement]: " str )
13238 (define-skeleton verilog-sk-prompt-inc
13239 "Prompt for the loop increment statement."
13240 "[increment statement]: " str )
13242 (define-skeleton verilog-sk-prompt-name
13243 "Prompt for the name of something."
13246 (define-skeleton verilog-sk-prompt-clock
13247 "Prompt for the name of something."
13248 "name and edge of clock(s): " str)
13250 (defvar verilog-sk-reset nil)
13251 (defun verilog-sk-prompt-reset ()
13252 "Prompt for the name of a state machine reset."
13253 (setq verilog-sk-reset (read-string "name of reset: " "rst")))
13256 (define-skeleton verilog-sk-prompt-state-selector
13257 "Prompt for the name of a state machine selector."
13258 "name of selector (eg {a,b,c,d}): " str )
13260 (define-skeleton verilog-sk-prompt-output
13261 "Prompt for the name of something."
13264 (define-skeleton verilog-sk-prompt-msb
13265 "Prompt for most significant bit specification."
13266 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
13268 (define-skeleton verilog-sk-prompt-lsb
13269 "Prompt for least significant bit specification."
13272 (defvar verilog-sk-p nil)
13273 (define-skeleton verilog-sk-prompt-width
13274 "Prompt for a width specification."
13277 (setq verilog-sk-p (point))
13278 (verilog-sk-prompt-msb)
13279 (if (> (point) verilog-sk-p) "] " " ")))
13281 (defun verilog-sk-header ()
13282 "Insert a descriptive header at the top of the file.
13283 See also `verilog-header' for an alternative format."
13286 (goto-char (point-min))
13287 (verilog-sk-header-tmpl)))
13289 (define-skeleton verilog-sk-header-tmpl
13290 "Insert a comment block containing the module title, author, etc."
13292 "// -*- Mode: Verilog -*-"
13293 "\n// Filename : " (buffer-name)
13294 "\n// Description : " str
13295 "\n// Author : " (user-full-name)
13296 "\n// Created On : " (current-time-string)
13297 "\n// Last Modified By: " (user-full-name)
13298 "\n// Last Modified On: " (current-time-string)
13299 "\n// Update Count : 0"
13300 "\n// Status : Unknown, Use with caution!"
13303 (define-skeleton verilog-sk-module
13304 "Insert a module definition."
13306 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
13308 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
13310 ;;; ------------------------------------------------------------------------
13311 ;;; Define a default OVM class, with macros and new()
13312 ;;; ------------------------------------------------------------------------
13314 (define-skeleton verilog-sk-ovm-class
13315 "Insert a class definition"
13317 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
13319 > "`ovm_object_utils_begin(" name ")" \n
13320 > (- verilog-indent-level) " `ovm_object_utils_end" \n
13322 > "function new(name=\"" name "\");" \n
13323 > "super.new(name);" \n
13324 > (- verilog-indent-level) "endfunction" \n
13326 > "endclass" (progn (electric-verilog-terminate-line) nil))
13328 (define-skeleton verilog-sk-uvm-class
13329 "Insert a class definition"
13331 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
13333 > "`uvm_object_utils_begin(" name ")" \n
13334 > (- verilog-indent-level) " `uvm_object_utils_end" \n
13336 > "function new(name=\"" name "\");" \n
13337 > "super.new(name);" \n
13338 > (- verilog-indent-level) "endfunction" \n
13340 > "endclass" (progn (electric-verilog-terminate-line) nil))
13342 (define-skeleton verilog-sk-primitive
13343 "Insert a task definition."
13345 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
13347 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
13349 (define-skeleton verilog-sk-task
13350 "Insert a task definition."
13352 > "task " '(verilog-sk-prompt-name) & ?; \n
13356 > (- verilog-indent-level-behavioral) "end" \n
13357 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
13359 (define-skeleton verilog-sk-function
13360 "Insert a function definition."
13362 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n
13366 > (- verilog-indent-level-behavioral) "end" \n
13367 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
13369 (define-skeleton verilog-sk-always
13370 "Insert always block. Uses the minibuffer to prompt
13371 for sensitivity list."
13373 > "always @ ( /*AUTOSENSE*/ ) begin\n"
13375 > (- verilog-indent-level-behavioral) "end" \n >
13378 (define-skeleton verilog-sk-initial
13379 "Insert an initial block."
13381 > "initial begin\n"
13383 > (- verilog-indent-level-behavioral) "end" \n > )
13385 (define-skeleton verilog-sk-specify
13386 "Insert specify block. "
13390 > (- verilog-indent-level-behavioral) "endspecify" \n > )
13392 (define-skeleton verilog-sk-generate
13393 "Insert generate block. "
13397 > (- verilog-indent-level-behavioral) "endgenerate" \n > )
13399 (define-skeleton verilog-sk-begin
13400 "Insert begin end block. Uses the minibuffer to prompt for name."
13402 > "begin" '(verilog-sk-prompt-name) \n
13404 > (- verilog-indent-level-behavioral) "end"
13407 (define-skeleton verilog-sk-fork
13408 "Insert a fork join block."
13413 > (- verilog-indent-level-behavioral) "end" \n
13416 > (- verilog-indent-level-behavioral) "end" \n
13417 > (- verilog-indent-level-behavioral) "join" \n
13421 (define-skeleton verilog-sk-case
13422 "Build skeleton case statement, prompting for the selector expression,
13423 and the case items."
13424 "[selector expression]: "
13425 > "case (" str ") " \n
13426 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
13427 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
13429 (define-skeleton verilog-sk-casex
13430 "Build skeleton casex statement, prompting for the selector expression,
13431 and the case items."
13432 "[selector expression]: "
13433 > "casex (" str ") " \n
13434 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
13435 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
13437 (define-skeleton verilog-sk-casez
13438 "Build skeleton casez statement, prompting for the selector expression,
13439 and the case items."
13440 "[selector expression]: "
13441 > "casez (" str ") " \n
13442 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
13443 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
13445 (define-skeleton verilog-sk-if
13446 "Insert a skeleton if statement."
13447 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
13449 > (- verilog-indent-level-behavioral) "end " \n )
13451 (define-skeleton verilog-sk-else-if
13452 "Insert a skeleton else if statement."
13453 > (verilog-indent-line) "else if ("
13454 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
13456 > "end" (progn (electric-verilog-terminate-line) nil))
13458 (define-skeleton verilog-sk-datadef
13459 "Common routine to get data definition."
13461 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
13463 (define-skeleton verilog-sk-input
13464 "Insert an input definition."
13466 > "input [" '(verilog-sk-datadef))
13468 (define-skeleton verilog-sk-output
13469 "Insert an output definition."
13471 > "output [" '(verilog-sk-datadef))
13473 (define-skeleton verilog-sk-inout
13474 "Insert an inout definition."
13476 > "inout [" '(verilog-sk-datadef))
13478 (defvar verilog-sk-signal nil)
13479 (define-skeleton verilog-sk-def-reg
13480 "Insert a reg definition."
13482 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations-auto) )
13484 (defun verilog-sk-define-signal ()
13485 "Insert a definition of signal under point at top of module."
13487 (let* ((sig-re "[a-zA-Z0-9_]*")
13488 (v1 (buffer-substring
13490 (skip-chars-backward sig-re)
13493 (skip-chars-forward sig-re)
13495 (if (not (member v1 verilog-keywords))
13497 (setq verilog-sk-signal v1)
13498 (verilog-beg-of-defun)
13499 (verilog-end-of-statement)
13500 (verilog-forward-syntactic-ws)
13501 (verilog-sk-def-reg)
13502 (message "signal at point is %s" v1))
13503 (message "object at point (%s) is a keyword" v1))))
13505 (define-skeleton verilog-sk-wire
13506 "Insert a wire definition."
13508 > "wire [" '(verilog-sk-datadef))
13510 (define-skeleton verilog-sk-reg
13511 "Insert a reg definition."
13513 > "reg [" '(verilog-sk-datadef))
13515 (define-skeleton verilog-sk-assign
13516 "Insert a skeleton assign statement."
13518 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
13520 (define-skeleton verilog-sk-while
13521 "Insert a skeleton while loop statement."
13523 > "while (" '(verilog-sk-prompt-condition) ") begin" \n
13525 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13527 (define-skeleton verilog-sk-repeat
13528 "Insert a skeleton repeat loop statement."
13530 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
13532 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13534 (define-skeleton verilog-sk-for
13535 "Insert a skeleton while loop statement."
13538 '(verilog-sk-prompt-init) "; "
13539 '(verilog-sk-prompt-condition) "; "
13540 '(verilog-sk-prompt-inc)
13543 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13545 (define-skeleton verilog-sk-comment
13546 "Inserts three comment lines, making a display comment."
13552 (define-skeleton verilog-sk-state-machine
13553 "Insert a state machine definition."
13554 "Name of state variable: "
13555 '(setq input "state")
13556 > "// State registers for " str | -23 \n
13557 '(setq verilog-sk-state str)
13558 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n
13561 > "// State FF for " verilog-sk-state \n
13562 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
13563 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
13564 > verilog-sk-state " = next_" verilog-sk-state ?; \n
13565 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
13567 > "// Next State Logic for " verilog-sk-state \n
13568 > "always @ ( /*AUTOSENSE*/ ) begin\n"
13569 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
13570 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
13571 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
13572 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
13576 ;; Include file loading with mouse/return event
13578 ;; idea & first impl.: M. Rouat (eldo-mode.el)
13579 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
13581 (if (featurep 'xemacs)
13582 (require 'overlay))
13584 (defconst verilog-include-file-regexp
13585 "^`include\\s-+\"\\([^\n\"]*\\)\""
13586 "Regexp that matches the include file.")
13588 (defvar verilog-mode-mouse-map
13589 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
13590 (set-keymap-parent map verilog-mode-map)
13591 ;; mouse button bindings
13592 (define-key map "\r" 'verilog-load-file-at-point)
13593 (if (featurep 'xemacs)
13594 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
13595 (define-key map [mouse-2] 'verilog-load-file-at-mouse))
13596 (if (featurep 'xemacs)
13597 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
13598 (define-key map [S-mouse-2] 'mouse-yank-at-click))
13600 "Map containing mouse bindings for `verilog-mode'.")
13603 (defun verilog-highlight-region (beg end old-len)
13604 "Colorize included files and modules in the (changed?) region.
13605 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
13606 (when (or verilog-highlight-includes
13607 verilog-highlight-modules)
13609 (save-match-data ;; A query-replace may call this function - do not disturb
13610 (verilog-save-buffer-state
13611 (verilog-save-scan-cache
13614 (setq end-point (point-at-eol))
13616 (beginning-of-line) ; scan entire line
13617 ;; delete overlays existing on this line
13618 (let ((overlays (overlays-in (point) end-point)))
13621 (overlay-get (car overlays) 'detachable)
13622 (or (overlay-get (car overlays) 'verilog-include-file)
13623 (overlay-get (car overlays) 'verilog-inst-module)))
13624 (delete-overlay (car overlays)))
13625 (setq overlays (cdr overlays))))
13627 ;; make new include overlays
13628 (when verilog-highlight-includes
13629 (while (search-forward-regexp verilog-include-file-regexp end-point t)
13630 (goto-char (match-beginning 1))
13631 (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
13632 (overlay-put ov 'start-closed 't)
13633 (overlay-put ov 'end-closed 't)
13634 (overlay-put ov 'evaporate 't)
13635 (overlay-put ov 'verilog-include-file 't)
13636 (overlay-put ov 'mouse-face 'highlight)
13637 (overlay-put ov 'local-map verilog-mode-mouse-map))))
13639 ;; make new module overlays
13641 ;; This scanner is syntax-fragile, so don't get bent
13642 (when verilog-highlight-modules
13643 (condition-case nil
13644 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
13646 (goto-char (match-beginning 0))
13647 (unless (verilog-inside-comment-or-string-p)
13648 (verilog-read-inst-module-matcher) ;; sets match 0
13649 (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
13650 (overlay-put ov 'start-closed 't)
13651 (overlay-put ov 'end-closed 't)
13652 (overlay-put ov 'evaporate 't)
13653 (overlay-put ov 'verilog-inst-module 't)
13654 (overlay-put ov 'mouse-face 'highlight)
13655 (overlay-put ov 'local-map verilog-mode-mouse-map)))))
13658 ;; Future highlights:
13659 ;; variables - make an Occur buffer of where referenced
13660 ;; pins - make an Occur buffer of the sig in the declaration module
13663 (defun verilog-highlight-buffer ()
13664 "Colorize included files and modules across the whole buffer."
13665 ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
13667 ;; delete and remake overlays
13668 (verilog-highlight-region (point-min) (point-max) nil))
13670 ;; Deprecated, but was interactive, so we'll keep it around
13671 (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
13673 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
13674 ;; so define this function to do more or less the same as ffap-at-mouse
13675 ;; but first resolve filename...
13676 (defun verilog-load-file-at-mouse (event)
13677 "Load file under button 2 click's EVENT.
13678 Files are checked based on `verilog-library-flags'."
13680 (save-excursion ;; implement a Verilog specific ffap-at-mouse
13681 (mouse-set-point event)
13682 (verilog-load-file-at-point t)))
13684 ;; ffap isn't usable for Verilog mode. It uses library paths.
13685 ;; so define this function to do more or less the same as ffap
13686 ;; but first resolve filename...
13687 (defun verilog-load-file-at-point (&optional warn)
13688 "Load file under point.
13689 If WARN, throw warning if not found.
13690 Files are checked based on `verilog-library-flags'."
13692 (save-excursion ;; implement a Verilog specific ffap
13693 (let ((overlays (overlays-in (point) (point)))
13695 (while (and overlays (not hit))
13696 (when (overlay-get (car overlays) 'verilog-inst-module)
13697 (verilog-goto-defun-file (buffer-substring
13698 (overlay-start (car overlays))
13699 (overlay-end (car overlays))))
13701 (setq overlays (cdr overlays)))
13703 (beginning-of-line)
13704 (when (and (not hit)
13705 (looking-at verilog-include-file-regexp))
13706 (if (and (car (verilog-library-filenames
13707 (match-string 1) (buffer-file-name)))
13708 (file-readable-p (car (verilog-library-filenames
13709 (match-string 1) (buffer-file-name)))))
13710 (find-file (car (verilog-library-filenames
13711 (match-string 1) (buffer-file-name))))
13714 "File '%s' isn't readable, use shift-mouse2 to paste in this field"
13715 (match-string 1))))))))
13721 (defun verilog-faq ()
13722 "Tell the user their current version, and where to get the FAQ etc."
13724 (with-output-to-temp-buffer "*verilog-mode help*"
13725 (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
13727 (princ "For new releases, see http://www.verilog.com\n")
13729 (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
13731 (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
13734 (autoload 'reporter-submit-bug-report "reporter")
13735 (defvar reporter-prompt-for-summary-p)
13737 (defun verilog-submit-bug-report ()
13738 "Submit via mail a bug report on verilog-mode.el."
13740 (let ((reporter-prompt-for-summary-p t))
13741 (reporter-submit-bug-report
13742 "mac@verilog.com, wsnyder@wsnyder.org"
13743 (concat "verilog-mode v" verilog-mode-version)
13745 verilog-active-low-regexp
13746 verilog-after-save-font-hook
13747 verilog-align-ifelse
13748 verilog-assignment-delay
13749 verilog-auto-arg-sort
13750 verilog-auto-declare-nettype
13751 verilog-auto-delete-trailing-whitespace
13752 verilog-auto-endcomments
13754 verilog-auto-ignore-concat
13755 verilog-auto-indent-on-newline
13756 verilog-auto-inout-ignore-regexp
13757 verilog-auto-input-ignore-regexp
13758 verilog-auto-inst-column
13759 verilog-auto-inst-dot-name
13760 verilog-auto-inst-interfaced-ports
13761 verilog-auto-inst-param-value
13762 verilog-auto-inst-sort
13763 verilog-auto-inst-template-numbers
13764 verilog-auto-inst-vector
13765 verilog-auto-lineup
13766 verilog-auto-newline
13767 verilog-auto-output-ignore-regexp
13768 verilog-auto-read-includes
13769 verilog-auto-reset-blocking-in-non
13770 verilog-auto-reset-widths
13771 verilog-auto-save-policy
13772 verilog-auto-sense-defines-constant
13773 verilog-auto-sense-include-inputs
13774 verilog-auto-star-expand
13775 verilog-auto-star-save
13776 verilog-auto-template-warn-unused
13777 verilog-auto-tieoff-declaration
13778 verilog-auto-tieoff-ignore-regexp
13779 verilog-auto-unused-ignore-regexp
13780 verilog-auto-wire-type
13781 verilog-before-auto-hook
13782 verilog-before-delete-auto-hook
13783 verilog-before-getopt-flags-hook
13784 verilog-before-save-font-hook
13785 verilog-cache-enabled
13786 verilog-case-indent
13787 verilog-cexp-indent
13790 verilog-delete-auto-hook
13791 verilog-getopt-flags-hook
13792 verilog-highlight-grouping-keywords
13793 verilog-highlight-includes
13794 verilog-highlight-modules
13795 verilog-highlight-p1800-keywords
13796 verilog-highlight-translate-off
13797 verilog-indent-begin-after-if
13798 verilog-indent-declaration-macros
13799 verilog-indent-level
13800 verilog-indent-level-behavioral
13801 verilog-indent-level-declaration
13802 verilog-indent-level-directive
13803 verilog-indent-level-module
13804 verilog-indent-lists
13805 verilog-library-directories
13806 verilog-library-extensions
13807 verilog-library-files
13808 verilog-library-flags
13810 verilog-minimum-comment-distance
13812 verilog-mode-release-date
13813 verilog-mode-release-emacs
13814 verilog-mode-version
13815 verilog-preprocessor
13817 verilog-tab-always-indent
13818 verilog-tab-to-comment
13819 verilog-typedef-regexp
13825 I want to report a bug.
13827 Before I go further, I want to say that Verilog mode has changed my life.
13828 I save so much time, my files are colored nicely, my co workers respect
13829 my coding ability... until now. I'd really appreciate anything you
13830 could do to help me out with this minor deficiency in the product.
13832 I've taken a look at the Verilog-Mode FAQ at
13833 http://www.veripool.org/verilog-mode-faq.html.
13835 And, I've considered filing the bug on the issue tracker at
13836 http://www.veripool.org/verilog-mode-bugs
13837 since I realize that public bugs are easier for you to track,
13838 and for others to search, but would prefer to email.
13840 So, to reproduce the bug, start a fresh Emacs via " invocation-name "
13841 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
13842 the code included below.
13844 Given those lines, I expected [[Fill in here]] to happen;
13845 but instead, [[Fill in here]] happens!.
13847 == The code: =="))))
13849 (provide 'verilog-mode)
13851 ;; Local Variables:
13852 ;; checkdoc-permit-comma-termination-flag:t
13853 ;; checkdoc-force-docstrings-flag:nil
13856 ;;; verilog-mode.el ends here