1 ;;; verilog-mode.el --- major mode for editing verilog source in Emacs
3 ;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
5 ;; Author: Michael McNamara <mac@verilog.com>
6 ;; Wilson Snyder <wsnyder@wsnyder.org>
7 ;; http://www.verilog.com
8 ;; http://www.veripool.org
10 ;; Keywords: languages
12 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
13 ;; file on 19/3/2008, and the maintainer agreed that when a bug is
14 ;; filed in the Emacs bug reporting system against this file, a copy
15 ;; of the bug report be sent to the maintainer's email address.
17 ;; This code supports Emacs 21.1 and later
18 ;; And XEmacs 21.1 and later
19 ;; Please do not make changes that break Emacs 21. Thanks!
23 ;; This file is part of GNU Emacs.
25 ;; GNU Emacs is free software: you can redistribute it and/or modify
26 ;; it under the terms of the GNU General Public License as published by
27 ;; the Free Software Foundation, either version 3 of the License, or
28 ;; (at your option) any later version.
30 ;; GNU Emacs is distributed in the hope that it will be useful,
31 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
32 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 ;; GNU General Public License for more details.
35 ;; You should have received a copy of the GNU General Public License
36 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
43 ;; A major mode for editing Verilog and SystemVerilog HDL source code (IEEE
44 ;; 1364-2005 and IEEE 1800-2012 standards). When you have entered Verilog
45 ;; mode, you may get more info by pressing C-h m. You may also get online
46 ;; help describing various functions by: C-h f <Name of function you want
49 ;; KNOWN BUGS / BUG REPORTS
50 ;; =======================
52 ;; SystemVerilog is a rapidly evolving language, and hence this mode is
53 ;; under continuous development. Please report any issues to the issue
56 ;; http://www.veripool.org/verilog-mode
58 ;; Please use verilog-submit-bug-report to submit a report; type C-c
59 ;; C-b to invoke this and as a result we will have a much easier time
60 ;; of reproducing the bug you find, and hence fixing it.
62 ;; INSTALLING THE MODE
63 ;; ===================
65 ;; An older version of this mode may be already installed as a part of
66 ;; your environment, and one method of updating would be to update
67 ;; your Emacs environment. Sometimes this is difficult for local
68 ;; political/control reasons, and hence you can always install a
69 ;; private copy (or even a shared copy) which overrides the system
72 ;; You can get step by step help in installing this file by going to
73 ;; <http://www.verilog.com/emacs_install.html>
75 ;; The short list of installation instructions are: To set up
76 ;; automatic Verilog mode, put this file in your load path, and put
77 ;; the following in code (please un comment it first!) in your
78 ;; .emacs, or in your site's site-load.el
80 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
81 ; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
83 ;; Be sure to examine at the help for verilog-auto, and the other
84 ;; verilog-auto-* functions for some major coding time savers.
86 ;; If you want to customize Verilog mode to fit your needs better,
87 ;; you may add the below lines (the values of the variables presented
88 ;; here are the defaults). Note also that if you use an Emacs that
89 ;; supports custom, it's probably better to use the custom menu to
90 ;; edit these. If working as a member of a large team these settings
91 ;; should be common across all users (in a site-start file), or set
92 ;; in Local Variables in every file. Otherwise, different people's
93 ;; AUTO expansion may result different whitespace changes.
95 ; ;; Enable syntax highlighting of **all** languages
96 ; (global-font-lock-mode t)
98 ; ;; User customization for Verilog mode
99 ; (setq verilog-indent-level 3
100 ; verilog-indent-level-module 3
101 ; verilog-indent-level-declaration 3
102 ; verilog-indent-level-behavioral 3
103 ; verilog-indent-level-directive 1
104 ; verilog-case-indent 2
105 ; verilog-auto-newline t
106 ; verilog-auto-indent-on-newline t
107 ; verilog-tab-always-indent t
108 ; verilog-auto-endcomments t
109 ; verilog-minimum-comment-distance 40
110 ; verilog-indent-begin-after-if t
111 ; verilog-auto-lineup 'declarations
112 ; verilog-highlight-p1800-keywords nil
113 ; verilog-linter "my_lint_shell_command"
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
"2014-10-03-c075a49-vpo"
127 "Version of this Verilog mode.")
128 (defconst verilog-mode-release-emacs t
129 "If non-nil, this version of Verilog mode was released with Emacs itself.")
131 (defun verilog-version ()
132 "Inform caller of the version of this file."
134 (message "Using verilog-mode version %s" verilog-mode-version
))
136 ;; Insure we have certain packages, and deal with it if we don't
137 ;; Be sure to note which Emacs flavor and version added each feature.
139 ;; Provide stuff if we are XEmacs
140 (when (featurep 'xemacs
)
145 (require 'regexp-opt
)
147 ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
154 (defmacro when
(cond &rest body
)
155 (list 'if cond
(cons 'progn body
))))
158 (if (fboundp 'unless
)
160 (defmacro unless
(cond &rest body
)
161 (cons 'if
(cons cond
(cons nil body
)))))
164 (if (fboundp 'store-match-data
)
166 (defmacro store-match-data
(&rest _args
) nil
))
169 (if (fboundp 'char-before
)
171 (defmacro char-before
(&rest _body
)
172 (char-after (1- (point)))))
177 (defsubst point-at-bol
(&optional N
)
178 (save-excursion (beginning-of-line N
) (point))))
183 (defsubst point-at-eol
(&optional N
)
184 (save-excursion (end-of-line N
) (point))))
190 (if (fboundp 'match-string-no-properties
)
192 (defsubst match-string-no-properties
(num &optional string
)
193 "Return string of text matched by last search, without text properties.
194 NUM specifies which parenthesized expression in the last regexp.
195 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
196 Zero means the entire text matched by the whole regexp or whole string.
197 STRING should be given if the last search was by `string-match' on STRING."
198 (if (match-beginning num
)
202 (match-beginning num
) (match-end num
))))
203 (set-text-properties 0 (length result
) nil result
)
205 (buffer-substring-no-properties (match-beginning num
)
210 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
211 nil
;; We've got what we needed
212 ;; We have the old custom-library, hack around it!
213 (defmacro defgroup
(&rest _args
) nil
)
214 (defmacro customize
(&rest _args
)
216 "Sorry, Customize is not available with this version of Emacs"))
217 (defmacro defcustom
(var value doc
&rest _args
)
218 `(defvar ,var
,value
,doc
))
220 (if (fboundp 'defface
)
222 (defmacro defface
(var values doc
&rest _args
)
226 (if (and (featurep 'custom
) (fboundp 'customize-group
))
227 nil
;; We've got what we needed
228 ;; We have an intermediate custom-library, hack around it!
229 (defmacro customize-group
(var &rest _args
)
233 (unless (boundp 'inhibit-point-motion-hooks
)
234 (defvar inhibit-point-motion-hooks nil
))
235 (unless (boundp 'deactivate-mark
)
236 (defvar deactivate-mark nil
))
239 ;; OK, do this stuff if we are NOT XEmacs:
240 (unless (featurep 'xemacs
)
241 (unless (fboundp 'region-active-p
)
242 (defmacro region-active-p
()
243 `(and transient-mark-mode mark-active
))))
246 ;; Provide a regular expression optimization routine, using regexp-opt
247 ;; if provided by the user's elisp libraries
249 ;; The below were disabled when GNU Emacs 22 was released;
250 ;; perhaps some still need to be there to support Emacs 21.
251 (if (featurep 'xemacs
)
252 (if (fboundp 'regexp-opt
)
253 ;; regexp-opt is defined, does it take 3 or 2 arguments?
254 (if (fboundp 'function-max-args
)
255 (let ((args (function-max-args `regexp-opt
)))
257 ((eq args
3) ;; It takes 3
258 (condition-case nil
; Hide this defun from emacses
259 ;with just a two input regexp
260 (defun verilog-regexp-opt (a b
)
261 "Deal with differing number of required arguments for `regexp-opt'.
262 Call `regexp-opt' on A and B."
266 ((eq args
2) ;; It takes 2
267 (defun verilog-regexp-opt (a b
)
268 "Call `regexp-opt' on A and B."
272 ;; We can't tell; assume it takes 2
273 (defun verilog-regexp-opt (a b
)
274 "Call `regexp-opt' on A and B."
277 ;; There is no regexp-opt, provide our own
278 (defun verilog-regexp-opt (strings &optional paren _shy
)
279 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
280 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
)))
283 (defalias 'verilog-regexp-opt
'regexp-opt
)))
286 ;; Both xemacs and emacs
288 (require 'diff
) ;; diff-command and diff-switches
291 (require 'compile
) ;; compilation-error-regexp-alist-alist
294 (unless (fboundp 'buffer-chars-modified-tick
) ;; Emacs 22 added
295 (defmacro buffer-chars-modified-tick
() (buffer-modified-tick)))
297 ;; Added in Emacs 24.1
299 (unless (fboundp 'prog-mode
)
300 (define-derived-mode prog-mode fundamental-mode
"Prog"))
304 (defun verilog-regexp-words (a)
305 "Call 'regexp-opt' with word delimiters for the words A."
306 (concat "\\<" (verilog-regexp-opt a t
) "\\>")))
307 (defun verilog-regexp-words (a)
308 "Call 'regexp-opt' with word delimiters for the words A."
309 ;; The FAQ references this function, so user LISP sometimes calls it
310 (concat "\\<" (verilog-regexp-opt a t
) "\\>"))
312 (defun verilog-easy-menu-filter (menu)
313 "Filter `easy-menu-define' MENU to support new features."
314 (cond ((not (featurep 'xemacs
))
315 menu
) ;; GNU Emacs - passthru
316 ;; XEmacs doesn't support :help. Strip it.
317 ;; Recursively filter the a submenu
319 (mapcar 'verilog-easy-menu-filter menu
))
320 ;; Look for [:help "blah"] and remove
322 (let ((i 0) (out []))
323 (while (< i
(length menu
))
324 (if (equal `:help
(aref menu i
))
326 (setq out
(vconcat out
(vector (aref menu i
)))
329 (t menu
))) ;; Default - ok
330 ;;(verilog-easy-menu-filter
331 ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
332 ;; "----" ["MB" nil :help "Help MB"]))
334 (defun verilog-define-abbrev (table name expansion
&optional hook
)
335 "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
336 Provides SYSTEM-FLAG in newer Emacs."
338 (define-abbrev table name expansion hook
0 t
)
340 (define-abbrev table name expansion hook
))))
342 (defun verilog-customize ()
343 "Customize variables and other settings used by Verilog-Mode."
345 (customize-group 'verilog-mode
))
347 (defun verilog-font-customize ()
348 "Customize fonts used by Verilog-Mode."
350 (if (fboundp 'customize-apropos
)
351 (customize-apropos "font-lock-*" 'faces
)))
353 (defun verilog-booleanp (value)
354 "Return t if VALUE is boolean.
355 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
356 This function may be removed when Emacs 21 is no longer supported."
357 (or (equal value t
) (equal value nil
)))
359 (defun verilog-insert-last-command-event ()
360 "Insert the `last-command-event'."
361 (insert (if (featurep 'xemacs
)
362 ;; XEmacs 21.5 doesn't like last-command-event
364 ;; And GNU Emacs 22 has obsoleted last-command-char
365 last-command-event
)))
367 (defvar verilog-no-change-functions nil
368 "True if `after-change-functions' is disabled.
369 Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")
371 (defvar verilog-in-hooks nil
372 "True when within a `verilog-run-hooks' block.")
374 (defmacro verilog-run-hooks
(&rest hooks
)
375 "Run each hook in HOOKS using `run-hooks'.
376 Set `verilog-in-hooks' during this time, to assist AUTO caches."
377 `(let ((verilog-in-hooks t
))
378 (run-hooks ,@hooks
)))
380 (defun verilog-syntax-ppss (&optional pos
)
381 (when verilog-no-change-functions
383 (verilog-scan-cache-flush)
384 ;; else don't let the AUTO code itself get away with flushing the cache,
385 ;; as that'll make things very slow
387 (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
388 (verilog-point-text))))
389 (if (fboundp 'syntax-ppss
)
391 (parse-partial-sexp (point-min) (or pos
(point)))))
393 (defgroup verilog-mode nil
394 "Major mode for Verilog source code."
398 ; (defgroup verilog-mode-fonts nil
399 ; "Facilitates easy customization fonts used in Verilog source text"
400 ; :link '(customize-apropos "font-lock-*" 'faces)
401 ; :group 'verilog-mode)
403 (defgroup verilog-mode-indent nil
404 "Customize indentation and highlighting of Verilog source text."
405 :group
'verilog-mode
)
407 (defgroup verilog-mode-actions nil
408 "Customize actions on Verilog source text."
409 :group
'verilog-mode
)
411 (defgroup verilog-mode-auto nil
412 "Customize AUTO actions when expanding Verilog source text."
413 :group
'verilog-mode
)
415 (defvar verilog-debug nil
416 "Non-nil means enable debug messages for `verilog-mode' internals.")
418 (defvar verilog-warn-fatal nil
419 "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
421 (defcustom verilog-linter
422 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
423 "Unix program and arguments to call to run a lint checker on Verilog source.
424 Depending on the `verilog-set-compile-command', this may be invoked when
425 you type \\[compile]. When the compile completes, \\[next-error] will take
426 you to the next lint error."
428 :group
'verilog-mode-actions
)
429 ;; We don't mark it safe, as it's used as a shell command
431 (defcustom verilog-coverage
432 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
433 "Program and arguments to use to annotate for coverage Verilog source.
434 Depending on the `verilog-set-compile-command', this may be invoked when
435 you type \\[compile]. When the compile completes, \\[next-error] will take
436 you to the next lint error."
438 :group
'verilog-mode-actions
)
439 ;; We don't mark it safe, as it's used as a shell command
441 (defcustom verilog-simulator
442 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
443 "Program and arguments to use to interpret Verilog source.
444 Depending on the `verilog-set-compile-command', this may be invoked when
445 you type \\[compile]. When the compile completes, \\[next-error] will take
446 you to the next lint error."
448 :group
'verilog-mode-actions
)
449 ;; We don't mark it safe, as it's used as a shell command
451 (defcustom verilog-compiler
452 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
453 "Program and arguments to use to compile Verilog source.
454 Depending on the `verilog-set-compile-command', this may be invoked when
455 you type \\[compile]. When the compile completes, \\[next-error] will take
456 you to the next lint error."
458 :group
'verilog-mode-actions
)
459 ;; We don't mark it safe, as it's used as a shell command
461 (defcustom verilog-preprocessor
462 ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
463 "vppreproc __FLAGS__ __FILE__"
464 "Program and arguments to use to preprocess Verilog source.
465 This is invoked with `verilog-preprocess', and depending on the
466 `verilog-set-compile-command', may also be invoked when you type
467 \\[compile]. When the compile completes, \\[next-error] will
468 take you to the next lint error."
470 :group
'verilog-mode-actions
)
471 ;; We don't mark it safe, as it's used as a shell command
473 (defvar verilog-preprocess-history nil
474 "History for `verilog-preprocess'.")
476 (defvar verilog-tool
'verilog-linter
477 "Which tool to use for building compiler-command.
478 Either nil, `verilog-linter, `verilog-compiler,
479 `verilog-coverage, `verilog-preprocessor, or `verilog-simulator.
480 Alternatively use the \"Choose Compilation Action\" menu. See
481 `verilog-set-compile-command' for more information.")
483 (defcustom verilog-highlight-translate-off nil
484 "Non-nil means background-highlight code excluded from translation.
485 That is, all code between \"// synopsys translate_off\" and
486 \"// synopsys translate_on\" is highlighted using a different background color
487 \(face `verilog-font-lock-translate-off-face').
489 Note: This will slow down on-the-fly fontification (and thus editing).
491 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
492 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
494 :group
'verilog-mode-indent
)
495 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
496 (put 'verilog-highlight-translate-off
'safe-local-variable
'verilog-booleanp
)
498 (defcustom verilog-auto-lineup
'declarations
499 "Type of statements to lineup across multiple lines.
500 If 'all' is selected, then all line ups described below are done.
502 If 'declarations', then just declarations are lined up with any
503 preceding declarations, taking into account widths and the like,
504 so or example the code:
511 If 'assignment', then assignments are lined up with any preceding
512 assignments, so for example the code
513 a_long_variable <= b + c;
516 a_long_variable <= b + c;
519 In order to speed up editing, large blocks of statements are lined up
520 only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
521 are lineup only when \\[verilog-pretty-declarations] is typed."
523 :type
'(radio (const :tag
"Line up Assignments and Declarations" all
)
524 (const :tag
"Line up Assignment statements" assignments
)
525 (const :tag
"Line up Declarations" declarations
)
526 (function :tag
"Other"))
527 :group
'verilog-mode-indent
)
528 (put 'verilog-auto-lineup
'safe-local-variable
529 '(lambda (x) (memq x
'(nil all assignments declarations
))))
531 (defcustom verilog-indent-level
3
532 "Indentation of Verilog statements with respect to containing block."
533 :group
'verilog-mode-indent
535 (put 'verilog-indent-level
'safe-local-variable
'integerp
)
537 (defcustom verilog-indent-level-module
3
538 "Indentation of Module level Verilog statements (eg always, initial).
539 Set to 0 to get initial and always statements lined up on the left side of
541 :group
'verilog-mode-indent
543 (put 'verilog-indent-level-module
'safe-local-variable
'integerp
)
545 (defcustom verilog-indent-level-declaration
3
546 "Indentation of declarations with respect to containing block.
547 Set to 0 to get them list right under containing block."
548 :group
'verilog-mode-indent
550 (put 'verilog-indent-level-declaration
'safe-local-variable
'integerp
)
552 (defcustom verilog-indent-declaration-macros nil
553 "How to treat macro expansions in a declaration.
558 If non nil, treat as:
562 :group
'verilog-mode-indent
564 (put 'verilog-indent-declaration-macros
'safe-local-variable
'verilog-booleanp
)
566 (defcustom verilog-indent-lists t
567 "How to treat indenting items in a list.
568 If t (the default), indent as:
569 always @( posedge a or
573 always @( posedge a or
575 :group
'verilog-mode-indent
577 (put 'verilog-indent-lists
'safe-local-variable
'verilog-booleanp
)
579 (defcustom verilog-indent-level-behavioral
3
580 "Absolute indentation of first begin in a task or function block.
581 Set to 0 to get such code to start at the left side of the screen."
582 :group
'verilog-mode-indent
584 (put 'verilog-indent-level-behavioral
'safe-local-variable
'integerp
)
586 (defcustom verilog-indent-level-directive
1
587 "Indentation to add to each level of `ifdef declarations.
588 Set to 0 to have all directives start at the left side of the screen."
589 :group
'verilog-mode-indent
591 (put 'verilog-indent-level-directive
'safe-local-variable
'integerp
)
593 (defcustom verilog-cexp-indent
2
594 "Indentation of Verilog statements split across lines."
595 :group
'verilog-mode-indent
597 (put 'verilog-cexp-indent
'safe-local-variable
'integerp
)
599 (defcustom verilog-case-indent
2
600 "Indentation for case statements."
601 :group
'verilog-mode-indent
603 (put 'verilog-case-indent
'safe-local-variable
'integerp
)
605 (defcustom verilog-auto-newline t
606 "Non-nil means automatically newline after semicolons."
607 :group
'verilog-mode-indent
609 (put 'verilog-auto-newline
'safe-local-variable
'verilog-booleanp
)
611 (defcustom verilog-auto-indent-on-newline t
612 "Non-nil means automatically indent line after newline."
613 :group
'verilog-mode-indent
615 (put 'verilog-auto-indent-on-newline
'safe-local-variable
'verilog-booleanp
)
617 (defcustom verilog-tab-always-indent t
618 "Non-nil means TAB should always re-indent the current line.
619 A nil value means TAB will only reindent when at the beginning of the line."
620 :group
'verilog-mode-indent
622 (put 'verilog-tab-always-indent
'safe-local-variable
'verilog-booleanp
)
624 (defcustom verilog-tab-to-comment nil
625 "Non-nil means TAB moves to the right hand column in preparation for a comment."
626 :group
'verilog-mode-actions
628 (put 'verilog-tab-to-comment
'safe-local-variable
'verilog-booleanp
)
630 (defcustom verilog-indent-begin-after-if t
631 "Non-nil means indent begin statements following if, else, while, etc.
632 Otherwise, line them up."
633 :group
'verilog-mode-indent
635 (put 'verilog-indent-begin-after-if
'safe-local-variable
'verilog-booleanp
)
637 (defcustom verilog-align-ifelse nil
638 "Non-nil means align `else' under matching `if'.
639 Otherwise else is lined up with first character on line holding matching if."
640 :group
'verilog-mode-indent
642 (put 'verilog-align-ifelse
'safe-local-variable
'verilog-booleanp
)
644 (defcustom verilog-minimum-comment-distance
10
645 "Minimum distance (in lines) between begin and end required before a comment.
646 Setting this variable to zero results in every end acquiring a comment; the
647 default avoids too many redundant comments in tight quarters."
648 :group
'verilog-mode-indent
650 (put 'verilog-minimum-comment-distance
'safe-local-variable
'integerp
)
652 (defcustom verilog-highlight-p1800-keywords nil
653 "Non-nil means highlight words newly reserved by IEEE-1800.
654 These will appear in `verilog-font-lock-p1800-face' in order to gently
655 suggest changing where these words are used as variables to something else.
656 A nil value means highlight these words as appropriate for the SystemVerilog
657 IEEE-1800 standard. Note that changing this will require restarting Emacs
658 to see the effect as font color choices are cached by Emacs."
659 :group
'verilog-mode-indent
661 (put 'verilog-highlight-p1800-keywords
'safe-local-variable
'verilog-booleanp
)
663 (defcustom verilog-highlight-grouping-keywords nil
664 "Non-nil means highlight grouping keywords more dramatically.
665 If false, these words are in the `font-lock-type-face'; if True then they are in
666 `verilog-font-lock-ams-face'. Some find that special highlighting on these
667 grouping constructs allow the structure of the code to be understood at a glance."
668 :group
'verilog-mode-indent
670 (put 'verilog-highlight-grouping-keywords
'safe-local-variable
'verilog-booleanp
)
672 (defcustom verilog-highlight-modules nil
673 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
674 When true, mousing over module names will allow jumping to the
675 module definition. If false, this is not supported. Setting
676 this is experimental, and may lead to bad performance."
677 :group
'verilog-mode-indent
679 (put 'verilog-highlight-modules
'safe-local-variable
'verilog-booleanp
)
681 (defcustom verilog-highlight-includes t
682 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
683 When true, mousing over include file names will allow jumping to the
684 file referenced. If false, this is not supported."
685 :group
'verilog-mode-indent
687 (put 'verilog-highlight-includes
'safe-local-variable
'verilog-booleanp
)
689 (defcustom verilog-auto-declare-nettype nil
690 "Non-nil specifies the data type to use with `verilog-auto-input' etc.
691 Set this to \"wire\" if the Verilog code uses \"`default_nettype
692 none\". Note using `default_nettype none isn't recommended practice; this
693 mode is experimental."
694 :version
"24.1" ;; rev670
695 :group
'verilog-mode-actions
697 (put 'verilog-auto-declare-nettype
'safe-local-variable
`stringp
)
699 (defcustom verilog-auto-wire-type nil
700 "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
701 Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'."
702 :version
"24.1" ;; rev673
703 :group
'verilog-mode-actions
705 (put 'verilog-auto-wire-type
'safe-local-variable
`stringp
)
707 (defcustom verilog-auto-endcomments t
708 "Non-nil means insert a comment /* ... */ after 'end's.
709 The name of the function or case will be set between the braces."
710 :group
'verilog-mode-actions
712 (put 'verilog-auto-endcomments
'safe-local-variable
'verilog-booleanp
)
714 (defcustom verilog-auto-delete-trailing-whitespace nil
715 "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
716 :version
"24.1" ;; rev703
717 :group
'verilog-mode-actions
719 (put 'verilog-auto-delete-trailing-whitespace
'safe-local-variable
'verilog-booleanp
)
721 (defcustom verilog-auto-ignore-concat nil
722 "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
723 This will exclude signals referenced as pin connections in {...}
724 from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
725 for backward compatibility only and not set in new designs; it
726 may be removed in future versions."
727 :group
'verilog-mode-actions
729 (put 'verilog-auto-ignore-concat
'safe-local-variable
'verilog-booleanp
)
731 (defcustom verilog-auto-read-includes nil
732 "Non-nil means to automatically read includes before AUTOs.
733 This will do a `verilog-read-defines' and `verilog-read-includes' before
734 each AUTO expansion. This makes it easier to embed defines and includes,
735 but can result in very slow reading times if there are many or large
737 :group
'verilog-mode-actions
739 (put 'verilog-auto-read-includes
'safe-local-variable
'verilog-booleanp
)
741 (defcustom verilog-auto-save-policy nil
742 "Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
743 A value of `force' will always do a \\[verilog-auto] automatically if
744 needed on every save. A value of `detect' will do \\[verilog-auto]
745 automatically when it thinks necessary. A value of `ask' will query the
746 user when it thinks updating is needed.
748 You should not rely on the 'ask or 'detect policies, they are safeguards
749 only. They do not detect when AUTOINSTs need to be updated because a
750 sub-module's port list has changed."
751 :group
'verilog-mode-actions
752 :type
'(choice (const nil
) (const ask
) (const detect
) (const force
)))
754 (defcustom verilog-auto-star-expand t
755 "Non-nil means to expand SystemVerilog .* instance ports.
756 They will be expanded in the same way as if there was an AUTOINST in the
757 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
758 :group
'verilog-mode-actions
760 (put 'verilog-auto-star-expand
'safe-local-variable
'verilog-booleanp
)
762 (defcustom verilog-auto-star-save nil
763 "Non-nil means save to disk SystemVerilog .* instance expansions.
764 A nil value indicates direct connections will be removed before saving.
765 Only meaningful to those created due to `verilog-auto-star-expand' being set.
767 Instead of setting this, you may want to use /*AUTOINST*/, which will
769 :group
'verilog-mode-actions
771 (put 'verilog-auto-star-save
'safe-local-variable
'verilog-booleanp
)
773 (defvar verilog-auto-update-tick nil
774 "Modification tick at which autos were last performed.")
776 (defvar verilog-auto-last-file-locals nil
777 "Text from file-local-variables during last evaluation.")
779 (defvar verilog-diff-function
'verilog-diff-report
780 "Function to run when `verilog-diff-auto' detects differences.
781 Function takes three arguments, the original buffer, the
782 difference buffer, and the point in original buffer with the
787 (defvar verilog-error-regexp-added nil
)
789 (defvar verilog-error-regexp-emacs-alist
792 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
794 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
796 ".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
798 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
800 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
803 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
804 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
806 "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
808 "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
810 "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
812 "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
814 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
816 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
818 "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
820 "List of regexps for Verilog compilers.
821 See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
823 (defvar verilog-error-regexp-xemacs-alist
824 ;; Emacs form is '((v-tool "re" 1 2) ...)
825 ;; XEmacs form is '(verilog ("re" 1 2) ...)
826 ;; So we can just map from Emacs to XEmacs
827 (cons 'verilog
(mapcar 'cdr verilog-error-regexp-emacs-alist
))
828 "List of regexps for Verilog compilers.
829 See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
831 (defvar verilog-error-font-lock-keywords
834 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
835 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
837 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t
)
838 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t
)
839 ;; verilog-IES (nc-verilog)
840 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t
)
841 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t
)
842 ;; verilog-surefire-1
843 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t
)
844 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t
)
845 ;; verilog-surefire-2
846 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t
)
847 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t
)
850 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
851 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
853 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
854 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
856 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t
)
857 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t
)
859 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
860 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
862 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
863 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t
)
865 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t
)
866 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
868 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t
)
869 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t
)
871 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t
)
872 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t
)
874 "Keywords to also highlight in Verilog *compilation* buffers.
875 Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
877 (defcustom verilog-library-flags
'("")
878 "List of standard Verilog arguments to use for /*AUTOINST*/.
879 These arguments are used to find files for `verilog-auto', and match
880 the flags accepted by a standard Verilog-XL simulator.
882 -f filename Reads more `verilog-library-flags' from the filename.
883 +incdir+dir Adds the directory to `verilog-library-directories'.
884 -Idir Adds the directory to `verilog-library-directories'.
885 -y dir Adds the directory to `verilog-library-directories'.
886 +libext+.v Adds the extensions to `verilog-library-extensions'.
887 -v filename Adds the filename to `verilog-library-files'.
889 filename Adds the filename to `verilog-library-files'.
890 This is not recommended, -v is a better choice.
892 You might want these defined in each file; put at the *END* of your file
896 // verilog-library-flags:(\"-y dir -y otherdir\")
899 Verilog-mode attempts to detect changes to this local variable, but they
900 are only insured to be correct when the file is first visited. Thus if you
901 have problems, use \\[find-alternate-file] RET to have these take effect.
903 See also the variables mentioned above."
904 :group
'verilog-mode-auto
905 :type
'(repeat string
))
906 (put 'verilog-library-flags
'safe-local-variable
'listp
)
908 (defcustom verilog-library-directories
'(".")
909 "List of directories when looking for files for /*AUTOINST*/.
910 The directory may be relative to the current file, or absolute.
911 Environment variables are also expanded in the directory names.
912 Having at least the current directory is a good idea.
914 You might want these defined in each file; put at the *END* of your file
918 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
921 Verilog-mode attempts to detect changes to this local variable, but they
922 are only insured to be correct when the file is first visited. Thus if you
923 have problems, use \\[find-alternate-file] RET to have these take effect.
925 See also `verilog-library-flags', `verilog-library-files'
926 and `verilog-library-extensions'."
927 :group
'verilog-mode-auto
928 :type
'(repeat file
))
929 (put 'verilog-library-directories
'safe-local-variable
'listp
)
931 (defcustom verilog-library-files
'()
932 "List of files to search for modules.
933 AUTOINST will use this when it needs to resolve a module name.
934 This is a complete path, usually to a technology file with many standard
937 You might want these defined in each file; put at the *END* of your file
941 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
944 Verilog-mode attempts to detect changes to this local variable, but they
945 are only insured to be correct when the file is first visited. Thus if you
946 have problems, use \\[find-alternate-file] RET to have these take effect.
948 See also `verilog-library-flags', `verilog-library-directories'."
949 :group
'verilog-mode-auto
950 :type
'(repeat directory
))
951 (put 'verilog-library-files
'safe-local-variable
'listp
)
953 (defcustom verilog-library-extensions
'(".v" ".sv")
954 "List of extensions to use when looking for files for /*AUTOINST*/.
955 See also `verilog-library-flags', `verilog-library-directories'."
956 :type
'(repeat string
)
957 :group
'verilog-mode-auto
)
958 (put 'verilog-library-extensions
'safe-local-variable
'listp
)
960 (defcustom verilog-active-low-regexp nil
961 "If true, treat signals matching this regexp as active low.
962 This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
963 you will probably also need `verilog-auto-reset-widths' set."
964 :group
'verilog-mode-auto
965 :type
'(choice (const nil
) regexp
))
966 (put 'verilog-active-low-regexp
'safe-local-variable
'stringp
)
968 (defcustom verilog-auto-sense-include-inputs nil
969 "Non-nil means AUTOSENSE should include all inputs.
970 If nil, only inputs that are NOT output signals in the same block are
972 :group
'verilog-mode-auto
974 (put 'verilog-auto-sense-include-inputs
'safe-local-variable
'verilog-booleanp
)
976 (defcustom verilog-auto-sense-defines-constant nil
977 "Non-nil means AUTOSENSE should assume all defines represent constants.
978 When true, the defines will not be included in sensitivity lists. To
979 maintain compatibility with other sites, this should be set at the bottom
980 of each Verilog file that requires it, rather than being set globally."
981 :group
'verilog-mode-auto
983 (put 'verilog-auto-sense-defines-constant
'safe-local-variable
'verilog-booleanp
)
985 (defcustom verilog-auto-reset-blocking-in-non t
986 "Non-nil means AUTORESET will reset blocking statements.
987 When true, AUTORESET will reset in blocking statements those
988 signals which were assigned with blocking assignments (=) even in
989 a block with non-blocking assignments (<=).
991 If nil, all blocking assigned signals are ignored when any
992 non-blocking assignment is in the AUTORESET block. This allows
993 blocking assignments to be used for temporary values and not have
994 those temporaries reset. See example in `verilog-auto-reset'."
995 :version
"24.1" ;; rev718
997 :group
'verilog-mode-auto
)
998 (put 'verilog-auto-reset-blocking-in-non
'safe-local-variable
'verilog-booleanp
)
1000 (defcustom verilog-auto-reset-widths t
1001 "True means AUTORESET should determine the width of signals.
1002 This is then used to set the width of the zero (32'h0 for example). This
1003 is required by some lint tools that aren't smart enough to ignore widths of
1004 the constant zero. This may result in ugly code when parameters determine
1005 the MSB or LSB of a signal inside an AUTORESET.
1007 If nil, AUTORESET uses \"0\" as the constant.
1009 If 'unbased', AUTORESET used the unbased unsized literal \"'0\"
1010 as the constant. This setting is strongly recommended for
1011 SystemVerilog designs."
1013 :group
'verilog-mode-auto
)
1014 (put 'verilog-auto-reset-widths
'safe-local-variable
1015 '(lambda (x) (memq x
'(nil t unbased
))))
1017 (defcustom verilog-assignment-delay
""
1018 "Text used for delays in delayed assignments. Add a trailing space if set."
1019 :group
'verilog-mode-auto
1021 (put 'verilog-assignment-delay
'safe-local-variable
'stringp
)
1023 (defcustom verilog-auto-arg-format
'packed
1024 "Formatting to use for AUTOARG signal names.
1025 If 'packed', then as many inputs and outputs that fit within
1026 `fill-column' will be put onto one line.
1028 If 'single', then a single input or output will be put onto each
1031 :type
'(radio (const :tag
"Line up Assignments and Declarations" packed
)
1032 (const :tag
"Line up Assignment statements" single
))
1033 :group
'verilog-mode-auto
)
1034 (put 'verilog-auto-arg-format
'safe-local-variable
1035 '(lambda (x) (memq x
'(packed single
))))
1037 (defcustom verilog-auto-arg-sort nil
1038 "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
1039 Declaration order is advantageous with order based instantiations
1040 and is the default for backward compatibility. Sorted order
1041 reduces changes when declarations are moved around in a file, and
1042 it's bad practice to rely on order based instantiations anyhow.
1044 See also `verilog-auto-inst-sort'."
1045 :group
'verilog-mode-auto
1047 (put 'verilog-auto-arg-sort
'safe-local-variable
'verilog-booleanp
)
1049 (defcustom verilog-auto-inst-dot-name nil
1050 "Non-nil means when creating ports with AUTOINST, use .name syntax.
1051 This will use \".port\" instead of \".port(port)\" when possible.
1052 This is only legal in SystemVerilog files, and will confuse older
1053 simulators. Setting `verilog-auto-inst-vector' to nil may also
1054 be desirable to increase how often .name will be used."
1055 :group
'verilog-mode-auto
1057 (put 'verilog-auto-inst-dot-name
'safe-local-variable
'verilog-booleanp
)
1059 (defcustom verilog-auto-inst-param-value nil
1060 "Non-nil means AUTOINST will replace parameters with the parameter value.
1061 If nil, leave parameters as symbolic names.
1063 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
1064 listed as such there (as when the default value is acceptable), it will not
1065 be replaced, and will remain symbolic.
1067 For example, imagine a submodule uses parameters to declare the size of its
1068 inputs. This is then used by an upper module:
1070 module InstModule (o,i);
1072 input [WIDTH-1:0] i;
1082 Note even though PARAM=10, the AUTOINST has left the parameter as a
1083 symbolic name. If `verilog-auto-inst-param-value' is set, this will
1092 :group
'verilog-mode-auto
1094 (put 'verilog-auto-inst-param-value
'safe-local-variable
'verilog-booleanp
)
1096 (defcustom verilog-auto-inst-sort nil
1097 "Non-nil means AUTOINST signals will be sorted, not in declaration order.
1098 Also affects AUTOINSTPARAM. Declaration order is the default for
1099 backward compatibility, and as some teams prefer signals that are
1100 declared together to remain together. Sorted order reduces
1101 changes when declarations are moved around in a file.
1103 See also `verilog-auto-arg-sort'."
1104 :version
"24.1" ;; rev688
1105 :group
'verilog-mode-auto
1107 (put 'verilog-auto-inst-sort
'safe-local-variable
'verilog-booleanp
)
1109 (defcustom verilog-auto-inst-vector t
1110 "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
1111 If nil, skip the subscript when it matches the entire bus as declared in
1112 the module (AUTOWIRE signals always are subscripted, you must manually
1113 declare the wire to have the subscripts removed.) Setting this to nil may
1114 speed up some simulators, but is less general and harder to read, so avoid."
1115 :group
'verilog-mode-auto
1117 (put 'verilog-auto-inst-vector
'safe-local-variable
'verilog-booleanp
)
1119 (defcustom verilog-auto-inst-template-numbers nil
1120 "If true, when creating templated ports with AUTOINST, add a comment.
1122 If t, the comment will add the line number of the template that
1123 was used for that port declaration. This setting is suggested
1124 only for debugging use, as regular use may cause a large numbers
1127 If 'lhs', the comment will show the left hand side of the
1128 AUTO_TEMPLATE rule that is matched. This is less precise than
1129 numbering (t) when multiple rules have the same pin name, but
1130 won't merge conflict."
1131 :group
'verilog-mode-auto
1132 :type
'(choice (const nil
) (const t
) (const lhs
)))
1133 (put 'verilog-auto-inst-template-numbers
'safe-local-variable
1134 '(lambda (x) (memq x
'(nil t lhs
))))
1136 (defcustom verilog-auto-inst-column
40
1137 "Indent-to column number for net name part of AUTOINST created pin."
1138 :group
'verilog-mode-indent
1140 (put 'verilog-auto-inst-column
'safe-local-variable
'integerp
)
1142 (defcustom verilog-auto-inst-interfaced-ports nil
1143 "Non-nil means include interfaced ports in AUTOINST expansions."
1144 :version
"24.3" ;; rev773, default change rev815
1145 :group
'verilog-mode-auto
1147 (put 'verilog-auto-inst-interfaced-ports
'safe-local-variable
'verilog-booleanp
)
1149 (defcustom verilog-auto-input-ignore-regexp nil
1150 "If non-nil, when creating AUTOINPUT, ignore signals matching this regexp.
1151 See the \\[verilog-faq] for examples on using this."
1152 :group
'verilog-mode-auto
1153 :type
'(choice (const nil
) regexp
))
1154 (put 'verilog-auto-input-ignore-regexp
'safe-local-variable
'stringp
)
1156 (defcustom verilog-auto-inout-ignore-regexp nil
1157 "If non-nil, when creating AUTOINOUT, ignore signals matching this regexp.
1158 See the \\[verilog-faq] for examples on using this."
1159 :group
'verilog-mode-auto
1160 :type
'(choice (const nil
) regexp
))
1161 (put 'verilog-auto-inout-ignore-regexp
'safe-local-variable
'stringp
)
1163 (defcustom verilog-auto-output-ignore-regexp nil
1164 "If non-nil, when creating AUTOOUTPUT, ignore signals matching this regexp.
1165 See the \\[verilog-faq] for examples on using this."
1166 :group
'verilog-mode-auto
1167 :type
'(choice (const nil
) regexp
))
1168 (put 'verilog-auto-output-ignore-regexp
'safe-local-variable
'stringp
)
1170 (defcustom verilog-auto-template-warn-unused nil
1171 "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
1172 This feature is not supported before Emacs 21.1 or XEmacs 21.4."
1173 :version
"24.3" ;;rev787
1174 :group
'verilog-mode-auto
1176 (put 'verilog-auto-template-warn-unused
'safe-local-variable
'verilog-booleanp
)
1178 (defcustom verilog-auto-tieoff-declaration
"wire"
1179 "Data type used for the declaration for AUTOTIEOFF.
1180 If \"wire\" then create a wire, if \"assign\" create an
1181 assignment, else the data type for variable creation."
1182 :version
"24.1" ;; rev713
1183 :group
'verilog-mode-auto
1185 (put 'verilog-auto-tieoff-declaration
'safe-local-variable
'stringp
)
1187 (defcustom verilog-auto-tieoff-ignore-regexp nil
1188 "If non-nil, when creating AUTOTIEOFF, ignore signals matching this regexp.
1189 See the \\[verilog-faq] for examples on using this."
1190 :group
'verilog-mode-auto
1191 :type
'(choice (const nil
) regexp
))
1192 (put 'verilog-auto-tieoff-ignore-regexp
'safe-local-variable
'stringp
)
1194 (defcustom verilog-auto-unused-ignore-regexp nil
1195 "If non-nil, when creating AUTOUNUSED, ignore signals matching this regexp.
1196 See the \\[verilog-faq] for examples on using this."
1197 :group
'verilog-mode-auto
1198 :type
'(choice (const nil
) regexp
))
1199 (put 'verilog-auto-unused-ignore-regexp
'safe-local-variable
'stringp
)
1201 (defcustom verilog-case-fold t
1202 "Non-nil means `verilog-mode' regexps should ignore case.
1203 This variable is t for backward compatibility; nil is suggested."
1205 :group
'verilog-mode
1207 (put 'verilog-case-fold
'safe-local-variable
'verilog-booleanp
)
1209 (defcustom verilog-typedef-regexp nil
1210 "If non-nil, regular expression that matches Verilog-2001 typedef names.
1211 For example, \"_t$\" matches typedefs named with _t, as in the C language.
1212 See also `verilog-case-fold'."
1213 :group
'verilog-mode-auto
1214 :type
'(choice (const nil
) regexp
))
1215 (put 'verilog-typedef-regexp
'safe-local-variable
'stringp
)
1217 (defcustom verilog-mode-hook
'verilog-set-compile-command
1218 "Hook run after Verilog mode is loaded."
1220 :group
'verilog-mode
)
1222 (defcustom verilog-auto-hook nil
1223 "Hook run after `verilog-mode' updates AUTOs."
1224 :group
'verilog-mode-auto
1227 (defcustom verilog-before-auto-hook nil
1228 "Hook run before `verilog-mode' updates AUTOs."
1229 :group
'verilog-mode-auto
1232 (defcustom verilog-delete-auto-hook nil
1233 "Hook run after `verilog-mode' deletes AUTOs."
1234 :group
'verilog-mode-auto
1237 (defcustom verilog-before-delete-auto-hook nil
1238 "Hook run before `verilog-mode' deletes AUTOs."
1239 :group
'verilog-mode-auto
1242 (defcustom verilog-getopt-flags-hook nil
1243 "Hook run after `verilog-getopt-flags' determines the Verilog option lists."
1244 :group
'verilog-mode-auto
1247 (defcustom verilog-before-getopt-flags-hook nil
1248 "Hook run before `verilog-getopt-flags' determines the Verilog option lists."
1249 :group
'verilog-mode-auto
1252 (defcustom verilog-before-save-font-hook nil
1253 "Hook run before `verilog-save-font-mods' removes highlighting."
1254 :version
"24.3" ;;rev735
1255 :group
'verilog-mode-auto
1258 (defcustom verilog-after-save-font-hook nil
1259 "Hook run after `verilog-save-font-mods' restores highlighting."
1260 :version
"24.3" ;;rev735
1261 :group
'verilog-mode-auto
1264 (defvar verilog-imenu-generic-expression
1265 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
1266 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
1267 "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
1270 ;; provide a verilog-header function.
1271 ;; Customization variables:
1273 (defvar verilog-date-scientific-format nil
1274 "If non-nil, dates are written in scientific format (e.g. 1997/09/17).
1275 If nil, in European format (e.g. 17.09.1997). The brain-dead American
1276 format (e.g. 09/17/1997) is not supported.")
1278 (defvar verilog-company nil
1279 "Default name of Company for Verilog header.
1280 If set will become buffer local.")
1281 (make-variable-buffer-local 'verilog-company
)
1283 (defvar verilog-project nil
1284 "Default name of Project for Verilog header.
1285 If set will become buffer local.")
1286 (make-variable-buffer-local 'verilog-project
)
1288 (defvar verilog-mode-map
1289 (let ((map (make-sparse-keymap)))
1290 (define-key map
";" 'electric-verilog-semi
)
1291 (define-key map
[(control 59)] 'electric-verilog-semi-with-comment
)
1292 (define-key map
":" 'electric-verilog-colon
)
1293 ;;(define-key map "=" 'electric-verilog-equal)
1294 (define-key map
"\`" 'electric-verilog-tick
)
1295 (define-key map
"\t" 'electric-verilog-tab
)
1296 (define-key map
"\r" 'electric-verilog-terminate-line
)
1297 ;; backspace/delete key bindings
1298 (define-key map
[backspace] 'backward-delete-char-untabify)
1299 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
1300 (define-key map [delete] 'delete-char)
1301 (define-key map [(meta delete)] 'kill-word))
1302 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
1303 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
1304 (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
1305 (define-key map "\M-\t" 'verilog-complete-word)
1306 (define-key map "\M-?" 'verilog-show-completions)
1307 ;; Note \C-c and letter are reserved for users
1308 (define-key map "\C-c\`" 'verilog-lint-off)
1309 (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit)
1310 (define-key map "\C-c\?" 'verilog-diff-auto)
1311 (define-key map "\C-c\C-r" 'verilog-label-be)
1312 (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
1313 (define-key map "\C-c=" 'verilog-pretty-expr)
1314 (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
1315 (define-key map "\M-*" 'verilog-star-comment)
1316 (define-key map "\C-c\C-c" 'verilog-comment-region)
1317 (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1318 (when (featurep 'xemacs)
1319 (define-key map [(meta control h)] 'verilog-mark-defun)
1320 (define-key map "\M-\C-a" 'verilog-beg-of-defun)
1321 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1322 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1323 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1324 (define-key map "\C-c\C-a" 'verilog-auto)
1325 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1326 (define-key map "\C-c\C-p" 'verilog-preprocess)
1327 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1328 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1329 (define-key map "\C-c\C-h" 'verilog-header)
1331 "Keymap used in Verilog mode.")
1335 verilog-menu verilog-mode-map "Menu for Verilog mode"
1336 (verilog-easy-menu-filter
1338 ("Choose Compilation Action"
1341 (setq verilog-tool nil)
1342 (verilog-set-compile-command))
1344 :selected (equal verilog-tool nil)
1345 :help "When invoking compilation, use compile-command"]
1348 (setq verilog-tool 'verilog-linter)
1349 (verilog-set-compile-command))
1351 :selected (equal verilog-tool `verilog-linter)
1352 :help "When invoking compilation, use lint checker"]
1355 (setq verilog-tool 'verilog-coverage)
1356 (verilog-set-compile-command))
1358 :selected (equal verilog-tool `verilog-coverage)
1359 :help "When invoking compilation, annotate for coverage"]
1362 (setq verilog-tool 'verilog-simulator)
1363 (verilog-set-compile-command))
1365 :selected (equal verilog-tool `verilog-simulator)
1366 :help "When invoking compilation, interpret Verilog source"]
1369 (setq verilog-tool 'verilog-compiler)
1370 (verilog-set-compile-command))
1372 :selected (equal verilog-tool `verilog-compiler)
1373 :help "When invoking compilation, compile Verilog source"]
1376 (setq verilog-tool 'verilog-preprocessor)
1377 (verilog-set-compile-command))
1379 :selected (equal verilog-tool `verilog-preprocessor)
1380 :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1383 ["Beginning of function" verilog-beg-of-defun
1385 :help "Move backward to the beginning of the current function or procedure"]
1386 ["End of function" verilog-end-of-defun
1388 :help "Move forward to the end of the current function or procedure"]
1389 ["Mark function" verilog-mark-defun
1391 :help "Mark the current Verilog function or procedure"]
1392 ["Goto function/module" verilog-goto-defun
1393 :help "Move to specified Verilog module/task/function"]
1394 ["Move to beginning of block" electric-verilog-backward-sexp
1395 :help "Move backward over one balanced expression"]
1396 ["Move to end of block" electric-verilog-forward-sexp
1397 :help "Move forward over one balanced expression"]
1400 ["Comment Region" verilog-comment-region
1401 :help "Put marked area into a comment"]
1402 ["UnComment Region" verilog-uncomment-region
1403 :help "Uncomment an area commented with Comment Region"]
1404 ["Multi-line comment insert" verilog-star-comment
1405 :help "Insert Verilog /* */ comment at point"]
1406 ["Lint error to comment" verilog-lint-off
1407 :help "Convert a Verilog linter warning line into a disable statement"]
1411 :help "Perform compilation-action (above) on the current buffer"]
1412 ["AUTO, Save, Compile" verilog-auto-save-compile
1413 :help "Recompute AUTOs, save buffer, and compile"]
1414 ["Next Compile Error" next-error
1415 :help "Visit next compilation error message and corresponding source code"]
1416 ["Ignore Lint Warning at point" verilog-lint-off
1417 :help "Convert a Verilog linter warning line into a disable statement"]
1419 ["Line up declarations around point" verilog-pretty-declarations
1420 :help "Line up declarations around point"]
1421 ["Line up equations around point" verilog-pretty-expr
1422 :help "Line up expressions around point"]
1423 ["Redo/insert comments on every end" verilog-label-be
1424 :help "Label matching begin ... end statements"]
1425 ["Expand [x:y] vector line" verilog-expand-vector
1426 :help "Take a signal vector on the current line and expand it to multiple lines"]
1427 ["Insert begin-end block" verilog-insert-block
1428 :help "Insert begin ... end"]
1429 ["Complete word" verilog-complete-word
1430 :help "Complete word at point"]
1432 ["Recompute AUTOs" verilog-auto
1433 :help "Expand AUTO meta-comment statements"]
1434 ["Kill AUTOs" verilog-delete-auto
1435 :help "Remove AUTO expansions"]
1436 ["Diff AUTOs" verilog-diff-auto
1437 :help "Show differences in AUTO expansions"]
1438 ["Inject AUTOs" verilog-inject-auto
1439 :help "Inject AUTOs into legacy non-AUTO buffer"]
1441 ["AUTO General" (describe-function 'verilog-auto)
1442 :help "Help introduction on AUTOs"]
1443 ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
1444 :help "Help on verilog-library-flags"]
1445 ["AUTO Library Path" (describe-variable 'verilog-library-directories)
1446 :help "Help on verilog-library-directories"]
1447 ["AUTO Library Files" (describe-variable 'verilog-library-files)
1448 :help "Help on verilog-library-files"]
1449 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
1450 :help "Help on verilog-library-extensions"]
1451 ["AUTO `define Reading" (describe-function 'verilog-read-defines)
1452 :help "Help on reading `defines"]
1453 ["AUTO `include Reading" (describe-function 'verilog-read-includes)
1454 :help "Help on parsing `includes"]
1455 ["AUTOARG" (describe-function 'verilog-auto-arg)
1456 :help "Help on AUTOARG - declaring module port list"]
1457 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
1458 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1459 ["AUTOASSIGNMODPORT" (describe-function 'verilog-auto-assign-modport)
1460 :help "Help on AUTOASSIGNMODPORT - creating assignments to/from modports"]
1461 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1462 :help "Help on AUTOINOUT - adding inouts from cells"]
1463 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
1464 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1465 ["AUTOINOUTIN" (describe-function 'verilog-auto-inout-in)
1466 :help "Help on AUTOINOUTIN - copying i/o from another file as all inputs"]
1467 ["AUTOINOUTMODPORT" (describe-function 'verilog-auto-inout-modport)
1468 :help "Help on AUTOINOUTMODPORT - copying i/o from an interface modport"]
1469 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1470 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1471 ["AUTOINOUTPARAM" (describe-function 'verilog-auto-inout-param)
1472 :help "Help on AUTOINOUTPARAM - copying parameters from another file"]
1473 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1474 :help "Help on AUTOINPUT - adding inputs from cells"]
1475 ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
1476 :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
1477 ["AUTOINSERTLAST" (describe-function 'verilog-auto-insert-last)
1478 :help "Help on AUTOINSERTLISPLAST - insert text from a lisp function"]
1479 ["AUTOINST" (describe-function 'verilog-auto-inst)
1480 :help "Help on AUTOINST - adding pins for cells"]
1481 ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
1482 :help "Help on expanding Verilog-2001 .* pins"]
1483 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
1484 :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
1485 ["AUTOLOGIC" (describe-function 'verilog-auto-logic)
1486 :help "Help on AUTOLOGIC - declaring logic signals"]
1487 ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
1488 :help "Help on AUTOOUTPUT - adding outputs from cells"]
1489 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
1490 :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
1491 ["AUTOREG" (describe-function 'verilog-auto-reg)
1492 :help "Help on AUTOREG - declaring registers for non-wires"]
1493 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
1494 :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
1495 ["AUTORESET" (describe-function 'verilog-auto-reset)
1496 :help "Help on AUTORESET - resetting always blocks"]
1497 ["AUTOSENSE or AS" (describe-function 'verilog-auto-sense)
1498 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1499 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1500 :help "Help on AUTOTIEOFF - tying off unused outputs"]
1501 ["AUTOUNDEF" (describe-function 'verilog-auto-undef)
1502 :help "Help on AUTOUNDEF - undefine all local defines"]
1503 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1504 :help "Help on AUTOUNUSED - terminating unused inputs"]
1505 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
1506 :help "Help on AUTOWIRE - declaring wires for cells"]
1509 ["Submit bug report" verilog-submit-bug-report
1510 :help "Submit via mail a bug report on verilog-mode.el"]
1511 ["Version and FAQ" verilog-faq
1512 :help "Show the current version, and where to get the FAQ etc"]
1513 ["Customize Verilog Mode..." verilog-customize
1514 :help "Customize variables and other settings used by Verilog-Mode"]
1515 ["Customize Verilog Fonts & Colors" verilog-font-customize
1516 :help "Customize fonts used by Verilog-Mode."])))
1519 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1520 (verilog-easy-menu-filter
1522 ["Header" verilog-sk-header
1523 :help "Insert a header block at the top of file"]
1524 ["Comment" verilog-sk-comment
1525 :help "Insert a comment block"]
1527 ["Module" verilog-sk-module
1528 :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
1529 ["OVM Class" verilog-sk-ovm-class
1530 :help "Insert an OVM class block"]
1531 ["UVM Object" verilog-sk-uvm-object
1532 :help "Insert an UVM object block"]
1533 ["UVM Component" verilog-sk-uvm-component
1534 :help "Insert an UVM component block"]
1535 ["Primitive" verilog-sk-primitive
1536 :help "Insert a primitive .. (.. );.. endprimitive block"]
1538 ["Input" verilog-sk-input
1539 :help "Insert an input declaration"]
1540 ["Output" verilog-sk-output
1541 :help "Insert an output declaration"]
1542 ["Inout" verilog-sk-inout
1543 :help "Insert an inout declaration"]
1544 ["Wire" verilog-sk-wire
1545 :help "Insert a wire declaration"]
1546 ["Reg" verilog-sk-reg
1547 :help "Insert a register declaration"]
1548 ["Define thing under point as a register" verilog-sk-define-signal
1549 :help "Define signal under point as a register at the top of the module"]
1551 ["Initial" verilog-sk-initial
1552 :help "Insert an initial begin .. end block"]
1553 ["Always" verilog-sk-always
1554 :help "Insert an always @(AS) begin .. end block"]
1555 ["Function" verilog-sk-function
1556 :help "Insert a function .. begin .. end endfunction block"]
1557 ["Task" verilog-sk-task
1558 :help "Insert a task .. begin .. end endtask block"]
1559 ["Specify" verilog-sk-specify
1560 :help "Insert a specify .. endspecify block"]
1561 ["Generate" verilog-sk-generate
1562 :help "Insert a generate .. endgenerate block"]
1564 ["Begin" verilog-sk-begin
1565 :help "Insert a begin .. end block"]
1567 :help "Insert an if (..) begin .. end block"]
1568 ["(if) else" verilog-sk-else-if
1569 :help "Insert an else if (..) begin .. end block"]
1570 ["For" verilog-sk-for
1571 :help "Insert a for (...) begin .. end block"]
1572 ["While" verilog-sk-while
1573 :help "Insert a while (...) begin .. end block"]
1574 ["Fork" verilog-sk-fork
1575 :help "Insert a fork begin .. end .. join block"]
1576 ["Repeat" verilog-sk-repeat
1577 :help "Insert a repeat (..) begin .. end block"]
1578 ["Case" verilog-sk-case
1579 :help "Insert a case block, prompting for details"]
1580 ["Casex" verilog-sk-casex
1581 :help "Insert a casex (...) item: begin.. end endcase block"]
1582 ["Casez" verilog-sk-casez
1583 :help "Insert a casez (...) item: begin.. end endcase block"])))
1585 (defvar verilog-mode-abbrev-table nil
1586 "Abbrev table in use in Verilog-mode buffers.")
1588 (define-abbrev-table 'verilog-mode-abbrev-table ())
1589 (verilog-define-abbrev verilog-mode-abbrev-table "class" "" 'verilog-sk-ovm-class)
1590 (verilog-define-abbrev verilog-mode-abbrev-table "always" "" 'verilog-sk-always)
1591 (verilog-define-abbrev verilog-mode-abbrev-table "begin" nil `verilog-sk-begin)
1592 (verilog-define-abbrev verilog-mode-abbrev-table "case" "" `verilog-sk-case)
1593 (verilog-define-abbrev verilog-mode-abbrev-table "for" "" `verilog-sk-for)
1594 (verilog-define-abbrev verilog-mode-abbrev-table "generate" "" `verilog-sk-generate)
1595 (verilog-define-abbrev verilog-mode-abbrev-table "initial" "" `verilog-sk-initial)
1596 (verilog-define-abbrev verilog-mode-abbrev-table "fork" "" `verilog-sk-fork)
1597 (verilog-define-abbrev verilog-mode-abbrev-table "module" "" `verilog-sk-module)
1598 (verilog-define-abbrev verilog-mode-abbrev-table "primitive" "" `verilog-sk-primitive)
1599 (verilog-define-abbrev verilog-mode-abbrev-table "repeat" "" `verilog-sk-repeat)
1600 (verilog-define-abbrev verilog-mode-abbrev-table "specify" "" `verilog-sk-specify)
1601 (verilog-define-abbrev verilog-mode-abbrev-table "task" "" `verilog-sk-task)
1602 (verilog-define-abbrev verilog-mode-abbrev-table "while" "" `verilog-sk-while)
1603 (verilog-define-abbrev verilog-mode-abbrev-table "casex" "" `verilog-sk-casex)
1604 (verilog-define-abbrev verilog-mode-abbrev-table "casez" "" `verilog-sk-casez)
1605 (verilog-define-abbrev verilog-mode-abbrev-table "if" "" `verilog-sk-if)
1606 (verilog-define-abbrev verilog-mode-abbrev-table "else if" "" `verilog-sk-else-if)
1607 (verilog-define-abbrev verilog-mode-abbrev-table "assign" "" `verilog-sk-assign)
1608 (verilog-define-abbrev verilog-mode-abbrev-table "function" "" `verilog-sk-function)
1609 (verilog-define-abbrev verilog-mode-abbrev-table "input" "" `verilog-sk-input)
1610 (verilog-define-abbrev verilog-mode-abbrev-table "output" "" `verilog-sk-output)
1611 (verilog-define-abbrev verilog-mode-abbrev-table "inout" "" `verilog-sk-inout)
1612 (verilog-define-abbrev verilog-mode-abbrev-table "wire" "" `verilog-sk-wire)
1613 (verilog-define-abbrev verilog-mode-abbrev-table "reg" "" `verilog-sk-reg)
1619 (defsubst verilog-within-string ()
1620 (nth 3 (parse-partial-sexp (point-at-bol) (point))))
1622 (defsubst verilog-string-match-fold (regexp string &optional start)
1623 "Like `string-match', but use `verilog-case-fold'.
1624 Return index of start of first match for REGEXP in STRING, or nil.
1625 Matching ignores case if `verilog-case-fold' is non-nil.
1626 If third arg START is non-nil, start search at that index in STRING."
1627 (let ((case-fold-search verilog-case-fold))
1628 (string-match regexp string start)))
1630 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1631 "Replace occurrences of FROM-STRING with TO-STRING.
1632 FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace.
1633 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1634 will break, as the o's continuously replace. xa -> x works ok though."
1635 ;; Hopefully soon to an Emacs built-in
1636 ;; Also note \ in the replacement prevent multiple replacements; IE
1637 ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
1638 ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
1640 (while (string-match from-string string start)
1641 (setq string (replace-match to-string fixedcase literal string)
1642 start (min (length string) (+ (match-beginning 0) (length to-string)))))
1645 (defsubst verilog-string-remove-spaces (string)
1646 "Remove spaces surrounding STRING."
1648 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
1649 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
1652 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
1653 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1654 "Like `re-search-forward', but skips over match in comments or strings."
1655 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1657 (re-search-forward REGEXP BOUND NOERROR)
1658 (setq mdata (match-data))
1659 (and (verilog-skip-forward-comment-or-string)
1661 (setq mdata '(nil nil))
1665 (store-match-data mdata)
1668 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
1669 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1670 "Like `re-search-backward', but skips over match in comments or strings."
1671 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1673 (re-search-backward REGEXP BOUND NOERROR)
1674 (setq mdata (match-data))
1675 (and (verilog-skip-backward-comment-or-string)
1677 (setq mdata '(nil nil))
1681 (store-match-data mdata)
1684 (defsubst verilog-re-search-forward-quick (regexp bound noerror)
1685 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
1686 but trashes match data and is faster for REGEXP that doesn't match often.
1687 This uses `verilog-scan' and text properties to ignore comments,
1688 so there may be a large up front penalty for the first search."
1690 (while (and (not pt)
1691 (re-search-forward regexp bound noerror))
1692 (if (verilog-inside-comment-or-string-p)
1693 (re-search-forward "[/\"\n]" nil t) ;; Only way a comment or quote can end
1694 (setq pt (match-end 0))))
1697 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
1698 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1699 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
1700 but trashes match data and is faster for REGEXP that doesn't match often.
1701 This uses `verilog-scan' and text properties to ignore comments,
1702 so there may be a large up front penalty for the first search."
1704 (while (and (not pt)
1705 (re-search-backward regexp bound noerror))
1706 (if (verilog-inside-comment-or-string-p)
1707 (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
1708 (setq pt (match-beginning 0))))
1711 (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
1712 "Like `re-search-forward', but first search for SUBSTR constant.
1713 Then searched for the normal REGEXP (which contains SUBSTR), with given
1714 BOUND and NOERROR. The REGEXP must fit within a single line.
1715 This speeds up complicated regexp matches."
1716 ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
1717 ;; thus require matches to be on one line, and use beginning-of-line.
1719 (while (and (not done)
1720 (search-forward substr bound noerror))
1723 (setq done (re-search-forward regexp (point-at-eol) noerror)))
1724 (unless (and (<= (match-beginning 0) (point))
1725 (>= (match-end 0) (point)))
1727 (when done (goto-char done))
1729 ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1731 (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
1732 "Like `re-search-backward', but first search for SUBSTR constant.
1733 Then searched for the normal REGEXP (which contains SUBSTR), with given
1734 BOUND and NOERROR. The REGEXP must fit within a single line.
1735 This speeds up complicated regexp matches."
1736 ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
1737 ;; thus require matches to be on one line, and use beginning-of-line.
1739 (while (and (not done)
1740 (search-backward substr bound noerror))
1743 (setq done (re-search-backward regexp (point-at-bol) noerror)))
1744 (unless (and (<= (match-beginning 0) (point))
1745 (>= (match-end 0) (point)))
1747 (when done (goto-char done))
1749 ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1751 (defun verilog-delete-trailing-whitespace ()
1752 "Delete trailing spaces or tabs, but not newlines nor linefeeds.
1753 Also add missing final newline.
1755 To call this from the command line, see \\[verilog-batch-diff-auto].
1757 To call on \\[verilog-auto], set `verilog-auto-delete-trailing-whitespace'."
1758 ;; Similar to `delete-trailing-whitespace' but that's not present in XEmacs
1760 (goto-char (point-min))
1761 (while (re-search-forward "[ \t]+$" nil t) ;; Not syntactic WS as no formfeed
1762 (replace-match "" nil nil))
1763 (goto-char (point-max))
1764 (unless (bolp) (insert "\n"))))
1766 (defvar compile-command)
1767 (defvar create-lockfiles) ;; Emacs 24
1769 ;; compilation program
1770 (defun verilog-set-compile-command ()
1771 "Function to compute shell command to compile Verilog.
1773 This reads `verilog-tool' and sets `compile-command'. This specifies the
1774 program that executes when you type \\[compile] or
1775 \\[verilog-auto-save-compile].
1777 By default `verilog-tool' uses a Makefile if one exists in the
1778 current directory. If not, it is set to the `verilog-linter',
1779 `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
1780 or `verilog-simulator' variables, as selected with the Verilog ->
1781 \"Choose Compilation Action\" menu.
1783 You should set `verilog-tool' or the other variables to the path and
1784 arguments for your Verilog simulator. For example:
1787 \"(cd /tmp; surecov %s)\".
1789 In the former case, the path to the current buffer is concat'ed to the
1790 value of `verilog-tool'; in the later, the path to the current buffer is
1791 substituted for the %s.
1793 Where __FLAGS__ appears in the string `verilog-current-flags'
1794 will be substituted.
1796 Where __FILE__ appears in the string, the variable
1797 `buffer-file-name' of the current buffer, without the directory
1798 portion, will be substituted."
1801 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1802 (file-exists-p "Makefile"))
1803 (set (make-local-variable 'compile-command) "make "))
1805 (set (make-local-variable 'compile-command)
1807 (if (string-match "%s" (eval verilog-tool))
1808 (format (eval verilog-tool) (or buffer-file-name ""))
1809 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1811 (verilog-modify-compile-command))
1813 (defun verilog-expand-command (command)
1814 "Replace meta-information in COMMAND and return it.
1815 Where __FLAGS__ appears in the string `verilog-current-flags'
1816 will be substituted. Where __FILE__ appears in the string, the
1817 current buffer's file-name, without the directory portion, will
1819 (setq command (verilog-string-replace-matches
1820 ;; Note \\b only works if under verilog syntax table
1821 "\\b__FLAGS__\\b" (verilog-current-flags)
1823 (setq command (verilog-string-replace-matches
1824 "\\b__FILE__\\b" (file-name-nondirectory
1825 (or (buffer-file-name) ""))
1829 (defun verilog-modify-compile-command ()
1830 "Update `compile-command' using `verilog-expand-command'."
1832 (stringp compile-command)
1833 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1834 (set (make-local-variable 'compile-command)
1835 (verilog-expand-command compile-command))))
1837 (if (featurep 'xemacs)
1838 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1839 (defun verilog-error-regexp-add-xemacs ()
1840 "Teach XEmacs about verilog errors.
1841 Called by `compilation-mode-hook'. This allows \\[next-error] to
1844 (if (boundp 'compilation-error-regexp-systems-alist)
1846 (not (equal compilation-error-regexp-systems-list 'all))
1847 (not (member compilation-error-regexp-systems-list 'verilog)))
1848 (push 'verilog compilation-error-regexp-systems-list)))
1849 (if (boundp 'compilation-error-regexp-alist-alist)
1850 (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
1851 (setcdr compilation-error-regexp-alist-alist
1852 (cons verilog-error-regexp-xemacs-alist
1853 (cdr compilation-error-regexp-alist-alist)))))
1854 (if (boundp 'compilation-font-lock-keywords)
1856 (set (make-local-variable 'compilation-font-lock-keywords)
1857 verilog-error-font-lock-keywords)
1858 (font-lock-set-defaults)))
1859 ;; Need to re-run compilation-error-regexp builder
1860 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
1861 (compilation-build-compilation-error-regexp-alist))
1864 ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
1865 (defun verilog-error-regexp-add-emacs ()
1866 "Tell Emacs compile that we are Verilog.
1867 Called by `compilation-mode-hook'. This allows \\[next-error] to
1870 (if (boundp 'compilation-error-regexp-alist-alist)
1872 (if (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
1875 (push (car item) compilation-error-regexp-alist)
1876 (push item compilation-error-regexp-alist-alist)
1878 verilog-error-regexp-emacs-alist)))))
1880 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
1881 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
1883 (defconst verilog-directive-re
1885 (verilog-regexp-words
1887 "`case" "`default" "`define" "`else" "`elsif" "`endfor" "`endif"
1888 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
1889 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
1890 "`time_scale" "`undef" "`while" ))))
1892 (defconst verilog-directive-re-1
1893 (concat "[ \t]*" verilog-directive-re))
1895 (defconst verilog-directive-begin
1896 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
1898 (defconst verilog-directive-middle
1899 "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
1901 (defconst verilog-directive-end
1902 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
1904 (defconst verilog-ovm-begin-re
1908 "`ovm_component_utils_begin"
1909 "`ovm_component_param_utils_begin"
1910 "`ovm_field_utils_begin"
1911 "`ovm_object_utils_begin"
1912 "`ovm_object_param_utils_begin"
1913 "`ovm_sequence_utils_begin"
1914 "`ovm_sequencer_utils_begin"
1917 (defconst verilog-ovm-end-re
1921 "`ovm_component_utils_end"
1922 "`ovm_field_utils_end"
1923 "`ovm_object_utils_end"
1924 "`ovm_sequence_utils_end"
1925 "`ovm_sequencer_utils_end"
1928 (defconst verilog-uvm-begin-re
1932 "`uvm_component_utils_begin"
1933 "`uvm_component_param_utils_begin"
1934 "`uvm_field_utils_begin"
1935 "`uvm_object_utils_begin"
1936 "`uvm_object_param_utils_begin"
1937 "`uvm_sequence_utils_begin"
1938 "`uvm_sequencer_utils_begin"
1941 (defconst verilog-uvm-end-re
1945 "`uvm_component_utils_end"
1946 "`uvm_field_utils_end"
1947 "`uvm_object_utils_end"
1948 "`uvm_sequence_utils_end"
1949 "`uvm_sequencer_utils_end"
1952 (defconst verilog-vmm-begin-re
1956 "`vmm_data_member_begin"
1957 "`vmm_env_member_begin"
1958 "`vmm_scenario_member_begin"
1959 "`vmm_subenv_member_begin"
1960 "`vmm_xactor_member_begin"
1963 (defconst verilog-vmm-end-re
1967 "`vmm_data_member_end"
1968 "`vmm_env_member_end"
1969 "`vmm_scenario_member_end"
1970 "`vmm_subenv_member_end"
1971 "`vmm_xactor_member_end"
1974 (defconst verilog-vmm-statement-re
1978 ;; "`vmm_xactor_member_enum_array"
1979 "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
1980 ;; "`vmm_xactor_member_scalar_array"
1981 ;; "`vmm_xactor_member_scalar"
1984 (defconst verilog-ovm-statement-re
1993 "`ovm_analysis_imp_decl"
1994 "`ovm_blocking_get_imp_decl"
1995 "`ovm_blocking_get_peek_imp_decl"
1996 "`ovm_blocking_master_imp_decl"
1997 "`ovm_blocking_peek_imp_decl"
1998 "`ovm_blocking_put_imp_decl"
1999 "`ovm_blocking_slave_imp_decl"
2000 "`ovm_blocking_transport_imp_decl"
2001 "`ovm_component_registry"
2002 "`ovm_component_registry_param"
2003 "`ovm_component_utils"
2006 "`ovm_declare_sequence_lib"
2013 "`ovm_field_aa_int_byte"
2014 "`ovm_field_aa_int_byte_unsigned"
2015 "`ovm_field_aa_int_int"
2016 "`ovm_field_aa_int_int_unsigned"
2017 "`ovm_field_aa_int_integer"
2018 "`ovm_field_aa_int_integer_unsigned"
2019 "`ovm_field_aa_int_key"
2020 "`ovm_field_aa_int_longint"
2021 "`ovm_field_aa_int_longint_unsigned"
2022 "`ovm_field_aa_int_shortint"
2023 "`ovm_field_aa_int_shortint_unsigned"
2024 "`ovm_field_aa_int_string"
2025 "`ovm_field_aa_object_int"
2026 "`ovm_field_aa_object_string"
2027 "`ovm_field_aa_string_int"
2028 "`ovm_field_aa_string_string"
2029 "`ovm_field_array_int"
2030 "`ovm_field_array_object"
2031 "`ovm_field_array_string"
2036 "`ovm_field_queue_int"
2037 "`ovm_field_queue_object"
2038 "`ovm_field_queue_string"
2039 "`ovm_field_sarray_int"
2044 "`ovm_get_peek_imp_decl"
2051 "`ovm_master_imp_decl"
2053 "`ovm_non_blocking_transport_imp_decl"
2054 "`ovm_nonblocking_get_imp_decl"
2055 "`ovm_nonblocking_get_peek_imp_decl"
2056 "`ovm_nonblocking_master_imp_decl"
2057 "`ovm_nonblocking_peek_imp_decl"
2058 "`ovm_nonblocking_put_imp_decl"
2059 "`ovm_nonblocking_slave_imp_decl"
2060 "`ovm_object_registry"
2061 "`ovm_object_registry_param"
2063 "`ovm_peek_imp_decl"
2064 "`ovm_phase_func_decl"
2065 "`ovm_phase_task_decl"
2066 "`ovm_print_aa_int_object"
2067 "`ovm_print_aa_string_int"
2068 "`ovm_print_aa_string_object"
2069 "`ovm_print_aa_string_string"
2070 "`ovm_print_array_int"
2071 "`ovm_print_array_object"
2072 "`ovm_print_array_string"
2073 "`ovm_print_object_queue"
2074 "`ovm_print_queue_int"
2075 "`ovm_print_string_queue"
2078 "`ovm_rand_send_with"
2080 "`ovm_sequence_utils"
2081 "`ovm_slave_imp_decl"
2082 "`ovm_transport_imp_decl"
2083 "`ovm_update_sequence_lib"
2084 "`ovm_update_sequence_lib_and_item"
2087 "`static_message") nil )))
2089 (defconst verilog-uvm-statement-re
2094 "`uvm_analysis_imp_decl"
2095 "`uvm_blocking_get_imp_decl"
2096 "`uvm_blocking_get_peek_imp_decl"
2097 "`uvm_blocking_master_imp_decl"
2098 "`uvm_blocking_peek_imp_decl"
2099 "`uvm_blocking_put_imp_decl"
2100 "`uvm_blocking_slave_imp_decl"
2101 "`uvm_blocking_transport_imp_decl"
2102 "`uvm_component_param_utils"
2103 "`uvm_component_registry"
2104 "`uvm_component_registry_param"
2105 "`uvm_component_utils"
2108 "`uvm_create_seq" ;; Undocumented in 1.1
2109 "`uvm_declare_p_sequencer"
2110 "`uvm_declare_sequence_lib" ;; Deprecated in 1.1
2113 "`uvm_do_callbacks_exit_on"
2114 "`uvm_do_obj_callbacks"
2115 "`uvm_do_obj_callbacks_exit_on"
2118 "`uvm_do_on_pri_with"
2122 "`uvm_do_seq" ;; Undocumented in 1.1
2123 "`uvm_do_seq_with" ;; Undocumented in 1.1
2126 "`uvm_error_context"
2128 "`uvm_fatal_context"
2129 "`uvm_field_aa_int_byte"
2130 "`uvm_field_aa_int_byte_unsigned"
2131 "`uvm_field_aa_int_enum"
2132 "`uvm_field_aa_int_int"
2133 "`uvm_field_aa_int_int_unsigned"
2134 "`uvm_field_aa_int_integer"
2135 "`uvm_field_aa_int_integer_unsigned"
2136 "`uvm_field_aa_int_key"
2137 "`uvm_field_aa_int_longint"
2138 "`uvm_field_aa_int_longint_unsigned"
2139 "`uvm_field_aa_int_shortint"
2140 "`uvm_field_aa_int_shortint_unsigned"
2141 "`uvm_field_aa_int_string"
2142 "`uvm_field_aa_object_int"
2143 "`uvm_field_aa_object_string"
2144 "`uvm_field_aa_string_int"
2145 "`uvm_field_aa_string_string"
2146 "`uvm_field_array_enum"
2147 "`uvm_field_array_int"
2148 "`uvm_field_array_object"
2149 "`uvm_field_array_string"
2154 "`uvm_field_queue_enum"
2155 "`uvm_field_queue_int"
2156 "`uvm_field_queue_object"
2157 "`uvm_field_queue_string"
2159 "`uvm_field_sarray_enum"
2160 "`uvm_field_sarray_int"
2161 "`uvm_field_sarray_object"
2162 "`uvm_field_sarray_string"
2165 "`uvm_file" ;; Undocumented in 1.1, use `__FILE__
2167 "`uvm_get_peek_imp_decl"
2170 "`uvm_line" ;; Undocumented in 1.1, use `__LINE__
2171 "`uvm_master_imp_decl"
2172 "`uvm_non_blocking_transport_imp_decl" ;; Deprecated in 1.1
2173 "`uvm_nonblocking_get_imp_decl"
2174 "`uvm_nonblocking_get_peek_imp_decl"
2175 "`uvm_nonblocking_master_imp_decl"
2176 "`uvm_nonblocking_peek_imp_decl"
2177 "`uvm_nonblocking_put_imp_decl"
2178 "`uvm_nonblocking_slave_imp_decl"
2179 "`uvm_nonblocking_transport_imp_decl"
2180 "`uvm_object_param_utils"
2181 "`uvm_object_registry"
2182 "`uvm_object_registry_param" ;; Undocumented in 1.1
2196 "`uvm_peek_imp_decl"
2199 "`uvm_rand_send_pri"
2200 "`uvm_rand_send_pri_with"
2201 "`uvm_rand_send_with"
2202 "`uvm_record_attribute"
2207 "`uvm_sequence_utils" ;; Deprecated in 1.1
2208 "`uvm_set_super_type"
2209 "`uvm_slave_imp_decl"
2210 "`uvm_transport_imp_decl"
2212 "`uvm_unpack_arrayN"
2218 "`uvm_unpack_queueN"
2220 "`uvm_unpack_sarray"
2221 "`uvm_unpack_sarrayN"
2222 "`uvm_unpack_string"
2223 "`uvm_update_sequence_lib" ;; Deprecated in 1.1
2224 "`uvm_update_sequence_lib_and_item" ;; Deprecated in 1.1
2226 "`uvm_warning_context") nil )))
2230 ;; Regular expressions used to calculate indent, etc.
2232 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
2239 (defconst verilog-assignment-operator-re
2243 ;; blocking assignment_operator
2244 "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
2245 ;; non blocking assignment operator
2248 "==" "!=" "===" "!===" "<=" ">=" "==\?" "!=\?"
2253 ;; Is this a legal verilog operator?
2257 (defconst verilog-assignment-operation-re
2259 ; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)"
2260 ; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)"
2261 "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" ))
2263 (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
2264 (defconst verilog-property-re
2265 (concat "\\(" verilog-label-re "\\)?"
2266 "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
2267 ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
2269 (defconst verilog-no-indent-begin-re
2271 (verilog-regexp-words
2272 '( "if" "else" "while" "for" "repeat" "always" "always_comb" "always_ff" "always_latch"
2273 "initial" "final"))))
2275 (defconst verilog-ends-re
2276 ;; Parenthesis indicate type of keyword found
2278 "\\(\\<else\\>\\)\\|" ; 1
2279 "\\(\\<if\\>\\)\\|" ; 2
2280 "\\(\\<assert\\>\\)\\|" ; 3
2281 "\\(\\<end\\>\\)\\|" ; 3.1
2282 "\\(\\<endcase\\>\\)\\|" ; 4
2283 "\\(\\<endfunction\\>\\)\\|" ; 5
2284 "\\(\\<endtask\\>\\)\\|" ; 6
2285 "\\(\\<endspecify\\>\\)\\|" ; 7
2286 "\\(\\<endtable\\>\\)\\|" ; 8
2287 "\\(\\<endgenerate\\>\\)\\|" ; 9
2288 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
2289 "\\(\\<endclass\\>\\)\\|" ; 11
2290 "\\(\\<endgroup\\>\\)\\|" ; 12
2292 "\\(\\<`vmm_data_member_end\\>\\)\\|"
2293 "\\(\\<`vmm_env_member_end\\>\\)\\|"
2294 "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
2295 "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
2296 "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
2298 "\\(\\<`ovm_component_utils_end\\>\\)\\|"
2299 "\\(\\<`ovm_field_utils_end\\>\\)\\|"
2300 "\\(\\<`ovm_object_utils_end\\>\\)\\|"
2301 "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
2302 "\\(\\<`ovm_sequencer_utils_end\\>\\)"
2304 "\\(\\<`uvm_component_utils_end\\>\\)\\|"
2305 "\\(\\<`uvm_field_utils_end\\>\\)\\|"
2306 "\\(\\<`uvm_object_utils_end\\>\\)\\|"
2307 "\\(\\<`uvm_sequence_utils_end\\>\\)\\|"
2308 "\\(\\<`uvm_sequencer_utils_end\\>\\)"
2311 (defconst verilog-auto-end-comment-lines-re
2312 ;; Matches to names in this list cause auto-end-commenting
2314 verilog-directive-re "\\)\\|\\("
2316 (verilog-regexp-words
2344 ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
2345 ;;; verilog-end-block-ordered-re matches exactly the same strings.
2346 (defconst verilog-end-block-ordered-re
2347 ;; Parenthesis indicate type of keyword found
2348 (concat "\\(\\<endcase\\>\\)\\|" ; 1
2349 "\\(\\<end\\>\\)\\|" ; 2
2350 "\\(\\<end" ; 3, but not used
2351 "\\(" ; 4, but not used
2352 "\\(function\\)\\|" ; 5
2354 "\\(module\\)\\|" ; 7
2355 "\\(primitive\\)\\|" ; 8
2356 "\\(interface\\)\\|" ; 9
2357 "\\(package\\)\\|" ; 10
2358 "\\(class\\)\\|" ; 11
2359 "\\(group\\)\\|" ; 12
2360 "\\(program\\)\\|" ; 13
2361 "\\(sequence\\)\\|" ; 14
2362 "\\(clocking\\)\\|" ; 15
2364 (defconst verilog-end-block-re
2366 (verilog-regexp-words
2368 `("end" ;; closes begin
2369 "endcase" ;; closes any of case, casex casez or randcase
2370 "join" "join_any" "join_none" ;; closes fork
2385 "`ovm_component_utils_end"
2386 "`ovm_field_utils_end"
2387 "`ovm_object_utils_end"
2388 "`ovm_sequence_utils_end"
2389 "`ovm_sequencer_utils_end"
2391 "`uvm_component_utils_end"
2392 "`uvm_field_utils_end"
2393 "`uvm_object_utils_end"
2394 "`uvm_sequence_utils_end"
2395 "`uvm_sequencer_utils_end"
2397 "`vmm_data_member_end"
2398 "`vmm_env_member_end"
2399 "`vmm_scenario_member_end"
2400 "`vmm_subenv_member_end"
2401 "`vmm_xactor_member_end"
2405 (defconst verilog-endcomment-reason-re
2406 ;; Parenthesis indicate type of keyword found
2408 "\\(\\<begin\\>\\)\\|" ; 1
2409 "\\(\\<else\\>\\)\\|" ; 2
2410 "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
2411 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" ; 4
2412 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" ; 5
2413 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" ; 6
2414 "\\(\\<fork\\>\\)\\|" ; 7
2415 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
2417 verilog-property-re "\\|"
2418 "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
2419 "\\(\\<clocking\\>\\)\\|"
2420 "\\(\\<task\\>\\)\\|"
2421 "\\(\\<function\\>\\)\\|"
2422 "\\(\\<initial\\>\\)\\|"
2423 "\\(\\<interface\\>\\)\\|"
2424 "\\(\\<package\\>\\)\\|"
2425 "\\(\\<final\\>\\)\\|"
2427 "\\(\\<while\\>\\)\\|"
2428 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
2429 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
2432 (defconst verilog-named-block-re "begin[ \t]*:")
2434 ;; These words begin a block which can occur inside a module which should be indented,
2435 ;; and closed with the respective word from the end-block list
2437 (defconst verilog-beg-block-re
2439 (verilog-regexp-words
2441 "case" "casex" "casez" "randcase"
2451 "`ovm_component_utils_begin"
2452 "`ovm_component_param_utils_begin"
2453 "`ovm_field_utils_begin"
2454 "`ovm_object_utils_begin"
2455 "`ovm_object_param_utils_begin"
2456 "`ovm_sequence_utils_begin"
2457 "`ovm_sequencer_utils_begin"
2459 "`uvm_component_utils_begin"
2460 "`uvm_component_param_utils_begin"
2461 "`uvm_field_utils_begin"
2462 "`uvm_object_utils_begin"
2463 "`uvm_object_param_utils_begin"
2464 "`uvm_sequence_utils_begin"
2465 "`uvm_sequencer_utils_begin"
2467 "`vmm_data_member_begin"
2468 "`vmm_env_member_begin"
2469 "`vmm_scenario_member_begin"
2470 "`vmm_subenv_member_begin"
2471 "`vmm_xactor_member_begin"
2473 ;; These are the same words, in a specific order in the regular
2474 ;; expression so that matching will work nicely for
2475 ;; verilog-forward-sexp and verilog-calc-indent
2476 (defconst verilog-beg-block-re-ordered
2477 ( concat "\\(\\<begin\\>\\)" ;1
2478 "\\|\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
2479 "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
2480 "\\|\\(\\<class\\>\\)" ;6
2481 "\\|\\(\\<table\\>\\)" ;7
2482 "\\|\\(\\<specify\\>\\)" ;8
2483 "\\|\\(\\<function\\>\\)" ;9
2484 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<function\\>\\)" ;10
2485 "\\|\\(\\<task\\>\\)" ;14
2486 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;15
2487 "\\|\\(\\<generate\\>\\)" ;18
2488 "\\|\\(\\<covergroup\\>\\)" ;16 20
2489 "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17 21
2490 "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25
2491 "\\|\\(\\<clocking\\>\\)" ;22 27
2492 "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;28
2493 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
2497 (defconst verilog-end-block-ordered-rry
2498 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2499 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
2500 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2501 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
2502 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
2503 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
2504 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
2505 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
2506 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
2507 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
2508 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
2509 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
2510 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
2513 (defconst verilog-nameable-item-re
2515 (verilog-regexp-words
2518 "join" "join_any" "join_none"
2535 (defconst verilog-declaration-opener
2537 (verilog-regexp-words
2538 `("module" "begin" "task" "function"))))
2540 (defconst verilog-declaration-prefix-re
2542 (verilog-regexp-words
2545 "inout" "input" "output" "ref"
2547 "const" "static" "protected" "local"
2549 "localparam" "parameter" "var"
2553 (defconst verilog-declaration-core-re
2555 (verilog-regexp-words
2557 ;; port direction (by themselves)
2558 "inout" "input" "output"
2559 ;; integer_atom_type
2560 "byte" "shortint" "int" "longint" "integer" "time"
2561 ;; integer_vector_type
2564 "shortreal" "real" "realtime"
2566 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
2568 "string" "event" "chandle" "virtual" "enum" "genvar"
2571 "mailbox" "semaphore"
2573 (defconst verilog-declaration-re
2574 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
2575 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
2576 (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?")
2577 (defconst verilog-optional-signed-range-re
2579 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
2580 (defconst verilog-macroexp-re "`\\sw+")
2582 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
2583 (defconst verilog-declaration-re-2-no-macro
2584 (concat "\\s-*" verilog-declaration-re
2585 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2587 (defconst verilog-declaration-re-2-macro
2588 (concat "\\s-*" verilog-declaration-re
2589 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2590 "\\|\\(" verilog-macroexp-re "\\)"
2592 (defconst verilog-declaration-re-1-macro
2593 (concat "^" verilog-declaration-re-2-macro))
2595 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
2597 (defconst verilog-defun-re
2598 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
2599 (defconst verilog-end-defun-re
2600 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
2601 (defconst verilog-zero-indent-re
2602 (concat verilog-defun-re "\\|" verilog-end-defun-re))
2603 (defconst verilog-inst-comment-re
2604 (eval-when-compile (verilog-regexp-words `("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced"))))
2606 (defconst verilog-behavioral-block-beg-re
2607 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
2608 "function" "task"))))
2609 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
2610 (defconst verilog-in-constraint-re ;; keywords legal in constraint blocks starting a statement/block
2611 (eval-when-compile (verilog-regexp-words `("if" "else" "solve" "foreach"))))
2613 (defconst verilog-indent-re
2615 (verilog-regexp-words
2618 "always" "always_latch" "always_ff" "always_comb"
2620 ; "unique" "priority"
2621 "case" "casex" "casez" "randcase" "endcase"
2623 "clocking" "endclocking"
2624 "config" "endconfig"
2625 "covergroup" "endgroup"
2626 "fork" "join" "join_any" "join_none"
2627 "function" "endfunction"
2629 "generate" "endgenerate"
2631 "interface" "endinterface"
2632 "module" "macromodule" "endmodule"
2633 "package" "endpackage"
2634 "primitive" "endprimitive"
2635 "program" "endprogram"
2636 "property" "endproperty"
2637 "sequence" "randsequence" "endsequence"
2638 "specify" "endspecify"
2645 "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
2646 "`while" "`endwhile"
2651 "`protect" "`endprotect"
2652 "`switch" "`endswitch"
2656 "`ovm_component_utils_begin"
2657 "`ovm_component_param_utils_begin"
2658 "`ovm_field_utils_begin"
2659 "`ovm_object_utils_begin"
2660 "`ovm_object_param_utils_begin"
2661 "`ovm_sequence_utils_begin"
2662 "`ovm_sequencer_utils_begin"
2664 "`ovm_component_utils_end"
2665 "`ovm_field_utils_end"
2666 "`ovm_object_utils_end"
2667 "`ovm_sequence_utils_end"
2668 "`ovm_sequencer_utils_end"
2670 "`uvm_component_utils_begin"
2671 "`uvm_component_param_utils_begin"
2672 "`uvm_field_utils_begin"
2673 "`uvm_object_utils_begin"
2674 "`uvm_object_param_utils_begin"
2675 "`uvm_sequence_utils_begin"
2676 "`uvm_sequencer_utils_begin"
2678 "`uvm_component_utils_end" ;; Typo in spec, it's not uvm_component_end
2679 "`uvm_field_utils_end"
2680 "`uvm_object_utils_end"
2681 "`uvm_sequence_utils_end"
2682 "`uvm_sequencer_utils_end"
2684 "`vmm_data_member_begin"
2685 "`vmm_env_member_begin"
2686 "`vmm_scenario_member_begin"
2687 "`vmm_subenv_member_begin"
2688 "`vmm_xactor_member_begin"
2690 "`vmm_data_member_end"
2691 "`vmm_env_member_end"
2692 "`vmm_scenario_member_end"
2693 "`vmm_subenv_member_end"
2694 "`vmm_xactor_member_end"
2697 (defconst verilog-defun-level-not-generate-re
2699 (verilog-regexp-words
2700 `( "module" "macromodule" "primitive" "class" "program"
2701 "interface" "package" "config"))))
2703 (defconst verilog-defun-level-re
2705 (verilog-regexp-words
2707 `( "module" "macromodule" "primitive" "class" "program"
2708 "interface" "package" "config")
2709 `( "initial" "final" "always" "always_comb" "always_ff"
2710 "always_latch" "endtask" "endfunction" )))))
2712 (defconst verilog-defun-level-generate-only-re
2714 (verilog-regexp-words
2715 `( "initial" "final" "always" "always_comb" "always_ff"
2716 "always_latch" "endtask" "endfunction" ))))
2718 (defconst verilog-cpp-level-re
2720 (verilog-regexp-words
2722 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2724 (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
2725 (defconst verilog-extended-case-re "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
2726 (defconst verilog-extended-complete-re
2727 (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
2728 "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
2729 "\\|\\(\\(\\<import\\>\\s-+\\)?\\(\"DPI-C\"\\s-+\\)?\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-+=\\s-+\\)?\\(function\\>\\|task\\>\\)\\)"
2730 "\\|" verilog-extended-case-re ))
2731 (defconst verilog-basic-complete-re
2733 (verilog-regexp-words
2735 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
2736 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
2737 "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
2739 (defconst verilog-complete-reg
2741 verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)"))
2743 (defconst verilog-end-statement-re
2744 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
2745 verilog-end-block-re "\\)"))
2747 (defconst verilog-endcase-re
2748 (concat verilog-extended-case-re "\\|"
2753 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
2754 "String used to mark beginning of excluded text.")
2755 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
2756 "String used to mark end of excluded text.")
2757 (defconst verilog-preprocessor-re
2759 (verilog-regexp-words
2761 "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else"
2764 (defconst verilog-keywords
2765 '( "`case" "`default" "`define" "`else" "`endfor" "`endif"
2766 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
2767 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
2768 "`time_scale" "`undef" "`while"
2770 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
2771 "assert" "assign" "assume" "automatic" "before" "begin" "bind"
2772 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
2773 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
2774 "config" "const" "constraint" "context" "continue" "cover"
2775 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
2776 "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
2777 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
2778 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
2779 "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
2780 "endtask" "enum" "event" "expect" "export" "extends" "extern"
2781 "final" "first_match" "for" "force" "foreach" "forever" "fork"
2782 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
2783 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
2784 "include" "initial" "inout" "input" "inside" "instance" "int"
2785 "integer" "interface" "intersect" "join" "join_any" "join_none"
2786 "large" "liblist" "library" "local" "localparam" "logic"
2787 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
2788 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
2789 "notif0" "notif1" "null" "or" "output" "package" "packed"
2790 "parameter" "pmos" "posedge" "primitive" "priority" "program"
2791 "property" "protected" "pull0" "pull1" "pulldown" "pullup"
2792 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2793 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
2794 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
2795 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
2796 "showcancelled" "signed" "small" "solve" "specify" "specparam"
2797 "static" "string" "strong0" "strong1" "struct" "super" "supply0"
2798 "supply1" "table" "tagged" "task" "this" "throughout" "time"
2799 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
2800 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
2801 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
2802 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
2803 "wire" "with" "within" "wor" "xnor" "xor"
2805 "accept_on" "checker" "endchecker" "eventually" "global" "implies"
2806 "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
2807 "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
2808 "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
2810 "implements" "interconnect" "nettype" "soft"
2812 "List of Verilog keywords.")
2814 (defconst verilog-comment-start-regexp "//\\|/\\*"
2815 "Dual comment value for `comment-start-regexp'.")
2817 (defvar verilog-mode-syntax-table
2818 (let ((table (make-syntax-table)))
2819 ;; Populate the syntax TABLE.
2820 (modify-syntax-entry ?\\ "\\" table)
2821 (modify-syntax-entry ?+ "." table)
2822 (modify-syntax-entry ?- "." table)
2823 (modify-syntax-entry ?= "." table)
2824 (modify-syntax-entry ?% "." table)
2825 (modify-syntax-entry ?< "." table)
2826 (modify-syntax-entry ?> "." table)
2827 (modify-syntax-entry ?& "." table)
2828 (modify-syntax-entry ?| "." table)
2829 ;; FIXME: This goes against Emacs conventions. Use "_" syntax instead and
2830 ;; then use regexps with things like "\\_<...\\_>".
2831 (modify-syntax-entry ?` "w" table) ;; ` is part of definition symbols in Verilog
2832 (modify-syntax-entry ?_ "w" table)
2833 (modify-syntax-entry ?\' "." table)
2835 ;; Set up TABLE to handle block and line style comments.
2836 (if (featurep 'xemacs)
2838 ;; XEmacs (formerly Lucid) has the best implementation
2839 (modify-syntax-entry ?/ ". 1456" table)
2840 (modify-syntax-entry ?* ". 23" table)
2841 (modify-syntax-entry ?\n "> b" table))
2842 ;; Emacs does things differently, but we can work with it
2843 (modify-syntax-entry ?/ ". 124b" table)
2844 (modify-syntax-entry ?* ". 23" table)
2845 (modify-syntax-entry ?\n "> b" table))
2847 "Syntax table used in Verilog mode buffers.")
2849 (defvar verilog-font-lock-keywords nil
2850 "Default highlighting for Verilog mode.")
2852 (defvar verilog-font-lock-keywords-1 nil
2853 "Subdued level highlighting for Verilog mode.")
2855 (defvar verilog-font-lock-keywords-2 nil
2856 "Medium level highlighting for Verilog mode.
2857 See also `verilog-font-lock-extra-types'.")
2859 (defvar verilog-font-lock-keywords-3 nil
2860 "Gaudy level highlighting for Verilog mode.
2861 See also `verilog-font-lock-extra-types'.")
2863 (defvar verilog-font-lock-translate-off-face
2864 'verilog-font-lock-translate-off-face
2865 "Font to use for translated off regions.")
2866 (defface verilog-font-lock-translate-off-face
2869 (:background "gray90" :italic t ))
2872 (:background "gray10" :italic t ))
2873 (((class grayscale) (background light))
2874 (:foreground "DimGray" :italic t))
2875 (((class grayscale) (background dark))
2876 (:foreground "LightGray" :italic t))
2878 "Font lock mode face used to background highlight translate-off regions."
2879 :group 'font-lock-highlighting-faces)
2881 (defvar verilog-font-lock-p1800-face
2882 'verilog-font-lock-p1800-face
2883 "Font to use for p1800 keywords.")
2884 (defface verilog-font-lock-p1800-face
2887 (:foreground "DarkOrange3" :bold t ))
2890 (:foreground "orange1" :bold t ))
2892 "Font lock mode face used to highlight P1800 keywords."
2893 :group 'font-lock-highlighting-faces)
2895 (defvar verilog-font-lock-ams-face
2896 'verilog-font-lock-ams-face
2897 "Font to use for Analog/Mixed Signal keywords.")
2898 (defface verilog-font-lock-ams-face
2901 (:foreground "Purple" :bold t ))
2904 (:foreground "orange1" :bold t ))
2906 "Font lock mode face used to highlight AMS keywords."
2907 :group 'font-lock-highlighting-faces)
2909 (defvar verilog-font-grouping-keywords-face
2910 'verilog-font-lock-grouping-keywords-face
2911 "Font to use for Verilog Grouping Keywords (such as begin..end).")
2912 (defface verilog-font-lock-grouping-keywords-face
2915 (:foreground "red4" :bold t ))
2918 (:foreground "red4" :bold t ))
2920 "Font lock mode face used to highlight verilog grouping keywords."
2921 :group 'font-lock-highlighting-faces)
2923 (let* ((verilog-type-font-keywords
2927 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
2928 "event" "genvar" "inout" "input" "integer" "localparam"
2929 "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" "notif1" "or"
2930 "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
2931 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
2932 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
2933 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
2934 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
2935 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
2938 (verilog-pragma-keywords
2941 '("surefire" "auto" "synopsys" "rtl_synthesis" "verilint" "leda" "0in"
2944 (verilog-1800-2005-keywords
2947 '("alias" "assert" "assume" "automatic" "before" "bind"
2948 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
2949 "clocking" "config" "const" "constraint" "context" "continue"
2950 "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
2951 "dist" "do" "edge" "endclass" "endclocking" "endconfig"
2952 "endgroup" "endprogram" "endproperty" "endsequence" "enum"
2953 "expect" "export" "extends" "extern" "first_match" "foreach"
2954 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
2955 "illegal_bins" "import" "incdir" "include" "inside" "instance"
2956 "int" "intersect" "large" "liblist" "library" "local" "longint"
2957 "matches" "medium" "modport" "new" "noshowcancelled" "null"
2958 "packed" "program" "property" "protected" "pull0" "pull1"
2959 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2960 "randcase" "randsequence" "ref" "release" "return" "scalared"
2961 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
2962 "specparam" "static" "string" "strong0" "strong1" "struct"
2963 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
2964 "type" "union" "unsigned" "use" "var" "virtual" "void"
2965 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
2968 (verilog-1800-2009-keywords
2971 '("accept_on" "checker" "endchecker" "eventually" "global"
2972 "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
2973 "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
2974 "sync_accept_on" "sync_reject_on" "unique0" "until"
2975 "until_with" "untyped" "weak" ) nil )))
2977 (verilog-1800-2012-keywords
2980 '("implements" "interconnect" "nettype" "soft" ) nil )))
2982 (verilog-ams-keywords
2985 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
2986 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
2987 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
2988 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
2989 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
2990 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
2991 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
2992 "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
2993 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
2994 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
2995 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
2997 (verilog-font-keywords
3001 "assign" "case" "casex" "casez" "randcase" "deassign"
3002 "default" "disable" "else" "endcase" "endfunction"
3003 "endgenerate" "endinterface" "endmodule" "endprimitive"
3004 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
3005 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
3006 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
3007 "package" "endpackage" "always" "always_comb" "always_ff"
3008 "always_latch" "posedge" "primitive" "priority" "release"
3009 "repeat" "specify" "table" "task" "unique" "wait" "while"
3010 "class" "program" "endclass" "endprogram"
3013 (verilog-font-grouping-keywords
3016 '( "begin" "end" ) nil ))))
3018 (setq verilog-font-lock-keywords
3020 ;; Fontify all builtin keywords
3021 (concat "\\<\\(" verilog-font-keywords "\\|"
3022 ;; And user/system tasks and functions
3023 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
3025 ;; Fontify all types
3026 (if verilog-highlight-grouping-keywords
3027 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
3028 'verilog-font-lock-ams-face)
3029 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
3030 'font-lock-type-face))
3031 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
3032 'font-lock-type-face)
3033 ;; Fontify IEEE-1800-2005 keywords appropriately
3034 (if verilog-highlight-p1800-keywords
3035 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
3036 'verilog-font-lock-p1800-face)
3037 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
3038 'font-lock-type-face))
3039 ;; Fontify IEEE-1800-2009 keywords appropriately
3040 (if verilog-highlight-p1800-keywords
3041 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
3042 'verilog-font-lock-p1800-face)
3043 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
3044 'font-lock-type-face))
3045 ;; Fontify IEEE-1800-2012 keywords appropriately
3046 (if verilog-highlight-p1800-keywords
3047 (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
3048 'verilog-font-lock-p1800-face)
3049 (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
3050 'font-lock-type-face))
3051 ;; Fontify Verilog-AMS keywords
3052 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
3053 'verilog-font-lock-ams-face)))
3055 (setq verilog-font-lock-keywords-1
3056 (append verilog-font-lock-keywords
3058 ;; Fontify module definitions
3060 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
3061 '(1 font-lock-keyword-face)
3062 '(3 font-lock-function-name-face 'prepend))
3063 ;; Fontify function definitions
3065 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
3066 '(1 font-lock-keyword-face)
3067 '(3 font-lock-constant-face prepend))
3068 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
3069 (1 font-lock-keyword-face)
3070 (2 font-lock-constant-face append))
3071 '("\\<function\\>\\s-+\\(\\sw+\\)"
3072 1 'font-lock-constant-face append))))
3074 (setq verilog-font-lock-keywords-2
3075 (append verilog-font-lock-keywords-1
3078 (concat "\\(//\\s-*\\(" verilog-pragma-keywords "\\)\\s-.*\\)")
3079 ;; Fontify escaped names
3080 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
3081 ;; Fontify macro definitions/ uses
3082 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
3083 'font-lock-preprocessor-face
3084 'font-lock-type-face))
3085 ;; Fontify delays/numbers
3086 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
3087 0 font-lock-type-face append)
3088 ;; Fontify instantiation names
3089 '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
3092 (setq verilog-font-lock-keywords-3
3093 (append verilog-font-lock-keywords-2
3094 (when verilog-highlight-translate-off
3096 ;; Fontify things in translate off regions
3097 '(verilog-match-translate-off
3098 (0 'verilog-font-lock-translate-off-face prepend))
3102 ;; Buffer state preservation
3104 (defmacro verilog-save-buffer-state (&rest body)
3105 "Execute BODY forms, saving state around insignificant change.
3106 Changes in text properties like `face' or `syntax-table' are
3107 considered insignificant. This macro allows text properties to
3108 be changed, even in a read-only buffer.
3110 A change is considered significant if it affects the buffer text
3111 in any way that isn't completely restored again. Any
3112 user-visible changes to the buffer must not be within a
3113 `verilog-save-buffer-state'."
3114 ;; From c-save-buffer-state
3115 `(let* ((modified (buffer-modified-p))
3116 (buffer-undo-list t)
3117 (inhibit-read-only t)
3118 (inhibit-point-motion-hooks t)
3119 (verilog-no-change-functions t)
3120 before-change-functions
3121 after-change-functions
3123 buffer-file-name ; Prevent primitives checking
3124 buffer-file-truename) ; for file modification
3129 (set-buffer-modified-p nil)))))
3131 (defmacro verilog-save-no-change-functions (&rest body)
3132 "Execute BODY forms, disabling all change hooks in BODY.
3133 For insignificant changes, see instead `verilog-save-buffer-state'."
3134 `(let* ((inhibit-point-motion-hooks t)
3135 (verilog-no-change-functions t)
3136 before-change-functions
3137 after-change-functions)
3140 (defvar verilog-save-font-mod-hooked nil
3141 "Local variable when inside a `verilog-save-font-mods' block.")
3142 (make-variable-buffer-local 'verilog-save-font-mod-hooked)
3144 (defmacro verilog-save-font-mods (&rest body)
3145 "Execute BODY forms, disabling text modifications to allow performing BODY.
3146 Includes temporary disabling of `font-lock' to restore the buffer
3147 to full text form for parsing. Additional actions may be specified with
3148 `verilog-before-save-font-hook' and `verilog-after-save-font-hook'."
3149 ;; Before version 20, match-string with font-lock returns a
3150 ;; vector that is not equal to the string. IE if on "input"
3151 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
3152 `(let* ((hooked (unless verilog-save-font-mod-hooked
3153 (verilog-run-hooks 'verilog-before-save-font-hook)
3155 (verilog-save-font-mod-hooked t)
3156 (fontlocked (when (and (boundp 'font-lock-mode) font-lock-mode)
3162 (when fontlocked (font-lock-mode t))
3163 (when hooked (verilog-run-hooks 'verilog-after-save-font-hook)))))
3166 ;; Comment detection and caching
3168 (defvar verilog-scan-cache-preserving nil
3169 "If true, the specified buffer's comment properties are static.
3170 Buffer changes will be ignored. See `verilog-inside-comment-or-string-p'
3171 and `verilog-scan'.")
3173 (defvar verilog-scan-cache-tick nil
3174 "Modification tick at which `verilog-scan' was last completed.")
3175 (make-variable-buffer-local 'verilog-scan-cache-tick)
3177 (defun verilog-scan-cache-flush ()
3178 "Flush the `verilog-scan' cache."
3179 (setq verilog-scan-cache-tick nil))
3181 (defun verilog-scan-cache-ok-p ()
3182 "Return t if the scan cache is up to date."
3183 (or (and verilog-scan-cache-preserving
3184 (eq verilog-scan-cache-preserving (current-buffer))
3185 verilog-scan-cache-tick)
3186 (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
3188 (defmacro verilog-save-scan-cache (&rest body)
3189 "Execute the BODY forms, allowing scan cache preservation within BODY.
3190 This requires that insertions must use `verilog-insert'."
3191 ;; If the buffer is out of date, trash it, as we'll not check later the tick
3192 ;; Note this must work properly if there's multiple layers of calls
3193 ;; to verilog-save-scan-cache even with differing ticks.
3195 (unless (verilog-scan-cache-ok-p) ;; Must be before let
3196 (setq verilog-scan-cache-tick nil))
3197 (let* ((verilog-scan-cache-preserving (current-buffer)))
3200 (defun verilog-scan-region (beg end)
3201 "Parse between BEG and END for `verilog-inside-comment-or-string-p'.
3202 This creates v-cmts properties where comments are in force."
3203 ;; Why properties and not overlays? Overlays have much slower non O(1)
3205 ;; This function is warm - called on every verilog-insert
3208 (verilog-save-buffer-state
3211 (while (< (point) end)
3212 (cond ((looking-at "//")
3214 (or (search-forward "\n" end t)
3216 ;; "1+": The leading // or /* itself isn't considered as
3217 ;; being "inside" the comment, so that a (search-backward)
3218 ;; that lands at the start of the // won't mis-indicate
3219 ;; it's inside a comment. Also otherwise it would be
3220 ;; hard to find a commented out /*AS*/ vs one that isn't
3221 (put-text-property (1+ pt) (point) 'v-cmts t))
3222 ((looking-at "/\\*")
3224 (or (search-forward "*/" end t)
3225 ;; No error - let later code indicate it so we can
3226 ;; use inside functions on-the-fly
3227 ;;(error "%s: Unmatched /* */, at char %d"
3228 ;; (verilog-point-text) (point))
3230 (put-text-property (1+ pt) (point) 'v-cmts t))
3233 (or (re-search-forward "[^\\]\"" end t) ;; don't forward-char first, since we look for a non backslash first
3234 ;; No error - let later code indicate it so we can
3236 (put-text-property (1+ pt) (point) 'v-cmts t))
3239 (if (re-search-forward "[/\"]" end t)
3241 (goto-char end))))))))))
3243 (defun verilog-scan ()
3244 "Parse the buffer, marking all comments with properties.
3245 Also assumes any text inserted since `verilog-scan-cache-tick'
3246 either is ok to parse as a non-comment, or `verilog-insert' was used."
3247 ;; See also `verilog-scan-debug' and `verilog-scan-and-debug'
3248 (unless (verilog-scan-cache-ok-p)
3250 (verilog-save-buffer-state
3252 (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
3253 verilog-scan-cache-preserving verilog-scan-cache-tick
3254 (buffer-chars-modified-tick)))
3255 (remove-text-properties (point-min) (point-max) '(v-cmts nil))
3256 (verilog-scan-region (point-min) (point-max))
3257 (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
3258 (when verilog-debug (message "Scanning... done"))))))
3260 (defun verilog-scan-debug ()
3261 "For debugging, show with display face results of `verilog-scan'."
3263 ;;(if dbg (setq dbg (concat dbg (format "verilog-scan-debug\n"))))
3265 (goto-char (point-min))
3266 (remove-text-properties (point-min) (point-max) '(face nil))
3268 (cond ((get-text-property (point) 'v-cmts)
3269 (put-text-property (point) (1+ (point)) `face 'underline)
3270 ;;(if dbg (setq dbg (concat dbg (format " v-cmts at %S\n" (point)))))
3273 (goto-char (or (next-property-change (point)) (point-max))))))))
3275 (defun verilog-scan-and-debug ()
3276 "For debugging, run `verilog-scan' and `verilog-scan-debug'."
3277 (let (verilog-scan-cache-preserving
3278 verilog-scan-cache-tick)
3279 (goto-char (point-min))
3281 (verilog-scan-debug)))
3283 (defun verilog-inside-comment-or-string-p (&optional pos)
3284 "Check if optional point POS is inside a comment.
3285 This may require a slow pre-parse of the buffer with `verilog-scan'
3286 to establish comment properties on all text."
3287 ;; This function is very hot
3290 (and (>= pos (point-min))
3291 (get-text-property pos 'v-cmts))
3292 (get-text-property (point) 'v-cmts)))
3294 (defun verilog-insert (&rest stuff)
3295 "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
3296 Any insert that includes a comment must have the entire comment
3297 inserted using a single call to `verilog-insert'."
3300 (insert (car stuff))
3301 (setq stuff (cdr stuff)))
3302 (verilog-scan-region pt (point))))
3306 (defun verilog-declaration-end ()
3307 (search-forward ";"))
3309 (defun verilog-point-text (&optional pointnum)
3310 "Return text describing where POINTNUM or current point is (for errors).
3311 Use filename, if current buffer being edited shorten to just buffer name."
3312 (concat (or (and (equal (window-buffer) (current-buffer))
3316 ":" (int-to-string (1+ (count-lines (point-min) (or pointnum (point)))))))
3318 (defun electric-verilog-backward-sexp ()
3319 "Move backward over one balanced expression."
3321 ;; before that see if we are in a comment
3322 (verilog-backward-sexp))
3324 (defun electric-verilog-forward-sexp ()
3325 "Move forward over one balanced expression."
3327 ;; before that see if we are in a comment
3328 (verilog-forward-sexp))
3330 ;;;used by hs-minor-mode
3331 (defun verilog-forward-sexp-function (arg)
3333 (verilog-backward-sexp)
3334 (verilog-forward-sexp)))
3337 (defun verilog-backward-sexp ()
3342 (if (not (looking-at "\\<"))
3345 ((verilog-skip-backward-comment-or-string))
3346 ((looking-at "\\<else\\>")
3348 verilog-end-block-re
3349 "\\|\\(\\<else\\>\\)"
3350 "\\|\\(\\<if\\>\\)"))
3351 (while (and (not found)
3352 (verilog-re-search-backward reg nil 'move))
3354 ((match-end 1) ; matched verilog-end-block-re
3355 ;; try to leap back to matching outward block by striding across
3356 ;; indent level changing tokens then immediately
3357 ;; previous line governs indentation.
3358 (verilog-leap-to-head))
3359 ((match-end 2) ; else, we're in deep
3360 (setq elsec (1+ elsec)))
3361 ((match-end 3) ; found it
3362 (setq elsec (1- elsec))
3364 ;; Now previous line describes syntax
3365 (setq found 't))))))
3366 ((looking-at verilog-end-block-re)
3367 (verilog-leap-to-head))
3368 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
3371 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
3373 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
3375 (verilog-re-search-backward "\\<class\\>" nil 'move))
3377 (verilog-re-search-backward "\\<program\\>" nil 'move))
3379 (verilog-re-search-backward "\\<interface\\>" nil 'move))
3381 (verilog-re-search-backward "\\<package\\>" nil 'move))
3384 (backward-sexp 1))))
3389 (defun verilog-forward-sexp ()
3394 (if (not (looking-at "\\<"))
3397 ((verilog-skip-forward-comment-or-string)
3398 (verilog-forward-syntactic-ws))
3399 ((looking-at verilog-beg-block-re-ordered)
3402 ;; Search forward for matching end
3403 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
3405 ;; Search forward for matching endcase
3406 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique0?\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
3407 (setq md 3) ;; ender is third item in regexp
3410 ;; might be "disable fork" or "wait fork"
3414 (looking-at verilog-disable-fork-re)
3415 (and (looking-at "fork")
3417 (setq here (point)) ;; sometimes a fork is just a fork
3419 (looking-at verilog-disable-fork-re))))
3420 (progn ;; it is a disable fork; ignore it
3421 (goto-char (match-end 0))
3424 (progn ;; it is a nice simple fork
3425 (goto-char here) ;; return from looking for "disable fork"
3426 ;; Search forward for matching join
3427 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))))
3429 ;; Search forward for matching endclass
3430 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
3433 ;; Search forward for matching endtable
3434 (setq reg "\\<endtable\\>" )
3437 ;; Search forward for matching endspecify
3438 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
3440 ;; Search forward for matching endfunction
3441 (setq reg "\\<endfunction\\>" )
3444 ;; Search forward for matching endfunction
3445 (setq reg "\\<endfunction\\>" )
3448 ;; Search forward for matching endtask
3449 (setq reg "\\<endtask\\>" )
3452 ;; Search forward for matching endtask
3453 (setq reg "\\<endtask\\>" )
3456 ;; Search forward for matching endgenerate
3457 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
3459 ;; Search forward for matching endgroup
3460 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
3462 ;; Search forward for matching endproperty
3463 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
3465 ;; Search forward for matching endsequence
3466 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
3467 (setq md 3)) ; 3 to get to endsequence in the reg above
3469 ;; Search forward for matching endclocking
3470 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
3477 (while (verilog-re-search-forward reg nil 'move)
3479 ((match-end md) ; a closer in regular expression, so we are climbing out
3480 (setq depth (1- depth))
3481 (if (= 0 depth) ; we are out!
3483 ((match-end 1) ; an opener in the r-e, so we are in deeper now
3484 (setq here (point)) ; remember where we started
3485 (goto-char (match-beginning 1))
3488 (looking-at verilog-disable-fork-re)
3489 (and (looking-at "fork")
3492 (looking-at verilog-disable-fork-re))))
3493 (progn ;; it is a disable fork; another false alarm
3494 (goto-char (match-end 0)))
3495 (progn ;; it is a simple fork (or has nothing to do with fork)
3497 (setq depth (1+ depth))))))))))
3498 (if (verilog-re-search-forward reg nil 'move)
3499 (throw 'skip 1))))))
3501 ((looking-at (concat
3502 "\\(\\<\\(macro\\)?module\\>\\)\\|"
3503 "\\(\\<primitive\\>\\)\\|"
3504 "\\(\\<class\\>\\)\\|"
3505 "\\(\\<program\\>\\)\\|"
3506 "\\(\\<interface\\>\\)\\|"
3507 "\\(\\<package\\>\\)"))
3510 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
3512 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
3514 (verilog-re-search-forward "\\<endclass\\>" nil 'move))
3516 (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
3518 (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
3520 (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
3523 (if (= (following-char) ?\) )
3525 (forward-sexp 1)))))
3528 (if (= (following-char) ?\) )
3530 (forward-sexp 1))))))
3532 (defun verilog-declaration-beg ()
3533 (verilog-re-search-backward verilog-declaration-re (bobp) t))
3539 (defvar verilog-which-tool 1)
3541 (define-derived-mode verilog-mode prog-mode "Verilog"
3542 "Major mode for editing Verilog code.
3543 \\<verilog-mode-map>
3544 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
3545 AUTOs can improve coding efficiency.
3547 Use \\[verilog-faq] for a pointer to frequently asked questions.
3549 NEWLINE, TAB indents for Verilog code.
3550 Delete converts tabs to spaces as it moves back.
3552 Supports highlighting.
3554 Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
3555 with no args, if that value is non-nil.
3557 Variables controlling indentation/edit style:
3559 variable `verilog-indent-level' (default 3)
3560 Indentation of Verilog statements with respect to containing block.
3561 `verilog-indent-level-module' (default 3)
3562 Absolute indentation of Module level Verilog statements.
3563 Set to 0 to get initial and always statements lined up
3564 on the left side of your screen.
3565 `verilog-indent-level-declaration' (default 3)
3566 Indentation of declarations with respect to containing block.
3567 Set to 0 to get them list right under containing block.
3568 `verilog-indent-level-behavioral' (default 3)
3569 Indentation of first begin in a task or function block
3570 Set to 0 to get such code to lined up underneath the task or
3572 `verilog-indent-level-directive' (default 1)
3573 Indentation of `ifdef/`endif blocks.
3574 `verilog-cexp-indent' (default 1)
3575 Indentation of Verilog statements broken across lines i.e.:
3578 `verilog-case-indent' (default 2)
3579 Indentation for case statements.
3580 `verilog-auto-newline' (default nil)
3581 Non-nil means automatically newline after semicolons and the punctuation
3583 `verilog-auto-indent-on-newline' (default t)
3584 Non-nil means automatically indent line after newline.
3585 `verilog-tab-always-indent' (default t)
3586 Non-nil means TAB in Verilog mode should always reindent the current line,
3587 regardless of where in the line point is when the TAB command is used.
3588 `verilog-indent-begin-after-if' (default t)
3589 Non-nil means to indent begin statements following a preceding
3590 if, else, while, for and repeat statements, if any. Otherwise,
3591 the begin is lined up with the preceding token. If t, you get:
3593 begin // amount of indent based on `verilog-cexp-indent'
3597 `verilog-auto-endcomments' (default t)
3598 Non-nil means a comment /* ... */ is set after the ends which ends
3599 cases, tasks, functions and modules.
3600 The type and name of the object will be set between the braces.
3601 `verilog-minimum-comment-distance' (default 10)
3602 Minimum distance (in lines) between begin and end required before a comment
3603 will be inserted. Setting this variable to zero results in every
3604 end acquiring a comment; the default avoids too many redundant
3605 comments in tight quarters.
3606 `verilog-auto-lineup' (default 'declarations)
3607 List of contexts where auto lineup of code should be done.
3609 Variables controlling other actions:
3611 `verilog-linter' (default surelint)
3612 Unix program to call to run the lint checker. This is the default
3613 command for \\[compile-command] and \\[verilog-auto-save-compile].
3615 See \\[customize] for the complete list of variables.
3617 AUTO expansion functions are, in part:
3619 \\[verilog-auto] Expand AUTO statements.
3620 \\[verilog-delete-auto] Remove the AUTOs.
3621 \\[verilog-inject-auto] Insert AUTOs for the first time.
3623 Some other functions are:
3625 \\[verilog-complete-word] Complete word with appropriate possibilities.
3626 \\[verilog-mark-defun] Mark function.
3627 \\[verilog-beg-of-defun] Move to beginning of current function.
3628 \\[verilog-end-of-defun] Move to end of current function.
3629 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
3631 \\[verilog-comment-region] Put marked area in a comment.
3632 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
3633 \\[verilog-insert-block] Insert begin ... end.
3634 \\[verilog-star-comment] Insert /* ... */.
3636 \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
3637 \\[verilog-sk-begin] Insert a begin .. end block.
3638 \\[verilog-sk-case] Insert a case block, prompting for details.
3639 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
3640 \\[verilog-sk-generate] Insert a generate .. endgenerate block.
3641 \\[verilog-sk-header] Insert a header block at the top of file.
3642 \\[verilog-sk-initial] Insert an initial begin .. end block.
3643 \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
3644 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
3645 \\[verilog-sk-ovm-class] Insert an OVM Class block.
3646 \\[verilog-sk-uvm-object] Insert an UVM Object block.
3647 \\[verilog-sk-uvm-component] Insert an UVM Component block.
3648 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
3649 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
3650 \\[verilog-sk-specify] Insert a specify .. endspecify block.
3651 \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
3652 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
3653 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
3654 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
3655 \\[verilog-sk-if] Insert an if (..) begin .. end block.
3656 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
3657 \\[verilog-sk-comment] Insert a comment block.
3658 \\[verilog-sk-assign] Insert an assign .. = ..; statement.
3659 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
3660 \\[verilog-sk-input] Insert an input declaration, prompting for details.
3661 \\[verilog-sk-output] Insert an output declaration, prompting for details.
3662 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
3663 \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
3664 \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
3665 \\[verilog-sk-reg] Insert a register declaration, prompting for details.
3666 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
3668 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
3669 Key bindings specific to `verilog-mode-map' are:
3671 \\{verilog-mode-map}"
3672 :abbrev-table verilog-mode-abbrev-table
3673 (set (make-local-variable 'beginning-of-defun-function)
3674 'verilog-beg-of-defun)
3675 (set (make-local-variable 'end-of-defun-function)
3676 'verilog-end-of-defun)
3677 (set-syntax-table verilog-mode-syntax-table)
3678 (set (make-local-variable 'indent-line-function)
3679 #'verilog-indent-line-relative)
3680 (set (make-local-variable 'comment-indent-function) 'verilog-comment-indent)
3681 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
3682 (set (make-local-variable 'comment-start) "// ")
3683 (set (make-local-variable 'comment-end) "")
3684 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
3685 (set (make-local-variable 'comment-multi-line) nil)
3686 ;; Set up for compilation
3687 (setq verilog-which-tool 1)
3688 (setq verilog-tool 'verilog-linter)
3689 (verilog-set-compile-command)
3690 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables
3691 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
3694 (when (featurep 'xemacs)
3695 (easy-menu-add verilog-stmt-menu)
3696 (easy-menu-add verilog-menu)
3697 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
3699 ;; Stuff for GNU Emacs
3700 (set (make-local-variable 'font-lock-defaults)
3701 `((verilog-font-lock-keywords
3702 verilog-font-lock-keywords-1
3703 verilog-font-lock-keywords-2
3704 verilog-font-lock-keywords-3)
3706 ,(if (functionp 'syntax-ppss)
3707 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
3708 ;; font-lock-beginning-of-syntax-function, so
3709 ;; font-lock-beginning-of-syntax-function, can't use
3710 ;; verilog-beg-of-defun.
3712 'verilog-beg-of-defun)))
3713 ;;------------------------------------------------------------
3714 ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
3715 ;; all buffer local:
3716 (unless noninteractive ;; Else can't see the result, and change hooks are slow
3717 (when (featurep 'xemacs)
3718 (make-local-hook 'font-lock-mode-hook)
3719 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
3720 (make-local-hook 'after-change-functions))
3721 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
3722 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
3723 (add-hook 'after-change-functions 'verilog-highlight-region t t))
3725 ;; Tell imenu how to handle Verilog.
3726 (set (make-local-variable 'imenu-generic-expression)
3727 verilog-imenu-generic-expression)
3728 ;; Tell which-func-modes that imenu knows about verilog
3729 (when (and (boundp 'which-func-modes) (listp which-func-modes))
3730 (add-to-list 'which-func-modes 'verilog-mode))
3732 (when (boundp 'hs-special-modes-alist)
3733 (unless (assq 'verilog-mode hs-special-modes-alist)
3734 (setq hs-special-modes-alist
3735 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
3736 verilog-forward-sexp-function)
3737 hs-special-modes-alist))))
3740 (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local)
3741 ;; verilog-mode-hook call added by define-derived-mode
3746 ;; Electric functions
3748 (defun electric-verilog-terminate-line (&optional arg)
3749 "Terminate line and indent next line.
3750 With optional ARG, remove existing end of line comments."
3752 ;; before that see if we are in a comment
3753 (let ((state (save-excursion (verilog-syntax-ppss))))
3755 ((nth 7 state) ; Inside // comment
3758 (delete-horizontal-space)
3763 (beginning-of-line)))
3764 (verilog-indent-line))
3765 ((nth 4 state) ; Inside any comment (hence /**/)
3767 (verilog-more-comment))
3769 ;; First, check if current line should be indented
3771 (delete-horizontal-space)
3773 (skip-chars-forward " \t")
3774 (if (looking-at verilog-auto-end-comment-lines-re)
3775 (let ((indent-str (verilog-indent-line)))
3776 ;; Maybe we should set some endcomments
3777 (if verilog-auto-endcomments
3778 (verilog-set-auto-endcomments indent-str arg))
3780 (delete-horizontal-space)
3787 (delete-horizontal-space)
3789 ;; see if we should line up assignments
3791 (if (or (eq 'all verilog-auto-lineup)
3792 (eq 'assignments verilog-auto-lineup))
3793 (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
3797 (if verilog-auto-indent-on-newline
3798 (verilog-indent-line)))
3802 (defun electric-verilog-terminate-and-indent ()
3803 "Insert a newline and indent for the next statement."
3805 (electric-verilog-terminate-line 1))
3807 (defun electric-verilog-semi ()
3808 "Insert `;' character and reindent the line."
3810 (verilog-insert-last-command-event)
3812 (if (or (verilog-in-comment-or-string-p)
3813 (verilog-in-escaped-name-p))
3817 (verilog-forward-ws&directives)
3818 (verilog-indent-line))
3819 (if (and verilog-auto-newline
3820 (not (verilog-parenthesis-depth)))
3821 (electric-verilog-terminate-line))))
3823 (defun electric-verilog-semi-with-comment ()
3824 "Insert `;' character, reindent the line and indent for comment."
3829 (verilog-indent-line))
3830 (indent-for-comment))
3832 (defun electric-verilog-colon ()
3833 "Insert `:' and do all indentations except line indent on this line."
3835 (verilog-insert-last-command-event)
3836 ;; Do nothing if within string.
3838 (verilog-within-string)
3839 (not (verilog-in-case-region-p)))
3843 (lim (progn (verilog-beg-of-statement) (point))))
3845 (verilog-backward-case-item lim)
3846 (verilog-indent-line)))
3847 ;; (let ((verilog-tab-always-indent nil))
3848 ;; (verilog-indent-line))
3851 ;;(defun electric-verilog-equal ()
3852 ;; "Insert `=', and do indentation if within block."
3854 ;; (verilog-insert-last-command-event)
3855 ;; Could auto line up expressions, but not yet
3856 ;; (if (eq (car (verilog-calculate-indent)) 'block)
3857 ;; (let ((verilog-tab-always-indent nil))
3858 ;; (verilog-indent-command)))
3861 (defun electric-verilog-tick ()
3862 "Insert back-tick, and indent to column 0 if this is a CPP directive."
3864 (verilog-insert-last-command-event)
3866 (if (verilog-in-directive-p)
3867 (verilog-indent-line))))
3869 (defun electric-verilog-tab ()
3870 "Function called when TAB is pressed in Verilog mode."
3872 ;; If verilog-tab-always-indent, indent the beginning of the line.
3874 ;; The region is active, indent it.
3875 ((and (region-active-p)
3876 (not (eq (region-beginning) (region-end))))
3877 (indent-region (region-beginning) (region-end) nil))
3878 ((or verilog-tab-always-indent
3880 (skip-chars-backward " \t")
3882 (let* ((oldpnt (point))
3886 (skip-chars-forward " \t")
3887 (verilog-indent-line)
3888 (back-to-indentation)
3890 (if (< (point) boi-point)
3891 (back-to-indentation)
3892 (cond ((not verilog-tab-to-comment))
3896 (indent-for-comment)
3897 (when (and (eolp) (= oldpnt (point)))
3898 ; kill existing comment
3900 (re-search-forward comment-start-skip oldpnt 'move)
3901 (goto-char (match-beginning 0))
3902 (skip-chars-backward " \t")
3903 (kill-region (point) oldpnt)))))))
3904 (t (progn (insert "\t")))))
3909 ;; Interactive functions
3912 (defun verilog-indent-buffer ()
3913 "Indent-region the entire buffer as Verilog code.
3914 To call this from the command line, see \\[verilog-batch-indent]."
3917 (indent-region (point-min) (point-max) nil))
3919 (defun verilog-insert-block ()
3920 "Insert Verilog begin ... end; block in the code with right indentation."
3922 (verilog-indent-line)
3924 (electric-verilog-terminate-line)
3926 (electric-verilog-terminate-line)
3929 (verilog-indent-line)))
3931 (defun verilog-star-comment ()
3932 "Insert Verilog star comment at point."
3934 (verilog-indent-line)
3942 (defun verilog-insert-1 (fmt max)
3943 "Use format string FMT to insert integers 0 to MAX - 1.
3944 Inserts one integer per line, at the current column. Stops early
3945 if it reaches the end of the buffer."
3946 (let ((col (current-column))
3950 (insert (format fmt n))
3952 ;; Note that this function does not bother to check for lines
3953 ;; shorter than col.
3957 (move-to-column col))))))
3959 (defun verilog-insert-indices (max)
3960 "Insert a set of indices into a rectangle.
3961 The upper left corner is defined by point. Indices begin with 0
3962 and extend to the MAX - 1. If no prefix arg is given, the user
3963 is prompted for a value. The indices are surrounded by square
3964 brackets \[]. For example, the following code with the point
3965 located after the first 'a' gives:
3971 a = b ==> insert-indices ==> a[ 4] = b
3977 (interactive "NMAX: ")
3978 (verilog-insert-1 "[%3d]" max))
3980 (defun verilog-generate-numbers (max)
3981 "Insert a set of generated numbers into a rectangle.
3982 The upper left corner is defined by point. The numbers are padded to three
3983 digits, starting with 000 and extending to (MAX - 1). If no prefix argument
3984 is supplied, then the user is prompted for the MAX number. Consider the
3985 following code fragment:
3991 buf buf ==> generate-numbers ==> buf buf004
3997 (interactive "NMAX: ")
3998 (verilog-insert-1 "%3.3d" max))
4000 (defun verilog-mark-defun ()
4001 "Mark the current Verilog function (or procedure).
4002 This puts the mark at the end, and point at the beginning."
4004 (if (featurep 'xemacs)
4007 (verilog-end-of-defun)
4009 (verilog-beg-of-defun)
4010 (if (fboundp 'zmacs-activate-region)
4011 (zmacs-activate-region)))
4014 (defun verilog-comment-region (start end)
4015 ;; checkdoc-params: (start end)
4016 "Put the region into a Verilog comment.
4017 The comments that are in this area are \"deformed\":
4018 `*)' becomes `!(*' and `}' becomes `!{'.
4019 These deformed comments are returned to normal if you use
4020 \\[verilog-uncomment-region] to undo the commenting.
4022 The commented area starts with `verilog-exclude-str-start', and ends with
4023 `verilog-exclude-str-end'. But if you change these variables,
4024 \\[verilog-uncomment-region] won't recognize the comments."
4027 ;; Insert start and endcomments
4029 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
4030 (not (save-excursion (skip-chars-backward " \t") (bolp))))
4032 (beginning-of-line))
4033 (insert verilog-exclude-str-end)
4038 (insert verilog-exclude-str-start)
4040 ;; Replace end-comments within commented area
4043 (while (re-search-backward "\\*/" start t)
4044 (replace-match "*-/" t t)))
4046 (let ((s+1 (1+ start)))
4047 (while (re-search-backward "/\\*" s+1 t)
4048 (replace-match "/-*" t t))))))
4050 (defun verilog-uncomment-region ()
4051 "Uncomment a commented area; change deformed comments back to normal.
4052 This command does nothing if the pointer is not in a commented
4053 area. See also `verilog-comment-region'."
4056 (let ((start (point))
4058 ;; Find the boundaries of the comment
4060 (setq start (progn (search-backward verilog-exclude-str-start nil t)
4062 (setq end (progn (search-forward verilog-exclude-str-end nil t)
4064 ;; Check if we're really inside a comment
4065 (if (or (equal start (point)) (<= end (point)))
4066 (message "Not standing within commented area.")
4068 ;; Remove endcomment
4071 (let ((pos (point)))
4073 (delete-region pos (1+ (point))))
4074 ;; Change comments back to normal
4076 (while (re-search-backward "\\*-/" start t)
4077 (replace-match "*/" t t)))
4079 (while (re-search-backward "/-\\*" start t)
4080 (replace-match "/*" t t)))
4081 ;; Remove start comment
4084 (let ((pos (point)))
4086 (delete-region pos (1+ (point)))))))))
4088 (defun verilog-beg-of-defun ()
4089 "Move backward to the beginning of the current function or procedure."
4091 (verilog-re-search-backward verilog-defun-re nil 'move))
4093 (defun verilog-beg-of-defun-quick ()
4094 "Move backward to the beginning of the current function or procedure.
4095 Uses `verilog-scan' cache."
4097 (verilog-re-search-backward-quick verilog-defun-re nil 'move))
4099 (defun verilog-end-of-defun ()
4100 "Move forward to the end of the current function or procedure."
4102 (verilog-re-search-forward verilog-end-defun-re nil 'move))
4104 (defun verilog-get-end-of-defun ()
4106 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
4109 (error "%s: Can't find endmodule" (verilog-point-text))
4112 (defun verilog-label-be ()
4113 "Label matching begin ... end, fork ... join and case ... endcase statements."
4118 (verilog-beg-of-defun)
4121 (verilog-end-of-defun)
4123 (goto-char (marker-position b))
4125 (message "Relabeling module..."))
4127 (> (marker-position e) (point))
4128 (verilog-re-search-forward
4130 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>"
4131 "\\|\\(`endif\\)\\|\\(`else\\)")
4133 (goto-char (match-beginning 0))
4134 (let ((indent-str (verilog-indent-line)))
4135 (verilog-set-auto-endcomments indent-str 't)
4137 (delete-horizontal-space))
4139 (if (= 9 (% cnt 10))
4140 (message "%d..." cnt)))
4145 (message "%d lines auto commented" cnt))))
4147 (defun verilog-beg-of-statement ()
4148 "Move backward to beginning of statement."
4150 ;; Move back token by token until we see the end
4151 ;; of some earlier line.
4154 ;; If the current point does not begin a new
4155 ;; statement, as in the character ahead of us is a ';', or SOF
4156 ;; or the string after us unambiguously starts a statement,
4157 ;; or the token before us unambiguously ends a statement,
4158 ;; then move back a token and test again.
4160 ;; stop if beginning of buffer
4162 ;; stop if we find a ;
4163 (= (preceding-char) ?\;)
4164 ;; stop if we see a named coverpoint
4165 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
4166 ;; keep going if we are in the middle of a word
4167 (not (or (looking-at "\\<") (forward-word -1)))
4168 ;; stop if we see an assertion (perhaps labeled)
4170 (looking-at "\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
4174 (verilog-backward-token)
4175 (if (looking-at verilog-label-re)
4178 ;; stop if we see an extended complete reg, perhaps a complete one
4180 (looking-at verilog-complete-reg)
4182 (while (and (looking-at verilog-extended-complete-re)
4183 (progn (setq p (point))
4184 (verilog-backward-token)
4187 ;; stop if we see a complete reg (previous found extended ones)
4188 (looking-at verilog-basic-complete-re)
4189 ;; stop if previous token is an ender
4191 (verilog-backward-token)
4193 (looking-at verilog-end-block-re)
4194 (looking-at verilog-preprocessor-re))))) ;; end of test
4195 (verilog-backward-syntactic-ws)
4196 (verilog-backward-token))
4197 ;; Now point is where the previous line ended.
4198 (verilog-forward-syntactic-ws)))
4200 (defun verilog-beg-of-statement-1 ()
4201 "Move backward to beginning of statement."
4203 (if (verilog-in-comment-p)
4204 (verilog-backward-syntactic-ws))
4207 (while (not (looking-at verilog-complete-reg))
4209 (verilog-backward-syntactic-ws)
4211 (= (preceding-char) ?\;)
4213 (verilog-backward-token)
4214 (looking-at verilog-ends-re)))
4218 (verilog-backward-token))))
4219 (verilog-forward-syntactic-ws)))
4222 ; (not (looking-at verilog-complete-reg))
4224 ; (not (= (preceding-char) ?\;)))
4225 ; (verilog-backward-token)
4226 ; (verilog-backward-syntactic-ws)
4227 ; (setq pt (point)))
4229 ; ;(verilog-forward-syntactic-ws)
4231 (defun verilog-end-of-statement ()
4232 "Move forward to end of current statement."
4236 ((verilog-in-directive-p)
4240 ((looking-at verilog-beg-block-re)
4241 (verilog-forward-sexp))
4243 ((equal (char-after) ?\})
4246 ;; Skip to end of statement
4247 ((condition-case nil
4252 (verilog-skip-forward-comment-or-string)
4255 (cond ((looking-at "[ \t]*;")
4256 (skip-chars-forward "^;")
4258 (throw 'found (point)))
4261 (looking-at verilog-beg-block-re))
4262 (goto-char (match-beginning 0))
4264 ((looking-at "[ \t]*)")
4265 (throw 'found (point)))
4267 (throw 'found (point)))
4273 ;; Skip a whole block
4276 (verilog-re-search-forward verilog-end-statement-re nil 'move)
4277 (setq nest (if (match-end 1)
4281 (throw 'found (point)))
4283 (throw 'found (verilog-end-of-statement))))))
4286 (defun verilog-in-case-region-p ()
4287 "Return true if in a case region.
4288 More specifically, point @ in the line foo : @ begin"
4292 (progn (verilog-forward-syntactic-ws)
4293 (looking-at "\\<begin\\>"))
4294 (progn (verilog-backward-syntactic-ws)
4295 (= (preceding-char) ?\:)))
4299 (verilog-re-search-backward
4300 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
4301 "\\(\\<endcase\\>\\)\\>")
4305 (setq nest (1+ nest)))
4309 (setq nest (1- nest)))
4311 (throw 'found (= nest 0)))))))
4314 (defun verilog-backward-up-list (arg)
4315 "Call `backward-up-list' ARG, ignoring comments."
4316 (let ((parse-sexp-ignore-comments t))
4317 (backward-up-list arg)))
4319 (defun verilog-forward-sexp-cmt (arg)
4320 "Call `forward-sexp' ARG, inside comments."
4321 (let ((parse-sexp-ignore-comments nil))
4322 (forward-sexp arg)))
4324 (defun verilog-forward-sexp-ign-cmt (arg)
4325 "Call `forward-sexp' ARG, ignoring comments."
4326 (let ((parse-sexp-ignore-comments t))
4327 (forward-sexp arg)))
4329 (defun verilog-in-generate-region-p ()
4330 "Return true if in a generate region.
4331 More specifically, after a generate and before an endgenerate."
4338 (verilog-re-search-backward
4339 "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
4341 ((match-end 1) ; module - we have crawled out
4343 ((match-end 2) ; generate
4344 (setq nest (1- nest)))
4345 ((match-end 3) ; endgenerate
4346 (setq nest (1+ nest))))))))
4347 (= nest 0) )) ; return nest
4349 (defun verilog-in-fork-region-p ()
4350 "Return true if between a fork and join."
4352 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
4357 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
4359 ((match-end 1) ; fork
4360 (setq nest (1- nest)))
4361 ((match-end 2) ; join
4362 (setq nest (1+ nest)))))))
4363 (= nest 0) )) ; return nest
4365 (defun verilog-backward-case-item (lim)
4366 "Skip backward to nearest enclosing case item.
4367 Limit search to point LIM."
4373 (verilog-re-search-backward verilog-endcomment-reason-re
4376 ;; Try to find the real :
4377 (if (save-excursion (search-backward ":" lim1 t))
4383 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
4387 (setq colon (1+ colon))
4389 (error "%s: unbalanced [" (verilog-point-text))))
4391 (setq colon (1- colon)))
4394 (setq colon (1+ colon)))))
4395 ;; Skip back to beginning of case item
4396 (skip-chars-backward "\t ")
4397 (verilog-skip-backward-comment-or-string)
4402 (verilog-re-search-backward
4403 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
4407 (goto-char (match-end 1))
4408 (verilog-forward-ws&directives)
4409 (if (looking-at "(")
4412 (verilog-forward-ws&directives)))
4415 (goto-char (match-end 0))
4416 (verilog-forward-ws&directives)
4418 (error "Malformed case item"))))
4419 (setq str (buffer-substring b e))
4423 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4424 (setq str (concat (substring str 0 e) "...")))
4433 (defun verilog-kill-existing-comment ()
4434 "Kill auto comment on this line."
4442 (search-forward "//" e t))))
4444 (delete-region (- b 2) e)))))
4446 (defconst verilog-directive-nest-re
4447 (concat "\\(`else\\>\\)\\|"
4448 "\\(`endif\\>\\)\\|"
4450 "\\(`ifdef\\>\\)\\|"
4451 "\\(`ifndef\\>\\)\\|"
4454 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
4455 "Add ending comment with given INDENT-STR.
4456 With KILL-EXISTING-COMMENT, remove what was there before.
4457 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
4458 Insert `// case expr ' if this line ends a case block.
4459 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
4460 Insert `// NAME ' if this line ends a function, task, module,
4461 primitive or interface named NAME."
4464 (; Comment close preprocessor directives
4466 (looking-at "\\(`endif\\)\\|\\(`else\\)")
4467 (or kill-existing-comment
4468 (not (save-excursion
4470 (search-backward "//" (point-at-bol) t)))))
4473 (else (if (match-end 2) "!" " ")))
4475 (if kill-existing-comment
4476 (verilog-kill-existing-comment))
4477 (delete-horizontal-space)
4480 (while (and (/= nest 0)
4481 (verilog-re-search-backward verilog-directive-nest-re nil 'move))
4483 ((match-end 1) ; `else
4486 ((match-end 2) ; `endif
4487 (setq nest (1+ nest)))
4488 ((match-end 3) ; `if
4489 (setq nest (1- nest)))
4490 ((match-end 4) ; `ifdef
4491 (setq nest (1- nest)))
4492 ((match-end 5) ; `ifndef
4493 (setq nest (1- nest)))
4494 ((match-end 6) ; `elsif
4505 (skip-chars-forward "^ \t")
4506 (verilog-forward-syntactic-ws)
4509 (skip-chars-forward "a-zA-Z0-9_")
4512 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
4513 (insert (concat " // " else m " " (buffer-substring b e))))
4515 (insert " // unmatched `else, `elsif or `endif")
4518 (; Comment close case/class/function/task/module and named block
4519 (and (looking-at "\\<end")
4520 (or kill-existing-comment
4521 (not (save-excursion
4523 (search-backward "//" (point-at-bol) t)))))
4524 (let ((type (car indent-str)))
4525 (unless (eq type 'declaration)
4526 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends
4527 (if (looking-at verilog-end-block-ordered-re)
4529 (;- This is a case block; search back for the start of this case
4530 (match-end 1) ;; of verilog-end-block-ordered-re
4533 (str "UNMATCHED!!"))
4535 (verilog-leap-to-head)
4537 ((looking-at "\\<randcase\\>")
4538 (setq str "randcase")
4540 ((looking-at "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
4541 (goto-char (match-end 0))
4542 (setq str (concat (match-string 0) " " (verilog-get-expr)))
4546 (if kill-existing-comment
4547 (verilog-kill-existing-comment))
4548 (delete-horizontal-space)
4549 (insert (concat " // " str ))
4550 (if err (ding 't))))
4552 (;- This is a begin..end block
4553 (match-end 2) ;; of verilog-end-block-ordered-re
4554 (let ((str " // UNMATCHED !!")
4560 (verilog-leap-to-head)
4561 (setq there (point))
4562 (if (not (match-end 0))
4566 (if kill-existing-comment
4567 (verilog-kill-existing-comment))
4568 (delete-horizontal-space)
4572 (save-excursion (verilog-beg-of-defun) (point)))
4575 (;-- handle named block differently
4576 (looking-at verilog-named-block-re)
4577 (search-forward ":")
4578 (setq there (point))
4579 (setq str (verilog-get-expr))
4581 (setq str (concat " // block: " str )))
4583 ((verilog-in-case-region-p) ;-- handle case item differently
4585 (setq str (verilog-backward-case-item lim))
4586 (setq there (point))
4588 (setq str (concat " // case: " str )))
4590 (;- try to find "reason" for this begin
4594 ;; (verilog-backward-token)
4595 (verilog-beg-of-statement)
4599 ((looking-at verilog-endcomment-reason-re)
4600 (setq there (match-end 0))
4601 (setq cntx (concat (match-string 0) " "))
4607 (if (and (verilog-continued-line)
4608 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
4610 (goto-char (match-end 0))
4611 (setq there (point))
4613 (concat " // " (match-string 0) " " (verilog-get-expr))))
4619 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4621 (while (verilog-re-search-backward reg nil 'move)
4623 ((match-end 1) ; begin
4624 (setq nest (1- nest)))
4625 ((match-end 2) ; end
4626 (setq nest (1+ nest)))
4630 (goto-char (match-end 0))
4631 (setq there (point))
4633 (setq str (verilog-get-expr))
4634 (setq str (concat " // else: !if" str ))
4639 (goto-char (match-end 0))
4640 (setq there (point))
4642 (setq str (verilog-get-expr))
4643 (setq str (concat " // else: !assert " str ))
4644 (throw 'skip 1)))))))))
4649 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4651 (while (verilog-re-search-backward reg nil 'move)
4653 ((match-end 1) ; begin
4654 (setq nest (1- nest)))
4655 ((match-end 2) ; end
4656 (setq nest (1+ nest)))
4660 (goto-char (match-end 0))
4661 (setq there (point))
4663 (setq str (verilog-get-expr))
4664 (setq str (concat " // else: !if" str ))
4669 (goto-char (match-end 0))
4670 (setq there (point))
4672 (setq str (verilog-get-expr))
4673 (setq str (concat " // else: !assert " str ))
4674 (throw 'skip 1)))))))))
4676 (; always_comb, always_ff, always_latch
4677 (or (match-end 4) (match-end 5) (match-end 6))
4678 (goto-char (match-end 0))
4679 (setq there (point))
4681 (setq str (concat " // " cntx )))
4683 (;- task/function/initial et cetera
4686 (goto-char (match-end 0))
4687 (setq there (point))
4689 (setq str (concat " // " cntx (verilog-get-expr))))
4692 (setq str " // auto-endcomment confused "))))
4695 (verilog-in-case-region-p) ;-- handle case item differently
4697 (setq there (point))
4699 (setq str (verilog-backward-case-item lim))))
4701 (setq str (concat " // case: " str )))
4703 ((verilog-in-fork-region-p)
4705 (setq str " // fork branch" ))
4707 ((looking-at "\\<end\\>")
4710 (verilog-forward-syntactic-ws)
4712 (setq str (verilog-get-expr))
4713 (setq str (concat " // " cntx str )))
4718 (if kill-existing-comment
4719 (verilog-kill-existing-comment))
4720 (delete-horizontal-space)
4722 (> (count-lines here there) verilog-minimum-comment-distance))
4726 (;- this is endclass, which can be nested
4727 (match-end 11) ;; of verilog-end-block-ordered-re
4730 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
4734 (while (verilog-re-search-backward reg nil 'move)
4736 ((match-end 3) ; endclass
4738 (setq string "unmatched endclass")
4741 ((match-end 2) ; endclass
4742 (setq nest (1+ nest)))
4744 ((match-end 1) ; class
4745 (setq nest (1- nest))
4748 (goto-char (match-end 0))
4751 (skip-chars-forward "^ \t")
4752 (verilog-forward-ws&directives)
4755 (skip-chars-forward "a-zA-Z0-9_")
4757 (setq string (buffer-substring b e)))
4761 (insert (concat " // " string ))))
4763 (;- this is end{function,generate,task,module,primitive,table,generate}
4764 ;- which can not be nested.
4766 (let (string reg (name-re nil))
4768 (if kill-existing-comment
4770 (verilog-kill-existing-comment)))
4771 (delete-horizontal-space)
4774 ((match-end 5) ;; of verilog-end-block-ordered-re
4775 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4776 (setq name-re "\\w+\\s-*("))
4777 ((match-end 6) ;; of verilog-end-block-ordered-re
4778 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4779 (setq name-re "\\w+\\s-*("))
4780 ((match-end 7) ;; of verilog-end-block-ordered-re
4781 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
4782 ((match-end 8) ;; of verilog-end-block-ordered-re
4783 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4784 ((match-end 9) ;; of verilog-end-block-ordered-re
4785 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
4786 ((match-end 10) ;; of verilog-end-block-ordered-re
4787 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4788 ((match-end 11) ;; of verilog-end-block-ordered-re
4789 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4790 ((match-end 12) ;; of verilog-end-block-ordered-re
4791 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4792 ((match-end 13) ;; of verilog-end-block-ordered-re
4793 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4794 ((match-end 14) ;; of verilog-end-block-ordered-re
4795 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4796 ((match-end 15) ;; of verilog-end-block-ordered-re
4797 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
4799 (t (error "Problem in verilog-set-auto-endcomments")))
4802 (verilog-re-search-backward reg nil 'move)
4806 (skip-chars-forward "^ \t")
4807 (verilog-forward-ws&directives)
4808 (if (looking-at "static\\|automatic")
4810 (goto-char (match-end 0))
4811 (verilog-forward-ws&directives)))
4812 (if (and name-re (verilog-re-search-forward name-re nil 'move))
4814 (goto-char (match-beginning 0))
4815 (verilog-forward-ws&directives)))
4818 (skip-chars-forward "a-zA-Z0-9_")
4820 (setq string (buffer-substring b e)))
4823 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
4825 (insert (concat " // " string )))
4828 (defun verilog-get-expr()
4829 "Grab expression at point, e.g., case ( a | b & (c ^d))."
4831 (verilog-forward-syntactic-ws)
4832 (skip-chars-forward " \t")
4838 (verilog-forward-syntactic-ws)
4839 (if (looking-at "(")
4842 (while (and (/= par 0)
4843 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4846 (setq par (1+ par)))
4848 (setq par (1- par)))))))
4852 (while (and (/= par 0)
4853 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4856 (setq par (1+ par)))
4858 (setq par (1- par)))))
4862 (while (and (/= par 0)
4863 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
4866 (setq par (1+ par)))
4868 (setq par (1- par)))))
4869 (verilog-forward-syntactic-ws)
4870 (skip-chars-forward "^ \t\n\f")
4872 ((looking-at "/[/\\*]")
4875 (skip-chars-forward "^: \t\n\f")
4877 (str (buffer-substring b e)))
4878 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4879 (setq str (concat (substring str 0 e) "...")))
4882 (defun verilog-expand-vector ()
4883 "Take a signal vector on the current line and expand it to multiple lines.
4884 Useful for creating tri's and other expanded fields."
4886 (verilog-expand-vector-internal "[" "]"))
4888 (defun verilog-expand-vector-internal (bra ket)
4889 "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
4892 (let ((signal-string (buffer-substring (point)
4894 (end-of-line) (point)))))
4898 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
4900 "\\(.*\\)$") signal-string)
4901 (let* ((sig-head (match-string 1 signal-string))
4902 (vec-start (string-to-number (match-string 2 signal-string)))
4903 (vec-end (if (= (match-beginning 3) (match-end 3))
4906 (substring signal-string (1+ (match-beginning 3))
4909 (if (= (match-beginning 4) (match-end 4))
4912 (substring signal-string (+ 2 (match-beginning 4))
4914 (sig-tail (match-string 5 signal-string))
4919 (let ((tmp vec-start))
4920 (setq vec-start vec-end
4922 vec-range (- vec-range))))
4923 (if (< vec-end vec-start)
4924 (while (<= vec-end vec-start)
4925 (setq vec (append vec (list vec-start)))
4926 (setq vec-start (- vec-start vec-range)))
4927 (while (<= vec-start vec-end)
4928 (setq vec (append vec (list vec-start)))
4929 (setq vec-start (+ vec-start vec-range))))
4931 ;; Delete current line
4932 (delete-region (point) (progn (forward-line 0) (point)))
4936 (insert (concat sig-head bra
4937 (int-to-string (car vec)) ket sig-tail "\n"))
4938 (setq vec (cdr vec)))
4943 (defun verilog-strip-comments ()
4944 "Strip all comments from the Verilog code."
4946 (goto-char (point-min))
4947 (while (re-search-forward "//" nil t)
4948 (if (verilog-within-string)
4949 (re-search-forward "\"" nil t)
4950 (if (verilog-in-star-comment-p)
4951 (re-search-forward "\*/" nil t)
4952 (let ((bpt (- (point) 2)))
4954 (delete-region bpt (point))))))
4956 (goto-char (point-min))
4957 (while (re-search-forward "/\\*" nil t)
4958 (if (verilog-within-string)
4959 (re-search-forward "\"" nil t)
4960 (let ((bpt (- (point) 2)))
4961 (re-search-forward "\\*/")
4962 (delete-region bpt (point))))))
4964 (defun verilog-one-line ()
4965 "Convert structural Verilog instances to occupy one line."
4967 (goto-char (point-min))
4968 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
4969 (replace-match "\\1 " nil nil)))
4971 (defun verilog-linter-name ()
4972 "Return name of linter, either surelint or verilint."
4973 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4975 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4977 (cond ((equal compile-word1 "surelint") `surelint)
4978 ((equal compile-word1 "verilint") `verilint)
4979 ((equal lint-word1 "surelint") `surelint)
4980 ((equal lint-word1 "verilint") `verilint)
4981 (t `surelint)))) ;; back compatibility
4983 (defun verilog-lint-off ()
4984 "Convert a Verilog linter warning line into a disable statement.
4986 pci_bfm_null.v, line 46: Unused input: pci_rst_
4987 becomes a comment for the appropriate tool.
4989 The first word of the `compile-command' or `verilog-linter'
4990 variables is used to determine which product is being used.
4992 See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
4994 (let ((linter (verilog-linter-name)))
4995 (cond ((equal linter `surelint)
4996 (verilog-surelint-off))
4997 ((equal linter `verilint)
4998 (verilog-verilint-off))
4999 (t (error "Linter name not set")))))
5001 (defvar compilation-last-buffer)
5002 (defvar next-error-last-buffer)
5004 (defun verilog-surelint-off ()
5005 "Convert a SureLint warning line into a disable statement.
5006 Run from Verilog source window; assumes there is a *compile* buffer
5007 with point set appropriately.
5010 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
5012 // surefire lint_line_off UDDONX"
5014 (let ((buff (if (boundp 'next-error-last-buffer)
5015 next-error-last-buffer
5016 compilation-last-buffer)))
5017 (when (buffer-live-p buff)
5019 (switch-to-buffer buff)
5022 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
5023 (let* ((code (match-string 2))
5024 (file (match-string 3))
5025 (line (match-string 4))
5026 (buffer (get-file-buffer file))
5031 (and (file-exists-p file)
5032 (find-file-noselect file)))
5034 (let* ((pop-up-windows t))
5035 (let ((name (expand-file-name
5037 (format "Find this error in: (default %s) "
5040 (if (file-directory-p name)
5041 (setq name (expand-file-name filename name)))
5043 (and (file-exists-p name)
5044 (find-file-noselect name))))))))
5045 (switch-to-buffer buffer)
5046 (goto-char (point-min))
5047 (forward-line (- (string-to-number line)))
5051 ((verilog-in-slash-comment-p)
5052 (re-search-backward "//")
5054 ((looking-at "// surefire lint_off_line ")
5055 (goto-char (match-end 0))
5056 (let ((lim (point-at-eol)))
5057 (if (re-search-forward code lim 'move)
5059 (insert (concat " " code)))))
5062 ((verilog-in-star-comment-p)
5063 (re-search-backward "/\*")
5064 (insert (format " // surefire lint_off_line %6s" code )))
5066 (insert (format " // surefire lint_off_line %6s" code ))
5069 (defun verilog-verilint-off ()
5070 "Convert a Verilint warning line into a disable statement.
5073 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
5075 //Verilint 240 off // WARNING: Unused input"
5079 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
5080 (replace-match (format
5081 ;; %3s makes numbers 1-999 line up nicely
5082 "\\1//Verilint %3s off // WARNING: \\3"
5085 (verilog-indent-line))))
5087 (defun verilog-auto-save-compile ()
5088 "Update automatics with \\[verilog-auto], save the buffer, and compile."
5090 (verilog-auto) ; Always do it for safety
5092 (compile compile-command))
5094 (defun verilog-preprocess (&optional command filename)
5095 "Preprocess the buffer, similar to `compile', but put output in Verilog-Mode.
5096 Takes optional COMMAND or defaults to `verilog-preprocessor', and
5097 FILENAME to find directory to run in, or defaults to `buffer-file-name`."
5100 (let ((default (verilog-expand-command verilog-preprocessor)))
5101 (set (make-local-variable `verilog-preprocessor)
5102 (read-from-minibuffer "Run Preprocessor (like this): "
5104 'verilog-preprocess-history default)))))
5105 (unless command (setq command (verilog-expand-command verilog-preprocessor)))
5106 (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
5107 (dir (file-name-directory (or filename buffer-file-name)))
5108 (cmd (concat "cd " dir "; " command)))
5109 (with-output-to-temp-buffer "*Verilog-Preprocessed*"
5110 (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
5111 (insert (concat "// " cmd "\n"))
5112 (call-process shell-file-name nil t nil shell-command-switch cmd)
5114 ;; Without this force, it takes a few idle seconds
5115 ;; to get the color, which is very jarring
5116 (unless (fboundp 'font-lock-ensure)
5117 ;; We should use font-lock-ensure in preference to
5118 ;; font-lock-fontify-buffer, but IIUC the problem this is supposed to
5119 ;; solve only appears in Emacsen older than font-lock-ensure anyway.
5120 (when fontlocked (font-lock-fontify-buffer)))))))
5127 (defun verilog-warn (string &rest args)
5128 "Print a warning with `format' using STRING and optional ARGS."
5129 (apply 'message (concat "%%Warning: " string) args))
5131 (defun verilog-warn-error (string &rest args)
5132 "Call `error' using STRING and optional ARGS.
5133 If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead."
5134 (if verilog-warn-fatal
5135 (apply 'error string args)
5136 (apply 'verilog-warn string args)))
5138 (defmacro verilog-batch-error-wrapper (&rest body)
5139 "Execute BODY and add error prefix to any errors found.
5140 This lets programs calling batch mode to easily extract error messages."
5141 `(let ((verilog-warn-fatal nil))
5145 (error "%%Error: %s%s" (error-message-string err)
5146 (if (featurep 'xemacs) "\n" "")))))) ;; XEmacs forgets to add a newline
5148 (defun verilog-batch-execute-func (funref &optional no-save)
5149 "Internal processing of a batch command.
5150 Runs FUNREF on all command arguments.
5151 Save the result unless optional NO-SAVE is t."
5152 (verilog-batch-error-wrapper
5153 ;; Setting global variables like that is *VERY NASTY* !!! --Stef
5154 ;; However, this function is called only when Emacs is being used as
5155 ;; a standalone language instead of as an editor, so we'll live.
5157 ;; General globals needed
5158 (setq make-backup-files nil)
5159 (setq-default make-backup-files nil)
5160 (setq enable-local-variables t)
5161 (setq enable-local-eval t)
5162 (setq create-lockfiles nil)
5163 ;; Make sure any sub-files we read get proper mode
5164 (setq-default major-mode 'verilog-mode)
5165 ;; Ditto files already read in
5166 ;; Remember buffer list, so don't later pickup any verilog-getopt files
5167 (let ((orig-buffer-list (buffer-list)))
5169 (when (buffer-file-name buf)
5170 (with-current-buffer buf
5172 (verilog-auto-reeval-locals)
5173 (verilog-getopt-flags))))
5175 ;; Process the files
5176 (mapcar (lambda (buf)
5177 (when (buffer-file-name buf)
5179 (if (not (file-exists-p (buffer-file-name buf)))
5181 (concat "File not found: " (buffer-file-name buf))))
5182 (message (concat "Processing " (buffer-file-name buf)))
5185 (when (and (not no-save)
5186 (buffer-modified-p)) ;; Avoid "no changes to be saved"
5188 orig-buffer-list))))
5190 (defun verilog-batch-auto ()
5191 "For use with --batch, perform automatic expansions as a stand-alone tool.
5192 This sets up the appropriate Verilog mode environment, updates automatics
5193 with \\[verilog-auto] on all command-line files, and saves the buffers.
5194 For proper results, multiple filenames need to be passed on the command
5195 line in bottom-up order."
5196 (unless noninteractive
5197 (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5198 (verilog-batch-execute-func `verilog-auto))
5200 (defun verilog-batch-delete-auto ()
5201 "For use with --batch, perform automatic deletion as a stand-alone tool.
5202 This sets up the appropriate Verilog mode environment, deletes automatics
5203 with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
5204 (unless noninteractive
5205 (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5206 (verilog-batch-execute-func `verilog-delete-auto))
5208 (defun verilog-batch-delete-trailing-whitespace ()
5209 "For use with --batch, perform whitespace deletion as a stand-alone tool.
5210 This sets up the appropriate Verilog mode environment, removes
5211 whitespace with \\[verilog-delete-trailing-whitespace] on all
5212 command-line files, and saves the buffers."
5213 (unless noninteractive
5214 (error "Use verilog-batch-delete-trailing-whitespace only with --batch")) ;; Otherwise we'd mess up buffer modes
5215 (verilog-batch-execute-func `verilog-delete-trailing-whitespace))
5217 (defun verilog-batch-diff-auto ()
5218 "For use with --batch, perform automatic differences as a stand-alone tool.
5219 This sets up the appropriate Verilog mode environment, expand automatics
5220 with \\[verilog-diff-auto] on all command-line files, and reports an error
5221 if any differences are observed. This is appropriate for adding to regressions
5222 to insure automatics are always properly maintained."
5223 (unless noninteractive
5224 (error "Use verilog-batch-diff-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5225 (verilog-batch-execute-func `verilog-diff-auto t))
5227 (defun verilog-batch-inject-auto ()
5228 "For use with --batch, perform automatic injection as a stand-alone tool.
5229 This sets up the appropriate Verilog mode environment, injects new automatics
5230 with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
5231 For proper results, multiple filenames need to be passed on the command
5232 line in bottom-up order."
5233 (unless noninteractive
5234 (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5235 (verilog-batch-execute-func `verilog-inject-auto))
5237 (defun verilog-batch-indent ()
5238 "For use with --batch, reindent an entire file as a stand-alone tool.
5239 This sets up the appropriate Verilog mode environment, calls
5240 \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
5241 (unless noninteractive
5242 (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes
5243 (verilog-batch-execute-func `verilog-indent-buffer))
5249 (defconst verilog-indent-alist
5250 '((block . (+ ind verilog-indent-level))
5251 (case . (+ ind verilog-case-indent))
5252 (cparenexp . (+ ind verilog-indent-level))
5253 (cexp . (+ ind verilog-cexp-indent))
5254 (defun . verilog-indent-level-module)
5255 (declaration . verilog-indent-level-declaration)
5256 (directive . (verilog-calculate-indent-directive))
5257 (tf . verilog-indent-level)
5258 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
5261 (comment . (verilog-comment-indent))
5265 (defun verilog-continued-line-1 (lim)
5266 "Return true if this is a continued line.
5267 Set point to where line starts. Limit search to point LIM."
5268 (let ((continued 't))
5269 (if (eq 0 (forward-line -1))
5272 (verilog-backward-ws&directives lim)
5274 (setq continued nil)
5275 (setq continued (verilog-backward-token))))
5276 (setq continued nil))
5279 (defun verilog-calculate-indent ()
5280 "Calculate the indent of the current Verilog line.
5281 Examine previous lines. Once a line is found that is definitive as to the
5282 type of the current line, return that lines' indent level and its type.
5283 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5285 (let* ((starting_position (point))
5287 (begin (looking-at "[ \t]*begin\\>"))
5288 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
5290 (type (catch 'nesting
5291 ;; Keep working backwards until we can figure out
5292 ;; what type of statement this is.
5293 ;; Basically we need to figure out
5294 ;; 1) if this is a continuation of the previous line;
5295 ;; 2) are we in a block scope (begin..end)
5297 ;; if we are in a comment, done.
5298 (if (verilog-in-star-comment-p)
5299 (throw 'nesting 'comment))
5301 ;; if we have a directive, done.
5302 (if (save-excursion (beginning-of-line)
5303 (and (looking-at verilog-directive-re-1)
5304 (not (or (looking-at "[ \t]*`[ou]vm_")
5305 (looking-at "[ \t]*`vmm_")))))
5306 (throw 'nesting 'directive))
5307 ;; indent structs as if there were module level
5308 (setq structres (verilog-in-struct-nested-p))
5309 (cond ((not structres) nil)
5310 ;;((and structres (equal (char-after) ?\})) (throw 'nesting 'struct-close))
5311 ((> structres 0) (throw 'nesting 'nested-struct))
5312 ((= structres 0) (throw 'nesting 'block))
5315 ;; if we are in a parenthesized list, and the user likes to indent these, return.
5316 ;; unless we are in the newfangled coverpoint or constraint blocks
5318 verilog-indent-lists
5320 (not (verilog-in-coverage-p))
5323 (throw 'nesting 'block)))
5325 ;; See if we are continuing a previous line
5327 ;; trap out if we crawl off the top of the buffer
5328 (if (bobp) (throw 'nesting 'cpp))
5330 (if (and (verilog-continued-line-1 lim)
5331 (or (not (verilog-in-coverage-p))
5332 (looking-at verilog-in-constraint-re) )) ;; may still get hosed if concat in constraint
5335 (not (looking-at verilog-complete-reg))
5336 (verilog-continued-line-1 lim))
5337 (progn (goto-char sp)
5338 (throw 'nesting 'cexp))
5341 (if (and (verilog-in-coverage-p)
5342 (looking-at verilog-in-constraint-re))
5345 (skip-chars-forward " \t")
5346 (throw 'nesting 'constraint)))
5348 (not verilog-indent-begin-after-if)
5349 (looking-at verilog-no-indent-begin-re))
5352 (skip-chars-forward " \t")
5353 (throw 'nesting 'statement))
5355 (throw 'nesting 'cexp))))
5356 ;; not a continued line
5357 (goto-char starting_position))
5359 (if (looking-at "\\<else\\>")
5360 ;; search back for governing if, striding across begin..end pairs
5363 (while (verilog-re-search-backward verilog-ends-re nil 'move)
5365 ((match-end 1) ; else, we're in deep
5366 (setq elsec (1+ elsec)))
5368 (setq elsec (1- elsec))
5370 (if verilog-align-ifelse
5371 (throw 'nesting 'statement)
5372 (progn ;; back up to first word on this line
5374 (verilog-forward-syntactic-ws)
5375 (throw 'nesting 'statement)))))
5376 ((match-end 3) ; assert block
5377 (setq elsec (1- elsec))
5378 (verilog-beg-of-statement) ;; doesn't get to beginning
5379 (if (looking-at verilog-property-re)
5380 (throw 'nesting 'statement) ; We don't need an endproperty for these
5381 (throw 'nesting 'block) ;We still need an endproperty
5384 ; try to leap back to matching outward block by striding across
5385 ; indent level changing tokens then immediately
5386 ; previous line governs indentation.
5387 (let (( reg) (nest 1))
5388 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
5390 ((match-end 4) ; end
5391 ;; Search back for matching begin
5392 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
5393 ((match-end 5) ; endcase
5394 ;; Search back for matching case
5395 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5396 ((match-end 6) ; endfunction
5397 ;; Search back for matching function
5398 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5399 ((match-end 7) ; endtask
5400 ;; Search back for matching task
5401 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
5402 ((match-end 8) ; endspecify
5403 ;; Search back for matching specify
5404 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5405 ((match-end 9) ; endtable
5406 ;; Search back for matching table
5407 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5408 ((match-end 10) ; endgenerate
5409 ;; Search back for matching generate
5410 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5411 ((match-end 11) ; joins
5412 ;; Search back for matching fork
5413 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
5414 ((match-end 12) ; class
5415 ;; Search back for matching class
5416 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5417 ((match-end 13) ; covergroup
5418 ;; Search back for matching covergroup
5419 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
5421 (while (verilog-re-search-backward reg nil 'move)
5423 ((match-end 1) ; begin
5424 (setq nest (1- nest))
5427 ((match-end 2) ; end
5428 (setq nest (1+ nest)))))
5430 (throw 'nesting (verilog-calc-1)))
5434 ;; Return type of block and indent level.
5437 (if (> par 0) ; Unclosed Parenthesis
5438 (list 'cparenexp par)
5441 (list type (verilog-case-indent-level)))
5442 ((eq type 'statement)
5443 (list type (current-column)))
5446 ((eq type 'constraint)
5447 (list 'block (current-column)))
5448 ((eq type 'nested-struct)
5449 (list 'block structres))
5451 (list type (verilog-current-indent-level))))))))
5453 (defun verilog-wai ()
5454 "Show matching nesting block for debugging."
5457 (let* ((type (verilog-calc-1))
5459 ;; Return type of block and indent level.
5463 verilog-indent-lists
5464 (not(or (verilog-in-coverage-p)
5465 (verilog-in-struct-p)))
5470 (setq depth (verilog-case-indent-level)))
5471 ((eq type 'statement)
5472 (setq depth (current-column)))
5476 (setq depth (verilog-current-indent-level)))))
5477 (message "You are at nesting %s depth %d" type depth))))
5479 (defun verilog-calc-1 ()
5481 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)"))
5482 (inconstraint (verilog-in-coverage-p)))
5483 (while (verilog-re-search-backward re nil 'move)
5486 ((equal (char-after) ?\{)
5487 ;; block type returned based on outer constraint { or inner
5488 (if (verilog-at-constraint-p)
5489 (cond (inconstraint (throw 'nesting 'constraint))
5490 (t (throw 'nesting 'statement)))))
5491 ((equal (char-after) ?\})
5493 (there (verilog-at-close-constraint-p)))
5494 (if there ;; we are at the } that closes a constraint. Find the { that opens it
5496 (if (> (verilog-in-paren-count) 0)
5498 (setq par-pos (verilog-parenthesis-depth))
5503 (backward-char 1)))))))
5505 ((looking-at verilog-beg-block-re-ordered)
5507 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
5508 (let ((here (point)))
5509 (verilog-beg-of-statement)
5510 (if (looking-at verilog-extended-case-re)
5511 (throw 'nesting 'case)
5513 (throw 'nesting 'case))
5515 ((match-end 4) ; *sigh* could be "disable fork"
5516 (let ((here (point)))
5517 (verilog-beg-of-statement)
5518 (if (looking-at verilog-disable-fork-re)
5519 t ; this is a normal statement
5520 (progn ; or is fork, starts a new block
5522 (throw 'nesting 'block)))))
5524 ((match-end 27) ; *sigh* might be a clocking declaration
5525 (let ((here (point)))
5526 (if (verilog-in-paren)
5527 t ; this is a normal statement
5528 (progn ; or is fork, starts a new block
5530 (throw 'nesting 'block)))))
5532 ;; need to consider typedef struct here...
5533 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
5534 ; *sigh* These words have an optional prefix:
5535 ; extern {virtual|protected}? function a();
5536 ; typedef class foo;
5537 ; and we don't want to confuse this with
5542 (verilog-beg-of-statement)
5543 (if (looking-at verilog-beg-block-re-ordered)
5544 (throw 'nesting 'block)
5545 (throw 'nesting 'defun)))
5548 ((looking-at "\\<property\\>")
5550 ; {assert|assume|cover} property (); are complete
5551 ; and could also be labeled: - foo: assert property
5553 ; property ID () ... needs end_property
5554 (verilog-beg-of-statement)
5555 (if (looking-at verilog-property-re)
5556 (throw 'continue 'statement) ; We don't need an endproperty for these
5557 (throw 'nesting 'block) ;We still need an endproperty
5560 (t (throw 'nesting 'block))))
5562 ((looking-at verilog-end-block-re)
5563 (verilog-leap-to-head)
5564 (if (verilog-in-case-region-p)
5566 (verilog-leap-to-case-head)
5567 (if (looking-at verilog-extended-case-re)
5568 (throw 'nesting 'case)))))
5570 ((looking-at verilog-defun-level-re)
5571 (if (looking-at verilog-defun-level-generate-only-re)
5572 (if (verilog-in-generate-region-p)
5573 (throw 'continue 'foo) ; always block in a generate - keep looking
5574 (throw 'nesting 'defun))
5575 (throw 'nesting 'defun)))
5577 ((looking-at verilog-cpp-level-re)
5578 (throw 'nesting 'cpp))
5581 (throw 'nesting 'cpp)))))
5583 (throw 'nesting 'cpp))))
5585 (defun verilog-calculate-indent-directive ()
5586 "Return indentation level for directive.
5587 For speed, the searcher looks at the last directive, not the indent
5588 of the appropriate enclosing block."
5589 (let ((base -1) ;; Indent of the line that determines our indentation
5590 (ind 0)) ;; Relative offset caused by other directives (like `endif on same line as `else)
5591 ;; Start at current location, scan back for another directive
5595 (while (and (< base 0)
5596 (verilog-re-search-backward verilog-directive-re nil t))
5597 (cond ((save-excursion (skip-chars-backward " \t") (bolp))
5598 (setq base (current-indentation))))
5599 (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL
5600 (setq ind (- ind verilog-indent-level-directive)))
5601 ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL
5602 (setq ind (+ ind verilog-indent-level-directive)))
5603 ((looking-at verilog-directive-begin)
5604 (setq ind (+ ind verilog-indent-level-directive)))))
5605 ;; Adjust indent to starting indent of critical line
5606 (setq ind (max 0 (+ ind base))))
5610 (skip-chars-forward " \t")
5611 (cond ((or (looking-at verilog-directive-middle)
5612 (looking-at verilog-directive-end))
5613 (setq ind (max 0 (- ind verilog-indent-level-directive))))))
5616 (defun verilog-leap-to-case-head ()
5619 (verilog-re-search-backward
5621 "\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
5622 "\\|\\(\\<endcase\\>\\)" )
5626 (let ((here (point)))
5627 (verilog-beg-of-statement)
5628 (unless (looking-at verilog-extended-case-re)
5630 (setq nest (1- nest)))
5632 (setq nest (1+ nest)))
5637 (defun verilog-leap-to-head ()
5638 "Move point to the head of this block.
5639 Jump from end to matching begin, from endcase to matching case, and so on."
5645 ((looking-at "\\<end\\>")
5646 ;; 1: Search back for matching begin
5647 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
5648 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
5649 ((looking-at "\\<endtask\\>")
5650 ;; 2: Search back for matching task
5651 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)")
5653 ((looking-at "\\<endcase\\>")
5655 (verilog-leap-to-case-head) )
5656 (setq reg nil) ; to force skip
5659 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
5660 ;; 4: Search back for matching fork
5661 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5662 ((looking-at "\\<endclass\\>")
5663 ;; 5: Search back for matching class
5664 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5665 ((looking-at "\\<endtable\\>")
5666 ;; 6: Search back for matching table
5667 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5668 ((looking-at "\\<endspecify\\>")
5669 ;; 7: Search back for matching specify
5670 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5671 ((looking-at "\\<endfunction\\>")
5672 ;; 8: Search back for matching function
5673 (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<function\\>\\)")
5675 ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5676 ((looking-at "\\<endgenerate\\>")
5677 ;; 8: Search back for matching generate
5678 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5679 ((looking-at "\\<endgroup\\>")
5680 ;; 10: Search back for matching covergroup
5681 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
5682 ((looking-at "\\<endproperty\\>")
5683 ;; 11: Search back for matching property
5684 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
5685 ((looking-at verilog-uvm-end-re)
5686 ;; 12: Search back for matching sequence
5687 (setq reg (concat "\\(" verilog-uvm-begin-re "\\|" verilog-uvm-end-re "\\)")))
5688 ((looking-at verilog-ovm-end-re)
5689 ;; 12: Search back for matching sequence
5690 (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
5691 ((looking-at verilog-vmm-end-re)
5692 ;; 12: Search back for matching sequence
5693 (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
5694 ((looking-at "\\<endinterface\\>")
5695 ;; 12: Search back for matching interface
5696 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
5697 ((looking-at "\\<endsequence\\>")
5698 ;; 12: Search back for matching sequence
5699 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
5700 ((looking-at "\\<endclocking\\>")
5701 ;; 12: Search back for matching clocking
5702 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
5705 (if (eq nesting 'yes)
5707 (while (verilog-re-search-backward reg nil 'move)
5709 ((match-end 1) ; begin
5710 (if (looking-at "fork")
5711 (let ((here (point)))
5712 (verilog-beg-of-statement)
5713 (unless (looking-at verilog-disable-fork-re)
5715 (setq nest (1- nest))))
5716 (setq nest (1- nest)))
5718 ;; Now previous line describes syntax
5723 ((match-end 2) ; end
5724 (setq nest (1+ nest)))
5726 ;; endcase, jump to case
5728 (setq nest (1+ nest))
5730 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5732 ;; join, jump to fork
5734 (setq nest (1+ nest))
5736 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5740 (verilog-re-search-backward reg nil 'move)
5741 (match-end 1)) ; task -> could be virtual and/or protected
5743 (verilog-beg-of-statement)
5745 (throw 'skip 1)))))))
5747 (defun verilog-continued-line ()
5748 "Return true if this is a continued line.
5749 Set point to where line starts."
5750 (let ((continued 't))
5751 (if (eq 0 (forward-line -1))
5754 (verilog-backward-ws&directives)
5756 (setq continued nil)
5757 (while (and continued
5759 (skip-chars-backward " \t")
5761 (setq continued (verilog-backward-token)))))
5762 (setq continued nil))
5765 (defun verilog-backward-token ()
5766 "Step backward token, returning true if this is a continued line."
5768 (verilog-backward-syntactic-ws)
5772 (;-- Anything ending in a ; is complete
5773 (= (preceding-char) ?\;)
5775 (; If a "}" is prefixed by a ";", then this is a complete statement
5776 ; i.e.: constraint foo { a = b; }
5777 (= (preceding-char) ?\})
5780 (not(verilog-at-close-constraint-p))))
5781 (;-- constraint foo { a = b }
5782 ; is a complete statement. *sigh*
5783 (= (preceding-char) ?\{)
5786 (not (verilog-at-constraint-p))))
5788 (= (preceding-char) ?\")
5790 (verilog-skip-backward-comment-or-string)
5794 (= (preceding-char) ?\])
5796 (verilog-backward-open-bracket)
5799 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
5800 ; also could be simply '@(foo)'
5802 ; (b, ... which ISN'T complete
5803 ;;;; Do we need this???
5804 (= (preceding-char) ?\))
5807 (verilog-backward-up-list 1)
5808 (verilog-backward-syntactic-ws)
5809 (let ((back (point)))
5813 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
5814 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
5815 ((looking-at verilog-uvm-statement-re)
5817 ((looking-at verilog-uvm-begin-re)
5819 ((looking-at verilog-uvm-end-re)
5821 ((looking-at verilog-ovm-statement-re)
5823 ((looking-at verilog-ovm-begin-re)
5825 ((looking-at verilog-ovm-end-re)
5827 ;; JBA find VMM macros
5828 ((looking-at verilog-vmm-statement-re)
5830 ((looking-at verilog-vmm-begin-re)
5832 ((looking-at verilog-vmm-end-re)
5834 ;; JBA trying to catch macro lines with no ; at end
5835 ((looking-at "\\<`")
5840 ((= (preceding-char) ?\@)
5843 (verilog-backward-token)
5844 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
5845 ((= (preceding-char) ?\#)
5849 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
5852 (while (= (preceding-char) ?\_)
5855 ((looking-at "\\<else\\>")
5857 ((looking-at verilog-behavioral-block-beg-re)
5859 ((looking-at verilog-indent-re)
5864 (verilog-backward-syntactic-ws)
5866 ((= (preceding-char) ?\:)
5868 (verilog-backward-syntactic-ws)
5870 (if (looking-at verilog-nameable-item-re )
5873 ((= (preceding-char) ?\#)
5876 ((= (preceding-char) ?\`)
5884 (defun verilog-backward-syntactic-ws ()
5885 "Move backwards putting point after first non-whitespace non-comment."
5886 (verilog-skip-backward-comments)
5887 (forward-comment (- (buffer-size))))
5889 (defun verilog-backward-syntactic-ws-quick ()
5890 "As with `verilog-backward-syntactic-ws' but use `verilog-scan' cache."
5891 (while (cond ((bobp)
5893 ((> (skip-syntax-backward " ") 0)
5895 ((eq (preceding-char) ?\n) ;; \n's terminate // so aren't space syntax
5898 ((or (verilog-inside-comment-or-string-p (1- (point)))
5899 (verilog-inside-comment-or-string-p (point)))
5900 (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
5903 (defun verilog-forward-syntactic-ws ()
5904 (verilog-skip-forward-comment-p)
5905 (forward-comment (buffer-size)))
5907 (defun verilog-backward-ws&directives (&optional bound)
5908 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
5909 Optional BOUND limits search."
5911 (let* ((bound (or bound (point-min)))
5914 (if (< bound (point))
5916 (let ((state (save-excursion (verilog-syntax-ppss))))
5918 ((nth 7 state) ;; in // comment
5919 (verilog-re-search-backward "//" nil 'move)
5920 (skip-chars-backward "/"))
5921 ((nth 4 state) ;; in /* */ comment
5922 (verilog-re-search-backward "/\*" nil 'move))))
5923 (narrow-to-region bound (point))
5924 (while (/= here (point))
5926 (verilog-skip-backward-comments)
5931 ((and verilog-highlight-translate-off
5932 (verilog-within-translate-off))
5933 (verilog-back-to-start-translate-off (point-min)))
5934 ((looking-at verilog-directive-re-1)
5938 (if p (goto-char p))))))))
5940 (defun verilog-forward-ws&directives (&optional bound)
5941 "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
5942 Optional BOUND limits search."
5944 (let* ((bound (or bound (point-max)))
5947 (if (> bound (point))
5949 (let ((state (save-excursion (verilog-syntax-ppss))))
5951 ((nth 7 state) ;; in // comment
5954 (skip-chars-forward " \t\n\f")
5956 ((nth 4 state) ;; in /* */ comment
5957 (verilog-re-search-forward "\*\/\\s-*" nil 'move))))
5958 (narrow-to-region (point) bound)
5959 (while (/= here (point))
5962 (forward-comment (buffer-size))
5963 (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ;; Attribute
5964 (goto-char (match-end 0)))
5967 (if (looking-at verilog-directive-re-1)
5970 (beginning-of-line 2))))))))
5972 (defun verilog-in-comment-p ()
5973 "Return true if in a star or // comment."
5974 (let ((state (save-excursion (verilog-syntax-ppss))))
5975 (or (nth 4 state) (nth 7 state))))
5977 (defun verilog-in-star-comment-p ()
5978 "Return true if in a star comment."
5979 (let ((state (save-excursion (verilog-syntax-ppss))))
5981 (nth 4 state) ; t if in a comment of style a // or b /**/
5983 (nth 7 state) ; t if in a comment of style b /**/
5986 (defun verilog-in-slash-comment-p ()
5987 "Return true if in a slash comment."
5988 (let ((state (save-excursion (verilog-syntax-ppss))))
5991 (defun verilog-in-comment-or-string-p ()
5992 "Return true if in a string or comment."
5993 (let ((state (save-excursion (verilog-syntax-ppss))))
5994 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
5996 (defun verilog-in-attribute-p ()
5997 "Return true if point is in an attribute (* [] attribute *)."
6000 (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
6001 (numberp (match-beginning 1)))))
6003 (defun verilog-in-parameter-p ()
6004 "Return true if point is in a parameter assignment #( p1=1, p2=5)."
6007 (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move)
6008 (numberp (match-beginning 1)))))
6010 (defun verilog-in-escaped-name-p ()
6011 "Return true if in an escaped name."
6014 (skip-chars-backward "^ \t\n\f")
6015 (if (equal (char-after (point) ) ?\\ )
6018 (defun verilog-in-directive-p ()
6019 "Return true if in a directive."
6022 (looking-at verilog-directive-re-1)))
6024 (defun verilog-in-parenthesis-p ()
6025 "Return true if in a ( ) expression (but not { } or [ ])."
6028 (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move)
6029 (numberp (match-beginning 1)))))
6031 (defun verilog-in-paren ()
6032 "Return true if in a parenthetical expression.
6033 May cache result using `verilog-syntax-ppss'."
6034 (let ((state (save-excursion (verilog-syntax-ppss))))
6035 (> (nth 0 state) 0 )))
6037 (defun verilog-in-paren-count ()
6038 "Return paren depth, floor to 0.
6039 May cache result using `verilog-syntax-ppss'."
6040 (let ((state (save-excursion (verilog-syntax-ppss))))
6041 (if (> (nth 0 state) 0)
6045 (defun verilog-in-paren-quick ()
6046 "Return true if in a parenthetical expression.
6047 Always starts from `point-min', to allow inserts with hooks disabled."
6048 ;; The -quick refers to its use alongside the other -quick functions,
6049 ;; not that it's likely to be faster than verilog-in-paren.
6050 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
6051 (> (nth 0 state) 0 )))
6053 (defun verilog-in-struct-p ()
6054 "Return true if in a struct declaration."
6057 (if (verilog-in-paren)
6059 (verilog-backward-up-list 1)
6060 (verilog-at-struct-p)
6064 (defun verilog-in-struct-nested-p ()
6065 "Return nil for not in struct.
6066 Return 0 for in non-nested struct.
6067 Return >0 for nested struct."
6071 (if (verilog-in-paren)
6073 (verilog-backward-up-list 1)
6074 (setq col (verilog-at-struct-mv-p))
6076 (if (verilog-in-struct-p) (current-column) 0)))
6079 (defun verilog-in-coverage-p ()
6080 "Return true if in a constraint or coverpoint expression."
6083 (if (verilog-in-paren)
6085 (verilog-backward-up-list 1)
6086 (verilog-at-constraint-p)
6089 (defun verilog-at-close-constraint-p ()
6090 "If at the } that closes a constraint or covergroup, return true."
6092 (equal (char-after) ?\})
6093 (verilog-in-coverage-p))
6096 (verilog-backward-ws&directives)
6097 (if (or (equal (char-before) ?\;)
6098 (equal (char-before) ?\}) ;; can end with inner constraint { } block or ;
6099 (equal (char-before) ?\{)) ;; empty constraint block
6103 (defun verilog-at-constraint-p ()
6104 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
6107 (equal (char-after) ?\{)
6109 (progn (backward-char 1)
6110 (verilog-backward-ws&directives)
6111 (or (equal (char-before) ?\{) ;; empty case
6112 (equal (char-before) ?\;)
6113 (equal (char-before) ?\})))))
6115 (let ( (pt (point)) (pass 0))
6116 (verilog-backward-ws&directives)
6117 (verilog-backward-token)
6118 (if (looking-at (concat "\\<constraint\\|coverpoint\\|cross\\|with\\>\\|" verilog-in-constraint-re))
6119 (progn (setq pass 1)
6120 (if (looking-at "\\<with\\>")
6121 (progn (verilog-backward-ws&directives)
6122 (beginning-of-line) ;; 1
6123 (verilog-forward-ws&directives)
6125 (verilog-beg-of-statement)
6127 ;; if first word token not keyword, it maybe the instance name
6128 ;; check next word token
6129 (if (looking-at "\\<\\w+\\>\\|\\s-*(\\s-*\\w+")
6130 (progn (verilog-beg-of-statement)
6131 (if (looking-at (concat "\\<\\(constraint\\|"
6132 "\\(?:\\w+\\s-*:\\s-*\\)?\\(coverpoint\\|cross\\)"
6133 "\\|with\\)\\>\\|" verilog-in-constraint-re))
6136 (progn (goto-char pt) nil) 1)))
6140 (defun verilog-at-struct-p ()
6141 "If at the { of a struct, return true, not moving point."
6143 (if (and (equal (char-after) ?\{)
6144 (verilog-backward-token))
6145 (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6148 (defun verilog-at-struct-mv-p ()
6149 "If at the { of a struct, return true, moving point to struct."
6151 (if (and (equal (char-after) ?\{)
6152 (verilog-backward-token))
6153 (if (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6154 (progn (verilog-beg-of-statement) (point))
6155 (progn (goto-char pt) nil))
6156 (progn (goto-char pt) nil))))
6158 (defun verilog-at-close-struct-p ()
6159 "If at the } that closes a struct, return true."
6161 (equal (char-after) ?\})
6162 (verilog-in-struct-p))
6165 (if (looking-at "}\\(?:\\s-*\\w+\\s-*\\)?;") 1))
6169 (defun verilog-parenthesis-depth ()
6170 "Return non zero if in parenthetical-expression."
6171 (save-excursion (nth 1 (verilog-syntax-ppss))))
6174 (defun verilog-skip-forward-comment-or-string ()
6175 "Return true if in a string or comment."
6176 (let ((state (save-excursion (verilog-syntax-ppss))))
6178 ((nth 3 state) ;Inside string
6179 (search-forward "\"")
6181 ((nth 7 state) ;Inside // comment
6184 ((nth 4 state) ;Inside any comment (hence /**/)
6185 (search-forward "*/"))
6189 (defun verilog-skip-backward-comment-or-string ()
6190 "Return true if in a string or comment."
6191 (let ((state (save-excursion (verilog-syntax-ppss))))
6193 ((nth 3 state) ;Inside string
6194 (search-backward "\"")
6196 ((nth 7 state) ;Inside // comment
6197 (search-backward "//")
6198 (skip-chars-backward "/")
6200 ((nth 4 state) ;Inside /* */ comment
6201 (search-backward "/*")
6206 (defun verilog-skip-backward-comments ()
6207 "Return true if a comment was skipped."
6211 (let ((state (save-excursion (verilog-syntax-ppss))))
6213 ((nth 7 state) ;Inside // comment
6214 (search-backward "//")
6215 (skip-chars-backward "/")
6216 (skip-chars-backward " \t\n\f")
6218 ((nth 4 state) ;Inside /* */ comment
6219 (search-backward "/*")
6220 (skip-chars-backward " \t\n\f")
6223 (= (char-before) ?\/)
6224 (= (char-before (1- (point))) ?\*))
6225 (goto-char (- (point) 2))
6226 t) ;; Let nth 4 state handle the rest
6228 (= (char-before) ?\))
6229 (= (char-before (1- (point))) ?\*))
6230 (goto-char (- (point) 2))
6231 (if (search-backward "(*" nil t)
6233 (skip-chars-backward " \t\n\f")
6236 (goto-char (+ (point) 2))
6239 (/= (skip-chars-backward " \t\n\f") 0))))))))
6241 (defun verilog-skip-forward-comment-p ()
6242 "If in comment, move to end and return true."
6244 (state (save-excursion (verilog-syntax-ppss)))
6246 ((nth 3 state) ;Inside string
6248 ((nth 7 state) ;Inside // comment
6252 ((nth 4 state) ;Inside /* comment
6253 (search-forward "*/")
6255 ((verilog-in-attribute-p) ;Inside (* attribute
6256 (search-forward "*)" nil t)
6259 (skip-chars-forward " \t\n\f")
6262 ((looking-at "\\/\\*")
6265 (goto-char (match-end 0))
6266 (if (search-forward "*/" nil t)
6268 (skip-chars-forward " \t\n\f")
6273 ((looking-at "(\\*")
6276 (goto-char (match-end 0))
6277 (if (search-forward "*)" nil t)
6279 (skip-chars-forward " \t\n\f")
6287 (defun verilog-indent-line-relative ()
6288 "Cheap version of indent line.
6289 Only look at a few lines to determine indent level."
6293 (if (looking-at "^[ \t]*$")
6294 (cond ;- A blank line; No need to be too smart.
6296 (setq indent-str (list 'cpp 0)))
6297 ((verilog-continued-line)
6298 (let ((sp1 (point)))
6299 (if (verilog-continued-line)
6303 (list 'statement (verilog-current-indent-level))))
6305 (setq indent-str (list 'block (verilog-current-indent-level)))))
6308 (setq indent-str (verilog-calculate-indent))))
6309 (progn (skip-chars-forward " \t")
6310 (setq indent-str (verilog-calculate-indent))))
6311 (verilog-do-indent indent-str)))
6313 (defun verilog-indent-line ()
6314 "Indent for special part of code."
6315 (verilog-do-indent (verilog-calculate-indent)))
6317 (defun verilog-do-indent (indent-str)
6318 (let ((type (car indent-str))
6319 (ind (car (cdr indent-str))))
6321 (; handle continued exp
6323 (let ((here (point)))
6324 (verilog-backward-syntactic-ws)
6327 (= (preceding-char) ?\,)
6328 (= (preceding-char) ?\])
6330 (verilog-beg-of-statement-1)
6331 (looking-at verilog-declaration-re)))
6336 (verilog-beg-of-statement-1)
6338 (if (looking-at verilog-declaration-re)
6339 (progn ;; we have multiple words
6340 (goto-char (match-end 0))
6341 (skip-chars-forward " \t")
6343 ((and verilog-indent-declaration-macros
6344 (= (following-char) ?\`))
6348 (skip-chars-forward " \t")))
6349 ((= (following-char) ?\[)
6352 (verilog-backward-up-list -1)
6353 (skip-chars-forward " \t"))))
6357 (+ (current-column) verilog-cexp-indent))))))
6359 (indent-line-to val)
6360 (if (and (not verilog-indent-lists)
6362 (verilog-pretty-declarations-auto))
6364 ((= (preceding-char) ?\) )
6366 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6367 (indent-line-to val)))
6371 (verilog-beg-of-statement-1)
6372 (if (and (< (point) here)
6373 (verilog-re-search-forward "=[ \\t]*" here 'move))
6374 (setq val (current-column))
6375 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
6377 (indent-line-to val))))))
6379 (; handle inside parenthetical expressions
6380 (eq type 'cparenexp)
6382 (val (save-excursion
6383 (verilog-backward-up-list 1)
6385 (if verilog-indent-lists
6386 (skip-chars-forward " \t")
6387 (verilog-forward-syntactic-ws))
6391 (decl (save-excursion
6393 (verilog-forward-syntactic-ws)
6395 (looking-at verilog-declaration-re))))
6396 (indent-line-to val)
6398 (verilog-pretty-declarations-auto))))
6400 (;-- Handle the ends
6402 (looking-at verilog-end-block-re)
6403 (verilog-at-close-constraint-p)
6404 (verilog-at-close-struct-p))
6405 (let ((val (if (eq type 'statement)
6406 (- ind verilog-indent-level)
6408 (indent-line-to val)))
6410 (;-- Case -- maybe line 'em up
6411 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
6414 ((looking-at "\\<endcase\\>")
6415 (indent-line-to ind))
6417 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6418 (indent-line-to val))))))
6421 (and (eq type 'defun)
6422 (looking-at verilog-zero-indent-re))
6429 (looking-at verilog-declaration-re))
6430 (verilog-indent-declaration ind))
6432 (;-- Everything else
6434 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6435 (indent-line-to val))))
6437 (if (looking-at "[ \t]+$")
6438 (skip-chars-forward " \t"))
6439 indent-str ; Return indent data
6442 (defun verilog-current-indent-level ()
6443 "Return the indent-level of the current statement."
6447 (setq par-pos (verilog-parenthesis-depth))
6451 (setq par-pos (verilog-parenthesis-depth)))
6452 (skip-chars-forward " \t")
6455 (defun verilog-case-indent-level ()
6456 "Return the indent-level of the current statement.
6457 Do not count named blocks or case-statements."
6459 (skip-chars-forward " \t")
6461 ((looking-at verilog-named-block-re)
6463 ((and (not (looking-at verilog-extended-case-re))
6464 (looking-at "^[^:;]+[ \t]*:"))
6465 (verilog-re-search-forward ":" nil t)
6466 (skip-chars-forward " \t")
6469 (current-column)))))
6471 (defun verilog-indent-comment ()
6472 "Indent current line as comment."
6475 ((verilog-in-star-comment-p)
6477 (re-search-backward "/\\*" nil t)
6478 (1+(current-column))))
6483 (re-search-backward "//" nil t)
6484 (current-column))))))
6485 (indent-line-to stcol)
6488 (defun verilog-more-comment ()
6489 "Make more comment lines like the previous."
6493 ((verilog-in-star-comment-p)
6496 (re-search-backward "/\\*" nil t)
6497 (1+(current-column))))
6502 (re-search-backward "//" nil t)
6503 (current-column))))))
6509 (skip-chars-forward " \t")
6513 (defun verilog-comment-indent (&optional _arg)
6514 "Return the column number the line should be indented to.
6515 _ARG is ignored, for `comment-indent-function' compatibility."
6517 ((verilog-in-star-comment-p)
6519 (re-search-backward "/\\*" nil t)
6520 (1+(current-column))))
6525 (re-search-backward "//" nil t)
6526 (current-column)))))
6530 (defun verilog-pretty-declarations-auto (&optional quiet)
6531 "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'."
6532 (when (or (eq 'all verilog-auto-lineup)
6533 (eq 'declarations verilog-auto-lineup))
6534 (verilog-pretty-declarations quiet)))
6536 (defun verilog-pretty-declarations (&optional quiet)
6537 "Line up declarations around point.
6538 Be verbose about progress unless optional QUIET set."
6540 (let* ((m1 (make-marker))
6554 ; (verilog-beg-of-statement-1)
6556 (verilog-forward-syntactic-ws)
6557 (and (not (verilog-in-directive-p)) ;; could have `define input foo
6558 (looking-at verilog-declaration-re)))
6560 (if (verilog-parenthesis-depth)
6561 ;; in an argument list or parameter block
6562 (setq el (verilog-backward-up-list -1)
6565 (verilog-backward-up-list 1)
6566 (forward-line) ;; ignore ( input foo,
6567 (verilog-re-search-forward verilog-declaration-re el 'move)
6568 (goto-char (match-beginning 0))
6569 (skip-chars-backward " \t")
6571 startpos (set-marker (make-marker) start)
6574 (verilog-backward-up-list -1)
6576 (verilog-backward-syntactic-ws)
6578 endpos (set-marker (make-marker) end)
6582 (skip-chars-forward " \t")
6584 ;; in a declaration block (not in argument list)
6587 (verilog-beg-of-statement-1)
6588 (while (and (looking-at verilog-declaration-re)
6590 (skip-chars-backward " \t")
6593 (verilog-backward-syntactic-ws)
6595 (verilog-beg-of-statement-1))
6597 startpos (set-marker (make-marker) start)
6600 (verilog-end-of-statement)
6601 (setq e (point)) ;Might be on last line
6602 (verilog-forward-syntactic-ws)
6603 (while (looking-at verilog-declaration-re)
6604 (verilog-end-of-statement)
6606 (verilog-forward-syntactic-ws))
6608 endpos (set-marker (make-marker) end)
6611 (verilog-do-indent (verilog-calculate-indent))
6612 (verilog-forward-ws&directives)
6614 ;; OK, start and end are set
6615 (goto-char (marker-position startpos))
6616 (if (and (not quiet)
6617 (> (- end start) 100))
6618 (message "Lining up declarations..(please stand by)"))
6619 ;; Get the beginning of line indent first
6620 (while (progn (setq e (marker-position endpos))
6623 ((save-excursion (skip-chars-backward " \t")
6625 (verilog-forward-ws&directives)
6626 (indent-line-to base-ind)
6627 (verilog-forward-ws&directives)
6629 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6632 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6635 ;; Now find biggest prefix
6636 (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
6637 ;; Now indent each line.
6638 (goto-char (marker-position startpos))
6639 (while (progn (setq e (marker-position endpos))
6640 (setq r (- e (point)))
6643 (unless quiet (message "%d" r))
6644 ;;(verilog-do-indent (verilog-calculate-indent)))
6645 (verilog-forward-ws&directives)
6647 ((or (and verilog-indent-declaration-macros
6648 (looking-at verilog-declaration-re-2-macro))
6649 (looking-at verilog-declaration-re-2-no-macro))
6650 (let ((p (match-end 0)))
6652 (if (verilog-re-search-forward "[[#`]" p 'move)
6656 (goto-char (marker-position m1))
6662 ((verilog-continued-line-1 (marker-position startpos))
6664 (indent-line-to ind))
6665 ((verilog-in-struct-p)
6666 ;; could have a declaration of a user defined item
6668 (verilog-end-of-statement))
6669 (t ; Must be comment or white space
6671 (verilog-forward-ws&directives)
6674 (unless quiet (message "")))))))
6676 (defun verilog-pretty-expr (&optional quiet _myre)
6677 "Line up expressions around point, optionally QUIET with regexp _MYRE ignored."
6679 (if (not (verilog-in-comment-or-string-p))
6681 (let ( (rexp (concat "^\\s-*" verilog-complete-reg))
6682 (rexp1 (concat "^\\s-*" verilog-basic-complete-re)))
6684 (if (and (not (looking-at rexp ))
6685 (looking-at verilog-assignment-operation-re)
6687 (goto-char (match-end 2))
6688 (and (not (verilog-in-attribute-p))
6689 (not (verilog-in-parameter-p))
6690 (not (verilog-in-comment-or-string-p)))))
6691 (let* ((here (point))
6697 (verilog-backward-syntactic-ws)
6699 (while (and (not (looking-at rexp1))
6700 (looking-at verilog-assignment-operation-re)
6704 (verilog-backward-syntactic-ws)
6706 ) ;Ack, need to grok `define
6712 (setq e (point)) ;Might be on last line
6713 (verilog-forward-syntactic-ws)
6716 (not (looking-at rexp1 ))
6717 (looking-at verilog-assignment-operation-re)
6720 (not (eq e (point)))))
6722 (verilog-forward-syntactic-ws)
6726 (endpos (set-marker (make-marker) end))
6730 (verilog-do-indent (verilog-calculate-indent))
6731 (if (and (not quiet)
6732 (> (- end start) 100))
6733 (message "Lining up expressions..(please stand by)"))
6735 ;; Set indent to minimum throughout region
6736 (while (< (point) (marker-position endpos))
6738 (verilog-just-one-space verilog-assignment-operation-re)
6740 (verilog-do-indent (verilog-calculate-indent))
6742 (verilog-forward-syntactic-ws)
6745 ;; Now find biggest prefix
6746 (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))
6748 ;; Now indent each line.
6750 (while (progn (setq e (marker-position endpos))
6751 (setq r (- e (point)))
6754 (if (not quiet) (message "%d" r))
6756 ((looking-at verilog-assignment-operation-re)
6757 (goto-char (match-beginning 2))
6758 (if (not (or (verilog-in-parenthesis-p) ;; leave attributes and comparisons alone
6759 (verilog-in-coverage-p)))
6760 (if (eq (char-after) ?=)
6761 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
6765 ((verilog-continued-line-1 start)
6767 (indent-line-to ind))
6768 (t ; Must be comment or white space
6770 (verilog-forward-ws&directives)
6774 (unless quiet (message ""))
6777 (defun verilog-just-one-space (myre)
6778 "Remove extra spaces around regular expression MYRE."
6780 (if (and (not(looking-at verilog-complete-reg))
6782 (let ((p1 (match-end 1))
6788 (just-one-space)))))
6790 (defun verilog-indent-declaration (baseind)
6791 "Indent current lines as declaration.
6792 Line up the variable names based on previous declaration's indentation.
6793 BASEIND is the base indent to offset everything."
6795 (let ((pos (point-marker))
6796 (lim (save-excursion
6797 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
6798 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
6804 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6805 (indent-line-to val)
6807 ;; Use previous declaration (in this module) as template.
6808 (if (or (eq 'all verilog-auto-lineup)
6809 (eq 'declarations verilog-auto-lineup))
6810 (if (verilog-re-search-backward
6811 (or (and verilog-indent-declaration-macros
6812 verilog-declaration-re-1-macro)
6813 verilog-declaration-re-1-no-macro) lim t)
6815 (goto-char (match-end 0))
6816 (skip-chars-forward " \t")
6817 (setq ind (current-column))
6821 (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6822 (indent-line-to val)
6823 (if (and verilog-indent-declaration-macros
6824 (looking-at verilog-declaration-re-2-macro))
6825 (let ((p (match-end 0)))
6827 (if (verilog-re-search-forward "[[#`]" p 'move)
6831 (goto-char (marker-position m1))
6834 (if (/= (current-column) ind)
6838 (if (looking-at verilog-declaration-re-2-no-macro)
6839 (let ((p (match-end 0)))
6841 (if (verilog-re-search-forward "[[`#]" p 'move)
6845 (goto-char (marker-position m1))
6848 (if (/= (current-column) ind)
6851 (indent-to ind))))))))))
6854 (defun verilog-get-lineup-indent (b edpos)
6855 "Return the indent level that will line up several lines within the region.
6856 Region is defined by B and EDPOS."
6860 ;; Get rightmost position
6861 (while (progn (setq e (marker-position edpos))
6863 (if (verilog-re-search-forward
6864 (or (and verilog-indent-declaration-macros
6865 verilog-declaration-re-1-macro)
6866 verilog-declaration-re-1-no-macro) e 'move)
6868 (goto-char (match-end 0))
6869 (verilog-backward-syntactic-ws)
6870 (if (> (current-column) ind)
6871 (setq ind (current-column)))
6872 (goto-char (match-end 0)))))
6875 ;; No lineup-string found
6878 (verilog-backward-syntactic-ws)
6879 ;;(skip-chars-backward " \t")
6880 (1+ (current-column))))))
6882 (defun verilog-get-lineup-indent-2 (myre b edpos)
6883 "Return the indent level that will line up several lines within the region."
6887 ;; Get rightmost position
6888 (while (progn (setq e (marker-position edpos))
6890 (if (and (verilog-re-search-forward myre e 'move)
6891 (not (verilog-in-attribute-p))) ;; skip attribute exprs
6893 (goto-char (match-beginning 2))
6894 (verilog-backward-syntactic-ws)
6895 (if (> (current-column) ind)
6896 (setq ind (current-column)))
6897 (goto-char (match-end 0)))
6901 ;; No lineup-string found
6904 (skip-chars-backward " \t")
6905 (1+ (current-column))))))
6907 (defun verilog-comment-depth (type val)
6908 "A useful mode debugging aide. TYPE and VAL are comments for insertion."
6915 (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t)
6917 (replace-match " /* -# ## */")
6921 (insert " /* ## ## */"))))
6924 (format "%s %d" type val))))
6930 (defvar verilog-str nil)
6931 (defvar verilog-all nil)
6932 (defvar verilog-pred nil)
6933 (defvar verilog-buffer-to-use nil)
6934 (defvar verilog-flag nil)
6935 (defvar verilog-toggle-completions nil
6936 "True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
6937 Repeated use of \\[verilog-complete-word] will show you all of them.
6938 Normally, when there is more than one possible completion,
6939 it displays a list of all possible completions.")
6942 (defvar verilog-type-keywords
6944 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
6945 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
6946 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
6947 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
6948 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
6949 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
6951 "Keywords for types used when completing a word in a declaration or parmlist.
6952 \(integer, real, reg...)")
6954 (defvar verilog-cpp-keywords
6955 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
6957 "Keywords to complete when at first word of a line in declarative scope.
6958 \(initial, always, begin, assign...)
6959 The procedures and variables defined within the Verilog program
6960 will be completed at runtime and should not be added to this list.")
6962 (defvar verilog-defun-keywords
6965 "always" "always_comb" "always_ff" "always_latch" "assign"
6966 "begin" "end" "generate" "endgenerate" "module" "endmodule"
6967 "specify" "endspecify" "function" "endfunction" "initial" "final"
6968 "task" "endtask" "primitive" "endprimitive"
6970 verilog-type-keywords)
6971 "Keywords to complete when at first word of a line in declarative scope.
6972 \(initial, always, begin, assign...)
6973 The procedures and variables defined within the Verilog program
6974 will be completed at runtime and should not be added to this list.")
6976 (defvar verilog-block-keywords
6978 "begin" "break" "case" "continue" "else" "end" "endfunction"
6979 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
6980 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
6982 "Keywords to complete when at first word of a line in behavioral scope.
6983 \(begin, if, then, else, for, fork...)
6984 The procedures and variables defined within the Verilog program
6985 will be completed at runtime and should not be added to this list.")
6987 (defvar verilog-tf-keywords
6988 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
6989 "Keywords to complete when at first word of a line in a task or function.
6990 \(begin, if, then, else, for, fork.)
6991 The procedures and variables defined within the Verilog program
6992 will be completed at runtime and should not be added to this list.")
6994 (defvar verilog-case-keywords
6995 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
6996 "Keywords to complete when at first word of a line in case scope.
6997 \(begin, if, then, else, for, fork...)
6998 The procedures and variables defined within the Verilog program
6999 will be completed at runtime and should not be added to this list.")
7001 (defvar verilog-separator-keywords
7002 '("else" "then" "begin")
7003 "Keywords to complete when NOT standing at the first word of a statement.
7004 \(else, then, begin...)
7005 Variables and function names defined within the Verilog program
7006 will be completed at runtime and should not be added to this list.")
7008 (defvar verilog-gate-ios
7009 ;; All these have an implied {"input"...} at the end
7023 ("pulldown" "output")
7028 ("rtran" "inout" "inout")
7029 ("rtranif0" "inout" "inout")
7030 ("rtranif1" "inout" "inout")
7031 ("tran" "inout" "inout")
7032 ("tranif0" "inout" "inout")
7033 ("tranif1" "inout" "inout")
7036 "Map of direction for each positional argument to each gate primitive.")
7038 (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
7039 "Keywords for gate primitives.")
7041 (defun verilog-string-diff (str1 str2)
7042 "Return index of first letter where STR1 and STR2 differs."
7046 (if (or (> (1+ diff) (length str1))
7047 (> (1+ diff) (length str2)))
7049 (or (equal (aref str1 diff) (aref str2 diff))
7051 (setq diff (1+ diff))))))
7053 ;; Calculate all possible completions for functions if argument is `function',
7054 ;; completions for procedures if argument is `procedure' or both functions and
7055 ;; procedures otherwise.
7057 (defun verilog-func-completion (type)
7058 "Build regular expression for module/task/function names.
7059 TYPE is 'module, 'tf for task or function, or t if unknown."
7060 (if (string= verilog-str "")
7061 (setq verilog-str "[a-zA-Z_]"))
7062 (let ((verilog-str (concat (cond
7063 ((eq type 'module) "\\<\\(module\\)\\s +")
7064 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
7065 (t "\\<\\(task\\|function\\|module\\)\\s +"))
7066 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
7069 (if (not (looking-at verilog-defun-re))
7070 (verilog-re-search-backward verilog-defun-re nil t))
7073 ;; Search through all reachable functions
7074 (goto-char (point-min))
7075 (while (verilog-re-search-forward verilog-str (point-max) t)
7076 (progn (setq match (buffer-substring (match-beginning 2)
7078 (if (or (null verilog-pred)
7079 (funcall verilog-pred match))
7080 (setq verilog-all (cons match verilog-all)))))
7081 (if (match-beginning 0)
7082 (goto-char (match-beginning 0)))))
7084 (defun verilog-get-completion-decl (end)
7085 "Macro for searching through current declaration (var, type or const)
7086 for matches of `str' and adding the occurrence tp `all' through point END."
7087 (let ((re (or (and verilog-indent-declaration-macros
7088 verilog-declaration-re-2-macro)
7089 verilog-declaration-re-2-no-macro))
7092 (while (and (< (point) end)
7093 (verilog-re-search-forward re end t))
7094 ;; Traverse current line
7095 (setq decl-end (save-excursion (verilog-declaration-end)))
7096 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
7097 (not (match-end 1)))
7098 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
7099 (if (string-match (concat "\\<" verilog-str) match)
7100 (if (or (null verilog-pred)
7101 (funcall verilog-pred match))
7102 (setq verilog-all (cons match verilog-all)))))
7106 (defun verilog-var-completion ()
7107 "Calculate all possible completions for variables (or constants)."
7108 (let ((start (point)))
7109 ;; Search for all reachable var declarations
7110 (verilog-beg-of-defun)
7112 ;; Check var declarations
7113 (verilog-get-completion-decl start))))
7115 (defun verilog-keyword-completion (keyword-list)
7116 "Give list of all possible completions of keywords in KEYWORD-LIST."
7118 (if (string-match (concat "\\<" verilog-str) s)
7119 (if (or (null verilog-pred)
7120 (funcall verilog-pred s))
7121 (setq verilog-all (cons s verilog-all)))))
7125 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
7126 "Function passed to `completing-read', `try-completion' or `all-completions'.
7127 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
7128 must be a function to be called for every match to check if this should
7129 really be a match. If VERILOG-FLAG is t, the function returns a list of
7130 all possible completions. If VERILOG-FLAG is nil it returns a string,
7131 the longest possible completion, or t if VERILOG-STR is an exact match.
7132 If VERILOG-FLAG is 'lambda, the function returns t if VERILOG-STR is an
7133 exact match, nil otherwise."
7135 (let ((verilog-all nil))
7136 ;; Set buffer to use for searching labels. This should be set
7137 ;; within functions which use verilog-completions
7138 (set-buffer verilog-buffer-to-use)
7140 ;; Determine what should be completed
7141 (let ((state (car (verilog-calculate-indent))))
7142 (cond ((eq state 'defun)
7143 (save-excursion (verilog-var-completion))
7144 (verilog-func-completion 'module)
7145 (verilog-keyword-completion verilog-defun-keywords))
7147 ((eq state 'behavioral)
7148 (save-excursion (verilog-var-completion))
7149 (verilog-func-completion 'module)
7150 (verilog-keyword-completion verilog-defun-keywords))
7153 (save-excursion (verilog-var-completion))
7154 (verilog-func-completion 'tf)
7155 (verilog-keyword-completion verilog-block-keywords))
7158 (save-excursion (verilog-var-completion))
7159 (verilog-func-completion 'tf)
7160 (verilog-keyword-completion verilog-case-keywords))
7163 (save-excursion (verilog-var-completion))
7164 (verilog-func-completion 'tf)
7165 (verilog-keyword-completion verilog-tf-keywords))
7168 (save-excursion (verilog-var-completion))
7169 (verilog-keyword-completion verilog-cpp-keywords))
7171 ((eq state 'cparenexp)
7172 (save-excursion (verilog-var-completion)))
7175 (save-excursion (verilog-var-completion))
7176 (verilog-func-completion 'both)
7177 (verilog-keyword-completion verilog-separator-keywords))))
7179 ;; Now we have built a list of all matches. Give response to caller
7180 (verilog-completion-response))))
7182 (defun verilog-completion-response ()
7183 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
7184 ;; This was not called by all-completions
7185 (if (null verilog-all)
7186 ;; Return nil if there was no matching label
7188 ;; Get longest string common in the labels
7189 ;; FIXME: Why not use `try-completion'?
7190 (let* ((elm (cdr verilog-all))
7191 (match (car verilog-all))
7192 (min (length match))
7194 (if (string= match verilog-str)
7195 ;; Return t if first match was an exact match
7197 (while (not (null elm))
7198 ;; Find longest common string
7199 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
7202 (setq match (substring match 0 min))))
7203 ;; Terminate with match=t if this is an exact match
7204 (if (string= (car elm) verilog-str)
7208 (setq elm (cdr elm)))))
7209 ;; If this is a test just for exact match, return nil ot t
7210 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
7213 ;; If flag is t, this was called by all-completions. Return
7214 ;; list of all possible completions
7218 (defvar verilog-last-word-numb 0)
7219 (defvar verilog-last-word-shown nil)
7220 (defvar verilog-last-completions nil)
7222 (defun verilog-complete-word ()
7223 "Complete word at current point.
7224 \(See also `verilog-toggle-completions', `verilog-type-keywords',
7225 and `verilog-separator-keywords'.)"
7226 ;; FIXME: Provide completion-at-point-function.
7228 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7229 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7230 (verilog-str (buffer-substring b e))
7231 ;; The following variable is used in verilog-completion
7232 (verilog-buffer-to-use (current-buffer))
7233 (allcomp (if (and verilog-toggle-completions
7234 (string= verilog-last-word-shown verilog-str))
7235 verilog-last-completions
7236 (all-completions verilog-str 'verilog-completion)))
7237 (match (if verilog-toggle-completions
7239 verilog-str (mapcar (lambda (elm)
7240 (cons elm 0)) allcomp)))))
7241 ;; Delete old string
7244 ;; Toggle-completions inserts whole labels
7245 (if verilog-toggle-completions
7247 ;; Update entry number in list
7248 (setq verilog-last-completions allcomp
7249 verilog-last-word-numb
7250 (if (>= verilog-last-word-numb (1- (length allcomp)))
7252 (1+ verilog-last-word-numb)))
7253 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
7254 ;; Display next match or same string if no match was found
7255 (if (not (null allcomp))
7256 (insert "" verilog-last-word-shown)
7257 (insert "" verilog-str)
7258 (message "(No match)")))
7259 ;; The other form of completion does not necessarily do that.
7261 ;; Insert match if found, or the original string if no match
7262 (if (or (null match) (equal match 't))
7263 (progn (insert "" verilog-str)
7264 (message "(No match)"))
7266 ;; Give message about current status of completion
7267 (cond ((equal match 't)
7268 (if (not (null (cdr allcomp)))
7269 (message "(Complete but not unique)")
7270 (message "(Sole completion)")))
7271 ;; Display buffer if the current completion didn't help
7272 ;; on completing the label.
7273 ((and (not (null (cdr allcomp))) (= (length verilog-str)
7275 (with-output-to-temp-buffer "*Completions*"
7276 (display-completion-list allcomp))
7277 ;; Wait for a key press. Then delete *Completion* window
7278 (momentary-string-display "" (point))
7279 (delete-window (get-buffer-window (get-buffer "*Completions*")))
7282 (defun verilog-show-completions ()
7283 "Show all possible completions at current point."
7285 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7286 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7287 (verilog-str (buffer-substring b e))
7288 ;; The following variable is used in verilog-completion
7289 (verilog-buffer-to-use (current-buffer))
7290 (allcomp (if (and verilog-toggle-completions
7291 (string= verilog-last-word-shown verilog-str))
7292 verilog-last-completions
7293 (all-completions verilog-str 'verilog-completion))))
7294 ;; Show possible completions in a temporary buffer.
7295 (with-output-to-temp-buffer "*Completions*"
7296 (display-completion-list allcomp))
7297 ;; Wait for a key press. Then delete *Completion* window
7298 (momentary-string-display "" (point))
7299 (delete-window (get-buffer-window (get-buffer "*Completions*")))))
7302 (defun verilog-get-default-symbol ()
7303 "Return symbol around current point as a string."
7305 (buffer-substring (progn
7306 (skip-chars-backward " \t")
7307 (skip-chars-backward "a-zA-Z0-9_")
7310 (skip-chars-forward "a-zA-Z0-9_")
7313 (defun verilog-build-defun-re (str &optional arg)
7314 "Return function/task/module starting with STR as regular expression.
7315 With optional second ARG non-nil, STR is the complete name of the instruction."
7317 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
7318 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
7320 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
7321 "Function passed to `completing-read', `try-completion' or `all-completions'.
7322 Returns a completion on any function name based on VERILOG-STR prefix. If
7323 VERILOG-PRED is non-nil, it must be a function to be called for every match
7324 to check if this should really be a match. If VERILOG-FLAG is t, the
7325 function returns a list of all possible completions. If it is nil it
7326 returns a string, the longest possible completion, or t if VERILOG-STR is
7327 an exact match. If VERILOG-FLAG is 'lambda, the function returns t if
7328 VERILOG-STR is an exact match, nil otherwise."
7330 (let ((verilog-all nil)
7333 ;; Set buffer to use for searching labels. This should be set
7334 ;; within functions which use verilog-completions
7335 (set-buffer verilog-buffer-to-use)
7337 (let ((verilog-str verilog-str))
7338 ;; Build regular expression for functions
7339 (if (string= verilog-str "")
7340 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
7341 (setq verilog-str (verilog-build-defun-re verilog-str)))
7342 (goto-char (point-min))
7344 ;; Build a list of all possible completions
7345 (while (verilog-re-search-forward verilog-str nil t)
7346 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
7347 (if (or (null verilog-pred)
7348 (funcall verilog-pred match))
7349 (setq verilog-all (cons match verilog-all)))))
7351 ;; Now we have built a list of all matches. Give response to caller
7352 (verilog-completion-response))))
7354 (defun verilog-goto-defun ()
7355 "Move to specified Verilog module/interface/task/function.
7356 The default is a name found in the buffer around point.
7357 If search fails, other files are checked based on
7358 `verilog-library-flags'."
7360 (let* ((default (verilog-get-default-symbol))
7361 ;; The following variable is used in verilog-comp-function
7362 (verilog-buffer-to-use (current-buffer))
7363 (label (if (not (string= default ""))
7364 ;; Do completion with default
7365 (completing-read (concat "Goto-Label: (default "
7367 'verilog-comp-defun nil nil "")
7368 ;; There is no default value. Complete without it
7369 (completing-read "Goto-Label: "
7370 'verilog-comp-defun nil nil "")))
7372 ;; Make sure library paths are correct, in case need to resolve module
7373 (verilog-auto-reeval-locals)
7374 (verilog-getopt-flags)
7375 ;; If there was no response on prompt, use default value
7376 (if (string= label "")
7377 (setq label default))
7378 ;; Goto right place in buffer if label is not an empty string
7379 (or (string= label "")
7382 (goto-char (point-min))
7384 (re-search-forward (verilog-build-defun-re label t) nil t)))
7387 (beginning-of-line))
7389 (verilog-goto-defun-file label))))
7391 ;; Eliminate compile warning
7392 (defvar occur-pos-list)
7394 (defun verilog-showscopes ()
7395 "List all scopes in this module."
7397 (let ((buffer (current-buffer))
7401 (prevpos (point-min))
7402 (final-context-start (make-marker))
7403 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
7404 (with-output-to-temp-buffer "*Occur*"
7406 (message (format "Searching for %s ..." regexp))
7407 ;; Find next match, but give up if prev match was at end of buffer.
7408 (while (and (not (= prevpos (point-max)))
7409 (verilog-re-search-forward regexp nil t))
7410 (goto-char (match-beginning 0))
7413 (setq linenum (+ linenum (count-lines prevpos (point)))))
7414 (setq prevpos (point))
7415 (goto-char (match-end 0))
7416 (let* ((start (save-excursion
7417 (goto-char (match-beginning 0))
7418 (forward-line (if (< nlines 0) nlines (- nlines)))
7420 (end (save-excursion
7421 (goto-char (match-end 0))
7423 (forward-line (1+ nlines))
7426 (tag (format "%3d" linenum))
7427 (empty (make-string (length tag) ?\ ))
7430 (setq tem (make-marker))
7431 (set-marker tem (point))
7432 (set-buffer standard-output)
7433 (setq occur-pos-list (cons tem occur-pos-list))
7434 (or first (zerop nlines)
7435 (insert "--------\n"))
7437 (insert-buffer-substring buffer start end)
7438 (backward-char (- end start))
7439 (setq tem (if (< nlines 0) (- nlines) nlines))
7443 (setq tem (1- tem)))
7444 (let ((this-linenum linenum))
7445 (set-marker final-context-start
7446 (+ (point) (- (match-end 0) (match-beginning 0))))
7447 (while (< (point) final-context-start)
7449 (setq tag (format "%3d" this-linenum)))
7450 (insert tag ?:)))))))
7451 (set-buffer-modified-p nil))))
7454 ;; Highlight helper functions
7455 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
7456 (defun verilog-within-translate-off ()
7457 "Return point if within translate-off region, else nil."
7458 (and (save-excursion
7460 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
7462 (equal "off" (match-string 2))
7465 (defun verilog-start-translate-off (limit)
7466 "Return point before translate-off directive if before LIMIT, else nil."
7467 (when (re-search-forward
7468 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7470 (match-beginning 0)))
7472 (defun verilog-back-to-start-translate-off (limit)
7473 "Return point before translate-off directive if before LIMIT, else nil."
7474 (when (re-search-backward
7475 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7477 (match-beginning 0)))
7479 (defun verilog-end-translate-off (limit)
7480 "Return point after translate-on directive if before LIMIT, else nil."
7482 (re-search-forward (concat
7483 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
7485 (defun verilog-match-translate-off (limit)
7486 "Match a translate-off block, setting `match-data' and returning t, else nil.
7487 Bound search by LIMIT."
7488 (when (< (point) limit)
7489 (let ((start (or (verilog-within-translate-off)
7490 (verilog-start-translate-off limit)))
7491 (case-fold-search t))
7493 (let ((end (or (verilog-end-translate-off limit) limit)))
7494 (set-match-data (list start end))
7495 (goto-char end))))))
7497 (defun verilog-font-lock-match-item (limit)
7498 "Match, and move over, any declaration item after point.
7499 Bound search by LIMIT. Adapted from
7500 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
7503 (narrow-to-region (point-min) limit)
7505 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
7507 (goto-char (match-end 1))
7508 ;; move to next item
7509 (if (looking-at "\\(\\s-*,\\)")
7510 (goto-char (match-end 1))
7515 ;; Added by Subbu Meiyappan for Header
7517 (defun verilog-header ()
7518 "Insert a standard Verilog file header.
7519 See also `verilog-sk-header' for an alternative format."
7521 (let ((start (point)))
7523 //-----------------------------------------------------------------------------
7525 // Project : <project>
7526 //-----------------------------------------------------------------------------
7527 // File : <filename>
7528 // Author : <author>
7529 // Created : <credate>
7530 // Last modified : <moddate>
7531 //-----------------------------------------------------------------------------
7534 //-----------------------------------------------------------------------------
7535 // Copyright (c) <copydate> by <company> This model is the confidential and
7536 // proprietary property of <company> and the possession or use of this
7537 // file requires a written license from <company>.
7538 //------------------------------------------------------------------------------
7539 // Modification history :
7541 //-----------------------------------------------------------------------------
7545 (search-forward "<filename>")
7546 (replace-match (buffer-name) t t)
7547 (search-forward "<author>") (replace-match "" t t)
7548 (insert (user-full-name))
7549 (insert " <" (user-login-name) "@" (system-name) ">")
7550 (search-forward "<credate>") (replace-match "" t t)
7551 (verilog-insert-date)
7552 (search-forward "<moddate>") (replace-match "" t t)
7553 (verilog-insert-date)
7554 (search-forward "<copydate>") (replace-match "" t t)
7555 (verilog-insert-year)
7556 (search-forward "<modhist>") (replace-match "" t t)
7557 (verilog-insert-date)
7558 (insert " : created")
7561 (setq string (read-string "title: "))
7562 (search-forward "<title>")
7563 (replace-match string t t)
7564 (setq string (read-string "project: " verilog-project))
7565 (setq verilog-project string)
7566 (search-forward "<project>")
7567 (replace-match string t t)
7568 (setq string (read-string "Company: " verilog-company))
7569 (setq verilog-company string)
7570 (search-forward "<company>")
7571 (replace-match string t t)
7572 (search-forward "<company>")
7573 (replace-match string t t)
7574 (search-forward "<company>")
7575 (replace-match string t t)
7576 (search-backward "<description>")
7577 (replace-match "" t t))))
7579 ;; verilog-header Uses the verilog-insert-date function
7581 (defun verilog-insert-date ()
7582 "Insert date from the system."
7584 (if verilog-date-scientific-format
7585 (insert (format-time-string "%Y/%m/%d"))
7586 (insert (format-time-string "%d.%m.%Y"))))
7588 (defun verilog-insert-year ()
7589 "Insert year from the system."
7591 (insert (format-time-string "%Y")))
7595 ;; Signal list parsing
7598 ;; Elements of a signal list
7599 ;; Unfortunately we use 'assoc' on this, so can't be a vector
7600 (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
7601 (list name bits comment mem enum signed type multidim modport))
7602 (defsubst verilog-sig-name (sig)
7604 (defsubst verilog-sig-bits (sig) ;; First element of packed array (pre signal-name)
7606 (defsubst verilog-sig-comment (sig)
7608 (defsubst verilog-sig-memory (sig) ;; Unpacked array (post signal-name)
7610 (defsubst verilog-sig-enum (sig)
7612 (defsubst verilog-sig-signed (sig)
7614 (defsubst verilog-sig-type (sig)
7616 (defsubst verilog-sig-type-set (sig type)
7617 (setcar (nthcdr 6 sig) type))
7618 (defsubst verilog-sig-multidim (sig) ;; Second and additional elements of packed array
7620 (defsubst verilog-sig-multidim-string (sig)
7621 (if (verilog-sig-multidim sig)
7622 (let ((str "") (args (verilog-sig-multidim sig)))
7624 (setq str (concat str (car args)))
7625 (setq args (cdr args)))
7627 (defsubst verilog-sig-modport (sig)
7629 (defsubst verilog-sig-width (sig)
7630 (verilog-make-width-expression (verilog-sig-bits sig)))
7632 (defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
7633 (vector outputs-del outputs-imm temps inputs))
7634 (defsubst verilog-alw-get-outputs-delayed (sigs)
7636 (defsubst verilog-alw-get-outputs-immediate (sigs)
7638 (defsubst verilog-alw-get-temps (sigs)
7640 (defsubst verilog-alw-get-inputs (sigs)
7642 (defsubst verilog-alw-get-uses-delayed (sigs)
7645 (defsubst verilog-modport-new (name clockings decls)
7646 (list name clockings decls))
7647 (defsubst verilog-modport-name (sig)
7649 (defsubst verilog-modport-clockings (sig)
7650 (nth 1 sig)) ;; Returns list of names
7651 (defsubst verilog-modport-clockings-add (sig val)
7652 (setcar (nthcdr 1 sig) (cons val (nth 1 sig))))
7653 (defsubst verilog-modport-decls (sig)
7654 (nth 2 sig)) ;; Returns verilog-decls-* structure
7655 (defsubst verilog-modport-decls-set (sig val)
7656 (setcar (nthcdr 2 sig) val))
7658 (defsubst verilog-modi-new (name fob pt type)
7659 (vector name fob pt type))
7660 (defsubst verilog-modi-name (modi)
7662 (defsubst verilog-modi-file-or-buffer (modi)
7664 (defsubst verilog-modi-get-point (modi)
7666 (defsubst verilog-modi-get-type (modi) ;; "module" or "interface"
7668 (defsubst verilog-modi-get-decls (modi)
7669 (verilog-modi-cache-results modi 'verilog-read-decls))
7670 (defsubst verilog-modi-get-sub-decls (modi)
7671 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
7673 ;; Signal reading for given module
7674 ;; Note these all take modi's - as returned from verilog-modi-current
7675 (defsubst verilog-decls-new (out inout in vars modports assigns consts gparams interfaces)
7676 (vector out inout in vars modports assigns consts gparams interfaces))
7677 (defsubst verilog-decls-append (a b)
7678 (cond ((not a) b) ((not b) a)
7679 (t (vector (append (aref a 0) (aref b 0)) (append (aref a 1) (aref b 1))
7680 (append (aref a 2) (aref b 2)) (append (aref a 3) (aref b 3))
7681 (append (aref a 4) (aref b 4)) (append (aref a 5) (aref b 5))
7682 (append (aref a 6) (aref b 6)) (append (aref a 7) (aref b 7))
7683 (append (aref a 8) (aref b 8))))))
7684 (defsubst verilog-decls-get-outputs (decls)
7686 (defsubst verilog-decls-get-inouts (decls)
7688 (defsubst verilog-decls-get-inputs (decls)
7690 (defsubst verilog-decls-get-vars (decls)
7692 (defsubst verilog-decls-get-modports (decls) ;; Also for clocking blocks; contains another verilog-decls struct
7693 (aref decls 4)) ;; Returns verilog-modport* structure
7694 (defsubst verilog-decls-get-assigns (decls)
7696 (defsubst verilog-decls-get-consts (decls)
7698 (defsubst verilog-decls-get-gparams (decls)
7700 (defsubst verilog-decls-get-interfaces (decls)
7704 (defsubst verilog-subdecls-new (out inout in intf intfd)
7705 (vector out inout in intf intfd))
7706 (defsubst verilog-subdecls-get-outputs (subdecls)
7708 (defsubst verilog-subdecls-get-inouts (subdecls)
7710 (defsubst verilog-subdecls-get-inputs (subdecls)
7712 (defsubst verilog-subdecls-get-interfaces (subdecls)
7714 (defsubst verilog-subdecls-get-interfaced (subdecls)
7717 (defun verilog-signals-from-signame (signame-list)
7718 "Return signals in standard form from SIGNAME-LIST, a simple list of names."
7719 (mapcar (lambda (name) (verilog-sig-new name nil nil nil nil nil nil nil nil))
7722 (defun verilog-signals-in (in-list not-list)
7723 "Return list of signals in IN-LIST that are also in NOT-LIST.
7724 Also remove any duplicates in IN-LIST.
7725 Signals must be in standard (base vector) form."
7726 ;; This function is hot, so implemented as O(1)
7727 (cond ((eval-when-compile (fboundp 'make-hash-table))
7728 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
7729 (ht-not (make-hash-table :test 'equal :rehash-size 4.0))
7732 (puthash (car (car not-list)) t ht-not)
7733 (setq not-list (cdr not-list)))
7735 (when (and (gethash (verilog-sig-name (car in-list)) ht-not)
7736 (not (gethash (verilog-sig-name (car in-list)) ht)))
7737 (setq out-list (cons (car in-list) out-list))
7738 (puthash (verilog-sig-name (car in-list)) t ht))
7739 (setq in-list (cdr in-list)))
7740 (nreverse out-list)))
7741 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
7745 (if (and (assoc (verilog-sig-name (car in-list)) not-list)
7746 (not (assoc (verilog-sig-name (car in-list)) out-list)))
7747 (setq out-list (cons (car in-list) out-list)))
7748 (setq in-list (cdr in-list)))
7749 (nreverse out-list)))))
7750 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("C" "")))
7752 (defun verilog-signals-not-in (in-list not-list)
7753 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
7754 Also remove any duplicates in IN-LIST.
7755 Signals must be in standard (base vector) form."
7756 ;; This function is hot, so implemented as O(1)
7757 (cond ((eval-when-compile (fboundp 'make-hash-table))
7758 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
7761 (puthash (car (car not-list)) t ht)
7762 (setq not-list (cdr not-list)))
7764 (when (not (gethash (verilog-sig-name (car in-list)) ht))
7765 (setq out-list (cons (car in-list) out-list))
7766 (puthash (verilog-sig-name (car in-list)) t ht))
7767 (setq in-list (cdr in-list)))
7768 (nreverse out-list)))
7769 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
7773 (if (and (not (assoc (verilog-sig-name (car in-list)) not-list))
7774 (not (assoc (verilog-sig-name (car in-list)) out-list)))
7775 (setq out-list (cons (car in-list) out-list)))
7776 (setq in-list (cdr in-list)))
7777 (nreverse out-list)))))
7778 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
7780 (defun verilog-signals-memory (in-list)
7781 "Return list of signals in IN-LIST that are memorized (multidimensional)."
7784 (if (nth 3 (car in-list))
7785 (setq out-list (cons (car in-list) out-list)))
7786 (setq in-list (cdr in-list)))
7788 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
7790 (defun verilog-signals-sort-compare (a b)
7791 "Compare signal A and B for sorting."
7792 (string< (verilog-sig-name a) (verilog-sig-name b)))
7794 (defun verilog-signals-not-params (in-list)
7795 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
7798 ;; Namespace intentionally short for AUTOs and compatibility
7799 (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
7800 (setq out-list (cons (car in-list) out-list)))
7801 (setq in-list (cdr in-list)))
7802 (nreverse out-list)))
7804 (defun verilog-signals-with (func in-list)
7805 "Return list of signals where FUNC is true executed on each signal in IN-LIST."
7808 (when (funcall func (car in-list))
7809 (setq out-list (cons (car in-list) out-list)))
7810 (setq in-list (cdr in-list)))
7811 (nreverse out-list)))
7813 (defun verilog-signals-combine-bus (in-list)
7814 "Return a list of signals in IN-LIST, with buses combined.
7815 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
7818 sig highbit lowbit ; Temp information about current signal
7819 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
7820 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
7823 ;; Shove signals so duplicated signals will be adjacent
7824 (setq in-list (sort in-list `verilog-signals-sort-compare))
7826 (setq sig (car in-list))
7827 ;; No current signal; form from existing details
7829 (setq sv-name (verilog-sig-name sig)
7832 sv-comment (verilog-sig-comment sig)
7833 sv-memory (verilog-sig-memory sig)
7834 sv-enum (verilog-sig-enum sig)
7835 sv-signed (verilog-sig-signed sig)
7836 sv-type (verilog-sig-type sig)
7837 sv-multidim (verilog-sig-multidim sig)
7838 sv-modport (verilog-sig-modport sig)
7841 ;; Extract bus details
7842 (setq bus (verilog-sig-bits sig))
7843 (setq bus (and bus (verilog-simplify-range-expression bus)))
7845 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
7846 (setq highbit (string-to-number (match-string 1 bus))
7847 lowbit (string-to-number
7848 (match-string 2 bus))))
7849 (and (string-match "\\[\\([0-9]+\\)\\]" bus)
7850 (setq highbit (string-to-number (match-string 1 bus))
7852 ;; Combine bits in bus
7854 (setq sv-highbit (max highbit sv-highbit)
7855 sv-lowbit (min lowbit sv-lowbit))
7856 (setq sv-highbit highbit
7859 ;; String, probably something like `preproc:0
7860 (setq sv-busstring bus)))
7861 ;; Peek ahead to next signal
7862 (setq in-list (cdr in-list))
7863 (setq sig (car in-list))
7864 (cond ((and sig (equal sv-name (verilog-sig-name sig)))
7865 ;; Combine with this signal
7866 (when (and sv-busstring
7867 (not (equal sv-busstring (verilog-sig-bits sig))))
7868 (when nil ;; Debugging
7869 (message (concat "Warning, can't merge into single bus "
7871 ", the AUTOs may be wrong")))
7872 (setq buswarn ", Couldn't Merge"))
7873 (if (verilog-sig-comment sig) (setq combo ", ..."))
7874 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
7875 sv-enum (or sv-enum (verilog-sig-enum sig))
7876 sv-signed (or sv-signed (verilog-sig-signed sig))
7877 sv-type (or sv-type (verilog-sig-type sig))
7878 sv-multidim (or sv-multidim (verilog-sig-multidim sig))
7879 sv-modport (or sv-modport (verilog-sig-modport sig))))
7880 ;; Doesn't match next signal, add to queue, zero in prep for next
7881 ;; Note sig may also be nil for the last signal in the list
7884 (cons (verilog-sig-new
7888 (concat "[" (int-to-string sv-highbit) ":"
7889 (int-to-string sv-lowbit) "]")))
7890 (concat sv-comment combo buswarn)
7891 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
7897 (defun verilog-sig-tieoff (sig)
7898 "Return tieoff expression for given SIG, with appropriate width.
7899 Tieoff value uses `verilog-active-low-regexp' and
7900 `verilog-auto-reset-widths'."
7902 (if (and verilog-active-low-regexp
7903 (verilog-string-match-fold verilog-active-low-regexp (verilog-sig-name sig)))
7905 (cond ((not verilog-auto-reset-widths)
7907 ((equal verilog-auto-reset-widths 'unbased)
7909 ;; Else presume verilog-auto-reset-widths is true
7911 (let* ((width (verilog-sig-width sig)))
7914 ((string-match "^[0-9]+$" width)
7915 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0")))
7917 (concat "{" width "{1'b0}}"))))))))
7923 (defun verilog-decls-princ (decls &optional header prefix)
7924 "For debug, dump the `verilog-read-decls' structure DECLS."
7926 (if header (princ header))
7927 (setq prefix (or prefix ""))
7928 (verilog-signals-princ (verilog-decls-get-outputs decls)
7929 (concat prefix "Outputs:\n") (concat prefix " "))
7930 (verilog-signals-princ (verilog-decls-get-inouts decls)
7931 (concat prefix "Inout:\n") (concat prefix " "))
7932 (verilog-signals-princ (verilog-decls-get-inputs decls)
7933 (concat prefix "Inputs:\n") (concat prefix " "))
7934 (verilog-signals-princ (verilog-decls-get-vars decls)
7935 (concat prefix "Vars:\n") (concat prefix " "))
7936 (verilog-signals-princ (verilog-decls-get-assigns decls)
7937 (concat prefix "Assigns:\n") (concat prefix " "))
7938 (verilog-signals-princ (verilog-decls-get-consts decls)
7939 (concat prefix "Consts:\n") (concat prefix " "))
7940 (verilog-signals-princ (verilog-decls-get-gparams decls)
7941 (concat prefix "Gparams:\n") (concat prefix " "))
7942 (verilog-signals-princ (verilog-decls-get-interfaces decls)
7943 (concat prefix "Interfaces:\n") (concat prefix " "))
7944 (verilog-modport-princ (verilog-decls-get-modports decls)
7945 (concat prefix "Modports:\n") (concat prefix " "))
7948 (defun verilog-signals-princ (signals &optional header prefix)
7949 "For debug, dump internal SIGNALS structures, with HEADER and PREFIX."
7951 (if header (princ header))
7953 (let ((sig (car signals)))
7954 (setq signals (cdr signals))
7956 (princ "\"") (princ (verilog-sig-name sig)) (princ "\"")
7957 (princ " bits=") (princ (verilog-sig-bits sig))
7958 (princ " cmt=") (princ (verilog-sig-comment sig))
7959 (princ " mem=") (princ (verilog-sig-memory sig))
7960 (princ " enum=") (princ (verilog-sig-enum sig))
7961 (princ " sign=") (princ (verilog-sig-signed sig))
7962 (princ " type=") (princ (verilog-sig-type sig))
7963 (princ " dim=") (princ (verilog-sig-multidim sig))
7964 (princ " modp=") (princ (verilog-sig-modport sig))
7967 (defun verilog-modport-princ (modports &optional header prefix)
7968 "For debug, dump internal MODPORT structures, with HEADER and PREFIX."
7970 (if header (princ header))
7972 (let ((sig (car modports)))
7973 (setq modports (cdr modports))
7975 (princ "\"") (princ (verilog-modport-name sig)) (princ "\"")
7976 (princ " clockings=") (princ (verilog-modport-clockings sig))
7978 (verilog-decls-princ (verilog-modport-decls sig)
7979 (concat prefix " syms:\n")
7980 (concat prefix " "))))))
7983 ;; Port/Wire/Etc Reading
7986 (defun verilog-read-inst-backward-name ()
7987 "Internal. Move point back to beginning of inst-name."
7988 (verilog-backward-open-paren)
7991 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary
7992 (cond ((looking-at ")")
7993 (verilog-backward-open-paren))
7994 (t (setq done t)))))
7995 (while (looking-at "\\]")
7996 (verilog-backward-open-bracket)
7997 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil))
7998 (skip-chars-backward "a-zA-Z0-9`_$"))
8000 (defun verilog-read-inst-module-matcher ()
8001 "Set match data 0 with module_name when point is inside instantiation."
8002 (verilog-read-inst-backward-name)
8003 ;; Skip over instantiation name
8004 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
8005 ;; Check for parameterized instantiations
8006 (when (looking-at ")")
8007 (verilog-backward-open-paren)
8008 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil))
8009 (skip-chars-backward "a-zA-Z0-9'_$")
8010 ;; #1 is legal syntax for gate primitives
8011 (when (save-excursion
8012 (verilog-backward-syntactic-ws-quick)
8013 (eq ?# (char-before)))
8014 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil)
8015 (skip-chars-backward "a-zA-Z0-9'_$"))
8016 (looking-at "[a-zA-Z0-9`_\$]+")
8017 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8018 (buffer-substring-no-properties (match-beginning 0) (match-end 0))
8019 ;; Caller assumes match-beginning/match-end is still set
8022 (defun verilog-read-inst-module ()
8023 "Return module_name when point is inside instantiation."
8025 (verilog-read-inst-module-matcher)))
8027 (defun verilog-read-inst-name ()
8028 "Return instance_name when point is inside instantiation."
8030 (verilog-read-inst-backward-name)
8031 (looking-at "[a-zA-Z0-9`_\$]+")
8032 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8033 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
8035 (defun verilog-read-module-name ()
8036 "Return module name when after its ( or ;."
8038 (re-search-backward "[(;]")
8039 ;; Due to "module x import y (" we must search for declaration begin
8040 (verilog-re-search-backward-quick verilog-defun-re nil nil)
8041 (goto-char (match-end 0))
8042 (verilog-re-search-forward-quick "\\b[a-zA-Z0-9`_\$]+" nil nil)
8043 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8044 (verilog-symbol-detick
8045 (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
8047 (defun verilog-read-inst-param-value ()
8048 "Return list of parameters and values when point is inside instantiation."
8050 (verilog-read-inst-backward-name)
8051 ;; Skip over instantiation name
8052 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
8053 ;; If there are parameterized instantiations
8054 (when (looking-at ")")
8055 (let ((end-pt (point))
8057 param-name paren-beg-pt param-value)
8058 (verilog-backward-open-paren)
8059 (while (verilog-re-search-forward-quick "\\." end-pt t)
8060 (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_\$]\\)" nil nil)
8061 (skip-chars-backward "a-zA-Z0-9'_$")
8062 (looking-at "[a-zA-Z0-9`_\$]+")
8063 (setq param-name (buffer-substring-no-properties
8064 (match-beginning 0) (match-end 0)))
8065 (verilog-re-search-forward-quick "(" nil nil)
8066 (setq paren-beg-pt (point))
8067 (verilog-forward-close-paren)
8068 (setq param-value (verilog-string-remove-spaces
8069 (buffer-substring-no-properties
8070 paren-beg-pt (1- (point)))))
8071 (setq params (cons (list param-name param-value) params)))
8074 (defun verilog-read-auto-params (num-param &optional max-param)
8075 "Return parameter list inside auto.
8076 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
8079 ;; /*AUTOPUNT("parameter", "parameter")*/
8081 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
8082 (setq olist (cons (match-string 1) olist))
8083 (goto-char (match-end 0))))
8084 (or (eq nil num-param)
8085 (<= num-param (length olist))
8086 (error "%s: Expected %d parameters" (verilog-point-text) num-param))
8087 (if (eq max-param nil) (setq max-param num-param))
8088 (or (eq nil max-param)
8089 (>= max-param (length olist))
8090 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
8093 (defun verilog-read-decls ()
8094 "Compute signal declaration information for the current module at point.
8095 Return an array of [outputs inouts inputs wire reg assign const]."
8096 (let ((end-mod-point (or (verilog-get-end-of-defun) (point-max)))
8097 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
8098 in-modport in-clocking in-ign-to-semi ptype ign-prop
8099 sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
8100 sigs-gparam sigs-intf sigs-modports
8101 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
8104 ;;(if dbg (setq dbg (concat dbg (format "\n\nverilog-read-decls START PT %s END %s\n" (point) end-mod-point))))
8106 (verilog-beg-of-defun-quick)
8107 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
8108 (while (< (point) end-mod-point)
8109 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
8112 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8113 (setq enum (match-string 2)))
8114 (search-forward "\n"))
8115 ((looking-at "/\\*")
8117 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8118 (setq enum (match-string 2)))
8119 (or (search-forward "*/")
8120 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8121 ((looking-at "(\\*")
8122 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8124 (or (search-forward "*)")
8125 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8126 ((eq ?\" (following-char))
8127 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first
8128 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
8129 ((eq ?\; (following-char))
8130 (cond (in-ign-to-semi ;; Such as inside a "import ...;" in a module header
8131 (setq in-ign-to-semi nil))
8132 ((and in-modport (not (eq in-modport t))) ;; end of a modport declaration
8133 (verilog-modport-decls-set
8135 (verilog-decls-new sigs-out sigs-inout sigs-in
8136 nil nil nil nil nil nil))
8137 ;; Pop from varstack to restore state to pre-clocking
8138 (setq tmp (car varstack)
8139 varstack (cdr varstack)
8140 sigs-out (aref tmp 0)
8141 sigs-inout (aref tmp 1)
8142 sigs-in (aref tmp 2))
8143 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
8144 v2kargs-ok nil in-modport nil ign-prop nil))
8146 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
8147 v2kargs-ok nil in-modport nil ign-prop nil)))
8149 ((eq ?= (following-char))
8150 (setq rvalue t newsig nil)
8152 ((and (eq ?, (following-char))
8153 (eq paren sig-paren))
8156 ;; ,'s can occur inside {} & funcs
8157 ((looking-at "[{(]")
8158 (setq paren (1+ paren))
8160 ((looking-at "[})]")
8161 (setq paren (1- paren))
8163 (when (< paren sig-paren)
8164 (setq expect-signal nil rvalue nil))) ; ) that ends variables inside v2k arg list
8165 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
8166 (goto-char (match-end 0))
8167 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
8168 (setcar (cdr (cdr (cdr newsig)))
8169 (if (verilog-sig-memory newsig)
8170 (concat (verilog-sig-memory newsig) (match-string 1))
8172 (vec ;; Multidimensional
8173 (setq multidim (cons vec multidim))
8174 (setq vec (verilog-string-replace-matches
8175 "\\s-+" "" nil nil (match-string 1))))
8177 (setq vec (verilog-string-replace-matches
8178 "\\s-+" "" nil nil (match-string 1))))))
8179 ;; Normal or escaped identifier -- note we remember the \ if escaped
8180 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8181 (goto-char (match-end 0))
8182 (setq keywd (match-string 1))
8183 (when (string-match "^\\\\" (match-string 1))
8184 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end
8185 ;; Add any :: package names to same identifier
8186 (while (looking-at "\\s-*::\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8187 (goto-char (match-end 0))
8188 (setq keywd (concat keywd "::" (match-string 1)))
8189 (when (string-match "^\\\\" (match-string 1))
8190 (setq keywd (concat keywd " ")))) ;; Escaped ID needs space at end
8191 (cond ((equal keywd "input")
8192 (setq vec nil enum nil rvalue nil newsig nil signed nil
8193 typedefed nil multidim nil ptype nil modport nil
8194 expect-signal 'sigs-in io t sig-paren paren))
8195 ((equal keywd "output")
8196 (setq vec nil enum nil rvalue nil newsig nil signed nil
8197 typedefed nil multidim nil ptype nil modport nil
8198 expect-signal 'sigs-out io t sig-paren paren))
8199 ((equal keywd "inout")
8200 (setq vec nil enum nil rvalue nil newsig nil signed nil
8201 typedefed nil multidim nil ptype nil modport nil
8202 expect-signal 'sigs-inout io t sig-paren paren))
8203 ((equal keywd "parameter")
8204 (setq vec nil enum nil rvalue nil signed nil
8205 typedefed nil multidim nil ptype nil modport nil
8206 expect-signal 'sigs-gparam io t sig-paren paren))
8207 ((member keywd '("wire" "reg" ; Fast
8209 "tri" "tri0" "tri1" "triand" "trior" "trireg"
8210 "uwire" "wand" "wor"
8211 ;; integer_atom_type
8212 "byte" "shortint" "int" "longint" "integer" "time"
8214 ;; integer_vector_type - "reg" above
8217 "shortreal" "real" "realtime"
8219 "string" "event" "chandle"))
8222 (if typedefed (concat typedefed " " keywd) keywd)))
8223 (t (setq vec nil enum nil rvalue nil signed nil
8224 typedefed nil multidim nil sig-paren paren
8225 expect-signal 'sigs-var modport nil))))
8226 ((equal keywd "assign")
8227 (setq vec nil enum nil rvalue nil signed nil
8228 typedefed nil multidim nil ptype nil modport nil
8229 expect-signal 'sigs-assign sig-paren paren))
8230 ((member keywd '("localparam" "genvar"))
8232 (setq vec nil enum nil rvalue nil signed nil
8233 typedefed nil multidim nil ptype nil modport nil
8234 expect-signal 'sigs-const sig-paren paren)))
8235 ((member keywd '("signed" "unsigned"))
8236 (setq signed keywd))
8237 ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
8239 ((member keywd '("class" "covergroup" "function"
8240 "property" "randsequence" "sequence" "task"))
8242 (setq functask (1+ functask))))
8243 ((member keywd '("endclass" "endgroup" "endfunction"
8244 "endproperty" "endsequence" "endtask"))
8245 (setq functask (1- functask)))
8246 ((equal keywd "modport")
8247 (setq in-modport t))
8248 ((equal keywd "clocking")
8249 (setq in-clocking t))
8250 ((equal keywd "import")
8251 (if v2kargs-ok ;; import in module header, not a modport import
8252 (setq in-ign-to-semi t rvalue t)))
8253 ((equal keywd "type")
8255 ((equal keywd "var"))
8256 ;; Ifdef? Ignore name of define
8257 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8261 (verilog-typedef-name-p keywd))
8264 (if typedefed (concat typedefed " " keywd) keywd)))
8265 (t (setq vec nil enum nil rvalue nil signed nil
8266 typedefed keywd ; Have a type
8267 multidim nil sig-paren paren
8268 expect-signal 'sigs-var modport nil))))
8269 ;; Interface with optional modport in v2k arglist?
8270 ;; Skip over parsing modport, and take the interface name as the type
8274 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
8275 (when (match-end 2) (goto-char (match-end 2)))
8276 (setq vec nil enum nil rvalue nil signed nil
8277 typedefed keywd multidim nil ptype nil modport (match-string 2)
8278 newsig nil sig-paren paren
8279 expect-signal 'sigs-intf io t ))
8280 ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
8281 ((looking-at "\\s-*\\.")
8282 (goto-char (match-end 0))
8284 (setq expect-signal nil)))
8285 ;; "modport <keywd>"
8286 ((and (eq in-modport t)
8287 (not (member keywd verilog-keywords)))
8288 (setq in-modport (verilog-modport-new keywd nil nil))
8289 (setq sigs-modports (cons in-modport sigs-modports))
8290 ;; Push old sig values to stack and point to new signal list
8291 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8293 (setq sigs-in nil sigs-inout nil sigs-out nil))
8294 ;; "modport x (clocking <keywd>)"
8295 ((and in-modport in-clocking)
8296 (verilog-modport-clockings-add in-modport keywd)
8297 (setq in-clocking nil))
8300 (equal keywd "endclocking"))
8301 (unless (eq in-clocking t)
8302 (verilog-modport-decls-set
8304 (verilog-decls-new sigs-out sigs-inout sigs-in
8305 nil nil nil nil nil nil))
8306 ;; Pop from varstack to restore state to pre-clocking
8307 (setq tmp (car varstack)
8308 varstack (cdr varstack)
8309 sigs-out (aref tmp 0)
8310 sigs-inout (aref tmp 1)
8311 sigs-in (aref tmp 2)))
8312 (setq in-clocking nil))
8313 ;; "clocking <keywd>"
8314 ((and (eq in-clocking t)
8315 (not (member keywd verilog-keywords)))
8316 (setq in-clocking (verilog-modport-new keywd nil nil))
8317 (setq sigs-modports (cons in-clocking sigs-modports))
8318 ;; Push old sig values to stack and point to new signal list
8319 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8321 (setq sigs-in nil sigs-inout nil sigs-out nil))
8322 ;; New signal, maybe?
8326 (not (member keywd verilog-keywords)))
8327 ;; Add new signal to expect-signal's variable
8328 ;;(if dbg (setq dbg (concat dbg (format "Pt %s New sig %s'\n" (point) keywd))))
8329 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
8330 (set expect-signal (cons newsig
8331 (symbol-value expect-signal))))))
8334 (skip-syntax-forward " "))
8336 (setq tmp (verilog-decls-new (nreverse sigs-out)
8337 (nreverse sigs-inout)
8340 (nreverse sigs-modports)
8341 (nreverse sigs-assign)
8342 (nreverse sigs-const)
8343 (nreverse sigs-gparam)
8344 (nreverse sigs-intf)))
8345 ;;(if dbg (verilog-decls-princ tmp))
8348 (defvar verilog-read-sub-decls-in-interfaced nil
8349 "For `verilog-read-sub-decls', process next signal as under interfaced block.")
8351 (defvar verilog-read-sub-decls-gate-ios nil
8352 "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
8355 ;; Prevent compile warnings; these are let's, not globals
8356 ;; Do not remove the eval-when-compile
8357 ;; - we want an error when we are debugging this code if they are refed.
8365 (defvar sigs-out-unk)
8367 ;; These are known to be from other packages and may not be defined
8368 (defvar diff-command nil)
8369 (defvar vector-skip-list)
8370 ;; There are known to be from newer versions of Emacs
8371 (defvar create-lockfiles))
8373 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
8374 "For `verilog-read-sub-decls-line', add a signal."
8375 ;; sig eq t to indicate .name syntax
8376 ;;(message "vrsds: %s(%S)" port sig)
8377 (let ((dotname (eq sig t))
8380 (setq port (verilog-symbol-detick-denumber port))
8381 (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
8382 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
8383 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
8384 (unless (or (not sig)
8385 (equal sig "")) ;; Ignore .foo(1'b1) assignments
8386 (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
8387 (equal "inout" verilog-read-sub-decls-gate-ios))
8389 (cons (verilog-sig-new
8391 (if dotname (verilog-sig-bits portdata) vec)
8392 (concat "To/From " comment)
8393 (verilog-sig-memory portdata)
8395 (verilog-sig-signed portdata)
8396 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8397 (verilog-sig-type portdata))
8400 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
8401 (equal "output" verilog-read-sub-decls-gate-ios))
8403 (cons (verilog-sig-new
8405 (if dotname (verilog-sig-bits portdata) vec)
8406 (concat "From " comment)
8407 (verilog-sig-memory portdata)
8409 (verilog-sig-signed portdata)
8410 ;; Though ok in SV, in V2K code, propagating the
8411 ;; "reg" in "output reg" upwards isn't legal.
8412 ;; Also for backwards compatibility we don't propagate
8413 ;; "input wire" upwards.
8414 ;; See also `verilog-signals-edit-wire-reg'.
8415 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8416 (verilog-sig-type portdata))
8419 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
8420 (equal "input" verilog-read-sub-decls-gate-ios))
8422 (cons (verilog-sig-new
8424 (if dotname (verilog-sig-bits portdata) vec)
8425 (concat "To " comment)
8426 (verilog-sig-memory portdata)
8428 (verilog-sig-signed portdata)
8429 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8430 (verilog-sig-type portdata))
8433 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
8435 (cons (verilog-sig-new
8437 (if dotname (verilog-sig-bits portdata) vec)
8438 (concat "To/From " comment)
8439 (verilog-sig-memory portdata)
8441 (verilog-sig-signed portdata)
8442 (verilog-sig-type portdata)
8445 ((setq portdata (and verilog-read-sub-decls-in-interfaced
8446 (assoc port (verilog-decls-get-vars submoddecls))))
8448 (cons (verilog-sig-new
8450 (if dotname (verilog-sig-bits portdata) vec)
8451 (concat "To/From " comment)
8452 (verilog-sig-memory portdata)
8454 (verilog-sig-signed portdata)
8455 (verilog-sig-type portdata)
8458 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
8461 (defun verilog-read-sub-decls-expr (submoddecls comment port expr)
8462 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
8463 ;;(message "vrsde: '%s'" expr)
8464 ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
8465 (setq expr (verilog-string-replace-matches "/\\*\\(\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
8466 ;; Remove front operators
8467 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8470 ;; {..., a, b} requires us to recurse on a,b
8471 ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
8472 ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
8473 (unless verilog-auto-ignore-concat
8474 (let ((mlst (split-string (match-string 1 expr) "[{},]"))
8476 (while (setq mstr (pop mlst))
8477 (verilog-read-sub-decls-expr submoddecls comment port mstr)))))
8479 (let (sig vec multidim)
8480 ;; Remove leading reduction operators, etc
8481 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8482 ;;(message "vrsde-ptop: '%s'" expr)
8483 (cond ;; Find \signal. Final space is part of escaped signal name
8484 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
8485 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
8486 (setq sig (match-string 1 expr)
8487 expr (substring expr (match-end 0))))
8489 ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
8490 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
8491 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
8492 expr (substring expr (match-end 0)))))
8493 ;; Find [vector] or [multi][multi][multi][vector]
8494 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
8495 ;;(message "vrsde-v: '%s'" (match-string 1 expr))
8496 (when vec (setq multidim (cons vec multidim)))
8497 (setq vec (match-string 1 expr)
8498 expr (substring expr (match-end 0))))
8499 ;; If found signal, and nothing unrecognized, add the signal
8500 ;;(message "vrsde-rem: '%s'" expr)
8501 (when (and sig (string-match "^\\s-*$" expr))
8502 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))))
8504 (defun verilog-read-sub-decls-line (submoddecls comment)
8505 "For `verilog-read-sub-decls', read lines of port defs until none match.
8506 Inserts the list of signals found, using submodi to look up each port."
8512 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
8513 (setq port (match-string 1))
8514 (goto-char (match-end 0)))
8516 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
8517 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space
8518 (goto-char (match-end 0)))
8520 ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
8521 (verilog-read-sub-decls-sig
8522 submoddecls comment (match-string 1) t ; sig==t for .name
8523 nil nil) ; vec multidim
8526 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
8527 (verilog-read-sub-decls-sig
8528 submoddecls comment (concat (match-string 1) " ") t ; sig==t for .name
8529 nil nil) ; vec multidim
8532 ((looking-at "\\s-*\\.[^(]*(")
8533 (setq port nil) ;; skip this line
8534 (goto-char (match-end 0)))
8536 (setq port nil done t))) ;; Unknown, ignore rest of line
8537 ;; Get signal name. Point is at the first-non-space after (
8538 ;; We intentionally ignore (non-escaped) signals with .s in them
8539 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
8541 (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
8542 (verilog-read-sub-decls-sig
8543 submoddecls comment port
8544 (verilog-string-remove-spaces (match-string 1)) ; sig
8545 nil nil)) ; vec multidim
8547 ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
8548 (verilog-read-sub-decls-sig
8549 submoddecls comment port
8550 (verilog-string-remove-spaces (match-string 1)) ; sig
8551 (match-string 2) nil)) ; vec multidim
8552 ;; Fastpath was above looking-at's.
8553 ;; For something more complicated invoke a parser
8554 ((looking-at "[^)]+")
8555 (verilog-read-sub-decls-expr
8556 submoddecls comment port
8558 (point) (1- (progn (search-backward "(") ; start at (
8559 (verilog-forward-sexp-ign-cmt 1)
8560 (point)))))))) ; expr
8562 (forward-line 1)))))
8564 (defun verilog-read-sub-decls-gate (submoddecls comment submod end-inst-point)
8565 "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
8566 Inserts the list of signals found."
8568 (let ((iolist (cdr (assoc submod verilog-gate-ios))))
8569 (while (< (point) end-inst-point)
8570 ;; Get primitive's signal name, as will never have port, and no trailing )
8571 (cond ((looking-at "//")
8572 (search-forward "\n"))
8573 ((looking-at "/\\*")
8574 (or (search-forward "*/")
8575 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8576 ((looking-at "(\\*")
8577 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8579 (or (search-forward "*)")
8580 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8581 ;; On pins, parse and advance to next pin
8582 ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
8583 ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
8584 (goto-char (match-end 0))
8585 (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
8586 iolist (cdr iolist))
8587 (verilog-read-sub-decls-expr
8588 submoddecls comment "primitive_port"
8592 (skip-syntax-forward " ")))))))
8594 (defun verilog-read-sub-decls ()
8595 "Internally parse signals going to modules under this module.
8596 Return an array of [ outputs inouts inputs ] signals for modules that are
8597 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
8598 is an output, then SIG will be included in the list.
8600 This only works on instantiations created with /*AUTOINST*/ converted by
8601 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
8602 component library to determine connectivity of the design.
8604 One work around for this problem is to manually create // Inputs and //
8605 Outputs comments above subcell signals, for example:
8613 (let ((end-mod-point (verilog-get-end-of-defun))
8614 st-point end-inst-point
8615 ;; below 3 modified by verilog-read-sub-decls-line
8616 sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
8617 (verilog-beg-of-defun-quick)
8618 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
8620 (goto-char (match-beginning 0))
8621 (unless (verilog-inside-comment-or-string-p)
8622 ;; Attempt to snarf a comment
8623 (let* ((submod (verilog-read-inst-module))
8624 (inst (verilog-read-inst-name))
8625 (subprim (member submod verilog-gate-keywords))
8626 (comment (concat inst " of " submod ".v"))
8627 submodi submoddecls)
8630 (setq submodi `primitive
8631 submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
8632 comment (concat inst " of " submod))
8633 (verilog-backward-open-paren)
8634 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
8638 (verilog-read-sub-decls-gate submoddecls comment submod end-inst-point))
8641 (when (setq submodi (verilog-modi-lookup submod t))
8642 (setq submoddecls (verilog-modi-get-decls submodi)
8643 verilog-read-sub-decls-gate-ios nil)
8644 (verilog-backward-open-paren)
8645 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
8648 ;; This could have used a list created by verilog-auto-inst
8649 ;; However I want it to be runnable even on user's manually added signals
8650 (let ((verilog-read-sub-decls-in-interfaced t))
8651 (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
8652 (verilog-read-sub-decls-line submoddecls comment))) ;; Modifies sigs-ifd
8653 (goto-char st-point)
8654 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
8655 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
8656 (goto-char st-point)
8657 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
8658 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
8659 (goto-char st-point)
8660 (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
8661 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout
8662 (goto-char st-point)
8663 (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
8664 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-in
8666 ;; Combine duplicate bits
8667 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
8668 (verilog-subdecls-new
8669 (verilog-signals-combine-bus (nreverse sigs-out))
8670 (verilog-signals-combine-bus (nreverse sigs-inout))
8671 (verilog-signals-combine-bus (nreverse sigs-in))
8672 (verilog-signals-combine-bus (nreverse sigs-intf))
8673 (verilog-signals-combine-bus (nreverse sigs-intfd))))))
8675 (defun verilog-read-inst-pins ()
8676 "Return an array of [ pins ] for the current instantiation at point.
8677 For example if declare A A (.B(SIG)) then B will be included in the list."
8679 (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point
8681 (verilog-backward-open-paren)
8682 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
8683 (setq pin (match-string 1))
8684 (unless (verilog-inside-comment-or-string-p)
8685 (setq pins (cons (list pin) pins))
8686 (when (looking-at "(")
8687 (verilog-forward-sexp-ign-cmt 1))))
8690 (defun verilog-read-arg-pins ()
8691 "Return an array of [ pins ] for the current argument declaration at point."
8693 (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point
8695 (verilog-backward-open-paren)
8696 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
8697 (setq pin (match-string 1))
8698 (unless (verilog-inside-comment-or-string-p)
8699 (setq pins (cons (list pin) pins))))
8702 (defun verilog-read-auto-constants (beg end-mod-point)
8703 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
8706 (let (sig-list tpl-end-pt)
8708 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
8709 (if (not (looking-at "\\s *("))
8710 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
8711 (search-forward "(" end-mod-point)
8712 (setq tpl-end-pt (save-excursion
8714 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8717 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
8718 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
8721 (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
8722 (make-variable-buffer-local 'verilog-cache-has-lisp)
8724 (defun verilog-read-auto-lisp-present ()
8725 "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
8727 (goto-char (point-min))
8728 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
8730 (defun verilog-read-auto-lisp (start end)
8731 "Look for and evaluate an AUTO_LISP between START and END.
8732 Must call `verilog-read-auto-lisp-present' before this function."
8733 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
8734 (when verilog-cache-has-lisp
8737 (while (re-search-forward "\\<AUTO_LISP(" end t)
8739 (let* ((beg-pt (prog1 (point)
8740 (verilog-forward-sexp-cmt 1))) ;; Closing paren
8742 (verilog-in-hooks t))
8743 (eval-region beg-pt end-pt nil))))))
8745 (defun verilog-read-always-signals-recurse
8746 (exit-keywd rvalue temp-next)
8747 "Recursive routine for parentheses/bracket matching.
8748 EXIT-KEYWD is expression to stop at, nil if top level.
8749 RVALUE is true if at right hand side of equal.
8750 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
8751 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue
8752 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
8754 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
8755 (while (not (or (eobp) gotend))
8758 (search-forward "\n"))
8759 ((looking-at "/\\*")
8760 (or (search-forward "*/")
8761 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8762 ((looking-at "(\\*")
8763 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8765 (or (search-forward "*)")
8766 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8767 (t (setq keywd (buffer-substring-no-properties
8769 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
8772 sig-last-tolk sig-tolk
8774 ;;(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))))
8777 (or (re-search-forward "[^\\]\"" nil t)
8778 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
8779 ;; else at top level loop, keep parsing
8780 ((and end-else-check (equal keywd "else"))
8781 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
8782 ;; no forward movement, want to see else in lower loop
8783 (setq end-else-check nil))
8784 ;; End at top level loop
8785 ((and end-else-check (looking-at "[^ \t\n\f]"))
8786 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
8789 ((and exit-keywd (equal keywd exit-keywd))
8791 (forward-char (length keywd)))
8792 ;; Standard tokens...
8794 (setq ignore-next nil rvalue semi-rvalue)
8795 ;; Final statement at top level loop?
8796 (when (not exit-keywd)
8797 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
8798 (setq end-else-check t))
8801 (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
8802 (goto-char (match-end 0))
8804 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z
8805 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next
8806 (setq ignore-next nil rvalue nil))
8807 ((equal "?" exit-keywd) ;; x?y:z rvalue
8809 ((equal "]" exit-keywd) ;; [x:y] rvalue
8811 (got-sig ;; label: statement
8812 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
8813 ((not rvalue) ;; begin label
8814 (setq ignore-next t rvalue nil)))
8818 ;;(if dbg (setq dbg (concat dbg (format "\t\tequal got-sig=%S got-list=%s\n" got-sig got-list))))
8819 (set got-list (cons got-sig (symbol-value got-list)))
8822 (if (eq (char-before) ?< )
8823 (setq sigs-out-d (append sigs-out-d sigs-out-unk)
8825 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
8827 (setq ignore-next nil rvalue t)
8831 (verilog-read-always-signals-recurse ":" rvalue nil))
8834 (verilog-read-always-signals-recurse "]" t nil))
8837 (cond (sig-last-tolk ;; Function call; zap last signal
8838 (setq got-sig nil)))
8839 (cond ((equal last-keywd "for")
8840 ;; temp-next: Variables on LHS are lvalues, but generally we want
8841 ;; to ignore them, assuming they are loop increments
8842 (verilog-read-always-signals-recurse ";" nil t)
8843 (verilog-read-always-signals-recurse ";" t nil)
8844 (verilog-read-always-signals-recurse ")" nil nil))
8845 (t (verilog-read-always-signals-recurse ")" t nil))))
8846 ((equal keywd "begin")
8847 (skip-syntax-forward "w_")
8848 (verilog-read-always-signals-recurse "end" nil nil)
8849 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
8850 (setq ignore-next nil rvalue semi-rvalue)
8851 (if (not exit-keywd) (setq end-else-check t)))
8852 ((member keywd '("case" "casex" "casez"))
8853 (skip-syntax-forward "w_")
8854 (verilog-read-always-signals-recurse "endcase" t nil)
8855 (setq ignore-next nil rvalue semi-rvalue)
8856 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end
8857 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent
8858 (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8859 (setq ignore-next t))
8861 (member keywd verilog-keywords)
8862 (string-match "^\\$" keywd)) ;; PLI task
8863 (setq ignore-next nil))
8865 (setq keywd (verilog-symbol-detick-denumber keywd))
8867 (set got-list (cons got-sig (symbol-value got-list)))
8868 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
8870 (setq got-list (cond (temp-next 'sigs-temp)
8873 got-sig (if (or (not keywd)
8874 (assoc keywd (symbol-value got-list)))
8875 nil (list keywd nil nil))
8878 (skip-chars-forward "a-zA-Z0-9$_.%`"))
8881 ;; End of non-comment token
8882 (setq last-keywd keywd)))
8883 (skip-syntax-forward " "))
8884 ;; Append the final pending signal
8886 ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
8887 (set got-list (cons got-sig (symbol-value got-list)))
8889 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
8892 (defun verilog-read-always-signals ()
8893 "Parse always block at point and return list of (outputs inout inputs)."
8896 sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
8897 (search-forward ")")
8898 (verilog-read-always-signals-recurse nil nil nil)
8899 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
8901 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))
8902 ;; Return what was found
8903 (verilog-alw-new sigs-out-d sigs-out-i sigs-temp sigs-in))))
8905 (defun verilog-read-instants ()
8906 "Parse module at point and return list of ( ( file instance ) ... )."
8907 (verilog-beg-of-defun-quick)
8908 (let* ((end-mod-point (verilog-get-end-of-defun))
8910 (instants-list nil))
8912 (while (< (point) end-mod-point)
8913 ;; Stay at level 0, no comments
8915 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
8916 (or (> (car state) 0) ; in parens
8917 (nth 5 state) ; comment
8921 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
8922 ;;(if (looking-at "^\\(.+\\)$")
8923 (let ((module (match-string 1))
8924 (instant (match-string 2)))
8925 (if (not (member module verilog-keywords))
8926 (setq instants-list (cons (list module instant) instants-list)))))
8931 (defun verilog-read-auto-template-middle ()
8932 "With point in middle of an AUTO_TEMPLATE, parse it.
8933 Returns REGEXP and list of ( (signal_name connection_name)... )."
8936 (let ((tpl-regexp "\\([0-9]+\\)")
8937 (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
8939 tpl-sig-list tpl-wild-list tpl-end-pt rep)
8941 ;; We reserve @"..." for future lisp expressions that evaluate
8942 ;; once-per-AUTOINST
8943 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
8944 (setq tpl-regexp (match-string 1))
8945 (goto-char (match-end 0)))
8946 (search-forward "(")
8947 ;; Parse lines in the template
8948 (when (or verilog-auto-inst-template-numbers
8949 verilog-auto-template-warn-unused)
8951 (let ((pre-pt (point)))
8952 (goto-char (point-min))
8953 (while (search-forward "AUTO_TEMPLATE" pre-pt t)
8954 (setq templateno (1+ templateno)))
8955 (while (< (point) pre-pt)
8957 (setq lineno (1+ lineno))))))
8958 (setq tpl-end-pt (save-excursion
8960 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8964 (while (< (point) tpl-end-pt)
8965 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8968 (match-string-no-properties 1)
8969 (match-string-no-properties 2)
8972 (goto-char (match-end 0)))
8975 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
8976 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8977 (setq rep (match-string-no-properties 3))
8978 (goto-char (match-end 0))
8982 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
8988 ((looking-at "[ \t\f]+")
8989 (goto-char (match-end 0)))
8991 (setq lineno (1+ lineno))
8992 (goto-char (match-end 0)))
8994 (search-forward "\n")
8995 (setq lineno (1+ lineno)))
8996 ((looking-at "/\\*")
8998 (or (search-forward "*/")
8999 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
9001 (error "%s: AUTO_TEMPLATE parsing error: %s"
9002 (verilog-point-text)
9003 (progn (looking-at ".*$") (match-string 0))))))
9006 (list tpl-sig-list tpl-wild-list)))))
9008 (defun verilog-read-auto-template (module)
9009 "Look for an auto_template for the instantiation of the given MODULE.
9010 If found returns `verilog-read-auto-template-inside' structure."
9014 ;; Note this search is expensive, as we hunt from mod-begin to point
9015 ;; for every instantiation. Likewise in verilog-read-auto-lisp.
9016 ;; So, we look first for an exact string rather than a slow regexp.
9017 ;; Someday we may keep a cache of every template, but this would also
9018 ;; need to record the relative position of each AUTOINST, as multiple
9019 ;; templates exist for each module, and we're inserting lines.
9021 ;; See also regexp in `verilog-auto-template-lint'
9022 (verilog-re-search-backward-substr
9024 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
9025 ;; Also try forward of this AUTOINST
9026 ;; This is for historical support; this isn't speced as working
9029 (verilog-re-search-forward-substr
9031 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
9032 (goto-char (match-end 0))
9033 (verilog-read-auto-template-middle))
9034 ;; If no template found
9035 (t (vector "" nil))))))
9036 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
9038 (defvar verilog-auto-template-hits nil "Successful lookups with `verilog-read-auto-template-hit'.")
9039 (make-variable-buffer-local 'verilog-auto-template-hits)
9041 (defun verilog-read-auto-template-hit (tpl-ass)
9042 "Record that TPL-ASS template from `verilog-read-auto-template' was used."
9043 (when (eval-when-compile (fboundp 'make-hash-table)) ;; else feature not allowed
9044 (when verilog-auto-template-warn-unused
9045 (unless verilog-auto-template-hits
9046 (setq verilog-auto-template-hits
9047 (make-hash-table :test 'equal :rehash-size 4.0)))
9048 (puthash (vector (nth 2 tpl-ass) (nth 3 tpl-ass)) t
9049 verilog-auto-template-hits))))
9051 (defun verilog-set-define (defname defvalue &optional buffer enumname)
9052 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
9053 Optionally associate it with the specified enumeration ENUMNAME."
9054 (with-current-buffer (or buffer (current-buffer))
9055 ;; Namespace intentionally short for AUTOs and compatibility
9056 (let ((mac (intern (concat "vh-" defname))))
9057 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
9058 ;; Need to define to a constant if no value given
9059 (set (make-local-variable mac)
9060 (if (equal defvalue "") "1" defvalue)))
9062 ;; Namespace intentionally short for AUTOs and compatibility
9063 (let ((enumvar (intern (concat "venum-" enumname))))
9064 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
9065 (unless (boundp enumvar) (set enumvar nil))
9066 (add-to-list (make-local-variable enumvar) defname)))))
9068 (defun verilog-read-defines (&optional filename recurse subcall)
9069 "Read `defines and parameters for the current file, or optional FILENAME.
9070 If the filename is provided, `verilog-library-flags' will be used to
9071 resolve it. If optional RECURSE is non-nil, recurse through `includes.
9073 Parameters must be simple assignments to constants, or have their own
9074 \"parameter\" label rather than a list of parameters. Thus:
9076 parameter X = 5, Y = 10; // Ok
9077 parameter X = {1'b1, 2'h2}; // Ok
9078 parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines
9080 Defines must be simple text substitutions, one on a line, starting
9081 at the beginning of the line. Any ifdefs or multiline comments around the
9084 Defines are stored inside Emacs variables using the name vh-{definename}.
9086 This function is useful for setting vh-* variables. The file variables
9087 feature can be used to set defines that `verilog-mode' can see; put at the
9088 *END* of your file something like:
9091 // vh-macro:\"macro_definition\"
9094 If macros are defined earlier in the same file and you want their values,
9095 you can read them automatically (provided `enable-local-eval' is on):
9098 // eval:(verilog-read-defines)
9099 // eval:(verilog-read-defines \"group_standard_includes.v\")
9102 Note these are only read when the file is first visited, you must use
9103 \\[find-alternate-file] RET to have these take effect after editing them!
9105 If you want to disable the \"Process `eval' or hook local variables\"
9106 warning message, you need to add to your init file:
9108 (setq enable-local-eval t)"
9109 (let ((origbuf (current-buffer)))
9111 (unless subcall (verilog-getopt-flags))
9113 (let ((fns (verilog-library-filenames filename (buffer-file-name))))
9115 (set-buffer (find-file-noselect (car fns)))
9116 (error (concat (verilog-point-text)
9117 ": Can't find verilog-read-defines file: " filename)))))
9119 (goto-char (point-min))
9120 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9121 (let ((inc (verilog-string-replace-matches
9122 "\"" "" nil nil (match-string-no-properties 1))))
9123 (unless (verilog-inside-comment-or-string-p)
9124 (verilog-read-defines inc recurse t)))))
9126 ;; note we don't use verilog-re... it's faster this way, and that
9127 ;; function has problems when comments are at the end of the define
9128 (goto-char (point-min))
9129 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
9130 (let ((defname (match-string-no-properties 1))
9131 (defvalue (match-string-no-properties 2)))
9132 (unless (verilog-inside-comment-or-string-p (match-beginning 0))
9133 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
9134 (verilog-set-define defname defvalue origbuf))))
9135 ;; Hack: Read parameters
9136 (goto-char (point-min))
9137 (while (re-search-forward
9138 "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
9140 ;; The primary way of getting defines is verilog-read-decls
9141 ;; However, that isn't called yet for included files, so we'll add another scheme
9142 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
9143 (setq enumname (match-string-no-properties 2)))
9144 (forward-comment 99999)
9145 (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
9146 "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
9147 (unless (verilog-inside-comment-or-string-p (match-beginning 0))
9148 (verilog-set-define (match-string-no-properties 1)
9149 (match-string-no-properties 2) origbuf enumname))
9150 (goto-char (match-end 0))
9151 (forward-comment 99999)))))))
9153 (defun verilog-read-includes ()
9154 "Read `includes for the current file.
9155 This will find all of the `includes which are at the beginning of lines,
9156 ignoring any ifdefs or multiline comments around them.
9157 `verilog-read-defines' is then performed on the current and each included
9160 It is often useful put at the *END* of your file something like:
9163 // eval:(verilog-read-defines)
9164 // eval:(verilog-read-includes)
9167 Note includes are only read when the file is first visited, you must use
9168 \\[find-alternate-file] RET to have these take effect after editing them!
9170 It is good to get in the habit of including all needed files in each .v
9171 file that needs it, rather than waiting for compile time. This will aid
9172 this process, Verilint, and readability. To prevent defining the same
9173 variable over and over when many modules are compiled together, put a test
9174 around the inside each include file:
9176 foo.v (an include file):
9177 `ifdef _FOO_V // include if not already included
9180 ... contents of file
9182 ;;slow: (verilog-read-defines nil t)
9184 (verilog-getopt-flags)
9185 (goto-char (point-min))
9186 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9187 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
9188 (verilog-read-defines inc nil t)))))
9190 (defun verilog-read-signals (&optional start end)
9191 "Return a simple list of all possible signals in the file.
9192 Bounded by optional region from START to END. Overly aggressive but fast.
9193 Some macros and such are also found and included. For dinotrace.el."
9194 (let (sigs-all keywd)
9195 (progn;save-excursion
9196 (goto-char (or start (point-min)))
9197 (setq end (or end (point-max)))
9198 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
9202 (search-forward "\n"))
9203 ((looking-at "/\\*")
9204 (search-forward "*/"))
9205 ((looking-at "(\\*")
9206 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
9207 (search-forward "*)")))
9208 ((eq ?\" (following-char))
9209 (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first
9210 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
9211 (goto-char (match-end 0))
9212 (setq keywd (match-string-no-properties 1))
9213 (or (member keywd verilog-keywords)
9214 (member keywd sigs-all)
9215 (setq sigs-all (cons keywd sigs-all))))
9216 (t (forward-char 1))))
9221 ;; Argument file parsing
9224 (defun verilog-getopt (arglist)
9225 "Parse -f, -v etc arguments in ARGLIST list or string."
9226 (unless (listp arglist) (setq arglist (list arglist)))
9227 (let ((space-args '())
9229 ;; Split on spaces, so users can pass whole command lines
9231 (setq arg (car arglist)
9232 arglist (cdr arglist))
9233 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
9234 (setq space-args (append space-args
9235 (list (match-string-no-properties 1 arg))))
9236 (setq arg (match-string 2 arg))))
9239 (setq arg (car space-args)
9240 space-args (cdr space-args))
9244 (setq next-param arg))
9246 (setq next-param arg))
9248 (setq next-param arg))
9249 ;; +libext+(ext1)+(ext2)...
9250 ((string-match "^\\+libext\\+\\(.*\\)" arg)
9251 (setq arg (match-string 1 arg))
9252 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
9253 (verilog-add-list-unique `verilog-library-extensions
9254 (match-string 1 arg))
9255 (setq arg (match-string 2 arg))))
9257 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val
9258 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine
9259 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val
9260 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define
9261 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
9263 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir
9264 (string-match "^-I\\(.*\\)" arg)) ;; -Idir
9265 (verilog-add-list-unique `verilog-library-directories
9266 (match-string 1 (substitute-in-file-name arg))))
9268 ((equal "+librescan" arg))
9269 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine
9270 ;; Second parameters
9271 ((equal next-param "-f")
9272 (setq next-param nil)
9273 (verilog-getopt-file (substitute-in-file-name arg)))
9274 ((equal next-param "-v")
9275 (setq next-param nil)
9276 (verilog-add-list-unique `verilog-library-files
9277 (substitute-in-file-name arg)))
9278 ((equal next-param "-y")
9279 (setq next-param nil)
9280 (verilog-add-list-unique `verilog-library-directories
9281 (substitute-in-file-name arg)))
9283 ((string-match "^[^-+]" arg)
9284 (verilog-add-list-unique `verilog-library-files
9285 (substitute-in-file-name arg)))
9286 ;; Default - ignore; no warning
9288 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
9290 (defun verilog-getopt-file (filename)
9291 "Read Verilog options from the specified FILENAME."
9293 (let ((fns (verilog-library-filenames filename (buffer-file-name)))
9294 (orig-buffer (current-buffer))
9297 (set-buffer (find-file-noselect (car fns)))
9298 (error (concat (verilog-point-text)
9299 ": Can't find verilog-getopt-file -f file: " filename)))
9300 (goto-char (point-min))
9302 (setq line (buffer-substring (point) (point-at-eol)))
9304 (when (string-match "//" line)
9305 (setq line (substring line 0 (match-beginning 0))))
9306 (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
9307 (verilog-getopt line))))))
9309 (defun verilog-getopt-flags ()
9310 "Convert `verilog-library-flags' into standard library variables."
9311 ;; If the flags are local, then all the outputs should be local also
9312 (when (local-variable-p `verilog-library-flags (current-buffer))
9313 (mapc 'make-local-variable '(verilog-library-extensions
9314 verilog-library-directories
9315 verilog-library-files
9316 verilog-library-flags)))
9317 ;; Allow user to customize
9318 (verilog-run-hooks 'verilog-before-getopt-flags-hook)
9319 ;; Process arguments
9320 (verilog-getopt verilog-library-flags)
9321 ;; Allow user to customize
9322 (verilog-run-hooks 'verilog-getopt-flags-hook))
9324 (defun verilog-add-list-unique (varref object)
9325 "Append to VARREF list the given OBJECT,
9326 unless it is already a member of the variable's list."
9327 (unless (member object (symbol-value varref))
9328 (set varref (append (symbol-value varref) (list object))))
9330 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
9332 (defun verilog-current-flags ()
9333 "Convert `verilog-library-flags' and similar variables to command line.
9334 Used for __FLAGS__ in `verilog-expand-command'."
9335 (let ((cmd (mapconcat `concat verilog-library-flags " ")))
9336 (when (equal cmd "")
9338 "+libext+" (mapconcat `concat verilog-library-extensions "+")
9339 (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
9340 verilog-library-directories "")
9341 (mapconcat (lambda (i) (concat " -v " i))
9342 verilog-library-files ""))))
9344 ;;(verilog-current-flags)
9348 ;; Cached directory support
9351 (defvar verilog-dir-cache-preserving nil
9352 "If true, the directory cache is enabled, and file system changes are ignored.
9353 See `verilog-dir-exists-p' and `verilog-dir-files'.")
9355 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
9356 (defvar verilog-dir-cache-list nil
9357 "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
9358 (defvar verilog-dir-cache-lib-filenames nil
9359 "Cached data for `verilog-library-filenames'.")
9361 (defmacro verilog-preserve-dir-cache (&rest body)
9362 "Execute the BODY forms, allowing directory cache preservation within BODY.
9363 This means that changes inside BODY made to the file system will not be
9364 seen by the `verilog-dir-files' and related functions."
9365 `(let ((verilog-dir-cache-preserving (current-buffer))
9366 verilog-dir-cache-list
9367 verilog-dir-cache-lib-filenames)
9370 (defun verilog-dir-files (dirname)
9371 "Return all filenames in the DIRNAME directory.
9372 Relative paths depend on the `default-directory'.
9373 Results are cached if inside `verilog-preserve-dir-cache'."
9374 (unless verilog-dir-cache-preserving
9375 (setq verilog-dir-cache-list nil)) ;; Cache disabled
9376 ;; We don't use expand-file-name on the dirname to make key, as it's slow
9377 (let* ((cache-key (list dirname default-directory))
9378 (fass (assoc cache-key verilog-dir-cache-list))
9380 (cond (fass ;; Return data from cache hit
9383 (setq exp-dirname (expand-file-name dirname)
9384 data (and (file-directory-p exp-dirname)
9385 (directory-files exp-dirname nil nil nil)))
9386 ;; Note we also encache nil for non-existing dirs.
9387 (setq verilog-dir-cache-list (cons (list cache-key data)
9388 verilog-dir-cache-list))
9390 ;; Miss-and-hit test:
9391 ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
9392 ;; (prin1 (verilog-dir-files ".")) nil)
9394 (defun verilog-dir-file-exists-p (filename)
9395 "Return true if FILENAME exists.
9396 Like `file-exists-p' but results are cached if inside
9397 `verilog-preserve-dir-cache'."
9398 (let* ((dirname (file-name-directory filename))
9399 ;; Correct for file-name-nondirectory returning same if no slash.
9400 (dirnamed (if (or (not dirname) (equal dirname filename))
9401 default-directory dirname))
9402 (flist (verilog-dir-files dirnamed)))
9404 (member (file-name-nondirectory filename) flist)
9406 ;;(verilog-dir-file-exists-p "verilog-mode.el")
9407 ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
9411 ;; Module name lookup
9414 (defun verilog-module-inside-filename-p (module filename)
9415 "Return modi if MODULE is specified inside FILENAME, else nil.
9416 Allows version control to check out the file if need be."
9417 (and (or (file-exists-p filename)
9418 (and (fboundp 'vc-backend)
9419 (vc-backend filename)))
9421 (with-current-buffer (find-file-noselect filename)
9423 (goto-char (point-min))
9425 ;; It may be tempting to look for verilog-defun-re,
9426 ;; don't, it slows things down a lot!
9427 (verilog-re-search-forward-quick "\\<\\(module\\|interface\\|program\\)\\>" nil t)
9428 (setq type (match-string-no-properties 0))
9429 (verilog-re-search-forward-quick "[(;]" nil t))
9430 (if (equal module (verilog-read-module-name))
9431 (setq modi (verilog-modi-new module filename (point) type))))
9434 (defun verilog-is-number (symbol)
9435 "Return true if SYMBOL is number-like."
9436 (or (string-match "^[0-9 \t:]+$" symbol)
9437 (string-match "^[---]*[0-9]+$" symbol)
9438 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
9440 (defun verilog-symbol-detick (symbol wing-it)
9441 "Return an expanded SYMBOL name without any defines.
9442 If the variable vh-{symbol} is defined, return that value.
9443 If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
9444 (while (and symbol (string-match "^`" symbol))
9445 (setq symbol (substring symbol 1))
9447 ;; Namespace intentionally short for AUTOs and compatibility
9448 (if (boundp (intern (concat "vh-" symbol)))
9449 ;; Emacs has a bug where boundp on a buffer-local
9450 ;; variable in only one buffer returns t in another.
9451 ;; This can confuse, so check for nil.
9452 ;; Namespace intentionally short for AUTOs and compatibility
9453 (let ((val (eval (intern (concat "vh-" symbol)))))
9455 (if wing-it symbol nil)
9457 (if wing-it symbol nil))))
9459 ;;(verilog-symbol-detick "`mod" nil)
9461 (defun verilog-symbol-detick-denumber (symbol)
9462 "Return SYMBOL with defines converted and any numbers dropped to nil."
9463 (when (string-match "^`" symbol)
9464 ;; This only will work if the define is a simple signal, not
9465 ;; something like a[b]. Sorry, it should be substituted into the parser
9467 (verilog-string-replace-matches
9468 "\[[^0-9: \t]+\]" "" nil nil
9469 (or (verilog-symbol-detick symbol nil)
9470 (if verilog-auto-sense-defines-constant
9473 (if (verilog-is-number symbol)
9477 (defun verilog-symbol-detick-text (text)
9478 "Return TEXT without any known defines.
9479 If the variable vh-{symbol} is defined, substitute that value."
9480 (let ((ok t) symbol val)
9481 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
9482 (setq symbol (match-string 1 text))
9485 ;; Namespace intentionally short for AUTOs and compatibility
9486 (boundp (intern (concat "vh-" symbol)))
9487 ;; Emacs has a bug where boundp on a buffer-local
9488 ;; variable in only one buffer returns t in another.
9489 ;; This can confuse, so check for nil.
9490 ;; Namespace intentionally short for AUTOs and compatibility
9491 (setq val (eval (intern (concat "vh-" symbol)))))
9492 (setq text (replace-match val nil nil text)))
9493 (t (setq ok nil)))))
9495 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
9497 (defun verilog-expand-dirnames (&optional dirnames)
9498 "Return a list of existing directories given a list of wildcarded DIRNAMES.
9499 Or, just the existing dirnames themselves if there are no wildcards."
9500 ;; Note this function is performance critical.
9501 ;; Do not call anything that requires disk access that cannot be cached.
9503 (unless dirnames (error "`verilog-library-directories' should include at least '.'"))
9504 (setq dirnames (reverse dirnames)) ; not nreverse
9506 pattern dirfile dirfiles dirname root filename rest basefile)
9508 (setq dirname (substitute-in-file-name (car dirnames))
9509 dirnames (cdr dirnames))
9510 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root
9511 "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *?
9514 (setq root (match-string 1 dirname)
9515 filename (match-string 2 dirname)
9516 rest (match-string 3 dirname)
9518 ;; now replace those * and ? with .+ and .
9519 ;; use ^ and /> to get only whole file names
9520 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
9521 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
9522 pattern (concat "^" pattern "$")
9523 dirfiles (verilog-dir-files root))
9525 (setq basefile (car dirfiles)
9526 dirfile (expand-file-name (concat root basefile rest))
9527 dirfiles (cdr dirfiles))
9528 (if (and (string-match pattern basefile)
9529 ;; Don't allow abc/*/rtl to match abc/rtl via ..
9530 (not (equal basefile "."))
9531 (not (equal basefile ".."))
9532 (file-directory-p dirfile))
9533 (setq dirlist (cons dirfile dirlist)))))
9536 (if (file-directory-p dirname)
9537 (setq dirlist (cons dirname dirlist))))))
9539 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
9541 (defun verilog-library-filenames (filename &optional current check-ext)
9542 "Return a search path to find the given FILENAME or module name.
9543 Uses the optional CURRENT filename or variable `buffer-file-name', plus
9544 `verilog-library-directories' and `verilog-library-extensions'
9545 variables to build the path. With optional CHECK-EXT also check
9546 `verilog-library-extensions'."
9547 (unless current (setq current (buffer-file-name)))
9548 (unless verilog-dir-cache-preserving
9549 (setq verilog-dir-cache-lib-filenames nil))
9550 (let* ((cache-key (list filename current check-ext))
9551 (fass (assoc cache-key verilog-dir-cache-lib-filenames))
9552 chkdirs chkdir chkexts fn outlist)
9553 (cond (fass ;; Return data from cache hit
9556 ;; Note this expand can't be easily cached, as we need to
9557 ;; pick up buffer-local variables for newly read sub-module files
9558 (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
9560 (setq chkdir (expand-file-name (car chkdirs)
9561 (file-name-directory current))
9562 chkexts (if check-ext verilog-library-extensions `("")))
9564 (setq fn (expand-file-name (concat filename (car chkexts))
9566 ;;(message "Check for %s" fn)
9567 (if (verilog-dir-file-exists-p fn)
9568 (setq outlist (cons (expand-file-name
9569 fn (file-name-directory current))
9571 (setq chkexts (cdr chkexts)))
9572 (setq chkdirs (cdr chkdirs)))
9573 (setq outlist (nreverse outlist))
9574 (setq verilog-dir-cache-lib-filenames
9575 (cons (list cache-key outlist)
9576 verilog-dir-cache-lib-filenames))
9579 (defun verilog-module-filenames (module current)
9580 "Return a search path to find the given MODULE name.
9581 Uses the CURRENT filename, `verilog-library-extensions',
9582 `verilog-library-directories' and `verilog-library-files'
9583 variables to build the path."
9584 ;; Return search locations for it
9585 (append (list current) ; first, current buffer
9586 (verilog-library-filenames module current t)
9587 verilog-library-files)) ; finally, any libraries
9590 ;; Module Information
9592 ;; Many of these functions work on "modi" a module information structure
9593 ;; A modi is: [module-name-string file-name begin-point]
9595 (defvar verilog-cache-enabled t
9596 "Non-nil enables caching of signals, etc. Set to nil for debugging to make things SLOW!")
9598 (defvar verilog-modi-cache-list nil
9599 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
9600 For speeding up verilog-modi-get-* commands.
9602 (make-variable-buffer-local 'verilog-modi-cache-list)
9604 (defvar verilog-modi-cache-preserve-tick nil
9605 "Modification tick after which the cache is still considered valid.
9606 Use `verilog-preserve-modi-cache' to set it.")
9607 (defvar verilog-modi-cache-preserve-buffer nil
9608 "Modification tick after which the cache is still considered valid.
9609 Use `verilog-preserve-modi-cache' to set it.")
9610 (defvar verilog-modi-cache-current-enable nil
9611 "Non-nil means allow caching `verilog-modi-current', set by let().")
9612 (defvar verilog-modi-cache-current nil
9613 "Currently active `verilog-modi-current', if any, set by let().")
9614 (defvar verilog-modi-cache-current-max nil
9615 "Current endmodule point for `verilog-modi-cache-current', if any.")
9617 (defun verilog-modi-current ()
9618 "Return the modi structure for the module currently at point, possibly cached."
9619 (cond ((and verilog-modi-cache-current
9620 (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
9621 (<= (point) verilog-modi-cache-current-max))
9622 ;; Slow assertion, for debugging the cache:
9623 ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
9624 verilog-modi-cache-current)
9625 (verilog-modi-cache-current-enable
9626 (setq verilog-modi-cache-current (verilog-modi-current-get)
9627 verilog-modi-cache-current-max
9628 ;; The cache expires when we pass "endmodule" as then the
9629 ;; current modi may change to the next module
9630 ;; This relies on the AUTOs generally inserting, not deleting text
9632 (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
9633 verilog-modi-cache-current)
9635 (verilog-modi-current-get))))
9637 (defun verilog-modi-current-get ()
9638 "Return the modi structure for the module currently at point."
9639 (let* (name type pt)
9640 ;; read current module's name
9642 (verilog-re-search-backward-quick verilog-defun-re nil nil)
9643 (setq type (match-string-no-properties 0))
9644 (verilog-re-search-forward-quick "(" nil nil)
9645 (setq name (verilog-read-module-name))
9647 ;; return modi - note this vector built two places
9648 (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
9650 (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
9651 (make-variable-buffer-local 'verilog-modi-lookup-cache)
9652 (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
9653 (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
9655 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
9656 "Find the file and point at which MODULE is defined.
9657 If ALLOW-CACHE is set, check and remember cache of previous lookups.
9658 Return modi if successful, else print message unless IGNORE-ERROR is true."
9659 (let* ((current (or (buffer-file-name) (current-buffer)))
9662 ;;(message "verilog-modi-lookup: %s" module)
9663 (cond ((and verilog-modi-lookup-cache
9664 verilog-cache-enabled
9666 (setq modi (gethash module verilog-modi-lookup-cache))
9667 (equal verilog-modi-lookup-last-current current)
9668 ;; If hit is in current buffer, then tick must match
9669 (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
9670 (not (equal current (verilog-modi-file-or-buffer modi)))))
9671 ;;(message "verilog-modi-lookup: HIT %S" modi)
9674 (t (let* ((realname (verilog-symbol-detick module t))
9675 (orig-filenames (verilog-module-filenames realname current))
9676 (filenames orig-filenames)
9678 (while (and filenames (not mif))
9679 (if (not (setq mif (verilog-module-inside-filename-p realname (car filenames))))
9680 (setq filenames (cdr filenames))))
9681 ;; mif has correct form to become later elements of modi
9682 (cond (mif (setq modi mif))
9685 (error (concat (verilog-point-text)
9686 ": Can't locate " module " module definition"
9687 (if (not (equal module realname))
9688 (concat " (Expanded macro to " realname ")")
9690 "\n Check the verilog-library-directories variable."
9691 "\n I looked in (if not listed, doesn't exist):\n\t"
9692 (mapconcat 'concat orig-filenames "\n\t"))))))
9693 (when (eval-when-compile (fboundp 'make-hash-table))
9694 (unless verilog-modi-lookup-cache
9695 (setq verilog-modi-lookup-cache
9696 (make-hash-table :test 'equal :rehash-size 4.0)))
9697 (puthash module modi verilog-modi-lookup-cache))
9698 (setq verilog-modi-lookup-last-current current
9699 verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
9702 (defun verilog-modi-filename (modi)
9703 "Filename of MODI, or name of buffer if it's never been saved."
9704 (if (bufferp (verilog-modi-file-or-buffer modi))
9705 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
9706 (buffer-name (verilog-modi-file-or-buffer modi)))
9707 (verilog-modi-file-or-buffer modi)))
9709 (defun verilog-modi-goto (modi)
9710 "Move point/buffer to specified MODI."
9711 (or modi (error "Passed unfound modi to goto, check earlier"))
9712 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
9713 (verilog-modi-file-or-buffer modi)
9714 (find-file-noselect (verilog-modi-file-or-buffer modi))))
9715 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax
9717 (goto-char (verilog-modi-get-point modi)))
9719 (defun verilog-goto-defun-file (module)
9720 "Move point to the file at which a given MODULE is defined."
9721 (interactive "sGoto File for Module: ")
9722 (let* ((modi (verilog-modi-lookup module nil)))
9724 (verilog-modi-goto modi)
9725 (switch-to-buffer (current-buffer)))))
9727 (defun verilog-modi-cache-results (modi function)
9728 "Run on MODI the given FUNCTION. Locate the module in a file.
9729 Cache the output of function so next call may have faster access."
9731 (save-excursion ;; Cache is buffer-local so can't avoid this.
9732 (verilog-modi-goto modi)
9733 (if (and (setq fass (assoc (list modi function)
9734 verilog-modi-cache-list))
9735 ;; Destroy caching when incorrect; Modified or file changed
9736 (not (and verilog-cache-enabled
9737 (or (equal (buffer-chars-modified-tick) (nth 1 fass))
9738 (and verilog-modi-cache-preserve-tick
9739 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
9740 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
9741 (equal (visited-file-modtime) (nth 2 fass)))))
9742 (setq verilog-modi-cache-list nil
9745 ;; Return data from cache hit
9749 ;; Clear then restore any highlighting to make emacs19 happy
9751 (verilog-save-font-mods
9752 (setq func-returns (funcall function)))
9753 ;; Cache for next time
9754 (setq verilog-modi-cache-list
9755 (cons (list (list modi function)
9756 (buffer-chars-modified-tick)
9757 (visited-file-modtime)
9759 verilog-modi-cache-list))
9762 (defun verilog-modi-cache-add (modi function element sig-list)
9763 "Add function return results to the module cache.
9764 Update MODI's cache for given FUNCTION so that the return ELEMENT of that
9765 function now contains the additional SIG-LIST parameters."
9768 (verilog-modi-goto modi)
9769 (if (setq fass (assoc (list modi function)
9770 verilog-modi-cache-list))
9771 (let ((func-returns (nth 3 fass)))
9772 (aset func-returns element
9773 (append sig-list (aref func-returns element))))))))
9775 (defmacro verilog-preserve-modi-cache (&rest body)
9776 "Execute the BODY forms, allowing cache preservation within BODY.
9777 This means that changes to the buffer will not result in the cache being
9778 flushed. If the changes affect the modsig state, they must call the
9779 modsig-cache-add-* function, else the results of later calls may be
9780 incorrect. Without this, changes are assumed to be adding/removing signals
9781 and invalidating the cache."
9782 `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
9783 (verilog-modi-cache-preserve-buffer (current-buffer)))
9787 (defun verilog-modi-modport-lookup-one (modi name &optional ignore-error)
9788 "Given a MODI, return the declarations related to the given modport NAME."
9789 ;; Recursive routine - see below
9790 (let* ((realname (verilog-symbol-detick name t))
9791 (modport (assoc name (verilog-decls-get-modports (verilog-modi-get-decls modi)))))
9792 (or modport ignore-error
9793 (error (concat (verilog-point-text)
9794 ": Can't locate " name " modport definition"
9795 (if (not (equal name realname))
9796 (concat " (Expanded macro to " realname ")")
9798 (let* ((decls (verilog-modport-decls modport))
9799 (clks (verilog-modport-clockings modport)))
9800 ;; Now expand any clocking's
9802 (setq decls (verilog-decls-append
9804 (verilog-modi-modport-lookup-one modi (car clks) ignore-error)))
9805 (setq clks (cdr clks)))
9808 (defun verilog-modi-modport-lookup (modi name-re &optional ignore-error)
9809 "Given a MODI, return the declarations related to the given modport NAME-RE.
9810 If the modport points to any clocking blocks, expand the signals to include
9811 those clocking block's signals."
9812 ;; Recursive routine - see below
9813 (let* ((mod-decls (verilog-modi-get-decls modi))
9814 (clks (verilog-decls-get-modports mod-decls))
9815 (name-re (concat "^" name-re "$"))
9816 (decls (verilog-decls-new nil nil nil nil nil nil nil nil nil)))
9817 ;; Pull in all modports
9819 (when (string-match name-re (verilog-modport-name (car clks)))
9820 (setq decls (verilog-decls-append
9822 (verilog-modi-modport-lookup-one modi (verilog-modport-name (car clks)) ignore-error))))
9823 (setq clks (cdr clks)))
9826 (defun verilog-signals-matching-enum (in-list enum)
9827 "Return all signals in IN-LIST matching the given ENUM."
9830 (if (equal (verilog-sig-enum (car in-list)) enum)
9831 (setq out-list (cons (car in-list) out-list)))
9832 (setq in-list (cdr in-list)))
9834 ;; Namespace intentionally short for AUTOs and compatibility
9835 (let* ((enumvar (intern (concat "venum-" enum)))
9836 (enumlist (and (boundp enumvar) (eval enumvar))))
9838 (add-to-list 'out-list (list (car enumlist)))
9839 (setq enumlist (cdr enumlist))))
9840 (nreverse out-list)))
9842 (defun verilog-signals-matching-regexp (in-list regexp)
9843 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
9844 (if (or (not regexp) (equal regexp ""))
9846 (let ((case-fold-search verilog-case-fold)
9849 (if (string-match regexp (verilog-sig-name (car in-list)))
9850 (setq out-list (cons (car in-list) out-list)))
9851 (setq in-list (cdr in-list)))
9852 (nreverse out-list))))
9854 (defun verilog-signals-not-matching-regexp (in-list regexp)
9855 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
9856 (if (or (not regexp) (equal regexp ""))
9858 (let ((case-fold-search verilog-case-fold)
9861 (if (not (string-match regexp (verilog-sig-name (car in-list))))
9862 (setq out-list (cons (car in-list) out-list)))
9863 (setq in-list (cdr in-list)))
9864 (nreverse out-list))))
9866 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
9867 "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
9869 (if (or (not regexp) (equal regexp ""))
9871 (let (out-list to-match)
9873 ;; Note verilog-insert-one-definition matches on this order
9874 (setq to-match (concat
9876 " " (verilog-sig-signed (car in-list))
9877 " " (verilog-sig-multidim (car in-list))
9878 (verilog-sig-bits (car in-list))))
9879 (if (string-match regexp to-match)
9880 (setq out-list (cons (car in-list) out-list)))
9881 (setq in-list (cdr in-list)))
9882 (nreverse out-list))))
9884 (defun verilog-signals-edit-wire-reg (in-list)
9885 "Return all signals in IN-LIST with wire/reg data types made blank."
9886 (mapcar (lambda (sig)
9887 (when (member (verilog-sig-type sig) '("wire" "reg"))
9888 (verilog-sig-type-set sig nil))
9892 (defun verilog-decls-get-signals (decls)
9893 "Return all declared signals in DECLS, excluding 'assign' statements."
9895 (verilog-decls-get-outputs decls)
9896 (verilog-decls-get-inouts decls)
9897 (verilog-decls-get-inputs decls)
9898 (verilog-decls-get-vars decls)
9899 (verilog-decls-get-consts decls)
9900 (verilog-decls-get-gparams decls)))
9902 (defun verilog-decls-get-ports (decls)
9904 (verilog-decls-get-outputs decls)
9905 (verilog-decls-get-inouts decls)
9906 (verilog-decls-get-inputs decls)))
9908 (defun verilog-decls-get-iovars (decls)
9910 (verilog-decls-get-vars decls)
9911 (verilog-decls-get-outputs decls)
9912 (verilog-decls-get-inouts decls)
9913 (verilog-decls-get-inputs decls)))
9915 (defsubst verilog-modi-cache-add-outputs (modi sig-list)
9916 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
9917 (defsubst verilog-modi-cache-add-inouts (modi sig-list)
9918 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
9919 (defsubst verilog-modi-cache-add-inputs (modi sig-list)
9920 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
9921 (defsubst verilog-modi-cache-add-vars (modi sig-list)
9922 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
9923 (defsubst verilog-modi-cache-add-gparams (modi sig-list)
9924 (verilog-modi-cache-add modi 'verilog-read-decls 7 sig-list))
9928 ;; Auto creation utilities
9931 (defun verilog-auto-re-search-do (search-for func)
9932 "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
9933 (goto-char (point-min))
9934 (while (verilog-re-search-forward-quick search-for nil t)
9937 (defun verilog-insert-one-definition (sig type indent-pt)
9938 "Print out a definition for SIG of the given TYPE,
9939 with appropriate INDENT-PT indentation."
9940 (indent-to indent-pt)
9941 ;; Note verilog-signals-matching-dir-re matches on this order
9943 (when (verilog-sig-modport sig)
9944 (insert "." (verilog-sig-modport sig)))
9945 (when (verilog-sig-signed sig)
9946 (insert " " (verilog-sig-signed sig)))
9947 (when (verilog-sig-multidim sig)
9948 (insert " " (verilog-sig-multidim-string sig)))
9949 (when (verilog-sig-bits sig)
9950 (insert " " (verilog-sig-bits sig)))
9951 (indent-to (max 24 (+ indent-pt 16)))
9952 (unless (= (char-syntax (preceding-char)) ?\ )
9953 (insert " ")) ; Need space between "]name" if indent-to did nothing
9954 (insert (verilog-sig-name sig))
9955 (when (verilog-sig-memory sig)
9956 (insert " " (verilog-sig-memory sig))))
9958 (defun verilog-insert-definition (modi sigs direction indent-pt v2k &optional dont-sort)
9959 "Print out a definition for MODI's list of SIGS of the given DIRECTION,
9960 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
9961 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output.
9962 When MODI is non-null, also add to modi-cache, for tracking."
9964 (cond ((equal direction "wire")
9965 (verilog-modi-cache-add-vars modi sigs))
9966 ((equal direction "reg")
9967 (verilog-modi-cache-add-vars modi sigs))
9968 ((equal direction "output")
9969 (verilog-modi-cache-add-outputs modi sigs)
9970 (when verilog-auto-declare-nettype
9971 (verilog-modi-cache-add-vars modi sigs)))
9972 ((equal direction "input")
9973 (verilog-modi-cache-add-inputs modi sigs)
9974 (when verilog-auto-declare-nettype
9975 (verilog-modi-cache-add-vars modi sigs)))
9976 ((equal direction "inout")
9977 (verilog-modi-cache-add-inouts modi sigs)
9978 (when verilog-auto-declare-nettype
9979 (verilog-modi-cache-add-vars modi sigs)))
9980 ((equal direction "interface"))
9981 ((equal direction "parameter")
9982 (verilog-modi-cache-add-gparams modi sigs))
9984 (error "Unsupported verilog-insert-definition direction: %s" direction))))
9986 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
9988 (let ((sig (car sigs)))
9989 (verilog-insert-one-definition
9991 ;; Want "type x" or "output type x", not "wire type x"
9992 (cond ((or (verilog-sig-type sig)
9993 verilog-auto-wire-type)
9995 (when (member direction '("input" "output" "inout"))
9996 (concat direction " "))
9997 (or (verilog-sig-type sig)
9998 verilog-auto-wire-type)))
9999 ((and verilog-auto-declare-nettype
10000 (member direction '("input" "output" "inout")))
10001 (concat direction " " verilog-auto-declare-nettype))
10005 (insert (if v2k "," ";"))
10006 (if (or (not (verilog-sig-comment sig))
10007 (equal "" (verilog-sig-comment sig)))
10009 (indent-to (max 48 (+ indent-pt 40)))
10010 (verilog-insert "// " (verilog-sig-comment sig) "\n"))
10011 (setq sigs (cdr sigs)))))
10014 (if (not (boundp 'indent-pt))
10015 (defvar indent-pt nil "Local used by insert-indent")))
10017 (defun verilog-insert-indent (&rest stuff)
10018 "Indent to position stored in local `indent-pt' variable, then insert STUFF.
10019 Presumes that any newlines end a list element."
10020 (let ((need-indent t))
10022 (if need-indent (indent-to indent-pt))
10023 (setq need-indent nil)
10024 (verilog-insert (car stuff))
10025 (setq need-indent (string-match "\n$" (car stuff))
10026 stuff (cdr stuff)))))
10027 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
10029 (defun verilog-forward-or-insert-line ()
10030 "Move forward a line, unless at EOB, then insert a newline."
10031 (if (eobp) (insert "\n")
10034 (defun verilog-repair-open-comma ()
10035 "Insert comma if previous argument is other than an open parenthesis or endif."
10036 ;; We can't just search backward for ) as it might be inside another expression.
10037 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
10039 (verilog-backward-syntactic-ws-quick)
10040 (when (and (not (save-excursion ;; Not beginning (, or existing ,
10042 (looking-at "[(,]")))
10043 (not (save-excursion ;; Not `endif, or user define
10045 (skip-chars-backward "[a-zA-Z0-9_`]")
10046 (looking-at "`"))))
10049 (defun verilog-repair-close-comma ()
10050 "If point is at a comma followed by a close parenthesis, fix it.
10051 This repairs those mis-inserted by an AUTOARG."
10052 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
10054 (verilog-forward-close-paren)
10056 (verilog-backward-syntactic-ws-quick)
10058 (when (looking-at ",")
10061 (defun verilog-make-width-expression (range-exp)
10062 "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
10063 ;; strip off the []
10064 (cond ((not range-exp)
10067 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
10068 (setq range-exp (match-string 1 range-exp)))
10069 (cond ((not range-exp)
10071 ;; [#:#] We can compute a numeric result
10072 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
10075 (1+ (abs (- (string-to-number (match-string 1 range-exp))
10076 (string-to-number (match-string 2 range-exp)))))))
10077 ;; [PARAM-1:0] can just return PARAM
10078 ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
10079 (match-string 1 range-exp))
10080 ;; [arbitrary] need math
10081 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
10082 (concat "(1+(" (match-string 1 range-exp) ")"
10083 (if (equal "0" (match-string 2 range-exp))
10084 "" ;; Don't bother with -(0)
10085 (concat "-(" (match-string 2 range-exp) ")"))
10088 ;;(verilog-make-width-expression "`A:`B")
10090 (defun verilog-simplify-range-expression (expr)
10091 "Return a simplified range expression with constants eliminated from EXPR."
10092 ;; Note this is always called with brackets; ie [z] or [z:z]
10093 (if (not (string-match "[---+*()]" expr))
10094 expr ;; short-circuit
10097 (while (not (equal last-pass out))
10098 (setq last-pass out)
10099 ;; Prefix regexp needs beginning of match, or some symbol of
10100 ;; lesser or equal precedence. We assume the [:]'s exist in expr.
10102 (while (string-match
10103 (concat "\\([[({:*+-]\\)" ; - must be last
10104 "(\\<\\([0-9A-Za-z_]+\\))"
10107 (setq out (replace-match "\\1\\2\\3" nil nil out)))
10108 (while (string-match
10109 (concat "\\([[({:*+-]\\)" ; - must be last
10110 "\\$clog2\\s *(\\<\\([0-9]+\\))"
10113 (setq out (replace-match
10115 (match-string 1 out)
10116 (int-to-string (verilog-clog2 (string-to-number (match-string 2 out))))
10117 (match-string 3 out))
10119 ;; For precedence do * before +/-
10120 (while (string-match
10121 (concat "\\([[({:*+-]\\)"
10122 "\\([0-9]+\\)\\s *\\([*]\\)\\s *\\([0-9]+\\)"
10125 (setq out (replace-match
10126 (concat (match-string 1 out)
10127 (int-to-string (* (string-to-number (match-string 2 out))
10128 (string-to-number (match-string 4 out))))
10129 (match-string 5 out))
10131 (while (string-match
10132 (concat "\\([[({:+-]\\)" ; No * here as higher prec
10133 "\\([0-9]+\\)\\s *\\([---+]\\)\\s *\\([0-9]+\\)"
10136 (let ((pre (match-string 1 out))
10137 (lhs (string-to-number (match-string 2 out)))
10138 (rhs (string-to-number (match-string 4 out)))
10139 (post (match-string 5 out))
10141 (when (equal pre "-")
10142 (setq lhs (- lhs)))
10143 (setq val (if (equal (match-string 3 out) "-")
10147 (concat (if (and (equal pre "-")
10149 "" ;; Not "--20" but just "-20"
10151 (int-to-string val)
10156 ;;(verilog-simplify-range-expression "[1:3]") ;; 1
10157 ;;(verilog-simplify-range-expression "[(1):3]") ;; 1
10158 ;;(verilog-simplify-range-expression "[(((16)+1)+1+(1+1))]") ;;20
10159 ;;(verilog-simplify-range-expression "[(2*3+6*7)]") ;; 48
10160 ;;(verilog-simplify-range-expression "[(FOO*4-1*2)]") ;; FOO*4-2
10161 ;;(verilog-simplify-range-expression "[(FOO*4+1-1)]") ;; FOO*4+0
10162 ;;(verilog-simplify-range-expression "[(func(BAR))]") ;; func(BAR)
10163 ;;(verilog-simplify-range-expression "[FOO-1+1-1+1]") ;; FOO-0
10164 ;;(verilog-simplify-range-expression "[$clog2(2)]") ;; 1
10165 ;;(verilog-simplify-range-expression "[$clog2(7)]") ;; 3
10167 (defun verilog-clog2 (value)
10168 "Compute $clog2 - ceiling log2 of VALUE."
10171 (ceiling (/ (log value) (log 2)))))
10173 (defun verilog-typedef-name-p (variable-name)
10174 "Return true if the VARIABLE-NAME is a type definition."
10175 (when verilog-typedef-regexp
10176 (verilog-string-match-fold verilog-typedef-regexp variable-name)))
10182 (defun verilog-delete-autos-lined ()
10183 "Delete autos that occupy multiple lines, between begin and end comments."
10184 ;; The newline must not have a comment property, so we must
10185 ;; delete the end auto's newline, not the first newline
10187 (let ((pt (point)))
10189 (looking-at "\\s-*// Beginning")
10190 (search-forward "// End of automatic" nil t))
10194 (delete-region pt (point)))))
10196 (defun verilog-delete-empty-auto-pair ()
10197 "Delete begin/end auto pair at point, if empty."
10199 (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
10200 "\\s-*// End of automatics\n"))
10201 (delete-region (point) (save-excursion (forward-line 2) (point)))))
10203 (defun verilog-forward-close-paren ()
10204 "Find the close parenthesis that match the current point.
10205 Ignore other close parenthesis with matching open parens."
10207 (while (> parens 0)
10208 (unless (verilog-re-search-forward-quick "[()]" nil t)
10209 (error "%s: Mismatching ()" (verilog-point-text)))
10210 (cond ((= (preceding-char) ?\( )
10211 (setq parens (1+ parens)))
10212 ((= (preceding-char) ?\) )
10213 (setq parens (1- parens)))))))
10215 (defun verilog-backward-open-paren ()
10216 "Find the open parenthesis that match the current point.
10217 Ignore other open parenthesis with matching close parens."
10219 (while (> parens 0)
10220 (unless (verilog-re-search-backward-quick "[()]" nil t)
10221 (error "%s: Mismatching ()" (verilog-point-text)))
10222 (cond ((= (following-char) ?\) )
10223 (setq parens (1+ parens)))
10224 ((= (following-char) ?\( )
10225 (setq parens (1- parens)))))))
10227 (defun verilog-backward-open-bracket ()
10228 "Find the open bracket that match the current point.
10229 Ignore other open bracket with matching close bracket."
10231 (while (> parens 0)
10232 (unless (verilog-re-search-backward-quick "[][]" nil t)
10233 (error "%s: Mismatching []" (verilog-point-text)))
10234 (cond ((= (following-char) ?\] )
10235 (setq parens (1+ parens)))
10236 ((= (following-char) ?\[ )
10237 (setq parens (1- parens)))))))
10239 (defun verilog-delete-to-paren ()
10240 "Delete the automatic inst/sense/arg created by autos.
10241 Deletion stops at the matching end parenthesis, outside comments."
10242 (delete-region (point)
10244 (verilog-backward-open-paren)
10245 (verilog-forward-sexp-ign-cmt 1) ;; Moves to paren that closes argdecl's
10249 (defun verilog-auto-star-safe ()
10250 "Return if a .* AUTOINST is safe to delete or expand.
10251 It was created by the AUTOS themselves, or by the user."
10252 (and verilog-auto-star-expand
10254 (concat "[ \t\n\f,]*\\([)]\\|// " verilog-inst-comment-re "\\)"))))
10256 (defun verilog-delete-auto-star-all ()
10257 "Delete a .* AUTOINST, if it is safe."
10258 (when (verilog-auto-star-safe)
10259 (verilog-delete-to-paren)))
10261 (defun verilog-delete-auto-star-implicit ()
10262 "Delete all .* implicit connections created by `verilog-auto-star'.
10263 This function will be called automatically at save unless
10264 `verilog-auto-star-save' is set, any non-templated expanded pins will be
10267 (let (paren-pt indent have-close-paren)
10269 (goto-char (point-min))
10270 ;; We need to match these even outside of comments.
10271 ;; For reasonable performance, we don't check if inside comments, sorry.
10272 (while (re-search-forward "// Implicit \\.\\*" nil t)
10273 (setq paren-pt (point))
10274 (beginning-of-line)
10275 (setq have-close-paren
10277 (when (search-forward ");" paren-pt t)
10278 (setq indent (current-indentation))
10280 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
10281 (when have-close-paren
10282 ;; Delete extra commentary
10286 (looking-at (concat "\\s *//\\s *" verilog-inst-comment-re "\n")))
10287 (delete-region (match-beginning 0) (match-end 0))))
10288 ;; If it is simple, we can put the ); on the same line as the last text
10289 (let ((rtn-pt (point)))
10291 (while (progn (backward-char 1)
10292 (looking-at "[ \t\n\f]")))
10293 (when (looking-at ",")
10294 (delete-region (+ 1 (point)) rtn-pt))))
10296 (indent-to indent))
10298 ;; Still need to kill final comma - always is one as we put one after the .*
10299 (re-search-backward ",")
10300 (delete-char 1))))))
10302 (defun verilog-delete-auto ()
10303 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
10304 Use \\[verilog-auto] to re-insert the updated AUTOs.
10306 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
10307 called before and after this function, respectively."
10310 (if (buffer-file-name)
10311 (find-file-noselect (buffer-file-name))) ;; To check we have latest version
10312 (verilog-save-no-change-functions
10313 (verilog-save-scan-cache
10314 ;; Allow user to customize
10315 (verilog-run-hooks 'verilog-before-delete-auto-hook)
10317 ;; Remove those that have multi-line insertions, possibly with parameters
10318 ;; We allow anything beginning with AUTO, so that users can add their own
10320 (verilog-auto-re-search-do
10321 (concat "/\\*AUTO[A-Za-z0-9_]+"
10322 ;; Optional parens or quoted parameter or .* for (((...)))
10323 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
10325 'verilog-delete-autos-lined)
10326 ;; Remove those that are in parenthesis
10327 (verilog-auto-re-search-do
10330 (verilog-regexp-words
10331 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
10334 'verilog-delete-to-paren)
10335 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
10336 (verilog-auto-re-search-do "\\.\\*"
10337 'verilog-delete-auto-star-all)
10338 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
10339 (goto-char (point-min))
10340 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
10341 (replace-match ""))
10344 (verilog-run-hooks 'verilog-delete-auto-hook)))))
10350 (defun verilog-inject-auto ()
10351 "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
10353 Any always @ blocks with sensitivity lists that match computed lists will
10354 be replaced with /*AS*/ comments.
10356 Any cells will get /*AUTOINST*/ added to the end of the pin list.
10357 Pins with have identical names will be deleted.
10359 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
10360 support adding new ports. You may wish to delete older ports yourself.
10364 module ExampInject (i, o);
10370 InstModule instName
10375 Typing \\[verilog-inject-auto] will make this into:
10377 module ExampInject (i, o/*AUTOARG*/
10382 always @ (/*AS*/i or j)
10384 InstModule instName
10393 (defun verilog-inject-arg ()
10394 "Inject AUTOARG into new code. See `verilog-inject-auto'."
10395 ;; Presume one module per file.
10397 (goto-char (point-min))
10398 (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
10399 (let ((endmodp (save-excursion
10400 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
10402 ;; See if there's already a comment .. inside a comment so not verilog-re-search
10403 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
10404 (verilog-re-search-forward-quick ";" nil t)
10406 (verilog-backward-syntactic-ws-quick)
10407 (backward-char 1) ; Moves to paren that closes argdecl's
10408 (when (looking-at ")")
10409 (verilog-insert "/*AUTOARG*/")))))))
10411 (defun verilog-inject-sense ()
10412 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
10414 (goto-char (point-min))
10415 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
10416 (let* ((start-pt (point))
10417 (modi (verilog-modi-current))
10418 (moddecls (verilog-modi-get-decls modi))
10422 (verilog-forward-sexp-ign-cmt 1)
10423 (backward-char 1) ;; End )
10424 (when (not (verilog-re-search-backward-quick "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
10425 (setq pre-sigs (verilog-signals-from-signame
10426 (verilog-read-signals start-pt (point)))
10427 got-sigs (verilog-auto-sense-sigs moddecls nil))
10428 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
10429 (verilog-signals-not-in got-sigs pre-sigs)))
10430 (delete-region start-pt (point))
10431 (verilog-insert "/*AS*/")))))))
10433 (defun verilog-inject-inst ()
10434 "Inject AUTOINST into new code. See `verilog-inject-auto'."
10436 (goto-char (point-min))
10437 ;; It's hard to distinguish modules; we'll instead search for pins.
10438 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t)
10439 (verilog-backward-open-paren) ;; Inst start
10441 ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip.
10443 (verilog-forward-close-paren)) ;; Parameters done
10446 (let ((indent-pt (+ (current-column)))
10447 (end-pt (save-excursion (verilog-forward-close-paren) (point))))
10448 (cond ((verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
10449 (goto-char end-pt)) ;; Already there, continue search with next instance
10451 ;; Delete identical interconnect
10452 (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc
10453 (while (verilog-re-search-forward-quick "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
10454 (delete-region (match-beginning 0) (match-end 0))
10455 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct
10456 (while (or (looking-at "[ \t\n\f,]+")
10457 (looking-at "//[^\n]*"))
10458 (delete-region (match-beginning 0) (match-end 0))
10459 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
10460 (verilog-forward-close-paren)
10462 ;; Not verilog-re-search, as we don't want to strip comments
10463 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
10464 (delete-region (match-beginning 0) (match-end 0)))
10465 (verilog-insert "\n")
10466 (verilog-insert-indent "/*AUTOINST*/")))))))))
10472 (defun verilog-diff-buffers-p (b1 b2 &optional whitespace)
10473 "Return nil if buffers B1 and B2 have same contents.
10474 Else, return point in B1 that first mismatches.
10475 If optional WHITESPACE true, ignore whitespace."
10477 (let* ((case-fold-search nil) ;; compare-buffer-substrings cares
10478 (p1 (with-current-buffer b1 (goto-char (point-min))))
10479 (p2 (with-current-buffer b2 (goto-char (point-min))))
10480 (maxp1 (with-current-buffer b1 (point-max)))
10481 (maxp2 (with-current-buffer b2 (point-max)))
10484 (while (not (and (eq p1 op1) (eq p2 op2)))
10485 ;; If both windows have whitespace optionally skip over it.
10487 ;; skip-syntax-* doesn't count \n
10488 (with-current-buffer b1
10490 (skip-chars-forward " \t\n\r\f\v")
10492 (with-current-buffer b2
10494 (skip-chars-forward " \t\n\r\f\v")
10495 (setq p2 (point))))
10496 (setq size (min (- maxp1 p1) (- maxp2 p2)))
10497 (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
10498 b1 p1 (+ size p1)))
10499 (setq progress (if (zerop progress) size (1- (abs progress))))
10500 (setq op1 p1 op2 p2
10502 p2 (+ p2 progress)))
10504 (if (and (eq p1 maxp1) (eq p2 maxp2))
10507 (defun verilog-diff-file-with-buffer (f1 b2 &optional whitespace show)
10508 "View the differences between file F1 and buffer B2.
10509 This requires the external program `diff-command' to be in your `exec-path',
10510 and uses `diff-switches' in which you may want to have \"-u\" flag.
10511 Ignores WHITESPACE if t, and writes output to stdout if SHOW."
10512 ;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
10513 ;; call `diff' as `diff' has different calling semantics on different
10514 ;; versions of Emacs.
10515 (if (not (file-exists-p f1))
10516 (message "Buffer %s has no associated file on disc" (buffer-name b2))
10517 (with-temp-buffer "*Verilog-Diff*"
10518 (let ((outbuf (current-buffer))
10519 (f2 (make-temp-file "vm-diff-auto-")))
10522 (with-current-buffer b2
10525 (write-region (point-min) (point-max) f2 nil 'nomessage)))
10526 (call-process diff-command nil outbuf t
10527 diff-switches ;; User may want -u in diff-switches
10528 (if whitespace "-b" "")
10530 ;; Print out results. Alternatively we could have call-processed
10531 ;; ourself, but this way we can reuse diff switches
10533 (with-current-buffer outbuf (message "%s" (buffer-string))))))
10535 (when (file-exists-p f2)
10536 (delete-file f2))))))
10538 (defun verilog-diff-report (b1 b2 diffpt)
10539 "Report differences detected with `verilog-diff-auto'.
10540 Differences are between buffers B1 and B2, starting at point
10541 DIFFPT. This function is called via `verilog-diff-function'."
10542 (let ((name1 (with-current-buffer b1 (buffer-file-name))))
10543 (verilog-warn "%s:%d: Difference in AUTO expansion found"
10544 name1 (with-current-buffer b1
10545 (count-lines (point-min) diffpt)))
10546 (cond (noninteractive
10547 (verilog-diff-file-with-buffer name1 b2 t t))
10549 (ediff-buffers b1 b2)))))
10551 (defun verilog-diff-auto ()
10552 "Expand AUTOs in a temporary buffer and indicate any change.
10553 Whitespace is ignored when detecting differences, but once a
10554 difference is detected, whitespace differences may be shown.
10556 To call this from the command line, see \\[verilog-batch-diff-auto].
10558 The action on differences is selected with
10559 `verilog-diff-function'. The default is `verilog-diff-report'
10560 which will report an error and run `ediff' in interactive mode,
10561 or `diff' in batch mode."
10563 (let ((b1 (current-buffer)) b2 diffpt
10564 (name1 (buffer-file-name))
10565 (newname "*Verilog-Diff*"))
10567 (when (get-buffer newname)
10568 (kill-buffer newname))
10569 (setq b2 (let (buffer-file-name) ;; Else clone is upset
10570 (clone-buffer newname)))
10571 (with-current-buffer b2
10572 ;; auto requires the filename, but can't have same filename in two
10573 ;; buffers; so override both b1 and b2's names
10574 (let ((buffer-file-name name1))
10577 (with-current-buffer b1 (setq buffer-file-name nil))
10579 (when (not verilog-auto-star-save)
10580 (verilog-delete-auto-star-implicit)))
10581 ;; Restore name if unwind
10582 (with-current-buffer b1 (setq buffer-file-name name1)))))
10584 (setq diffpt (verilog-diff-buffers-p b1 b2 t))
10585 (cond ((not diffpt)
10586 (unless noninteractive (message "AUTO expansion identical"))
10587 (kill-buffer newname)) ;; Nice to cleanup after oneself
10589 (funcall verilog-diff-function b1 b2 diffpt)))
10590 ;; Return result of compare
10598 (defun verilog-auto-save-check ()
10599 "On saving see if we need auto update."
10600 (cond ((not verilog-auto-save-policy)) ; disabled
10601 ((not (save-excursion
10603 (let ((case-fold-search nil))
10604 (goto-char (point-min))
10605 (re-search-forward "AUTO" nil t))))))
10606 ((eq verilog-auto-save-policy 'force)
10608 ((not (buffer-modified-p)))
10609 ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
10610 ((eq verilog-auto-save-policy 'detect)
10613 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
10615 ;; Don't ask again if didn't update
10616 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
10617 (when (not verilog-auto-star-save)
10618 (verilog-delete-auto-star-implicit))
10619 nil) ;; Always return nil -- we don't write the file ourselves
10621 (defun verilog-auto-read-locals ()
10622 "Return file local variable segment at bottom of file."
10624 (goto-char (point-max))
10625 (if (re-search-backward "Local Variables:" nil t)
10626 (buffer-substring-no-properties (point) (point-max))
10629 (defun verilog-auto-reeval-locals (&optional force)
10630 "Read file local variable segment at bottom of file if it has changed.
10631 If FORCE, always reread it."
10632 (let ((curlocal (verilog-auto-read-locals)))
10633 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
10634 (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
10635 ;; Note this may cause this function to be recursively invoked,
10636 ;; because hack-local-variables may call (verilog-mode)
10637 ;; The above when statement will prevent it from recursing forever.
10638 (hack-local-variables)
10645 (defun verilog-auto-arg-ports (sigs message indent-pt)
10646 "Print a list of ports for AUTOARG.
10647 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
10649 (when verilog-auto-arg-sort
10650 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
10652 (indent-to indent-pt)
10656 (indent-to indent-pt)
10658 (cond ((equal verilog-auto-arg-format 'single)
10660 (indent-to indent-pt)
10662 ;; verilog-auto-arg-format 'packed
10663 ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
10665 (indent-to indent-pt)
10670 (insert (verilog-sig-name (car sigs)) ",")
10671 (setq sigs (cdr sigs))))))
10673 (defun verilog-auto-arg ()
10674 "Expand AUTOARG statements.
10675 Replace the argument declarations at the beginning of the
10676 module with ones automatically derived from input and output
10677 statements. This can be dangerous if the module is instantiated
10678 using position-based connections, so use only name-based when
10679 instantiating the resulting module. Long lines are split based
10680 on the `fill-column', see \\[set-fill-column].
10683 Concatenation and outputting partial buses is not supported.
10685 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10689 module ExampArg (/*AUTOARG*/);
10694 Typing \\[verilog-auto] will make this into:
10696 module ExampArg (/*AUTOARG*/
10706 The argument declarations may be printed in declaration order to
10707 best suit order based instantiations, or alphabetically, based on
10708 the `verilog-auto-arg-sort' variable.
10710 Formatting is controlled with `verilog-auto-arg-format' variable.
10712 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
10713 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
10714 conservative guess on adding a comma for the first signal, if you have
10715 any ifdefs or complicated expressions before the AUTOARG you will need
10716 to choose the comma yourself.
10718 Avoid declaring ports manually, as it makes code harder to maintain."
10720 (let* ((modi (verilog-modi-current))
10721 (moddecls (verilog-modi-get-decls modi))
10722 (skip-pins (aref (verilog-read-arg-pins) 0)))
10723 (verilog-repair-open-comma)
10724 (verilog-auto-arg-ports (verilog-signals-not-in
10725 (verilog-decls-get-outputs moddecls)
10728 verilog-indent-level-declaration)
10729 (verilog-auto-arg-ports (verilog-signals-not-in
10730 (verilog-decls-get-inouts moddecls)
10733 verilog-indent-level-declaration)
10734 (verilog-auto-arg-ports (verilog-signals-not-in
10735 (verilog-decls-get-inputs moddecls)
10738 verilog-indent-level-declaration)
10739 (verilog-repair-close-comma)
10740 (unless (eq (char-before) ?/ )
10742 (indent-to verilog-indent-level-declaration))))
10744 (defun verilog-auto-assign-modport ()
10745 "Expand AUTOASSIGNMODPORT statements, as part of \\[verilog-auto].
10746 Take input/output/inout statements from the specified interface
10747 and modport and use to build assignments into the modport, for
10748 making verification modules that connect to UVM interfaces.
10750 The first parameter is the name of an interface.
10752 The second parameter is a regexp of modports to read from in
10755 The third parameter is the instance name to use to dot reference into.
10757 The optional fourth parameter is a regular expression, and only
10758 signals matching the regular expression will be included.
10762 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
10764 Inouts are not supported, as assignments must be unidirectional.
10766 If a signal is part of the interface header and in both a
10767 modport and the interface itself, it will not be listed. (As
10768 this would result in a syntax error when the connections are
10771 See the example in `verilog-auto-inout-modport'."
10773 (let* ((params (verilog-read-auto-params 3 4))
10774 (submod (nth 0 params))
10775 (modport-re (nth 1 params))
10776 (inst-name (nth 2 params))
10777 (regexp (nth 3 params))
10778 direction-re submodi) ;; direction argument not supported until requested
10779 ;; Lookup position, etc of co-module
10780 ;; Note this may raise an error
10781 (when (setq submodi (verilog-modi-lookup submod t))
10782 (let* ((indent-pt (current-indentation))
10783 (submoddecls (verilog-modi-get-decls submodi))
10784 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
10785 (sig-list-i (verilog-signals-in ;; Decls doesn't have data types, must resolve
10786 (verilog-decls-get-vars submoddecls)
10787 (verilog-signals-not-in
10788 (verilog-decls-get-inputs submodportdecls)
10789 (verilog-decls-get-ports submoddecls))))
10790 (sig-list-o (verilog-signals-in ;; Decls doesn't have data types, must resolve
10791 (verilog-decls-get-vars submoddecls)
10792 (verilog-signals-not-in
10793 (verilog-decls-get-outputs submodportdecls)
10794 (verilog-decls-get-ports submoddecls)))))
10796 (setq sig-list-i (verilog-signals-edit-wire-reg
10797 (verilog-signals-matching-dir-re
10798 (verilog-signals-matching-regexp sig-list-i regexp)
10799 "input" direction-re))
10800 sig-list-o (verilog-signals-edit-wire-reg
10801 (verilog-signals-matching-dir-re
10802 (verilog-signals-matching-regexp sig-list-o regexp)
10803 "output" direction-re)))
10804 (setq sig-list-i (sort (copy-alist sig-list-i) `verilog-signals-sort-compare))
10805 (setq sig-list-o (sort (copy-alist sig-list-o) `verilog-signals-sort-compare))
10806 (when (or sig-list-i sig-list-o)
10807 (verilog-insert-indent "// Beginning of automatic assignments from modport\n")
10808 ;; Don't sort them so an upper AUTOINST will match the main module
10809 (let ((sigs sig-list-o))
10811 (verilog-insert-indent "assign " (verilog-sig-name (car sigs))
10813 "." (verilog-sig-name (car sigs)) ";\n")
10814 (setq sigs (cdr sigs))))
10815 (let ((sigs sig-list-i))
10817 (verilog-insert-indent "assign " inst-name
10818 "." (verilog-sig-name (car sigs))
10819 " = " (verilog-sig-name (car sigs)) ";\n")
10820 (setq sigs (cdr sigs))))
10821 (verilog-insert-indent "// End of automatics\n")))))))
10823 (defun verilog-auto-inst-port-map (_port-st)
10826 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
10827 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
10828 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
10829 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
10830 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
10831 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
10832 (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
10833 (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
10835 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
10836 "Print out an instantiation connection for this PORT-ST.
10837 Insert to INDENT-PT, use template TPL-LIST.
10838 @ are instantiation numbers, replaced with TPL-NUM.
10839 @\"(expression @)\" are evaluated, with @ as a variable.
10840 If FOR-STAR add comment it is a .* expansion.
10841 If PAR-VALUES replace final strings with these parameter values."
10842 (let* ((port (verilog-sig-name port-st))
10843 (tpl-ass (or (assoc port (car tpl-list))
10844 (verilog-auto-inst-port-map port-st)))
10845 ;; vl-* are documented for user use
10846 (vl-name (verilog-sig-name port-st))
10847 (vl-width (verilog-sig-width port-st))
10848 (vl-modport (verilog-sig-modport port-st))
10849 (vl-mbits (if (verilog-sig-multidim port-st)
10850 (verilog-sig-multidim-string port-st) ""))
10851 (vl-bits (if (or verilog-auto-inst-vector
10852 (not (assoc port vector-skip-list))
10853 (not (equal (verilog-sig-bits port-st)
10854 (verilog-sig-bits (assoc port vector-skip-list)))))
10855 (or (verilog-sig-bits port-st) "")
10857 (case-fold-search nil)
10858 (check-values par-values)
10860 ;; Replace parameters in bit-width
10861 (when (and check-values
10862 (not (equal vl-bits "")))
10863 (while check-values
10864 (setq vl-bits (verilog-string-replace-matches
10865 (concat "\\<" (nth 0 (car check-values)) "\\>")
10866 (concat "(" (nth 1 (car check-values)) ")")
10868 vl-mbits (verilog-string-replace-matches
10869 (concat "\\<" (nth 0 (car check-values)) "\\>")
10870 (concat "(" (nth 1 (car check-values)) ")")
10872 check-values (cdr check-values)))
10873 (setq vl-bits (verilog-simplify-range-expression vl-bits)
10874 vl-mbits (verilog-simplify-range-expression vl-mbits)
10875 vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
10876 ;; Default net value if not found
10877 (setq dflt-bits (if (and (verilog-sig-bits port-st)
10878 (or (verilog-sig-multidim port-st)
10879 (verilog-sig-memory port-st)))
10880 (concat "/*" vl-mbits vl-bits "*/")
10882 tpl-net (concat port
10883 (if vl-modport (concat "." vl-modport) "")
10886 (cond (tpl-ass ; Template of exact port name
10887 (setq tpl-net (nth 1 tpl-ass)))
10888 ((nth 1 tpl-list) ; Wildcards in template, search them
10889 (let ((wildcards (nth 1 tpl-list)))
10891 (when (string-match (nth 0 (car wildcards)) port)
10892 (setq tpl-ass (car wildcards) ; so allow @ parsing
10893 tpl-net (replace-match (nth 1 (car wildcards))
10895 (setq wildcards (cdr wildcards))))))
10896 ;; Parse Templated variable
10898 ;; Evaluate @"(lispcode)"
10899 (when (string-match "@\".*[^\\]\"" tpl-net)
10900 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
10903 (substring tpl-net 0 (match-beginning 0))
10905 (let* ((expr (match-string 1 tpl-net))
10908 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
10909 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
10910 (prin1 (eval (car (read-from-string expr)))
10911 (lambda (_ch) ())))))
10912 (if (numberp value) (setq value (number-to-string value)))
10914 (substring tpl-net (match-end 0))))))
10915 ;; Replace @ and [] magic variables in final output
10916 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
10917 (setq tpl-net (verilog-string-replace-matches "\\[\\]\\[\\]" dflt-bits nil nil tpl-net))
10918 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
10920 (indent-to indent-pt)
10922 (unless (and verilog-auto-inst-dot-name
10923 (equal port tpl-net))
10924 (indent-to verilog-auto-inst-column)
10925 (insert "(" tpl-net ")"))
10928 (verilog-read-auto-template-hit tpl-ass)
10929 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
10930 verilog-auto-inst-column))
10931 ;; verilog-insert requires the complete comment in one call - including the newline
10932 (cond ((equal verilog-auto-inst-template-numbers `lhs)
10933 (verilog-insert " // Templated"
10934 " LHS: " (nth 0 tpl-ass)
10936 (verilog-auto-inst-template-numbers
10937 (verilog-insert " // Templated"
10938 " T" (int-to-string (nth 2 tpl-ass))
10939 " L" (int-to-string (nth 3 tpl-ass))
10942 (verilog-insert " // Templated\n"))))
10944 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
10945 verilog-auto-inst-column))
10946 (verilog-insert " // Implicit .\*\n")) ;For some reason the . or * must be escaped...
10949 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
10950 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
10951 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
10953 (defun verilog-auto-inst-port-list (sig-list indent-pt tpl-list tpl-num for-star par-values)
10954 "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
10955 (when verilog-auto-inst-sort
10956 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)))
10957 (mapc (lambda (port)
10958 (verilog-auto-inst-port port indent-pt
10959 tpl-list tpl-num for-star par-values))
10962 (defun verilog-auto-inst-first ()
10963 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
10964 ;; Do we need a trailing comma?
10965 ;; There maybe an ifdef or something similar before us. What a mess. Thus
10966 ;; to avoid trouble we only insert on preceding ) or *.
10967 ;; Insert first port on new line
10968 (insert "\n") ;; Must insert before search, so point will move forward if insert comma
10970 (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
10971 (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure
10975 (defun verilog-auto-star ()
10976 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
10978 If `verilog-auto-star-expand' is set, .* pins are treated if they were
10979 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
10980 will also ignore any .* that are not last in your pin list (this prevents
10981 it from deleting pins following the .* when it expands the AUTOINST.)
10983 On writing your file, unless `verilog-auto-star-save' is set, any
10984 non-templated expanded pins will be removed. You may do this at any time
10985 with \\[verilog-delete-auto-star-implicit].
10987 If you are converting a module to use .* for the first time, you may wish
10988 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
10990 See `verilog-auto-inst' for examples, templates, and more information."
10991 (when (verilog-auto-star-safe)
10992 (verilog-auto-inst)))
10994 (defun verilog-auto-inst ()
10995 "Expand AUTOINST statements, as part of \\[verilog-auto].
10996 Replace the pin connections to an instantiation or interface
10997 declaration with ones automatically derived from the module or
10998 interface header of the instantiated item.
11000 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
11001 and delete them before saving unless `verilog-auto-star-save' is set.
11002 See `verilog-auto-star' for more information.
11004 The pins are printed in declaration order or alphabetically,
11005 based on the `verilog-auto-inst-sort' variable.
11008 Module names must be resolvable to filenames by adding a
11009 `verilog-library-extensions', and being found in the same directory, or
11010 by changing the variable `verilog-library-flags' or
11011 `verilog-library-directories'. Macros `modname are translated through the
11012 vh-{name} Emacs variable, if that is not found, it just ignores the `.
11014 In templates you must have one signal per line, ending in a ), or ));,
11015 and have proper () nesting, including a final ); to end the template.
11017 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11019 SystemVerilog multidimensional input/output has only experimental support.
11021 SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
11023 Parameters referenced by the instantiation will remain symbolic, unless
11024 `verilog-auto-inst-param-value' is set.
11026 Gate primitives (and/or) may have AUTOINST for the purpose of
11027 AUTOWIRE declarations, etc. Gates are the only case when
11028 position based connections are passed.
11030 The array part of arrayed instances are ignored; this may
11031 result in undesirable default AUTOINST connections; use a
11034 For example, first take the submodule InstModule.v:
11036 module InstModule (o,i);
11039 wire [31:0] o = {32{i}};
11042 This is then used in an upper level module:
11044 module ExampInst (o,i);
11047 InstModule instName
11051 Typing \\[verilog-auto] will make this into:
11053 module ExampInst (o,i);
11056 InstModule instName
11064 Where the list of inputs and outputs came from the inst module.
11068 Unless you are instantiating a module multiple times, or the module is
11069 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
11070 It just makes for unmaintainable code. To sanitize signal names, try
11071 vrename from URL `http://www.veripool.org'.
11073 When you need to violate this suggestion there are two ways to list
11074 exceptions, placing them before the AUTOINST, or using templates.
11076 Any ports defined before the /*AUTOINST*/ are not included in the list of
11077 automatics. This is similar to making a template as described below, but
11078 is restricted to simple connections just like you normally make. Also note
11079 that any signals before the AUTOINST will only be picked up by AUTOWIRE if
11080 you have the appropriate // Input or // Output comment, and exactly the
11081 same line formatting as AUTOINST itself uses.
11083 InstModule instName
11085 .i (my_i_dont_mess_with_it),
11093 For multiple instantiations based upon a single template, create a
11094 commented out template:
11096 /* InstModule AUTO_TEMPLATE (
11101 Templates go ABOVE the instantiation(s). When an instantiation is
11102 expanded `verilog-mode' simply searches up for the closest template.
11103 Thus you can have multiple templates for the same module, just alternate
11104 between the template for an instantiation and the instantiation itself.
11105 (For backward compatibility if no template is found above, it
11106 will also look below, but do not use this behavior in new designs.)
11108 The module name must be the same as the name of the module in the
11109 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
11110 words and capitalized. Only signals that must be different for each
11111 instantiation need to be listed.
11113 Inside a template, a [] in a connection name (with nothing else
11114 inside the brackets) will be replaced by the same bus subscript
11115 as it is being connected to, or the [] will be removed if it is
11116 a single bit signal.
11118 Inside a template, a [][] in a connection name will behave
11119 similarly to a [] for scalar or single-dimensional connection;
11120 for a multidimensional connection it will print a comment
11121 similar to that printed when a template is not used. Generally
11122 it is a good idea to do this for all connections in a template,
11123 as then they will work for any width signal, and with AUTOWIRE.
11124 See PTL_BUS becoming PTL_BUSNEW below.
11126 Inside a template, a [] in a connection name (with nothing else inside
11127 the brackets) will be replaced by the same bus subscript as it is being
11128 connected to, or the [] will be removed if it is a single bit signal.
11129 Generally it is a good idea to do this for all connections in a template,
11130 as then they will work for any width signal, and with AUTOWIRE. See
11131 PTL_BUS becoming PTL_BUSNEW below.
11133 If you have a complicated template, set `verilog-auto-inst-template-numbers'
11134 to see which regexps are matching. Don't leave that mode set after
11135 debugging is completed though, it will result in lots of extra differences
11136 and merge conflicts.
11138 Setting `verilog-auto-template-warn-unused' will report errors
11139 if any template lines are unused.
11143 /* InstModule AUTO_TEMPLATE (
11144 .ptl_bus (ptl_busnew[]),
11147 InstModule ms2m (/*AUTOINST*/);
11149 Typing \\[verilog-auto] will make this into:
11151 InstModule ms2m (/*AUTOINST*/
11153 .NotInTemplate (NotInTemplate),
11154 .ptl_bus (ptl_busnew[3:0]), // Templated
11158 Multiple Module Templates:
11160 The same template lines can be applied to multiple modules with
11161 the syntax as follows:
11163 /* InstModuleA AUTO_TEMPLATE
11164 InstModuleB AUTO_TEMPLATE
11165 InstModuleC AUTO_TEMPLATE
11166 InstModuleD AUTO_TEMPLATE (
11167 .ptl_bus (ptl_busnew[]),
11171 Note there is only one AUTO_TEMPLATE opening parenthesis.
11175 It is common to instantiate a cell multiple times, so templates make it
11176 trivial to substitute part of the cell name into the connection name.
11178 /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
11180 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
11184 If no regular expression is provided immediately after the AUTO_TEMPLATE
11185 keyword, then the @ character in any connection names will be replaced
11186 with the instantiation number; the first digits found in the cell's
11187 instantiation name.
11189 If a regular expression is provided, the @ character will be replaced
11190 with the first \(\) grouping that matches against the cell name. Using a
11191 regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no
11192 regexp is provided. If you use multiple layers of parenthesis,
11193 \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number
11194 characters after test and before _, whereas
11195 \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire
11200 /* InstModule AUTO_TEMPLATE (
11201 .ptl_mapvalidx (ptl_mapvalid[@]),
11202 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
11205 InstModule ms2m (/*AUTOINST*/);
11207 Typing \\[verilog-auto] will make this into:
11209 InstModule ms2m (/*AUTOINST*/
11211 .ptl_mapvalidx (ptl_mapvalid[2]),
11212 .ptl_mapvalidp1x (ptl_mapvalid[3]));
11214 Note the @ character was replaced with the 2 from \"ms2m\".
11216 Alternatively, using a regular expression for @:
11218 /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
11219 .ptl_mapvalidx (@_ptl_mapvalid),
11220 .ptl_mapvalidp1x (ptl_mapvalid_@),
11223 InstModule ms2_FOO (/*AUTOINST*/);
11224 InstModule ms2_BAR (/*AUTOINST*/);
11226 Typing \\[verilog-auto] will make this into:
11228 InstModule ms2_FOO (/*AUTOINST*/
11230 .ptl_mapvalidx (FOO_ptl_mapvalid),
11231 .ptl_mapvalidp1x (ptl_mapvalid_FOO));
11232 InstModule ms2_BAR (/*AUTOINST*/
11234 .ptl_mapvalidx (BAR_ptl_mapvalid),
11235 .ptl_mapvalidp1x (ptl_mapvalid_BAR));
11240 A template entry of the form
11242 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
11244 will apply an Emacs style regular expression search for any port beginning
11245 in pci_req followed by numbers and ending in _l and connecting that to
11246 the pci_req_jtag_[] net, with the bus subscript coming from what matches
11247 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
11249 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
11250 does the same thing. (Note a @ in the connection/replacement text is
11251 completely different -- still use \\1 there!) Thus this is the same as
11252 the above template:
11254 .pci_req@_l (pci_req_jtag_[\\1]),
11256 Here's another example to remove the _l, useful when naming conventions
11257 specify _ alone to mean active low. Note the use of [] to keep the bus
11260 .\\(.*\\)_l (\\1_[]),
11264 First any regular expression template is expanded.
11266 If the syntax @\"( ... )\" is found in a connection, the expression in
11267 quotes will be evaluated as a Lisp expression, with @ replaced by the
11268 instantiation number. The MAPVALIDP1X example above would put @+1 modulo
11269 4 into the brackets. Quote all double-quotes inside the expression with
11270 a leading backslash (\\\"...\\\"); or if the Lisp template is also a
11271 regexp template backslash the backslash quote (\\\\\"...\\\\\").
11273 There are special variables defined that are useful in these
11276 vl-name Name portion of the input/output port.
11277 vl-bits Bus bits portion of the input/output port ('[2:0]').
11278 vl-mbits Multidimensional array bits for port ('[2:0][3:0]').
11279 vl-width Width of the input/output port ('3' for [2:0]).
11280 May be a (...) expression if bits isn't a constant.
11281 vl-dir Direction of the pin input/output/inout/interface.
11282 vl-modport The modport, if an interface with a modport.
11283 vl-cell-type Module name/type of the cell ('InstModule').
11284 vl-cell-name Instance name of the cell ('instName').
11286 Normal Lisp variables may be used in expressions. See
11287 `verilog-read-defines' which can set vh-{definename} variables for use
11288 here. Also, any comments of the form:
11290 /*AUTO_LISP(setq foo 1)*/
11292 will evaluate any Lisp expression inside the parenthesis between the
11293 beginning of the buffer and the point of the AUTOINST. This allows
11294 functions to be defined or variables to be changed between instantiations.
11295 (See also `verilog-auto-insert-lisp' if you want the output from your
11296 lisp function to be inserted.)
11298 Note that when using lisp expressions errors may occur when @ is not a
11299 number; you may need to use the standard Emacs Lisp functions
11300 `number-to-string' and `string-to-number'.
11302 After the evaluation is completed, @ substitution and [] substitution
11305 For more information see the \\[verilog-faq] and forums at URL
11306 `http://www.veripool.org'."
11309 (let* ((pt (point))
11310 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
11311 (indent-pt (save-excursion (verilog-backward-open-paren)
11312 (1+ (current-column))))
11313 (verilog-auto-inst-column (max verilog-auto-inst-column
11314 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11315 (modi (verilog-modi-current))
11316 (moddecls (verilog-modi-get-decls modi))
11317 (vector-skip-list (unless verilog-auto-inst-vector
11318 (verilog-decls-get-signals moddecls)))
11319 submod submodi submoddecls
11320 inst skip-pins tpl-list tpl-num did-first par-values)
11322 ;; Find module name that is instantiated
11323 (setq submod (verilog-read-inst-module)
11324 inst (verilog-read-inst-name)
11325 vl-cell-type submod
11327 skip-pins (aref (verilog-read-inst-pins) 0))
11329 ;; Parse any AUTO_LISP() before here
11330 (verilog-read-auto-lisp (point-min) pt)
11332 ;; Read parameters (after AUTO_LISP)
11333 (setq par-values (and verilog-auto-inst-param-value
11334 (verilog-read-inst-param-value)))
11336 ;; Lookup position, etc of submodule
11337 ;; Note this may raise an error
11338 (when (and (not (member submod verilog-gate-keywords))
11339 (setq submodi (verilog-modi-lookup submod t)))
11340 (setq submoddecls (verilog-modi-get-decls submodi))
11341 ;; If there's a number in the instantiation, it may be an argument to the
11342 ;; automatic variable instantiation program.
11343 (let* ((tpl-info (verilog-read-auto-template submod))
11344 (tpl-regexp (aref tpl-info 0)))
11345 (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
11346 (match-string 1 inst)
11348 tpl-list (aref tpl-info 1)))
11349 ;; Find submodule's signals and dump
11350 (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
11351 (verilog-signals-not-in
11352 (verilog-decls-get-vars submoddecls)
11354 (vl-dir "interfaced"))
11355 (when (and sig-list
11356 verilog-auto-inst-interfaced-ports)
11357 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11358 ;; Note these are searched for in verilog-read-sub-decls.
11359 (verilog-insert-indent "// Interfaced\n")
11360 (verilog-auto-inst-port-list sig-list indent-pt
11361 tpl-list tpl-num for-star par-values)))
11362 (let ((sig-list (verilog-signals-not-in
11363 (verilog-decls-get-interfaces submoddecls)
11365 (vl-dir "interface"))
11367 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11368 ;; Note these are searched for in verilog-read-sub-decls.
11369 (verilog-insert-indent "// Interfaces\n")
11370 (verilog-auto-inst-port-list sig-list indent-pt
11371 tpl-list tpl-num for-star par-values)))
11372 (let ((sig-list (verilog-signals-not-in
11373 (verilog-decls-get-outputs submoddecls)
11377 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11378 (verilog-insert-indent "// Outputs\n")
11379 (verilog-auto-inst-port-list sig-list indent-pt
11380 tpl-list tpl-num for-star par-values)))
11381 (let ((sig-list (verilog-signals-not-in
11382 (verilog-decls-get-inouts submoddecls)
11386 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11387 (verilog-insert-indent "// Inouts\n")
11388 (verilog-auto-inst-port-list sig-list indent-pt
11389 tpl-list tpl-num for-star par-values)))
11390 (let ((sig-list (verilog-signals-not-in
11391 (verilog-decls-get-inputs submoddecls)
11395 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11396 (verilog-insert-indent "// Inputs\n")
11397 (verilog-auto-inst-port-list sig-list indent-pt
11398 tpl-list tpl-num for-star par-values)))
11402 (re-search-backward "," pt t)
11405 (search-forward "\n") ;; Added by inst-port
11407 (if (search-forward ")" nil t) ;; From user, moved up a line
11409 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it
11410 (delete-char -1)))))))))
11412 (defun verilog-auto-inst-param ()
11413 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
11414 Replace the parameter connections to an instantiation with ones
11415 automatically derived from the module header of the instantiated netlist.
11417 See \\[verilog-auto-inst] for limitations, and templates to customize the
11420 For example, first take the submodule InstModule.v:
11422 module InstModule (o,i);
11426 This is then used in an upper level module:
11428 module ExampInst (o,i);
11430 InstModule #(/*AUTOINSTPARAM*/)
11431 instName (/*AUTOINST*/);
11434 Typing \\[verilog-auto] will make this into:
11436 module ExampInst (o,i);
11439 InstModule #(/*AUTOINSTPARAM*/
11442 instName (/*AUTOINST*/);
11445 Where the list of parameter connections come from the inst module.
11449 You can customize the parameter connections using AUTO_TEMPLATEs,
11450 just as you would with \\[verilog-auto-inst]."
11453 (let* ((pt (point))
11454 (indent-pt (save-excursion (verilog-backward-open-paren)
11455 (1+ (current-column))))
11456 (verilog-auto-inst-column (max verilog-auto-inst-column
11457 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11458 (modi (verilog-modi-current))
11459 (moddecls (verilog-modi-get-decls modi))
11460 (vector-skip-list (unless verilog-auto-inst-vector
11461 (verilog-decls-get-signals moddecls)))
11462 submod submodi submoddecls
11463 inst skip-pins tpl-list tpl-num did-first)
11464 ;; Find module name that is instantiated
11465 (setq submod (save-excursion
11466 ;; Get to the point where AUTOINST normally is to read the module
11467 (verilog-re-search-forward-quick "[(;]" nil nil)
11468 (verilog-read-inst-module))
11469 inst (save-excursion
11470 ;; Get to the point where AUTOINST normally is to read the module
11471 (verilog-re-search-forward-quick "[(;]" nil nil)
11472 (verilog-read-inst-name))
11473 vl-cell-type submod
11475 skip-pins (aref (verilog-read-inst-pins) 0))
11477 ;; Parse any AUTO_LISP() before here
11478 (verilog-read-auto-lisp (point-min) pt)
11480 ;; Lookup position, etc of submodule
11481 ;; Note this may raise an error
11482 (when (setq submodi (verilog-modi-lookup submod t))
11483 (setq submoddecls (verilog-modi-get-decls submodi))
11484 ;; If there's a number in the instantiation, it may be an argument to the
11485 ;; automatic variable instantiation program.
11486 (let* ((tpl-info (verilog-read-auto-template submod))
11487 (tpl-regexp (aref tpl-info 0)))
11488 (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
11489 (match-string 1 inst)
11491 tpl-list (aref tpl-info 1)))
11492 ;; Find submodule's signals and dump
11493 (let ((sig-list (verilog-signals-not-in
11494 (verilog-decls-get-gparams submoddecls)
11496 (vl-dir "parameter"))
11498 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11499 ;; Note these are searched for in verilog-read-sub-decls.
11500 (verilog-insert-indent "// Parameters\n")
11501 (verilog-auto-inst-port-list sig-list indent-pt
11502 tpl-list tpl-num nil nil)))
11506 (re-search-backward "," pt t)
11509 (search-forward "\n") ;; Added by inst-port
11511 (if (search-forward ")" nil t) ;; From user, moved up a line
11512 (delete-char -1)))))))))
11514 (defun verilog-auto-reg ()
11515 "Expand AUTOREG statements, as part of \\[verilog-auto].
11516 Make reg statements for any output that isn't already declared,
11517 and isn't a wire output from a block. `verilog-auto-wire-type'
11518 may be used to change the datatype of the declarations.
11521 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11523 This does NOT work on memories, declare those yourself.
11527 module ExampReg (o,i);
11534 Typing \\[verilog-auto] will make this into:
11536 module ExampReg (o,i);
11540 // Beginning of automatic regs (for this module's undeclared outputs)
11542 // End of automatics
11546 ;; Point must be at insertion point.
11547 (let* ((indent-pt (current-indentation))
11548 (modi (verilog-modi-current))
11549 (moddecls (verilog-modi-get-decls modi))
11550 (modsubdecls (verilog-modi-get-sub-decls modi))
11551 (sig-list (verilog-signals-not-in
11552 (verilog-decls-get-outputs moddecls)
11553 (append (verilog-signals-with ;; ignore typed signals
11555 (verilog-decls-get-outputs moddecls))
11556 (verilog-decls-get-vars moddecls)
11557 (verilog-decls-get-assigns moddecls)
11558 (verilog-decls-get-consts moddecls)
11559 (verilog-decls-get-gparams moddecls)
11560 (verilog-subdecls-get-interfaced modsubdecls)
11561 (verilog-subdecls-get-outputs modsubdecls)
11562 (verilog-subdecls-get-inouts modsubdecls)))))
11564 (verilog-forward-or-insert-line)
11565 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
11566 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
11567 (verilog-insert-indent "// End of automatics\n")))))
11569 (defun verilog-auto-reg-input ()
11570 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
11571 Make reg statements instantiation inputs that aren't already declared.
11572 This is useful for making a top level shell for testing the module that is
11573 to be instantiated.
11576 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
11578 This does NOT work on memories, declare those yourself.
11580 An example (see `verilog-auto-inst' for what else is going on here):
11582 module ExampRegInput (o,i);
11586 InstModule instName
11590 Typing \\[verilog-auto] will make this into:
11592 module ExampRegInput (o,i);
11596 // Beginning of automatic reg inputs (for undeclared ...
11597 reg [31:0] iv; // From inst of inst.v
11598 // End of automatics
11599 InstModule instName
11607 ;; Point must be at insertion point.
11608 (let* ((indent-pt (current-indentation))
11609 (modi (verilog-modi-current))
11610 (moddecls (verilog-modi-get-decls modi))
11611 (modsubdecls (verilog-modi-get-sub-decls modi))
11612 (sig-list (verilog-signals-combine-bus
11613 (verilog-signals-not-in
11614 (append (verilog-subdecls-get-inputs modsubdecls)
11615 (verilog-subdecls-get-inouts modsubdecls))
11616 (append (verilog-decls-get-signals moddecls)
11617 (verilog-decls-get-assigns moddecls))))))
11619 (verilog-forward-or-insert-line)
11620 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
11621 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
11622 (verilog-insert-indent "// End of automatics\n")))))
11624 (defun verilog-auto-logic-setup ()
11625 "Prepare variables due to AUTOLOGIC."
11626 (unless verilog-auto-wire-type
11627 (set (make-local-variable 'verilog-auto-wire-type)
11630 (defun verilog-auto-logic ()
11631 "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
11632 Make wire statements using the SystemVerilog logic keyword.
11633 This is currently equivalent to:
11637 with the below at the bottom of the file
11639 // Local Variables:
11640 // verilog-auto-logic-type:\"logic\"
11643 In the future AUTOLOGIC may declare additional identifiers,
11644 while AUTOWIRE will not."
11646 (verilog-auto-logic-setup)
11647 (verilog-auto-wire)))
11649 (defun verilog-auto-wire ()
11650 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
11651 Make wire statements for instantiations outputs that aren't
11652 already declared. `verilog-auto-wire-type' may be used to change
11653 the datatype of the declarations.
11656 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
11657 and all buses must have widths, such as those from AUTOINST, or using []
11660 This does NOT work on memories or SystemVerilog .name connections,
11661 declare those yourself.
11663 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
11664 determine how to bus together. This occurs when you have ports with
11665 non-numeric or non-sequential bus subscripts. If Verilog mode
11666 mis-guessed, you'll have to declare them yourself.
11668 An example (see `verilog-auto-inst' for what else is going on here):
11670 module ExampWire (o,i);
11674 InstModule instName
11678 Typing \\[verilog-auto] will make this into:
11680 module ExampWire (o,i);
11684 // Beginning of automatic wires
11685 wire [31:0] ov; // From inst of inst.v
11686 // End of automatics
11687 InstModule instName
11696 ;; Point must be at insertion point.
11697 (let* ((indent-pt (current-indentation))
11698 (modi (verilog-modi-current))
11699 (moddecls (verilog-modi-get-decls modi))
11700 (modsubdecls (verilog-modi-get-sub-decls modi))
11701 (sig-list (verilog-signals-combine-bus
11702 (verilog-signals-not-in
11703 (append (verilog-subdecls-get-outputs modsubdecls)
11704 (verilog-subdecls-get-inouts modsubdecls))
11705 (verilog-decls-get-signals moddecls)))))
11707 (verilog-forward-or-insert-line)
11708 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
11709 (verilog-insert-definition modi sig-list "wire" indent-pt nil)
11710 (verilog-insert-indent "// End of automatics\n")
11711 ;; We used to optionally call verilog-pretty-declarations and
11712 ;; verilog-pretty-expr here, but it's too slow on huge modules,
11713 ;; plus makes everyone's module change. Finally those call
11714 ;; syntax-ppss which is broken when change hooks are disabled.
11717 (defun verilog-auto-output ()
11718 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
11719 Make output statements for any output signal from an /*AUTOINST*/ that
11720 isn't an input to another AUTOINST. This is useful for modules which
11721 only instantiate other modules.
11724 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11726 If placed inside the parenthesis of a module declaration, it creates
11727 Verilog 2001 style, else uses Verilog 1995 style.
11729 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11730 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11732 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11734 Signals matching `verilog-auto-output-ignore-regexp' are not included.
11736 An example (see `verilog-auto-inst' for what else is going on here):
11738 module ExampOutput (ov,i);
11741 InstModule instName
11745 Typing \\[verilog-auto] will make this into:
11747 module ExampOutput (ov,i);
11750 // Beginning of automatic outputs (from unused autoinst outputs)
11751 output [31:0] ov; // From inst of inst.v
11752 // End of automatics
11753 InstModule instName
11761 You may also provide an optional regular expression, in which case only
11762 signals matching the regular expression will be included. For example the
11763 same expansion will result from only extracting outputs starting with ov:
11765 /*AUTOOUTPUT(\"^ov\")*/"
11767 ;; Point must be at insertion point.
11768 (let* ((indent-pt (current-indentation))
11769 (params (verilog-read-auto-params 0 1))
11770 (regexp (nth 0 params))
11771 (v2k (verilog-in-paren-quick))
11772 (modi (verilog-modi-current))
11773 (moddecls (verilog-modi-get-decls modi))
11774 (modsubdecls (verilog-modi-get-sub-decls modi))
11775 (sig-list (verilog-signals-not-in
11776 (verilog-subdecls-get-outputs modsubdecls)
11777 (append (verilog-decls-get-outputs moddecls)
11778 (verilog-decls-get-inouts moddecls)
11779 (verilog-decls-get-inputs moddecls)
11780 (verilog-subdecls-get-inputs modsubdecls)
11781 (verilog-subdecls-get-inouts modsubdecls)))))
11783 (setq sig-list (verilog-signals-matching-regexp
11785 (setq sig-list (verilog-signals-not-matching-regexp
11786 sig-list verilog-auto-output-ignore-regexp))
11787 (verilog-forward-or-insert-line)
11788 (when v2k (verilog-repair-open-comma))
11790 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
11791 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
11792 (verilog-insert-indent "// End of automatics\n"))
11793 (when v2k (verilog-repair-close-comma)))))
11795 (defun verilog-auto-output-every ()
11796 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
11797 Make output statements for any signals that aren't primary inputs or
11798 outputs already. This makes every signal in the design an output. This is
11799 useful to get Synopsys to preserve every signal in the design, since it
11800 won't optimize away the outputs.
11804 module ExampOutputEvery (o,i,tempa,tempb);
11807 /*AUTOOUTPUTEVERY*/
11809 wire tempb = tempa;
11813 Typing \\[verilog-auto] will make this into:
11815 module ExampOutputEvery (o,i,tempa,tempb);
11818 /*AUTOOUTPUTEVERY*/
11819 // Beginning of automatic outputs (every signal)
11822 // End of automatics
11824 wire tempb = tempa;
11828 You may also provide an optional regular expression, in which case only
11829 signals matching the regular expression will be included. For example the
11830 same expansion will result from only extracting outputs starting with ov:
11832 /*AUTOOUTPUTEVERY(\"^ov\")*/"
11834 ;;Point must be at insertion point
11835 (let* ((indent-pt (current-indentation))
11836 (params (verilog-read-auto-params 0 1))
11837 (regexp (nth 0 params))
11838 (v2k (verilog-in-paren-quick))
11839 (modi (verilog-modi-current))
11840 (moddecls (verilog-modi-get-decls modi))
11841 (sig-list (verilog-signals-combine-bus
11842 (verilog-signals-not-in
11843 (verilog-decls-get-signals moddecls)
11844 (verilog-decls-get-ports moddecls)))))
11846 (setq sig-list (verilog-signals-matching-regexp
11848 (setq sig-list (verilog-signals-not-matching-regexp
11849 sig-list verilog-auto-output-ignore-regexp))
11850 (verilog-forward-or-insert-line)
11851 (when v2k (verilog-repair-open-comma))
11853 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
11854 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
11855 (verilog-insert-indent "// End of automatics\n"))
11856 (when v2k (verilog-repair-close-comma)))))
11858 (defun verilog-auto-input ()
11859 "Expand AUTOINPUT statements, as part of \\[verilog-auto].
11860 Make input statements for any input signal into an /*AUTOINST*/ that
11861 isn't declared elsewhere inside the module. This is useful for modules which
11862 only instantiate other modules.
11865 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11867 If placed inside the parenthesis of a module declaration, it creates
11868 Verilog 2001 style, else uses Verilog 1995 style.
11870 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11871 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11873 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11875 Signals matching `verilog-auto-input-ignore-regexp' are not included.
11877 An example (see `verilog-auto-inst' for what else is going on here):
11879 module ExampInput (ov,i);
11882 InstModule instName
11886 Typing \\[verilog-auto] will make this into:
11888 module ExampInput (ov,i);
11891 // Beginning of automatic inputs (from unused autoinst inputs)
11892 input i; // From inst of inst.v
11893 // End of automatics
11894 InstModule instName
11902 You may also provide an optional regular expression, in which case only
11903 signals matching the regular expression will be included. For example the
11904 same expansion will result from only extracting inputs starting with i:
11906 /*AUTOINPUT(\"^i\")*/"
11908 (let* ((indent-pt (current-indentation))
11909 (params (verilog-read-auto-params 0 1))
11910 (regexp (nth 0 params))
11911 (v2k (verilog-in-paren-quick))
11912 (modi (verilog-modi-current))
11913 (moddecls (verilog-modi-get-decls modi))
11914 (modsubdecls (verilog-modi-get-sub-decls modi))
11915 (sig-list (verilog-signals-not-in
11916 (verilog-subdecls-get-inputs modsubdecls)
11917 (append (verilog-decls-get-inputs moddecls)
11918 (verilog-decls-get-inouts moddecls)
11919 (verilog-decls-get-outputs moddecls)
11920 (verilog-decls-get-vars moddecls)
11921 (verilog-decls-get-consts moddecls)
11922 (verilog-decls-get-gparams moddecls)
11923 (verilog-subdecls-get-interfaced modsubdecls)
11924 (verilog-subdecls-get-outputs modsubdecls)
11925 (verilog-subdecls-get-inouts modsubdecls)))))
11927 (setq sig-list (verilog-signals-matching-regexp
11929 (setq sig-list (verilog-signals-not-matching-regexp
11930 sig-list verilog-auto-input-ignore-regexp))
11931 (verilog-forward-or-insert-line)
11932 (when v2k (verilog-repair-open-comma))
11934 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
11935 (verilog-insert-definition modi sig-list "input" indent-pt v2k)
11936 (verilog-insert-indent "// End of automatics\n"))
11937 (when v2k (verilog-repair-close-comma)))))
11939 (defun verilog-auto-inout ()
11940 "Expand AUTOINOUT statements, as part of \\[verilog-auto].
11941 Make inout statements for any inout signal in an /*AUTOINST*/ that
11942 isn't declared elsewhere inside the module.
11945 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11947 If placed inside the parenthesis of a module declaration, it creates
11948 Verilog 2001 style, else uses Verilog 1995 style.
11950 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11951 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11953 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11955 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
11957 An example (see `verilog-auto-inst' for what else is going on here):
11959 module ExampInout (ov,i);
11962 InstModule instName
11966 Typing \\[verilog-auto] will make this into:
11968 module ExampInout (ov,i);
11971 // Beginning of automatic inouts (from unused autoinst inouts)
11972 inout [31:0] ov; // From inst of inst.v
11973 // End of automatics
11974 InstModule instName
11982 You may also provide an optional regular expression, in which case only
11983 signals matching the regular expression will be included. For example the
11984 same expansion will result from only extracting inouts starting with i:
11986 /*AUTOINOUT(\"^i\")*/"
11988 ;; Point must be at insertion point.
11989 (let* ((indent-pt (current-indentation))
11990 (params (verilog-read-auto-params 0 1))
11991 (regexp (nth 0 params))
11992 (v2k (verilog-in-paren-quick))
11993 (modi (verilog-modi-current))
11994 (moddecls (verilog-modi-get-decls modi))
11995 (modsubdecls (verilog-modi-get-sub-decls modi))
11996 (sig-list (verilog-signals-not-in
11997 (verilog-subdecls-get-inouts modsubdecls)
11998 (append (verilog-decls-get-outputs moddecls)
11999 (verilog-decls-get-inouts moddecls)
12000 (verilog-decls-get-inputs moddecls)
12001 (verilog-subdecls-get-inputs modsubdecls)
12002 (verilog-subdecls-get-outputs modsubdecls)))))
12004 (setq sig-list (verilog-signals-matching-regexp
12006 (setq sig-list (verilog-signals-not-matching-regexp
12007 sig-list verilog-auto-inout-ignore-regexp))
12008 (verilog-forward-or-insert-line)
12009 (when v2k (verilog-repair-open-comma))
12011 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
12012 (verilog-insert-definition modi sig-list "inout" indent-pt v2k)
12013 (verilog-insert-indent "// End of automatics\n"))
12014 (when v2k (verilog-repair-close-comma)))))
12016 (defun verilog-auto-inout-module (&optional complement all-in)
12017 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
12018 Take input/output/inout statements from the specified module and insert
12019 into the current module. This is useful for making null templates and
12020 shell modules which need to have identical I/O with another module.
12021 Any I/O which are already defined in this module will not be redefined.
12022 For the complement of this function, see `verilog-auto-inout-comp',
12023 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12026 If placed inside the parenthesis of a module declaration, it creates
12027 Verilog 2001 style, else uses Verilog 1995 style.
12029 Concatenation and outputting partial buses is not supported.
12031 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12033 Signals are not inserted in the same order as in the original module,
12034 though they will appear to be in the same order to an AUTOINST
12035 instantiating either module.
12037 Signals declared as \"output reg\" or \"output wire\" etc will
12038 lose the wire/reg declaration so that shell modules may
12039 generate those outputs differently. However, \"output logic\"
12044 module ExampShell (/*AUTOARG*/);
12045 /*AUTOINOUTMODULE(\"ExampMain\")*/
12048 module ExampMain (i,o,io);
12054 Typing \\[verilog-auto] will make this into:
12056 module ExampShell (/*AUTOARG*/i,o,io);
12057 /*AUTOINOUTMODULE(\"ExampMain\")*/
12058 // Beginning of automatic in/out/inouts (from specific module)
12062 // End of automatics
12065 You may also provide an optional regular expression, in which case only
12066 signals matching the regular expression will be included. For example the
12067 same expansion will result from only extracting signals starting with i:
12069 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
12071 You may also provide an optional second regular expression, in
12072 which case only signals which have that pin direction and data
12073 type will be included. This matches against everything before
12074 the signal name in the declaration, for example against
12075 \"input\" (single bit), \"output logic\" (direction and type) or
12076 \"output [1:0]\" (direction and implicit type). You also
12077 probably want to skip spaces in your regexp.
12079 For example, the below will result in matching the output \"o\"
12080 against the previous example's module:
12082 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/"
12084 (let* ((params (verilog-read-auto-params 1 3))
12085 (submod (nth 0 params))
12086 (regexp (nth 1 params))
12087 (direction-re (nth 2 params))
12089 ;; Lookup position, etc of co-module
12090 ;; Note this may raise an error
12091 (when (setq submodi (verilog-modi-lookup submod t))
12092 (let* ((indent-pt (current-indentation))
12093 (v2k (verilog-in-paren-quick))
12094 (modi (verilog-modi-current))
12095 (moddecls (verilog-modi-get-decls modi))
12096 (submoddecls (verilog-modi-get-decls submodi))
12097 (sig-list-i (verilog-signals-not-in
12100 (verilog-decls-get-inputs submoddecls)
12101 (verilog-decls-get-inouts submoddecls)
12102 (verilog-decls-get-outputs submoddecls)))
12104 (verilog-decls-get-outputs submoddecls))
12105 (t (verilog-decls-get-inputs submoddecls)))
12106 (append (verilog-decls-get-inputs moddecls))))
12107 (sig-list-o (verilog-signals-not-in
12110 (verilog-decls-get-inputs submoddecls))
12111 (t (verilog-decls-get-outputs submoddecls)))
12112 (append (verilog-decls-get-outputs moddecls))))
12113 (sig-list-io (verilog-signals-not-in
12115 (t (verilog-decls-get-inouts submoddecls)))
12116 (append (verilog-decls-get-inouts moddecls))))
12117 (sig-list-if (verilog-signals-not-in
12118 (verilog-decls-get-interfaces submoddecls)
12119 (append (verilog-decls-get-interfaces moddecls)))))
12121 (setq sig-list-i (verilog-signals-edit-wire-reg
12122 (verilog-signals-matching-dir-re
12123 (verilog-signals-matching-regexp sig-list-i regexp)
12124 "input" direction-re))
12125 sig-list-o (verilog-signals-edit-wire-reg
12126 (verilog-signals-matching-dir-re
12127 (verilog-signals-matching-regexp sig-list-o regexp)
12128 "output" direction-re))
12129 sig-list-io (verilog-signals-edit-wire-reg
12130 (verilog-signals-matching-dir-re
12131 (verilog-signals-matching-regexp sig-list-io regexp)
12132 "inout" direction-re))
12133 sig-list-if (verilog-signals-matching-dir-re
12134 (verilog-signals-matching-regexp sig-list-if regexp)
12135 "interface" direction-re))
12136 (when v2k (verilog-repair-open-comma))
12137 (when (or sig-list-i sig-list-o sig-list-io sig-list-if)
12138 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
12139 ;; Don't sort them so an upper AUTOINST will match the main module
12140 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12141 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12142 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12143 (verilog-insert-definition modi sig-list-if "interface" indent-pt v2k t)
12144 (verilog-insert-indent "// End of automatics\n"))
12145 (when v2k (verilog-repair-close-comma)))))))
12147 (defun verilog-auto-inout-comp ()
12148 "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
12149 Take input/output/inout statements from the specified module and
12150 insert the inverse into the current module (inputs become outputs
12151 and vice-versa.) This is useful for making test and stimulus
12152 modules which need to have complementing I/O with another module.
12153 Any I/O which are already defined in this module will not be
12154 redefined. For the complement of this function, see
12155 `verilog-auto-inout-module'.
12158 If placed inside the parenthesis of a module declaration, it creates
12159 Verilog 2001 style, else uses Verilog 1995 style.
12161 Concatenation and outputting partial buses is not supported.
12163 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12165 Signals are not inserted in the same order as in the original module,
12166 though they will appear to be in the same order to an AUTOINST
12167 instantiating either module.
12171 module ExampShell (/*AUTOARG*/);
12172 /*AUTOINOUTCOMP(\"ExampMain\")*/
12175 module ExampMain (i,o,io);
12181 Typing \\[verilog-auto] will make this into:
12183 module ExampShell (/*AUTOARG*/i,o,io);
12184 /*AUTOINOUTCOMP(\"ExampMain\")*/
12185 // Beginning of automatic in/out/inouts (from specific module)
12189 // End of automatics
12192 You may also provide an optional regular expression, in which case only
12193 signals matching the regular expression will be included. For example the
12194 same expansion will result from only extracting signals starting with i:
12196 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
12197 (verilog-auto-inout-module t nil))
12199 (defun verilog-auto-inout-in ()
12200 "Expand AUTOINOUTIN statements, as part of \\[verilog-auto].
12201 Take input/output/inout statements from the specified module and
12202 insert them as all inputs into the current module. This is
12203 useful for making monitor modules which need to see all signals
12204 as inputs based on another module. Any I/O which are already
12205 defined in this module will not be redefined. See also
12206 `verilog-auto-inout-module'.
12209 If placed inside the parenthesis of a module declaration, it creates
12210 Verilog 2001 style, else uses Verilog 1995 style.
12212 Concatenation and outputting partial buses is not supported.
12214 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12216 Signals are not inserted in the same order as in the original module,
12217 though they will appear to be in the same order to an AUTOINST
12218 instantiating either module.
12222 module ExampShell (/*AUTOARG*/);
12223 /*AUTOINOUTIN(\"ExampMain\")*/
12226 module ExampMain (i,o,io);
12232 Typing \\[verilog-auto] will make this into:
12234 module ExampShell (/*AUTOARG*/i,o,io);
12235 /*AUTOINOUTIN(\"ExampMain\")*/
12236 // Beginning of automatic in/out/inouts (from specific module)
12240 // End of automatics
12243 You may also provide an optional regular expression, in which case only
12244 signals matching the regular expression will be included. For example the
12245 same expansion will result from only extracting signals starting with i:
12247 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
12248 (verilog-auto-inout-module nil t))
12250 (defun verilog-auto-inout-param ()
12251 "Expand AUTOINOUTPARAM statements, as part of \\[verilog-auto].
12252 Take input/output/inout statements from the specified module and insert
12253 into the current module. This is useful for making null templates and
12254 shell modules which need to have identical I/O with another module.
12255 Any I/O which are already defined in this module will not be redefined.
12256 For the complement of this function, see `verilog-auto-inout-comp',
12257 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12260 If placed inside the parenthesis of a module declaration, it creates
12261 Verilog 2001 style, else uses Verilog 1995 style.
12263 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12265 Parameters are inserted in the same order as in the original module.
12267 Parameters do not have values, which is SystemVerilog 2009 syntax.
12271 module ExampShell ();
12272 /*AUTOINOUTPARAM(\"ExampMain\")*/
12275 module ExampMain ();
12276 parameter PARAM = 22;
12279 Typing \\[verilog-auto] will make this into:
12281 module ExampShell (/*AUTOARG*/i,o,io);
12282 /*AUTOINOUTPARAM(\"ExampMain\")*/
12283 // Beginning of automatic parameters (from specific module)
12285 // End of automatics
12288 You may also provide an optional regular expression, in which case only
12289 parameters matching the regular expression will be included. For example the
12290 same expansion will result from only extracting parameters starting with i:
12292 /*AUTOINOUTPARAM(\"ExampMain\",\"^i\")*/"
12294 (let* ((params (verilog-read-auto-params 1 2))
12295 (submod (nth 0 params))
12296 (regexp (nth 1 params))
12298 ;; Lookup position, etc of co-module
12299 ;; Note this may raise an error
12300 (when (setq submodi (verilog-modi-lookup submod t))
12301 (let* ((indent-pt (current-indentation))
12302 (v2k (verilog-in-paren-quick))
12303 (modi (verilog-modi-current))
12304 (moddecls (verilog-modi-get-decls modi))
12305 (submoddecls (verilog-modi-get-decls submodi))
12306 (sig-list-p (verilog-signals-not-in
12307 (verilog-decls-get-gparams submoddecls)
12308 (append (verilog-decls-get-gparams moddecls)))))
12310 (setq sig-list-p (verilog-signals-matching-regexp sig-list-p regexp))
12311 (when v2k (verilog-repair-open-comma))
12313 (verilog-insert-indent "// Beginning of automatic parameters (from specific module)\n")
12314 ;; Don't sort them so an upper AUTOINST will match the main module
12315 (verilog-insert-definition modi sig-list-p "parameter" indent-pt v2k t)
12316 (verilog-insert-indent "// End of automatics\n"))
12317 (when v2k (verilog-repair-close-comma)))))))
12319 (defun verilog-auto-inout-modport ()
12320 "Expand AUTOINOUTMODPORT statements, as part of \\[verilog-auto].
12321 Take input/output/inout statements from the specified interface
12322 and modport and insert into the current module. This is useful
12323 for making verification modules that connect to UVM interfaces.
12325 The first parameter is the name of an interface.
12327 The second parameter is a regexp of modports to read from in
12330 The optional third parameter is a regular expression, and only
12331 signals matching the regular expression will be included.
12334 If placed inside the parenthesis of a module declaration, it creates
12335 Verilog 2001 style, else uses Verilog 1995 style.
12337 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
12339 As with other autos, any inputs/outputs declared in the module
12340 will suppress the AUTO from redeclaring an inputs/outputs by
12346 ( input logic clk );
12348 logic [7:0] req_dat;
12349 clocking mon_clkblk @(posedge clk);
12353 modport mp(clocking mon_clkblk);
12358 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12359 // Beginning of automatic in/out/inouts (from modport)
12360 input [7:0] req_dat,
12362 // End of automatics
12364 /*AUTOASSIGNMODPORT(\"ExampIf\" \"mp\")*/
12367 Typing \\[verilog-auto] will make this into:
12372 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12373 // Beginning of automatic in/out/inouts (from modport)
12376 // End of automatics
12379 If the modport is part of a UVM monitor/driver class, this
12380 creates a wrapper module that may be used to instantiate the
12381 driver/monitor using AUTOINST in the testbench."
12383 (let* ((params (verilog-read-auto-params 2 3))
12384 (submod (nth 0 params))
12385 (modport-re (nth 1 params))
12386 (regexp (nth 2 params))
12387 direction-re submodi) ;; direction argument not supported until requested
12388 ;; Lookup position, etc of co-module
12389 ;; Note this may raise an error
12390 (when (setq submodi (verilog-modi-lookup submod t))
12391 (let* ((indent-pt (current-indentation))
12392 (v2k (verilog-in-paren-quick))
12393 (modi (verilog-modi-current))
12394 (moddecls (verilog-modi-get-decls modi))
12395 (submoddecls (verilog-modi-get-decls submodi))
12396 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
12397 (sig-list-i (verilog-signals-in ;; Decls doesn't have data types, must resolve
12398 (verilog-decls-get-vars submoddecls)
12399 (verilog-signals-not-in
12400 (verilog-decls-get-inputs submodportdecls)
12401 (append (verilog-decls-get-ports submoddecls)
12402 (verilog-decls-get-ports moddecls)))))
12403 (sig-list-o (verilog-signals-in ;; Decls doesn't have data types, must resolve
12404 (verilog-decls-get-vars submoddecls)
12405 (verilog-signals-not-in
12406 (verilog-decls-get-outputs submodportdecls)
12407 (append (verilog-decls-get-ports submoddecls)
12408 (verilog-decls-get-ports moddecls)))))
12409 (sig-list-io (verilog-signals-in ;; Decls doesn't have data types, must resolve
12410 (verilog-decls-get-vars submoddecls)
12411 (verilog-signals-not-in
12412 (verilog-decls-get-inouts submodportdecls)
12413 (append (verilog-decls-get-ports submoddecls)
12414 (verilog-decls-get-ports moddecls))))))
12416 (setq sig-list-i (verilog-signals-edit-wire-reg
12417 (verilog-signals-matching-dir-re
12418 (verilog-signals-matching-regexp sig-list-i regexp)
12419 "input" direction-re))
12420 sig-list-o (verilog-signals-edit-wire-reg
12421 (verilog-signals-matching-dir-re
12422 (verilog-signals-matching-regexp sig-list-o regexp)
12423 "output" direction-re))
12424 sig-list-io (verilog-signals-edit-wire-reg
12425 (verilog-signals-matching-dir-re
12426 (verilog-signals-matching-regexp sig-list-io regexp)
12427 "inout" direction-re)))
12428 (when v2k (verilog-repair-open-comma))
12429 (when (or sig-list-i sig-list-o sig-list-io)
12430 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from modport)\n")
12431 ;; Don't sort them so an upper AUTOINST will match the main module
12432 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12433 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12434 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12435 (verilog-insert-indent "// End of automatics\n"))
12436 (when v2k (verilog-repair-close-comma)))))))
12438 (defun verilog-auto-insert-lisp ()
12439 "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
12440 The Lisp code provided is called before other AUTOS are expanded,
12441 and the Lisp code generally will call `insert` to insert text
12442 into the current file beginning on the line after the
12445 See also AUTOINSERTLAST and `verilog-auto-insert-last' which
12446 executes after (as opposed to before) other AUTOs.
12448 See also AUTO_LISP, which takes a Lisp expression and evaluates
12449 it during `verilog-auto-inst' but does not insert any text.
12453 module ExampInsertLisp;
12454 /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
12457 // For this example we declare the function in the
12458 // module's file itself. Often you'd define it instead
12459 // in a site-start.el or init file.
12463 (defun my-verilog-insert-hello (who)
12464 (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
12468 Typing \\[verilog-auto] will call my-verilog-insert-hello and
12469 expand the above into:
12471 // Beginning of automatic insert lisp
12472 initial $write(\"hello world\");
12473 // End of automatics
12475 You can also call an external program and insert the returned
12478 /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
12479 // Beginning of automatic insert lisp
12481 // End of automatics"
12483 ;; Point is at end of /*AUTO...*/
12484 (let* ((indent-pt (current-indentation))
12485 (cmd-end-pt (save-excursion (search-backward ")")
12487 (point))) ;; Closing paren
12488 (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
12489 (backward-sexp 1) ;; Inside comment
12490 (point))) ;; Beginning paren
12491 (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
12492 (verilog-forward-or-insert-line)
12493 ;; Some commands don't move point (like insert-file) so we always
12494 ;; add the begin/end comments, then delete it if not needed
12495 (verilog-insert-indent "// Beginning of automatic insert lisp\n")
12496 (verilog-insert-indent "// End of automatics\n")
12500 (setq verilog-scan-cache-tick nil) ;; Clear cache; inserted unknown text
12501 (verilog-delete-empty-auto-pair))))
12503 (defun verilog-auto-insert-last ()
12504 "Expand AUTOINSERTLAST statements, as part of \\[verilog-auto].
12505 The Lisp code provided is called after all other AUTOS have been
12506 expanded, and the Lisp code generally will call `insert` to
12507 insert text into the current file beginning on the line after the
12510 Other than when called (after AUTOs are expanded), the functionality
12511 is otherwise identical to AUTOINSERTLISP and `verilog-auto-insert-lisp' which
12512 executes before (as opposed to after) other AUTOs.
12514 See `verilog-auto-insert-lisp' for examples."
12515 (verilog-auto-insert-lisp))
12517 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
12518 "Return list of signals for current AUTOSENSE block."
12519 (let* ((sigss (verilog-read-always-signals))
12520 (sig-list (verilog-signals-not-params
12521 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
12522 (append (and (not verilog-auto-sense-include-inputs)
12523 (verilog-alw-get-outputs-delayed sigss))
12524 (and (not verilog-auto-sense-include-inputs)
12525 (verilog-alw-get-outputs-immediate sigss))
12526 (verilog-alw-get-temps sigss)
12527 (verilog-decls-get-consts moddecls)
12528 (verilog-decls-get-gparams moddecls)
12532 (defun verilog-auto-sense ()
12533 "Expand AUTOSENSE statements, as part of \\[verilog-auto].
12534 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
12535 with one automatically derived from all inputs declared in the always
12536 statement. Signals that are generated within the same always block are NOT
12537 placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
12538 Long lines are split based on the `fill-column', see \\[set-fill-column].
12541 Verilog does not allow memories (multidimensional arrays) in sensitivity
12542 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
12545 AUTOSENSE cannot always determine if a `define is a constant or a signal
12546 (it could be in an include file for example). If a `define or other signal
12547 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
12548 declaration anywhere in the module (parenthesis are required):
12550 /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */
12552 Better yet, use a parameter, which will be understood to be constant
12556 If AUTOSENSE makes a mistake, please report it. (First try putting
12557 a begin/end after your always!) As a workaround, if a signal that
12558 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
12559 If a signal should be in the sensitivity list wasn't, placing it before
12560 the /*AUTOSENSE*/ comment will prevent it from being deleted when the
12561 autos are updated (or added if it occurs there already).
12565 always @ (/*AS*/) begin
12566 /* AUTO_CONSTANT (`constant) */
12567 outin = ina | inb | `constant;
12571 Typing \\[verilog-auto] will make this into:
12573 always @ (/*AS*/ina or inb) begin
12574 /* AUTO_CONSTANT (`constant) */
12575 outin = ina | inb | `constant;
12579 Note in Verilog 2001, you can often get the same result from the new @*
12580 operator. (This was added to the language in part due to AUTOSENSE!)
12583 outin = ina | inb | `constant;
12588 (let* ((start-pt (save-excursion
12589 (verilog-re-search-backward-quick "(" nil t)
12591 (indent-pt (save-excursion
12592 (or (and (goto-char start-pt) (1+ (current-column)))
12593 (current-indentation))))
12594 (modi (verilog-modi-current))
12595 (moddecls (verilog-modi-get-decls modi))
12596 (sig-memories (verilog-signals-memory
12597 (verilog-decls-get-vars moddecls)))
12598 sig-list not-first presense-sigs)
12599 ;; Read signals in always, eliminate outputs from sense list
12600 (setq presense-sigs (verilog-signals-from-signame
12602 (verilog-read-signals start-pt (point)))))
12603 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
12605 (let ((tlen (length sig-list)))
12606 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
12607 (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
12608 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/"
12609 (save-excursion (goto-char (point))
12610 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
12611 (verilog-re-search-backward-quick "\\s-" start-pt t)
12612 (while (looking-at "\\s-`endif")
12613 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
12614 (verilog-re-search-backward-quick "\\s-" start-pt t))
12615 (not (looking-at "\\s-or\\b"))))
12616 (setq not-first t))
12617 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
12619 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
12621 (indent-to indent-pt)
12622 (if not-first (insert "or ")))
12623 (not-first (insert " or ")))
12624 (insert (verilog-sig-name (car sig-list)))
12625 (setq sig-list (cdr sig-list)
12628 (defun verilog-auto-reset ()
12629 "Expand AUTORESET statements, as part of \\[verilog-auto].
12630 Replace the /*AUTORESET*/ comment with code to initialize all
12631 registers set elsewhere in the always block.
12634 AUTORESET will not clear memories.
12636 AUTORESET uses <= if the signal has a <= assignment in the block,
12639 If <= is used, all = assigned variables are ignored if
12640 `verilog-auto-reset-blocking-in-non' is nil; they are presumed
12643 /*AUTORESET*/ presumes that any signals mentioned between the previous
12644 begin/case/if statement and the AUTORESET comment are being reset manually
12645 and should not be automatically reset. This includes omitting any signals
12646 used on the right hand side of assignments.
12648 By default, AUTORESET will include the width of the signal in the
12649 autos, SystemVerilog designs may want to change this. To control
12650 this behavior, see `verilog-auto-reset-widths'. In some cases
12651 AUTORESET must use a '0 assignment and it will print NOWIDTH; use
12652 `verilog-auto-reset-widths' unbased to prevent this.
12654 AUTORESET ties signals to deasserted, which is presumed to be zero.
12655 Signals that match `verilog-active-low-regexp' will be deasserted by tying
12658 AUTORESET may try to reset arrays or structures that cannot be
12659 reset by a simple assignment, resulting in compile errors. This
12660 is a feature to be taken as a hint that you need to reset these
12661 signals manually (or put them into a \"`ifdef NEVER signal<=`0;
12662 `endif\" so Verilog-Mode ignores them.)
12666 always @(posedge clk or negedge reset_l) begin
12667 if (!reset_l) begin
12678 Typing \\[verilog-auto] will make this into:
12680 always @(posedge core_clk or negedge reset_l) begin
12681 if (!reset_l) begin
12684 // Beginning of autoreset for uninitialized flops
12686 b = 0; // if `verilog-auto-reset-blocking-in-non' true
12687 // End of automatics
12699 (let* ((indent-pt (current-indentation))
12700 (modi (verilog-modi-current))
12701 (moddecls (verilog-modi-get-decls modi))
12702 (all-list (verilog-decls-get-signals moddecls))
12703 sigss sig-list dly-list prereset-sigs)
12704 ;; Read signals in always, eliminate outputs from reset list
12705 (setq prereset-sigs (verilog-signals-from-signame
12707 (verilog-read-signals
12709 (verilog-re-search-backward-quick "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t)
12713 (verilog-re-search-backward-quick "@" nil t)
12714 (setq sigss (verilog-read-always-signals)))
12715 (setq dly-list (verilog-alw-get-outputs-delayed sigss))
12716 (setq sig-list (verilog-signals-not-in (append
12717 (verilog-alw-get-outputs-delayed sigss)
12718 (when (or (not (verilog-alw-get-uses-delayed sigss))
12719 verilog-auto-reset-blocking-in-non)
12720 (verilog-alw-get-outputs-immediate sigss)))
12722 (verilog-alw-get-temps sigss)
12724 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
12727 (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
12729 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths
12731 (indent-to indent-pt)
12732 (insert (verilog-sig-name sig)
12733 (if (assoc (verilog-sig-name sig) dly-list)
12734 (concat " <= " verilog-assignment-delay)
12736 (verilog-sig-tieoff sig)
12738 (setq sig-list (cdr sig-list))))
12739 (verilog-insert-indent "// End of automatics")))))
12741 (defun verilog-auto-tieoff ()
12742 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
12743 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
12744 signals to deasserted.
12746 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
12747 input/output list as another module, but no internals. Specifically, it
12748 finds all outputs in the module, and if that input is not otherwise declared
12749 as a register or wire, creates a tieoff.
12751 AUTORESET ties signals to deasserted, which is presumed to be zero.
12752 Signals that match `verilog-active-low-regexp' will be deasserted by tying
12755 You can add signals you do not want included in AUTOTIEOFF with
12756 `verilog-auto-tieoff-ignore-regexp'.
12758 `verilog-auto-wire-type' may be used to change the datatype of
12761 `verilog-auto-reset-widths' may be used to change how the tieoff
12762 value's width is generated.
12764 An example of making a stub for another module:
12766 module ExampStub (/*AUTOINST*/);
12767 /*AUTOINOUTPARAM(\"Foo\")*/
12768 /*AUTOINOUTMODULE(\"Foo\")*/
12770 // verilator lint_off UNUSED
12771 wire _unused_ok = &{1'b0,
12774 // verilator lint_on UNUSED
12777 Typing \\[verilog-auto] will make this into:
12779 module ExampStub (/*AUTOINST*/...);
12780 /*AUTOINOUTPARAM(\"Foo\")*/
12781 /*AUTOINOUTMODULE(\"Foo\")*/
12782 // Beginning of autotieoff
12784 // End of automatics
12787 // Beginning of autotieoff
12788 wire [2:0] foo = 3'b0;
12789 // End of automatics
12795 (let* ((indent-pt (current-indentation))
12796 (modi (verilog-modi-current))
12797 (moddecls (verilog-modi-get-decls modi))
12798 (modsubdecls (verilog-modi-get-sub-decls modi))
12799 (sig-list (verilog-signals-not-in
12800 (verilog-decls-get-outputs moddecls)
12801 (append (verilog-decls-get-vars moddecls)
12802 (verilog-decls-get-assigns moddecls)
12803 (verilog-decls-get-consts moddecls)
12804 (verilog-decls-get-gparams moddecls)
12805 (verilog-subdecls-get-interfaced modsubdecls)
12806 (verilog-subdecls-get-outputs modsubdecls)
12807 (verilog-subdecls-get-inouts modsubdecls)))))
12808 (setq sig-list (verilog-signals-not-matching-regexp
12809 sig-list verilog-auto-tieoff-ignore-regexp))
12811 (verilog-forward-or-insert-line)
12812 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
12813 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
12814 (verilog-modi-cache-add-vars modi sig-list) ; Before we trash list
12816 (let ((sig (car sig-list)))
12817 (cond ((equal verilog-auto-tieoff-declaration "assign")
12818 (indent-to indent-pt)
12819 (insert "assign " (verilog-sig-name sig)))
12821 (verilog-insert-one-definition sig verilog-auto-tieoff-declaration indent-pt)))
12822 (indent-to (max 48 (+ indent-pt 40)))
12823 (insert "= " (verilog-sig-tieoff sig)
12825 (setq sig-list (cdr sig-list))))
12826 (verilog-insert-indent "// End of automatics\n")))))
12828 (defun verilog-auto-undef ()
12829 "Expand AUTOUNDEF statements, as part of \\[verilog-auto].
12830 Take any `defines since the last AUTOUNDEF in the current file
12831 and create `undefs for them. This is used to insure that
12832 file-local defines do not pollute the global `define name space.
12835 AUTOUNDEF presumes any identifier following `define is the
12836 name of a define. Any `ifdefs are ignored.
12838 AUTOUNDEF suppresses creating an `undef for any define that was
12839 `undefed before the AUTOUNDEF. This may be used to work around
12840 the ignoring of `ifdefs as shown below.
12849 `undef M_BAZ // Emacs will see this and not `undef M_BAZ
12854 Typing \\[verilog-auto] will make this into:
12858 // Beginning of automatic undefs
12861 // End of automatics
12863 You may also provide an optional regular expression, in which case only
12864 defines the regular expression will be undefed."
12866 (let* ((params (verilog-read-auto-params 0 1))
12867 (regexp (nth 0 params))
12868 (indent-pt (current-indentation))
12872 ;; Scan from start of file, or last AUTOUNDEF
12873 (or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
12874 (goto-char (point-min)))
12875 (while (verilog-re-search-forward-quick
12876 "`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
12877 (cond ((equal (match-string-no-properties 1) "define")
12878 (setq def (match-string-no-properties 2))
12879 (when (and (or (not regexp)
12880 (string-match regexp def))
12881 (not (member def defs))) ;; delete-dups not in 21.1
12882 (setq defs (cons def defs))))
12884 (setq defs (delete (match-string-no-properties 2) defs))))))
12886 (setq defs (sort defs 'string<))
12888 (verilog-forward-or-insert-line)
12889 (verilog-insert-indent "// Beginning of automatic undefs\n")
12891 (verilog-insert-indent "`undef " (car defs) "\n")
12892 (setq defs (cdr defs)))
12893 (verilog-insert-indent "// End of automatics\n")))))
12895 (defun verilog-auto-unused ()
12896 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
12897 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
12898 input and inout signals.
12900 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
12901 input/output list as another module, but no internals. Specifically, it
12902 finds all inputs and inouts in the module, and if that input is not otherwise
12903 used, adds it to a comma separated list.
12905 The comma separated list is intended to be used to create a _unused_ok
12906 signal. Using the exact name \"_unused_ok\" for name of the temporary
12907 signal is recommended as it will insure maximum forward compatibility, it
12908 also makes lint warnings easy to understand; ignore any unused warnings
12909 with \"unused\" in the signal name.
12911 To reduce simulation time, the _unused_ok signal should be forced to a
12912 constant to prevent wiggling. The easiest thing to do is use a
12913 reduction-and with 1'b0 as shown.
12915 This way all unused signals are in one place, making it convenient to add
12916 your tool's specific pragmas around the assignment to disable any unused
12919 You can add signals you do not want included in AUTOUNUSED with
12920 `verilog-auto-unused-ignore-regexp'.
12922 An example of making a stub for another module:
12924 module ExampStub (/*AUTOINST*/);
12925 /*AUTOINOUTPARAM(\"Examp\")*/
12926 /*AUTOINOUTMODULE(\"Examp\")*/
12928 // verilator lint_off UNUSED
12929 wire _unused_ok = &{1'b0,
12932 // verilator lint_on UNUSED
12935 Typing \\[verilog-auto] will make this into:
12938 // verilator lint_off UNUSED
12939 wire _unused_ok = &{1'b0,
12941 // Beginning of automatics
12945 // End of automatics
12947 // verilator lint_on UNUSED
12952 (let* ((indent-pt (progn (search-backward "/*") (current-column)))
12953 (modi (verilog-modi-current))
12954 (moddecls (verilog-modi-get-decls modi))
12955 (modsubdecls (verilog-modi-get-sub-decls modi))
12956 (sig-list (verilog-signals-not-in
12957 (append (verilog-decls-get-inputs moddecls)
12958 (verilog-decls-get-inouts moddecls))
12959 (append (verilog-subdecls-get-inputs modsubdecls)
12960 (verilog-subdecls-get-inouts modsubdecls)))))
12961 (setq sig-list (verilog-signals-not-matching-regexp
12962 sig-list verilog-auto-unused-ignore-regexp))
12964 (verilog-forward-or-insert-line)
12965 (verilog-insert-indent "// Beginning of automatic unused inputs\n")
12966 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
12968 (let ((sig (car sig-list)))
12969 (indent-to indent-pt)
12970 (insert (verilog-sig-name sig) ",\n")
12971 (setq sig-list (cdr sig-list))))
12972 (verilog-insert-indent "// End of automatics\n")))))
12974 (defun verilog-enum-ascii (signm elim-regexp)
12975 "Convert an enum name SIGNM to an ascii string for insertion.
12976 Remove user provided prefix ELIM-REGEXP."
12977 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
12978 (let ((case-fold-search t))
12979 ;; All upper becomes all lower for readability
12980 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
12982 (defun verilog-auto-ascii-enum ()
12983 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
12984 Create a register to contain the ASCII decode of an enumerated signal type.
12985 This will allow trace viewers to show the ASCII name of states.
12987 First, parameters are built into an enumeration using the synopsys enum
12988 comment. The comment must be between the keyword and the symbol.
12989 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
12991 Next, registers which that enum applies to are also tagged with the same
12994 Finally, an AUTOASCIIENUM command is used.
12996 The first parameter is the name of the signal to be decoded.
12998 The second parameter is the name to store the ASCII code into. For the
12999 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
13000 a signal that is just for simulation, and the magic characters _ascii
13001 tell viewers like Dinotrace to display in ASCII format.
13003 The third optional parameter is a string which will be removed
13004 from the state names. It defaults to \"\" which removes nothing.
13006 The fourth optional parameter is \"onehot\" to force one-hot
13007 decoding. If unspecified, if and only if the first parameter
13008 width is 2^(number of states in enum) and does NOT match the
13009 width of the enum, the signal is assumed to be a one-hot
13010 decode. Otherwise, it's a normal encoded state vector.
13012 `verilog-auto-wire-type' may be used to change the datatype of
13015 \"auto enum\" may be used in place of \"synopsys enum\".
13019 //== State enumeration
13020 parameter [2:0] // synopsys enum state_info
13024 //== State variables
13025 reg [2:0] /* synopsys enum state_info */
13026 state_r; /* synopsys state_vector state_r */
13027 reg [2:0] /* synopsys enum state_info */
13030 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
13032 Typing \\[verilog-auto] will make this into:
13034 ... same front matter ...
13036 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
13037 // Beginning of automatic ASCII enum decoding
13038 reg [39:0] state_ascii_r; // Decode of state_r
13039 always @(state_r) begin
13041 SM_IDLE: state_ascii_r = \"idle \";
13042 SM_SEND: state_ascii_r = \"send \";
13043 SM_WAIT1: state_ascii_r = \"wait1\";
13044 default: state_ascii_r = \"%Erro\";
13047 // End of automatics"
13049 (let* ((params (verilog-read-auto-params 2 4))
13050 (undecode-name (nth 0 params))
13051 (ascii-name (nth 1 params))
13052 (elim-regexp (and (nth 2 params)
13053 (not (equal (nth 2 params) ""))
13055 (one-hot-flag (nth 3 params))
13057 (indent-pt (current-indentation))
13058 (modi (verilog-modi-current))
13059 (moddecls (verilog-modi-get-decls modi))
13061 (sig-list-consts (append (verilog-decls-get-consts moddecls)
13062 (verilog-decls-get-gparams moddecls)))
13063 (sig-list-all (verilog-decls-get-iovars moddecls))
13065 (undecode-sig (or (assoc undecode-name sig-list-all)
13066 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
13067 (undecode-enum (or (verilog-sig-enum undecode-sig)
13068 (error "%s: Signal %s does not have an enum tag" (verilog-point-text) undecode-name)))
13070 (enum-sigs (verilog-signals-not-in
13071 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
13072 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))
13076 (string-match "onehot" (or one-hot-flag ""))
13077 (and ;; width(enum) != width(sig)
13078 (or (not (verilog-sig-bits (car enum-sigs)))
13079 (not (equal (verilog-sig-width (car enum-sigs))
13080 (verilog-sig-width undecode-sig))))
13081 ;; count(enums) == width(sig)
13082 (equal (number-to-string (length enum-sigs))
13083 (verilog-sig-width undecode-sig)))))
13087 ;; Find number of ascii chars needed
13088 (let ((tmp-sigs enum-sigs))
13090 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
13091 ascii-chars (max ascii-chars (length (verilog-enum-ascii
13092 (verilog-sig-name (car tmp-sigs))
13094 tmp-sigs (cdr tmp-sigs))))
13096 (verilog-forward-or-insert-line)
13097 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
13098 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
13099 (concat "Decode of " undecode-name) nil nil))))
13100 (verilog-insert-definition modi decode-sig-list "reg" indent-pt nil))
13102 (verilog-insert-indent "always @(" undecode-name ") begin\n")
13103 (setq indent-pt (+ indent-pt verilog-indent-level))
13104 (verilog-insert-indent "case ({" undecode-name "})\n")
13105 (setq indent-pt (+ indent-pt verilog-case-indent))
13107 (let ((tmp-sigs enum-sigs)
13108 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
13109 (+ (if one-hot 9 1) (max 8 enum-chars))
13110 ascii-name ascii-chars))
13111 (errname (substring "%Error" 0 (min 6 ascii-chars))))
13113 (verilog-insert-indent
13116 (concat (if one-hot "(")
13117 ;; Use enum-sigs length as that's numeric
13118 ;; verilog-sig-width undecode-sig might not be.
13119 (if one-hot (number-to-string (length enum-sigs)))
13120 ;; We use a shift instead of var[index]
13121 ;; so that a non-one hot value will show as error.
13122 (if one-hot "'b1<<")
13123 (verilog-sig-name (car tmp-sigs))
13124 (if one-hot ")") ":")
13125 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
13127 (setq tmp-sigs (cdr tmp-sigs)))
13128 (verilog-insert-indent (format chrfmt "default:" errname)))
13130 (setq indent-pt (- indent-pt verilog-case-indent))
13131 (verilog-insert-indent "endcase\n")
13132 (setq indent-pt (- indent-pt verilog-indent-level))
13133 (verilog-insert-indent "end\n"
13134 "// End of automatics\n"))))
13136 (defun verilog-auto-templated-rel ()
13137 "Replace Templated relative line numbers with absolute line numbers.
13138 Internal use only. This hacks around the line numbers in AUTOINST Templates
13139 being different from the final output's line numbering."
13140 (let ((templateno 0) (template-line (list 0)) (buf-line 1))
13141 ;; Find line number each template is on
13142 ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
13143 (goto-char (point-min))
13144 (while (not (eobp))
13145 (when (looking-at ".*AUTO_TEMPLATE")
13146 (setq templateno (1+ templateno))
13147 (setq template-line (cons buf-line template-line)))
13148 (setq buf-line (1+ buf-line))
13150 (setq template-line (nreverse template-line))
13151 ;; Replace T# L# with absolute line number
13152 (goto-char (point-min))
13153 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
13155 (concat " Templated "
13156 (int-to-string (+ (nth (string-to-number (match-string 1))
13158 (string-to-number (match-string 2)))))
13161 (defun verilog-auto-template-lint ()
13162 "Check AUTO_TEMPLATEs for unused lines.
13163 Enable with `verilog-auto-template-warn-unused'."
13164 (let ((name1 (or (buffer-file-name) (buffer-name))))
13166 (goto-char (point-min))
13167 (while (re-search-forward
13168 "^\\s-*/?\\*?\\s-*[a-zA-Z0-9`_$]+\\s-+AUTO_TEMPLATE" nil t)
13169 (let* ((tpl-info (verilog-read-auto-template-middle))
13170 (tpl-list (aref tpl-info 1))
13171 (tlines (append (nth 0 tpl-list) (nth 1 tpl-list)))
13174 (setq tpl-ass (car tlines)
13175 tlines (cdr tlines))
13177 (unless (or (not (eval-when-compile (fboundp 'make-hash-table))) ;; Not supported, no warning
13178 (not verilog-auto-template-hits)
13179 (gethash (vector (nth 2 tpl-ass) (nth 3 tpl-ass))
13180 verilog-auto-template-hits))
13181 (verilog-warn-error "%s:%d: AUTO_TEMPLATE line unused: \".%s (%s)\""
13183 (+ (elt tpl-ass 3) ;; Template line number
13184 (count-lines (point-min) (point)))
13185 (elt tpl-ass 0) (elt tpl-ass 1))
13193 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing an arg
13194 "Expand AUTO statements.
13195 Look for any /*AUTO...*/ commands in the code, as used in
13196 instantiations or argument headers. Update the list of signals
13197 following the /*AUTO...*/ command.
13199 Use \\[verilog-delete-auto] to remove the AUTOs.
13201 Use \\[verilog-diff-auto] to see differences in AUTO expansion.
13203 Use \\[verilog-inject-auto] to insert AUTOs for the first time.
13205 Use \\[verilog-faq] for a pointer to frequently asked questions.
13207 For new users, we recommend setting `verilog-case-fold' to nil
13208 and `verilog-auto-arg-sort' to t.
13210 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
13211 called before and after this function, respectively.
13214 module ModuleName (/*AUTOARG*/);
13219 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
13221 You can also update the AUTOs from the shell using:
13222 emacs --batch <filenames.v> -f verilog-batch-auto
13223 Or fix indentation with:
13224 emacs --batch <filenames.v> -f verilog-batch-indent
13225 Likewise, you can delete or inject AUTOs with:
13226 emacs --batch <filenames.v> -f verilog-batch-delete-auto
13227 emacs --batch <filenames.v> -f verilog-batch-inject-auto
13228 Or check if AUTOs have the same expansion
13229 emacs --batch <filenames.v> -f verilog-batch-diff-auto
13231 Using \\[describe-function], see also:
13232 `verilog-auto-arg' for AUTOARG module instantiations
13233 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
13234 `verilog-auto-assign-modport' for AUTOASSIGNMODPORT assignment to/from modport
13235 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
13236 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
13237 `verilog-auto-inout-in' for AUTOINOUTIN inputs for all i/o
13238 `verilog-auto-inout-modport' for AUTOINOUTMODPORT i/o from an interface modport
13239 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
13240 `verilog-auto-inout-param' for AUTOINOUTPARAM copying params from elsewhere
13241 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
13242 `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
13243 `verilog-auto-insert-last' for AUTOINSERTLAST insert code from lisp function
13244 `verilog-auto-inst' for AUTOINST instantiation pins
13245 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
13246 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
13247 `verilog-auto-logic' for AUTOLOGIC declaring logic signals
13248 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
13249 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
13250 `verilog-auto-reg' for AUTOREG registers
13251 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
13252 `verilog-auto-reset' for AUTORESET flop resets
13253 `verilog-auto-sense' for AUTOSENSE or AS always sensitivity lists
13254 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
13255 `verilog-auto-undef' for AUTOUNDEF `undef of local `defines
13256 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
13257 `verilog-auto-wire' for AUTOWIRE instantiation wires
13259 `verilog-read-defines' for reading `define values
13260 `verilog-read-includes' for reading `includes
13262 If you have bugs with these autos, please file an issue at
13263 URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
13264 Wilson Snyder (wsnyder@wsnyder.org)."
13266 (unless noninteractive (message "Updating AUTOs..."))
13267 (if (fboundp 'dinotrace-unannotate-all)
13268 (dinotrace-unannotate-all))
13269 (verilog-save-font-mods
13270 (let ((oldbuf (if (not (buffer-modified-p))
13272 (case-fold-search verilog-case-fold)
13273 ;; Cache directories; we don't write new files, so can't change
13274 (verilog-dir-cache-preserving t)
13275 ;; Cache current module
13276 (verilog-modi-cache-current-enable t)
13277 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
13278 verilog-modi-cache-current)
13280 ;; Disable change hooks for speed
13281 ;; This let can't be part of above let; must restore
13282 ;; after-change-functions before font-lock resumes
13283 (verilog-save-no-change-functions
13284 (verilog-save-scan-cache
13286 ;; Wipe cache; otherwise if we AUTOed a block above this one,
13287 ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
13288 (setq verilog-modi-cache-list nil)
13290 (setq verilog-auto-template-hits nil)
13291 ;; If we're not in verilog-mode, change syntax table so parsing works right
13292 (unless (eq major-mode `verilog-mode) (verilog-mode))
13293 ;; Allow user to customize
13294 (verilog-run-hooks 'verilog-before-auto-hook)
13295 ;; Try to save the user from needing to revert-file to reread file local-variables
13296 (verilog-auto-reeval-locals)
13297 (verilog-read-auto-lisp-present)
13298 (verilog-read-auto-lisp (point-min) (point-max))
13299 (verilog-getopt-flags)
13300 ;; From here on out, we can cache anything we read from disk
13301 (verilog-preserve-dir-cache
13302 ;; These two may seem obvious to do always, but on large includes it can be way too slow
13303 (when verilog-auto-read-includes
13304 (verilog-read-includes)
13305 (verilog-read-defines nil nil t))
13306 ;; Setup variables due to SystemVerilog expansion
13307 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic-setup)
13308 ;; This particular ordering is important
13309 ;; INST: Lower modules correct, no internal dependencies, FIRST
13310 (verilog-preserve-modi-cache
13311 ;; Clear existing autos else we'll be screwed by existing ones
13312 (verilog-delete-auto)
13313 ;; Injection if appropriate
13315 (verilog-inject-inst)
13316 (verilog-inject-sense)
13317 (verilog-inject-arg))
13319 ;; Do user inserts first, so their code can insert AUTOs
13320 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
13321 'verilog-auto-insert-lisp)
13322 ;; Expand instances before need the signals the instances input/output
13323 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
13324 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
13325 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
13326 ;; Doesn't matter when done, but combine it with a common changer
13327 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
13328 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
13329 ;; Must be done before autoin/out as creates a reg
13330 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM(.*?)\\*/" 'verilog-auto-ascii-enum)
13332 ;; first in/outs from other files
13333 (verilog-auto-re-search-do "/\\*AUTOINOUTMODPORT(.*?)\\*/" 'verilog-auto-inout-modport)
13334 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE(.*?)\\*/" 'verilog-auto-inout-module)
13335 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP(.*?)\\*/" 'verilog-auto-inout-comp)
13336 (verilog-auto-re-search-do "/\\*AUTOINOUTIN(.*?)\\*/" 'verilog-auto-inout-in)
13337 (verilog-auto-re-search-do "/\\*AUTOINOUTPARAM(.*?)\\*/" 'verilog-auto-inout-param)
13338 ;; next in/outs which need previous sucked inputs first
13339 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((.*?)\\)?\\*/" 'verilog-auto-output)
13340 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((.*?)\\)?\\*/" 'verilog-auto-input)
13341 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((.*?)\\)?\\*/" 'verilog-auto-inout)
13342 ;; Then tie off those in/outs
13343 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
13344 ;; These can be anywhere after AUTOINSERTLISP
13345 (verilog-auto-re-search-do "/\\*AUTOUNDEF\\((.*?)\\)?\\*/" 'verilog-auto-undef)
13346 ;; Wires/regs must be after inputs/outputs
13347 (verilog-auto-re-search-do "/\\*AUTOASSIGNMODPORT(.*?)\\*/" 'verilog-auto-assign-modport)
13348 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
13349 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
13350 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
13351 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
13352 ;; outputevery needs AUTOOUTPUTs done first
13353 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\((.*?)\\)?\\*/" 'verilog-auto-output-every)
13354 ;; After we've created all new variables
13355 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
13356 ;; Must be after all inputs outputs are generated
13357 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
13359 (verilog-auto-re-search-do "/\\*AUTOINSERTLAST(.*?)\\*/" 'verilog-auto-insert-last)
13360 ;; Fix line numbers (comments only)
13361 (when verilog-auto-inst-template-numbers
13362 (verilog-auto-templated-rel))
13363 (when verilog-auto-template-warn-unused
13364 (verilog-auto-template-lint))))
13366 (verilog-run-hooks 'verilog-auto-hook)
13368 (when verilog-auto-delete-trailing-whitespace
13369 (verilog-delete-trailing-whitespace))
13371 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
13373 ;; If end result is same as when started, clear modified flag
13374 (cond ((and oldbuf (equal oldbuf (buffer-string)))
13375 (set-buffer-modified-p nil)
13376 (unless noninteractive (message "Updating AUTOs...done (no changes)")))
13377 (t (unless noninteractive (message "Updating AUTOs...done"))))
13378 ;; End of after-change protection
13381 ;; Currently handled in verilog-save-font-mods
13386 ;; Skeleton based code insertion
13388 (defvar verilog-template-map
13389 (let ((map (make-sparse-keymap)))
13390 (define-key map "a" 'verilog-sk-always)
13391 (define-key map "b" 'verilog-sk-begin)
13392 (define-key map "c" 'verilog-sk-case)
13393 (define-key map "f" 'verilog-sk-for)
13394 (define-key map "g" 'verilog-sk-generate)
13395 (define-key map "h" 'verilog-sk-header)
13396 (define-key map "i" 'verilog-sk-initial)
13397 (define-key map "j" 'verilog-sk-fork)
13398 (define-key map "m" 'verilog-sk-module)
13399 (define-key map "o" 'verilog-sk-ovm-class)
13400 (define-key map "p" 'verilog-sk-primitive)
13401 (define-key map "r" 'verilog-sk-repeat)
13402 (define-key map "s" 'verilog-sk-specify)
13403 (define-key map "t" 'verilog-sk-task)
13404 (define-key map "u" 'verilog-sk-uvm-object)
13405 (define-key map "w" 'verilog-sk-while)
13406 (define-key map "x" 'verilog-sk-casex)
13407 (define-key map "z" 'verilog-sk-casez)
13408 (define-key map "?" 'verilog-sk-if)
13409 (define-key map ":" 'verilog-sk-else-if)
13410 (define-key map "/" 'verilog-sk-comment)
13411 (define-key map "A" 'verilog-sk-assign)
13412 (define-key map "F" 'verilog-sk-function)
13413 (define-key map "I" 'verilog-sk-input)
13414 (define-key map "O" 'verilog-sk-output)
13415 (define-key map "S" 'verilog-sk-state-machine)
13416 (define-key map "=" 'verilog-sk-inout)
13417 (define-key map "U" 'verilog-sk-uvm-component)
13418 (define-key map "W" 'verilog-sk-wire)
13419 (define-key map "R" 'verilog-sk-reg)
13420 (define-key map "D" 'verilog-sk-define-signal)
13422 "Keymap used in Verilog mode for smart template operations.")
13426 ;; Place the templates into Verilog Mode. They may be inserted under any key.
13427 ;; C-c C-t will be the default. If you use templates a lot, you
13428 ;; may want to consider moving the binding to another key in your init
13431 ;; Note \C-c and letter are reserved for users
13432 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
13434 ;;; ---- statement skeletons ------------------------------------------
13436 (define-skeleton verilog-sk-prompt-condition
13437 "Prompt for the loop condition."
13438 "[condition]: " str )
13440 (define-skeleton verilog-sk-prompt-init
13441 "Prompt for the loop init statement."
13442 "[initial statement]: " str )
13444 (define-skeleton verilog-sk-prompt-inc
13445 "Prompt for the loop increment statement."
13446 "[increment statement]: " str )
13448 (define-skeleton verilog-sk-prompt-name
13449 "Prompt for the name of something."
13452 (define-skeleton verilog-sk-prompt-clock
13453 "Prompt for the name of something."
13454 "name and edge of clock(s): " str)
13456 (defvar verilog-sk-reset nil)
13457 (defun verilog-sk-prompt-reset ()
13458 "Prompt for the name of a state machine reset."
13459 (setq verilog-sk-reset (read-string "name of reset: " "rst")))
13462 (define-skeleton verilog-sk-prompt-state-selector
13463 "Prompt for the name of a state machine selector."
13464 "name of selector (eg {a,b,c,d}): " str )
13466 (define-skeleton verilog-sk-prompt-output
13467 "Prompt for the name of something."
13470 (define-skeleton verilog-sk-prompt-msb
13471 "Prompt for most significant bit specification."
13472 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
13474 (define-skeleton verilog-sk-prompt-lsb
13475 "Prompt for least significant bit specification."
13478 (defvar verilog-sk-p nil)
13479 (define-skeleton verilog-sk-prompt-width
13480 "Prompt for a width specification."
13483 (setq verilog-sk-p (point))
13484 (verilog-sk-prompt-msb)
13485 (if (> (point) verilog-sk-p) "] " " ")))
13487 (defun verilog-sk-header ()
13488 "Insert a descriptive header at the top of the file.
13489 See also `verilog-header' for an alternative format."
13492 (goto-char (point-min))
13493 (verilog-sk-header-tmpl)))
13495 (define-skeleton verilog-sk-header-tmpl
13496 "Insert a comment block containing the module title, author, etc."
13498 "// -*- Mode: Verilog -*-"
13499 "\n// Filename : " (buffer-name)
13500 "\n// Description : " str
13501 "\n// Author : " (user-full-name)
13502 "\n// Created On : " (current-time-string)
13503 "\n// Last Modified By: " (user-full-name)
13504 "\n// Last Modified On: " (current-time-string)
13505 "\n// Update Count : 0"
13506 "\n// Status : Unknown, Use with caution!"
13509 (define-skeleton verilog-sk-module
13510 "Insert a module definition."
13512 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
13514 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
13516 ;;; ------------------------------------------------------------------------
13517 ;;; Define a default OVM class, with macros and new()
13518 ;;; ------------------------------------------------------------------------
13520 (define-skeleton verilog-sk-ovm-class
13521 "Insert a class definition"
13523 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
13525 > "`ovm_object_utils_begin(" name ")" \n
13526 > (- verilog-indent-level) " `ovm_object_utils_end" \n
13528 > "function new(string name=\"" name "\");" \n
13529 > "super.new(name);" \n
13530 > (- verilog-indent-level) "endfunction" \n
13532 > "endclass" (progn (electric-verilog-terminate-line) nil))
13534 (define-skeleton verilog-sk-uvm-object
13535 "Insert a class definition"
13537 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
13539 > "`uvm_object_utils_begin(" name ")" \n
13540 > (- verilog-indent-level) "`uvm_object_utils_end" \n
13542 > "function new(string name=\"" name "\");" \n
13543 > "super.new(name);" \n
13544 > (- verilog-indent-level) "endfunction" \n
13546 > "endclass" (progn (electric-verilog-terminate-line) nil))
13548 (define-skeleton verilog-sk-uvm-component
13549 "Insert a class definition"
13551 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
13553 > "`uvm_component_utils_begin(" name ")" \n
13554 > (- verilog-indent-level) "`uvm_component_utils_end" \n
13556 > "function new(string name=\"\", uvm_component parent);" \n
13557 > "super.new(name, parent);" \n
13558 > (- verilog-indent-level) "endfunction" \n
13560 > "endclass" (progn (electric-verilog-terminate-line) nil))
13562 (define-skeleton verilog-sk-primitive
13563 "Insert a task definition."
13565 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
13567 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
13569 (define-skeleton verilog-sk-task
13570 "Insert a task definition."
13572 > "task " '(verilog-sk-prompt-name) & ?; \n
13576 > (- verilog-indent-level-behavioral) "end" \n
13577 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
13579 (define-skeleton verilog-sk-function
13580 "Insert a function definition."
13582 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n
13586 > (- verilog-indent-level-behavioral) "end" \n
13587 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
13589 (define-skeleton verilog-sk-always
13590 "Insert always block. Uses the minibuffer to prompt
13591 for sensitivity list."
13593 > "always @ ( /*AUTOSENSE*/ ) begin\n"
13595 > (- verilog-indent-level-behavioral) "end" \n >
13598 (define-skeleton verilog-sk-initial
13599 "Insert an initial block."
13601 > "initial begin\n"
13603 > (- verilog-indent-level-behavioral) "end" \n > )
13605 (define-skeleton verilog-sk-specify
13606 "Insert specify block. "
13610 > (- verilog-indent-level-behavioral) "endspecify" \n > )
13612 (define-skeleton verilog-sk-generate
13613 "Insert generate block. "
13617 > (- verilog-indent-level-behavioral) "endgenerate" \n > )
13619 (define-skeleton verilog-sk-begin
13620 "Insert begin end block. Uses the minibuffer to prompt for name."
13622 > "begin" '(verilog-sk-prompt-name) \n
13624 > (- verilog-indent-level-behavioral) "end" )
13626 (define-skeleton verilog-sk-fork
13627 "Insert a fork join block."
13632 > (- verilog-indent-level-behavioral) "end" \n
13635 > (- verilog-indent-level-behavioral) "end" \n
13636 > (- verilog-indent-level-behavioral) "join" \n
13640 (define-skeleton verilog-sk-case
13641 "Build skeleton case statement, prompting for the selector expression,
13642 and the case items."
13643 "[selector expression]: "
13644 > "case (" str ") " \n
13645 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
13646 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
13648 (define-skeleton verilog-sk-casex
13649 "Build skeleton casex statement, prompting for the selector expression,
13650 and the case items."
13651 "[selector expression]: "
13652 > "casex (" str ") " \n
13653 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
13654 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
13656 (define-skeleton verilog-sk-casez
13657 "Build skeleton casez statement, prompting for the selector expression,
13658 and the case items."
13659 "[selector expression]: "
13660 > "casez (" str ") " \n
13661 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
13662 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
13664 (define-skeleton verilog-sk-if
13665 "Insert a skeleton if statement."
13666 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
13668 > (- verilog-indent-level-behavioral) "end " \n )
13670 (define-skeleton verilog-sk-else-if
13671 "Insert a skeleton else if statement."
13672 > (verilog-indent-line) "else if ("
13673 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
13675 > "end" (progn (electric-verilog-terminate-line) nil))
13677 (define-skeleton verilog-sk-datadef
13678 "Common routine to get data definition."
13680 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
13682 (define-skeleton verilog-sk-input
13683 "Insert an input definition."
13685 > "input [" '(verilog-sk-datadef))
13687 (define-skeleton verilog-sk-output
13688 "Insert an output definition."
13690 > "output [" '(verilog-sk-datadef))
13692 (define-skeleton verilog-sk-inout
13693 "Insert an inout definition."
13695 > "inout [" '(verilog-sk-datadef))
13697 (defvar verilog-sk-signal nil)
13698 (define-skeleton verilog-sk-def-reg
13699 "Insert a reg definition."
13701 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations-auto) )
13703 (defun verilog-sk-define-signal ()
13704 "Insert a definition of signal under point at top of module."
13706 (let* ((sig-re "[a-zA-Z0-9_]*")
13707 (v1 (buffer-substring
13709 (skip-chars-backward sig-re)
13712 (skip-chars-forward sig-re)
13714 (if (not (member v1 verilog-keywords))
13716 (setq verilog-sk-signal v1)
13717 (verilog-beg-of-defun)
13718 (verilog-end-of-statement)
13719 (verilog-forward-syntactic-ws)
13720 (verilog-sk-def-reg)
13721 (message "signal at point is %s" v1))
13722 (message "object at point (%s) is a keyword" v1))))
13724 (define-skeleton verilog-sk-wire
13725 "Insert a wire definition."
13727 > "wire [" '(verilog-sk-datadef))
13729 (define-skeleton verilog-sk-reg
13730 "Insert a reg definition."
13732 > "reg [" '(verilog-sk-datadef))
13734 (define-skeleton verilog-sk-assign
13735 "Insert a skeleton assign statement."
13737 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
13739 (define-skeleton verilog-sk-while
13740 "Insert a skeleton while loop statement."
13742 > "while (" '(verilog-sk-prompt-condition) ") begin" \n
13744 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13746 (define-skeleton verilog-sk-repeat
13747 "Insert a skeleton repeat loop statement."
13749 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
13751 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13753 (define-skeleton verilog-sk-for
13754 "Insert a skeleton while loop statement."
13757 '(verilog-sk-prompt-init) "; "
13758 '(verilog-sk-prompt-condition) "; "
13759 '(verilog-sk-prompt-inc)
13762 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13764 (define-skeleton verilog-sk-comment
13765 "Inserts three comment lines, making a display comment."
13771 (define-skeleton verilog-sk-state-machine
13772 "Insert a state machine definition."
13773 "Name of state variable: "
13774 '(setq input "state")
13775 > "// State registers for " str | -23 \n
13776 '(setq verilog-sk-state str)
13777 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n
13780 > "// State FF for " verilog-sk-state \n
13781 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
13782 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
13783 > verilog-sk-state " = next_" verilog-sk-state ?; \n
13784 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
13786 > "// Next State Logic for " verilog-sk-state \n
13787 > "always @ ( /*AUTOSENSE*/ ) begin\n"
13788 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
13789 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
13790 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
13791 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
13795 ;; Include file loading with mouse/return event
13797 ;; idea & first impl.: M. Rouat (eldo-mode.el)
13798 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
13800 (if (featurep 'xemacs)
13801 (require 'overlay))
13803 (defconst verilog-include-file-regexp
13804 "^`include\\s-+\"\\([^\n\"]*\\)\""
13805 "Regexp that matches the include file.")
13807 (defvar verilog-mode-mouse-map
13808 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
13809 (set-keymap-parent map verilog-mode-map)
13810 ;; mouse button bindings
13811 (define-key map "\r" 'verilog-load-file-at-point)
13812 (if (featurep 'xemacs)
13813 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
13814 (define-key map [mouse-2] 'verilog-load-file-at-mouse))
13815 (if (featurep 'xemacs)
13816 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
13817 (define-key map [S-mouse-2] 'mouse-yank-at-click))
13819 "Map containing mouse bindings for `verilog-mode'.")
13822 (defun verilog-highlight-region (beg end _old-len)
13823 "Colorize included files and modules in the (changed?) region.
13824 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
13825 (when (or verilog-highlight-includes
13826 verilog-highlight-modules)
13828 (save-match-data ;; A query-replace may call this function - do not disturb
13829 (verilog-save-buffer-state
13830 (verilog-save-scan-cache
13833 (setq end-point (point-at-eol))
13835 (beginning-of-line) ; scan entire line
13836 ;; delete overlays existing on this line
13837 (let ((overlays (overlays-in (point) end-point)))
13840 (overlay-get (car overlays) 'detachable)
13841 (or (overlay-get (car overlays) 'verilog-include-file)
13842 (overlay-get (car overlays) 'verilog-inst-module)))
13843 (delete-overlay (car overlays)))
13844 (setq overlays (cdr overlays))))
13846 ;; make new include overlays
13847 (when verilog-highlight-includes
13848 (while (search-forward-regexp verilog-include-file-regexp end-point t)
13849 (goto-char (match-beginning 1))
13850 (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
13851 (overlay-put ov 'start-closed 't)
13852 (overlay-put ov 'end-closed 't)
13853 (overlay-put ov 'evaporate 't)
13854 (overlay-put ov 'verilog-include-file 't)
13855 (overlay-put ov 'mouse-face 'highlight)
13856 (overlay-put ov 'local-map verilog-mode-mouse-map))))
13858 ;; make new module overlays
13860 ;; This scanner is syntax-fragile, so don't get bent
13861 (when verilog-highlight-modules
13862 (condition-case nil
13863 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
13865 (goto-char (match-beginning 0))
13866 (unless (verilog-inside-comment-or-string-p)
13867 (verilog-read-inst-module-matcher) ;; sets match 0
13868 (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
13869 (overlay-put ov 'start-closed 't)
13870 (overlay-put ov 'end-closed 't)
13871 (overlay-put ov 'evaporate 't)
13872 (overlay-put ov 'verilog-inst-module 't)
13873 (overlay-put ov 'mouse-face 'highlight)
13874 (overlay-put ov 'local-map verilog-mode-mouse-map)))))
13877 ;; Future highlights:
13878 ;; variables - make an Occur buffer of where referenced
13879 ;; pins - make an Occur buffer of the sig in the declaration module
13882 (defun verilog-highlight-buffer ()
13883 "Colorize included files and modules across the whole buffer."
13884 ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
13886 ;; delete and remake overlays
13887 (verilog-highlight-region (point-min) (point-max) nil))
13889 ;; Deprecated, but was interactive, so we'll keep it around
13890 (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
13892 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
13893 ;; so define this function to do more or less the same as ffap-at-mouse
13894 ;; but first resolve filename...
13895 (defun verilog-load-file-at-mouse (event)
13896 "Load file under button 2 click's EVENT.
13897 Files are checked based on `verilog-library-flags'."
13899 (save-excursion ;; implement a Verilog specific ffap-at-mouse
13900 (mouse-set-point event)
13901 (verilog-load-file-at-point t)))
13903 ;; ffap isn't usable for Verilog mode. It uses library paths.
13904 ;; so define this function to do more or less the same as ffap
13905 ;; but first resolve filename...
13906 (defun verilog-load-file-at-point (&optional warn)
13907 "Load file under point.
13908 If WARN, throw warning if not found.
13909 Files are checked based on `verilog-library-flags'."
13911 (save-excursion ;; implement a Verilog specific ffap
13912 (let ((overlays (overlays-in (point) (point)))
13914 (while (and overlays (not hit))
13915 (when (overlay-get (car overlays) 'verilog-inst-module)
13916 (verilog-goto-defun-file (buffer-substring
13917 (overlay-start (car overlays))
13918 (overlay-end (car overlays))))
13920 (setq overlays (cdr overlays)))
13922 (beginning-of-line)
13923 (when (and (not hit)
13924 (looking-at verilog-include-file-regexp))
13925 (if (and (car (verilog-library-filenames
13926 (match-string 1) (buffer-file-name)))
13927 (file-readable-p (car (verilog-library-filenames
13928 (match-string 1) (buffer-file-name)))))
13929 (find-file (car (verilog-library-filenames
13930 (match-string 1) (buffer-file-name))))
13933 "File '%s' isn't readable, use shift-mouse2 to paste in this field"
13934 (match-string 1))))))))
13940 (defun verilog-faq ()
13941 "Tell the user their current version, and where to get the FAQ etc."
13943 (with-output-to-temp-buffer "*verilog-mode help*"
13944 (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
13946 (princ "For new releases, see http://www.verilog.com\n")
13948 (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
13950 (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
13953 (autoload 'reporter-submit-bug-report "reporter")
13954 (defvar reporter-prompt-for-summary-p)
13956 (defun verilog-submit-bug-report ()
13957 "Submit via mail a bug report on verilog-mode.el."
13959 (let ((reporter-prompt-for-summary-p t))
13960 (reporter-submit-bug-report
13961 "mac@verilog.com, wsnyder@wsnyder.org"
13962 (concat "verilog-mode v" verilog-mode-version)
13964 verilog-active-low-regexp
13965 verilog-after-save-font-hook
13966 verilog-align-ifelse
13967 verilog-assignment-delay
13968 verilog-auto-arg-sort
13969 verilog-auto-declare-nettype
13970 verilog-auto-delete-trailing-whitespace
13971 verilog-auto-endcomments
13973 verilog-auto-ignore-concat
13974 verilog-auto-indent-on-newline
13975 verilog-auto-inout-ignore-regexp
13976 verilog-auto-input-ignore-regexp
13977 verilog-auto-inst-column
13978 verilog-auto-inst-dot-name
13979 verilog-auto-inst-interfaced-ports
13980 verilog-auto-inst-param-value
13981 verilog-auto-inst-sort
13982 verilog-auto-inst-template-numbers
13983 verilog-auto-inst-vector
13984 verilog-auto-lineup
13985 verilog-auto-newline
13986 verilog-auto-output-ignore-regexp
13987 verilog-auto-read-includes
13988 verilog-auto-reset-blocking-in-non
13989 verilog-auto-reset-widths
13990 verilog-auto-save-policy
13991 verilog-auto-sense-defines-constant
13992 verilog-auto-sense-include-inputs
13993 verilog-auto-star-expand
13994 verilog-auto-star-save
13995 verilog-auto-template-warn-unused
13996 verilog-auto-tieoff-declaration
13997 verilog-auto-tieoff-ignore-regexp
13998 verilog-auto-unused-ignore-regexp
13999 verilog-auto-wire-type
14000 verilog-before-auto-hook
14001 verilog-before-delete-auto-hook
14002 verilog-before-getopt-flags-hook
14003 verilog-before-save-font-hook
14004 verilog-cache-enabled
14006 verilog-case-indent
14007 verilog-cexp-indent
14010 verilog-delete-auto-hook
14011 verilog-getopt-flags-hook
14012 verilog-highlight-grouping-keywords
14013 verilog-highlight-includes
14014 verilog-highlight-modules
14015 verilog-highlight-p1800-keywords
14016 verilog-highlight-translate-off
14017 verilog-indent-begin-after-if
14018 verilog-indent-declaration-macros
14019 verilog-indent-level
14020 verilog-indent-level-behavioral
14021 verilog-indent-level-declaration
14022 verilog-indent-level-directive
14023 verilog-indent-level-module
14024 verilog-indent-lists
14025 verilog-library-directories
14026 verilog-library-extensions
14027 verilog-library-files
14028 verilog-library-flags
14030 verilog-minimum-comment-distance
14032 verilog-mode-release-emacs
14033 verilog-mode-version
14034 verilog-preprocessor
14036 verilog-tab-always-indent
14037 verilog-tab-to-comment
14038 verilog-typedef-regexp
14044 I want to report a bug.
14046 Before I go further, I want to say that Verilog mode has changed my life.
14047 I save so much time, my files are colored nicely, my co workers respect
14048 my coding ability... until now. I'd really appreciate anything you
14049 could do to help me out with this minor deficiency in the product.
14051 I've taken a look at the Verilog-Mode FAQ at
14052 http://www.veripool.org/verilog-mode-faq.html.
14054 And, I've considered filing the bug on the issue tracker at
14055 http://www.veripool.org/verilog-mode-bugs
14056 since I realize that public bugs are easier for you to track,
14057 and for others to search, but would prefer to email.
14059 So, to reproduce the bug, start a fresh Emacs via " invocation-name "
14060 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
14061 the code included below.
14063 Given those lines, I expected [[Fill in here]] to happen;
14064 but instead, [[Fill in here]] happens!.
14066 == The code: =="))))
14068 (provide 'verilog-mode)
14070 ;; Local Variables:
14071 ;; checkdoc-permit-comma-termination-flag:t
14072 ;; checkdoc-force-docstrings-flag:nil
14075 ;;; verilog-mode.el ends here