1 ;; verilog-mode.el --- major mode for editing verilog source in Emacs
3 ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
5 ;; Author: Michael McNamara (mac@verilog.com),
6 ;; Wilson Snyder (wsnyder@wsnyder.org)
7 ;; Please see our web sites:
8 ;; http://www.verilog.com
9 ;; http://www.veripool.org
11 ;; Keywords: languages
13 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
14 ;; file on 19/3/2008, and the maintainer agreed that when a bug is
15 ;; filed in the Emacs bug reporting system against this file, a copy
16 ;; of the bug report be sent to the maintainer's email address.
18 ;; This code supports Emacs 21.1 and later
19 ;; And XEmacs 21.1 and later
20 ;; Please do not make changes that break Emacs 21. Thanks!
24 ;; This file is part of GNU Emacs.
26 ;; GNU Emacs is free software: you can redistribute it and/or modify
27 ;; it under the terms of the GNU General Public License as published by
28 ;; the Free Software Foundation, either version 3 of the License, or
29 ;; (at your option) any later version.
31 ;; GNU Emacs is distributed in the hope that it will be useful,
32 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ;; GNU General Public License for more details.
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
41 ;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs
46 ;; A major mode for editing Verilog HDL source code. When you have
47 ;; entered Verilog mode, you may get more info by pressing C-h m. You
48 ;; may also get online help describing various functions by: C-h f
49 ;; <Name of function you want described>
51 ;; KNOWN BUGS / BUG REPORTS
52 ;; =======================
54 ;; Verilog is a rapidly evolving language, and hence this mode is
55 ;; under continuous development. Hence this is beta code, and likely
56 ;; has bugs. Please report any issues to the issue tracker at
57 ;; http://www.veripool.org/verilog-mode
58 ;; Please use verilog-submit-bug-report to submit a report; type C-c
59 ;; C-b to invoke this and as a result I will have a much easier time
60 ;; of reproducing the bug you find, and hence fixing it.
62 ;; INSTALLING THE MODE
63 ;; ===================
65 ;; An older version of this mode may be already installed as a part of
66 ;; your environment, and one method of updating would be to update
67 ;; your Emacs environment. Sometimes this is difficult for local
68 ;; political/control reasons, and hence you can always install a
69 ;; private copy (or even a shared copy) which overrides the system
72 ;; You can get step by step help in installing this file by going to
73 ;; <http://www.verilog.com/emacs_install.html>
75 ;; The short list of installation instructions are: To set up
76 ;; automatic Verilog mode, put this file in your load path, and put
77 ;; the following in code (please un comment it first!) in your
78 ;; .emacs, or in your site's site-load.el
80 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
81 ; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
83 ;; Be sure to examine at the help for verilog-auto, and the other
84 ;; verilog-auto-* functions for some major coding time savers.
86 ;; If you want to customize Verilog mode to fit your needs better,
87 ;; you may add the below lines (the values of the variables presented
88 ;; here are the defaults). Note also that if you use an Emacs that
89 ;; supports custom, it's probably better to use the custom menu to
90 ;; edit these. If working as a member of a large team these settings
91 ;; should be common across all users (in a site-start file), or set
92 ;; in Local Variables in every file. Otherwise, different people's
93 ;; AUTO expansion may result different whitespace changes.
95 ; ;; Enable syntax highlighting of **all** languages
96 ; (global-font-lock-mode t)
98 ; ;; User customization for Verilog mode
99 ; (setq verilog-indent-level 3
100 ; verilog-indent-level-module 3
101 ; verilog-indent-level-declaration 3
102 ; verilog-indent-level-behavioral 3
103 ; verilog-indent-level-directive 1
104 ; verilog-case-indent 2
105 ; verilog-auto-newline t
106 ; verilog-auto-indent-on-newline t
107 ; verilog-tab-always-indent t
108 ; verilog-auto-endcomments t
109 ; verilog-minimum-comment-distance 40
110 ; verilog-indent-begin-after-if t
111 ; verilog-auto-lineup 'declarations
112 ; verilog-highlight-p1800-keywords nil
113 ; verilog-linter "my_lint_shell_command"
120 ;; See commit history at http://www.veripool.org/verilog-mode.html
121 ;; (This section is required to appease checkdoc.)
125 ;; This variable will always hold the version number of the mode
126 (defconst verilog-mode-version
"800"
127 "Version of this Verilog mode.")
128 (defconst verilog-mode-release-date
"2012-04-23-GNU"
129 "Release date of this Verilog mode.")
130 (defconst verilog-mode-release-emacs t
131 "If non-nil, this version of Verilog mode was released with Emacs itself.")
133 (defun verilog-version ()
134 "Inform caller of the version of this file."
136 (message "Using verilog-mode version %s" verilog-mode-version
))
138 ;; Insure we have certain packages, and deal with it if we don't
139 ;; Be sure to note which Emacs flavor and version added each feature.
141 ;; Provide stuff if we are XEmacs
142 (when (featurep 'xemacs
)
147 (require 'regexp-opt
)
149 ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
156 (defmacro when
(cond &rest body
)
157 (list 'if cond
(cons 'progn body
))))
160 (if (fboundp 'unless
)
162 (defmacro unless
(cond &rest body
)
163 (cons 'if
(cons cond
(cons nil body
)))))
166 (if (fboundp 'store-match-data
)
168 (defmacro store-match-data
(&rest args
) nil
))
171 (if (fboundp 'char-before
)
173 (defmacro char-before
(&rest body
)
174 (char-after (1- (point)))))
179 (defsubst point-at-bol
(&optional N
)
180 (save-excursion (beginning-of-line N
) (point))))
185 (defsubst point-at-eol
(&optional N
)
186 (save-excursion (end-of-line N
) (point))))
192 (if (fboundp 'match-string-no-properties
)
194 (defsubst match-string-no-properties
(num &optional string
)
195 "Return string of text matched by last search, without text properties.
196 NUM specifies which parenthesized expression in the last regexp.
197 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
198 Zero means the entire text matched by the whole regexp or whole string.
199 STRING should be given if the last search was by `string-match' on STRING."
200 (if (match-beginning num
)
204 (match-beginning num
) (match-end num
))))
205 (set-text-properties 0 (length result
) nil result
)
207 (buffer-substring-no-properties (match-beginning num
)
212 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
213 nil
;; We've got what we needed
214 ;; We have the old custom-library, hack around it!
215 (defmacro defgroup
(&rest args
) nil
)
216 (defmacro customize
(&rest args
)
218 "Sorry, Customize is not available with this version of Emacs"))
219 (defmacro defcustom
(var value doc
&rest args
)
220 `(defvar ,var
,value
,doc
))
222 (if (fboundp 'defface
)
224 (defmacro defface
(var values doc
&rest args
)
228 (if (and (featurep 'custom
) (fboundp 'customize-group
))
229 nil
;; We've got what we needed
230 ;; We have an intermediate custom-library, hack around it!
231 (defmacro customize-group
(var &rest args
)
235 (unless (boundp 'inhibit-point-motion-hooks
)
236 (defvar inhibit-point-motion-hooks nil
))
237 (unless (boundp 'deactivate-mark
)
238 (defvar deactivate-mark nil
))
241 ;; OK, do this stuff if we are NOT XEmacs:
242 (unless (featurep 'xemacs
)
243 (unless (fboundp 'region-active-p
)
244 (defmacro region-active-p
()
245 `(and transient-mark-mode mark-active
))))
248 ;; Provide a regular expression optimization routine, using regexp-opt
249 ;; if provided by the user's elisp libraries
251 ;; The below were disabled when GNU Emacs 22 was released;
252 ;; perhaps some still need to be there to support Emacs 21.
253 (if (featurep 'xemacs
)
254 (if (fboundp 'regexp-opt
)
255 ;; regexp-opt is defined, does it take 3 or 2 arguments?
256 (if (fboundp 'function-max-args
)
257 (let ((args (function-max-args `regexp-opt
)))
259 ((eq args
3) ;; It takes 3
260 (condition-case nil
; Hide this defun from emacses
261 ;with just a two input regexp
262 (defun verilog-regexp-opt (a b
)
263 "Deal with differing number of required arguments for `regexp-opt'.
264 Call 'regexp-opt' on A and B."
268 ((eq args
2) ;; It takes 2
269 (defun verilog-regexp-opt (a b
)
270 "Call 'regexp-opt' on A and B."
274 ;; We can't tell; assume it takes 2
275 (defun verilog-regexp-opt (a b
)
276 "Call 'regexp-opt' on A and B."
279 ;; There is no regexp-opt, provide our own
280 (defun verilog-regexp-opt (strings &optional paren shy
)
281 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
282 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
)))
285 (defalias 'verilog-regexp-opt
'regexp-opt
)))
288 ;; Both xemacs and emacs
290 (require 'diff
) ;; diff-command and diff-switches
293 (require 'compile
) ;; compilation-error-regexp-alist-alist
296 (unless (fboundp 'buffer-chars-modified-tick
) ;; Emacs 22 added
297 (defmacro buffer-chars-modified-tick
() (buffer-modified-tick)))
299 ;; Added in Emacs 24.1
301 (unless (fboundp 'prog-mode
)
302 (define-derived-mode prog-mode fundamental-mode
"Prog"))
306 (defun verilog-regexp-words (a)
307 "Call 'regexp-opt' with word delimiters for the words A."
308 (concat "\\<" (verilog-regexp-opt a t
) "\\>")))
309 (defun verilog-regexp-words (a)
310 "Call 'regexp-opt' with word delimiters for the words A."
311 ;; The FAQ references this function, so user LISP sometimes calls it
312 (concat "\\<" (verilog-regexp-opt a t
) "\\>"))
314 (defun verilog-easy-menu-filter (menu)
315 "Filter `easy-menu-define' MENU to support new features."
316 (cond ((not (featurep 'xemacs
))
317 menu
) ;; GNU Emacs - passthru
318 ;; XEmacs doesn't support :help. Strip it.
319 ;; Recursively filter the a submenu
321 (mapcar 'verilog-easy-menu-filter menu
))
322 ;; Look for [:help "blah"] and remove
324 (let ((i 0) (out []))
325 (while (< i
(length menu
))
326 (if (equal `:help
(aref menu i
))
328 (setq out
(vconcat out
(vector (aref menu i
)))
331 (t menu
))) ;; Default - ok
332 ;;(verilog-easy-menu-filter
333 ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
334 ;; "----" ["MB" nil :help "Help MB"]))
336 (defun verilog-define-abbrev (table name expansion
&optional hook
)
337 "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
338 Provides SYSTEM-FLAG in newer Emacs."
340 (define-abbrev table name expansion hook
0 t
)
342 (define-abbrev table name expansion hook
))))
344 (defun verilog-customize ()
345 "Customize variables and other settings used by Verilog-Mode."
347 (customize-group 'verilog-mode
))
349 (defun verilog-font-customize ()
350 "Customize fonts used by Verilog-Mode."
352 (if (fboundp 'customize-apropos
)
353 (customize-apropos "font-lock-*" 'faces
)))
355 (defun verilog-booleanp (value)
356 "Return t if VALUE is boolean.
357 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
358 This function may be removed when Emacs 21 is no longer supported."
359 (or (equal value t
) (equal value nil
)))
361 (defun verilog-insert-last-command-event ()
362 "Insert the `last-command-event'."
363 (insert (if (featurep 'xemacs
)
364 ;; XEmacs 21.5 doesn't like last-command-event
366 ;; And GNU Emacs 22 has obsoleted last-command-char
367 last-command-event
)))
369 (defvar verilog-no-change-functions nil
370 "True if `after-change-functions' is disabled.
371 Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")
373 (defvar verilog-in-hooks nil
374 "True when within a `verilog-run-hooks' block.")
376 (defmacro verilog-run-hooks
(&rest hooks
)
377 "Run each hook in HOOKS using `run-hooks'.
378 Set `verilog-in-hooks' during this time, to assist AUTO caches."
379 `(let ((verilog-in-hooks t
))
380 (run-hooks ,@hooks
)))
382 (defun verilog-syntax-ppss (&optional pos
)
383 (when verilog-no-change-functions
385 (verilog-scan-cache-flush)
386 ;; else don't let the AUTO code itself get away with flushing the cache,
387 ;; as that'll make things very slow
389 (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
390 (verilog-point-text))))
391 (if (fboundp 'syntax-ppss
)
393 (parse-partial-sexp (point-min) (or pos
(point)))))
395 (defgroup verilog-mode nil
396 "Major mode for Verilog source code."
400 ; (defgroup verilog-mode-fonts nil
401 ; "Facilitates easy customization fonts used in Verilog source text"
402 ; :link '(customize-apropos "font-lock-*" 'faces)
403 ; :group 'verilog-mode)
405 (defgroup verilog-mode-indent nil
406 "Customize indentation and highlighting of Verilog source text."
407 :group
'verilog-mode
)
409 (defgroup verilog-mode-actions nil
410 "Customize actions on Verilog source text."
411 :group
'verilog-mode
)
413 (defgroup verilog-mode-auto nil
414 "Customize AUTO actions when expanding Verilog source text."
415 :group
'verilog-mode
)
417 (defvar verilog-debug nil
418 "Non-nil means enable debug messages for `verilog-mode' internals.")
420 (defvar verilog-warn-fatal nil
421 "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
423 (defcustom verilog-linter
424 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
425 "Unix program and arguments to call to run a lint checker on Verilog source.
426 Depending on the `verilog-set-compile-command', this may be invoked when
427 you type \\[compile]. When the compile completes, \\[next-error] will take
428 you to the next lint error."
430 :group
'verilog-mode-actions
)
431 ;; We don't mark it safe, as it's used as a shell command
433 (defcustom verilog-coverage
434 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
435 "Program and arguments to use to annotate for coverage Verilog source.
436 Depending on the `verilog-set-compile-command', this may be invoked when
437 you type \\[compile]. When the compile completes, \\[next-error] will take
438 you to the next lint error."
440 :group
'verilog-mode-actions
)
441 ;; We don't mark it safe, as it's used as a shell command
443 (defcustom verilog-simulator
444 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
445 "Program and arguments to use to interpret Verilog source.
446 Depending on the `verilog-set-compile-command', this may be invoked when
447 you type \\[compile]. When the compile completes, \\[next-error] will take
448 you to the next lint error."
450 :group
'verilog-mode-actions
)
451 ;; We don't mark it safe, as it's used as a shell command
453 (defcustom verilog-compiler
454 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
455 "Program and arguments to use to compile Verilog source.
456 Depending on the `verilog-set-compile-command', this may be invoked when
457 you type \\[compile]. When the compile completes, \\[next-error] will take
458 you to the next lint error."
460 :group
'verilog-mode-actions
)
461 ;; We don't mark it safe, as it's used as a shell command
463 (defcustom verilog-preprocessor
464 ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
465 "vppreproc __FLAGS__ __FILE__"
466 "Program and arguments to use to preprocess Verilog source.
467 This is invoked with `verilog-preprocess', and depending on the
468 `verilog-set-compile-command', may also be invoked when you type
469 \\[compile]. When the compile completes, \\[next-error] will
470 take you to the next lint error."
472 :group
'verilog-mode-actions
)
473 ;; We don't mark it safe, as it's used as a shell command
475 (defvar verilog-preprocess-history nil
476 "History for `verilog-preprocess'.")
478 (defvar verilog-tool
'verilog-linter
479 "Which tool to use for building compiler-command.
480 Either nil, `verilog-linter, `verilog-compiler,
481 `verilog-coverage, `verilog-preprocessor, or `verilog-simulator.
482 Alternatively use the \"Choose Compilation Action\" menu. See
483 `verilog-set-compile-command' for more information.")
485 (defcustom verilog-highlight-translate-off nil
486 "Non-nil means background-highlight code excluded from translation.
487 That is, all code between \"// synopsys translate_off\" and
488 \"// synopsys translate_on\" is highlighted using a different background color
489 \(face `verilog-font-lock-translate-off-face').
491 Note: This will slow down on-the-fly fontification (and thus editing).
493 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
494 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
496 :group
'verilog-mode-indent
)
497 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
498 (put 'verilog-highlight-translate-off
'safe-local-variable
'verilog-booleanp
)
500 (defcustom verilog-auto-lineup
'declarations
501 "Type of statements to lineup across multiple lines.
502 If 'all' is selected, then all line ups described below are done.
504 If 'declaration', then just declarations are lined up with any
505 preceding declarations, taking into account widths and the like,
506 so or example the code:
513 If 'assignment', then assignments are lined up with any preceding
514 assignments, so for example the code
515 a_long_variable <= b + c;
518 a_long_variable <= b + c;
521 In order to speed up editing, large blocks of statements are lined up
522 only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
523 are lineup only when \\[verilog-pretty-declarations] is typed."
525 :type
'(radio (const :tag
"Line up Assignments and Declarations" all
)
526 (const :tag
"Line up Assignment statements" assignments
)
527 (const :tag
"Line up Declarations" declarations
)
528 (function :tag
"Other"))
529 :group
'verilog-mode-indent
)
530 (put 'verilog-auto-lineup
'safe-local-variable
531 '(lambda (x) (memq x
'(nil all assignments declarations
))))
533 (defcustom verilog-indent-level
3
534 "Indentation of Verilog statements with respect to containing block."
535 :group
'verilog-mode-indent
537 (put 'verilog-indent-level
'safe-local-variable
'integerp
)
539 (defcustom verilog-indent-level-module
3
540 "Indentation of Module level Verilog statements (eg always, initial).
541 Set to 0 to get initial and always statements lined up on the left side of
543 :group
'verilog-mode-indent
545 (put 'verilog-indent-level-module
'safe-local-variable
'integerp
)
547 (defcustom verilog-indent-level-declaration
3
548 "Indentation of declarations with respect to containing block.
549 Set to 0 to get them list right under containing block."
550 :group
'verilog-mode-indent
552 (put 'verilog-indent-level-declaration
'safe-local-variable
'integerp
)
554 (defcustom verilog-indent-declaration-macros nil
555 "How to treat macro expansions in a declaration.
560 If non nil, treat as:
564 :group
'verilog-mode-indent
566 (put 'verilog-indent-declaration-macros
'safe-local-variable
'verilog-booleanp
)
568 (defcustom verilog-indent-lists t
569 "How to treat indenting items in a list.
570 If t (the default), indent as:
571 always @( posedge a or
575 always @( posedge a or
577 :group
'verilog-mode-indent
579 (put 'verilog-indent-lists
'safe-local-variable
'verilog-booleanp
)
581 (defcustom verilog-indent-level-behavioral
3
582 "Absolute indentation of first begin in a task or function block.
583 Set to 0 to get such code to start at the left side of the screen."
584 :group
'verilog-mode-indent
586 (put 'verilog-indent-level-behavioral
'safe-local-variable
'integerp
)
588 (defcustom verilog-indent-level-directive
1
589 "Indentation to add to each level of `ifdef declarations.
590 Set to 0 to have all directives start at the left side of the screen."
591 :group
'verilog-mode-indent
593 (put 'verilog-indent-level-directive
'safe-local-variable
'integerp
)
595 (defcustom verilog-cexp-indent
2
596 "Indentation of Verilog statements split across lines."
597 :group
'verilog-mode-indent
599 (put 'verilog-cexp-indent
'safe-local-variable
'integerp
)
601 (defcustom verilog-case-indent
2
602 "Indentation for case statements."
603 :group
'verilog-mode-indent
605 (put 'verilog-case-indent
'safe-local-variable
'integerp
)
607 (defcustom verilog-auto-newline t
608 "Non-nil means automatically newline after semicolons."
609 :group
'verilog-mode-indent
611 (put 'verilog-auto-newline
'safe-local-variable
'verilog-booleanp
)
613 (defcustom verilog-auto-indent-on-newline t
614 "Non-nil means automatically indent line after newline."
615 :group
'verilog-mode-indent
617 (put 'verilog-auto-indent-on-newline
'safe-local-variable
'verilog-booleanp
)
619 (defcustom verilog-tab-always-indent t
620 "Non-nil means TAB should always re-indent the current line.
621 A nil value means TAB will only reindent when at the beginning of the line."
622 :group
'verilog-mode-indent
624 (put 'verilog-tab-always-indent
'safe-local-variable
'verilog-booleanp
)
626 (defcustom verilog-tab-to-comment nil
627 "Non-nil means TAB moves to the right hand column in preparation for a comment."
628 :group
'verilog-mode-actions
630 (put 'verilog-tab-to-comment
'safe-local-variable
'verilog-booleanp
)
632 (defcustom verilog-indent-begin-after-if t
633 "Non-nil means indent begin statements following if, else, while, etc.
634 Otherwise, line them up."
635 :group
'verilog-mode-indent
637 (put 'verilog-indent-begin-after-if
'safe-local-variable
'verilog-booleanp
)
639 (defcustom verilog-align-ifelse nil
640 "Non-nil means align `else' under matching `if'.
641 Otherwise else is lined up with first character on line holding matching if."
642 :group
'verilog-mode-indent
644 (put 'verilog-align-ifelse
'safe-local-variable
'verilog-booleanp
)
646 (defcustom verilog-minimum-comment-distance
10
647 "Minimum distance (in lines) between begin and end required before a comment.
648 Setting this variable to zero results in every end acquiring a comment; the
649 default avoids too many redundant comments in tight quarters."
650 :group
'verilog-mode-indent
652 (put 'verilog-minimum-comment-distance
'safe-local-variable
'integerp
)
654 (defcustom verilog-highlight-p1800-keywords nil
655 "Non-nil means highlight words newly reserved by IEEE-1800.
656 These will appear in `verilog-font-lock-p1800-face' in order to gently
657 suggest changing where these words are used as variables to something else.
658 A nil value means highlight these words as appropriate for the SystemVerilog
659 IEEE-1800 standard. Note that changing this will require restarting Emacs
660 to see the effect as font color choices are cached by Emacs."
661 :group
'verilog-mode-indent
663 (put 'verilog-highlight-p1800-keywords
'safe-local-variable
'verilog-booleanp
)
665 (defcustom verilog-highlight-grouping-keywords nil
666 "Non-nil means highlight grouping keywords 'begin' and 'end' more dramatically.
667 If false, these words are in the `font-lock-type-face'; if True then they are in
668 `verilog-font-lock-ams-face'. Some find that special highlighting on these
669 grouping constructs allow the structure of the code to be understood at a glance."
670 :group
'verilog-mode-indent
672 (put 'verilog-highlight-grouping-keywords
'safe-local-variable
'verilog-booleanp
)
674 (defcustom verilog-highlight-modules nil
675 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
676 When true, mousing over module names will allow jumping to the
677 module definition. If false, this is not supported. Setting
678 this is experimental, and may lead to bad performance."
679 :group
'verilog-mode-indent
681 (put 'verilog-highlight-modules
'safe-local-variable
'verilog-booleanp
)
683 (defcustom verilog-highlight-includes t
684 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
685 When true, mousing over include file names will allow jumping to the
686 file referenced. If false, this is not supported."
687 :group
'verilog-mode-indent
689 (put 'verilog-highlight-includes
'safe-local-variable
'verilog-booleanp
)
691 (defcustom verilog-auto-declare-nettype nil
692 "Non-nil specifies the data type to use with `verilog-auto-input' etc.
693 Set this to \"wire\" if the Verilog code uses \"`default_nettype
694 none\". Note using `default_nettype none isn't recommended practice; this
695 mode is experimental."
696 :version
"24.1" ;; rev670
697 :group
'verilog-mode-actions
699 (put 'verilog-auto-declare-nettype
'safe-local-variable
`stringp
)
701 (defcustom verilog-auto-wire-type nil
702 "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
703 Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'."
704 :version
"24.1" ;; rev673
705 :group
'verilog-mode-actions
707 (put 'verilog-auto-wire-type
'safe-local-variable
`stringp
)
709 (defcustom verilog-auto-endcomments t
710 "Non-nil means insert a comment /* ... */ after 'end's.
711 The name of the function or case will be set between the braces."
712 :group
'verilog-mode-actions
714 (put 'verilog-auto-endcomments
'safe-local-variable
'verilog-booleanp
)
716 (defcustom verilog-auto-delete-trailing-whitespace nil
717 "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
718 :version
"24.1" ;; rev703
719 :group
'verilog-mode-actions
721 (put 'verilog-auto-delete-trailing-whitespace
'safe-local-variable
'verilog-booleanp
)
723 (defcustom verilog-auto-ignore-concat nil
724 "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
725 This will exclude signals referenced as pin connections in {...}
726 from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
727 for backward compatibility only and not set in new designs; it
728 may be removed in future versions."
729 :group
'verilog-mode-actions
731 (put 'verilog-auto-ignore-concat
'safe-local-variable
'verilog-booleanp
)
733 (defcustom verilog-auto-read-includes nil
734 "Non-nil means to automatically read includes before AUTOs.
735 This will do a `verilog-read-defines' and `verilog-read-includes' before
736 each AUTO expansion. This makes it easier to embed defines and includes,
737 but can result in very slow reading times if there are many or large
739 :group
'verilog-mode-actions
741 (put 'verilog-auto-read-includes
'safe-local-variable
'verilog-booleanp
)
743 (defcustom verilog-auto-save-policy nil
744 "Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
745 A value of `force' will always do a \\[verilog-auto] automatically if
746 needed on every save. A value of `detect' will do \\[verilog-auto]
747 automatically when it thinks necessary. A value of `ask' will query the
748 user when it thinks updating is needed.
750 You should not rely on the 'ask or 'detect policies, they are safeguards
751 only. They do not detect when AUTOINSTs need to be updated because a
752 sub-module's port list has changed."
753 :group
'verilog-mode-actions
754 :type
'(choice (const nil
) (const ask
) (const detect
) (const force
)))
756 (defcustom verilog-auto-star-expand t
757 "Non-nil means to expand SystemVerilog .* instance ports.
758 They will be expanded in the same way as if there was an AUTOINST in the
759 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
760 :group
'verilog-mode-actions
762 (put 'verilog-auto-star-expand
'safe-local-variable
'verilog-booleanp
)
764 (defcustom verilog-auto-star-save nil
765 "Non-nil means save to disk SystemVerilog .* instance expansions.
766 A nil value indicates direct connections will be removed before saving.
767 Only meaningful to those created due to `verilog-auto-star-expand' being set.
769 Instead of setting this, you may want to use /*AUTOINST*/, which will
771 :group
'verilog-mode-actions
773 (put 'verilog-auto-star-save
'safe-local-variable
'verilog-booleanp
)
775 (defvar verilog-auto-update-tick nil
776 "Modification tick at which autos were last performed.")
778 (defvar verilog-auto-last-file-locals nil
779 "Text from file-local-variables during last evaluation.")
781 (defvar verilog-diff-function
'verilog-diff-report
782 "Function to run when `verilog-diff-auto' detects differences.
783 Function takes three arguments, the original buffer, the
784 difference buffer, and the point in original buffer with the
789 (defvar verilog-error-regexp-added nil
)
791 (defvar verilog-error-regexp-emacs-alist
794 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
796 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
798 ".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
800 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
802 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
805 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
806 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
808 "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
810 "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
812 "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
814 "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
816 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
818 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
820 "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
822 "List of regexps for Verilog compilers.
823 See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
825 (defvar verilog-error-regexp-xemacs-alist
826 ;; Emacs form is '((v-tool "re" 1 2) ...)
827 ;; XEmacs form is '(verilog ("re" 1 2) ...)
828 ;; So we can just map from Emacs to XEmacs
829 (cons 'verilog
(mapcar 'cdr verilog-error-regexp-emacs-alist
))
830 "List of regexps for Verilog compilers.
831 See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
833 (defvar verilog-error-font-lock-keywords
836 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
837 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
839 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t
)
840 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t
)
841 ;; verilog-IES (nc-verilog)
842 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t
)
843 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t
)
844 ;; verilog-surefire-1
845 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t
)
846 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t
)
847 ;; verilog-surefire-2
848 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t
)
849 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t
)
852 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
853 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
855 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
856 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
858 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t
)
859 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t
)
861 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
862 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
864 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
865 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t
)
867 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t
)
868 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
870 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t
)
871 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t
)
873 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t
)
874 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t
)
876 "Keywords to also highlight in Verilog *compilation* buffers.
877 Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
879 (defcustom verilog-library-flags
'("")
880 "List of standard Verilog arguments to use for /*AUTOINST*/.
881 These arguments are used to find files for `verilog-auto', and match
882 the flags accepted by a standard Verilog-XL simulator.
884 -f filename Reads more `verilog-library-flags' from the filename.
885 +incdir+dir Adds the directory to `verilog-library-directories'.
886 -Idir Adds the directory to `verilog-library-directories'.
887 -y dir Adds the directory to `verilog-library-directories'.
888 +libext+.v Adds the extensions to `verilog-library-extensions'.
889 -v filename Adds the filename to `verilog-library-files'.
891 filename Adds the filename to `verilog-library-files'.
892 This is not recommended, -v is a better choice.
894 You might want these defined in each file; put at the *END* of your file
898 // verilog-library-flags:(\"-y dir -y otherdir\")
901 Verilog-mode attempts to detect changes to this local variable, but they
902 are only insured to be correct when the file is first visited. Thus if you
903 have problems, use \\[find-alternate-file] RET to have these take effect.
905 See also the variables mentioned above."
906 :group
'verilog-mode-auto
907 :type
'(repeat string
))
908 (put 'verilog-library-flags
'safe-local-variable
'listp
)
910 (defcustom verilog-library-directories
'(".")
911 "List of directories when looking for files for /*AUTOINST*/.
912 The directory may be relative to the current file, or absolute.
913 Environment variables are also expanded in the directory names.
914 Having at least the current directory is a good idea.
916 You might want these defined in each file; put at the *END* of your file
920 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
923 Verilog-mode attempts to detect changes to this local variable, but they
924 are only insured to be correct when the file is first visited. Thus if you
925 have problems, use \\[find-alternate-file] RET to have these take effect.
927 See also `verilog-library-flags', `verilog-library-files'
928 and `verilog-library-extensions'."
929 :group
'verilog-mode-auto
930 :type
'(repeat file
))
931 (put 'verilog-library-directories
'safe-local-variable
'listp
)
933 (defcustom verilog-library-files
'()
934 "List of files to search for modules.
935 AUTOINST will use this when it needs to resolve a module name.
936 This is a complete path, usually to a technology file with many standard
939 You might want these defined in each file; put at the *END* of your file
943 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
946 Verilog-mode attempts to detect changes to this local variable, but they
947 are only insured to be correct when the file is first visited. Thus if you
948 have problems, use \\[find-alternate-file] RET to have these take effect.
950 See also `verilog-library-flags', `verilog-library-directories'."
951 :group
'verilog-mode-auto
952 :type
'(repeat directory
))
953 (put 'verilog-library-files
'safe-local-variable
'listp
)
955 (defcustom verilog-library-extensions
'(".v" ".sv")
956 "List of extensions to use when looking for files for /*AUTOINST*/.
957 See also `verilog-library-flags', `verilog-library-directories'."
958 :type
'(repeat string
)
959 :group
'verilog-mode-auto
)
960 (put 'verilog-library-extensions
'safe-local-variable
'listp
)
962 (defcustom verilog-active-low-regexp nil
963 "If set, treat signals matching this regexp as active low.
964 This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
965 you will probably also need `verilog-auto-reset-widths' set."
966 :group
'verilog-mode-auto
968 (put 'verilog-active-low-regexp
'safe-local-variable
'stringp
)
970 (defcustom verilog-auto-sense-include-inputs nil
971 "Non-nil means AUTOSENSE should include all inputs.
972 If nil, only inputs that are NOT output signals in the same block are
974 :group
'verilog-mode-auto
976 (put 'verilog-auto-sense-include-inputs
'safe-local-variable
'verilog-booleanp
)
978 (defcustom verilog-auto-sense-defines-constant nil
979 "Non-nil means AUTOSENSE should assume all defines represent constants.
980 When true, the defines will not be included in sensitivity lists. To
981 maintain compatibility with other sites, this should be set at the bottom
982 of each Verilog file that requires it, rather than being set globally."
983 :group
'verilog-mode-auto
985 (put 'verilog-auto-sense-defines-constant
'safe-local-variable
'verilog-booleanp
)
987 (defcustom verilog-auto-reset-blocking-in-non t
988 "Non-nil means AUTORESET will reset blocking statements.
989 When true, AUTORESET will reset in blocking statements those
990 signals which were assigned with blocking assignments (=) even in
991 a block with non-blocking assignments (<=).
993 If nil, all blocking assigned signals are ignored when any
994 non-blocking assignment is in the AUTORESET block. This allows
995 blocking assignments to be used for temporary values and not have
996 those temporaries reset. See example in `verilog-auto-reset'."
997 :version
"24.1" ;; rev718
999 :group
'verilog-mode-auto
)
1000 (put 'verilog-auto-reset-blocking-in-non
'safe-local-variable
'verilog-booleanp
)
1002 (defcustom verilog-auto-reset-widths t
1003 "True means AUTORESET should determine the width of signals.
1004 This is then used to set the width of the zero (32'h0 for example). This
1005 is required by some lint tools that aren't smart enough to ignore widths of
1006 the constant zero. This may result in ugly code when parameters determine
1007 the MSB or LSB of a signal inside an AUTORESET.
1009 If nil, AUTORESET uses \"0\" as the constant.
1011 If 'unbased', AUTORESET used the unbased unsized literal \"'0\"
1012 as the constant. This setting is strongly recommended for
1013 SystemVerilog designs."
1015 :group
'verilog-mode-auto
)
1016 (put 'verilog-auto-reset-widths
'safe-local-variable
1017 '(lambda (x) (memq x
'(nil t unbased
))))
1019 (defcustom verilog-assignment-delay
""
1020 "Text used for delays in delayed assignments. Add a trailing space if set."
1021 :group
'verilog-mode-auto
1023 (put 'verilog-assignment-delay
'safe-local-variable
'stringp
)
1025 (defcustom verilog-auto-arg-sort nil
1026 "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
1027 Declaration order is advantageous with order based instantiations
1028 and is the default for backward compatibility. Sorted order
1029 reduces changes when declarations are moved around in a file, and
1030 it's bad practice to rely on order based instantiations anyhow.
1032 See also `verilog-auto-inst-sort'."
1033 :group
'verilog-mode-auto
1035 (put 'verilog-auto-arg-sort
'safe-local-variable
'verilog-booleanp
)
1037 (defcustom verilog-auto-inst-dot-name nil
1038 "Non-nil means when creating ports with AUTOINST, use .name syntax.
1039 This will use \".port\" instead of \".port(port)\" when possible.
1040 This is only legal in SystemVerilog files, and will confuse older
1041 simulators. Setting `verilog-auto-inst-vector' to nil may also
1042 be desirable to increase how often .name will be used."
1043 :group
'verilog-mode-auto
1045 (put 'verilog-auto-inst-dot-name
'safe-local-variable
'verilog-booleanp
)
1047 (defcustom verilog-auto-inst-param-value nil
1048 "Non-nil means AUTOINST will replace parameters with the parameter value.
1049 If nil, leave parameters as symbolic names.
1051 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
1052 listed as such there (as when the default value is acceptable), it will not
1053 be replaced, and will remain symbolic.
1055 For example, imagine a submodule uses parameters to declare the size of its
1056 inputs. This is then used by an upper module:
1058 module InstModule (o,i);
1060 input [WIDTH-1:0] i;
1070 Note even though PARAM=10, the AUTOINST has left the parameter as a
1071 symbolic name. If `verilog-auto-inst-param-value' is set, this will
1080 :group
'verilog-mode-auto
1082 (put 'verilog-auto-inst-param-value
'safe-local-variable
'verilog-booleanp
)
1084 (defcustom verilog-auto-inst-sort nil
1085 "Non-nil means AUTOINST signals will be sorted, not in declaration order.
1086 Also affects AUTOINSTPARAM. Declaration order is the default for
1087 backward compatibility, and as some teams prefer signals that are
1088 declared together to remain together. Sorted order reduces
1089 changes when declarations are moved around in a file.
1091 See also `verilog-auto-arg-sort'."
1092 :version
"24.1" ;; rev688
1093 :group
'verilog-mode-auto
1095 (put 'verilog-auto-inst-sort
'safe-local-variable
'verilog-booleanp
)
1097 (defcustom verilog-auto-inst-vector t
1098 "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
1099 If nil, skip the subscript when it matches the entire bus as declared in
1100 the module (AUTOWIRE signals always are subscripted, you must manually
1101 declare the wire to have the subscripts removed.) Setting this to nil may
1102 speed up some simulators, but is less general and harder to read, so avoid."
1103 :group
'verilog-mode-auto
1105 (put 'verilog-auto-inst-vector
'safe-local-variable
'verilog-booleanp
)
1107 (defcustom verilog-auto-inst-template-numbers nil
1108 "If true, when creating templated ports with AUTOINST, add a comment.
1110 If t, the comment will add the line number of the template that
1111 was used for that port declaration. This setting is suggested
1112 only for debugging use, as regular use may cause a large numbers
1115 If 'lhs', the comment will show the left hand side of the
1116 AUTO_TEMPLATE rule that is matched. This is less precise than
1117 numbering (t) when multiple rules have the same pin name, but
1118 won't merge conflict."
1119 :group
'verilog-mode-auto
1120 :type
'(choice (const nil
) (const t
) (const lhs
)))
1121 (put 'verilog-auto-inst-template-numbers
'safe-local-variable
1122 '(lambda (x) (memq x
'(nil t lhs
))))
1124 (defcustom verilog-auto-inst-column
40
1125 "Indent-to column number for net name part of AUTOINST created pin."
1126 :group
'verilog-mode-indent
1128 (put 'verilog-auto-inst-column
'safe-local-variable
'integerp
)
1130 (defcustom verilog-auto-inst-interfaced-ports t
1131 "Non-nil means include interfaced ports in AUTOINST expansions."
1132 :group
'verilog-mode-auto
1134 (put 'verilog-auto-inst-interfaced-ports
'safe-local-variable
'verilog-booleanp
)
1136 (defcustom verilog-auto-input-ignore-regexp nil
1137 "If set, when creating AUTOINPUT list, ignore signals matching this regexp.
1138 See the \\[verilog-faq] for examples on using this."
1139 :group
'verilog-mode-auto
1141 (put 'verilog-auto-input-ignore-regexp
'safe-local-variable
'stringp
)
1143 (defcustom verilog-auto-inout-ignore-regexp nil
1144 "If set, when creating AUTOINOUT list, ignore signals matching this regexp.
1145 See the \\[verilog-faq] for examples on using this."
1146 :group
'verilog-mode-auto
1148 (put 'verilog-auto-inout-ignore-regexp
'safe-local-variable
'stringp
)
1150 (defcustom verilog-auto-output-ignore-regexp nil
1151 "If set, when creating AUTOOUTPUT list, ignore signals matching this regexp.
1152 See the \\[verilog-faq] for examples on using this."
1153 :group
'verilog-mode-auto
1155 (put 'verilog-auto-output-ignore-regexp
'safe-local-variable
'stringp
)
1157 (defcustom verilog-auto-template-warn-unused nil
1158 "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
1159 This feature is not supported before Emacs 21.1 or XEmacs 21.4."
1160 :group
'verilog-mode-auto
1162 (put 'verilog-auto-template-warn-unused
'safe-local-variable
'verilog-booleanp
)
1164 (defcustom verilog-auto-tieoff-declaration
"wire"
1165 "Data type used for the declaration for AUTOTIEOFF.
1166 If \"wire\" then create a wire, if \"assign\" create an
1167 assignment, else the data type for variable creation."
1168 :version
"24.1" ;; rev713
1169 :group
'verilog-mode-auto
1171 (put 'verilog-auto-tieoff-declaration
'safe-local-variable
'stringp
)
1173 (defcustom verilog-auto-tieoff-ignore-regexp nil
1174 "If set, when creating AUTOTIEOFF list, ignore signals matching this regexp.
1175 See the \\[verilog-faq] for examples on using this."
1176 :group
'verilog-mode-auto
1178 (put 'verilog-auto-tieoff-ignore-regexp
'safe-local-variable
'stringp
)
1180 (defcustom verilog-auto-unused-ignore-regexp nil
1181 "If set, when creating AUTOUNUSED list, ignore signals matching this regexp.
1182 See the \\[verilog-faq] for examples on using this."
1183 :group
'verilog-mode-auto
1185 (put 'verilog-auto-unused-ignore-regexp
'safe-local-variable
'stringp
)
1187 (defcustom verilog-typedef-regexp nil
1188 "If non-nil, regular expression that matches Verilog-2001 typedef names.
1189 For example, \"_t$\" matches typedefs named with _t, as in the C language."
1190 :group
'verilog-mode-auto
1192 (put 'verilog-typedef-regexp
'safe-local-variable
'stringp
)
1194 (defcustom verilog-mode-hook
'verilog-set-compile-command
1195 "Hook run after Verilog mode is loaded."
1197 :group
'verilog-mode
)
1199 (defcustom verilog-auto-hook nil
1200 "Hook run after `verilog-mode' updates AUTOs."
1201 :group
'verilog-mode-auto
1204 (defcustom verilog-before-auto-hook nil
1205 "Hook run before `verilog-mode' updates AUTOs."
1206 :group
'verilog-mode-auto
1209 (defcustom verilog-delete-auto-hook nil
1210 "Hook run after `verilog-mode' deletes AUTOs."
1211 :group
'verilog-mode-auto
1214 (defcustom verilog-before-delete-auto-hook nil
1215 "Hook run before `verilog-mode' deletes AUTOs."
1216 :group
'verilog-mode-auto
1219 (defcustom verilog-getopt-flags-hook nil
1220 "Hook run after `verilog-getopt-flags' determines the Verilog option lists."
1221 :group
'verilog-mode-auto
1224 (defcustom verilog-before-getopt-flags-hook nil
1225 "Hook run before `verilog-getopt-flags' determines the Verilog option lists."
1226 :group
'verilog-mode-auto
1229 (defcustom verilog-before-save-font-hook nil
1230 "Hook run before `verilog-save-font-mods' removes highlighting."
1231 :group
'verilog-mode-auto
1234 (defcustom verilog-after-save-font-hook nil
1235 "Hook run after `verilog-save-font-mods' restores highlighting."
1236 :group
'verilog-mode-auto
1239 (defvar verilog-imenu-generic-expression
1240 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
1241 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
1242 "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
1245 ;; provide a verilog-header function.
1246 ;; Customization variables:
1248 (defvar verilog-date-scientific-format nil
1249 "If non-nil, dates are written in scientific format (e.g. 1997/09/17).
1250 If nil, in European format (e.g. 17.09.1997). The brain-dead American
1251 format (e.g. 09/17/1997) is not supported.")
1253 (defvar verilog-company nil
1254 "Default name of Company for Verilog header.
1255 If set will become buffer local.")
1256 (make-variable-buffer-local 'verilog-company
)
1258 (defvar verilog-project nil
1259 "Default name of Project for Verilog header.
1260 If set will become buffer local.")
1261 (make-variable-buffer-local 'verilog-project
)
1263 (defvar verilog-mode-map
1264 (let ((map (make-sparse-keymap)))
1265 (define-key map
";" 'electric-verilog-semi
)
1266 (define-key map
[(control 59)] 'electric-verilog-semi-with-comment
)
1267 (define-key map
":" 'electric-verilog-colon
)
1268 ;;(define-key map "=" 'electric-verilog-equal)
1269 (define-key map
"\`" 'electric-verilog-tick
)
1270 (define-key map
"\t" 'electric-verilog-tab
)
1271 (define-key map
"\r" 'electric-verilog-terminate-line
)
1272 ;; backspace/delete key bindings
1273 (define-key map
[backspace] 'backward-delete-char-untabify)
1274 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
1275 (define-key map [delete] 'delete-char)
1276 (define-key map [(meta delete)] 'kill-word))
1277 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
1278 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
1279 (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
1280 (define-key map "\M-\t" 'verilog-complete-word)
1281 (define-key map "\M-?" 'verilog-show-completions)
1282 ;; Note \C-c and letter are reserved for users
1283 (define-key map "\C-c\`" 'verilog-lint-off)
1284 (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit)
1285 (define-key map "\C-c\?" 'verilog-diff-auto)
1286 (define-key map "\C-c\C-r" 'verilog-label-be)
1287 (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
1288 (define-key map "\C-c=" 'verilog-pretty-expr)
1289 (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
1290 (define-key map "\M-*" 'verilog-star-comment)
1291 (define-key map "\C-c\C-c" 'verilog-comment-region)
1292 (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1293 (when (featurep 'xemacs)
1294 (define-key map [(meta control h)] 'verilog-mark-defun)
1295 (define-key map "\M-\C-a" 'verilog-beg-of-defun)
1296 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1297 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1298 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1299 (define-key map "\C-c\C-a" 'verilog-auto)
1300 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1301 (define-key map "\C-c\C-p" 'verilog-preprocess)
1302 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1303 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1304 (define-key map "\C-c\C-h" 'verilog-header)
1306 "Keymap used in Verilog mode.")
1310 verilog-menu verilog-mode-map "Menu for Verilog mode"
1311 (verilog-easy-menu-filter
1313 ("Choose Compilation Action"
1316 (setq verilog-tool nil)
1317 (verilog-set-compile-command))
1319 :selected (equal verilog-tool nil)
1320 :help "When invoking compilation, use compile-command"]
1323 (setq verilog-tool 'verilog-linter)
1324 (verilog-set-compile-command))
1326 :selected (equal verilog-tool `verilog-linter)
1327 :help "When invoking compilation, use lint checker"]
1330 (setq verilog-tool 'verilog-coverage)
1331 (verilog-set-compile-command))
1333 :selected (equal verilog-tool `verilog-coverage)
1334 :help "When invoking compilation, annotate for coverage"]
1337 (setq verilog-tool 'verilog-simulator)
1338 (verilog-set-compile-command))
1340 :selected (equal verilog-tool `verilog-simulator)
1341 :help "When invoking compilation, interpret Verilog source"]
1344 (setq verilog-tool 'verilog-compiler)
1345 (verilog-set-compile-command))
1347 :selected (equal verilog-tool `verilog-compiler)
1348 :help "When invoking compilation, compile Verilog source"]
1351 (setq verilog-tool 'verilog-preprocessor)
1352 (verilog-set-compile-command))
1354 :selected (equal verilog-tool `verilog-preprocessor)
1355 :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1358 ["Beginning of function" verilog-beg-of-defun
1360 :help "Move backward to the beginning of the current function or procedure"]
1361 ["End of function" verilog-end-of-defun
1363 :help "Move forward to the end of the current function or procedure"]
1364 ["Mark function" verilog-mark-defun
1366 :help "Mark the current Verilog function or procedure"]
1367 ["Goto function/module" verilog-goto-defun
1368 :help "Move to specified Verilog module/task/function"]
1369 ["Move to beginning of block" electric-verilog-backward-sexp
1370 :help "Move backward over one balanced expression"]
1371 ["Move to end of block" electric-verilog-forward-sexp
1372 :help "Move forward over one balanced expression"]
1375 ["Comment Region" verilog-comment-region
1376 :help "Put marked area into a comment"]
1377 ["UnComment Region" verilog-uncomment-region
1378 :help "Uncomment an area commented with Comment Region"]
1379 ["Multi-line comment insert" verilog-star-comment
1380 :help "Insert Verilog /* */ comment at point"]
1381 ["Lint error to comment" verilog-lint-off
1382 :help "Convert a Verilog linter warning line into a disable statement"]
1386 :help "Perform compilation-action (above) on the current buffer"]
1387 ["AUTO, Save, Compile" verilog-auto-save-compile
1388 :help "Recompute AUTOs, save buffer, and compile"]
1389 ["Next Compile Error" next-error
1390 :help "Visit next compilation error message and corresponding source code"]
1391 ["Ignore Lint Warning at point" verilog-lint-off
1392 :help "Convert a Verilog linter warning line into a disable statement"]
1394 ["Line up declarations around point" verilog-pretty-declarations
1395 :help "Line up declarations around point"]
1396 ["Line up equations around point" verilog-pretty-expr
1397 :help "Line up expressions around point"]
1398 ["Redo/insert comments on every end" verilog-label-be
1399 :help "Label matching begin ... end statements"]
1400 ["Expand [x:y] vector line" verilog-expand-vector
1401 :help "Take a signal vector on the current line and expand it to multiple lines"]
1402 ["Insert begin-end block" verilog-insert-block
1403 :help "Insert begin ... end"]
1404 ["Complete word" verilog-complete-word
1405 :help "Complete word at point"]
1407 ["Recompute AUTOs" verilog-auto
1408 :help "Expand AUTO meta-comment statements"]
1409 ["Kill AUTOs" verilog-delete-auto
1410 :help "Remove AUTO expansions"]
1411 ["Diff AUTOs" verilog-diff-auto
1412 :help "Show differences in AUTO expansions"]
1413 ["Inject AUTOs" verilog-inject-auto
1414 :help "Inject AUTOs into legacy non-AUTO buffer"]
1416 ["AUTO General" (describe-function 'verilog-auto)
1417 :help "Help introduction on AUTOs"]
1418 ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
1419 :help "Help on verilog-library-flags"]
1420 ["AUTO Library Path" (describe-variable 'verilog-library-directories)
1421 :help "Help on verilog-library-directories"]
1422 ["AUTO Library Files" (describe-variable 'verilog-library-files)
1423 :help "Help on verilog-library-files"]
1424 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
1425 :help "Help on verilog-library-extensions"]
1426 ["AUTO `define Reading" (describe-function 'verilog-read-defines)
1427 :help "Help on reading `defines"]
1428 ["AUTO `include Reading" (describe-function 'verilog-read-includes)
1429 :help "Help on parsing `includes"]
1430 ["AUTOARG" (describe-function 'verilog-auto-arg)
1431 :help "Help on AUTOARG - declaring module port list"]
1432 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
1433 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1434 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
1435 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1436 ["AUTOINOUTIN" (describe-function 'verilog-auto-inout-in)
1437 :help "Help on AUTOINOUTCOMP - copying i/o from another file as all inputs"]
1438 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1439 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1440 ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
1441 :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
1442 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1443 :help "Help on AUTOINOUT - adding inouts from cells"]
1444 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1445 :help "Help on AUTOINPUT - adding inputs from cells"]
1446 ["AUTOINST" (describe-function 'verilog-auto-inst)
1447 :help "Help on AUTOINST - adding pins for cells"]
1448 ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
1449 :help "Help on expanding Verilog-2001 .* pins"]
1450 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
1451 :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
1452 ["AUTOLOGIC" (describe-function 'verilog-auto-logic)
1453 :help "Help on AUTOLOGIC - declaring logic signals"]
1454 ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
1455 :help "Help on AUTOOUTPUT - adding outputs from cells"]
1456 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
1457 :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
1458 ["AUTOREG" (describe-function 'verilog-auto-reg)
1459 :help "Help on AUTOREG - declaring registers for non-wires"]
1460 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
1461 :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
1462 ["AUTORESET" (describe-function 'verilog-auto-reset)
1463 :help "Help on AUTORESET - resetting always blocks"]
1464 ["AUTOSENSE" (describe-function 'verilog-auto-sense)
1465 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1466 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1467 :help "Help on AUTOTIEOFF - tying off unused outputs"]
1468 ["AUTOUNDEF" (describe-function 'verilog-auto-undef)
1469 :help "Help on AUTOUNDEF - undefine all local defines"]
1470 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1471 :help "Help on AUTOUNUSED - terminating unused inputs"]
1472 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
1473 :help "Help on AUTOWIRE - declaring wires for cells"]
1476 ["Submit bug report" verilog-submit-bug-report
1477 :help "Submit via mail a bug report on verilog-mode.el"]
1478 ["Version and FAQ" verilog-faq
1479 :help "Show the current version, and where to get the FAQ etc"]
1480 ["Customize Verilog Mode..." verilog-customize
1481 :help "Customize variables and other settings used by Verilog-Mode"]
1482 ["Customize Verilog Fonts & Colors" verilog-font-customize
1483 :help "Customize fonts used by Verilog-Mode."])))
1486 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1487 (verilog-easy-menu-filter
1489 ["Header" verilog-sk-header
1490 :help "Insert a header block at the top of file"]
1491 ["Comment" verilog-sk-comment
1492 :help "Insert a comment block"]
1494 ["Module" verilog-sk-module
1495 :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
1496 ["OVM Class" verilog-sk-ovm-class
1497 :help "Insert an OVM class block"]
1498 ["UVM Class" verilog-sk-uvm-class
1499 :help "Insert an UVM class block"]
1500 ["Primitive" verilog-sk-primitive
1501 :help "Insert a primitive .. (.. );.. endprimitive block"]
1503 ["Input" verilog-sk-input
1504 :help "Insert an input declaration"]
1505 ["Output" verilog-sk-output
1506 :help "Insert an output declaration"]
1507 ["Inout" verilog-sk-inout
1508 :help "Insert an inout declaration"]
1509 ["Wire" verilog-sk-wire
1510 :help "Insert a wire declaration"]
1511 ["Reg" verilog-sk-reg
1512 :help "Insert a register declaration"]
1513 ["Define thing under point as a register" verilog-sk-define-signal
1514 :help "Define signal under point as a register at the top of the module"]
1516 ["Initial" verilog-sk-initial
1517 :help "Insert an initial begin .. end block"]
1518 ["Always" verilog-sk-always
1519 :help "Insert an always @(AS) begin .. end block"]
1520 ["Function" verilog-sk-function
1521 :help "Insert a function .. begin .. end endfunction block"]
1522 ["Task" verilog-sk-task
1523 :help "Insert a task .. begin .. end endtask block"]
1524 ["Specify" verilog-sk-specify
1525 :help "Insert a specify .. endspecify block"]
1526 ["Generate" verilog-sk-generate
1527 :help "Insert a generate .. endgenerate block"]
1529 ["Begin" verilog-sk-begin
1530 :help "Insert a begin .. end block"]
1532 :help "Insert an if (..) begin .. end block"]
1533 ["(if) else" verilog-sk-else-if
1534 :help "Insert an else if (..) begin .. end block"]
1535 ["For" verilog-sk-for
1536 :help "Insert a for (...) begin .. end block"]
1537 ["While" verilog-sk-while
1538 :help "Insert a while (...) begin .. end block"]
1539 ["Fork" verilog-sk-fork
1540 :help "Insert a fork begin .. end .. join block"]
1541 ["Repeat" verilog-sk-repeat
1542 :help "Insert a repeat (..) begin .. end block"]
1543 ["Case" verilog-sk-case
1544 :help "Insert a case block, prompting for details"]
1545 ["Casex" verilog-sk-casex
1546 :help "Insert a casex (...) item: begin.. end endcase block"]
1547 ["Casez" verilog-sk-casez
1548 :help "Insert a casez (...) item: begin.. end endcase block"])))
1550 (defvar verilog-mode-abbrev-table nil
1551 "Abbrev table in use in Verilog-mode buffers.")
1553 (define-abbrev-table 'verilog-mode-abbrev-table ())
1554 (verilog-define-abbrev verilog-mode-abbrev-table "class" "" 'verilog-sk-ovm-class)
1555 (verilog-define-abbrev verilog-mode-abbrev-table "always" "" 'verilog-sk-always)
1556 (verilog-define-abbrev verilog-mode-abbrev-table "begin" nil `verilog-sk-begin)
1557 (verilog-define-abbrev verilog-mode-abbrev-table "case" "" `verilog-sk-case)
1558 (verilog-define-abbrev verilog-mode-abbrev-table "for" "" `verilog-sk-for)
1559 (verilog-define-abbrev verilog-mode-abbrev-table "generate" "" `verilog-sk-generate)
1560 (verilog-define-abbrev verilog-mode-abbrev-table "initial" "" `verilog-sk-initial)
1561 (verilog-define-abbrev verilog-mode-abbrev-table "fork" "" `verilog-sk-fork)
1562 (verilog-define-abbrev verilog-mode-abbrev-table "module" "" `verilog-sk-module)
1563 (verilog-define-abbrev verilog-mode-abbrev-table "primitive" "" `verilog-sk-primitive)
1564 (verilog-define-abbrev verilog-mode-abbrev-table "repeat" "" `verilog-sk-repeat)
1565 (verilog-define-abbrev verilog-mode-abbrev-table "specify" "" `verilog-sk-specify)
1566 (verilog-define-abbrev verilog-mode-abbrev-table "task" "" `verilog-sk-task)
1567 (verilog-define-abbrev verilog-mode-abbrev-table "while" "" `verilog-sk-while)
1568 (verilog-define-abbrev verilog-mode-abbrev-table "casex" "" `verilog-sk-casex)
1569 (verilog-define-abbrev verilog-mode-abbrev-table "casez" "" `verilog-sk-casez)
1570 (verilog-define-abbrev verilog-mode-abbrev-table "if" "" `verilog-sk-if)
1571 (verilog-define-abbrev verilog-mode-abbrev-table "else if" "" `verilog-sk-else-if)
1572 (verilog-define-abbrev verilog-mode-abbrev-table "assign" "" `verilog-sk-assign)
1573 (verilog-define-abbrev verilog-mode-abbrev-table "function" "" `verilog-sk-function)
1574 (verilog-define-abbrev verilog-mode-abbrev-table "input" "" `verilog-sk-input)
1575 (verilog-define-abbrev verilog-mode-abbrev-table "output" "" `verilog-sk-output)
1576 (verilog-define-abbrev verilog-mode-abbrev-table "inout" "" `verilog-sk-inout)
1577 (verilog-define-abbrev verilog-mode-abbrev-table "wire" "" `verilog-sk-wire)
1578 (verilog-define-abbrev verilog-mode-abbrev-table "reg" "" `verilog-sk-reg)
1584 (defsubst verilog-within-string ()
1585 (nth 3 (parse-partial-sexp (point-at-bol) (point))))
1587 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1588 "Replace occurrences of FROM-STRING with TO-STRING.
1589 FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace.
1590 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1591 will break, as the o's continuously replace. xa -> x works ok though."
1592 ;; Hopefully soon to an Emacs built-in
1593 ;; Also note \ in the replacement prevent multiple replacements; IE
1594 ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
1595 ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
1597 (while (string-match from-string string start)
1598 (setq string (replace-match to-string fixedcase literal string)
1599 start (min (length string) (+ (match-beginning 0) (length to-string)))))
1602 (defsubst verilog-string-remove-spaces (string)
1603 "Remove spaces surrounding STRING."
1605 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
1606 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
1609 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
1610 ; checkdoc-params: (REGEXP BOUND NOERROR)
1611 "Like `re-search-forward', but skips over match in comments or strings."
1612 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1614 (re-search-forward REGEXP BOUND NOERROR)
1615 (setq mdata (match-data))
1616 (and (verilog-skip-forward-comment-or-string)
1618 (setq mdata '(nil nil))
1622 (store-match-data mdata)
1625 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
1626 ; checkdoc-params: (REGEXP BOUND NOERROR)
1627 "Like `re-search-backward', but skips over match in comments or strings."
1628 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1630 (re-search-backward REGEXP BOUND NOERROR)
1631 (setq mdata (match-data))
1632 (and (verilog-skip-backward-comment-or-string)
1634 (setq mdata '(nil nil))
1638 (store-match-data mdata)
1641 (defsubst verilog-re-search-forward-quick (regexp bound noerror)
1642 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
1643 but trashes match data and is faster for REGEXP that doesn't match often.
1644 This uses `verilog-scan' and text properties to ignore comments,
1645 so there may be a large up front penalty for the first search."
1647 (while (and (not pt)
1648 (re-search-forward regexp bound noerror))
1649 (if (verilog-inside-comment-or-string-p)
1650 (re-search-forward "[/\"\n]" nil t) ;; Only way a comment or quote can end
1651 (setq pt (match-end 0))))
1654 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
1655 ; checkdoc-params: (REGEXP BOUND NOERROR)
1656 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
1657 but trashes match data and is faster for REGEXP that doesn't match often.
1658 This uses `verilog-scan' and text properties to ignore comments,
1659 so there may be a large up front penalty for the first search."
1661 (while (and (not pt)
1662 (re-search-backward regexp bound noerror))
1663 (if (verilog-inside-comment-or-string-p)
1664 (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
1665 (setq pt (match-beginning 0))))
1668 (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
1669 "Like `re-search-forward', but first search for SUBSTR constant.
1670 Then searched for the normal REGEXP (which contains SUBSTR), with given
1671 BOUND and NOERROR. The REGEXP must fit within a single line.
1672 This speeds up complicated regexp matches."
1673 ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
1674 ;; thus require matches to be on one line, and use beginning-of-line.
1676 (while (and (not done)
1677 (search-forward substr bound noerror))
1680 (setq done (re-search-forward regexp (point-at-eol) noerror)))
1681 (unless (and (<= (match-beginning 0) (point))
1682 (>= (match-end 0) (point)))
1684 (when done (goto-char done))
1686 ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1688 (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
1689 "Like `re-search-backward', but first search for SUBSTR constant.
1690 Then searched for the normal REGEXP (which contains SUBSTR), with given
1691 BOUND and NOERROR. The REGEXP must fit within a single line.
1692 This speeds up complicated regexp matches."
1693 ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
1694 ;; thus require matches to be on one line, and use beginning-of-line.
1696 (while (and (not done)
1697 (search-backward substr bound noerror))
1700 (setq done (re-search-backward regexp (point-at-bol) noerror)))
1701 (unless (and (<= (match-beginning 0) (point))
1702 (>= (match-end 0) (point)))
1704 (when done (goto-char done))
1706 ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1708 (defun verilog-delete-trailing-whitespace ()
1709 "Delete trailing spaces or tabs, but not newlines nor linefeeds."
1710 ;; Similar to `delete-trailing-whitespace' but that's not present in XEmacs
1712 (goto-char (point-min))
1713 (while (re-search-forward "[ \t]+$" nil t) ;; Not syntactic WS as no formfeed
1714 (replace-match "" nil nil))))
1716 (defvar compile-command)
1718 ;; compilation program
1719 (defun verilog-set-compile-command ()
1720 "Function to compute shell command to compile Verilog.
1722 This reads `verilog-tool' and sets `compile-command'. This specifies the
1723 program that executes when you type \\[compile] or
1724 \\[verilog-auto-save-compile].
1726 By default `verilog-tool' uses a Makefile if one exists in the
1727 current directory. If not, it is set to the `verilog-linter',
1728 `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
1729 or `verilog-simulator' variables, as selected with the Verilog ->
1730 \"Choose Compilation Action\" menu.
1732 You should set `verilog-tool' or the other variables to the path and
1733 arguments for your Verilog simulator. For example:
1736 \"(cd /tmp; surecov %s)\".
1738 In the former case, the path to the current buffer is concat'ed to the
1739 value of `verilog-tool'; in the later, the path to the current buffer is
1740 substituted for the %s.
1742 Where __FLAGS__ appears in the string `verilog-current-flags'
1743 will be substituted.
1745 Where __FILE__ appears in the string, the variable
1746 `buffer-file-name' of the current buffer, without the directory
1747 portion, will be substituted."
1750 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1751 (file-exists-p "Makefile"))
1752 (set (make-local-variable 'compile-command) "make "))
1754 (set (make-local-variable 'compile-command)
1756 (if (string-match "%s" (eval verilog-tool))
1757 (format (eval verilog-tool) (or buffer-file-name ""))
1758 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1760 (verilog-modify-compile-command))
1762 (defun verilog-expand-command (command)
1763 "Replace meta-information in COMMAND and return it.
1764 Where __FLAGS__ appears in the string `verilog-current-flags'
1765 will be substituted. Where __FILE__ appears in the string, the
1766 current buffer's file-name, without the directory portion, will
1768 (setq command (verilog-string-replace-matches
1769 ;; Note \\b only works if under verilog syntax table
1770 "\\b__FLAGS__\\b" (verilog-current-flags)
1772 (setq command (verilog-string-replace-matches
1773 "\\b__FILE__\\b" (file-name-nondirectory
1774 (or (buffer-file-name) ""))
1778 (defun verilog-modify-compile-command ()
1779 "Update `compile-command' using `verilog-expand-command'."
1781 (stringp compile-command)
1782 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1783 (set (make-local-variable 'compile-command)
1784 (verilog-expand-command compile-command))))
1786 (if (featurep 'xemacs)
1787 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1788 (defun verilog-error-regexp-add-xemacs ()
1789 "Teach XEmacs about verilog errors.
1790 Called by `compilation-mode-hook'. This allows \\[next-error] to
1793 (if (boundp 'compilation-error-regexp-systems-alist)
1795 (not (equal compilation-error-regexp-systems-list 'all))
1796 (not (member compilation-error-regexp-systems-list 'verilog)))
1797 (push 'verilog compilation-error-regexp-systems-list)))
1798 (if (boundp 'compilation-error-regexp-alist-alist)
1799 (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
1800 (setcdr compilation-error-regexp-alist-alist
1801 (cons verilog-error-regexp-xemacs-alist
1802 (cdr compilation-error-regexp-alist-alist)))))
1803 (if (boundp 'compilation-font-lock-keywords)
1805 (set (make-local-variable 'compilation-font-lock-keywords)
1806 verilog-error-font-lock-keywords)
1807 (font-lock-set-defaults)))
1808 ;; Need to re-run compilation-error-regexp builder
1809 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
1810 (compilation-build-compilation-error-regexp-alist))
1813 ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
1814 (defun verilog-error-regexp-add-emacs ()
1815 "Tell Emacs compile that we are Verilog.
1816 Called by `compilation-mode-hook'. This allows \\[next-error] to
1819 (if (boundp 'compilation-error-regexp-alist-alist)
1821 (if (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
1824 (push (car item) compilation-error-regexp-alist)
1825 (push item compilation-error-regexp-alist-alist)
1827 verilog-error-regexp-emacs-alist)))))
1829 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
1830 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
1832 (defconst verilog-directive-re
1834 (verilog-regexp-words
1836 "`case" "`default" "`define" "`else" "`elsif" "`endfor" "`endif"
1837 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
1838 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
1839 "`time_scale" "`undef" "`while" ))))
1841 (defconst verilog-directive-re-1
1842 (concat "[ \t]*" verilog-directive-re))
1844 (defconst verilog-directive-begin
1845 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
1847 (defconst verilog-directive-middle
1848 "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
1850 (defconst verilog-directive-end
1851 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
1853 (defconst verilog-ovm-begin-re
1857 "`ovm_component_utils_begin"
1858 "`ovm_component_param_utils_begin"
1859 "`ovm_field_utils_begin"
1860 "`ovm_object_utils_begin"
1861 "`ovm_object_param_utils_begin"
1862 "`ovm_sequence_utils_begin"
1863 "`ovm_sequencer_utils_begin"
1866 (defconst verilog-ovm-end-re
1870 "`ovm_component_utils_end"
1871 "`ovm_field_utils_end"
1872 "`ovm_object_utils_end"
1873 "`ovm_sequence_utils_end"
1874 "`ovm_sequencer_utils_end"
1877 (defconst verilog-uvm-begin-re
1881 "`uvm_component_utils_begin"
1882 "`uvm_component_param_utils_begin"
1883 "`uvm_field_utils_begin"
1884 "`uvm_object_utils_begin"
1885 "`uvm_object_param_utils_begin"
1886 "`uvm_sequence_utils_begin"
1887 "`uvm_sequencer_utils_begin"
1890 (defconst verilog-uvm-end-re
1894 "`uvm_component_utils_end"
1895 "`uvm_field_utils_end"
1896 "`uvm_object_utils_end"
1897 "`uvm_sequence_utils_end"
1898 "`uvm_sequencer_utils_end"
1901 (defconst verilog-vmm-begin-re
1905 "`vmm_data_member_begin"
1906 "`vmm_env_member_begin"
1907 "`vmm_scenario_member_begin"
1908 "`vmm_subenv_member_begin"
1909 "`vmm_xactor_member_begin"
1912 (defconst verilog-vmm-end-re
1916 "`vmm_data_member_end"
1917 "`vmm_env_member_end"
1918 "`vmm_scenario_member_end"
1919 "`vmm_subenv_member_end"
1920 "`vmm_xactor_member_end"
1923 (defconst verilog-vmm-statement-re
1927 ;; "`vmm_xactor_member_enum_array"
1928 "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
1929 ;; "`vmm_xactor_member_scalar_array"
1930 ;; "`vmm_xactor_member_scalar"
1933 (defconst verilog-ovm-statement-re
1942 "`ovm_analysis_imp_decl"
1943 "`ovm_blocking_get_imp_decl"
1944 "`ovm_blocking_get_peek_imp_decl"
1945 "`ovm_blocking_master_imp_decl"
1946 "`ovm_blocking_peek_imp_decl"
1947 "`ovm_blocking_put_imp_decl"
1948 "`ovm_blocking_slave_imp_decl"
1949 "`ovm_blocking_transport_imp_decl"
1950 "`ovm_component_registry"
1951 "`ovm_component_registry_param"
1952 "`ovm_component_utils"
1955 "`ovm_declare_sequence_lib"
1962 "`ovm_field_aa_int_byte"
1963 "`ovm_field_aa_int_byte_unsigned"
1964 "`ovm_field_aa_int_int"
1965 "`ovm_field_aa_int_int_unsigned"
1966 "`ovm_field_aa_int_integer"
1967 "`ovm_field_aa_int_integer_unsigned"
1968 "`ovm_field_aa_int_key"
1969 "`ovm_field_aa_int_longint"
1970 "`ovm_field_aa_int_longint_unsigned"
1971 "`ovm_field_aa_int_shortint"
1972 "`ovm_field_aa_int_shortint_unsigned"
1973 "`ovm_field_aa_int_string"
1974 "`ovm_field_aa_object_int"
1975 "`ovm_field_aa_object_string"
1976 "`ovm_field_aa_string_int"
1977 "`ovm_field_aa_string_string"
1978 "`ovm_field_array_int"
1979 "`ovm_field_array_object"
1980 "`ovm_field_array_string"
1985 "`ovm_field_queue_int"
1986 "`ovm_field_queue_object"
1987 "`ovm_field_queue_string"
1988 "`ovm_field_sarray_int"
1993 "`ovm_get_peek_imp_decl"
2000 "`ovm_master_imp_decl"
2002 "`ovm_non_blocking_transport_imp_decl"
2003 "`ovm_nonblocking_get_imp_decl"
2004 "`ovm_nonblocking_get_peek_imp_decl"
2005 "`ovm_nonblocking_master_imp_decl"
2006 "`ovm_nonblocking_peek_imp_decl"
2007 "`ovm_nonblocking_put_imp_decl"
2008 "`ovm_nonblocking_slave_imp_decl"
2009 "`ovm_object_registry"
2010 "`ovm_object_registry_param"
2012 "`ovm_peek_imp_decl"
2013 "`ovm_phase_func_decl"
2014 "`ovm_phase_task_decl"
2015 "`ovm_print_aa_int_object"
2016 "`ovm_print_aa_string_int"
2017 "`ovm_print_aa_string_object"
2018 "`ovm_print_aa_string_string"
2019 "`ovm_print_array_int"
2020 "`ovm_print_array_object"
2021 "`ovm_print_array_string"
2022 "`ovm_print_object_queue"
2023 "`ovm_print_queue_int"
2024 "`ovm_print_string_queue"
2027 "`ovm_rand_send_with"
2029 "`ovm_sequence_utils"
2030 "`ovm_slave_imp_decl"
2031 "`ovm_transport_imp_decl"
2032 "`ovm_update_sequence_lib"
2033 "`ovm_update_sequence_lib_and_item"
2036 "`static_message") nil )))
2038 (defconst verilog-uvm-statement-re
2043 "`uvm_analysis_imp_decl"
2044 "`uvm_blocking_get_imp_decl"
2045 "`uvm_blocking_get_peek_imp_decl"
2046 "`uvm_blocking_master_imp_decl"
2047 "`uvm_blocking_peek_imp_decl"
2048 "`uvm_blocking_put_imp_decl"
2049 "`uvm_blocking_slave_imp_decl"
2050 "`uvm_blocking_transport_imp_decl"
2051 "`uvm_component_param_utils"
2052 "`uvm_component_registry"
2053 "`uvm_component_registry_param"
2054 "`uvm_component_utils"
2057 "`uvm_create_seq" ;; Undocumented in 1.1
2058 "`uvm_declare_p_sequencer"
2059 "`uvm_declare_sequence_lib" ;; Deprecated in 1.1
2062 "`uvm_do_callbacks_exit_on"
2063 "`uvm_do_obj_callbacks"
2064 "`uvm_do_obj_callbacks_exit_on"
2067 "`uvm_do_on_pri_with"
2071 "`uvm_do_seq" ;; Undocumented in 1.1
2072 "`uvm_do_seq_with" ;; Undocumented in 1.1
2075 "`uvm_error_context"
2077 "`uvm_fatal_context"
2078 "`uvm_field_aa_int_byte"
2079 "`uvm_field_aa_int_byte_unsigned"
2080 "`uvm_field_aa_int_enum"
2081 "`uvm_field_aa_int_int"
2082 "`uvm_field_aa_int_int_unsigned"
2083 "`uvm_field_aa_int_integer"
2084 "`uvm_field_aa_int_integer_unsigned"
2085 "`uvm_field_aa_int_key"
2086 "`uvm_field_aa_int_longint"
2087 "`uvm_field_aa_int_longint_unsigned"
2088 "`uvm_field_aa_int_shortint"
2089 "`uvm_field_aa_int_shortint_unsigned"
2090 "`uvm_field_aa_int_string"
2091 "`uvm_field_aa_object_int"
2092 "`uvm_field_aa_object_string"
2093 "`uvm_field_aa_string_int"
2094 "`uvm_field_aa_string_string"
2095 "`uvm_field_array_enum"
2096 "`uvm_field_array_int"
2097 "`uvm_field_array_object"
2098 "`uvm_field_array_string"
2103 "`uvm_field_queue_enum"
2104 "`uvm_field_queue_int"
2105 "`uvm_field_queue_object"
2106 "`uvm_field_queue_string"
2108 "`uvm_field_sarray_enum"
2109 "`uvm_field_sarray_int"
2110 "`uvm_field_sarray_object"
2111 "`uvm_field_sarray_string"
2114 "`uvm_file" ;; Undocumented in 1.1, use `__FILE__
2116 "`uvm_get_peek_imp_decl"
2119 "`uvm_line" ;; Undocumented in 1.1, use `__LINE__
2120 "`uvm_master_imp_decl"
2121 "`uvm_non_blocking_transport_imp_decl" ;; Deprecated in 1.1
2122 "`uvm_nonblocking_get_imp_decl"
2123 "`uvm_nonblocking_get_peek_imp_decl"
2124 "`uvm_nonblocking_master_imp_decl"
2125 "`uvm_nonblocking_peek_imp_decl"
2126 "`uvm_nonblocking_put_imp_decl"
2127 "`uvm_nonblocking_slave_imp_decl"
2128 "`uvm_nonblocking_transport_imp_decl"
2129 "`uvm_object_param_utils"
2130 "`uvm_object_registry"
2131 "`uvm_object_registry_param" ;; Undocumented in 1.1
2145 "`uvm_peek_imp_decl"
2148 "`uvm_rand_send_pri"
2149 "`uvm_rand_send_pri_with"
2150 "`uvm_rand_send_with"
2151 "`uvm_record_attribute"
2156 "`uvm_sequence_utils" ;; Deprecated in 1.1
2157 "`uvm_set_super_type"
2158 "`uvm_slave_imp_decl"
2159 "`uvm_transport_imp_decl"
2161 "`uvm_unpack_arrayN"
2167 "`uvm_unpack_queueN"
2169 "`uvm_unpack_sarray"
2170 "`uvm_unpack_sarrayN"
2171 "`uvm_unpack_string"
2172 "`uvm_update_sequence_lib" ;; Deprecated in 1.1
2173 "`uvm_update_sequence_lib_and_item" ;; Deprecated in 1.1
2175 "`uvm_warning_context") nil )))
2179 ;; Regular expressions used to calculate indent, etc.
2181 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
2188 (defconst verilog-assignment-operator-re
2192 ;; blocking assignment_operator
2193 "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
2194 ;; non blocking assignment operator
2197 "==" "!=" "===" "!===" "<=" ">=" "==\?" "!=\?"
2202 ;; Is this a legal verilog operator?
2206 (defconst verilog-assignment-operation-re
2208 ; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)"
2209 ; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)"
2210 "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" ))
2212 (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
2213 (defconst verilog-property-re
2214 (concat "\\(" verilog-label-re "\\)?"
2215 "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
2216 ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
2218 (defconst verilog-no-indent-begin-re
2219 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>")
2221 (defconst verilog-ends-re
2222 ;; Parenthesis indicate type of keyword found
2224 "\\(\\<else\\>\\)\\|" ; 1
2225 "\\(\\<if\\>\\)\\|" ; 2
2226 "\\(\\<assert\\>\\)\\|" ; 3
2227 "\\(\\<end\\>\\)\\|" ; 3.1
2228 "\\(\\<endcase\\>\\)\\|" ; 4
2229 "\\(\\<endfunction\\>\\)\\|" ; 5
2230 "\\(\\<endtask\\>\\)\\|" ; 6
2231 "\\(\\<endspecify\\>\\)\\|" ; 7
2232 "\\(\\<endtable\\>\\)\\|" ; 8
2233 "\\(\\<endgenerate\\>\\)\\|" ; 9
2234 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
2235 "\\(\\<endclass\\>\\)\\|" ; 11
2236 "\\(\\<endgroup\\>\\)\\|" ; 12
2238 "\\(\\<`vmm_data_member_end\\>\\)\\|"
2239 "\\(\\<`vmm_env_member_end\\>\\)\\|"
2240 "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
2241 "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
2242 "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
2244 "\\(\\<`ovm_component_utils_end\\>\\)\\|"
2245 "\\(\\<`ovm_field_utils_end\\>\\)\\|"
2246 "\\(\\<`ovm_object_utils_end\\>\\)\\|"
2247 "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
2248 "\\(\\<`ovm_sequencer_utils_end\\>\\)"
2250 "\\(\\<`uvm_component_utils_end\\>\\)\\|"
2251 "\\(\\<`uvm_field_utils_end\\>\\)\\|"
2252 "\\(\\<`uvm_object_utils_end\\>\\)\\|"
2253 "\\(\\<`uvm_sequence_utils_end\\>\\)\\|"
2254 "\\(\\<`uvm_sequencer_utils_end\\>\\)"
2257 (defconst verilog-auto-end-comment-lines-re
2258 ;; Matches to names in this list cause auto-end-commenting
2260 verilog-directive-re "\\)\\|\\("
2262 (verilog-regexp-words
2290 ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
2291 ;;; verilog-end-block-ordered-re matches exactly the same strings.
2292 (defconst verilog-end-block-ordered-re
2293 ;; Parenthesis indicate type of keyword found
2294 (concat "\\(\\<endcase\\>\\)\\|" ; 1
2295 "\\(\\<end\\>\\)\\|" ; 2
2296 "\\(\\<end" ; 3, but not used
2297 "\\(" ; 4, but not used
2298 "\\(function\\)\\|" ; 5
2300 "\\(module\\)\\|" ; 7
2301 "\\(primitive\\)\\|" ; 8
2302 "\\(interface\\)\\|" ; 9
2303 "\\(package\\)\\|" ; 10
2304 "\\(class\\)\\|" ; 11
2305 "\\(group\\)\\|" ; 12
2306 "\\(program\\)\\|" ; 13
2307 "\\(sequence\\)\\|" ; 14
2308 "\\(clocking\\)\\|" ; 15
2310 (defconst verilog-end-block-re
2312 (verilog-regexp-words
2314 `("end" ;; closes begin
2315 "endcase" ;; closes any of case, casex casez or randcase
2316 "join" "join_any" "join_none" ;; closes fork
2331 "`ovm_component_utils_end"
2332 "`ovm_field_utils_end"
2333 "`ovm_object_utils_end"
2334 "`ovm_sequence_utils_end"
2335 "`ovm_sequencer_utils_end"
2337 "`uvm_component_utils_end"
2338 "`uvm_field_utils_end"
2339 "`uvm_object_utils_end"
2340 "`uvm_sequence_utils_end"
2341 "`uvm_sequencer_utils_end"
2343 "`vmm_data_member_end"
2344 "`vmm_env_member_end"
2345 "`vmm_scenario_member_end"
2346 "`vmm_subenv_member_end"
2347 "`vmm_xactor_member_end"
2351 (defconst verilog-endcomment-reason-re
2352 ;; Parenthesis indicate type of keyword found
2354 "\\(\\<begin\\>\\)\\|" ; 1
2355 "\\(\\<else\\>\\)\\|" ; 2
2356 "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
2357 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" ; 4
2358 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" ; 5
2359 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" ; 6
2360 "\\(\\<fork\\>\\)\\|" ; 7
2361 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
2363 verilog-property-re "\\|"
2364 "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
2365 "\\(\\<clocking\\>\\)\\|"
2366 "\\(\\<task\\>\\)\\|"
2367 "\\(\\<function\\>\\)\\|"
2368 "\\(\\<initial\\>\\)\\|"
2369 "\\(\\<interface\\>\\)\\|"
2370 "\\(\\<package\\>\\)\\|"
2371 "\\(\\<final\\>\\)\\|"
2373 "\\(\\<while\\>\\)\\|"
2374 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
2375 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
2378 (defconst verilog-named-block-re "begin[ \t]*:")
2380 ;; These words begin a block which can occur inside a module which should be indented,
2381 ;; and closed with the respective word from the end-block list
2383 (defconst verilog-beg-block-re
2385 (verilog-regexp-words
2387 "case" "casex" "casez" "randcase"
2397 "`ovm_component_utils_begin"
2398 "`ovm_component_param_utils_begin"
2399 "`ovm_field_utils_begin"
2400 "`ovm_object_utils_begin"
2401 "`ovm_object_param_utils_begin"
2402 "`ovm_sequence_utils_begin"
2403 "`ovm_sequencer_utils_begin"
2405 "`uvm_component_utils_begin"
2406 "`uvm_component_param_utils_begin"
2407 "`uvm_field_utils_begin"
2408 "`uvm_object_utils_begin"
2409 "`uvm_object_param_utils_begin"
2410 "`uvm_sequence_utils_begin"
2411 "`uvm_sequencer_utils_begin"
2413 "`vmm_data_member_begin"
2414 "`vmm_env_member_begin"
2415 "`vmm_scenario_member_begin"
2416 "`vmm_subenv_member_begin"
2417 "`vmm_xactor_member_begin"
2419 ;; These are the same words, in a specific order in the regular
2420 ;; expression so that matching will work nicely for
2421 ;; verilog-forward-sexp and verilog-calc-indent
2422 (defconst verilog-beg-block-re-ordered
2423 ( concat "\\(\\<begin\\>\\)" ;1
2424 "\\|\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
2425 "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
2426 "\\|\\(\\<class\\>\\)" ;6
2427 "\\|\\(\\<table\\>\\)" ;7
2428 "\\|\\(\\<specify\\>\\)" ;8
2429 "\\|\\(\\<function\\>\\)" ;9
2430 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<function\\>\\)" ;10
2431 "\\|\\(\\<task\\>\\)" ;14
2432 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;15
2433 "\\|\\(\\<generate\\>\\)" ;18
2434 "\\|\\(\\<covergroup\\>\\)" ;16 20
2435 "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17 21
2436 "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25
2437 "\\|\\(\\<clocking\\>\\)" ;22 27
2438 "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;28
2439 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
2443 (defconst verilog-end-block-ordered-rry
2444 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2445 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
2446 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2447 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
2448 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
2449 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
2450 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
2451 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
2452 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
2453 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
2454 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
2455 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
2456 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
2459 (defconst verilog-nameable-item-re
2461 (verilog-regexp-words
2464 "join" "join_any" "join_none"
2481 (defconst verilog-declaration-opener
2483 (verilog-regexp-words
2484 `("module" "begin" "task" "function"))))
2486 (defconst verilog-declaration-prefix-re
2488 (verilog-regexp-words
2491 "inout" "input" "output" "ref"
2493 "const" "static" "protected" "local"
2495 "localparam" "parameter" "var"
2499 (defconst verilog-declaration-core-re
2501 (verilog-regexp-words
2503 ;; port direction (by themselves)
2504 "inout" "input" "output"
2505 ;; integer_atom_type
2506 "byte" "shortint" "int" "longint" "integer" "time"
2507 ;; integer_vector_type
2510 "shortreal" "real" "realtime"
2512 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
2514 "string" "event" "chandle" "virtual" "enum" "genvar"
2517 "mailbox" "semaphore"
2519 (defconst verilog-declaration-re
2520 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
2521 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
2522 (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?")
2523 (defconst verilog-optional-signed-range-re
2525 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
2526 (defconst verilog-macroexp-re "`\\sw+")
2528 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
2529 (defconst verilog-declaration-re-2-no-macro
2530 (concat "\\s-*" verilog-declaration-re
2531 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2533 (defconst verilog-declaration-re-2-macro
2534 (concat "\\s-*" verilog-declaration-re
2535 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2536 "\\|\\(" verilog-macroexp-re "\\)"
2538 (defconst verilog-declaration-re-1-macro
2539 (concat "^" verilog-declaration-re-2-macro))
2541 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
2543 (defconst verilog-defun-re
2544 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
2545 (defconst verilog-end-defun-re
2546 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
2547 (defconst verilog-zero-indent-re
2548 (concat verilog-defun-re "\\|" verilog-end-defun-re))
2549 (defconst verilog-inst-comment-re
2550 (eval-when-compile (verilog-regexp-words `("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced"))))
2552 (defconst verilog-behavioral-block-beg-re
2553 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
2554 "function" "task"))))
2555 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
2556 (defconst verilog-indent-re
2558 (verilog-regexp-words
2561 "always" "always_latch" "always_ff" "always_comb"
2563 ; "unique" "priority"
2564 "case" "casex" "casez" "randcase" "endcase"
2566 "clocking" "endclocking"
2567 "config" "endconfig"
2568 "covergroup" "endgroup"
2569 "fork" "join" "join_any" "join_none"
2570 "function" "endfunction"
2572 "generate" "endgenerate"
2574 "interface" "endinterface"
2575 "module" "macromodule" "endmodule"
2576 "package" "endpackage"
2577 "primitive" "endprimitive"
2578 "program" "endprogram"
2579 "property" "endproperty"
2580 "sequence" "randsequence" "endsequence"
2581 "specify" "endspecify"
2588 "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
2589 "`while" "`endwhile"
2594 "`protect" "`endprotect"
2595 "`switch" "`endswitch"
2599 "`ovm_component_utils_begin"
2600 "`ovm_component_param_utils_begin"
2601 "`ovm_field_utils_begin"
2602 "`ovm_object_utils_begin"
2603 "`ovm_object_param_utils_begin"
2604 "`ovm_sequence_utils_begin"
2605 "`ovm_sequencer_utils_begin"
2607 "`ovm_component_utils_end"
2608 "`ovm_field_utils_end"
2609 "`ovm_object_utils_end"
2610 "`ovm_sequence_utils_end"
2611 "`ovm_sequencer_utils_end"
2613 "`uvm_component_utils_begin"
2614 "`uvm_component_param_utils_begin"
2615 "`uvm_field_utils_begin"
2616 "`uvm_object_utils_begin"
2617 "`uvm_object_param_utils_begin"
2618 "`uvm_sequence_utils_begin"
2619 "`uvm_sequencer_utils_begin"
2621 "`uvm_component_utils_end" ;; Typo in spec, it's not uvm_component_end
2622 "`uvm_field_utils_end"
2623 "`uvm_object_utils_end"
2624 "`uvm_sequence_utils_end"
2625 "`uvm_sequencer_utils_end"
2627 "`vmm_data_member_begin"
2628 "`vmm_env_member_begin"
2629 "`vmm_scenario_member_begin"
2630 "`vmm_subenv_member_begin"
2631 "`vmm_xactor_member_begin"
2633 "`vmm_data_member_end"
2634 "`vmm_env_member_end"
2635 "`vmm_scenario_member_end"
2636 "`vmm_subenv_member_end"
2637 "`vmm_xactor_member_end"
2640 (defconst verilog-defun-level-not-generate-re
2642 (verilog-regexp-words
2643 `( "module" "macromodule" "primitive" "class" "program"
2644 "interface" "package" "config"))))
2646 (defconst verilog-defun-level-re
2648 (verilog-regexp-words
2650 `( "module" "macromodule" "primitive" "class" "program"
2651 "interface" "package" "config")
2652 `( "initial" "final" "always" "always_comb" "always_ff"
2653 "always_latch" "endtask" "endfunction" )))))
2655 (defconst verilog-defun-level-generate-only-re
2657 (verilog-regexp-words
2658 `( "initial" "final" "always" "always_comb" "always_ff"
2659 "always_latch" "endtask" "endfunction" ))))
2661 (defconst verilog-cpp-level-re
2663 (verilog-regexp-words
2665 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2667 (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
2668 (defconst verilog-extended-case-re "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
2669 (defconst verilog-extended-complete-re
2670 (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
2671 "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
2672 "\\|\\(\\(\\<import\\>\\s-+\\)?\\(\"DPI-C\"\\s-+\\)?\\(\\<pure\\>\\s-+\\)?\\(function\\>\\|task\\>\\)\\)"
2673 "\\|" verilog-extended-case-re ))
2674 (defconst verilog-basic-complete-re
2676 (verilog-regexp-words
2678 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
2679 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
2680 "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
2682 (defconst verilog-complete-reg
2684 verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)"))
2686 (defconst verilog-end-statement-re
2687 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
2688 verilog-end-block-re "\\)"))
2690 (defconst verilog-endcase-re
2691 (concat verilog-extended-case-re "\\|"
2696 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
2697 "String used to mark beginning of excluded text.")
2698 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
2699 "String used to mark end of excluded text.")
2700 (defconst verilog-preprocessor-re
2702 (verilog-regexp-words
2704 "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else"
2707 (defconst verilog-keywords
2708 '( "`case" "`default" "`define" "`else" "`endfor" "`endif"
2709 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
2710 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
2711 "`time_scale" "`undef" "`while"
2713 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
2714 "assert" "assign" "assume" "automatic" "before" "begin" "bind"
2715 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
2716 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
2717 "config" "const" "constraint" "context" "continue" "cover"
2718 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
2719 "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
2720 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
2721 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
2722 "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
2723 "endtask" "enum" "event" "expect" "export" "extends" "extern"
2724 "final" "first_match" "for" "force" "foreach" "forever" "fork"
2725 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
2726 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
2727 "include" "initial" "inout" "input" "inside" "instance" "int"
2728 "integer" "interface" "intersect" "join" "join_any" "join_none"
2729 "large" "liblist" "library" "local" "localparam" "logic"
2730 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
2731 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
2732 "notif0" "notif1" "null" "or" "output" "package" "packed"
2733 "parameter" "pmos" "posedge" "primitive" "priority" "program"
2734 "property" "protected" "pull0" "pull1" "pulldown" "pullup"
2735 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2736 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
2737 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
2738 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
2739 "showcancelled" "signed" "small" "solve" "specify" "specparam"
2740 "static" "string" "strong0" "strong1" "struct" "super" "supply0"
2741 "supply1" "table" "tagged" "task" "this" "throughout" "time"
2742 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
2743 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
2744 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
2745 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
2746 "wire" "with" "within" "wor" "xnor" "xor"
2748 "accept_on" "checker" "endchecker" "eventually" "global" "implies"
2749 "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
2750 "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
2751 "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
2753 "List of Verilog keywords.")
2755 (defconst verilog-comment-start-regexp "//\\|/\\*"
2756 "Dual comment value for `comment-start-regexp'.")
2758 (defvar verilog-mode-syntax-table
2759 (let ((table (make-syntax-table)))
2760 ;; Populate the syntax TABLE.
2761 (modify-syntax-entry ?\\ "\\" table)
2762 (modify-syntax-entry ?+ "." table)
2763 (modify-syntax-entry ?- "." table)
2764 (modify-syntax-entry ?= "." table)
2765 (modify-syntax-entry ?% "." table)
2766 (modify-syntax-entry ?< "." table)
2767 (modify-syntax-entry ?> "." table)
2768 (modify-syntax-entry ?& "." table)
2769 (modify-syntax-entry ?| "." table)
2770 (modify-syntax-entry ?` "w" table)
2771 (modify-syntax-entry ?_ "w" table)
2772 (modify-syntax-entry ?\' "." table)
2774 ;; Set up TABLE to handle block and line style comments.
2775 (if (featurep 'xemacs)
2777 ;; XEmacs (formerly Lucid) has the best implementation
2778 (modify-syntax-entry ?/ ". 1456" table)
2779 (modify-syntax-entry ?* ". 23" table)
2780 (modify-syntax-entry ?\n "> b" table))
2781 ;; Emacs does things differently, but we can work with it
2782 (modify-syntax-entry ?/ ". 124b" table)
2783 (modify-syntax-entry ?* ". 23" table)
2784 (modify-syntax-entry ?\n "> b" table))
2786 "Syntax table used in Verilog mode buffers.")
2788 (defvar verilog-font-lock-keywords nil
2789 "Default highlighting for Verilog mode.")
2791 (defvar verilog-font-lock-keywords-1 nil
2792 "Subdued level highlighting for Verilog mode.")
2794 (defvar verilog-font-lock-keywords-2 nil
2795 "Medium level highlighting for Verilog mode.
2796 See also `verilog-font-lock-extra-types'.")
2798 (defvar verilog-font-lock-keywords-3 nil
2799 "Gaudy level highlighting for Verilog mode.
2800 See also `verilog-font-lock-extra-types'.")
2802 (defvar verilog-font-lock-translate-off-face
2803 'verilog-font-lock-translate-off-face
2804 "Font to use for translated off regions.")
2805 (defface verilog-font-lock-translate-off-face
2808 (:background "gray90" :italic t ))
2811 (:background "gray10" :italic t ))
2812 (((class grayscale) (background light))
2813 (:foreground "DimGray" :italic t))
2814 (((class grayscale) (background dark))
2815 (:foreground "LightGray" :italic t))
2817 "Font lock mode face used to background highlight translate-off regions."
2818 :group 'font-lock-highlighting-faces)
2820 (defvar verilog-font-lock-p1800-face
2821 'verilog-font-lock-p1800-face
2822 "Font to use for p1800 keywords.")
2823 (defface verilog-font-lock-p1800-face
2826 (:foreground "DarkOrange3" :bold t ))
2829 (:foreground "orange1" :bold t ))
2831 "Font lock mode face used to highlight P1800 keywords."
2832 :group 'font-lock-highlighting-faces)
2834 (defvar verilog-font-lock-ams-face
2835 'verilog-font-lock-ams-face
2836 "Font to use for Analog/Mixed Signal keywords.")
2837 (defface verilog-font-lock-ams-face
2840 (:foreground "Purple" :bold t ))
2843 (:foreground "orange1" :bold t ))
2845 "Font lock mode face used to highlight AMS keywords."
2846 :group 'font-lock-highlighting-faces)
2848 (defvar verilog-font-grouping-keywords-face
2849 'verilog-font-lock-grouping-keywords-face
2850 "Font to use for Verilog Grouping Keywords (such as begin..end).")
2851 (defface verilog-font-lock-grouping-keywords-face
2854 (:foreground "red4" :bold t ))
2857 (:foreground "red4" :bold t ))
2859 "Font lock mode face used to highlight verilog grouping keywords."
2860 :group 'font-lock-highlighting-faces)
2862 (let* ((verilog-type-font-keywords
2866 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
2867 "event" "genvar" "inout" "input" "integer" "localparam"
2868 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or"
2869 "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
2870 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
2871 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
2872 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
2873 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
2874 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
2877 (verilog-pragma-keywords
2880 '("surefire" "auto" "synopsys" "rtl_synthesis" "verilint" "leda" "0in"
2883 (verilog-1800-2005-keywords
2886 '("alias" "assert" "assume" "automatic" "before" "bind"
2887 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
2888 "clocking" "config" "const" "constraint" "context" "continue"
2889 "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
2890 "dist" "do" "edge" "endclass" "endclocking" "endconfig"
2891 "endgroup" "endprogram" "endproperty" "endsequence" "enum"
2892 "expect" "export" "extends" "extern" "first_match" "foreach"
2893 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
2894 "illegal_bins" "import" "incdir" "include" "inside" "instance"
2895 "int" "intersect" "large" "liblist" "library" "local" "longint"
2896 "matches" "medium" "modport" "new" "noshowcancelled" "null"
2897 "packed" "program" "property" "protected" "pull0" "pull1"
2898 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2899 "randcase" "randsequence" "ref" "release" "return" "scalared"
2900 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
2901 "specparam" "static" "string" "strong0" "strong1" "struct"
2902 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
2903 "type" "union" "unsigned" "use" "var" "virtual" "void"
2904 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
2907 (verilog-1800-2009-keywords
2910 '("accept_on" "checker" "endchecker" "eventually" "global"
2911 "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
2912 "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
2913 "sync_accept_on" "sync_reject_on" "unique0" "until"
2914 "until_with" "untyped" "weak" ) nil )))
2916 (verilog-ams-keywords
2919 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
2920 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
2921 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
2922 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
2923 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
2924 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
2925 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
2926 "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
2927 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
2928 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
2929 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
2931 (verilog-font-keywords
2935 "assign" "case" "casex" "casez" "randcase" "deassign"
2936 "default" "disable" "else" "endcase" "endfunction"
2937 "endgenerate" "endinterface" "endmodule" "endprimitive"
2938 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
2939 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
2940 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
2941 "package" "endpackage" "always" "always_comb" "always_ff"
2942 "always_latch" "posedge" "primitive" "priority" "release"
2943 "repeat" "specify" "table" "task" "unique" "wait" "while"
2944 "class" "program" "endclass" "endprogram"
2947 (verilog-font-grouping-keywords
2950 '( "begin" "end" ) nil ))))
2952 (setq verilog-font-lock-keywords
2954 ;; Fontify all builtin keywords
2955 (concat "\\<\\(" verilog-font-keywords "\\|"
2956 ;; And user/system tasks and functions
2957 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
2959 ;; Fontify all types
2960 (if verilog-highlight-grouping-keywords
2961 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2962 'verilog-font-lock-ams-face)
2963 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2964 'font-lock-type-face))
2965 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
2966 'font-lock-type-face)
2967 ;; Fontify IEEE-1800-2005 keywords appropriately
2968 (if verilog-highlight-p1800-keywords
2969 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
2970 'verilog-font-lock-p1800-face)
2971 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
2972 'font-lock-type-face))
2973 ;; Fontify IEEE-1800-2009 keywords appropriately
2974 (if verilog-highlight-p1800-keywords
2975 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
2976 'verilog-font-lock-p1800-face)
2977 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
2978 'font-lock-type-face))
2979 ;; Fontify Verilog-AMS keywords
2980 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
2981 'verilog-font-lock-ams-face)))
2983 (setq verilog-font-lock-keywords-1
2984 (append verilog-font-lock-keywords
2986 ;; Fontify module definitions
2988 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
2989 '(1 font-lock-keyword-face)
2990 '(3 font-lock-function-name-face 'prepend))
2991 ;; Fontify function definitions
2993 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
2994 '(1 font-lock-keyword-face)
2995 '(3 font-lock-constant-face prepend))
2996 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
2997 (1 font-lock-keyword-face)
2998 (2 font-lock-constant-face append))
2999 '("\\<function\\>\\s-+\\(\\sw+\\)"
3000 1 'font-lock-constant-face append))))
3002 (setq verilog-font-lock-keywords-2
3003 (append verilog-font-lock-keywords-1
3006 (concat "\\(//\\s-*\\(" verilog-pragma-keywords "\\)\\s-.*\\)")
3007 ;; Fontify escaped names
3008 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
3009 ;; Fontify macro definitions/ uses
3010 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
3011 'font-lock-preprocessor-face
3012 'font-lock-type-face))
3013 ;; Fontify delays/numbers
3014 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
3015 0 font-lock-type-face append)
3016 ;; Fontify instantiation names
3017 '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
3020 (setq verilog-font-lock-keywords-3
3021 (append verilog-font-lock-keywords-2
3022 (when verilog-highlight-translate-off
3024 ;; Fontify things in translate off regions
3025 '(verilog-match-translate-off
3026 (0 'verilog-font-lock-translate-off-face prepend))
3030 ;; Buffer state preservation
3032 (defmacro verilog-save-buffer-state (&rest body)
3033 "Execute BODY forms, saving state around insignificant change.
3034 Changes in text properties like `face' or `syntax-table' are
3035 considered insignificant. This macro allows text properties to
3036 be changed, even in a read-only buffer.
3038 A change is considered significant if it affects the buffer text
3039 in any way that isn't completely restored again. Any
3040 user-visible changes to the buffer must not be within a
3041 `verilog-save-buffer-state'."
3042 ;; From c-save-buffer-state
3043 `(let* ((modified (buffer-modified-p))
3044 (buffer-undo-list t)
3045 (inhibit-read-only t)
3046 (inhibit-point-motion-hooks t)
3047 (verilog-no-change-functions t)
3048 before-change-functions
3049 after-change-functions
3051 buffer-file-name ; Prevent primitives checking
3052 buffer-file-truename) ; for file modification
3057 (set-buffer-modified-p nil)))))
3059 (defmacro verilog-save-no-change-functions (&rest body)
3060 "Execute BODY forms, disabling all change hooks in BODY.
3061 For insignificant changes, see instead `verilog-save-buffer-state'."
3062 `(let* ((inhibit-point-motion-hooks t)
3063 (verilog-no-change-functions t)
3064 before-change-functions
3065 after-change-functions)
3068 (defvar verilog-save-font-mod-hooked nil
3069 "Local variable when inside a `verilog-save-font-mods' block.")
3070 (make-variable-buffer-local 'verilog-save-font-mod-hooked)
3072 (defmacro verilog-save-font-mods (&rest body)
3073 "Execute BODY forms, disabling text modifications to allow performing BODY.
3074 Includes temporary disabling of `font-lock' to restore the buffer
3075 to full text form for parsing. Additional actions may be specified with
3076 `verilog-before-save-font-hook' and `verilog-after-save-font-hook'."
3077 ;; Before version 20, match-string with font-lock returns a
3078 ;; vector that is not equal to the string. IE if on "input"
3079 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
3080 `(let* ((hooked (unless verilog-save-font-mod-hooked
3081 (verilog-run-hooks 'verilog-before-save-font-hook)
3083 (verilog-save-font-mod-hooked t)
3084 (fontlocked (when (and (boundp 'font-lock-mode) font-lock-mode)
3090 (when fontlocked (font-lock-mode t))
3091 (when hooked (verilog-run-hooks 'verilog-after-save-font-hook)))))
3094 ;; Comment detection and caching
3096 (defvar verilog-scan-cache-preserving nil
3097 "If set, the specified buffer's comment properties are static.
3098 Buffer changes will be ignored. See `verilog-inside-comment-or-string-p'
3099 and `verilog-scan'.")
3101 (defvar verilog-scan-cache-tick nil
3102 "Modification tick at which `verilog-scan' was last completed.")
3103 (make-variable-buffer-local 'verilog-scan-cache-tick)
3105 (defun verilog-scan-cache-flush ()
3106 "Flush the `verilog-scan' cache."
3107 (setq verilog-scan-cache-tick nil))
3109 (defun verilog-scan-cache-ok-p ()
3110 "Return t iff the scan cache is up to date."
3111 (or (and verilog-scan-cache-preserving
3112 (eq verilog-scan-cache-preserving (current-buffer))
3113 verilog-scan-cache-tick)
3114 (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
3116 (defmacro verilog-save-scan-cache (&rest body)
3117 "Execute the BODY forms, allowing scan cache preservation within BODY.
3118 This requires that insertions must use `verilog-insert'."
3119 ;; If the buffer is out of date, trash it, as we'll not check later the tick
3120 ;; Note this must work properly if there's multiple layers of calls
3121 ;; to verilog-save-scan-cache even with differing ticks.
3123 (unless (verilog-scan-cache-ok-p) ;; Must be before let
3124 (setq verilog-scan-cache-tick nil))
3125 (let* ((verilog-scan-cache-preserving (current-buffer)))
3128 (defun verilog-scan-region (beg end)
3129 "Parse between BEG and END for `verilog-inside-comment-or-string-p'.
3130 This creates v-cmts properties where comments are in force."
3131 ;; Why properties and not overlays? Overlays have much slower non O(1)
3133 ;; This function is warm - called on every verilog-insert
3136 (verilog-save-buffer-state
3139 (while (< (point) end)
3140 (cond ((looking-at "//")
3142 (or (search-forward "\n" end t)
3144 ;; "1+": The leading // or /* itself isn't considered as
3145 ;; being "inside" the comment, so that a (search-backward)
3146 ;; that lands at the start of the // won't mis-indicate
3147 ;; it's inside a comment. Also otherwise it would be
3148 ;; hard to find a commented out /*AS*/ vs one that isn't
3149 (put-text-property (1+ pt) (point) 'v-cmts t))
3150 ((looking-at "/\\*")
3152 (or (search-forward "*/" end t)
3153 ;; No error - let later code indicate it so we can
3154 ;; use inside functions on-the-fly
3155 ;;(error "%s: Unmatched /* */, at char %d"
3156 ;; (verilog-point-text) (point))
3158 (put-text-property (1+ pt) (point) 'v-cmts t))
3161 (or (re-search-forward "[^\\]\"" end t) ;; don't forward-char first, since we look for a non backslash first
3162 ;; No error - let later code indicate it so we can
3164 (put-text-property (1+ pt) (point) 'v-cmts t))
3167 (if (re-search-forward "[/\"]" end t)
3169 (goto-char end))))))))))
3171 (defun verilog-scan ()
3172 "Parse the buffer, marking all comments with properties.
3173 Also assumes any text inserted since `verilog-scan-cache-tick'
3174 either is ok to parse as a non-comment, or `verilog-insert' was used."
3175 ;; See also `verilog-scan-debug' and `verilog-scan-and-debug'
3176 (unless (verilog-scan-cache-ok-p)
3178 (verilog-save-buffer-state
3180 (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
3181 verilog-scan-cache-preserving verilog-scan-cache-tick
3182 (buffer-chars-modified-tick)))
3183 (remove-text-properties (point-min) (point-max) '(v-cmts nil))
3184 (verilog-scan-region (point-min) (point-max))
3185 (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
3186 (when verilog-debug (message "Scanning... done"))))))
3188 (defun verilog-scan-debug ()
3189 "For debugging, show with display face results of `verilog-scan'."
3191 ;;(if dbg (setq dbg (concat dbg (format "verilog-scan-debug\n"))))
3193 (goto-char (point-min))
3194 (remove-text-properties (point-min) (point-max) '(face nil))
3196 (cond ((get-text-property (point) 'v-cmts)
3197 (put-text-property (point) (1+ (point)) `face 'underline)
3198 ;;(if dbg (setq dbg (concat dbg (format " v-cmts at %S\n" (point)))))
3201 (goto-char (or (next-property-change (point)) (point-max))))))))
3203 (defun verilog-scan-and-debug ()
3204 "For debugging, run `verilog-scan' and `verilog-scan-debug'."
3205 (let (verilog-scan-cache-preserving
3206 verilog-scan-cache-tick)
3207 (goto-char (point-min))
3209 (verilog-scan-debug)))
3211 (defun verilog-inside-comment-or-string-p (&optional pos)
3212 "Check if optional point POS is inside a comment.
3213 This may require a slow pre-parse of the buffer with `verilog-scan'
3214 to establish comment properties on all text."
3215 ;; This function is very hot
3218 (and (>= pos (point-min))
3219 (get-text-property pos 'v-cmts))
3220 (get-text-property (point) 'v-cmts)))
3222 (defun verilog-insert (&rest stuff)
3223 "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
3224 Any insert that includes a comment must have the entire comment
3225 inserted using a single call to `verilog-insert'."
3228 (insert (car stuff))
3229 (setq stuff (cdr stuff)))
3230 (verilog-scan-region pt (point))))
3234 (defun verilog-declaration-end ()
3235 (search-forward ";"))
3237 (defun verilog-point-text (&optional pointnum)
3238 "Return text describing where POINTNUM or current point is (for errors).
3239 Use filename, if current buffer being edited shorten to just buffer name."
3240 (concat (or (and (equal (window-buffer (selected-window)) (current-buffer))
3244 ":" (int-to-string (1+ (count-lines (point-min) (or pointnum (point)))))))
3246 (defun electric-verilog-backward-sexp ()
3247 "Move backward over one balanced expression."
3249 ;; before that see if we are in a comment
3250 (verilog-backward-sexp))
3252 (defun electric-verilog-forward-sexp ()
3253 "Move forward over one balanced expression."
3255 ;; before that see if we are in a comment
3256 (verilog-forward-sexp))
3258 ;;;used by hs-minor-mode
3259 (defun verilog-forward-sexp-function (arg)
3261 (verilog-backward-sexp)
3262 (verilog-forward-sexp)))
3265 (defun verilog-backward-sexp ()
3270 (if (not (looking-at "\\<"))
3273 ((verilog-skip-backward-comment-or-string))
3274 ((looking-at "\\<else\\>")
3276 verilog-end-block-re
3277 "\\|\\(\\<else\\>\\)"
3278 "\\|\\(\\<if\\>\\)"))
3279 (while (and (not found)
3280 (verilog-re-search-backward reg nil 'move))
3282 ((match-end 1) ; matched verilog-end-block-re
3283 ; try to leap back to matching outward block by striding across
3284 ; indent level changing tokens then immediately
3285 ; previous line governs indentation.
3286 (verilog-leap-to-head))
3287 ((match-end 2) ; else, we're in deep
3288 (setq elsec (1+ elsec)))
3289 ((match-end 3) ; found it
3290 (setq elsec (1- elsec))
3292 ;; Now previous line describes syntax
3293 (setq found 't))))))
3294 ((looking-at verilog-end-block-re)
3295 (verilog-leap-to-head))
3296 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
3299 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
3301 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
3303 (verilog-re-search-backward "\\<class\\>" nil 'move))
3305 (verilog-re-search-backward "\\<program\\>" nil 'move))
3307 (verilog-re-search-backward "\\<interface\\>" nil 'move))
3309 (verilog-re-search-backward "\\<package\\>" nil 'move))
3312 (backward-sexp 1))))
3317 (defun verilog-forward-sexp ()
3322 (if (not (looking-at "\\<"))
3325 ((verilog-skip-forward-comment-or-string)
3326 (verilog-forward-syntactic-ws))
3327 ((looking-at verilog-beg-block-re-ordered)
3330 ;; Search forward for matching end
3331 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
3333 ;; Search forward for matching endcase
3334 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
3335 (setq md 3) ;; ender is third item in regexp
3338 ;; might be "disable fork" or "wait fork"
3342 (looking-at verilog-disable-fork-re)
3343 (and (looking-at "fork")
3345 (setq here (point)) ;; sometimes a fork is just a fork
3347 (looking-at verilog-disable-fork-re))))
3348 (progn ;; it is a disable fork; ignore it
3349 (goto-char (match-end 0))
3352 (progn ;; it is a nice simple fork
3353 (goto-char here) ;; return from looking for "disable fork"
3354 ;; Search forward for matching join
3355 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))))
3357 ;; Search forward for matching endclass
3358 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
3361 ;; Search forward for matching endtable
3362 (setq reg "\\<endtable\\>" )
3365 ;; Search forward for matching endspecify
3366 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
3368 ;; Search forward for matching endfunction
3369 (setq reg "\\<endfunction\\>" )
3372 ;; Search forward for matching endfunction
3373 (setq reg "\\<endfunction\\>" )
3376 ;; Search forward for matching endtask
3377 (setq reg "\\<endtask\\>" )
3380 ;; Search forward for matching endtask
3381 (setq reg "\\<endtask\\>" )
3384 ;; Search forward for matching endgenerate
3385 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
3387 ;; Search forward for matching endgroup
3388 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
3390 ;; Search forward for matching endproperty
3391 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
3393 ;; Search forward for matching endsequence
3394 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
3395 (setq md 3)) ; 3 to get to endsequence in the reg above
3397 ;; Search forward for matching endclocking
3398 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
3405 (while (verilog-re-search-forward reg nil 'move)
3407 ((match-end md) ; a closer in regular expression, so we are climbing out
3408 (setq depth (1- depth))
3409 (if (= 0 depth) ; we are out!
3411 ((match-end 1) ; an opener in the r-e, so we are in deeper now
3412 (setq here (point)) ; remember where we started
3413 (goto-char (match-beginning 1))
3416 (looking-at verilog-disable-fork-re)
3417 (and (looking-at "fork")
3420 (looking-at verilog-disable-fork-re))))
3421 (progn ;; it is a disable fork; another false alarm
3422 (goto-char (match-end 0)))
3423 (progn ;; it is a simple fork (or has nothing to do with fork)
3425 (setq depth (1+ depth))))))))))
3426 (if (verilog-re-search-forward reg nil 'move)
3427 (throw 'skip 1))))))
3429 ((looking-at (concat
3430 "\\(\\<\\(macro\\)?module\\>\\)\\|"
3431 "\\(\\<primitive\\>\\)\\|"
3432 "\\(\\<class\\>\\)\\|"
3433 "\\(\\<program\\>\\)\\|"
3434 "\\(\\<interface\\>\\)\\|"
3435 "\\(\\<package\\>\\)"))
3438 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
3440 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
3442 (verilog-re-search-forward "\\<endclass\\>" nil 'move))
3444 (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
3446 (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
3448 (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
3451 (if (= (following-char) ?\) )
3453 (forward-sexp 1)))))
3456 (if (= (following-char) ?\) )
3458 (forward-sexp 1))))))
3460 (defun verilog-declaration-beg ()
3461 (verilog-re-search-backward verilog-declaration-re (bobp) t))
3467 (defvar verilog-which-tool 1)
3469 (define-derived-mode verilog-mode prog-mode "Verilog"
3470 "Major mode for editing Verilog code.
3471 \\<verilog-mode-map>
3472 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
3473 AUTOs can improve coding efficiency.
3475 Use \\[verilog-faq] for a pointer to frequently asked questions.
3477 NEWLINE, TAB indents for Verilog code.
3478 Delete converts tabs to spaces as it moves back.
3480 Supports highlighting.
3482 Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
3483 with no args, if that value is non-nil.
3485 Variables controlling indentation/edit style:
3487 variable `verilog-indent-level' (default 3)
3488 Indentation of Verilog statements with respect to containing block.
3489 `verilog-indent-level-module' (default 3)
3490 Absolute indentation of Module level Verilog statements.
3491 Set to 0 to get initial and always statements lined up
3492 on the left side of your screen.
3493 `verilog-indent-level-declaration' (default 3)
3494 Indentation of declarations with respect to containing block.
3495 Set to 0 to get them list right under containing block.
3496 `verilog-indent-level-behavioral' (default 3)
3497 Indentation of first begin in a task or function block
3498 Set to 0 to get such code to lined up underneath the task or
3500 `verilog-indent-level-directive' (default 1)
3501 Indentation of `ifdef/`endif blocks.
3502 `verilog-cexp-indent' (default 1)
3503 Indentation of Verilog statements broken across lines i.e.:
3506 `verilog-case-indent' (default 2)
3507 Indentation for case statements.
3508 `verilog-auto-newline' (default nil)
3509 Non-nil means automatically newline after semicolons and the punctuation
3511 `verilog-auto-indent-on-newline' (default t)
3512 Non-nil means automatically indent line after newline.
3513 `verilog-tab-always-indent' (default t)
3514 Non-nil means TAB in Verilog mode should always reindent the current line,
3515 regardless of where in the line point is when the TAB command is used.
3516 `verilog-indent-begin-after-if' (default t)
3517 Non-nil means to indent begin statements following a preceding
3518 if, else, while, for and repeat statements, if any. Otherwise,
3519 the begin is lined up with the preceding token. If t, you get:
3521 begin // amount of indent based on `verilog-cexp-indent'
3525 `verilog-auto-endcomments' (default t)
3526 Non-nil means a comment /* ... */ is set after the ends which ends
3527 cases, tasks, functions and modules.
3528 The type and name of the object will be set between the braces.
3529 `verilog-minimum-comment-distance' (default 10)
3530 Minimum distance (in lines) between begin and end required before a comment
3531 will be inserted. Setting this variable to zero results in every
3532 end acquiring a comment; the default avoids too many redundant
3533 comments in tight quarters.
3534 `verilog-auto-lineup' (default 'declarations)
3535 List of contexts where auto lineup of code should be done.
3537 Variables controlling other actions:
3539 `verilog-linter' (default surelint)
3540 Unix program to call to run the lint checker. This is the default
3541 command for \\[compile-command] and \\[verilog-auto-save-compile].
3543 See \\[customize] for the complete list of variables.
3545 AUTO expansion functions are, in part:
3547 \\[verilog-auto] Expand AUTO statements.
3548 \\[verilog-delete-auto] Remove the AUTOs.
3549 \\[verilog-inject-auto] Insert AUTOs for the first time.
3551 Some other functions are:
3553 \\[verilog-complete-word] Complete word with appropriate possibilities.
3554 \\[verilog-mark-defun] Mark function.
3555 \\[verilog-beg-of-defun] Move to beginning of current function.
3556 \\[verilog-end-of-defun] Move to end of current function.
3557 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
3559 \\[verilog-comment-region] Put marked area in a comment.
3560 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
3561 \\[verilog-insert-block] Insert begin ... end.
3562 \\[verilog-star-comment] Insert /* ... */.
3564 \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
3565 \\[verilog-sk-begin] Insert a begin .. end block.
3566 \\[verilog-sk-case] Insert a case block, prompting for details.
3567 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
3568 \\[verilog-sk-generate] Insert a generate .. endgenerate block.
3569 \\[verilog-sk-header] Insert a header block at the top of file.
3570 \\[verilog-sk-initial] Insert an initial begin .. end block.
3571 \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
3572 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
3573 \\[verilog-sk-ovm-class] Insert an OVM Class block.
3574 \\[verilog-sk-uvm-class] Insert an UVM Class block.
3575 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
3576 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
3577 \\[verilog-sk-specify] Insert a specify .. endspecify block.
3578 \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
3579 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
3580 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
3581 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
3582 \\[verilog-sk-if] Insert an if (..) begin .. end block.
3583 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
3584 \\[verilog-sk-comment] Insert a comment block.
3585 \\[verilog-sk-assign] Insert an assign .. = ..; statement.
3586 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
3587 \\[verilog-sk-input] Insert an input declaration, prompting for details.
3588 \\[verilog-sk-output] Insert an output declaration, prompting for details.
3589 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
3590 \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
3591 \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
3592 \\[verilog-sk-reg] Insert a register declaration, prompting for details.
3593 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
3595 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
3596 Key bindings specific to `verilog-mode-map' are:
3598 \\{verilog-mode-map}"
3599 :abbrev-table verilog-mode-abbrev-table
3600 (set (make-local-variable 'beginning-of-defun-function)
3601 'verilog-beg-of-defun)
3602 (set (make-local-variable 'end-of-defun-function)
3603 'verilog-end-of-defun)
3604 (set-syntax-table verilog-mode-syntax-table)
3605 (set (make-local-variable 'indent-line-function)
3606 #'verilog-indent-line-relative)
3607 (setq comment-indent-function 'verilog-comment-indent)
3608 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
3609 (set (make-local-variable 'comment-start) "// ")
3610 (set (make-local-variable 'comment-end) "")
3611 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
3612 (set (make-local-variable 'comment-multi-line) nil)
3613 ;; Set up for compilation
3614 (setq verilog-which-tool 1)
3615 (setq verilog-tool 'verilog-linter)
3616 (verilog-set-compile-command)
3617 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables
3618 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
3621 (when (featurep 'xemacs)
3622 (easy-menu-add verilog-stmt-menu)
3623 (easy-menu-add verilog-menu)
3624 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
3626 ;; Stuff for GNU Emacs
3627 (set (make-local-variable 'font-lock-defaults)
3628 `((verilog-font-lock-keywords
3629 verilog-font-lock-keywords-1
3630 verilog-font-lock-keywords-2
3631 verilog-font-lock-keywords-3)
3633 ,(if (functionp 'syntax-ppss)
3634 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
3635 ;; font-lock-beginning-of-syntax-function, so
3636 ;; font-lock-beginning-of-syntax-function, can't use
3637 ;; verilog-beg-of-defun.
3639 'verilog-beg-of-defun)))
3640 ;;------------------------------------------------------------
3641 ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
3642 ;; all buffer local:
3643 (unless noninteractive ;; Else can't see the result, and change hooks are slow
3644 (when (featurep 'xemacs)
3645 (make-local-hook 'font-lock-mode-hook)
3646 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
3647 (make-local-hook 'after-change-functions))
3648 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
3649 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
3650 (add-hook 'after-change-functions 'verilog-highlight-region t t))
3652 ;; Tell imenu how to handle Verilog.
3653 (set (make-local-variable 'imenu-generic-expression)
3654 verilog-imenu-generic-expression)
3655 ;; Tell which-func-modes that imenu knows about verilog
3656 (when (and (boundp 'which-func-modes) (listp which-func-modes))
3657 (add-to-list 'which-func-modes 'verilog-mode))
3659 (when (boundp 'hs-special-modes-alist)
3660 (unless (assq 'verilog-mode hs-special-modes-alist)
3661 (setq hs-special-modes-alist
3662 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
3663 verilog-forward-sexp-function)
3664 hs-special-modes-alist))))
3667 (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local)
3668 ;; verilog-mode-hook call added by define-derived-mode
3673 ;; Electric functions
3675 (defun electric-verilog-terminate-line (&optional arg)
3676 "Terminate line and indent next line.
3677 With optional ARG, remove existing end of line comments."
3679 ;; before that see if we are in a comment
3680 (let ((state (save-excursion (verilog-syntax-ppss))))
3682 ((nth 7 state) ; Inside // comment
3685 (delete-horizontal-space)
3690 (beginning-of-line)))
3691 (verilog-indent-line))
3692 ((nth 4 state) ; Inside any comment (hence /**/)
3694 (verilog-more-comment))
3696 ;; First, check if current line should be indented
3698 (delete-horizontal-space)
3700 (skip-chars-forward " \t")
3701 (if (looking-at verilog-auto-end-comment-lines-re)
3702 (let ((indent-str (verilog-indent-line)))
3703 ;; Maybe we should set some endcomments
3704 (if verilog-auto-endcomments
3705 (verilog-set-auto-endcomments indent-str arg))
3707 (delete-horizontal-space)
3714 (delete-horizontal-space)
3716 ;; see if we should line up assignments
3718 (if (or (eq 'all verilog-auto-lineup)
3719 (eq 'assignments verilog-auto-lineup))
3720 (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
3724 (if verilog-auto-indent-on-newline
3725 (verilog-indent-line)))
3729 (defun electric-verilog-terminate-and-indent ()
3730 "Insert a newline and indent for the next statement."
3732 (electric-verilog-terminate-line 1))
3734 (defun electric-verilog-semi ()
3735 "Insert `;' character and reindent the line."
3737 (verilog-insert-last-command-event)
3739 (if (or (verilog-in-comment-or-string-p)
3740 (verilog-in-escaped-name-p))
3744 (verilog-forward-ws&directives)
3745 (verilog-indent-line))
3746 (if (and verilog-auto-newline
3747 (not (verilog-parenthesis-depth)))
3748 (electric-verilog-terminate-line))))
3750 (defun electric-verilog-semi-with-comment ()
3751 "Insert `;' character, reindent the line and indent for comment."
3756 (verilog-indent-line))
3757 (indent-for-comment))
3759 (defun electric-verilog-colon ()
3760 "Insert `:' and do all indentations except line indent on this line."
3762 (verilog-insert-last-command-event)
3763 ;; Do nothing if within string.
3765 (verilog-within-string)
3766 (not (verilog-in-case-region-p)))
3770 (lim (progn (verilog-beg-of-statement) (point))))
3772 (verilog-backward-case-item lim)
3773 (verilog-indent-line)))
3774 ;; (let ((verilog-tab-always-indent nil))
3775 ;; (verilog-indent-line))
3778 ;;(defun electric-verilog-equal ()
3779 ;; "Insert `=', and do indentation if within block."
3781 ;; (verilog-insert-last-command-event)
3782 ;; Could auto line up expressions, but not yet
3783 ;; (if (eq (car (verilog-calculate-indent)) 'block)
3784 ;; (let ((verilog-tab-always-indent nil))
3785 ;; (verilog-indent-command)))
3788 (defun electric-verilog-tick ()
3789 "Insert back-tick, and indent to column 0 if this is a CPP directive."
3791 (verilog-insert-last-command-event)
3793 (if (verilog-in-directive-p)
3794 (verilog-indent-line))))
3796 (defun electric-verilog-tab ()
3797 "Function called when TAB is pressed in Verilog mode."
3799 ;; If verilog-tab-always-indent, indent the beginning of the line.
3801 ;; The region is active, indent it.
3802 ((and (region-active-p)
3803 (not (eq (region-beginning) (region-end))))
3804 (indent-region (region-beginning) (region-end) nil))
3805 ((or verilog-tab-always-indent
3807 (skip-chars-backward " \t")
3809 (let* ((oldpnt (point))
3813 (skip-chars-forward " \t")
3814 (verilog-indent-line)
3815 (back-to-indentation)
3817 (if (< (point) boi-point)
3818 (back-to-indentation)
3819 (cond ((not verilog-tab-to-comment))
3823 (indent-for-comment)
3824 (when (and (eolp) (= oldpnt (point)))
3825 ; kill existing comment
3827 (re-search-forward comment-start-skip oldpnt 'move)
3828 (goto-char (match-beginning 0))
3829 (skip-chars-backward " \t")
3830 (kill-region (point) oldpnt)))))))
3831 (t (progn (insert "\t")))))
3836 ;; Interactive functions
3839 (defun verilog-indent-buffer ()
3840 "Indent-region the entire buffer as Verilog code.
3841 To call this from the command line, see \\[verilog-batch-indent]."
3844 (indent-region (point-min) (point-max) nil))
3846 (defun verilog-insert-block ()
3847 "Insert Verilog begin ... end; block in the code with right indentation."
3849 (verilog-indent-line)
3851 (electric-verilog-terminate-line)
3853 (electric-verilog-terminate-line)
3856 (verilog-indent-line)))
3858 (defun verilog-star-comment ()
3859 "Insert Verilog star comment at point."
3861 (verilog-indent-line)
3869 (defun verilog-insert-1 (fmt max)
3870 "Use format string FMT to insert integers 0 to MAX - 1.
3871 Inserts one integer per line, at the current column. Stops early
3872 if it reaches the end of the buffer."
3873 (let ((col (current-column))
3877 (insert (format fmt n))
3879 ;; Note that this function does not bother to check for lines
3880 ;; shorter than col.
3884 (move-to-column col))))))
3886 (defun verilog-insert-indices (max)
3887 "Insert a set of indices into a rectangle.
3888 The upper left corner is defined by point. Indices begin with 0
3889 and extend to the MAX - 1. If no prefix arg is given, the user
3890 is prompted for a value. The indices are surrounded by square
3891 brackets \[]. For example, the following code with the point
3892 located after the first 'a' gives:
3898 a = b ==> insert-indices ==> a[ 4] = b
3904 (interactive "NMAX: ")
3905 (verilog-insert-1 "[%3d]" max))
3907 (defun verilog-generate-numbers (max)
3908 "Insert a set of generated numbers into a rectangle.
3909 The upper left corner is defined by point. The numbers are padded to three
3910 digits, starting with 000 and extending to (MAX - 1). If no prefix argument
3911 is supplied, then the user is prompted for the MAX number. Consider the
3912 following code fragment:
3918 buf buf ==> generate-numbers ==> buf buf004
3924 (interactive "NMAX: ")
3925 (verilog-insert-1 "%3.3d" max))
3927 (defun verilog-mark-defun ()
3928 "Mark the current Verilog function (or procedure).
3929 This puts the mark at the end, and point at the beginning."
3931 (if (featurep 'xemacs)
3934 (verilog-end-of-defun)
3936 (verilog-beg-of-defun)
3937 (if (fboundp 'zmacs-activate-region)
3938 (zmacs-activate-region)))
3941 (defun verilog-comment-region (start end)
3942 ; checkdoc-params: (start end)
3943 "Put the region into a Verilog comment.
3944 The comments that are in this area are \"deformed\":
3945 `*)' becomes `!(*' and `}' becomes `!{'.
3946 These deformed comments are returned to normal if you use
3947 \\[verilog-uncomment-region] to undo the commenting.
3949 The commented area starts with `verilog-exclude-str-start', and ends with
3950 `verilog-exclude-str-end'. But if you change these variables,
3951 \\[verilog-uncomment-region] won't recognize the comments."
3954 ;; Insert start and endcomments
3956 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
3957 (not (save-excursion (skip-chars-backward " \t") (bolp))))
3959 (beginning-of-line))
3960 (insert verilog-exclude-str-end)
3965 (insert verilog-exclude-str-start)
3967 ;; Replace end-comments within commented area
3970 (while (re-search-backward "\\*/" start t)
3971 (replace-match "*-/" t t)))
3973 (let ((s+1 (1+ start)))
3974 (while (re-search-backward "/\\*" s+1 t)
3975 (replace-match "/-*" t t))))))
3977 (defun verilog-uncomment-region ()
3978 "Uncomment a commented area; change deformed comments back to normal.
3979 This command does nothing if the pointer is not in a commented
3980 area. See also `verilog-comment-region'."
3983 (let ((start (point))
3985 ;; Find the boundaries of the comment
3987 (setq start (progn (search-backward verilog-exclude-str-start nil t)
3989 (setq end (progn (search-forward verilog-exclude-str-end nil t)
3991 ;; Check if we're really inside a comment
3992 (if (or (equal start (point)) (<= end (point)))
3993 (message "Not standing within commented area.")
3995 ;; Remove endcomment
3998 (let ((pos (point)))
4000 (delete-region pos (1+ (point))))
4001 ;; Change comments back to normal
4003 (while (re-search-backward "\\*-/" start t)
4004 (replace-match "*/" t t)))
4006 (while (re-search-backward "/-\\*" start t)
4007 (replace-match "/*" t t)))
4008 ;; Remove start comment
4011 (let ((pos (point)))
4013 (delete-region pos (1+ (point)))))))))
4015 (defun verilog-beg-of-defun ()
4016 "Move backward to the beginning of the current function or procedure."
4018 (verilog-re-search-backward verilog-defun-re nil 'move))
4020 (defun verilog-beg-of-defun-quick ()
4021 "Move backward to the beginning of the current function or procedure.
4022 Uses `verilog-scan' cache."
4024 (verilog-re-search-backward-quick verilog-defun-re nil 'move))
4026 (defun verilog-end-of-defun ()
4027 "Move forward to the end of the current function or procedure."
4029 (verilog-re-search-forward verilog-end-defun-re nil 'move))
4031 (defun verilog-get-beg-of-defun (&optional warn)
4033 (cond ((verilog-re-search-forward-quick verilog-defun-re nil t)
4036 (error "%s: Can't find module beginning" (verilog-point-text))
4038 (defun verilog-get-end-of-defun (&optional warn)
4040 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
4043 (error "%s: Can't find endmodule" (verilog-point-text))
4046 (defun verilog-label-be (&optional arg)
4047 "Label matching begin ... end, fork ... join and case ... endcase statements.
4048 With ARG, first kill any existing labels."
4053 (verilog-beg-of-defun)
4056 (verilog-end-of-defun)
4058 (goto-char (marker-position b))
4060 (message "Relabeling module..."))
4062 (> (marker-position e) (point))
4063 (verilog-re-search-forward
4065 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>"
4066 "\\|\\(`endif\\)\\|\\(`else\\)")
4068 (goto-char (match-beginning 0))
4069 (let ((indent-str (verilog-indent-line)))
4070 (verilog-set-auto-endcomments indent-str 't)
4072 (delete-horizontal-space))
4074 (if (= 9 (% cnt 10))
4075 (message "%d..." cnt)))
4080 (message "%d lines auto commented" cnt))))
4082 (defun verilog-beg-of-statement ()
4083 "Move backward to beginning of statement."
4085 ;; Move back token by token until we see the end
4086 ;; of some earlier line.
4089 ;; If the current point does not begin a new
4090 ;; statement, as in the character ahead of us is a ';', or SOF
4091 ;; or the string after us unambiguously starts a statement,
4092 ;; or the token before us unambiguously ends a statement,
4093 ;; then move back a token and test again.
4095 ;; stop if beginning of buffer
4097 ;; stop if we find a ;
4098 (= (preceding-char) ?\;)
4099 ;; stop if we see a named coverpoint
4100 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
4101 ;; keep going if we are in the middle of a word
4102 (not (or (looking-at "\\<") (forward-word -1)))
4103 ;; stop if we see an assertion (perhaps labeled)
4105 (looking-at "\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
4109 (verilog-backward-token)
4110 (if (looking-at verilog-label-re)
4113 ;; stop if we see an extended complete reg, perhaps a complete one
4115 (looking-at verilog-complete-reg)
4117 (while (and (looking-at verilog-extended-complete-re)
4118 (progn (setq p (point))
4119 (verilog-backward-token)
4122 ;; stop if we see a complete reg (previous found extended ones)
4123 (looking-at verilog-basic-complete-re)
4124 ;; stop if previous token is an ender
4126 (verilog-backward-token)
4128 (looking-at verilog-end-block-re)
4129 (looking-at verilog-preprocessor-re))))) ;; end of test
4130 (verilog-backward-syntactic-ws)
4131 (verilog-backward-token))
4132 ;; Now point is where the previous line ended.
4133 (verilog-forward-syntactic-ws)))
4135 (defun verilog-beg-of-statement-1 ()
4136 "Move backward to beginning of statement."
4138 (if (verilog-in-comment-p)
4139 (verilog-backward-syntactic-ws))
4142 (while (not (looking-at verilog-complete-reg))
4144 (verilog-backward-syntactic-ws)
4146 (= (preceding-char) ?\;)
4148 (verilog-backward-token)
4149 (looking-at verilog-ends-re)))
4153 (verilog-backward-token))))
4154 (verilog-forward-syntactic-ws)))
4157 ; (not (looking-at verilog-complete-reg))
4159 ; (not (= (preceding-char) ?\;)))
4160 ; (verilog-backward-token)
4161 ; (verilog-backward-syntactic-ws)
4162 ; (setq pt (point)))
4164 ; ;(verilog-forward-syntactic-ws)
4166 (defun verilog-end-of-statement ()
4167 "Move forward to end of current statement."
4171 ((verilog-in-directive-p)
4175 ((looking-at verilog-beg-block-re)
4176 (verilog-forward-sexp))
4178 ((equal (char-after) ?\})
4181 ;; Skip to end of statement
4182 ((condition-case nil
4187 (verilog-skip-forward-comment-or-string)
4190 (cond ((looking-at "[ \t]*;")
4191 (skip-chars-forward "^;")
4193 (throw 'found (point)))
4196 (looking-at verilog-beg-block-re))
4197 (goto-char (match-beginning 0))
4199 ((looking-at "[ \t]*)")
4200 (throw 'found (point)))
4202 (throw 'found (point)))
4208 ;; Skip a whole block
4211 (verilog-re-search-forward verilog-end-statement-re nil 'move)
4212 (setq nest (if (match-end 1)
4216 (throw 'found (point)))
4218 (throw 'found (verilog-end-of-statement))))))
4221 (defun verilog-in-case-region-p ()
4222 "Return true if in a case region.
4223 More specifically, point @ in the line foo : @ begin"
4227 (progn (verilog-forward-syntactic-ws)
4228 (looking-at "\\<begin\\>"))
4229 (progn (verilog-backward-syntactic-ws)
4230 (= (preceding-char) ?\:)))
4234 (verilog-re-search-backward
4235 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
4236 "\\(\\<endcase\\>\\)\\>")
4240 (setq nest (1+ nest)))
4244 (setq nest (1- nest)))
4246 (throw 'found (= nest 0)))))))
4249 (defun verilog-backward-up-list (arg)
4250 "Call `backward-up-list' ARG, ignoring comments."
4251 (let ((parse-sexp-ignore-comments t))
4252 (backward-up-list arg)))
4254 (defun verilog-forward-sexp-cmt (arg)
4255 "Call `forward-sexp' ARG, inside comments."
4256 (let ((parse-sexp-ignore-comments nil))
4257 (forward-sexp arg)))
4259 (defun verilog-forward-sexp-ign-cmt (arg)
4260 "Call `forward-sexp' ARG, ignoring comments."
4261 (let ((parse-sexp-ignore-comments t))
4262 (forward-sexp arg)))
4264 (defun verilog-in-generate-region-p ()
4265 "Return true if in a generate region.
4266 More specifically, after a generate and before an endgenerate."
4273 (verilog-re-search-backward
4274 "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
4276 ((match-end 1) ; module - we have crawled out
4278 ((match-end 2) ; generate
4279 (setq nest (1- nest)))
4280 ((match-end 3) ; endgenerate
4281 (setq nest (1+ nest))))))))
4282 (= nest 0) )) ; return nest
4284 (defun verilog-in-fork-region-p ()
4285 "Return true if between a fork and join."
4287 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
4292 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
4294 ((match-end 1) ; fork
4295 (setq nest (1- nest)))
4296 ((match-end 2) ; join
4297 (setq nest (1+ nest)))))))
4298 (= nest 0) )) ; return nest
4300 (defun verilog-backward-case-item (lim)
4301 "Skip backward to nearest enclosing case item.
4302 Limit search to point LIM."
4308 (verilog-re-search-backward verilog-endcomment-reason-re
4311 ;; Try to find the real :
4312 (if (save-excursion (search-backward ":" lim1 t))
4318 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
4322 (setq colon (1+ colon))
4324 (error "%s: unbalanced [" (verilog-point-text))))
4326 (setq colon (1- colon)))
4329 (setq colon (1+ colon)))))
4330 ;; Skip back to beginning of case item
4331 (skip-chars-backward "\t ")
4332 (verilog-skip-backward-comment-or-string)
4337 (verilog-re-search-backward
4338 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
4342 (goto-char (match-end 1))
4343 (verilog-forward-ws&directives)
4344 (if (looking-at "(")
4347 (verilog-forward-ws&directives)))
4350 (goto-char (match-end 0))
4351 (verilog-forward-ws&directives)
4353 (error "Malformed case item"))))
4354 (setq str (buffer-substring b e))
4358 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4359 (setq str (concat (substring str 0 e) "...")))
4368 (defun verilog-kill-existing-comment ()
4369 "Kill auto comment on this line."
4377 (search-forward "//" e t))))
4379 (delete-region (- b 2) e)))))
4381 (defconst verilog-directive-nest-re
4382 (concat "\\(`else\\>\\)\\|"
4383 "\\(`endif\\>\\)\\|"
4385 "\\(`ifdef\\>\\)\\|"
4386 "\\(`ifndef\\>\\)\\|"
4388 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
4389 "Add ending comment with given INDENT-STR.
4390 With KILL-EXISTING-COMMENT, remove what was there before.
4391 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
4392 Insert `// case expr ' if this line ends a case block.
4393 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
4394 Insert `// NAME ' if this line ends a function, task, module,
4395 primitive or interface named NAME."
4398 (; Comment close preprocessor directives
4400 (looking-at "\\(`endif\\)\\|\\(`else\\)")
4401 (or kill-existing-comment
4402 (not (save-excursion
4404 (search-backward "//" (point-at-bol) t)))))
4407 (else (if (match-end 2) "!" " ")))
4409 (if kill-existing-comment
4410 (verilog-kill-existing-comment))
4411 (delete-horizontal-space)
4414 (while (and (/= nest 0)
4415 (verilog-re-search-backward verilog-directive-nest-re nil 'move))
4417 ((match-end 1) ; `else
4420 ((match-end 2) ; `endif
4421 (setq nest (1+ nest)))
4422 ((match-end 3) ; `if
4423 (setq nest (1- nest)))
4424 ((match-end 4) ; `ifdef
4425 (setq nest (1- nest)))
4426 ((match-end 5) ; `ifndef
4427 (setq nest (1- nest)))
4428 ((match-end 6) ; `elsif
4439 (skip-chars-forward "^ \t")
4440 (verilog-forward-syntactic-ws)
4443 (skip-chars-forward "a-zA-Z0-9_")
4446 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
4447 (insert (concat " // " else m " " (buffer-substring b e))))
4449 (insert " // unmatched `else, `elsif or `endif")
4452 (; Comment close case/class/function/task/module and named block
4453 (and (looking-at "\\<end")
4454 (or kill-existing-comment
4455 (not (save-excursion
4457 (search-backward "//" (point-at-bol) t)))))
4458 (let ((type (car indent-str)))
4459 (unless (eq type 'declaration)
4460 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends
4461 (if (looking-at verilog-end-block-ordered-re)
4463 (;- This is a case block; search back for the start of this case
4464 (match-end 1) ;; of verilog-end-block-ordered-re
4467 (str "UNMATCHED!!"))
4469 (verilog-leap-to-head)
4471 ((looking-at "\\<randcase\\>")
4472 (setq str "randcase")
4474 ((looking-at "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
4475 (goto-char (match-end 0))
4476 (setq str (concat (match-string 0) " " (verilog-get-expr)))
4480 (if kill-existing-comment
4481 (verilog-kill-existing-comment))
4482 (delete-horizontal-space)
4483 (insert (concat " // " str ))
4484 (if err (ding 't))))
4486 (;- This is a begin..end block
4487 (match-end 2) ;; of verilog-end-block-ordered-re
4488 (let ((str " // UNMATCHED !!")
4494 (verilog-leap-to-head)
4495 (setq there (point))
4496 (if (not (match-end 0))
4500 (if kill-existing-comment
4501 (verilog-kill-existing-comment))
4502 (delete-horizontal-space)
4506 (save-excursion (verilog-beg-of-defun) (point)))
4509 (;-- handle named block differently
4510 (looking-at verilog-named-block-re)
4511 (search-forward ":")
4512 (setq there (point))
4513 (setq str (verilog-get-expr))
4515 (setq str (concat " // block: " str )))
4517 ((verilog-in-case-region-p) ;-- handle case item differently
4519 (setq str (verilog-backward-case-item lim))
4520 (setq there (point))
4522 (setq str (concat " // case: " str )))
4524 (;- try to find "reason" for this begin
4528 ;; (verilog-backward-token)
4529 (verilog-beg-of-statement)
4533 ((looking-at verilog-endcomment-reason-re)
4534 (setq there (match-end 0))
4535 (setq cntx (concat (match-string 0) " "))
4541 (if (and (verilog-continued-line)
4542 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
4544 (goto-char (match-end 0))
4545 (setq there (point))
4547 (concat " // " (match-string 0) " " (verilog-get-expr))))
4553 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4555 (while (verilog-re-search-backward reg nil 'move)
4557 ((match-end 1) ; begin
4558 (setq nest (1- nest)))
4559 ((match-end 2) ; end
4560 (setq nest (1+ nest)))
4564 (goto-char (match-end 0))
4565 (setq there (point))
4567 (setq str (verilog-get-expr))
4568 (setq str (concat " // else: !if" str ))
4573 (goto-char (match-end 0))
4574 (setq there (point))
4576 (setq str (verilog-get-expr))
4577 (setq str (concat " // else: !assert " str ))
4578 (throw 'skip 1)))))))))
4583 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4585 (while (verilog-re-search-backward reg nil 'move)
4587 ((match-end 1) ; begin
4588 (setq nest (1- nest)))
4589 ((match-end 2) ; end
4590 (setq nest (1+ nest)))
4594 (goto-char (match-end 0))
4595 (setq there (point))
4597 (setq str (verilog-get-expr))
4598 (setq str (concat " // else: !if" str ))
4603 (goto-char (match-end 0))
4604 (setq there (point))
4606 (setq str (verilog-get-expr))
4607 (setq str (concat " // else: !assert " str ))
4608 (throw 'skip 1)))))))))
4610 (; always_comb, always_ff, always_latch
4611 (or (match-end 4) (match-end 5) (match-end 6))
4612 (goto-char (match-end 0))
4613 (setq there (point))
4615 (setq str (concat " // " cntx )))
4617 (;- task/function/initial et cetera
4620 (goto-char (match-end 0))
4621 (setq there (point))
4623 (setq str (concat " // " cntx (verilog-get-expr))))
4626 (setq str " // auto-endcomment confused "))))
4629 (verilog-in-case-region-p) ;-- handle case item differently
4631 (setq there (point))
4633 (setq str (verilog-backward-case-item lim))))
4635 (setq str (concat " // case: " str )))
4637 ((verilog-in-fork-region-p)
4639 (setq str " // fork branch" ))
4641 ((looking-at "\\<end\\>")
4644 (verilog-forward-syntactic-ws)
4646 (setq str (verilog-get-expr))
4647 (setq str (concat " // " cntx str )))
4652 (if kill-existing-comment
4653 (verilog-kill-existing-comment))
4654 (delete-horizontal-space)
4656 (> (count-lines here there) verilog-minimum-comment-distance))
4660 (;- this is endclass, which can be nested
4661 (match-end 11) ;; of verilog-end-block-ordered-re
4664 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
4668 (while (verilog-re-search-backward reg nil 'move)
4670 ((match-end 3) ; endclass
4672 (setq string "unmatched endclass")
4675 ((match-end 2) ; endclass
4676 (setq nest (1+ nest)))
4678 ((match-end 1) ; class
4679 (setq nest (1- nest))
4682 (goto-char (match-end 0))
4685 (skip-chars-forward "^ \t")
4686 (verilog-forward-ws&directives)
4689 (skip-chars-forward "a-zA-Z0-9_")
4691 (setq string (buffer-substring b e)))
4695 (insert (concat " // " string ))))
4697 (;- this is end{function,generate,task,module,primitive,table,generate}
4698 ;- which can not be nested.
4700 (let (string reg (name-re nil))
4702 (if kill-existing-comment
4704 (verilog-kill-existing-comment)))
4705 (delete-horizontal-space)
4708 ((match-end 5) ;; of verilog-end-block-ordered-re
4709 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4710 (setq name-re "\\w+\\s-*("))
4711 ((match-end 6) ;; of verilog-end-block-ordered-re
4712 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4713 (setq name-re "\\w+\\s-*("))
4714 ((match-end 7) ;; of verilog-end-block-ordered-re
4715 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
4716 ((match-end 8) ;; of verilog-end-block-ordered-re
4717 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4718 ((match-end 9) ;; of verilog-end-block-ordered-re
4719 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
4720 ((match-end 10) ;; of verilog-end-block-ordered-re
4721 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4722 ((match-end 11) ;; of verilog-end-block-ordered-re
4723 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4724 ((match-end 12) ;; of verilog-end-block-ordered-re
4725 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4726 ((match-end 13) ;; of verilog-end-block-ordered-re
4727 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4728 ((match-end 14) ;; of verilog-end-block-ordered-re
4729 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4730 ((match-end 15) ;; of verilog-end-block-ordered-re
4731 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
4733 (t (error "Problem in verilog-set-auto-endcomments")))
4736 (verilog-re-search-backward reg nil 'move)
4740 (skip-chars-forward "^ \t")
4741 (verilog-forward-ws&directives)
4742 (if (looking-at "static\\|automatic")
4744 (goto-char (match-end 0))
4745 (verilog-forward-ws&directives)))
4746 (if (and name-re (verilog-re-search-forward name-re nil 'move))
4748 (goto-char (match-beginning 0))
4749 (verilog-forward-ws&directives)))
4752 (skip-chars-forward "a-zA-Z0-9_")
4754 (setq string (buffer-substring b e)))
4757 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
4759 (insert (concat " // " string )))
4762 (defun verilog-get-expr()
4763 "Grab expression at point, e.g, case ( a | b & (c ^d))."
4765 (verilog-forward-syntactic-ws)
4766 (skip-chars-forward " \t")
4772 (verilog-forward-syntactic-ws)
4773 (if (looking-at "(")
4776 (while (and (/= par 0)
4777 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4780 (setq par (1+ par)))
4782 (setq par (1- par)))))))
4786 (while (and (/= par 0)
4787 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4790 (setq par (1+ par)))
4792 (setq par (1- par)))))
4796 (while (and (/= par 0)
4797 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
4800 (setq par (1+ par)))
4802 (setq par (1- par)))))
4803 (verilog-forward-syntactic-ws)
4804 (skip-chars-forward "^ \t\n\f")
4806 ((looking-at "/[/\\*]")
4809 (skip-chars-forward "^: \t\n\f")
4811 (str (buffer-substring b e)))
4812 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4813 (setq str (concat (substring str 0 e) "...")))
4816 (defun verilog-expand-vector ()
4817 "Take a signal vector on the current line and expand it to multiple lines.
4818 Useful for creating tri's and other expanded fields."
4820 (verilog-expand-vector-internal "[" "]"))
4822 (defun verilog-expand-vector-internal (bra ket)
4823 "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
4826 (let ((signal-string (buffer-substring (point)
4828 (end-of-line) (point)))))
4832 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
4834 "\\(.*\\)$") signal-string)
4835 (let* ((sig-head (match-string 1 signal-string))
4836 (vec-start (string-to-number (match-string 2 signal-string)))
4837 (vec-end (if (= (match-beginning 3) (match-end 3))
4840 (substring signal-string (1+ (match-beginning 3))
4843 (if (= (match-beginning 4) (match-end 4))
4846 (substring signal-string (+ 2 (match-beginning 4))
4848 (sig-tail (match-string 5 signal-string))
4853 (let ((tmp vec-start))
4854 (setq vec-start vec-end
4856 vec-range (- vec-range))))
4857 (if (< vec-end vec-start)
4858 (while (<= vec-end vec-start)
4859 (setq vec (append vec (list vec-start)))
4860 (setq vec-start (- vec-start vec-range)))
4861 (while (<= vec-start vec-end)
4862 (setq vec (append vec (list vec-start)))
4863 (setq vec-start (+ vec-start vec-range))))
4865 ;; Delete current line
4866 (delete-region (point) (progn (forward-line 0) (point)))
4870 (insert (concat sig-head bra
4871 (int-to-string (car vec)) ket sig-tail "\n"))
4872 (setq vec (cdr vec)))
4877 (defun verilog-strip-comments ()
4878 "Strip all comments from the Verilog code."
4880 (goto-char (point-min))
4881 (while (re-search-forward "//" nil t)
4882 (if (verilog-within-string)
4883 (re-search-forward "\"" nil t)
4884 (if (verilog-in-star-comment-p)
4885 (re-search-forward "\*/" nil t)
4886 (let ((bpt (- (point) 2)))
4888 (delete-region bpt (point))))))
4890 (goto-char (point-min))
4891 (while (re-search-forward "/\\*" nil t)
4892 (if (verilog-within-string)
4893 (re-search-forward "\"" nil t)
4894 (let ((bpt (- (point) 2)))
4895 (re-search-forward "\\*/")
4896 (delete-region bpt (point))))))
4898 (defun verilog-one-line ()
4899 "Convert structural Verilog instances to occupy one line."
4901 (goto-char (point-min))
4902 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
4903 (replace-match "\\1 " nil nil)))
4905 (defun verilog-linter-name ()
4906 "Return name of linter, either surelint or verilint."
4907 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4909 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4911 (cond ((equal compile-word1 "surelint") `surelint)
4912 ((equal compile-word1 "verilint") `verilint)
4913 ((equal lint-word1 "surelint") `surelint)
4914 ((equal lint-word1 "verilint") `verilint)
4915 (t `surelint)))) ;; back compatibility
4917 (defun verilog-lint-off ()
4918 "Convert a Verilog linter warning line into a disable statement.
4920 pci_bfm_null.v, line 46: Unused input: pci_rst_
4921 becomes a comment for the appropriate tool.
4923 The first word of the `compile-command' or `verilog-linter'
4924 variables is used to determine which product is being used.
4926 See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
4928 (let ((linter (verilog-linter-name)))
4929 (cond ((equal linter `surelint)
4930 (verilog-surelint-off))
4931 ((equal linter `verilint)
4932 (verilog-verilint-off))
4933 (t (error "Linter name not set")))))
4935 (defvar compilation-last-buffer)
4936 (defvar next-error-last-buffer)
4938 (defun verilog-surelint-off ()
4939 "Convert a SureLint warning line into a disable statement.
4940 Run from Verilog source window; assumes there is a *compile* buffer
4941 with point set appropriately.
4944 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
4946 // surefire lint_line_off UDDONX"
4948 (let ((buff (if (boundp 'next-error-last-buffer)
4949 next-error-last-buffer
4950 compilation-last-buffer)))
4951 (when (buffer-live-p buff)
4953 (switch-to-buffer buff)
4956 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
4957 (let* ((code (match-string 2))
4958 (file (match-string 3))
4959 (line (match-string 4))
4960 (buffer (get-file-buffer file))
4965 (and (file-exists-p file)
4966 (find-file-noselect file)))
4968 (let* ((pop-up-windows t))
4969 (let ((name (expand-file-name
4971 (format "Find this error in: (default %s) "
4974 (if (file-directory-p name)
4975 (setq name (expand-file-name filename name)))
4977 (and (file-exists-p name)
4978 (find-file-noselect name))))))))
4979 (switch-to-buffer buffer)
4980 (goto-char (point-min))
4981 (forward-line (- (string-to-number line)))
4985 ((verilog-in-slash-comment-p)
4986 (re-search-backward "//")
4988 ((looking-at "// surefire lint_off_line ")
4989 (goto-char (match-end 0))
4990 (let ((lim (point-at-eol)))
4991 (if (re-search-forward code lim 'move)
4993 (insert (concat " " code)))))
4996 ((verilog-in-star-comment-p)
4997 (re-search-backward "/\*")
4998 (insert (format " // surefire lint_off_line %6s" code )))
5000 (insert (format " // surefire lint_off_line %6s" code ))
5003 (defun verilog-verilint-off ()
5004 "Convert a Verilint warning line into a disable statement.
5007 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
5009 //Verilint 240 off // WARNING: Unused input"
5013 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
5014 (replace-match (format
5015 ;; %3s makes numbers 1-999 line up nicely
5016 "\\1//Verilint %3s off // WARNING: \\3"
5019 (verilog-indent-line))))
5021 (defun verilog-auto-save-compile ()
5022 "Update automatics with \\[verilog-auto], save the buffer, and compile."
5024 (verilog-auto) ; Always do it for safety
5026 (compile compile-command))
5028 (defun verilog-preprocess (&optional command filename)
5029 "Preprocess the buffer, similar to `compile', but put output in Verilog-Mode.
5030 Takes optional COMMAND or defaults to `verilog-preprocessor', and
5031 FILENAME to find directory to run in, or defaults to `buffer-file-name`."
5034 (let ((default (verilog-expand-command verilog-preprocessor)))
5035 (set (make-local-variable `verilog-preprocessor)
5036 (read-from-minibuffer "Run Preprocessor (like this): "
5038 'verilog-preprocess-history default)))))
5039 (unless command (setq command (verilog-expand-command verilog-preprocessor)))
5040 (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
5041 (dir (file-name-directory (or filename buffer-file-name)))
5042 (cmd (concat "cd " dir "; " command)))
5043 (with-output-to-temp-buffer "*Verilog-Preprocessed*"
5044 (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
5045 (insert (concat "// " cmd "\n"))
5046 (call-process shell-file-name nil t nil shell-command-switch cmd)
5048 ;; Without this force, it takes a few idle seconds
5049 ;; to get the color, which is very jarring
5050 (when fontlocked (font-lock-fontify-buffer))))))
5057 (defun verilog-warn (string &rest args)
5058 "Print a warning with `format' using STRING and optional ARGS."
5059 (apply 'message (concat "%%Warning: " string) args))
5061 (defun verilog-warn-error (string &rest args)
5062 "Call `error' using STRING and optional ARGS.
5063 If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead."
5064 (if verilog-warn-fatal
5065 (apply 'error string args)
5066 (apply 'verilog-warn string args)))
5068 (defmacro verilog-batch-error-wrapper (&rest body)
5069 "Execute BODY and add error prefix to any errors found.
5070 This lets programs calling batch mode to easily extract error messages."
5071 `(let ((verilog-warn-fatal nil))
5075 (error "%%Error: %s%s" (error-message-string err)
5076 (if (featurep 'xemacs) "\n" "")))))) ;; XEmacs forgets to add a newline
5078 (defun verilog-batch-execute-func (funref &optional no-save)
5079 "Internal processing of a batch command.
5080 Runs FUNREF on all command arguments.
5081 Save the result unless optional NO-SAVE is t."
5082 (verilog-batch-error-wrapper
5083 ;; Setting global variables like that is *VERY NASTY* !!! --Stef
5084 ;; However, this function is called only when Emacs is being used as
5085 ;; a standalone language instead of as an editor, so we'll live.
5087 ;; General globals needed
5088 (setq make-backup-files nil)
5089 (setq-default make-backup-files nil)
5090 (setq enable-local-variables t)
5091 (setq enable-local-eval t)
5092 ;; Make sure any sub-files we read get proper mode
5093 (setq-default major-mode 'verilog-mode)
5094 ;; Ditto files already read in
5096 (when (buffer-file-name buf)
5097 (with-current-buffer buf
5100 ;; Process the files
5101 (mapcar (lambda (buf)
5102 (when (buffer-file-name buf)
5104 (if (not (file-exists-p (buffer-file-name buf)))
5106 (concat "File not found: " (buffer-file-name buf))))
5107 (message (concat "Processing " (buffer-file-name buf)))
5110 (unless no-save (save-buffer)))))
5113 (defun verilog-batch-auto ()
5114 "For use with --batch, perform automatic expansions as a stand-alone tool.
5115 This sets up the appropriate Verilog mode environment, updates automatics
5116 with \\[verilog-auto] on all command-line files, and saves the buffers.
5117 For proper results, multiple filenames need to be passed on the command
5118 line in bottom-up order."
5119 (unless noninteractive
5120 (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5121 (verilog-batch-execute-func `verilog-auto))
5123 (defun verilog-batch-delete-auto ()
5124 "For use with --batch, perform automatic deletion as a stand-alone tool.
5125 This sets up the appropriate Verilog mode environment, deletes automatics
5126 with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
5127 (unless noninteractive
5128 (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5129 (verilog-batch-execute-func `verilog-delete-auto))
5131 (defun verilog-batch-diff-auto ()
5132 "For use with --batch, perform automatic differences as a stand-alone tool.
5133 This sets up the appropriate Verilog mode environment, expand automatics
5134 with \\[verilog-diff-auto] on all command-line files, and reports an error
5135 if any differences are observed. This is appropriate for adding to regressions
5136 to insure automatics are always properly maintained."
5137 (unless noninteractive
5138 (error "Use verilog-batch-diff-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5139 (verilog-batch-execute-func `verilog-diff-auto t))
5141 (defun verilog-batch-inject-auto ()
5142 "For use with --batch, perform automatic injection as a stand-alone tool.
5143 This sets up the appropriate Verilog mode environment, injects new automatics
5144 with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
5145 For proper results, multiple filenames need to be passed on the command
5146 line in bottom-up order."
5147 (unless noninteractive
5148 (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5149 (verilog-batch-execute-func `verilog-inject-auto))
5151 (defun verilog-batch-indent ()
5152 "For use with --batch, reindent an entire file as a stand-alone tool.
5153 This sets up the appropriate Verilog mode environment, calls
5154 \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
5155 (unless noninteractive
5156 (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes
5157 (verilog-batch-execute-func `verilog-indent-buffer))
5163 (defconst verilog-indent-alist
5164 '((block . (+ ind verilog-indent-level))
5165 (case . (+ ind verilog-case-indent))
5166 (cparenexp . (+ ind verilog-indent-level))
5167 (cexp . (+ ind verilog-cexp-indent))
5168 (defun . verilog-indent-level-module)
5169 (declaration . verilog-indent-level-declaration)
5170 (directive . (verilog-calculate-indent-directive))
5171 (tf . verilog-indent-level)
5172 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
5175 (comment . (verilog-comment-indent))
5179 (defun verilog-continued-line-1 (lim)
5180 "Return true if this is a continued line.
5181 Set point to where line starts. Limit search to point LIM."
5182 (let ((continued 't))
5183 (if (eq 0 (forward-line -1))
5186 (verilog-backward-ws&directives lim)
5188 (setq continued nil)
5189 (setq continued (verilog-backward-token))))
5190 (setq continued nil))
5193 (defun verilog-calculate-indent ()
5194 "Calculate the indent of the current Verilog line.
5195 Examine previous lines. Once a line is found that is definitive as to the
5196 type of the current line, return that lines' indent level and its type.
5197 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5199 (let* ((starting_position (point))
5201 (begin (looking-at "[ \t]*begin\\>"))
5202 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
5203 (type (catch 'nesting
5204 ;; Keep working backwards until we can figure out
5205 ;; what type of statement this is.
5206 ;; Basically we need to figure out
5207 ;; 1) if this is a continuation of the previous line;
5208 ;; 2) are we in a block scope (begin..end)
5210 ;; if we are in a comment, done.
5211 (if (verilog-in-star-comment-p)
5212 (throw 'nesting 'comment))
5214 ;; if we have a directive, done.
5215 (if (save-excursion (beginning-of-line)
5216 (and (looking-at verilog-directive-re-1)
5217 (not (or (looking-at "[ \t]*`[ou]vm_")
5218 (looking-at "[ \t]*`vmm_")))))
5219 (throw 'nesting 'directive))
5220 ;; indent structs as if there were module level
5221 (if (verilog-in-struct-p)
5222 (throw 'nesting 'block))
5224 ;; if we are in a parenthesized list, and the user likes to indent these, return.
5225 ;; unless we are in the newfangled coverpoint or constraint blocks
5227 verilog-indent-lists
5229 (not (verilog-in-coverage-p))
5232 (throw 'nesting 'block)))
5234 ;; See if we are continuing a previous line
5236 ;; trap out if we crawl off the top of the buffer
5237 (if (bobp) (throw 'nesting 'cpp))
5239 (if (verilog-continued-line-1 lim)
5242 (not (looking-at verilog-complete-reg))
5243 (verilog-continued-line-1 lim))
5244 (progn (goto-char sp)
5245 (throw 'nesting 'cexp))
5250 (not verilog-indent-begin-after-if)
5251 (looking-at verilog-no-indent-begin-re))
5254 (skip-chars-forward " \t")
5255 (throw 'nesting 'statement))
5257 (throw 'nesting 'cexp))))
5258 ;; not a continued line
5259 (goto-char starting_position))
5261 (if (looking-at "\\<else\\>")
5262 ;; search back for governing if, striding across begin..end pairs
5265 (while (verilog-re-search-backward verilog-ends-re nil 'move)
5267 ((match-end 1) ; else, we're in deep
5268 (setq elsec (1+ elsec)))
5270 (setq elsec (1- elsec))
5272 (if verilog-align-ifelse
5273 (throw 'nesting 'statement)
5274 (progn ;; back up to first word on this line
5276 (verilog-forward-syntactic-ws)
5277 (throw 'nesting 'statement)))))
5278 ((match-end 3) ; assert block
5279 (setq elsec (1- elsec))
5280 (verilog-beg-of-statement) ;; doesn't get to beginning
5281 (if (looking-at verilog-property-re)
5282 (throw 'nesting 'statement) ; We don't need an endproperty for these
5283 (throw 'nesting 'block) ;We still need an endproperty
5286 ; try to leap back to matching outward block by striding across
5287 ; indent level changing tokens then immediately
5288 ; previous line governs indentation.
5289 (let (( reg) (nest 1))
5290 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
5292 ((match-end 4) ; end
5293 ;; Search back for matching begin
5294 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
5295 ((match-end 5) ; endcase
5296 ;; Search back for matching case
5297 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5298 ((match-end 6) ; endfunction
5299 ;; Search back for matching function
5300 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5301 ((match-end 7) ; endtask
5302 ;; Search back for matching task
5303 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
5304 ((match-end 8) ; endspecify
5305 ;; Search back for matching specify
5306 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5307 ((match-end 9) ; endtable
5308 ;; Search back for matching table
5309 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5310 ((match-end 10) ; endgenerate
5311 ;; Search back for matching generate
5312 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5313 ((match-end 11) ; joins
5314 ;; Search back for matching fork
5315 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
5316 ((match-end 12) ; class
5317 ;; Search back for matching class
5318 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5319 ((match-end 13) ; covergroup
5320 ;; Search back for matching covergroup
5321 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
5323 (while (verilog-re-search-backward reg nil 'move)
5325 ((match-end 1) ; begin
5326 (setq nest (1- nest))
5329 ((match-end 2) ; end
5330 (setq nest (1+ nest)))))
5332 (throw 'nesting (verilog-calc-1)))
5336 ;; Return type of block and indent level.
5339 (if (> par 0) ; Unclosed Parenthesis
5340 (list 'cparenexp par)
5343 (list type (verilog-case-indent-level)))
5344 ((eq type 'statement)
5345 (list type (current-column)))
5349 (list type (verilog-current-indent-level))))))))
5351 (defun verilog-wai ()
5352 "Show matching nesting block for debugging."
5355 (let* ((type (verilog-calc-1))
5357 ;; Return type of block and indent level.
5361 verilog-indent-lists
5362 (not(or (verilog-in-coverage-p)
5363 (verilog-in-struct-p)))
5368 (setq depth (verilog-case-indent-level)))
5369 ((eq type 'statement)
5370 (setq depth (current-column)))
5374 (setq depth (verilog-current-indent-level)))))
5375 (message "You are at nesting %s depth %d" type depth))))
5376 (defun verilog-calc-1 ()
5378 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)")))
5379 (while (verilog-re-search-backward re nil 'move)
5382 ((equal (char-after) ?\{)
5383 (if (verilog-at-constraint-p)
5384 (throw 'nesting 'block)))
5386 ((equal (char-after) ?\})
5387 (let ((there (verilog-at-close-constraint-p)))
5388 (if there ;; we are at the } that closes a constraint. Find the { that opens it
5392 (verilog-beg-of-statement)))))
5394 ((looking-at verilog-beg-block-re-ordered)
5396 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
5397 (let ((here (point)))
5398 (verilog-beg-of-statement)
5399 (if (looking-at verilog-extended-case-re)
5400 (throw 'nesting 'case)
5402 (throw 'nesting 'case))
5404 ((match-end 4) ; *sigh* could be "disable fork"
5405 (let ((here (point)))
5406 (verilog-beg-of-statement)
5407 (if (looking-at verilog-disable-fork-re)
5408 t ; this is a normal statement
5409 (progn ; or is fork, starts a new block
5411 (throw 'nesting 'block)))))
5413 ((match-end 27) ; *sigh* might be a clocking declaration
5414 (let ((here (point)))
5415 (if (verilog-in-paren)
5416 t ; this is a normal statement
5417 (progn ; or is fork, starts a new block
5419 (throw 'nesting 'block)))))
5421 ;; need to consider typedef struct here...
5422 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
5423 ; *sigh* These words have an optional prefix:
5424 ; extern {virtual|protected}? function a();
5425 ; typedef class foo;
5426 ; and we don't want to confuse this with
5431 (verilog-beg-of-statement)
5432 (if (looking-at verilog-beg-block-re-ordered)
5433 (throw 'nesting 'block)
5434 (throw 'nesting 'defun)))
5437 ((looking-at "\\<property\\>")
5439 ; {assert|assume|cover} property (); are complete
5440 ; and could also be labeled: - foo: assert property
5442 ; property ID () ... needs end_property
5443 (verilog-beg-of-statement)
5444 (if (looking-at verilog-property-re)
5445 (throw 'continue 'statement) ; We don't need an endproperty for these
5446 (throw 'nesting 'block) ;We still need an endproperty
5449 (t (throw 'nesting 'block))))
5451 ((looking-at verilog-end-block-re)
5452 (verilog-leap-to-head)
5453 (if (verilog-in-case-region-p)
5455 (verilog-leap-to-case-head)
5456 (if (looking-at verilog-extended-case-re)
5457 (throw 'nesting 'case)))))
5459 ((looking-at verilog-defun-level-re)
5460 (if (looking-at verilog-defun-level-generate-only-re)
5461 (if (verilog-in-generate-region-p)
5462 (throw 'continue 'foo) ; always block in a generate - keep looking
5463 (throw 'nesting 'defun))
5464 (throw 'nesting 'defun)))
5466 ((looking-at verilog-cpp-level-re)
5467 (throw 'nesting 'cpp))
5470 (throw 'nesting 'cpp)))))
5472 (throw 'nesting 'cpp))))
5474 (defun verilog-calculate-indent-directive ()
5475 "Return indentation level for directive.
5476 For speed, the searcher looks at the last directive, not the indent
5477 of the appropriate enclosing block."
5478 (let ((base -1) ;; Indent of the line that determines our indentation
5479 (ind 0)) ;; Relative offset caused by other directives (like `endif on same line as `else)
5480 ;; Start at current location, scan back for another directive
5484 (while (and (< base 0)
5485 (verilog-re-search-backward verilog-directive-re nil t))
5486 (cond ((save-excursion (skip-chars-backward " \t") (bolp))
5487 (setq base (current-indentation))))
5488 (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL
5489 (setq ind (- ind verilog-indent-level-directive)))
5490 ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL
5491 (setq ind (+ ind verilog-indent-level-directive)))
5492 ((looking-at verilog-directive-begin)
5493 (setq ind (+ ind verilog-indent-level-directive)))))
5494 ;; Adjust indent to starting indent of critical line
5495 (setq ind (max 0 (+ ind base))))
5499 (skip-chars-forward " \t")
5500 (cond ((or (looking-at verilog-directive-middle)
5501 (looking-at verilog-directive-end))
5502 (setq ind (max 0 (- ind verilog-indent-level-directive))))))
5505 (defun verilog-leap-to-case-head ()
5508 (verilog-re-search-backward
5510 "\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
5511 "\\|\\(\\<endcase\\>\\)" )
5515 (let ((here (point)))
5516 (verilog-beg-of-statement)
5517 (unless (looking-at verilog-extended-case-re)
5519 (setq nest (1- nest)))
5521 (setq nest (1+ nest)))
5526 (defun verilog-leap-to-head ()
5527 "Move point to the head of this block.
5528 Jump from end to matching begin, from endcase to matching case, and so on."
5534 ((looking-at "\\<end\\>")
5535 ;; 1: Search back for matching begin
5536 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
5537 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
5538 ((looking-at "\\<endtask\\>")
5539 ;; 2: Search back for matching task
5540 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)")
5542 ((looking-at "\\<endcase\\>")
5544 (verilog-leap-to-case-head) )
5545 (setq reg nil) ; to force skip
5548 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
5549 ;; 4: Search back for matching fork
5550 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5551 ((looking-at "\\<endclass\\>")
5552 ;; 5: Search back for matching class
5553 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5554 ((looking-at "\\<endtable\\>")
5555 ;; 6: Search back for matching table
5556 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5557 ((looking-at "\\<endspecify\\>")
5558 ;; 7: Search back for matching specify
5559 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5560 ((looking-at "\\<endfunction\\>")
5561 ;; 8: Search back for matching function
5562 (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<function\\>\\)")
5564 ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5565 ((looking-at "\\<endgenerate\\>")
5566 ;; 8: Search back for matching generate
5567 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5568 ((looking-at "\\<endgroup\\>")
5569 ;; 10: Search back for matching covergroup
5570 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
5571 ((looking-at "\\<endproperty\\>")
5572 ;; 11: Search back for matching property
5573 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
5574 ((looking-at verilog-uvm-end-re)
5575 ;; 12: Search back for matching sequence
5576 (setq reg (concat "\\(" verilog-uvm-begin-re "\\|" verilog-uvm-end-re "\\)")))
5577 ((looking-at verilog-ovm-end-re)
5578 ;; 12: Search back for matching sequence
5579 (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
5580 ((looking-at verilog-vmm-end-re)
5581 ;; 12: Search back for matching sequence
5582 (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
5583 ((looking-at "\\<endinterface\\>")
5584 ;; 12: Search back for matching interface
5585 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
5586 ((looking-at "\\<endsequence\\>")
5587 ;; 12: Search back for matching sequence
5588 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
5589 ((looking-at "\\<endclocking\\>")
5590 ;; 12: Search back for matching clocking
5591 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
5594 (if (eq nesting 'yes)
5596 (while (verilog-re-search-backward reg nil 'move)
5598 ((match-end 1) ; begin
5599 (if (looking-at "fork")
5600 (let ((here (point)))
5601 (verilog-beg-of-statement)
5602 (unless (looking-at verilog-disable-fork-re)
5604 (setq nest (1- nest))))
5605 (setq nest (1- nest)))
5607 ;; Now previous line describes syntax
5612 ((match-end 2) ; end
5613 (setq nest (1+ nest)))
5615 ;; endcase, jump to case
5617 (setq nest (1+ nest))
5619 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5621 ;; join, jump to fork
5623 (setq nest (1+ nest))
5625 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5629 (verilog-re-search-backward reg nil 'move)
5630 (match-end 1)) ; task -> could be virtual and/or protected
5632 (verilog-beg-of-statement)
5634 (throw 'skip 1)))))))
5636 (defun verilog-continued-line ()
5637 "Return true if this is a continued line.
5638 Set point to where line starts."
5639 (let ((continued 't))
5640 (if (eq 0 (forward-line -1))
5643 (verilog-backward-ws&directives)
5645 (setq continued nil)
5646 (while (and continued
5648 (skip-chars-backward " \t")
5650 (setq continued (verilog-backward-token)))))
5651 (setq continued nil))
5654 (defun verilog-backward-token ()
5655 "Step backward token, returning true if this is a continued line."
5657 (verilog-backward-syntactic-ws)
5661 (;-- Anything ending in a ; is complete
5662 (= (preceding-char) ?\;)
5664 (; If a "}" is prefixed by a ";", then this is a complete statement
5665 ; i.e.: constraint foo { a = b; }
5666 (= (preceding-char) ?\})
5669 (not(verilog-at-close-constraint-p))))
5670 (;-- constraint foo { a = b }
5671 ; is a complete statement. *sigh*
5672 (= (preceding-char) ?\{)
5675 (not (verilog-at-constraint-p))))
5677 (= (preceding-char) ?\")
5679 (verilog-skip-backward-comment-or-string)
5683 (= (preceding-char) ?\])
5685 (verilog-backward-open-bracket)
5688 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
5689 ; also could be simply '@(foo)'
5691 ; (b, ... which ISN'T complete
5692 ;;;; Do we need this???
5693 (= (preceding-char) ?\))
5696 (verilog-backward-up-list 1)
5697 (verilog-backward-syntactic-ws)
5698 (let ((back (point)))
5702 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
5703 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
5704 ((looking-at verilog-uvm-statement-re)
5706 ((looking-at verilog-uvm-begin-re)
5708 ((looking-at verilog-uvm-end-re)
5710 ((looking-at verilog-ovm-statement-re)
5712 ((looking-at verilog-ovm-begin-re)
5714 ((looking-at verilog-ovm-end-re)
5716 ;; JBA find VMM macros
5717 ((looking-at verilog-vmm-statement-re)
5719 ((looking-at verilog-vmm-begin-re)
5721 ((looking-at verilog-vmm-end-re)
5723 ;; JBA trying to catch macro lines with no ; at end
5724 ((looking-at "\\<`")
5729 ((= (preceding-char) ?\@)
5732 (verilog-backward-token)
5733 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
5734 ((= (preceding-char) ?\#)
5738 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
5741 (while (= (preceding-char) ?\_)
5744 ((looking-at "\\<else\\>")
5746 ((looking-at verilog-behavioral-block-beg-re)
5748 ((looking-at verilog-indent-re)
5753 (verilog-backward-syntactic-ws)
5755 ((= (preceding-char) ?\:)
5757 (verilog-backward-syntactic-ws)
5759 (if (looking-at verilog-nameable-item-re )
5762 ((= (preceding-char) ?\#)
5765 ((= (preceding-char) ?\`)
5773 (defun verilog-backward-syntactic-ws ()
5774 "Move backwards putting point after first non-whitespace non-comment."
5775 (verilog-skip-backward-comments)
5776 (forward-comment (- (buffer-size))))
5778 (defun verilog-backward-syntactic-ws-quick ()
5779 "As with `verilog-backward-syntactic-ws' but use `verilog-scan' cache."
5780 (while (cond ((bobp)
5782 ((> (skip-syntax-backward " ") 0)
5784 ((eq (preceding-char) ?\n) ;; \n's terminate // so aren't space syntax
5787 ((or (verilog-inside-comment-or-string-p (1- (point)))
5788 (verilog-inside-comment-or-string-p (point)))
5789 (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
5792 (defun verilog-forward-syntactic-ws ()
5793 (verilog-skip-forward-comment-p)
5794 (forward-comment (buffer-size)))
5796 (defun verilog-backward-ws&directives (&optional bound)
5797 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
5798 Optional BOUND limits search."
5800 (let* ((bound (or bound (point-min)))
5803 (if (< bound (point))
5805 (let ((state (save-excursion (verilog-syntax-ppss))))
5807 ((nth 7 state) ;; in // comment
5808 (verilog-re-search-backward "//" nil 'move)
5809 (skip-chars-backward "/"))
5810 ((nth 4 state) ;; in /* */ comment
5811 (verilog-re-search-backward "/\*" nil 'move))))
5812 (narrow-to-region bound (point))
5813 (while (/= here (point))
5815 (verilog-skip-backward-comments)
5820 ((and verilog-highlight-translate-off
5821 (verilog-within-translate-off))
5822 (verilog-back-to-start-translate-off (point-min)))
5823 ((looking-at verilog-directive-re-1)
5827 (if p (goto-char p))))))))
5829 (defun verilog-forward-ws&directives (&optional bound)
5830 "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
5831 Optional BOUND limits search."
5833 (let* ((bound (or bound (point-max)))
5836 (if (> bound (point))
5838 (let ((state (save-excursion (verilog-syntax-ppss))))
5840 ((nth 7 state) ;; in // comment
5843 (skip-chars-forward " \t\n\f")
5845 ((nth 4 state) ;; in /* */ comment
5846 (verilog-re-search-forward "\*\/\\s-*" nil 'move))))
5847 (narrow-to-region (point) bound)
5848 (while (/= here (point))
5851 (forward-comment (buffer-size))
5852 (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ;; Attribute
5853 (goto-char (match-end 0)))
5856 (if (looking-at verilog-directive-re-1)
5859 (beginning-of-line 2))))))))
5861 (defun verilog-in-comment-p ()
5862 "Return true if in a star or // comment."
5863 (let ((state (save-excursion (verilog-syntax-ppss))))
5864 (or (nth 4 state) (nth 7 state))))
5866 (defun verilog-in-star-comment-p ()
5867 "Return true if in a star comment."
5868 (let ((state (save-excursion (verilog-syntax-ppss))))
5870 (nth 4 state) ; t if in a comment of style a // or b /**/
5872 (nth 7 state) ; t if in a comment of style b /**/
5875 (defun verilog-in-slash-comment-p ()
5876 "Return true if in a slash comment."
5877 (let ((state (save-excursion (verilog-syntax-ppss))))
5880 (defun verilog-in-comment-or-string-p ()
5881 "Return true if in a string or comment."
5882 (let ((state (save-excursion (verilog-syntax-ppss))))
5883 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
5885 (defun verilog-in-attribute-p ()
5886 "Return true if point is in an attribute (* [] attribute *)."
5889 (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
5890 (numberp (match-beginning 1)))))
5892 (defun verilog-in-parameter-p ()
5893 "Return true if point is in a parameter assignment #( p1=1, p2=5)."
5896 (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move)
5897 (numberp (match-beginning 1)))))
5899 (defun verilog-in-escaped-name-p ()
5900 "Return true if in an escaped name."
5903 (skip-chars-backward "^ \t\n\f")
5904 (if (equal (char-after (point) ) ?\\ )
5907 (defun verilog-in-directive-p ()
5908 "Return true if in a directive."
5911 (looking-at verilog-directive-re-1)))
5913 (defun verilog-in-parenthesis-p ()
5914 "Return true if in a ( ) expression (but not { } or [ ])."
5917 (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move)
5918 (numberp (match-beginning 1)))))
5920 (defun verilog-in-paren ()
5921 "Return true if in a parenthetical expression.
5922 May cache result using `verilog-syntax-ppss'."
5923 (let ((state (save-excursion (verilog-syntax-ppss))))
5924 (> (nth 0 state) 0 )))
5926 (defun verilog-in-paren-quick ()
5927 "Return true if in a parenthetical expression.
5928 Always starts from `point-min', to allow inserts with hooks disabled."
5929 ;; The -quick refers to its use alongside the other -quick functions,
5930 ;; not that it's likely to be faster than verilog-in-paren.
5931 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
5932 (> (nth 0 state) 0 )))
5934 (defun verilog-in-struct-p ()
5935 "Return true if in a struct declaration."
5938 (if (verilog-in-paren)
5940 (verilog-backward-up-list 1)
5941 (verilog-at-struct-p)
5945 (defun verilog-in-coverage-p ()
5946 "Return true if in a constraint or coverpoint expression."
5949 (if (verilog-in-paren)
5951 (verilog-backward-up-list 1)
5952 (verilog-at-constraint-p)
5955 (defun verilog-at-close-constraint-p ()
5956 "If at the } that closes a constraint or covergroup, return true."
5958 (equal (char-after) ?\})
5962 (verilog-backward-ws&directives)
5963 (if (equal (char-before) ?\;)
5967 (defun verilog-at-constraint-p ()
5968 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
5971 (equal (char-after) ?\{)
5973 (progn (backward-char 1)
5974 (verilog-backward-ws&directives)
5975 (equal (char-before) ?\;))))
5977 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move)
5981 (defun verilog-at-struct-p ()
5982 "If at the { of a struct, return true, moving point to struct."
5984 (if (and (equal (char-after) ?\{)
5985 (verilog-backward-token))
5986 (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
5989 (defun verilog-parenthesis-depth ()
5990 "Return non zero if in parenthetical-expression."
5991 (save-excursion (nth 1 (verilog-syntax-ppss))))
5994 (defun verilog-skip-forward-comment-or-string ()
5995 "Return true if in a string or comment."
5996 (let ((state (save-excursion (verilog-syntax-ppss))))
5998 ((nth 3 state) ;Inside string
5999 (search-forward "\"")
6001 ((nth 7 state) ;Inside // comment
6004 ((nth 4 state) ;Inside any comment (hence /**/)
6005 (search-forward "*/"))
6009 (defun verilog-skip-backward-comment-or-string ()
6010 "Return true if in a string or comment."
6011 (let ((state (save-excursion (verilog-syntax-ppss))))
6013 ((nth 3 state) ;Inside string
6014 (search-backward "\"")
6016 ((nth 7 state) ;Inside // comment
6017 (search-backward "//")
6018 (skip-chars-backward "/")
6020 ((nth 4 state) ;Inside /* */ comment
6021 (search-backward "/*")
6026 (defun verilog-skip-backward-comments ()
6027 "Return true if a comment was skipped."
6031 (let ((state (save-excursion (verilog-syntax-ppss))))
6033 ((nth 7 state) ;Inside // comment
6034 (search-backward "//")
6035 (skip-chars-backward "/")
6036 (skip-chars-backward " \t\n\f")
6038 ((nth 4 state) ;Inside /* */ comment
6039 (search-backward "/*")
6040 (skip-chars-backward " \t\n\f")
6043 (= (char-before) ?\/)
6044 (= (char-before (1- (point))) ?\*))
6045 (goto-char (- (point) 2))
6046 t) ;; Let nth 4 state handle the rest
6048 (= (char-before) ?\))
6049 (= (char-before (1- (point))) ?\*))
6050 (goto-char (- (point) 2))
6051 (if (search-backward "(*" nil t)
6053 (skip-chars-backward " \t\n\f")
6056 (goto-char (+ (point) 2))
6059 (/= (skip-chars-backward " \t\n\f") 0))))))))
6061 (defun verilog-skip-forward-comment-p ()
6062 "If in comment, move to end and return true."
6064 (state (save-excursion (verilog-syntax-ppss)))
6066 ((nth 3 state) ;Inside string
6068 ((nth 7 state) ;Inside // comment
6072 ((nth 4 state) ;Inside /* comment
6073 (search-forward "*/")
6075 ((verilog-in-attribute-p) ;Inside (* attribute
6076 (search-forward "*)" nil t)
6079 (skip-chars-forward " \t\n\f")
6082 ((looking-at "\\/\\*")
6085 (goto-char (match-end 0))
6086 (if (search-forward "*/" nil t)
6088 (skip-chars-forward " \t\n\f")
6093 ((looking-at "(\\*")
6096 (goto-char (match-end 0))
6097 (if (search-forward "*)" nil t)
6099 (skip-chars-forward " \t\n\f")
6107 (defun verilog-indent-line-relative ()
6108 "Cheap version of indent line.
6109 Only look at a few lines to determine indent level."
6113 (if (looking-at "^[ \t]*$")
6114 (cond ;- A blank line; No need to be too smart.
6116 (setq indent-str (list 'cpp 0)))
6117 ((verilog-continued-line)
6118 (let ((sp1 (point)))
6119 (if (verilog-continued-line)
6123 (list 'statement (verilog-current-indent-level))))
6125 (setq indent-str (list 'block (verilog-current-indent-level)))))
6128 (setq indent-str (verilog-calculate-indent))))
6129 (progn (skip-chars-forward " \t")
6130 (setq indent-str (verilog-calculate-indent))))
6131 (verilog-do-indent indent-str)))
6133 (defun verilog-indent-line ()
6134 "Indent for special part of code."
6135 (verilog-do-indent (verilog-calculate-indent)))
6137 (defun verilog-do-indent (indent-str)
6138 (let ((type (car indent-str))
6139 (ind (car (cdr indent-str))))
6141 (; handle continued exp
6143 (let ((here (point)))
6144 (verilog-backward-syntactic-ws)
6147 (= (preceding-char) ?\,)
6148 (= (preceding-char) ?\])
6150 (verilog-beg-of-statement-1)
6151 (looking-at verilog-declaration-re)))
6156 (verilog-beg-of-statement-1)
6158 (if (looking-at verilog-declaration-re)
6159 (progn ;; we have multiple words
6160 (goto-char (match-end 0))
6161 (skip-chars-forward " \t")
6163 ((and verilog-indent-declaration-macros
6164 (= (following-char) ?\`))
6168 (skip-chars-forward " \t")))
6169 ((= (following-char) ?\[)
6172 (verilog-backward-up-list -1)
6173 (skip-chars-forward " \t"))))
6177 (+ (current-column) verilog-cexp-indent))))))
6179 (indent-line-to val)
6180 (if (and (not verilog-indent-lists)
6182 (verilog-pretty-declarations-auto))
6184 ((= (preceding-char) ?\) )
6186 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6187 (indent-line-to val)))
6191 (verilog-beg-of-statement-1)
6192 (if (and (< (point) here)
6193 (verilog-re-search-forward "=[ \\t]*" here 'move))
6194 (setq val (current-column))
6195 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
6197 (indent-line-to val))))))
6199 (; handle inside parenthetical expressions
6200 (eq type 'cparenexp)
6202 (val (save-excursion
6203 (verilog-backward-up-list 1)
6205 (if verilog-indent-lists
6206 (skip-chars-forward " \t")
6207 (verilog-forward-syntactic-ws))
6211 (decl (save-excursion
6213 (verilog-forward-syntactic-ws)
6215 (looking-at verilog-declaration-re))))
6216 (indent-line-to val)
6218 (verilog-pretty-declarations-auto))))
6220 (;-- Handle the ends
6222 (looking-at verilog-end-block-re )
6223 (verilog-at-close-constraint-p))
6224 (let ((val (if (eq type 'statement)
6225 (- ind verilog-indent-level)
6227 (indent-line-to val)))
6229 (;-- Case -- maybe line 'em up
6230 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
6233 ((looking-at "\\<endcase\\>")
6234 (indent-line-to ind))
6236 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6237 (indent-line-to val))))))
6240 (and (eq type 'defun)
6241 (looking-at verilog-zero-indent-re))
6248 (looking-at verilog-declaration-re))
6249 (verilog-indent-declaration ind))
6251 (;-- Everything else
6253 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6254 (indent-line-to val))))
6256 (if (looking-at "[ \t]+$")
6257 (skip-chars-forward " \t"))
6258 indent-str ; Return indent data
6261 (defun verilog-current-indent-level ()
6262 "Return the indent-level of the current statement."
6266 (setq par-pos (verilog-parenthesis-depth))
6270 (setq par-pos (verilog-parenthesis-depth)))
6271 (skip-chars-forward " \t")
6274 (defun verilog-case-indent-level ()
6275 "Return the indent-level of the current statement.
6276 Do not count named blocks or case-statements."
6278 (skip-chars-forward " \t")
6280 ((looking-at verilog-named-block-re)
6282 ((and (not (looking-at verilog-extended-case-re))
6283 (looking-at "^[^:;]+[ \t]*:"))
6284 (verilog-re-search-forward ":" nil t)
6285 (skip-chars-forward " \t")
6288 (current-column)))))
6290 (defun verilog-indent-comment ()
6291 "Indent current line as comment."
6294 ((verilog-in-star-comment-p)
6296 (re-search-backward "/\\*" nil t)
6297 (1+(current-column))))
6302 (re-search-backward "//" nil t)
6303 (current-column))))))
6304 (indent-line-to stcol)
6307 (defun verilog-more-comment ()
6308 "Make more comment lines like the previous."
6312 ((verilog-in-star-comment-p)
6315 (re-search-backward "/\\*" nil t)
6316 (1+(current-column))))
6321 (re-search-backward "//" nil t)
6322 (current-column))))))
6328 (skip-chars-forward " \t")
6332 (defun verilog-comment-indent (&optional arg)
6333 "Return the column number the line should be indented to.
6334 ARG is ignored, for `comment-indent-function' compatibility."
6336 ((verilog-in-star-comment-p)
6338 (re-search-backward "/\\*" nil t)
6339 (1+(current-column))))
6344 (re-search-backward "//" nil t)
6345 (current-column)))))
6349 (defun verilog-pretty-declarations-auto (&optional quiet)
6350 "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'."
6351 (when (or (eq 'all verilog-auto-lineup)
6352 (eq 'declarations verilog-auto-lineup))
6353 (verilog-pretty-declarations quiet)))
6355 (defun verilog-pretty-declarations (&optional quiet)
6356 "Line up declarations around point.
6357 Be verbose about progress unless optional QUIET set."
6359 (let* ((m1 (make-marker))
6373 ; (verilog-beg-of-statement-1)
6375 (verilog-forward-syntactic-ws)
6376 (and (not (verilog-in-directive-p)) ;; could have `define input foo
6377 (looking-at verilog-declaration-re)))
6379 (if (verilog-parenthesis-depth)
6380 ;; in an argument list or parameter block
6381 (setq el (verilog-backward-up-list -1)
6384 (verilog-backward-up-list 1)
6385 (forward-line) ;; ignore ( input foo,
6386 (verilog-re-search-forward verilog-declaration-re el 'move)
6387 (goto-char (match-beginning 0))
6388 (skip-chars-backward " \t")
6390 startpos (set-marker (make-marker) start)
6393 (verilog-backward-up-list -1)
6395 (verilog-backward-syntactic-ws)
6397 endpos (set-marker (make-marker) end)
6401 (skip-chars-forward " \t")
6404 ;; in a declaration block (not in argument list)
6407 (verilog-beg-of-statement-1)
6408 (while (and (looking-at verilog-declaration-re)
6410 (skip-chars-backward " \t")
6413 (verilog-backward-syntactic-ws)
6415 (verilog-beg-of-statement-1))
6417 startpos (set-marker (make-marker) start)
6420 (verilog-end-of-statement)
6421 (setq e (point)) ;Might be on last line
6422 (verilog-forward-syntactic-ws)
6423 (while (looking-at verilog-declaration-re)
6424 (verilog-end-of-statement)
6426 (verilog-forward-syntactic-ws))
6428 endpos (set-marker (make-marker) end)
6431 (verilog-do-indent (verilog-calculate-indent))
6432 (verilog-forward-ws&directives)
6434 ;; OK, start and end are set
6435 (goto-char (marker-position startpos))
6436 (if (and (not quiet)
6437 (> (- end start) 100))
6438 (message "Lining up declarations..(please stand by)"))
6439 ;; Get the beginning of line indent first
6440 (while (progn (setq e (marker-position endpos))
6443 ((save-excursion (skip-chars-backward " \t")
6445 (verilog-forward-ws&directives)
6446 (indent-line-to base-ind)
6447 (verilog-forward-ws&directives)
6449 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6452 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6455 ;; Now find biggest prefix
6456 (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
6457 ;; Now indent each line.
6458 (goto-char (marker-position startpos))
6459 (while (progn (setq e (marker-position endpos))
6460 (setq r (- e (point)))
6463 (unless quiet (message "%d" r))
6464 ;;(verilog-do-indent (verilog-calculate-indent)))
6465 (verilog-forward-ws&directives)
6467 ((or (and verilog-indent-declaration-macros
6468 (looking-at verilog-declaration-re-2-macro))
6469 (looking-at verilog-declaration-re-2-no-macro))
6470 (let ((p (match-end 0)))
6472 (if (verilog-re-search-forward "[[#`]" p 'move)
6476 (goto-char (marker-position m1))
6482 ((verilog-continued-line-1 (marker-position startpos))
6484 (indent-line-to ind))
6485 ((verilog-in-struct-p)
6486 ;; could have a declaration of a user defined item
6488 (verilog-end-of-statement))
6489 (t ; Must be comment or white space
6491 (verilog-forward-ws&directives)
6494 (unless quiet (message "")))))))
6496 (defun verilog-pretty-expr (&optional quiet myre)
6497 "Line up expressions around point, optionally QUIET with regexp MYRE ignored."
6499 (if (not (verilog-in-comment-or-string-p))
6501 (let ( (rexp (concat "^\\s-*" verilog-complete-reg))
6502 (rexp1 (concat "^\\s-*" verilog-basic-complete-re)))
6504 (if (and (not (looking-at rexp ))
6505 (looking-at verilog-assignment-operation-re)
6507 (goto-char (match-end 2))
6508 (and (not (verilog-in-attribute-p))
6509 (not (verilog-in-parameter-p))
6510 (not (verilog-in-comment-or-string-p)))))
6511 (let* ((here (point))
6517 (verilog-backward-syntactic-ws)
6519 (while (and (not (looking-at rexp1))
6520 (looking-at verilog-assignment-operation-re)
6524 (verilog-backward-syntactic-ws)
6526 ) ;Ack, need to grok `define
6532 (setq e (point)) ;Might be on last line
6533 (verilog-forward-syntactic-ws)
6536 (not (looking-at rexp1 ))
6537 (looking-at verilog-assignment-operation-re)
6540 (not (eq e (point)))))
6542 (verilog-forward-syntactic-ws)
6546 (endpos (set-marker (make-marker) end))
6550 (verilog-do-indent (verilog-calculate-indent))
6551 (if (and (not quiet)
6552 (> (- end start) 100))
6553 (message "Lining up expressions..(please stand by)"))
6555 ;; Set indent to minimum throughout region
6556 (while (< (point) (marker-position endpos))
6558 (verilog-just-one-space verilog-assignment-operation-re)
6560 (verilog-do-indent (verilog-calculate-indent))
6562 (verilog-forward-syntactic-ws)
6565 ;; Now find biggest prefix
6566 (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))
6568 ;; Now indent each line.
6570 (while (progn (setq e (marker-position endpos))
6571 (setq r (- e (point)))
6574 (if (not quiet) (message "%d" r))
6576 ((looking-at verilog-assignment-operation-re)
6577 (goto-char (match-beginning 2))
6578 (if (not (or (verilog-in-parenthesis-p) ;; leave attributes and comparisons alone
6579 (verilog-in-coverage-p)))
6580 (if (eq (char-after) ?=)
6581 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
6585 ((verilog-continued-line-1 start)
6587 (indent-line-to ind))
6588 (t ; Must be comment or white space
6590 (verilog-forward-ws&directives)
6594 (unless quiet (message ""))
6597 (defun verilog-just-one-space (myre)
6598 "Remove extra spaces around regular expression MYRE."
6600 (if (and (not(looking-at verilog-complete-reg))
6602 (let ((p1 (match-end 1))
6608 (just-one-space)))))
6610 (defun verilog-indent-declaration (baseind)
6611 "Indent current lines as declaration.
6612 Line up the variable names based on previous declaration's indentation.
6613 BASEIND is the base indent to offset everything."
6615 (let ((pos (point-marker))
6616 (lim (save-excursion
6617 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
6618 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
6624 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6625 (indent-line-to val)
6627 ;; Use previous declaration (in this module) as template.
6628 (if (or (eq 'all verilog-auto-lineup)
6629 (eq 'declarations verilog-auto-lineup))
6630 (if (verilog-re-search-backward
6631 (or (and verilog-indent-declaration-macros
6632 verilog-declaration-re-1-macro)
6633 verilog-declaration-re-1-no-macro) lim t)
6635 (goto-char (match-end 0))
6636 (skip-chars-forward " \t")
6637 (setq ind (current-column))
6641 (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6642 (indent-line-to val)
6643 (if (and verilog-indent-declaration-macros
6644 (looking-at verilog-declaration-re-2-macro))
6645 (let ((p (match-end 0)))
6647 (if (verilog-re-search-forward "[[#`]" p 'move)
6651 (goto-char (marker-position m1))
6654 (if (/= (current-column) ind)
6658 (if (looking-at verilog-declaration-re-2-no-macro)
6659 (let ((p (match-end 0)))
6661 (if (verilog-re-search-forward "[[`#]" p 'move)
6665 (goto-char (marker-position m1))
6668 (if (/= (current-column) ind)
6671 (indent-to ind))))))))))
6674 (defun verilog-get-lineup-indent (b edpos)
6675 "Return the indent level that will line up several lines within the region.
6676 Region is defined by B and EDPOS."
6680 ;; Get rightmost position
6681 (while (progn (setq e (marker-position edpos))
6683 (if (verilog-re-search-forward
6684 (or (and verilog-indent-declaration-macros
6685 verilog-declaration-re-1-macro)
6686 verilog-declaration-re-1-no-macro) e 'move)
6688 (goto-char (match-end 0))
6689 (verilog-backward-syntactic-ws)
6690 (if (> (current-column) ind)
6691 (setq ind (current-column)))
6692 (goto-char (match-end 0)))))
6695 ;; No lineup-string found
6698 (verilog-backward-syntactic-ws)
6699 ;;(skip-chars-backward " \t")
6700 (1+ (current-column))))))
6702 (defun verilog-get-lineup-indent-2 (myre b edpos)
6703 "Return the indent level that will line up several lines within the region."
6707 ;; Get rightmost position
6708 (while (progn (setq e (marker-position edpos))
6710 (if (and (verilog-re-search-forward myre e 'move)
6711 (not (verilog-in-attribute-p))) ;; skip attribute exprs
6713 (goto-char (match-beginning 2))
6714 (verilog-backward-syntactic-ws)
6715 (if (> (current-column) ind)
6716 (setq ind (current-column)))
6717 (goto-char (match-end 0)))
6721 ;; No lineup-string found
6724 (skip-chars-backward " \t")
6725 (1+ (current-column))))))
6727 (defun verilog-comment-depth (type val)
6728 "A useful mode debugging aide. TYPE and VAL are comments for insertion."
6736 (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t)
6738 (replace-match " /* -# ## */")
6742 (insert " /* ## ## */"))))
6745 (format "%s %d" type val))))
6751 (defvar verilog-str nil)
6752 (defvar verilog-all nil)
6753 (defvar verilog-pred nil)
6754 (defvar verilog-buffer-to-use nil)
6755 (defvar verilog-flag nil)
6756 (defvar verilog-toggle-completions nil
6757 "True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
6758 Repeated use of \\[verilog-complete-word] will show you all of them.
6759 Normally, when there is more than one possible completion,
6760 it displays a list of all possible completions.")
6763 (defvar verilog-type-keywords
6765 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
6766 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
6767 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
6768 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
6769 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
6770 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
6772 "Keywords for types used when completing a word in a declaration or parmlist.
6773 \(integer, real, reg...)")
6775 (defvar verilog-cpp-keywords
6776 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
6778 "Keywords to complete when at first word of a line in declarative scope.
6779 \(initial, always, begin, assign...)
6780 The procedures and variables defined within the Verilog program
6781 will be completed at runtime and should not be added to this list.")
6783 (defvar verilog-defun-keywords
6786 "always" "always_comb" "always_ff" "always_latch" "assign"
6787 "begin" "end" "generate" "endgenerate" "module" "endmodule"
6788 "specify" "endspecify" "function" "endfunction" "initial" "final"
6789 "task" "endtask" "primitive" "endprimitive"
6791 verilog-type-keywords)
6792 "Keywords to complete when at first word of a line in declarative scope.
6793 \(initial, always, begin, assign...)
6794 The procedures and variables defined within the Verilog program
6795 will be completed at runtime and should not be added to this list.")
6797 (defvar verilog-block-keywords
6799 "begin" "break" "case" "continue" "else" "end" "endfunction"
6800 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
6801 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
6803 "Keywords to complete when at first word of a line in behavioral scope.
6804 \(begin, if, then, else, for, fork...)
6805 The procedures and variables defined within the Verilog program
6806 will be completed at runtime and should not be added to this list.")
6808 (defvar verilog-tf-keywords
6809 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
6810 "Keywords to complete when at first word of a line in a task or function.
6811 \(begin, if, then, else, for, fork.)
6812 The procedures and variables defined within the Verilog program
6813 will be completed at runtime and should not be added to this list.")
6815 (defvar verilog-case-keywords
6816 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
6817 "Keywords to complete when at first word of a line in case scope.
6818 \(begin, if, then, else, for, fork...)
6819 The procedures and variables defined within the Verilog program
6820 will be completed at runtime and should not be added to this list.")
6822 (defvar verilog-separator-keywords
6823 '("else" "then" "begin")
6824 "Keywords to complete when NOT standing at the first word of a statement.
6825 \(else, then, begin...)
6826 Variables and function names defined within the Verilog program
6827 will be completed at runtime and should not be added to this list.")
6829 (defvar verilog-gate-ios
6830 ;; All these have an implied {"input"...} at the end
6844 ("pulldown" "output")
6849 ("rtran" "inout" "inout")
6850 ("rtranif0" "inout" "inout")
6851 ("rtranif1" "inout" "inout")
6852 ("tran" "inout" "inout")
6853 ("tranif0" "inout" "inout")
6854 ("tranif1" "inout" "inout")
6857 "Map of direction for each positional argument to each gate primitive.")
6859 (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
6860 "Keywords for gate primitives.")
6862 (defun verilog-string-diff (str1 str2)
6863 "Return index of first letter where STR1 and STR2 differs."
6867 (if (or (> (1+ diff) (length str1))
6868 (> (1+ diff) (length str2)))
6870 (or (equal (aref str1 diff) (aref str2 diff))
6872 (setq diff (1+ diff))))))
6874 ;; Calculate all possible completions for functions if argument is `function',
6875 ;; completions for procedures if argument is `procedure' or both functions and
6876 ;; procedures otherwise.
6878 (defun verilog-func-completion (type)
6879 "Build regular expression for module/task/function names.
6880 TYPE is 'module, 'tf for task or function, or t if unknown."
6881 (if (string= verilog-str "")
6882 (setq verilog-str "[a-zA-Z_]"))
6883 (let ((verilog-str (concat (cond
6884 ((eq type 'module) "\\<\\(module\\)\\s +")
6885 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
6886 (t "\\<\\(task\\|function\\|module\\)\\s +"))
6887 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
6890 (if (not (looking-at verilog-defun-re))
6891 (verilog-re-search-backward verilog-defun-re nil t))
6894 ;; Search through all reachable functions
6895 (goto-char (point-min))
6896 (while (verilog-re-search-forward verilog-str (point-max) t)
6897 (progn (setq match (buffer-substring (match-beginning 2)
6899 (if (or (null verilog-pred)
6900 (funcall verilog-pred match))
6901 (setq verilog-all (cons match verilog-all)))))
6902 (if (match-beginning 0)
6903 (goto-char (match-beginning 0)))))
6905 (defun verilog-get-completion-decl (end)
6906 "Macro for searching through current declaration (var, type or const)
6907 for matches of `str' and adding the occurrence tp `all' through point END."
6908 (let ((re (or (and verilog-indent-declaration-macros
6909 verilog-declaration-re-2-macro)
6910 verilog-declaration-re-2-no-macro))
6913 (while (and (< (point) end)
6914 (verilog-re-search-forward re end t))
6915 ;; Traverse current line
6916 (setq decl-end (save-excursion (verilog-declaration-end)))
6917 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
6918 (not (match-end 1)))
6919 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
6920 (if (string-match (concat "\\<" verilog-str) match)
6921 (if (or (null verilog-pred)
6922 (funcall verilog-pred match))
6923 (setq verilog-all (cons match verilog-all)))))
6927 (defun verilog-type-completion ()
6928 "Calculate all possible completions for types."
6929 (let ((start (point))
6931 ;; Search for all reachable type declarations
6932 (while (or (verilog-beg-of-defun)
6933 (setq goon (not goon)))
6935 (if (and (< start (prog1 (save-excursion (verilog-end-of-defun)
6938 (verilog-re-search-forward
6939 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
6941 (not (match-end 1)))
6942 ;; Check current type declaration
6943 (verilog-get-completion-decl start))))))
6945 (defun verilog-var-completion ()
6946 "Calculate all possible completions for variables (or constants)."
6947 (let ((start (point)))
6948 ;; Search for all reachable var declarations
6949 (verilog-beg-of-defun)
6951 ;; Check var declarations
6952 (verilog-get-completion-decl start))))
6954 (defun verilog-keyword-completion (keyword-list)
6955 "Give list of all possible completions of keywords in KEYWORD-LIST."
6957 (if (string-match (concat "\\<" verilog-str) s)
6958 (if (or (null verilog-pred)
6959 (funcall verilog-pred s))
6960 (setq verilog-all (cons s verilog-all)))))
6964 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
6965 "Function passed to `completing-read', `try-completion' or `all-completions'.
6966 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
6967 must be a function to be called for every match to check if this should
6968 really be a match. If VERILOG-FLAG is t, the function returns a list of
6969 all possible completions. If VERILOG-FLAG is nil it returns a string,
6970 the longest possible completion, or t if VERILOG-STR is an exact match.
6971 If VERILOG-FLAG is 'lambda, the function returns t if VERILOG-STR is an
6972 exact match, nil otherwise."
6974 (let ((verilog-all nil))
6975 ;; Set buffer to use for searching labels. This should be set
6976 ;; within functions which use verilog-completions
6977 (set-buffer verilog-buffer-to-use)
6979 ;; Determine what should be completed
6980 (let ((state (car (verilog-calculate-indent))))
6981 (cond ((eq state 'defun)
6982 (save-excursion (verilog-var-completion))
6983 (verilog-func-completion 'module)
6984 (verilog-keyword-completion verilog-defun-keywords))
6986 ((eq state 'behavioral)
6987 (save-excursion (verilog-var-completion))
6988 (verilog-func-completion 'module)
6989 (verilog-keyword-completion verilog-defun-keywords))
6992 (save-excursion (verilog-var-completion))
6993 (verilog-func-completion 'tf)
6994 (verilog-keyword-completion verilog-block-keywords))
6997 (save-excursion (verilog-var-completion))
6998 (verilog-func-completion 'tf)
6999 (verilog-keyword-completion verilog-case-keywords))
7002 (save-excursion (verilog-var-completion))
7003 (verilog-func-completion 'tf)
7004 (verilog-keyword-completion verilog-tf-keywords))
7007 (save-excursion (verilog-var-completion))
7008 (verilog-keyword-completion verilog-cpp-keywords))
7010 ((eq state 'cparenexp)
7011 (save-excursion (verilog-var-completion)))
7014 (save-excursion (verilog-var-completion))
7015 (verilog-func-completion 'both)
7016 (verilog-keyword-completion verilog-separator-keywords))))
7018 ;; Now we have built a list of all matches. Give response to caller
7019 (verilog-completion-response))))
7021 (defun verilog-completion-response ()
7022 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
7023 ;; This was not called by all-completions
7024 (if (null verilog-all)
7025 ;; Return nil if there was no matching label
7027 ;; Get longest string common in the labels
7028 (let* ((elm (cdr verilog-all))
7029 (match (car verilog-all))
7030 (min (length match))
7032 (if (string= match verilog-str)
7033 ;; Return t if first match was an exact match
7035 (while (not (null elm))
7036 ;; Find longest common string
7037 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
7040 (setq match (substring match 0 min))))
7041 ;; Terminate with match=t if this is an exact match
7042 (if (string= (car elm) verilog-str)
7046 (setq elm (cdr elm)))))
7047 ;; If this is a test just for exact match, return nil ot t
7048 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
7051 ;; If flag is t, this was called by all-completions. Return
7052 ;; list of all possible completions
7056 (defvar verilog-last-word-numb 0)
7057 (defvar verilog-last-word-shown nil)
7058 (defvar verilog-last-completions nil)
7060 (defun verilog-complete-word ()
7061 "Complete word at current point.
7062 \(See also `verilog-toggle-completions', `verilog-type-keywords',
7063 and `verilog-separator-keywords'.)"
7065 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7066 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7067 (verilog-str (buffer-substring b e))
7068 ;; The following variable is used in verilog-completion
7069 (verilog-buffer-to-use (current-buffer))
7070 (allcomp (if (and verilog-toggle-completions
7071 (string= verilog-last-word-shown verilog-str))
7072 verilog-last-completions
7073 (all-completions verilog-str 'verilog-completion)))
7074 (match (if verilog-toggle-completions
7076 verilog-str (mapcar (lambda (elm)
7077 (cons elm 0)) allcomp)))))
7078 ;; Delete old string
7081 ;; Toggle-completions inserts whole labels
7082 (if verilog-toggle-completions
7084 ;; Update entry number in list
7085 (setq verilog-last-completions allcomp
7086 verilog-last-word-numb
7087 (if (>= verilog-last-word-numb (1- (length allcomp)))
7089 (1+ verilog-last-word-numb)))
7090 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
7091 ;; Display next match or same string if no match was found
7092 (if (not (null allcomp))
7093 (insert "" verilog-last-word-shown)
7094 (insert "" verilog-str)
7095 (message "(No match)")))
7096 ;; The other form of completion does not necessarily do that.
7098 ;; Insert match if found, or the original string if no match
7099 (if (or (null match) (equal match 't))
7100 (progn (insert "" verilog-str)
7101 (message "(No match)"))
7103 ;; Give message about current status of completion
7104 (cond ((equal match 't)
7105 (if (not (null (cdr allcomp)))
7106 (message "(Complete but not unique)")
7107 (message "(Sole completion)")))
7108 ;; Display buffer if the current completion didn't help
7109 ;; on completing the label.
7110 ((and (not (null (cdr allcomp))) (= (length verilog-str)
7112 (with-output-to-temp-buffer "*Completions*"
7113 (display-completion-list allcomp))
7114 ;; Wait for a key press. Then delete *Completion* window
7115 (momentary-string-display "" (point))
7116 (delete-window (get-buffer-window (get-buffer "*Completions*")))
7119 (defun verilog-show-completions ()
7120 "Show all possible completions at current point."
7122 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7123 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7124 (verilog-str (buffer-substring b e))
7125 ;; The following variable is used in verilog-completion
7126 (verilog-buffer-to-use (current-buffer))
7127 (allcomp (if (and verilog-toggle-completions
7128 (string= verilog-last-word-shown verilog-str))
7129 verilog-last-completions
7130 (all-completions verilog-str 'verilog-completion))))
7131 ;; Show possible completions in a temporary buffer.
7132 (with-output-to-temp-buffer "*Completions*"
7133 (display-completion-list allcomp))
7134 ;; Wait for a key press. Then delete *Completion* window
7135 (momentary-string-display "" (point))
7136 (delete-window (get-buffer-window (get-buffer "*Completions*")))))
7139 (defun verilog-get-default-symbol ()
7140 "Return symbol around current point as a string."
7142 (buffer-substring (progn
7143 (skip-chars-backward " \t")
7144 (skip-chars-backward "a-zA-Z0-9_")
7147 (skip-chars-forward "a-zA-Z0-9_")
7150 (defun verilog-build-defun-re (str &optional arg)
7151 "Return function/task/module starting with STR as regular expression.
7152 With optional second ARG non-nil, STR is the complete name of the instruction."
7154 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
7155 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
7157 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
7158 "Function passed to `completing-read', `try-completion' or `all-completions'.
7159 Returns a completion on any function name based on VERILOG-STR prefix. If
7160 VERILOG-PRED is non-nil, it must be a function to be called for every match
7161 to check if this should really be a match. If VERILOG-FLAG is t, the
7162 function returns a list of all possible completions. If it is nil it
7163 returns a string, the longest possible completion, or t if VERILOG-STR is
7164 an exact match. If VERILOG-FLAG is 'lambda, the function returns t if
7165 VERILOG-STR is an exact match, nil otherwise."
7167 (let ((verilog-all nil)
7170 ;; Set buffer to use for searching labels. This should be set
7171 ;; within functions which use verilog-completions
7172 (set-buffer verilog-buffer-to-use)
7174 (let ((verilog-str verilog-str))
7175 ;; Build regular expression for functions
7176 (if (string= verilog-str "")
7177 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
7178 (setq verilog-str (verilog-build-defun-re verilog-str)))
7179 (goto-char (point-min))
7181 ;; Build a list of all possible completions
7182 (while (verilog-re-search-forward verilog-str nil t)
7183 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
7184 (if (or (null verilog-pred)
7185 (funcall verilog-pred match))
7186 (setq verilog-all (cons match verilog-all)))))
7188 ;; Now we have built a list of all matches. Give response to caller
7189 (verilog-completion-response))))
7191 (defun verilog-goto-defun ()
7192 "Move to specified Verilog module/interface/task/function.
7193 The default is a name found in the buffer around point.
7194 If search fails, other files are checked based on
7195 `verilog-library-flags'."
7197 (let* ((default (verilog-get-default-symbol))
7198 ;; The following variable is used in verilog-comp-function
7199 (verilog-buffer-to-use (current-buffer))
7200 (label (if (not (string= default ""))
7201 ;; Do completion with default
7202 (completing-read (concat "Goto-Label: (default "
7204 'verilog-comp-defun nil nil "")
7205 ;; There is no default value. Complete without it
7206 (completing-read "Goto-Label: "
7207 'verilog-comp-defun nil nil "")))
7209 ;; Make sure library paths are correct, in case need to resolve module
7210 (verilog-auto-reeval-locals)
7211 (verilog-getopt-flags)
7212 ;; If there was no response on prompt, use default value
7213 (if (string= label "")
7214 (setq label default))
7215 ;; Goto right place in buffer if label is not an empty string
7216 (or (string= label "")
7219 (goto-char (point-min))
7221 (re-search-forward (verilog-build-defun-re label t) nil t)))
7224 (beginning-of-line))
7226 (verilog-goto-defun-file label))))
7228 ;; Eliminate compile warning
7229 (defvar occur-pos-list)
7231 (defun verilog-showscopes ()
7232 "List all scopes in this module."
7234 (let ((buffer (current-buffer))
7238 (prevpos (point-min))
7239 (final-context-start (make-marker))
7240 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
7241 (with-output-to-temp-buffer "*Occur*"
7243 (message (format "Searching for %s ..." regexp))
7244 ;; Find next match, but give up if prev match was at end of buffer.
7245 (while (and (not (= prevpos (point-max)))
7246 (verilog-re-search-forward regexp nil t))
7247 (goto-char (match-beginning 0))
7250 (setq linenum (+ linenum (count-lines prevpos (point)))))
7251 (setq prevpos (point))
7252 (goto-char (match-end 0))
7253 (let* ((start (save-excursion
7254 (goto-char (match-beginning 0))
7255 (forward-line (if (< nlines 0) nlines (- nlines)))
7257 (end (save-excursion
7258 (goto-char (match-end 0))
7260 (forward-line (1+ nlines))
7263 (tag (format "%3d" linenum))
7264 (empty (make-string (length tag) ?\ ))
7267 (setq tem (make-marker))
7268 (set-marker tem (point))
7269 (set-buffer standard-output)
7270 (setq occur-pos-list (cons tem occur-pos-list))
7271 (or first (zerop nlines)
7272 (insert "--------\n"))
7274 (insert-buffer-substring buffer start end)
7275 (backward-char (- end start))
7276 (setq tem (if (< nlines 0) (- nlines) nlines))
7280 (setq tem (1- tem)))
7281 (let ((this-linenum linenum))
7282 (set-marker final-context-start
7283 (+ (point) (- (match-end 0) (match-beginning 0))))
7284 (while (< (point) final-context-start)
7286 (setq tag (format "%3d" this-linenum)))
7287 (insert tag ?:)))))))
7288 (set-buffer-modified-p nil))))
7291 ;; Highlight helper functions
7292 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
7293 (defun verilog-within-translate-off ()
7294 "Return point if within translate-off region, else nil."
7295 (and (save-excursion
7297 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
7299 (equal "off" (match-string 2))
7302 (defun verilog-start-translate-off (limit)
7303 "Return point before translate-off directive if before LIMIT, else nil."
7304 (when (re-search-forward
7305 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7307 (match-beginning 0)))
7309 (defun verilog-back-to-start-translate-off (limit)
7310 "Return point before translate-off directive if before LIMIT, else nil."
7311 (when (re-search-backward
7312 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7314 (match-beginning 0)))
7316 (defun verilog-end-translate-off (limit)
7317 "Return point after translate-on directive if before LIMIT, else nil."
7319 (re-search-forward (concat
7320 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
7322 (defun verilog-match-translate-off (limit)
7323 "Match a translate-off block, setting `match-data' and returning t, else nil.
7324 Bound search by LIMIT."
7325 (when (< (point) limit)
7326 (let ((start (or (verilog-within-translate-off)
7327 (verilog-start-translate-off limit)))
7328 (case-fold-search t))
7330 (let ((end (or (verilog-end-translate-off limit) limit)))
7331 (set-match-data (list start end))
7332 (goto-char end))))))
7334 (defun verilog-font-lock-match-item (limit)
7335 "Match, and move over, any declaration item after point.
7336 Bound search by LIMIT. Adapted from
7337 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
7340 (narrow-to-region (point-min) limit)
7342 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
7344 (goto-char (match-end 1))
7345 ;; move to next item
7346 (if (looking-at "\\(\\s-*,\\)")
7347 (goto-char (match-end 1))
7352 ;; Added by Subbu Meiyappan for Header
7354 (defun verilog-header ()
7355 "Insert a standard Verilog file header.
7356 See also `verilog-sk-header' for an alternative format."
7358 (let ((start (point)))
7360 //-----------------------------------------------------------------------------
7362 // Project : <project>
7363 //-----------------------------------------------------------------------------
7364 // File : <filename>
7365 // Author : <author>
7366 // Created : <credate>
7367 // Last modified : <moddate>
7368 //-----------------------------------------------------------------------------
7371 //-----------------------------------------------------------------------------
7372 // Copyright (c) <copydate> by <company> This model is the confidential and
7373 // proprietary property of <company> and the possession or use of this
7374 // file requires a written license from <company>.
7375 //------------------------------------------------------------------------------
7376 // Modification history :
7378 //-----------------------------------------------------------------------------
7382 (search-forward "<filename>")
7383 (replace-match (buffer-name) t t)
7384 (search-forward "<author>") (replace-match "" t t)
7385 (insert (user-full-name))
7386 (insert " <" (user-login-name) "@" (system-name) ">")
7387 (search-forward "<credate>") (replace-match "" t t)
7388 (verilog-insert-date)
7389 (search-forward "<moddate>") (replace-match "" t t)
7390 (verilog-insert-date)
7391 (search-forward "<copydate>") (replace-match "" t t)
7392 (verilog-insert-year)
7393 (search-forward "<modhist>") (replace-match "" t t)
7394 (verilog-insert-date)
7395 (insert " : created")
7398 (setq string (read-string "title: "))
7399 (search-forward "<title>")
7400 (replace-match string t t)
7401 (setq string (read-string "project: " verilog-project))
7402 (setq verilog-project string)
7403 (search-forward "<project>")
7404 (replace-match string t t)
7405 (setq string (read-string "Company: " verilog-company))
7406 (setq verilog-company string)
7407 (search-forward "<company>")
7408 (replace-match string t t)
7409 (search-forward "<company>")
7410 (replace-match string t t)
7411 (search-forward "<company>")
7412 (replace-match string t t)
7413 (search-backward "<description>")
7414 (replace-match "" t t))))
7416 ;; verilog-header Uses the verilog-insert-date function
7418 (defun verilog-insert-date ()
7419 "Insert date from the system."
7421 (if verilog-date-scientific-format
7422 (insert (format-time-string "%Y/%m/%d"))
7423 (insert (format-time-string "%d.%m.%Y"))))
7425 (defun verilog-insert-year ()
7426 "Insert year from the system."
7428 (insert (format-time-string "%Y")))
7432 ;; Signal list parsing
7435 ;; Elements of a signal list
7436 ;; Unfortunately we use 'assoc' on this, so can't be a vector
7437 (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
7438 (list name bits comment mem enum signed type multidim modport))
7439 (defsubst verilog-sig-name (sig)
7441 (defsubst verilog-sig-bits (sig)
7443 (defsubst verilog-sig-comment (sig)
7445 (defsubst verilog-sig-memory (sig)
7447 (defsubst verilog-sig-enum (sig)
7449 (defsubst verilog-sig-signed (sig)
7451 (defsubst verilog-sig-type (sig)
7453 (defsubst verilog-sig-type-set (sig type)
7454 (setcar (nthcdr 6 sig) type))
7455 (defsubst verilog-sig-multidim (sig)
7457 (defsubst verilog-sig-multidim-string (sig)
7458 (if (verilog-sig-multidim sig)
7459 (let ((str "") (args (verilog-sig-multidim sig)))
7461 (setq str (concat str (car args)))
7462 (setq args (cdr args)))
7464 (defsubst verilog-sig-modport (sig)
7466 (defsubst verilog-sig-width (sig)
7467 (verilog-make-width-expression (verilog-sig-bits sig)))
7469 (defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
7470 (vector outputs-del outputs-imm temps inputs))
7471 (defsubst verilog-alw-get-outputs-delayed (sigs)
7473 (defsubst verilog-alw-get-outputs-immediate (sigs)
7475 (defsubst verilog-alw-get-temps (sigs)
7477 (defsubst verilog-alw-get-inputs (sigs)
7479 (defsubst verilog-alw-get-uses-delayed (sigs)
7482 (defsubst verilog-modi-new (name fob pt type)
7483 (vector name fob pt type))
7484 (defsubst verilog-modi-name (modi)
7486 (defsubst verilog-modi-file-or-buffer (modi)
7488 (defsubst verilog-modi-get-point (modi)
7490 (defsubst verilog-modi-get-type (modi) ;; "module" or "interface"
7492 (defsubst verilog-modi-get-decls (modi)
7493 (verilog-modi-cache-results modi 'verilog-read-decls))
7494 (defsubst verilog-modi-get-sub-decls (modi)
7495 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
7497 ;; Signal reading for given module
7498 ;; Note these all take modi's - as returned from verilog-modi-current
7499 (defsubst verilog-decls-new (out inout in vars unuseds assigns consts gparams interfaces)
7500 (vector out inout in vars unuseds assigns consts gparams interfaces))
7501 (defsubst verilog-decls-get-outputs (decls)
7503 (defsubst verilog-decls-get-inouts (decls)
7505 (defsubst verilog-decls-get-inputs (decls)
7507 (defsubst verilog-decls-get-vars (decls)
7509 ;;(defsubst verilog-decls-get-unused (decls)
7511 (defsubst verilog-decls-get-assigns (decls)
7513 (defsubst verilog-decls-get-consts (decls)
7515 (defsubst verilog-decls-get-gparams (decls)
7517 (defsubst verilog-decls-get-interfaces (decls)
7520 (defsubst verilog-subdecls-new (out inout in intf intfd)
7521 (vector out inout in intf intfd))
7522 (defsubst verilog-subdecls-get-outputs (subdecls)
7524 (defsubst verilog-subdecls-get-inouts (subdecls)
7526 (defsubst verilog-subdecls-get-inputs (subdecls)
7528 (defsubst verilog-subdecls-get-interfaces (subdecls)
7530 (defsubst verilog-subdecls-get-interfaced (subdecls)
7533 (defun verilog-signals-from-signame (signame-list)
7534 "Return signals in standard form from SIGNAME-LIST, a simple list of names."
7535 (mapcar (lambda (name) (verilog-sig-new name nil nil nil nil nil nil nil nil))
7538 (defun verilog-signals-not-in (in-list not-list)
7539 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
7540 Also remove any duplicates in IN-LIST.
7541 Signals must be in standard (base vector) form."
7542 ;; This function is hot, so implemented as O(1)
7543 (cond ((eval-when-compile (fboundp 'make-hash-table))
7544 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
7547 (puthash (car (car not-list)) t ht)
7548 (setq not-list (cdr not-list)))
7550 (when (not (gethash (verilog-sig-name (car in-list)) ht))
7551 (setq out-list (cons (car in-list) out-list))
7552 (puthash (verilog-sig-name (car in-list)) t ht))
7553 (setq in-list (cdr in-list)))
7554 (nreverse out-list)))
7555 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
7559 (if (not (or (assoc (verilog-sig-name (car in-list)) not-list)
7560 (assoc (verilog-sig-name (car in-list)) out-list)))
7561 (setq out-list (cons (car in-list) out-list)))
7562 (setq in-list (cdr in-list)))
7563 (nreverse out-list)))))
7564 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
7566 (defun verilog-signals-memory (in-list)
7567 "Return list of signals in IN-LIST that are memorized (multidimensional)."
7570 (if (nth 3 (car in-list))
7571 (setq out-list (cons (car in-list) out-list)))
7572 (setq in-list (cdr in-list)))
7574 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
7576 (defun verilog-signals-sort-compare (a b)
7577 "Compare signal A and B for sorting."
7578 (string< (verilog-sig-name a) (verilog-sig-name b)))
7580 (defun verilog-signals-not-params (in-list)
7581 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
7584 (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
7585 (setq out-list (cons (car in-list) out-list)))
7586 (setq in-list (cdr in-list)))
7587 (nreverse out-list)))
7589 (defun verilog-signals-with (func in-list)
7590 "Return IN-LIST with only signals where FUNC passed each signal is true."
7593 (when (funcall func (car in-list))
7594 (setq out-list (cons (car in-list) out-list)))
7595 (setq in-list (cdr in-list)))
7596 (nreverse out-list)))
7598 (defun verilog-signals-combine-bus (in-list)
7599 "Return a list of signals in IN-LIST, with buses combined.
7600 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
7603 sig highbit lowbit ; Temp information about current signal
7604 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
7605 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
7608 ;; Shove signals so duplicated signals will be adjacent
7609 (setq in-list (sort in-list `verilog-signals-sort-compare))
7611 (setq sig (car in-list))
7612 ;; No current signal; form from existing details
7614 (setq sv-name (verilog-sig-name sig)
7617 sv-comment (verilog-sig-comment sig)
7618 sv-memory (verilog-sig-memory sig)
7619 sv-enum (verilog-sig-enum sig)
7620 sv-signed (verilog-sig-signed sig)
7621 sv-type (verilog-sig-type sig)
7622 sv-multidim (verilog-sig-multidim sig)
7623 sv-modport (verilog-sig-modport sig)
7626 ;; Extract bus details
7627 (setq bus (verilog-sig-bits sig))
7628 (setq bus (and bus (verilog-simplify-range-expression bus)))
7630 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
7631 (setq highbit (string-to-number (match-string 1 bus))
7632 lowbit (string-to-number
7633 (match-string 2 bus))))
7634 (and (string-match "\\[\\([0-9]+\\)\\]" bus)
7635 (setq highbit (string-to-number (match-string 1 bus))
7637 ;; Combine bits in bus
7639 (setq sv-highbit (max highbit sv-highbit)
7640 sv-lowbit (min lowbit sv-lowbit))
7641 (setq sv-highbit highbit
7644 ;; String, probably something like `preproc:0
7645 (setq sv-busstring bus)))
7646 ;; Peek ahead to next signal
7647 (setq in-list (cdr in-list))
7648 (setq sig (car in-list))
7649 (cond ((and sig (equal sv-name (verilog-sig-name sig)))
7650 ;; Combine with this signal
7651 (when (and sv-busstring
7652 (not (equal sv-busstring (verilog-sig-bits sig))))
7653 (when nil ;; Debugging
7654 (message (concat "Warning, can't merge into single bus "
7656 ", the AUTOs may be wrong")))
7657 (setq buswarn ", Couldn't Merge"))
7658 (if (verilog-sig-comment sig) (setq combo ", ..."))
7659 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
7660 sv-enum (or sv-enum (verilog-sig-enum sig))
7661 sv-signed (or sv-signed (verilog-sig-signed sig))
7662 sv-type (or sv-type (verilog-sig-type sig))
7663 sv-multidim (or sv-multidim (verilog-sig-multidim sig))
7664 sv-modport (or sv-modport (verilog-sig-modport sig))))
7665 ;; Doesn't match next signal, add to queue, zero in prep for next
7666 ;; Note sig may also be nil for the last signal in the list
7669 (cons (verilog-sig-new
7673 (concat "[" (int-to-string sv-highbit) ":"
7674 (int-to-string sv-lowbit) "]")))
7675 (concat sv-comment combo buswarn)
7676 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
7682 (defun verilog-sig-tieoff (sig)
7683 "Return tieoff expression for given SIG, with appropriate width.
7684 Tieoff value uses `verilog-active-low-regexp' and
7685 `verilog-auto-reset-widths'."
7687 (if (and verilog-active-low-regexp
7688 (string-match verilog-active-low-regexp (verilog-sig-name sig)))
7690 (cond ((not verilog-auto-reset-widths)
7692 ((equal verilog-auto-reset-widths 'unbased)
7694 ;; Else presume verilog-auto-reset-widths is true
7696 (let* ((width (verilog-sig-width sig)))
7697 (if (string-match "^[0-9]+$" width)
7698 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0"))
7699 (concat "{" width "{1'b0}}")))))))
7705 (defun verilog-decls-princ (decls)
7706 "For debug, dump the `verilog-read-decls' structure DECLS."
7707 (verilog-signals-princ (verilog-decls-get-outputs decls)
7709 (verilog-signals-princ (verilog-decls-get-inouts decls)
7711 (verilog-signals-princ (verilog-decls-get-inputs decls)
7713 (verilog-signals-princ (verilog-decls-get-vars decls)
7715 (verilog-signals-princ (verilog-decls-get-assigns decls)
7717 (verilog-signals-princ (verilog-decls-get-consts decls)
7719 (verilog-signals-princ (verilog-decls-get-gparams decls)
7721 (verilog-signals-princ (verilog-decls-get-interfaces decls)
7722 "Interfaces:\n" " ")
7725 (defun verilog-signals-princ (signals &optional header prefix)
7726 "For debug, dump internal SIGNALS structures, with HEADER and PREFIX."
7730 (let ((sig (car signals)))
7731 (setq signals (cdr signals))
7733 (princ "\"") (princ (verilog-sig-name sig)) (princ "\"")
7734 (princ " bits=") (princ (verilog-sig-bits sig))
7735 (princ " cmt=") (princ (verilog-sig-comment sig))
7736 (princ " mem=") (princ (verilog-sig-memory sig))
7737 (princ " enum=") (princ (verilog-sig-enum sig))
7738 (princ " sign=") (princ (verilog-sig-signed sig))
7739 (princ " type=") (princ (verilog-sig-type sig))
7740 (princ " dim=") (princ (verilog-sig-multidim sig))
7741 (princ " modp=") (princ (verilog-sig-modport sig))
7745 ;; Port/Wire/Etc Reading
7748 (defun verilog-read-inst-backward-name ()
7749 "Internal. Move point back to beginning of inst-name."
7750 (verilog-backward-open-paren)
7753 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary
7754 (cond ((looking-at ")")
7755 (verilog-backward-open-paren))
7756 (t (setq done t)))))
7757 (while (looking-at "\\]")
7758 (verilog-backward-open-bracket)
7759 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil))
7760 (skip-chars-backward "a-zA-Z0-9`_$"))
7762 (defun verilog-read-inst-module-matcher ()
7763 "Set match data 0 with module_name when point is inside instantiation."
7764 (verilog-read-inst-backward-name)
7765 ;; Skip over instantiation name
7766 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
7767 ;; Check for parameterized instantiations
7768 (when (looking-at ")")
7769 (verilog-backward-open-paren)
7770 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil))
7771 (skip-chars-backward "a-zA-Z0-9'_$")
7772 (looking-at "[a-zA-Z0-9`_\$]+")
7773 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7774 (buffer-substring-no-properties (match-beginning 0) (match-end 0))
7775 ;; Caller assumes match-beginning/match-end is still set
7778 (defun verilog-read-inst-module ()
7779 "Return module_name when point is inside instantiation."
7781 (verilog-read-inst-module-matcher)))
7783 (defun verilog-read-inst-name ()
7784 "Return instance_name when point is inside instantiation."
7786 (verilog-read-inst-backward-name)
7787 (looking-at "[a-zA-Z0-9`_\$]+")
7788 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7789 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
7791 (defun verilog-read-module-name ()
7792 "Return module name when after its ( or ;."
7794 (re-search-backward "[(;]")
7795 ;; Due to "module x import y (" we must search for declaration begin
7796 (verilog-re-search-backward-quick verilog-defun-re nil nil)
7797 (goto-char (match-end 0))
7798 (verilog-re-search-forward-quick "\\b[a-zA-Z0-9`_\$]+" nil nil)
7799 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7800 (verilog-symbol-detick
7801 (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
7803 (defun verilog-read-inst-param-value ()
7804 "Return list of parameters and values when point is inside instantiation."
7806 (verilog-read-inst-backward-name)
7807 ;; Skip over instantiation name
7808 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
7809 ;; If there are parameterized instantiations
7810 (when (looking-at ")")
7811 (let ((end-pt (point))
7813 param-name paren-beg-pt param-value)
7814 (verilog-backward-open-paren)
7815 (while (verilog-re-search-forward-quick "\\." end-pt t)
7816 (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_\$]\\)" nil nil)
7817 (skip-chars-backward "a-zA-Z0-9'_$")
7818 (looking-at "[a-zA-Z0-9`_\$]+")
7819 (setq param-name (buffer-substring-no-properties
7820 (match-beginning 0) (match-end 0)))
7821 (verilog-re-search-forward-quick "(" nil nil)
7822 (setq paren-beg-pt (point))
7823 (verilog-forward-close-paren)
7824 (setq param-value (verilog-string-remove-spaces
7825 (buffer-substring-no-properties
7826 paren-beg-pt (1- (point)))))
7827 (setq params (cons (list param-name param-value) params)))
7830 (defun verilog-read-auto-params (num-param &optional max-param)
7831 "Return parameter list inside auto.
7832 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
7835 ;; /*AUTOPUNT("parameter", "parameter")*/
7837 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
7838 (setq olist (cons (match-string 1) olist))
7839 (goto-char (match-end 0))))
7840 (or (eq nil num-param)
7841 (<= num-param (length olist))
7842 (error "%s: Expected %d parameters" (verilog-point-text) num-param))
7843 (if (eq max-param nil) (setq max-param num-param))
7844 (or (eq nil max-param)
7845 (>= max-param (length olist))
7846 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
7849 (defun verilog-read-decls ()
7850 "Compute signal declaration information for the current module at point.
7851 Return an array of [outputs inouts inputs wire reg assign const]."
7852 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
7853 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
7854 in-modport ptype ign-prop
7855 sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
7856 sigs-gparam sigs-intf
7857 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
7860 (verilog-beg-of-defun-quick)
7861 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
7862 (while (< (point) end-mod-point)
7863 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
7866 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7867 (setq enum (match-string 2)))
7868 (search-forward "\n"))
7869 ((looking-at "/\\*")
7871 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7872 (setq enum (match-string 2)))
7873 (or (search-forward "*/")
7874 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
7875 ((looking-at "(\\*")
7876 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
7878 (or (search-forward "*)")
7879 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
7880 ((eq ?\" (following-char))
7881 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first
7882 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
7883 ((eq ?\; (following-char))
7884 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
7885 v2kargs-ok nil in-modport nil ign-prop nil)
7887 ((eq ?= (following-char))
7888 (setq rvalue t newsig nil)
7890 ((and (eq ?, (following-char))
7891 (eq paren sig-paren))
7894 ;; ,'s can occur inside {} & funcs
7895 ((looking-at "[{(]")
7896 (setq paren (1+ paren))
7898 ((looking-at "[})]")
7899 (setq paren (1- paren))
7901 (when (< paren sig-paren)
7902 (setq expect-signal nil))) ; ) that ends variables inside v2k arg list
7903 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
7904 (goto-char (match-end 0))
7905 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
7906 (setcar (cdr (cdr (cdr newsig)))
7907 (if (verilog-sig-memory newsig)
7908 (concat (verilog-sig-memory newsig) (match-string 1))
7910 (vec ;; Multidimensional
7911 (setq multidim (cons vec multidim))
7912 (setq vec (verilog-string-replace-matches
7913 "\\s-+" "" nil nil (match-string 1))))
7915 (setq vec (verilog-string-replace-matches
7916 "\\s-+" "" nil nil (match-string 1))))))
7917 ;; Normal or escaped identifier -- note we remember the \ if escaped
7918 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
7919 (goto-char (match-end 0))
7920 (setq keywd (match-string 1))
7921 (when (string-match "^\\\\" (match-string 1))
7922 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end
7923 ;; Add any :: package names to same identifier
7924 (while (looking-at "\\s-*::\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
7925 (goto-char (match-end 0))
7926 (setq keywd (concat keywd "::" (match-string 1)))
7927 (when (string-match "^\\\\" (match-string 1))
7928 (setq keywd (concat keywd " ")))) ;; Escaped ID needs space at end
7929 (cond ((equal keywd "input")
7930 (setq vec nil enum nil rvalue nil newsig nil signed nil
7931 typedefed nil multidim nil ptype nil modport nil
7932 expect-signal 'sigs-in io t sig-paren paren))
7933 ((equal keywd "output")
7934 (setq vec nil enum nil rvalue nil newsig nil signed nil
7935 typedefed nil multidim nil ptype nil modport nil
7936 expect-signal 'sigs-out io t sig-paren paren))
7937 ((equal keywd "inout")
7938 (setq vec nil enum nil rvalue nil newsig nil signed nil
7939 typedefed nil multidim nil ptype nil modport nil
7940 expect-signal 'sigs-inout io t sig-paren paren))
7941 ((equal keywd "parameter")
7942 (setq vec nil enum nil rvalue nil signed nil
7943 typedefed nil multidim nil ptype nil modport nil
7944 expect-signal 'sigs-gparam io t sig-paren paren))
7945 ((member keywd '("wire" "reg" ; Fast
7947 "tri" "tri0" "tri1" "triand" "trior" "trireg"
7948 "uwire" "wand" "wor"
7949 ;; integer_atom_type
7950 "byte" "shortint" "int" "longint" "integer" "time"
7952 ;; integer_vector_type - "reg" above
7955 "shortreal" "real" "realtime"
7957 "string" "event" "chandle"))
7960 (if typedefed (concat typedefed " " keywd) keywd)))
7961 (t (setq vec nil enum nil rvalue nil signed nil
7962 typedefed nil multidim nil sig-paren paren
7963 expect-signal 'sigs-var modport nil))))
7964 ((equal keywd "assign")
7965 (setq vec nil enum nil rvalue nil signed nil
7966 typedefed nil multidim nil ptype nil modport nil
7967 expect-signal 'sigs-assign sig-paren paren))
7968 ((member keywd '("localparam" "genvar"))
7970 (setq vec nil enum nil rvalue nil signed nil
7971 typedefed nil multidim nil ptype nil modport nil
7972 expect-signal 'sigs-const sig-paren paren)))
7973 ((member keywd '("signed" "unsigned"))
7974 (setq signed keywd))
7975 ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
7977 ((member keywd '("class" "clocking" "covergroup" "function"
7978 "property" "randsequence" "sequence" "task"))
7980 (setq functask (1+ functask))))
7981 ((member keywd '("endclass" "endclocking" "endgroup" "endfunction"
7982 "endproperty" "endsequence" "endtask"))
7983 (setq functask (1- functask)))
7984 ((equal keywd "modport")
7985 (setq in-modport t))
7986 ((equal keywd "type")
7988 ;; Ifdef? Ignore name of define
7989 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
7993 (verilog-typedef-name-p keywd))
7994 (setq typedefed keywd))
7995 ;; Interface with optional modport in v2k arglist?
7996 ;; Skip over parsing modport, and take the interface name as the type
8000 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
8001 (when (match-end 2) (goto-char (match-end 2)))
8002 (setq vec nil enum nil rvalue nil signed nil
8003 typedefed keywd multidim nil ptype nil modport (match-string 2)
8004 newsig nil sig-paren paren
8005 expect-signal 'sigs-intf io t ))
8006 ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
8007 ((looking-at "\\s-*\\.")
8008 (goto-char (match-end 0))
8010 (setq expect-signal nil)))
8011 ;; New signal, maybe?
8016 (not (member keywd verilog-keywords)))
8017 ;; Add new signal to expect-signal's variable
8018 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
8019 (set expect-signal (cons newsig
8020 (symbol-value expect-signal))))))
8023 (skip-syntax-forward " "))
8025 (verilog-decls-new (nreverse sigs-out)
8026 (nreverse sigs-inout)
8030 (nreverse sigs-assign)
8031 (nreverse sigs-const)
8032 (nreverse sigs-gparam)
8033 (nreverse sigs-intf)))))
8035 (defvar verilog-read-sub-decls-in-interfaced nil
8036 "For `verilog-read-sub-decls', process next signal as under interfaced block.")
8038 (defvar verilog-read-sub-decls-gate-ios nil
8039 "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
8042 ;; Prevent compile warnings; these are let's, not globals
8043 ;; Do not remove the eval-when-compile
8044 ;; - we want an error when we are debugging this code if they are refed.
8049 (defvar sigs-intfd))
8051 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
8052 "For `verilog-read-sub-decls-line', add a signal."
8053 ;; sig eq t to indicate .name syntax
8054 ;;(message "vrsds: %s(%S)" port sig)
8055 (let ((dotname (eq sig t))
8058 (setq port (verilog-symbol-detick-denumber port))
8059 (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
8060 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
8061 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
8062 (unless (or (not sig)
8063 (equal sig "")) ;; Ignore .foo(1'b1) assignments
8064 (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
8065 (equal "inout" verilog-read-sub-decls-gate-ios))
8067 (cons (verilog-sig-new
8069 (if dotname (verilog-sig-bits portdata) vec)
8070 (concat "To/From " comment)
8071 (verilog-sig-memory portdata)
8073 (verilog-sig-signed portdata)
8074 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8075 (verilog-sig-type portdata))
8078 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
8079 (equal "output" verilog-read-sub-decls-gate-ios))
8081 (cons (verilog-sig-new
8083 (if dotname (verilog-sig-bits portdata) vec)
8084 (concat "From " comment)
8085 (verilog-sig-memory portdata)
8087 (verilog-sig-signed portdata)
8088 ;; Though ok in SV, in V2K code, propagating the
8089 ;; "reg" in "output reg" upwards isn't legal.
8090 ;; Also for backwards compatibility we don't propagate
8091 ;; "input wire" upwards.
8092 ;; See also `verilog-signals-edit-wire-reg'.
8093 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8094 (verilog-sig-type portdata))
8097 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
8098 (equal "input" verilog-read-sub-decls-gate-ios))
8100 (cons (verilog-sig-new
8102 (if dotname (verilog-sig-bits portdata) vec)
8103 (concat "To " comment)
8104 (verilog-sig-memory portdata)
8106 (verilog-sig-signed portdata)
8107 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8108 (verilog-sig-type portdata))
8111 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
8113 (cons (verilog-sig-new
8115 (if dotname (verilog-sig-bits portdata) vec)
8116 (concat "To/From " comment)
8117 (verilog-sig-memory portdata)
8119 (verilog-sig-signed portdata)
8120 (verilog-sig-type portdata)
8123 ((setq portdata (and verilog-read-sub-decls-in-interfaced
8124 (assoc port (verilog-decls-get-vars submoddecls))))
8126 (cons (verilog-sig-new
8128 (if dotname (verilog-sig-bits portdata) vec)
8129 (concat "To/From " comment)
8130 (verilog-sig-memory portdata)
8132 (verilog-sig-signed portdata)
8133 (verilog-sig-type portdata)
8136 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
8139 (defun verilog-read-sub-decls-expr (submoddecls comment port expr)
8140 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
8141 ;;(message "vrsde: '%s'" expr)
8142 ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
8143 (setq expr (verilog-string-replace-matches "/\\*\\(\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
8144 ;; Remove front operators
8145 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8148 ;; {..., a, b} requires us to recurse on a,b
8149 ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
8150 ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
8151 (unless verilog-auto-ignore-concat
8152 (let ((mlst (split-string (match-string 1 expr) "[{},]"))
8154 (while (setq mstr (pop mlst))
8155 (verilog-read-sub-decls-expr submoddecls comment port mstr)))))
8157 (let (sig vec multidim)
8158 ;; Remove leading reduction operators, etc
8159 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8160 ;;(message "vrsde-ptop: '%s'" expr)
8161 (cond ;; Find \signal. Final space is part of escaped signal name
8162 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
8163 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
8164 (setq sig (match-string 1 expr)
8165 expr (substring expr (match-end 0))))
8167 ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
8168 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
8169 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
8170 expr (substring expr (match-end 0)))))
8171 ;; Find [vector] or [multi][multi][multi][vector]
8172 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
8173 ;;(message "vrsde-v: '%s'" (match-string 1 expr))
8174 (when vec (setq multidim (cons vec multidim)))
8175 (setq vec (match-string 1 expr)
8176 expr (substring expr (match-end 0))))
8177 ;; If found signal, and nothing unrecognized, add the signal
8178 ;;(message "vrsde-rem: '%s'" expr)
8179 (when (and sig (string-match "^\\s-*$" expr))
8180 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))))
8182 (defun verilog-read-sub-decls-line (submoddecls comment)
8183 "For `verilog-read-sub-decls', read lines of port defs until none match.
8184 Inserts the list of signals found, using submodi to look up each port."
8190 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
8191 (setq port (match-string 1))
8192 (goto-char (match-end 0)))
8194 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
8195 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space
8196 (goto-char (match-end 0)))
8198 ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
8199 (verilog-read-sub-decls-sig
8200 submoddecls comment (match-string 1) t ; sig==t for .name
8201 nil nil) ; vec multidim
8204 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
8205 (verilog-read-sub-decls-sig
8206 submoddecls comment (concat (match-string 1) " ") t ; sig==t for .name
8207 nil nil) ; vec multidim
8210 ((looking-at "\\s-*\\.[^(]*(")
8211 (setq port nil) ;; skip this line
8212 (goto-char (match-end 0)))
8214 (setq port nil done t))) ;; Unknown, ignore rest of line
8215 ;; Get signal name. Point is at the first-non-space after (
8216 ;; We intentionally ignore (non-escaped) signals with .s in them
8217 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
8219 (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
8220 (verilog-read-sub-decls-sig
8221 submoddecls comment port
8222 (verilog-string-remove-spaces (match-string 1)) ; sig
8223 nil nil)) ; vec multidim
8225 ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
8226 (verilog-read-sub-decls-sig
8227 submoddecls comment port
8228 (verilog-string-remove-spaces (match-string 1)) ; sig
8229 (match-string 2) nil)) ; vec multidim
8230 ;; Fastpath was above looking-at's.
8231 ;; For something more complicated invoke a parser
8232 ((looking-at "[^)]+")
8233 (verilog-read-sub-decls-expr
8234 submoddecls comment port
8236 (point) (1- (progn (search-backward "(") ; start at (
8237 (verilog-forward-sexp-ign-cmt 1)
8238 (point)))))))) ; expr
8240 (forward-line 1)))))
8242 (defun verilog-read-sub-decls-gate (submoddecls comment submod end-inst-point)
8243 "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
8244 Inserts the list of signals found."
8246 (let ((iolist (cdr (assoc submod verilog-gate-ios))))
8247 (while (< (point) end-inst-point)
8248 ;; Get primitive's signal name, as will never have port, and no trailing )
8249 (cond ((looking-at "//")
8250 (search-forward "\n"))
8251 ((looking-at "/\\*")
8252 (or (search-forward "*/")
8253 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8254 ((looking-at "(\\*")
8255 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8257 (or (search-forward "*)")
8258 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8259 ;; On pins, parse and advance to next pin
8260 ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
8261 ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
8262 (goto-char (match-end 0))
8263 (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
8264 iolist (cdr iolist))
8265 (verilog-read-sub-decls-expr
8266 submoddecls comment "primitive_port"
8270 (skip-syntax-forward " ")))))))
8272 (defun verilog-read-sub-decls ()
8273 "Internally parse signals going to modules under this module.
8274 Return an array of [ outputs inouts inputs ] signals for modules that are
8275 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
8276 is an output, then SIG will be included in the list.
8278 This only works on instantiations created with /*AUTOINST*/ converted by
8279 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
8280 component library to determine connectivity of the design.
8282 One work around for this problem is to manually create // Inputs and //
8283 Outputs comments above subcell signals, for example:
8291 (let ((end-mod-point (verilog-get-end-of-defun t))
8292 st-point end-inst-point
8293 ;; below 3 modified by verilog-read-sub-decls-line
8294 sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
8295 (verilog-beg-of-defun-quick)
8296 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
8298 (goto-char (match-beginning 0))
8299 (unless (verilog-inside-comment-or-string-p)
8300 ;; Attempt to snarf a comment
8301 (let* ((submod (verilog-read-inst-module))
8302 (inst (verilog-read-inst-name))
8303 (subprim (member submod verilog-gate-keywords))
8304 (comment (concat inst " of " submod ".v"))
8305 submodi submoddecls)
8308 (setq submodi `primitive
8309 submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
8310 comment (concat inst " of " submod))
8311 (verilog-backward-open-paren)
8312 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
8316 (verilog-read-sub-decls-gate submoddecls comment submod end-inst-point))
8319 (when (setq submodi (verilog-modi-lookup submod t))
8320 (setq submoddecls (verilog-modi-get-decls submodi)
8321 verilog-read-sub-decls-gate-ios nil)
8322 (verilog-backward-open-paren)
8323 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
8326 ;; This could have used a list created by verilog-auto-inst
8327 ;; However I want it to be runnable even on user's manually added signals
8328 (let ((verilog-read-sub-decls-in-interfaced t))
8329 (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
8330 (verilog-read-sub-decls-line submoddecls comment))) ;; Modifies sigs-ifd
8331 (goto-char st-point)
8332 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
8333 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
8334 (goto-char st-point)
8335 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
8336 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
8337 (goto-char st-point)
8338 (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
8339 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout
8340 (goto-char st-point)
8341 (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
8342 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-in
8344 ;; Combine duplicate bits
8345 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
8346 (verilog-subdecls-new
8347 (verilog-signals-combine-bus (nreverse sigs-out))
8348 (verilog-signals-combine-bus (nreverse sigs-inout))
8349 (verilog-signals-combine-bus (nreverse sigs-in))
8350 (verilog-signals-combine-bus (nreverse sigs-intf))
8351 (verilog-signals-combine-bus (nreverse sigs-intfd))))))
8353 (defun verilog-read-inst-pins ()
8354 "Return an array of [ pins ] for the current instantiation at point.
8355 For example if declare A A (.B(SIG)) then B will be included in the list."
8357 (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point
8359 (verilog-backward-open-paren)
8360 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
8361 (setq pin (match-string 1))
8362 (unless (verilog-inside-comment-or-string-p)
8363 (setq pins (cons (list pin) pins))
8364 (when (looking-at "(")
8365 (verilog-forward-sexp-ign-cmt 1))))
8368 (defun verilog-read-arg-pins ()
8369 "Return an array of [ pins ] for the current argument declaration at point."
8371 (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point
8373 (verilog-backward-open-paren)
8374 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
8375 (setq pin (match-string 1))
8376 (unless (verilog-inside-comment-or-string-p)
8377 (setq pins (cons (list pin) pins))))
8380 (defun verilog-read-auto-constants (beg end-mod-point)
8381 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
8384 (let (sig-list tpl-end-pt)
8386 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
8387 (if (not (looking-at "\\s *("))
8388 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
8389 (search-forward "(" end-mod-point)
8390 (setq tpl-end-pt (save-excursion
8392 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8395 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
8396 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
8399 (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
8400 (make-variable-buffer-local 'verilog-cache-has-lisp)
8402 (defun verilog-read-auto-lisp-present ()
8403 "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
8405 (goto-char (point-min))
8406 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
8408 (defun verilog-read-auto-lisp (start end)
8409 "Look for and evaluate an AUTO_LISP between START and END.
8410 Must call `verilog-read-auto-lisp-present' before this function."
8411 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
8412 (when verilog-cache-has-lisp
8415 (while (re-search-forward "\\<AUTO_LISP(" end t)
8417 (let* ((beg-pt (prog1 (point)
8418 (verilog-forward-sexp-cmt 1))) ;; Closing paren
8420 (verilog-in-hooks t))
8421 (eval-region beg-pt end-pt nil))))))
8424 ;; Prevent compile warnings; these are let's, not globals
8425 ;; Do not remove the eval-when-compile
8426 ;; - we want an error when we are debugging this code if they are refed.
8430 (defvar sigs-out-unk)
8432 (defvar vector-skip-list))
8434 (defun verilog-read-always-signals-recurse
8435 (exit-keywd rvalue temp-next)
8436 "Recursive routine for parentheses/bracket matching.
8437 EXIT-KEYWD is expression to stop at, nil if top level.
8438 RVALUE is true if at right hand side of equal.
8439 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
8440 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue
8441 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
8443 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
8444 (while (not (or (eobp) gotend))
8447 (search-forward "\n"))
8448 ((looking-at "/\\*")
8449 (or (search-forward "*/")
8450 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8451 ((looking-at "(\\*")
8452 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8454 (or (search-forward "*)")
8455 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8456 (t (setq keywd (buffer-substring-no-properties
8458 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
8461 sig-last-tolk sig-tolk
8463 ;;(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))))
8466 (or (re-search-forward "[^\\]\"" nil t)
8467 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
8468 ;; else at top level loop, keep parsing
8469 ((and end-else-check (equal keywd "else"))
8470 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
8471 ;; no forward movement, want to see else in lower loop
8472 (setq end-else-check nil))
8473 ;; End at top level loop
8474 ((and end-else-check (looking-at "[^ \t\n\f]"))
8475 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
8478 ((and exit-keywd (equal keywd exit-keywd))
8480 (forward-char (length keywd)))
8481 ;; Standard tokens...
8483 (setq ignore-next nil rvalue semi-rvalue)
8484 ;; Final statement at top level loop?
8485 (when (not exit-keywd)
8486 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
8487 (setq end-else-check t))
8490 (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
8491 (goto-char (match-end 0))
8493 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z
8494 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next
8495 (setq ignore-next nil rvalue nil))
8496 ((equal "?" exit-keywd) ;; x?y:z rvalue
8498 ((equal "]" exit-keywd) ;; [x:y] rvalue
8500 (got-sig ;; label: statement
8501 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
8502 ((not rvalue) ;; begin label
8503 (setq ignore-next t rvalue nil)))
8507 ;;(if dbg (setq dbg (concat dbg (format "\t\tequal got-sig=%S got-list=%s\n" got-sig got-list))))
8508 (set got-list (cons got-sig (symbol-value got-list)))
8511 (if (eq (char-before) ?< )
8512 (setq sigs-out-d (append sigs-out-d sigs-out-unk)
8514 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
8516 (setq ignore-next nil rvalue t)
8520 (verilog-read-always-signals-recurse ":" rvalue nil))
8523 (verilog-read-always-signals-recurse "]" t nil))
8526 (cond (sig-last-tolk ;; Function call; zap last signal
8527 (setq got-sig nil)))
8528 (cond ((equal last-keywd "for")
8529 ;; temp-next: Variables on LHS are lvalues, but generally we want
8530 ;; to ignore them, assuming they are loop increments
8531 (verilog-read-always-signals-recurse ";" nil t)
8532 (verilog-read-always-signals-recurse ";" t nil)
8533 (verilog-read-always-signals-recurse ")" nil nil))
8534 (t (verilog-read-always-signals-recurse ")" t nil))))
8535 ((equal keywd "begin")
8536 (skip-syntax-forward "w_")
8537 (verilog-read-always-signals-recurse "end" nil nil)
8538 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
8539 (setq ignore-next nil rvalue semi-rvalue)
8540 (if (not exit-keywd) (setq end-else-check t)))
8541 ((member keywd '("case" "casex" "casez"))
8542 (skip-syntax-forward "w_")
8543 (verilog-read-always-signals-recurse "endcase" t nil)
8544 (setq ignore-next nil rvalue semi-rvalue)
8545 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end
8546 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent
8547 (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8548 (setq ignore-next t))
8550 (member keywd verilog-keywords)
8551 (string-match "^\\$" keywd)) ;; PLI task
8552 (setq ignore-next nil))
8554 (setq keywd (verilog-symbol-detick-denumber keywd))
8556 (set got-list (cons got-sig (symbol-value got-list)))
8557 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
8559 (setq got-list (cond (temp-next 'sigs-temp)
8562 got-sig (if (or (not keywd)
8563 (assoc keywd (symbol-value got-list)))
8564 nil (list keywd nil nil))
8567 (skip-chars-forward "a-zA-Z0-9$_.%`"))
8570 ;; End of non-comment token
8571 (setq last-keywd keywd)))
8572 (skip-syntax-forward " "))
8573 ;; Append the final pending signal
8575 ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
8576 (set got-list (cons got-sig (symbol-value got-list)))
8578 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
8581 (defun verilog-read-always-signals ()
8582 "Parse always block at point and return list of (outputs inout inputs)."
8585 sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
8586 (search-forward ")")
8587 (verilog-read-always-signals-recurse nil nil nil)
8588 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
8590 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))
8591 ;; Return what was found
8592 (verilog-alw-new sigs-out-d sigs-out-i sigs-temp sigs-in))))
8594 (defun verilog-read-instants ()
8595 "Parse module at point and return list of ( ( file instance ) ... )."
8596 (verilog-beg-of-defun-quick)
8597 (let* ((end-mod-point (verilog-get-end-of-defun t))
8599 (instants-list nil))
8601 (while (< (point) end-mod-point)
8602 ;; Stay at level 0, no comments
8604 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
8605 (or (> (car state) 0) ; in parens
8606 (nth 5 state) ; comment
8610 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
8611 ;;(if (looking-at "^\\(.+\\)$")
8612 (let ((module (match-string 1))
8613 (instant (match-string 2)))
8614 (if (not (member module verilog-keywords))
8615 (setq instants-list (cons (list module instant) instants-list)))))
8620 (defun verilog-read-auto-template-middle ()
8621 "With point in middle of an AUTO_TEMPLATE, parse it.
8622 Returns REGEXP and list of ( (signal_name connection_name)... )."
8625 (let ((tpl-regexp "\\([0-9]+\\)")
8626 (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
8628 tpl-sig-list tpl-wild-list tpl-end-pt rep)
8630 ;; We reserve @"..." for future lisp expressions that evaluate
8631 ;; once-per-AUTOINST
8632 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
8633 (setq tpl-regexp (match-string 1))
8634 (goto-char (match-end 0)))
8635 (search-forward "(")
8636 ;; Parse lines in the template
8637 (when (or verilog-auto-inst-template-numbers
8638 verilog-auto-template-warn-unused)
8640 (let ((pre-pt (point)))
8641 (goto-char (point-min))
8642 (while (search-forward "AUTO_TEMPLATE" pre-pt t)
8643 (setq templateno (1+ templateno)))
8644 (while (< (point) pre-pt)
8646 (setq lineno (1+ lineno))))))
8647 (setq tpl-end-pt (save-excursion
8649 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8653 (while (< (point) tpl-end-pt)
8654 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8657 (match-string-no-properties 1)
8658 (match-string-no-properties 2)
8661 (goto-char (match-end 0)))
8664 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
8665 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8666 (setq rep (match-string-no-properties 3))
8667 (goto-char (match-end 0))
8671 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
8677 ((looking-at "[ \t\f]+")
8678 (goto-char (match-end 0)))
8680 (setq lineno (1+ lineno))
8681 (goto-char (match-end 0)))
8683 (search-forward "\n")
8684 (setq lineno (1+ lineno)))
8685 ((looking-at "/\\*")
8687 (or (search-forward "*/")
8688 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8690 (error "%s: AUTO_TEMPLATE parsing error: %s"
8691 (verilog-point-text)
8692 (progn (looking-at ".*$") (match-string 0))))))
8695 (list tpl-sig-list tpl-wild-list)))))
8697 (defun verilog-read-auto-template (module)
8698 "Look for an auto_template for the instantiation of the given MODULE.
8699 If found returns `verilog-read-auto-template-inside' structure."
8703 ;; Note this search is expensive, as we hunt from mod-begin to point
8704 ;; for every instantiation. Likewise in verilog-read-auto-lisp.
8705 ;; So, we look first for an exact string rather than a slow regexp.
8706 ;; Someday we may keep a cache of every template, but this would also
8707 ;; need to record the relative position of each AUTOINST, as multiple
8708 ;; templates exist for each module, and we're inserting lines.
8710 ;; See also regexp in `verilog-auto-template-lint'
8711 (verilog-re-search-backward-substr
8713 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
8714 ;; Also try forward of this AUTOINST
8715 ;; This is for historical support; this isn't speced as working
8718 (verilog-re-search-forward-substr
8720 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
8721 (goto-char (match-end 0))
8722 (verilog-read-auto-template-middle))
8723 ;; If no template found
8724 (t (vector "" nil))))))
8725 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
8727 (defvar verilog-auto-template-hits nil "Successful lookups with `verilog-read-auto-template-hit'.")
8728 (make-variable-buffer-local 'verilog-auto-template-hits)
8730 (defun verilog-read-auto-template-hit (tpl-ass)
8731 "Record that TPL-ASS template from `verilog-read-auto-template' was used."
8732 (when (eval-when-compile (fboundp 'make-hash-table)) ;; else feature not allowed
8733 (when verilog-auto-template-warn-unused
8734 (unless verilog-auto-template-hits
8735 (setq verilog-auto-template-hits
8736 (make-hash-table :test 'equal :rehash-size 4.0)))
8737 (puthash (vector (nth 2 tpl-ass) (nth 3 tpl-ass)) t
8738 verilog-auto-template-hits))))
8740 (defun verilog-set-define (defname defvalue &optional buffer enumname)
8741 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
8742 Optionally associate it with the specified enumeration ENUMNAME."
8743 (with-current-buffer (or buffer (current-buffer))
8744 (let ((mac (intern (concat "vh-" defname))))
8745 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
8746 ;; Need to define to a constant if no value given
8747 (set (make-local-variable mac)
8748 (if (equal defvalue "") "1" defvalue)))
8750 (let ((enumvar (intern (concat "venum-" enumname))))
8751 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
8752 (unless (boundp enumvar) (set enumvar nil))
8753 (add-to-list (make-local-variable enumvar) defname)))))
8755 (defun verilog-read-defines (&optional filename recurse subcall)
8756 "Read `defines and parameters for the current file, or optional FILENAME.
8757 If the filename is provided, `verilog-library-flags' will be used to
8758 resolve it. If optional RECURSE is non-nil, recurse through `includes.
8760 Parameters must be simple assignments to constants, or have their own
8761 \"parameter\" label rather than a list of parameters. Thus:
8763 parameter X = 5, Y = 10; // Ok
8764 parameter X = {1'b1, 2'h2}; // Ok
8765 parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines
8767 Defines must be simple text substitutions, one on a line, starting
8768 at the beginning of the line. Any ifdefs or multiline comments around the
8771 Defines are stored inside Emacs variables using the name vh-{definename}.
8773 This function is useful for setting vh-* variables. The file variables
8774 feature can be used to set defines that `verilog-mode' can see; put at the
8775 *END* of your file something like:
8778 // vh-macro:\"macro_definition\"
8781 If macros are defined earlier in the same file and you want their values,
8782 you can read them automatically (provided `enable-local-eval' is on):
8785 // eval:(verilog-read-defines)
8786 // eval:(verilog-read-defines \"group_standard_includes.v\")
8789 Note these are only read when the file is first visited, you must use
8790 \\[find-alternate-file] RET to have these take effect after editing them!
8792 If you want to disable the \"Process `eval' or hook local variables\"
8793 warning message, you need to add to your .emacs file:
8795 (setq enable-local-eval t)"
8796 (let ((origbuf (current-buffer)))
8798 (unless subcall (verilog-getopt-flags))
8800 (let ((fns (verilog-library-filenames filename (buffer-file-name))))
8802 (set-buffer (find-file-noselect (car fns)))
8803 (error (concat (verilog-point-text)
8804 ": Can't find verilog-read-defines file: " filename)))))
8806 (goto-char (point-min))
8807 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
8808 (let ((inc (verilog-string-replace-matches
8809 "\"" "" nil nil (match-string-no-properties 1))))
8810 (unless (verilog-inside-comment-or-string-p)
8811 (verilog-read-defines inc recurse t)))))
8813 ;; note we don't use verilog-re... it's faster this way, and that
8814 ;; function has problems when comments are at the end of the define
8815 (goto-char (point-min))
8816 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
8817 (let ((defname (match-string-no-properties 1))
8818 (defvalue (match-string-no-properties 2)))
8819 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
8820 (verilog-set-define defname defvalue origbuf)))
8821 ;; Hack: Read parameters
8822 (goto-char (point-min))
8823 (while (re-search-forward
8824 "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
8826 ;; The primary way of getting defines is verilog-read-decls
8827 ;; However, that isn't called yet for included files, so we'll add another scheme
8828 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8829 (setq enumname (match-string-no-properties 2)))
8830 (forward-comment 99999)
8831 (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
8832 "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
8833 (verilog-set-define (match-string-no-properties 1)
8834 (match-string-no-properties 2) origbuf enumname)
8835 (goto-char (match-end 0))
8836 (forward-comment 99999)))))))
8838 (defun verilog-read-includes ()
8839 "Read `includes for the current file.
8840 This will find all of the `includes which are at the beginning of lines,
8841 ignoring any ifdefs or multiline comments around them.
8842 `verilog-read-defines' is then performed on the current and each included
8845 It is often useful put at the *END* of your file something like:
8848 // eval:(verilog-read-defines)
8849 // eval:(verilog-read-includes)
8852 Note includes are only read when the file is first visited, you must use
8853 \\[find-alternate-file] RET to have these take effect after editing them!
8855 It is good to get in the habit of including all needed files in each .v
8856 file that needs it, rather than waiting for compile time. This will aid
8857 this process, Verilint, and readability. To prevent defining the same
8858 variable over and over when many modules are compiled together, put a test
8859 around the inside each include file:
8861 foo.v (an include file):
8862 `ifdef _FOO_V // include if not already included
8865 ... contents of file
8867 ;;slow: (verilog-read-defines nil t))
8869 (verilog-getopt-flags)
8870 (goto-char (point-min))
8871 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
8872 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
8873 (verilog-read-defines inc nil t)))))
8875 (defun verilog-read-signals (&optional start end)
8876 "Return a simple list of all possible signals in the file.
8877 Bounded by optional region from START to END. Overly aggressive but fast.
8878 Some macros and such are also found and included. For dinotrace.el."
8879 (let (sigs-all keywd)
8880 (progn;save-excursion
8881 (goto-char (or start (point-min)))
8882 (setq end (or end (point-max)))
8883 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
8887 (search-forward "\n"))
8888 ((looking-at "/\\*")
8889 (search-forward "*/"))
8890 ((looking-at "(\\*")
8891 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
8892 (search-forward "*)")))
8893 ((eq ?\" (following-char))
8894 (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first
8895 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
8896 (goto-char (match-end 0))
8897 (setq keywd (match-string-no-properties 1))
8898 (or (member keywd verilog-keywords)
8899 (member keywd sigs-all)
8900 (setq sigs-all (cons keywd sigs-all))))
8901 (t (forward-char 1))))
8906 ;; Argument file parsing
8909 (defun verilog-getopt (arglist)
8910 "Parse -f, -v etc arguments in ARGLIST list or string."
8911 (unless (listp arglist) (setq arglist (list arglist)))
8912 (let ((space-args '())
8914 ;; Split on spaces, so users can pass whole command lines
8916 (setq arg (car arglist)
8917 arglist (cdr arglist))
8918 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
8919 (setq space-args (append space-args
8920 (list (match-string-no-properties 1 arg))))
8921 (setq arg (match-string 2 arg))))
8924 (setq arg (car space-args)
8925 space-args (cdr space-args))
8929 (setq next-param arg))
8931 (setq next-param arg))
8933 (setq next-param arg))
8934 ;; +libext+(ext1)+(ext2)...
8935 ((string-match "^\\+libext\\+\\(.*\\)" arg)
8936 (setq arg (match-string 1 arg))
8937 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
8938 (verilog-add-list-unique `verilog-library-extensions
8939 (match-string 1 arg))
8940 (setq arg (match-string 2 arg))))
8942 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val
8943 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine
8944 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val
8945 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define
8946 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
8948 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir
8949 (string-match "^-I\\(.*\\)" arg)) ;; -Idir
8950 (verilog-add-list-unique `verilog-library-directories
8951 (match-string 1 (substitute-in-file-name arg))))
8953 ((equal "+librescan" arg))
8954 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine
8955 ;; Second parameters
8956 ((equal next-param "-f")
8957 (setq next-param nil)
8958 (verilog-getopt-file (substitute-in-file-name arg)))
8959 ((equal next-param "-v")
8960 (setq next-param nil)
8961 (verilog-add-list-unique `verilog-library-files
8962 (substitute-in-file-name arg)))
8963 ((equal next-param "-y")
8964 (setq next-param nil)
8965 (verilog-add-list-unique `verilog-library-directories
8966 (substitute-in-file-name arg)))
8968 ((string-match "^[^-+]" arg)
8969 (verilog-add-list-unique `verilog-library-files
8970 (substitute-in-file-name arg)))
8971 ;; Default - ignore; no warning
8973 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
8975 (defun verilog-getopt-file (filename)
8976 "Read Verilog options from the specified FILENAME."
8978 (let ((fns (verilog-library-filenames filename (buffer-file-name)))
8979 (orig-buffer (current-buffer))
8982 (set-buffer (find-file-noselect (car fns)))
8983 (error (concat (verilog-point-text)
8984 ": Can't find verilog-getopt-file -f file: " filename)))
8985 (goto-char (point-min))
8987 (setq line (buffer-substring (point) (point-at-eol)))
8989 (when (string-match "//" line)
8990 (setq line (substring line 0 (match-beginning 0))))
8991 (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
8992 (verilog-getopt line))))))
8994 (defun verilog-getopt-flags ()
8995 "Convert `verilog-library-flags' into standard library variables."
8996 ;; If the flags are local, then all the outputs should be local also
8997 (when (local-variable-p `verilog-library-flags (current-buffer))
8998 (mapc 'make-local-variable '(verilog-library-extensions
8999 verilog-library-directories
9000 verilog-library-files
9001 verilog-library-flags)))
9002 ;; Allow user to customize
9003 (verilog-run-hooks 'verilog-before-getopt-flags-hook)
9004 ;; Process arguments
9005 (verilog-getopt verilog-library-flags)
9006 ;; Allow user to customize
9007 (verilog-run-hooks 'verilog-getopt-flags-hook))
9009 (defun verilog-add-list-unique (varref object)
9010 "Append to VARREF list the given OBJECT,
9011 unless it is already a member of the variable's list."
9012 (unless (member object (symbol-value varref))
9013 (set varref (append (symbol-value varref) (list object))))
9015 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
9017 (defun verilog-current-flags ()
9018 "Convert `verilog-library-flags' and similar variables to command line.
9019 Used for __FLAGS__ in `verilog-expand-command'."
9020 (let ((cmd (mapconcat `concat verilog-library-flags " ")))
9021 (when (equal cmd "")
9023 "+libext+" (mapconcat `concat verilog-library-extensions "+")
9024 (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
9025 verilog-library-directories "")
9026 (mapconcat (lambda (i) (concat " -v " i))
9027 verilog-library-files ""))))
9029 ;;(verilog-current-flags)
9033 ;; Cached directory support
9036 (defvar verilog-dir-cache-preserving nil
9037 "If set, the directory cache is enabled, and file system changes are ignored.
9038 See `verilog-dir-exists-p' and `verilog-dir-files'.")
9040 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
9041 (defvar verilog-dir-cache-list nil
9042 "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
9043 (defvar verilog-dir-cache-lib-filenames nil
9044 "Cached data for `verilog-library-filenames'.")
9046 (defmacro verilog-preserve-dir-cache (&rest body)
9047 "Execute the BODY forms, allowing directory cache preservation within BODY.
9048 This means that changes inside BODY made to the file system will not be
9049 seen by the `verilog-dir-files' and related functions."
9050 `(let ((verilog-dir-cache-preserving (current-buffer))
9051 verilog-dir-cache-list
9052 verilog-dir-cache-lib-filenames)
9055 (defun verilog-dir-files (dirname)
9056 "Return all filenames in the DIRNAME directory.
9057 Relative paths depend on the `default-directory'.
9058 Results are cached if inside `verilog-preserve-dir-cache'."
9059 (unless verilog-dir-cache-preserving
9060 (setq verilog-dir-cache-list nil)) ;; Cache disabled
9061 ;; We don't use expand-file-name on the dirname to make key, as it's slow
9062 (let* ((cache-key (list dirname default-directory))
9063 (fass (assoc cache-key verilog-dir-cache-list))
9065 (cond (fass ;; Return data from cache hit
9068 (setq exp-dirname (expand-file-name dirname)
9069 data (and (file-directory-p exp-dirname)
9070 (directory-files exp-dirname nil nil nil)))
9071 ;; Note we also encache nil for non-existing dirs.
9072 (setq verilog-dir-cache-list (cons (list cache-key data)
9073 verilog-dir-cache-list))
9075 ;; Miss-and-hit test:
9076 ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
9077 ;; (prin1 (verilog-dir-files ".")) nil)
9079 (defun verilog-dir-file-exists-p (filename)
9080 "Return true if FILENAME exists.
9081 Like `file-exists-p' but results are cached if inside
9082 `verilog-preserve-dir-cache'."
9083 (let* ((dirname (file-name-directory filename))
9084 ;; Correct for file-name-nondirectory returning same if no slash.
9085 (dirnamed (if (or (not dirname) (equal dirname filename))
9086 default-directory dirname))
9087 (flist (verilog-dir-files dirnamed)))
9089 (member (file-name-nondirectory filename) flist)
9091 ;;(verilog-dir-file-exists-p "verilog-mode.el")
9092 ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
9096 ;; Module name lookup
9099 (defun verilog-module-inside-filename-p (module filename)
9100 "Return modi if MODULE is specified inside FILENAME, else nil.
9101 Allows version control to check out the file if need be."
9102 (and (or (file-exists-p filename)
9103 (and (fboundp 'vc-backend)
9104 (vc-backend filename)))
9106 (with-current-buffer (find-file-noselect filename)
9108 (goto-char (point-min))
9110 ;; It may be tempting to look for verilog-defun-re,
9111 ;; don't, it slows things down a lot!
9112 (verilog-re-search-forward-quick "\\<\\(module\\|interface\\|program\\)\\>" nil t)
9113 (setq type (match-string-no-properties 0))
9114 (verilog-re-search-forward-quick "[(;]" nil t))
9115 (if (equal module (verilog-read-module-name))
9116 (setq modi (verilog-modi-new module filename (point) type))))
9119 (defun verilog-is-number (symbol)
9120 "Return true if SYMBOL is number-like."
9121 (or (string-match "^[0-9 \t:]+$" symbol)
9122 (string-match "^[---]*[0-9]+$" symbol)
9123 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
9125 (defun verilog-symbol-detick (symbol wing-it)
9126 "Return an expanded SYMBOL name without any defines.
9127 If the variable vh-{symbol} is defined, return that value.
9128 If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
9129 (while (and symbol (string-match "^`" symbol))
9130 (setq symbol (substring symbol 1))
9132 (if (boundp (intern (concat "vh-" symbol)))
9133 ;; Emacs has a bug where boundp on a buffer-local
9134 ;; variable in only one buffer returns t in another.
9135 ;; This can confuse, so check for nil.
9136 (let ((val (eval (intern (concat "vh-" symbol)))))
9138 (if wing-it symbol nil)
9140 (if wing-it symbol nil))))
9142 ;;(verilog-symbol-detick "`mod" nil)
9144 (defun verilog-symbol-detick-denumber (symbol)
9145 "Return SYMBOL with defines converted and any numbers dropped to nil."
9146 (when (string-match "^`" symbol)
9147 ;; This only will work if the define is a simple signal, not
9148 ;; something like a[b]. Sorry, it should be substituted into the parser
9150 (verilog-string-replace-matches
9151 "\[[^0-9: \t]+\]" "" nil nil
9152 (or (verilog-symbol-detick symbol nil)
9153 (if verilog-auto-sense-defines-constant
9156 (if (verilog-is-number symbol)
9160 (defun verilog-symbol-detick-text (text)
9161 "Return TEXT without any known defines.
9162 If the variable vh-{symbol} is defined, substitute that value."
9163 (let ((ok t) symbol val)
9164 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
9165 (setq symbol (match-string 1 text))
9168 (boundp (intern (concat "vh-" symbol)))
9169 ;; Emacs has a bug where boundp on a buffer-local
9170 ;; variable in only one buffer returns t in another.
9171 ;; This can confuse, so check for nil.
9172 (setq val (eval (intern (concat "vh-" symbol)))))
9173 (setq text (replace-match val nil nil text)))
9174 (t (setq ok nil)))))
9176 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
9178 (defun verilog-expand-dirnames (&optional dirnames)
9179 "Return a list of existing directories given a list of wildcarded DIRNAMES.
9180 Or, just the existing dirnames themselves if there are no wildcards."
9181 ;; Note this function is performance critical.
9182 ;; Do not call anything that requires disk access that cannot be cached.
9184 (unless dirnames (error "`verilog-library-directories' should include at least '.'"))
9185 (setq dirnames (reverse dirnames)) ; not nreverse
9187 pattern dirfile dirfiles dirname root filename rest basefile)
9189 (setq dirname (substitute-in-file-name (car dirnames))
9190 dirnames (cdr dirnames))
9191 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root
9192 "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *?
9195 (setq root (match-string 1 dirname)
9196 filename (match-string 2 dirname)
9197 rest (match-string 3 dirname)
9199 ;; now replace those * and ? with .+ and .
9200 ;; use ^ and /> to get only whole file names
9201 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
9202 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
9203 pattern (concat "^" pattern "$")
9204 dirfiles (verilog-dir-files root))
9206 (setq basefile (car dirfiles)
9207 dirfile (expand-file-name (concat root basefile rest))
9208 dirfiles (cdr dirfiles))
9209 (if (and (string-match pattern basefile)
9210 ;; Don't allow abc/*/rtl to match abc/rtl via ..
9211 (not (equal basefile "."))
9212 (not (equal basefile ".."))
9213 (file-directory-p dirfile))
9214 (setq dirlist (cons dirfile dirlist)))))
9217 (if (file-directory-p dirname)
9218 (setq dirlist (cons dirname dirlist))))))
9220 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
9222 (defun verilog-library-filenames (filename &optional current check-ext)
9223 "Return a search path to find the given FILENAME or module name.
9224 Uses the optional CURRENT filename or variable `buffer-file-name', plus
9225 `verilog-library-directories' and `verilog-library-extensions'
9226 variables to build the path. With optional CHECK-EXT also check
9227 `verilog-library-extensions'."
9228 (unless current (setq current (buffer-file-name)))
9229 (unless verilog-dir-cache-preserving
9230 (setq verilog-dir-cache-lib-filenames nil))
9231 (let* ((cache-key (list filename current check-ext))
9232 (fass (assoc cache-key verilog-dir-cache-lib-filenames))
9233 chkdirs chkdir chkexts fn outlist)
9234 (cond (fass ;; Return data from cache hit
9237 ;; Note this expand can't be easily cached, as we need to
9238 ;; pick up buffer-local variables for newly read sub-module files
9239 (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
9241 (setq chkdir (expand-file-name (car chkdirs)
9242 (file-name-directory current))
9243 chkexts (if check-ext verilog-library-extensions `("")))
9245 (setq fn (expand-file-name (concat filename (car chkexts))
9247 ;;(message "Check for %s" fn)
9248 (if (verilog-dir-file-exists-p fn)
9249 (setq outlist (cons (expand-file-name
9250 fn (file-name-directory current))
9252 (setq chkexts (cdr chkexts)))
9253 (setq chkdirs (cdr chkdirs)))
9254 (setq outlist (nreverse outlist))
9255 (setq verilog-dir-cache-lib-filenames
9256 (cons (list cache-key outlist)
9257 verilog-dir-cache-lib-filenames))
9260 (defun verilog-module-filenames (module current)
9261 "Return a search path to find the given MODULE name.
9262 Uses the CURRENT filename, `verilog-library-extensions',
9263 `verilog-library-directories' and `verilog-library-files'
9264 variables to build the path."
9265 ;; Return search locations for it
9266 (append (list current) ; first, current buffer
9267 (verilog-library-filenames module current t)
9268 verilog-library-files)) ; finally, any libraries
9271 ;; Module Information
9273 ;; Many of these functions work on "modi" a module information structure
9274 ;; A modi is: [module-name-string file-name begin-point]
9276 (defvar verilog-cache-enabled t
9277 "Non-nil enables caching of signals, etc. Set to nil for debugging to make things SLOW!")
9279 (defvar verilog-modi-cache-list nil
9280 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
9281 For speeding up verilog-modi-get-* commands.
9283 (make-variable-buffer-local 'verilog-modi-cache-list)
9285 (defvar verilog-modi-cache-preserve-tick nil
9286 "Modification tick after which the cache is still considered valid.
9287 Use `verilog-preserve-modi-cache' to set it.")
9288 (defvar verilog-modi-cache-preserve-buffer nil
9289 "Modification tick after which the cache is still considered valid.
9290 Use `verilog-preserve-modi-cache' to set it.")
9291 (defvar verilog-modi-cache-current-enable nil
9292 "Non-nil means allow caching `verilog-modi-current', set by let().")
9293 (defvar verilog-modi-cache-current nil
9294 "Currently active `verilog-modi-current', if any, set by let().")
9295 (defvar verilog-modi-cache-current-max nil
9296 "Current endmodule point for `verilog-modi-cache-current', if any.")
9298 (defun verilog-modi-current ()
9299 "Return the modi structure for the module currently at point, possibly cached."
9300 (cond ((and verilog-modi-cache-current
9301 (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
9302 (<= (point) verilog-modi-cache-current-max))
9303 ;; Slow assertion, for debugging the cache:
9304 ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
9305 verilog-modi-cache-current)
9306 (verilog-modi-cache-current-enable
9307 (setq verilog-modi-cache-current (verilog-modi-current-get)
9308 verilog-modi-cache-current-max
9309 ;; The cache expires when we pass "endmodule" as then the
9310 ;; current modi may change to the next module
9311 ;; This relies on the AUTOs generally inserting, not deleting text
9313 (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
9314 verilog-modi-cache-current)
9316 (verilog-modi-current-get))))
9318 (defun verilog-modi-current-get ()
9319 "Return the modi structure for the module currently at point."
9320 (let* (name type pt)
9321 ;; read current module's name
9323 (verilog-re-search-backward-quick verilog-defun-re nil nil)
9324 (setq type (match-string-no-properties 0))
9325 (verilog-re-search-forward-quick "(" nil nil)
9326 (setq name (verilog-read-module-name))
9328 ;; return modi - note this vector built two places
9329 (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
9331 (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
9332 (make-variable-buffer-local 'verilog-modi-lookup-cache)
9333 (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
9334 (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
9336 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
9337 "Find the file and point at which MODULE is defined.
9338 If ALLOW-CACHE is set, check and remember cache of previous lookups.
9339 Return modi if successful, else print message unless IGNORE-ERROR is true."
9340 (let* ((current (or (buffer-file-name) (current-buffer)))
9343 ;;(message "verilog-modi-lookup: %s" module)
9344 (cond ((and verilog-modi-lookup-cache
9345 verilog-cache-enabled
9347 (setq modi (gethash module verilog-modi-lookup-cache))
9348 (equal verilog-modi-lookup-last-current current)
9349 ;; Iff hit is in current buffer, then tick must match
9350 (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
9351 (not (equal current (verilog-modi-file-or-buffer modi)))))
9352 ;;(message "verilog-modi-lookup: HIT %S" modi)
9355 (t (let* ((realmod (verilog-symbol-detick module t))
9356 (orig-filenames (verilog-module-filenames realmod current))
9357 (filenames orig-filenames)
9359 (while (and filenames (not mif))
9360 (if (not (setq mif (verilog-module-inside-filename-p realmod (car filenames))))
9361 (setq filenames (cdr filenames))))
9362 ;; mif has correct form to become later elements of modi
9363 (cond (mif (setq modi mif))
9366 (error (concat (verilog-point-text)
9367 ": Can't locate " module " module definition"
9368 (if (not (equal module realmod))
9369 (concat " (Expanded macro to " realmod ")")
9371 "\n Check the verilog-library-directories variable."
9372 "\n I looked in (if not listed, doesn't exist):\n\t"
9373 (mapconcat 'concat orig-filenames "\n\t"))))))
9374 (when (eval-when-compile (fboundp 'make-hash-table))
9375 (unless verilog-modi-lookup-cache
9376 (setq verilog-modi-lookup-cache
9377 (make-hash-table :test 'equal :rehash-size 4.0)))
9378 (puthash module modi verilog-modi-lookup-cache))
9379 (setq verilog-modi-lookup-last-current current
9380 verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
9383 (defun verilog-modi-filename (modi)
9384 "Filename of MODI, or name of buffer if it's never been saved."
9385 (if (bufferp (verilog-modi-file-or-buffer modi))
9386 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
9387 (buffer-name (verilog-modi-file-or-buffer modi)))
9388 (verilog-modi-file-or-buffer modi)))
9390 (defun verilog-modi-goto (modi)
9391 "Move point/buffer to specified MODI."
9392 (or modi (error "Passed unfound modi to goto, check earlier"))
9393 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
9394 (verilog-modi-file-or-buffer modi)
9395 (find-file-noselect (verilog-modi-file-or-buffer modi))))
9396 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax
9398 (goto-char (verilog-modi-get-point modi)))
9400 (defun verilog-goto-defun-file (module)
9401 "Move point to the file at which a given MODULE is defined."
9402 (interactive "sGoto File for Module: ")
9403 (let* ((modi (verilog-modi-lookup module nil)))
9405 (verilog-modi-goto modi)
9406 (switch-to-buffer (current-buffer)))))
9408 (defun verilog-modi-cache-results (modi function)
9409 "Run on MODI the given FUNCTION. Locate the module in a file.
9410 Cache the output of function so next call may have faster access."
9412 (save-excursion ;; Cache is buffer-local so can't avoid this.
9413 (verilog-modi-goto modi)
9414 (if (and (setq fass (assoc (list modi function)
9415 verilog-modi-cache-list))
9416 ;; Destroy caching when incorrect; Modified or file changed
9417 (not (and verilog-cache-enabled
9418 (or (equal (buffer-chars-modified-tick) (nth 1 fass))
9419 (and verilog-modi-cache-preserve-tick
9420 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
9421 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
9422 (equal (visited-file-modtime) (nth 2 fass)))))
9423 (setq verilog-modi-cache-list nil
9426 ;; Return data from cache hit
9430 ;; Clear then restore any highlighting to make emacs19 happy
9432 (verilog-save-font-mods
9433 (setq func-returns (funcall function)))
9434 ;; Cache for next time
9435 (setq verilog-modi-cache-list
9436 (cons (list (list modi function)
9437 (buffer-chars-modified-tick)
9438 (visited-file-modtime)
9440 verilog-modi-cache-list))
9443 (defun verilog-modi-cache-add (modi function element sig-list)
9444 "Add function return results to the module cache.
9445 Update MODI's cache for given FUNCTION so that the return ELEMENT of that
9446 function now contains the additional SIG-LIST parameters."
9449 (verilog-modi-goto modi)
9450 (if (setq fass (assoc (list modi function)
9451 verilog-modi-cache-list))
9452 (let ((func-returns (nth 3 fass)))
9453 (aset func-returns element
9454 (append sig-list (aref func-returns element))))))))
9456 (defmacro verilog-preserve-modi-cache (&rest body)
9457 "Execute the BODY forms, allowing cache preservation within BODY.
9458 This means that changes to the buffer will not result in the cache being
9459 flushed. If the changes affect the modsig state, they must call the
9460 modsig-cache-add-* function, else the results of later calls may be
9461 incorrect. Without this, changes are assumed to be adding/removing signals
9462 and invalidating the cache."
9463 `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
9464 (verilog-modi-cache-preserve-buffer (current-buffer)))
9468 (defun verilog-signals-matching-enum (in-list enum)
9469 "Return all signals in IN-LIST matching the given ENUM."
9472 (if (equal (verilog-sig-enum (car in-list)) enum)
9473 (setq out-list (cons (car in-list) out-list)))
9474 (setq in-list (cdr in-list)))
9476 (let* ((enumvar (intern (concat "venum-" enum)))
9477 (enumlist (and (boundp enumvar) (eval enumvar))))
9479 (add-to-list 'out-list (list (car enumlist)))
9480 (setq enumlist (cdr enumlist))))
9481 (nreverse out-list)))
9483 (defun verilog-signals-matching-regexp (in-list regexp)
9484 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
9485 (if (or (not regexp) (equal regexp ""))
9489 (if (string-match regexp (verilog-sig-name (car in-list)))
9490 (setq out-list (cons (car in-list) out-list)))
9491 (setq in-list (cdr in-list)))
9492 (nreverse out-list))))
9494 (defun verilog-signals-not-matching-regexp (in-list regexp)
9495 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
9496 (if (or (not regexp) (equal regexp ""))
9500 (if (not (string-match regexp (verilog-sig-name (car in-list))))
9501 (setq out-list (cons (car in-list) out-list)))
9502 (setq in-list (cdr in-list)))
9503 (nreverse out-list))))
9505 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
9506 "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
9508 (if (or (not regexp) (equal regexp ""))
9510 (let (out-list to-match)
9512 ;; Note verilog-insert-one-definition matches on this order
9513 (setq to-match (concat
9515 " " (verilog-sig-signed (car in-list))
9516 " " (verilog-sig-multidim (car in-list))
9517 (verilog-sig-bits (car in-list))))
9518 (if (string-match regexp to-match)
9519 (setq out-list (cons (car in-list) out-list)))
9520 (setq in-list (cdr in-list)))
9521 (nreverse out-list))))
9523 (defun verilog-signals-edit-wire-reg (in-list)
9524 "Return all signals in IN-LIST with wire/reg data types made blank."
9525 (mapcar (lambda (sig)
9526 (when (member (verilog-sig-type sig) '("wire" "reg"))
9527 (verilog-sig-type-set sig nil))
9531 (defun verilog-decls-get-signals (decls)
9532 "Return all declared signals in DECLS, excluding 'assign' statements."
9534 (verilog-decls-get-outputs decls)
9535 (verilog-decls-get-inouts decls)
9536 (verilog-decls-get-inputs decls)
9537 (verilog-decls-get-vars decls)
9538 (verilog-decls-get-consts decls)
9539 (verilog-decls-get-gparams decls)))
9541 (defun verilog-decls-get-ports (decls)
9543 (verilog-decls-get-outputs decls)
9544 (verilog-decls-get-inouts decls)
9545 (verilog-decls-get-inputs decls)))
9547 (defsubst verilog-modi-cache-add-outputs (modi sig-list)
9548 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
9549 (defsubst verilog-modi-cache-add-inouts (modi sig-list)
9550 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
9551 (defsubst verilog-modi-cache-add-inputs (modi sig-list)
9552 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
9553 (defsubst verilog-modi-cache-add-vars (modi sig-list)
9554 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
9558 ;; Auto creation utilities
9561 (defun verilog-auto-re-search-do (search-for func)
9562 "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
9563 (goto-char (point-min))
9564 (while (verilog-re-search-forward-quick search-for nil t)
9567 (defun verilog-insert-one-definition (sig type indent-pt)
9568 "Print out a definition for SIG of the given TYPE,
9569 with appropriate INDENT-PT indentation."
9570 (indent-to indent-pt)
9571 ;; Note verilog-signals-matching-dir-re matches on this order
9573 (when (verilog-sig-modport sig)
9574 (insert "." (verilog-sig-modport sig)))
9575 (when (verilog-sig-signed sig)
9576 (insert " " (verilog-sig-signed sig)))
9577 (when (verilog-sig-multidim sig)
9578 (insert " " (verilog-sig-multidim-string sig)))
9579 (when (verilog-sig-bits sig)
9580 (insert " " (verilog-sig-bits sig)))
9581 (indent-to (max 24 (+ indent-pt 16)))
9582 (unless (= (char-syntax (preceding-char)) ?\ )
9583 (insert " ")) ; Need space between "]name" if indent-to did nothing
9584 (insert (verilog-sig-name sig))
9585 (when (verilog-sig-memory sig)
9586 (insert " " (verilog-sig-memory sig))))
9588 (defun verilog-insert-definition (modi sigs direction indent-pt v2k &optional dont-sort)
9589 "Print out a definition for MODI's list of SIGS of the given DIRECTION,
9590 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
9591 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output.
9592 When MODI is non-null, also add to modi-cache, for tracking."
9594 (cond ((equal direction "wire")
9595 (verilog-modi-cache-add-vars modi sigs))
9596 ((equal direction "reg")
9597 (verilog-modi-cache-add-vars modi sigs))
9598 ((equal direction "output")
9599 (verilog-modi-cache-add-outputs modi sigs)
9600 (when verilog-auto-declare-nettype
9601 (verilog-modi-cache-add-vars modi sigs)))
9602 ((equal direction "input")
9603 (verilog-modi-cache-add-inputs modi sigs)
9604 (when verilog-auto-declare-nettype
9605 (verilog-modi-cache-add-vars modi sigs)))
9606 ((equal direction "inout")
9607 (verilog-modi-cache-add-inouts modi sigs)
9608 (when verilog-auto-declare-nettype
9609 (verilog-modi-cache-add-vars modi sigs)))
9610 ((equal direction "interface"))
9612 (error "Unsupported verilog-insert-definition direction: %s" direction))))
9614 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
9616 (let ((sig (car sigs)))
9617 (verilog-insert-one-definition
9619 ;; Want "type x" or "output type x", not "wire type x"
9620 (cond ((or (verilog-sig-type sig)
9621 verilog-auto-wire-type)
9623 (when (member direction '("input" "output" "inout"))
9624 (concat direction " "))
9625 (or (verilog-sig-type sig)
9626 verilog-auto-wire-type)))
9627 ((and verilog-auto-declare-nettype
9628 (member direction '("input" "output" "inout")))
9629 (concat direction " " verilog-auto-declare-nettype))
9633 (insert (if v2k "," ";"))
9634 (if (or (not (verilog-sig-comment sig))
9635 (equal "" (verilog-sig-comment sig)))
9637 (indent-to (max 48 (+ indent-pt 40)))
9638 (verilog-insert "// " (verilog-sig-comment sig) "\n"))
9639 (setq sigs (cdr sigs)))))
9642 (if (not (boundp 'indent-pt))
9643 (defvar indent-pt nil "Local used by insert-indent")))
9645 (defun verilog-insert-indent (&rest stuff)
9646 "Indent to position stored in local `indent-pt' variable, then insert STUFF.
9647 Presumes that any newlines end a list element."
9648 (let ((need-indent t))
9650 (if need-indent (indent-to indent-pt))
9651 (setq need-indent nil)
9652 (verilog-insert (car stuff))
9653 (setq need-indent (string-match "\n$" (car stuff))
9654 stuff (cdr stuff)))))
9655 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
9657 (defun verilog-repair-open-comma ()
9658 "Insert comma if previous argument is other than an open parenthesis or endif."
9659 ;; We can't just search backward for ) as it might be inside another expression.
9660 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
9662 (verilog-backward-syntactic-ws-quick)
9663 (when (and (not (save-excursion ;; Not beginning (, or existing ,
9665 (looking-at "[(,]")))
9666 (not (save-excursion ;; Not `endif, or user define
9668 (skip-chars-backward "[a-zA-Z0-9_`]")
9672 (defun verilog-repair-close-comma ()
9673 "If point is at a comma followed by a close parenthesis, fix it.
9674 This repairs those mis-inserted by an AUTOARG."
9675 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
9677 (verilog-forward-close-paren)
9679 (verilog-backward-syntactic-ws-quick)
9681 (when (looking-at ",")
9684 (defun verilog-get-list (start end)
9685 "Return the elements of a comma separated list between START and END."
9687 (let ((my-list (list))
9690 (while (< (point) end)
9691 (when (re-search-forward "\\([^,{]+\\)" end t)
9692 (setq my-string (verilog-string-remove-spaces (match-string 1)))
9693 (setq my-list (nconc my-list (list my-string) ))
9694 (goto-char (match-end 0))))
9697 (defun verilog-make-width-expression (range-exp)
9698 "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
9700 (cond ((not range-exp)
9703 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
9704 (setq range-exp (match-string 1 range-exp)))
9705 (cond ((not range-exp)
9707 ;; [#:#] We can compute a numeric result
9708 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
9711 (1+ (abs (- (string-to-number (match-string 1 range-exp))
9712 (string-to-number (match-string 2 range-exp)))))))
9713 ;; [PARAM-1:0] can just return PARAM
9714 ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
9715 (match-string 1 range-exp))
9716 ;; [arbitrary] need math
9717 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
9718 (concat "(1+(" (match-string 1 range-exp) ")"
9719 (if (equal "0" (match-string 2 range-exp))
9720 "" ;; Don't bother with -(0)
9721 (concat "-(" (match-string 2 range-exp) ")"))
9724 ;;(verilog-make-width-expression "`A:`B")
9726 (defun verilog-simplify-range-expression (expr)
9727 "Return a simplified range expression with constants eliminated from EXPR."
9728 ;; Note this is always called with brackets; ie [z] or [z:z]
9729 (if (not (string-match "[---+*()]" expr))
9730 expr ;; short-circuit
9733 (while (not (equal last-pass out))
9734 (setq last-pass out)
9735 ;; Prefix regexp needs beginning of match, or some symbol of
9736 ;; lesser or equal precedence. We assume the [:]'s exist in expr.
9738 (while (string-match
9739 (concat "\\([[({:*+-]\\)" ; - must be last
9740 "(\\<\\([0-9A-Za-z_]+\\))"
9743 (setq out (replace-match "\\1\\2\\3" nil nil out)))
9744 ;; For precedence do * before +/-
9745 (while (string-match
9746 (concat "\\([[({:*+-]\\)"
9747 "\\([0-9]+\\)\\s *\\([*]\\)\\s *\\([0-9]+\\)"
9750 (setq out (replace-match
9751 (concat (match-string 1 out)
9752 (int-to-string (* (string-to-number (match-string 2 out))
9753 (string-to-number (match-string 4 out))))
9754 (match-string 5 out))
9756 (while (string-match
9757 (concat "\\([[({:+-]\\)" ; No * here as higher prec
9758 "\\([0-9]+\\)\\s *\\([---+]\\)\\s *\\([0-9]+\\)"
9761 (let ((pre (match-string 1 out))
9762 (lhs (string-to-number (match-string 2 out)))
9763 (rhs (string-to-number (match-string 4 out)))
9764 (post (match-string 5 out))
9766 (when (equal pre "-")
9768 (setq val (if (equal (match-string 3 out) "-")
9772 (concat (if (and (equal pre "-")
9774 "" ;; Not "--20" but just "-20"
9780 ;;(verilog-simplify-range-expression "[1:3]") ;; 1
9781 ;;(verilog-simplify-range-expression "[(1):3]") ;; 1
9782 ;;(verilog-simplify-range-expression "[(((16)+1)+1+(1+1))]") ;;20
9783 ;;(verilog-simplify-range-expression "[(2*3+6*7)]") ;; 48
9784 ;;(verilog-simplify-range-expression "[(FOO*4-1*2)]") ;; FOO*4-2
9785 ;;(verilog-simplify-range-expression "[(FOO*4+1-1)]") ;; FOO*4+0
9786 ;;(verilog-simplify-range-expression "[(func(BAR))]") ;; func(BAR)
9787 ;;(verilog-simplify-range-expression "[FOO-1+1-1+1]") ;; FOO-0
9789 (defun verilog-typedef-name-p (variable-name)
9790 "Return true if the VARIABLE-NAME is a type definition."
9791 (when verilog-typedef-regexp
9792 (string-match verilog-typedef-regexp variable-name)))
9798 (defun verilog-delete-autos-lined ()
9799 "Delete autos that occupy multiple lines, between begin and end comments."
9800 ;; The newline must not have a comment property, so we must
9801 ;; delete the end auto's newline, not the first newline
9805 (looking-at "\\s-*// Beginning")
9806 (search-forward "// End of automatic" nil t))
9810 (delete-region pt (point)))))
9812 (defun verilog-delete-empty-auto-pair ()
9813 "Delete begin/end auto pair at point, if empty."
9815 (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
9816 "\\s-*// End of automatics\n"))
9817 (delete-region (point) (save-excursion (forward-line 2) (point)))))
9819 (defun verilog-forward-close-paren ()
9820 "Find the close parenthesis that match the current point.
9821 Ignore other close parenthesis with matching open parens."
9824 (unless (verilog-re-search-forward-quick "[()]" nil t)
9825 (error "%s: Mismatching ()" (verilog-point-text)))
9826 (cond ((= (preceding-char) ?\( )
9827 (setq parens (1+ parens)))
9828 ((= (preceding-char) ?\) )
9829 (setq parens (1- parens)))))))
9831 (defun verilog-backward-open-paren ()
9832 "Find the open parenthesis that match the current point.
9833 Ignore other open parenthesis with matching close parens."
9836 (unless (verilog-re-search-backward-quick "[()]" nil t)
9837 (error "%s: Mismatching ()" (verilog-point-text)))
9838 (cond ((= (following-char) ?\) )
9839 (setq parens (1+ parens)))
9840 ((= (following-char) ?\( )
9841 (setq parens (1- parens)))))))
9843 (defun verilog-backward-open-bracket ()
9844 "Find the open bracket that match the current point.
9845 Ignore other open bracket with matching close bracket."
9848 (unless (verilog-re-search-backward-quick "[][]" nil t)
9849 (error "%s: Mismatching []" (verilog-point-text)))
9850 (cond ((= (following-char) ?\] )
9851 (setq parens (1+ parens)))
9852 ((= (following-char) ?\[ )
9853 (setq parens (1- parens)))))))
9855 (defun verilog-delete-to-paren ()
9856 "Delete the automatic inst/sense/arg created by autos.
9857 Deletion stops at the matching end parenthesis, outside comments."
9858 (delete-region (point)
9860 (verilog-backward-open-paren)
9861 (verilog-forward-sexp-ign-cmt 1) ;; Moves to paren that closes argdecl's
9865 (defun verilog-auto-star-safe ()
9866 "Return if a .* AUTOINST is safe to delete or expand.
9867 It was created by the AUTOS themselves, or by the user."
9868 (and verilog-auto-star-expand
9870 (concat "[ \t\n\f,]*\\([)]\\|// " verilog-inst-comment-re "\\)"))))
9872 (defun verilog-delete-auto-star-all ()
9873 "Delete a .* AUTOINST, if it is safe."
9874 (when (verilog-auto-star-safe)
9875 (verilog-delete-to-paren)))
9877 (defun verilog-delete-auto-star-implicit ()
9878 "Delete all .* implicit connections created by `verilog-auto-star'.
9879 This function will be called automatically at save unless
9880 `verilog-auto-star-save' is set, any non-templated expanded pins will be
9883 (let (paren-pt indent have-close-paren)
9885 (goto-char (point-min))
9886 ;; We need to match these even outside of comments.
9887 ;; For reasonable performance, we don't check if inside comments, sorry.
9888 (while (re-search-forward "// Implicit \\.\\*" nil t)
9889 (setq paren-pt (point))
9891 (setq have-close-paren
9893 (when (search-forward ");" paren-pt t)
9894 (setq indent (current-indentation))
9896 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
9897 (when have-close-paren
9898 ;; Delete extra commentary
9902 (looking-at (concat "\\s *//\\s *" verilog-inst-comment-re "\n")))
9903 (delete-region (match-beginning 0) (match-end 0))))
9904 ;; If it is simple, we can put the ); on the same line as the last text
9905 (let ((rtn-pt (point)))
9907 (while (progn (backward-char 1)
9908 (looking-at "[ \t\n\f]")))
9909 (when (looking-at ",")
9910 (delete-region (+ 1 (point)) rtn-pt))))
9914 ;; Still need to kill final comma - always is one as we put one after the .*
9915 (re-search-backward ",")
9916 (delete-char 1))))))
9918 (defun verilog-delete-auto ()
9919 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
9920 Use \\[verilog-auto] to re-insert the updated AUTOs.
9922 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
9923 called before and after this function, respectively."
9926 (if (buffer-file-name)
9927 (find-file-noselect (buffer-file-name))) ;; To check we have latest version
9928 (verilog-save-no-change-functions
9929 (verilog-save-scan-cache
9930 ;; Allow user to customize
9931 (verilog-run-hooks 'verilog-before-delete-auto-hook)
9933 ;; Remove those that have multi-line insertions, possibly with parameters
9934 ;; We allow anything beginning with AUTO, so that users can add their own
9936 (verilog-auto-re-search-do
9937 (concat "/\\*AUTO[A-Za-z0-9_]+"
9938 ;; Optional parens or quoted parameter or .* for (((...)))
9939 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
9941 'verilog-delete-autos-lined)
9942 ;; Remove those that are in parenthesis
9943 (verilog-auto-re-search-do
9946 (verilog-regexp-words
9947 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
9950 'verilog-delete-to-paren)
9951 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
9952 (verilog-auto-re-search-do "\\.\\*"
9953 'verilog-delete-auto-star-all)
9954 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
9955 (goto-char (point-min))
9956 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
9960 (verilog-run-hooks 'verilog-delete-auto-hook)))))
9966 (defun verilog-inject-auto ()
9967 "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
9969 Any always @ blocks with sensitivity lists that match computed lists will
9970 be replaced with /*AS*/ comments.
9972 Any cells will get /*AUTOINST*/ added to the end of the pin list.
9973 Pins with have identical names will be deleted.
9975 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
9976 support adding new ports. You may wish to delete older ports yourself.
9980 module ExampInject (i, o);
9991 Typing \\[verilog-inject-auto] will make this into:
9993 module ExampInject (i, o/*AUTOARG*/
9998 always @ (/*AS*/i or j)
10000 InstModule instName
10009 (defun verilog-inject-arg ()
10010 "Inject AUTOARG into new code. See `verilog-inject-auto'."
10011 ;; Presume one module per file.
10013 (goto-char (point-min))
10014 (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
10015 (let ((endmodp (save-excursion
10016 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
10018 ;; See if there's already a comment .. inside a comment so not verilog-re-search
10019 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
10020 (verilog-re-search-forward-quick ";" nil t)
10022 (verilog-backward-syntactic-ws-quick)
10023 (backward-char 1) ; Moves to paren that closes argdecl's
10024 (when (looking-at ")")
10025 (verilog-insert "/*AUTOARG*/")))))))
10027 (defun verilog-inject-sense ()
10028 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
10030 (goto-char (point-min))
10031 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
10032 (let* ((start-pt (point))
10033 (modi (verilog-modi-current))
10034 (moddecls (verilog-modi-get-decls modi))
10038 (verilog-forward-sexp-ign-cmt 1)
10039 (backward-char 1) ;; End )
10040 (when (not (verilog-re-search-backward-quick "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
10041 (setq pre-sigs (verilog-signals-from-signame
10042 (verilog-read-signals start-pt (point)))
10043 got-sigs (verilog-auto-sense-sigs moddecls nil))
10044 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
10045 (verilog-signals-not-in got-sigs pre-sigs)))
10046 (delete-region start-pt (point))
10047 (verilog-insert "/*AS*/")))))))
10049 (defun verilog-inject-inst ()
10050 "Inject AUTOINST into new code. See `verilog-inject-auto'."
10052 (goto-char (point-min))
10053 ;; It's hard to distinguish modules; we'll instead search for pins.
10054 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t)
10055 (verilog-backward-open-paren) ;; Inst start
10057 ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip.
10059 (verilog-forward-close-paren)) ;; Parameters done
10062 (let ((indent-pt (+ (current-column)))
10063 (end-pt (save-excursion (verilog-forward-close-paren) (point))))
10064 (cond ((verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
10065 (goto-char end-pt)) ;; Already there, continue search with next instance
10067 ;; Delete identical interconnect
10068 (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc
10069 (while (verilog-re-search-forward-quick "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
10070 (delete-region (match-beginning 0) (match-end 0))
10071 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct
10072 (while (or (looking-at "[ \t\n\f,]+")
10073 (looking-at "//[^\n]*"))
10074 (delete-region (match-beginning 0) (match-end 0))
10075 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
10076 (verilog-forward-close-paren)
10078 ;; Not verilog-re-search, as we don't want to strip comments
10079 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
10080 (delete-region (match-beginning 0) (match-end 0)))
10081 (verilog-insert "\n")
10082 (verilog-insert-indent "/*AUTOINST*/")))))))))
10088 (defun verilog-diff-buffers-p (b1 b2 &optional whitespace)
10089 "Return nil if buffers B1 and B2 have same contents.
10090 Else, return point in B1 that first mismatches.
10091 If optional WHITESPACE true, ignore whitespace."
10093 (let* ((case-fold-search nil) ;; compare-buffer-substrings cares
10094 (p1 (with-current-buffer b1 (goto-char (point-min))))
10095 (p2 (with-current-buffer b2 (goto-char (point-min))))
10096 (maxp1 (with-current-buffer b1 (point-max)))
10097 (maxp2 (with-current-buffer b2 (point-max)))
10100 (while (not (and (eq p1 op1) (eq p2 op2)))
10101 ;; If both windows have whitespace optionally skip over it.
10103 ;; skip-syntax-* doesn't count \n
10104 (with-current-buffer b1
10106 (skip-chars-forward " \t\n\r\f\v")
10108 (with-current-buffer b2
10110 (skip-chars-forward " \t\n\r\f\v")
10111 (setq p2 (point))))
10112 (setq size (min (- maxp1 p1) (- maxp2 p2)))
10113 (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
10114 b1 p1 (+ size p1)))
10115 (setq progress (if (zerop progress) size (1- (abs progress))))
10116 (setq op1 p1 op2 p2
10118 p2 (+ p2 progress)))
10120 (if (and (eq p1 maxp1) (eq p2 maxp2))
10123 (defun verilog-diff-file-with-buffer (f1 b2 &optional whitespace show)
10124 "View the differences between file F1 and buffer B2.
10125 This requires the external program `diff-command' to be in your `exec-path',
10126 and uses `diff-switches' in which you may want to have \"-u\" flag.
10127 Ignores WHITESPACE if t, and writes output to stdout if SHOW."
10128 ;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
10129 ;; call `diff' as `diff' has different calling semantics on different
10130 ;; versions of Emacs.
10131 (if (not (file-exists-p f1))
10132 (message "Buffer %s has no associated file on disc" (buffer-name b2))
10133 (with-temp-buffer "*Verilog-Diff*"
10134 (let ((outbuf (current-buffer))
10135 (f2 (make-temp-file "vm-diff-auto-")))
10138 (with-current-buffer b2
10141 (write-region (point-min) (point-max) f2 nil 'nomessage)))
10142 (call-process diff-command nil outbuf t
10143 diff-switches ;; User may want -u in diff-switches
10144 (if whitespace "-b" "")
10146 ;; Print out results. Alternatively we could have call-processed
10147 ;; ourself, but this way we can reuse diff switches
10149 (with-current-buffer outbuf (message "%s" (buffer-string))))))
10151 (when (file-exists-p f2)
10152 (delete-file f2))))))
10154 (defun verilog-diff-report (b1 b2 diffpt)
10155 "Report differences detected with `verilog-diff-auto'.
10156 Differences are between buffers B1 and B2, starting at point
10157 DIFFPT. This function is called via `verilog-diff-function'."
10158 (let ((name1 (with-current-buffer b1 (buffer-file-name))))
10159 (verilog-warn "%s:%d: Difference in AUTO expansion found"
10160 name1 (with-current-buffer b1
10161 (1+ (count-lines (point-min) (point)))))
10162 (cond (noninteractive
10163 (verilog-diff-file-with-buffer name1 b2 t t))
10165 (ediff-buffers b1 b2)))))
10167 (defun verilog-diff-auto ()
10168 "Expand AUTOs in a temporary buffer and indicate any change.
10169 Whitespace differences are ignored to determine identicalness, but
10170 once a difference is detected, whitespace differences may be shown.
10172 To call this from the command line, see \\[verilog-batch-diff-auto].
10174 The action on differences is selected with
10175 `verilog-diff-function'. The default is `verilog-diff-report'
10176 which will report an error and run `ediff' in interactive mode,
10177 or `diff' in batch mode."
10179 (let ((b1 (current-buffer)) b2 diffpt
10180 (name1 (buffer-file-name))
10181 (newname "*Verilog-Diff*"))
10183 (when (get-buffer newname)
10184 (kill-buffer newname))
10185 (setq b2 (let (buffer-file-name) ;; Else clone is upset
10186 (clone-buffer newname)))
10187 (with-current-buffer b2
10188 ;; auto requires the filename, but can't have same filename in two
10189 ;; buffers; so override both b1 and b2's names
10190 (let ((buffer-file-name name1))
10193 (with-current-buffer b1 (setq buffer-file-name nil))
10195 (when (not verilog-auto-star-save)
10196 (verilog-delete-auto-star-implicit)))
10197 ;; Restore name if unwind
10198 (with-current-buffer b1 (setq buffer-file-name name1)))))
10200 (setq diffpt (verilog-diff-buffers-p b1 b2 t))
10201 (cond ((not diffpt)
10202 (unless noninteractive (message "AUTO expansion identical"))
10203 (kill-buffer newname)) ;; Nice to cleanup after oneself
10205 (funcall verilog-diff-function b1 b2 diffpt)))
10206 ;; Return result of compare
10214 (defun verilog-auto-save-check ()
10215 "On saving see if we need auto update."
10216 (cond ((not verilog-auto-save-policy)) ; disabled
10217 ((not (save-excursion
10219 (let ((case-fold-search nil))
10220 (goto-char (point-min))
10221 (re-search-forward "AUTO" nil t))))))
10222 ((eq verilog-auto-save-policy 'force)
10224 ((not (buffer-modified-p)))
10225 ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
10226 ((eq verilog-auto-save-policy 'detect)
10229 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
10231 ;; Don't ask again if didn't update
10232 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
10233 (when (not verilog-auto-star-save)
10234 (verilog-delete-auto-star-implicit))
10235 nil) ;; Always return nil -- we don't write the file ourselves
10237 (defun verilog-auto-read-locals ()
10238 "Return file local variable segment at bottom of file."
10240 (goto-char (point-max))
10241 (if (re-search-backward "Local Variables:" nil t)
10242 (buffer-substring-no-properties (point) (point-max))
10245 (defun verilog-auto-reeval-locals (&optional force)
10246 "Read file local variable segment at bottom of file if it has changed.
10247 If FORCE, always reread it."
10248 (let ((curlocal (verilog-auto-read-locals)))
10249 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
10250 (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
10251 ;; Note this may cause this function to be recursively invoked,
10252 ;; because hack-local-variables may call (verilog-mode)
10253 ;; The above when statement will prevent it from recursing forever.
10254 (hack-local-variables)
10261 (defun verilog-auto-arg-ports (sigs message indent-pt)
10262 "Print a list of ports for an AUTOINST.
10263 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
10265 (when verilog-auto-arg-sort
10266 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
10268 (indent-to indent-pt)
10272 (indent-to indent-pt)
10274 (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
10276 (indent-to indent-pt))
10277 (t (insert space)))
10278 (insert (verilog-sig-name (car sigs)) ",")
10279 (setq sigs (cdr sigs)
10282 (defun verilog-auto-arg ()
10283 "Expand AUTOARG statements.
10284 Replace the argument declarations at the beginning of the
10285 module with ones automatically derived from input and output
10286 statements. This can be dangerous if the module is instantiated
10287 using position-based connections, so use only name-based when
10288 instantiating the resulting module. Long lines are split based
10289 on the `fill-column', see \\[set-fill-column].
10292 Concatenation and outputting partial buses is not supported.
10294 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10298 module ExampArg (/*AUTOARG*/);
10303 Typing \\[verilog-auto] will make this into:
10305 module ExampArg (/*AUTOARG*/
10315 The argument declarations may be printed in declaration order to best suit
10316 order based instantiations, or alphabetically, based on the
10317 `verilog-auto-arg-sort' variable.
10319 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
10320 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
10321 conservative guess on adding a comma for the first signal, if you have
10322 any ifdefs or complicated expressions before the AUTOARG you will need
10323 to choose the comma yourself.
10325 Avoid declaring ports manually, as it makes code harder to maintain."
10327 (let* ((modi (verilog-modi-current))
10328 (moddecls (verilog-modi-get-decls modi))
10329 (skip-pins (aref (verilog-read-arg-pins) 0)))
10330 (verilog-repair-open-comma)
10331 (verilog-auto-arg-ports (verilog-signals-not-in
10332 (verilog-decls-get-outputs moddecls)
10335 verilog-indent-level-declaration)
10336 (verilog-auto-arg-ports (verilog-signals-not-in
10337 (verilog-decls-get-inouts moddecls)
10340 verilog-indent-level-declaration)
10341 (verilog-auto-arg-ports (verilog-signals-not-in
10342 (verilog-decls-get-inputs moddecls)
10345 verilog-indent-level-declaration)
10346 (verilog-repair-close-comma)
10347 (unless (eq (char-before) ?/ )
10349 (indent-to verilog-indent-level-declaration))))
10351 (defun verilog-auto-inst-port-map (port-st)
10354 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
10355 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
10356 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
10357 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
10358 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
10359 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
10360 (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
10361 (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
10363 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
10364 "Print out an instantiation connection for this PORT-ST.
10365 Insert to INDENT-PT, use template TPL-LIST.
10366 @ are instantiation numbers, replaced with TPL-NUM.
10367 @\"(expression @)\" are evaluated, with @ as a variable.
10368 If FOR-STAR add comment it is a .* expansion.
10369 If PAR-VALUES replace final strings with these parameter values."
10370 (let* ((port (verilog-sig-name port-st))
10371 (tpl-ass (or (assoc port (car tpl-list))
10372 (verilog-auto-inst-port-map port-st)))
10373 ;; vl-* are documented for user use
10374 (vl-name (verilog-sig-name port-st))
10375 (vl-width (verilog-sig-width port-st))
10376 (vl-modport (verilog-sig-modport port-st))
10377 (vl-mbits (if (verilog-sig-multidim port-st)
10378 (verilog-sig-multidim-string port-st) ""))
10379 (vl-bits (if (or verilog-auto-inst-vector
10380 (not (assoc port vector-skip-list))
10381 (not (equal (verilog-sig-bits port-st)
10382 (verilog-sig-bits (assoc port vector-skip-list)))))
10383 (or (verilog-sig-bits port-st) "")
10385 (case-fold-search nil)
10386 (check-values par-values)
10388 ;; Replace parameters in bit-width
10389 (when (and check-values
10390 (not (equal vl-bits "")))
10391 (while check-values
10392 (setq vl-bits (verilog-string-replace-matches
10393 (concat "\\<" (nth 0 (car check-values)) "\\>")
10394 (concat "(" (nth 1 (car check-values)) ")")
10396 vl-mbits (verilog-string-replace-matches
10397 (concat "\\<" (nth 0 (car check-values)) "\\>")
10398 (concat "(" (nth 1 (car check-values)) ")")
10400 check-values (cdr check-values)))
10401 (setq vl-bits (verilog-simplify-range-expression vl-bits)
10402 vl-mbits (verilog-simplify-range-expression vl-mbits)
10403 vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
10404 ;; Default net value if not found
10405 (setq tpl-net (concat port
10406 (if vl-modport (concat "." vl-modport) "")
10407 (if (verilog-sig-multidim port-st)
10408 (concat "/*" vl-mbits vl-bits "*/")
10409 (concat vl-bits))))
10411 (cond (tpl-ass ; Template of exact port name
10412 (setq tpl-net (nth 1 tpl-ass)))
10413 ((nth 1 tpl-list) ; Wildcards in template, search them
10414 (let ((wildcards (nth 1 tpl-list)))
10416 (when (string-match (nth 0 (car wildcards)) port)
10417 (setq tpl-ass (car wildcards) ; so allow @ parsing
10418 tpl-net (replace-match (nth 1 (car wildcards))
10420 (setq wildcards (cdr wildcards))))))
10421 ;; Parse Templated variable
10423 ;; Evaluate @"(lispcode)"
10424 (when (string-match "@\".*[^\\]\"" tpl-net)
10425 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
10428 (substring tpl-net 0 (match-beginning 0))
10430 (let* ((expr (match-string 1 tpl-net))
10433 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
10434 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
10435 (prin1 (eval (car (read-from-string expr)))
10436 (lambda (ch) ())))))
10437 (if (numberp value) (setq value (number-to-string value)))
10439 (substring tpl-net (match-end 0))))))
10440 ;; Replace @ and [] magic variables in final output
10441 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
10442 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
10444 (indent-to indent-pt)
10446 (unless (and verilog-auto-inst-dot-name
10447 (equal port tpl-net))
10448 (indent-to verilog-auto-inst-column)
10449 (insert "(" tpl-net ")"))
10452 (verilog-read-auto-template-hit tpl-ass)
10453 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
10454 verilog-auto-inst-column))
10455 ;; verilog-insert requires the complete comment in one call - including the newline
10456 (cond ((equal verilog-auto-inst-template-numbers `lhs)
10457 (verilog-insert " // Templated"
10458 " LHS: " (nth 0 tpl-ass)
10460 (verilog-auto-inst-template-numbers
10461 (verilog-insert " // Templated"
10462 " T" (int-to-string (nth 2 tpl-ass))
10463 " L" (int-to-string (nth 3 tpl-ass))
10466 (verilog-insert " // Templated\n"))))
10468 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
10469 verilog-auto-inst-column))
10470 (verilog-insert " // Implicit .\*\n")) ;For some reason the . or * must be escaped...
10473 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
10474 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
10475 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
10477 (defun verilog-auto-inst-port-list (sig-list indent-pt tpl-list tpl-num for-star par-values)
10478 "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
10479 (when verilog-auto-inst-sort
10480 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)))
10481 (mapc (lambda (port)
10482 (verilog-auto-inst-port port indent-pt
10483 tpl-list tpl-num for-star par-values))
10486 (defun verilog-auto-inst-first ()
10487 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
10488 ;; Do we need a trailing comma?
10489 ;; There maybe an ifdef or something similar before us. What a mess. Thus
10490 ;; to avoid trouble we only insert on preceding ) or *.
10491 ;; Insert first port on new line
10492 (insert "\n") ;; Must insert before search, so point will move forward if insert comma
10494 (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
10495 (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure
10499 (defun verilog-auto-star ()
10500 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
10502 If `verilog-auto-star-expand' is set, .* pins are treated if they were
10503 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
10504 will also ignore any .* that are not last in your pin list (this prevents
10505 it from deleting pins following the .* when it expands the AUTOINST.)
10507 On writing your file, unless `verilog-auto-star-save' is set, any
10508 non-templated expanded pins will be removed. You may do this at any time
10509 with \\[verilog-delete-auto-star-implicit].
10511 If you are converting a module to use .* for the first time, you may wish
10512 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
10514 See `verilog-auto-inst' for examples, templates, and more information."
10515 (when (verilog-auto-star-safe)
10516 (verilog-auto-inst)))
10518 (defun verilog-auto-inst ()
10519 "Expand AUTOINST statements, as part of \\[verilog-auto].
10520 Replace the pin connections to an instantiation or interface
10521 declaration with ones automatically derived from the module or
10522 interface header of the instantiated item.
10524 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
10525 and delete them before saving unless `verilog-auto-star-save' is set.
10526 See `verilog-auto-star' for more information.
10528 The pins are printed in declaration order or alphabetically,
10529 based on the `verilog-auto-inst-sort' variable.
10532 Module names must be resolvable to filenames by adding a
10533 `verilog-library-extensions', and being found in the same directory, or
10534 by changing the variable `verilog-library-flags' or
10535 `verilog-library-directories'. Macros `modname are translated through the
10536 vh-{name} Emacs variable, if that is not found, it just ignores the `.
10538 In templates you must have one signal per line, ending in a ), or ));,
10539 and have proper () nesting, including a final ); to end the template.
10541 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10543 SystemVerilog multidimensional input/output has only experimental support.
10545 SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
10547 Parameters referenced by the instantiation will remain symbolic, unless
10548 `verilog-auto-inst-param-value' is set.
10550 Gate primitives (and/or) may have AUTOINST for the purpose of
10551 AUTOWIRE declarations, etc. Gates are the only case when
10552 position based connections are passed.
10554 For example, first take the submodule InstModule.v:
10556 module InstModule (o,i);
10559 wire [31:0] o = {32{i}};
10562 This is then used in an upper level module:
10564 module ExampInst (o,i);
10567 InstModule instName
10571 Typing \\[verilog-auto] will make this into:
10573 module ExampInst (o,i);
10576 InstModule instName
10584 Where the list of inputs and outputs came from the inst module.
10588 Unless you are instantiating a module multiple times, or the module is
10589 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
10590 It just makes for unmaintainable code. To sanitize signal names, try
10591 vrename from URL `http://www.veripool.org'.
10593 When you need to violate this suggestion there are two ways to list
10594 exceptions, placing them before the AUTOINST, or using templates.
10596 Any ports defined before the /*AUTOINST*/ are not included in the list of
10597 automatics. This is similar to making a template as described below, but
10598 is restricted to simple connections just like you normally make. Also note
10599 that any signals before the AUTOINST will only be picked up by AUTOWIRE if
10600 you have the appropriate // Input or // Output comment, and exactly the
10601 same line formatting as AUTOINST itself uses.
10603 InstModule instName
10605 .i (my_i_dont_mess_with_it),
10613 For multiple instantiations based upon a single template, create a
10614 commented out template:
10616 /* InstModule AUTO_TEMPLATE (
10621 Templates go ABOVE the instantiation(s). When an instantiation is
10622 expanded `verilog-mode' simply searches up for the closest template.
10623 Thus you can have multiple templates for the same module, just alternate
10624 between the template for an instantiation and the instantiation itself.
10625 (For backward compatibility if no template is found above, it
10626 will also look below, but do not use this behavior in new designs.)
10628 The module name must be the same as the name of the module in the
10629 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
10630 words and capitalized. Only signals that must be different for each
10631 instantiation need to be listed.
10633 Inside a template, a [] in a connection name (with nothing else inside
10634 the brackets) will be replaced by the same bus subscript as it is being
10635 connected to, or the [] will be removed if it is a single bit signal.
10636 Generally it is a good idea to do this for all connections in a template,
10637 as then they will work for any width signal, and with AUTOWIRE. See
10638 PTL_BUS becoming PTL_BUSNEW below.
10640 If you have a complicated template, set `verilog-auto-inst-template-numbers'
10641 to see which regexps are matching. Don't leave that mode set after
10642 debugging is completed though, it will result in lots of extra differences
10643 and merge conflicts.
10645 Setting `verilog-auto-template-warn-unused' will report errors
10646 if any template lines are unused.
10650 /* InstModule AUTO_TEMPLATE (
10651 .ptl_bus (ptl_busnew[]),
10654 InstModule ms2m (/*AUTOINST*/);
10656 Typing \\[verilog-auto] will make this into:
10658 InstModule ms2m (/*AUTOINST*/
10660 .NotInTemplate (NotInTemplate),
10661 .ptl_bus (ptl_busnew[3:0]), // Templated
10665 Multiple Module Templates:
10667 The same template lines can be applied to multiple modules with
10668 the syntax as follows:
10670 /* InstModuleA AUTO_TEMPLATE
10671 InstModuleB AUTO_TEMPLATE
10672 InstModuleC AUTO_TEMPLATE
10673 InstModuleD AUTO_TEMPLATE (
10674 .ptl_bus (ptl_busnew[]),
10678 Note there is only one AUTO_TEMPLATE opening parenthesis.
10682 It is common to instantiate a cell multiple times, so templates make it
10683 trivial to substitute part of the cell name into the connection name.
10685 /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
10687 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
10691 If no regular expression is provided immediately after the AUTO_TEMPLATE
10692 keyword, then the @ character in any connection names will be replaced
10693 with the instantiation number; the first digits found in the cell's
10694 instantiation name.
10696 If a regular expression is provided, the @ character will be replaced
10697 with the first \(\) grouping that matches against the cell name. Using a
10698 regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no
10699 regexp is provided. If you use multiple layers of parenthesis,
10700 \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number
10701 characters after test and before _, whereas
10702 \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire
10707 /* InstModule AUTO_TEMPLATE (
10708 .ptl_mapvalidx (ptl_mapvalid[@]),
10709 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
10712 InstModule ms2m (/*AUTOINST*/);
10714 Typing \\[verilog-auto] will make this into:
10716 InstModule ms2m (/*AUTOINST*/
10718 .ptl_mapvalidx (ptl_mapvalid[2]),
10719 .ptl_mapvalidp1x (ptl_mapvalid[3]));
10721 Note the @ character was replaced with the 2 from \"ms2m\".
10723 Alternatively, using a regular expression for @:
10725 /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
10726 .ptl_mapvalidx (@_ptl_mapvalid),
10727 .ptl_mapvalidp1x (ptl_mapvalid_@),
10730 InstModule ms2_FOO (/*AUTOINST*/);
10731 InstModule ms2_BAR (/*AUTOINST*/);
10733 Typing \\[verilog-auto] will make this into:
10735 InstModule ms2_FOO (/*AUTOINST*/
10737 .ptl_mapvalidx (FOO_ptl_mapvalid),
10738 .ptl_mapvalidp1x (ptl_mapvalid_FOO));
10739 InstModule ms2_BAR (/*AUTOINST*/
10741 .ptl_mapvalidx (BAR_ptl_mapvalid),
10742 .ptl_mapvalidp1x (ptl_mapvalid_BAR));
10747 A template entry of the form
10749 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
10751 will apply an Emacs style regular expression search for any port beginning
10752 in pci_req followed by numbers and ending in _l and connecting that to
10753 the pci_req_jtag_[] net, with the bus subscript coming from what matches
10754 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
10756 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
10757 does the same thing. (Note a @ in the connection/replacement text is
10758 completely different -- still use \\1 there!) Thus this is the same as
10759 the above template:
10761 .pci_req@_l (pci_req_jtag_[\\1]),
10763 Here's another example to remove the _l, useful when naming conventions
10764 specify _ alone to mean active low. Note the use of [] to keep the bus
10767 .\\(.*\\)_l (\\1_[]),
10771 First any regular expression template is expanded.
10773 If the syntax @\"( ... )\" is found in a connection, the expression in
10774 quotes will be evaluated as a Lisp expression, with @ replaced by the
10775 instantiation number. The MAPVALIDP1X example above would put @+1 modulo
10776 4 into the brackets. Quote all double-quotes inside the expression with
10777 a leading backslash (\\\"...\\\"); or if the Lisp template is also a
10778 regexp template backslash the backslash quote (\\\\\"...\\\\\").
10780 There are special variables defined that are useful in these
10783 vl-name Name portion of the input/output port.
10784 vl-bits Bus bits portion of the input/output port ('[2:0]').
10785 vl-mbits Multidimensional array bits for port ('[2:0][3:0]').
10786 vl-width Width of the input/output port ('3' for [2:0]).
10787 May be a (...) expression if bits isn't a constant.
10788 vl-dir Direction of the pin input/output/inout/interface.
10789 vl-modport The modport, if an interface with a modport.
10790 vl-cell-type Module name/type of the cell ('InstModule').
10791 vl-cell-name Instance name of the cell ('instName').
10793 Normal Lisp variables may be used in expressions. See
10794 `verilog-read-defines' which can set vh-{definename} variables for use
10795 here. Also, any comments of the form:
10797 /*AUTO_LISP(setq foo 1)*/
10799 will evaluate any Lisp expression inside the parenthesis between the
10800 beginning of the buffer and the point of the AUTOINST. This allows
10801 functions to be defined or variables to be changed between instantiations.
10802 (See also `verilog-auto-insert-lisp' if you want the output from your
10803 lisp function to be inserted.)
10805 Note that when using lisp expressions errors may occur when @ is not a
10806 number; you may need to use the standard Emacs Lisp functions
10807 `number-to-string' and `string-to-number'.
10809 After the evaluation is completed, @ substitution and [] substitution
10812 For more information see the \\[verilog-faq] and forums at URL
10813 `http://www.veripool.org'."
10816 (let* ((pt (point))
10817 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
10818 (indent-pt (save-excursion (verilog-backward-open-paren)
10819 (1+ (current-column))))
10820 (verilog-auto-inst-column (max verilog-auto-inst-column
10821 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
10822 (modi (verilog-modi-current))
10823 (moddecls (verilog-modi-get-decls modi))
10824 (vector-skip-list (unless verilog-auto-inst-vector
10825 (verilog-decls-get-signals moddecls)))
10826 submod submodi submoddecls
10827 inst skip-pins tpl-list tpl-num did-first par-values)
10829 ;; Find module name that is instantiated
10830 (setq submod (verilog-read-inst-module)
10831 inst (verilog-read-inst-name)
10832 vl-cell-type submod
10834 skip-pins (aref (verilog-read-inst-pins) 0))
10836 ;; Parse any AUTO_LISP() before here
10837 (verilog-read-auto-lisp (point-min) pt)
10839 ;; Read parameters (after AUTO_LISP)
10840 (setq par-values (and verilog-auto-inst-param-value
10841 (verilog-read-inst-param-value)))
10843 ;; Lookup position, etc of submodule
10844 ;; Note this may raise an error
10845 (when (and (not (member submod verilog-gate-keywords))
10846 (setq submodi (verilog-modi-lookup submod t)))
10847 (setq submoddecls (verilog-modi-get-decls submodi))
10848 ;; If there's a number in the instantiation, it may be an argument to the
10849 ;; automatic variable instantiation program.
10850 (let* ((tpl-info (verilog-read-auto-template submod))
10851 (tpl-regexp (aref tpl-info 0)))
10852 (setq tpl-num (if (string-match tpl-regexp inst)
10853 (match-string 1 inst)
10855 tpl-list (aref tpl-info 1)))
10856 ;; Find submodule's signals and dump
10857 (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
10858 (verilog-signals-not-in
10859 (verilog-decls-get-vars submoddecls)
10861 (vl-dir "interfaced"))
10862 (when (and sig-list
10863 verilog-auto-inst-interfaced-ports)
10864 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
10865 ;; Note these are searched for in verilog-read-sub-decls.
10866 (verilog-insert-indent "// Interfaced\n")
10867 (verilog-auto-inst-port-list sig-list indent-pt
10868 tpl-list tpl-num for-star par-values)))
10869 (let ((sig-list (verilog-signals-not-in
10870 (verilog-decls-get-interfaces submoddecls)
10872 (vl-dir "interface"))
10874 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
10875 ;; Note these are searched for in verilog-read-sub-decls.
10876 (verilog-insert-indent "// Interfaces\n")
10877 (verilog-auto-inst-port-list sig-list indent-pt
10878 tpl-list tpl-num for-star par-values)))
10879 (let ((sig-list (verilog-signals-not-in
10880 (verilog-decls-get-outputs submoddecls)
10884 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
10885 (verilog-insert-indent "// Outputs\n")
10886 (verilog-auto-inst-port-list sig-list indent-pt
10887 tpl-list tpl-num for-star par-values)))
10888 (let ((sig-list (verilog-signals-not-in
10889 (verilog-decls-get-inouts submoddecls)
10893 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
10894 (verilog-insert-indent "// Inouts\n")
10895 (verilog-auto-inst-port-list sig-list indent-pt
10896 tpl-list tpl-num for-star par-values)))
10897 (let ((sig-list (verilog-signals-not-in
10898 (verilog-decls-get-inputs submoddecls)
10902 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
10903 (verilog-insert-indent "// Inputs\n")
10904 (verilog-auto-inst-port-list sig-list indent-pt
10905 tpl-list tpl-num for-star par-values)))
10909 (re-search-backward "," pt t)
10912 (search-forward "\n") ;; Added by inst-port
10914 (if (search-forward ")" nil t) ;; From user, moved up a line
10916 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it
10917 (delete-char -1)))))))))
10919 (defun verilog-auto-inst-param ()
10920 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
10921 Replace the parameter connections to an instantiation with ones
10922 automatically derived from the module header of the instantiated netlist.
10924 See \\[verilog-auto-inst] for limitations, and templates to customize the
10927 For example, first take the submodule InstModule.v:
10929 module InstModule (o,i);
10933 This is then used in an upper level module:
10935 module ExampInst (o,i);
10937 InstModule #(/*AUTOINSTPARAM*/)
10938 instName (/*AUTOINST*/);
10941 Typing \\[verilog-auto] will make this into:
10943 module ExampInst (o,i);
10946 InstModule #(/*AUTOINSTPARAM*/
10949 instName (/*AUTOINST*/);
10952 Where the list of parameter connections come from the inst module.
10956 You can customize the parameter connections using AUTO_TEMPLATEs,
10957 just as you would with \\[verilog-auto-inst]."
10960 (let* ((pt (point))
10961 (indent-pt (save-excursion (verilog-backward-open-paren)
10962 (1+ (current-column))))
10963 (verilog-auto-inst-column (max verilog-auto-inst-column
10964 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
10965 (modi (verilog-modi-current))
10966 (moddecls (verilog-modi-get-decls modi))
10967 (vector-skip-list (unless verilog-auto-inst-vector
10968 (verilog-decls-get-signals moddecls)))
10969 submod submodi submoddecls
10970 inst skip-pins tpl-list tpl-num did-first)
10971 ;; Find module name that is instantiated
10972 (setq submod (save-excursion
10973 ;; Get to the point where AUTOINST normally is to read the module
10974 (verilog-re-search-forward-quick "[(;]" nil nil)
10975 (verilog-read-inst-module))
10976 inst (save-excursion
10977 ;; Get to the point where AUTOINST normally is to read the module
10978 (verilog-re-search-forward-quick "[(;]" nil nil)
10979 (verilog-read-inst-name))
10980 vl-cell-type submod
10982 skip-pins (aref (verilog-read-inst-pins) 0))
10984 ;; Parse any AUTO_LISP() before here
10985 (verilog-read-auto-lisp (point-min) pt)
10987 ;; Lookup position, etc of submodule
10988 ;; Note this may raise an error
10989 (when (setq submodi (verilog-modi-lookup submod t))
10990 (setq submoddecls (verilog-modi-get-decls submodi))
10991 ;; If there's a number in the instantiation, it may be an argument to the
10992 ;; automatic variable instantiation program.
10993 (let* ((tpl-info (verilog-read-auto-template submod))
10994 (tpl-regexp (aref tpl-info 0)))
10995 (setq tpl-num (if (string-match tpl-regexp inst)
10996 (match-string 1 inst)
10998 tpl-list (aref tpl-info 1)))
10999 ;; Find submodule's signals and dump
11000 (let ((sig-list (verilog-signals-not-in
11001 (verilog-decls-get-gparams submoddecls)
11003 (vl-dir "parameter"))
11005 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11006 ;; Note these are searched for in verilog-read-sub-decls.
11007 (verilog-insert-indent "// Parameters\n")
11008 (verilog-auto-inst-port-list sig-list indent-pt
11009 tpl-list tpl-num nil nil)))
11013 (re-search-backward "," pt t)
11016 (search-forward "\n") ;; Added by inst-port
11018 (if (search-forward ")" nil t) ;; From user, moved up a line
11019 (delete-char -1)))))))))
11021 (defun verilog-auto-reg ()
11022 "Expand AUTOREG statements, as part of \\[verilog-auto].
11023 Make reg statements for any output that isn't already declared,
11024 and isn't a wire output from a block. `verilog-auto-wire-type'
11025 may be used to change the datatype of the declarations.
11028 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11030 This does NOT work on memories, declare those yourself.
11034 module ExampReg (o,i);
11041 Typing \\[verilog-auto] will make this into:
11043 module ExampReg (o,i);
11047 // Beginning of automatic regs (for this module's undeclared outputs)
11049 // End of automatics
11053 ;; Point must be at insertion point.
11054 (let* ((indent-pt (current-indentation))
11055 (modi (verilog-modi-current))
11056 (moddecls (verilog-modi-get-decls modi))
11057 (modsubdecls (verilog-modi-get-sub-decls modi))
11058 (sig-list (verilog-signals-not-in
11059 (verilog-decls-get-outputs moddecls)
11060 (append (verilog-signals-with ;; ignore typed signals
11062 (verilog-decls-get-outputs moddecls))
11063 (verilog-decls-get-vars moddecls)
11064 (verilog-decls-get-assigns moddecls)
11065 (verilog-decls-get-consts moddecls)
11066 (verilog-decls-get-gparams moddecls)
11067 (verilog-subdecls-get-interfaced modsubdecls)
11068 (verilog-subdecls-get-outputs modsubdecls)
11069 (verilog-subdecls-get-inouts modsubdecls)))))
11072 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
11073 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
11074 (verilog-insert-indent "// End of automatics\n")))))
11076 (defun verilog-auto-reg-input ()
11077 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
11078 Make reg statements instantiation inputs that aren't already declared.
11079 This is useful for making a top level shell for testing the module that is
11080 to be instantiated.
11083 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
11085 This does NOT work on memories, declare those yourself.
11087 An example (see `verilog-auto-inst' for what else is going on here):
11089 module ExampRegInput (o,i);
11093 InstModule instName
11097 Typing \\[verilog-auto] will make this into:
11099 module ExampRegInput (o,i);
11103 // Beginning of automatic reg inputs (for undeclared ...
11104 reg [31:0] iv; // From inst of inst.v
11105 // End of automatics
11106 InstModule instName
11114 ;; Point must be at insertion point.
11115 (let* ((indent-pt (current-indentation))
11116 (modi (verilog-modi-current))
11117 (moddecls (verilog-modi-get-decls modi))
11118 (modsubdecls (verilog-modi-get-sub-decls modi))
11119 (sig-list (verilog-signals-combine-bus
11120 (verilog-signals-not-in
11121 (append (verilog-subdecls-get-inputs modsubdecls)
11122 (verilog-subdecls-get-inouts modsubdecls))
11123 (append (verilog-decls-get-signals moddecls)
11124 (verilog-decls-get-assigns moddecls))))))
11127 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
11128 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
11129 (verilog-insert-indent "// End of automatics\n")))))
11131 (defun verilog-auto-logic-setup ()
11132 "Prepare variables due to AUTOLOGIC."
11133 (unless verilog-auto-wire-type
11134 (set (make-local-variable 'verilog-auto-wire-type)
11137 (defun verilog-auto-logic ()
11138 "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
11139 Make wire statements using the SystemVerilog logic keyword.
11140 This is currently equivalent to:
11144 with the below at the bottom of the file
11146 // Local Variables:
11147 // verilog-auto-logic-type:\"logic\"
11150 In the future AUTOLOGIC may declare additional identifiers,
11151 while AUTOWIRE will not."
11153 (verilog-auto-logic-setup)
11154 (verilog-auto-wire)))
11156 (defun verilog-auto-wire ()
11157 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
11158 Make wire statements for instantiations outputs that aren't
11159 already declared. `verilog-auto-wire-type' may be used to change
11160 the datatype of the declarations.
11163 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
11164 and all buses must have widths, such as those from AUTOINST, or using []
11167 This does NOT work on memories or SystemVerilog .name connections,
11168 declare those yourself.
11170 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
11171 determine how to bus together. This occurs when you have ports with
11172 non-numeric or non-sequential bus subscripts. If Verilog mode
11173 mis-guessed, you'll have to declare them yourself.
11175 An example (see `verilog-auto-inst' for what else is going on here):
11177 module ExampWire (o,i);
11181 InstModule instName
11185 Typing \\[verilog-auto] will make this into:
11187 module ExampWire (o,i);
11191 // Beginning of automatic wires
11192 wire [31:0] ov; // From inst of inst.v
11193 // End of automatics
11194 InstModule instName
11203 ;; Point must be at insertion point.
11204 (let* ((indent-pt (current-indentation))
11205 (modi (verilog-modi-current))
11206 (moddecls (verilog-modi-get-decls modi))
11207 (modsubdecls (verilog-modi-get-sub-decls modi))
11208 (sig-list (verilog-signals-combine-bus
11209 (verilog-signals-not-in
11210 (append (verilog-subdecls-get-outputs modsubdecls)
11211 (verilog-subdecls-get-inouts modsubdecls))
11212 (verilog-decls-get-signals moddecls)))))
11215 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
11216 (verilog-insert-definition modi sig-list "wire" indent-pt nil)
11217 (verilog-insert-indent "// End of automatics\n")
11218 ;; We used to optionally call verilog-pretty-declarations and
11219 ;; verilog-pretty-expr here, but it's too slow on huge modules,
11220 ;; plus makes everyone's module change. Finally those call
11221 ;; syntax-ppss which is broken when change hooks are disabled.
11224 (defun verilog-auto-output (&optional with-params)
11225 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
11226 Make output statements for any output signal from an /*AUTOINST*/ that
11227 isn't an input to another AUTOINST. This is useful for modules which
11228 only instantiate other modules.
11231 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11233 If placed inside the parenthesis of a module declaration, it creates
11234 Verilog 2001 style, else uses Verilog 1995 style.
11236 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11237 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11239 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11241 Signals matching `verilog-auto-output-ignore-regexp' are not included.
11243 An example (see `verilog-auto-inst' for what else is going on here):
11245 module ExampOutput (ov,i);
11248 InstModule instName
11252 Typing \\[verilog-auto] will make this into:
11254 module ExampOutput (ov,i);
11257 // Beginning of automatic outputs (from unused autoinst outputs)
11258 output [31:0] ov; // From inst of inst.v
11259 // End of automatics
11260 InstModule instName
11268 You may also provide an optional regular expression, in which case only
11269 signals matching the regular expression will be included. For example the
11270 same expansion will result from only extracting outputs starting with ov:
11272 /*AUTOOUTPUT(\"^ov\")*/"
11274 ;; Point must be at insertion point.
11275 (let* ((indent-pt (current-indentation))
11276 (regexp (and with-params
11277 (nth 0 (verilog-read-auto-params 1))))
11278 (v2k (verilog-in-paren-quick))
11279 (modi (verilog-modi-current))
11280 (moddecls (verilog-modi-get-decls modi))
11281 (modsubdecls (verilog-modi-get-sub-decls modi))
11282 (sig-list (verilog-signals-not-in
11283 (verilog-subdecls-get-outputs modsubdecls)
11284 (append (verilog-decls-get-outputs moddecls)
11285 (verilog-decls-get-inouts moddecls)
11286 (verilog-subdecls-get-inputs modsubdecls)
11287 (verilog-subdecls-get-inouts modsubdecls)))))
11289 (setq sig-list (verilog-signals-matching-regexp
11291 (setq sig-list (verilog-signals-not-matching-regexp
11292 sig-list verilog-auto-output-ignore-regexp))
11294 (when v2k (verilog-repair-open-comma))
11296 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
11297 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
11298 (verilog-insert-indent "// End of automatics\n"))
11299 (when v2k (verilog-repair-close-comma)))))
11301 (defun verilog-auto-output-every ()
11302 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
11303 Make output statements for any signals that aren't primary inputs or
11304 outputs already. This makes every signal in the design an output. This is
11305 useful to get Synopsys to preserve every signal in the design, since it
11306 won't optimize away the outputs.
11310 module ExampOutputEvery (o,i,tempa,tempb);
11313 /*AUTOOUTPUTEVERY*/
11315 wire tempb = tempa;
11319 Typing \\[verilog-auto] will make this into:
11321 module ExampOutputEvery (o,i,tempa,tempb);
11324 /*AUTOOUTPUTEVERY*/
11325 // Beginning of automatic outputs (every signal)
11328 // End of automatics
11330 wire tempb = tempa;
11334 ;;Point must be at insertion point
11335 (let* ((indent-pt (current-indentation))
11336 (v2k (verilog-in-paren-quick))
11337 (modi (verilog-modi-current))
11338 (moddecls (verilog-modi-get-decls modi))
11339 (sig-list (verilog-signals-combine-bus
11340 (verilog-signals-not-in
11341 (verilog-decls-get-signals moddecls)
11342 (verilog-decls-get-ports moddecls)))))
11344 (when v2k (verilog-repair-open-comma))
11346 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
11347 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
11348 (verilog-insert-indent "// End of automatics\n"))
11349 (when v2k (verilog-repair-close-comma)))))
11351 (defun verilog-auto-input (&optional with-params)
11352 "Expand AUTOINPUT statements, as part of \\[verilog-auto].
11353 Make input statements for any input signal into an /*AUTOINST*/ that
11354 isn't declared elsewhere inside the module. This is useful for modules which
11355 only instantiate other modules.
11358 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11360 If placed inside the parenthesis of a module declaration, it creates
11361 Verilog 2001 style, else uses Verilog 1995 style.
11363 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11364 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11366 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11368 Signals matching `verilog-auto-input-ignore-regexp' are not included.
11370 An example (see `verilog-auto-inst' for what else is going on here):
11372 module ExampInput (ov,i);
11375 InstModule instName
11379 Typing \\[verilog-auto] will make this into:
11381 module ExampInput (ov,i);
11384 // Beginning of automatic inputs (from unused autoinst inputs)
11385 input i; // From inst of inst.v
11386 // End of automatics
11387 InstModule instName
11395 You may also provide an optional regular expression, in which case only
11396 signals matching the regular expression will be included. For example the
11397 same expansion will result from only extracting inputs starting with i:
11399 /*AUTOINPUT(\"^i\")*/"
11401 (let* ((indent-pt (current-indentation))
11402 (regexp (and with-params
11403 (nth 0 (verilog-read-auto-params 1))))
11404 (v2k (verilog-in-paren-quick))
11405 (modi (verilog-modi-current))
11406 (moddecls (verilog-modi-get-decls modi))
11407 (modsubdecls (verilog-modi-get-sub-decls modi))
11408 (sig-list (verilog-signals-not-in
11409 (verilog-subdecls-get-inputs modsubdecls)
11410 (append (verilog-decls-get-inputs moddecls)
11411 (verilog-decls-get-inouts moddecls)
11412 (verilog-decls-get-vars moddecls)
11413 (verilog-decls-get-consts moddecls)
11414 (verilog-decls-get-gparams moddecls)
11415 (verilog-subdecls-get-interfaced modsubdecls)
11416 (verilog-subdecls-get-outputs modsubdecls)
11417 (verilog-subdecls-get-inouts modsubdecls)))))
11419 (setq sig-list (verilog-signals-matching-regexp
11421 (setq sig-list (verilog-signals-not-matching-regexp
11422 sig-list verilog-auto-input-ignore-regexp))
11424 (when v2k (verilog-repair-open-comma))
11426 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
11427 (verilog-insert-definition modi sig-list "input" indent-pt v2k)
11428 (verilog-insert-indent "// End of automatics\n"))
11429 (when v2k (verilog-repair-close-comma)))))
11431 (defun verilog-auto-inout (&optional with-params)
11432 "Expand AUTOINOUT statements, as part of \\[verilog-auto].
11433 Make inout statements for any inout signal in an /*AUTOINST*/ that
11434 isn't declared elsewhere inside the module.
11437 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11439 If placed inside the parenthesis of a module declaration, it creates
11440 Verilog 2001 style, else uses Verilog 1995 style.
11442 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11443 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11445 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11447 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
11449 An example (see `verilog-auto-inst' for what else is going on here):
11451 module ExampInout (ov,i);
11454 InstModule instName
11458 Typing \\[verilog-auto] will make this into:
11460 module ExampInout (ov,i);
11463 // Beginning of automatic inouts (from unused autoinst inouts)
11464 inout [31:0] ov; // From inst of inst.v
11465 // End of automatics
11466 InstModule instName
11474 You may also provide an optional regular expression, in which case only
11475 signals matching the regular expression will be included. For example the
11476 same expansion will result from only extracting inouts starting with i:
11478 /*AUTOINOUT(\"^i\")*/"
11480 ;; Point must be at insertion point.
11481 (let* ((indent-pt (current-indentation))
11482 (regexp (and with-params
11483 (nth 0 (verilog-read-auto-params 1))))
11484 (v2k (verilog-in-paren-quick))
11485 (modi (verilog-modi-current))
11486 (moddecls (verilog-modi-get-decls modi))
11487 (modsubdecls (verilog-modi-get-sub-decls modi))
11488 (sig-list (verilog-signals-not-in
11489 (verilog-subdecls-get-inouts modsubdecls)
11490 (append (verilog-decls-get-outputs moddecls)
11491 (verilog-decls-get-inouts moddecls)
11492 (verilog-decls-get-inputs moddecls)
11493 (verilog-subdecls-get-inputs modsubdecls)
11494 (verilog-subdecls-get-outputs modsubdecls)))))
11496 (setq sig-list (verilog-signals-matching-regexp
11498 (setq sig-list (verilog-signals-not-matching-regexp
11499 sig-list verilog-auto-inout-ignore-regexp))
11501 (when v2k (verilog-repair-open-comma))
11503 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
11504 (verilog-insert-definition modi sig-list "inout" indent-pt v2k)
11505 (verilog-insert-indent "// End of automatics\n"))
11506 (when v2k (verilog-repair-close-comma)))))
11508 (defun verilog-auto-inout-module (&optional complement all-in)
11509 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
11510 Take input/output/inout statements from the specified module and insert
11511 into the current module. This is useful for making null templates and
11512 shell modules which need to have identical I/O with another module.
11513 Any I/O which are already defined in this module will not be redefined.
11514 For the complement of this function, see `verilog-auto-inout-comp',
11515 and to make monitors with all inputs, see `verilog-auto-inout-in'.
11518 If placed inside the parenthesis of a module declaration, it creates
11519 Verilog 2001 style, else uses Verilog 1995 style.
11521 Concatenation and outputting partial buses is not supported.
11523 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11525 Signals are not inserted in the same order as in the original module,
11526 though they will appear to be in the same order to an AUTOINST
11527 instantiating either module.
11529 Signals declared as \"output reg\" or \"output wire\" etc will
11530 lose the wire/reg declaration so that shell modules may
11531 generate those outputs differently. However, \"output logic\"
11536 module ExampShell (/*AUTOARG*/);
11537 /*AUTOINOUTMODULE(\"ExampMain\")*/
11540 module ExampMain (i,o,io);
11546 Typing \\[verilog-auto] will make this into:
11548 module ExampShell (/*AUTOARG*/i,o,io);
11549 /*AUTOINOUTMODULE(\"ExampMain\")*/
11550 // Beginning of automatic in/out/inouts (from specific module)
11554 // End of automatics
11557 You may also provide an optional regular expression, in which case only
11558 signals matching the regular expression will be included. For example the
11559 same expansion will result from only extracting signals starting with i:
11561 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
11563 You may also provide an optional second regular expression, in
11564 which case only signals which have that pin direction and data
11565 type will be included. This matches against everything before
11566 the signal name in the declaration, for example against
11567 \"input\" (single bit), \"output logic\" (direction and type) or
11568 \"output [1:0]\" (direction and implicit type). You also
11569 probably want to skip spaces in your regexp.
11571 For example, the below will result in matching the output \"o\"
11572 against the previous example's module:
11574 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/"
11576 (let* ((params (verilog-read-auto-params 1 3))
11577 (submod (nth 0 params))
11578 (regexp (nth 1 params))
11579 (direction-re (nth 2 params))
11581 ;; Lookup position, etc of co-module
11582 ;; Note this may raise an error
11583 (when (setq submodi (verilog-modi-lookup submod t))
11584 (let* ((indent-pt (current-indentation))
11585 (v2k (verilog-in-paren-quick))
11586 (modi (verilog-modi-current))
11587 (moddecls (verilog-modi-get-decls modi))
11588 (submoddecls (verilog-modi-get-decls submodi))
11589 (sig-list-i (verilog-signals-not-in
11592 (verilog-decls-get-inputs submoddecls)
11593 (verilog-decls-get-inouts submoddecls)
11594 (verilog-decls-get-outputs submoddecls)))
11596 (verilog-decls-get-outputs submoddecls))
11597 (t (verilog-decls-get-inputs submoddecls)))
11598 (append (verilog-decls-get-inputs moddecls))))
11599 (sig-list-o (verilog-signals-not-in
11602 (verilog-decls-get-inputs submoddecls))
11603 (t (verilog-decls-get-outputs submoddecls)))
11604 (append (verilog-decls-get-outputs moddecls))))
11605 (sig-list-io (verilog-signals-not-in
11607 (t (verilog-decls-get-inouts submoddecls)))
11608 (append (verilog-decls-get-inouts moddecls))))
11609 (sig-list-if (verilog-signals-not-in
11610 (verilog-decls-get-interfaces submoddecls)
11611 (append (verilog-decls-get-interfaces moddecls)))))
11613 (setq sig-list-i (verilog-signals-edit-wire-reg
11614 (verilog-signals-matching-dir-re
11615 (verilog-signals-matching-regexp sig-list-i regexp)
11616 "input" direction-re))
11617 sig-list-o (verilog-signals-edit-wire-reg
11618 (verilog-signals-matching-dir-re
11619 (verilog-signals-matching-regexp sig-list-o regexp)
11620 "output" direction-re))
11621 sig-list-io (verilog-signals-edit-wire-reg
11622 (verilog-signals-matching-dir-re
11623 (verilog-signals-matching-regexp sig-list-io regexp)
11624 "inout" direction-re))
11625 sig-list-if (verilog-signals-matching-dir-re
11626 (verilog-signals-matching-regexp sig-list-if regexp)
11627 "interface" direction-re))
11628 (when v2k (verilog-repair-open-comma))
11629 (when (or sig-list-i sig-list-o sig-list-io)
11630 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
11631 ;; Don't sort them so an upper AUTOINST will match the main module
11632 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
11633 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
11634 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
11635 (verilog-insert-definition modi sig-list-if "interface" indent-pt v2k t)
11636 (verilog-insert-indent "// End of automatics\n"))
11637 (when v2k (verilog-repair-close-comma)))))))
11639 (defun verilog-auto-inout-comp ()
11640 "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
11641 Take input/output/inout statements from the specified module and
11642 insert the inverse into the current module (inputs become outputs
11643 and vice-versa.) This is useful for making test and stimulus
11644 modules which need to have complementing I/O with another module.
11645 Any I/O which are already defined in this module will not be
11646 redefined. For the complement of this function, see
11647 `verilog-auto-inout-module'.
11650 If placed inside the parenthesis of a module declaration, it creates
11651 Verilog 2001 style, else uses Verilog 1995 style.
11653 Concatenation and outputting partial buses is not supported.
11655 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11657 Signals are not inserted in the same order as in the original module,
11658 though they will appear to be in the same order to an AUTOINST
11659 instantiating either module.
11663 module ExampShell (/*AUTOARG*/);
11664 /*AUTOINOUTCOMP(\"ExampMain\")*/
11667 module ExampMain (i,o,io);
11673 Typing \\[verilog-auto] will make this into:
11675 module ExampShell (/*AUTOARG*/i,o,io);
11676 /*AUTOINOUTCOMP(\"ExampMain\")*/
11677 // Beginning of automatic in/out/inouts (from specific module)
11681 // End of automatics
11684 You may also provide an optional regular expression, in which case only
11685 signals matching the regular expression will be included. For example the
11686 same expansion will result from only extracting signals starting with i:
11688 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
11689 (verilog-auto-inout-module t nil))
11691 (defun verilog-auto-inout-in ()
11692 "Expand AUTOINOUTIN statements, as part of \\[verilog-auto].
11693 Take input/output/inout statements from the specified module and
11694 insert them as all inputs into the current module. This is
11695 useful for making monitor modules which need to see all signals
11696 as inputs based on another module. Any I/O which are already
11697 defined in this module will not be redefined. See also
11698 `verilog-auto-inout-module'.
11701 If placed inside the parenthesis of a module declaration, it creates
11702 Verilog 2001 style, else uses Verilog 1995 style.
11704 Concatenation and outputting partial buses is not supported.
11706 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11708 Signals are not inserted in the same order as in the original module,
11709 though they will appear to be in the same order to an AUTOINST
11710 instantiating either module.
11714 module ExampShell (/*AUTOARG*/);
11715 /*AUTOINOUTIN(\"ExampMain\")*/
11718 module ExampMain (i,o,io);
11724 Typing \\[verilog-auto] will make this into:
11726 module ExampShell (/*AUTOARG*/i,o,io);
11727 /*AUTOINOUTIN(\"ExampMain\")*/
11728 // Beginning of automatic in/out/inouts (from specific module)
11732 // End of automatics
11735 You may also provide an optional regular expression, in which case only
11736 signals matching the regular expression will be included. For example the
11737 same expansion will result from only extracting signals starting with i:
11739 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
11740 (verilog-auto-inout-module nil t))
11742 (defun verilog-auto-insert-lisp ()
11743 "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
11744 The Lisp code provided is called, and the Lisp code calls
11745 `insert` to insert text into the current file beginning on the
11746 line after the AUTOINSERTLISP.
11748 See also AUTO_LISP, which takes a Lisp expression and evaluates
11749 it during `verilog-auto-inst' but does not insert any text.
11753 module ExampInsertLisp;
11754 /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
11757 // For this example we declare the function in the
11758 // module's file itself. Often you'd define it instead
11759 // in a site-start.el or .emacs file.
11763 (defun my-verilog-insert-hello (who)
11764 (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
11768 Typing \\[verilog-auto] will call my-verilog-insert-hello and
11769 expand the above into:
11771 // Beginning of automatic insert lisp
11772 initial $write(\"hello world\");
11773 // End of automatics
11775 You can also call an external program and insert the returned
11778 /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
11779 // Beginning of automatic insert lisp
11781 // End of automatics"
11783 ;; Point is at end of /*AUTO...*/
11784 (let* ((indent-pt (current-indentation))
11785 (cmd-end-pt (save-excursion (search-backward ")")
11787 (point))) ;; Closing paren
11788 (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
11789 (backward-sexp 1) ;; Inside comment
11790 (point))) ;; Beginning paren
11791 (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
11793 ;; Some commands don't move point (like insert-file) so we always
11794 ;; add the begin/end comments, then delete it if not needed
11795 (verilog-insert-indent "// Beginning of automatic insert lisp\n")
11796 (verilog-insert-indent "// End of automatics\n")
11800 (setq verilog-scan-cache-tick nil) ;; Clear cache; inserted unknown text
11801 (verilog-delete-empty-auto-pair))))
11803 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
11804 "Return list of signals for current AUTOSENSE block."
11805 (let* ((sigss (verilog-read-always-signals))
11806 (sig-list (verilog-signals-not-params
11807 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
11808 (append (and (not verilog-auto-sense-include-inputs)
11809 (verilog-alw-get-outputs-delayed sigss))
11810 (and (not verilog-auto-sense-include-inputs)
11811 (verilog-alw-get-outputs-immediate sigss))
11812 (verilog-alw-get-temps sigss)
11813 (verilog-decls-get-consts moddecls)
11814 (verilog-decls-get-gparams moddecls)
11818 (defun verilog-auto-sense ()
11819 "Expand AUTOSENSE statements, as part of \\[verilog-auto].
11820 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
11821 with one automatically derived from all inputs declared in the always
11822 statement. Signals that are generated within the same always block are NOT
11823 placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
11824 Long lines are split based on the `fill-column', see \\[set-fill-column].
11827 Verilog does not allow memories (multidimensional arrays) in sensitivity
11828 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
11831 AUTOSENSE cannot always determine if a `define is a constant or a signal
11832 (it could be in an include file for example). If a `define or other signal
11833 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
11834 declaration anywhere in the module (parenthesis are required):
11836 /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */
11838 Better yet, use a parameter, which will be understood to be constant
11842 If AUTOSENSE makes a mistake, please report it. (First try putting
11843 a begin/end after your always!) As a workaround, if a signal that
11844 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
11845 If a signal should be in the sensitivity list wasn't, placing it before
11846 the /*AUTOSENSE*/ comment will prevent it from being deleted when the
11847 autos are updated (or added if it occurs there already).
11851 always @ (/*AS*/) begin
11852 /* AUTO_CONSTANT (`constant) */
11853 outin = ina | inb | `constant;
11857 Typing \\[verilog-auto] will make this into:
11859 always @ (/*AS*/ina or inb) begin
11860 /* AUTO_CONSTANT (`constant) */
11861 outin = ina | inb | `constant;
11865 Note in Verilog 2001, you can often get the same result from the new @*
11866 operator. (This was added to the language in part due to AUTOSENSE!)
11869 outin = ina | inb | `constant;
11874 (let* ((start-pt (save-excursion
11875 (verilog-re-search-backward-quick "(" nil t)
11877 (indent-pt (save-excursion
11878 (or (and (goto-char start-pt) (1+ (current-column)))
11879 (current-indentation))))
11880 (modi (verilog-modi-current))
11881 (moddecls (verilog-modi-get-decls modi))
11882 (sig-memories (verilog-signals-memory
11883 (verilog-decls-get-vars moddecls)))
11884 sig-list not-first presense-sigs)
11885 ;; Read signals in always, eliminate outputs from sense list
11886 (setq presense-sigs (verilog-signals-from-signame
11888 (verilog-read-signals start-pt (point)))))
11889 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
11891 (let ((tlen (length sig-list)))
11892 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
11893 (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
11894 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/"
11895 (save-excursion (goto-char (point))
11896 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
11897 (verilog-re-search-backward-quick "\\s-" start-pt t)
11898 (while (looking-at "\\s-`endif")
11899 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
11900 (verilog-re-search-backward-quick "\\s-" start-pt t))
11901 (not (looking-at "\\s-or\\b"))))
11902 (setq not-first t))
11903 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
11905 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
11907 (indent-to indent-pt)
11908 (if not-first (insert "or ")))
11909 (not-first (insert " or ")))
11910 (insert (verilog-sig-name (car sig-list)))
11911 (setq sig-list (cdr sig-list)
11914 (defun verilog-auto-reset ()
11915 "Expand AUTORESET statements, as part of \\[verilog-auto].
11916 Replace the /*AUTORESET*/ comment with code to initialize all
11917 registers set elsewhere in the always block.
11920 AUTORESET will not clear memories.
11922 AUTORESET uses <= if the signal has a <= assignment in the block,
11925 If <= is used, all = assigned variables are ignored if
11926 `verilog-auto-reset-blocking-in-non' is nil; they are presumed
11929 /*AUTORESET*/ presumes that any signals mentioned between the previous
11930 begin/case/if statement and the AUTORESET comment are being reset manually
11931 and should not be automatically reset. This includes omitting any signals
11932 used on the right hand side of assignments.
11934 By default, AUTORESET will include the width of the signal in the
11935 autos, SystemVerilog designs may want to change this. To control
11936 this behavior, see `verilog-auto-reset-widths'.
11938 AUTORESET ties signals to deasserted, which is presumed to be zero.
11939 Signals that match `verilog-active-low-regexp' will be deasserted by tying
11944 always @(posedge clk or negedge reset_l) begin
11945 if (!reset_l) begin
11956 Typing \\[verilog-auto] will make this into:
11958 always @(posedge core_clk or negedge reset_l) begin
11959 if (!reset_l) begin
11962 // Beginning of autoreset for uninitialized flops
11964 b = 0; // if `verilog-auto-reset-blocking-in-non' true
11965 // End of automatics
11977 (let* ((indent-pt (current-indentation))
11978 (modi (verilog-modi-current))
11979 (moddecls (verilog-modi-get-decls modi))
11980 (all-list (verilog-decls-get-signals moddecls))
11981 sigss sig-list dly-list prereset-sigs)
11982 ;; Read signals in always, eliminate outputs from reset list
11983 (setq prereset-sigs (verilog-signals-from-signame
11985 (verilog-read-signals
11987 (verilog-re-search-backward-quick "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t)
11991 (verilog-re-search-backward-quick "@" nil t)
11992 (setq sigss (verilog-read-always-signals)))
11993 (setq dly-list (verilog-alw-get-outputs-delayed sigss))
11994 (setq sig-list (verilog-signals-not-in (append
11995 (verilog-alw-get-outputs-delayed sigss)
11996 (when (or (not (verilog-alw-get-uses-delayed sigss))
11997 verilog-auto-reset-blocking-in-non)
11998 (verilog-alw-get-outputs-immediate sigss)))
12000 (verilog-alw-get-temps sigss)
12002 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
12005 (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
12007 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths
12009 (indent-to indent-pt)
12010 (insert (verilog-sig-name sig)
12011 (if (assoc (verilog-sig-name sig) dly-list)
12012 (concat " <= " verilog-assignment-delay)
12014 (verilog-sig-tieoff sig)
12016 (setq sig-list (cdr sig-list))))
12017 (verilog-insert-indent "// End of automatics")))))
12019 (defun verilog-auto-tieoff ()
12020 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
12021 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
12022 signals to deasserted.
12024 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
12025 input/output list as another module, but no internals. Specifically, it
12026 finds all outputs in the module, and if that input is not otherwise declared
12027 as a register or wire, creates a tieoff.
12029 AUTORESET ties signals to deasserted, which is presumed to be zero.
12030 Signals that match `verilog-active-low-regexp' will be deasserted by tying
12033 You can add signals you do not want included in AUTOTIEOFF with
12034 `verilog-auto-tieoff-ignore-regexp'.
12036 `verilog-auto-wire-type' may be used to change the datatype of
12039 `verilog-auto-reset-widths' may be used to change how the tieoff
12040 value's width is generated.
12042 An example of making a stub for another module:
12044 module ExampStub (/*AUTOINST*/);
12045 /*AUTOINOUTMODULE(\"Foo\")*/
12047 // verilator lint_off UNUSED
12048 wire _unused_ok = &{1'b0,
12051 // verilator lint_on UNUSED
12054 Typing \\[verilog-auto] will make this into:
12056 module ExampStub (/*AUTOINST*/...);
12057 /*AUTOINOUTMODULE(\"Foo\")*/
12058 // Beginning of autotieoff
12060 // End of automatics
12063 // Beginning of autotieoff
12064 wire [2:0] foo = 3'b0;
12065 // End of automatics
12071 (let* ((indent-pt (current-indentation))
12072 (modi (verilog-modi-current))
12073 (moddecls (verilog-modi-get-decls modi))
12074 (modsubdecls (verilog-modi-get-sub-decls modi))
12075 (sig-list (verilog-signals-not-in
12076 (verilog-decls-get-outputs moddecls)
12077 (append (verilog-decls-get-vars moddecls)
12078 (verilog-decls-get-assigns moddecls)
12079 (verilog-decls-get-consts moddecls)
12080 (verilog-decls-get-gparams moddecls)
12081 (verilog-subdecls-get-interfaced modsubdecls)
12082 (verilog-subdecls-get-outputs modsubdecls)
12083 (verilog-subdecls-get-inouts modsubdecls)))))
12084 (setq sig-list (verilog-signals-not-matching-regexp
12085 sig-list verilog-auto-tieoff-ignore-regexp))
12088 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
12089 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
12090 (verilog-modi-cache-add-vars modi sig-list) ; Before we trash list
12092 (let ((sig (car sig-list)))
12093 (cond ((equal verilog-auto-tieoff-declaration "assign")
12094 (indent-to indent-pt)
12095 (insert "assign " (verilog-sig-name sig)))
12097 (verilog-insert-one-definition sig verilog-auto-tieoff-declaration indent-pt)))
12098 (indent-to (max 48 (+ indent-pt 40)))
12099 (insert "= " (verilog-sig-tieoff sig)
12101 (setq sig-list (cdr sig-list))))
12102 (verilog-insert-indent "// End of automatics\n")))))
12104 (defun verilog-auto-undef ()
12105 "Expand AUTOUNDEF statements, as part of \\[verilog-auto].
12106 Take any `defines since the last AUTOUNDEF in the current file
12107 and create `undefs for them. This is used to insure that
12108 file-local defines do not pollute the global `define name space.
12111 AUTOUNDEF presumes any identifier following `define is the
12112 name of a define. Any `ifdefs are ignored.
12114 AUTOUNDEF suppresses creating an `undef for any define that was
12115 `undefed before the AUTOUNDEF. This may be used to work around
12116 the ignoring of `ifdefs as shown below.
12125 `undef M_BAZ // Emacs will see this and not `undef M_BAZ
12130 Typing \\[verilog-auto] will make this into:
12134 // Beginning of automatic undefs
12137 // End of automatics
12139 You may also provide an optional regular expression, in which case only
12140 defines the regular expression will be undefed."
12142 (let* ((params (verilog-read-auto-params 0 1))
12143 (regexp (nth 0 params))
12144 (indent-pt (current-indentation))
12148 ;; Scan from start of file, or last AUTOUNDEF
12149 (or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
12150 (goto-char (point-min)))
12151 (while (verilog-re-search-forward-quick
12152 "`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
12153 (cond ((equal (match-string-no-properties 1) "define")
12154 (setq def (match-string-no-properties 2))
12155 (when (and (or (not regexp)
12156 (string-match regexp def))
12157 (not (member def defs))) ;; delete-dups not in 21.1
12158 (setq defs (cons def defs))))
12160 (setq defs (delete (match-string-no-properties 2) defs))))))
12162 (setq defs (sort defs 'string<))
12165 (verilog-insert-indent "// Beginning of automatic undefs\n")
12167 (verilog-insert-indent "`undef " (car defs) "\n")
12168 (setq defs (cdr defs)))
12169 (verilog-insert-indent "// End of automatics\n")))))
12171 (defun verilog-auto-unused ()
12172 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
12173 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
12174 input and inout signals.
12176 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
12177 input/output list as another module, but no internals. Specifically, it
12178 finds all inputs and inouts in the module, and if that input is not otherwise
12179 used, adds it to a comma separated list.
12181 The comma separated list is intended to be used to create a _unused_ok
12182 signal. Using the exact name \"_unused_ok\" for name of the temporary
12183 signal is recommended as it will insure maximum forward compatibility, it
12184 also makes lint warnings easy to understand; ignore any unused warnings
12185 with \"unused\" in the signal name.
12187 To reduce simulation time, the _unused_ok signal should be forced to a
12188 constant to prevent wiggling. The easiest thing to do is use a
12189 reduction-and with 1'b0 as shown.
12191 This way all unused signals are in one place, making it convenient to add
12192 your tool's specific pragmas around the assignment to disable any unused
12195 You can add signals you do not want included in AUTOUNUSED with
12196 `verilog-auto-unused-ignore-regexp'.
12198 An example of making a stub for another module:
12200 module ExampStub (/*AUTOINST*/);
12201 /*AUTOINOUTMODULE(\"Examp\")*/
12203 // verilator lint_off UNUSED
12204 wire _unused_ok = &{1'b0,
12207 // verilator lint_on UNUSED
12210 Typing \\[verilog-auto] will make this into:
12213 // verilator lint_off UNUSED
12214 wire _unused_ok = &{1'b0,
12216 // Beginning of automatics
12220 // End of automatics
12222 // verilator lint_on UNUSED
12227 (let* ((indent-pt (progn (search-backward "/*") (current-column)))
12228 (modi (verilog-modi-current))
12229 (moddecls (verilog-modi-get-decls modi))
12230 (modsubdecls (verilog-modi-get-sub-decls modi))
12231 (sig-list (verilog-signals-not-in
12232 (append (verilog-decls-get-inputs moddecls)
12233 (verilog-decls-get-inouts moddecls))
12234 (append (verilog-subdecls-get-inputs modsubdecls)
12235 (verilog-subdecls-get-inouts modsubdecls)))))
12236 (setq sig-list (verilog-signals-not-matching-regexp
12237 sig-list verilog-auto-unused-ignore-regexp))
12240 (verilog-insert-indent "// Beginning of automatic unused inputs\n")
12241 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
12243 (let ((sig (car sig-list)))
12244 (indent-to indent-pt)
12245 (insert (verilog-sig-name sig) ",\n")
12246 (setq sig-list (cdr sig-list))))
12247 (verilog-insert-indent "// End of automatics\n")))))
12249 (defun verilog-enum-ascii (signm elim-regexp)
12250 "Convert an enum name SIGNM to an ascii string for insertion.
12251 Remove user provided prefix ELIM-REGEXP."
12252 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
12253 (let ((case-fold-search t))
12254 ;; All upper becomes all lower for readability
12255 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
12257 (defun verilog-auto-ascii-enum ()
12258 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
12259 Create a register to contain the ASCII decode of an enumerated signal type.
12260 This will allow trace viewers to show the ASCII name of states.
12262 First, parameters are built into an enumeration using the synopsys enum
12263 comment. The comment must be between the keyword and the symbol.
12264 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
12266 Next, registers which that enum applies to are also tagged with the same
12269 Finally, an AUTOASCIIENUM command is used.
12271 The first parameter is the name of the signal to be decoded.
12273 The second parameter is the name to store the ASCII code into. For the
12274 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
12275 a signal that is just for simulation, and the magic characters _ascii
12276 tell viewers like Dinotrace to display in ASCII format.
12278 The third optional parameter is a string which will be removed
12279 from the state names. It defaults to \"\" which removes nothing.
12281 The fourth optional parameter is \"onehot\" to force one-hot
12282 decoding. If unspecified, if and only if the first parameter
12283 width is 2^(number of states in enum) and does NOT match the
12284 width of the enum, the signal is assumed to be a one-hot
12285 decode. Otherwise, it's a normal encoded state vector.
12287 `verilog-auto-wire-type' may be used to change the datatype of
12290 \"auto enum\" may be used in place of \"synopsys enum\".
12294 //== State enumeration
12295 parameter [2:0] // synopsys enum state_info
12299 //== State variables
12300 reg [2:0] /* synopsys enum state_info */
12301 state_r; /* synopsys state_vector state_r */
12302 reg [2:0] /* synopsys enum state_info */
12305 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
12307 Typing \\[verilog-auto] will make this into:
12309 ... same front matter ...
12311 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
12312 // Beginning of automatic ASCII enum decoding
12313 reg [39:0] state_ascii_r; // Decode of state_r
12314 always @(state_r) begin
12316 SM_IDLE: state_ascii_r = \"idle \";
12317 SM_SEND: state_ascii_r = \"send \";
12318 SM_WAIT1: state_ascii_r = \"wait1\";
12319 default: state_ascii_r = \"%Erro\";
12322 // End of automatics"
12324 (let* ((params (verilog-read-auto-params 2 4))
12325 (undecode-name (nth 0 params))
12326 (ascii-name (nth 1 params))
12327 (elim-regexp (and (nth 2 params)
12328 (not (equal (nth 2 params) ""))
12330 (one-hot-flag (nth 3 params))
12332 (indent-pt (current-indentation))
12333 (modi (verilog-modi-current))
12334 (moddecls (verilog-modi-get-decls modi))
12336 (sig-list-consts (append (verilog-decls-get-consts moddecls)
12337 (verilog-decls-get-gparams moddecls)))
12338 (sig-list-all (append (verilog-decls-get-vars moddecls)
12339 (verilog-decls-get-outputs moddecls)
12340 (verilog-decls-get-inouts moddecls)
12341 (verilog-decls-get-inputs moddecls)))
12343 (undecode-sig (or (assoc undecode-name sig-list-all)
12344 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
12345 (undecode-enum (or (verilog-sig-enum undecode-sig)
12346 (error "%s: Signal %s does not have an enum tag" (verilog-point-text) undecode-name)))
12348 (enum-sigs (verilog-signals-not-in
12349 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
12350 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))
12354 (string-match "onehot" (or one-hot-flag ""))
12355 (and ;; width(enum) != width(sig)
12356 (or (not (verilog-sig-bits (car enum-sigs)))
12357 (not (equal (verilog-sig-width (car enum-sigs))
12358 (verilog-sig-width undecode-sig))))
12359 ;; count(enums) == width(sig)
12360 (equal (number-to-string (length enum-sigs))
12361 (verilog-sig-width undecode-sig)))))
12365 ;; Find number of ascii chars needed
12366 (let ((tmp-sigs enum-sigs))
12368 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
12369 ascii-chars (max ascii-chars (length (verilog-enum-ascii
12370 (verilog-sig-name (car tmp-sigs))
12372 tmp-sigs (cdr tmp-sigs))))
12375 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
12376 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
12377 (concat "Decode of " undecode-name) nil nil))))
12378 (verilog-insert-definition modi decode-sig-list "reg" indent-pt nil))
12380 (verilog-insert-indent "always @(" undecode-name ") begin\n")
12381 (setq indent-pt (+ indent-pt verilog-indent-level))
12382 (verilog-insert-indent "case ({" undecode-name "})\n")
12383 (setq indent-pt (+ indent-pt verilog-case-indent))
12385 (let ((tmp-sigs enum-sigs)
12386 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
12387 (+ (if one-hot 9 1) (max 8 enum-chars))
12388 ascii-name ascii-chars))
12389 (errname (substring "%Error" 0 (min 6 ascii-chars))))
12391 (verilog-insert-indent
12394 (concat (if one-hot "(")
12395 ;; Use enum-sigs length as that's numeric
12396 ;; verilog-sig-width undecode-sig might not be.
12397 (if one-hot (number-to-string (length enum-sigs)))
12398 ;; We use a shift instead of var[index]
12399 ;; so that a non-one hot value will show as error.
12400 (if one-hot "'b1<<")
12401 (verilog-sig-name (car tmp-sigs))
12402 (if one-hot ")") ":")
12403 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
12405 (setq tmp-sigs (cdr tmp-sigs)))
12406 (verilog-insert-indent (format chrfmt "default:" errname)))
12408 (setq indent-pt (- indent-pt verilog-case-indent))
12409 (verilog-insert-indent "endcase\n")
12410 (setq indent-pt (- indent-pt verilog-indent-level))
12411 (verilog-insert-indent "end\n"
12412 "// End of automatics\n"))))
12414 (defun verilog-auto-templated-rel ()
12415 "Replace Templated relative line numbers with absolute line numbers.
12416 Internal use only. This hacks around the line numbers in AUTOINST Templates
12417 being different from the final output's line numbering."
12418 (let ((templateno 0) (template-line (list 0)) (buf-line 1))
12419 ;; Find line number each template is on
12420 ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
12421 (goto-char (point-min))
12422 (while (not (eobp))
12423 (when (looking-at ".*AUTO_TEMPLATE")
12424 (setq templateno (1+ templateno))
12425 (setq template-line (cons buf-line template-line)))
12426 (setq buf-line (1+ buf-line))
12428 (setq template-line (nreverse template-line))
12429 ;; Replace T# L# with absolute line number
12430 (goto-char (point-min))
12431 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
12433 (concat " Templated "
12434 (int-to-string (+ (nth (string-to-number (match-string 1))
12436 (string-to-number (match-string 2)))))
12439 (defun verilog-auto-template-lint ()
12440 "Check AUTO_TEMPLATEs for unused lines.
12441 Enable with `verilog-auto-template-warn-unused'."
12442 (let ((name1 (or (buffer-file-name) (buffer-name))))
12444 (goto-char (point-min))
12445 (while (re-search-forward
12446 "^\\s-*/?\\*?\\s-*[a-zA-Z0-9`_$]+\\s-+AUTO_TEMPLATE" nil t)
12447 (let* ((tpl-info (verilog-read-auto-template-middle))
12448 (tpl-list (aref tpl-info 1))
12449 (tlines (append (nth 0 tpl-list) (nth 1 tpl-list)))
12452 (setq tpl-ass (car tlines)
12453 tlines (cdr tlines))
12455 (unless (or (not (eval-when-compile (fboundp 'make-hash-table))) ;; Not supported, no warning
12456 (not verilog-auto-template-hits)
12457 (gethash (vector (nth 2 tpl-ass) (nth 3 tpl-ass))
12458 verilog-auto-template-hits))
12459 (verilog-warn-error "%s:%d: AUTO_TEMPLATE line unused: \".%s (%s)\""
12461 (+ (elt tpl-ass 3) ;; Template line number
12462 (count-lines (point-min) (point)))
12463 (elt tpl-ass 0) (elt tpl-ass 1))
12471 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing an arg
12472 "Expand AUTO statements.
12473 Look for any /*AUTO...*/ commands in the code, as used in
12474 instantiations or argument headers. Update the list of signals
12475 following the /*AUTO...*/ command.
12477 Use \\[verilog-delete-auto] to remove the AUTOs.
12479 Use \\[verilog-diff-auto] to see differences in AUTO expansion.
12481 Use \\[verilog-inject-auto] to insert AUTOs for the first time.
12483 Use \\[verilog-faq] for a pointer to frequently asked questions.
12485 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
12486 called before and after this function, respectively.
12489 module ModuleName (/*AUTOARG*/);
12494 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
12496 You can also update the AUTOs from the shell using:
12497 emacs --batch <filenames.v> -f verilog-batch-auto
12498 Or fix indentation with:
12499 emacs --batch <filenames.v> -f verilog-batch-indent
12500 Likewise, you can delete or inject AUTOs with:
12501 emacs --batch <filenames.v> -f verilog-batch-delete-auto
12502 emacs --batch <filenames.v> -f verilog-batch-inject-auto
12503 Or check if AUTOs have the same expansion
12504 emacs --batch <filenames.v> -f verilog-batch-diff-auto
12506 Using \\[describe-function], see also:
12507 `verilog-auto-arg' for AUTOARG module instantiations
12508 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
12509 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
12510 `verilog-auto-inout-in' for AUTOINOUTIN inputs for all i/o
12511 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
12512 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
12513 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
12514 `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
12515 `verilog-auto-inst' for AUTOINST instantiation pins
12516 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
12517 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
12518 `verilog-auto-logic' for AUTOLOGIC declaring logic signals
12519 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
12520 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
12521 `verilog-auto-reg' for AUTOREG registers
12522 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
12523 `verilog-auto-reset' for AUTORESET flop resets
12524 `verilog-auto-sense' for AUTOSENSE always sensitivity lists
12525 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
12526 `verilog-auto-undef' for AUTOUNDEF `undef of local `defines
12527 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
12528 `verilog-auto-wire' for AUTOWIRE instantiation wires
12530 `verilog-read-defines' for reading `define values
12531 `verilog-read-includes' for reading `includes
12533 If you have bugs with these autos, please file an issue at
12534 URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
12535 Wilson Snyder (wsnyder@wsnyder.org)."
12537 (unless noninteractive (message "Updating AUTOs..."))
12538 (if (fboundp 'dinotrace-unannotate-all)
12539 (dinotrace-unannotate-all))
12540 (verilog-save-font-mods
12541 (let ((oldbuf (if (not (buffer-modified-p))
12543 ;; Cache directories; we don't write new files, so can't change
12544 (verilog-dir-cache-preserving t)
12545 ;; Cache current module
12546 (verilog-modi-cache-current-enable t)
12547 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
12548 verilog-modi-cache-current)
12550 ;; Disable change hooks for speed
12551 ;; This let can't be part of above let; must restore
12552 ;; after-change-functions before font-lock resumes
12553 (verilog-save-no-change-functions
12554 (verilog-save-scan-cache
12556 ;; Wipe cache; otherwise if we AUTOed a block above this one,
12557 ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
12558 (setq verilog-modi-cache-list nil)
12560 (setq verilog-auto-template-hits nil)
12561 ;; If we're not in verilog-mode, change syntax table so parsing works right
12562 (unless (eq major-mode `verilog-mode) (verilog-mode))
12563 ;; Allow user to customize
12564 (verilog-run-hooks 'verilog-before-auto-hook)
12565 ;; Try to save the user from needing to revert-file to reread file local-variables
12566 (verilog-auto-reeval-locals)
12567 (verilog-read-auto-lisp-present)
12568 (verilog-read-auto-lisp (point-min) (point-max))
12569 (verilog-getopt-flags)
12570 ;; From here on out, we can cache anything we read from disk
12571 (verilog-preserve-dir-cache
12572 ;; These two may seem obvious to do always, but on large includes it can be way too slow
12573 (when verilog-auto-read-includes
12574 (verilog-read-includes)
12575 (verilog-read-defines nil nil t))
12576 ;; Setup variables due to SystemVerilog expansion
12577 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic-setup)
12578 ;; This particular ordering is important
12579 ;; INST: Lower modules correct, no internal dependencies, FIRST
12580 (verilog-preserve-modi-cache
12581 ;; Clear existing autos else we'll be screwed by existing ones
12582 (verilog-delete-auto)
12583 ;; Injection if appropriate
12585 (verilog-inject-inst)
12586 (verilog-inject-sense)
12587 (verilog-inject-arg))
12589 ;; Do user inserts first, so their code can insert AUTOs
12590 ;; We may provide an AUTOINSERTLISPLAST if another cleanup pass is needed
12591 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
12592 'verilog-auto-insert-lisp)
12593 ;; Expand instances before need the signals the instances input/output
12594 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
12595 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
12596 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
12597 ;; Doesn't matter when done, but combine it with a common changer
12598 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
12599 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
12600 ;; Must be done before autoin/out as creates a reg
12601 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM([^)]*)\\*/" 'verilog-auto-ascii-enum)
12603 ;; first in/outs from other files
12604 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE([^)]*)\\*/" 'verilog-auto-inout-module)
12605 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP([^)]*)\\*/" 'verilog-auto-inout-comp)
12606 (verilog-auto-re-search-do "/\\*AUTOINOUTIN([^)]*)\\*/" 'verilog-auto-inout-in)
12607 ;; next in/outs which need previous sucked inputs first
12608 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((\"[^\"]*\")\\)\\*/"
12609 (lambda () (verilog-auto-output t)))
12610 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\*/" 'verilog-auto-output)
12611 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((\"[^\"]*\")\\)\\*/"
12612 (lambda () (verilog-auto-input t)))
12613 (verilog-auto-re-search-do "/\\*AUTOINPUT\\*/" 'verilog-auto-input)
12614 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((\"[^\"]*\")\\)\\*/"
12615 (lambda () (verilog-auto-inout t)))
12616 (verilog-auto-re-search-do "/\\*AUTOINOUT\\*/" 'verilog-auto-inout)
12617 ;; Then tie off those in/outs
12618 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
12619 ;; These can be anywhere after AUTOINSERTLISP
12620 (verilog-auto-re-search-do "/\\*AUTOUNDEF\\((\"[^\"]*\")\\)?\\*/" 'verilog-auto-undef)
12621 ;; Wires/regs must be after inputs/outputs
12622 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
12623 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
12624 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
12625 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
12626 ;; outputevery needs AUTOOUTPUTs done first
12627 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\*/" 'verilog-auto-output-every)
12628 ;; After we've created all new variables
12629 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
12630 ;; Must be after all inputs outputs are generated
12631 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
12632 ;; Fix line numbers (comments only)
12633 (when verilog-auto-inst-template-numbers
12634 (verilog-auto-templated-rel))
12635 (when verilog-auto-template-warn-unused
12636 (verilog-auto-template-lint))))
12638 (verilog-run-hooks 'verilog-auto-hook)
12640 (when verilog-auto-delete-trailing-whitespace
12641 (verilog-delete-trailing-whitespace))
12643 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
12645 ;; If end result is same as when started, clear modified flag
12646 (cond ((and oldbuf (equal oldbuf (buffer-string)))
12647 (set-buffer-modified-p nil)
12648 (unless noninteractive (message "Updating AUTOs...done (no changes)")))
12649 (t (unless noninteractive (message "Updating AUTOs...done"))))
12650 ;; End of after-change protection
12653 ;; Currently handled in verilog-save-font-mods
12658 ;; Skeleton based code insertion
12660 (defvar verilog-template-map
12661 (let ((map (make-sparse-keymap)))
12662 (define-key map "a" 'verilog-sk-always)
12663 (define-key map "b" 'verilog-sk-begin)
12664 (define-key map "c" 'verilog-sk-case)
12665 (define-key map "f" 'verilog-sk-for)
12666 (define-key map "g" 'verilog-sk-generate)
12667 (define-key map "h" 'verilog-sk-header)
12668 (define-key map "i" 'verilog-sk-initial)
12669 (define-key map "j" 'verilog-sk-fork)
12670 (define-key map "m" 'verilog-sk-module)
12671 (define-key map "o" 'verilog-sk-ovm-class)
12672 (define-key map "p" 'verilog-sk-primitive)
12673 (define-key map "r" 'verilog-sk-repeat)
12674 (define-key map "s" 'verilog-sk-specify)
12675 (define-key map "t" 'verilog-sk-task)
12676 (define-key map "u" 'verilog-sk-uvm-class)
12677 (define-key map "w" 'verilog-sk-while)
12678 (define-key map "x" 'verilog-sk-casex)
12679 (define-key map "z" 'verilog-sk-casez)
12680 (define-key map "?" 'verilog-sk-if)
12681 (define-key map ":" 'verilog-sk-else-if)
12682 (define-key map "/" 'verilog-sk-comment)
12683 (define-key map "A" 'verilog-sk-assign)
12684 (define-key map "F" 'verilog-sk-function)
12685 (define-key map "I" 'verilog-sk-input)
12686 (define-key map "O" 'verilog-sk-output)
12687 (define-key map "S" 'verilog-sk-state-machine)
12688 (define-key map "=" 'verilog-sk-inout)
12689 (define-key map "W" 'verilog-sk-wire)
12690 (define-key map "R" 'verilog-sk-reg)
12691 (define-key map "D" 'verilog-sk-define-signal)
12693 "Keymap used in Verilog mode for smart template operations.")
12697 ;; Place the templates into Verilog Mode. They may be inserted under any key.
12698 ;; C-c C-t will be the default. If you use templates a lot, you
12699 ;; may want to consider moving the binding to another key in your .emacs
12702 ;; Note \C-c and letter are reserved for users
12703 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
12705 ;;; ---- statement skeletons ------------------------------------------
12707 (define-skeleton verilog-sk-prompt-condition
12708 "Prompt for the loop condition."
12709 "[condition]: " str )
12711 (define-skeleton verilog-sk-prompt-init
12712 "Prompt for the loop init statement."
12713 "[initial statement]: " str )
12715 (define-skeleton verilog-sk-prompt-inc
12716 "Prompt for the loop increment statement."
12717 "[increment statement]: " str )
12719 (define-skeleton verilog-sk-prompt-name
12720 "Prompt for the name of something."
12723 (define-skeleton verilog-sk-prompt-clock
12724 "Prompt for the name of something."
12725 "name and edge of clock(s): " str)
12727 (defvar verilog-sk-reset nil)
12728 (defun verilog-sk-prompt-reset ()
12729 "Prompt for the name of a state machine reset."
12730 (setq verilog-sk-reset (read-string "name of reset: " "rst")))
12733 (define-skeleton verilog-sk-prompt-state-selector
12734 "Prompt for the name of a state machine selector."
12735 "name of selector (eg {a,b,c,d}): " str )
12737 (define-skeleton verilog-sk-prompt-output
12738 "Prompt for the name of something."
12741 (define-skeleton verilog-sk-prompt-msb
12742 "Prompt for most significant bit specification."
12743 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
12745 (define-skeleton verilog-sk-prompt-lsb
12746 "Prompt for least significant bit specification."
12749 (defvar verilog-sk-p nil)
12750 (define-skeleton verilog-sk-prompt-width
12751 "Prompt for a width specification."
12754 (setq verilog-sk-p (point))
12755 (verilog-sk-prompt-msb)
12756 (if (> (point) verilog-sk-p) "] " " ")))
12758 (defun verilog-sk-header ()
12759 "Insert a descriptive header at the top of the file.
12760 See also `verilog-header' for an alternative format."
12763 (goto-char (point-min))
12764 (verilog-sk-header-tmpl)))
12766 (define-skeleton verilog-sk-header-tmpl
12767 "Insert a comment block containing the module title, author, etc."
12769 "// -*- Mode: Verilog -*-"
12770 "\n// Filename : " (buffer-name)
12771 "\n// Description : " str
12772 "\n// Author : " (user-full-name)
12773 "\n// Created On : " (current-time-string)
12774 "\n// Last Modified By: " (user-full-name)
12775 "\n// Last Modified On: " (current-time-string)
12776 "\n// Update Count : 0"
12777 "\n// Status : Unknown, Use with caution!"
12780 (define-skeleton verilog-sk-module
12781 "Insert a module definition."
12783 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
12785 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
12787 ;;; ------------------------------------------------------------------------
12788 ;;; Define a default OVM class, with macros and new()
12789 ;;; ------------------------------------------------------------------------
12791 (define-skeleton verilog-sk-ovm-class
12792 "Insert a class definition"
12794 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
12796 > "`ovm_object_utils_begin(" name ")" \n
12797 > (- verilog-indent-level) " `ovm_object_utils_end" \n
12799 > "function new(name=\"" name "\");" \n
12800 > "super.new(name);" \n
12801 > (- verilog-indent-level) "endfunction" \n
12803 > "endclass" (progn (electric-verilog-terminate-line) nil))
12805 (define-skeleton verilog-sk-uvm-class
12806 "Insert a class definition"
12808 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
12810 > "`uvm_object_utils_begin(" name ")" \n
12811 > (- verilog-indent-level) " `uvm_object_utils_end" \n
12813 > "function new(name=\"" name "\");" \n
12814 > "super.new(name);" \n
12815 > (- verilog-indent-level) "endfunction" \n
12817 > "endclass" (progn (electric-verilog-terminate-line) nil))
12819 (define-skeleton verilog-sk-primitive
12820 "Insert a task definition."
12822 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
12824 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
12826 (define-skeleton verilog-sk-task
12827 "Insert a task definition."
12829 > "task " '(verilog-sk-prompt-name) & ?; \n
12833 > (- verilog-indent-level-behavioral) "end" \n
12834 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
12836 (define-skeleton verilog-sk-function
12837 "Insert a function definition."
12839 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n
12843 > (- verilog-indent-level-behavioral) "end" \n
12844 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
12846 (define-skeleton verilog-sk-always
12847 "Insert always block. Uses the minibuffer to prompt
12848 for sensitivity list."
12850 > "always @ ( /*AUTOSENSE*/ ) begin\n"
12852 > (- verilog-indent-level-behavioral) "end" \n >
12855 (define-skeleton verilog-sk-initial
12856 "Insert an initial block."
12858 > "initial begin\n"
12860 > (- verilog-indent-level-behavioral) "end" \n > )
12862 (define-skeleton verilog-sk-specify
12863 "Insert specify block. "
12867 > (- verilog-indent-level-behavioral) "endspecify" \n > )
12869 (define-skeleton verilog-sk-generate
12870 "Insert generate block. "
12874 > (- verilog-indent-level-behavioral) "endgenerate" \n > )
12876 (define-skeleton verilog-sk-begin
12877 "Insert begin end block. Uses the minibuffer to prompt for name."
12879 > "begin" '(verilog-sk-prompt-name) \n
12881 > (- verilog-indent-level-behavioral) "end"
12884 (define-skeleton verilog-sk-fork
12885 "Insert a fork join block."
12890 > (- verilog-indent-level-behavioral) "end" \n
12893 > (- verilog-indent-level-behavioral) "end" \n
12894 > (- verilog-indent-level-behavioral) "join" \n
12898 (define-skeleton verilog-sk-case
12899 "Build skeleton case statement, prompting for the selector expression,
12900 and the case items."
12901 "[selector expression]: "
12902 > "case (" str ") " \n
12903 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
12904 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
12906 (define-skeleton verilog-sk-casex
12907 "Build skeleton casex statement, prompting for the selector expression,
12908 and the case items."
12909 "[selector expression]: "
12910 > "casex (" str ") " \n
12911 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
12912 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
12914 (define-skeleton verilog-sk-casez
12915 "Build skeleton casez statement, prompting for the selector expression,
12916 and the case items."
12917 "[selector expression]: "
12918 > "casez (" str ") " \n
12919 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
12920 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
12922 (define-skeleton verilog-sk-if
12923 "Insert a skeleton if statement."
12924 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
12926 > (- verilog-indent-level-behavioral) "end " \n )
12928 (define-skeleton verilog-sk-else-if
12929 "Insert a skeleton else if statement."
12930 > (verilog-indent-line) "else if ("
12931 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
12933 > "end" (progn (electric-verilog-terminate-line) nil))
12935 (define-skeleton verilog-sk-datadef
12936 "Common routine to get data definition."
12938 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
12940 (define-skeleton verilog-sk-input
12941 "Insert an input definition."
12943 > "input [" '(verilog-sk-datadef))
12945 (define-skeleton verilog-sk-output
12946 "Insert an output definition."
12948 > "output [" '(verilog-sk-datadef))
12950 (define-skeleton verilog-sk-inout
12951 "Insert an inout definition."
12953 > "inout [" '(verilog-sk-datadef))
12955 (defvar verilog-sk-signal nil)
12956 (define-skeleton verilog-sk-def-reg
12957 "Insert a reg definition."
12959 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations-auto) )
12961 (defun verilog-sk-define-signal ()
12962 "Insert a definition of signal under point at top of module."
12964 (let* ((sig-re "[a-zA-Z0-9_]*")
12965 (v1 (buffer-substring
12967 (skip-chars-backward sig-re)
12970 (skip-chars-forward sig-re)
12972 (if (not (member v1 verilog-keywords))
12974 (setq verilog-sk-signal v1)
12975 (verilog-beg-of-defun)
12976 (verilog-end-of-statement)
12977 (verilog-forward-syntactic-ws)
12978 (verilog-sk-def-reg)
12979 (message "signal at point is %s" v1))
12980 (message "object at point (%s) is a keyword" v1))))
12982 (define-skeleton verilog-sk-wire
12983 "Insert a wire definition."
12985 > "wire [" '(verilog-sk-datadef))
12987 (define-skeleton verilog-sk-reg
12988 "Insert a reg definition."
12990 > "reg [" '(verilog-sk-datadef))
12992 (define-skeleton verilog-sk-assign
12993 "Insert a skeleton assign statement."
12995 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
12997 (define-skeleton verilog-sk-while
12998 "Insert a skeleton while loop statement."
13000 > "while (" '(verilog-sk-prompt-condition) ") begin" \n
13002 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13004 (define-skeleton verilog-sk-repeat
13005 "Insert a skeleton repeat loop statement."
13007 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
13009 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13011 (define-skeleton verilog-sk-for
13012 "Insert a skeleton while loop statement."
13015 '(verilog-sk-prompt-init) "; "
13016 '(verilog-sk-prompt-condition) "; "
13017 '(verilog-sk-prompt-inc)
13020 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13022 (define-skeleton verilog-sk-comment
13023 "Inserts three comment lines, making a display comment."
13029 (define-skeleton verilog-sk-state-machine
13030 "Insert a state machine definition."
13031 "Name of state variable: "
13032 '(setq input "state")
13033 > "// State registers for " str | -23 \n
13034 '(setq verilog-sk-state str)
13035 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n
13038 > "// State FF for " verilog-sk-state \n
13039 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
13040 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
13041 > verilog-sk-state " = next_" verilog-sk-state ?; \n
13042 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
13044 > "// Next State Logic for " verilog-sk-state \n
13045 > "always @ ( /*AUTOSENSE*/ ) begin\n"
13046 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
13047 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
13048 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
13049 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
13053 ;; Include file loading with mouse/return event
13055 ;; idea & first impl.: M. Rouat (eldo-mode.el)
13056 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
13058 (if (featurep 'xemacs)
13059 (require 'overlay))
13061 (defconst verilog-include-file-regexp
13062 "^`include\\s-+\"\\([^\n\"]*\\)\""
13063 "Regexp that matches the include file.")
13065 (defvar verilog-mode-mouse-map
13066 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
13067 (set-keymap-parent map verilog-mode-map)
13068 ;; mouse button bindings
13069 (define-key map "\r" 'verilog-load-file-at-point)
13070 (if (featurep 'xemacs)
13071 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
13072 (define-key map [mouse-2] 'verilog-load-file-at-mouse))
13073 (if (featurep 'xemacs)
13074 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
13075 (define-key map [S-mouse-2] 'mouse-yank-at-click))
13077 "Map containing mouse bindings for `verilog-mode'.")
13080 (defun verilog-highlight-region (beg end old-len)
13081 "Colorize included files and modules in the (changed?) region.
13082 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
13083 (when (or verilog-highlight-includes
13084 verilog-highlight-modules)
13086 (save-match-data ;; A query-replace may call this function - do not disturb
13087 (verilog-save-buffer-state
13088 (verilog-save-scan-cache
13091 (setq end-point (point-at-eol))
13093 (beginning-of-line) ; scan entire line
13094 ;; delete overlays existing on this line
13095 (let ((overlays (overlays-in (point) end-point)))
13098 (overlay-get (car overlays) 'detachable)
13099 (or (overlay-get (car overlays) 'verilog-include-file)
13100 (overlay-get (car overlays) 'verilog-inst-module)))
13101 (delete-overlay (car overlays)))
13102 (setq overlays (cdr overlays))))
13104 ;; make new include overlays
13105 (when verilog-highlight-includes
13106 (while (search-forward-regexp verilog-include-file-regexp end-point t)
13107 (goto-char (match-beginning 1))
13108 (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
13109 (overlay-put ov 'start-closed 't)
13110 (overlay-put ov 'end-closed 't)
13111 (overlay-put ov 'evaporate 't)
13112 (overlay-put ov 'verilog-include-file 't)
13113 (overlay-put ov 'mouse-face 'highlight)
13114 (overlay-put ov 'local-map verilog-mode-mouse-map))))
13116 ;; make new module overlays
13118 ;; This scanner is syntax-fragile, so don't get bent
13119 (when verilog-highlight-modules
13120 (condition-case nil
13121 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
13123 (goto-char (match-beginning 0))
13124 (unless (verilog-inside-comment-or-string-p)
13125 (verilog-read-inst-module-matcher) ;; sets match 0
13126 (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
13127 (overlay-put ov 'start-closed 't)
13128 (overlay-put ov 'end-closed 't)
13129 (overlay-put ov 'evaporate 't)
13130 (overlay-put ov 'verilog-inst-module 't)
13131 (overlay-put ov 'mouse-face 'highlight)
13132 (overlay-put ov 'local-map verilog-mode-mouse-map)))))
13135 ;; Future highlights:
13136 ;; variables - make an Occur buffer of where referenced
13137 ;; pins - make an Occur buffer of the sig in the declaration module
13140 (defun verilog-highlight-buffer ()
13141 "Colorize included files and modules across the whole buffer."
13142 ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
13144 ;; delete and remake overlays
13145 (verilog-highlight-region (point-min) (point-max) nil))
13147 ;; Deprecated, but was interactive, so we'll keep it around
13148 (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
13150 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
13151 ;; so define this function to do more or less the same as ffap-at-mouse
13152 ;; but first resolve filename...
13153 (defun verilog-load-file-at-mouse (event)
13154 "Load file under button 2 click's EVENT.
13155 Files are checked based on `verilog-library-flags'."
13157 (save-excursion ;; implement a Verilog specific ffap-at-mouse
13158 (mouse-set-point event)
13159 (verilog-load-file-at-point t)))
13161 ;; ffap isn't usable for Verilog mode. It uses library paths.
13162 ;; so define this function to do more or less the same as ffap
13163 ;; but first resolve filename...
13164 (defun verilog-load-file-at-point (&optional warn)
13165 "Load file under point.
13166 If WARN, throw warning if not found.
13167 Files are checked based on `verilog-library-flags'."
13169 (save-excursion ;; implement a Verilog specific ffap
13170 (let ((overlays (overlays-in (point) (point)))
13172 (while (and overlays (not hit))
13173 (when (overlay-get (car overlays) 'verilog-inst-module)
13174 (verilog-goto-defun-file (buffer-substring
13175 (overlay-start (car overlays))
13176 (overlay-end (car overlays))))
13178 (setq overlays (cdr overlays)))
13180 (beginning-of-line)
13181 (when (and (not hit)
13182 (looking-at verilog-include-file-regexp))
13183 (if (and (car (verilog-library-filenames
13184 (match-string 1) (buffer-file-name)))
13185 (file-readable-p (car (verilog-library-filenames
13186 (match-string 1) (buffer-file-name)))))
13187 (find-file (car (verilog-library-filenames
13188 (match-string 1) (buffer-file-name))))
13191 "File '%s' isn't readable, use shift-mouse2 to paste in this field"
13192 (match-string 1))))))))
13198 (defun verilog-faq ()
13199 "Tell the user their current version, and where to get the FAQ etc."
13201 (with-output-to-temp-buffer "*verilog-mode help*"
13202 (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
13204 (princ "For new releases, see http://www.verilog.com\n")
13206 (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
13208 (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
13211 (autoload 'reporter-submit-bug-report "reporter")
13212 (defvar reporter-prompt-for-summary-p)
13214 (defun verilog-submit-bug-report ()
13215 "Submit via mail a bug report on verilog-mode.el."
13217 (let ((reporter-prompt-for-summary-p t))
13218 (reporter-submit-bug-report
13219 "mac@verilog.com, wsnyder@wsnyder.org"
13220 (concat "verilog-mode v" verilog-mode-version)
13222 verilog-active-low-regexp
13223 verilog-after-save-font-hook
13224 verilog-align-ifelse
13225 verilog-assignment-delay
13226 verilog-auto-arg-sort
13227 verilog-auto-declare-nettype
13228 verilog-auto-delete-trailing-whitespace
13229 verilog-auto-endcomments
13231 verilog-auto-ignore-concat
13232 verilog-auto-indent-on-newline
13233 verilog-auto-inout-ignore-regexp
13234 verilog-auto-input-ignore-regexp
13235 verilog-auto-inst-column
13236 verilog-auto-inst-dot-name
13237 verilog-auto-inst-interfaced-ports
13238 verilog-auto-inst-param-value
13239 verilog-auto-inst-sort
13240 verilog-auto-inst-template-numbers
13241 verilog-auto-inst-vector
13242 verilog-auto-lineup
13243 verilog-auto-newline
13244 verilog-auto-output-ignore-regexp
13245 verilog-auto-read-includes
13246 verilog-auto-reset-blocking-in-non
13247 verilog-auto-reset-widths
13248 verilog-auto-save-policy
13249 verilog-auto-sense-defines-constant
13250 verilog-auto-sense-include-inputs
13251 verilog-auto-star-expand
13252 verilog-auto-star-save
13253 verilog-auto-template-warn-unused
13254 verilog-auto-tieoff-declaration
13255 verilog-auto-tieoff-ignore-regexp
13256 verilog-auto-unused-ignore-regexp
13257 verilog-auto-wire-type
13258 verilog-before-auto-hook
13259 verilog-before-delete-auto-hook
13260 verilog-before-getopt-flags-hook
13261 verilog-before-save-font-hook
13262 verilog-cache-enabled
13263 verilog-case-indent
13264 verilog-cexp-indent
13267 verilog-delete-auto-hook
13268 verilog-getopt-flags-hook
13269 verilog-highlight-grouping-keywords
13270 verilog-highlight-includes
13271 verilog-highlight-modules
13272 verilog-highlight-p1800-keywords
13273 verilog-highlight-translate-off
13274 verilog-indent-begin-after-if
13275 verilog-indent-declaration-macros
13276 verilog-indent-level
13277 verilog-indent-level-behavioral
13278 verilog-indent-level-declaration
13279 verilog-indent-level-directive
13280 verilog-indent-level-module
13281 verilog-indent-lists
13282 verilog-library-directories
13283 verilog-library-extensions
13284 verilog-library-files
13285 verilog-library-flags
13287 verilog-minimum-comment-distance
13289 verilog-mode-release-date
13290 verilog-mode-release-emacs
13291 verilog-mode-version
13292 verilog-preprocessor
13294 verilog-tab-always-indent
13295 verilog-tab-to-comment
13296 verilog-typedef-regexp
13302 I want to report a bug.
13304 Before I go further, I want to say that Verilog mode has changed my life.
13305 I save so much time, my files are colored nicely, my co workers respect
13306 my coding ability... until now. I'd really appreciate anything you
13307 could do to help me out with this minor deficiency in the product.
13309 I've taken a look at the Verilog-Mode FAQ at
13310 http://www.veripool.org/verilog-mode-faq.html.
13312 And, I've considered filing the bug on the issue tracker at
13313 http://www.veripool.org/verilog-mode-bugs
13314 since I realize that public bugs are easier for you to track,
13315 and for others to search, but would prefer to email.
13317 So, to reproduce the bug, start a fresh Emacs via " invocation-name "
13318 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
13319 the code included below.
13321 Given those lines, I expected [[Fill in here]] to happen;
13322 but instead, [[Fill in here]] happens!.
13324 == The code: =="))))
13326 (provide 'verilog-mode)
13328 ;; Local Variables:
13329 ;; checkdoc-permit-comma-termination-flag:t
13330 ;; checkdoc-force-docstrings-flag:nil
13333 ;;; verilog-mode.el ends here