1 ;; verilog-mode.el --- major mode for editing verilog source in Emacs
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Michael McNamara (mac@verilog.com),
7 ;; Wilson Snyder (wsnyder@wsnyder.org)
8 ;; Please see our web sites:
9 ;; http://www.verilog.com
10 ;; http://www.veripool.org
12 ;; Keywords: languages
14 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
15 ;; file on 19/3/2008, and the maintainer agreed that when a bug is
16 ;; filed in the Emacs bug reporting system against this file, a copy
17 ;; of the bug report be sent to the maintainer's email address.
19 ;; This code supports Emacs 21.1 and later
20 ;; And XEmacs 21.1 and later
21 ;; Please do not make changes that break Emacs 21. Thanks!
25 ;; This file is part of GNU Emacs.
27 ;; GNU Emacs is free software: you can redistribute it and/or modify
28 ;; it under the terms of the GNU General Public License as published by
29 ;; the Free Software Foundation, either version 3 of the License, or
30 ;; (at your option) any later version.
32 ;; GNU Emacs is distributed in the hope that it will be useful,
33 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
34 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 ;; GNU General Public License for more details.
37 ;; You should have received a copy of the GNU General Public License
38 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
42 ;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs
47 ;; A major mode for editing Verilog HDL source code. When you have
48 ;; entered Verilog mode, you may get more info by pressing C-h m. You
49 ;; may also get online help describing various functions by: C-h f
50 ;; <Name of function you want described>
52 ;; KNOWN BUGS / BUG REPORTS
53 ;; =======================
55 ;; Verilog is a rapidly evolving language, and hence this mode is
56 ;; under continuous development. Hence this is beta code, and likely
57 ;; has bugs. Please report any issues to the issue tracker at
58 ;; http://www.veripool.org/verilog-mode
59 ;; Please use verilog-submit-bug-report to submit a report; type C-c
60 ;; C-b to invoke this and as a result I will have a much easier time
61 ;; of reproducing the bug you find, and hence fixing it.
63 ;; INSTALLING THE MODE
64 ;; ===================
66 ;; An older version of this mode may be already installed as a part of
67 ;; your environment, and one method of updating would be to update
68 ;; your Emacs environment. Sometimes this is difficult for local
69 ;; political/control reasons, and hence you can always install a
70 ;; private copy (or even a shared copy) which overrides the system
73 ;; You can get step by step help in installing this file by going to
74 ;; <http://www.verilog.com/emacs_install.html>
76 ;; The short list of installation instructions are: To set up
77 ;; automatic Verilog mode, put this file in your load path, and put
78 ;; the following in code (please un comment it first!) in your
79 ;; .emacs, or in your site's site-load.el
81 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
82 ; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
84 ;; Be sure to examine at the help for verilog-auto, and the other
85 ;; verilog-auto-* functions for some major coding time savers.
87 ;; If you want to customize Verilog mode to fit your needs better,
88 ;; you may add the below lines (the values of the variables presented
89 ;; here are the defaults). Note also that if you use an Emacs that
90 ;; supports custom, it's probably better to use the custom menu to
91 ;; edit these. If working as a member of a large team these settings
92 ;; should be common across all users (in a site-start file), or set
93 ;; in Local Variables in every file. Otherwise, different people's
94 ;; AUTO expansion may result different whitespace changes.
96 ; ;; Enable syntax highlighting of **all** languages
97 ; (global-font-lock-mode t)
99 ; ;; User customization for Verilog mode
100 ; (setq verilog-indent-level 3
101 ; verilog-indent-level-module 3
102 ; verilog-indent-level-declaration 3
103 ; verilog-indent-level-behavioral 3
104 ; verilog-indent-level-directive 1
105 ; verilog-case-indent 2
106 ; verilog-auto-newline t
107 ; verilog-auto-indent-on-newline t
108 ; verilog-tab-always-indent t
109 ; verilog-auto-endcomments t
110 ; verilog-minimum-comment-distance 40
111 ; verilog-indent-begin-after-if t
112 ; verilog-auto-lineup 'declarations
113 ; verilog-highlight-p1800-keywords nil
114 ; verilog-linter "my_lint_shell_command"
121 ;; See commit history at http://www.veripool.org/verilog-mode.html
122 ;; (This section is required to appease checkdoc.)
126 ;; This variable will always hold the version number of the mode
127 (defconst verilog-mode-version
"647"
128 "Version of this Verilog mode.")
129 (defconst verilog-mode-release-date
"2010-10-20-GNU"
130 "Release date of this Verilog mode.")
131 (defconst verilog-mode-release-emacs t
132 "If non-nil, this version of Verilog mode was released with Emacs itself.")
134 (defun verilog-version ()
135 "Inform caller of the version of this file."
137 (message "Using verilog-mode version %s" verilog-mode-version
))
139 ;; Insure we have certain packages, and deal with it if we don't
140 ;; Be sure to note which Emacs flavor and version added each feature.
142 ;; Provide stuff if we are XEmacs
143 (when (featurep 'xemacs
)
148 (require 'regexp-opt
)
150 ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
157 (defmacro when
(cond &rest body
)
158 (list 'if cond
(cons 'progn body
))))
161 (if (fboundp 'unless
)
163 (defmacro unless
(cond &rest body
)
164 (cons 'if
(cons cond
(cons nil body
)))))
167 (if (fboundp 'store-match-data
)
169 (defmacro store-match-data
(&rest args
) nil
))
172 (if (fboundp 'char-before
)
174 (defmacro char-before
(&rest body
)
175 (char-after (1- (point)))))
181 (if (fboundp 'match-string-no-properties
)
183 (defsubst match-string-no-properties
(num &optional string
)
184 "Return string of text matched by last search, without text properties.
185 NUM specifies which parenthesized expression in the last regexp.
186 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
187 Zero means the entire text matched by the whole regexp or whole string.
188 STRING should be given if the last search was by `string-match' on STRING."
189 (if (match-beginning num
)
193 (match-beginning num
) (match-end num
))))
194 (set-text-properties 0 (length result
) nil result
)
196 (buffer-substring-no-properties (match-beginning num
)
201 (if (and (featurep 'custom
) (fboundp 'custom-declare-variable
))
202 nil
;; We've got what we needed
203 ;; We have the old custom-library, hack around it!
204 (defmacro defgroup
(&rest args
) nil
)
205 (defmacro customize
(&rest args
)
207 "Sorry, Customize is not available with this version of Emacs"))
208 (defmacro defcustom
(var value doc
&rest args
)
209 `(defvar ,var
,value
,doc
))
211 (if (fboundp 'defface
)
213 (defmacro defface
(var values doc
&rest args
)
217 (if (and (featurep 'custom
) (fboundp 'customize-group
))
218 nil
;; We've got what we needed
219 ;; We have an intermediate custom-library, hack around it!
220 (defmacro customize-group
(var &rest args
)
224 (unless (boundp 'inhibit-point-motion-hooks
)
225 (defvar inhibit-point-motion-hooks nil
))
226 (unless (boundp 'deactivate-mark
)
227 (defvar deactivate-mark nil
))
230 ;; OK, do this stuff if we are NOT XEmacs:
231 (unless (featurep 'xemacs
)
232 (unless (fboundp 'region-active-p
)
233 (defmacro region-active-p
()
234 `(and transient-mark-mode mark-active
))))
237 ;; Provide a regular expression optimization routine, using regexp-opt
238 ;; if provided by the user's elisp libraries
240 ;; The below were disabled when GNU Emacs 22 was released;
241 ;; perhaps some still need to be there to support Emacs 21.
242 (if (featurep 'xemacs
)
243 (if (fboundp 'regexp-opt
)
244 ;; regexp-opt is defined, does it take 3 or 2 arguments?
245 (if (fboundp 'function-max-args
)
246 (let ((args (function-max-args `regexp-opt
)))
248 ((eq args
3) ;; It takes 3
249 (condition-case nil
; Hide this defun from emacses
250 ;with just a two input regexp
251 (defun verilog-regexp-opt (a b
)
252 "Deal with differing number of required arguments for `regexp-opt'.
253 Call 'regexp-opt' on A and B."
257 ((eq args
2) ;; It takes 2
258 (defun verilog-regexp-opt (a b
)
259 "Call 'regexp-opt' on A and B."
263 ;; We can't tell; assume it takes 2
264 (defun verilog-regexp-opt (a b
)
265 "Call 'regexp-opt' on A and B."
268 ;; There is no regexp-opt, provide our own
269 (defun verilog-regexp-opt (strings &optional paren shy
)
270 (let ((open (if paren
"\\(" "")) (close (if paren
"\\)" "")))
271 (concat open
(mapconcat 'regexp-quote strings
"\\|") close
)))
274 (defalias 'verilog-regexp-opt
'regexp-opt
)))
277 ;; Both xemacs and emacs
279 (unless (fboundp 'buffer-chars-modified-tick
) ;; Emacs 22 added
280 (defmacro buffer-chars-modified-tick
() (buffer-modified-tick)))
284 (defun verilog-regexp-words (a)
285 "Call 'regexp-opt' with word delimiters for the words A."
286 (concat "\\<" (verilog-regexp-opt a t
) "\\>")))
287 (defun verilog-regexp-words (a)
288 "Call 'regexp-opt' with word delimiters for the words A."
289 ;; The FAQ references this function, so user LISP sometimes calls it
290 (concat "\\<" (verilog-regexp-opt a t
) "\\>"))
292 (defun verilog-easy-menu-filter (menu)
293 "Filter `easy-menu-define' MENU to support new features."
294 (cond ((not (featurep 'xemacs
))
295 menu
) ;; GNU Emacs - passthru
296 ;; Xemacs doesn't support :help. Strip it.
297 ;; Recursively filter the a submenu
299 (mapcar 'verilog-easy-menu-filter menu
))
300 ;; Look for [:help "blah"] and remove
302 (let ((i 0) (out []))
303 (while (< i
(length menu
))
304 (if (equal `:help
(aref menu i
))
306 (setq out
(vconcat out
(vector (aref menu i
)))
309 (t menu
))) ;; Default - ok
310 ;;(verilog-easy-menu-filter
311 ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
312 ;; "----" ["MB" nil :help "Help MB"]))
314 (defun verilog-customize ()
315 "Customize variables and other settings used by Verilog-Mode."
317 (customize-group 'verilog-mode
))
319 (defun verilog-font-customize ()
320 "Customize fonts used by Verilog-Mode."
322 (if (fboundp 'customize-apropos
)
323 (customize-apropos "font-lock-*" 'faces
)))
325 (defun verilog-booleanp (value)
326 "Return t if VALUE is boolean.
327 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
328 This function may be removed when Emacs 21 is no longer supported."
329 (or (equal value t
) (equal value nil
)))
331 (defun verilog-insert-last-command-event ()
332 "Insert the `last-command-event'."
333 (insert (if (featurep 'xemacs
)
334 ;; XEmacs 21.5 doesn't like last-command-event
336 ;; And GNU Emacs 22 has obsoleted last-command-char
337 last-command-event
)))
339 (defalias 'verilog-syntax-ppss
340 (if (fboundp 'syntax-ppss
) 'syntax-ppss
341 (lambda (&optional pos
) (parse-partial-sexp (point-min) (or pos
(point))))))
343 (defgroup verilog-mode nil
344 "Facilitates easy editing of Verilog source text."
348 ; (defgroup verilog-mode-fonts nil
349 ; "Facilitates easy customization fonts used in Verilog source text"
350 ; :link '(customize-apropos "font-lock-*" 'faces)
351 ; :group 'verilog-mode)
353 (defgroup verilog-mode-indent nil
354 "Customize indentation and highlighting of Verilog source text."
355 :group
'verilog-mode
)
357 (defgroup verilog-mode-actions nil
358 "Customize actions on Verilog source text."
359 :group
'verilog-mode
)
361 (defgroup verilog-mode-auto nil
362 "Customize AUTO actions when expanding Verilog source text."
363 :group
'verilog-mode
)
365 (defvar verilog-debug nil
366 "If set, enable debug messages for `verilog-mode' internals.")
368 (defcustom verilog-linter
369 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
370 "*Unix program and arguments to call to run a lint checker on Verilog source.
371 Depending on the `verilog-set-compile-command', this may be invoked when
372 you type \\[compile]. When the compile completes, \\[next-error] will take
373 you to the next lint error."
375 :group
'verilog-mode-actions
)
376 ;; We don't mark it safe, as it's used as a shell command
378 (defcustom verilog-coverage
379 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
380 "*Program and arguments to use to annotate for coverage Verilog source.
381 Depending on the `verilog-set-compile-command', this may be invoked when
382 you type \\[compile]. When the compile completes, \\[next-error] will take
383 you to the next lint error."
385 :group
'verilog-mode-actions
)
386 ;; We don't mark it safe, as it's used as a shell command
388 (defcustom verilog-simulator
389 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
390 "*Program and arguments to use to interpret Verilog source.
391 Depending on the `verilog-set-compile-command', this may be invoked when
392 you type \\[compile]. When the compile completes, \\[next-error] will take
393 you to the next lint error."
395 :group
'verilog-mode-actions
)
396 ;; We don't mark it safe, as it's used as a shell command
398 (defcustom verilog-compiler
399 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
400 "*Program and arguments to use to compile Verilog source.
401 Depending on the `verilog-set-compile-command', this may be invoked when
402 you type \\[compile]. When the compile completes, \\[next-error] will take
403 you to the next lint error."
405 :group
'verilog-mode-actions
)
406 ;; We don't mark it safe, as it's used as a shell command
408 (defcustom verilog-preprocessor
409 ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
410 "vppreproc __FLAGS__ __FILE__"
411 "*Program and arguments to use to preprocess Verilog source.
412 This is invoked with `verilog-preprocess', and depending on the
413 `verilog-set-compile-command', may also be invoked when you type
414 \\[compile]. When the compile completes, \\[next-error] will
415 take you to the next lint error."
417 :group
'verilog-mode-actions
)
418 ;; We don't mark it safe, as it's used as a shell command
420 (defvar verilog-preprocess-history nil
421 "History for `verilog-preprocess'.")
423 (defvar verilog-tool
'verilog-linter
424 "Which tool to use for building compiler-command.
425 Either nil, `verilog-linter, `verilog-compiler,
426 `verilog-coverage, `verilog-preprocessor, or `verilog-simulator.
427 Alternatively use the \"Choose Compilation Action\" menu. See
428 `verilog-set-compile-command' for more information.")
430 (defcustom verilog-highlight-translate-off nil
431 "*Non-nil means background-highlight code excluded from translation.
432 That is, all code between \"// synopsys translate_off\" and
433 \"// synopsys translate_on\" is highlighted using a different background color
434 \(face `verilog-font-lock-translate-off-face').
436 Note: This will slow down on-the-fly fontification (and thus editing).
438 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
439 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
441 :group
'verilog-mode-indent
)
442 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
443 (put 'verilog-highlight-translate-off
'safe-local-variable
'verilog-booleanp
)
445 (defcustom verilog-auto-lineup
'declarations
446 "*Type of statements to lineup across multiple lines.
447 If 'all' is selected, then all line ups described below are done.
449 If 'declaration', then just declarations are lined up with any
450 preceding declarations, taking into account widths and the like,
451 so or example the code:
458 If 'assignment', then assignments are lined up with any preceding
459 assignments, so for example the code
460 a_long_variable <= b + c;
463 a_long_variable <= b + c;
466 In order to speed up editing, large blocks of statements are lined up
467 only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
468 are lineup only when \\[verilog-pretty-declarations] is typed."
470 :type
'(radio (const :tag
"Line up Assignments and Declarations" all
)
471 (const :tag
"Line up Assignment statements" assignments
)
472 (const :tag
"Line up Declarations" declarations
)
473 (function :tag
"Other"))
474 :group
'verilog-mode-indent
)
476 (defcustom verilog-indent-level
3
477 "*Indentation of Verilog statements with respect to containing block."
478 :group
'verilog-mode-indent
480 (put 'verilog-indent-level
'safe-local-variable
'integerp
)
482 (defcustom verilog-indent-level-module
3
483 "*Indentation of Module level Verilog statements (eg always, initial).
484 Set to 0 to get initial and always statements lined up on the left side of
486 :group
'verilog-mode-indent
488 (put 'verilog-indent-level-module
'safe-local-variable
'integerp
)
490 (defcustom verilog-indent-level-declaration
3
491 "*Indentation of declarations with respect to containing block.
492 Set to 0 to get them list right under containing block."
493 :group
'verilog-mode-indent
495 (put 'verilog-indent-level-declaration
'safe-local-variable
'integerp
)
497 (defcustom verilog-indent-declaration-macros nil
498 "*How to treat macro expansions in a declaration.
503 If non nil, treat as:
507 :group
'verilog-mode-indent
509 (put 'verilog-indent-declaration-macros
'safe-local-variable
'verilog-booleanp
)
511 (defcustom verilog-indent-lists t
512 "*How to treat indenting items in a list.
513 If t (the default), indent as:
514 always @( posedge a or
518 always @( posedge a or
520 :group
'verilog-mode-indent
522 (put 'verilog-indent-lists
'safe-local-variable
'verilog-booleanp
)
524 (defcustom verilog-indent-level-behavioral
3
525 "*Absolute indentation of first begin in a task or function block.
526 Set to 0 to get such code to start at the left side of the screen."
527 :group
'verilog-mode-indent
529 (put 'verilog-indent-level-behavioral
'safe-local-variable
'integerp
)
531 (defcustom verilog-indent-level-directive
1
532 "*Indentation to add to each level of `ifdef declarations.
533 Set to 0 to have all directives start at the left side of the screen."
534 :group
'verilog-mode-indent
536 (put 'verilog-indent-level-directive
'safe-local-variable
'integerp
)
538 (defcustom verilog-cexp-indent
2
539 "*Indentation of Verilog statements split across lines."
540 :group
'verilog-mode-indent
542 (put 'verilog-cexp-indent
'safe-local-variable
'integerp
)
544 (defcustom verilog-case-indent
2
545 "*Indentation for case statements."
546 :group
'verilog-mode-indent
548 (put 'verilog-case-indent
'safe-local-variable
'integerp
)
550 (defcustom verilog-auto-newline t
551 "*True means automatically newline after semicolons."
552 :group
'verilog-mode-indent
554 (put 'verilog-auto-newline
'safe-local-variable
'verilog-booleanp
)
556 (defcustom verilog-auto-indent-on-newline t
557 "*True means automatically indent line after newline."
558 :group
'verilog-mode-indent
560 (put 'verilog-auto-indent-on-newline
'safe-local-variable
'verilog-booleanp
)
562 (defcustom verilog-tab-always-indent t
563 "*True means TAB should always re-indent the current line.
564 A nil value means TAB will only reindent when at the beginning of the line."
565 :group
'verilog-mode-indent
567 (put 'verilog-tab-always-indent
'safe-local-variable
'verilog-booleanp
)
569 (defcustom verilog-tab-to-comment nil
570 "*True means TAB moves to the right hand column in preparation for a comment."
571 :group
'verilog-mode-actions
573 (put 'verilog-tab-to-comment
'safe-local-variable
'verilog-booleanp
)
575 (defcustom verilog-indent-begin-after-if t
576 "*If true, indent begin statements following if, else, while, for and repeat.
577 Otherwise, line them up."
578 :group
'verilog-mode-indent
580 (put 'verilog-indent-begin-after-if
'safe-local-variable
'verilog-booleanp
)
583 (defcustom verilog-align-ifelse nil
584 "*If true, align `else' under matching `if'.
585 Otherwise else is lined up with first character on line holding matching if."
586 :group
'verilog-mode-indent
588 (put 'verilog-align-ifelse
'safe-local-variable
'verilog-booleanp
)
590 (defcustom verilog-minimum-comment-distance
10
591 "*Minimum distance (in lines) between begin and end required before a comment.
592 Setting this variable to zero results in every end acquiring a comment; the
593 default avoids too many redundant comments in tight quarters."
594 :group
'verilog-mode-indent
596 (put 'verilog-minimum-comment-distance
'safe-local-variable
'integerp
)
598 (defcustom verilog-highlight-p1800-keywords nil
599 "*True means highlight words newly reserved by IEEE-1800.
600 These will appear in `verilog-font-lock-p1800-face' in order to gently
601 suggest changing where these words are used as variables to something else.
602 A nil value means highlight these words as appropriate for the SystemVerilog
603 IEEE-1800 standard. Note that changing this will require restarting Emacs
604 to see the effect as font color choices are cached by Emacs."
605 :group
'verilog-mode-indent
607 (put 'verilog-highlight-p1800-keywords
'safe-local-variable
'verilog-booleanp
)
609 (defcustom verilog-highlight-grouping-keywords nil
610 "*True means highlight grouping keywords 'begin' and 'end' more dramatically.
611 If false, these words are in the `font-lock-type-face'; if True then they are in
612 `verilog-font-lock-ams-face'. Some find that special highlighting on these
613 grouping constructs allow the structure of the code to be understood at a glance."
614 :group
'verilog-mode-indent
616 (put 'verilog-highlight-grouping-keywords
'safe-local-variable
'verilog-booleanp
)
618 (defcustom verilog-highlight-modules nil
619 "*True means highlight module statements for `verilog-load-file-at-point'.
620 When true, mousing over module names will allow jumping to the
621 module definition. If false, this is not supported. Setting
622 this is experimental, and may lead to bad performance."
623 :group
'verilog-mode-indent
625 (put 'verilog-highlight-modules
'safe-local-variable
'verilog-booleanp
)
627 (defcustom verilog-highlight-includes t
628 "*True means highlight module statements for `verilog-load-file-at-point'.
629 When true, mousing over include file names will allow jumping to the
630 file referenced. If false, this is not supported."
631 :group
'verilog-mode-indent
633 (put 'verilog-highlight-includes
'safe-local-variable
'verilog-booleanp
)
635 (defcustom verilog-auto-endcomments t
636 "*True means insert a comment /* ... */ after 'end's.
637 The name of the function or case will be set between the braces."
638 :group
'verilog-mode-actions
640 (put 'verilog-auto-endcomments
'safe-local-variable
'verilog-booleanp
)
642 (defcustom verilog-auto-ignore-concat nil
643 "*True means ignore signals in {...} concatenations for AUTOWIRE etc.
644 This will exclude signals referenced as pin connections in {...}
645 from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
646 for backward compatibility only and not set in new designs; it
647 may be removed in future versions."
648 :group
'verilog-mode-actions
650 (put 'verilog-auto-ignore-concat
'safe-local-variable
'verilog-booleanp
)
652 (defcustom verilog-auto-read-includes nil
653 "*True means to automatically read includes before AUTOs.
654 This will do a `verilog-read-defines' and `verilog-read-includes' before
655 each AUTO expansion. This makes it easier to embed defines and includes,
656 but can result in very slow reading times if there are many or large
658 :group
'verilog-mode-actions
660 (put 'verilog-auto-read-includes
'safe-local-variable
'verilog-booleanp
)
662 (defcustom verilog-auto-save-policy nil
663 "*Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
664 A value of `force' will always do a \\[verilog-auto] automatically if
665 needed on every save. A value of `detect' will do \\[verilog-auto]
666 automatically when it thinks necessary. A value of `ask' will query the
667 user when it thinks updating is needed.
669 You should not rely on the 'ask or 'detect policies, they are safeguards
670 only. They do not detect when AUTOINSTs need to be updated because a
671 sub-module's port list has changed."
672 :group
'verilog-mode-actions
673 :type
'(choice (const nil
) (const ask
) (const detect
) (const force
)))
675 (defcustom verilog-auto-star-expand t
676 "*Non-nil indicates to expand a SystemVerilog .* instance ports.
677 They will be expanded in the same way as if there was a AUTOINST in the
678 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
679 :group
'verilog-mode-actions
681 (put 'verilog-auto-star-expand
'safe-local-variable
'verilog-booleanp
)
683 (defcustom verilog-auto-star-save nil
684 "*Non-nil indicates to save to disk SystemVerilog .* instance expansions.
685 A nil value indicates direct connections will be removed before saving.
686 Only meaningful to those created due to `verilog-auto-star-expand' being set.
688 Instead of setting this, you may want to use /*AUTOINST*/, which will
690 :group
'verilog-mode-actions
692 (put 'verilog-auto-star-save
'safe-local-variable
'verilog-booleanp
)
694 (defvar verilog-auto-update-tick nil
695 "Modification tick at which autos were last performed.")
697 (defvar verilog-auto-last-file-locals nil
698 "Text from file-local-variables during last evaluation.")
702 (defvar verilog-error-regexp-added nil
)
704 (defvar verilog-error-regexp-emacs-alist
707 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
709 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
711 ".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
713 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
715 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
718 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
719 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
721 "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
723 "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
725 "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
727 "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
729 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
731 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
733 "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
735 "List of regexps for Verilog compilers.
736 See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
738 (defvar verilog-error-regexp-xemacs-alist
739 ;; Emacs form is '((v-tool "re" 1 2) ...)
740 ;; XEmacs form is '(verilog ("re" 1 2) ...)
741 ;; So we can just map from Emacs to Xemacs
742 (cons 'verilog
(mapcar 'cdr verilog-error-regexp-emacs-alist
))
743 "List of regexps for Verilog compilers.
744 See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
746 (defvar verilog-error-font-lock-keywords
749 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
750 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t
)
752 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t
)
753 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t
)
754 ;; verilog-IES (nc-verilog)
755 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t
)
756 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t
)
757 ;; verilog-surefire-1
758 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t
)
759 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t
)
760 ;; verilog-surefire-2
761 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t
)
762 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t
)
765 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
766 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
768 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
769 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t
)
771 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t
)
772 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t
)
774 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
775 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t
)
777 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
778 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t
)
780 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t
)
781 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t
)
783 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t
)
784 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t
)
786 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t
)
787 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t
)
789 "*Keywords to also highlight in Verilog *compilation* buffers.
790 Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
792 (defcustom verilog-library-flags
'("")
793 "*List of standard Verilog arguments to use for /*AUTOINST*/.
794 These arguments are used to find files for `verilog-auto', and match
795 the flags accepted by a standard Verilog-XL simulator.
797 -f filename Reads more `verilog-library-flags' from the filename.
798 +incdir+dir Adds the directory to `verilog-library-directories'.
799 -Idir Adds the directory to `verilog-library-directories'.
800 -y dir Adds the directory to `verilog-library-directories'.
801 +libext+.v Adds the extensions to `verilog-library-extensions'.
802 -v filename Adds the filename to `verilog-library-files'.
804 filename Adds the filename to `verilog-library-files'.
805 This is not recommended, -v is a better choice.
807 You might want these defined in each file; put at the *END* of your file
811 // verilog-library-flags:(\"-y dir -y otherdir\")
814 Verilog-mode attempts to detect changes to this local variable, but they
815 are only insured to be correct when the file is first visited. Thus if you
816 have problems, use \\[find-alternate-file] RET to have these take effect.
818 See also the variables mentioned above."
819 :group
'verilog-mode-auto
820 :type
'(repeat string
))
821 (put 'verilog-library-flags
'safe-local-variable
'listp
)
823 (defcustom verilog-library-directories
'(".")
824 "*List of directories when looking for files for /*AUTOINST*/.
825 The directory may be relative to the current file, or absolute.
826 Environment variables are also expanded in the directory names.
827 Having at least the current directory is a good idea.
829 You might want these defined in each file; put at the *END* of your file
833 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
836 Verilog-mode attempts to detect changes to this local variable, but they
837 are only insured to be correct when the file is first visited. Thus if you
838 have problems, use \\[find-alternate-file] RET to have these take effect.
840 See also `verilog-library-flags', `verilog-library-files'
841 and `verilog-library-extensions'."
842 :group
'verilog-mode-auto
843 :type
'(repeat file
))
844 (put 'verilog-library-directories
'safe-local-variable
'listp
)
846 (defcustom verilog-library-files
'()
847 "*List of files to search for modules.
848 AUTOINST will use this when it needs to resolve a module name.
849 This is a complete path, usually to a technology file with many standard
852 You might want these defined in each file; put at the *END* of your file
856 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
859 Verilog-mode attempts to detect changes to this local variable, but they
860 are only insured to be correct when the file is first visited. Thus if you
861 have problems, use \\[find-alternate-file] RET to have these take effect.
863 See also `verilog-library-flags', `verilog-library-directories'."
864 :group
'verilog-mode-auto
865 :type
'(repeat directory
))
866 (put 'verilog-library-files
'safe-local-variable
'listp
)
868 (defcustom verilog-library-extensions
'(".v" ".sv")
869 "*List of extensions to use when looking for files for /*AUTOINST*/.
870 See also `verilog-library-flags', `verilog-library-directories'."
871 :type
'(repeat string
)
872 :group
'verilog-mode-auto
)
873 (put 'verilog-library-extensions
'safe-local-variable
'listp
)
875 (defcustom verilog-active-low-regexp nil
876 "*If set, treat signals matching this regexp as active low.
877 This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
878 you will probably also need `verilog-auto-reset-widths' set."
879 :group
'verilog-mode-auto
881 (put 'verilog-active-low-regexp
'safe-local-variable
'stringp
)
883 (defcustom verilog-auto-sense-include-inputs nil
884 "*If true, AUTOSENSE should include all inputs.
885 If nil, only inputs that are NOT output signals in the same block are
887 :group
'verilog-mode-auto
889 (put 'verilog-auto-sense-include-inputs
'safe-local-variable
'verilog-booleanp
)
891 (defcustom verilog-auto-sense-defines-constant nil
892 "*If true, AUTOSENSE should assume all defines represent constants.
893 When true, the defines will not be included in sensitivity lists. To
894 maintain compatibility with other sites, this should be set at the bottom
895 of each Verilog file that requires it, rather than being set globally."
896 :group
'verilog-mode-auto
898 (put 'verilog-auto-sense-defines-constant
'safe-local-variable
'verilog-booleanp
)
900 (defcustom verilog-auto-reset-widths t
901 "*If true, AUTORESET should determine the width of signals.
902 This is then used to set the width of the zero (32'h0 for example). This
903 is required by some lint tools that aren't smart enough to ignore widths of
904 the constant zero. This may result in ugly code when parameters determine
905 the MSB or LSB of a signal inside an AUTORESET."
907 :group
'verilog-mode-auto
)
908 (put 'verilog-auto-reset-widths
'safe-local-variable
'verilog-booleanp
)
910 (defcustom verilog-assignment-delay
""
911 "*Text used for delays in delayed assignments. Add a trailing space if set."
912 :group
'verilog-mode-auto
914 (put 'verilog-assignment-delay
'safe-local-variable
'stringp
)
916 (defcustom verilog-auto-arg-sort nil
917 "*If set, AUTOARG signal names will be sorted, not in delaration order.
918 Declaration order is advantageous with order based instantiations
919 and is the default for backward compatibility. Sorted order
920 reduces changes when declarations are moved around in a file, and
921 it's bad practice to rely on order based instantiations anyhow."
922 :group
'verilog-mode-auto
924 (put 'verilog-auto-arg-sort
'safe-local-variable
'verilog-booleanp
)
926 (defcustom verilog-auto-inst-dot-name nil
927 "*If true, when creating ports with AUTOINST, use .name syntax.
928 This will use \".port\" instead of \".port(port)\" when possible.
929 This is only legal in SystemVerilog files, and will confuse older
930 simulators. Setting `verilog-auto-inst-vector' to nil may also
931 be desirable to increase how often .name will be used."
932 :group
'verilog-mode-auto
934 (put 'verilog-auto-inst-dot-name
'safe-local-variable
'verilog-booleanp
)
936 (defcustom verilog-auto-inst-param-value nil
937 "*If set, AUTOINST will replace parameters with the parameter value.
938 If nil, leave parameters as symbolic names.
940 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
941 listed as such there (as when the default value is acceptable), it will not
942 be replaced, and will remain symbolic.
944 For example, imagine a submodule uses parameters to declare the size of its
945 inputs. This is then used by a upper module:
947 module InstModule (o,i);
959 Note even though PARAM=10, the AUTOINST has left the parameter as a
960 symbolic name. If `verilog-auto-inst-param-value' is set, this will
969 :group
'verilog-mode-auto
971 (put 'verilog-auto-inst-param-value
'safe-local-variable
'verilog-booleanp
)
973 (defcustom verilog-auto-inst-vector t
974 "*If true, when creating default ports with AUTOINST, use bus subscripts.
975 If nil, skip the subscript when it matches the entire bus as declared in
976 the module (AUTOWIRE signals always are subscripted, you must manually
977 declare the wire to have the subscripts removed.) Setting this to nil may
978 speed up some simulators, but is less general and harder to read, so avoid."
979 :group
'verilog-mode-auto
981 (put 'verilog-auto-inst-vector
'safe-local-variable
'verilog-booleanp
)
983 (defcustom verilog-auto-inst-template-numbers nil
984 "*If true, when creating templated ports with AUTOINST, add a comment.
985 The comment will add the line number of the template that was used for that
986 port declaration. Setting this aids in debugging, but nil is suggested for
987 regular use to prevent large numbers of merge conflicts."
988 :group
'verilog-mode-auto
990 (put 'verilog-auto-inst-template-numbers
'safe-local-variable
'verilog-booleanp
)
992 (defcustom verilog-auto-inst-column
40
993 "*Indent-to column number for net name part of AUTOINST created pin."
994 :group
'verilog-mode-indent
996 (put 'verilog-auto-inst-column
'safe-local-variable
'integerp
)
998 (defcustom verilog-auto-input-ignore-regexp nil
999 "*If set, when creating AUTOINPUT list, ignore signals matching this regexp.
1000 See the \\[verilog-faq] for examples on using this."
1001 :group
'verilog-mode-auto
1003 (put 'verilog-auto-input-ignore-regexp
'safe-local-variable
'stringp
)
1005 (defcustom verilog-auto-inout-ignore-regexp nil
1006 "*If set, when creating AUTOINOUT list, ignore signals matching this regexp.
1007 See the \\[verilog-faq] for examples on using this."
1008 :group
'verilog-mode-auto
1010 (put 'verilog-auto-inout-ignore-regexp
'safe-local-variable
'stringp
)
1012 (defcustom verilog-auto-output-ignore-regexp nil
1013 "*If set, when creating AUTOOUTPUT list, ignore signals matching this regexp.
1014 See the \\[verilog-faq] for examples on using this."
1015 :group
'verilog-mode-auto
1017 (put 'verilog-auto-output-ignore-regexp
'safe-local-variable
'stringp
)
1019 (defcustom verilog-auto-tieoff-ignore-regexp nil
1020 "*If set, when creating AUTOTIEOFF list, ignore signals matching this regexp.
1021 See the \\[verilog-faq] for examples on using this."
1022 :group
'verilog-mode-auto
1024 (put 'verilog-auto-tieoff-ignore-regexp
'safe-local-variable
'stringp
)
1026 (defcustom verilog-auto-unused-ignore-regexp nil
1027 "*If set, when creating AUTOUNUSED list, ignore signals matching this regexp.
1028 See the \\[verilog-faq] for examples on using this."
1029 :group
'verilog-mode-auto
1031 (put 'verilog-auto-unused-ignore-regexp
'safe-local-variable
'stringp
)
1033 (defcustom verilog-typedef-regexp nil
1034 "*If non-nil, regular expression that matches Verilog-2001 typedef names.
1035 For example, \"_t$\" matches typedefs named with _t, as in the C language."
1036 :group
'verilog-mode-auto
1038 (put 'verilog-typedef-regexp
'safe-local-variable
'stringp
)
1040 (defcustom verilog-mode-hook
'verilog-set-compile-command
1041 "*Hook run after Verilog mode is loaded."
1043 :group
'verilog-mode
)
1045 (defcustom verilog-auto-hook nil
1046 "*Hook run after `verilog-mode' updates AUTOs."
1047 :group
'verilog-mode-auto
1050 (defcustom verilog-before-auto-hook nil
1051 "*Hook run before `verilog-mode' updates AUTOs."
1052 :group
'verilog-mode-auto
1055 (defcustom verilog-delete-auto-hook nil
1056 "*Hook run after `verilog-mode' deletes AUTOs."
1057 :group
'verilog-mode-auto
1060 (defcustom verilog-before-delete-auto-hook nil
1061 "*Hook run before `verilog-mode' deletes AUTOs."
1062 :group
'verilog-mode-auto
1065 (defcustom verilog-getopt-flags-hook nil
1066 "*Hook run after `verilog-getopt-flags' determines the Verilog option lists."
1067 :group
'verilog-mode-auto
1070 (defcustom verilog-before-getopt-flags-hook nil
1071 "*Hook run before `verilog-getopt-flags' determines the Verilog option lists."
1072 :group
'verilog-mode-auto
1075 (defvar verilog-imenu-generic-expression
1076 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
1077 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
1078 "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
1081 ;; provide a verilog-header function.
1082 ;; Customization variables:
1084 (defvar verilog-date-scientific-format nil
1085 "*If non-nil, dates are written in scientific format (e.g. 1997/09/17).
1086 If nil, in European format (e.g. 17.09.1997). The brain-dead American
1087 format (e.g. 09/17/1997) is not supported.")
1089 (defvar verilog-company nil
1090 "*Default name of Company for Verilog header.
1091 If set will become buffer local.")
1092 (make-variable-buffer-local 'verilog-company
)
1094 (defvar verilog-project nil
1095 "*Default name of Project for Verilog header.
1096 If set will become buffer local.")
1097 (make-variable-buffer-local 'verilog-project
)
1099 (defvar verilog-mode-map
1100 (let ((map (make-sparse-keymap)))
1101 (define-key map
";" 'electric-verilog-semi
)
1102 (define-key map
[(control 59)] 'electric-verilog-semi-with-comment
)
1103 (define-key map
":" 'electric-verilog-colon
)
1104 ;;(define-key map "=" 'electric-verilog-equal)
1105 (define-key map
"\`" 'electric-verilog-tick
)
1106 (define-key map
"\t" 'electric-verilog-tab
)
1107 (define-key map
"\r" 'electric-verilog-terminate-line
)
1108 ;; backspace/delete key bindings
1109 (define-key map
[backspace] 'backward-delete-char-untabify)
1110 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
1111 (define-key map [delete] 'delete-char)
1112 (define-key map [(meta delete)] 'kill-word))
1113 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
1114 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
1115 (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
1116 (define-key map "\M-\t" 'verilog-complete-word)
1117 (define-key map "\M-?" 'verilog-show-completions)
1118 (define-key map "\C-c\`" 'verilog-lint-off)
1119 (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit)
1120 (define-key map "\C-c\C-r" 'verilog-label-be)
1121 (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
1122 (define-key map "\C-c=" 'verilog-pretty-expr)
1123 (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
1124 (define-key map "\M-*" 'verilog-star-comment)
1125 (define-key map "\C-c\C-c" 'verilog-comment-region)
1126 (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1127 (when (featurep 'xemacs)
1128 (define-key map [(meta control h)] 'verilog-mark-defun)
1129 (define-key map "\M-\C-a" 'verilog-beg-of-defun)
1130 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1131 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1132 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1133 (define-key map "\C-c\C-a" 'verilog-auto)
1134 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1135 (define-key map "\C-c\C-p" 'verilog-preprocess)
1136 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1137 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1138 (define-key map "\C-c\C-h" 'verilog-header)
1140 "Keymap used in Verilog mode.")
1144 verilog-menu verilog-mode-map "Menu for Verilog mode"
1145 (verilog-easy-menu-filter
1147 ("Choose Compilation Action"
1150 (setq verilog-tool nil)
1151 (verilog-set-compile-command))
1153 :selected (equal verilog-tool nil)
1154 :help "When invoking compilation, use compile-command"]
1157 (setq verilog-tool 'verilog-linter)
1158 (verilog-set-compile-command))
1160 :selected (equal verilog-tool `verilog-linter)
1161 :help "When invoking compilation, use lint checker"]
1164 (setq verilog-tool 'verilog-coverage)
1165 (verilog-set-compile-command))
1167 :selected (equal verilog-tool `verilog-coverage)
1168 :help "When invoking compilation, annotate for coverage"]
1171 (setq verilog-tool 'verilog-simulator)
1172 (verilog-set-compile-command))
1174 :selected (equal verilog-tool `verilog-simulator)
1175 :help "When invoking compilation, interpret Verilog source"]
1178 (setq verilog-tool 'verilog-compiler)
1179 (verilog-set-compile-command))
1181 :selected (equal verilog-tool `verilog-compiler)
1182 :help "When invoking compilation, compile Verilog source"]
1185 (setq verilog-tool 'verilog-preprocessor)
1186 (verilog-set-compile-command))
1188 :selected (equal verilog-tool `verilog-preprocessor)
1189 :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1192 ["Beginning of function" verilog-beg-of-defun
1194 :help "Move backward to the beginning of the current function or procedure"]
1195 ["End of function" verilog-end-of-defun
1197 :help "Move forward to the end of the current function or procedure"]
1198 ["Mark function" verilog-mark-defun
1200 :help "Mark the current Verilog function or procedure"]
1201 ["Goto function/module" verilog-goto-defun
1202 :help "Move to specified Verilog module/task/function"]
1203 ["Move to beginning of block" electric-verilog-backward-sexp
1204 :help "Move backward over one balanced expression"]
1205 ["Move to end of block" electric-verilog-forward-sexp
1206 :help "Move forward over one balanced expression"]
1209 ["Comment Region" verilog-comment-region
1210 :help "Put marked area into a comment"]
1211 ["UnComment Region" verilog-uncomment-region
1212 :help "Uncomment an area commented with Comment Region"]
1213 ["Multi-line comment insert" verilog-star-comment
1214 :help "Insert Verilog /* */ comment at point"]
1215 ["Lint error to comment" verilog-lint-off
1216 :help "Convert a Verilog linter warning line into a disable statement"]
1220 :help "Perform compilation-action (above) on the current buffer"]
1221 ["AUTO, Save, Compile" verilog-auto-save-compile
1222 :help "Recompute AUTOs, save buffer, and compile"]
1223 ["Next Compile Error" next-error
1224 :help "Visit next compilation error message and corresponding source code"]
1225 ["Ignore Lint Warning at point" verilog-lint-off
1226 :help "Convert a Verilog linter warning line into a disable statement"]
1228 ["Line up declarations around point" verilog-pretty-declarations
1229 :help "Line up declarations around point"]
1230 ["Line up equations around point" verilog-pretty-expr
1231 :help "Line up expressions around point"]
1232 ["Redo/insert comments on every end" verilog-label-be
1233 :help "Label matching begin ... end statements"]
1234 ["Expand [x:y] vector line" verilog-expand-vector
1235 :help "Take a signal vector on the current line and expand it to multiple lines"]
1236 ["Insert begin-end block" verilog-insert-block
1237 :help "Insert begin ... end"]
1238 ["Complete word" verilog-complete-word
1239 :help "Complete word at point"]
1241 ["Recompute AUTOs" verilog-auto
1242 :help "Expand AUTO meta-comment statements"]
1243 ["Kill AUTOs" verilog-delete-auto
1244 :help "Remove AUTO expansions"]
1245 ["Inject AUTOs" verilog-inject-auto
1246 :help "Inject AUTOs into legacy non-AUTO buffer"]
1248 ["AUTO General" (describe-function 'verilog-auto)
1249 :help "Help introduction on AUTOs"]
1250 ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
1251 :help "Help on verilog-library-flags"]
1252 ["AUTO Library Path" (describe-variable 'verilog-library-directories)
1253 :help "Help on verilog-library-directories"]
1254 ["AUTO Library Files" (describe-variable 'verilog-library-files)
1255 :help "Help on verilog-library-files"]
1256 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
1257 :help "Help on verilog-library-extensions"]
1258 ["AUTO `define Reading" (describe-function 'verilog-read-defines)
1259 :help "Help on reading `defines"]
1260 ["AUTO `include Reading" (describe-function 'verilog-read-includes)
1261 :help "Help on parsing `includes"]
1262 ["AUTOARG" (describe-function 'verilog-auto-arg)
1263 :help "Help on AUTOARG - declaring module port list"]
1264 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
1265 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1266 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
1267 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1268 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1269 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1270 ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
1271 :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
1272 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1273 :help "Help on AUTOINOUT - adding inouts from cells"]
1274 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1275 :help "Help on AUTOINPUT - adding inputs from cells"]
1276 ["AUTOINST" (describe-function 'verilog-auto-inst)
1277 :help "Help on AUTOINST - adding pins for cells"]
1278 ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
1279 :help "Help on expanding Verilog-2001 .* pins"]
1280 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
1281 :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
1282 ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
1283 :help "Help on AUTOOUTPUT - adding outputs from cells"]
1284 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
1285 :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
1286 ["AUTOREG" (describe-function 'verilog-auto-reg)
1287 :help "Help on AUTOREG - declaring registers for non-wires"]
1288 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
1289 :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
1290 ["AUTORESET" (describe-function 'verilog-auto-reset)
1291 :help "Help on AUTORESET - resetting always blocks"]
1292 ["AUTOSENSE" (describe-function 'verilog-auto-sense)
1293 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1294 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1295 :help "Help on AUTOTIEOFF - tieing off unused outputs"]
1296 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1297 :help "Help on AUTOUNUSED - terminating unused inputs"]
1298 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
1299 :help "Help on AUTOWIRE - declaring wires for cells"]
1302 ["Submit bug report" verilog-submit-bug-report
1303 :help "Submit via mail a bug report on verilog-mode.el"]
1304 ["Version and FAQ" verilog-faq
1305 :help "Show the current version, and where to get the FAQ etc"]
1306 ["Customize Verilog Mode..." verilog-customize
1307 :help "Customize variables and other settings used by Verilog-Mode"]
1308 ["Customize Verilog Fonts & Colors" verilog-font-customize
1309 :help "Customize fonts used by Verilog-Mode."])))
1312 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1313 (verilog-easy-menu-filter
1315 ["Header" verilog-sk-header
1316 :help "Insert a header block at the top of file"]
1317 ["Comment" verilog-sk-comment
1318 :help "Insert a comment block"]
1320 ["Module" verilog-sk-module
1321 :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
1322 ["Primitive" verilog-sk-primitive
1323 :help "Insert a primitive .. (.. );.. endprimitive block"]
1325 ["Input" verilog-sk-input
1326 :help "Insert an input declaration"]
1327 ["Output" verilog-sk-output
1328 :help "Insert an output declaration"]
1329 ["Inout" verilog-sk-inout
1330 :help "Insert an inout declaration"]
1331 ["Wire" verilog-sk-wire
1332 :help "Insert a wire declaration"]
1333 ["Reg" verilog-sk-reg
1334 :help "Insert a register declaration"]
1335 ["Define thing under point as a register" verilog-sk-define-signal
1336 :help "Define signal under point as a register at the top of the module"]
1338 ["Initial" verilog-sk-initial
1339 :help "Insert an initial begin .. end block"]
1340 ["Always" verilog-sk-always
1341 :help "Insert an always @(AS) begin .. end block"]
1342 ["Function" verilog-sk-function
1343 :help "Insert a function .. begin .. end endfunction block"]
1344 ["Task" verilog-sk-task
1345 :help "Insert a task .. begin .. end endtask block"]
1346 ["Specify" verilog-sk-specify
1347 :help "Insert a specify .. endspecify block"]
1348 ["Generate" verilog-sk-generate
1349 :help "Insert a generate .. endgenerate block"]
1351 ["Begin" verilog-sk-begin
1352 :help "Insert a begin .. end block"]
1354 :help "Insert an if (..) begin .. end block"]
1355 ["(if) else" verilog-sk-else-if
1356 :help "Insert an else if (..) begin .. end block"]
1357 ["For" verilog-sk-for
1358 :help "Insert a for (...) begin .. end block"]
1359 ["While" verilog-sk-while
1360 :help "Insert a while (...) begin .. end block"]
1361 ["Fork" verilog-sk-fork
1362 :help "Insert a fork begin .. end .. join block"]
1363 ["Repeat" verilog-sk-repeat
1364 :help "Insert a repeat (..) begin .. end block"]
1365 ["Case" verilog-sk-case
1366 :help "Insert a case block, prompting for details"]
1367 ["Casex" verilog-sk-casex
1368 :help "Insert a casex (...) item: begin.. end endcase block"]
1369 ["Casez" verilog-sk-casez
1370 :help "Insert a casez (...) item: begin.. end endcase block"])))
1372 (defvar verilog-mode-abbrev-table nil
1373 "Abbrev table in use in Verilog-mode buffers.")
1375 (define-abbrev-table 'verilog-mode-abbrev-table ())
1381 (defsubst verilog-get-beg-of-line (&optional arg)
1383 (beginning-of-line arg)
1386 (defsubst verilog-get-end-of-line (&optional arg)
1391 (defsubst verilog-within-string ()
1393 (nth 3 (parse-partial-sexp (verilog-get-beg-of-line) (point)))))
1395 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1396 "Replace occurrences of FROM-STRING with TO-STRING.
1397 FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace.
1398 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1399 will break, as the o's continuously replace. xa -> x works ok though."
1400 ;; Hopefully soon to a emacs built-in
1402 (while (string-match from-string string start)
1403 (setq string (replace-match to-string fixedcase literal string)
1404 start (min (length string) (+ (match-beginning 0) (length to-string)))))
1407 (defsubst verilog-string-remove-spaces (string)
1408 "Remove spaces surrounding STRING."
1410 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
1411 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
1414 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
1415 ; checkdoc-params: (REGEXP BOUND NOERROR)
1416 "Like `re-search-forward', but skips over match in comments or strings."
1417 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1419 (re-search-forward REGEXP BOUND NOERROR)
1420 (setq mdata (match-data))
1421 (and (verilog-skip-forward-comment-or-string)
1423 (setq mdata '(nil nil))
1427 (store-match-data mdata)
1430 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
1431 ; checkdoc-params: (REGEXP BOUND NOERROR)
1432 "Like `re-search-backward', but skips over match in comments or strings."
1433 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1435 (re-search-backward REGEXP BOUND NOERROR)
1436 (setq mdata (match-data))
1437 (and (verilog-skip-backward-comment-or-string)
1439 (setq mdata '(nil nil))
1443 (store-match-data mdata)
1446 (defsubst verilog-re-search-forward-quick (regexp bound noerror)
1447 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
1448 but trashes match data and is faster for REGEXP that doesn't match often.
1449 This may at some point use text properties to ignore comments,
1450 so there may be a large up front penalty for the first search."
1452 (while (and (not pt)
1453 (re-search-forward regexp bound noerror))
1454 (if (not (verilog-inside-comment-p))
1455 (setq pt (match-end 0))))
1458 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
1459 ; checkdoc-params: (REGEXP BOUND NOERROR)
1460 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
1461 but trashes match data and is faster for REGEXP that doesn't match often.
1462 This may at some point use text properties to ignore comments,
1463 so there may be a large up front penalty for the first search."
1465 (while (and (not pt)
1466 (re-search-backward regexp bound noerror))
1467 (if (not (verilog-inside-comment-p))
1468 (setq pt (match-end 0))))
1471 (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
1472 "Like `re-search-forward', but first search for SUBSTR constant.
1473 Then searched for the normal REGEXP (which contains SUBSTR), with given
1474 BOUND and NOERROR. The REGEXP must fit within a single line.
1475 This speeds up complicated regexp matches."
1476 ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
1477 ;; thus require matches to be on one line, and use beginning-of-line.
1479 (while (and (not done)
1480 (search-forward substr bound noerror))
1483 (setq done (re-search-forward regexp (verilog-get-end-of-line) noerror)))
1484 (unless (and (<= (match-beginning 0) (point))
1485 (>= (match-end 0) (point)))
1487 (when done (goto-char done))
1489 ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1491 (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
1492 "Like `re-search-backward', but first search for SUBSTR constant.
1493 Then searched for the normal REGEXP (which contains SUBSTR), with given
1494 BOUND and NOERROR. The REGEXP must fit within a single line.
1495 This speeds up complicated regexp matches."
1496 ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
1497 ;; thus require matches to be on one line, and use beginning-of-line.
1499 (while (and (not done)
1500 (search-backward substr bound noerror))
1503 (setq done (re-search-backward regexp (verilog-get-beg-of-line) noerror)))
1504 (unless (and (<= (match-beginning 0) (point))
1505 (>= (match-end 0) (point)))
1507 (when done (goto-char done))
1509 ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1511 (defvar compile-command)
1513 ;; compilation program
1514 (defun verilog-set-compile-command ()
1515 "Function to compute shell command to compile Verilog.
1517 This reads `verilog-tool' and sets `compile-command'. This specifies the
1518 program that executes when you type \\[compile] or
1519 \\[verilog-auto-save-compile].
1521 By default `verilog-tool' uses a Makefile if one exists in the
1522 current directory. If not, it is set to the `verilog-linter',
1523 `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
1524 or `verilog-simulator' variables, as selected with the Verilog ->
1525 \"Choose Compilation Action\" menu.
1527 You should set `verilog-tool' or the other variables to the path and
1528 arguments for your Verilog simulator. For example:
1531 \"(cd /tmp; surecov %s)\".
1533 In the former case, the path to the current buffer is concat'ed to the
1534 value of `verilog-tool'; in the later, the path to the current buffer is
1535 substituted for the %s.
1537 Where __FLAGS__ appears in the string `verilog-current-flags'
1538 will be substituted.
1540 Where __FILE__ appears in the string, the variable
1541 `buffer-file-name' of the current buffer, without the directory
1542 portion, will be substituted."
1545 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1546 (file-exists-p "Makefile"))
1547 (make-local-variable 'compile-command)
1548 (setq compile-command "make "))
1550 (make-local-variable 'compile-command)
1551 (setq compile-command
1553 (if (string-match "%s" (eval verilog-tool))
1554 (format (eval verilog-tool) (or buffer-file-name ""))
1555 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1557 (verilog-modify-compile-command))
1559 (defun verilog-expand-command (command)
1560 "Replace meta-information in COMMAND and return it.
1561 Where __FLAGS__ appears in the string `verilog-current-flags'
1562 will be substituted. Where __FILE__ appears in the string, the
1563 current buffer's file-name, without the directory portion, will
1565 (setq command (verilog-string-replace-matches
1566 ;; Note \\b only works if under verilog syntax table
1567 "\\b__FLAGS__\\b" (verilog-current-flags)
1569 (setq command (verilog-string-replace-matches
1570 "\\b__FILE__\\b" (file-name-nondirectory
1571 (or (buffer-file-name) ""))
1575 (defun verilog-modify-compile-command ()
1576 "Update `compile-command' using `verilog-expand-command'."
1578 (stringp compile-command)
1579 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1580 (make-local-variable 'compile-command)
1581 (setq compile-command (verilog-expand-command compile-command))))
1583 (if (featurep 'xemacs)
1584 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1585 (defun verilog-error-regexp-add-xemacs ()
1586 "Teach XEmacs about verilog errors.
1587 Called by `compilation-mode-hook'. This allows \\[next-error] to
1590 (if (boundp 'compilation-error-regexp-systems-alist)
1592 (not (equal compilation-error-regexp-systems-list 'all))
1593 (not (member compilation-error-regexp-systems-list 'verilog)))
1594 (push 'verilog compilation-error-regexp-systems-list)))
1595 (if (boundp 'compilation-error-regexp-alist-alist)
1596 (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
1597 (setcdr compilation-error-regexp-alist-alist
1598 (cons verilog-error-regexp-xemacs-alist
1599 (cdr compilation-error-regexp-alist-alist)))))
1600 (if (boundp 'compilation-font-lock-keywords)
1602 (make-local-variable 'compilation-font-lock-keywords)
1603 (setq compilation-font-lock-keywords verilog-error-font-lock-keywords)
1604 (font-lock-set-defaults)))
1605 ;; Need to re-run compilation-error-regexp builder
1606 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
1607 (compilation-build-compilation-error-regexp-alist))
1610 ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
1611 (defun verilog-error-regexp-add-emacs ()
1612 "Tell Emacs compile that we are Verilog.
1613 Called by `compilation-mode-hook'. This allows \\[next-error] to
1616 (if (boundp 'compilation-error-regexp-alist-alist)
1618 (if (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
1621 (push (car item) compilation-error-regexp-alist)
1622 (push item compilation-error-regexp-alist-alist)
1624 verilog-error-regexp-emacs-alist)))))
1626 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
1627 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
1629 (defconst verilog-directive-re
1631 (verilog-regexp-words
1633 "`case" "`default" "`define" "`else" "`elsif" "`endfor" "`endif"
1634 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
1635 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
1636 "`time_scale" "`undef" "`while" ))))
1638 (defconst verilog-directive-re-1
1639 (concat "[ \t]*" verilog-directive-re))
1641 (defconst verilog-directive-begin
1642 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
1644 (defconst verilog-directive-middle
1645 "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
1647 (defconst verilog-directive-end
1648 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
1650 (defconst verilog-ovm-begin-re
1654 "`ovm_component_utils_begin"
1655 "`ovm_component_param_utils_begin"
1656 "`ovm_field_utils_begin"
1657 "`ovm_object_utils_begin"
1658 "`ovm_object_param_utils_begin"
1659 "`ovm_sequence_utils_begin"
1660 "`ovm_sequencer_utils_begin"
1663 (defconst verilog-ovm-end-re
1667 "`ovm_component_utils_end"
1668 "`ovm_field_utils_end"
1669 "`ovm_object_utils_end"
1670 "`ovm_sequence_utils_end"
1671 "`ovm_sequencer_utils_end"
1674 (defconst verilog-vmm-begin-re
1678 "`vmm_data_member_begin"
1679 "`vmm_env_member_begin"
1680 "`vmm_scenario_member_begin"
1681 "`vmm_subenv_member_begin"
1682 "`vmm_xactor_member_begin"
1685 (defconst verilog-vmm-end-re
1689 "`vmm_data_member_end"
1690 "`vmm_env_member_end"
1691 "`vmm_scenario_member_end"
1692 "`vmm_subenv_member_end"
1693 "`vmm_xactor_member_end"
1696 (defconst verilog-vmm-statement-re
1700 ;; "`vmm_xactor_member_enum_array"
1701 "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
1702 ;; "`vmm_xactor_member_scalar_array"
1703 ;; "`vmm_xactor_member_scalar"
1706 (defconst verilog-ovm-statement-re
1715 "`ovm_analysis_imp_decl"
1716 "`ovm_blocking_get_imp_decl"
1717 "`ovm_blocking_get_peek_imp_decl"
1718 "`ovm_blocking_master_imp_decl"
1719 "`ovm_blocking_peek_imp_decl"
1720 "`ovm_blocking_put_imp_decl"
1721 "`ovm_blocking_slave_imp_decl"
1722 "`ovm_blocking_transport_imp_decl"
1723 "`ovm_component_registry"
1724 "`ovm_component_registry_param"
1725 "`ovm_component_utils"
1728 "`ovm_declare_sequence_lib"
1735 "`ovm_field_aa_int_byte"
1736 "`ovm_field_aa_int_byte_unsigned"
1737 "`ovm_field_aa_int_int"
1738 "`ovm_field_aa_int_int_unsigned"
1739 "`ovm_field_aa_int_integer"
1740 "`ovm_field_aa_int_integer_unsigned"
1741 "`ovm_field_aa_int_key"
1742 "`ovm_field_aa_int_longint"
1743 "`ovm_field_aa_int_longint_unsigned"
1744 "`ovm_field_aa_int_shortint"
1745 "`ovm_field_aa_int_shortint_unsigned"
1746 "`ovm_field_aa_int_string"
1747 "`ovm_field_aa_object_int"
1748 "`ovm_field_aa_object_string"
1749 "`ovm_field_aa_string_int"
1750 "`ovm_field_aa_string_string"
1751 "`ovm_field_array_int"
1752 "`ovm_field_array_object"
1753 "`ovm_field_array_string"
1758 "`ovm_field_queue_int"
1759 "`ovm_field_queue_object"
1760 "`ovm_field_queue_string"
1761 "`ovm_field_sarray_int"
1766 "`ovm_get_peek_imp_decl"
1773 "`ovm_master_imp_decl"
1775 "`ovm_non_blocking_transport_imp_decl"
1776 "`ovm_nonblocking_get_imp_decl"
1777 "`ovm_nonblocking_get_peek_imp_decl"
1778 "`ovm_nonblocking_master_imp_decl"
1779 "`ovm_nonblocking_peek_imp_decl"
1780 "`ovm_nonblocking_put_imp_decl"
1781 "`ovm_nonblocking_slave_imp_decl"
1782 "`ovm_object_registry"
1783 "`ovm_object_registry_param"
1785 "`ovm_peek_imp_decl"
1786 "`ovm_phase_func_decl"
1787 "`ovm_phase_task_decl"
1788 "`ovm_print_aa_int_object"
1789 "`ovm_print_aa_string_int"
1790 "`ovm_print_aa_string_object"
1791 "`ovm_print_aa_string_string"
1792 "`ovm_print_array_int"
1793 "`ovm_print_array_object"
1794 "`ovm_print_array_string"
1795 "`ovm_print_object_queue"
1796 "`ovm_print_queue_int"
1797 "`ovm_print_string_queue"
1800 "`ovm_rand_send_with"
1802 "`ovm_sequence_utils"
1803 "`ovm_slave_imp_decl"
1804 "`ovm_transport_imp_decl"
1805 "`ovm_update_sequence_lib"
1806 "`ovm_update_sequence_lib_and_item"
1809 "`static_message") nil )))
1813 ;; Regular expressions used to calculate indent, etc.
1815 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
1823 (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
1824 (defconst verilog-property-re
1825 (concat "\\(" verilog-label-re "\\)?"
1826 "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
1827 ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
1829 (defconst verilog-no-indent-begin-re
1830 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>")
1832 (defconst verilog-ends-re
1833 ;; Parenthesis indicate type of keyword found
1835 "\\(\\<else\\>\\)\\|" ; 1
1836 "\\(\\<if\\>\\)\\|" ; 2
1837 "\\(\\<assert\\>\\)\\|" ; 3
1838 "\\(\\<end\\>\\)\\|" ; 3.1
1839 "\\(\\<endcase\\>\\)\\|" ; 4
1840 "\\(\\<endfunction\\>\\)\\|" ; 5
1841 "\\(\\<endtask\\>\\)\\|" ; 6
1842 "\\(\\<endspecify\\>\\)\\|" ; 7
1843 "\\(\\<endtable\\>\\)\\|" ; 8
1844 "\\(\\<endgenerate\\>\\)\\|" ; 9
1845 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
1846 "\\(\\<endclass\\>\\)\\|" ; 11
1847 "\\(\\<endgroup\\>\\)\\|" ; 12
1849 "\\(\\<`vmm_data_member_end\\>\\)\\|"
1850 "\\(\\<`vmm_env_member_end\\>\\)\\|"
1851 "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
1852 "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
1853 "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
1855 "\\(\\<`ovm_component_utils_end\\>\\)\\|"
1856 "\\(\\<`ovm_field_utils_end\\>\\)\\|"
1857 "\\(\\<`ovm_object_utils_end\\>\\)\\|"
1858 "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
1859 "\\(\\<`ovm_sequencer_utils_end\\>\\)"
1863 (defconst verilog-auto-end-comment-lines-re
1864 ;; Matches to names in this list cause auto-end-commentation
1866 verilog-directive-re "\\)\\|\\("
1868 (verilog-regexp-words
1896 ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
1897 ;;; verilog-end-block-ordered-re matches exactly the same strings.
1898 (defconst verilog-end-block-ordered-re
1899 ;; Parenthesis indicate type of keyword found
1900 (concat "\\(\\<endcase\\>\\)\\|" ; 1
1901 "\\(\\<end\\>\\)\\|" ; 2
1902 "\\(\\<end" ; 3, but not used
1903 "\\(" ; 4, but not used
1904 "\\(function\\)\\|" ; 5
1906 "\\(module\\)\\|" ; 7
1907 "\\(primitive\\)\\|" ; 8
1908 "\\(interface\\)\\|" ; 9
1909 "\\(package\\)\\|" ; 10
1910 "\\(class\\)\\|" ; 11
1911 "\\(group\\)\\|" ; 12
1912 "\\(program\\)\\|" ; 13
1913 "\\(sequence\\)\\|" ; 14
1914 "\\(clocking\\)\\|" ; 15
1916 (defconst verilog-end-block-re
1918 (verilog-regexp-words
1920 `("end" ;; closes begin
1921 "endcase" ;; closes any of case, casex casez or randcase
1922 "join" "join_any" "join_none" ;; closes fork
1937 "`ovm_component_utils_end"
1938 "`ovm_field_utils_end"
1939 "`ovm_object_utils_end"
1940 "`ovm_sequence_utils_end"
1941 "`ovm_sequencer_utils_end"
1943 "`vmm_data_member_end"
1944 "`vmm_env_member_end"
1945 "`vmm_scenario_member_end"
1946 "`vmm_subenv_member_end"
1947 "`vmm_xactor_member_end"
1951 (defconst verilog-endcomment-reason-re
1952 ;; Parenthesis indicate type of keyword found
1954 "\\(\\<begin\\>\\)\\|" ; 1
1955 "\\(\\<else\\>\\)\\|" ; 2
1956 "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
1957 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" ; 4
1958 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" ; 5
1959 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" ; 6
1960 "\\(\\<fork\\>\\)\\|" ; 7
1961 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
1963 verilog-property-re "\\|"
1964 "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
1965 "\\(\\<clocking\\>\\)\\|"
1966 "\\(\\<task\\>\\)\\|"
1967 "\\(\\<function\\>\\)\\|"
1968 "\\(\\<initial\\>\\)\\|"
1969 "\\(\\<interface\\>\\)\\|"
1970 "\\(\\<package\\>\\)\\|"
1971 "\\(\\<final\\>\\)\\|"
1973 "\\(\\<while\\>\\)\\|"
1974 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
1975 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
1978 (defconst verilog-named-block-re "begin[ \t]*:")
1980 ;; These words begin a block which can occur inside a module which should be indented,
1981 ;; and closed with the respective word from the end-block list
1983 (defconst verilog-beg-block-re
1985 (verilog-regexp-words
1987 "case" "casex" "casez" "randcase"
1997 "`ovm_component_utils_begin"
1998 "`ovm_component_param_utils_begin"
1999 "`ovm_field_utils_begin"
2000 "`ovm_object_utils_begin"
2001 "`ovm_object_param_utils_begin"
2002 "`ovm_sequence_utils_begin"
2003 "`ovm_sequencer_utils_begin"
2005 "`vmm_data_member_begin"
2006 "`vmm_env_member_begin"
2007 "`vmm_scenario_member_begin"
2008 "`vmm_subenv_member_begin"
2009 "`vmm_xactor_member_begin"
2011 ;; These are the same words, in a specific order in the regular
2012 ;; expression so that matching will work nicely for
2013 ;; verilog-forward-sexp and verilog-calc-indent
2014 (defconst verilog-beg-block-re-ordered
2015 ( concat "\\(\\<begin\\>\\)" ;1
2016 "\\|\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
2017 "\\|\\(\\(\\<disable\\>\\s-+\\)?fork\\>\\)" ;4,5
2018 "\\|\\(\\<class\\>\\)" ;6
2019 "\\|\\(\\<table\\>\\)" ;7
2020 "\\|\\(\\<specify\\>\\)" ;8
2021 "\\|\\(\\<function\\>\\)" ;9
2022 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<function\\>\\)" ;10
2023 "\\|\\(\\<task\\>\\)" ;14
2024 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;15
2025 "\\|\\(\\<generate\\>\\)" ;18
2026 "\\|\\(\\<covergroup\\>\\)" ;16 20
2027 "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17 21
2028 "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25
2029 "\\|\\(\\<clocking\\>\\)" ;22 27
2030 "\\|\\(\\<`ovm_[a-z_]+_begin\\>\\)" ;28
2031 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
2036 (defconst verilog-end-block-ordered-rry
2037 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2038 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
2039 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2040 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
2041 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
2042 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
2043 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
2044 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
2045 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
2046 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
2047 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
2048 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
2049 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
2052 (defconst verilog-nameable-item-re
2054 (verilog-regexp-words
2057 "join" "join_any" "join_none"
2074 (defconst verilog-declaration-opener
2076 (verilog-regexp-words
2077 `("module" "begin" "task" "function"))))
2079 (defconst verilog-declaration-prefix-re
2081 (verilog-regexp-words
2084 "inout" "input" "output" "ref"
2086 "const" "static" "protected" "local"
2088 "localparam" "parameter" "var"
2092 (defconst verilog-declaration-core-re
2094 (verilog-regexp-words
2096 ;; port direction (by themselves)
2097 "inout" "input" "output"
2098 ;; integer_atom_type
2099 "byte" "shortint" "int" "longint" "integer" "time"
2100 ;; integer_vector_type
2103 "shortreal" "real" "realtime"
2105 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
2107 "string" "event" "chandle" "virtual" "enum" "genvar"
2110 "mailbox" "semaphore"
2112 (defconst verilog-declaration-re
2113 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
2114 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
2115 (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?")
2116 (defconst verilog-optional-signed-range-re
2118 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
2119 (defconst verilog-macroexp-re "`\\sw+")
2121 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
2122 (defconst verilog-declaration-re-2-no-macro
2123 (concat "\\s-*" verilog-declaration-re
2124 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2126 (defconst verilog-declaration-re-2-macro
2127 (concat "\\s-*" verilog-declaration-re
2128 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2129 "\\|\\(" verilog-macroexp-re "\\)"
2131 (defconst verilog-declaration-re-1-macro
2132 (concat "^" verilog-declaration-re-2-macro))
2134 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
2136 (defconst verilog-defun-re
2137 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
2138 (defconst verilog-end-defun-re
2139 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
2140 (defconst verilog-zero-indent-re
2141 (concat verilog-defun-re "\\|" verilog-end-defun-re))
2143 (defconst verilog-behavioral-block-beg-re
2144 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
2145 "function" "task"))))
2146 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
2147 (defconst verilog-indent-re
2149 (verilog-regexp-words
2152 "always" "always_latch" "always_ff" "always_comb"
2154 ; "unique" "priority"
2155 "case" "casex" "casez" "randcase" "endcase"
2157 "clocking" "endclocking"
2158 "config" "endconfig"
2159 "covergroup" "endgroup"
2160 "fork" "join" "join_any" "join_none"
2161 "function" "endfunction"
2163 "generate" "endgenerate"
2165 "interface" "endinterface"
2166 "module" "macromodule" "endmodule"
2167 "package" "endpackage"
2168 "primitive" "endprimative"
2169 "program" "endprogram"
2170 "property" "endproperty"
2171 "sequence" "randsequence" "endsequence"
2172 "specify" "endspecify"
2179 "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
2180 "`while" "`endwhile"
2185 "`protect" "`endprotect"
2186 "`switch" "`endswitch"
2190 "`ovm_component_utils_begin"
2191 "`ovm_component_param_utils_begin"
2192 "`ovm_field_utils_begin"
2193 "`ovm_object_utils_begin"
2194 "`ovm_object_param_utils_begin"
2195 "`ovm_sequence_utils_begin"
2196 "`ovm_sequencer_utils_begin"
2198 "`ovm_component_utils_end"
2199 "`ovm_field_utils_end"
2200 "`ovm_object_utils_end"
2201 "`ovm_sequence_utils_end"
2202 "`ovm_sequencer_utils_end"
2204 "`vmm_data_member_begin"
2205 "`vmm_env_member_begin"
2206 "`vmm_scenario_member_begin"
2207 "`vmm_subenv_member_begin"
2208 "`vmm_xactor_member_begin"
2210 "`vmm_data_member_end"
2211 "`vmm_env_member_end"
2212 "`vmm_scenario_member_end"
2213 "`vmm_subenv_member_end"
2214 "`vmm_xactor_member_end"
2217 (defconst verilog-defun-level-not-generate-re
2219 (verilog-regexp-words
2220 `( "module" "macromodule" "primitive" "class" "program"
2221 "interface" "package" "config"))))
2223 (defconst verilog-defun-level-re
2225 (verilog-regexp-words
2227 `( "module" "macromodule" "primitive" "class" "program"
2228 "interface" "package" "config")
2229 `( "initial" "final" "always" "always_comb" "always_ff"
2230 "always_latch" "endtask" "endfunction" )))))
2232 (defconst verilog-defun-level-generate-only-re
2234 (verilog-regexp-words
2235 `( "initial" "final" "always" "always_comb" "always_ff"
2236 "always_latch" "endtask" "endfunction" ))))
2238 (defconst verilog-cpp-level-re
2240 (verilog-regexp-words
2242 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2244 (defconst verilog-disable-fork-re "disable\\s-+fork\\>")
2245 (defconst verilog-fork-wait-re "fork\\s-+wait\\>")
2246 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?")
2247 (defconst verilog-extended-complete-re
2248 (concat "\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)"
2249 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)"
2250 "\\|\\(\\<import\\>\\s-+\\)?\"DPI-C\"\\s-+\\(function\\>\\|task\\>\\)"
2251 "\\|" verilog-extended-case-re ))
2252 (defconst verilog-basic-complete-re
2254 (verilog-regexp-words
2256 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
2257 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
2258 "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
2260 (defconst verilog-complete-reg
2262 verilog-extended-complete-re
2264 verilog-basic-complete-re))
2266 (defconst verilog-end-statement-re
2267 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
2268 verilog-end-block-re "\\)"))
2270 (defconst verilog-endcase-re
2271 (concat verilog-extended-case-re "\\|"
2276 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
2277 "String used to mark beginning of excluded text.")
2278 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
2279 "String used to mark end of excluded text.")
2280 (defconst verilog-preprocessor-re
2282 (verilog-regexp-words
2284 "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else"
2287 (defconst verilog-keywords
2288 '( "`case" "`default" "`define" "`else" "`endfor" "`endif"
2289 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
2290 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
2291 "`time_scale" "`undef" "`while"
2293 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
2294 "assert" "assign" "assume" "automatic" "before" "begin" "bind"
2295 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
2296 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
2297 "config" "const" "constraint" "context" "continue" "cover"
2298 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
2299 "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
2300 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
2301 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
2302 "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
2303 "endtask" "enum" "event" "expect" "export" "extends" "extern"
2304 "final" "first_match" "for" "force" "foreach" "forever" "fork"
2305 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
2306 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
2307 "include" "initial" "inout" "input" "inside" "instance" "int"
2308 "integer" "interface" "intersect" "join" "join_any" "join_none"
2309 "large" "liblist" "library" "local" "localparam" "logic"
2310 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
2311 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
2312 "notif0" "notif1" "null" "or" "output" "package" "packed"
2313 "parameter" "pmos" "posedge" "primitive" "priority" "program"
2314 "property" "protected" "pull0" "pull1" "pulldown" "pullup"
2315 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2316 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
2317 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
2318 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
2319 "showcancelled" "signed" "small" "solve" "specify" "specparam"
2320 "static" "string" "strong0" "strong1" "struct" "super" "supply0"
2321 "supply1" "table" "tagged" "task" "this" "throughout" "time"
2322 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
2323 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
2324 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
2325 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
2326 "wire" "with" "within" "wor" "xnor" "xor"
2328 "accept_on" "checker" "endchecker" "eventually" "global" "implies"
2329 "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
2330 "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
2331 "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
2333 "List of Verilog keywords.")
2335 (defconst verilog-comment-start-regexp "//\\|/\\*"
2336 "Dual comment value for `comment-start-regexp'.")
2338 (defvar verilog-mode-syntax-table
2339 (let ((table (make-syntax-table)))
2340 ;; Populate the syntax TABLE.
2341 (modify-syntax-entry ?\\ "\\" table)
2342 (modify-syntax-entry ?+ "." table)
2343 (modify-syntax-entry ?- "." table)
2344 (modify-syntax-entry ?= "." table)
2345 (modify-syntax-entry ?% "." table)
2346 (modify-syntax-entry ?< "." table)
2347 (modify-syntax-entry ?> "." table)
2348 (modify-syntax-entry ?& "." table)
2349 (modify-syntax-entry ?| "." table)
2350 (modify-syntax-entry ?` "w" table)
2351 (modify-syntax-entry ?_ "w" table)
2352 (modify-syntax-entry ?\' "." table)
2354 ;; Set up TABLE to handle block and line style comments.
2355 (if (featurep 'xemacs)
2357 ;; XEmacs (formerly Lucid) has the best implementation
2358 (modify-syntax-entry ?/ ". 1456" table)
2359 (modify-syntax-entry ?* ". 23" table)
2360 (modify-syntax-entry ?\n "> b" table))
2361 ;; Emacs does things differently, but we can work with it
2362 (modify-syntax-entry ?/ ". 124b" table)
2363 (modify-syntax-entry ?* ". 23" table)
2364 (modify-syntax-entry ?\n "> b" table))
2366 "Syntax table used in Verilog mode buffers.")
2368 (defvar verilog-font-lock-keywords nil
2369 "Default highlighting for Verilog mode.")
2371 (defvar verilog-font-lock-keywords-1 nil
2372 "Subdued level highlighting for Verilog mode.")
2374 (defvar verilog-font-lock-keywords-2 nil
2375 "Medium level highlighting for Verilog mode.
2376 See also `verilog-font-lock-extra-types'.")
2378 (defvar verilog-font-lock-keywords-3 nil
2379 "Gaudy level highlighting for Verilog mode.
2380 See also `verilog-font-lock-extra-types'.")
2381 (defvar verilog-font-lock-translate-off-face
2382 'verilog-font-lock-translate-off-face
2383 "Font to use for translated off regions.")
2384 (defface verilog-font-lock-translate-off-face
2387 (:background "gray90" :italic t ))
2390 (:background "gray10" :italic t ))
2391 (((class grayscale) (background light))
2392 (:foreground "DimGray" :italic t))
2393 (((class grayscale) (background dark))
2394 (:foreground "LightGray" :italic t))
2396 "Font lock mode face used to background highlight translate-off regions."
2397 :group 'font-lock-highlighting-faces)
2399 (defvar verilog-font-lock-p1800-face
2400 'verilog-font-lock-p1800-face
2401 "Font to use for p1800 keywords.")
2402 (defface verilog-font-lock-p1800-face
2405 (:foreground "DarkOrange3" :bold t ))
2408 (:foreground "orange1" :bold t ))
2410 "Font lock mode face used to highlight P1800 keywords."
2411 :group 'font-lock-highlighting-faces)
2413 (defvar verilog-font-lock-ams-face
2414 'verilog-font-lock-ams-face
2415 "Font to use for Analog/Mixed Signal keywords.")
2416 (defface verilog-font-lock-ams-face
2419 (:foreground "Purple" :bold t ))
2422 (:foreground "orange1" :bold t ))
2424 "Font lock mode face used to highlight AMS keywords."
2425 :group 'font-lock-highlighting-faces)
2427 (defvar verilog-font-grouping-keywords-face
2428 'verilog-font-lock-grouping-keywords-face
2429 "Font to use for Verilog Grouping Keywords (such as begin..end).")
2430 (defface verilog-font-lock-grouping-keywords-face
2433 (:foreground "red4" :bold t ))
2436 (:foreground "red4" :bold t ))
2438 "Font lock mode face used to highlight verilog grouping keywords."
2439 :group 'font-lock-highlighting-faces)
2441 (let* ((verilog-type-font-keywords
2445 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
2446 "event" "genvar" "inout" "input" "integer" "localparam"
2447 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or"
2448 "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
2449 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
2450 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
2451 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
2452 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
2453 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
2456 (verilog-pragma-keywords
2459 '("surefire" "synopsys" "rtl_synthesis" "verilint" "leda" "0in") nil
2462 (verilog-1800-2005-keywords
2465 '("alias" "assert" "assume" "automatic" "before" "bind"
2466 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
2467 "clocking" "config" "const" "constraint" "context" "continue"
2468 "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
2469 "dist" "do" "edge" "endclass" "endclocking" "endconfig"
2470 "endgroup" "endprogram" "endproperty" "endsequence" "enum"
2471 "expect" "export" "extends" "extern" "first_match" "foreach"
2472 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
2473 "illegal_bins" "import" "incdir" "include" "inside" "instance"
2474 "int" "intersect" "large" "liblist" "library" "local" "longint"
2475 "matches" "medium" "modport" "new" "noshowcancelled" "null"
2476 "packed" "program" "property" "protected" "pull0" "pull1"
2477 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2478 "randcase" "randsequence" "ref" "release" "return" "scalared"
2479 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
2480 "specparam" "static" "string" "strong0" "strong1" "struct"
2481 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
2482 "type" "union" "unsigned" "use" "var" "virtual" "void"
2483 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
2486 (verilog-1800-2009-keywords
2489 '("accept_on" "checker" "endchecker" "eventually" "global"
2490 "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
2491 "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
2492 "sync_accept_on" "sync_reject_on" "unique0" "until"
2493 "until_with" "untyped" "weak" ) nil )))
2495 (verilog-ams-keywords
2498 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
2499 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
2500 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
2501 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
2502 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
2503 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
2504 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
2505 "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
2506 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
2507 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
2508 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
2510 (verilog-font-keywords
2514 "assign" "case" "casex" "casez" "randcase" "deassign"
2515 "default" "disable" "else" "endcase" "endfunction"
2516 "endgenerate" "endinterface" "endmodule" "endprimitive"
2517 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
2518 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
2519 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
2520 "package" "endpackage" "always" "always_comb" "always_ff"
2521 "always_latch" "posedge" "primitive" "priority" "release"
2522 "repeat" "specify" "table" "task" "unique" "wait" "while"
2523 "class" "program" "endclass" "endprogram"
2526 (verilog-font-grouping-keywords
2529 '( "begin" "end" ) nil ))))
2531 (setq verilog-font-lock-keywords
2533 ;; Fontify all builtin keywords
2534 (concat "\\<\\(" verilog-font-keywords "\\|"
2535 ;; And user/system tasks and functions
2536 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
2538 ;; Fontify all types
2539 (if verilog-highlight-grouping-keywords
2540 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2541 'verilog-font-lock-ams-face)
2542 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2543 'font-lock-type-face))
2544 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
2545 'font-lock-type-face)
2546 ;; Fontify IEEE-1800-2005 keywords appropriately
2547 (if verilog-highlight-p1800-keywords
2548 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
2549 'verilog-font-lock-p1800-face)
2550 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
2551 'font-lock-type-face))
2552 ;; Fontify IEEE-1800-2009 keywords appropriately
2553 (if verilog-highlight-p1800-keywords
2554 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
2555 'verilog-font-lock-p1800-face)
2556 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
2557 'font-lock-type-face))
2558 ;; Fontify Verilog-AMS keywords
2559 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
2560 'verilog-font-lock-ams-face)))
2562 (setq verilog-font-lock-keywords-1
2563 (append verilog-font-lock-keywords
2565 ;; Fontify module definitions
2567 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
2568 '(1 font-lock-keyword-face)
2569 '(3 font-lock-function-name-face 'prepend))
2570 ;; Fontify function definitions
2572 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
2573 '(1 font-lock-keyword-face)
2574 '(3 font-lock-constant-face prepend))
2575 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
2576 (1 font-lock-keyword-face)
2577 (2 font-lock-constant-face append))
2578 '("\\<function\\>\\s-+\\(\\sw+\\)"
2579 1 'font-lock-constant-face append))))
2581 (setq verilog-font-lock-keywords-2
2582 (append verilog-font-lock-keywords-1
2585 (concat "\\(//\\s-*" verilog-pragma-keywords "\\s-.*\\)")
2586 ;; Fontify escaped names
2587 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
2588 ;; Fontify macro definitions/ uses
2589 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
2590 'font-lock-preprocessor-face
2591 'font-lock-type-face))
2592 ;; Fontify delays/numbers
2593 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
2594 0 font-lock-type-face append)
2595 ;; Fontify instantiation names
2596 '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
2599 (setq verilog-font-lock-keywords-3
2600 (append verilog-font-lock-keywords-2
2601 (when verilog-highlight-translate-off
2603 ;; Fontify things in translate off regions
2604 '(verilog-match-translate-off
2605 (0 'verilog-font-lock-translate-off-face prepend))
2609 ;; Buffer state preservation
2611 (defmacro verilog-save-buffer-state (&rest body)
2612 "Execute BODY forms, saving state around insignificant change.
2613 Changes in text properties like `face' or `syntax-table' are
2614 considered insignificant. This macro allows text properties to
2615 be changed, even in a read-only buffer.
2617 A change is considered significant if it affects the buffer text
2618 in any way that isn't completely restored again. Any
2619 user-visible changes to the buffer must not be within a
2620 `verilog-save-buffer-state'."
2621 ;; From c-save-buffer-state
2622 `(let* ((modified (buffer-modified-p))
2623 (buffer-undo-list t)
2624 (inhibit-read-only t)
2625 (inhibit-point-motion-hooks t)
2626 before-change-functions
2627 after-change-functions
2629 buffer-file-name ; Prevent primitives checking
2630 buffer-file-truename) ; for file modification
2635 (set-buffer-modified-p nil)))))
2637 (defmacro verilog-save-no-change-functions (&rest body)
2638 "Execute BODY forms, disabling all change hooks in BODY.
2639 For insigificant changes, see instead `verilog-save-buffer-state'."
2640 `(let* ((inhibit-point-motion-hooks t)
2641 before-change-functions
2642 after-change-functions)
2646 ;; Comment detection and caching
2648 (defvar verilog-scan-cache-preserving nil
2649 "If set, the specified buffer's comment properties are static.
2650 Buffer changes will be ignored. See `verilog-inside-comment-p'
2651 and `verilog-scan'.")
2653 (defvar verilog-scan-cache-tick nil
2654 "Modification tick at which `verilog-scan' was last completed.")
2655 (make-variable-buffer-local 'verilog-scan-cache-tick)
2657 (defun verilog-scan-cache-ok-p ()
2658 "Return t iff the scan cache is up to date."
2659 (or (and verilog-scan-cache-preserving
2660 (eq verilog-scan-cache-preserving (current-buffer))
2661 verilog-scan-cache-tick)
2662 (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
2664 (defmacro verilog-save-scan-cache (&rest body)
2665 "Execute the BODY forms, allowing scan cache preservation within BODY.
2666 This requires that insertions must use `verilog-insert'."
2667 ;; If the buffer is out of date, trash it, as we'll not check later the tick
2668 ;; Note this must work properly if there's multiple layers of calls
2669 ;; to verilog-save-scan-cache even with differing ticks.
2671 (unless (verilog-scan-cache-ok-p) ;; Must be before let
2672 (setq verilog-scan-cache-tick nil))
2673 (let* ((verilog-scan-cache-preserving (current-buffer)))
2676 (defun verilog-scan-region (beg end)
2677 "Parse comments between BEG and END for `verilog-inside-comment-p'.
2678 This creates v-cmt properties where comments are in force."
2679 ;; Why properties and not overlays? Overlays have much slower non O(1)
2681 ;; This function is warm - called on every verilog-insert
2684 (verilog-save-buffer-state
2687 (while (< (point) end)
2688 (cond ((looking-at "//")
2690 (or (search-forward "\n" end t)
2692 ;; "1+": The leading // or /* itself isn't considered as
2693 ;; being "inside" the comment, so that a (search-backward)
2694 ;; that lands at the start of the // won't mis-indicate
2695 ;; it's inside a comment
2696 (put-text-property (1+ pt) (point) 'v-cmt t))
2697 ((looking-at "/\\*")
2699 (or (search-forward "*/" end t)
2700 ;; No error - let later code indicate it so we can
2701 ;; use inside functions on-the-fly
2702 ;;(error "%s: Unmatched /* */, at char %d"
2703 ;; (verilog-point-text) (point))
2705 (put-text-property (1+ pt) (point) 'v-cmt t))
2708 (if (re-search-forward "/[/*]" end t)
2710 (goto-char end))))))))))
2712 (defun verilog-scan ()
2713 "Parse the buffer, marking all comments with properties.
2714 Also assumes any text inserted since `verilog-scan-cache-tick'
2715 either is ok to parse as a non-comment, or `verilog-insert' was used."
2716 (unless (verilog-scan-cache-ok-p)
2718 (verilog-save-buffer-state
2720 (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
2721 verilog-scan-cache-preserving verilog-scan-cache-tick
2722 (buffer-chars-modified-tick)))
2723 (remove-text-properties (point-min) (point-max) '(v-cmt nil))
2724 (verilog-scan-region (point-min) (point-max))
2725 (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
2726 (when verilog-debug (message "Scaning... done"))))))
2728 (defun verilog-inside-comment-p ()
2729 "Check if point inside a comment.
2730 This may require a slow pre-parse of the buffer with `verilog-scan'
2731 to establish comment properties on all text."
2732 ;; This function is very hot
2734 (get-text-property (point) 'v-cmt))
2736 (defun verilog-insert (&rest stuff)
2737 "Insert STUFF arguments, tracking comments for `verilog-inside-comment-p'.
2738 Any insert that includes a comment must have the entire commente
2739 inserted using a single call to `verilog-insert'."
2742 (insert (car stuff))
2743 (setq stuff (cdr stuff)))
2744 (verilog-scan-region pt (point))))
2748 (defun verilog-declaration-end ()
2749 (search-forward ";"))
2751 (defun verilog-point-text (&optional pointnum)
2752 "Return text describing where POINTNUM or current point is (for errors).
2753 Use filename, if current buffer being edited shorten to just buffer name."
2754 (concat (or (and (equal (window-buffer (selected-window)) (current-buffer))
2758 ":" (int-to-string (count-lines (point-min) (or pointnum (point))))))
2760 (defun electric-verilog-backward-sexp ()
2761 "Move backward over one balanced expression."
2763 ;; before that see if we are in a comment
2764 (verilog-backward-sexp))
2766 (defun electric-verilog-forward-sexp ()
2767 "Move forward over one balanced expression."
2769 ;; before that see if we are in a comment
2770 (verilog-forward-sexp))
2772 ;;;used by hs-minor-mode
2773 (defun verilog-forward-sexp-function (arg)
2775 (verilog-backward-sexp)
2776 (verilog-forward-sexp)))
2779 (defun verilog-backward-sexp ()
2784 (if (not (looking-at "\\<"))
2787 ((verilog-skip-backward-comment-or-string))
2788 ((looking-at "\\<else\\>")
2790 verilog-end-block-re
2791 "\\|\\(\\<else\\>\\)"
2792 "\\|\\(\\<if\\>\\)"))
2793 (while (and (not found)
2794 (verilog-re-search-backward reg nil 'move))
2796 ((match-end 1) ; matched verilog-end-block-re
2797 ; try to leap back to matching outward block by striding across
2798 ; indent level changing tokens then immediately
2799 ; previous line governs indentation.
2800 (verilog-leap-to-head))
2801 ((match-end 2) ; else, we're in deep
2802 (setq elsec (1+ elsec)))
2803 ((match-end 3) ; found it
2804 (setq elsec (1- elsec))
2806 ;; Now previous line describes syntax
2807 (setq found 't))))))
2808 ((looking-at verilog-end-block-re)
2809 (verilog-leap-to-head))
2810 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
2813 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
2815 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
2817 (verilog-re-search-backward "\\<class\\>" nil 'move))
2819 (verilog-re-search-backward "\\<program\\>" nil 'move))
2821 (verilog-re-search-backward "\\<interface\\>" nil 'move))
2823 (verilog-re-search-backward "\\<package\\>" nil 'move))
2826 (backward-sexp 1))))
2831 (defun verilog-forward-sexp ()
2836 (if (not (looking-at "\\<"))
2839 ((verilog-skip-forward-comment-or-string)
2840 (verilog-forward-syntactic-ws))
2841 ((looking-at verilog-beg-block-re-ordered)
2844 ;; Search forward for matching end
2845 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
2847 ;; Search forward for matching endcase
2848 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
2849 (setq md 3) ;; ender is third item in regexp
2852 ;; might be "disable fork" or "fork wait"
2855 (if (looking-at verilog-fork-wait-re)
2856 (progn ;; it is a fork wait; ignore it
2857 (goto-char (match-end 0))
2860 (looking-at verilog-disable-fork-re)
2861 (and (looking-at "fork")
2863 (setq here (point)) ;; sometimes a fork is just a fork
2865 (looking-at verilog-disable-fork-re))))
2866 (progn ;; it is a disable fork; ignore it
2867 (goto-char (match-end 0))
2870 (progn ;; it is a nice simple fork
2871 (goto-char here) ;; return from looking for "disable fork"
2872 ;; Search forward for matching join
2873 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))))))
2875 ;; Search forward for matching endclass
2876 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
2879 ;; Search forward for matching endtable
2880 (setq reg "\\<endtable\\>" )
2883 ;; Search forward for matching endspecify
2884 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
2886 ;; Search forward for matching endfunction
2887 (setq reg "\\<endfunction\\>" )
2890 ;; Search forward for matching endfunction
2891 (setq reg "\\<endfunction\\>" )
2894 ;; Search forward for matching endtask
2895 (setq reg "\\<endtask\\>" )
2898 ;; Search forward for matching endtask
2899 (setq reg "\\<endtask\\>" )
2902 ;; Search forward for matching endgenerate
2903 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
2905 ;; Search forward for matching endgroup
2906 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
2908 ;; Search forward for matching endproperty
2909 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
2911 ;; Search forward for matching endsequence
2912 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
2913 (setq md 3)) ; 3 to get to endsequence in the reg above
2915 ;; Search forward for matching endclocking
2916 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
2923 (while (verilog-re-search-forward reg nil 'move)
2925 ((match-end md) ; a closer in regular expression, so we are climbing out
2926 (setq depth (1- depth))
2927 (if (= 0 depth) ; we are out!
2929 ((match-end 1) ; an opener in the r-e, so we are in deeper now
2930 (setq here (point)) ; remember where we started
2931 (goto-char (match-beginning 1))
2933 ((looking-at verilog-fork-wait-re)
2934 (goto-char (match-end 0))) ; false alarm
2936 (looking-at verilog-disable-fork-re)
2937 (and (looking-at "fork")
2940 (looking-at verilog-disable-fork-re))))
2941 (progn ;; it is a disable fork; another false alarm
2942 (goto-char (match-end 0)))
2943 (progn ;; it is a simple fork (or has nothing to do with fork)
2945 (setq depth (1+ depth))))))))))
2946 (if (verilog-re-search-forward reg nil 'move)
2947 (throw 'skip 1))))))
2949 ((looking-at (concat
2950 "\\(\\<\\(macro\\)?module\\>\\)\\|"
2951 "\\(\\<primitive\\>\\)\\|"
2952 "\\(\\<class\\>\\)\\|"
2953 "\\(\\<program\\>\\)\\|"
2954 "\\(\\<interface\\>\\)\\|"
2955 "\\(\\<package\\>\\)"))
2958 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
2960 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
2962 (verilog-re-search-forward "\\<endclass\\>" nil 'move))
2964 (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
2966 (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
2968 (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
2971 (if (= (following-char) ?\) )
2973 (forward-sexp 1)))))
2976 (if (= (following-char) ?\) )
2978 (forward-sexp 1))))))
2980 (defun verilog-declaration-beg ()
2981 (verilog-re-search-backward verilog-declaration-re (bobp) t))
2987 (defvar verilog-which-tool 1)
2989 (defun verilog-mode ()
2990 "Major mode for editing Verilog code.
2991 \\<verilog-mode-map>
2992 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
2993 AUTOs can improve coding efficiency.
2995 Use \\[verilog-faq] for a pointer to frequently asked questions.
2997 NEWLINE, TAB indents for Verilog code.
2998 Delete converts tabs to spaces as it moves back.
3000 Supports highlighting.
3002 Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
3003 with no args, if that value is non-nil.
3005 Variables controlling indentation/edit style:
3007 variable `verilog-indent-level' (default 3)
3008 Indentation of Verilog statements with respect to containing block.
3009 `verilog-indent-level-module' (default 3)
3010 Absolute indentation of Module level Verilog statements.
3011 Set to 0 to get initial and always statements lined up
3012 on the left side of your screen.
3013 `verilog-indent-level-declaration' (default 3)
3014 Indentation of declarations with respect to containing block.
3015 Set to 0 to get them list right under containing block.
3016 `verilog-indent-level-behavioral' (default 3)
3017 Indentation of first begin in a task or function block
3018 Set to 0 to get such code to lined up underneath the task or
3020 `verilog-indent-level-directive' (default 1)
3021 Indentation of `ifdef/`endif blocks.
3022 `verilog-cexp-indent' (default 1)
3023 Indentation of Verilog statements broken across lines i.e.:
3026 `verilog-case-indent' (default 2)
3027 Indentation for case statements.
3028 `verilog-auto-newline' (default nil)
3029 Non-nil means automatically newline after semicolons and the punctuation
3031 `verilog-auto-indent-on-newline' (default t)
3032 Non-nil means automatically indent line after newline.
3033 `verilog-tab-always-indent' (default t)
3034 Non-nil means TAB in Verilog mode should always reindent the current line,
3035 regardless of where in the line point is when the TAB command is used.
3036 `verilog-indent-begin-after-if' (default t)
3037 Non-nil means to indent begin statements following a preceding
3038 if, else, while, for and repeat statements, if any. Otherwise,
3039 the begin is lined up with the preceding token. If t, you get:
3041 begin // amount of indent based on `verilog-cexp-indent'
3045 `verilog-auto-endcomments' (default t)
3046 Non-nil means a comment /* ... */ is set after the ends which ends
3047 cases, tasks, functions and modules.
3048 The type and name of the object will be set between the braces.
3049 `verilog-minimum-comment-distance' (default 10)
3050 Minimum distance (in lines) between begin and end required before a comment
3051 will be inserted. Setting this variable to zero results in every
3052 end acquiring a comment; the default avoids too many redundant
3053 comments in tight quarters.
3054 `verilog-auto-lineup' (default 'declarations)
3055 List of contexts where auto lineup of code should be done.
3057 Variables controlling other actions:
3059 `verilog-linter' (default surelint)
3060 Unix program to call to run the lint checker. This is the default
3061 command for \\[compile-command] and \\[verilog-auto-save-compile].
3063 See \\[customize] for the complete list of variables.
3065 AUTO expansion functions are, in part:
3067 \\[verilog-auto] Expand AUTO statements.
3068 \\[verilog-delete-auto] Remove the AUTOs.
3069 \\[verilog-inject-auto] Insert AUTOs for the first time.
3071 Some other functions are:
3073 \\[verilog-complete-word] Complete word with appropriate possibilities.
3074 \\[verilog-mark-defun] Mark function.
3075 \\[verilog-beg-of-defun] Move to beginning of current function.
3076 \\[verilog-end-of-defun] Move to end of current function.
3077 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
3079 \\[verilog-comment-region] Put marked area in a comment.
3080 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
3081 \\[verilog-insert-block] Insert begin ... end.
3082 \\[verilog-star-comment] Insert /* ... */.
3084 \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
3085 \\[verilog-sk-begin] Insert a begin .. end block.
3086 \\[verilog-sk-case] Insert a case block, prompting for details.
3087 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
3088 \\[verilog-sk-generate] Insert a generate .. endgenerate block.
3089 \\[verilog-sk-header] Insert a header block at the top of file.
3090 \\[verilog-sk-initial] Insert an initial begin .. end block.
3091 \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
3092 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
3093 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
3094 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
3095 \\[verilog-sk-specify] Insert a specify .. endspecify block.
3096 \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
3097 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
3098 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
3099 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
3100 \\[verilog-sk-if] Insert an if (..) begin .. end block.
3101 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
3102 \\[verilog-sk-comment] Insert a comment block.
3103 \\[verilog-sk-assign] Insert an assign .. = ..; statement.
3104 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
3105 \\[verilog-sk-input] Insert an input declaration, prompting for details.
3106 \\[verilog-sk-output] Insert an output declaration, prompting for details.
3107 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
3108 \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
3109 \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
3110 \\[verilog-sk-reg] Insert a register declaration, prompting for details.
3111 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
3113 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
3114 Key bindings specific to `verilog-mode-map' are:
3116 \\{verilog-mode-map}"
3118 (kill-all-local-variables)
3119 (use-local-map verilog-mode-map)
3120 (setq major-mode 'verilog-mode)
3121 (setq mode-name "Verilog")
3122 (setq local-abbrev-table verilog-mode-abbrev-table)
3123 (set (make-local-variable 'beginning-of-defun-function)
3124 'verilog-beg-of-defun)
3125 (set (make-local-variable 'end-of-defun-function)
3126 'verilog-end-of-defun)
3127 (set-syntax-table verilog-mode-syntax-table)
3128 (make-local-variable 'indent-line-function)
3129 (setq indent-line-function 'verilog-indent-line-relative)
3130 (setq comment-indent-function 'verilog-comment-indent)
3131 (make-local-variable 'parse-sexp-ignore-comments)
3132 (setq parse-sexp-ignore-comments nil)
3133 (make-local-variable 'comment-start)
3134 (make-local-variable 'comment-end)
3135 (make-local-variable 'comment-multi-line)
3136 (make-local-variable 'comment-start-skip)
3137 (setq comment-start "// "
3139 comment-start-skip "/\\*+ *\\|// *"
3140 comment-multi-line nil)
3141 ;; Set up for compilation
3142 (setq verilog-which-tool 1)
3143 (setq verilog-tool 'verilog-linter)
3144 (verilog-set-compile-command)
3145 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables
3146 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
3149 (when (featurep 'xemacs)
3150 (easy-menu-add verilog-stmt-menu)
3151 (easy-menu-add verilog-menu)
3152 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
3154 ;; Stuff for GNU Emacs
3155 (set (make-local-variable 'font-lock-defaults)
3156 `((verilog-font-lock-keywords verilog-font-lock-keywords-1
3157 verilog-font-lock-keywords-2
3158 verilog-font-lock-keywords-3)
3160 ,(if (functionp 'syntax-ppss)
3161 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
3162 ;; font-lock-beginning-of-syntax-function, so
3163 ;; font-lock-beginning-of-syntax-function, can't use
3164 ;; verilog-beg-of-defun.
3166 'verilog-beg-of-defun)))
3167 ;;------------------------------------------------------------
3168 ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
3169 ;; all buffer local:
3170 (unless noninteractive ;; Else can't see the result, and change hooks are slow
3171 (when (featurep 'xemacs)
3172 (make-local-hook 'font-lock-mode-hook)
3173 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
3174 (make-local-hook 'after-change-functions))
3175 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
3176 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
3177 (add-hook 'after-change-functions 'verilog-highlight-region t t))
3179 ;; Tell imenu how to handle Verilog.
3180 (make-local-variable 'imenu-generic-expression)
3181 (setq imenu-generic-expression verilog-imenu-generic-expression)
3182 ;; Tell which-func-modes that imenu knows about verilog
3183 (when (boundp 'which-function-modes)
3184 (add-to-list 'which-func-modes 'verilog-mode))
3186 (when (boundp 'hs-special-modes-alist)
3187 (unless (assq 'verilog-mode hs-special-modes-alist)
3188 (setq hs-special-modes-alist
3189 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
3190 verilog-forward-sexp-function)
3191 hs-special-modes-alist))))
3194 (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local
3195 (run-hooks 'verilog-mode-hook))
3199 ;; Electric functions
3201 (defun electric-verilog-terminate-line (&optional arg)
3202 "Terminate line and indent next line.
3203 With optional ARG, remove existing end of line comments."
3205 ;; before that see if we are in a comment
3206 (let ((state (save-excursion (verilog-syntax-ppss))))
3208 ((nth 7 state) ; Inside // comment
3211 (delete-horizontal-space)
3216 (beginning-of-line)))
3217 (verilog-indent-line))
3218 ((nth 4 state) ; Inside any comment (hence /**/)
3220 (verilog-more-comment))
3222 ;; First, check if current line should be indented
3224 (delete-horizontal-space)
3226 (skip-chars-forward " \t")
3227 (if (looking-at verilog-auto-end-comment-lines-re)
3228 (let ((indent-str (verilog-indent-line)))
3229 ;; Maybe we should set some endcomments
3230 (if verilog-auto-endcomments
3231 (verilog-set-auto-endcomments indent-str arg))
3233 (delete-horizontal-space)
3240 (delete-horizontal-space)
3242 ;; see if we should line up assignments
3244 (if (or (eq 'all verilog-auto-lineup)
3245 (eq 'assignments verilog-auto-lineup))
3246 (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
3250 (if verilog-auto-indent-on-newline
3251 (verilog-indent-line)))
3255 (defun electric-verilog-terminate-and-indent ()
3256 "Insert a newline and indent for the next statement."
3258 (electric-verilog-terminate-line 1))
3260 (defun electric-verilog-semi ()
3261 "Insert `;' character and reindent the line."
3263 (verilog-insert-last-command-event)
3265 (if (or (verilog-in-comment-or-string-p)
3266 (verilog-in-escaped-name-p))
3270 (verilog-forward-ws&directives)
3271 (verilog-indent-line))
3272 (if (and verilog-auto-newline
3273 (not (verilog-parenthesis-depth)))
3274 (electric-verilog-terminate-line))))
3276 (defun electric-verilog-semi-with-comment ()
3277 "Insert `;' character, reindent the line and indent for comment."
3282 (verilog-indent-line))
3283 (indent-for-comment))
3285 (defun electric-verilog-colon ()
3286 "Insert `:' and do all indentations except line indent on this line."
3288 (verilog-insert-last-command-event)
3289 ;; Do nothing if within string.
3291 (verilog-within-string)
3292 (not (verilog-in-case-region-p)))
3296 (lim (progn (verilog-beg-of-statement) (point))))
3298 (verilog-backward-case-item lim)
3299 (verilog-indent-line)))
3300 ;; (let ((verilog-tab-always-indent nil))
3301 ;; (verilog-indent-line))
3304 ;;(defun electric-verilog-equal ()
3305 ;; "Insert `=', and do indentation if within block."
3307 ;; (verilog-insert-last-command-event)
3308 ;; Could auto line up expressions, but not yet
3309 ;; (if (eq (car (verilog-calculate-indent)) 'block)
3310 ;; (let ((verilog-tab-always-indent nil))
3311 ;; (verilog-indent-command)))
3314 (defun electric-verilog-tick ()
3315 "Insert back-tick, and indent to column 0 if this is a CPP directive."
3317 (verilog-insert-last-command-event)
3319 (if (verilog-in-directive-p)
3320 (verilog-indent-line))))
3322 (defun electric-verilog-tab ()
3323 "Function called when TAB is pressed in Verilog mode."
3325 ;; If verilog-tab-always-indent, indent the beginning of the line.
3327 ;; The region is active, indent it.
3328 ((and (region-active-p)
3329 (not (eq (region-beginning) (region-end))))
3330 (indent-region (region-beginning) (region-end) nil))
3331 ((or verilog-tab-always-indent
3333 (skip-chars-backward " \t")
3335 (let* ((oldpnt (point))
3339 (skip-chars-forward " \t")
3340 (verilog-indent-line)
3341 (back-to-indentation)
3343 (if (< (point) boi-point)
3344 (back-to-indentation)
3345 (cond ((not verilog-tab-to-comment))
3349 (indent-for-comment)
3350 (when (and (eolp) (= oldpnt (point)))
3351 ; kill existing comment
3353 (re-search-forward comment-start-skip oldpnt 'move)
3354 (goto-char (match-beginning 0))
3355 (skip-chars-backward " \t")
3356 (kill-region (point) oldpnt)))))))
3357 (t (progn (insert "\t")))))
3362 ;; Interactive functions
3365 (defun verilog-indent-buffer ()
3366 "Indent-region the entire buffer as Verilog code.
3367 To call this from the command line, see \\[verilog-batch-indent]."
3370 (indent-region (point-min) (point-max) nil))
3372 (defun verilog-insert-block ()
3373 "Insert Verilog begin ... end; block in the code with right indentation."
3375 (verilog-indent-line)
3377 (electric-verilog-terminate-line)
3379 (electric-verilog-terminate-line)
3382 (verilog-indent-line)))
3384 (defun verilog-star-comment ()
3385 "Insert Verilog star comment at point."
3387 (verilog-indent-line)
3395 (defun verilog-insert-1 (fmt max)
3396 "Use format string FMT to insert integers 0 to MAX - 1.
3397 Inserts one integer per line, at the current column. Stops early
3398 if it reaches the end of the buffer."
3399 (let ((col (current-column))
3403 (insert (format fmt n))
3405 ;; Note that this function does not bother to check for lines
3406 ;; shorter than col.
3410 (move-to-column col))))))
3412 (defun verilog-insert-indices (max)
3413 "Insert a set of indices into a rectangle.
3414 The upper left corner is defined by point. Indices begin with 0
3415 and extend to the MAX - 1. If no prefix arg is given, the user
3416 is prompted for a value. The indices are surrounded by square
3417 brackets \[]. For example, the following code with the point
3418 located after the first 'a' gives:
3424 a = b ==> insert-indices ==> a[ 4] = b
3430 (interactive "NMAX: ")
3431 (verilog-insert-1 "[%3d]" max))
3433 (defun verilog-generate-numbers (max)
3434 "Insert a set of generated numbers into a rectangle.
3435 The upper left corner is defined by point. The numbers are padded to three
3436 digits, starting with 000 and extending to (MAX - 1). If no prefix argument
3437 is supplied, then the user is prompted for the MAX number. Consider the
3438 following code fragment:
3444 buf buf ==> generate-numbers ==> buf buf004
3450 (interactive "NMAX: ")
3451 (verilog-insert-1 "%3.3d" max))
3453 (defun verilog-mark-defun ()
3454 "Mark the current Verilog function (or procedure).
3455 This puts the mark at the end, and point at the beginning."
3457 (if (featurep 'xemacs)
3460 (verilog-end-of-defun)
3462 (verilog-beg-of-defun)
3463 (if (fboundp 'zmacs-activate-region)
3464 (zmacs-activate-region)))
3467 (defun verilog-comment-region (start end)
3468 ; checkdoc-params: (start end)
3469 "Put the region into a Verilog comment.
3470 The comments that are in this area are \"deformed\":
3471 `*)' becomes `!(*' and `}' becomes `!{'.
3472 These deformed comments are returned to normal if you use
3473 \\[verilog-uncomment-region] to undo the commenting.
3475 The commented area starts with `verilog-exclude-str-start', and ends with
3476 `verilog-exclude-str-end'. But if you change these variables,
3477 \\[verilog-uncomment-region] won't recognize the comments."
3480 ;; Insert start and endcomments
3482 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
3483 (not (save-excursion (skip-chars-backward " \t") (bolp))))
3485 (beginning-of-line))
3486 (insert verilog-exclude-str-end)
3491 (insert verilog-exclude-str-start)
3493 ;; Replace end-comments within commented area
3496 (while (re-search-backward "\\*/" start t)
3497 (replace-match "*-/" t t)))
3499 (let ((s+1 (1+ start)))
3500 (while (re-search-backward "/\\*" s+1 t)
3501 (replace-match "/-*" t t))))))
3503 (defun verilog-uncomment-region ()
3504 "Uncomment a commented area; change deformed comments back to normal.
3505 This command does nothing if the pointer is not in a commented
3506 area. See also `verilog-comment-region'."
3509 (let ((start (point))
3511 ;; Find the boundaries of the comment
3513 (setq start (progn (search-backward verilog-exclude-str-start nil t)
3515 (setq end (progn (search-forward verilog-exclude-str-end nil t)
3517 ;; Check if we're really inside a comment
3518 (if (or (equal start (point)) (<= end (point)))
3519 (message "Not standing within commented area.")
3521 ;; Remove endcomment
3524 (let ((pos (point)))
3526 (delete-region pos (1+ (point))))
3527 ;; Change comments back to normal
3529 (while (re-search-backward "\\*-/" start t)
3530 (replace-match "*/" t t)))
3532 (while (re-search-backward "/-\\*" start t)
3533 (replace-match "/*" t t)))
3534 ;; Remove start comment
3537 (let ((pos (point)))
3539 (delete-region pos (1+ (point)))))))))
3541 (defun verilog-beg-of-defun ()
3542 "Move backward to the beginning of the current function or procedure."
3544 (verilog-re-search-backward verilog-defun-re nil 'move))
3546 (defun verilog-end-of-defun ()
3547 "Move forward to the end of the current function or procedure."
3549 (verilog-re-search-forward verilog-end-defun-re nil 'move))
3551 (defun verilog-get-beg-of-defun (&optional warn)
3553 (cond ((verilog-re-search-forward-quick verilog-defun-re nil t)
3556 (error "%s: Can't find module beginning" (verilog-point-text))
3558 (defun verilog-get-end-of-defun (&optional warn)
3560 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
3563 (error "%s: Can't find endmodule" (verilog-point-text))
3566 (defun verilog-label-be (&optional arg)
3567 "Label matching begin ... end, fork ... join and case ... endcase statements.
3568 With ARG, first kill any existing labels."
3573 (verilog-beg-of-defun)
3576 (verilog-end-of-defun)
3578 (goto-char (marker-position b))
3580 (message "Relabeling module..."))
3582 (> (marker-position e) (point))
3583 (verilog-re-search-forward
3585 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>"
3586 "\\|\\(`endif\\)\\|\\(`else\\)")
3588 (goto-char (match-beginning 0))
3589 (let ((indent-str (verilog-indent-line)))
3590 (verilog-set-auto-endcomments indent-str 't)
3592 (delete-horizontal-space))
3594 (if (= 9 (% cnt 10))
3595 (message "%d..." cnt)))
3600 (message "%d lines auto commented" cnt))))
3602 (defun verilog-beg-of-statement ()
3603 "Move backward to beginning of statement."
3605 ;; Move back token by token until we see the end
3606 ;; of some ealier line.
3609 ;; If the current point does not begin a new
3610 ;; statement, as in the character ahead of us is a ';', or SOF
3611 ;; or the string after us unambiguously starts a statement,
3612 ;; or the token before us unambiguously ends a statement,
3613 ;; then move back a token and test again.
3615 ;; stop if beginning of buffer
3617 ;; stop if we find a ;
3618 (= (preceding-char) ?\;)
3619 ;; stop if we see a named coverpoint
3620 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
3621 ;; keep going if we are in the middle of a word
3622 (not (or (looking-at "\\<") (forward-word -1)))
3623 ;; stop if we see an assertion (perhaps labled)
3625 (looking-at "\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
3629 (verilog-backward-token)
3630 (if (looking-at verilog-label-re)
3633 ;; stop if we see a complete reg, perhaps an extended one
3635 (looking-at verilog-complete-reg)
3637 (while (and (looking-at verilog-extended-complete-re)
3638 (progn (setq p (point))
3639 (verilog-backward-token)
3642 ;; stop if we see a complete reg (previous found extended ones)
3643 (looking-at verilog-basic-complete-re)
3644 ;; stop if previous token is an ender
3646 (verilog-backward-token)
3648 (looking-at verilog-end-block-re)
3649 (looking-at verilog-preprocessor-re))))) ;; end of test
3650 (verilog-backward-syntactic-ws)
3651 (verilog-backward-token))
3652 ;; Now point is where the previous line ended.
3653 (verilog-forward-syntactic-ws)))
3655 (defun verilog-beg-of-statement-1 ()
3656 "Move backward to beginning of statement."
3658 (if (verilog-in-comment-p)
3659 (verilog-backward-syntactic-ws))
3662 (while (not (looking-at verilog-complete-reg))
3664 (verilog-backward-syntactic-ws)
3666 (= (preceding-char) ?\;)
3668 (verilog-backward-token)
3669 (looking-at verilog-ends-re)))
3673 (verilog-backward-token))))
3674 (verilog-forward-syntactic-ws)))
3677 ; (not (looking-at verilog-complete-reg))
3679 ; (not (= (preceding-char) ?\;)))
3680 ; (verilog-backward-token)
3681 ; (verilog-backward-syntactic-ws)
3682 ; (setq pt (point)))
3684 ; ;(verilog-forward-syntactic-ws)
3686 (defun verilog-end-of-statement ()
3687 "Move forward to end of current statement."
3691 ((verilog-in-directive-p)
3695 ((looking-at verilog-beg-block-re)
3696 (verilog-forward-sexp))
3698 ((equal (char-after) ?\})
3701 ;; Skip to end of statement
3702 ((condition-case nil
3707 (verilog-skip-forward-comment-or-string)
3710 (cond ((looking-at "[ \t]*;")
3711 (skip-chars-forward "^;")
3713 (throw 'found (point)))
3716 (looking-at verilog-beg-block-re))
3717 (goto-char (match-beginning 0))
3719 ((looking-at "[ \t]*)")
3720 (throw 'found (point)))
3722 (throw 'found (point)))
3728 ;; Skip a whole block
3731 (verilog-re-search-forward verilog-end-statement-re nil 'move)
3732 (setq nest (if (match-end 1)
3736 (throw 'found (point)))
3738 (throw 'found (verilog-end-of-statement))))))
3741 (defun verilog-in-case-region-p ()
3742 "Return true if in a case region.
3743 More specifically, point @ in the line foo : @ begin"
3747 (progn (verilog-forward-syntactic-ws)
3748 (looking-at "\\<begin\\>"))
3749 (progn (verilog-backward-syntactic-ws)
3750 (= (preceding-char) ?\:)))
3754 (verilog-re-search-backward
3755 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
3756 "\\(\\<endcase\\>\\)\\>")
3760 (setq nest (1+ nest)))
3764 (setq nest (1- nest)))
3766 (throw 'found (= nest 0)))))))
3768 (defun verilog-backward-up-list (arg)
3769 "Like backward-up-list, but deal with comments."
3770 (let (saved-psic parse-sexp-ignore-comments)
3771 (setq parse-sexp-ignore-comments 1)
3772 (backward-up-list arg)
3773 (setq parse-sexp-ignore-comments saved-psic)
3776 (defun verilog-in-struct-region-p ()
3777 "Return true if in a struct region.
3778 More specifically, in a list after a struct|union keyword."
3781 (let* ((state (verilog-syntax-ppss))
3782 (depth (nth 0 state)))
3784 (progn (verilog-backward-up-list depth)
3785 (verilog-beg-of-statement)
3786 (looking-at "\\<typedef\\>?\\s-*\\<struct\\|union\\>"))))))
3788 (defun verilog-in-generate-region-p ()
3789 "Return true if in a generate region.
3790 More specifically, after a generate and before an endgenerate."
3797 (verilog-re-search-backward
3798 "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
3800 ((match-end 1) ; module - we have crawled out
3802 ((match-end 2) ; generate
3803 (setq nest (1- nest)))
3804 ((match-end 3) ; endgenerate
3805 (setq nest (1+ nest))))))))
3806 (= nest 0) )) ; return nest
3808 (defun verilog-in-fork-region-p ()
3809 "Return true if between a fork and join."
3811 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
3816 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
3818 ((match-end 1) ; fork
3819 (setq nest (1- nest)))
3820 ((match-end 2) ; join
3821 (setq nest (1+ nest)))))))
3822 (= nest 0) )) ; return nest
3824 (defun verilog-backward-case-item (lim)
3825 "Skip backward to nearest enclosing case item.
3826 Limit search to point LIM."
3832 (verilog-re-search-backward verilog-endcomment-reason-re
3835 ;; Try to find the real :
3836 (if (save-excursion (search-backward ":" lim1 t))
3842 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
3846 (setq colon (1+ colon))
3848 (error "%s: unbalanced [" (verilog-point-text))))
3850 (setq colon (1- colon)))
3853 (setq colon (1+ colon)))))
3854 ;; Skip back to beginning of case item
3855 (skip-chars-backward "\t ")
3856 (verilog-skip-backward-comment-or-string)
3861 (verilog-re-search-backward
3862 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
3866 (goto-char (match-end 1))
3867 (verilog-forward-ws&directives)
3868 (if (looking-at "(")
3871 (verilog-forward-ws&directives)))
3874 (goto-char (match-end 0))
3875 (verilog-forward-ws&directives)
3877 (error "Malformed case item"))))
3878 (setq str (buffer-substring b e))
3882 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
3883 (setq str (concat (substring str 0 e) "...")))
3892 (defun verilog-kill-existing-comment ()
3893 "Kill auto comment on this line."
3901 (search-forward "//" e t))))
3903 (delete-region (- b 2) e)))))
3905 (defconst verilog-directive-nest-re
3906 (concat "\\(`else\\>\\)\\|"
3907 "\\(`endif\\>\\)\\|"
3909 "\\(`ifdef\\>\\)\\|"
3910 "\\(`ifndef\\>\\)\\|"
3912 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
3913 "Add ending comment with given INDENT-STR.
3914 With KILL-EXISTING-COMMENT, remove what was there before.
3915 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
3916 Insert `// case expr ' if this line ends a case block.
3917 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
3918 Insert `// NAME ' if this line ends a function, task, module,
3919 primitive or interface named NAME."
3922 (; Comment close preprocessor directives
3924 (looking-at "\\(`endif\\)\\|\\(`else\\)")
3925 (or kill-existing-comment
3926 (not (save-excursion
3928 (search-backward "//" (verilog-get-beg-of-line) t)))))
3931 (else (if (match-end 2) "!" " ")))
3933 (if kill-existing-comment
3934 (verilog-kill-existing-comment))
3935 (delete-horizontal-space)
3938 (while (and (/= nest 0)
3939 (verilog-re-search-backward verilog-directive-nest-re nil 'move))
3941 ((match-end 1) ; `else
3944 ((match-end 2) ; `endif
3945 (setq nest (1+ nest)))
3946 ((match-end 3) ; `if
3947 (setq nest (1- nest)))
3948 ((match-end 4) ; `ifdef
3949 (setq nest (1- nest)))
3950 ((match-end 5) ; `ifndef
3951 (setq nest (1- nest)))
3952 ((match-end 6) ; `elsif
3963 (skip-chars-forward "^ \t")
3964 (verilog-forward-syntactic-ws)
3967 (skip-chars-forward "a-zA-Z0-9_")
3970 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
3971 (insert (concat " // " else m " " (buffer-substring b e))))
3973 (insert " // unmatched `else, `elsif or `endif")
3976 (; Comment close case/class/function/task/module and named block
3977 (and (looking-at "\\<end")
3978 (or kill-existing-comment
3979 (not (save-excursion
3981 (search-backward "//" (verilog-get-beg-of-line) t)))))
3982 (let ((type (car indent-str)))
3983 (unless (eq type 'declaration)
3984 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends
3985 (if (looking-at verilog-end-block-ordered-re)
3987 (;- This is a case block; search back for the start of this case
3988 (match-end 1) ;; of verilog-end-block-ordered-re
3991 (str "UNMATCHED!!"))
3993 (verilog-leap-to-head)
3995 ((looking-at "\\<randcase\\>")
3996 (setq str "randcase")
3998 ((looking-at "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
3999 (goto-char (match-end 0))
4000 (setq str (concat (match-string 0) " " (verilog-get-expr)))
4004 (if kill-existing-comment
4005 (verilog-kill-existing-comment))
4006 (delete-horizontal-space)
4007 (insert (concat " // " str ))
4008 (if err (ding 't))))
4010 (;- This is a begin..end block
4011 (match-end 2) ;; of verilog-end-block-ordered-re
4012 (let ((str " // UNMATCHED !!")
4018 (verilog-leap-to-head)
4019 (setq there (point))
4020 (if (not (match-end 0))
4024 (if kill-existing-comment
4025 (verilog-kill-existing-comment))
4026 (delete-horizontal-space)
4030 (save-excursion (verilog-beg-of-defun) (point)))
4033 (;-- handle named block differently
4034 (looking-at verilog-named-block-re)
4035 (search-forward ":")
4036 (setq there (point))
4037 (setq str (verilog-get-expr))
4039 (setq str (concat " // block: " str )))
4041 ((verilog-in-case-region-p) ;-- handle case item differently
4043 (setq str (verilog-backward-case-item lim))
4044 (setq there (point))
4046 (setq str (concat " // case: " str )))
4048 (;- try to find "reason" for this begin
4052 ;; (verilog-backward-token)
4053 (verilog-beg-of-statement)
4057 ((looking-at verilog-endcomment-reason-re)
4058 (setq there (match-end 0))
4059 (setq cntx (concat (match-string 0) " "))
4065 (if (and (verilog-continued-line)
4066 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
4068 (goto-char (match-end 0))
4069 (setq there (point))
4071 (concat " // " (match-string 0) " " (verilog-get-expr))))
4077 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4079 (while (verilog-re-search-backward reg nil 'move)
4081 ((match-end 1) ; begin
4082 (setq nest (1- nest)))
4083 ((match-end 2) ; end
4084 (setq nest (1+ nest)))
4088 (goto-char (match-end 0))
4089 (setq there (point))
4091 (setq str (verilog-get-expr))
4092 (setq str (concat " // else: !if" str ))
4097 (goto-char (match-end 0))
4098 (setq there (point))
4100 (setq str (verilog-get-expr))
4101 (setq str (concat " // else: !assert " str ))
4102 (throw 'skip 1)))))))))
4107 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4109 (while (verilog-re-search-backward reg nil 'move)
4111 ((match-end 1) ; begin
4112 (setq nest (1- nest)))
4113 ((match-end 2) ; end
4114 (setq nest (1+ nest)))
4118 (goto-char (match-end 0))
4119 (setq there (point))
4121 (setq str (verilog-get-expr))
4122 (setq str (concat " // else: !if" str ))
4127 (goto-char (match-end 0))
4128 (setq there (point))
4130 (setq str (verilog-get-expr))
4131 (setq str (concat " // else: !assert " str ))
4132 (throw 'skip 1)))))))))
4134 (; always_comb, always_ff, always_latch
4135 (or (match-end 4) (match-end 5) (match-end 6))
4136 (goto-char (match-end 0))
4137 (setq there (point))
4139 (setq str (concat " // " cntx )))
4141 (;- task/function/initial et cetera
4144 (goto-char (match-end 0))
4145 (setq there (point))
4147 (setq str (concat " // " cntx (verilog-get-expr))))
4150 (setq str " // auto-endcomment confused "))))
4153 (verilog-in-case-region-p) ;-- handle case item differently
4155 (setq there (point))
4157 (setq str (verilog-backward-case-item lim))))
4159 (setq str (concat " // case: " str )))
4161 ((verilog-in-fork-region-p)
4163 (setq str " // fork branch" ))
4165 ((looking-at "\\<end\\>")
4168 (verilog-forward-syntactic-ws)
4170 (setq str (verilog-get-expr))
4171 (setq str (concat " // " cntx str )))
4176 (if kill-existing-comment
4177 (verilog-kill-existing-comment))
4178 (delete-horizontal-space)
4180 (> (count-lines here there) verilog-minimum-comment-distance))
4184 (;- this is endclass, which can be nested
4185 (match-end 11) ;; of verilog-end-block-ordered-re
4188 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
4192 (while (verilog-re-search-backward reg nil 'move)
4194 ((match-end 3) ; endclass
4196 (setq string "unmatched endclass")
4199 ((match-end 2) ; endclass
4200 (setq nest (1+ nest)))
4202 ((match-end 1) ; class
4203 (setq nest (1- nest))
4206 (goto-char (match-end 0))
4209 (skip-chars-forward "^ \t")
4210 (verilog-forward-ws&directives)
4213 (skip-chars-forward "a-zA-Z0-9_")
4215 (setq string (buffer-substring b e)))
4219 (insert (concat " // " string ))))
4221 (;- this is end{function,generate,task,module,primitive,table,generate}
4222 ;- which can not be nested.
4224 (let (string reg (name-re nil))
4226 (if kill-existing-comment
4228 (verilog-kill-existing-comment)))
4229 (delete-horizontal-space)
4232 ((match-end 5) ;; of verilog-end-block-ordered-re
4233 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4234 (setq name-re "\\w+\\s-*(")
4236 ((match-end 6) ;; of verilog-end-block-ordered-re
4237 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)"))
4238 ((match-end 7) ;; of verilog-end-block-ordered-re
4239 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
4240 ((match-end 8) ;; of verilog-end-block-ordered-re
4241 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4242 ((match-end 9) ;; of verilog-end-block-ordered-re
4243 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
4244 ((match-end 10) ;; of verilog-end-block-ordered-re
4245 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4246 ((match-end 11) ;; of verilog-end-block-ordered-re
4247 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4248 ((match-end 12) ;; of verilog-end-block-ordered-re
4249 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4250 ((match-end 13) ;; of verilog-end-block-ordered-re
4251 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4252 ((match-end 14) ;; of verilog-end-block-ordered-re
4253 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4254 ((match-end 15) ;; of verilog-end-block-ordered-re
4255 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
4257 (t (error "Problem in verilog-set-auto-endcomments")))
4260 (verilog-re-search-backward reg nil 'move)
4264 (skip-chars-forward "^ \t")
4265 (verilog-forward-ws&directives)
4266 (if (looking-at "static\\|automatic")
4268 (goto-char (match-end 0))
4269 (verilog-forward-ws&directives)))
4270 (if (and name-re (verilog-re-search-forward name-re nil 'move))
4272 (goto-char (match-beginning 0))
4273 (verilog-forward-ws&directives)))
4276 (skip-chars-forward "a-zA-Z0-9_")
4278 (setq string (buffer-substring b e)))
4281 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
4283 (insert (concat " // " string )))
4286 (defun verilog-get-expr()
4287 "Grab expression at point, e.g, case ( a | b & (c ^d))."
4289 (verilog-forward-syntactic-ws)
4290 (skip-chars-forward " \t")
4296 (verilog-forward-syntactic-ws)
4297 (if (looking-at "(")
4300 (while (and (/= par 0)
4301 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4304 (setq par (1+ par)))
4306 (setq par (1- par)))))))
4310 (while (and (/= par 0)
4311 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4314 (setq par (1+ par)))
4316 (setq par (1- par)))))
4320 (while (and (/= par 0)
4321 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
4324 (setq par (1+ par)))
4326 (setq par (1- par)))))
4327 (verilog-forward-syntactic-ws)
4328 (skip-chars-forward "^ \t\n\f")
4330 ((looking-at "/[/\\*]")
4333 (skip-chars-forward "^: \t\n\f")
4335 (str (buffer-substring b e)))
4336 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4337 (setq str (concat (substring str 0 e) "...")))
4340 (defun verilog-expand-vector ()
4341 "Take a signal vector on the current line and expand it to multiple lines.
4342 Useful for creating tri's and other expanded fields."
4344 (verilog-expand-vector-internal "[" "]"))
4346 (defun verilog-expand-vector-internal (bra ket)
4347 "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
4350 (let ((signal-string (buffer-substring (point)
4352 (end-of-line) (point)))))
4356 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
4358 "\\(.*\\)$") signal-string)
4359 (let* ((sig-head (match-string 1 signal-string))
4360 (vec-start (string-to-number (match-string 2 signal-string)))
4361 (vec-end (if (= (match-beginning 3) (match-end 3))
4364 (substring signal-string (1+ (match-beginning 3))
4367 (if (= (match-beginning 4) (match-end 4))
4370 (substring signal-string (+ 2 (match-beginning 4))
4372 (sig-tail (match-string 5 signal-string))
4377 (let ((tmp vec-start))
4378 (setq vec-start vec-end
4380 vec-range (- vec-range))))
4381 (if (< vec-end vec-start)
4382 (while (<= vec-end vec-start)
4383 (setq vec (append vec (list vec-start)))
4384 (setq vec-start (- vec-start vec-range)))
4385 (while (<= vec-start vec-end)
4386 (setq vec (append vec (list vec-start)))
4387 (setq vec-start (+ vec-start vec-range))))
4389 ;; Delete current line
4390 (delete-region (point) (progn (forward-line 0) (point)))
4394 (insert (concat sig-head bra
4395 (int-to-string (car vec)) ket sig-tail "\n"))
4396 (setq vec (cdr vec)))
4401 (defun verilog-strip-comments ()
4402 "Strip all comments from the Verilog code."
4404 (goto-char (point-min))
4405 (while (re-search-forward "//" nil t)
4406 (if (verilog-within-string)
4407 (re-search-forward "\"" nil t)
4408 (if (verilog-in-star-comment-p)
4409 (re-search-forward "\*/" nil t)
4410 (let ((bpt (- (point) 2)))
4412 (delete-region bpt (point))))))
4414 (goto-char (point-min))
4415 (while (re-search-forward "/\\*" nil t)
4416 (if (verilog-within-string)
4417 (re-search-forward "\"" nil t)
4418 (let ((bpt (- (point) 2)))
4419 (re-search-forward "\\*/")
4420 (delete-region bpt (point))))))
4422 (defun verilog-one-line ()
4423 "Convert structural Verilog instances to occupy one line."
4425 (goto-char (point-min))
4426 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
4427 (replace-match "\\1 " nil nil)))
4429 (defun verilog-linter-name ()
4430 "Return name of linter, either surelint or verilint."
4431 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4433 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4435 (cond ((equal compile-word1 "surelint") `surelint)
4436 ((equal compile-word1 "verilint") `verilint)
4437 ((equal lint-word1 "surelint") `surelint)
4438 ((equal lint-word1 "verilint") `verilint)
4439 (t `surelint)))) ;; back compatibility
4441 (defun verilog-lint-off ()
4442 "Convert a Verilog linter warning line into a disable statement.
4444 pci_bfm_null.v, line 46: Unused input: pci_rst_
4445 becomes a comment for the appropriate tool.
4447 The first word of the `compile-command' or `verilog-linter'
4448 variables is used to determine which product is being used.
4450 See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
4452 (let ((linter (verilog-linter-name)))
4453 (cond ((equal linter `surelint)
4454 (verilog-surelint-off))
4455 ((equal linter `verilint)
4456 (verilog-verilint-off))
4457 (t (error "Linter name not set")))))
4459 (defvar compilation-last-buffer)
4460 (defvar next-error-last-buffer)
4462 (defun verilog-surelint-off ()
4463 "Convert a SureLint warning line into a disable statement.
4464 Run from Verilog source window; assumes there is a *compile* buffer
4465 with point set appropriately.
4468 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
4470 // surefire lint_line_off UDDONX"
4472 (let ((buff (if (boundp 'next-error-last-buffer)
4473 next-error-last-buffer
4474 compilation-last-buffer)))
4475 (when (buffer-live-p buff)
4476 ;; FIXME with-current-buffer?
4478 (switch-to-buffer buff)
4481 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
4482 (let* ((code (match-string 2))
4483 (file (match-string 3))
4484 (line (match-string 4))
4485 (buffer (get-file-buffer file))
4490 (and (file-exists-p file)
4491 (find-file-noselect file)))
4493 (let* ((pop-up-windows t))
4494 (let ((name (expand-file-name
4496 (format "Find this error in: (default %s) "
4499 (if (file-directory-p name)
4500 (setq name (expand-file-name filename name)))
4502 (and (file-exists-p name)
4503 (find-file-noselect name))))))))
4504 (switch-to-buffer buffer)
4505 (goto-char (point-min))
4506 (forward-line (- (string-to-number line)))
4510 ((verilog-in-slash-comment-p)
4511 (re-search-backward "//")
4513 ((looking-at "// surefire lint_off_line ")
4514 (goto-char (match-end 0))
4515 (let ((lim (save-excursion (end-of-line) (point))))
4516 (if (re-search-forward code lim 'move)
4518 (insert (concat " " code)))))
4521 ((verilog-in-star-comment-p)
4522 (re-search-backward "/\*")
4523 (insert (format " // surefire lint_off_line %6s" code )))
4525 (insert (format " // surefire lint_off_line %6s" code ))
4528 (defun verilog-verilint-off ()
4529 "Convert a Verilint warning line into a disable statement.
4532 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
4534 //Verilint 240 off // WARNING: Unused input"
4538 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
4539 (replace-match (format
4540 ;; %3s makes numbers 1-999 line up nicely
4541 "\\1//Verilint %3s off // WARNING: \\3"
4544 (verilog-indent-line))))
4546 (defun verilog-auto-save-compile ()
4547 "Update automatics with \\[verilog-auto], save the buffer, and compile."
4549 (verilog-auto) ; Always do it for safety
4551 (compile compile-command))
4553 (defun verilog-preprocess (&optional command filename)
4554 "Preprocess the buffer, similar to `compile', but leave output in Verilog-Mode.
4555 Takes optional COMMAND or defaults to `verilog-preprocessor', and
4556 FILENAME or defaults to `buffer-file-name`."
4559 (let ((default (verilog-expand-command verilog-preprocessor)))
4560 (set (make-local-variable `verilog-preprocessor)
4561 (read-from-minibuffer "Run Preprocessor (like this): "
4563 'verilog-preprocess-history default)))))
4564 (unless command (setq command (verilog-expand-command verilog-preprocessor)))
4565 (let* ((dir (file-name-directory (or filename buffer-file-name)))
4566 (file (file-name-nondirectory (or filename buffer-file-name)))
4567 (cmd (concat "cd " dir "; " command " " file)))
4568 (with-output-to-temp-buffer "*Verilog-Preprocessed*"
4570 (set-buffer "*Verilog-Preprocessed*")
4571 (insert (concat "// " cmd "\n"))
4572 (shell-command cmd "*Verilog-Preprocessed*")
4574 (font-lock-mode)))))
4581 (defmacro verilog-batch-error-wrapper (&rest body)
4582 "Execute BODY and add error prefix to any errors found.
4583 This lets programs calling batch mode to easily extract error messages."
4584 `(condition-case err
4587 (error "%%Error: %s%s" (error-message-string err)
4588 (if (featurep 'xemacs) "\n" ""))))) ;; XEmacs forgets to add a newline
4590 (defun verilog-batch-execute-func (funref)
4591 "Internal processing of a batch command, running FUNREF on all command arguments."
4592 (verilog-batch-error-wrapper
4593 ;; Setting global variables like that is *VERY NASTY* !!! --Stef
4594 ;; However, this function is called only when Emacs is being used as
4595 ;; a standalone language instead of as an editor, so we'll live.
4597 ;; General globals needed
4598 (setq make-backup-files nil)
4599 (setq-default make-backup-files nil)
4600 (setq enable-local-variables t)
4601 (setq enable-local-eval t)
4602 ;; Make sure any sub-files we read get proper mode
4603 (setq-default major-mode 'verilog-mode)
4604 ;; Ditto files already read in
4606 (when (buffer-file-name buf)
4607 (with-current-buffer buf
4610 ;; Process the files
4611 (mapcar '(lambda (buf)
4612 (when (buffer-file-name buf)
4614 (if (not (file-exists-p (buffer-file-name buf)))
4616 (concat "File not found: " (buffer-file-name buf))))
4617 (message (concat "Processing " (buffer-file-name buf)))
4623 (defun verilog-batch-auto ()
4624 "For use with --batch, perform automatic expansions as a stand-alone tool.
4625 This sets up the appropriate Verilog mode environment, updates automatics
4626 with \\[verilog-auto] on all command-line files, and saves the buffers.
4627 For proper results, multiple filenames need to be passed on the command
4628 line in bottom-up order."
4629 (unless noninteractive
4630 (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
4631 (verilog-batch-execute-func `verilog-auto))
4633 (defun verilog-batch-delete-auto ()
4634 "For use with --batch, perform automatic deletion as a stand-alone tool.
4635 This sets up the appropriate Verilog mode environment, deletes automatics
4636 with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
4637 (unless noninteractive
4638 (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
4639 (verilog-batch-execute-func `verilog-delete-auto))
4641 (defun verilog-batch-inject-auto ()
4642 "For use with --batch, perform automatic injection as a stand-alone tool.
4643 This sets up the appropriate Verilog mode environment, injects new automatics
4644 with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
4645 For proper results, multiple filenames need to be passed on the command
4646 line in bottom-up order."
4647 (unless noninteractive
4648 (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
4649 (verilog-batch-execute-func `verilog-inject-auto))
4651 (defun verilog-batch-indent ()
4652 "For use with --batch, reindent an a entire file as a stand-alone tool.
4653 This sets up the appropriate Verilog mode environment, calls
4654 \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
4655 (unless noninteractive
4656 (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes
4657 (verilog-batch-execute-func `verilog-indent-buffer))
4663 (defconst verilog-indent-alist
4664 '((block . (+ ind verilog-indent-level))
4665 (case . (+ ind verilog-case-indent))
4666 (cparenexp . (+ ind verilog-indent-level))
4667 (cexp . (+ ind verilog-cexp-indent))
4668 (defun . verilog-indent-level-module)
4669 (declaration . verilog-indent-level-declaration)
4670 (directive . (verilog-calculate-indent-directive))
4671 (tf . verilog-indent-level)
4672 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
4675 (comment . (verilog-comment-indent))
4679 (defun verilog-continued-line-1 (lim)
4680 "Return true if this is a continued line.
4681 Set point to where line starts. Limit search to point LIM."
4682 (let ((continued 't))
4683 (if (eq 0 (forward-line -1))
4686 (verilog-backward-ws&directives lim)
4688 (setq continued nil)
4689 (setq continued (verilog-backward-token))))
4690 (setq continued nil))
4693 (defun verilog-calculate-indent ()
4694 "Calculate the indent of the current Verilog line.
4695 Examine previous lines. Once a line is found that is definitive as to the
4696 type of the current line, return that lines' indent level and its type.
4697 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
4699 (let* ((starting_position (point))
4701 (begin (looking-at "[ \t]*begin\\>"))
4702 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
4703 (type (catch 'nesting
4704 ;; Keep working backwards until we can figure out
4705 ;; what type of statement this is.
4706 ;; Basically we need to figure out
4707 ;; 1) if this is a continuation of the previous line;
4708 ;; 2) are we in a block scope (begin..end)
4710 ;; if we are in a comment, done.
4711 (if (verilog-in-star-comment-p)
4712 (throw 'nesting 'comment))
4714 ;; if we have a directive, done.
4715 (if (save-excursion (beginning-of-line)
4716 (and (looking-at verilog-directive-re-1)
4717 (not (or (looking-at "[ \t]*`ovm_")
4718 (looking-at "[ \t]*`vmm_")))))
4719 (throw 'nesting 'directive))
4720 ;; indent structs as if there were module level
4721 (if (verilog-in-struct-p)
4722 (throw 'nesting 'block))
4724 ;; unless we are in the newfangled coverpoint or constraint blocks
4725 ;; if we are in a parenthesized list, and the user likes to indent these, return.
4727 verilog-indent-lists
4729 (not (verilog-in-coverage-p))
4732 (throw 'nesting 'block)))
4734 ;; See if we are continuing a previous line
4736 ;; trap out if we crawl off the top of the buffer
4737 (if (bobp) (throw 'nesting 'cpp))
4739 (if (verilog-continued-line-1 lim)
4742 (not (looking-at verilog-complete-reg))
4743 (verilog-continued-line-1 lim))
4744 (progn (goto-char sp)
4745 (throw 'nesting 'cexp))
4750 (not verilog-indent-begin-after-if)
4751 (looking-at verilog-no-indent-begin-re))
4754 (skip-chars-forward " \t")
4755 (throw 'nesting 'statement))
4757 (throw 'nesting 'cexp))))
4758 ;; not a continued line
4759 (goto-char starting_position))
4761 (if (looking-at "\\<else\\>")
4762 ;; search back for governing if, striding across begin..end pairs
4765 (while (verilog-re-search-backward verilog-ends-re nil 'move)
4767 ((match-end 1) ; else, we're in deep
4768 (setq elsec (1+ elsec)))
4770 (setq elsec (1- elsec))
4772 (if verilog-align-ifelse
4773 (throw 'nesting 'statement)
4774 (progn ;; back up to first word on this line
4776 (verilog-forward-syntactic-ws)
4777 (throw 'nesting 'statement)))))
4778 ((match-end 3) ; assert block
4779 (setq elsec (1- elsec))
4780 (verilog-beg-of-statement) ;; doesn't get to beginning
4781 (if (looking-at verilog-property-re)
4782 (throw 'nesting 'statement) ; We don't need an endproperty for these
4783 (throw 'nesting 'block) ;We still need a endproperty
4786 ; try to leap back to matching outward block by striding across
4787 ; indent level changing tokens then immediately
4788 ; previous line governs indentation.
4789 (let (( reg) (nest 1))
4790 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
4792 ((match-end 4) ; end
4793 ;; Search back for matching begin
4794 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
4795 ((match-end 5) ; endcase
4796 ;; Search back for matching case
4797 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
4798 ((match-end 6) ; endfunction
4799 ;; Search back for matching function
4800 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
4801 ((match-end 7) ; endtask
4802 ;; Search back for matching task
4803 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
4804 ((match-end 8) ; endspecify
4805 ;; Search back for matching specify
4806 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
4807 ((match-end 9) ; endtable
4808 ;; Search back for matching table
4809 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
4810 ((match-end 10) ; endgenerate
4811 ;; Search back for matching generate
4812 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
4813 ((match-end 11) ; joins
4814 ;; Search back for matching fork
4815 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
4816 ((match-end 12) ; class
4817 ;; Search back for matching class
4818 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
4819 ((match-end 13) ; covergroup
4820 ;; Search back for matching covergroup
4821 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
4823 (while (verilog-re-search-backward reg nil 'move)
4825 ((match-end 1) ; begin
4826 (setq nest (1- nest))
4829 ((match-end 2) ; end
4830 (setq nest (1+ nest)))))
4832 (throw 'nesting (verilog-calc-1)))
4836 ;; Return type of block and indent level.
4839 (if (> par 0) ; Unclosed Parenthesis
4840 (list 'cparenexp par)
4843 (list type (verilog-case-indent-level)))
4844 ((eq type 'statement)
4845 (list type (current-column)))
4849 (list type (verilog-current-indent-level))))))))
4851 (defun verilog-wai ()
4852 "Show matching nesting block for debugging."
4855 (let* ((type (verilog-calc-1))
4857 ;; Return type of block and indent level.
4861 verilog-indent-lists
4862 (not(or (verilog-in-coverage-p)
4863 (verilog-in-struct-p)))
4868 (setq depth (verilog-case-indent-level)))
4869 ((eq type 'statement)
4870 (setq depth (current-column)))
4874 (setq depth (verilog-current-indent-level)))))
4875 (message "You are at nesting %s depth %d" type depth))))
4877 (defun verilog-calc-1 ()
4879 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)")))
4880 (while (verilog-re-search-backward re nil 'move)
4883 ((equal (char-after) ?\{)
4884 (if (verilog-at-constraint-p)
4885 (throw 'nesting 'block)))
4887 ((equal (char-after) ?\})
4888 (let ((there (verilog-at-close-constraint-p)))
4889 (if there ;; we are at the } that closes a constraint. Find the { that opens it
4893 (verilog-beg-of-statement)))))
4895 ((looking-at verilog-beg-block-re-ordered)
4897 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
4898 (let ((here (point)))
4899 (verilog-beg-of-statement)
4900 (if (looking-at verilog-extended-case-re)
4901 (throw 'nesting 'case)
4903 (throw 'nesting 'case))
4905 ((match-end 4) ; *sigh* could be "disable fork"
4906 (let ((here (point)))
4907 (verilog-beg-of-statement)
4908 (if (or (looking-at verilog-disable-fork-re)
4909 (looking-at verilog-fork-wait-re))
4910 t ; this is a normal statement
4911 (progn ; or is fork, starts a new block
4913 (throw 'nesting 'block)))))
4915 ((match-end 27) ; *sigh* might be a clocking declaration
4916 (let ((here (point)))
4917 (if (verilog-in-paren)
4918 t ; this is a normal statement
4919 (progn ; or is fork, starts a new block
4921 (throw 'nesting 'block)))))
4923 ;; need to consider typedef struct here...
4924 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
4925 ; *sigh* These words have an optional prefix:
4926 ; extern {virtual|protected}? function a();
4927 ; typedef class foo;
4928 ; and we don't want to confuse this with
4933 (verilog-beg-of-statement)
4934 (if (looking-at verilog-beg-block-re-ordered)
4935 (throw 'nesting 'block)
4936 (throw 'nesting 'defun)))
4938 ((looking-at "\\<property\\>")
4940 ; {assert|assume|cover} property (); are complete
4941 ; and could also be labeled: - foo: assert property
4943 ; property ID () ... needs end_property
4944 (verilog-beg-of-statement)
4945 (if (looking-at verilog-property-re)
4946 (throw 'continue 'statement) ; We don't need an endproperty for these
4947 (throw 'nesting 'block) ;We still need a endproperty
4950 (t (throw 'nesting 'block))))
4952 ((looking-at verilog-end-block-re)
4953 (verilog-leap-to-head)
4954 (if (verilog-in-case-region-p)
4956 (verilog-leap-to-case-head)
4957 (if (looking-at verilog-extended-case-re)
4958 (throw 'nesting 'case)))))
4960 ((looking-at verilog-defun-level-re)
4961 (if (looking-at verilog-defun-level-generate-only-re)
4962 (if (verilog-in-generate-region-p)
4963 (throw 'continue 'foo) ; always block in a generate - keep looking
4964 (throw 'nesting 'defun))
4965 (throw 'nesting 'defun)))
4967 ((looking-at verilog-cpp-level-re)
4968 (throw 'nesting 'cpp))
4971 (throw 'nesting 'cpp)))))
4973 (throw 'nesting 'cpp))))
4975 (defun verilog-calculate-indent-directive ()
4976 "Return indentation level for directive.
4977 For speed, the searcher looks at the last directive, not the indent
4978 of the appropriate enclosing block."
4979 (let ((base -1) ;; Indent of the line that determines our indentation
4980 (ind 0)) ;; Relative offset caused by other directives (like `endif on same line as `else)
4981 ;; Start at current location, scan back for another directive
4985 (while (and (< base 0)
4986 (verilog-re-search-backward verilog-directive-re nil t))
4987 (cond ((save-excursion (skip-chars-backward " \t") (bolp))
4988 (setq base (current-indentation))))
4989 (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL
4990 (setq ind (- ind verilog-indent-level-directive)))
4991 ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL
4992 (setq ind (+ ind verilog-indent-level-directive)))
4993 ((looking-at verilog-directive-begin)
4994 (setq ind (+ ind verilog-indent-level-directive)))))
4995 ;; Adjust indent to starting indent of critical line
4996 (setq ind (max 0 (+ ind base))))
5000 (skip-chars-forward " \t")
5001 (cond ((or (looking-at verilog-directive-middle)
5002 (looking-at verilog-directive-end))
5003 (setq ind (max 0 (- ind verilog-indent-level-directive))))))
5006 (defun verilog-leap-to-case-head ()
5009 (verilog-re-search-backward
5011 "\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
5012 "\\|\\(\\<endcase\\>\\)" )
5016 (let ((here (point)))
5017 (verilog-beg-of-statement)
5018 (unless (looking-at verilog-extended-case-re)
5020 (setq nest (1- nest)))
5022 (setq nest (1+ nest)))
5027 (defun verilog-leap-to-head ()
5028 "Move point to the head of this block.
5029 Jump from end to matching begin, from endcase to matching case, and so on."
5035 ((looking-at "\\<end\\>")
5036 ;; 1: Search back for matching begin
5037 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
5038 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
5039 ((looking-at "\\<endtask\\>")
5040 ;; 2: Search back for matching task
5041 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)")
5043 ((looking-at "\\<endcase\\>")
5045 (verilog-leap-to-case-head) )
5046 (setq reg nil) ; to force skip
5049 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
5050 ;; 4: Search back for matching fork
5051 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5052 ((looking-at "\\<endclass\\>")
5053 ;; 5: Search back for matching class
5054 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5055 ((looking-at "\\<endtable\\>")
5056 ;; 6: Search back for matching table
5057 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5058 ((looking-at "\\<endspecify\\>")
5059 ;; 7: Search back for matching specify
5060 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5061 ((looking-at "\\<endfunction\\>")
5062 ;; 8: Search back for matching function
5063 (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<function\\>\\)")
5065 ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5066 ((looking-at "\\<endgenerate\\>")
5067 ;; 8: Search back for matching generate
5068 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5069 ((looking-at "\\<endgroup\\>")
5070 ;; 10: Search back for matching covergroup
5071 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
5072 ((looking-at "\\<endproperty\\>")
5073 ;; 11: Search back for matching property
5074 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
5075 ((looking-at verilog-ovm-end-re)
5076 ;; 12: Search back for matching sequence
5077 (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
5078 ((looking-at verilog-vmm-end-re)
5079 ;; 12: Search back for matching sequence
5080 (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
5081 ((looking-at "\\<endinterface\\>")
5082 ;; 12: Search back for matching interface
5083 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
5084 ((looking-at "\\<endsequence\\>")
5085 ;; 12: Search back for matching sequence
5086 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
5087 ((looking-at "\\<endclocking\\>")
5088 ;; 12: Search back for matching clocking
5089 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
5092 (if (eq nesting 'yes)
5094 (while (verilog-re-search-backward reg nil 'move)
5096 ((match-end 1) ; begin
5097 (if (looking-at "fork")
5098 (let ((here (point)))
5099 (verilog-beg-of-statement)
5100 (unless (looking-at verilog-disable-fork-re)
5102 (setq nest (1- nest))))
5103 (setq nest (1- nest)))
5105 ;; Now previous line describes syntax
5110 ((match-end 2) ; end
5111 (setq nest (1+ nest)))
5113 ;; endcase, jump to case
5115 (setq nest (1+ nest))
5117 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5119 ;; join, jump to fork
5121 (setq nest (1+ nest))
5123 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5127 (verilog-re-search-backward reg nil 'move)
5128 (match-end 1)) ; task -> could be virtual and/or protected
5130 (verilog-beg-of-statement)
5132 (throw 'skip 1)))))))
5134 (defun verilog-continued-line ()
5135 "Return true if this is a continued line.
5136 Set point to where line starts."
5137 (let ((continued 't))
5138 (if (eq 0 (forward-line -1))
5141 (verilog-backward-ws&directives)
5143 (setq continued nil)
5144 (while (and continued
5146 (skip-chars-backward " \t")
5148 (setq continued (verilog-backward-token)))))
5149 (setq continued nil))
5152 (defun verilog-backward-token ()
5153 "Step backward token, returing true if this is a continued line."
5155 (verilog-backward-syntactic-ws)
5159 (;-- Anything ending in a ; is complete
5160 (= (preceding-char) ?\;)
5162 (; If a "}" is prefixed by a ";", then this is a complete statement
5163 ; i.e.: constraint foo { a = b; }
5164 (= (preceding-char) ?\})
5167 (not(verilog-at-close-constraint-p))))
5168 (;-- constraint foo { a = b }
5169 ; is a complete statement. *sigh*
5170 (= (preceding-char) ?\{)
5173 (not (verilog-at-constraint-p))))
5175 (= (preceding-char) ?\")
5177 (verilog-skip-backward-comment-or-string)
5181 (= (preceding-char) ?\])
5183 (verilog-backward-open-bracket)
5186 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
5187 ; also could be simply '@(foo)'
5189 ; (b, ... which ISN'T complete
5190 ;;;; Do we need this???
5191 (= (preceding-char) ?\))
5194 (verilog-backward-up-list 1)
5195 (verilog-backward-syntactic-ws)
5196 (let ((back (point)))
5200 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
5201 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
5202 ((looking-at verilog-ovm-statement-re)
5204 ((looking-at verilog-ovm-begin-re)
5206 ((looking-at verilog-ovm-end-re)
5208 ;; JBA find VMM macros
5209 ((looking-at verilog-vmm-statement-re)
5211 ((looking-at verilog-vmm-begin-re)
5213 ((looking-at verilog-vmm-end-re)
5215 ;; JBA trying to catch macro lines with no ; at end
5216 ((looking-at "\\<`")
5221 ((= (preceding-char) ?\@)
5224 (verilog-backward-token)
5225 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
5226 ((= (preceding-char) ?\#)
5230 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
5233 (while (= (preceding-char) ?\_)
5236 ((looking-at "\\<else\\>")
5238 ((looking-at verilog-behavioral-block-beg-re)
5240 ((looking-at verilog-indent-re)
5245 (verilog-backward-syntactic-ws)
5247 ((= (preceding-char) ?\:)
5249 (verilog-backward-syntactic-ws)
5251 (if (looking-at verilog-nameable-item-re )
5254 ((= (preceding-char) ?\#)
5257 ((= (preceding-char) ?\`)
5265 (defun verilog-backward-syntactic-ws ()
5266 (verilog-skip-backward-comments)
5267 (forward-comment (- (buffer-size))))
5269 (defun verilog-forward-syntactic-ws ()
5270 (verilog-skip-forward-comment-p)
5271 (forward-comment (buffer-size)))
5273 (defun verilog-backward-ws&directives (&optional bound)
5274 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
5275 Optional BOUND limits search."
5277 (let* ((bound (or bound (point-min)))
5280 (if (< bound (point))
5282 (let ((state (save-excursion (verilog-syntax-ppss))))
5284 ((nth 7 state) ;; in // comment
5285 (verilog-re-search-backward "//" nil 'move)
5286 (skip-chars-backward "/"))
5287 ((nth 4 state) ;; in /* */ comment
5288 (verilog-re-search-backward "/\*" nil 'move))))
5289 (narrow-to-region bound (point))
5290 (while (/= here (point))
5292 (verilog-skip-backward-comments)
5297 ((and verilog-highlight-translate-off
5298 (verilog-within-translate-off))
5299 (verilog-back-to-start-translate-off (point-min)))
5300 ((looking-at verilog-directive-re-1)
5304 (if p (goto-char p))))))))
5306 (defun verilog-forward-ws&directives (&optional bound)
5307 "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
5308 Optional BOUND limits search."
5310 (let* ((bound (or bound (point-max)))
5313 (if (> bound (point))
5315 (let ((state (save-excursion (verilog-syntax-ppss))))
5317 ((nth 7 state) ;; in // comment
5320 (skip-chars-forward " \t\n\f")
5322 ((nth 4 state) ;; in /* */ comment
5323 (verilog-re-search-forward "\*\/\\s-*" nil 'move))))
5324 (narrow-to-region (point) bound)
5325 (while (/= here (point))
5328 (forward-comment (buffer-size))
5329 (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ;; Attribute
5330 (goto-char (match-end 0)))
5333 (if (looking-at verilog-directive-re-1)
5336 (beginning-of-line 2))))))))
5338 (defun verilog-in-comment-p ()
5339 "Return true if in a star or // comment."
5340 (let ((state (save-excursion (verilog-syntax-ppss))))
5341 (or (nth 4 state) (nth 7 state))))
5343 (defun verilog-in-star-comment-p ()
5344 "Return true if in a star comment."
5345 (let ((state (save-excursion (verilog-syntax-ppss))))
5347 (nth 4 state) ; t if in a comment of style a // or b /**/
5349 (nth 7 state) ; t if in a comment of style b /**/
5352 (defun verilog-in-slash-comment-p ()
5353 "Return true if in a slash comment."
5354 (let ((state (save-excursion (verilog-syntax-ppss))))
5357 (defun verilog-in-comment-or-string-p ()
5358 "Return true if in a string or comment."
5359 (let ((state (save-excursion (verilog-syntax-ppss))))
5360 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
5362 (defun verilog-in-attribute-p ()
5363 "Return true if point is in an attribute (* [] attribute *)."
5365 (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
5366 (numberp (match-beginning 1))))
5368 (defun verilog-in-escaped-name-p ()
5369 "Return true if in an escaped name."
5372 (skip-chars-backward "^ \t\n\f")
5373 (if (equal (char-after (point) ) ?\\ )
5376 (defun verilog-in-directive-p ()
5377 "Return true if in a directive."
5380 (looking-at verilog-directive-re-1)))
5382 (defun verilog-in-paren ()
5383 "Return true if in a parenthetical expression."
5384 (let ((state (save-excursion (verilog-syntax-ppss))))
5385 (> (nth 0 state) 0 )))
5387 (defun verilog-in-struct-p ()
5388 "Return true if in a struct declaration."
5391 (if (verilog-in-paren)
5393 (verilog-backward-up-list 1)
5394 (verilog-at-struct-p)
5398 (defun verilog-in-coverage-p ()
5399 "Return true if in a constraint or coverpoint expression."
5402 (if (verilog-in-paren)
5404 (verilog-backward-up-list 1)
5405 (verilog-at-constraint-p)
5408 (defun verilog-at-close-constraint-p ()
5409 "If at the } that closes a constraint or covergroup, return true."
5411 (equal (char-after) ?\})
5415 (verilog-backward-ws&directives)
5416 (if (equal (char-before) ?\;)
5420 (defun verilog-at-constraint-p ()
5421 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
5424 (equal (char-after) ?\{)
5426 (progn (backward-char 1)
5427 (verilog-backward-ws&directives)
5428 (equal (char-before) ?\;))))
5430 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move)
5434 (defun verilog-at-struct-p ()
5435 "If at the { of a struct, return true, moving point to struct."
5437 (if (and (equal (char-after) ?\{)
5438 (verilog-backward-token))
5439 (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
5442 (defun verilog-parenthesis-depth ()
5443 "Return non zero if in parenthetical-expression."
5444 (save-excursion (nth 1 (verilog-syntax-ppss))))
5447 (defun verilog-skip-forward-comment-or-string ()
5448 "Return true if in a string or comment."
5449 (let ((state (save-excursion (verilog-syntax-ppss))))
5451 ((nth 3 state) ;Inside string
5452 (search-forward "\"")
5454 ((nth 7 state) ;Inside // comment
5457 ((nth 4 state) ;Inside any comment (hence /**/)
5458 (search-forward "*/"))
5462 (defun verilog-skip-backward-comment-or-string ()
5463 "Return true if in a string or comment."
5464 (let ((state (save-excursion (verilog-syntax-ppss))))
5466 ((nth 3 state) ;Inside string
5467 (search-backward "\"")
5469 ((nth 7 state) ;Inside // comment
5470 (search-backward "//")
5471 (skip-chars-backward "/")
5473 ((nth 4 state) ;Inside /* */ comment
5474 (search-backward "/*")
5479 (defun verilog-skip-backward-comments ()
5480 "Return true if a comment was skipped."
5484 (let ((state (save-excursion (verilog-syntax-ppss))))
5486 ((nth 7 state) ;Inside // comment
5487 (search-backward "//")
5488 (skip-chars-backward "/")
5489 (skip-chars-backward " \t\n\f")
5491 ((nth 4 state) ;Inside /* */ comment
5492 (search-backward "/*")
5493 (skip-chars-backward " \t\n\f")
5496 (= (char-before) ?\/)
5497 (= (char-before (1- (point))) ?\*))
5498 (goto-char (- (point) 2))
5499 t) ;; Let nth 4 state handle the rest
5501 (= (char-before) ?\))
5502 (= (char-before (1- (point))) ?\*))
5503 (goto-char (- (point) 2))
5504 (if (search-backward "(*" nil t)
5506 (skip-chars-backward " \t\n\f")
5509 (goto-char (+ (point) 2))
5512 (/= (skip-chars-backward " \t\n\f") 0))))))))
5514 (defun verilog-skip-forward-comment-p ()
5515 "If in comment, move to end and return true."
5517 (state (save-excursion (verilog-syntax-ppss)))
5519 ((nth 3 state) ;Inside string
5521 ((nth 7 state) ;Inside // comment
5525 ((nth 4 state) ;Inside /* comment
5526 (search-forward "*/")
5528 ((verilog-in-attribute-p) ;Inside (* attribute
5529 (search-forward "*)" nil t)
5532 (skip-chars-forward " \t\n\f")
5535 ((looking-at "\\/\\*")
5538 (goto-char (match-end 0))
5539 (if (search-forward "*/" nil t)
5541 (skip-chars-forward " \t\n\f")
5546 ((looking-at "(\\*")
5549 (goto-char (match-end 0))
5550 (if (search-forward "*)" nil t)
5552 (skip-chars-forward " \t\n\f")
5560 (defun verilog-indent-line-relative ()
5561 "Cheap version of indent line.
5562 Only look at a few lines to determine indent level."
5566 (if (looking-at "^[ \t]*$")
5567 (cond ;- A blank line; No need to be too smart.
5569 (setq indent-str (list 'cpp 0)))
5570 ((verilog-continued-line)
5571 (let ((sp1 (point)))
5572 (if (verilog-continued-line)
5576 (list 'statement (verilog-current-indent-level))))
5578 (setq indent-str (list 'block (verilog-current-indent-level)))))
5581 (setq indent-str (verilog-calculate-indent))))
5582 (progn (skip-chars-forward " \t")
5583 (setq indent-str (verilog-calculate-indent))))
5584 (verilog-do-indent indent-str)))
5586 (defun verilog-indent-line ()
5587 "Indent for special part of code."
5588 (verilog-do-indent (verilog-calculate-indent)))
5590 (defun verilog-do-indent (indent-str)
5591 (let ((type (car indent-str))
5592 (ind (car (cdr indent-str))))
5594 (; handle continued exp
5596 (let ((here (point)))
5597 (verilog-backward-syntactic-ws)
5600 (= (preceding-char) ?\,)
5601 (= (preceding-char) ?\])
5603 (verilog-beg-of-statement-1)
5604 (looking-at verilog-declaration-re)))
5609 (verilog-beg-of-statement-1)
5611 (if (looking-at verilog-declaration-re)
5612 (progn ;; we have multiple words
5613 (goto-char (match-end 0))
5614 (skip-chars-forward " \t")
5616 ((and verilog-indent-declaration-macros
5617 (= (following-char) ?\`))
5621 (skip-chars-forward " \t")))
5622 ((= (following-char) ?\[)
5625 (verilog-backward-up-list -1)
5626 (skip-chars-forward " \t"))))
5630 (+ (current-column) verilog-cexp-indent))))))
5632 (indent-line-to val)))
5633 ((= (preceding-char) ?\) )
5635 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
5636 (indent-line-to val)))
5640 (verilog-beg-of-statement-1)
5641 (if (and (< (point) here)
5642 (verilog-re-search-forward "=[ \\t]*" here 'move))
5643 (setq val (current-column))
5644 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
5646 (indent-line-to val))))))
5648 (; handle inside parenthetical expressions
5649 (eq type 'cparenexp)
5651 (val (save-excursion
5652 (verilog-backward-up-list 1)
5654 (if verilog-indent-lists
5655 (skip-chars-forward " \t")
5656 (verilog-forward-syntactic-ws))
5660 (decl (save-excursion
5662 (verilog-forward-syntactic-ws)
5664 (looking-at verilog-declaration-re))))
5665 (indent-line-to val)
5667 (verilog-pretty-declarations))))
5669 (;-- Handle the ends
5671 (looking-at verilog-end-block-re )
5672 (verilog-at-close-constraint-p))
5673 (let ((val (if (eq type 'statement)
5674 (- ind verilog-indent-level)
5676 (indent-line-to val)))
5678 (;-- Case -- maybe line 'em up
5679 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
5682 ((looking-at "\\<endcase\\>")
5683 (indent-line-to ind))
5685 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
5686 (indent-line-to val))))))
5689 (and (eq type 'defun)
5690 (looking-at verilog-zero-indent-re))
5697 (looking-at verilog-declaration-re))
5698 (verilog-indent-declaration ind))
5700 (;-- Everything else
5702 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
5703 (indent-line-to val))))
5705 (if (looking-at "[ \t]+$")
5706 (skip-chars-forward " \t"))
5707 indent-str ; Return indent data
5710 (defun verilog-current-indent-level ()
5711 "Return the indent-level of the current statement."
5715 (setq par-pos (verilog-parenthesis-depth))
5719 (setq par-pos (verilog-parenthesis-depth)))
5720 (skip-chars-forward " \t")
5723 (defun verilog-case-indent-level ()
5724 "Return the indent-level of the current statement.
5725 Do not count named blocks or case-statements."
5727 (skip-chars-forward " \t")
5729 ((looking-at verilog-named-block-re)
5731 ((and (not (looking-at verilog-extended-case-re))
5732 (looking-at "^[^:;]+[ \t]*:"))
5733 (verilog-re-search-forward ":" nil t)
5734 (skip-chars-forward " \t")
5737 (current-column)))))
5739 (defun verilog-indent-comment ()
5740 "Indent current line as comment."
5743 ((verilog-in-star-comment-p)
5745 (re-search-backward "/\\*" nil t)
5746 (1+(current-column))))
5751 (re-search-backward "//" nil t)
5752 (current-column))))))
5753 (indent-line-to stcol)
5756 (defun verilog-more-comment ()
5757 "Make more comment lines like the previous."
5761 ((verilog-in-star-comment-p)
5764 (re-search-backward "/\\*" nil t)
5765 (1+(current-column))))
5770 (re-search-backward "//" nil t)
5771 (current-column))))))
5777 (skip-chars-forward " \t")
5781 (defun verilog-comment-indent (&optional arg)
5782 "Return the column number the line should be indented to.
5783 ARG is ignored, for `comment-indent-function' compatibility."
5785 ((verilog-in-star-comment-p)
5787 (re-search-backward "/\\*" nil t)
5788 (1+(current-column))))
5793 (re-search-backward "//" nil t)
5794 (current-column)))))
5798 (defun verilog-pretty-declarations (&optional quiet)
5799 "Line up declarations around point.
5800 Be verbose about progress unless optional QUIET set."
5802 (let* ((m1 (make-marker))
5816 ; (verilog-beg-of-statement-1)
5818 (verilog-forward-syntactic-ws)
5819 (and (not (verilog-in-directive-p)) ;; could have `define input foo
5820 (looking-at verilog-declaration-re)))
5822 (if (verilog-parenthesis-depth)
5823 ;; in an argument list or parameter block
5824 (setq el (verilog-backward-up-list -1)
5827 (verilog-backward-up-list 1)
5828 (forward-line) ;; ignore ( input foo,
5829 (verilog-re-search-forward verilog-declaration-re el 'move)
5830 (goto-char (match-beginning 0))
5831 (skip-chars-backward " \t")
5833 startpos (set-marker (make-marker) start)
5836 (verilog-backward-up-list -1)
5838 (verilog-backward-syntactic-ws)
5840 endpos (set-marker (make-marker) end)
5844 (skip-chars-forward " \t")
5847 ;; in a declaration block (not in argument list)
5850 (verilog-beg-of-statement-1)
5851 (while (and (looking-at verilog-declaration-re)
5853 (skip-chars-backward " \t")
5856 (verilog-backward-syntactic-ws)
5858 (verilog-beg-of-statement-1))
5860 startpos (set-marker (make-marker) start)
5863 (verilog-end-of-statement)
5864 (setq e (point)) ;Might be on last line
5865 (verilog-forward-syntactic-ws)
5866 (while (looking-at verilog-declaration-re)
5867 (verilog-end-of-statement)
5869 (verilog-forward-syntactic-ws))
5871 endpos (set-marker (make-marker) end)
5874 (verilog-do-indent (verilog-calculate-indent))
5875 (verilog-forward-ws&directives)
5877 ;; OK, start and end are set
5878 (goto-char (marker-position startpos))
5879 (if (and (not quiet)
5880 (> (- end start) 100))
5881 (message "Lining up declarations..(please stand by)"))
5882 ;; Get the beginning of line indent first
5883 (while (progn (setq e (marker-position endpos))
5886 ((save-excursion (skip-chars-backward " \t")
5888 (verilog-forward-ws&directives)
5889 (indent-line-to base-ind)
5890 (verilog-forward-ws&directives)
5892 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
5895 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
5898 ;; Now find biggest prefix
5899 (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
5900 ;; Now indent each line.
5901 (goto-char (marker-position startpos))
5902 (while (progn (setq e (marker-position endpos))
5903 (setq r (- e (point)))
5906 (unless quiet (message "%d" r))
5907 ;;(verilog-do-indent (verilog-calculate-indent)))
5908 (verilog-forward-ws&directives)
5910 ((or (and verilog-indent-declaration-macros
5911 (looking-at verilog-declaration-re-2-macro))
5912 (looking-at verilog-declaration-re-2-no-macro))
5913 (let ((p (match-end 0)))
5915 (if (verilog-re-search-forward "[[#`]" p 'move)
5919 (goto-char (marker-position m1))
5925 ((verilog-continued-line-1 (marker-position startpos))
5927 (indent-line-to ind))
5928 ((verilog-in-struct-p)
5929 ;; could have a declaration of a user defined item
5931 (verilog-end-of-statement))
5932 (t ; Must be comment or white space
5934 (verilog-forward-ws&directives)
5937 (unless quiet (message "")))))))
5939 (defun verilog-pretty-expr (&optional quiet myre)
5940 "Line up expressions around point, optionally QUIET with regexp MYRE."
5941 (interactive "i\nsRegular Expression: ((<|:)?=) ")
5943 (if (or (eq myre nil)
5944 (string-equal myre ""))
5945 (setq myre "\\(<\\|:\\)?="))
5946 ;; want to match the first <= | := | =
5947 (setq myre (concat "\\(^.*?\\)\\(" myre "\\)"))
5948 (let ((rexp(concat "^\\s-*" verilog-complete-reg)))
5950 (if (and (not (looking-at rexp ))
5953 (goto-char (match-beginning 2))
5954 (not (verilog-in-comment-or-string-p))))
5955 (let* ((here (point))
5961 (verilog-backward-syntactic-ws)
5963 (while (and (not (looking-at rexp ))
5968 (verilog-backward-syntactic-ws)
5970 ) ;Ack, need to grok `define
5976 (setq e (point)) ;Might be on last line
5977 (verilog-forward-syntactic-ws)
5980 (not (looking-at rexp ))
5984 (not (eq e (point)))))
5986 (verilog-forward-syntactic-ws)
5990 (endpos (set-marker (make-marker) end))
5994 (verilog-do-indent (verilog-calculate-indent))
5995 (if (and (not quiet)
5996 (> (- end start) 100))
5997 (message "Lining up expressions..(please stand by)"))
5999 ;; Set indent to minimum throughout region
6000 (while (< (point) (marker-position endpos))
6002 (verilog-just-one-space myre)
6004 (verilog-forward-syntactic-ws)
6007 ;; Now find biggest prefix
6008 (setq ind (verilog-get-lineup-indent-2 myre start endpos))
6010 ;; Now indent each line.
6012 (while (progn (setq e (marker-position endpos))
6013 (setq r (- e (point)))
6016 (if (not quiet) (message "%d" r))
6019 (goto-char (match-beginning 2))
6020 (if (not (verilog-parenthesis-depth)) ;; ignore parenthesized exprs
6021 (if (eq (char-after) ?=)
6022 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
6025 ((verilog-continued-line-1 start)
6027 (indent-line-to ind))
6028 (t ; Must be comment or white space
6030 (verilog-forward-ws&directives)
6034 (unless quiet (message ""))
6037 (defun verilog-just-one-space (myre)
6038 "Remove extra spaces around regular expression MYRE."
6040 (if (and (not(looking-at verilog-complete-reg))
6042 (let ((p1 (match-end 1))
6046 (if (looking-at "\\s-") (just-one-space))
6049 (if (looking-at "\\s-") (just-one-space))
6052 (defun verilog-indent-declaration (baseind)
6053 "Indent current lines as declaration.
6054 Line up the variable names based on previous declaration's indentation.
6055 BASEIND is the base indent to offset everything."
6057 (let ((pos (point-marker))
6058 (lim (save-excursion
6059 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
6060 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
6066 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6067 (indent-line-to val)
6069 ;; Use previous declaration (in this module) as template.
6070 (if (or (eq 'all verilog-auto-lineup)
6071 (eq 'declarations verilog-auto-lineup))
6072 (if (verilog-re-search-backward
6073 (or (and verilog-indent-declaration-macros
6074 verilog-declaration-re-1-macro)
6075 verilog-declaration-re-1-no-macro) lim t)
6077 (goto-char (match-end 0))
6078 (skip-chars-forward " \t")
6079 (setq ind (current-column))
6083 (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6084 (indent-line-to val)
6085 (if (and verilog-indent-declaration-macros
6086 (looking-at verilog-declaration-re-2-macro))
6087 (let ((p (match-end 0)))
6089 (if (verilog-re-search-forward "[[#`]" p 'move)
6093 (goto-char (marker-position m1))
6096 (if (/= (current-column) ind)
6100 (if (looking-at verilog-declaration-re-2-no-macro)
6101 (let ((p (match-end 0)))
6103 (if (verilog-re-search-forward "[[`#]" p 'move)
6107 (goto-char (marker-position m1))
6110 (if (/= (current-column) ind)
6113 (indent-to ind))))))))))
6116 (defun verilog-get-lineup-indent (b edpos)
6117 "Return the indent level that will line up several lines within the region.
6118 Region is defined by B and EDPOS."
6122 ;; Get rightmost position
6123 (while (progn (setq e (marker-position edpos))
6125 (if (verilog-re-search-forward
6126 (or (and verilog-indent-declaration-macros
6127 verilog-declaration-re-1-macro)
6128 verilog-declaration-re-1-no-macro) e 'move)
6130 (goto-char (match-end 0))
6131 (verilog-backward-syntactic-ws)
6132 (if (> (current-column) ind)
6133 (setq ind (current-column)))
6134 (goto-char (match-end 0)))))
6137 ;; No lineup-string found
6140 (verilog-backward-syntactic-ws)
6141 ;;(skip-chars-backward " \t")
6142 (1+ (current-column))))))
6144 (defun verilog-get-lineup-indent-2 (myre b edpos)
6145 "Return the indent level that will line up several lines within the region."
6149 ;; Get rightmost position
6150 (while (progn (setq e (marker-position edpos))
6152 (if (and (verilog-re-search-forward myre e 'move)
6153 (not (verilog-parenthesis-depth))) ;; skip parenthesized exprs
6155 (goto-char (match-beginning 2))
6156 (verilog-backward-syntactic-ws)
6157 (if (> (current-column) ind)
6158 (setq ind (current-column)))
6159 (goto-char (match-end 0)))
6163 ;; No lineup-string found
6166 (skip-chars-backward " \t")
6167 (1+ (current-column))))))
6169 (defun verilog-comment-depth (type val)
6170 "A useful mode debugging aide. TYPE and VAL are comments for insertion."
6178 (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t)
6180 (replace-match " /* -# ## */")
6184 (insert " /* ## ## */"))))
6187 (format "%s %d" type val))))
6193 (defvar verilog-str nil)
6194 (defvar verilog-all nil)
6195 (defvar verilog-pred nil)
6196 (defvar verilog-buffer-to-use nil)
6197 (defvar verilog-flag nil)
6198 (defvar verilog-toggle-completions nil
6199 "*True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
6200 Repeated use of \\[verilog-complete-word] will show you all of them.
6201 Normally, when there is more than one possible completion,
6202 it displays a list of all possible completions.")
6205 (defvar verilog-type-keywords
6207 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
6208 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
6209 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
6210 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
6211 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
6212 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
6214 "*Keywords for types used when completing a word in a declaration or parmlist.
6215 \(integer, real, reg...)")
6217 (defvar verilog-cpp-keywords
6218 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
6220 "*Keywords to complete when at first word of a line in declarative scope.
6221 \(initial, always, begin, assign...)
6222 The procedures and variables defined within the Verilog program
6223 will be completed at runtime and should not be added to this list.")
6225 (defvar verilog-defun-keywords
6228 "always" "always_comb" "always_ff" "always_latch" "assign"
6229 "begin" "end" "generate" "endgenerate" "module" "endmodule"
6230 "specify" "endspecify" "function" "endfunction" "initial" "final"
6231 "task" "endtask" "primitive" "endprimitive"
6233 verilog-type-keywords)
6234 "*Keywords to complete when at first word of a line in declarative scope.
6235 \(initial, always, begin, assign...)
6236 The procedures and variables defined within the Verilog program
6237 will be completed at runtime and should not be added to this list.")
6239 (defvar verilog-block-keywords
6241 "begin" "break" "case" "continue" "else" "end" "endfunction"
6242 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
6243 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
6245 "*Keywords to complete when at first word of a line in behavioral scope.
6246 \(begin, if, then, else, for, fork...)
6247 The procedures and variables defined within the Verilog program
6248 will be completed at runtime and should not be added to this list.")
6250 (defvar verilog-tf-keywords
6251 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
6252 "*Keywords to complete when at first word of a line in a task or function.
6253 \(begin, if, then, else, for, fork.)
6254 The procedures and variables defined within the Verilog program
6255 will be completed at runtime and should not be added to this list.")
6257 (defvar verilog-case-keywords
6258 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
6259 "*Keywords to complete when at first word of a line in case scope.
6260 \(begin, if, then, else, for, fork...)
6261 The procedures and variables defined within the Verilog program
6262 will be completed at runtime and should not be added to this list.")
6264 (defvar verilog-separator-keywords
6265 '("else" "then" "begin")
6266 "*Keywords to complete when NOT standing at the first word of a statement.
6267 \(else, then, begin...)
6268 Variables and function names defined within the Verilog program
6269 will be completed at runtime and should not be added to this list.")
6271 (defvar verilog-gate-ios
6272 ;; All these have an implied {"input"...} at the end
6286 ("pulldown" "output")
6291 ("rtran" "inout" "inout")
6292 ("rtranif0" "inout" "inout")
6293 ("rtranif1" "inout" "inout")
6294 ("tran" "inout" "inout")
6295 ("tranif0" "inout" "inout")
6296 ("tranif1" "inout" "inout")
6299 "*Map of direction for each positional argument to each gate primitive.")
6301 (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
6302 "*Keywords for gate primitives.")
6304 (defun verilog-string-diff (str1 str2)
6305 "Return index of first letter where STR1 and STR2 differs."
6309 (if (or (> (1+ diff) (length str1))
6310 (> (1+ diff) (length str2)))
6312 (or (equal (aref str1 diff) (aref str2 diff))
6314 (setq diff (1+ diff))))))
6316 ;; Calculate all possible completions for functions if argument is `function',
6317 ;; completions for procedures if argument is `procedure' or both functions and
6318 ;; procedures otherwise.
6320 (defun verilog-func-completion (type)
6321 "Build regular expression for module/task/function names.
6322 TYPE is 'module, 'tf for task or function, or t if unknown."
6323 (if (string= verilog-str "")
6324 (setq verilog-str "[a-zA-Z_]"))
6325 (let ((verilog-str (concat (cond
6326 ((eq type 'module) "\\<\\(module\\)\\s +")
6327 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
6328 (t "\\<\\(task\\|function\\|module\\)\\s +"))
6329 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
6332 (if (not (looking-at verilog-defun-re))
6333 (verilog-re-search-backward verilog-defun-re nil t))
6336 ;; Search through all reachable functions
6337 (goto-char (point-min))
6338 (while (verilog-re-search-forward verilog-str (point-max) t)
6339 (progn (setq match (buffer-substring (match-beginning 2)
6341 (if (or (null verilog-pred)
6342 (funcall verilog-pred match))
6343 (setq verilog-all (cons match verilog-all)))))
6344 (if (match-beginning 0)
6345 (goto-char (match-beginning 0)))))
6347 (defun verilog-get-completion-decl (end)
6348 "Macro for searching through current declaration (var, type or const)
6349 for matches of `str' and adding the occurrence tp `all' through point END."
6350 (let ((re (or (and verilog-indent-declaration-macros
6351 verilog-declaration-re-2-macro)
6352 verilog-declaration-re-2-no-macro))
6355 (while (and (< (point) end)
6356 (verilog-re-search-forward re end t))
6357 ;; Traverse current line
6358 (setq decl-end (save-excursion (verilog-declaration-end)))
6359 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
6360 (not (match-end 1)))
6361 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
6362 (if (string-match (concat "\\<" verilog-str) match)
6363 (if (or (null verilog-pred)
6364 (funcall verilog-pred match))
6365 (setq verilog-all (cons match verilog-all)))))
6369 (defun verilog-type-completion ()
6370 "Calculate all possible completions for types."
6371 (let ((start (point))
6373 ;; Search for all reachable type declarations
6374 (while (or (verilog-beg-of-defun)
6375 (setq goon (not goon)))
6377 (if (and (< start (prog1 (save-excursion (verilog-end-of-defun)
6380 (verilog-re-search-forward
6381 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
6383 (not (match-end 1)))
6384 ;; Check current type declaration
6385 (verilog-get-completion-decl start))))))
6387 (defun verilog-var-completion ()
6388 "Calculate all possible completions for variables (or constants)."
6389 (let ((start (point)))
6390 ;; Search for all reachable var declarations
6391 (verilog-beg-of-defun)
6393 ;; Check var declarations
6394 (verilog-get-completion-decl start))))
6396 (defun verilog-keyword-completion (keyword-list)
6397 "Give list of all possible completions of keywords in KEYWORD-LIST."
6398 (mapcar '(lambda (s)
6399 (if (string-match (concat "\\<" verilog-str) s)
6400 (if (or (null verilog-pred)
6401 (funcall verilog-pred s))
6402 (setq verilog-all (cons s verilog-all)))))
6406 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
6407 "Function passed to `completing-read', `try-completion' or `all-completions'.
6408 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
6409 must be a function to be called for every match to check if this should
6410 really be a match. If VERILOG-FLAG is t, the function returns a list of
6411 all possible completions. If VERILOG-FLAG is nil it returns a string,
6412 the longest possible completion, or t if VERILOG-STR is an exact match.
6413 If VERILOG-FLAG is 'lambda, the function returns t if VERILOG-STR is an
6414 exact match, nil otherwise."
6416 (let ((verilog-all nil))
6417 ;; Set buffer to use for searching labels. This should be set
6418 ;; within functions which use verilog-completions
6419 (set-buffer verilog-buffer-to-use)
6421 ;; Determine what should be completed
6422 (let ((state (car (verilog-calculate-indent))))
6423 (cond ((eq state 'defun)
6424 (save-excursion (verilog-var-completion))
6425 (verilog-func-completion 'module)
6426 (verilog-keyword-completion verilog-defun-keywords))
6428 ((eq state 'behavioral)
6429 (save-excursion (verilog-var-completion))
6430 (verilog-func-completion 'module)
6431 (verilog-keyword-completion verilog-defun-keywords))
6434 (save-excursion (verilog-var-completion))
6435 (verilog-func-completion 'tf)
6436 (verilog-keyword-completion verilog-block-keywords))
6439 (save-excursion (verilog-var-completion))
6440 (verilog-func-completion 'tf)
6441 (verilog-keyword-completion verilog-case-keywords))
6444 (save-excursion (verilog-var-completion))
6445 (verilog-func-completion 'tf)
6446 (verilog-keyword-completion verilog-tf-keywords))
6449 (save-excursion (verilog-var-completion))
6450 (verilog-keyword-completion verilog-cpp-keywords))
6452 ((eq state 'cparenexp)
6453 (save-excursion (verilog-var-completion)))
6456 (save-excursion (verilog-var-completion))
6457 (verilog-func-completion 'both)
6458 (verilog-keyword-completion verilog-separator-keywords))))
6460 ;; Now we have built a list of all matches. Give response to caller
6461 (verilog-completion-response))))
6463 (defun verilog-completion-response ()
6464 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
6465 ;; This was not called by all-completions
6466 (if (null verilog-all)
6467 ;; Return nil if there was no matching label
6469 ;; Get longest string common in the labels
6470 (let* ((elm (cdr verilog-all))
6471 (match (car verilog-all))
6472 (min (length match))
6474 (if (string= match verilog-str)
6475 ;; Return t if first match was an exact match
6477 (while (not (null elm))
6478 ;; Find longest common string
6479 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
6482 (setq match (substring match 0 min))))
6483 ;; Terminate with match=t if this is an exact match
6484 (if (string= (car elm) verilog-str)
6488 (setq elm (cdr elm)))))
6489 ;; If this is a test just for exact match, return nil ot t
6490 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
6493 ;; If flag is t, this was called by all-completions. Return
6494 ;; list of all possible completions
6498 (defvar verilog-last-word-numb 0)
6499 (defvar verilog-last-word-shown nil)
6500 (defvar verilog-last-completions nil)
6502 (defun verilog-complete-word ()
6503 "Complete word at current point.
6504 \(See also `verilog-toggle-completions', `verilog-type-keywords',
6505 and `verilog-separator-keywords'.)"
6507 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
6508 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
6509 (verilog-str (buffer-substring b e))
6510 ;; The following variable is used in verilog-completion
6511 (verilog-buffer-to-use (current-buffer))
6512 (allcomp (if (and verilog-toggle-completions
6513 (string= verilog-last-word-shown verilog-str))
6514 verilog-last-completions
6515 (all-completions verilog-str 'verilog-completion)))
6516 (match (if verilog-toggle-completions
6518 verilog-str (mapcar '(lambda (elm)
6519 (cons elm 0)) allcomp)))))
6520 ;; Delete old string
6523 ;; Toggle-completions inserts whole labels
6524 (if verilog-toggle-completions
6526 ;; Update entry number in list
6527 (setq verilog-last-completions allcomp
6528 verilog-last-word-numb
6529 (if (>= verilog-last-word-numb (1- (length allcomp)))
6531 (1+ verilog-last-word-numb)))
6532 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
6533 ;; Display next match or same string if no match was found
6534 (if (not (null allcomp))
6535 (insert "" verilog-last-word-shown)
6536 (insert "" verilog-str)
6537 (message "(No match)")))
6538 ;; The other form of completion does not necessarily do that.
6540 ;; Insert match if found, or the original string if no match
6541 (if (or (null match) (equal match 't))
6542 (progn (insert "" verilog-str)
6543 (message "(No match)"))
6545 ;; Give message about current status of completion
6546 (cond ((equal match 't)
6547 (if (not (null (cdr allcomp)))
6548 (message "(Complete but not unique)")
6549 (message "(Sole completion)")))
6550 ;; Display buffer if the current completion didn't help
6551 ;; on completing the label.
6552 ((and (not (null (cdr allcomp))) (= (length verilog-str)
6554 (with-output-to-temp-buffer "*Completions*"
6555 (display-completion-list allcomp))
6556 ;; Wait for a key press. Then delete *Completion* window
6557 (momentary-string-display "" (point))
6558 (delete-window (get-buffer-window (get-buffer "*Completions*")))
6561 (defun verilog-show-completions ()
6562 "Show all possible completions at current point."
6564 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
6565 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
6566 (verilog-str (buffer-substring b e))
6567 ;; The following variable is used in verilog-completion
6568 (verilog-buffer-to-use (current-buffer))
6569 (allcomp (if (and verilog-toggle-completions
6570 (string= verilog-last-word-shown verilog-str))
6571 verilog-last-completions
6572 (all-completions verilog-str 'verilog-completion))))
6573 ;; Show possible completions in a temporary buffer.
6574 (with-output-to-temp-buffer "*Completions*"
6575 (display-completion-list allcomp))
6576 ;; Wait for a key press. Then delete *Completion* window
6577 (momentary-string-display "" (point))
6578 (delete-window (get-buffer-window (get-buffer "*Completions*")))))
6581 (defun verilog-get-default-symbol ()
6582 "Return symbol around current point as a string."
6584 (buffer-substring (progn
6585 (skip-chars-backward " \t")
6586 (skip-chars-backward "a-zA-Z0-9_")
6589 (skip-chars-forward "a-zA-Z0-9_")
6592 (defun verilog-build-defun-re (str &optional arg)
6593 "Return function/task/module starting with STR as regular expression.
6594 With optional second ARG non-nil, STR is the complete name of the instruction."
6596 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
6597 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
6599 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
6600 "Function passed to `completing-read', `try-completion' or `all-completions'.
6601 Returns a completion on any function name based on VERILOG-STR prefix. If
6602 VERILOG-PRED is non-nil, it must be a function to be called for every match
6603 to check if this should really be a match. If VERILOG-FLAG is t, the
6604 function returns a list of all possible completions. If it is nil it
6605 returns a string, the longest possible completion, or t if VERILOG-STR is
6606 an exact match. If VERILOG-FLAG is 'lambda, the function returns t if
6607 VERILOG-STR is an exact match, nil otherwise."
6609 (let ((verilog-all nil)
6612 ;; Set buffer to use for searching labels. This should be set
6613 ;; within functions which use verilog-completions
6614 (set-buffer verilog-buffer-to-use)
6616 (let ((verilog-str verilog-str))
6617 ;; Build regular expression for functions
6618 (if (string= verilog-str "")
6619 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
6620 (setq verilog-str (verilog-build-defun-re verilog-str)))
6621 (goto-char (point-min))
6623 ;; Build a list of all possible completions
6624 (while (verilog-re-search-forward verilog-str nil t)
6625 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
6626 (if (or (null verilog-pred)
6627 (funcall verilog-pred match))
6628 (setq verilog-all (cons match verilog-all)))))
6630 ;; Now we have built a list of all matches. Give response to caller
6631 (verilog-completion-response))))
6633 (defun verilog-goto-defun ()
6634 "Move to specified Verilog module/interface/task/function.
6635 The default is a name found in the buffer around point.
6636 If search fails, other files are checked based on
6637 `verilog-library-flags'."
6639 (let* ((default (verilog-get-default-symbol))
6640 ;; The following variable is used in verilog-comp-function
6641 (verilog-buffer-to-use (current-buffer))
6642 (label (if (not (string= default ""))
6643 ;; Do completion with default
6644 (completing-read (concat "Goto-Label: (default "
6646 'verilog-comp-defun nil nil "")
6647 ;; There is no default value. Complete without it
6648 (completing-read "Goto-Label: "
6649 'verilog-comp-defun nil nil "")))
6651 ;; Make sure library paths are correct, in case need to resolve module
6652 (verilog-auto-reeval-locals)
6653 (verilog-getopt-flags)
6654 ;; If there was no response on prompt, use default value
6655 (if (string= label "")
6656 (setq label default))
6657 ;; Goto right place in buffer if label is not an empty string
6658 (or (string= label "")
6661 (goto-char (point-min))
6663 (re-search-forward (verilog-build-defun-re label t) nil t)))
6666 (beginning-of-line))
6668 (verilog-goto-defun-file label))))
6670 ;; Eliminate compile warning
6671 (defvar occur-pos-list)
6673 (defun verilog-showscopes ()
6674 "List all scopes in this module."
6676 (let ((buffer (current-buffer))
6680 (prevpos (point-min))
6681 (final-context-start (make-marker))
6682 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
6683 (with-output-to-temp-buffer "*Occur*"
6685 (message (format "Searching for %s ..." regexp))
6686 ;; Find next match, but give up if prev match was at end of buffer.
6687 (while (and (not (= prevpos (point-max)))
6688 (verilog-re-search-forward regexp nil t))
6689 (goto-char (match-beginning 0))
6692 (setq linenum (+ linenum (count-lines prevpos (point)))))
6693 (setq prevpos (point))
6694 (goto-char (match-end 0))
6695 (let* ((start (save-excursion
6696 (goto-char (match-beginning 0))
6697 (forward-line (if (< nlines 0) nlines (- nlines)))
6699 (end (save-excursion
6700 (goto-char (match-end 0))
6702 (forward-line (1+ nlines))
6705 (tag (format "%3d" linenum))
6706 (empty (make-string (length tag) ?\ ))
6709 (setq tem (make-marker))
6710 (set-marker tem (point))
6711 (set-buffer standard-output)
6712 (setq occur-pos-list (cons tem occur-pos-list))
6713 (or first (zerop nlines)
6714 (insert "--------\n"))
6716 (insert-buffer-substring buffer start end)
6717 (backward-char (- end start))
6718 (setq tem (if (< nlines 0) (- nlines) nlines))
6722 (setq tem (1- tem)))
6723 (let ((this-linenum linenum))
6724 (set-marker final-context-start
6725 (+ (point) (- (match-end 0) (match-beginning 0))))
6726 (while (< (point) final-context-start)
6728 (setq tag (format "%3d" this-linenum)))
6729 (insert tag ?:)))))))
6730 (set-buffer-modified-p nil))))
6733 ;; Highlight helper functions
6734 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
6735 (defun verilog-within-translate-off ()
6736 "Return point if within translate-off region, else nil."
6737 (and (save-excursion
6739 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
6741 (equal "off" (match-string 2))
6744 (defun verilog-start-translate-off (limit)
6745 "Return point before translate-off directive if before LIMIT, else nil."
6746 (when (re-search-forward
6747 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
6749 (match-beginning 0)))
6751 (defun verilog-back-to-start-translate-off (limit)
6752 "Return point before translate-off directive if before LIMIT, else nil."
6753 (when (re-search-backward
6754 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
6756 (match-beginning 0)))
6758 (defun verilog-end-translate-off (limit)
6759 "Return point after translate-on directive if before LIMIT, else nil."
6761 (re-search-forward (concat
6762 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
6764 (defun verilog-match-translate-off (limit)
6765 "Match a translate-off block, setting `match-data' and returning t, else nil.
6766 Bound search by LIMIT."
6767 (when (< (point) limit)
6768 (let ((start (or (verilog-within-translate-off)
6769 (verilog-start-translate-off limit)))
6770 (case-fold-search t))
6772 (let ((end (or (verilog-end-translate-off limit) limit)))
6773 (set-match-data (list start end))
6774 (goto-char end))))))
6776 (defun verilog-font-lock-match-item (limit)
6777 "Match, and move over, any declaration item after point.
6778 Bound search by LIMIT. Adapted from
6779 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
6782 (narrow-to-region (point-min) limit)
6784 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
6786 (goto-char (match-end 1))
6787 ;; move to next item
6788 (if (looking-at "\\(\\s-*,\\)")
6789 (goto-char (match-end 1))
6794 ;; Added by Subbu Meiyappan for Header
6796 (defun verilog-header ()
6797 "Insert a standard Verilog file header.
6798 See also `verilog-sk-header' for an alternative format."
6800 (let ((start (point)))
6802 //-----------------------------------------------------------------------------
6804 // Project : <project>
6805 //-----------------------------------------------------------------------------
6806 // File : <filename>
6807 // Author : <author>
6808 // Created : <credate>
6809 // Last modified : <moddate>
6810 //-----------------------------------------------------------------------------
6813 //-----------------------------------------------------------------------------
6814 // Copyright (c) <copydate> by <company> This model is the confidential and
6815 // proprietary property of <company> and the possession or use of this
6816 // file requires a written license from <company>.
6817 //------------------------------------------------------------------------------
6818 // Modification history :
6820 //-----------------------------------------------------------------------------
6824 (search-forward "<filename>")
6825 (replace-match (buffer-name) t t)
6826 (search-forward "<author>") (replace-match "" t t)
6827 (insert (user-full-name))
6828 (insert " <" (user-login-name) "@" (system-name) ">")
6829 (search-forward "<credate>") (replace-match "" t t)
6830 (verilog-insert-date)
6831 (search-forward "<moddate>") (replace-match "" t t)
6832 (verilog-insert-date)
6833 (search-forward "<copydate>") (replace-match "" t t)
6834 (verilog-insert-year)
6835 (search-forward "<modhist>") (replace-match "" t t)
6836 (verilog-insert-date)
6837 (insert " : created")
6840 (setq string (read-string "title: "))
6841 (search-forward "<title>")
6842 (replace-match string t t)
6843 (setq string (read-string "project: " verilog-project))
6844 (setq verilog-project string)
6845 (search-forward "<project>")
6846 (replace-match string t t)
6847 (setq string (read-string "Company: " verilog-company))
6848 (setq verilog-company string)
6849 (search-forward "<company>")
6850 (replace-match string t t)
6851 (search-forward "<company>")
6852 (replace-match string t t)
6853 (search-forward "<company>")
6854 (replace-match string t t)
6855 (search-backward "<description>")
6856 (replace-match "" t t))))
6858 ;; verilog-header Uses the verilog-insert-date function
6860 (defun verilog-insert-date ()
6861 "Insert date from the system."
6863 (if verilog-date-scientific-format
6864 (insert (format-time-string "%Y/%m/%d"))
6865 (insert (format-time-string "%d.%m.%Y"))))
6867 (defun verilog-insert-year ()
6868 "Insert year from the system."
6870 (insert (format-time-string "%Y")))
6874 ;; Signal list parsing
6877 ;; Elements of a signal list
6878 (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
6879 (list name bits comment mem enum signed type multidim modport))
6880 (defsubst verilog-sig-name (sig)
6882 (defsubst verilog-sig-bits (sig)
6884 (defsubst verilog-sig-comment (sig)
6886 (defsubst verilog-sig-memory (sig)
6888 (defsubst verilog-sig-enum (sig)
6890 (defsubst verilog-sig-signed (sig)
6892 (defsubst verilog-sig-type (sig)
6894 (defsubst verilog-sig-multidim (sig)
6896 (defsubst verilog-sig-multidim-string (sig)
6897 (if (verilog-sig-multidim sig)
6898 (let ((str "") (args (verilog-sig-multidim sig)))
6900 (setq str (concat str (car args)))
6901 (setq args (cdr args)))
6903 (defsubst verilog-sig-modport (sig)
6905 (defsubst verilog-sig-width (sig)
6906 (verilog-make-width-expression (verilog-sig-bits sig)))
6908 (defsubst verilog-alw-new (outputs temps inputs delayed)
6909 (list outputs temps inputs delayed))
6910 (defsubst verilog-alw-get-outputs (sigs)
6912 (defsubst verilog-alw-get-temps (sigs)
6914 (defsubst verilog-alw-get-inputs (sigs)
6916 (defsubst verilog-alw-get-uses-delayed (sigs)
6919 (defsubst verilog-modi-new (name fob pt type)
6920 (vector name fob pt type))
6921 (defsubst verilog-modi-name (modi)
6923 (defsubst verilog-modi-file-or-buffer (modi)
6925 (defsubst verilog-modi-get-point (modi)
6927 (defsubst verilog-modi-get-type (modi) ;; "module" or "interface"
6929 (defsubst verilog-modi-get-decls (modi)
6930 (verilog-modi-cache-results modi 'verilog-read-decls))
6931 (defsubst verilog-modi-get-sub-decls (modi)
6932 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
6934 ;; Signal reading for given module
6935 ;; Note these all take modi's - as returned from verilog-modi-current
6936 (defsubst verilog-decls-new (out inout in wires regs assigns consts gparams interfaces)
6937 (vector out inout in wires regs assigns consts gparams interfaces))
6938 (defsubst verilog-decls-get-outputs (decls)
6940 (defsubst verilog-decls-get-inouts (decls)
6942 (defsubst verilog-decls-get-inputs (decls)
6944 (defsubst verilog-decls-get-wires (decls)
6946 (defsubst verilog-decls-get-regs (decls)
6948 (defsubst verilog-decls-get-assigns (decls)
6950 (defsubst verilog-decls-get-consts (decls)
6952 (defsubst verilog-decls-get-gparams (decls)
6954 (defsubst verilog-decls-get-interfaces (decls)
6957 (defsubst verilog-subdecls-new (out inout in intf intfd)
6958 (vector out inout in intf intfd))
6959 (defsubst verilog-subdecls-get-outputs (subdecls)
6961 (defsubst verilog-subdecls-get-inouts (subdecls)
6963 (defsubst verilog-subdecls-get-inputs (subdecls)
6965 (defsubst verilog-subdecls-get-interfaces (subdecls)
6967 (defsubst verilog-subdecls-get-interfaced (subdecls)
6970 (defun verilog-signals-not-in (in-list not-list)
6971 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
6972 Also remove any duplicates in IN-LIST.
6973 Signals must be in standard (base vector) form."
6974 ;; This function is hot, so implemented as O(1)
6975 (cond ((eval-when-compile (fboundp 'make-hash-table))
6976 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
6979 (puthash (car (car not-list)) t ht)
6980 (setq not-list (cdr not-list)))
6982 (when (not (gethash (car (car in-list)) ht))
6983 (setq out-list (cons (car in-list) out-list))
6984 (puthash (car (car in-list)) t ht))
6985 (setq in-list (cdr in-list)))
6986 (nreverse out-list)))
6987 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
6991 (if (not (or (assoc (car (car in-list)) not-list)
6992 (assoc (car (car in-list)) out-list)))
6993 (setq out-list (cons (car in-list) out-list)))
6994 (setq in-list (cdr in-list)))
6995 (nreverse out-list)))))
6996 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
6998 (defun verilog-signals-memory (in-list)
6999 "Return list of signals in IN-LIST that are memoried (multidimensional)."
7002 (if (nth 3 (car in-list))
7003 (setq out-list (cons (car in-list) out-list)))
7004 (setq in-list (cdr in-list)))
7006 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
7008 (defun verilog-signals-sort-compare (a b)
7009 "Compare signal A and B for sorting."
7010 (string< (car a) (car b)))
7012 (defun verilog-signals-not-params (in-list)
7013 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
7016 (unless (boundp (intern (concat "vh-" (car (car in-list)))))
7017 (setq out-list (cons (car in-list) out-list)))
7018 (setq in-list (cdr in-list)))
7019 (nreverse out-list)))
7021 (defun verilog-signals-combine-bus (in-list)
7022 "Return a list of signals in IN-LIST, with busses combined.
7023 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
7026 sig highbit lowbit ; Temp information about current signal
7027 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
7028 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
7031 ;; Shove signals so duplicated signals will be adjacent
7032 (setq in-list (sort in-list `verilog-signals-sort-compare))
7034 (setq sig (car in-list))
7035 ;; No current signal; form from existing details
7037 (setq sv-name (verilog-sig-name sig)
7040 sv-comment (verilog-sig-comment sig)
7041 sv-memory (verilog-sig-memory sig)
7042 sv-enum (verilog-sig-enum sig)
7043 sv-signed (verilog-sig-signed sig)
7044 sv-type (verilog-sig-type sig)
7045 sv-multidim (verilog-sig-multidim sig)
7046 sv-modport (verilog-sig-modport sig)
7049 ;; Extract bus details
7050 (setq bus (verilog-sig-bits sig))
7052 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
7053 (setq highbit (string-to-number (match-string 1 bus))
7054 lowbit (string-to-number
7055 (match-string 2 bus))))
7056 (and (string-match "\\[\\([0-9]+\\)\\]" bus)
7057 (setq highbit (string-to-number (match-string 1 bus))
7059 ;; Combine bits in bus
7061 (setq sv-highbit (max highbit sv-highbit)
7062 sv-lowbit (min lowbit sv-lowbit))
7063 (setq sv-highbit highbit
7066 ;; String, probably something like `preproc:0
7067 (setq sv-busstring bus)))
7068 ;; Peek ahead to next signal
7069 (setq in-list (cdr in-list))
7070 (setq sig (car in-list))
7071 (cond ((and sig (equal sv-name (verilog-sig-name sig)))
7072 ;; Combine with this signal
7073 (when (and sv-busstring
7074 (not (equal sv-busstring (verilog-sig-bits sig))))
7075 (when nil ;; Debugging
7076 (message (concat "Warning, can't merge into single bus "
7078 ", the AUTOs may be wrong")))
7079 (setq buswarn ", Couldn't Merge"))
7080 (if (verilog-sig-comment sig) (setq combo ", ..."))
7081 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
7082 sv-enum (or sv-enum (verilog-sig-enum sig))
7083 sv-signed (or sv-signed (verilog-sig-signed sig))
7084 sv-type (or sv-type (verilog-sig-type sig))
7085 sv-multidim (or sv-multidim (verilog-sig-multidim sig))
7086 sv-modport (or sv-modport (verilog-sig-modport sig))))
7087 ;; Doesn't match next signal, add to queue, zero in prep for next
7088 ;; Note sig may also be nil for the last signal in the list
7091 (cons (verilog-sig-new
7095 (concat "[" (int-to-string sv-highbit) ":"
7096 (int-to-string sv-lowbit) "]")))
7097 (concat sv-comment combo buswarn)
7098 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
7104 (defun verilog-sig-tieoff (sig &optional no-width)
7105 "Return tieoff expression for given SIG, with appropriate width.
7106 Ignore width if optional NO-WIDTH is set."
7107 (let* ((width (if no-width nil (verilog-sig-width sig))))
7109 (if (and verilog-active-low-regexp
7110 (string-match verilog-active-low-regexp (verilog-sig-name sig)))
7114 ((string-match "^[0-9]+$" width)
7115 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0")))
7117 (concat "{" width "{1'b0}}"))))))
7120 ;; Port/Wire/Etc Reading
7123 (defun verilog-read-inst-backward-name ()
7124 "Internal. Move point back to beginning of inst-name."
7125 (verilog-backward-open-paren)
7128 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary
7129 (cond ((looking-at ")")
7130 (verilog-backward-open-paren))
7131 (t (setq done t)))))
7132 (while (looking-at "\\]")
7133 (verilog-backward-open-bracket)
7134 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil))
7135 (skip-chars-backward "a-zA-Z0-9`_$"))
7137 (defun verilog-read-inst-module-matcher ()
7138 "Set match data 0 with module_name when point is inside instantiation."
7139 (verilog-read-inst-backward-name)
7140 ;; Skip over instantiation name
7141 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
7142 ;; Check for parameterized instantiations
7143 (when (looking-at ")")
7144 (verilog-backward-open-paren)
7145 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil))
7146 (skip-chars-backward "a-zA-Z0-9'_$")
7147 (looking-at "[a-zA-Z0-9`_\$]+")
7148 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7149 (buffer-substring-no-properties (match-beginning 0) (match-end 0))
7150 ;; Caller assumes match-beginning/match-end is still set
7153 (defun verilog-read-inst-module ()
7154 "Return module_name when point is inside instantiation."
7156 (verilog-read-inst-module-matcher)))
7158 (defun verilog-read-inst-name ()
7159 "Return instance_name when point is inside instantiation."
7161 (verilog-read-inst-backward-name)
7162 (looking-at "[a-zA-Z0-9`_\$]+")
7163 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7164 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
7166 (defun verilog-read-module-name ()
7167 "Return module name when after its ( or ;."
7169 (re-search-backward "[(;]")
7170 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil)
7171 (skip-chars-backward "a-zA-Z0-9`_$")
7172 (looking-at "[a-zA-Z0-9`_\$]+")
7173 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7174 (verilog-symbol-detick
7175 (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
7177 (defun verilog-read-inst-param-value ()
7178 "Return list of parameters and values when point is inside instantiation."
7180 (verilog-read-inst-backward-name)
7181 ;; Skip over instantiation name
7182 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
7183 ;; If there are parameterized instantiations
7184 (when (looking-at ")")
7185 (let ((end-pt (point))
7187 param-name paren-beg-pt param-value)
7188 (verilog-backward-open-paren)
7189 (while (verilog-re-search-forward-quick "\\." end-pt t)
7190 (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_\$]\\)" nil nil)
7191 (skip-chars-backward "a-zA-Z0-9'_$")
7192 (looking-at "[a-zA-Z0-9`_\$]+")
7193 (setq param-name (buffer-substring-no-properties
7194 (match-beginning 0) (match-end 0)))
7195 (verilog-re-search-forward-quick "(" nil nil)
7196 (setq paren-beg-pt (point))
7197 (verilog-forward-close-paren)
7198 (setq param-value (verilog-string-remove-spaces
7199 (buffer-substring-no-properties
7200 paren-beg-pt (1- (point)))))
7201 (setq params (cons (list param-name param-value) params)))
7204 (defun verilog-read-auto-params (num-param &optional max-param)
7205 "Return parameter list inside auto.
7206 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
7209 ;; /*AUTOPUNT("parameter", "parameter")*/
7210 (search-backward "(")
7211 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
7212 (setq olist (cons (match-string 1) olist))
7213 (goto-char (match-end 0))))
7214 (or (eq nil num-param)
7215 (<= num-param (length olist))
7216 (error "%s: Expected %d parameters" (verilog-point-text) num-param))
7217 (if (eq max-param nil) (setq max-param num-param))
7218 (or (eq nil max-param)
7219 (>= max-param (length olist))
7220 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
7223 (defun verilog-read-decls ()
7224 "Compute signal declaration information for the current module at point.
7225 Return a array of [outputs inouts inputs wire reg assign const]."
7226 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
7227 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
7229 sigs-in sigs-out sigs-inout sigs-wire sigs-reg sigs-assign sigs-const
7230 sigs-gparam sigs-intf
7231 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
7234 (verilog-beg-of-defun)
7235 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
7236 (while (< (point) end-mod-point)
7237 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
7240 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7241 (setq enum (match-string 1)))
7242 (search-forward "\n"))
7243 ((looking-at "/\\*")
7245 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7246 (setq enum (match-string 1)))
7247 (or (search-forward "*/")
7248 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
7249 ((looking-at "(\\*")
7251 (or (looking-at "\\s-*)") ; It's an "always @ (*)"
7252 (search-forward "*)")
7253 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
7254 ((eq ?\" (following-char))
7255 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first
7256 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
7257 ((eq ?\; (following-char))
7258 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
7259 v2kargs-ok nil in-modport nil)
7261 ((eq ?= (following-char))
7262 (setq rvalue t newsig nil)
7264 ((and (eq ?, (following-char))
7265 (eq paren sig-paren))
7268 ;; ,'s can occur inside {} & funcs
7269 ((looking-at "[{(]")
7270 (setq paren (1+ paren))
7272 ((looking-at "[})]")
7273 (setq paren (1- paren))
7275 (when (< paren sig-paren)
7276 (setq expect-signal nil))) ; ) that ends variables inside v2k arg list
7277 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
7278 (goto-char (match-end 0))
7279 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
7280 (setcar (cdr (cdr (cdr newsig))) (match-string 1)))
7281 (vec ;; Multidimensional
7282 (setq multidim (cons vec multidim))
7283 (setq vec (verilog-string-replace-matches
7284 "\\s-+" "" nil nil (match-string 1))))
7286 (setq vec (verilog-string-replace-matches
7287 "\\s-+" "" nil nil (match-string 1))))))
7288 ;; Normal or escaped identifier -- note we remember the \ if escaped
7289 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
7290 (goto-char (match-end 0))
7291 (setq keywd (match-string 1))
7292 (when (string-match "^\\\\" (match-string 1))
7293 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end
7294 ;; Add any :: package names to same identifier
7295 (while (looking-at "\\s-*::\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
7296 (goto-char (match-end 0))
7297 (setq keywd (concat keywd "::" (match-string 1)))
7298 (when (string-match "^\\\\" (match-string 1))
7299 (setq keywd (concat keywd " ")))) ;; Escaped ID needs space at end
7300 (cond ((equal keywd "input")
7301 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
7302 expect-signal 'sigs-in io t modport nil))
7303 ((equal keywd "output")
7304 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
7305 expect-signal 'sigs-out io t modport nil))
7306 ((equal keywd "inout")
7307 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
7308 expect-signal 'sigs-inout io t modport nil))
7309 ((equal keywd "parameter")
7310 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
7311 expect-signal 'sigs-gparam io t modport nil))
7312 ((member keywd '("wire" "tri" "tri0" "tri1" "triand" "trior" "wand" "wor"))
7313 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
7314 expect-signal 'sigs-wire modport nil)))
7315 ((member keywd '("reg" "trireg"
7316 "byte" "shortint" "int" "longint" "integer" "time"
7318 "shortreal" "real" "realtime"
7319 "string" "event" "chandle"))
7320 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
7321 expect-signal 'sigs-reg modport nil)))
7322 ((equal keywd "assign")
7323 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
7324 expect-signal 'sigs-assign modport nil))
7325 ((member keywd '("supply0" "supply1" "supply"
7326 "localparam" "genvar"))
7327 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
7328 expect-signal 'sigs-const modport nil)))
7329 ((equal keywd "signed")
7330 (setq signed "signed"))
7331 ((member keywd '("class" "clocking" "covergroup" "function"
7332 "property" "randsequence" "sequence" "task"))
7333 (setq functask (1+ functask)))
7334 ((member keywd '("endclass" "endclocking" "endgroup" "endfunction"
7335 "endproperty" "endsequence" "endtask"))
7336 (setq functask (1- functask)))
7337 ((equal keywd "modport")
7338 (setq in-modport t))
7339 ;; Ifdef? Ignore name of define
7340 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
7343 ((verilog-typedef-name-p keywd)
7344 (setq typedefed keywd))
7345 ;; Interface with optional modport in v2k arglist?
7346 ;; Skip over parsing modport, and take the interface name as the type
7350 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
7351 (when (match-end 2) (goto-char (match-end 2)))
7352 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed keywd multidim nil sig-paren paren
7353 expect-signal 'sigs-intf io t modport (match-string 2)))
7354 ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
7355 ((looking-at "\\s-*\\.")
7356 (goto-char (match-end 0))
7358 (setq expect-signal nil)))
7359 ;; New signal, maybe?
7364 (not (member keywd verilog-keywords)))
7365 ;; Add new signal to expect-signal's variable
7366 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
7367 (set expect-signal (cons newsig
7368 (symbol-value expect-signal))))))
7371 (skip-syntax-forward " "))
7373 (verilog-decls-new (nreverse sigs-out)
7374 (nreverse sigs-inout)
7376 (nreverse sigs-wire)
7378 (nreverse sigs-assign)
7379 (nreverse sigs-const)
7380 (nreverse sigs-gparam)
7381 (nreverse sigs-intf)))))
7383 (defvar verilog-read-sub-decls-in-interfaced nil
7384 "For `verilog-read-sub-decls', process next signal as under interfaced block.")
7386 (defvar verilog-read-sub-decls-gate-ios nil
7387 "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
7390 ;; Prevent compile warnings; these are let's, not globals
7391 ;; Do not remove the eval-when-compile
7392 ;; - we want a error when we are debugging this code if they are refed.
7397 (defvar sigs-intfd))
7399 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
7400 "For `verilog-read-sub-decls-line', add a signal."
7401 ;; sig eq t to indicate .name syntax
7402 ;;(message "vrsds: %s(%S)" port sig)
7403 (let ((dotname (eq sig t))
7406 (setq port (verilog-symbol-detick-denumber port))
7407 (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
7408 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
7409 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
7410 (unless (or (not sig)
7411 (equal sig "")) ;; Ignore .foo(1'b1) assignments
7412 (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
7413 (equal "inout" verilog-read-sub-decls-gate-ios))
7415 (cons (verilog-sig-new
7417 (if dotname (verilog-sig-bits portdata) vec)
7418 (concat "To/From " comment) nil nil
7419 (verilog-sig-signed portdata)
7420 (verilog-sig-type portdata)
7423 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
7424 (equal "output" verilog-read-sub-decls-gate-ios))
7426 (cons (verilog-sig-new
7428 (if dotname (verilog-sig-bits portdata) vec)
7429 (concat "From " comment) nil nil
7430 (verilog-sig-signed portdata)
7431 (verilog-sig-type portdata)
7434 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
7435 (equal "input" verilog-read-sub-decls-gate-ios))
7437 (cons (verilog-sig-new
7439 (if dotname (verilog-sig-bits portdata) vec)
7440 (concat "To " comment) nil nil
7441 (verilog-sig-signed portdata)
7442 (verilog-sig-type portdata)
7445 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
7447 (cons (verilog-sig-new
7449 (if dotname (verilog-sig-bits portdata) vec)
7450 (concat "To/From " comment) nil nil
7451 (verilog-sig-signed portdata)
7452 (verilog-sig-type portdata)
7455 ((setq portdata (and verilog-read-sub-decls-in-interfaced
7456 (or (assoc port (verilog-decls-get-regs submoddecls))
7457 (assoc port (verilog-decls-get-wires submoddecls)))))
7459 (cons (verilog-sig-new
7461 (if dotname (verilog-sig-bits portdata) vec)
7462 (concat "To/From " comment) nil nil
7463 (verilog-sig-signed portdata)
7464 (verilog-sig-type portdata)
7467 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
7470 (defun verilog-read-sub-decls-expr (submoddecls comment port expr)
7471 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
7472 ;;(message "vrsde: '%s'" expr)
7473 ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
7474 (setq expr (verilog-string-replace-matches "/\\*\\(\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
7475 ;; Remove front operators
7476 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
7479 ;; {..., a, b} requires us to recurse on a,b
7480 ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
7481 ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
7482 (unless verilog-auto-ignore-concat
7483 (let ((mlst (split-string (match-string 1 expr) "[{},]"))
7485 (while (setq mstr (pop mlst))
7486 (verilog-read-sub-decls-expr submoddecls comment port mstr)))))
7488 (let (sig vec multidim)
7489 ;; Remove leading reduction operators, etc
7490 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
7491 ;;(message "vrsde-ptop: '%s'" expr)
7492 (cond ;; Find \signal. Final space is part of escaped signal name
7493 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
7494 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
7495 (setq sig (match-string 1 expr)
7496 expr (substring expr (match-end 0))))
7498 ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
7499 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
7500 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
7501 expr (substring expr (match-end 0)))))
7502 ;; Find [vector] or [multi][multi][multi][vector]
7503 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
7504 ;;(message "vrsde-v: '%s'" (match-string 1 expr))
7505 (when vec (setq multidim (cons vec multidim)))
7506 (setq vec (match-string 1 expr)
7507 expr (substring expr (match-end 0))))
7508 ;; If found signal, and nothing unrecognized, add the signal
7509 ;;(message "vrsde-rem: '%s'" expr)
7510 (when (and sig (string-match "^\\s-*$" expr))
7511 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))))
7513 (defun verilog-read-sub-decls-line (submoddecls comment)
7514 "For `verilog-read-sub-decls', read lines of port defs until none match.
7515 Inserts the list of signals found, using submodi to look up each port."
7521 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
7522 (setq port (match-string 1))
7523 (goto-char (match-end 0)))
7525 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
7526 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space
7527 (goto-char (match-end 0)))
7529 ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
7530 (verilog-read-sub-decls-sig
7531 submoddecls comment (match-string 1) t ; sig==t for .name
7532 nil nil) ; vec multidim
7535 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
7536 (verilog-read-sub-decls-sig
7537 submoddecls comment (concat (match-string 1) " ") t ; sig==t for .name
7538 nil nil) ; vec multidim
7541 ((looking-at "\\s-*\\.[^(]*(")
7542 (setq port nil) ;; skip this line
7543 (goto-char (match-end 0)))
7545 (setq port nil done t))) ;; Unknown, ignore rest of line
7546 ;; Get signal name. Point is at the first-non-space after (
7547 ;; We intentionally ignore (non-escaped) signals with .s in them
7548 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
7550 (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
7551 (verilog-read-sub-decls-sig
7552 submoddecls comment port
7553 (verilog-string-remove-spaces (match-string 1)) ; sig
7554 nil nil)) ; vec multidim
7556 ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
7557 (verilog-read-sub-decls-sig
7558 submoddecls comment port
7559 (verilog-string-remove-spaces (match-string 1)) ; sig
7560 (match-string 2) nil)) ; vec multidim
7561 ;; Fastpath was above looking-at's.
7562 ;; For something more complicated invoke a parser
7563 ((looking-at "[^)]+")
7564 (verilog-read-sub-decls-expr
7565 submoddecls comment port
7567 (point) (1- (progn (search-backward "(") ; start at (
7568 (forward-sexp 1) (point)))))))) ; expr
7570 (forward-line 1)))))
7572 (defun verilog-read-sub-decls-gate (submoddecls comment submod end-inst-point)
7573 "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
7574 Inserts the list of signals found."
7576 (let ((iolist (cdr (assoc submod verilog-gate-ios))))
7577 (while (< (point) end-inst-point)
7578 ;; Get primitive's signal name, as will never have port, and no trailing )
7579 (cond ((looking-at "//")
7580 (search-forward "\n"))
7581 ((looking-at "/\\*")
7582 (or (search-forward "*/")
7583 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
7584 ((looking-at "(\\*")
7585 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
7586 (search-forward "*)")
7587 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
7588 ;; On pins, parse and advance to next pin
7589 ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
7590 ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
7591 (goto-char (match-end 0))
7592 (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
7593 iolist (cdr iolist))
7594 (verilog-read-sub-decls-expr
7595 submoddecls comment "primitive_port"
7599 (skip-syntax-forward " ")))))))
7601 (defun verilog-read-sub-decls ()
7602 "Internally parse signals going to modules under this module.
7603 Return a array of [ outputs inouts inputs ] signals for modules that are
7604 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
7605 is a output, then SIG will be included in the list.
7607 This only works on instantiations created with /*AUTOINST*/ converted by
7608 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
7609 component library to determine connectivity of the design.
7611 One work around for this problem is to manually create // Inputs and //
7612 Outputs comments above subcell signals, for example:
7620 (let ((end-mod-point (verilog-get-end-of-defun t))
7621 st-point end-inst-point
7622 ;; below 3 modified by verilog-read-sub-decls-line
7623 sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
7624 (verilog-beg-of-defun)
7625 (while (verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
7627 (goto-char (match-beginning 0))
7628 (unless (verilog-inside-comment-p)
7629 ;; Attempt to snarf a comment
7630 (let* ((submod (verilog-read-inst-module))
7631 (inst (verilog-read-inst-name))
7632 (subprim (member submod verilog-gate-keywords))
7633 (comment (concat inst " of " submod ".v"))
7634 submodi submoddecls)
7637 (setq submodi `primitive
7638 submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
7639 comment (concat inst " of " submod))
7640 (verilog-backward-open-paren)
7641 (setq end-inst-point (save-excursion (forward-sexp 1) (point))
7644 (verilog-read-sub-decls-gate submoddecls comment submod end-inst-point))
7647 (when (setq submodi (verilog-modi-lookup submod t))
7648 (setq submoddecls (verilog-modi-get-decls submodi)
7649 verilog-read-sub-decls-gate-ios nil)
7650 (verilog-backward-open-paren)
7651 (setq end-inst-point (save-excursion (forward-sexp 1) (point))
7653 ;; This could have used a list created by verilog-auto-inst
7654 ;; However I want it to be runnable even on user's manually added signals
7655 (let ((verilog-read-sub-decls-in-interfaced t))
7656 (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
7657 (verilog-read-sub-decls-line submoddecls comment))) ;; Modifies sigs-ifd
7658 (goto-char st-point)
7659 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
7660 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
7661 (goto-char st-point)
7662 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
7663 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
7664 (goto-char st-point)
7665 (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
7666 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout
7667 (goto-char st-point)
7668 (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
7669 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-in
7671 ;; Combine duplicate bits
7672 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
7673 (verilog-subdecls-new
7674 (verilog-signals-combine-bus (nreverse sigs-out))
7675 (verilog-signals-combine-bus (nreverse sigs-inout))
7676 (verilog-signals-combine-bus (nreverse sigs-in))
7677 (verilog-signals-combine-bus (nreverse sigs-intf))
7678 (verilog-signals-combine-bus (nreverse sigs-intfd))))))
7680 (defun verilog-read-inst-pins ()
7681 "Return an array of [ pins ] for the current instantiation at point.
7682 For example if declare A A (.B(SIG)) then B will be included in the list."
7684 (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point
7686 (verilog-backward-open-paren)
7687 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
7688 (setq pin (match-string 1))
7689 (unless (verilog-inside-comment-p)
7690 (setq pins (cons (list pin) pins))
7691 (when (looking-at "(")
7695 (defun verilog-read-arg-pins ()
7696 "Return an array of [ pins ] for the current argument declaration at point."
7698 (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point
7700 (verilog-backward-open-paren)
7701 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
7702 (setq pin (match-string 1))
7703 (unless (verilog-inside-comment-p)
7704 (setq pins (cons (list pin) pins))))
7707 (defun verilog-read-auto-constants (beg end-mod-point)
7708 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
7711 (let (sig-list tpl-end-pt)
7713 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
7714 (if (not (looking-at "\\s *("))
7715 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
7716 (search-forward "(" end-mod-point)
7717 (setq tpl-end-pt (save-excursion
7719 (forward-sexp 1) ;; Moves to paren that closes argdecl's
7722 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
7723 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
7726 (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
7727 (make-variable-buffer-local 'verilog-cache-has-lisp)
7729 (defun verilog-read-auto-lisp-present ()
7730 "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
7732 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
7734 (defun verilog-read-auto-lisp (start end)
7735 "Look for and evaluate a AUTO_LISP between START and END.
7736 Must call `verilog-read-auto-lisp-present' before this function."
7737 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
7738 (when verilog-cache-has-lisp
7741 (while (re-search-forward "\\<AUTO_LISP(" end t)
7743 (let* ((beg-pt (prog1 (point)
7744 (forward-sexp 1))) ;; Closing paren
7746 (eval-region beg-pt end-pt nil))))))
7749 ;; Prevent compile warnings; these are let's, not globals
7750 ;; Do not remove the eval-when-compile
7751 ;; - we want a error when we are debugging this code if they are refed.
7755 (defvar uses-delayed)
7756 (defvar vector-skip-list))
7758 (defun verilog-read-always-signals-recurse
7759 (exit-keywd rvalue temp-next)
7760 "Recursive routine for parentheses/bracket matching.
7761 EXIT-KEYWD is expression to stop at, nil if top level.
7762 RVALUE is true if at right hand side of equal.
7763 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
7764 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue
7765 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
7767 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
7768 (while (not (or (eobp) gotend))
7771 (search-forward "\n"))
7772 ((looking-at "/\\*")
7773 (or (search-forward "*/")
7774 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
7775 ((looking-at "(\\*")
7776 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
7777 (search-forward "*)")
7778 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
7779 (t (setq keywd (buffer-substring-no-properties
7781 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
7784 sig-last-tolk sig-tolk
7786 ;;(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))))
7789 (or (re-search-forward "[^\\]\"" nil t)
7790 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
7791 ;; else at top level loop, keep parsing
7792 ((and end-else-check (equal keywd "else"))
7793 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
7794 ;; no forward movement, want to see else in lower loop
7795 (setq end-else-check nil))
7796 ;; End at top level loop
7797 ((and end-else-check (looking-at "[^ \t\n\f]"))
7798 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
7801 ((and exit-keywd (equal keywd exit-keywd))
7803 (forward-char (length keywd)))
7804 ;; Standard tokens...
7806 (setq ignore-next nil rvalue semi-rvalue)
7807 ;; Final statement at top level loop?
7808 (when (not exit-keywd)
7809 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
7810 (setq end-else-check t))
7813 (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
7814 (goto-char (match-end 0))
7816 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z
7817 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next
7818 (setq ignore-next nil rvalue nil))
7819 ((equal "?" exit-keywd) ;; x?y:z rvalue
7821 ((equal "]" exit-keywd) ;; [x:y] rvalue
7823 (got-sig ;; label: statement
7824 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
7825 ((not rvalue) ;; begin label
7826 (setq ignore-next t rvalue nil)))
7829 (if (and (eq (char-before) ?< )
7831 (setq uses-delayed 1))
7832 (setq ignore-next nil rvalue t)
7836 (verilog-read-always-signals-recurse ":" rvalue nil))
7839 (verilog-read-always-signals-recurse "]" t nil))
7842 (cond (sig-last-tolk ;; Function call; zap last signal
7843 (setq got-sig nil)))
7844 (cond ((equal last-keywd "for")
7845 ;; temp-next: Variables on LHS are lvalues, but generally we want
7846 ;; to ignore them, assuming they are loop increments
7847 (verilog-read-always-signals-recurse ";" nil t)
7848 (verilog-read-always-signals-recurse ";" t nil)
7849 (verilog-read-always-signals-recurse ")" nil nil))
7850 (t (verilog-read-always-signals-recurse ")" t nil))))
7851 ((equal keywd "begin")
7852 (skip-syntax-forward "w_")
7853 (verilog-read-always-signals-recurse "end" nil nil)
7854 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
7855 (setq ignore-next nil rvalue semi-rvalue)
7856 (if (not exit-keywd) (setq end-else-check t)))
7857 ((member keywd '("case" "casex" "casez"))
7858 (skip-syntax-forward "w_")
7859 (verilog-read-always-signals-recurse "endcase" t nil)
7860 (setq ignore-next nil rvalue semi-rvalue)
7861 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end
7862 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent
7863 (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
7864 (setq ignore-next t))
7866 (member keywd verilog-keywords)
7867 (string-match "^\\$" keywd)) ;; PLI task
7868 (setq ignore-next nil))
7870 (setq keywd (verilog-symbol-detick-denumber keywd))
7872 (set got-list (cons got-sig (symbol-value got-list)))
7873 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
7875 (setq got-list (cond (temp-next 'sigs-temp)
7878 got-sig (if (or (not keywd)
7879 (assoc keywd (symbol-value got-list)))
7880 nil (list keywd nil nil))
7883 (skip-chars-forward "a-zA-Z0-9$_.%`"))
7886 ;; End of non-comment token
7887 (setq last-keywd keywd)))
7888 (skip-syntax-forward " "))
7889 ;; Append the final pending signal
7891 ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
7892 (set got-list (cons got-sig (symbol-value got-list)))
7894 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
7897 (defun verilog-read-always-signals ()
7898 "Parse always block at point and return list of (outputs inout inputs)."
7901 sigs-out sigs-temp sigs-in
7902 uses-delayed) ;; Found signal/rvalue; push if not function
7903 (search-forward ")")
7904 (verilog-read-always-signals-recurse nil nil nil)
7905 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))
7906 ;; Return what was found
7907 (verilog-alw-new sigs-out sigs-temp sigs-in uses-delayed))))
7909 (defun verilog-read-instants ()
7910 "Parse module at point and return list of ( ( file instance ) ... )."
7911 (verilog-beg-of-defun)
7912 (let* ((end-mod-point (verilog-get-end-of-defun t))
7914 (instants-list nil))
7916 (while (< (point) end-mod-point)
7917 ;; Stay at level 0, no comments
7919 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
7920 (or (> (car state) 0) ; in parens
7921 (nth 5 state) ; comment
7925 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
7926 ;;(if (looking-at "^\\(.+\\)$")
7927 (let ((module (match-string 1))
7928 (instant (match-string 2)))
7929 (if (not (member module verilog-keywords))
7930 (setq instants-list (cons (list module instant) instants-list)))))
7935 (defun verilog-read-auto-template (module)
7936 "Look for a auto_template for the instantiation of the given MODULE.
7937 If found returns the signal name connections. Return REGEXP and
7938 list of ( (signal_name connection_name)... )."
7941 (let ((tpl-regexp "\\([0-9]+\\)")
7945 tpl-sig-list tpl-wild-list tpl-end-pt rep)
7946 ;; Note this search is expensive, as we hunt from mod-begin to point
7947 ;; for every instantiation. Likewise in verilog-read-auto-lisp.
7948 ;; So, we look first for an exact string rather than a slow regexp.
7949 ;; Someday we may keep a cache of every template, but this would also
7950 ;; need to record the relative position of each AUTOINST, as multiple
7951 ;; templates exist for each module, and we're inserting lines.
7953 (verilog-re-search-backward-substr
7955 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
7956 ;; Also try forward of this AUTOINST
7957 ;; This is for historical support; this isn't speced as working
7960 (verilog-re-search-forward-substr
7962 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
7963 (goto-char (match-end 0))
7965 ;; We reserve @"..." for future lisp expressions that evaluate
7966 ;; once-per-AUTOINST
7967 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
7968 (setq tpl-regexp (match-string 1))
7969 (goto-char (match-end 0)))
7970 (search-forward "(")
7971 ;; Parse lines in the template
7972 (when verilog-auto-inst-template-numbers
7974 (goto-char (point-min))
7975 (while (search-forward "AUTO_TEMPLATE" nil t)
7976 (setq templateno (1+ templateno)))))
7977 (setq tpl-end-pt (save-excursion
7979 (forward-sexp 1) ;; Moves to paren that closes argdecl's
7983 (while (< (point) tpl-end-pt)
7984 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
7985 (setq tpl-sig-list (cons (list
7986 (match-string-no-properties 1)
7987 (match-string-no-properties 2)
7990 (goto-char (match-end 0)))
7993 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
7994 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
7995 (setq rep (match-string-no-properties 3))
7996 (goto-char (match-end 0))
8000 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
8006 ((looking-at "[ \t\f]+")
8007 (goto-char (match-end 0)))
8009 (setq lineno (1+ lineno))
8010 (goto-char (match-end 0)))
8012 (search-forward "\n"))
8013 ((looking-at "/\\*")
8015 (or (search-forward "*/")
8016 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8018 (error "%s: AUTO_TEMPLATE parsing error: %s"
8019 (verilog-point-text)
8020 (progn (looking-at ".*$") (match-string 0))))))
8023 (list tpl-sig-list tpl-wild-list)))
8024 ;; If no template found
8025 (t (vector tpl-regexp nil))))))
8026 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
8028 (defun verilog-set-define (defname defvalue &optional buffer enumname)
8029 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
8030 Optionally associate it with the specified enumeration ENUMNAME."
8031 (with-current-buffer (or buffer (current-buffer))
8032 (let ((mac (intern (concat "vh-" defname))))
8033 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
8034 ;; Need to define to a constant if no value given
8035 (set (make-local-variable mac)
8036 (if (equal defvalue "") "1" defvalue)))
8038 (let ((enumvar (intern (concat "venum-" enumname))))
8039 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
8040 (unless (boundp enumvar) (set enumvar nil))
8041 (make-local-variable enumvar)
8042 (add-to-list enumvar defname)))))
8044 (defun verilog-read-defines (&optional filename recurse subcall)
8045 "Read `defines and parameters for the current file, or optional FILENAME.
8046 If the filename is provided, `verilog-library-flags' will be used to
8047 resolve it. If optional RECURSE is non-nil, recurse through `includes.
8049 Parameters must be simple assignments to constants, or have their own
8050 \"parameter\" label rather than a list of parameters. Thus:
8052 parameter X = 5, Y = 10; // Ok
8053 parameter X = {1'b1, 2'h2}; // Ok
8054 parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines
8056 Defines must be simple text substitutions, one on a line, starting
8057 at the beginning of the line. Any ifdefs or multiline comments around the
8060 Defines are stored inside Emacs variables using the name vh-{definename}.
8062 This function is useful for setting vh-* variables. The file variables
8063 feature can be used to set defines that `verilog-mode' can see; put at the
8064 *END* of your file something like:
8067 // vh-macro:\"macro_definition\"
8070 If macros are defined earlier in the same file and you want their values,
8071 you can read them automatically (provided `enable-local-eval' is on):
8074 // eval:(verilog-read-defines)
8075 // eval:(verilog-read-defines \"group_standard_includes.v\")
8078 Note these are only read when the file is first visited, you must use
8079 \\[find-alternate-file] RET to have these take effect after editing them!
8081 If you want to disable the \"Process `eval' or hook local variables\"
8082 warning message, you need to add to your .emacs file:
8084 (setq enable-local-eval t)"
8085 (let ((origbuf (current-buffer)))
8087 (unless subcall (verilog-getopt-flags))
8089 (let ((fns (verilog-library-filenames filename (buffer-file-name))))
8091 (set-buffer (find-file-noselect (car fns)))
8092 (error (concat (verilog-point-text)
8093 ": Can't find verilog-read-defines file: " filename)))))
8095 (goto-char (point-min))
8096 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
8097 (let ((inc (verilog-string-replace-matches
8098 "\"" "" nil nil (match-string-no-properties 1))))
8099 (unless (verilog-inside-comment-p)
8100 (verilog-read-defines inc recurse t)))))
8102 ;; note we don't use verilog-re... it's faster this way, and that
8103 ;; function has problems when comments are at the end of the define
8104 (goto-char (point-min))
8105 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
8106 (let ((defname (match-string-no-properties 1))
8107 (defvalue (match-string-no-properties 2)))
8108 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
8109 (verilog-set-define defname defvalue origbuf)))
8110 ;; Hack: Read parameters
8111 (goto-char (point-min))
8112 (while (re-search-forward
8113 "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-+" nil t)
8115 ;; The primary way of getting defines is verilog-read-decls
8116 ;; However, that isn't called yet for included files, so we'll add another scheme
8117 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8118 (setq enumname (match-string-no-properties 1)))
8119 (forward-comment 999)
8120 (while (looking-at "\\s-*,?\\s-*\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\s-*")
8121 (verilog-set-define (match-string-no-properties 1)
8122 (match-string-no-properties 2) origbuf enumname)
8123 (goto-char (match-end 0))
8124 (forward-comment 999)))))))
8126 (defun verilog-read-includes ()
8127 "Read `includes for the current file.
8128 This will find all of the `includes which are at the beginning of lines,
8129 ignoring any ifdefs or multiline comments around them.
8130 `verilog-read-defines' is then performed on the current and each included
8133 It is often useful put at the *END* of your file something like:
8136 // eval:(verilog-read-defines)
8137 // eval:(verilog-read-includes)
8140 Note includes are only read when the file is first visited, you must use
8141 \\[find-alternate-file] RET to have these take effect after editing them!
8143 It is good to get in the habit of including all needed files in each .v
8144 file that needs it, rather than waiting for compile time. This will aid
8145 this process, Verilint, and readability. To prevent defining the same
8146 variable over and over when many modules are compiled together, put a test
8147 around the inside each include file:
8150 `ifdef _FOO_V // include if not already included
8153 ... contents of file
8155 ;;slow: (verilog-read-defines nil t))
8157 (verilog-getopt-flags)
8158 (goto-char (point-min))
8159 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
8160 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
8161 (verilog-read-defines inc nil t)))))
8163 (defun verilog-read-signals (&optional start end)
8164 "Return a simple list of all possible signals in the file.
8165 Bounded by optional region from START to END. Overly aggressive but fast.
8166 Some macros and such are also found and included. For dinotrace.el."
8167 (let (sigs-all keywd)
8168 (progn;save-excursion
8169 (goto-char (or start (point-min)))
8170 (setq end (or end (point-max)))
8171 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
8175 (search-forward "\n"))
8176 ((looking-at "/\\*")
8177 (search-forward "*/"))
8178 ((looking-at "(\\*")
8179 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
8180 (search-forward "*)")))
8181 ((eq ?\" (following-char))
8182 (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first
8183 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
8184 (goto-char (match-end 0))
8185 (setq keywd (match-string-no-properties 1))
8186 (or (member keywd verilog-keywords)
8187 (member keywd sigs-all)
8188 (setq sigs-all (cons keywd sigs-all))))
8189 (t (forward-char 1))))
8194 ;; Argument file parsing
8197 (defun verilog-getopt (arglist)
8198 "Parse -f, -v etc arguments in ARGLIST list or string."
8199 (unless (listp arglist) (setq arglist (list arglist)))
8200 (let ((space-args '())
8202 ;; Split on spaces, so users can pass whole command lines
8204 (setq arg (car arglist)
8205 arglist (cdr arglist))
8206 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
8207 (setq space-args (append space-args
8208 (list (match-string-no-properties 1 arg))))
8209 (setq arg (match-string 2 arg))))
8212 (setq arg (car space-args)
8213 space-args (cdr space-args))
8217 (setq next-param arg))
8219 (setq next-param arg))
8221 (setq next-param arg))
8222 ;; +libext+(ext1)+(ext2)...
8223 ((string-match "^\\+libext\\+\\(.*\\)" arg)
8224 (setq arg (match-string 1 arg))
8225 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
8226 (verilog-add-list-unique `verilog-library-extensions
8227 (match-string 1 arg))
8228 (setq arg (match-string 2 arg))))
8230 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val
8231 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine
8232 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val
8233 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define
8234 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
8236 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir
8237 (string-match "^-I\\(.*\\)" arg)) ;; -Idir
8238 (verilog-add-list-unique `verilog-library-directories
8239 (match-string 1 (substitute-in-file-name arg))))
8241 ((equal "+librescan" arg))
8242 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine
8243 ;; Second parameters
8244 ((equal next-param "-f")
8245 (setq next-param nil)
8246 (verilog-getopt-file (substitute-in-file-name arg)))
8247 ((equal next-param "-v")
8248 (setq next-param nil)
8249 (verilog-add-list-unique `verilog-library-files
8250 (substitute-in-file-name arg)))
8251 ((equal next-param "-y")
8252 (setq next-param nil)
8253 (verilog-add-list-unique `verilog-library-directories
8254 (substitute-in-file-name arg)))
8256 ((string-match "^[^-+]" arg)
8257 (verilog-add-list-unique `verilog-library-files
8258 (substitute-in-file-name arg)))
8259 ;; Default - ignore; no warning
8261 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
8263 (defun verilog-getopt-file (filename)
8264 "Read Verilog options from the specified FILENAME."
8266 (let ((fns (verilog-library-filenames filename (buffer-file-name)))
8267 (orig-buffer (current-buffer))
8270 (set-buffer (find-file-noselect (car fns)))
8271 (error (concat (verilog-point-text)
8272 ": Can't find verilog-getopt-file -f file: " filename)))
8273 (goto-char (point-min))
8275 (setq line (buffer-substring (point)
8276 (save-excursion (end-of-line) (point))))
8278 (when (string-match "//" line)
8279 (setq line (substring line 0 (match-beginning 0))))
8280 (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
8281 (verilog-getopt line))))))
8283 (defun verilog-getopt-flags ()
8284 "Convert `verilog-library-flags' into standard library variables."
8285 ;; If the flags are local, then all the outputs should be local also
8286 (when (local-variable-p `verilog-library-flags (current-buffer))
8287 (mapc 'make-local-variable '(verilog-library-extensions
8288 verilog-library-directories
8289 verilog-library-files
8290 verilog-library-flags)))
8291 ;; Allow user to customize
8292 (run-hooks 'verilog-before-getopt-flags-hook)
8293 ;; Process arguments
8294 (verilog-getopt verilog-library-flags)
8295 ;; Allow user to customize
8296 (run-hooks 'verilog-getopt-flags-hook))
8298 (defun verilog-add-list-unique (varref object)
8299 "Append to VARREF list the given OBJECT,
8300 unless it is already a member of the variable's list."
8301 (unless (member object (symbol-value varref))
8302 (set varref (append (symbol-value varref) (list object))))
8304 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
8306 (defun verilog-current-flags ()
8307 "Convert `verilog-library-flags' and similar variables to command line.
8308 Used for __FLAGS__ in `verilog-expand-command'."
8309 (let ((cmd (mapconcat `concat verilog-library-flags " ")))
8310 (when (equal cmd "")
8312 "+libext+" (mapconcat `concat verilog-library-extensions "+")
8313 (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
8314 verilog-library-directories "")
8315 (mapconcat (lambda (i) (concat " -v " i))
8316 verilog-library-files ""))))
8318 ;;(verilog-current-flags)
8322 ;; Cached directory support
8325 (defvar verilog-dir-cache-preserving nil
8326 "If set, the directory cache is enabled, and file system changes are ignored.
8327 See `verilog-dir-exists-p' and `verilog-dir-files'.")
8329 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
8330 (defvar verilog-dir-cache-list nil
8331 "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
8332 (defvar verilog-dir-cache-lib-filenames nil
8333 "Cached data for `verilog-library-filenames'.")
8335 (defmacro verilog-preserve-dir-cache (&rest body)
8336 "Execute the BODY forms, allowing directory cache preservation within BODY.
8337 This means that changes inside BODY made to the file system will not be
8338 seen by the `verilog-dir-files' and related functions."
8339 `(let ((verilog-dir-cache-preserving (current-buffer))
8340 verilog-dir-cache-list
8341 verilog-dir-cache-lib-filenames)
8344 (defun verilog-dir-files (dirname)
8345 "Return all filenames in the DIRNAME directory.
8346 Relative paths depend on the `default-directory'.
8347 Results are cached if inside `verilog-preserve-dir-cache'."
8348 (unless verilog-dir-cache-preserving
8349 (setq verilog-dir-cache-list nil)) ;; Cache disabled
8350 ;; We don't use expand-file-name on the dirname to make key, as it's slow
8351 (let* ((cache-key (list dirname default-directory))
8352 (fass (assoc cache-key verilog-dir-cache-list))
8354 (cond (fass ;; Return data from cache hit
8357 (setq exp-dirname (expand-file-name dirname)
8358 data (and (file-directory-p exp-dirname)
8359 (directory-files exp-dirname nil nil nil)))
8360 ;; Note we also encache nil for non-existing dirs.
8361 (setq verilog-dir-cache-list (cons (list cache-key data)
8362 verilog-dir-cache-list))
8364 ;; Miss-and-hit test:
8365 ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
8366 ;; (prin1 (verilog-dir-files ".")) nil)
8368 (defun verilog-dir-file-exists-p (filename)
8369 "Return true if FILENAME exists.
8370 Like `file-exists-p' but results are cached if inside
8371 `verilog-preserve-dir-cache'."
8372 (let* ((dirname (file-name-directory filename))
8373 ;; Correct for file-name-nondirectory returning same if no slash.
8374 (dirnamed (if (or (not dirname) (equal dirname filename))
8375 default-directory dirname))
8376 (flist (verilog-dir-files dirnamed)))
8378 (member (file-name-nondirectory filename) flist)
8380 ;;(verilog-dir-file-exists-p "verilog-mode.el")
8381 ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
8385 ;; Module name lookup
8388 (defun verilog-module-inside-filename-p (module filename)
8389 "Return modi if MODULE is specified inside FILENAME, else nil.
8390 Allows version control to check out the file if need be."
8391 (and (or (file-exists-p filename)
8392 (and (fboundp 'vc-backend)
8393 (vc-backend filename)))
8395 (with-current-buffer (find-file-noselect filename)
8397 (goto-char (point-min))
8399 ;; It may be tempting to look for verilog-defun-re,
8400 ;; don't, it slows things down a lot!
8401 (verilog-re-search-forward-quick "\\<\\(module\\|interface\\)\\>" nil t)
8402 (setq type (match-string-no-properties 0))
8403 (verilog-re-search-forward-quick "[(;]" nil t))
8404 (if (equal module (verilog-read-module-name))
8405 (setq modi (verilog-modi-new module filename (point) type))))
8408 (defun verilog-is-number (symbol)
8409 "Return true if SYMBOL is number-like."
8410 (or (string-match "^[0-9 \t:]+$" symbol)
8411 (string-match "^[---]*[0-9]+$" symbol)
8412 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
8414 (defun verilog-symbol-detick (symbol wing-it)
8415 "Return an expanded SYMBOL name without any defines.
8416 If the variable vh-{symbol} is defined, return that value.
8417 If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
8418 (while (and symbol (string-match "^`" symbol))
8419 (setq symbol (substring symbol 1))
8421 (if (boundp (intern (concat "vh-" symbol)))
8422 ;; Emacs has a bug where boundp on a buffer-local
8423 ;; variable in only one buffer returns t in another.
8424 ;; This can confuse, so check for nil.
8425 (let ((val (eval (intern (concat "vh-" symbol)))))
8427 (if wing-it symbol nil)
8429 (if wing-it symbol nil))))
8431 ;;(verilog-symbol-detick "`mod" nil)
8433 (defun verilog-symbol-detick-denumber (symbol)
8434 "Return SYMBOL with defines converted and any numbers dropped to nil."
8435 (when (string-match "^`" symbol)
8436 ;; This only will work if the define is a simple signal, not
8437 ;; something like a[b]. Sorry, it should be substituted into the parser
8439 (verilog-string-replace-matches
8440 "\[[^0-9: \t]+\]" "" nil nil
8441 (or (verilog-symbol-detick symbol nil)
8442 (if verilog-auto-sense-defines-constant
8445 (if (verilog-is-number symbol)
8449 (defun verilog-symbol-detick-text (text)
8450 "Return TEXT without any known defines.
8451 If the variable vh-{symbol} is defined, substitute that value."
8452 (let ((ok t) symbol val)
8453 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
8454 (setq symbol (match-string 1 text))
8457 (boundp (intern (concat "vh-" symbol)))
8458 ;; Emacs has a bug where boundp on a buffer-local
8459 ;; variable in only one buffer returns t in another.
8460 ;; This can confuse, so check for nil.
8461 (setq val (eval (intern (concat "vh-" symbol)))))
8462 (setq text (replace-match val nil nil text)))
8463 (t (setq ok nil)))))
8465 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
8467 (defun verilog-expand-dirnames (&optional dirnames)
8468 "Return a list of existing directories given a list of wildcarded DIRNAMES.
8469 Or, just the existing dirnames themselves if there are no wildcards."
8470 ;; Note this function is performance critical.
8471 ;; Do not call anything that requires disk access that cannot be cached.
8473 (unless dirnames (error "`verilog-library-directories' should include at least '.'"))
8474 (setq dirnames (reverse dirnames)) ; not nreverse
8476 pattern dirfile dirfiles dirname root filename rest basefile)
8478 (setq dirname (substitute-in-file-name (car dirnames))
8479 dirnames (cdr dirnames))
8480 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root
8481 "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *?
8484 (setq root (match-string 1 dirname)
8485 filename (match-string 2 dirname)
8486 rest (match-string 3 dirname)
8488 ;; now replace those * and ? with .+ and .
8489 ;; use ^ and /> to get only whole file names
8490 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
8491 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
8492 pattern (concat "^" pattern "$")
8493 dirfiles (verilog-dir-files root))
8495 (setq basefile (car dirfiles)
8496 dirfile (expand-file-name (concat root basefile rest))
8497 dirfiles (cdr dirfiles))
8498 (if (and (string-match pattern basefile)
8499 ;; Don't allow abc/*/rtl to match abc/rtl via ..
8500 (not (equal basefile "."))
8501 (not (equal basefile ".."))
8502 (file-directory-p dirfile))
8503 (setq dirlist (cons dirfile dirlist)))))
8506 (if (file-directory-p dirname)
8507 (setq dirlist (cons dirname dirlist))))))
8509 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
8511 (defun verilog-library-filenames (filename &optional current check-ext)
8512 "Return a search path to find the given FILENAME or module name.
8513 Uses the optional CURRENT filename or buffer-file-name, plus
8514 `verilog-library-directories' and `verilog-library-extensions'
8515 variables to build the path. With optional CHECK-EXT also check
8516 `verilog-library-extensions'."
8517 (unless current (setq current (buffer-file-name)))
8518 (unless verilog-dir-cache-preserving
8519 (setq verilog-dir-cache-lib-filenames nil))
8520 (let* ((cache-key (list filename current check-ext))
8521 (fass (assoc cache-key verilog-dir-cache-lib-filenames))
8522 chkdirs chkdir chkexts fn outlist)
8523 (cond (fass ;; Return data from cache hit
8526 ;; Note this expand can't be easily cached, as we need to
8527 ;; pick up buffer-local variables for newly read sub-module files
8528 (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
8530 (setq chkdir (expand-file-name (car chkdirs)
8531 (file-name-directory current))
8532 chkexts (if check-ext verilog-library-extensions `("")))
8534 (setq fn (expand-file-name (concat filename (car chkexts))
8536 ;;(message "Check for %s" fn)
8537 (if (verilog-dir-file-exists-p fn)
8538 (setq outlist (cons (expand-file-name
8539 fn (file-name-directory current))
8541 (setq chkexts (cdr chkexts)))
8542 (setq chkdirs (cdr chkdirs)))
8543 (setq outlist (nreverse outlist))
8544 (setq verilog-dir-cache-lib-filenames
8545 (cons (list cache-key outlist)
8546 verilog-dir-cache-lib-filenames))
8549 (defun verilog-module-filenames (module current)
8550 "Return a search path to find the given MODULE name.
8551 Uses the CURRENT filename, `verilog-library-extensions',
8552 `verilog-library-directories' and `verilog-library-files'
8553 variables to build the path."
8554 ;; Return search locations for it
8555 (append (list current) ; first, current buffer
8556 (verilog-library-filenames module current t)
8557 verilog-library-files)) ; finally, any libraries
8560 ;; Module Information
8562 ;; Many of these functions work on "modi" a module information structure
8563 ;; A modi is: [module-name-string file-name begin-point]
8565 (defvar verilog-cache-enabled t
8566 "If true, enable caching of signals, etc. Set to nil for debugging to make things SLOW!")
8568 (defvar verilog-modi-cache-list nil
8569 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
8570 For speeding up verilog-modi-get-* commands.
8572 (make-variable-buffer-local 'verilog-modi-cache-list)
8574 (defvar verilog-modi-cache-preserve-tick nil
8575 "Modification tick after which the cache is still considered valid.
8576 Use `verilog-preserve-modi-cache' to set it.")
8577 (defvar verilog-modi-cache-preserve-buffer nil
8578 "Modification tick after which the cache is still considered valid.
8579 Use `verilog-preserve-modi-cache' to set it.")
8580 (defvar verilog-modi-cache-current-enable nil
8581 "If true, allow caching `verilog-modi-current', set by let().")
8582 (defvar verilog-modi-cache-current nil
8583 "Currently active `verilog-modi-current', if any, set by let().")
8584 (defvar verilog-modi-cache-current-max nil
8585 "Current endmodule point for `verilog-modi-cache-current', if any.")
8587 (defun verilog-modi-current ()
8588 "Return the modi structure for the module currently at point, possibly cached."
8589 (cond ((and verilog-modi-cache-current
8590 (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
8591 (<= (point) verilog-modi-cache-current-max))
8592 ;; Slow assertion, for debugging the cache:
8593 ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
8594 verilog-modi-cache-current)
8595 (verilog-modi-cache-current-enable
8596 (setq verilog-modi-cache-current (verilog-modi-current-get)
8597 verilog-modi-cache-current-max
8598 ;; The cache expires when we pass "endmodule" as then the
8599 ;; current modi may change to the next module
8600 ;; This relies on the AUTOs generally inserting, not deleting text
8602 (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
8603 verilog-modi-cache-current)
8605 (verilog-modi-current-get))))
8607 (defun verilog-modi-current-get ()
8608 "Return the modi structure for the module currently at point."
8609 (let* (name type pt)
8610 ;; read current module's name
8612 (verilog-re-search-backward-quick verilog-defun-re nil nil)
8613 (setq type (match-string-no-properties 0))
8614 (verilog-re-search-forward-quick "(" nil nil)
8615 (setq name (verilog-read-module-name))
8617 ;; return modi - note this vector built two places
8618 (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
8620 (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
8621 (make-variable-buffer-local 'verilog-modi-lookup-cache)
8622 (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
8623 (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
8625 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
8626 "Find the file and point at which MODULE is defined.
8627 If ALLOW-CACHE is set, check and remember cache of previous lookups.
8628 Return modi if successful, else print message unless IGNORE-ERROR is true."
8629 (let* ((current (or (buffer-file-name) (current-buffer)))
8632 ;;(message "verilog-modi-lookup: %s" module)
8633 (cond ((and verilog-modi-lookup-cache
8634 verilog-cache-enabled
8636 (setq modi (gethash module verilog-modi-lookup-cache))
8637 (equal verilog-modi-lookup-last-current current)
8638 ;; Iff hit is in current buffer, then tick must match
8639 (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
8640 (not (equal current (verilog-modi-file-or-buffer modi)))))
8641 ;;(message "verilog-modi-lookup: HIT %S" modi)
8644 (t (let* ((realmod (verilog-symbol-detick module t))
8645 (orig-filenames (verilog-module-filenames realmod current))
8646 (filenames orig-filenames)
8648 (while (and filenames (not mif))
8649 (if (not (setq mif (verilog-module-inside-filename-p realmod (car filenames))))
8650 (setq filenames (cdr filenames))))
8651 ;; mif has correct form to become later elements of modi
8652 (cond (mif (setq modi mif))
8655 (error (concat (verilog-point-text)
8656 ": Can't locate " module " module definition"
8657 (if (not (equal module realmod))
8658 (concat " (Expanded macro to " realmod ")")
8660 "\n Check the verilog-library-directories variable."
8661 "\n I looked in (if not listed, doesn't exist):\n\t"
8662 (mapconcat 'concat orig-filenames "\n\t"))))))
8663 (when (eval-when-compile (fboundp 'make-hash-table))
8664 (unless verilog-modi-lookup-cache
8665 (setq verilog-modi-lookup-cache
8666 (make-hash-table :test 'equal :rehash-size 4.0)))
8667 (puthash module modi verilog-modi-lookup-cache))
8668 (setq verilog-modi-lookup-last-current current
8669 verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
8672 (defun verilog-modi-filename (modi)
8673 "Filename of MODI, or name of buffer if it's never been saved."
8674 (if (bufferp (verilog-modi-file-or-buffer modi))
8675 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
8676 (buffer-name (verilog-modi-file-or-buffer modi)))
8677 (verilog-modi-file-or-buffer modi)))
8679 (defun verilog-modi-goto (modi)
8680 "Move point/buffer to specified MODI."
8681 (or modi (error "Passed unfound modi to goto, check earlier"))
8682 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
8683 (verilog-modi-file-or-buffer modi)
8684 (find-file-noselect (verilog-modi-file-or-buffer modi))))
8685 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax
8687 (goto-char (verilog-modi-get-point modi)))
8689 (defun verilog-goto-defun-file (module)
8690 "Move point to the file at which a given MODULE is defined."
8691 (interactive "sGoto File for Module: ")
8692 (let* ((modi (verilog-modi-lookup module nil)))
8694 (verilog-modi-goto modi)
8695 (switch-to-buffer (current-buffer)))))
8697 (defun verilog-modi-cache-results (modi function)
8698 "Run on MODI the given FUNCTION. Locate the module in a file.
8699 Cache the output of function so next call may have faster access."
8701 (save-excursion ;; Cache is buffer-local so can't avoid this.
8702 (verilog-modi-goto modi)
8703 (if (and (setq fass (assoc (list modi function)
8704 verilog-modi-cache-list))
8705 ;; Destroy caching when incorrect; Modified or file changed
8706 (not (and verilog-cache-enabled
8707 (or (equal (buffer-chars-modified-tick) (nth 1 fass))
8708 (and verilog-modi-cache-preserve-tick
8709 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
8710 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
8711 (equal (visited-file-modtime) (nth 2 fass)))))
8712 (setq verilog-modi-cache-list nil
8715 ;; Return data from cache hit
8719 ;; Clear then restore any highlighting to make emacs19 happy
8720 (let ((fontlocked (when (and (boundp 'font-lock-mode)
8725 (setq func-returns (funcall function))
8726 (when fontlocked (font-lock-mode t))
8727 ;; Cache for next time
8728 (setq verilog-modi-cache-list
8729 (cons (list (list modi function)
8730 (buffer-chars-modified-tick)
8731 (visited-file-modtime)
8733 verilog-modi-cache-list))
8736 (defun verilog-modi-cache-add (modi function element sig-list)
8737 "Add function return results to the module cache.
8738 Update MODI's cache for given FUNCTION so that the return ELEMENT of that
8739 function now contains the additional SIG-LIST parameters."
8742 (verilog-modi-goto modi)
8743 (if (setq fass (assoc (list modi function)
8744 verilog-modi-cache-list))
8745 (let ((func-returns (nth 3 fass)))
8746 (aset func-returns element
8747 (append sig-list (aref func-returns element))))))))
8749 (defmacro verilog-preserve-modi-cache (&rest body)
8750 "Execute the BODY forms, allowing cache preservation within BODY.
8751 This means that changes to the buffer will not result in the cache being
8752 flushed. If the changes affect the modsig state, they must call the
8753 modsig-cache-add-* function, else the results of later calls may be
8754 incorrect. Without this, changes are assumed to be adding/removing signals
8755 and invalidating the cache."
8756 `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
8757 (verilog-modi-cache-preserve-buffer (current-buffer)))
8761 (defun verilog-signals-matching-enum (in-list enum)
8762 "Return all signals in IN-LIST matching the given ENUM."
8765 (if (equal (verilog-sig-enum (car in-list)) enum)
8766 (setq out-list (cons (car in-list) out-list)))
8767 (setq in-list (cdr in-list)))
8769 (let* ((enumvar (intern (concat "venum-" enum)))
8770 (enumlist (and (boundp enumvar) (eval enumvar))))
8772 (add-to-list 'out-list (list (car enumlist)))
8773 (setq enumlist (cdr enumlist))))
8774 (nreverse out-list)))
8776 (defun verilog-signals-matching-regexp (in-list regexp)
8777 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
8778 (if (or (not regexp) (equal regexp ""))
8782 (if (string-match regexp (verilog-sig-name (car in-list)))
8783 (setq out-list (cons (car in-list) out-list)))
8784 (setq in-list (cdr in-list)))
8785 (nreverse out-list))))
8787 (defun verilog-signals-not-matching-regexp (in-list regexp)
8788 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
8789 (if (or (not regexp) (equal regexp ""))
8793 (if (not (string-match regexp (verilog-sig-name (car in-list))))
8794 (setq out-list (cons (car in-list) out-list)))
8795 (setq in-list (cdr in-list)))
8796 (nreverse out-list))))
8798 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
8799 "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
8801 (if (or (not regexp) (equal regexp ""))
8803 (let (out-list to-match)
8805 ;; Note verilog-insert-one-definition matches on this order
8806 (setq to-match (concat
8808 " " (verilog-sig-signed (car in-list))
8809 " " (verilog-sig-multidim (car in-list))
8810 (verilog-sig-bits (car in-list))))
8811 (if (string-match regexp to-match)
8812 (setq out-list (cons (car in-list) out-list)))
8813 (setq in-list (cdr in-list)))
8814 (nreverse out-list))))
8817 (defun verilog-decls-get-signals (decls)
8819 (verilog-decls-get-outputs decls)
8820 (verilog-decls-get-inouts decls)
8821 (verilog-decls-get-inputs decls)
8822 (verilog-decls-get-wires decls)
8823 (verilog-decls-get-regs decls)
8824 (verilog-decls-get-assigns decls)
8825 (verilog-decls-get-consts decls)
8826 (verilog-decls-get-gparams decls)))
8828 (defun verilog-decls-get-ports (decls)
8830 (verilog-decls-get-outputs decls)
8831 (verilog-decls-get-inouts decls)
8832 (verilog-decls-get-inputs decls)))
8834 (defsubst verilog-modi-cache-add-outputs (modi sig-list)
8835 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
8836 (defsubst verilog-modi-cache-add-inouts (modi sig-list)
8837 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
8838 (defsubst verilog-modi-cache-add-inputs (modi sig-list)
8839 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
8840 (defsubst verilog-modi-cache-add-wires (modi sig-list)
8841 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
8842 (defsubst verilog-modi-cache-add-regs (modi sig-list)
8843 (verilog-modi-cache-add modi 'verilog-read-decls 4 sig-list))
8845 (defun verilog-signals-from-signame (signame-list)
8846 "Return signals in standard form from SIGNAME-LIST, a simple list of signal names."
8847 (mapcar (function (lambda (name) (list name nil nil)))
8851 ;; Auto creation utilities
8854 (defun verilog-auto-re-search-do (search-for func)
8855 "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
8856 (goto-char (point-min))
8857 (while (verilog-re-search-forward search-for nil t)
8860 (defun verilog-insert-one-definition (sig type indent-pt)
8861 "Print out a definition for SIG of the given TYPE,
8862 with appropriate INDENT-PT indentation."
8863 (indent-to indent-pt)
8864 ;; Note verilog-signals-matching-dir-re matches on this order
8866 (when (verilog-sig-modport sig)
8867 (insert "." (verilog-sig-modport sig)))
8868 (when (verilog-sig-signed sig)
8869 (insert " " (verilog-sig-signed sig)))
8870 (when (verilog-sig-multidim sig)
8871 (insert " " (verilog-sig-multidim-string sig)))
8872 (when (verilog-sig-bits sig)
8873 (insert " " (verilog-sig-bits sig)))
8874 (indent-to (max 24 (+ indent-pt 16)))
8875 (unless (= (char-syntax (preceding-char)) ?\ )
8876 (insert " ")) ; Need space between "]name" if indent-to did nothing
8877 (insert (verilog-sig-name sig)))
8879 (defun verilog-insert-definition (sigs direction indent-pt v2k &optional dont-sort)
8880 "Print out a definition for a list of SIGS of the given DIRECTION,
8881 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
8882 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output."
8884 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
8886 (let ((sig (car sigs)))
8887 (verilog-insert-one-definition
8889 ;; Want "type x" or "output type x", not "wire type x"
8890 (cond ((verilog-sig-type sig)
8892 (if (not (member direction '("wire" "interface")))
8893 (concat direction " "))
8894 (verilog-sig-type sig)))
8897 (insert (if v2k "," ";"))
8898 (if (or (not (verilog-sig-comment sig))
8899 (equal "" (verilog-sig-comment sig)))
8901 (indent-to (max 48 (+ indent-pt 40)))
8902 (verilog-insert "// " (verilog-sig-comment sig) "\n"))
8903 (setq sigs (cdr sigs)))))
8906 (if (not (boundp 'indent-pt))
8907 (defvar indent-pt nil "Local used by insert-indent")))
8909 (defun verilog-insert-indent (&rest stuff)
8910 "Indent to position stored in local `indent-pt' variable, then insert STUFF.
8911 Presumes that any newlines end a list element."
8912 (let ((need-indent t))
8914 (if need-indent (indent-to indent-pt))
8915 (setq need-indent nil)
8916 (verilog-insert (car stuff))
8917 (setq need-indent (string-match "\n$" (car stuff))
8918 stuff (cdr stuff)))))
8919 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
8921 (defun verilog-repair-open-comma ()
8922 "Insert comma if previous argument is other than a open parenthesis or endif."
8923 ;; We can't just search backward for ) as it might be inside another expression.
8924 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
8926 (verilog-backward-syntactic-ws)
8927 (when (and (not (save-excursion ;; Not beginning (, or existing ,
8929 (looking-at "[(,]")))
8930 (not (save-excursion ;; Not `endif, or user define
8932 (skip-chars-backward "[a-zA-Z0-9_`]")
8936 (defun verilog-repair-close-comma ()
8937 "If point is at a comma followed by a close parenthesis, fix it.
8938 This repairs those mis-inserted by a AUTOARG."
8939 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
8941 (verilog-forward-close-paren)
8943 (verilog-backward-syntactic-ws)
8945 (when (looking-at ",")
8948 (defun verilog-get-list (start end)
8949 "Return the elements of a comma separated list between START and END."
8951 (let ((my-list (list))
8954 (while (< (point) end)
8955 (when (re-search-forward "\\([^,{]+\\)" end t)
8956 (setq my-string (verilog-string-remove-spaces (match-string 1)))
8957 (setq my-list (nconc my-list (list my-string) ))
8958 (goto-char (match-end 0))))
8961 (defun verilog-make-width-expression (range-exp)
8962 "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
8964 (cond ((not range-exp)
8967 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
8968 (setq range-exp (match-string 1 range-exp)))
8969 (cond ((not range-exp)
8971 ;; [#:#] We can compute a numeric result
8972 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
8975 (1+ (abs (- (string-to-number (match-string 1 range-exp))
8976 (string-to-number (match-string 2 range-exp)))))))
8977 ;; [PARAM-1:0] can just return PARAM
8978 ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
8979 (match-string 1 range-exp))
8980 ;; [arbitrary] need math
8981 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
8982 (concat "(1+(" (match-string 1 range-exp) ")"
8983 (if (equal "0" (match-string 2 range-exp))
8984 "" ;; Don't bother with -(0)
8985 (concat "-(" (match-string 2 range-exp) ")"))
8988 ;;(verilog-make-width-expression "`A:`B")
8990 (defun verilog-simplify-range-expression (range-exp)
8991 "Return a simplified range expression with constants eliminated from RANGE-EXP."
8992 (let ((out range-exp)
8994 (while (not (equal last-pass out))
8995 (setq last-pass out)
8996 (while (string-match "(\\<\\([0-9A-Z-az_]+\\)\\>)" out)
8997 (setq out (replace-match "\\1" nil nil out)))
8998 (while (string-match "\\<\\([0-9]+\\)\\>\\s *\\+\\s *\\<\\([0-9]+\\)\\>" out)
8999 (setq out (replace-match
9000 (int-to-string (+ (string-to-number (match-string 1 out))
9001 (string-to-number (match-string 2 out))))
9003 (while (string-match "\\<\\([0-9]+\\)\\>\\s *\\-\\s *\\<\\([0-9]+\\)\\>" out)
9004 (setq out (replace-match
9005 (int-to-string (- (string-to-number (match-string 1 out))
9006 (string-to-number (match-string 2 out))))
9009 ;;(verilog-simplify-range-expression "1")
9010 ;;(verilog-simplify-range-expression "(((16)+1)-3)")
9012 (defun verilog-typedef-name-p (variable-name)
9013 "Return true if the VARIABLE-NAME is a type definition."
9014 (when verilog-typedef-regexp
9015 (string-match verilog-typedef-regexp variable-name)))
9021 (defun verilog-delete-autos-lined ()
9022 "Delete autos that occupy multiple lines, between begin and end comments."
9026 (looking-at "\\s-*// Beginning")
9027 (search-forward "// End of automatic" nil t))
9030 (delete-region pt (point))
9033 (defun verilog-delete-empty-auto-pair ()
9034 "Delete begin/end auto pair at point, if empty."
9036 (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
9037 "\\s-*// End of automatics\n"))
9038 (delete-region (point) (save-excursion (forward-line 2) (point)))))
9040 (defun verilog-forward-close-paren ()
9041 "Find the close parenthesis that match the current point.
9042 Ignore other close parenthesis with matching open parens."
9045 (unless (verilog-re-search-forward-quick "[()]" nil t)
9046 (error "%s: Mismatching ()" (verilog-point-text)))
9047 (cond ((= (preceding-char) ?\( )
9048 (setq parens (1+ parens)))
9049 ((= (preceding-char) ?\) )
9050 (setq parens (1- parens)))))))
9052 (defun verilog-backward-open-paren ()
9053 "Find the open parenthesis that match the current point.
9054 Ignore other open parenthesis with matching close parens."
9057 (unless (verilog-re-search-backward-quick "[()]" nil t)
9058 (error "%s: Mismatching ()" (verilog-point-text)))
9059 (cond ((= (following-char) ?\) )
9060 (setq parens (1+ parens)))
9061 ((= (following-char) ?\( )
9062 (setq parens (1- parens)))))))
9064 (defun verilog-backward-open-bracket ()
9065 "Find the open bracket that match the current point.
9066 Ignore other open bracket with matching close bracket."
9069 (unless (verilog-re-search-backward-quick "[][]" nil t)
9070 (error "%s: Mismatching []" (verilog-point-text)))
9071 (cond ((= (following-char) ?\] )
9072 (setq parens (1+ parens)))
9073 ((= (following-char) ?\[ )
9074 (setq parens (1- parens)))))))
9076 (defun verilog-delete-to-paren ()
9077 "Delete the automatic inst/sense/arg created by autos.
9078 Deletion stops at the matching end parenthesis."
9079 (delete-region (point)
9081 (verilog-backward-open-paren)
9082 (forward-sexp 1) ;; Moves to paren that closes argdecl's
9086 (defun verilog-auto-star-safe ()
9087 "Return if a .* AUTOINST is safe to delete or expand.
9088 It was created by the AUTOS themselves, or by the user."
9089 (and verilog-auto-star-expand
9090 (looking-at "[ \t\n\f,]*\\([)]\\|// \\(Outputs\\|Inouts\\|Inputs\\|Interfaces\\)\\)")))
9092 (defun verilog-delete-auto-star-all ()
9093 "Delete a .* AUTOINST, if it is safe."
9094 (when (verilog-auto-star-safe)
9095 (verilog-delete-to-paren)))
9097 (defun verilog-delete-auto-star-implicit ()
9098 "Delete all .* implicit connections created by `verilog-auto-star'.
9099 This function will be called automatically at save unless
9100 `verilog-auto-star-save' is set, any non-templated expanded pins will be
9103 (let (paren-pt indent have-close-paren)
9105 (goto-char (point-min))
9106 ;; We need to match these even outside of comments.
9107 ;; For reasonable performance, we don't check if inside comments, sorry.
9108 (while (re-search-forward "// Implicit \\.\\*" nil t)
9109 (setq paren-pt (point))
9111 (setq have-close-paren
9113 (when (search-forward ");" paren-pt t)
9114 (setq indent (current-indentation))
9116 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
9117 (when have-close-paren
9118 ;; Delete extra commentary
9122 (looking-at "\\s *//\\s *\\(Outputs\\|Inouts\\|Inputs\\|Interfaces\\)\n"))
9123 (delete-region (match-beginning 0) (match-end 0))))
9124 ;; If it is simple, we can put the ); on the same line as the last text
9125 (let ((rtn-pt (point)))
9127 (while (progn (backward-char 1)
9128 (looking-at "[ \t\n\f]")))
9129 (when (looking-at ",")
9130 (delete-region (+ 1 (point)) rtn-pt))))
9134 ;; Still need to kill final comma - always is one as we put one after the .*
9135 (re-search-backward ",")
9136 (delete-char 1))))))
9138 (defun verilog-delete-auto ()
9139 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
9140 Use \\[verilog-auto] to re-insert the updated AUTOs.
9142 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
9143 called before and after this function, respectively."
9146 (if (buffer-file-name)
9147 (find-file-noselect (buffer-file-name))) ;; To check we have latest version
9148 (verilog-save-no-change-functions
9149 (verilog-save-scan-cache
9150 ;; Allow user to customize
9151 (run-hooks 'verilog-before-delete-auto-hook)
9153 ;; Remove those that have multi-line insertions, possibly with parameters
9154 (verilog-auto-re-search-do
9157 (verilog-regexp-words
9158 `("AUTOASCIIENUM" "AUTOCONCATCOMMENT" "AUTODEFINEVALUE"
9159 "AUTOINOUT" "AUTOINOUTCOMP" "AUTOINOUTMODULE"
9160 "AUTOINPUT" "AUTOINSERTLISP" "AUTOOUTPUT" "AUTOOUTPUTEVERY"
9161 "AUTOREG" "AUTOREGINPUT" "AUTORESET" "AUTOTIEOFF"
9162 "AUTOUNUSED" "AUTOWIRE")))
9163 ;; Optional parens or quoted parameter or .* for (((...)))
9164 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
9166 'verilog-delete-autos-lined)
9167 ;; Remove those that are in parenthesis
9168 (verilog-auto-re-search-do
9171 (verilog-regexp-words
9172 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
9175 'verilog-delete-to-paren)
9176 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
9177 (verilog-auto-re-search-do "\\.\\*"
9178 'verilog-delete-auto-star-all)
9179 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
9180 (goto-char (point-min))
9181 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)[ \tLT0-9]*$" nil t)
9185 (run-hooks 'verilog-delete-auto-hook)))))
9191 (defun verilog-inject-auto ()
9192 "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
9194 Any always @ blocks with sensitivity lists that match computed lists will
9195 be replaced with /*AS*/ comments.
9197 Any cells will get /*AUTOINST*/ added to the end of the pin list.
9198 Pins with have identical names will be deleted.
9200 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
9201 support adding new ports. You may wish to delete older ports yourself.
9205 module ExampInject (i, o);
9216 Typing \\[verilog-inject-auto] will make this into:
9218 module ExampInject (i, o/*AUTOARG*/
9223 always @ (/*AS*/i or j)
9234 (defun verilog-inject-arg ()
9235 "Inject AUTOARG into new code. See `verilog-inject-auto'."
9236 ;; Presume one module per file.
9238 (goto-char (point-min))
9239 (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
9240 (let ((endmodp (save-excursion
9241 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
9243 ;; See if there's already a comment .. inside a comment so not verilog-re-search
9244 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
9245 (verilog-re-search-forward-quick ";" nil t)
9247 (verilog-backward-syntactic-ws)
9248 (backward-char 1) ; Moves to paren that closes argdecl's
9249 (when (looking-at ")")
9250 (verilog-insert "/*AUTOARG*/")))))))
9252 (defun verilog-inject-sense ()
9253 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
9255 (goto-char (point-min))
9256 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
9257 (let* ((start-pt (point))
9258 (modi (verilog-modi-current))
9259 (moddecls (verilog-modi-get-decls modi))
9264 (backward-char 1) ;; End )
9265 (when (not (verilog-re-search-backward "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
9266 (setq pre-sigs (verilog-signals-from-signame
9267 (verilog-read-signals start-pt (point)))
9268 got-sigs (verilog-auto-sense-sigs moddecls nil))
9269 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
9270 (verilog-signals-not-in got-sigs pre-sigs)))
9271 (delete-region start-pt (point))
9272 (verilog-insert "/*AS*/")))))))
9274 (defun verilog-inject-inst ()
9275 "Inject AUTOINST into new code. See `verilog-inject-auto'."
9277 (goto-char (point-min))
9278 ;; It's hard to distinguish modules; we'll instead search for pins.
9279 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t)
9280 (verilog-backward-open-paren) ;; Inst start
9282 ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip.
9284 (verilog-forward-close-paren)) ;; Parameters done
9287 (let ((indent-pt (+ (current-column)))
9288 (end-pt (save-excursion (verilog-forward-close-paren) (point))))
9289 (cond ((verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
9290 (goto-char end-pt)) ;; Already there, continue search with next instance
9292 ;; Delete identical interconnect
9293 (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc
9294 (while (verilog-re-search-forward "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
9295 (delete-region (match-beginning 0) (match-end 0))
9296 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct
9297 (while (or (looking-at "[ \t\n\f,]+")
9298 (looking-at "//[^\n]*"))
9299 (delete-region (match-beginning 0) (match-end 0))
9300 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
9301 (verilog-forward-close-paren)
9303 ;; Not verilog-re-search, as we don't want to strip comments
9304 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
9305 (delete-region (match-beginning 0) (match-end 0)))
9306 (verilog-insert "\n")
9307 (verilog-insert-indent "/*AUTOINST*/")))))))))
9313 (defun verilog-auto-save-check ()
9314 "On saving see if we need auto update."
9315 (cond ((not verilog-auto-save-policy)) ; disabled
9316 ((not (save-excursion
9318 (let ((case-fold-search nil))
9319 (goto-char (point-min))
9320 (re-search-forward "AUTO" nil t))))))
9321 ((eq verilog-auto-save-policy 'force)
9323 ((not (buffer-modified-p)))
9324 ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
9325 ((eq verilog-auto-save-policy 'detect)
9328 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
9330 ;; Don't ask again if didn't update
9331 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
9332 (when (not verilog-auto-star-save)
9333 (verilog-delete-auto-star-implicit))
9334 nil) ;; Always return nil -- we don't write the file ourselves
9336 (defun verilog-auto-read-locals ()
9337 "Return file local variable segment at bottom of file."
9339 (goto-char (point-max))
9340 (if (re-search-backward "Local Variables:" nil t)
9341 (buffer-substring-no-properties (point) (point-max))
9344 (defun verilog-auto-reeval-locals (&optional force)
9345 "Read file local variable segment at bottom of file if it has changed.
9346 If FORCE, always reread it."
9347 (make-local-variable 'verilog-auto-last-file-locals)
9348 (let ((curlocal (verilog-auto-read-locals)))
9349 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
9350 (setq verilog-auto-last-file-locals curlocal)
9351 ;; Note this may cause this function to be recursively invoked,
9352 ;; because hack-local-variables may call (verilog-mode)
9353 ;; The above when statement will prevent it from recursing forever.
9354 (hack-local-variables)
9361 (defun verilog-auto-arg-ports (sigs message indent-pt)
9362 "Print a list of ports for a AUTOINST.
9363 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
9365 (when verilog-auto-arg-sort
9366 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
9368 (indent-to indent-pt)
9372 (indent-to indent-pt)
9374 (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
9376 (indent-to indent-pt))
9378 (insert (verilog-sig-name (car sigs)) ",")
9379 (setq sigs (cdr sigs)
9382 (defun verilog-auto-arg ()
9383 "Expand AUTOARG statements.
9384 Replace the argument declarations at the beginning of the
9385 module with ones automatically derived from input and output
9386 statements. This can be dangerous if the module is instantiated
9387 using position-based connections, so use only name-based when
9388 instantiating the resulting module. Long lines are split based
9389 on the `fill-column', see \\[set-fill-column].
9392 Concatenation and outputting partial busses is not supported.
9394 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
9398 module ExampArg (/*AUTOARG*/);
9403 Typing \\[verilog-auto] will make this into:
9405 module ExampArg (/*AUTOARG*/
9415 The argument declarations may be printed in declaration order to best suit
9416 order based instantiations, or alphabetically, based on the
9417 `verilog-auto-arg-sort' variable.
9419 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
9420 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
9421 conservative guess on adding a comma for the first signal, if you have
9422 any ifdefs or complicated expressions before the AUTOARG you will need
9423 to choose the comma yourself.
9425 Avoid declaring ports manually, as it makes code harder to maintain."
9427 (let* ((modi (verilog-modi-current))
9428 (moddecls (verilog-modi-get-decls modi))
9429 (skip-pins (aref (verilog-read-arg-pins) 0)))
9430 (verilog-repair-open-comma)
9431 (verilog-auto-arg-ports (verilog-signals-not-in
9432 (verilog-decls-get-outputs moddecls)
9435 verilog-indent-level-declaration)
9436 (verilog-auto-arg-ports (verilog-signals-not-in
9437 (verilog-decls-get-inouts moddecls)
9440 verilog-indent-level-declaration)
9441 (verilog-auto-arg-ports (verilog-signals-not-in
9442 (verilog-decls-get-inputs moddecls)
9445 verilog-indent-level-declaration)
9446 (verilog-repair-close-comma)
9447 (unless (eq (char-before) ?/ )
9449 (indent-to verilog-indent-level-declaration))))
9451 (defun verilog-auto-inst-port-map (port-st)
9454 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
9455 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
9456 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
9457 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
9458 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
9459 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
9460 (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
9461 (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
9463 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
9464 "Print out a instantiation connection for this PORT-ST.
9465 Insert to INDENT-PT, use template TPL-LIST.
9466 @ are instantiation numbers, replaced with TPL-NUM.
9467 @\"(expression @)\" are evaluated, with @ as a variable.
9468 If FOR-STAR add comment it is a .* expansion.
9469 If PAR-VALUES replace final strings with these parameter values."
9470 (let* ((port (verilog-sig-name port-st))
9471 (tpl-ass (or (assoc port (car tpl-list))
9472 (verilog-auto-inst-port-map port-st)))
9473 ;; vl-* are documented for user use
9474 (vl-name (verilog-sig-name port-st))
9475 (vl-width (verilog-sig-width port-st))
9476 (vl-modport (verilog-sig-modport port-st))
9477 (vl-mbits (if (verilog-sig-multidim port-st)
9478 (verilog-sig-multidim-string port-st) ""))
9479 (vl-bits (if (or verilog-auto-inst-vector
9480 (not (assoc port vector-skip-list))
9481 (not (equal (verilog-sig-bits port-st)
9482 (verilog-sig-bits (assoc port vector-skip-list)))))
9483 (or (verilog-sig-bits port-st) "")
9485 (case-fold-search nil)
9486 (check-values par-values)
9488 ;; Replace parameters in bit-width
9489 (when (and check-values
9490 (not (equal vl-bits "")))
9492 (setq vl-bits (verilog-string-replace-matches
9493 (concat "\\<" (nth 0 (car check-values)) "\\>")
9494 (concat "(" (nth 1 (car check-values)) ")")
9496 check-values (cdr check-values)))
9497 (setq vl-bits (verilog-simplify-range-expression vl-bits))) ; Not in the loop for speed
9498 ;; Default net value if not found
9499 (setq tpl-net (concat port
9500 (if vl-modport (concat "." vl-modport) "")
9501 (if (verilog-sig-multidim port-st)
9502 (concat "/*" (verilog-sig-multidim-string port-st)
9506 (cond (tpl-ass ; Template of exact port name
9507 (setq tpl-net (nth 1 tpl-ass)))
9508 ((nth 1 tpl-list) ; Wildcards in template, search them
9509 (let ((wildcards (nth 1 tpl-list)))
9511 (when (string-match (nth 0 (car wildcards)) port)
9512 (setq tpl-ass (car wildcards) ; so allow @ parsing
9513 tpl-net (replace-match (nth 1 (car wildcards))
9515 (setq wildcards (cdr wildcards))))))
9516 ;; Parse Templated variable
9518 ;; Evaluate @"(lispcode)"
9519 (when (string-match "@\".*[^\\]\"" tpl-net)
9520 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
9523 (substring tpl-net 0 (match-beginning 0))
9525 (let* ((expr (match-string 1 tpl-net))
9528 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
9529 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
9530 (prin1 (eval (car (read-from-string expr)))
9531 (lambda (ch) ())))))
9532 (if (numberp value) (setq value (number-to-string value)))
9534 (substring tpl-net (match-end 0))))))
9535 ;; Replace @ and [] magic variables in final output
9536 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
9537 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
9539 (indent-to indent-pt)
9541 (unless (and verilog-auto-inst-dot-name
9542 (equal port tpl-net))
9543 (indent-to verilog-auto-inst-column)
9544 (insert "(" tpl-net ")"))
9547 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
9548 verilog-auto-inst-column))
9549 (if verilog-auto-inst-template-numbers
9550 (verilog-insert " // Templated"
9551 " T" (int-to-string (nth 2 tpl-ass))
9552 " L" (int-to-string (nth 3 tpl-ass)))
9553 (verilog-insert " // Templated")))
9555 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
9556 verilog-auto-inst-column))
9557 (verilog-insert " // Implicit .\*"))) ;For some reason the . or * must be escaped...
9559 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
9560 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
9561 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
9563 (defun verilog-auto-inst-first ()
9564 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
9565 ;; Do we need a trailing comma?
9566 ;; There maybe a ifdef or something similar before us. What a mess. Thus
9567 ;; to avoid trouble we only insert on preceding ) or *.
9568 ;; Insert first port on new line
9569 (insert "\n") ;; Must insert before search, so point will move forward if insert comma
9571 (verilog-re-search-backward "[^ \t\n\f]" nil nil)
9572 (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure
9576 (defun verilog-auto-star ()
9577 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
9579 If `verilog-auto-star-expand' is set, .* pins are treated if they were
9580 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
9581 will also ignore any .* that are not last in your pin list (this prevents
9582 it from deleting pins following the .* when it expands the AUTOINST.)
9584 On writing your file, unless `verilog-auto-star-save' is set, any
9585 non-templated expanded pins will be removed. You may do this at any time
9586 with \\[verilog-delete-auto-star-implicit].
9588 If you are converting a module to use .* for the first time, you may wish
9589 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
9591 See `verilog-auto-inst' for examples, templates, and more information."
9592 (when (verilog-auto-star-safe)
9593 (verilog-auto-inst)))
9595 (defun verilog-auto-inst ()
9596 "Expand AUTOINST statements, as part of \\[verilog-auto].
9597 Replace the pin connections to an instantiation or interface
9598 declaration with ones automatically derived from the module or
9599 interface header of the instantiated item.
9601 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
9602 and delete them before saving unless `verilog-auto-star-save' is set.
9603 See `verilog-auto-star' for more information.
9606 Module names must be resolvable to filenames by adding a
9607 `verilog-library-extensions', and being found in the same directory, or
9608 by changing the variable `verilog-library-flags' or
9609 `verilog-library-directories'. Macros `modname are translated through the
9610 vh-{name} Emacs variable, if that is not found, it just ignores the `.
9612 In templates you must have one signal per line, ending in a ), or ));,
9613 and have proper () nesting, including a final ); to end the template.
9615 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
9617 SystemVerilog multidimensional input/output has only experimental support.
9619 SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
9621 Parameters referenced by the instantiation will remain symbolic, unless
9622 `verilog-auto-inst-param-value' is set.
9624 Gate primitives (and/or) may have AUTOINST for the purpose of
9625 AUTOWIRE declarations, etc. Gates are the only case when
9626 position based connections are passed.
9628 For example, first take the submodule InstModule.v:
9630 module InstModule (o,i);
9633 wire [31:0] o = {32{i}};
9636 This is then used in a upper level module:
9638 module ExampInst (o,i);
9645 Typing \\[verilog-auto] will make this into:
9647 module ExampInst (o,i);
9658 Where the list of inputs and outputs came from the inst module.
9662 Unless you are instantiating a module multiple times, or the module is
9663 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
9664 It just makes for unmaintainable code. To sanitize signal names, try
9665 vrename from URL `http://www.veripool.org'.
9667 When you need to violate this suggestion there are two ways to list
9668 exceptions, placing them before the AUTOINST, or using templates.
9670 Any ports defined before the /*AUTOINST*/ are not included in the list of
9671 automatics. This is similar to making a template as described below, but
9672 is restricted to simple connections just like you normally make. Also note
9673 that any signals before the AUTOINST will only be picked up by AUTOWIRE if
9674 you have the appropriate // Input or // Output comment, and exactly the
9675 same line formatting as AUTOINST itself uses.
9679 .i (my_i_dont_mess_with_it),
9687 For multiple instantiations based upon a single template, create a
9688 commented out template:
9690 /* InstModule AUTO_TEMPLATE (
9695 Templates go ABOVE the instantiation(s). When an instantiation is
9696 expanded `verilog-mode' simply searches up for the closest template.
9697 Thus you can have multiple templates for the same module, just alternate
9698 between the template for an instantiation and the instantiation itself.
9700 The module name must be the same as the name of the module in the
9701 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
9702 words and capitalized. Only signals that must be different for each
9703 instantiation need to be listed.
9705 Inside a template, a [] in a connection name (with nothing else inside
9706 the brackets) will be replaced by the same bus subscript as it is being
9707 connected to, or the [] will be removed if it is a single bit signal.
9708 Generally it is a good idea to do this for all connections in a template,
9709 as then they will work for any width signal, and with AUTOWIRE. See
9710 PTL_BUS becoming PTL_BUSNEW below.
9712 If you have a complicated template, set `verilog-auto-inst-template-numbers'
9713 to see which regexps are matching. Don't leave that mode set after
9714 debugging is completed though, it will result in lots of extra differences
9715 and merge conflicts.
9719 /* InstModule AUTO_TEMPLATE (
9720 .ptl_bus (ptl_busnew[]),
9723 InstModule ms2m (/*AUTOINST*/);
9725 Typing \\[verilog-auto] will make this into:
9727 InstModule ms2m (/*AUTOINST*/
9729 .NotInTemplate (NotInTemplate),
9730 .ptl_bus (ptl_busnew[3:0]), // Templated
9735 It is common to instantiate a cell multiple times, so templates make it
9736 trivial to substitute part of the cell name into the connection name.
9738 /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
9740 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
9744 If no regular expression is provided immediately after the AUTO_TEMPLATE
9745 keyword, then the @ character in any connection names will be replaced
9746 with the instantiation number; the first digits found in the cell's
9749 If a regular expression is provided, the @ character will be replaced
9750 with the first \(\) grouping that matches against the cell name. Using a
9751 regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no
9752 regexp is provided. If you use multiple layers of parenthesis,
9753 \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number
9754 characters after test and before _, whereas
9755 \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire
9760 /* InstModule AUTO_TEMPLATE (
9761 .ptl_mapvalidx (ptl_mapvalid[@]),
9762 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
9765 InstModule ms2m (/*AUTOINST*/);
9767 Typing \\[verilog-auto] will make this into:
9769 InstModule ms2m (/*AUTOINST*/
9771 .ptl_mapvalidx (ptl_mapvalid[2]),
9772 .ptl_mapvalidp1x (ptl_mapvalid[3]));
9774 Note the @ character was replaced with the 2 from \"ms2m\".
9776 Alternatively, using a regular expression for @:
9778 /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
9779 .ptl_mapvalidx (@_ptl_mapvalid),
9780 .ptl_mapvalidp1x (ptl_mapvalid_@),
9783 InstModule ms2_FOO (/*AUTOINST*/);
9784 InstModule ms2_BAR (/*AUTOINST*/);
9786 Typing \\[verilog-auto] will make this into:
9788 InstModule ms2_FOO (/*AUTOINST*/
9790 .ptl_mapvalidx (FOO_ptl_mapvalid),
9791 .ptl_mapvalidp1x (ptl_mapvalid_FOO));
9792 InstModule ms2_BAR (/*AUTOINST*/
9794 .ptl_mapvalidx (BAR_ptl_mapvalid),
9795 .ptl_mapvalidp1x (ptl_mapvalid_BAR));
9800 A template entry of the form
9802 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
9804 will apply an Emacs style regular expression search for any port beginning
9805 in pci_req followed by numbers and ending in _l and connecting that to
9806 the pci_req_jtag_[] net, with the bus subscript coming from what matches
9807 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
9809 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
9810 does the same thing. (Note a @ in the connection/replacement text is
9811 completely different -- still use \\1 there!) Thus this is the same as
9814 .pci_req@_l (pci_req_jtag_[\\1]),
9816 Here's another example to remove the _l, useful when naming conventions
9817 specify _ alone to mean active low. Note the use of [] to keep the bus
9820 .\\(.*\\)_l (\\1_[]),
9824 First any regular expression template is expanded.
9826 If the syntax @\"( ... )\" is found in a connection, the expression in
9827 quotes will be evaluated as a Lisp expression, with @ replaced by the
9828 instantiation number. The MAPVALIDP1X example above would put @+1 modulo
9829 4 into the brackets. Quote all double-quotes inside the expression with
9830 a leading backslash (\\\"...\\\"); or if the Lisp template is also a
9831 regexp template backslash the backslash quote (\\\\\"...\\\\\").
9833 There are special variables defined that are useful in these
9836 vl-name Name portion of the input/output port.
9837 vl-bits Bus bits portion of the input/output port ('[2:0]').
9838 vl-mbits Multidimensional array bits for port ('[2:0][3:0]').
9839 vl-width Width of the input/output port ('3' for [2:0]).
9840 May be a (...) expression if bits isn't a constant.
9841 vl-dir Direction of the pin input/output/inout/interface.
9842 vl-modport The modport, if an interface with a modport.
9843 vl-cell-type Module name/type of the cell ('InstModule').
9844 vl-cell-name Instance name of the cell ('instName').
9846 Normal Lisp variables may be used in expressions. See
9847 `verilog-read-defines' which can set vh-{definename} variables for use
9848 here. Also, any comments of the form:
9850 /*AUTO_LISP(setq foo 1)*/
9852 will evaluate any Lisp expression inside the parenthesis between the
9853 beginning of the buffer and the point of the AUTOINST. This allows
9854 functions to be defined or variables to be changed between instantiations.
9855 (See also `verilog-auto-insert-lisp' if you want the output from your
9856 lisp function to be inserted.)
9858 Note that when using lisp expressions errors may occur when @ is not a
9859 number; you may need to use the standard Emacs Lisp functions
9860 `number-to-string' and `string-to-number'.
9862 After the evaluation is completed, @ substitution and [] substitution
9865 For more information see the \\[verilog-faq] and forums at URL
9866 `http://www.veripool.org'."
9870 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
9871 (indent-pt (save-excursion (verilog-backward-open-paren)
9872 (1+ (current-column))))
9873 (verilog-auto-inst-column (max verilog-auto-inst-column
9874 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
9875 (modi (verilog-modi-current))
9876 (moddecls (verilog-modi-get-decls modi))
9877 (vector-skip-list (unless verilog-auto-inst-vector
9878 (verilog-decls-get-signals moddecls)))
9879 submod submodi submoddecls
9880 inst skip-pins tpl-list tpl-num did-first par-values)
9882 ;; Find module name that is instantiated
9883 (setq submod (verilog-read-inst-module)
9884 inst (verilog-read-inst-name)
9887 skip-pins (aref (verilog-read-inst-pins) 0))
9889 ;; Parse any AUTO_LISP() before here
9890 (verilog-read-auto-lisp (point-min) pt)
9892 ;; Read parameters (after AUTO_LISP)
9893 (setq par-values (and verilog-auto-inst-param-value
9894 (verilog-read-inst-param-value)))
9896 ;; Lookup position, etc of submodule
9897 ;; Note this may raise an error
9898 (when (and (not (member submod verilog-gate-keywords))
9899 (setq submodi (verilog-modi-lookup submod t)))
9900 (setq submoddecls (verilog-modi-get-decls submodi))
9901 ;; If there's a number in the instantiation, it may be a argument to the
9902 ;; automatic variable instantiation program.
9903 (let* ((tpl-info (verilog-read-auto-template submod))
9904 (tpl-regexp (aref tpl-info 0)))
9905 (setq tpl-num (if (string-match tpl-regexp inst)
9906 (match-string 1 inst)
9908 tpl-list (aref tpl-info 1)))
9909 ;; Find submodule's signals and dump
9910 (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
9911 (verilog-signals-not-in
9912 (append (verilog-decls-get-wires submoddecls)
9913 (verilog-decls-get-regs submoddecls))
9915 (vl-dir "interfaced"))
9917 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9918 ;; Note these are searched for in verilog-read-sub-decls.
9919 (verilog-insert-indent "// Interfaced\n")
9920 (mapc (lambda (port)
9921 (verilog-auto-inst-port port indent-pt
9922 tpl-list tpl-num for-star par-values))
9924 (let ((sig-list (verilog-signals-not-in
9925 (verilog-decls-get-interfaces submoddecls)
9927 (vl-dir "interface"))
9929 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9930 ;; Note these are searched for in verilog-read-sub-decls.
9931 (verilog-insert-indent "// Interfaces\n")
9932 (mapc (lambda (port)
9933 (verilog-auto-inst-port port indent-pt
9934 tpl-list tpl-num for-star par-values))
9936 (let ((sig-list (verilog-signals-not-in
9937 (verilog-decls-get-outputs submoddecls)
9941 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9942 (verilog-insert-indent "// Outputs\n")
9943 (mapc (lambda (port)
9944 (verilog-auto-inst-port port indent-pt
9945 tpl-list tpl-num for-star par-values))
9947 (let ((sig-list (verilog-signals-not-in
9948 (verilog-decls-get-inouts submoddecls)
9952 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9953 (verilog-insert-indent "// Inouts\n")
9954 (mapc (lambda (port)
9955 (verilog-auto-inst-port port indent-pt
9956 tpl-list tpl-num for-star par-values))
9958 (let ((sig-list (verilog-signals-not-in
9959 (verilog-decls-get-inputs submoddecls)
9963 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9964 (verilog-insert-indent "// Inputs\n")
9965 (mapc (lambda (port)
9966 (verilog-auto-inst-port port indent-pt
9967 tpl-list tpl-num for-star par-values))
9972 (re-search-backward "," pt t)
9975 (search-forward "\n") ;; Added by inst-port
9977 (if (search-forward ")" nil t) ;; From user, moved up a line
9979 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it
9980 (delete-char -1)))))))))
9982 (defun verilog-auto-inst-param ()
9983 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
9984 Replace the parameter connections to an instantiation with ones
9985 automatically derived from the module header of the instantiated netlist.
9987 See \\[verilog-auto-inst] for limitations, and templates to customize the
9990 For example, first take the submodule InstModule.v:
9992 module InstModule (o,i);
9996 This is then used in a upper level module:
9998 module ExampInst (o,i);
10000 InstModule #(/*AUTOINSTPARAM*/)
10001 instName (/*AUTOINST*/);
10004 Typing \\[verilog-auto] will make this into:
10006 module ExampInst (o,i);
10009 InstModule #(/*AUTOINSTPARAM*/
10012 instName (/*AUTOINST*/);
10015 Where the list of parameter connections come from the inst module.
10019 You can customize the parameter connections using AUTO_TEMPLATEs,
10020 just as you would with \\[verilog-auto-inst]."
10023 (let* ((pt (point))
10024 (indent-pt (save-excursion (verilog-backward-open-paren)
10025 (1+ (current-column))))
10026 (verilog-auto-inst-column (max verilog-auto-inst-column
10027 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
10028 (modi (verilog-modi-current))
10029 (moddecls (verilog-modi-get-decls modi))
10030 (vector-skip-list (unless verilog-auto-inst-vector
10031 (verilog-decls-get-signals moddecls)))
10032 submod submodi submoddecls
10033 inst skip-pins tpl-list tpl-num did-first)
10034 ;; Find module name that is instantiated
10035 (setq submod (save-excursion
10036 ;; Get to the point where AUTOINST normally is to read the module
10037 (verilog-re-search-forward-quick "[(;]" nil nil)
10038 (verilog-read-inst-module))
10039 inst (save-excursion
10040 ;; Get to the point where AUTOINST normally is to read the module
10041 (verilog-re-search-forward-quick "[(;]" nil nil)
10042 (verilog-read-inst-name))
10043 vl-cell-type submod
10045 skip-pins (aref (verilog-read-inst-pins) 0))
10047 ;; Parse any AUTO_LISP() before here
10048 (verilog-read-auto-lisp (point-min) pt)
10050 ;; Lookup position, etc of submodule
10051 ;; Note this may raise an error
10052 (when (setq submodi (verilog-modi-lookup submod t))
10053 (setq submoddecls (verilog-modi-get-decls submodi))
10054 ;; If there's a number in the instantiation, it may be a argument to the
10055 ;; automatic variable instantiation program.
10056 (let* ((tpl-info (verilog-read-auto-template submod))
10057 (tpl-regexp (aref tpl-info 0)))
10058 (setq tpl-num (if (string-match tpl-regexp inst)
10059 (match-string 1 inst)
10061 tpl-list (aref tpl-info 1)))
10062 ;; Find submodule's signals and dump
10063 (let ((sig-list (verilog-signals-not-in
10064 (verilog-decls-get-gparams submoddecls)
10066 (vl-dir "parameter"))
10068 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
10069 ;; Note these are searched for in verilog-read-sub-decls.
10070 (verilog-insert-indent "// Parameters\n")
10071 (mapc (lambda (port)
10072 (verilog-auto-inst-port port indent-pt
10073 tpl-list tpl-num nil nil))
10078 (re-search-backward "," pt t)
10081 (search-forward "\n") ;; Added by inst-port
10083 (if (search-forward ")" nil t) ;; From user, moved up a line
10084 (delete-char -1)))))))))
10086 (defun verilog-auto-reg ()
10087 "Expand AUTOREG statements, as part of \\[verilog-auto].
10088 Make reg statements for any output that isn't already declared,
10089 and isn't a wire output from a block.
10092 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
10094 This does NOT work on memories, declare those yourself.
10098 module ExampReg (o,i);
10105 Typing \\[verilog-auto] will make this into:
10107 module ExampReg (o,i);
10111 // Beginning of automatic regs (for this module's undeclared outputs)
10113 // End of automatics
10117 ;; Point must be at insertion point.
10118 (let* ((indent-pt (current-indentation))
10119 (modi (verilog-modi-current))
10120 (moddecls (verilog-modi-get-decls modi))
10121 (modsubdecls (verilog-modi-get-sub-decls modi))
10122 (sig-list (verilog-signals-not-in
10123 (verilog-decls-get-outputs moddecls)
10124 (append (verilog-decls-get-wires moddecls)
10125 (verilog-decls-get-regs moddecls)
10126 (verilog-decls-get-assigns moddecls)
10127 (verilog-decls-get-consts moddecls)
10128 (verilog-decls-get-gparams moddecls)
10129 (verilog-subdecls-get-interfaced modsubdecls)
10130 (verilog-subdecls-get-outputs modsubdecls)
10131 (verilog-subdecls-get-inouts modsubdecls)))))
10134 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
10135 (verilog-insert-definition sig-list "reg" indent-pt nil)
10136 (verilog-modi-cache-add-regs modi sig-list)
10137 (verilog-insert-indent "// End of automatics\n")))))
10139 (defun verilog-auto-reg-input ()
10140 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
10141 Make reg statements instantiation inputs that aren't already declared.
10142 This is useful for making a top level shell for testing the module that is
10143 to be instantiated.
10146 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
10148 This does NOT work on memories, declare those yourself.
10150 An example (see `verilog-auto-inst' for what else is going on here):
10152 module ExampRegInput (o,i);
10156 InstModule instName
10160 Typing \\[verilog-auto] will make this into:
10162 module ExampRegInput (o,i);
10166 // Beginning of automatic reg inputs (for undeclared ...
10167 reg [31:0] iv; // From inst of inst.v
10168 // End of automatics
10169 InstModule instName
10177 ;; Point must be at insertion point.
10178 (let* ((indent-pt (current-indentation))
10179 (modi (verilog-modi-current))
10180 (moddecls (verilog-modi-get-decls modi))
10181 (modsubdecls (verilog-modi-get-sub-decls modi))
10182 (sig-list (verilog-signals-combine-bus
10183 (verilog-signals-not-in
10184 (append (verilog-subdecls-get-inputs modsubdecls)
10185 (verilog-subdecls-get-inouts modsubdecls))
10186 (verilog-decls-get-signals moddecls)))))
10189 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
10190 (verilog-insert-definition sig-list "reg" indent-pt nil)
10191 (verilog-modi-cache-add-regs modi sig-list)
10192 (verilog-insert-indent "// End of automatics\n")))))
10194 (defun verilog-auto-wire ()
10195 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
10196 Make wire statements for instantiations outputs that aren't
10200 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
10201 and all busses must have widths, such as those from AUTOINST, or using []
10204 This does NOT work on memories or SystemVerilog .name connections,
10205 declare those yourself.
10207 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
10208 determine how to bus together. This occurs when you have ports with
10209 non-numeric or non-sequential bus subscripts. If Verilog mode
10210 mis-guessed, you'll have to declare them yourself.
10212 An example (see `verilog-auto-inst' for what else is going on here):
10214 module ExampWire (o,i);
10218 InstModule instName
10222 Typing \\[verilog-auto] will make this into:
10224 module ExampWire (o,i);
10228 // Beginning of automatic wires
10229 wire [31:0] ov; // From inst of inst.v
10230 // End of automatics
10231 InstModule instName
10240 ;; Point must be at insertion point.
10241 (let* ((indent-pt (current-indentation))
10242 (modi (verilog-modi-current))
10243 (moddecls (verilog-modi-get-decls modi))
10244 (modsubdecls (verilog-modi-get-sub-decls modi))
10245 (sig-list (verilog-signals-combine-bus
10246 (verilog-signals-not-in
10247 (append (verilog-subdecls-get-outputs modsubdecls)
10248 (verilog-subdecls-get-inouts modsubdecls))
10249 (verilog-decls-get-signals moddecls)))))
10252 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
10253 (verilog-insert-definition sig-list "wire" indent-pt nil)
10254 (verilog-modi-cache-add-wires modi sig-list)
10255 (verilog-insert-indent "// End of automatics\n")
10256 (when nil ;; Too slow on huge modules, plus makes everyone's module change
10257 (beginning-of-line)
10259 (verilog-pretty-declarations quiet)
10261 (verilog-pretty-expr t "//"))))))
10263 (defun verilog-auto-output (&optional with-params)
10264 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
10265 Make output statements for any output signal from an /*AUTOINST*/ that
10266 isn't a input to another AUTOINST. This is useful for modules which
10267 only instantiate other modules.
10270 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
10272 If placed inside the parenthesis of a module declaration, it creates
10273 Verilog 2001 style, else uses Verilog 1995 style.
10275 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
10276 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE).
10278 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10280 Signals matching `verilog-auto-output-ignore-regexp' are not included.
10282 An example (see `verilog-auto-inst' for what else is going on here):
10284 module ExampOutput (ov,i);
10287 InstModule instName
10291 Typing \\[verilog-auto] will make this into:
10293 module ExampOutput (ov,i);
10296 // Beginning of automatic outputs (from unused autoinst outputs)
10297 output [31:0] ov; // From inst of inst.v
10298 // End of automatics
10299 InstModule instName
10307 You may also provide an optional regular expression, in which case only
10308 signals matching the regular expression will be included. For example the
10309 same expansion will result from only extracting outputs starting with ov:
10311 /*AUTOOUTPUT(\"^ov\")*/"
10313 ;; Point must be at insertion point.
10314 (let* ((indent-pt (current-indentation))
10315 (regexp (and with-params
10316 (nth 0 (verilog-read-auto-params 1))))
10317 (v2k (verilog-in-paren))
10318 (modi (verilog-modi-current))
10319 (moddecls (verilog-modi-get-decls modi))
10320 (modsubdecls (verilog-modi-get-sub-decls modi))
10321 (sig-list (verilog-signals-not-in
10322 (verilog-subdecls-get-outputs modsubdecls)
10323 (append (verilog-decls-get-outputs moddecls)
10324 (verilog-decls-get-inouts moddecls)
10325 (verilog-subdecls-get-inputs modsubdecls)
10326 (verilog-subdecls-get-inouts modsubdecls)))))
10328 (setq sig-list (verilog-signals-matching-regexp
10330 (setq sig-list (verilog-signals-not-matching-regexp
10331 sig-list verilog-auto-output-ignore-regexp))
10333 (when v2k (verilog-repair-open-comma))
10335 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
10336 (verilog-insert-definition sig-list "output" indent-pt v2k)
10337 (verilog-modi-cache-add-outputs modi sig-list)
10338 (verilog-insert-indent "// End of automatics\n"))
10339 (when v2k (verilog-repair-close-comma)))))
10341 (defun verilog-auto-output-every ()
10342 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
10343 Make output statements for any signals that aren't primary inputs or
10344 outputs already. This makes every signal in the design a output. This is
10345 useful to get Synopsys to preserve every signal in the design, since it
10346 won't optimize away the outputs.
10350 module ExampOutputEvery (o,i,tempa,tempb);
10353 /*AUTOOUTPUTEVERY*/
10355 wire tempb = tempa;
10359 Typing \\[verilog-auto] will make this into:
10361 module ExampOutputEvery (o,i,tempa,tempb);
10364 /*AUTOOUTPUTEVERY*/
10365 // Beginning of automatic outputs (every signal)
10368 // End of automatics
10370 wire tempb = tempa;
10374 ;;Point must be at insertion point
10375 (let* ((indent-pt (current-indentation))
10376 (v2k (verilog-in-paren))
10377 (modi (verilog-modi-current))
10378 (moddecls (verilog-modi-get-decls modi))
10379 (sig-list (verilog-signals-combine-bus
10380 (verilog-signals-not-in
10381 (verilog-decls-get-signals moddecls)
10382 (verilog-decls-get-ports moddecls)))))
10384 (when v2k (verilog-repair-open-comma))
10386 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
10387 (verilog-insert-definition sig-list "output" indent-pt v2k)
10388 (verilog-modi-cache-add-outputs modi sig-list)
10389 (verilog-insert-indent "// End of automatics\n"))
10390 (when v2k (verilog-repair-close-comma)))))
10392 (defun verilog-auto-input (&optional with-params)
10393 "Expand AUTOINPUT statements, as part of \\[verilog-auto].
10394 Make input statements for any input signal into an /*AUTOINST*/ that
10395 isn't declared elsewhere inside the module. This is useful for modules which
10396 only instantiate other modules.
10399 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
10401 If placed inside the parenthesis of a module declaration, it creates
10402 Verilog 2001 style, else uses Verilog 1995 style.
10404 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
10405 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE).
10407 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10409 Signals matching `verilog-auto-input-ignore-regexp' are not included.
10411 An example (see `verilog-auto-inst' for what else is going on here):
10413 module ExampInput (ov,i);
10416 InstModule instName
10420 Typing \\[verilog-auto] will make this into:
10422 module ExampInput (ov,i);
10425 // Beginning of automatic inputs (from unused autoinst inputs)
10426 input i; // From inst of inst.v
10427 // End of automatics
10428 InstModule instName
10436 You may also provide an optional regular expression, in which case only
10437 signals matching the regular expression will be included. For example the
10438 same expansion will result from only extracting inputs starting with i:
10440 /*AUTOINPUT(\"^i\")*/"
10442 (let* ((indent-pt (current-indentation))
10443 (regexp (and with-params
10444 (nth 0 (verilog-read-auto-params 1))))
10445 (v2k (verilog-in-paren))
10446 (modi (verilog-modi-current))
10447 (moddecls (verilog-modi-get-decls modi))
10448 (modsubdecls (verilog-modi-get-sub-decls modi))
10449 (sig-list (verilog-signals-not-in
10450 (verilog-subdecls-get-inputs modsubdecls)
10451 (append (verilog-decls-get-inputs moddecls)
10452 (verilog-decls-get-inouts moddecls)
10453 (verilog-decls-get-wires moddecls)
10454 (verilog-decls-get-regs moddecls)
10455 (verilog-decls-get-consts moddecls)
10456 (verilog-decls-get-gparams moddecls)
10457 (verilog-subdecls-get-interfaced modsubdecls)
10458 (verilog-subdecls-get-outputs modsubdecls)
10459 (verilog-subdecls-get-inouts modsubdecls)))))
10461 (setq sig-list (verilog-signals-matching-regexp
10463 (setq sig-list (verilog-signals-not-matching-regexp
10464 sig-list verilog-auto-input-ignore-regexp))
10466 (when v2k (verilog-repair-open-comma))
10468 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
10469 (verilog-insert-definition sig-list "input" indent-pt v2k)
10470 (verilog-modi-cache-add-inputs modi sig-list)
10471 (verilog-insert-indent "// End of automatics\n"))
10472 (when v2k (verilog-repair-close-comma)))))
10474 (defun verilog-auto-inout (&optional with-params)
10475 "Expand AUTOINOUT statements, as part of \\[verilog-auto].
10476 Make inout statements for any inout signal in an /*AUTOINST*/ that
10477 isn't declared elsewhere inside the module.
10480 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
10482 If placed inside the parenthesis of a module declaration, it creates
10483 Verilog 2001 style, else uses Verilog 1995 style.
10485 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
10486 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE).
10488 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10490 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
10492 An example (see `verilog-auto-inst' for what else is going on here):
10494 module ExampInout (ov,i);
10497 InstModule instName
10501 Typing \\[verilog-auto] will make this into:
10503 module ExampInout (ov,i);
10506 // Beginning of automatic inouts (from unused autoinst inouts)
10507 inout [31:0] ov; // From inst of inst.v
10508 // End of automatics
10509 InstModule instName
10517 You may also provide an optional regular expression, in which case only
10518 signals matching the regular expression will be included. For example the
10519 same expansion will result from only extracting inouts starting with i:
10521 /*AUTOINOUT(\"^i\")*/"
10523 ;; Point must be at insertion point.
10524 (let* ((indent-pt (current-indentation))
10525 (regexp (and with-params
10526 (nth 0 (verilog-read-auto-params 1))))
10527 (v2k (verilog-in-paren))
10528 (modi (verilog-modi-current))
10529 (moddecls (verilog-modi-get-decls modi))
10530 (modsubdecls (verilog-modi-get-sub-decls modi))
10531 (sig-list (verilog-signals-not-in
10532 (verilog-subdecls-get-inouts modsubdecls)
10533 (append (verilog-decls-get-outputs moddecls)
10534 (verilog-decls-get-inouts moddecls)
10535 (verilog-decls-get-inputs moddecls)
10536 (verilog-subdecls-get-inputs modsubdecls)
10537 (verilog-subdecls-get-outputs modsubdecls)))))
10539 (setq sig-list (verilog-signals-matching-regexp
10541 (setq sig-list (verilog-signals-not-matching-regexp
10542 sig-list verilog-auto-inout-ignore-regexp))
10544 (when v2k (verilog-repair-open-comma))
10546 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
10547 (verilog-insert-definition sig-list "inout" indent-pt v2k)
10548 (verilog-modi-cache-add-inouts modi sig-list)
10549 (verilog-insert-indent "// End of automatics\n"))
10550 (when v2k (verilog-repair-close-comma)))))
10552 (defun verilog-auto-inout-module (&optional complement)
10553 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
10554 Take input/output/inout statements from the specified module and insert
10555 into the current module. This is useful for making null templates and
10556 shell modules which need to have identical I/O with another module.
10557 Any I/O which are already defined in this module will not be redefined.
10558 For the complement of this function, see `verilog-auto-inout-comp'.
10561 If placed inside the parenthesis of a module declaration, it creates
10562 Verilog 2001 style, else uses Verilog 1995 style.
10564 Concatenation and outputting partial busses is not supported.
10566 Module names must be resolvable to filenames. See `verilog-auto-inst'.
10568 Signals are not inserted in the same order as in the original module,
10569 though they will appear to be in the same order to a AUTOINST
10570 instantiating either module.
10574 module ExampShell (/*AUTOARG*/);
10575 /*AUTOINOUTMODULE(\"ExampMain\")*/
10578 module ExampMain (i,o,io);
10584 Typing \\[verilog-auto] will make this into:
10586 module ExampShell (/*AUTOARG*/i,o,io);
10587 /*AUTOINOUTMODULE(\"ExampMain\")*/
10588 // Beginning of automatic in/out/inouts (from specific module)
10592 // End of automatics
10595 You may also provide an optional regular expression, in which case only
10596 signals matching the regular expression will be included. For example the
10597 same expansion will result from only extracting signals starting with i:
10599 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
10601 You may also provide an optional second regular expression, in
10602 which case only signals which have that pin direction and data
10603 type will be included. This matches against everything before
10604 the signal name in the declaration, for example against
10605 \"input\" (single bit), \"output logic\" (direction and type) or
10606 \"output [1:0]\" (direction and implicit type). You also
10607 probably want to skip spaces in your regexp.
10609 For example, the below will result in matching the output \"o\"
10610 against the previous example's module:
10612 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/"
10614 (let* ((params (verilog-read-auto-params 1 3))
10615 (submod (nth 0 params))
10616 (regexp (nth 1 params))
10617 (direction-re (nth 2 params))
10619 ;; Lookup position, etc of co-module
10620 ;; Note this may raise an error
10621 (when (setq submodi (verilog-modi-lookup submod t))
10622 (let* ((indent-pt (current-indentation))
10623 (v2k (verilog-in-paren))
10624 (modi (verilog-modi-current))
10625 (moddecls (verilog-modi-get-decls modi))
10626 (submoddecls (verilog-modi-get-decls submodi))
10627 (sig-list-i (verilog-signals-not-in
10629 (verilog-decls-get-outputs submoddecls)
10630 (verilog-decls-get-inputs submoddecls))
10631 (append (verilog-decls-get-inputs moddecls))))
10632 (sig-list-o (verilog-signals-not-in
10634 (verilog-decls-get-inputs submoddecls)
10635 (verilog-decls-get-outputs submoddecls))
10636 (append (verilog-decls-get-outputs moddecls))))
10637 (sig-list-io (verilog-signals-not-in
10638 (verilog-decls-get-inouts submoddecls)
10639 (append (verilog-decls-get-inouts moddecls))))
10640 (sig-list-if (verilog-signals-not-in
10641 (verilog-decls-get-interfaces submoddecls)
10642 (append (verilog-decls-get-interfaces moddecls)))))
10644 (setq sig-list-i (verilog-signals-matching-dir-re
10645 (verilog-signals-matching-regexp sig-list-i regexp)
10646 "input" direction-re)
10647 sig-list-o (verilog-signals-matching-dir-re
10648 (verilog-signals-matching-regexp sig-list-o regexp)
10649 "output" direction-re)
10650 sig-list-io (verilog-signals-matching-dir-re
10651 (verilog-signals-matching-regexp sig-list-io regexp)
10652 "inout" direction-re)
10653 sig-list-if (verilog-signals-matching-dir-re
10654 (verilog-signals-matching-regexp sig-list-if regexp)
10655 "interface" direction-re))
10656 (when v2k (verilog-repair-open-comma))
10657 (when (or sig-list-i sig-list-o sig-list-io)
10658 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
10659 ;; Don't sort them so a upper AUTOINST will match the main module
10660 (verilog-insert-definition sig-list-o "output" indent-pt v2k t)
10661 (verilog-insert-definition sig-list-io "inout" indent-pt v2k t)
10662 (verilog-insert-definition sig-list-i "input" indent-pt v2k t)
10663 (verilog-insert-definition sig-list-if "interface" indent-pt v2k t)
10664 (verilog-modi-cache-add-inputs modi sig-list-i)
10665 (verilog-modi-cache-add-outputs modi sig-list-o)
10666 (verilog-modi-cache-add-inouts modi sig-list-io)
10667 (verilog-insert-indent "// End of automatics\n"))
10668 (when v2k (verilog-repair-close-comma)))))))
10670 (defun verilog-auto-inout-comp ()
10671 "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
10672 Take input/output/inout statements from the specified module and
10673 insert the inverse into the current module (inputs become outputs
10674 and vice-versa.) This is useful for making test and stimulus
10675 modules which need to have complementing I/O with another module.
10676 Any I/O which are already defined in this module will not be
10677 redefined. For the complement of this function, see
10678 `verilog-auto-inout-module'.
10681 If placed inside the parenthesis of a module declaration, it creates
10682 Verilog 2001 style, else uses Verilog 1995 style.
10684 Concatenation and outputting partial busses is not supported.
10686 Module names must be resolvable to filenames. See `verilog-auto-inst'.
10688 Signals are not inserted in the same order as in the original module,
10689 though they will appear to be in the same order to a AUTOINST
10690 instantiating either module.
10694 module ExampShell (/*AUTOARG*/);
10695 /*AUTOINOUTCOMP(\"ExampMain\")*/
10698 module ExampMain (i,o,io);
10704 Typing \\[verilog-auto] will make this into:
10706 module ExampShell (/*AUTOARG*/i,o,io);
10707 /*AUTOINOUTCOMP(\"ExampMain\")*/
10708 // Beginning of automatic in/out/inouts (from specific module)
10712 // End of automatics
10715 You may also provide an optional regular expression, in which case only
10716 signals matching the regular expression will be included. For example the
10717 same expansion will result from only extracting signals starting with i:
10719 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
10720 (verilog-auto-inout-module t))
10722 (defun verilog-auto-insert-lisp ()
10723 "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
10724 The Lisp code provided is called, and the Lisp code calls
10725 `insert` to insert text into the current file beginning on the
10726 line after the AUTOINSERTLISP.
10728 See also AUTO_LISP, which takes a Lisp expression and evaluates
10729 it during `verilog-auto-inst' but does not insert any text.
10733 module ExampInsertLisp;
10734 /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
10737 // For this example we declare the function in the
10738 // module's file itself. Often you'd define it instead
10739 // in a site-start.el or .emacs file.
10743 (defun my-verilog-insert-hello (who)
10744 (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
10748 Typing \\[verilog-auto] will call my-verilog-insert-hello and
10749 expand the above into:
10751 // Beginning of automatic insert lisp
10752 initial $write(\"hello world\");
10753 // End of automatics
10755 You can also call an external program and insert the returned
10758 /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
10759 // Beginning of automatic insert lisp
10761 // End of automatics"
10763 ;; Point is at end of /*AUTO...*/
10764 (let* ((indent-pt (current-indentation))
10765 (cmd-end-pt (save-excursion (search-backward ")")
10767 (point))) ;; Closing paren
10768 (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
10770 (point))) ;; Beginning paren
10771 (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
10773 ;; Some commands don't move point (like insert-file) so we always
10774 ;; add the begin/end comments, then delete it if not needed
10775 (verilog-insert-indent "// Beginning of automatic insert lisp\n")
10776 (verilog-insert-indent "// End of automatics\n")
10780 (setq verilog-scan-cache-tick nil) ;; Clear cache; inserted unknown text
10781 (verilog-delete-empty-auto-pair))))
10783 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
10784 "Return list of signals for current AUTOSENSE block."
10785 (let* ((sigss (verilog-read-always-signals))
10786 (sig-list (verilog-signals-not-params
10787 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
10788 (append (and (not verilog-auto-sense-include-inputs)
10789 (verilog-alw-get-outputs sigss))
10790 (verilog-alw-get-temps sigss)
10791 (verilog-decls-get-consts moddecls)
10792 (verilog-decls-get-gparams moddecls)
10796 (defun verilog-auto-sense ()
10797 "Expand AUTOSENSE statements, as part of \\[verilog-auto].
10798 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
10799 with one automatically derived from all inputs declared in the always
10800 statement. Signals that are generated within the same always block are NOT
10801 placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
10802 Long lines are split based on the `fill-column', see \\[set-fill-column].
10805 Verilog does not allow memories (multidimensional arrays) in sensitivity
10806 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
10809 AUTOSENSE cannot always determine if a `define is a constant or a signal
10810 (it could be in a include file for example). If a `define or other signal
10811 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
10812 declaration anywhere in the module (parenthesis are required):
10814 /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */
10816 Better yet, use a parameter, which will be understood to be constant
10820 If AUTOSENSE makes a mistake, please report it. (First try putting
10821 a begin/end after your always!) As a workaround, if a signal that
10822 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
10823 If a signal should be in the sensitivity list wasn't, placing it before
10824 the /*AUTOSENSE*/ comment will prevent it from being deleted when the
10825 autos are updated (or added if it occurs there already).
10829 always @ (/*AS*/) begin
10830 /* AUTO_CONSTANT (`constant) */
10831 outin = ina | inb | `constant;
10835 Typing \\[verilog-auto] will make this into:
10837 always @ (/*AS*/ina or inb) begin
10838 /* AUTO_CONSTANT (`constant) */
10839 outin = ina | inb | `constant;
10843 Note in Verilog 2001, you can often get the same result from the new @*
10844 operator. (This was added to the language in part due to AUTOSENSE!)
10847 outin = ina | inb | `constant;
10852 (let* ((start-pt (save-excursion
10853 (verilog-re-search-backward "(" nil t)
10855 (indent-pt (save-excursion
10856 (or (and (goto-char start-pt) (1+ (current-column)))
10857 (current-indentation))))
10858 (modi (verilog-modi-current))
10859 (moddecls (verilog-modi-get-decls modi))
10860 (sig-memories (verilog-signals-memory
10862 (verilog-decls-get-regs moddecls)
10863 (verilog-decls-get-wires moddecls))))
10864 sig-list not-first presense-sigs)
10865 ;; Read signals in always, eliminate outputs from sense list
10866 (setq presense-sigs (verilog-signals-from-signame
10868 (verilog-read-signals start-pt (point)))))
10869 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
10871 (let ((tlen (length sig-list)))
10872 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
10873 (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
10874 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/"
10875 (save-excursion (goto-char (point))
10876 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t)
10877 (verilog-re-search-backward "\\s-" start-pt t)
10878 (while (looking-at "\\s-`endif")
10879 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t)
10880 (verilog-re-search-backward "\\s-" start-pt t))
10881 (not (looking-at "\\s-or\\b"))))
10882 (setq not-first t))
10883 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
10885 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
10887 (indent-to indent-pt)
10888 (if not-first (insert "or ")))
10889 (not-first (insert " or ")))
10890 (insert (verilog-sig-name (car sig-list)))
10891 (setq sig-list (cdr sig-list)
10894 (defun verilog-auto-reset ()
10895 "Expand AUTORESET statements, as part of \\[verilog-auto].
10896 Replace the /*AUTORESET*/ comment with code to initialize all
10897 registers set elsewhere in the always block.
10900 AUTORESET will not clear memories.
10902 AUTORESET uses <= if there are any <= assignments in the block,
10905 /*AUTORESET*/ presumes that any signals mentioned between the previous
10906 begin/case/if statement and the AUTORESET comment are being reset manually
10907 and should not be automatically reset. This includes omitting any signals
10908 used on the right hand side of assignments.
10910 By default, AUTORESET will include the width of the signal in the autos,
10911 this is a recent change. To control this behavior, see
10912 `verilog-auto-reset-widths'.
10914 AUTORESET ties signals to deasserted, which is presumed to be zero.
10915 Signals that match `verilog-active-low-regexp' will be deasserted by tieing
10920 always @(posedge clk or negedge reset_l) begin
10921 if (!reset_l) begin
10932 Typing \\[verilog-auto] will make this into:
10934 always @(posedge core_clk or negedge reset_l) begin
10935 if (!reset_l) begin
10938 // Beginning of autoreset for uninitialized flops
10941 // End of automatics
10953 (let* ((indent-pt (current-indentation))
10954 (modi (verilog-modi-current))
10955 (moddecls (verilog-modi-get-decls modi))
10956 (all-list (verilog-decls-get-signals moddecls))
10957 sigss sig-list prereset-sigs assignment-str)
10958 ;; Read signals in always, eliminate outputs from reset list
10959 (setq prereset-sigs (verilog-signals-from-signame
10961 (verilog-read-signals
10963 (verilog-re-search-backward "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t)
10967 (verilog-re-search-backward "@" nil t)
10968 (setq sigss (verilog-read-always-signals)))
10969 (setq assignment-str (if (verilog-alw-get-uses-delayed sigss)
10970 (concat " <= " verilog-assignment-delay)
10972 (setq sig-list (verilog-signals-not-in (verilog-alw-get-outputs sigss)
10974 (verilog-alw-get-temps sigss)
10976 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
10979 (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
10980 (indent-to indent-pt)
10982 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths
10984 (insert (verilog-sig-name sig)
10986 (verilog-sig-tieoff sig (not verilog-auto-reset-widths))
10988 (indent-to indent-pt)
10989 (setq sig-list (cdr sig-list))))
10990 (verilog-insert "// End of automatics")))))
10992 (defun verilog-auto-tieoff ()
10993 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
10994 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
10995 signals to deasserted.
10997 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
10998 input/output list as another module, but no internals. Specifically, it
10999 finds all outputs in the module, and if that input is not otherwise declared
11000 as a register or wire, creates a tieoff.
11002 AUTORESET ties signals to deasserted, which is presumed to be zero.
11003 Signals that match `verilog-active-low-regexp' will be deasserted by tieing
11006 You can add signals you do not want included in AUTOTIEOFF with
11007 `verilog-auto-tieoff-ignore-regexp'.
11009 An example of making a stub for another module:
11011 module ExampStub (/*AUTOINST*/);
11012 /*AUTOINOUTMODULE(\"Foo\")*/
11014 // verilator lint_off UNUSED
11015 wire _unused_ok = &{1'b0,
11018 // verilator lint_on UNUSED
11021 Typing \\[verilog-auto] will make this into:
11023 module ExampStub (/*AUTOINST*/...);
11024 /*AUTOINOUTMODULE(\"Foo\")*/
11025 // Beginning of autotieoff
11027 // End of automatics
11030 // Beginning of autotieoff
11031 wire [2:0] foo = 3'b0;
11032 // End of automatics
11038 (let* ((indent-pt (current-indentation))
11039 (modi (verilog-modi-current))
11040 (moddecls (verilog-modi-get-decls modi))
11041 (modsubdecls (verilog-modi-get-sub-decls modi))
11042 (sig-list (verilog-signals-not-in
11043 (verilog-decls-get-outputs moddecls)
11044 (append (verilog-decls-get-wires moddecls)
11045 (verilog-decls-get-regs moddecls)
11046 (verilog-decls-get-assigns moddecls)
11047 (verilog-decls-get-consts moddecls)
11048 (verilog-decls-get-gparams moddecls)
11049 (verilog-subdecls-get-interfaced modsubdecls)
11050 (verilog-subdecls-get-outputs modsubdecls)
11051 (verilog-subdecls-get-inouts modsubdecls)))))
11052 (setq sig-list (verilog-signals-not-matching-regexp
11053 sig-list verilog-auto-tieoff-ignore-regexp))
11056 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
11057 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
11058 (verilog-modi-cache-add-wires modi sig-list) ; Before we trash list
11060 (let ((sig (car sig-list)))
11061 (verilog-insert-one-definition sig "wire" indent-pt)
11062 (indent-to (max 48 (+ indent-pt 40)))
11063 (insert "= " (verilog-sig-tieoff sig)
11065 (setq sig-list (cdr sig-list))))
11066 (verilog-insert-indent "// End of automatics\n")))))
11068 (defun verilog-auto-unused ()
11069 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
11070 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
11071 input and inout signals.
11073 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
11074 input/output list as another module, but no internals. Specifically, it
11075 finds all inputs and inouts in the module, and if that input is not otherwise
11076 used, adds it to a comma separated list.
11078 The comma separated list is intended to be used to create a _unused_ok
11079 signal. Using the exact name \"_unused_ok\" for name of the temporary
11080 signal is recommended as it will insure maximum forward compatibility, it
11081 also makes lint warnings easy to understand; ignore any unused warnings
11082 with \"unused\" in the signal name.
11084 To reduce simulation time, the _unused_ok signal should be forced to a
11085 constant to prevent wiggling. The easiest thing to do is use a
11086 reduction-and with 1'b0 as shown.
11088 This way all unused signals are in one place, making it convenient to add
11089 your tool's specific pragmas around the assignment to disable any unused
11092 You can add signals you do not want included in AUTOUNUSED with
11093 `verilog-auto-unused-ignore-regexp'.
11095 An example of making a stub for another module:
11097 module ExampStub (/*AUTOINST*/);
11098 /*AUTOINOUTMODULE(\"Examp\")*/
11100 // verilator lint_off UNUSED
11101 wire _unused_ok = &{1'b0,
11104 // verilator lint_on UNUSED
11107 Typing \\[verilog-auto] will make this into:
11110 // verilator lint_off UNUSED
11111 wire _unused_ok = &{1'b0,
11113 // Beginning of automatics
11117 // End of automatics
11119 // verilator lint_on UNUSED
11124 (let* ((indent-pt (progn (search-backward "/*") (current-column)))
11125 (modi (verilog-modi-current))
11126 (moddecls (verilog-modi-get-decls modi))
11127 (modsubdecls (verilog-modi-get-sub-decls modi))
11128 (sig-list (verilog-signals-not-in
11129 (append (verilog-decls-get-inputs moddecls)
11130 (verilog-decls-get-inouts moddecls))
11131 (append (verilog-subdecls-get-inputs modsubdecls)
11132 (verilog-subdecls-get-inouts modsubdecls)))))
11133 (setq sig-list (verilog-signals-not-matching-regexp
11134 sig-list verilog-auto-unused-ignore-regexp))
11137 (verilog-insert-indent "// Beginning of automatic unused inputs\n")
11138 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
11140 (let ((sig (car sig-list)))
11141 (indent-to indent-pt)
11142 (insert (verilog-sig-name sig) ",\n")
11143 (setq sig-list (cdr sig-list))))
11144 (verilog-insert-indent "// End of automatics\n")))))
11146 (defun verilog-enum-ascii (signm elim-regexp)
11147 "Convert an enum name SIGNM to an ascii string for insertion.
11148 Remove user provided prefix ELIM-REGEXP."
11149 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
11150 (let ((case-fold-search t))
11151 ;; All upper becomes all lower for readability
11152 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
11154 (defun verilog-auto-ascii-enum ()
11155 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
11156 Create a register to contain the ASCII decode of a enumerated signal type.
11157 This will allow trace viewers to show the ASCII name of states.
11159 First, parameters are built into a enumeration using the synopsys enum
11160 comment. The comment must be between the keyword and the symbol.
11161 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
11163 Next, registers which that enum applies to are also tagged with the same
11164 enum. Synopsys also suggests labeling state vectors, but `verilog-mode'
11167 Finally, a AUTOASCIIENUM command is used.
11169 The first parameter is the name of the signal to be decoded.
11170 If and only if the first parameter width is 2^(number of states
11171 in enum) and does NOT match the width of the enum, the signal
11172 is assumed to be a one hot decode. Otherwise, it's a normal
11173 encoded state vector.
11175 The second parameter is the name to store the ASCII code into. For the
11176 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
11177 a signal that is just for simulation, and the magic characters _ascii
11178 tell viewers like Dinotrace to display in ASCII format.
11180 The final optional parameter is a string which will be removed from the
11185 //== State enumeration
11186 parameter [2:0] // synopsys enum state_info
11190 //== State variables
11191 reg [2:0] /* synopsys enum state_info */
11192 state_r; /* synopsys state_vector state_r */
11193 reg [2:0] /* synopsys enum state_info */
11196 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
11198 Typing \\[verilog-auto] will make this into:
11200 ... same front matter ...
11202 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
11203 // Beginning of automatic ASCII enum decoding
11204 reg [39:0] state_ascii_r; // Decode of state_r
11205 always @(state_r) begin
11207 SM_IDLE: state_ascii_r = \"idle \";
11208 SM_SEND: state_ascii_r = \"send \";
11209 SM_WAIT1: state_ascii_r = \"wait1\";
11210 default: state_ascii_r = \"%Erro\";
11213 // End of automatics"
11215 (let* ((params (verilog-read-auto-params 2 3))
11216 (undecode-name (nth 0 params))
11217 (ascii-name (nth 1 params))
11218 (elim-regexp (nth 2 params))
11220 (indent-pt (current-indentation))
11221 (modi (verilog-modi-current))
11222 (moddecls (verilog-modi-get-decls modi))
11224 (sig-list-consts (append (verilog-decls-get-consts moddecls)
11225 (verilog-decls-get-gparams moddecls)))
11226 (sig-list-all (append (verilog-decls-get-regs moddecls)
11227 (verilog-decls-get-outputs moddecls)
11228 (verilog-decls-get-inouts moddecls)
11229 (verilog-decls-get-inputs moddecls)
11230 (verilog-decls-get-wires moddecls)))
11232 (undecode-sig (or (assoc undecode-name sig-list-all)
11233 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
11234 (undecode-enum (or (verilog-sig-enum undecode-sig)
11235 (error "%s: Signal %s does not have a enum tag" (verilog-point-text) undecode-name)))
11237 (enum-sigs (verilog-signals-not-in
11238 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
11239 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))
11242 (one-hot (and ;; width(enum) != width(sig)
11243 (or (not (verilog-sig-bits (car enum-sigs)))
11244 (not (equal (verilog-sig-width (car enum-sigs))
11245 (verilog-sig-width undecode-sig))))
11246 ;; count(enums) == width(sig)
11247 (equal (number-to-string (length enum-sigs))
11248 (verilog-sig-width undecode-sig))))
11252 ;; Find number of ascii chars needed
11253 (let ((tmp-sigs enum-sigs))
11255 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
11256 ascii-chars (max ascii-chars (length (verilog-enum-ascii
11257 (verilog-sig-name (car tmp-sigs))
11259 tmp-sigs (cdr tmp-sigs))))
11262 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
11263 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
11264 (concat "Decode of " undecode-name) nil nil))))
11265 (verilog-insert-definition decode-sig-list "reg" indent-pt nil)
11266 (verilog-modi-cache-add-regs modi decode-sig-list))
11268 (verilog-insert-indent "always @(" undecode-name ") begin\n")
11269 (setq indent-pt (+ indent-pt verilog-indent-level))
11270 (indent-to indent-pt)
11271 (insert "case ({" undecode-name "})\n")
11272 (setq indent-pt (+ indent-pt verilog-case-indent))
11274 (let ((tmp-sigs enum-sigs)
11275 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
11276 (+ (if one-hot 9 1) (max 8 enum-chars))
11277 ascii-name ascii-chars))
11278 (errname (substring "%Error" 0 (min 6 ascii-chars))))
11280 (verilog-insert-indent
11283 (concat (if one-hot "(")
11284 (if one-hot (verilog-sig-width undecode-sig))
11285 ;; We use a shift instead of var[index]
11286 ;; so that a non-one hot value will show as error.
11287 (if one-hot "'b1<<")
11288 (verilog-sig-name (car tmp-sigs))
11289 (if one-hot ")") ":")
11290 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
11292 (setq tmp-sigs (cdr tmp-sigs)))
11293 (verilog-insert-indent (format chrfmt "default:" errname)))
11295 (setq indent-pt (- indent-pt verilog-case-indent))
11296 (verilog-insert-indent "endcase\n")
11297 (setq indent-pt (- indent-pt verilog-indent-level))
11298 (verilog-insert-indent "end\n"
11299 "// End of automatics\n"))))
11301 (defun verilog-auto-templated-rel ()
11302 "Replace Templated relative line numbers with absolute line numbers.
11303 Internal use only. This hacks around the line numbers in AUTOINST Templates
11304 being different from the final output's line numbering."
11305 (let ((templateno 0) (template-line (list 0)) (buf-line 1))
11306 ;; Find line number each template is on
11307 ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
11308 (goto-char (point-min))
11309 (while (not (eobp))
11310 (when (looking-at ".*AUTO_TEMPLATE")
11311 (setq templateno (1+ templateno))
11312 (setq template-line (cons buf-line template-line)))
11313 (setq buf-line (1+ buf-line))
11315 (setq template-line (nreverse template-line))
11316 ;; Replace T# L# with absolute line number
11317 (goto-char (point-min))
11318 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
11320 (concat " Templated "
11321 (int-to-string (+ (nth (string-to-number (match-string 1))
11323 (string-to-number (match-string 2)))))
11331 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing a arg
11332 "Expand AUTO statements.
11333 Look for any /*AUTO...*/ commands in the code, as used in
11334 instantiations or argument headers. Update the list of signals
11335 following the /*AUTO...*/ command.
11337 Use \\[verilog-delete-auto] to remove the AUTOs.
11339 Use \\[verilog-inject-auto] to insert AUTOs for the first time.
11341 Use \\[verilog-faq] for a pointer to frequently asked questions.
11343 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
11344 called before and after this function, respectively.
11347 module ModuleName (/*AUTOARG*/);
11352 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
11354 You can also update the AUTOs from the shell using:
11355 emacs --batch <filenames.v> -f verilog-batch-auto
11356 Or fix indentation with:
11357 emacs --batch <filenames.v> -f verilog-batch-indent
11358 Likewise, you can delete or inject AUTOs with:
11359 emacs --batch <filenames.v> -f verilog-batch-delete-auto
11360 emacs --batch <filenames.v> -f verilog-batch-inject-auto
11362 Using \\[describe-function], see also:
11363 `verilog-auto-arg' for AUTOARG module instantiations
11364 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
11365 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
11366 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
11367 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
11368 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
11369 `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
11370 `verilog-auto-inst' for AUTOINST instantiation pins
11371 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
11372 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
11373 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
11374 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
11375 `verilog-auto-reg' for AUTOREG registers
11376 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
11377 `verilog-auto-reset' for AUTORESET flop resets
11378 `verilog-auto-sense' for AUTOSENSE always sensitivity lists
11379 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
11380 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
11381 `verilog-auto-wire' for AUTOWIRE instantiation wires
11383 `verilog-read-defines' for reading `define values
11384 `verilog-read-includes' for reading `includes
11386 If you have bugs with these autos, please file an issue at
11387 URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
11388 Wilson Snyder (wsnyder@wsnyder.org)."
11390 (unless noninteractive (message "Updating AUTOs..."))
11391 (if (fboundp 'dinotrace-unannotate-all)
11392 (dinotrace-unannotate-all))
11393 (let ((oldbuf (if (not (buffer-modified-p))
11395 ;; Before version 20, match-string with font-lock returns a
11396 ;; vector that is not equal to the string. IE if on "input"
11397 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
11398 (fontlocked (when (and (boundp 'font-lock-mode)
11402 ;; Cache directories; we don't write new files, so can't change
11403 (verilog-dir-cache-preserving t)
11404 ;; Cache current module
11405 (verilog-modi-cache-current-enable t)
11406 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
11407 verilog-modi-cache-current)
11409 ;; Disable change hooks for speed
11410 ;; This let can't be part of above let; must restore
11411 ;; after-change-functions before font-lock resumes
11412 (verilog-save-no-change-functions
11413 (verilog-save-scan-cache
11415 ;; If we're not in verilog-mode, change syntax table so parsing works right
11416 (unless (eq major-mode `verilog-mode) (verilog-mode))
11417 ;; Allow user to customize
11418 (run-hooks 'verilog-before-auto-hook)
11419 ;; Try to save the user from needing to revert-file to reread file local-variables
11420 (verilog-auto-reeval-locals)
11421 (verilog-read-auto-lisp-present)
11422 (verilog-read-auto-lisp (point-min) (point-max))
11423 (verilog-getopt-flags)
11424 ;; From here on out, we can cache anything we read from disk
11425 (verilog-preserve-dir-cache
11426 ;; These two may seem obvious to do always, but on large includes it can be way too slow
11427 (when verilog-auto-read-includes
11428 (verilog-read-includes)
11429 (verilog-read-defines nil nil t))
11430 ;; This particular ordering is important
11431 ;; INST: Lower modules correct, no internal dependencies, FIRST
11432 (verilog-preserve-modi-cache
11433 ;; Clear existing autos else we'll be screwed by existing ones
11434 (verilog-delete-auto)
11435 ;; Injection if appropriate
11437 (verilog-inject-inst)
11438 (verilog-inject-sense)
11439 (verilog-inject-arg))
11441 ;; Do user inserts first, so their code can insert AUTOs
11442 ;; We may provide a AUTOINSERTLISPLAST if another cleanup pass is needed
11443 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
11444 'verilog-auto-insert-lisp)
11445 ;; Expand instances before need the signals the instances input/output
11446 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
11447 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
11448 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
11449 ;; Doesn't matter when done, but combine it with a common changer
11450 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
11451 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
11452 ;; Must be done before autoin/out as creates a reg
11453 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM([^)]*)\\*/" 'verilog-auto-ascii-enum)
11455 ;; first in/outs from other files
11456 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE([^)]*)\\*/" 'verilog-auto-inout-module)
11457 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP([^)]*)\\*/" 'verilog-auto-inout-comp)
11458 ;; next in/outs which need previous sucked inputs first
11459 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((\"[^\"]*\")\\)\\*/"
11460 '(lambda () (verilog-auto-output t)))
11461 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\*/" 'verilog-auto-output)
11462 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((\"[^\"]*\")\\)\\*/"
11463 '(lambda () (verilog-auto-input t)))
11464 (verilog-auto-re-search-do "/\\*AUTOINPUT\\*/" 'verilog-auto-input)
11465 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((\"[^\"]*\")\\)\\*/"
11466 '(lambda () (verilog-auto-inout t)))
11467 (verilog-auto-re-search-do "/\\*AUTOINOUT\\*/" 'verilog-auto-inout)
11468 ;; Then tie off those in/outs
11469 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
11470 ;; Wires/regs must be after inputs/outputs
11471 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
11472 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
11473 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
11474 ;; outputevery needs AUTOOUTPUTs done first
11475 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\*/" 'verilog-auto-output-every)
11476 ;; After we've created all new variables
11477 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
11478 ;; Must be after all inputs outputs are generated
11479 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
11480 ;; Fix line numbers (comments only)
11481 (when verilog-auto-inst-template-numbers
11482 (verilog-auto-templated-rel))))
11484 (run-hooks 'verilog-auto-hook)
11486 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
11488 ;; If end result is same as when started, clear modified flag
11489 (cond ((and oldbuf (equal oldbuf (buffer-string)))
11490 (set-buffer-modified-p nil)
11491 (unless noninteractive (message "Updating AUTOs...done (no changes)")))
11492 (t (unless noninteractive (message "Updating AUTOs...done"))))
11493 ;; End of after-change protection
11497 ;; Restore font-lock
11498 (when fontlocked (font-lock-mode t))))))
11502 ;; Skeleton based code insertion
11504 (defvar verilog-template-map
11505 (let ((map (make-sparse-keymap)))
11506 (define-key map "a" 'verilog-sk-always)
11507 (define-key map "b" 'verilog-sk-begin)
11508 (define-key map "c" 'verilog-sk-case)
11509 (define-key map "f" 'verilog-sk-for)
11510 (define-key map "g" 'verilog-sk-generate)
11511 (define-key map "h" 'verilog-sk-header)
11512 (define-key map "i" 'verilog-sk-initial)
11513 (define-key map "j" 'verilog-sk-fork)
11514 (define-key map "m" 'verilog-sk-module)
11515 (define-key map "p" 'verilog-sk-primitive)
11516 (define-key map "r" 'verilog-sk-repeat)
11517 (define-key map "s" 'verilog-sk-specify)
11518 (define-key map "t" 'verilog-sk-task)
11519 (define-key map "w" 'verilog-sk-while)
11520 (define-key map "x" 'verilog-sk-casex)
11521 (define-key map "z" 'verilog-sk-casez)
11522 (define-key map "?" 'verilog-sk-if)
11523 (define-key map ":" 'verilog-sk-else-if)
11524 (define-key map "/" 'verilog-sk-comment)
11525 (define-key map "A" 'verilog-sk-assign)
11526 (define-key map "F" 'verilog-sk-function)
11527 (define-key map "I" 'verilog-sk-input)
11528 (define-key map "O" 'verilog-sk-output)
11529 (define-key map "S" 'verilog-sk-state-machine)
11530 (define-key map "=" 'verilog-sk-inout)
11531 (define-key map "W" 'verilog-sk-wire)
11532 (define-key map "R" 'verilog-sk-reg)
11533 (define-key map "D" 'verilog-sk-define-signal)
11535 "Keymap used in Verilog mode for smart template operations.")
11539 ;; Place the templates into Verilog Mode. They may be inserted under any key.
11540 ;; C-c C-t will be the default. If you use templates a lot, you
11541 ;; may want to consider moving the binding to another key in your .emacs
11544 ;(define-key verilog-mode-map "\C-ct" verilog-template-map)
11545 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
11547 ;;; ---- statement skeletons ------------------------------------------
11549 (define-skeleton verilog-sk-prompt-condition
11550 "Prompt for the loop condition."
11551 "[condition]: " str )
11553 (define-skeleton verilog-sk-prompt-init
11554 "Prompt for the loop init statement."
11555 "[initial statement]: " str )
11557 (define-skeleton verilog-sk-prompt-inc
11558 "Prompt for the loop increment statement."
11559 "[increment statement]: " str )
11561 (define-skeleton verilog-sk-prompt-name
11562 "Prompt for the name of something."
11565 (define-skeleton verilog-sk-prompt-clock
11566 "Prompt for the name of something."
11567 "name and edge of clock(s): " str)
11569 (defvar verilog-sk-reset nil)
11570 (defun verilog-sk-prompt-reset ()
11571 "Prompt for the name of a state machine reset."
11572 (setq verilog-sk-reset (read-string "name of reset: " "rst")))
11575 (define-skeleton verilog-sk-prompt-state-selector
11576 "Prompt for the name of a state machine selector."
11577 "name of selector (eg {a,b,c,d}): " str )
11579 (define-skeleton verilog-sk-prompt-output
11580 "Prompt for the name of something."
11583 (define-skeleton verilog-sk-prompt-msb
11584 "Prompt for least significant bit specification."
11585 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
11587 (define-skeleton verilog-sk-prompt-lsb
11588 "Prompt for least significant bit specification."
11591 (defvar verilog-sk-p nil)
11592 (define-skeleton verilog-sk-prompt-width
11593 "Prompt for a width specification."
11596 (setq verilog-sk-p (point))
11597 (verilog-sk-prompt-msb)
11598 (if (> (point) verilog-sk-p) "] " " ")))
11600 (defun verilog-sk-header ()
11601 "Insert a descriptive header at the top of the file.
11602 See also `verilog-header' for an alternative format."
11605 (goto-char (point-min))
11606 (verilog-sk-header-tmpl)))
11608 (define-skeleton verilog-sk-header-tmpl
11609 "Insert a comment block containing the module title, author, etc."
11611 "// -*- Mode: Verilog -*-"
11612 "\n// Filename : " (buffer-name)
11613 "\n// Description : " str
11614 "\n// Author : " (user-full-name)
11615 "\n// Created On : " (current-time-string)
11616 "\n// Last Modified By: " (user-full-name)
11617 "\n// Last Modified On: " (current-time-string)
11618 "\n// Update Count : 0"
11619 "\n// Status : Unknown, Use with caution!"
11622 (define-skeleton verilog-sk-module
11623 "Insert a module definition."
11625 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
11627 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
11629 (define-skeleton verilog-sk-primitive
11630 "Insert a task definition."
11632 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
11634 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
11636 (define-skeleton verilog-sk-task
11637 "Insert a task definition."
11639 > "task " '(verilog-sk-prompt-name) & ?; \n
11643 > (- verilog-indent-level-behavioral) "end" \n
11644 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
11646 (define-skeleton verilog-sk-function
11647 "Insert a function definition."
11649 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n
11653 > (- verilog-indent-level-behavioral) "end" \n
11654 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
11656 (define-skeleton verilog-sk-always
11657 "Insert always block. Uses the minibuffer to prompt
11658 for sensitivity list."
11660 > "always @ ( /*AUTOSENSE*/ ) begin\n"
11662 > (- verilog-indent-level-behavioral) "end" \n >
11665 (define-skeleton verilog-sk-initial
11666 "Insert an initial block."
11668 > "initial begin\n"
11670 > (- verilog-indent-level-behavioral) "end" \n > )
11672 (define-skeleton verilog-sk-specify
11673 "Insert specify block. "
11677 > (- verilog-indent-level-behavioral) "endspecify" \n > )
11679 (define-skeleton verilog-sk-generate
11680 "Insert generate block. "
11684 > (- verilog-indent-level-behavioral) "endgenerate" \n > )
11686 (define-skeleton verilog-sk-begin
11687 "Insert begin end block. Uses the minibuffer to prompt for name."
11689 > "begin" '(verilog-sk-prompt-name) \n
11691 > (- verilog-indent-level-behavioral) "end"
11694 (define-skeleton verilog-sk-fork
11695 "Insert a fork join block."
11700 > (- verilog-indent-level-behavioral) "end" \n
11703 > (- verilog-indent-level-behavioral) "end" \n
11704 > (- verilog-indent-level-behavioral) "join" \n
11708 (define-skeleton verilog-sk-case
11709 "Build skeleton case statement, prompting for the selector expression,
11710 and the case items."
11711 "[selector expression]: "
11712 > "case (" str ") " \n
11713 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
11714 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
11716 (define-skeleton verilog-sk-casex
11717 "Build skeleton casex statement, prompting for the selector expression,
11718 and the case items."
11719 "[selector expression]: "
11720 > "casex (" str ") " \n
11721 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
11722 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
11724 (define-skeleton verilog-sk-casez
11725 "Build skeleton casez statement, prompting for the selector expression,
11726 and the case items."
11727 "[selector expression]: "
11728 > "casez (" str ") " \n
11729 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
11730 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
11732 (define-skeleton verilog-sk-if
11733 "Insert a skeleton if statement."
11734 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
11736 > (- verilog-indent-level-behavioral) "end " \n )
11738 (define-skeleton verilog-sk-else-if
11739 "Insert a skeleton else if statement."
11740 > (verilog-indent-line) "else if ("
11741 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
11743 > "end" (progn (electric-verilog-terminate-line) nil))
11745 (define-skeleton verilog-sk-datadef
11746 "Common routine to get data definition."
11748 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
11750 (define-skeleton verilog-sk-input
11751 "Insert an input definition."
11753 > "input [" '(verilog-sk-datadef))
11755 (define-skeleton verilog-sk-output
11756 "Insert an output definition."
11758 > "output [" '(verilog-sk-datadef))
11760 (define-skeleton verilog-sk-inout
11761 "Insert an inout definition."
11763 > "inout [" '(verilog-sk-datadef))
11765 (defvar verilog-sk-signal nil)
11766 (define-skeleton verilog-sk-def-reg
11767 "Insert a reg definition."
11769 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations) )
11771 (defun verilog-sk-define-signal ()
11772 "Insert a definition of signal under point at top of module."
11774 (let* ((sig-re "[a-zA-Z0-9_]*")
11775 (v1 (buffer-substring
11777 (skip-chars-backward sig-re)
11780 (skip-chars-forward sig-re)
11782 (if (not (member v1 verilog-keywords))
11784 (setq verilog-sk-signal v1)
11785 (verilog-beg-of-defun)
11786 (verilog-end-of-statement)
11787 (verilog-forward-syntactic-ws)
11788 (verilog-sk-def-reg)
11789 (message "signal at point is %s" v1))
11790 (message "object at point (%s) is a keyword" v1))))
11792 (define-skeleton verilog-sk-wire
11793 "Insert a wire definition."
11795 > "wire [" '(verilog-sk-datadef))
11797 (define-skeleton verilog-sk-reg
11798 "Insert a reg definition."
11800 > "reg [" '(verilog-sk-datadef))
11802 (define-skeleton verilog-sk-assign
11803 "Insert a skeleton assign statement."
11805 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
11807 (define-skeleton verilog-sk-while
11808 "Insert a skeleton while loop statement."
11810 > "while (" '(verilog-sk-prompt-condition) ") begin" \n
11812 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
11814 (define-skeleton verilog-sk-repeat
11815 "Insert a skeleton repeat loop statement."
11817 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
11819 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
11821 (define-skeleton verilog-sk-for
11822 "Insert a skeleton while loop statement."
11825 '(verilog-sk-prompt-init) "; "
11826 '(verilog-sk-prompt-condition) "; "
11827 '(verilog-sk-prompt-inc)
11830 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
11832 (define-skeleton verilog-sk-comment
11833 "Inserts three comment lines, making a display comment."
11839 (define-skeleton verilog-sk-state-machine
11840 "Insert a state machine definition."
11841 "Name of state variable: "
11842 '(setq input "state")
11843 > "// State registers for " str | -23 \n
11844 '(setq verilog-sk-state str)
11845 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n
11848 > "// State FF for " verilog-sk-state \n
11849 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
11850 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
11851 > verilog-sk-state " = next_" verilog-sk-state ?; \n
11852 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
11854 > "// Next State Logic for " verilog-sk-state \n
11855 > "always @ ( /*AUTOSENSE*/ ) begin\n"
11856 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
11857 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
11858 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
11859 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
11863 ;; Include file loading with mouse/return event
11865 ;; idea & first impl.: M. Rouat (eldo-mode.el)
11866 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
11868 (if (featurep 'xemacs)
11869 (require 'overlay))
11871 (defconst verilog-include-file-regexp
11872 "^`include\\s-+\"\\([^\n\"]*\\)\""
11873 "Regexp that matches the include file.")
11875 (defvar verilog-mode-mouse-map
11876 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
11877 (set-keymap-parent map verilog-mode-map)
11878 ;; mouse button bindings
11879 (define-key map "\r" 'verilog-load-file-at-point)
11880 (if (featurep 'xemacs)
11881 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
11882 (define-key map [mouse-2] 'verilog-load-file-at-mouse))
11883 (if (featurep 'xemacs)
11884 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
11885 (define-key map [S-mouse-2] 'mouse-yank-at-click))
11887 "Map containing mouse bindings for `verilog-mode'.")
11890 (defun verilog-highlight-region (beg end old-len)
11891 "Colorize included files and modules in the (changed?) region.
11892 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
11893 (when (or verilog-highlight-includes
11894 verilog-highlight-modules)
11896 (save-match-data ;; A query-replace may call this function - do not disturb
11897 (verilog-save-buffer-state
11898 (verilog-save-scan-cache
11901 (setq end-point (verilog-get-end-of-line))
11903 (beginning-of-line) ; scan entire line
11904 ;; delete overlays existing on this line
11905 (let ((overlays (overlays-in (point) end-point)))
11908 (overlay-get (car overlays) 'detachable)
11909 (or (overlay-get (car overlays) 'verilog-include-file)
11910 (overlay-get (car overlays) 'verilog-inst-module)))
11911 (delete-overlay (car overlays)))
11912 (setq overlays (cdr overlays))))
11914 ;; make new include overlays
11915 (when verilog-highlight-includes
11916 (while (search-forward-regexp verilog-include-file-regexp end-point t)
11917 (goto-char (match-beginning 1))
11918 (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
11919 (overlay-put ov 'start-closed 't)
11920 (overlay-put ov 'end-closed 't)
11921 (overlay-put ov 'evaporate 't)
11922 (overlay-put ov 'verilog-include-file 't)
11923 (overlay-put ov 'mouse-face 'highlight)
11924 (overlay-put ov 'local-map verilog-mode-mouse-map))))
11926 ;; make new module overlays
11928 ;; This scanner is syntax-fragile, so don't get bent
11929 (when verilog-highlight-modules
11930 (condition-case nil
11931 (while (verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
11933 (goto-char (match-beginning 0))
11934 (unless (verilog-inside-comment-p)
11935 (verilog-read-inst-module-matcher) ;; sets match 0
11936 (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
11937 (overlay-put ov 'start-closed 't)
11938 (overlay-put ov 'end-closed 't)
11939 (overlay-put ov 'evaporate 't)
11940 (overlay-put ov 'verilog-inst-module 't)
11941 (overlay-put ov 'mouse-face 'highlight)
11942 (overlay-put ov 'local-map verilog-mode-mouse-map)))))
11945 ;; Future highlights:
11946 ;; variables - make an Occur buffer of where referenced
11947 ;; pins - make an Occur buffer of the sig in the declaration module
11950 (defun verilog-highlight-buffer ()
11951 "Colorize included files and modules across the whole buffer."
11952 ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
11954 ;; delete and remake overlays
11955 (verilog-highlight-region (point-min) (point-max) nil))
11957 ;; Deprecated, but was interactive, so we'll keep it around
11958 (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
11960 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
11961 ;; so define this function to do more or less the same as ffap-at-mouse
11962 ;; but first resolve filename...
11963 (defun verilog-load-file-at-mouse (event)
11964 "Load file under button 2 click's EVENT.
11965 Files are checked based on `verilog-library-flags'."
11967 (save-excursion ;; implement a Verilog specific ffap-at-mouse
11968 (mouse-set-point event)
11969 (verilog-load-file-at-point t)))
11971 ;; ffap isn't useable for Verilog mode. It uses library paths.
11972 ;; so define this function to do more or less the same as ffap
11973 ;; but first resolve filename...
11974 (defun verilog-load-file-at-point (&optional warn)
11975 "Load file under point.
11976 If WARN, throw warning if not found.
11977 Files are checked based on `verilog-library-flags'."
11979 (save-excursion ;; implement a Verilog specific ffap
11980 (let ((overlays (overlays-in (point) (point)))
11982 (while (and overlays (not hit))
11983 (when (overlay-get (car overlays) 'verilog-inst-module)
11984 (verilog-goto-defun-file (buffer-substring
11985 (overlay-start (car overlays))
11986 (overlay-end (car overlays))))
11988 (setq overlays (cdr overlays)))
11990 (beginning-of-line)
11991 (when (and (not hit)
11992 (looking-at verilog-include-file-regexp))
11993 (if (and (car (verilog-library-filenames
11994 (match-string 1) (buffer-file-name)))
11995 (file-readable-p (car (verilog-library-filenames
11996 (match-string 1) (buffer-file-name)))))
11997 (find-file (car (verilog-library-filenames
11998 (match-string 1) (buffer-file-name))))
12001 "File '%s' isn't readable, use shift-mouse2 to paste in this field"
12002 (match-string 1))))))))
12008 (defun verilog-faq ()
12009 "Tell the user their current version, and where to get the FAQ etc."
12011 (with-output-to-temp-buffer "*verilog-mode help*"
12012 (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
12014 (princ "For new releases, see http://www.verilog.com\n")
12016 (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
12018 (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
12021 (autoload 'reporter-submit-bug-report "reporter")
12022 (defvar reporter-prompt-for-summary-p)
12024 (defun verilog-submit-bug-report ()
12025 "Submit via mail a bug report on verilog-mode.el."
12027 (let ((reporter-prompt-for-summary-p t))
12028 (reporter-submit-bug-report
12029 "mac@verilog.com, wsnyder@wsnyder.org"
12030 (concat "verilog-mode v" verilog-mode-version)
12032 verilog-active-low-regexp
12033 verilog-align-ifelse
12034 verilog-assignment-delay
12035 verilog-auto-arg-sort
12036 verilog-auto-endcomments
12038 verilog-auto-ignore-concat
12039 verilog-auto-indent-on-newline
12040 verilog-auto-inout-ignore-regexp
12041 verilog-auto-input-ignore-regexp
12042 verilog-auto-inst-column
12043 verilog-auto-inst-dot-name
12044 verilog-auto-inst-param-value
12045 verilog-auto-inst-template-numbers
12046 verilog-auto-inst-vector
12047 verilog-auto-lineup
12048 verilog-auto-newline
12049 verilog-auto-output-ignore-regexp
12050 verilog-auto-read-includes
12051 verilog-auto-reset-widths
12052 verilog-auto-save-policy
12053 verilog-auto-sense-defines-constant
12054 verilog-auto-sense-include-inputs
12055 verilog-auto-star-expand
12056 verilog-auto-star-save
12057 verilog-auto-unused-ignore-regexp
12058 verilog-before-auto-hook
12059 verilog-before-delete-auto-hook
12060 verilog-before-getopt-flags-hook
12061 verilog-case-indent
12062 verilog-cexp-indent
12065 verilog-delete-auto-hook
12066 verilog-getopt-flags-hook
12067 verilog-highlight-grouping-keywords
12068 verilog-highlight-p1800-keywords
12069 verilog-highlight-translate-off
12070 verilog-indent-begin-after-if
12071 verilog-indent-declaration-macros
12072 verilog-indent-level
12073 verilog-indent-level-behavioral
12074 verilog-indent-level-declaration
12075 verilog-indent-level-directive
12076 verilog-indent-level-module
12077 verilog-indent-lists
12078 verilog-library-directories
12079 verilog-library-extensions
12080 verilog-library-files
12081 verilog-library-flags
12083 verilog-minimum-comment-distance
12085 verilog-preprocessor
12087 verilog-tab-always-indent
12088 verilog-tab-to-comment
12089 verilog-typedef-regexp
12094 I want to report a bug.
12096 Before I go further, I want to say that Verilog mode has changed my life.
12097 I save so much time, my files are colored nicely, my co workers respect
12098 my coding ability... until now. I'd really appreciate anything you
12099 could do to help me out with this minor deficiency in the product.
12101 I've taken a look at the Verilog-Mode FAQ at
12102 http://www.veripool.org/verilog-mode-faq.html.
12104 And, I've considered filing the bug on the issue tracker at
12105 http://www.veripool.org/verilog-mode-bugs
12106 since I realize that public bugs are easier for you to track,
12107 and for others to search, but would prefer to email.
12109 So, to reproduce the bug, start a fresh Emacs via " invocation-name "
12110 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
12111 the code included below.
12113 Given those lines, I expected [[Fill in here]] to happen;
12114 but instead, [[Fill in here]] happens!.
12116 == The code: =="))))
12118 (provide 'verilog-mode)
12120 ;; Local Variables:
12121 ;; checkdoc-permit-comma-termination-flag:t
12122 ;; checkdoc-force-docstrings-flag:nil
12125 ;; arch-tag: 87923725-57b3-41b5-9494-be21118c6a6f
12126 ;;; verilog-mode.el ends here