comparison lisp/progmodes/verilog-mode.el @ 111161:7cae32037c1d

verilog-mode.el updates. This file should be copied to the trunk verbatim. * verilog-mode.el (verilog-directive-re): Make this variable auto-built for efficiency of execution and updating. (verilog-extended-complete-re): Support 'pure' fucntion & task declarations (these have no bodies). (verilog-beg-of-statement): general cleanup to enable support of 'pure' fucntion & task declarations (these have no bodies). These efforts together fix Verilog bug210 from veripool; which was also noticed by Steve Pearlmutter. (verilog-directive-re, verilog-directive-begin, verilog-indent-re) (verilog-directive-nest-re, verilog-set-auto-endcomments): Support `elsif. Reported by Shankar Giri. (verilog-forward-ws&directives, verilog-in-attribute-p): Fixes for attribute handling for lining up declarations and assignments. (verilog-beg-of-statement-1): Fix issue where continued declaration is indented differently if it is after a begin..end clock. (verilog-in-attribute-p, verilog-skip-backward-comments) (verilog-skip-forward-comment-p): Support proper treatment of attributes by indent code. Reported by Jeff Steele. (verilog-in-directive-p): Fix comment to correctly describe function. (verilog-backward-up-list, verilog-in-struct-region-p) (verilog-backward-token, verilog-in-struct-p) (verilog-in-coverage-p, verilog-do-indent) (verilog-pretty-declarations): Use verilog-backward-up-list as wrapper around backward-up-list inorder to properly skip comments. Reported by David Rogoff. (verilog-property-re, verilog-endcomment-reason-re) (verilog-beg-of-statement, verilog-set-auto-endcomments) (verilog-calc-1 ): Fix for assert a; else b; indentation (new form of if). Reported by Max Bjurling and (verilog-calc-1): Fix for clocking block in modport declaration. Reported by Brian Hunter. * verilog-mode.el (verilog-auto-inst, verilog-gate-ios) (verilog-gate-keywords, verilog-read-sub-decls) (verilog-read-sub-decls-gate, verilog-read-sub-decls-gate-ios) (verilog-read-sub-decls-line, verilog-read-sub-decls-sig): Support AUTOINST for gate primitives, bug284. Reported by Mark Johnson. (verilog-read-decls): Fix spaces in V2K module parameters causing mis-identification as interfaces, bug287. (verilog-read-decls): Fix not treating "parameter string" as a parameter in AUTOINSTPARAM. (verilog-read-always-signals-recurse, verilog-read-decls): Fix not treating `elsif similar to `endif inside AUTOSENSE. (verilog-do-indent): Implement correct automatic or static task or function end comment highlight. Reported by Steve Pearlmutter. (verilog-font-lock-keywords-2): Fix highlighting of single character pins, bug264. Reported by Michael Laajanen. (verilog-auto-inst, verilog-read-decls, verilog-read-sub-decls) (verilog-read-sub-decls-in-interfaced, verilog-read-sub-decls-sig) (verilog-subdecls-get-interfaced, verilog-subdecls-new): Support interfaces with AUTOINST, bug270. Reported by Luis Gutierrez. (verilog-pretty-expr): Fix interactive arguments, bug272. Reported by Mark Johnson. (verilog-auto-tieoff, verilog-auto-tieoff-ignore-regexp): Add 'verilog-auto-tieoff-ignore-regexp' for AUTOTIEOFF, bug269. Suggested by Gary Delp. (verilog-mode-map, verilog-preprocess, verilog-preprocess-history) (verilog-preprocessor, verilog-set-compile-command): Create verilog-preprocess and verilog-preprocessor to show preprocessed output. (verilog-get-beg-of-line, verilog-get-end-of-line) (verilog-modi-file-or-buffer, verilog-modi-name) (verilog-modi-point, verilog-within-string): Move defmacro's before first use to avoid warning. Reported by Steve Pearlmutter. (verilog-colorize-buffer, verilog-colorize-include-files-buffer) (verilog-colorize-region, verilog-highlight-buffer) (verilog-highlight-includes, verilog-highlight-modules) (verilog-highlight-region, verilog-mode): Rename colorize to highlight to match other packages. Disable module highlighting, as received speed complaints, reenable for experimentation only using new verilog-highlight-modules. (verilog-read-decls): Fix regexp stack overflow in very large AUTO_TEMPLATEs, bug250. (verilog-auto, verilog-delete-auto, verilog-save-buffer-state) (verilog-scan): Create verilog-save-buffer-state to standardize making insignificant changes that shouldn't call hooks. (verilog-save-no-change-functions, verilog-save-scan-cache) (verilog-scan, verilog-scan-cache-ok-p, verilog-scan-region): Create verilog-save-no-change-functions to wrap verilog-scan preservation, and fix to work with nested preserved calls. (verilog-auto-inst, verilog-auto-inst-dot-name): Support .name port syntax for AUTOWIRE, and with new verilog-auto-inst-dot-name generate .name with AUTOINST, bug245. Suggested by David Rogoff. (verilog-submit-bug-report): Update variable list to be complete. (verilog-auto, verilog-colorize-region): Fix AUTO expansion breaking on-the-fly font-locking. (verilog-colorize-buffer, verilog-colorize-include-files) (verilog-colorize-include-files-buffer, verilog-colorize-region) (verilog-load-file-at-mouse, verilog-load-file-at-point) (verilog-mode, verilog-read-inst-module-matcher): With point on a AUTOINST cell instance name, middle mouse button now finds-file on it. Suggested by Brad Dobbie. (verilog-alw-get-temps, verilog-auto-reset) (verilog-auto-sense-sigs, verilog-read-always-signals) (verilog-read-always-signals-recurse): Fix loop indexes being AUTORESET. AUTORESET now assumes any variables in the initialization section of a for() should be ignored. Reported by Dan Dever. (verilog-error-font-lock-keywords) (verilog-error-regexp-emacs-alist) (verilog-error-regexp-xemacs-alist): Fix error detection of Cadence HAL, reported by David Asher. Repair drift between the three similar error variables. (verilog-modi-lookup, verilog-modi-lookup-cache) (verilog-modi-lookup-last-current, verilog-modi-lookup-last-mod) (verilog-modi-lookup-last-modi, verilog-modi-lookup-last-tick): Fix slow verilog-auto expansion on very large files. (verilog-read-sub-decls-expr, verilog-read-sub-decls-line): Fix AUTOOUTPUT treating "1*2" as a signal name in submodule connection "{1*2{...". Broke in last revision. (verilog-read-sub-decls-expr): Fix AUTOOUTPUT not detecting submodule connections with replications "{#{a},#{b}}".
author Dan Nicolaescu <dann@ics.uci.edu>
date Sat, 23 Oct 2010 14:12:38 -0700
parents c1945e85d4b9
children bf6806de6892 33be1f38d8b9
comparison
equal deleted inserted replaced
111160:5b8d952e783f 111161:7cae32037c1d
1 ;; verilog-mode.el --- major mode for editing verilog source in Emacs 1 ;; verilog-mode.el --- major mode for editing verilog source in Emacs
2 2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 5
6 ;; Author: Michael McNamara (mac@verilog.com) 6 ;; Author: Michael McNamara (mac@verilog.com),
7 ;; http://www.verilog.com 7 ;; Wilson Snyder (wsnyder@wsnyder.org)
8 ;; Please see our web sites:
9 ;; http://www.verilog.com
10 ;; http://www.veripool.org
8 ;; 11 ;;
9 ;; AUTO features, signal, modsig; by: Wilson Snyder
10 ;; (wsnyder@wsnyder.org)
11 ;; http://www.veripool.org
12 ;; Keywords: languages 12 ;; Keywords: languages
13 13
14 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this 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 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 16 ;; filed in the Emacs bug reporting system against this file, a copy
77 ;; automatic Verilog mode, put this file in your load path, and put 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 78 ;; the following in code (please un comment it first!) in your
79 ;; .emacs, or in your site's site-load.el 79 ;; .emacs, or in your site's site-load.el
80 80
81 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t ) 81 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
82 ; (add-to-list 'auto-mode-alist '("\\.[ds]?v\\'" . verilog-mode)) 82 ; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
83 83
84 ;; If you want to customize Verilog mode to fit your needs better,
85 ;; you may add these lines (the values of the variables presented
86 ;; here are the defaults). Note also that if you use an Emacs that
87 ;; supports custom, it's probably better to use the custom menu to
88 ;; edit these.
89 ;;
90 ;; Be sure to examine at the help for verilog-auto, and the other 84 ;; Be sure to examine at the help for verilog-auto, and the other
91 ;; verilog-auto-* functions for some major coding time savers. 85 ;; verilog-auto-* functions for some major coding time savers.
92 ;; 86 ;;
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.
95 ;;
96 ; ;; Enable syntax highlighting of **all** languages
97 ; (global-font-lock-mode t)
98 ;
93 ; ;; User customization for Verilog mode 99 ; ;; User customization for Verilog mode
94 ; (setq verilog-indent-level 3 100 ; (setq verilog-indent-level 3
95 ; verilog-indent-level-module 3 101 ; verilog-indent-level-module 3
96 ; verilog-indent-level-declaration 3 102 ; verilog-indent-level-declaration 3
97 ; verilog-indent-level-behavioral 3 103 ; verilog-indent-level-behavioral 3
116 ;; (This section is required to appease checkdoc.) 122 ;; (This section is required to appease checkdoc.)
117 123
118 ;;; Code: 124 ;;; Code:
119 125
120 ;; This variable will always hold the version number of the mode 126 ;; This variable will always hold the version number of the mode
121 (defconst verilog-mode-version "556" 127 (defconst verilog-mode-version "647"
122 "Version of this Verilog mode.") 128 "Version of this Verilog mode.")
123 (defconst verilog-mode-release-date "2009-12-10-GNU" 129 (defconst verilog-mode-release-date "2010-10-20-GNU"
124 "Release date of this Verilog mode.") 130 "Release date of this Verilog mode.")
125 (defconst verilog-mode-release-emacs t 131 (defconst verilog-mode-release-emacs t
126 "If non-nil, this version of Verilog mode was released with Emacs itself.") 132 "If non-nil, this version of Verilog mode was released with Emacs itself.")
127 133
128 (defun verilog-version () 134 (defun verilog-version ()
211 (if (and (featurep 'custom) (fboundp 'customize-group)) 217 (if (and (featurep 'custom) (fboundp 'customize-group))
212 nil ;; We've got what we needed 218 nil ;; We've got what we needed
213 ;; We have an intermediate custom-library, hack around it! 219 ;; We have an intermediate custom-library, hack around it!
214 (defmacro customize-group (var &rest args) 220 (defmacro customize-group (var &rest args)
215 `(customize ,var)) 221 `(customize ,var))
216 )) 222 )
223
224 (unless (boundp 'inhibit-point-motion-hooks)
225 (defvar inhibit-point-motion-hooks nil))
226 (unless (boundp 'deactivate-mark)
227 (defvar deactivate-mark nil))
228 )
229 ;;
217 ;; OK, do this stuff if we are NOT XEmacs: 230 ;; OK, do this stuff if we are NOT XEmacs:
218 (unless (featurep 'xemacs) 231 (unless (featurep 'xemacs)
219 (unless (fboundp 'region-active-p) 232 (unless (fboundp 'region-active-p)
220 (defmacro region-active-p () 233 (defmacro region-active-p ()
221 `(and transient-mark-mode mark-active)))) 234 `(and transient-mark-mode mark-active))))
258 (concat open (mapconcat 'regexp-quote strings "\\|") close))) 271 (concat open (mapconcat 'regexp-quote strings "\\|") close)))
259 ) 272 )
260 ;; Emacs. 273 ;; Emacs.
261 (defalias 'verilog-regexp-opt 'regexp-opt))) 274 (defalias 'verilog-regexp-opt 'regexp-opt)))
262 275
276 (eval-and-compile
277 ;; Both xemacs and emacs
278 (condition-case nil
279 (unless (fboundp 'buffer-chars-modified-tick) ;; Emacs 22 added
280 (defmacro buffer-chars-modified-tick () (buffer-modified-tick)))
281 (error nil)))
282
263 (eval-when-compile 283 (eval-when-compile
264 (defun verilog-regexp-words (a) 284 (defun verilog-regexp-words (a)
265 "Call 'regexp-opt' with word delimiters for the words A." 285 "Call 'regexp-opt' with word delimiters for the words A."
266 (concat "\\<" (verilog-regexp-opt a t) "\\>"))) 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) "\\>"))
267 291
268 (defun verilog-easy-menu-filter (menu) 292 (defun verilog-easy-menu-filter (menu)
269 "Filter `easy-menu-define' MENU to support new features." 293 "Filter `easy-menu-define' MENU to support new features."
270 (cond ((not (featurep 'xemacs)) 294 (cond ((not (featurep 'xemacs))
271 menu) ;; GNU Emacs - passthru 295 menu) ;; GNU Emacs - passthru
336 360
337 (defgroup verilog-mode-auto nil 361 (defgroup verilog-mode-auto nil
338 "Customize AUTO actions when expanding Verilog source text." 362 "Customize AUTO actions when expanding Verilog source text."
339 :group 'verilog-mode) 363 :group 'verilog-mode)
340 364
365 (defvar verilog-debug nil
366 "If set, enable debug messages for `verilog-mode' internals.")
367
341 (defcustom verilog-linter 368 (defcustom verilog-linter
342 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'" 369 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
343 "*Unix program and arguments to call to run a lint checker on Verilog source. 370 "*Unix program and arguments to call to run a lint checker on Verilog source.
344 Depending on the `verilog-set-compile-command', this may be invoked when 371 Depending on the `verilog-set-compile-command', this may be invoked when
345 you type \\[compile]. When the compile completes, \\[next-error] will take 372 you type \\[compile]. When the compile completes, \\[next-error] will take
376 you to the next lint error." 403 you to the next lint error."
377 :type 'string 404 :type 'string
378 :group 'verilog-mode-actions) 405 :group 'verilog-mode-actions)
379 ;; We don't mark it safe, as it's used as a shell command 406 ;; We don't mark it safe, as it's used as a shell command
380 407
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."
416 :type 'string
417 :group 'verilog-mode-actions)
418 ;; We don't mark it safe, as it's used as a shell command
419
420 (defvar verilog-preprocess-history nil
421 "History for `verilog-preprocess'.")
422
381 (defvar verilog-tool 'verilog-linter 423 (defvar verilog-tool 'verilog-linter
382 "Which tool to use for building compiler-command. 424 "Which tool to use for building compiler-command.
383 Either nil, `verilog-linter, `verilog-coverage, `verilog-simulator, or 425 Either nil, `verilog-linter, `verilog-compiler,
384 `verilog-compiler. Alternatively use the \"Choose Compilation Action\" 426 `verilog-coverage, `verilog-preprocessor, or `verilog-simulator.
385 menu. See `verilog-set-compile-command' for more information.") 427 Alternatively use the \"Choose Compilation Action\" menu. See
428 `verilog-set-compile-command' for more information.")
386 429
387 (defcustom verilog-highlight-translate-off nil 430 (defcustom verilog-highlight-translate-off nil
388 "*Non-nil means background-highlight code excluded from translation. 431 "*Non-nil means background-highlight code excluded from translation.
389 That is, all code between \"// synopsys translate_off\" and 432 That is, all code between \"// synopsys translate_off\" and
390 \"// synopsys translate_on\" is highlighted using a different background color 433 \"// synopsys translate_on\" is highlighted using a different background color
570 grouping constructs allow the structure of the code to be understood at a glance." 613 grouping constructs allow the structure of the code to be understood at a glance."
571 :group 'verilog-mode-indent 614 :group 'verilog-mode-indent
572 :type 'boolean) 615 :type 'boolean)
573 (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp) 616 (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
574 617
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
624 :type 'boolean)
625 (put 'verilog-highlight-modules 'safe-local-variable 'verilog-booleanp)
626
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
632 :type 'boolean)
633 (put 'verilog-highlight-includes 'safe-local-variable 'verilog-booleanp)
634
575 (defcustom verilog-auto-endcomments t 635 (defcustom verilog-auto-endcomments t
576 "*True means insert a comment /* ... */ after 'end's. 636 "*True means insert a comment /* ... */ after 'end's.
577 The name of the function or case will be set between the braces." 637 The name of the function or case will be set between the braces."
578 :group 'verilog-mode-actions 638 :group 'verilog-mode-actions
579 :type 'boolean) 639 :type 'boolean)
638 "Text from file-local-variables during last evaluation.") 698 "Text from file-local-variables during last evaluation.")
639 699
640 ;;; Compile support 700 ;;; Compile support
641 (require 'compile) 701 (require 'compile)
642 (defvar verilog-error-regexp-added nil) 702 (defvar verilog-error-regexp-added nil)
643 ; List of regexps for Verilog compilers, like verilint. See compilation-error-regexp-alist 703
644 ; for the formatting.
645 ; Here is the version for Emacs 22:
646 (defvar verilog-error-regexp-emacs-alist 704 (defvar verilog-error-regexp-emacs-alist
647 '( 705 '(
648 (verilog-xl-1 706 (verilog-xl-1
649 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3) 707 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
650 (verilog-xl-2 708 (verilog-xl-2
651 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3) 709 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
652 (verilog-IES 710 (verilog-IES
653 ".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)" 1 2) 711 ".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
654 (verilog-surefire-1 712 (verilog-surefire-1
655 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2) 713 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
656 (verilog-surefire-2 714 (verilog-surefire-2
657 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 ) 715 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
658 (verilog-verbose 716 (verilog-verbose
670 (verilog-vcs-4 728 (verilog-vcs-4
671 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2) 729 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
672 (verilog-verilator 730 (verilog-verilator
673 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) 731 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
674 (verilog-leda 732 (verilog-leda
675 "In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\): 733 "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
676 .* 734 )
677 .* 735 "List of regexps for Verilog compilers.
678 .* 736 See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
679 \\(Warning\\|Error\\|Failure\\)" 1 2) 737
680 ))
681 ;; And the version for XEmacs:
682 (defvar verilog-error-regexp-xemacs-alist 738 (defvar verilog-error-regexp-xemacs-alist
683 '(verilog 739 ;; Emacs form is '((v-tool "re" 1 2) ...)
684 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2) 740 ;; XEmacs form is '(verilog ("re" 1 2) ...)
685 ("\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 ) 741 ;; So we can just map from Emacs to Xemacs
686 ("\ 742 (cons 'verilog (mapcar 'cdr verilog-error-regexp-emacs-alist))
687 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ 743 "List of regexps for Verilog compilers.
688 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5) 744 See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
689 ; xsim
690 ; Error! in file /homes/mac/Axis/Xsim/test.v at line 13 [OBJ_NOT_DECLARED]
691 ("\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
692 ; vcs
693 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
694 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
695 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
696 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
697 ; Verilator
698 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
699 ; verilog-xl
700 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
701 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 2) ; vxl
702 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 2)
703 ; nc-verilog
704 (".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 2)
705 ; Leda
706 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 2)
707 )
708 )
709 745
710 (defvar verilog-error-font-lock-keywords 746 (defvar verilog-error-font-lock-keywords
711 '( 747 '(
748 ;; verilog-xl-1
749 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
750 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
751 ;; verilog-xl-2
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
712 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t) 758 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
713 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t) 759 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
714 760 ;; verilog-surefire-2
715 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t) 761 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t)
716 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t) 762 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t)
717 763 ;; verilog-verbose
718 ("\ 764 ("\
719 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ 765 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
720 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t) 766 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
721 ("\ 767 ("\
722 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ 768 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
723 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t) 769 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
724 770 ;; verilog-vcs-1
725 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t) 771 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t)
726 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t) 772 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t)
727 773 ;; verilog-vcs-2
728 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
729 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)
730
731 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t) 774 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
732 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t) 775 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
733 776 ;; verilog-vcs-3
734 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t) 777 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
735 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t) 778 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t)
736 779 ;; verilog-vcs-4
737 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t) 780 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t)
738 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t) 781 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
739 ; vxl 782 ;; verilog-verilator
740 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t) 783 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
741 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t) 784 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)
742 785 ;; verilog-leda
743 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 bold t) 786 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t)
744 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 2 bold t) 787 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t)
745
746 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 bold t)
747 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 2 bold t)
748 ; nc-verilog
749 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 bold t)
750 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t)
751 ; Leda
752 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 bold t)
753 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 2 bold t)
754 ) 788 )
755 "*Keywords to also highlight in Verilog *compilation* buffers.") 789 "*Keywords to also highlight in Verilog *compilation* buffers.
790 Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
756 791
757 (defcustom verilog-library-flags '("") 792 (defcustom verilog-library-flags '("")
758 "*List of standard Verilog arguments to use for /*AUTOINST*/. 793 "*List of standard Verilog arguments to use for /*AUTOINST*/.
759 These arguments are used to find files for `verilog-auto', and match 794 These arguments are used to find files for `verilog-auto', and match
760 the flags accepted by a standard Verilog-XL simulator. 795 the flags accepted by a standard Verilog-XL simulator.
886 it's bad practice to rely on order based instantiations anyhow." 921 it's bad practice to rely on order based instantiations anyhow."
887 :group 'verilog-mode-auto 922 :group 'verilog-mode-auto
888 :type 'boolean) 923 :type 'boolean)
889 (put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp) 924 (put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)
890 925
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
933 :type 'boolean)
934 (put 'verilog-auto-inst-dot-name 'safe-local-variable 'verilog-booleanp)
935
891 (defcustom verilog-auto-inst-param-value nil 936 (defcustom verilog-auto-inst-param-value nil
892 "*If set, AUTOINST will replace parameters with the parameter value. 937 "*If set, AUTOINST will replace parameters with the parameter value.
893 If nil, leave parameters as symbolic names. 938 If nil, leave parameters as symbolic names.
894 939
895 Parameters must be in Verilog 2001 format #(...), and if a parameter is not 940 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
897 be replaced, and will remain symbolic. 942 be replaced, and will remain symbolic.
898 943
899 For example, imagine a submodule uses parameters to declare the size of its 944 For example, imagine a submodule uses parameters to declare the size of its
900 inputs. This is then used by a upper module: 945 inputs. This is then used by a upper module:
901 946
902 module InstModule (o,i) 947 module InstModule (o,i);
903 parameter WIDTH; 948 parameter WIDTH;
904 input [WIDTH-1:0] i; 949 input [WIDTH-1:0] i;
905 endmodule 950 endmodule
906 951
907 module ExampInst; 952 module ExampInst;
968 "*If set, when creating AUTOOUTPUT list, ignore signals matching this regexp. 1013 "*If set, when creating AUTOOUTPUT list, ignore signals matching this regexp.
969 See the \\[verilog-faq] for examples on using this." 1014 See the \\[verilog-faq] for examples on using this."
970 :group 'verilog-mode-auto 1015 :group 'verilog-mode-auto
971 :type 'string) 1016 :type 'string)
972 (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp) 1017 (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
1018
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
1023 :type 'string)
1024 (put 'verilog-auto-tieoff-ignore-regexp 'safe-local-variable 'stringp)
973 1025
974 (defcustom verilog-auto-unused-ignore-regexp nil 1026 (defcustom verilog-auto-unused-ignore-regexp nil
975 "*If set, when creating AUTOUNUSED list, ignore signals matching this regexp. 1027 "*If set, when creating AUTOUNUSED list, ignore signals matching this regexp.
976 See the \\[verilog-faq] for examples on using this." 1028 See the \\[verilog-faq] for examples on using this."
977 :group 'verilog-mode-auto 1029 :group 'verilog-mode-auto
1078 (define-key map "\M-\C-e" 'verilog-end-of-defun)) 1130 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1079 (define-key map "\C-c\C-d" 'verilog-goto-defun) 1131 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1080 (define-key map "\C-c\C-k" 'verilog-delete-auto) 1132 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1081 (define-key map "\C-c\C-a" 'verilog-auto) 1133 (define-key map "\C-c\C-a" 'verilog-auto)
1082 (define-key map "\C-c\C-s" 'verilog-auto-save-compile) 1134 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1135 (define-key map "\C-c\C-p" 'verilog-preprocess)
1083 (define-key map "\C-c\C-z" 'verilog-inject-auto) 1136 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1084 (define-key map "\C-c\C-e" 'verilog-expand-vector) 1137 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1085 (define-key map "\C-c\C-h" 'verilog-header) 1138 (define-key map "\C-c\C-h" 'verilog-header)
1086 map) 1139 map)
1087 "Keymap used in Verilog mode.") 1140 "Keymap used in Verilog mode.")
1125 (setq verilog-tool 'verilog-compiler) 1178 (setq verilog-tool 'verilog-compiler)
1126 (verilog-set-compile-command)) 1179 (verilog-set-compile-command))
1127 :style radio 1180 :style radio
1128 :selected (equal verilog-tool `verilog-compiler) 1181 :selected (equal verilog-tool `verilog-compiler)
1129 :help "When invoking compilation, compile Verilog source"] 1182 :help "When invoking compilation, compile Verilog source"]
1183 ["Preprocessor"
1184 (progn
1185 (setq verilog-tool 'verilog-preprocessor)
1186 (verilog-set-compile-command))
1187 :style radio
1188 :selected (equal verilog-tool `verilog-preprocessor)
1189 :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1130 ) 1190 )
1131 ("Move" 1191 ("Move"
1132 ["Beginning of function" verilog-beg-of-defun 1192 ["Beginning of function" verilog-beg-of-defun
1133 :keys "C-M-a" 1193 :keys "C-M-a"
1134 :help "Move backward to the beginning of the current function or procedure"] 1194 :help "Move backward to the beginning of the current function or procedure"]
1316 1376
1317 ;; 1377 ;;
1318 ;; Macros 1378 ;; Macros
1319 ;; 1379 ;;
1320 1380
1381 (defsubst verilog-get-beg-of-line (&optional arg)
1382 (save-excursion
1383 (beginning-of-line arg)
1384 (point)))
1385
1386 (defsubst verilog-get-end-of-line (&optional arg)
1387 (save-excursion
1388 (end-of-line arg)
1389 (point)))
1390
1391 (defsubst verilog-within-string ()
1392 (save-excursion
1393 (nth 3 (parse-partial-sexp (verilog-get-beg-of-line) (point)))))
1394
1321 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string) 1395 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1322 "Replace occurrences of FROM-STRING with TO-STRING. 1396 "Replace occurrences of FROM-STRING with TO-STRING.
1323 FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace. 1397 FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace.
1324 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\") 1398 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1325 will break, as the o's continuously replace. xa -> x works ok though." 1399 will break, as the o's continuously replace. xa -> x works ok though."
1392 (re-search-backward regexp bound noerror)) 1466 (re-search-backward regexp bound noerror))
1393 (if (not (verilog-inside-comment-p)) 1467 (if (not (verilog-inside-comment-p))
1394 (setq pt (match-end 0)))) 1468 (setq pt (match-end 0))))
1395 pt)) 1469 pt))
1396 1470
1397 (defsubst verilog-get-beg-of-line (&optional arg) 1471 (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
1398 (save-excursion 1472 "Like `re-search-forward', but first search for SUBSTR constant.
1399 (beginning-of-line arg) 1473 Then searched for the normal REGEXP (which contains SUBSTR), with given
1400 (point))) 1474 BOUND and NOERROR. The REGEXP must fit within a single line.
1401 1475 This speeds up complicated regexp matches."
1402 (defsubst verilog-get-end-of-line (&optional arg) 1476 ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
1403 (save-excursion 1477 ;; thus require matches to be on one line, and use beginning-of-line.
1404 (end-of-line arg) 1478 (let (done)
1405 (point))) 1479 (while (and (not done)
1406 1480 (search-forward substr bound noerror))
1407 (defsubst verilog-within-string () 1481 (save-excursion
1408 (save-excursion 1482 (beginning-of-line)
1409 (nth 3 (parse-partial-sexp (verilog-get-beg-of-line) (point))))) 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)))
1486 (setq done nil)))
1487 (when done (goto-char done))
1488 done))
1489 ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1490
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.
1498 (let (done)
1499 (while (and (not done)
1500 (search-backward substr bound noerror))
1501 (save-excursion
1502 (end-of-line)
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)))
1506 (setq done nil)))
1507 (when done (goto-char done))
1508 done))
1509 ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1410 1510
1411 (defvar compile-command) 1511 (defvar compile-command)
1412 1512
1413 ;; compilation program 1513 ;; compilation program
1414 (defun verilog-set-compile-command () 1514 (defun verilog-set-compile-command ()
1416 1516
1417 This reads `verilog-tool' and sets `compile-command'. This specifies the 1517 This reads `verilog-tool' and sets `compile-command'. This specifies the
1418 program that executes when you type \\[compile] or 1518 program that executes when you type \\[compile] or
1419 \\[verilog-auto-save-compile]. 1519 \\[verilog-auto-save-compile].
1420 1520
1421 By default `verilog-tool' uses a Makefile if one exists in the current 1521 By default `verilog-tool' uses a Makefile if one exists in the
1422 directory. If not, it is set to the `verilog-linter', `verilog-coverage', 1522 current directory. If not, it is set to the `verilog-linter',
1423 `verilog-simulator', or `verilog-compiler' variables, as selected with the 1523 `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
1424 Verilog -> \"Choose Compilation Action\" menu. 1524 or `verilog-simulator' variables, as selected with the Verilog ->
1525 \"Choose Compilation Action\" menu.
1425 1526
1426 You should set `verilog-tool' or the other variables to the path and 1527 You should set `verilog-tool' or the other variables to the path and
1427 arguments for your Verilog simulator. For example: 1528 arguments for your Verilog simulator. For example:
1428 \"vcs -p123 -O\" 1529 \"vcs -p123 -O\"
1429 or a string like: 1530 or a string like:
1431 1532
1432 In the former case, the path to the current buffer is concat'ed to the 1533 In the former case, the path to the current buffer is concat'ed to the
1433 value of `verilog-tool'; in the later, the path to the current buffer is 1534 value of `verilog-tool'; in the later, the path to the current buffer is
1434 substituted for the %s. 1535 substituted for the %s.
1435 1536
1436 Where __FILE__ appears in the string, the `buffer-file-name' of the 1537 Where __FLAGS__ appears in the string `verilog-current-flags'
1437 current buffer, without the directory portion, will be substituted." 1538 will be substituted.
1539
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."
1438 (interactive) 1543 (interactive)
1439 (cond 1544 (cond
1440 ((or (file-exists-p "makefile") ;If there is a makefile, use it 1545 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1441 (file-exists-p "Makefile")) 1546 (file-exists-p "Makefile"))
1442 (make-local-variable 'compile-command) 1547 (make-local-variable 'compile-command)
1449 (format (eval verilog-tool) (or buffer-file-name "")) 1554 (format (eval verilog-tool) (or buffer-file-name ""))
1450 (concat (eval verilog-tool) " " (or buffer-file-name ""))) 1555 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1451 "")))) 1556 ""))))
1452 (verilog-modify-compile-command)) 1557 (verilog-modify-compile-command))
1453 1558
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
1564 be substituted."
1565 (setq command (verilog-string-replace-matches
1566 ;; Note \\b only works if under verilog syntax table
1567 "\\b__FLAGS__\\b" (verilog-current-flags)
1568 t t command))
1569 (setq command (verilog-string-replace-matches
1570 "\\b__FILE__\\b" (file-name-nondirectory
1571 (or (buffer-file-name) ""))
1572 t t command))
1573 command)
1574
1454 (defun verilog-modify-compile-command () 1575 (defun verilog-modify-compile-command ()
1455 "Replace meta-information in `compile-command'. 1576 "Update `compile-command' using `verilog-expand-command'."
1456 Where __FILE__ appears in the string, the current buffer's file-name,
1457 without the directory portion, will be substituted."
1458 (when (and 1577 (when (and
1459 (stringp compile-command) 1578 (stringp compile-command)
1460 (string-match "\\b__FILE__\\b" compile-command)) 1579 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1461 (make-local-variable 'compile-command) 1580 (make-local-variable 'compile-command)
1462 (setq compile-command 1581 (setq compile-command (verilog-expand-command compile-command))))
1463 (verilog-string-replace-matches
1464 "\\b__FILE__\\b" (file-name-nondirectory (buffer-file-name))
1465 t t compile-command))))
1466 1582
1467 (if (featurep 'xemacs) 1583 (if (featurep 'xemacs)
1468 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling. 1584 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1469 (defun verilog-error-regexp-add-xemacs () 1585 (defun verilog-error-regexp-add-xemacs ()
1470 "Teach XEmacs about verilog errors. 1586 "Teach XEmacs about verilog errors.
1509 1625
1510 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs)) 1626 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
1511 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs)) 1627 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
1512 1628
1513 (defconst verilog-directive-re 1629 (defconst verilog-directive-re
1514 ;; "`case" "`default" "`define" "`define" "`else" "`endfor" "`endif" 1630 (eval-when-compile
1515 ;; "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" 1631 (verilog-regexp-words
1516 ;; "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" 1632 '(
1517 ;; "`time_scale" "`undef" "`while" 1633 "`case" "`default" "`define" "`else" "`elsif" "`endfor" "`endif"
1518 "\\<`\\(case\\|def\\(ault\\|ine\\(\\)?\\)\\|e\\(lse\\|nd\\(for\\|if\\|protect\\|switch\\|while\\)\\)\\|for\\(mat\\)?\\|i\\(f\\(def\\|ndef\\)?\\|nclude\\)\\|let\\|protect\\|switch\\|time\\(_scale\\|scale\\)\\|undef\\|while\\)\\>") 1634 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
1635 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
1636 "`time_scale" "`undef" "`while" ))))
1519 1637
1520 (defconst verilog-directive-re-1 1638 (defconst verilog-directive-re-1
1521 (concat "[ \t]*" verilog-directive-re)) 1639 (concat "[ \t]*" verilog-directive-re))
1522 1640
1523 (defconst verilog-directive-begin 1641 (defconst verilog-directive-begin
1524 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>") 1642 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
1525 1643
1526 (defconst verilog-directive-middle 1644 (defconst verilog-directive-middle
1527 "\\<`\\(else\\|default\\|case\\)\\>") 1645 "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
1528 1646
1529 (defconst verilog-directive-end 1647 (defconst verilog-directive-end
1530 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>") 1648 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
1531 1649
1532 (defconst verilog-ovm-begin-re 1650 (defconst verilog-ovm-begin-re
1701 ;; a[34:32] : 1819 ;; a[34:32] :
1702 ;; a, 1820 ;; a,
1703 ;; b : 1821 ;; b :
1704 1822
1705 (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*")) 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\\>"
1828
1706 (defconst verilog-no-indent-begin-re 1829 (defconst verilog-no-indent-begin-re
1707 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>") 1830 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>")
1708 1831
1709 (defconst verilog-ends-re 1832 (defconst verilog-ends-re
1710 ;; Parenthesis indicate type of keyword found 1833 ;; Parenthesis indicate type of keyword found
1835 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" ; 5 1958 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" ; 5
1836 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" ; 6 1959 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" ; 6
1837 "\\(\\<fork\\>\\)\\|" ; 7 1960 "\\(\\<fork\\>\\)\\|" ; 7
1838 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|" 1961 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
1839 "\\(\\<if\\>\\)\\|" 1962 "\\(\\<if\\>\\)\\|"
1963 verilog-property-re "\\|"
1964 "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
1840 "\\(\\<clocking\\>\\)\\|" 1965 "\\(\\<clocking\\>\\)\\|"
1841 "\\(\\<task\\>\\)\\|" 1966 "\\(\\<task\\>\\)\\|"
1842 "\\(\\<function\\>\\)\\|" 1967 "\\(\\<function\\>\\)\\|"
1843 "\\(\\<initial\\>\\)\\|" 1968 "\\(\\<initial\\>\\)\\|"
1844 "\\(\\<interface\\>\\)\\|" 1969 "\\(\\<interface\\>\\)\\|"
2049 "task" "endtask" 2174 "task" "endtask"
2050 "virtual" 2175 "virtual"
2051 "`case" 2176 "`case"
2052 "`default" 2177 "`default"
2053 "`define" "`undef" 2178 "`define" "`undef"
2054 "`if" "`ifdef" "`ifndef" "`else" "`endif" 2179 "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
2055 "`while" "`endwhile" 2180 "`while" "`endwhile"
2056 "`for" "`endfor" 2181 "`for" "`endfor"
2057 "`format" 2182 "`format"
2058 "`include" 2183 "`include"
2059 "`let" 2184 "`let"
2114 (eval-when-compile 2239 (eval-when-compile
2115 (verilog-regexp-words 2240 (verilog-regexp-words
2116 `( 2241 `(
2117 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass" 2242 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2118 )))) 2243 ))))
2119 (defconst verilog-disable-fork-re "disable\\s-+fork") 2244 (defconst verilog-disable-fork-re "disable\\s-+fork\\>")
2245 (defconst verilog-fork-wait-re "fork\\s-+wait\\>")
2120 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?") 2246 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?")
2121 (defconst verilog-extended-complete-re 2247 (defconst verilog-extended-complete-re
2122 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)" 2248 (concat "\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)"
2123 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)" 2249 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)"
2124 "\\|\\(\\<import\\>\\s-+\\)?\"DPI-C\"\\s-+\\(function\\>\\|task\\>\\)" 2250 "\\|\\(\\<import\\>\\s-+\\)?\"DPI-C\"\\s-+\\(function\\>\\|task\\>\\)"
2125 "\\|" verilog-extended-case-re )) 2251 "\\|" verilog-extended-case-re ))
2126 (defconst verilog-basic-complete-re 2252 (defconst verilog-basic-complete-re
2127 (eval-when-compile 2253 (eval-when-compile
2196 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri" 2322 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
2197 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union" 2323 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
2198 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void" 2324 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
2199 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard" 2325 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
2200 "wire" "with" "within" "wor" "xnor" "xor" 2326 "wire" "with" "within" "wor" "xnor" "xor"
2327 ;; 1800-2009
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"
2201 ) 2332 )
2202 "List of Verilog keywords.") 2333 "List of Verilog keywords.")
2203 2334
2204 (defconst verilog-comment-start-regexp "//\\|/\\*" 2335 (defconst verilog-comment-start-regexp "//\\|/\\*"
2205 "Dual comment value for `comment-start-regexp'.") 2336 "Dual comment value for `comment-start-regexp'.")
2312 (verilog-regexp-opt 2443 (verilog-regexp-opt
2313 '( 2444 '(
2314 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam" 2445 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
2315 "event" "genvar" "inout" "input" "integer" "localparam" 2446 "event" "genvar" "inout" "input" "integer" "localparam"
2316 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or" 2447 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or"
2317 "output" "parameter" "pmos" "pull0" "pull1" "pullup" 2448 "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
2318 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" 2449 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
2319 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply" 2450 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
2320 "supply0" "supply1" "time" "tran" "tranif0" "tranif1" 2451 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
2321 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef" 2452 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
2322 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor" 2453 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
2326 (eval-when-compile 2457 (eval-when-compile
2327 (verilog-regexp-opt 2458 (verilog-regexp-opt
2328 '("surefire" "synopsys" "rtl_synthesis" "verilint" "leda" "0in") nil 2459 '("surefire" "synopsys" "rtl_synthesis" "verilint" "leda" "0in") nil
2329 ))) 2460 )))
2330 2461
2331 (verilog-p1800-keywords 2462 (verilog-1800-2005-keywords
2332 (eval-when-compile 2463 (eval-when-compile
2333 (verilog-regexp-opt 2464 (verilog-regexp-opt
2334 '("alias" "assert" "assume" "automatic" "before" "bind" 2465 '("alias" "assert" "assume" "automatic" "before" "bind"
2335 "bins" "binsof" "break" "byte" "cell" "chandle" "class" 2466 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
2336 "clocking" "config" "const" "constraint" "context" "continue" 2467 "clocking" "config" "const" "constraint" "context" "continue"
2350 "super" "tagged" "this" "throughout" "timeprecision" "timeunit" 2481 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
2351 "type" "union" "unsigned" "use" "var" "virtual" "void" 2482 "type" "union" "unsigned" "use" "var" "virtual" "void"
2352 "wait_order" "weak0" "weak1" "wildcard" "with" "within" 2483 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
2353 ) nil ))) 2484 ) nil )))
2354 2485
2486 (verilog-1800-2009-keywords
2487 (eval-when-compile
2488 (verilog-regexp-opt
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 )))
2494
2355 (verilog-ams-keywords 2495 (verilog-ams-keywords
2356 (eval-when-compile 2496 (eval-when-compile
2357 (verilog-regexp-opt 2497 (verilog-regexp-opt
2358 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim" 2498 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
2359 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh" 2499 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
2401 'verilog-font-lock-ams-face) 2541 'verilog-font-lock-ams-face)
2402 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>") 2542 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2403 'font-lock-type-face)) 2543 'font-lock-type-face))
2404 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>") 2544 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
2405 'font-lock-type-face) 2545 'font-lock-type-face)
2406 ;; Fontify IEEE-P1800 keywords appropriately 2546 ;; Fontify IEEE-1800-2005 keywords appropriately
2407 (if verilog-highlight-p1800-keywords 2547 (if verilog-highlight-p1800-keywords
2408 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") 2548 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
2409 'verilog-font-lock-p1800-face) 2549 'verilog-font-lock-p1800-face)
2410 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") 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 "\\)\\>")
2411 'font-lock-type-face)) 2557 'font-lock-type-face))
2412 ;; Fontify Verilog-AMS keywords 2558 ;; Fontify Verilog-AMS keywords
2413 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>") 2559 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
2414 'verilog-font-lock-ams-face))) 2560 'verilog-font-lock-ams-face)))
2415 2561
2445 'font-lock-type-face)) 2591 'font-lock-type-face))
2446 ;; Fontify delays/numbers 2592 ;; Fontify delays/numbers
2447 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)" 2593 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
2448 0 font-lock-type-face append) 2594 0 font-lock-type-face append)
2449 ;; Fontify instantiation names 2595 ;; Fontify instantiation names
2450 '("\\([A-Za-z][A-Za-z0-9_]+\\)\\s-*(" 1 font-lock-function-name-face) 2596 '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
2451 ))) 2597 )))
2452 2598
2453 (setq verilog-font-lock-keywords-3 2599 (setq verilog-font-lock-keywords-3
2454 (append verilog-font-lock-keywords-2 2600 (append verilog-font-lock-keywords-2
2455 (when verilog-highlight-translate-off 2601 (when verilog-highlight-translate-off
2457 ;; Fontify things in translate off regions 2603 ;; Fontify things in translate off regions
2458 '(verilog-match-translate-off 2604 '(verilog-match-translate-off
2459 (0 'verilog-font-lock-translate-off-face prepend)) 2605 (0 'verilog-font-lock-translate-off-face prepend))
2460 ))))) 2606 )))))
2461 2607
2608 ;;
2609 ;; Buffer state preservation
2610
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.
2616
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
2628 deactivate-mark
2629 buffer-file-name ; Prevent primitives checking
2630 buffer-file-truename) ; for file modification
2631 (unwind-protect
2632 (progn ,@body)
2633 (and (not modified)
2634 (buffer-modified-p)
2635 (set-buffer-modified-p nil)))))
2636
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)
2643 (progn ,@body)))
2644
2645 ;;
2646 ;; Comment detection and caching
2647
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'.")
2652
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)
2656
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))))
2663
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.
2670 `(progn
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)))
2674 (progn ,@body))))
2675
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)
2680 ;; lookup times.
2681 ;; This function is warm - called on every verilog-insert
2682 (save-excursion
2683 (save-match-data
2684 (verilog-save-buffer-state
2685 (let (pt)
2686 (goto-char beg)
2687 (while (< (point) end)
2688 (cond ((looking-at "//")
2689 (setq pt (point))
2690 (or (search-forward "\n" end t)
2691 (goto-char end))
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 "/\\*")
2698 (setq pt (point))
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))
2704 (goto-char end))
2705 (put-text-property (1+ pt) (point) 'v-cmt t))
2706 (t
2707 (forward-char 1)
2708 (if (re-search-forward "/[/*]" end t)
2709 (backward-char 2)
2710 (goto-char end))))))))))
2711
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)
2717 (save-excursion
2718 (verilog-save-buffer-state
2719 (when verilog-debug
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"))))))
2462 2727
2463 (defun verilog-inside-comment-p () 2728 (defun verilog-inside-comment-p ()
2464 "Check if point inside a nested comment." 2729 "Check if point inside a comment.
2465 (save-excursion 2730 This may require a slow pre-parse of the buffer with `verilog-scan'
2466 (let ((st-point (point)) hitbeg) 2731 to establish comment properties on all text."
2467 (or (search-backward "//" (verilog-get-beg-of-line) t) 2732 ;; This function is very hot
2468 (if (progn 2733 (verilog-scan)
2469 ;; This is for tricky case //*, we keep searching if /* 2734 (get-text-property (point) 'v-cmt))
2470 ;; is proceeded by // on same line. 2735
2471 (while 2736 (defun verilog-insert (&rest stuff)
2472 (and (setq hitbeg (search-backward "/*" nil t)) 2737 "Insert STUFF arguments, tracking comments for `verilog-inside-comment-p'.
2473 (progn 2738 Any insert that includes a comment must have the entire commente
2474 (forward-char 1) 2739 inserted using a single call to `verilog-insert'."
2475 (search-backward "//" (verilog-get-beg-of-line) t)))) 2740 (let ((pt (point)))
2476 hitbeg) 2741 (while stuff
2477 (not (search-forward "*/" st-point t))))))) 2742 (insert (car stuff))
2743 (setq stuff (cdr stuff)))
2744 (verilog-scan-region pt (point))))
2745
2746 ;; More searching
2478 2747
2479 (defun verilog-declaration-end () 2748 (defun verilog-declaration-end ()
2480 (search-forward ";")) 2749 (search-forward ";"))
2481 2750
2482 (defun verilog-point-text (&optional pointnum) 2751 (defun verilog-point-text (&optional pointnum)
2578 ;; Search forward for matching endcase 2847 ;; Search forward for matching endcase
2579 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ) 2848 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
2580 (setq md 3) ;; ender is third item in regexp 2849 (setq md 3) ;; ender is third item in regexp
2581 ) 2850 )
2582 ((match-end 4) 2851 ((match-end 4)
2583 ;; might be "disable fork" 2852 ;; might be "disable fork" or "fork wait"
2584 (if (or 2853 (let
2585 (looking-at verilog-disable-fork-re) 2854 (here)
2586 (and (looking-at "fork") 2855 (if (looking-at verilog-fork-wait-re)
2587 (progn 2856 (progn ;; it is a fork wait; ignore it
2588 (forward-word -1) 2857 (goto-char (match-end 0))
2589 (looking-at verilog-disable-fork-re)))) 2858 (setq reg nil))
2590 (progn 2859 (if (or
2591 (goto-char (match-end 0)) 2860 (looking-at verilog-disable-fork-re)
2592 (forward-word 1) 2861 (and (looking-at "fork")
2593 (setq reg nil)) 2862 (progn
2594 (progn 2863 (setq here (point)) ;; sometimes a fork is just a fork
2595 ;; Search forward for matching join 2864 (forward-word -1)
2596 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))) 2865 (looking-at verilog-disable-fork-re))))
2866 (progn ;; it is a disable fork; ignore it
2867 (goto-char (match-end 0))
2868 (forward-word 1)
2869 (setq reg nil))
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\\)?\\>\\)" ))))))
2597 ((match-end 6) 2874 ((match-end 6)
2598 ;; Search forward for matching endclass 2875 ;; Search forward for matching endclass
2599 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) 2876 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
2600 2877
2601 ((match-end 7) 2878 ((match-end 7)
2639 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" ))) 2916 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
2640 (if (and reg 2917 (if (and reg
2641 (forward-word 1)) 2918 (forward-word 1))
2642 (catch 'skip 2919 (catch 'skip
2643 (if (eq nest 'yes) 2920 (if (eq nest 'yes)
2644 (let ((depth 1)) 2921 (let ((depth 1)
2922 here )
2645 (while (verilog-re-search-forward reg nil 'move) 2923 (while (verilog-re-search-forward reg nil 'move)
2646 (cond 2924 (cond
2647 ((match-end md) ; the closer in reg, so we are climbing out 2925 ((match-end md) ; a closer in regular expression, so we are climbing out
2648 (setq depth (1- depth)) 2926 (setq depth (1- depth))
2649 (if (= 0 depth) ; we are out! 2927 (if (= 0 depth) ; we are out!
2650 (throw 'skip 1))) 2928 (throw 'skip 1)))
2651 ((match-end 1) ; the opener in reg, so we are deeper now 2929 ((match-end 1) ; an opener in the r-e, so we are in deeper now
2652 (setq depth (1+ depth)))))) 2930 (setq here (point)) ; remember where we started
2931 (goto-char (match-beginning 1))
2932 (cond
2933 ((looking-at verilog-fork-wait-re)
2934 (goto-char (match-end 0))) ; false alarm
2935 ((if (or
2936 (looking-at verilog-disable-fork-re)
2937 (and (looking-at "fork")
2938 (progn
2939 (forward-word -1)
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)
2944 (goto-char here)
2945 (setq depth (1+ depth))))))))))
2653 (if (verilog-re-search-forward reg nil 'move) 2946 (if (verilog-re-search-forward reg nil 'move)
2654 (throw 'skip 1)))))) 2947 (throw 'skip 1))))))
2655 2948
2656 ((looking-at (concat 2949 ((looking-at (concat
2657 "\\(\\<\\(macro\\)?module\\>\\)\\|" 2950 "\\(\\<\\(macro\\)?module\\>\\)\\|"
2870 ;; font-lock-beginning-of-syntax-function, can't use 3163 ;; font-lock-beginning-of-syntax-function, can't use
2871 ;; verilog-beg-of-defun. 3164 ;; verilog-beg-of-defun.
2872 nil 3165 nil
2873 'verilog-beg-of-defun))) 3166 'verilog-beg-of-defun)))
2874 ;;------------------------------------------------------------ 3167 ;;------------------------------------------------------------
2875 ;; now hook in 'verilog-colorize-include-files (eldo-mode.el&spice-mode.el) 3168 ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
2876 ;; all buffer local: 3169 ;; all buffer local:
2877 (when (featurep 'xemacs) 3170 (unless noninteractive ;; Else can't see the result, and change hooks are slow
2878 (make-local-hook 'font-lock-mode-hook) 3171 (when (featurep 'xemacs)
2879 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs 3172 (make-local-hook 'font-lock-mode-hook)
2880 (make-local-hook 'after-change-functions)) 3173 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
2881 (add-hook 'font-lock-mode-hook 'verilog-colorize-include-files-buffer t t) 3174 (make-local-hook 'after-change-functions))
2882 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-colorize-include-files-buffer t t) ; not in Emacs 3175 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
2883 (add-hook 'after-change-functions 'verilog-colorize-include-files 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))
2884 3178
2885 ;; Tell imenu how to handle Verilog. 3179 ;; Tell imenu how to handle Verilog.
2886 (make-local-variable 'imenu-generic-expression) 3180 (make-local-variable 'imenu-generic-expression)
2887 (setq imenu-generic-expression verilog-imenu-generic-expression) 3181 (setq imenu-generic-expression verilog-imenu-generic-expression)
2888 ;; Tell which-func-modes that imenu knows about verilog 3182 ;; Tell which-func-modes that imenu knows about verilog
3308 (defun verilog-beg-of-statement () 3602 (defun verilog-beg-of-statement ()
3309 "Move backward to beginning of statement." 3603 "Move backward to beginning of statement."
3310 (interactive) 3604 (interactive)
3311 ;; Move back token by token until we see the end 3605 ;; Move back token by token until we see the end
3312 ;; of some ealier line. 3606 ;; of some ealier line.
3313 (while 3607 (let (h)
3314 ;; If the current point does not begin a new 3608 (while
3315 ;; statement, as in the character ahead of us is a ';', or SOF 3609 ;; If the current point does not begin a new
3316 ;; or the string after us unambiguously starts a statement, 3610 ;; statement, as in the character ahead of us is a ';', or SOF
3317 ;; or the token before us unambiguously ends a statement, 3611 ;; or the string after us unambiguously starts a statement,
3318 ;; then move back a token and test again. 3612 ;; or the token before us unambiguously ends a statement,
3319 (not (or 3613 ;; then move back a token and test again.
3320 (bolp) 3614 (not (or
3321 (= (preceding-char) ?\;) 3615 ;; stop if beginning of buffer
3322 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)") 3616 (bolp)
3323 (not (or 3617 ;; stop if we find a ;
3324 (looking-at "\\<") 3618 (= (preceding-char) ?\;)
3325 (forward-word -1))) 3619 ;; stop if we see a named coverpoint
3326 (and 3620 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
3327 (looking-at verilog-complete-reg) 3621 ;; keep going if we are in the middle of a word
3328 (not (save-excursion 3622 (not (or (looking-at "\\<") (forward-word -1)))
3329 (verilog-backward-token) 3623 ;; stop if we see an assertion (perhaps labled)
3330 (looking-at verilog-extended-complete-re)))) 3624 (and
3331 (looking-at verilog-basic-complete-re) 3625 (looking-at "\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
3332 (save-excursion 3626 (progn
3333 (verilog-backward-token) 3627 (setq h (point))
3334 (or 3628 (save-excursion
3335 (looking-at verilog-end-block-re) 3629 (verilog-backward-token)
3336 (looking-at verilog-preprocessor-re))))) 3630 (if (looking-at verilog-label-re)
3631 (setq h (point))))
3632 (goto-char h)))
3633 ;; stop if we see a complete reg, perhaps an extended one
3634 (and
3635 (looking-at verilog-complete-reg)
3636 (let* ((p (point)))
3637 (while (and (looking-at verilog-extended-complete-re)
3638 (progn (setq p (point))
3639 (verilog-backward-token)
3640 (/= p (point)))))
3641 (goto-char p)))
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
3645 (save-excursion
3646 (verilog-backward-token)
3647 (or
3648 (looking-at verilog-end-block-re)
3649 (looking-at verilog-preprocessor-re))))) ;; end of test
3337 (verilog-backward-syntactic-ws) 3650 (verilog-backward-syntactic-ws)
3338 (verilog-backward-token)) 3651 (verilog-backward-token))
3339 ;; Now point is where the previous line ended. 3652 ;; Now point is where the previous line ended.
3340 (verilog-forward-syntactic-ws)) 3653 (verilog-forward-syntactic-ws)))
3341 3654
3342 (defun verilog-beg-of-statement-1 () 3655 (defun verilog-beg-of-statement-1 ()
3343 "Move backward to beginning of statement." 3656 "Move backward to beginning of statement."
3344 (interactive) 3657 (interactive)
3345 (if (verilog-in-comment-p) 3658 (if (verilog-in-comment-p)
3348 (catch 'done 3661 (catch 'done
3349 (while (not (looking-at verilog-complete-reg)) 3662 (while (not (looking-at verilog-complete-reg))
3350 (setq pt (point)) 3663 (setq pt (point))
3351 (verilog-backward-syntactic-ws) 3664 (verilog-backward-syntactic-ws)
3352 (if (or (bolp) 3665 (if (or (bolp)
3353 (= (preceding-char) ?\;)) 3666 (= (preceding-char) ?\;)
3667 (save-excursion
3668 (verilog-backward-token)
3669 (looking-at verilog-ends-re)))
3354 (progn 3670 (progn
3355 (goto-char pt) 3671 (goto-char pt)
3356 (throw 'done t)) 3672 (throw 'done t))
3357 (verilog-backward-token)))) 3673 (verilog-backward-token))))
3358 (verilog-forward-syntactic-ws))) 3674 (verilog-forward-syntactic-ws)))
3447 (throw 'found 1)) 3763 (throw 'found 1))
3448 (setq nest (1- nest))) 3764 (setq nest (1- nest)))
3449 (t 3765 (t
3450 (throw 'found (= nest 0))))))) 3766 (throw 'found (= nest 0)))))))
3451 nil))) 3767 nil)))
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)
3774 ))
3775
3452 (defun verilog-in-struct-region-p () 3776 (defun verilog-in-struct-region-p ()
3453 "Return true if in a struct region. 3777 "Return true if in a struct region.
3454 More specifically, in a list after a struct|union keyword." 3778 More specifically, in a list after a struct|union keyword."
3455 (interactive) 3779 (interactive)
3456 (save-excursion 3780 (save-excursion
3457 (let* ((state (verilog-syntax-ppss)) 3781 (let* ((state (verilog-syntax-ppss))
3458 (depth (nth 0 state))) 3782 (depth (nth 0 state)))
3459 (if depth 3783 (if depth
3460 (progn (backward-up-list depth) 3784 (progn (verilog-backward-up-list depth)
3461 (verilog-beg-of-statement) 3785 (verilog-beg-of-statement)
3462 (looking-at "\\<typedef\\>?\\s-*\\<struct\\|union\\>")))))) 3786 (looking-at "\\<typedef\\>?\\s-*\\<struct\\|union\\>"))))))
3463 3787
3464 (defun verilog-in-generate-region-p () 3788 (defun verilog-in-generate-region-p ()
3465 "Return true if in a generate region. 3789 "Return true if in a generate region.
3581 (defconst verilog-directive-nest-re 3905 (defconst verilog-directive-nest-re
3582 (concat "\\(`else\\>\\)\\|" 3906 (concat "\\(`else\\>\\)\\|"
3583 "\\(`endif\\>\\)\\|" 3907 "\\(`endif\\>\\)\\|"
3584 "\\(`if\\>\\)\\|" 3908 "\\(`if\\>\\)\\|"
3585 "\\(`ifdef\\>\\)\\|" 3909 "\\(`ifdef\\>\\)\\|"
3586 "\\(`ifndef\\>\\)")) 3910 "\\(`ifndef\\>\\)\\|"
3911 "\\(`elsif\\>\\)"))
3587 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment) 3912 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
3588 "Add ending comment with given INDENT-STR. 3913 "Add ending comment with given INDENT-STR.
3589 With KILL-EXISTING-COMMENT, remove what was there before. 3914 With KILL-EXISTING-COMMENT, remove what was there before.
3590 Insert `// case: 7 ' or `// NAME ' on this line if appropriate. 3915 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
3591 Insert `// case expr ' if this line ends a case block. 3916 Insert `// case expr ' if this line ends a case block.
3621 ((match-end 3) ; `if 3946 ((match-end 3) ; `if
3622 (setq nest (1- nest))) 3947 (setq nest (1- nest)))
3623 ((match-end 4) ; `ifdef 3948 ((match-end 4) ; `ifdef
3624 (setq nest (1- nest))) 3949 (setq nest (1- nest)))
3625 ((match-end 5) ; `ifndef 3950 ((match-end 5) ; `ifndef
3626 (setq nest (1- nest))))) 3951 (setq nest (1- nest)))
3952 ((match-end 6) ; `elsif
3953 (if (= nest 1)
3954 (progn
3955 (setq else "!")
3956 (setq nest 0))))))
3627 (if (match-end 0) 3957 (if (match-end 0)
3628 (setq 3958 (setq
3629 m (buffer-substring 3959 m (buffer-substring
3630 (match-beginning 0) 3960 (match-beginning 0)
3631 (match-end 0)) 3961 (match-end 0))
3638 (point))))) 3968 (point)))))
3639 (if b 3969 (if b
3640 (if (> (count-lines (point) b) verilog-minimum-comment-distance) 3970 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
3641 (insert (concat " // " else m " " (buffer-substring b e)))) 3971 (insert (concat " // " else m " " (buffer-substring b e))))
3642 (progn 3972 (progn
3643 (insert " // unmatched `else or `endif") 3973 (insert " // unmatched `else, `elsif or `endif")
3644 (ding 't))))) 3974 (ding 't)))))
3645 3975
3646 (; Comment close case/class/function/task/module and named block 3976 (; Comment close case/class/function/task/module and named block
3647 (and (looking-at "\\<end") 3977 (and (looking-at "\\<end")
3648 (or kill-existing-comment 3978 (or kill-existing-comment
3717 4047
3718 (;- try to find "reason" for this begin 4048 (;- try to find "reason" for this begin
3719 (cond 4049 (cond
3720 (; 4050 (;
3721 (eq here (progn 4051 (eq here (progn
3722 (verilog-backward-token) 4052 ;; (verilog-backward-token)
3723 (verilog-beg-of-statement-1) 4053 (verilog-beg-of-statement)
3724 (point))) 4054 (point)))
3725 (setq err nil) 4055 (setq err nil)
3726 (setq str "")) 4056 (setq str ""))
3727 ((looking-at verilog-endcomment-reason-re) 4057 ((looking-at verilog-endcomment-reason-re)
3728 (setq there (match-end 0)) 4058 (setq there (match-end 0))
3742 (setq str "")))) 4072 (setq str ""))))
3743 4073
3744 (;- else 4074 (;- else
3745 (match-end 2) 4075 (match-end 2)
3746 (let ((nest 0) 4076 (let ((nest 0)
3747 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")) 4077 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
3748 (catch 'skip 4078 (catch 'skip
3749 (while (verilog-re-search-backward reg nil 'move) 4079 (while (verilog-re-search-backward reg nil 'move)
3750 (cond 4080 (cond
3751 ((match-end 1) ; begin 4081 ((match-end 1) ; begin
3752 (setq nest (1- nest))) 4082 (setq nest (1- nest)))
3758 (goto-char (match-end 0)) 4088 (goto-char (match-end 0))
3759 (setq there (point)) 4089 (setq there (point))
3760 (setq err nil) 4090 (setq err nil)
3761 (setq str (verilog-get-expr)) 4091 (setq str (verilog-get-expr))
3762 (setq str (concat " // else: !if" str )) 4092 (setq str (concat " // else: !if" str ))
4093 (throw 'skip 1))))
4094 ((match-end 4)
4095 (if (= 0 nest)
4096 (progn
4097 (goto-char (match-end 0))
4098 (setq there (point))
4099 (setq err nil)
4100 (setq str (verilog-get-expr))
4101 (setq str (concat " // else: !assert " str ))
3763 (throw 'skip 1))))))))) 4102 (throw 'skip 1)))))))))
3764
3765 (;- end else 4103 (;- end else
3766 (match-end 3) 4104 (match-end 3)
3767 (goto-char there) 4105 (goto-char there)
3768 (let ((nest 0) 4106 (let ((nest 0)
3769 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")) 4107 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
3770 (catch 'skip 4108 (catch 'skip
3771 (while (verilog-re-search-backward reg nil 'move) 4109 (while (verilog-re-search-backward reg nil 'move)
3772 (cond 4110 (cond
3773 ((match-end 1) ; begin 4111 ((match-end 1) ; begin
3774 (setq nest (1- nest))) 4112 (setq nest (1- nest)))
3780 (goto-char (match-end 0)) 4118 (goto-char (match-end 0))
3781 (setq there (point)) 4119 (setq there (point))
3782 (setq err nil) 4120 (setq err nil)
3783 (setq str (verilog-get-expr)) 4121 (setq str (verilog-get-expr))
3784 (setq str (concat " // else: !if" str )) 4122 (setq str (concat " // else: !if" str ))
4123 (throw 'skip 1))))
4124 ((match-end 4)
4125 (if (= 0 nest)
4126 (progn
4127 (goto-char (match-end 0))
4128 (setq there (point))
4129 (setq err nil)
4130 (setq str (verilog-get-expr))
4131 (setq str (concat " // else: !assert " str ))
3785 (throw 'skip 1))))))))) 4132 (throw 'skip 1)))))))))
4133
3786 (; always_comb, always_ff, always_latch 4134 (; always_comb, always_ff, always_latch
3787 (or (match-end 4) (match-end 5) (match-end 6)) 4135 (or (match-end 4) (match-end 5) (match-end 6))
3788 (goto-char (match-end 0)) 4136 (goto-char (match-end 0))
3789 (setq there (point)) 4137 (setq there (point))
3790 (setq err nil) 4138 (setq err nil)
3913 (cond 4261 (cond
3914 ((match-end 1) 4262 ((match-end 1)
3915 (setq b (progn 4263 (setq b (progn
3916 (skip-chars-forward "^ \t") 4264 (skip-chars-forward "^ \t")
3917 (verilog-forward-ws&directives) 4265 (verilog-forward-ws&directives)
4266 (if (looking-at "static\\|automatic")
4267 (progn
4268 (goto-char (match-end 0))
4269 (verilog-forward-ws&directives)))
3918 (if (and name-re (verilog-re-search-forward name-re nil 'move)) 4270 (if (and name-re (verilog-re-search-forward name-re nil 'move))
3919 (progn 4271 (progn
3920 (goto-char (match-beginning 0)) 4272 (goto-char (match-beginning 0))
3921 (verilog-forward-ws&directives))) 4273 (verilog-forward-ws&directives)))
3922 (point)) 4274 (point))
4196 (interactive) 4548 (interactive)
4197 (verilog-auto) ; Always do it for safety 4549 (verilog-auto) ; Always do it for safety
4198 (save-buffer) 4550 (save-buffer)
4199 (compile compile-command)) 4551 (compile compile-command))
4200 4552
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`."
4557 (interactive
4558 (list
4559 (let ((default (verilog-expand-command verilog-preprocessor)))
4560 (set (make-local-variable `verilog-preprocessor)
4561 (read-from-minibuffer "Run Preprocessor (like this): "
4562 default nil nil
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*"
4569 (save-excursion
4570 (set-buffer "*Verilog-Preprocessed*")
4571 (insert (concat "// " cmd "\n"))
4572 (shell-command cmd "*Verilog-Preprocessed*")
4573 (verilog-mode)
4574 (font-lock-mode)))))
4201 4575
4202 4576
4203 ;; 4577 ;;
4204 ;; Batch 4578 ;; Batch
4205 ;; 4579 ;;
4338 (throw 'nesting 'comment)) 4712 (throw 'nesting 'comment))
4339 4713
4340 ;; if we have a directive, done. 4714 ;; if we have a directive, done.
4341 (if (save-excursion (beginning-of-line) 4715 (if (save-excursion (beginning-of-line)
4342 (and (looking-at verilog-directive-re-1) 4716 (and (looking-at verilog-directive-re-1)
4343 (not (or (looking-at "[ \t]*`ovm_") 4717 (not (or (looking-at "[ \t]*`ovm_")
4344 (looking-at "[ \t]*`vmm_"))))) 4718 (looking-at "[ \t]*`vmm_")))))
4345 (throw 'nesting 'directive)) 4719 (throw 'nesting 'directive))
4346 ;; indent structs as if there were module level 4720 ;; indent structs as if there were module level
4347 (if (verilog-in-struct-p) 4721 (if (verilog-in-struct-p)
4348 (throw 'nesting 'block)) 4722 (throw 'nesting 'block))
4402 (verilog-forward-syntactic-ws) 4776 (verilog-forward-syntactic-ws)
4403 (throw 'nesting 'statement))))) 4777 (throw 'nesting 'statement)))))
4404 ((match-end 3) ; assert block 4778 ((match-end 3) ; assert block
4405 (setq elsec (1- elsec)) 4779 (setq elsec (1- elsec))
4406 (verilog-beg-of-statement) ;; doesn't get to beginning 4780 (verilog-beg-of-statement) ;; doesn't get to beginning
4407 (if (looking-at (concat "\\(" verilog-label-re "\\)?" 4781 (if (looking-at verilog-property-re)
4408 "\\(assert\\|assume\\|cover\\)\\s-+property\\>"))
4409 (throw 'nesting 'statement) ; We don't need an endproperty for these 4782 (throw 'nesting 'statement) ; We don't need an endproperty for these
4410 (throw 'nesting 'block) ;We still need a endproperty 4783 (throw 'nesting 'block) ;We still need a endproperty
4411 )) 4784 ))
4412 (t ; endblock 4785 (t ; endblock
4413 ; try to leap back to matching outward block by striding across 4786 ; try to leap back to matching outward block by striding across
4530 (throw 'nesting 'case)) 4903 (throw 'nesting 'case))
4531 4904
4532 ((match-end 4) ; *sigh* could be "disable fork" 4905 ((match-end 4) ; *sigh* could be "disable fork"
4533 (let ((here (point))) 4906 (let ((here (point)))
4534 (verilog-beg-of-statement) 4907 (verilog-beg-of-statement)
4535 (if (looking-at verilog-disable-fork-re) 4908 (if (or (looking-at verilog-disable-fork-re)
4536 t ; is disable fork, this is a normal statement 4909 (looking-at verilog-fork-wait-re))
4910 t ; this is a normal statement
4537 (progn ; or is fork, starts a new block 4911 (progn ; or is fork, starts a new block
4538 (goto-char here) 4912 (goto-char here)
4539 (throw 'nesting 'block))))) 4913 (throw 'nesting 'block)))))
4540 4914
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
4920 (goto-char here)
4921 (throw 'nesting 'block)))))
4541 4922
4542 ;; need to consider typedef struct here... 4923 ;; need to consider typedef struct here...
4543 ((looking-at "\\<class\\|struct\\|function\\|task\\>") 4924 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
4544 ; *sigh* These words have an optional prefix: 4925 ; *sigh* These words have an optional prefix:
4545 ; extern {virtual|protected}? function a(); 4926 ; extern {virtual|protected}? function a();
4559 ; {assert|assume|cover} property (); are complete 4940 ; {assert|assume|cover} property (); are complete
4560 ; and could also be labeled: - foo: assert property 4941 ; and could also be labeled: - foo: assert property
4561 ; but 4942 ; but
4562 ; property ID () ... needs end_property 4943 ; property ID () ... needs end_property
4563 (verilog-beg-of-statement) 4944 (verilog-beg-of-statement)
4564 (if (looking-at (concat "\\(" verilog-label-re "\\)?" 4945 (if (looking-at verilog-property-re)
4565 "\\(assert\\|assume\\|cover\\)\\s-+property\\>"))
4566 (throw 'continue 'statement) ; We don't need an endproperty for these 4946 (throw 'continue 'statement) ; We don't need an endproperty for these
4567 (throw 'nesting 'block) ;We still need a endproperty 4947 (throw 'nesting 'block) ;We still need a endproperty
4568 )) 4948 ))
4569 4949
4570 (t (throw 'nesting 'block)))) 4950 (t (throw 'nesting 'block))))
4809 ; (b, ... which ISN'T complete 5189 ; (b, ... which ISN'T complete
4810 ;;;; Do we need this??? 5190 ;;;; Do we need this???
4811 (= (preceding-char) ?\)) 5191 (= (preceding-char) ?\))
4812 (progn 5192 (progn
4813 (backward-char) 5193 (backward-char)
4814 (backward-up-list 1) 5194 (verilog-backward-up-list 1)
4815 (verilog-backward-syntactic-ws) 5195 (verilog-backward-syntactic-ws)
4816 (let ((back (point))) 5196 (let ((back (point)))
4817 (forward-word -1) 5197 (forward-word -1)
4818 (cond 5198 (cond
4819 ;;XX 5199 ;;XX
4880 5260
4881 (t 5261 (t
4882 (goto-char back) 5262 (goto-char back)
4883 t)))))))) 5263 t))))))))
4884 5264
4885 (defun verilog-backward-syntactic-ws (&optional bound) 5265 (defun verilog-backward-syntactic-ws ()
4886 "Backward skip over syntactic whitespace for Emacs 19. 5266 (verilog-skip-backward-comments)
4887 Optional BOUND limits search." 5267 (forward-comment (- (buffer-size))))
4888 (save-restriction 5268
4889 (let* ((bound (or bound (point-min))) (here bound) ) 5269 (defun verilog-forward-syntactic-ws ()
4890 (if (< bound (point)) 5270 (verilog-skip-forward-comment-p)
4891 (progn 5271 (forward-comment (buffer-size)))
4892 (narrow-to-region bound (point))
4893 (while (/= here (point))
4894 (setq here (point))
4895 (verilog-skip-backward-comments))))))
4896 t)
4897
4898 (defun verilog-forward-syntactic-ws (&optional bound)
4899 "Forward skip over syntactic whitespace for Emacs 19.
4900 Optional BOUND limits search."
4901 (save-restriction
4902 (let* ((bound (or bound (point-max)))
4903 (here bound))
4904 (if (> bound (point))
4905 (progn
4906 (narrow-to-region (point) bound)
4907 (while (/= here (point))
4908 (setq here (point))
4909 (forward-comment (buffer-size))))))))
4910 5272
4911 (defun verilog-backward-ws&directives (&optional bound) 5273 (defun verilog-backward-ws&directives (&optional bound)
4912 "Backward skip over syntactic whitespace and compiler directives for Emacs 19. 5274 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
4913 Optional BOUND limits search." 5275 Optional BOUND limits search."
4914 (save-restriction 5276 (save-restriction
4951 (if (> bound (point)) 5313 (if (> bound (point))
4952 (progn 5314 (progn
4953 (let ((state (save-excursion (verilog-syntax-ppss)))) 5315 (let ((state (save-excursion (verilog-syntax-ppss))))
4954 (cond 5316 (cond
4955 ((nth 7 state) ;; in // comment 5317 ((nth 7 state) ;; in // comment
4956 (verilog-re-search-forward "//" nil 'move)) 5318 (end-of-line)
5319 (forward-char 1)
5320 (skip-chars-forward " \t\n\f")
5321 )
4957 ((nth 4 state) ;; in /* */ comment 5322 ((nth 4 state) ;; in /* */ comment
4958 (verilog-re-search-forward "/\*" nil 'move)))) 5323 (verilog-re-search-forward "\*\/\\s-*" nil 'move))))
4959 (narrow-to-region (point) bound) 5324 (narrow-to-region (point) bound)
4960 (while (/= here (point)) 5325 (while (/= here (point))
4961 (setq here (point) 5326 (setq here (point)
4962 jump nil) 5327 jump nil)
4963 (forward-comment (buffer-size)) 5328 (forward-comment (buffer-size))
5329 (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ;; Attribute
5330 (goto-char (match-end 0)))
4964 (save-excursion 5331 (save-excursion
4965 (beginning-of-line) 5332 (beginning-of-line)
4966 (if (looking-at verilog-directive-re-1) 5333 (if (looking-at verilog-directive-re-1)
4967 (setq jump t))) 5334 (setq jump t)))
4968 (if jump 5335 (if jump
4989 5356
4990 (defun verilog-in-comment-or-string-p () 5357 (defun verilog-in-comment-or-string-p ()
4991 "Return true if in a string or comment." 5358 "Return true if in a string or comment."
4992 (let ((state (save-excursion (verilog-syntax-ppss)))) 5359 (let ((state (save-excursion (verilog-syntax-ppss))))
4993 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment) 5360 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
5361
5362 (defun verilog-in-attribute-p ()
5363 "Return true if point is in an attribute (* [] attribute *)."
5364 (save-excursion
5365 (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
5366 (numberp (match-beginning 1))))
4994 5367
4995 (defun verilog-in-escaped-name-p () 5368 (defun verilog-in-escaped-name-p ()
4996 "Return true if in an escaped name." 5369 "Return true if in an escaped name."
4997 (save-excursion 5370 (save-excursion
4998 (backward-char) 5371 (backward-char)
4999 (skip-chars-backward "^ \t\n\f") 5372 (skip-chars-backward "^ \t\n\f")
5000 (if (equal (char-after (point) ) ?\\ ) 5373 (if (equal (char-after (point) ) ?\\ )
5001 t 5374 t
5002 nil))) 5375 nil)))
5003 (defun verilog-in-directive-p () 5376 (defun verilog-in-directive-p ()
5004 "Return true if in a star or // comment." 5377 "Return true if in a directive."
5005 (save-excursion 5378 (save-excursion
5006 (beginning-of-line) 5379 (beginning-of-line)
5007 (looking-at verilog-directive-re-1))) 5380 (looking-at verilog-directive-re-1)))
5008 5381
5009 (defun verilog-in-paren () 5382 (defun verilog-in-paren ()
5015 "Return true if in a struct declaration." 5388 "Return true if in a struct declaration."
5016 (interactive) 5389 (interactive)
5017 (save-excursion 5390 (save-excursion
5018 (if (verilog-in-paren) 5391 (if (verilog-in-paren)
5019 (progn 5392 (progn
5020 (backward-up-list 1) 5393 (verilog-backward-up-list 1)
5021 (verilog-at-struct-p) 5394 (verilog-at-struct-p)
5022 ) 5395 )
5023 nil))) 5396 nil)))
5024 5397
5025 (defun verilog-in-coverage-p () 5398 (defun verilog-in-coverage-p ()
5026 "Return true if in a constraint or coverpoint expression." 5399 "Return true if in a constraint or coverpoint expression."
5027 (interactive) 5400 (interactive)
5028 (save-excursion 5401 (save-excursion
5029 (if (verilog-in-paren) 5402 (if (verilog-in-paren)
5030 (progn 5403 (progn
5031 (backward-up-list 1) 5404 (verilog-backward-up-list 1)
5032 (verilog-at-constraint-p) 5405 (verilog-at-constraint-p)
5033 ) 5406 )
5034 nil))) 5407 nil)))
5035 (defun verilog-at-close-constraint-p () 5408 (defun verilog-at-close-constraint-p ()
5036 "If at the } that closes a constraint or covergroup, return true." 5409 "If at the } that closes a constraint or covergroup, return true."
5121 t) 5494 t)
5122 ((and (not (bobp)) 5495 ((and (not (bobp))
5123 (= (char-before) ?\/) 5496 (= (char-before) ?\/)
5124 (= (char-before (1- (point))) ?\*)) 5497 (= (char-before (1- (point))) ?\*))
5125 (goto-char (- (point) 2)) 5498 (goto-char (- (point) 2))
5126 t) 5499 t) ;; Let nth 4 state handle the rest
5500 ((and (not (bobp))
5501 (= (char-before) ?\))
5502 (= (char-before (1- (point))) ?\*))
5503 (goto-char (- (point) 2))
5504 (if (search-backward "(*" nil t)
5505 (progn
5506 (skip-chars-backward " \t\n\f")
5507 t)
5508 (progn
5509 (goto-char (+ (point) 2))
5510 nil)))
5127 (t 5511 (t
5128 (skip-chars-backward " \t\n\f") 5512 (/= (skip-chars-backward " \t\n\f") 0))))))))
5129 nil)))))))
5130 5513
5131 (defun verilog-skip-forward-comment-p () 5514 (defun verilog-skip-forward-comment-p ()
5132 "If in comment, move to end and return true." 5515 "If in comment, move to end and return true."
5133 (let (state) 5516 (let* (h
5134 (progn 5517 (state (save-excursion (verilog-syntax-ppss)))
5135 (setq state (save-excursion (verilog-syntax-ppss))) 5518 (skip (cond
5136 (cond 5519 ((nth 3 state) ;Inside string
5137 ((nth 3 state) 5520 t)
5138 t) 5521 ((nth 7 state) ;Inside // comment
5139 ((nth 7 state) ;Inside // comment 5522 (end-of-line)
5140 (end-of-line) 5523 (forward-char 1)
5141 (forward-char 1) 5524 t)
5142 t) 5525 ((nth 4 state) ;Inside /* comment
5143 ((nth 4 state) ;Inside any comment 5526 (search-forward "*/")
5144 t) 5527 t)
5145 (t 5528 ((verilog-in-attribute-p) ;Inside (* attribute
5146 nil))))) 5529 (search-forward "*)" nil t)
5530 t)
5531 (t nil))))
5532 (skip-chars-forward " \t\n\f")
5533 (while
5534 (cond
5535 ((looking-at "\\/\\*")
5536 (progn
5537 (setq h (point))
5538 (goto-char (match-end 0))
5539 (if (search-forward "*/" nil t)
5540 (progn
5541 (skip-chars-forward " \t\n\f")
5542 (setq skip 't))
5543 (progn
5544 (goto-char h)
5545 nil))))
5546 ((looking-at "(\\*")
5547 (progn
5548 (setq h (point))
5549 (goto-char (match-end 0))
5550 (if (search-forward "*)" nil t)
5551 (progn
5552 (skip-chars-forward " \t\n\f")
5553 (setq skip 't))
5554 (progn
5555 (goto-char h)
5556 nil))))
5557 (t nil)))
5558 skip))
5147 5559
5148 (defun verilog-indent-line-relative () 5560 (defun verilog-indent-line-relative ()
5149 "Cheap version of indent line. 5561 "Cheap version of indent line.
5150 Only look at a few lines to determine indent level." 5562 Only look at a few lines to determine indent level."
5151 (interactive) 5563 (interactive)
5208 (forward-word 1) 5620 (forward-word 1)
5209 (skip-chars-forward " \t"))) 5621 (skip-chars-forward " \t")))
5210 ((= (following-char) ?\[) 5622 ((= (following-char) ?\[)
5211 (progn 5623 (progn
5212 (forward-char 1) 5624 (forward-char 1)
5213 (backward-up-list -1) 5625 (verilog-backward-up-list -1)
5214 (skip-chars-forward " \t")))) 5626 (skip-chars-forward " \t"))))
5215 (current-column)) 5627 (current-column))
5216 (progn 5628 (progn
5217 (goto-char fst) 5629 (goto-char fst)
5218 (+ (current-column) verilog-cexp-indent)))))) 5630 (+ (current-column) verilog-cexp-indent))))))
5233 (goto-char here) 5645 (goto-char here)
5234 (indent-line-to val)))))) 5646 (indent-line-to val))))))
5235 5647
5236 (; handle inside parenthetical expressions 5648 (; handle inside parenthetical expressions
5237 (eq type 'cparenexp) 5649 (eq type 'cparenexp)
5238 (let ((val (save-excursion 5650 (let* ( here
5239 (backward-up-list 1) 5651 (val (save-excursion
5240 (forward-char 1) 5652 (verilog-backward-up-list 1)
5241 (skip-chars-forward " \t") 5653 (forward-char 1)
5242 (current-column)))) 5654 (if verilog-indent-lists
5243 (indent-line-to val) 5655 (skip-chars-forward " \t")
5244 )) 5656 (verilog-forward-syntactic-ws))
5657 (setq here (point))
5658 (current-column)))
5659
5660 (decl (save-excursion
5661 (goto-char here)
5662 (verilog-forward-syntactic-ws)
5663 (setq here (point))
5664 (looking-at verilog-declaration-re))))
5665 (indent-line-to val)
5666 (if decl
5667 (verilog-pretty-declarations))))
5245 5668
5246 (;-- Handle the ends 5669 (;-- Handle the ends
5247 (or 5670 (or
5248 (looking-at verilog-end-block-re ) 5671 (looking-at verilog-end-block-re )
5249 (verilog-at-close-constraint-p)) 5672 (verilog-at-close-constraint-p))
5374 5797
5375 (defun verilog-pretty-declarations (&optional quiet) 5798 (defun verilog-pretty-declarations (&optional quiet)
5376 "Line up declarations around point. 5799 "Line up declarations around point.
5377 Be verbose about progress unless optional QUIET set." 5800 Be verbose about progress unless optional QUIET set."
5378 (interactive) 5801 (interactive)
5379 (save-excursion 5802 (let* ((m1 (make-marker))
5380 (if (progn 5803 (e (point))
5381 (verilog-beg-of-statement-1) 5804 el
5382 (and (not (verilog-in-directive-p)) ;; could have `define input foo 5805 r
5383 (not (verilog-parenthesis-depth)) ;; could be in a #(param block ) 5806 (here (point))
5807 ind
5808 start
5809 startpos
5810 end
5811 endpos
5812 base-ind
5813 )
5814 (save-excursion
5815 (if (progn
5816 ; (verilog-beg-of-statement-1)
5817 (beginning-of-line)
5818 (verilog-forward-syntactic-ws)
5819 (and (not (verilog-in-directive-p)) ;; could have `define input foo
5384 (looking-at verilog-declaration-re))) 5820 (looking-at verilog-declaration-re)))
5385 (let* ((m1 (make-marker)) 5821 (progn
5386 (e (point)) 5822 (if (verilog-parenthesis-depth)
5387 (r) 5823 ;; in an argument list or parameter block
5388 (here (point)) 5824 (setq el (verilog-backward-up-list -1)
5389 ;; Start of declaration range 5825 start (progn
5390 (start 5826 (goto-char e)
5391 (progn 5827 (verilog-backward-up-list 1)
5392 (verilog-beg-of-statement-1) 5828 (forward-line) ;; ignore ( input foo,
5393 (while (and (looking-at verilog-declaration-re) 5829 (verilog-re-search-forward verilog-declaration-re el 'move)
5394 (not (bobp))) 5830 (goto-char (match-beginning 0))
5395 (skip-chars-backward " \t") 5831 (skip-chars-backward " \t")
5396 (setq e (point)) 5832 (point))
5397 (beginning-of-line) 5833 startpos (set-marker (make-marker) start)
5398 (verilog-backward-syntactic-ws) 5834 end (progn
5399 (backward-char) 5835 (goto-char start)
5400 (verilog-beg-of-statement-1)) 5836 (verilog-backward-up-list -1)
5401 e)) 5837 (forward-char -1)
5402 ;; End of declaration range 5838 (verilog-backward-syntactic-ws)
5403 (end 5839 (point))
5404 (progn 5840 endpos (set-marker (make-marker) end)
5405 (goto-char here) 5841 base-ind (progn
5406 (verilog-end-of-statement) 5842 (goto-char start)
5407 (setq e (point)) ;Might be on last line 5843 (forward-char 1)
5408 (verilog-forward-syntactic-ws) 5844 (skip-chars-forward " \t")
5409 (while (looking-at verilog-declaration-re) 5845 (current-column))
5410 ;;(beginning-of-line) 5846 )
5411 (verilog-end-of-statement) 5847 ;; in a declaration block (not in argument list)
5412 (setq e (point)) 5848 (setq
5413 (verilog-forward-syntactic-ws)) 5849 start (progn
5414 e)) 5850 (verilog-beg-of-statement-1)
5415 (edpos (set-marker (make-marker) end)) 5851 (while (and (looking-at verilog-declaration-re)
5416 (ind) 5852 (not (bobp)))
5417 (base-ind 5853 (skip-chars-backward " \t")
5418 (progn 5854 (setq e (point))
5419 (goto-char start) 5855 (beginning-of-line)
5420 (verilog-do-indent (verilog-calculate-indent)) 5856 (verilog-backward-syntactic-ws)
5421 (verilog-forward-ws&directives) 5857 (backward-char)
5422 (current-column)))) 5858 (verilog-beg-of-statement-1))
5423 (goto-char start) 5859 e)
5424 (if (and (not quiet) 5860 startpos (set-marker (make-marker) start)
5425 (> (- end start) 100)) 5861 end (progn
5426 (message "Lining up declarations..(please stand by)")) 5862 (goto-char here)
5427 ;; Get the beginning of line indent first 5863 (verilog-end-of-statement)
5428 (while (progn (setq e (marker-position edpos)) 5864 (setq e (point)) ;Might be on last line
5429 (< (point) e)) 5865 (verilog-forward-syntactic-ws)
5430 (cond 5866 (while (looking-at verilog-declaration-re)
5431 ( (save-excursion (skip-chars-backward " \t") 5867 (verilog-end-of-statement)
5432 (bolp)) 5868 (setq e (point))
5433 (verilog-forward-ws&directives) 5869 (verilog-forward-syntactic-ws))
5434 (indent-line-to base-ind) 5870 e)
5435 (verilog-forward-ws&directives) 5871 endpos (set-marker (make-marker) end)
5436 (verilog-re-search-forward "[ \t\n\f]" e 'move)) 5872 base-ind (progn
5437 (t 5873 (goto-char start)
5438 (just-one-space) 5874 (verilog-do-indent (verilog-calculate-indent))
5439 (verilog-re-search-forward "[ \t\n\f]" e 'move))) 5875 (verilog-forward-ws&directives)
5440 ;;(forward-line) 5876 (current-column))))
5441 ) 5877 ;; OK, start and end are set
5442 ;; Now find biggest prefix 5878 (goto-char (marker-position startpos))
5443 (setq ind (verilog-get-lineup-indent start edpos)) 5879 (if (and (not quiet)
5444 ;; Now indent each line. 5880 (> (- end start) 100))
5445 (goto-char start) 5881 (message "Lining up declarations..(please stand by)"))
5446 (while (progn (setq e (marker-position edpos)) 5882 ;; Get the beginning of line indent first
5447 (setq r (- e (point))) 5883 (while (progn (setq e (marker-position endpos))
5448 (> r 0)) 5884 (< (point) e))
5449 (setq e (point)) 5885 (cond
5450 (unless quiet (message "%d" r)) 5886 ((save-excursion (skip-chars-backward " \t")
5451 (verilog-indent-line) 5887 (bolp))
5452 (cond 5888 (verilog-forward-ws&directives)
5453 ((or (and verilog-indent-declaration-macros 5889 (indent-line-to base-ind)
5454 (looking-at verilog-declaration-re-2-macro)) 5890 (verilog-forward-ws&directives)
5455 (looking-at verilog-declaration-re-2-no-macro)) 5891 (if (< (point) e)
5456 (let ((p (match-end 0))) 5892 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
5457 (set-marker m1 p) 5893 (t
5458 (if (verilog-re-search-forward "[[#`]" p 'move) 5894 (just-one-space)
5459 (progn 5895 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
5460 (forward-char -1) 5896 ;;(forward-line)
5461 (just-one-space) 5897 )
5462 (goto-char (marker-position m1)) 5898 ;; Now find biggest prefix
5463 (just-one-space) 5899 (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
5464 (indent-to ind)) 5900 ;; Now indent each line.
5465 (progn 5901 (goto-char (marker-position startpos))
5466 (just-one-space) 5902 (while (progn (setq e (marker-position endpos))
5467 (indent-to ind))))) 5903 (setq r (- e (point)))
5468 ((verilog-continued-line-1 start) 5904 (> r 0))
5469 (goto-char e) 5905 (setq e (point))
5470 (indent-line-to ind)) 5906 (unless quiet (message "%d" r))
5471 ((verilog-in-struct-p) 5907 ;;(verilog-do-indent (verilog-calculate-indent)))
5472 ;; could have a declaration of a user defined item 5908 (verilog-forward-ws&directives)
5473 (goto-char e) 5909 (cond
5474 (verilog-end-of-statement)) 5910 ((or (and verilog-indent-declaration-macros
5475 (t ; Must be comment or white space 5911 (looking-at verilog-declaration-re-2-macro))
5476 (goto-char e) 5912 (looking-at verilog-declaration-re-2-no-macro))
5477 (verilog-forward-ws&directives) 5913 (let ((p (match-end 0)))
5478 (forward-line -1))) 5914 (set-marker m1 p)
5479 (forward-line 1)) 5915 (if (verilog-re-search-forward "[[#`]" p 'move)
5480 (unless quiet (message "")))))) 5916 (progn
5917 (forward-char -1)
5918 (just-one-space)
5919 (goto-char (marker-position m1))
5920 (just-one-space)
5921 (indent-to ind))
5922 (progn
5923 (just-one-space)
5924 (indent-to ind)))))
5925 ((verilog-continued-line-1 (marker-position startpos))
5926 (goto-char e)
5927 (indent-line-to ind))
5928 ((verilog-in-struct-p)
5929 ;; could have a declaration of a user defined item
5930 (goto-char e)
5931 (verilog-end-of-statement))
5932 (t ; Must be comment or white space
5933 (goto-char e)
5934 (verilog-forward-ws&directives)
5935 (forward-line -1)))
5936 (forward-line 1))
5937 (unless quiet (message "")))))))
5481 5938
5482 (defun verilog-pretty-expr (&optional quiet myre) 5939 (defun verilog-pretty-expr (&optional quiet myre)
5483 "Line up expressions around point, optionally QUIET with regexp MYRE." 5940 "Line up expressions around point, optionally QUIET with regexp MYRE."
5484 (interactive "sRegular Expression: ((<|:)?=) ") 5941 (interactive "i\nsRegular Expression: ((<|:)?=) ")
5485 (save-excursion 5942 (save-excursion
5486 (if (or (eq myre nil) 5943 (if (or (eq myre nil)
5487 (string-equal myre "")) 5944 (string-equal myre ""))
5488 (setq myre "\\(<\\|:\\)?=")) 5945 (setq myre "\\(<\\|:\\)?="))
5489 (setq myre (concat "\\(^[^;#:<=>]*\\)\\(" myre "\\)")) 5946 ;; want to match the first <= | := | =
5947 (setq myre (concat "\\(^.*?\\)\\(" myre "\\)"))
5490 (let ((rexp(concat "^\\s-*" verilog-complete-reg))) 5948 (let ((rexp(concat "^\\s-*" verilog-complete-reg)))
5491 (beginning-of-line) 5949 (beginning-of-line)
5492 (if (and (not (looking-at rexp )) 5950 (if (and (not (looking-at rexp ))
5493 (looking-at myre) 5951 (looking-at myre)
5494 (save-excursion 5952 (save-excursion
5527 (setq e (point)) 5985 (setq e (point))
5528 (verilog-forward-syntactic-ws) 5986 (verilog-forward-syntactic-ws)
5529 (beginning-of-line) 5987 (beginning-of-line)
5530 ) 5988 )
5531 e)) 5989 e))
5532 (edpos (set-marker (make-marker) end)) 5990 (endpos (set-marker (make-marker) end))
5533 (ind) 5991 (ind)
5534 ) 5992 )
5535 (goto-char start) 5993 (goto-char start)
5536 (verilog-do-indent (verilog-calculate-indent)) 5994 (verilog-do-indent (verilog-calculate-indent))
5537 (if (and (not quiet) 5995 (if (and (not quiet)
5538 (> (- end start) 100)) 5996 (> (- end start) 100))
5539 (message "Lining up expressions..(please stand by)")) 5997 (message "Lining up expressions..(please stand by)"))
5540 5998
5541 ;; Set indent to minimum throughout region 5999 ;; Set indent to minimum throughout region
5542 (while (< (point) (marker-position edpos)) 6000 (while (< (point) (marker-position endpos))
5543 (beginning-of-line) 6001 (beginning-of-line)
5544 (verilog-just-one-space myre) 6002 (verilog-just-one-space myre)
5545 (end-of-line) 6003 (end-of-line)
5546 (verilog-forward-syntactic-ws) 6004 (verilog-forward-syntactic-ws)
5547 ) 6005 )
5548 6006
5549 ;; Now find biggest prefix 6007 ;; Now find biggest prefix
5550 (setq ind (verilog-get-lineup-indent-2 myre start edpos)) 6008 (setq ind (verilog-get-lineup-indent-2 myre start endpos))
5551 6009
5552 ;; Now indent each line. 6010 ;; Now indent each line.
5553 (goto-char start) 6011 (goto-char start)
5554 (while (progn (setq e (marker-position edpos)) 6012 (while (progn (setq e (marker-position endpos))
5555 (setq r (- e (point))) 6013 (setq r (- e (point)))
5556 (> r 0)) 6014 (> r 0))
5557 (setq e (point)) 6015 (setq e (point))
5558 (if (not quiet) (message "%d" r)) 6016 (if (not quiet) (message "%d" r))
5559 (cond 6017 (cond
5677 (if (> ind 0) 6135 (if (> ind 0)
5678 (1+ ind) 6136 (1+ ind)
5679 ;; No lineup-string found 6137 ;; No lineup-string found
5680 (goto-char b) 6138 (goto-char b)
5681 (end-of-line) 6139 (end-of-line)
5682 (skip-chars-backward " \t") 6140 (verilog-backward-syntactic-ws)
6141 ;;(skip-chars-backward " \t")
5683 (1+ (current-column)))))) 6142 (1+ (current-column))))))
5684 6143
5685 (defun verilog-get-lineup-indent-2 (myre b edpos) 6144 (defun verilog-get-lineup-indent-2 (myre b edpos)
5686 "Return the indent level that will line up several lines within the region." 6145 "Return the indent level that will line up several lines within the region."
5687 (save-excursion 6146 (save-excursion
5745 6204
5746 (defvar verilog-type-keywords 6205 (defvar verilog-type-keywords
5747 '( 6206 '(
5748 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input" 6207 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
5749 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" 6208 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
5750 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pullup" 6209 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
5751 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0" 6210 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
5752 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1" 6211 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5753 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor" 6212 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
5754 ) 6213 )
5755 "*Keywords for types used when completing a word in a declaration or parmlist. 6214 "*Keywords for types used when completing a word in a declaration or parmlist.
5806 '("else" "then" "begin") 6265 '("else" "then" "begin")
5807 "*Keywords to complete when NOT standing at the first word of a statement. 6266 "*Keywords to complete when NOT standing at the first word of a statement.
5808 \(else, then, begin...) 6267 \(else, then, begin...)
5809 Variables and function names defined within the Verilog program 6268 Variables and function names defined within the Verilog program
5810 will be completed at runtime and should not be added to this list.") 6269 will be completed at runtime and should not be added to this list.")
6270
6271 (defvar verilog-gate-ios
6272 ;; All these have an implied {"input"...} at the end
6273 '(("and" "output")
6274 ("buf" "output")
6275 ("bufif0" "output")
6276 ("bufif1" "output")
6277 ("cmos" "output")
6278 ("nand" "output")
6279 ("nmos" "output")
6280 ("nor" "output")
6281 ("not" "output")
6282 ("notif0" "output")
6283 ("notif1" "output")
6284 ("or" "output")
6285 ("pmos" "output")
6286 ("pulldown" "output")
6287 ("pullup" "output")
6288 ("rcmos" "output")
6289 ("rnmos" "output")
6290 ("rpmos" "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")
6297 ("xnor" "output")
6298 ("xor" "output"))
6299 "*Map of direction for each positional argument to each gate primitive.")
6300
6301 (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
6302 "*Keywords for gate primitives.")
5811 6303
5812 (defun verilog-string-diff (str1 str2) 6304 (defun verilog-string-diff (str1 str2)
5813 "Return index of first letter where STR1 and STR2 differs." 6305 "Return index of first letter where STR1 and STR2 differs."
5814 (catch 'done 6306 (catch 'done
5815 (let ((diff 0)) 6307 (let ((diff 0))
6137 6629
6138 ;; Now we have built a list of all matches. Give response to caller 6630 ;; Now we have built a list of all matches. Give response to caller
6139 (verilog-completion-response)))) 6631 (verilog-completion-response))))
6140 6632
6141 (defun verilog-goto-defun () 6633 (defun verilog-goto-defun ()
6142 "Move to specified Verilog module/task/function. 6634 "Move to specified Verilog module/interface/task/function.
6143 The default is a name found in the buffer around point. 6635 The default is a name found in the buffer around point.
6144 If search fails, other files are checked based on 6636 If search fails, other files are checked based on
6145 `verilog-library-flags'." 6637 `verilog-library-flags'."
6146 (interactive) 6638 (interactive)
6147 (let* ((default (verilog-get-default-symbol)) 6639 (let* ((default (verilog-get-default-symbol))
6381 ;; 6873 ;;
6382 ;; Signal list parsing 6874 ;; Signal list parsing
6383 ;; 6875 ;;
6384 6876
6385 ;; Elements of a signal list 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))
6386 (defsubst verilog-sig-name (sig) 6880 (defsubst verilog-sig-name (sig)
6387 (car sig)) 6881 (car sig))
6388 (defsubst verilog-sig-bits (sig) 6882 (defsubst verilog-sig-bits (sig)
6389 (nth 1 sig)) 6883 (nth 1 sig))
6390 (defsubst verilog-sig-comment (sig) 6884 (defsubst verilog-sig-comment (sig)
6409 (defsubst verilog-sig-modport (sig) 6903 (defsubst verilog-sig-modport (sig)
6410 (nth 8 sig)) 6904 (nth 8 sig))
6411 (defsubst verilog-sig-width (sig) 6905 (defsubst verilog-sig-width (sig)
6412 (verilog-make-width-expression (verilog-sig-bits sig))) 6906 (verilog-make-width-expression (verilog-sig-bits sig)))
6413 6907
6908 (defsubst verilog-alw-new (outputs temps inputs delayed)
6909 (list outputs temps inputs delayed))
6910 (defsubst verilog-alw-get-outputs (sigs)
6911 (nth 0 sigs))
6912 (defsubst verilog-alw-get-temps (sigs)
6913 (nth 1 sigs))
6414 (defsubst verilog-alw-get-inputs (sigs) 6914 (defsubst verilog-alw-get-inputs (sigs)
6415 (nth 2 sigs)) 6915 (nth 2 sigs))
6416 (defsubst verilog-alw-get-outputs (sigs)
6417 (nth 0 sigs))
6418 (defsubst verilog-alw-get-uses-delayed (sigs) 6916 (defsubst verilog-alw-get-uses-delayed (sigs)
6419 (nth 3 sigs)) 6917 (nth 3 sigs))
6918
6919 (defsubst verilog-modi-new (name fob pt type)
6920 (vector name fob pt type))
6921 (defsubst verilog-modi-name (modi)
6922 (aref modi 0))
6923 (defsubst verilog-modi-file-or-buffer (modi)
6924 (aref modi 1))
6925 (defsubst verilog-modi-get-point (modi)
6926 (aref modi 2))
6927 (defsubst verilog-modi-get-type (modi) ;; "module" or "interface"
6928 (aref modi 3))
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))
6933
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)
6939 (aref decls 0))
6940 (defsubst verilog-decls-get-inouts (decls)
6941 (aref decls 1))
6942 (defsubst verilog-decls-get-inputs (decls)
6943 (aref decls 2))
6944 (defsubst verilog-decls-get-wires (decls)
6945 (aref decls 3))
6946 (defsubst verilog-decls-get-regs (decls)
6947 (aref decls 4))
6948 (defsubst verilog-decls-get-assigns (decls)
6949 (aref decls 5))
6950 (defsubst verilog-decls-get-consts (decls)
6951 (aref decls 6))
6952 (defsubst verilog-decls-get-gparams (decls)
6953 (aref decls 7))
6954 (defsubst verilog-decls-get-interfaces (decls)
6955 (aref decls 8))
6956
6957 (defsubst verilog-subdecls-new (out inout in intf intfd)
6958 (vector out inout in intf intfd))
6959 (defsubst verilog-subdecls-get-outputs (subdecls)
6960 (aref subdecls 0))
6961 (defsubst verilog-subdecls-get-inouts (subdecls)
6962 (aref subdecls 1))
6963 (defsubst verilog-subdecls-get-inputs (subdecls)
6964 (aref subdecls 2))
6965 (defsubst verilog-subdecls-get-interfaces (subdecls)
6966 (aref subdecls 3))
6967 (defsubst verilog-subdecls-get-interfaced (subdecls)
6968 (aref subdecls 4))
6420 6969
6421 (defun verilog-signals-not-in (in-list not-list) 6970 (defun verilog-signals-not-in (in-list not-list)
6422 "Return list of signals in IN-LIST that aren't also in NOT-LIST. 6971 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
6423 Also remove any duplicates in IN-LIST. 6972 Also remove any duplicates in IN-LIST.
6424 Signals must be in standard (base vector) form." 6973 Signals must be in standard (base vector) form."
6425 (let (out-list) 6974 ;; This function is hot, so implemented as O(1)
6426 (while in-list 6975 (cond ((eval-when-compile (fboundp 'make-hash-table))
6427 (if (not (or (assoc (car (car in-list)) not-list) 6976 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
6428 (assoc (car (car in-list)) out-list))) 6977 out-list)
6429 (setq out-list (cons (car in-list) out-list))) 6978 (while not-list
6430 (setq in-list (cdr in-list))) 6979 (puthash (car (car not-list)) t ht)
6431 (nreverse out-list))) 6980 (setq not-list (cdr not-list)))
6981 (while in-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)
6988 (t
6989 (let (out-list)
6990 (while in-list
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)))))
6432 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" ""))) 6996 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
6433
6434 (defun verilog-signals-in (in-list other-list)
6435 "Return list of signals in IN-LIST that are also in OTHER-LIST.
6436 Signals must be in standard (base vector) form."
6437 (let (out-list)
6438 (while in-list
6439 (if (assoc (car (car in-list)) other-list)
6440 (setq out-list (cons (car in-list) out-list)))
6441 (setq in-list (cdr in-list)))
6442 (nreverse out-list)))
6443 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
6444 6997
6445 (defun verilog-signals-memory (in-list) 6998 (defun verilog-signals-memory (in-list)
6446 "Return list of signals in IN-LIST that are memoried (multidimensional)." 6999 "Return list of signals in IN-LIST that are memoried (multidimensional)."
6447 (let (out-list) 7000 (let (out-list)
6448 (while in-list 7001 (while in-list
6533 sv-modport (or sv-modport (verilog-sig-modport sig)))) 7086 sv-modport (or sv-modport (verilog-sig-modport sig))))
6534 ;; Doesn't match next signal, add to queue, zero in prep for next 7087 ;; Doesn't match next signal, add to queue, zero in prep for next
6535 ;; Note sig may also be nil for the last signal in the list 7088 ;; Note sig may also be nil for the last signal in the list
6536 (t 7089 (t
6537 (setq out-list 7090 (setq out-list
6538 (cons 7091 (cons (verilog-sig-new
6539 (list sv-name 7092 sv-name
6540 (or sv-busstring 7093 (or sv-busstring
6541 (if sv-highbit 7094 (if sv-highbit
6542 (concat "[" (int-to-string sv-highbit) ":" 7095 (concat "[" (int-to-string sv-highbit) ":"
6543 (int-to-string sv-lowbit) "]"))) 7096 (int-to-string sv-lowbit) "]")))
6544 (concat sv-comment combo buswarn) 7097 (concat sv-comment combo buswarn)
6545 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport) 7098 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
6546 out-list) 7099 out-list)
6547 sv-name nil)))) 7100 sv-name nil))))
6548 ;; 7101 ;;
6549 out-list)) 7102 out-list))
6550 7103
6551 (defun verilog-sig-tieoff (sig &optional no-width) 7104 (defun verilog-sig-tieoff (sig &optional no-width)
6579 (while (looking-at "\\]") 7132 (while (looking-at "\\]")
6580 (verilog-backward-open-bracket) 7133 (verilog-backward-open-bracket)
6581 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil)) 7134 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil))
6582 (skip-chars-backward "a-zA-Z0-9`_$")) 7135 (skip-chars-backward "a-zA-Z0-9`_$"))
6583 7136
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
7151 )
7152
6584 (defun verilog-read-inst-module () 7153 (defun verilog-read-inst-module ()
6585 "Return module_name when point is inside instantiation." 7154 "Return module_name when point is inside instantiation."
6586 (save-excursion 7155 (save-excursion
6587 (verilog-read-inst-backward-name) 7156 (verilog-read-inst-module-matcher)))
6588 ;; Skip over instantiation name
6589 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
6590 ;; Check for parameterized instantiations
6591 (when (looking-at ")")
6592 (verilog-backward-open-paren)
6593 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil))
6594 (skip-chars-backward "a-zA-Z0-9'_$")
6595 (looking-at "[a-zA-Z0-9`_\$]+")
6596 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
6597 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
6598 7157
6599 (defun verilog-read-inst-name () 7158 (defun verilog-read-inst-name ()
6600 "Return instance_name when point is inside instantiation." 7159 "Return instance_name when point is inside instantiation."
6601 (save-excursion 7160 (save-excursion
6602 (verilog-read-inst-backward-name) 7161 (verilog-read-inst-backward-name)
6664 (defun verilog-read-decls () 7223 (defun verilog-read-decls ()
6665 "Compute signal declaration information for the current module at point. 7224 "Compute signal declaration information for the current module at point.
6666 Return a array of [outputs inouts inputs wire reg assign const]." 7225 Return a array of [outputs inouts inputs wire reg assign const]."
6667 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max))) 7226 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
6668 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t) 7227 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
7228 in-modport
6669 sigs-in sigs-out sigs-inout sigs-wire sigs-reg sigs-assign sigs-const 7229 sigs-in sigs-out sigs-inout sigs-wire sigs-reg sigs-assign sigs-const
6670 sigs-gparam sigs-intf 7230 sigs-gparam sigs-intf
6671 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim 7231 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
6672 modport) 7232 modport)
6673 (save-excursion 7233 (save-excursion
6674 (verilog-beg-of-defun) 7234 (verilog-beg-of-defun)
6675 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point)) 7235 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
6676 (while (< (point) end-mod-point) 7236 (while (< (point) end-mod-point)
6677 ;;(if dbg (setq dbg (cons (format "Pt %s Vec %s Kwd'%s'\n" (point) vec keywd) dbg))) 7237 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
6678 (cond 7238 (cond
6679 ((looking-at "//") 7239 ((looking-at "//")
6680 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") 7240 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
6681 (setq enum (match-string 1))) 7241 (setq enum (match-string 1)))
6682 (search-forward "\n")) 7242 (search-forward "\n"))
6683 ((looking-at "/\\*") 7243 ((looking-at "/\\*")
6684 (forward-char 2) 7244 (forward-char 2)
6685 (if (looking-at "[^*]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") 7245 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
6686 (setq enum (match-string 1))) 7246 (setq enum (match-string 1)))
6687 (or (search-forward "*/") 7247 (or (search-forward "*/")
6688 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) 7248 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
6689 ((looking-at "(\\*") 7249 ((looking-at "(\\*")
6690 (forward-char 2) 7250 (forward-char 2)
6694 ((eq ?\" (following-char)) 7254 ((eq ?\" (following-char))
6695 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first 7255 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first
6696 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point)))) 7256 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
6697 ((eq ?\; (following-char)) 7257 ((eq ?\; (following-char))
6698 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil 7258 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
6699 v2kargs-ok nil) 7259 v2kargs-ok nil in-modport nil)
6700 (forward-char 1)) 7260 (forward-char 1))
6701 ((eq ?= (following-char)) 7261 ((eq ?= (following-char))
6702 (setq rvalue t newsig nil) 7262 (setq rvalue t newsig nil)
6703 (forward-char 1)) 7263 (forward-char 1))
6704 ((and (eq ?, (following-char)) 7264 ((and (eq ?, (following-char))
6752 ((member keywd '("wire" "tri" "tri0" "tri1" "triand" "trior" "wand" "wor")) 7312 ((member keywd '("wire" "tri" "tri0" "tri1" "triand" "trior" "wand" "wor"))
6753 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 7313 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6754 expect-signal 'sigs-wire modport nil))) 7314 expect-signal 'sigs-wire modport nil)))
6755 ((member keywd '("reg" "trireg" 7315 ((member keywd '("reg" "trireg"
6756 "byte" "shortint" "int" "longint" "integer" "time" 7316 "byte" "shortint" "int" "longint" "integer" "time"
6757 "bit" "logic")) 7317 "bit" "logic"
7318 "shortreal" "real" "realtime"
7319 "string" "event" "chandle"))
6758 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 7320 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6759 expect-signal 'sigs-reg modport nil))) 7321 expect-signal 'sigs-reg modport nil)))
6760 ((equal keywd "assign") 7322 ((equal keywd "assign")
6761 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 7323 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6762 expect-signal 'sigs-assign modport nil)) 7324 expect-signal 'sigs-assign modport nil))
6770 "property" "randsequence" "sequence" "task")) 7332 "property" "randsequence" "sequence" "task"))
6771 (setq functask (1+ functask))) 7333 (setq functask (1+ functask)))
6772 ((member keywd '("endclass" "endclocking" "endgroup" "endfunction" 7334 ((member keywd '("endclass" "endclocking" "endgroup" "endfunction"
6773 "endproperty" "endsequence" "endtask")) 7335 "endproperty" "endsequence" "endtask"))
6774 (setq functask (1- functask))) 7336 (setq functask (1- functask)))
7337 ((equal keywd "modport")
7338 (setq in-modport t))
6775 ;; Ifdef? Ignore name of define 7339 ;; Ifdef? Ignore name of define
6776 ((member keywd '("`ifdef" "`ifndef")) 7340 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
6777 (setq rvalue t)) 7341 (setq rvalue t))
6778 ;; Type? 7342 ;; Type?
6779 ((verilog-typedef-name-p keywd) 7343 ((verilog-typedef-name-p keywd)
6780 (setq typedefed keywd)) 7344 (setq typedefed keywd))
6781 ;; Interface with optional modport in v2k arglist? 7345 ;; Interface with optional modport in v2k arglist?
6782 ;; Skip over parsing modport, and take the interface name as the type 7346 ;; Skip over parsing modport, and take the interface name as the type
6783 ((and v2kargs-ok 7347 ((and v2kargs-ok
6784 (eq paren 1) 7348 (eq paren 1)
6785 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z0-9`_$]+\\)\\|\\)\\s-*[a-zA-Z0-9`_$]+")) 7349 (not rvalue)
7350 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
6786 (when (match-end 2) (goto-char (match-end 2))) 7351 (when (match-end 2) (goto-char (match-end 2)))
6787 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed keywd multidim nil sig-paren paren 7352 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed keywd multidim nil sig-paren paren
6788 expect-signal 'sigs-intf io t modport (match-string 2))) 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))
7357 (when (not rvalue)
7358 (setq expect-signal nil)))
6789 ;; New signal, maybe? 7359 ;; New signal, maybe?
6790 ((and expect-signal 7360 ((and expect-signal
7361 (not rvalue)
6791 (eq functask 0) 7362 (eq functask 0)
6792 (not rvalue) 7363 (not in-modport)
6793 (not (member keywd verilog-keywords))) 7364 (not (member keywd verilog-keywords)))
6794 ;; Add new signal to expect-signal's variable 7365 ;; Add new signal to expect-signal's variable
6795 (setq newsig (list keywd vec nil nil enum signed typedefed multidim modport)) 7366 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
6796 (set expect-signal (cons newsig 7367 (set expect-signal (cons newsig
6797 (symbol-value expect-signal)))))) 7368 (symbol-value expect-signal))))))
6798 (t 7369 (t
6799 (forward-char 1))) 7370 (forward-char 1)))
6800 (skip-syntax-forward " ")) 7371 (skip-syntax-forward " "))
6801 ;; Return arguments 7372 ;; Return arguments
6802 (vector (nreverse sigs-out) 7373 (verilog-decls-new (nreverse sigs-out)
6803 (nreverse sigs-inout) 7374 (nreverse sigs-inout)
6804 (nreverse sigs-in) 7375 (nreverse sigs-in)
6805 (nreverse sigs-wire) 7376 (nreverse sigs-wire)
6806 (nreverse sigs-reg) 7377 (nreverse sigs-reg)
6807 (nreverse sigs-assign) 7378 (nreverse sigs-assign)
6808 (nreverse sigs-const) 7379 (nreverse sigs-const)
6809 (nreverse sigs-gparam) 7380 (nreverse sigs-gparam)
6810 (nreverse sigs-intf))))) 7381 (nreverse sigs-intf)))))
7382
7383 (defvar verilog-read-sub-decls-in-interfaced nil
7384 "For `verilog-read-sub-decls', process next signal as under interfaced block.")
7385
7386 (defvar verilog-read-sub-decls-gate-ios nil
7387 "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
6811 7388
6812 (eval-when-compile 7389 (eval-when-compile
6813 ;; Prevent compile warnings; these are let's, not globals 7390 ;; Prevent compile warnings; these are let's, not globals
6814 ;; Do not remove the eval-when-compile 7391 ;; Do not remove the eval-when-compile
6815 ;; - we want a error when we are debugging this code if they are refed. 7392 ;; - we want a error when we are debugging this code if they are refed.
6816 (defvar sigs-in) 7393 (defvar sigs-in)
6817 (defvar sigs-inout) 7394 (defvar sigs-inout)
6818 (defvar sigs-out) 7395 (defvar sigs-out)
6819 (defvar sigs-intf)) 7396 (defvar sigs-intf)
6820 7397 (defvar sigs-intfd))
6821
6822 (defsubst verilog-modi-get-decls (modi)
6823 (verilog-modi-cache-results modi 'verilog-read-decls))
6824
6825 (defsubst verilog-modi-get-sub-decls (modi)
6826 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
6827
6828
6829 ;; Signal reading for given module
6830 ;; Note these all take modi's - as returned from the
6831 ;; verilog-modi-current function.
6832 (defsubst verilog-decls-get-outputs (decls)
6833 (aref decls 0))
6834 (defsubst verilog-decls-get-inouts (decls)
6835 (aref decls 1))
6836 (defsubst verilog-decls-get-inputs (decls)
6837 (aref decls 2))
6838 (defsubst verilog-decls-get-wires (decls)
6839 (aref decls 3))
6840 (defsubst verilog-decls-get-regs (decls)
6841 (aref decls 4))
6842 (defsubst verilog-decls-get-assigns (decls)
6843 (aref decls 5))
6844 (defsubst verilog-decls-get-consts (decls)
6845 (aref decls 6))
6846 (defsubst verilog-decls-get-gparams (decls)
6847 (aref decls 7))
6848 (defsubst verilog-decls-get-interfaces (decls)
6849 (aref decls 8))
6850 (defsubst verilog-subdecls-get-outputs (subdecls)
6851 (aref subdecls 0))
6852 (defsubst verilog-subdecls-get-inouts (subdecls)
6853 (aref subdecls 1))
6854 (defsubst verilog-subdecls-get-inputs (subdecls)
6855 (aref subdecls 2))
6856 (defsubst verilog-subdecls-get-interfaces (subdecls)
6857 (aref subdecls 3))
6858
6859 7398
6860 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim) 7399 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
6861 "For `verilog-read-sub-decls-line', add a signal." 7400 "For `verilog-read-sub-decls-line', add a signal."
6862 (let (portdata) 7401 ;; sig eq t to indicate .name syntax
7402 ;;(message "vrsds: %s(%S)" port sig)
7403 (let ((dotname (eq sig t))
7404 portdata)
6863 (when sig 7405 (when sig
6864 (setq port (verilog-symbol-detick-denumber port)) 7406 (setq port (verilog-symbol-detick-denumber port))
6865 (setq sig (verilog-symbol-detick-denumber sig)) 7407 (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
6866 (if sig (setq sig (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil sig)))
6867 (if vec (setq vec (verilog-symbol-detick-denumber vec))) 7408 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
6868 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim))) 7409 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
6869 (unless (or (not sig) 7410 (unless (or (not sig)
6870 (equal sig "")) ;; Ignore .foo(1'b1) assignments 7411 (equal sig "")) ;; Ignore .foo(1'b1) assignments
6871 (cond ((setq portdata (assoc port (verilog-decls-get-inouts submoddecls))) 7412 (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
6872 (setq sigs-inout (cons (list sig vec (concat "To/From " comment) nil nil 7413 (equal "inout" verilog-read-sub-decls-gate-ios))
6873 (verilog-sig-signed portdata) 7414 (setq sigs-inout
6874 (verilog-sig-type portdata) 7415 (cons (verilog-sig-new
6875 multidim) 7416 sig
6876 sigs-inout))) 7417 (if dotname (verilog-sig-bits portdata) vec)
6877 ((setq portdata (assoc port (verilog-decls-get-outputs submoddecls))) 7418 (concat "To/From " comment) nil nil
6878 (setq sigs-out (cons (list sig vec (concat "From " comment) nil nil 7419 (verilog-sig-signed portdata)
6879 (verilog-sig-signed portdata) 7420 (verilog-sig-type portdata)
6880 (verilog-sig-type portdata) 7421 multidim nil)
6881 multidim) 7422 sigs-inout)))
6882 sigs-out))) 7423 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
6883 ((setq portdata (assoc port (verilog-decls-get-inputs submoddecls))) 7424 (equal "output" verilog-read-sub-decls-gate-ios))
6884 (setq sigs-in (cons (list sig vec (concat "To " comment) nil nil 7425 (setq sigs-out
6885 (verilog-sig-signed portdata) 7426 (cons (verilog-sig-new
6886 (verilog-sig-type portdata) 7427 sig
6887 multidim) 7428 (if dotname (verilog-sig-bits portdata) vec)
6888 sigs-in))) 7429 (concat "From " comment) nil nil
7430 (verilog-sig-signed portdata)
7431 (verilog-sig-type portdata)
7432 multidim nil)
7433 sigs-out)))
7434 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
7435 (equal "input" verilog-read-sub-decls-gate-ios))
7436 (setq sigs-in
7437 (cons (verilog-sig-new
7438 sig
7439 (if dotname (verilog-sig-bits portdata) vec)
7440 (concat "To " comment) nil nil
7441 (verilog-sig-signed portdata)
7442 (verilog-sig-type portdata)
7443 multidim nil)
7444 sigs-in)))
6889 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls))) 7445 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
6890 (setq sigs-intf (cons (list sig vec (concat "To/From " comment) nil nil 7446 (setq sigs-intf
6891 (verilog-sig-signed portdata) 7447 (cons (verilog-sig-new
6892 (verilog-sig-type portdata) 7448 sig
6893 multidim) 7449 (if dotname (verilog-sig-bits portdata) vec)
6894 sigs-intf))) 7450 (concat "To/From " comment) nil nil
7451 (verilog-sig-signed portdata)
7452 (verilog-sig-type portdata)
7453 multidim nil)
7454 sigs-intf)))
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)))))
7458 (setq sigs-intfd
7459 (cons (verilog-sig-new
7460 sig
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)
7465 multidim nil)
7466 sigs-intf)))
6895 ;; (t -- warning pin isn't defined.) ; Leave for lint tool 7467 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
6896 ))))) 7468 )))))
6897 7469
6898 (defun verilog-read-sub-decls-expr (submoddecls comment port expr) 7470 (defun verilog-read-sub-decls-expr (submoddecls comment port expr)
6899 "For `verilog-read-sub-decls-line', parse a subexpression and add signals." 7471 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
6903 ;; Remove front operators 7475 ;; Remove front operators
6904 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr)) 7476 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
6905 ;; 7477 ;;
6906 (cond 7478 (cond
6907 ;; {..., a, b} requires us to recurse on a,b 7479 ;; {..., a, b} requires us to recurse on a,b
6908 ((string-match "^\\s-*{\\([^{}]*\\)}\\s-*$" expr) 7480 ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
7481 ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
6909 (unless verilog-auto-ignore-concat 7482 (unless verilog-auto-ignore-concat
6910 (let ((mlst (split-string (match-string 1 expr) ",")) 7483 (let ((mlst (split-string (match-string 1 expr) "[{},]"))
6911 mstr) 7484 mstr)
6912 (while (setq mstr (pop mlst)) 7485 (while (setq mstr (pop mlst))
6913 (verilog-read-sub-decls-expr submoddecls comment port mstr))))) 7486 (verilog-read-sub-decls-expr submoddecls comment port mstr)))))
6914 (t 7487 (t
6915 (let (sig vec multidim) 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)
6916 (cond ;; Find \signal. Final space is part of escaped signal name 7492 (cond ;; Find \signal. Final space is part of escaped signal name
6917 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr) 7493 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
6918 ;;(message "vrsde-s: '%s'" (match-string 1 expr)) 7494 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
6919 (setq sig (match-string 1 expr) 7495 (setq sig (match-string 1 expr)
6920 expr (substring expr (match-end 0)))) 7496 expr (substring expr (match-end 0))))
6921 ;; Find signal 7497 ;; Find signal
6922 ((string-match "^\\s-*\\([^[({).\\]+\\)" expr) 7498 ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
6923 ;;(message "vrsde-s: '%s'" (match-string 1 expr)) 7499 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
6924 (setq sig (verilog-string-remove-spaces (match-string 1 expr)) 7500 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
6925 expr (substring expr (match-end 0))))) 7501 expr (substring expr (match-end 0)))))
6926 ;; Find [vector] or [multi][multi][multi][vector] 7502 ;; Find [vector] or [multi][multi][multi][vector]
6927 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr) 7503 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
6933 ;;(message "vrsde-rem: '%s'" expr) 7509 ;;(message "vrsde-rem: '%s'" expr)
6934 (when (and sig (string-match "^\\s-*$" expr)) 7510 (when (and sig (string-match "^\\s-*$" expr))
6935 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim)))))) 7511 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))))
6936 7512
6937 (defun verilog-read-sub-decls-line (submoddecls comment) 7513 (defun verilog-read-sub-decls-line (submoddecls comment)
6938 "For `verilog-read-sub-decls', read lines of port defs until none match anymore. 7514 "For `verilog-read-sub-decls', read lines of port defs until none match.
6939 Return the list of signals found, using submodi to look up each port." 7515 Inserts the list of signals found, using submodi to look up each port."
6940 (let (done port) 7516 (let (done port)
6941 (save-excursion 7517 (save-excursion
6942 (forward-line 1) 7518 (forward-line 1)
6943 (while (not done) 7519 (while (not done)
6944 ;; Get port name 7520 ;; Get port name
6945 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*") 7521 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
6946 (setq port (match-string 1)) 7522 (setq port (match-string 1))
6947 (goto-char (match-end 0))) 7523 (goto-char (match-end 0)))
7524 ;; .\escaped (
6948 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*") 7525 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
6949 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space 7526 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space
6950 (goto-char (match-end 0))) 7527 (goto-char (match-end 0)))
7528 ;; .name
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
7533 (setq port nil))
7534 ;; .\escaped_name
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
7539 (setq port nil))
7540 ;; random
6951 ((looking-at "\\s-*\\.[^(]*(") 7541 ((looking-at "\\s-*\\.[^(]*(")
6952 (setq port nil) ;; skip this line 7542 (setq port nil) ;; skip this line
6953 (goto-char (match-end 0))) 7543 (goto-char (match-end 0)))
6954 (t 7544 (t
6955 (setq port nil done t))) ;; Unknown, ignore rest of line 7545 (setq port nil done t))) ;; Unknown, ignore rest of line
6956 ;; Get signal name. Point is at the first-non-space after ( 7546 ;; Get signal name. Point is at the first-non-space after (
6957 ;; We intentionally ignore (non-escaped) signals with .s in them 7547 ;; We intentionally ignore (non-escaped) signals with .s in them
6958 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs. 7548 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
6959 (when port 7549 (when port
6960 (cond ((looking-at "\\([^[({).\\]*\\)\\s-*)") 7550 (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
6961 (verilog-read-sub-decls-sig 7551 (verilog-read-sub-decls-sig
6962 submoddecls comment port 7552 submoddecls comment port
6963 (verilog-string-remove-spaces (match-string 1)) ; sig 7553 (verilog-string-remove-spaces (match-string 1)) ; sig
6964 nil nil)) ; vec multidim 7554 nil nil)) ; vec multidim
6965 ;; 7555 ;;
6966 ((looking-at "\\([^[({).\\]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)") 7556 ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
6967 (verilog-read-sub-decls-sig 7557 (verilog-read-sub-decls-sig
6968 submoddecls comment port 7558 submoddecls comment port
6969 (verilog-string-remove-spaces (match-string 1)) ; sig 7559 (verilog-string-remove-spaces (match-string 1)) ; sig
6970 (match-string 2) nil)) ; vec multidim 7560 (match-string 2) nil)) ; vec multidim
6971 ;; Fastpath was above looking-at's. 7561 ;; Fastpath was above looking-at's.
6972 ;; For something more complicated invoke a parser 7562 ;; For something more complicated invoke a parser
6973 ((looking-at "[^)]+") 7563 ((looking-at "[^)]+")
6974 (verilog-read-sub-decls-expr 7564 (verilog-read-sub-decls-expr
6975 submoddecls comment port 7565 submoddecls comment port
6976 (buffer-substring 7566 (buffer-substring
6977 (point) (1- (progn (backward-char 1) ; start at ( 7567 (point) (1- (progn (search-backward "(") ; start at (
6978 (forward-sexp 1) (point)))))))) ; expr 7568 (forward-sexp 1) (point)))))))) ; expr
6979 ;; 7569 ;;
6980 (forward-line 1))))) 7570 (forward-line 1)))))
7571
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."
7575 (save-excursion
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"
7596 (match-string 0)))
7597 (t
7598 (forward-char 1)
7599 (skip-syntax-forward " ")))))))
6981 7600
6982 (defun verilog-read-sub-decls () 7601 (defun verilog-read-sub-decls ()
6983 "Internally parse signals going to modules under this module. 7602 "Internally parse signals going to modules under this module.
6984 Return a array of [ outputs inouts inputs ] signals for modules that are 7603 Return a array of [ outputs inouts inputs ] signals for modules that are
6985 instantiated in this module. For example if declare A A (.B(SIG)) and SIG 7604 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
6999 .in (in));" 7618 .in (in));"
7000 (save-excursion 7619 (save-excursion
7001 (let ((end-mod-point (verilog-get-end-of-defun t)) 7620 (let ((end-mod-point (verilog-get-end-of-defun t))
7002 st-point end-inst-point 7621 st-point end-inst-point
7003 ;; below 3 modified by verilog-read-sub-decls-line 7622 ;; below 3 modified by verilog-read-sub-decls-line
7004 sigs-out sigs-inout sigs-in sigs-intf) 7623 sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
7005 (verilog-beg-of-defun) 7624 (verilog-beg-of-defun)
7006 (while (verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t) 7625 (while (verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
7007 (save-excursion 7626 (save-excursion
7008 (goto-char (match-beginning 0)) 7627 (goto-char (match-beginning 0))
7009 (unless (verilog-inside-comment-p) 7628 (unless (verilog-inside-comment-p)
7010 ;; Attempt to snarf a comment 7629 ;; Attempt to snarf a comment
7011 (let* ((submod (verilog-read-inst-module)) 7630 (let* ((submod (verilog-read-inst-module))
7012 (inst (verilog-read-inst-name)) 7631 (inst (verilog-read-inst-name))
7632 (subprim (member submod verilog-gate-keywords))
7013 (comment (concat inst " of " submod ".v")) 7633 (comment (concat inst " of " submod ".v"))
7014 submodi submoddecls) 7634 submodi submoddecls)
7015 (when (setq submodi (verilog-modi-lookup submod t)) 7635 (cond
7016 (setq submoddecls (verilog-modi-get-decls submodi)) 7636 (subprim
7017 ;; This could have used a list created by verilog-auto-inst 7637 (setq submodi `primitive
7018 ;; However I want it to be runnable even on user's manually added signals 7638 submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
7639 comment (concat inst " of " submod))
7019 (verilog-backward-open-paren) 7640 (verilog-backward-open-paren)
7020 (setq end-inst-point (save-excursion (forward-sexp 1) (point)) 7641 (setq end-inst-point (save-excursion (forward-sexp 1) (point))
7021 st-point (point)) 7642 st-point (point))
7022 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t) 7643 (forward-char 1)
7023 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out 7644 (verilog-read-sub-decls-gate submoddecls comment submod end-inst-point))
7024 (goto-char st-point) 7645 ;; Non-primitive
7025 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t) 7646 (t
7026 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out 7647 (when (setq submodi (verilog-modi-lookup submod t))
7027 (goto-char st-point) 7648 (setq submoddecls (verilog-modi-get-decls submodi)
7028 (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t) 7649 verilog-read-sub-decls-gate-ios nil)
7029 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout 7650 (verilog-backward-open-paren)
7030 (goto-char st-point) 7651 (setq end-inst-point (save-excursion (forward-sexp 1) (point))
7031 (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t) 7652 st-point (point))
7032 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-in 7653 ;; This could have used a list created by verilog-auto-inst
7033 ))))) 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
7670 )))))))
7034 ;; Combine duplicate bits 7671 ;; Combine duplicate bits
7035 ;;(setq rr (vector sigs-out sigs-inout sigs-in)) 7672 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
7036 (vector (verilog-signals-combine-bus (nreverse sigs-out)) 7673 (verilog-subdecls-new
7037 (verilog-signals-combine-bus (nreverse sigs-inout)) 7674 (verilog-signals-combine-bus (nreverse sigs-out))
7038 (verilog-signals-combine-bus (nreverse sigs-in)) 7675 (verilog-signals-combine-bus (nreverse sigs-inout))
7039 (verilog-signals-combine-bus (nreverse sigs-intf)))))) 7676 (verilog-signals-combine-bus (nreverse sigs-in))
7677 (verilog-signals-combine-bus (nreverse sigs-intf))
7678 (verilog-signals-combine-bus (nreverse sigs-intfd))))))
7040 7679
7041 (defun verilog-read-inst-pins () 7680 (defun verilog-read-inst-pins ()
7042 "Return an array of [ pins ] for the current instantiation at point. 7681 "Return an array of [ pins ] for the current instantiation at point.
7043 For example if declare A A (.B(SIG)) then B will be included in the list." 7682 For example if declare A A (.B(SIG)) then B will be included in the list."
7044 (save-excursion 7683 (save-excursion
7082 (point))) 7721 (point)))
7083 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t) 7722 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
7084 (setq sig-list (cons (list (match-string 1) nil nil) sig-list)))) 7723 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
7085 sig-list))) 7724 sig-list)))
7086 7725
7726 (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
7727 (make-variable-buffer-local 'verilog-cache-has-lisp)
7728
7729 (defun verilog-read-auto-lisp-present ()
7730 "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
7731 (save-excursion
7732 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
7733
7087 (defun verilog-read-auto-lisp (start end) 7734 (defun verilog-read-auto-lisp (start end)
7088 "Look for and evaluate a AUTO_LISP between START and END." 7735 "Look for and evaluate a AUTO_LISP between START and END.
7089 (save-excursion 7736 Must call `verilog-read-auto-lisp-present' before this function."
7090 (goto-char start) 7737 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
7091 (while (re-search-forward "\\<AUTO_LISP(" end t) 7738 (when verilog-cache-has-lisp
7092 (backward-char) 7739 (save-excursion
7093 (let* ((beg-pt (prog1 (point) 7740 (goto-char start)
7094 (forward-sexp 1))) ;; Closing paren 7741 (while (re-search-forward "\\<AUTO_LISP(" end t)
7095 (end-pt (point))) 7742 (backward-char)
7096 (eval-region beg-pt end-pt nil))))) 7743 (let* ((beg-pt (prog1 (point)
7744 (forward-sexp 1))) ;; Closing paren
7745 (end-pt (point)))
7746 (eval-region beg-pt end-pt nil))))))
7097 7747
7098 (eval-when-compile 7748 (eval-when-compile
7099 ;; Prevent compile warnings; these are let's, not globals 7749 ;; Prevent compile warnings; these are let's, not globals
7100 ;; Do not remove the eval-when-compile 7750 ;; Do not remove the eval-when-compile
7101 ;; - we want a error when we are debugging this code if they are refed. 7751 ;; - we want a error when we are debugging this code if they are refed.
7102 (defvar sigs-in) 7752 (defvar sigs-in)
7103 (defvar sigs-out) 7753 (defvar sigs-out)
7104 (defvar got-sig) 7754 (defvar sigs-temp)
7105 (defvar got-rvalue)
7106 (defvar uses-delayed) 7755 (defvar uses-delayed)
7107 (defvar vector-skip-list)) 7756 (defvar vector-skip-list))
7108 7757
7109 (defun verilog-read-always-signals-recurse 7758 (defun verilog-read-always-signals-recurse
7110 (exit-keywd rvalue ignore-next) 7759 (exit-keywd rvalue temp-next)
7111 "Recursive routine for parentheses/bracket matching. 7760 "Recursive routine for parentheses/bracket matching.
7112 EXIT-KEYWD is expression to stop at, nil if top level. 7761 EXIT-KEYWD is expression to stop at, nil if top level.
7113 RVALUE is true if at right hand side of equal. 7762 RVALUE is true if at right hand side of equal.
7114 IGNORE-NEXT is true to ignore next token, fake from inside case statement." 7763 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
7115 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue 7764 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue
7116 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-rvalue end-else-check) 7765 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
7117 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue ignore-next)))) 7766 ignore-next)
7767 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
7118 (while (not (or (eobp) gotend)) 7768 (while (not (or (eobp) gotend))
7119 (cond 7769 (cond
7120 ((looking-at "//") 7770 ((looking-at "//")
7121 (search-forward "\n")) 7771 (search-forward "\n"))
7122 ((looking-at "/\\*") 7772 ((looking-at "/\\*")
7190 ((equal keywd "(") 7840 ((equal keywd "(")
7191 (forward-char 1) 7841 (forward-char 1)
7192 (cond (sig-last-tolk ;; Function call; zap last signal 7842 (cond (sig-last-tolk ;; Function call; zap last signal
7193 (setq got-sig nil))) 7843 (setq got-sig nil)))
7194 (cond ((equal last-keywd "for") 7844 (cond ((equal last-keywd "for")
7195 (verilog-read-always-signals-recurse ";" nil nil) 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)
7196 (verilog-read-always-signals-recurse ";" t nil) 7848 (verilog-read-always-signals-recurse ";" t nil)
7197 (verilog-read-always-signals-recurse ")" nil nil)) 7849 (verilog-read-always-signals-recurse ")" nil nil))
7198 (t (verilog-read-always-signals-recurse ")" t nil)))) 7850 (t (verilog-read-always-signals-recurse ")" t nil))))
7199 ((equal keywd "begin") 7851 ((equal keywd "begin")
7200 (skip-syntax-forward "w_") 7852 (skip-syntax-forward "w_")
7201 (verilog-read-always-signals-recurse "end" nil nil) 7853 (verilog-read-always-signals-recurse "end" nil nil)
7202 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd)))) 7854 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
7203 (setq ignore-next nil rvalue semi-rvalue) 7855 (setq ignore-next nil rvalue semi-rvalue)
7204 (if (not exit-keywd) (setq end-else-check t))) 7856 (if (not exit-keywd) (setq end-else-check t)))
7205 ((or (equal keywd "case") 7857 ((member keywd '("case" "casex" "casez"))
7206 (equal keywd "casex")
7207 (equal keywd "casez"))
7208 (skip-syntax-forward "w_") 7858 (skip-syntax-forward "w_")
7209 (verilog-read-always-signals-recurse "endcase" t nil) 7859 (verilog-read-always-signals-recurse "endcase" t nil)
7210 (setq ignore-next nil rvalue semi-rvalue) 7860 (setq ignore-next nil rvalue semi-rvalue)
7211 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end 7861 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end
7212 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent 7862 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent
7213 (cond ((or (equal keywd "`ifdef") 7863 (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
7214 (equal keywd "`ifndef"))
7215 (setq ignore-next t)) 7864 (setq ignore-next t))
7216 ((or ignore-next 7865 ((or ignore-next
7217 (member keywd verilog-keywords) 7866 (member keywd verilog-keywords)
7218 (string-match "^\\$" keywd)) ;; PLI task 7867 (string-match "^\\$" keywd)) ;; PLI task
7219 (setq ignore-next nil)) 7868 (setq ignore-next nil))
7220 (t 7869 (t
7221 (setq keywd (verilog-symbol-detick-denumber keywd)) 7870 (setq keywd (verilog-symbol-detick-denumber keywd))
7222 (when got-sig 7871 (when got-sig
7223 (if got-rvalue (setq sigs-in (cons got-sig sigs-in)) 7872 (set got-list (cons got-sig (symbol-value got-list)))
7224 (setq sigs-out (cons got-sig sigs-out))) 7873 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
7225 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue))))
7226 ) 7874 )
7227 (setq got-rvalue rvalue 7875 (setq got-list (cond (temp-next 'sigs-temp)
7876 (rvalue 'sigs-in)
7877 (t 'sigs-out))
7228 got-sig (if (or (not keywd) 7878 got-sig (if (or (not keywd)
7229 (assoc keywd (if got-rvalue sigs-in sigs-out))) 7879 (assoc keywd (symbol-value got-list)))
7230 nil (list keywd nil nil)) 7880 nil (list keywd nil nil))
7881 temp-next nil
7231 sig-tolk t))) 7882 sig-tolk t)))
7232 (skip-chars-forward "a-zA-Z0-9$_.%`")) 7883 (skip-chars-forward "a-zA-Z0-9$_.%`"))
7233 (t 7884 (t
7234 (forward-char 1))) 7885 (forward-char 1)))
7235 ;; End of non-comment token 7886 ;; End of non-comment token
7236 (setq last-keywd keywd))) 7887 (setq last-keywd keywd)))
7237 (skip-syntax-forward " ")) 7888 (skip-syntax-forward " "))
7238 ;; Append the final pending signal 7889 ;; Append the final pending signal
7239 (when got-sig 7890 (when got-sig
7240 (if got-rvalue (setq sigs-in (cons got-sig sigs-in)) 7891 ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
7241 (setq sigs-out (cons got-sig sigs-out))) 7892 (set got-list (cons got-sig (symbol-value got-list)))
7242 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue))))
7243 (setq got-sig nil)) 7893 (setq got-sig nil))
7244 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd)))) 7894 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
7245 )) 7895 ))
7246 7896
7247 (defun verilog-read-always-signals () 7897 (defun verilog-read-always-signals ()
7248 "Parse always block at point and return list of (outputs inout inputs)." 7898 "Parse always block at point and return list of (outputs inout inputs)."
7249 ;; Insert new
7250 (save-excursion 7899 (save-excursion
7251 (let* (;;(dbg "") 7900 (let* (;;(dbg "")
7252 sigs-in sigs-out 7901 sigs-out sigs-temp sigs-in
7253 uses-delayed) ;; Found signal/rvalue; push if not function 7902 uses-delayed) ;; Found signal/rvalue; push if not function
7254 (search-forward ")") 7903 (search-forward ")")
7255 (verilog-read-always-signals-recurse nil nil nil) 7904 (verilog-read-always-signals-recurse nil nil nil)
7256 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg "")) 7905 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))
7257 ;; Return what was found 7906 ;; Return what was found
7258 (list sigs-out nil sigs-in uses-delayed)))) 7907 (verilog-alw-new sigs-out sigs-temp sigs-in uses-delayed))))
7259 7908
7260 (defun verilog-read-instants () 7909 (defun verilog-read-instants ()
7261 "Parse module at point and return list of ( ( file instance ) ... )." 7910 "Parse module at point and return list of ( ( file instance ) ... )."
7262 (verilog-beg-of-defun) 7911 (verilog-beg-of-defun)
7263 (let* ((end-mod-point (verilog-get-end-of-defun t)) 7912 (let* ((end-mod-point (verilog-get-end-of-defun t))
7290 (save-excursion 7939 (save-excursion
7291 ;; Find beginning 7940 ;; Find beginning
7292 (let ((tpl-regexp "\\([0-9]+\\)") 7941 (let ((tpl-regexp "\\([0-9]+\\)")
7293 (lineno 0) 7942 (lineno 0)
7294 (templateno 0) 7943 (templateno 0)
7944 (pt (point))
7295 tpl-sig-list tpl-wild-list tpl-end-pt rep) 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.
7296 (cond ((or 7952 (cond ((or
7297 (re-search-backward (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t) 7953 (verilog-re-search-backward-substr
7298 (progn 7954 "AUTO_TEMPLATE"
7299 (goto-char (point-min)) 7955 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
7300 (re-search-forward (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
7958 (progn
7959 (goto-char pt)
7960 (verilog-re-search-forward-substr
7961 "AUTO_TEMPLATE"
7962 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
7301 (goto-char (match-end 0)) 7963 (goto-char (match-end 0))
7302 ;; Parse "REGEXP" 7964 ;; Parse "REGEXP"
7303 ;; We reserve @"..." for future lisp expressions that evaluate once-per-AUTOINST 7965 ;; We reserve @"..." for future lisp expressions that evaluate
7966 ;; once-per-AUTOINST
7304 (when (looking-at "\\s-*\"\\([^\"]*\\)\"") 7967 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
7305 (setq tpl-regexp (match-string 1)) 7968 (setq tpl-regexp (match-string 1))
7306 (goto-char (match-end 0))) 7969 (goto-char (match-end 0)))
7307 (search-forward "(") 7970 (search-forward "(")
7308 ;; Parse lines in the template 7971 ;; Parse lines in the template
7429 (error (concat (verilog-point-text) 8092 (error (concat (verilog-point-text)
7430 ": Can't find verilog-read-defines file: " filename))))) 8093 ": Can't find verilog-read-defines file: " filename)))))
7431 (when recurse 8094 (when recurse
7432 (goto-char (point-min)) 8095 (goto-char (point-min))
7433 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t) 8096 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
7434 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string-no-properties 1)))) 8097 (let ((inc (verilog-string-replace-matches
8098 "\"" "" nil nil (match-string-no-properties 1))))
7435 (unless (verilog-inside-comment-p) 8099 (unless (verilog-inside-comment-p)
7436 (verilog-read-defines inc recurse t))))) 8100 (verilog-read-defines inc recurse t)))))
7437 ;; Read `defines 8101 ;; Read `defines
7438 ;; note we don't use verilog-re... it's faster this way, and that 8102 ;; note we don't use verilog-re... it's faster this way, and that
7439 ;; function has problems when comments are at the end of the define 8103 ;; function has problems when comments are at the end of the define
7452 ;; However, that isn't called yet for included files, so we'll add another scheme 8116 ;; However, that isn't called yet for included files, so we'll add another scheme
7453 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") 8117 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7454 (setq enumname (match-string-no-properties 1))) 8118 (setq enumname (match-string-no-properties 1)))
7455 (forward-comment 999) 8119 (forward-comment 999)
7456 (while (looking-at "\\s-*,?\\s-*\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\s-*") 8120 (while (looking-at "\\s-*,?\\s-*\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\s-*")
7457 (verilog-set-define (match-string-no-properties 1) (match-string-no-properties 2) origbuf enumname) 8121 (verilog-set-define (match-string-no-properties 1)
8122 (match-string-no-properties 2) origbuf enumname)
7458 (goto-char (match-end 0)) 8123 (goto-char (match-end 0))
7459 (forward-comment 999))))))) 8124 (forward-comment 999)))))))
7460 8125
7461 (defun verilog-read-includes () 8126 (defun verilog-read-includes ()
7462 "Read `includes for the current file. 8127 "Read `includes for the current file.
7636 (unless (member object (symbol-value varref)) 8301 (unless (member object (symbol-value varref))
7637 (set varref (append (symbol-value varref) (list object)))) 8302 (set varref (append (symbol-value varref) (list object))))
7638 varref) 8303 varref)
7639 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l) 8304 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
7640 8305
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 "")
8311 (setq cmd (concat
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 ""))))
8317 cmd))
8318 ;;(verilog-current-flags)
8319
7641 8320
7642 ;; 8321 ;;
7643 ;; Cached directory support 8322 ;; Cached directory support
7644 ;; 8323 ;;
7645 8324
7655 8334
7656 (defmacro verilog-preserve-dir-cache (&rest body) 8335 (defmacro verilog-preserve-dir-cache (&rest body)
7657 "Execute the BODY forms, allowing directory cache preservation within BODY. 8336 "Execute the BODY forms, allowing directory cache preservation within BODY.
7658 This means that changes inside BODY made to the file system will not be 8337 This means that changes inside BODY made to the file system will not be
7659 seen by the `verilog-dir-files' and related functions." 8338 seen by the `verilog-dir-files' and related functions."
7660 `(let ((verilog-dir-cache-preserving t) 8339 `(let ((verilog-dir-cache-preserving (current-buffer))
7661 verilog-dir-cache-list 8340 verilog-dir-cache-list
7662 verilog-dir-cache-lib-filenames) 8341 verilog-dir-cache-lib-filenames)
7663 (progn ,@body))) 8342 (progn ,@body)))
7664 8343
7665 (defun verilog-dir-files (dirname) 8344 (defun verilog-dir-files (dirname)
7705 ;; 8384 ;;
7706 ;; Module name lookup 8385 ;; Module name lookup
7707 ;; 8386 ;;
7708 8387
7709 (defun verilog-module-inside-filename-p (module filename) 8388 (defun verilog-module-inside-filename-p (module filename)
7710 "Return point if MODULE is specified inside FILENAME, else nil. 8389 "Return modi if MODULE is specified inside FILENAME, else nil.
7711 Allows version control to check out the file if need be." 8390 Allows version control to check out the file if need be."
7712 (and (or (file-exists-p filename) 8391 (and (or (file-exists-p filename)
7713 (and (fboundp 'vc-backend) 8392 (and (fboundp 'vc-backend)
7714 (vc-backend filename))) 8393 (vc-backend filename)))
7715 (let (pt) 8394 (let (modi type)
7716 (with-current-buffer (find-file-noselect filename) 8395 (with-current-buffer (find-file-noselect filename)
7717 (save-excursion 8396 (save-excursion
7718 (goto-char (point-min)) 8397 (goto-char (point-min))
7719 (while (and 8398 (while (and
7720 ;; It may be tempting to look for verilog-defun-re, 8399 ;; It may be tempting to look for verilog-defun-re,
7721 ;; don't, it slows things down a lot! 8400 ;; don't, it slows things down a lot!
7722 (verilog-re-search-forward-quick "\\<module\\>" nil t) 8401 (verilog-re-search-forward-quick "\\<\\(module\\|interface\\)\\>" nil t)
8402 (setq type (match-string-no-properties 0))
7723 (verilog-re-search-forward-quick "[(;]" nil t)) 8403 (verilog-re-search-forward-quick "[(;]" nil t))
7724 (if (equal module (verilog-read-module-name)) 8404 (if (equal module (verilog-read-module-name))
7725 (setq pt (point)))) 8405 (setq modi (verilog-modi-new module filename (point) type))))
7726 pt))))) 8406 modi)))))
7727 8407
7728 (defun verilog-is-number (symbol) 8408 (defun verilog-is-number (symbol)
7729 "Return true if SYMBOL is number-like." 8409 "Return true if SYMBOL is number-like."
7730 (or (string-match "^[0-9 \t:]+$" symbol) 8410 (or (string-match "^[0-9 \t:]+$" symbol)
7731 (string-match "^[---]*[0-9]+$" symbol) 8411 (string-match "^[---]*[0-9]+$" symbol)
7887 8567
7888 (defvar verilog-modi-cache-list nil 8568 (defvar verilog-modi-cache-list nil
7889 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)... 8569 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
7890 For speeding up verilog-modi-get-* commands. 8570 For speeding up verilog-modi-get-* commands.
7891 Buffer-local.") 8571 Buffer-local.")
7892
7893 (make-variable-buffer-local 'verilog-modi-cache-list) 8572 (make-variable-buffer-local 'verilog-modi-cache-list)
7894 8573
7895 (defvar verilog-modi-cache-preserve-tick nil 8574 (defvar verilog-modi-cache-preserve-tick nil
7896 "Modification tick after which the cache is still considered valid. 8575 "Modification tick after which the cache is still considered valid.
7897 Use `verilog-preserve-modi-cache' to set it.") 8576 Use `verilog-preserve-modi-cache' to set it.")
7898 (defvar verilog-modi-cache-preserve-buffer nil 8577 (defvar verilog-modi-cache-preserve-buffer nil
7899 "Modification tick after which the cache is still considered valid. 8578 "Modification tick after which the cache is still considered valid.
7900 Use `verilog-preserve-modi-cache' to set it.") 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.")
7901 8586
7902 (defun verilog-modi-current () 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
8601 (save-excursion
8602 (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
8603 verilog-modi-cache-current)
8604 (t
8605 (verilog-modi-current-get))))
8606
8607 (defun verilog-modi-current-get ()
7903 "Return the modi structure for the module currently at point." 8608 "Return the modi structure for the module currently at point."
7904 (let* (name pt) 8609 (let* (name type pt)
7905 ;; read current module's name 8610 ;; read current module's name
7906 (save-excursion 8611 (save-excursion
7907 (verilog-re-search-backward-quick verilog-defun-re nil nil) 8612 (verilog-re-search-backward-quick verilog-defun-re nil nil)
8613 (setq type (match-string-no-properties 0))
7908 (verilog-re-search-forward-quick "(" nil nil) 8614 (verilog-re-search-forward-quick "(" nil nil)
7909 (setq name (verilog-read-module-name)) 8615 (setq name (verilog-read-module-name))
7910 (setq pt (point))) 8616 (setq pt (point)))
7911 ;; return 8617 ;; return modi - note this vector built two places
7912 (vector name (or (buffer-file-name) (current-buffer)) pt))) 8618 (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
7913 8619
7914 (defvar verilog-modi-lookup-last-mod nil "Cache of last module looked up.") 8620 (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
7915 (defvar verilog-modi-lookup-last-modi nil "Cache of last modi returned.") 8621 (make-variable-buffer-local 'verilog-modi-lookup-cache)
7916 (defvar verilog-modi-lookup-last-current nil "Cache of last `current-buffer' looked up.") 8622 (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
7917 (defvar verilog-modi-lookup-last-tick nil "Cache of last `buffer-modified-tick' looked up.") 8623 (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
7918 8624
7919 (defun verilog-modi-lookup (module allow-cache &optional ignore-error) 8625 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
7920 "Find the file and point at which MODULE is defined. 8626 "Find the file and point at which MODULE is defined.
7921 If ALLOW-CACHE is set, check and remember cache of previous lookups. 8627 If ALLOW-CACHE is set, check and remember cache of previous lookups.
7922 Return modi if successful, else print message unless IGNORE-ERROR is true." 8628 Return modi if successful, else print message unless IGNORE-ERROR is true."
7923 (let* ((current (or (buffer-file-name) (current-buffer)))) 8629 (let* ((current (or (buffer-file-name) (current-buffer)))
7924 (cond ((and verilog-modi-lookup-last-modi 8630 modi)
8631 ;; Check cache
8632 ;;(message "verilog-modi-lookup: %s" module)
8633 (cond ((and verilog-modi-lookup-cache
7925 verilog-cache-enabled 8634 verilog-cache-enabled
7926 allow-cache 8635 allow-cache
7927 (equal verilog-modi-lookup-last-mod module) 8636 (setq modi (gethash module verilog-modi-lookup-cache))
7928 (equal verilog-modi-lookup-last-current current) 8637 (equal verilog-modi-lookup-last-current current)
7929 (equal verilog-modi-lookup-last-tick (buffer-modified-tick))) 8638 ;; Iff hit is in current buffer, then tick must match
7930 ;; ok as is 8639 (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
7931 ) 8640 (not (equal current (verilog-modi-file-or-buffer modi)))))
8641 ;;(message "verilog-modi-lookup: HIT %S" modi)
8642 modi)
8643 ;; Miss
7932 (t (let* ((realmod (verilog-symbol-detick module t)) 8644 (t (let* ((realmod (verilog-symbol-detick module t))
7933 (orig-filenames (verilog-module-filenames realmod current)) 8645 (orig-filenames (verilog-module-filenames realmod current))
7934 (filenames orig-filenames) 8646 (filenames orig-filenames)
7935 pt) 8647 mif)
7936 (while (and filenames (not pt)) 8648 (while (and filenames (not mif))
7937 (if (not (setq pt (verilog-module-inside-filename-p realmod (car filenames)))) 8649 (if (not (setq mif (verilog-module-inside-filename-p realmod (car filenames))))
7938 (setq filenames (cdr filenames)))) 8650 (setq filenames (cdr filenames))))
7939 (cond (pt (setq verilog-modi-lookup-last-modi 8651 ;; mif has correct form to become later elements of modi
7940 (vector realmod (car filenames) pt))) 8652 (cond (mif (setq modi mif))
7941 (t (setq verilog-modi-lookup-last-modi nil) 8653 (t (setq modi nil)
7942 (or ignore-error 8654 (or ignore-error
7943 (error (concat (verilog-point-text) 8655 (error (concat (verilog-point-text)
7944 ": Can't locate " module " module definition" 8656 ": Can't locate " module " module definition"
7945 (if (not (equal module realmod)) 8657 (if (not (equal module realmod))
7946 (concat " (Expanded macro to " realmod ")") 8658 (concat " (Expanded macro to " realmod ")")
7947 "") 8659 "")
7948 "\n Check the verilog-library-directories variable." 8660 "\n Check the verilog-library-directories variable."
7949 "\n I looked in (if not listed, doesn't exist):\n\t" 8661 "\n I looked in (if not listed, doesn't exist):\n\t"
7950 (mapconcat 'concat orig-filenames "\n\t")))))) 8662 (mapconcat 'concat orig-filenames "\n\t"))))))
7951 (setq verilog-modi-lookup-last-mod module 8663 (when (eval-when-compile (fboundp 'make-hash-table))
7952 verilog-modi-lookup-last-current current 8664 (unless verilog-modi-lookup-cache
7953 verilog-modi-lookup-last-tick (buffer-modified-tick))))) 8665 (setq verilog-modi-lookup-cache
7954 verilog-modi-lookup-last-modi)) 8666 (make-hash-table :test 'equal :rehash-size 4.0)))
7955 8667 (puthash module modi verilog-modi-lookup-cache))
7956 (defsubst verilog-modi-name (modi) 8668 (setq verilog-modi-lookup-last-current current
7957 (aref modi 0)) 8669 verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
7958 (defsubst verilog-modi-file-or-buffer (modi) 8670 modi))
7959 (aref modi 1))
7960 (defsubst verilog-modi-point (modi)
7961 (aref modi 2))
7962 8671
7963 (defun verilog-modi-filename (modi) 8672 (defun verilog-modi-filename (modi)
7964 "Filename of MODI, or name of buffer if it's never been saved." 8673 "Filename of MODI, or name of buffer if it's never been saved."
7965 (if (bufferp (verilog-modi-file-or-buffer modi)) 8674 (if (bufferp (verilog-modi-file-or-buffer modi))
7966 (or (buffer-file-name (verilog-modi-file-or-buffer modi)) 8675 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
7973 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi)) 8682 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
7974 (verilog-modi-file-or-buffer modi) 8683 (verilog-modi-file-or-buffer modi)
7975 (find-file-noselect (verilog-modi-file-or-buffer modi)))) 8684 (find-file-noselect (verilog-modi-file-or-buffer modi))))
7976 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax 8685 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax
7977 (verilog-mode)) 8686 (verilog-mode))
7978 (goto-char (verilog-modi-point modi))) 8687 (goto-char (verilog-modi-get-point modi)))
7979 8688
7980 (defun verilog-goto-defun-file (module) 8689 (defun verilog-goto-defun-file (module)
7981 "Move point to the file at which a given MODULE is defined." 8690 "Move point to the file at which a given MODULE is defined."
7982 (interactive "sGoto File for Module: ") 8691 (interactive "sGoto File for Module: ")
7983 (let* ((modi (verilog-modi-lookup module nil))) 8692 (let* ((modi (verilog-modi-lookup module nil)))
7993 (verilog-modi-goto modi) 8702 (verilog-modi-goto modi)
7994 (if (and (setq fass (assoc (list modi function) 8703 (if (and (setq fass (assoc (list modi function)
7995 verilog-modi-cache-list)) 8704 verilog-modi-cache-list))
7996 ;; Destroy caching when incorrect; Modified or file changed 8705 ;; Destroy caching when incorrect; Modified or file changed
7997 (not (and verilog-cache-enabled 8706 (not (and verilog-cache-enabled
7998 (or (equal (buffer-modified-tick) (nth 1 fass)) 8707 (or (equal (buffer-chars-modified-tick) (nth 1 fass))
7999 (and verilog-modi-cache-preserve-tick 8708 (and verilog-modi-cache-preserve-tick
8000 (<= verilog-modi-cache-preserve-tick (nth 1 fass)) 8709 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
8001 (equal verilog-modi-cache-preserve-buffer (current-buffer)))) 8710 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
8002 (equal (visited-file-modtime) (nth 2 fass))))) 8711 (equal (visited-file-modtime) (nth 2 fass)))))
8003 (setq verilog-modi-cache-list nil 8712 (setq verilog-modi-cache-list nil
8016 (setq func-returns (funcall function)) 8725 (setq func-returns (funcall function))
8017 (when fontlocked (font-lock-mode t)) 8726 (when fontlocked (font-lock-mode t))
8018 ;; Cache for next time 8727 ;; Cache for next time
8019 (setq verilog-modi-cache-list 8728 (setq verilog-modi-cache-list
8020 (cons (list (list modi function) 8729 (cons (list (list modi function)
8021 (buffer-modified-tick) 8730 (buffer-chars-modified-tick)
8022 (visited-file-modtime) 8731 (visited-file-modtime)
8023 func-returns) 8732 func-returns)
8024 verilog-modi-cache-list)) 8733 verilog-modi-cache-list))
8025 func-returns)))))) 8734 func-returns))))))
8026 8735
8042 This means that changes to the buffer will not result in the cache being 8751 This means that changes to the buffer will not result in the cache being
8043 flushed. If the changes affect the modsig state, they must call the 8752 flushed. If the changes affect the modsig state, they must call the
8044 modsig-cache-add-* function, else the results of later calls may be 8753 modsig-cache-add-* function, else the results of later calls may be
8045 incorrect. Without this, changes are assumed to be adding/removing signals 8754 incorrect. Without this, changes are assumed to be adding/removing signals
8046 and invalidating the cache." 8755 and invalidating the cache."
8047 `(let ((verilog-modi-cache-preserve-tick (buffer-modified-tick)) 8756 `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
8048 (verilog-modi-cache-preserve-buffer (current-buffer))) 8757 (verilog-modi-cache-preserve-buffer (current-buffer)))
8049 (progn ,@body))) 8758 (progn ,@body)))
8050 8759
8051 8760
8052 (defun verilog-signals-matching-enum (in-list enum) 8761 (defun verilog-signals-matching-enum (in-list enum)
8188 (insert (if v2k "," ";")) 8897 (insert (if v2k "," ";"))
8189 (if (or (not (verilog-sig-comment sig)) 8898 (if (or (not (verilog-sig-comment sig))
8190 (equal "" (verilog-sig-comment sig))) 8899 (equal "" (verilog-sig-comment sig)))
8191 (insert "\n") 8900 (insert "\n")
8192 (indent-to (max 48 (+ indent-pt 40))) 8901 (indent-to (max 48 (+ indent-pt 40)))
8193 (insert (concat "// " (verilog-sig-comment sig) "\n"))) 8902 (verilog-insert "// " (verilog-sig-comment sig) "\n"))
8194 (setq sigs (cdr sigs))))) 8903 (setq sigs (cdr sigs)))))
8195 8904
8196 (eval-when-compile 8905 (eval-when-compile
8197 (if (not (boundp 'indent-pt)) 8906 (if (not (boundp 'indent-pt))
8198 (defvar indent-pt nil "Local used by insert-indent"))) 8907 (defvar indent-pt nil "Local used by insert-indent")))
8202 Presumes that any newlines end a list element." 8911 Presumes that any newlines end a list element."
8203 (let ((need-indent t)) 8912 (let ((need-indent t))
8204 (while stuff 8913 (while stuff
8205 (if need-indent (indent-to indent-pt)) 8914 (if need-indent (indent-to indent-pt))
8206 (setq need-indent nil) 8915 (setq need-indent nil)
8207 (insert (car stuff)) 8916 (verilog-insert (car stuff))
8208 (setq need-indent (string-match "\n$" (car stuff)) 8917 (setq need-indent (string-match "\n$" (car stuff))
8209 stuff (cdr stuff))))) 8918 stuff (cdr stuff)))))
8210 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n")) 8919 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
8211 8920
8212 (defun verilog-repair-open-comma () 8921 (defun verilog-repair-open-comma ()
8434 called before and after this function, respectively." 9143 called before and after this function, respectively."
8435 (interactive) 9144 (interactive)
8436 (save-excursion 9145 (save-excursion
8437 (if (buffer-file-name) 9146 (if (buffer-file-name)
8438 (find-file-noselect (buffer-file-name))) ;; To check we have latest version 9147 (find-file-noselect (buffer-file-name))) ;; To check we have latest version
8439 ;; Allow user to customize 9148 (verilog-save-no-change-functions
8440 (run-hooks 'verilog-before-delete-auto-hook) 9149 (verilog-save-scan-cache
8441 9150 ;; Allow user to customize
8442 ;; Remove those that have multi-line insertions, possibly with parameters 9151 (run-hooks 'verilog-before-delete-auto-hook)
8443 (verilog-auto-re-search-do 9152
8444 (concat "/\\*" 9153 ;; Remove those that have multi-line insertions, possibly with parameters
8445 (eval-when-compile 9154 (verilog-auto-re-search-do
8446 (verilog-regexp-words 9155 (concat "/\\*"
8447 `("AUTOASCIIENUM" "AUTOCONCATCOMMENT" "AUTODEFINEVALUE" 9156 (eval-when-compile
8448 "AUTOINOUT" "AUTOINOUTCOMP" "AUTOINOUTMODULE" 9157 (verilog-regexp-words
8449 "AUTOINPUT" "AUTOINSERTLISP" "AUTOOUTPUT" "AUTOOUTPUTEVERY" 9158 `("AUTOASCIIENUM" "AUTOCONCATCOMMENT" "AUTODEFINEVALUE"
8450 "AUTOREG" "AUTOREGINPUT" "AUTORESET" "AUTOTIEOFF" 9159 "AUTOINOUT" "AUTOINOUTCOMP" "AUTOINOUTMODULE"
8451 "AUTOUNUSED" "AUTOWIRE"))) 9160 "AUTOINPUT" "AUTOINSERTLISP" "AUTOOUTPUT" "AUTOOUTPUTEVERY"
8452 ;; Optional parens or quoted parameter or .* for (((...))) 9161 "AUTOREG" "AUTOREGINPUT" "AUTORESET" "AUTOTIEOFF"
8453 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?" 9162 "AUTOUNUSED" "AUTOWIRE")))
8454 "\\*/") 9163 ;; Optional parens or quoted parameter or .* for (((...)))
8455 'verilog-delete-autos-lined) 9164 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
8456 ;; Remove those that are in parenthesis 9165 "\\*/")
8457 (verilog-auto-re-search-do 9166 'verilog-delete-autos-lined)
8458 (concat "/\\*" 9167 ;; Remove those that are in parenthesis
8459 (eval-when-compile 9168 (verilog-auto-re-search-do
8460 (verilog-regexp-words 9169 (concat "/\\*"
8461 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM" 9170 (eval-when-compile
8462 "AUTOSENSE"))) 9171 (verilog-regexp-words
8463 "\\*/") 9172 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
8464 'verilog-delete-to-paren) 9173 "AUTOSENSE")))
8465 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments 9174 "\\*/")
8466 (verilog-auto-re-search-do "\\.\\*" 9175 'verilog-delete-to-paren)
8467 'verilog-delete-auto-star-all) 9176 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
8468 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed 9177 (verilog-auto-re-search-do "\\.\\*"
8469 (goto-char (point-min)) 9178 'verilog-delete-auto-star-all)
8470 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)[ \tLT0-9]*$" nil t) 9179 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
8471 (replace-match "")) 9180 (goto-char (point-min))
8472 9181 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)[ \tLT0-9]*$" nil t)
8473 ;; Final customize 9182 (replace-match ""))
8474 (run-hooks 'verilog-delete-auto-hook))) 9183
9184 ;; Final customize
9185 (run-hooks 'verilog-delete-auto-hook)))))
8475 9186
8476 ;; 9187 ;;
8477 ;; Auto inject 9188 ;; Auto inject
8478 ;; 9189 ;;
8479 9190
8534 (verilog-re-search-forward-quick ";" nil t) 9245 (verilog-re-search-forward-quick ";" nil t)
8535 (backward-char 1) 9246 (backward-char 1)
8536 (verilog-backward-syntactic-ws) 9247 (verilog-backward-syntactic-ws)
8537 (backward-char 1) ; Moves to paren that closes argdecl's 9248 (backward-char 1) ; Moves to paren that closes argdecl's
8538 (when (looking-at ")") 9249 (when (looking-at ")")
8539 (insert "/*AUTOARG*/"))))))) 9250 (verilog-insert "/*AUTOARG*/")))))))
8540 9251
8541 (defun verilog-inject-sense () 9252 (defun verilog-inject-sense ()
8542 "Inject AUTOSENSE into new code. See `verilog-inject-auto'." 9253 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
8543 (save-excursion 9254 (save-excursion
8544 (goto-char (point-min)) 9255 (goto-char (point-min))
8556 (verilog-read-signals start-pt (point))) 9267 (verilog-read-signals start-pt (point)))
8557 got-sigs (verilog-auto-sense-sigs moddecls nil)) 9268 got-sigs (verilog-auto-sense-sigs moddecls nil))
8558 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal? 9269 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
8559 (verilog-signals-not-in got-sigs pre-sigs))) 9270 (verilog-signals-not-in got-sigs pre-sigs)))
8560 (delete-region start-pt (point)) 9271 (delete-region start-pt (point))
8561 (insert "/*AS*/"))))))) 9272 (verilog-insert "/*AS*/")))))))
8562 9273
8563 (defun verilog-inject-inst () 9274 (defun verilog-inject-inst ()
8564 "Inject AUTOINST into new code. See `verilog-inject-auto'." 9275 "Inject AUTOINST into new code. See `verilog-inject-auto'."
8565 (save-excursion 9276 (save-excursion
8566 (goto-char (point-min)) 9277 (goto-char (point-min))
8590 (verilog-forward-close-paren) 9301 (verilog-forward-close-paren)
8591 (backward-char 1) 9302 (backward-char 1)
8592 ;; Not verilog-re-search, as we don't want to strip comments 9303 ;; Not verilog-re-search, as we don't want to strip comments
8593 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t) 9304 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
8594 (delete-region (match-beginning 0) (match-end 0))) 9305 (delete-region (match-beginning 0) (match-end 0)))
8595 (insert "\n") 9306 (verilog-insert "\n")
8596 (indent-to indent-pt) 9307 (verilog-insert-indent "/*AUTOINST*/")))))))))
8597 (insert "/*AUTOINST*/")))))))))
8598 9308
8599 ;; 9309 ;;
8600 ;; Auto save 9310 ;; Auto save
8601 ;; 9311 ;;
8602 9312
8609 (goto-char (point-min)) 9319 (goto-char (point-min))
8610 (re-search-forward "AUTO" nil t)))))) 9320 (re-search-forward "AUTO" nil t))))))
8611 ((eq verilog-auto-save-policy 'force) 9321 ((eq verilog-auto-save-policy 'force)
8612 (verilog-auto)) 9322 (verilog-auto))
8613 ((not (buffer-modified-p))) 9323 ((not (buffer-modified-p)))
8614 ((eq verilog-auto-update-tick (buffer-modified-tick))) ; up-to-date 9324 ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
8615 ((eq verilog-auto-save-policy 'detect) 9325 ((eq verilog-auto-save-policy 'detect)
8616 (verilog-auto)) 9326 (verilog-auto))
8617 (t 9327 (t
8618 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ") 9328 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
8619 (verilog-auto)) 9329 (verilog-auto))
8620 ;; Don't ask again if didn't update 9330 ;; Don't ask again if didn't update
8621 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick)))) 9331 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
8622 (when (not verilog-auto-star-save) 9332 (when (not verilog-auto-star-save)
8623 (verilog-delete-auto-star-implicit)) 9333 (verilog-delete-auto-star-implicit))
8624 nil) ;; Always return nil -- we don't write the file ourselves 9334 nil) ;; Always return nil -- we don't write the file ourselves
8625 9335
8626 (defun verilog-auto-read-locals () 9336 (defun verilog-auto-read-locals ()
8745 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning 9455 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
8746 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning 9456 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
8747 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning 9457 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
8748 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning 9458 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
8749 (defvar vl-dir 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
8750 9462
8751 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values) 9463 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
8752 "Print out a instantiation connection for this PORT-ST. 9464 "Print out a instantiation connection for this PORT-ST.
8753 Insert to INDENT-PT, use template TPL-LIST. 9465 Insert to INDENT-PT, use template TPL-LIST.
8754 @ are instantiation numbers, replaced with TPL-NUM. 9466 @ are instantiation numbers, replaced with TPL-NUM.
8760 (verilog-auto-inst-port-map port-st))) 9472 (verilog-auto-inst-port-map port-st)))
8761 ;; vl-* are documented for user use 9473 ;; vl-* are documented for user use
8762 (vl-name (verilog-sig-name port-st)) 9474 (vl-name (verilog-sig-name port-st))
8763 (vl-width (verilog-sig-width port-st)) 9475 (vl-width (verilog-sig-width port-st))
8764 (vl-modport (verilog-sig-modport 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) ""))
8765 (vl-bits (if (or verilog-auto-inst-vector 9479 (vl-bits (if (or verilog-auto-inst-vector
8766 (not (assoc port vector-skip-list)) 9480 (not (assoc port vector-skip-list))
8767 (not (equal (verilog-sig-bits port-st) 9481 (not (equal (verilog-sig-bits port-st)
8768 (verilog-sig-bits (assoc port vector-skip-list))))) 9482 (verilog-sig-bits (assoc port vector-skip-list)))))
8769 (or (verilog-sig-bits port-st) "") 9483 (or (verilog-sig-bits port-st) "")
8822 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net)) 9536 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
8823 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net))) 9537 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
8824 ;; Insert it 9538 ;; Insert it
8825 (indent-to indent-pt) 9539 (indent-to indent-pt)
8826 (insert "." port) 9540 (insert "." port)
8827 (indent-to verilog-auto-inst-column) 9541 (unless (and verilog-auto-inst-dot-name
8828 (insert "(" tpl-net "),") 9542 (equal port tpl-net))
9543 (indent-to verilog-auto-inst-column)
9544 (insert "(" tpl-net ")"))
9545 (insert ",")
8829 (cond (tpl-ass 9546 (cond (tpl-ass
8830 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) 9547 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
8831 verilog-auto-inst-column)) 9548 verilog-auto-inst-column))
8832 (insert " // Templated") 9549 (if verilog-auto-inst-template-numbers
8833 (when verilog-auto-inst-template-numbers 9550 (verilog-insert " // Templated"
8834 (insert " T" (int-to-string (nth 2 tpl-ass)) 9551 " T" (int-to-string (nth 2 tpl-ass))
8835 " L" (int-to-string (nth 3 tpl-ass))))) 9552 " L" (int-to-string (nth 3 tpl-ass)))
9553 (verilog-insert " // Templated")))
8836 (for-star 9554 (for-star
8837 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) 9555 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
8838 verilog-auto-inst-column)) 9556 verilog-auto-inst-column))
8839 (insert " // Implicit .\*"))) ;For some reason the . or * must be escaped... 9557 (verilog-insert " // Implicit .\*"))) ;For some reason the . or * must be escaped...
8840 (insert "\n"))) 9558 (insert "\n")))
8841 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3") 9559 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
8842 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]") 9560 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
8843 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));") 9561 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
8844 9562
8874 (when (verilog-auto-star-safe) 9592 (when (verilog-auto-star-safe)
8875 (verilog-auto-inst))) 9593 (verilog-auto-inst)))
8876 9594
8877 (defun verilog-auto-inst () 9595 (defun verilog-auto-inst ()
8878 "Expand AUTOINST statements, as part of \\[verilog-auto]. 9596 "Expand AUTOINST statements, as part of \\[verilog-auto].
8879 Replace the pin connections to an instantiation with ones 9597 Replace the pin connections to an instantiation or interface
8880 automatically derived from the module header of the instantiated netlist. 9598 declaration with ones automatically derived from the module or
9599 interface header of the instantiated item.
8881 9600
8882 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports, 9601 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
8883 and delete them before saving unless `verilog-auto-star-save' is set. 9602 and delete them before saving unless `verilog-auto-star-save' is set.
8884 See `verilog-auto-star' for more information. 9603 See `verilog-auto-star' for more information.
8885 9604
8895 9614
8896 Typedefs must match `verilog-typedef-regexp', which is disabled by default. 9615 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
8897 9616
8898 SystemVerilog multidimensional input/output has only experimental support. 9617 SystemVerilog multidimensional input/output has only experimental support.
8899 9618
9619 SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
9620
8900 Parameters referenced by the instantiation will remain symbolic, unless 9621 Parameters referenced by the instantiation will remain symbolic, unless
8901 `verilog-auto-inst-param-value' is set. 9622 `verilog-auto-inst-param-value' is set.
8902 9623
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.
9627
8903 For example, first take the submodule InstModule.v: 9628 For example, first take the submodule InstModule.v:
8904 9629
8905 module InstModule (o,i) 9630 module InstModule (o,i);
8906 output [31:0] o; 9631 output [31:0] o;
8907 input i; 9632 input i;
8908 wire [31:0] o = {32{i}}; 9633 wire [31:0] o = {32{i}};
8909 endmodule 9634 endmodule
8910 9635
8911 This is then used in a upper level module: 9636 This is then used in a upper level module:
8912 9637
8913 module ExampInst (o,i) 9638 module ExampInst (o,i);
8914 output o; 9639 output o;
8915 input i; 9640 input i;
8916 InstModule instName 9641 InstModule instName
8917 (/*AUTOINST*/); 9642 (/*AUTOINST*/);
8918 endmodule 9643 endmodule
8919 9644
8920 Typing \\[verilog-auto] will make this into: 9645 Typing \\[verilog-auto] will make this into:
8921 9646
8922 module ExampInst (o,i) 9647 module ExampInst (o,i);
8923 output o; 9648 output o;
8924 input i; 9649 input i;
8925 InstModule instName 9650 InstModule instName
8926 (/*AUTOINST*/ 9651 (/*AUTOINST*/
8927 // Outputs 9652 // Outputs
9108 There are special variables defined that are useful in these 9833 There are special variables defined that are useful in these
9109 Lisp functions: 9834 Lisp functions:
9110 9835
9111 vl-name Name portion of the input/output port. 9836 vl-name Name portion of the input/output port.
9112 vl-bits Bus bits portion of the input/output port ('[2:0]'). 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]').
9113 vl-width Width of the input/output port ('3' for [2:0]). 9839 vl-width Width of the input/output port ('3' for [2:0]).
9114 May be a (...) expression if bits isn't a constant. 9840 May be a (...) expression if bits isn't a constant.
9115 vl-dir Direction of the pin input/output/inout/interface. 9841 vl-dir Direction of the pin input/output/inout/interface.
9116 vl-modport The modport, if an interface with a modport. 9842 vl-modport The modport, if an interface with a modport.
9117 vl-cell-type Module name/type of the cell ('InstModule'). 9843 vl-cell-type Module name/type of the cell ('InstModule').
9167 (setq par-values (and verilog-auto-inst-param-value 9893 (setq par-values (and verilog-auto-inst-param-value
9168 (verilog-read-inst-param-value))) 9894 (verilog-read-inst-param-value)))
9169 9895
9170 ;; Lookup position, etc of submodule 9896 ;; Lookup position, etc of submodule
9171 ;; Note this may raise an error 9897 ;; Note this may raise an error
9172 (when (setq submodi (verilog-modi-lookup submod t)) 9898 (when (and (not (member submod verilog-gate-keywords))
9899 (setq submodi (verilog-modi-lookup submod t)))
9173 (setq submoddecls (verilog-modi-get-decls submodi)) 9900 (setq submoddecls (verilog-modi-get-decls submodi))
9174 ;; If there's a number in the instantiation, it may be a argument to the 9901 ;; If there's a number in the instantiation, it may be a argument to the
9175 ;; automatic variable instantiation program. 9902 ;; automatic variable instantiation program.
9176 (let* ((tpl-info (verilog-read-auto-template submod)) 9903 (let* ((tpl-info (verilog-read-auto-template submod))
9177 (tpl-regexp (aref tpl-info 0))) 9904 (tpl-regexp (aref tpl-info 0)))
9178 (setq tpl-num (if (string-match tpl-regexp inst) 9905 (setq tpl-num (if (string-match tpl-regexp inst)
9179 (match-string 1 inst) 9906 (match-string 1 inst)
9180 "") 9907 "")
9181 tpl-list (aref tpl-info 1))) 9908 tpl-list (aref tpl-info 1)))
9182 ;; Find submodule's signals and dump 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))
9914 skip-pins)))
9915 (vl-dir "interfaced"))
9916 (when sig-list
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))
9923 sig-list)))
9183 (let ((sig-list (verilog-signals-not-in 9924 (let ((sig-list (verilog-signals-not-in
9184 (verilog-decls-get-interfaces submoddecls) 9925 (verilog-decls-get-interfaces submoddecls)
9185 skip-pins)) 9926 skip-pins))
9186 (vl-dir "interface")) 9927 (vl-dir "interface"))
9187 (when sig-list 9928 (when sig-list
9188 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 9929 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9189 (indent-to indent-pt)
9190 ;; Note these are searched for in verilog-read-sub-decls. 9930 ;; Note these are searched for in verilog-read-sub-decls.
9191 (insert "// Interfaces\n") 9931 (verilog-insert-indent "// Interfaces\n")
9192 (mapc (lambda (port) 9932 (mapc (lambda (port)
9193 (verilog-auto-inst-port port indent-pt 9933 (verilog-auto-inst-port port indent-pt
9194 tpl-list tpl-num for-star par-values)) 9934 tpl-list tpl-num for-star par-values))
9195 sig-list))) 9935 sig-list)))
9196 (let ((sig-list (verilog-signals-not-in 9936 (let ((sig-list (verilog-signals-not-in
9197 (verilog-decls-get-outputs submoddecls) 9937 (verilog-decls-get-outputs submoddecls)
9198 skip-pins)) 9938 skip-pins))
9199 (vl-dir "output")) 9939 (vl-dir "output"))
9200 (when sig-list 9940 (when sig-list
9201 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 9941 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9202 (indent-to indent-pt) 9942 (verilog-insert-indent "// Outputs\n")
9203 (insert "// Outputs\n")
9204 (mapc (lambda (port) 9943 (mapc (lambda (port)
9205 (verilog-auto-inst-port port indent-pt 9944 (verilog-auto-inst-port port indent-pt
9206 tpl-list tpl-num for-star par-values)) 9945 tpl-list tpl-num for-star par-values))
9207 sig-list))) 9946 sig-list)))
9208 (let ((sig-list (verilog-signals-not-in 9947 (let ((sig-list (verilog-signals-not-in
9209 (verilog-decls-get-inouts submoddecls) 9948 (verilog-decls-get-inouts submoddecls)
9210 skip-pins)) 9949 skip-pins))
9211 (vl-dir "inout")) 9950 (vl-dir "inout"))
9212 (when sig-list 9951 (when sig-list
9213 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 9952 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9214 (indent-to indent-pt) 9953 (verilog-insert-indent "// Inouts\n")
9215 (insert "// Inouts\n")
9216 (mapc (lambda (port) 9954 (mapc (lambda (port)
9217 (verilog-auto-inst-port port indent-pt 9955 (verilog-auto-inst-port port indent-pt
9218 tpl-list tpl-num for-star par-values)) 9956 tpl-list tpl-num for-star par-values))
9219 sig-list))) 9957 sig-list)))
9220 (let ((sig-list (verilog-signals-not-in 9958 (let ((sig-list (verilog-signals-not-in
9221 (verilog-decls-get-inputs submoddecls) 9959 (verilog-decls-get-inputs submoddecls)
9222 skip-pins)) 9960 skip-pins))
9223 (vl-dir "input")) 9961 (vl-dir "input"))
9224 (when sig-list 9962 (when sig-list
9225 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 9963 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9226 (indent-to indent-pt) 9964 (verilog-insert-indent "// Inputs\n")
9227 (insert "// Inputs\n")
9228 (mapc (lambda (port) 9965 (mapc (lambda (port)
9229 (verilog-auto-inst-port port indent-pt 9966 (verilog-auto-inst-port port indent-pt
9230 tpl-list tpl-num for-star par-values)) 9967 tpl-list tpl-num for-star par-values))
9231 sig-list))) 9968 sig-list)))
9232 ;; Kill extra semi 9969 ;; Kill extra semi
9234 (cond (did-first 9971 (cond (did-first
9235 (re-search-backward "," pt t) 9972 (re-search-backward "," pt t)
9236 (delete-char 1) 9973 (delete-char 1)
9237 (insert ");") 9974 (insert ");")
9238 (search-forward "\n") ;; Added by inst-port 9975 (search-forward "\n") ;; Added by inst-port
9239 (delete-backward-char 1) 9976 (delete-char -1)
9240 (if (search-forward ")" nil t) ;; From user, moved up a line 9977 (if (search-forward ")" nil t) ;; From user, moved up a line
9241 (delete-backward-char 1)) 9978 (delete-char -1))
9242 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it 9979 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it
9243 (delete-backward-char 1))))))))) 9980 (delete-char -1)))))))))
9244 9981
9245 (defun verilog-auto-inst-param () 9982 (defun verilog-auto-inst-param ()
9246 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto]. 9983 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
9247 Replace the parameter connections to an instantiation with ones 9984 Replace the parameter connections to an instantiation with ones
9248 automatically derived from the module header of the instantiated netlist. 9985 automatically derived from the module header of the instantiated netlist.
9250 See \\[verilog-auto-inst] for limitations, and templates to customize the 9987 See \\[verilog-auto-inst] for limitations, and templates to customize the
9251 output. 9988 output.
9252 9989
9253 For example, first take the submodule InstModule.v: 9990 For example, first take the submodule InstModule.v:
9254 9991
9255 module InstModule (o,i) 9992 module InstModule (o,i);
9256 parameter PAR; 9993 parameter PAR;
9257 endmodule 9994 endmodule
9258 9995
9259 This is then used in a upper level module: 9996 This is then used in a upper level module:
9260 9997
9261 module ExampInst (o,i) 9998 module ExampInst (o,i);
9262 parameter PAR; 9999 parameter PAR;
9263 InstModule #(/*AUTOINSTPARAM*/) 10000 InstModule #(/*AUTOINSTPARAM*/)
9264 instName (/*AUTOINST*/); 10001 instName (/*AUTOINST*/);
9265 endmodule 10002 endmodule
9266 10003
9267 Typing \\[verilog-auto] will make this into: 10004 Typing \\[verilog-auto] will make this into:
9268 10005
9269 module ExampInst (o,i) 10006 module ExampInst (o,i);
9270 output o; 10007 output o;
9271 input i; 10008 input i;
9272 InstModule #(/*AUTOINSTPARAM*/ 10009 InstModule #(/*AUTOINSTPARAM*/
9273 // Parameters 10010 // Parameters
9274 .PAR (PAR)); 10011 .PAR (PAR));
9327 (verilog-decls-get-gparams submoddecls) 10064 (verilog-decls-get-gparams submoddecls)
9328 skip-pins)) 10065 skip-pins))
9329 (vl-dir "parameter")) 10066 (vl-dir "parameter"))
9330 (when sig-list 10067 (when sig-list
9331 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 10068 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9332 (indent-to indent-pt)
9333 ;; Note these are searched for in verilog-read-sub-decls. 10069 ;; Note these are searched for in verilog-read-sub-decls.
9334 (insert "// Parameters\n") 10070 (verilog-insert-indent "// Parameters\n")
9335 (mapc (lambda (port) 10071 (mapc (lambda (port)
9336 (verilog-auto-inst-port port indent-pt 10072 (verilog-auto-inst-port port indent-pt
9337 tpl-list tpl-num nil nil)) 10073 tpl-list tpl-num nil nil))
9338 sig-list))) 10074 sig-list)))
9339 ;; Kill extra semi 10075 ;; Kill extra semi
9341 (cond (did-first 10077 (cond (did-first
9342 (re-search-backward "," pt t) 10078 (re-search-backward "," pt t)
9343 (delete-char 1) 10079 (delete-char 1)
9344 (insert ")") 10080 (insert ")")
9345 (search-forward "\n") ;; Added by inst-port 10081 (search-forward "\n") ;; Added by inst-port
9346 (delete-backward-char 1) 10082 (delete-char -1)
9347 (if (search-forward ")" nil t) ;; From user, moved up a line 10083 (if (search-forward ")" nil t) ;; From user, moved up a line
9348 (delete-backward-char 1))))))))) 10084 (delete-char -1)))))))))
9349 10085
9350 (defun verilog-auto-reg () 10086 (defun verilog-auto-reg ()
9351 "Expand AUTOREG statements, as part of \\[verilog-auto]. 10087 "Expand AUTOREG statements, as part of \\[verilog-auto].
9352 Make reg statements for any output that isn't already declared, 10088 Make reg statements for any output that isn't already declared,
9353 and isn't a wire output from a block. 10089 and isn't a wire output from a block.
9357 10093
9358 This does NOT work on memories, declare those yourself. 10094 This does NOT work on memories, declare those yourself.
9359 10095
9360 An example: 10096 An example:
9361 10097
9362 module ExampReg (o,i) 10098 module ExampReg (o,i);
9363 output o; 10099 output o;
9364 input i; 10100 input i;
9365 /*AUTOREG*/ 10101 /*AUTOREG*/
9366 always o = i; 10102 always o = i;
9367 endmodule 10103 endmodule
9368 10104
9369 Typing \\[verilog-auto] will make this into: 10105 Typing \\[verilog-auto] will make this into:
9370 10106
9371 module ExampReg (o,i) 10107 module ExampReg (o,i);
9372 output o; 10108 output o;
9373 input i; 10109 input i;
9374 /*AUTOREG*/ 10110 /*AUTOREG*/
9375 // Beginning of automatic regs (for this module's undeclared outputs) 10111 // Beginning of automatic regs (for this module's undeclared outputs)
9376 reg o; 10112 reg o;
9388 (append (verilog-decls-get-wires moddecls) 10124 (append (verilog-decls-get-wires moddecls)
9389 (verilog-decls-get-regs moddecls) 10125 (verilog-decls-get-regs moddecls)
9390 (verilog-decls-get-assigns moddecls) 10126 (verilog-decls-get-assigns moddecls)
9391 (verilog-decls-get-consts moddecls) 10127 (verilog-decls-get-consts moddecls)
9392 (verilog-decls-get-gparams moddecls) 10128 (verilog-decls-get-gparams moddecls)
10129 (verilog-subdecls-get-interfaced modsubdecls)
9393 (verilog-subdecls-get-outputs modsubdecls) 10130 (verilog-subdecls-get-outputs modsubdecls)
9394 (verilog-subdecls-get-inouts modsubdecls))))) 10131 (verilog-subdecls-get-inouts modsubdecls)))))
9395 (forward-line 1) 10132 (forward-line 1)
9396 (when sig-list 10133 (when sig-list
9397 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n") 10134 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
9410 10147
9411 This does NOT work on memories, declare those yourself. 10148 This does NOT work on memories, declare those yourself.
9412 10149
9413 An example (see `verilog-auto-inst' for what else is going on here): 10150 An example (see `verilog-auto-inst' for what else is going on here):
9414 10151
9415 module ExampRegInput (o,i) 10152 module ExampRegInput (o,i);
9416 output o; 10153 output o;
9417 input i; 10154 input i;
9418 /*AUTOREGINPUT*/ 10155 /*AUTOREGINPUT*/
9419 InstModule instName 10156 InstModule instName
9420 (/*AUTOINST*/); 10157 (/*AUTOINST*/);
9421 endmodule 10158 endmodule
9422 10159
9423 Typing \\[verilog-auto] will make this into: 10160 Typing \\[verilog-auto] will make this into:
9424 10161
9425 module ExampRegInput (o,i) 10162 module ExampRegInput (o,i);
9426 output o; 10163 output o;
9427 input i; 10164 input i;
9428 /*AUTOREGINPUT*/ 10165 /*AUTOREGINPUT*/
9429 // Beginning of automatic reg inputs (for undeclared ... 10166 // Beginning of automatic reg inputs (for undeclared ...
9430 reg [31:0] iv; // From inst of inst.v 10167 reg [31:0] iv; // From inst of inst.v
9472 non-numeric or non-sequential bus subscripts. If Verilog mode 10209 non-numeric or non-sequential bus subscripts. If Verilog mode
9473 mis-guessed, you'll have to declare them yourself. 10210 mis-guessed, you'll have to declare them yourself.
9474 10211
9475 An example (see `verilog-auto-inst' for what else is going on here): 10212 An example (see `verilog-auto-inst' for what else is going on here):
9476 10213
9477 module ExampWire (o,i) 10214 module ExampWire (o,i);
9478 output o; 10215 output o;
9479 input i; 10216 input i;
9480 /*AUTOWIRE*/ 10217 /*AUTOWIRE*/
9481 InstModule instName 10218 InstModule instName
9482 (/*AUTOINST*/); 10219 (/*AUTOINST*/);
9483 endmodule 10220 endmodule
9484 10221
9485 Typing \\[verilog-auto] will make this into: 10222 Typing \\[verilog-auto] will make this into:
9486 10223
9487 module ExampWire (o,i) 10224 module ExampWire (o,i);
9488 output o; 10225 output o;
9489 input i; 10226 input i;
9490 /*AUTOWIRE*/ 10227 /*AUTOWIRE*/
9491 // Beginning of automatic wires 10228 // Beginning of automatic wires
9492 wire [31:0] ov; // From inst of inst.v 10229 wire [31:0] ov; // From inst of inst.v
9542 10279
9543 Signals matching `verilog-auto-output-ignore-regexp' are not included. 10280 Signals matching `verilog-auto-output-ignore-regexp' are not included.
9544 10281
9545 An example (see `verilog-auto-inst' for what else is going on here): 10282 An example (see `verilog-auto-inst' for what else is going on here):
9546 10283
9547 module ExampOutput (ov,i) 10284 module ExampOutput (ov,i);
9548 input i; 10285 input i;
9549 /*AUTOOUTPUT*/ 10286 /*AUTOOUTPUT*/
9550 InstModule instName 10287 InstModule instName
9551 (/*AUTOINST*/); 10288 (/*AUTOINST*/);
9552 endmodule 10289 endmodule
9553 10290
9554 Typing \\[verilog-auto] will make this into: 10291 Typing \\[verilog-auto] will make this into:
9555 10292
9556 module ExampOutput (ov,i) 10293 module ExampOutput (ov,i);
9557 input i; 10294 input i;
9558 /*AUTOOUTPUT*/ 10295 /*AUTOOUTPUT*/
9559 // Beginning of automatic outputs (from unused autoinst outputs) 10296 // Beginning of automatic outputs (from unused autoinst outputs)
9560 output [31:0] ov; // From inst of inst.v 10297 output [31:0] ov; // From inst of inst.v
9561 // End of automatics 10298 // End of automatics
9608 useful to get Synopsys to preserve every signal in the design, since it 10345 useful to get Synopsys to preserve every signal in the design, since it
9609 won't optimize away the outputs. 10346 won't optimize away the outputs.
9610 10347
9611 An example: 10348 An example:
9612 10349
9613 module ExampOutputEvery (o,i,tempa,tempb) 10350 module ExampOutputEvery (o,i,tempa,tempb);
9614 output o; 10351 output o;
9615 input i; 10352 input i;
9616 /*AUTOOUTPUTEVERY*/ 10353 /*AUTOOUTPUTEVERY*/
9617 wire tempa = i; 10354 wire tempa = i;
9618 wire tempb = tempa; 10355 wire tempb = tempa;
9619 wire o = tempb; 10356 wire o = tempb;
9620 endmodule 10357 endmodule
9621 10358
9622 Typing \\[verilog-auto] will make this into: 10359 Typing \\[verilog-auto] will make this into:
9623 10360
9624 module ExampOutputEvery (o,i,tempa,tempb) 10361 module ExampOutputEvery (o,i,tempa,tempb);
9625 output o; 10362 output o;
9626 input i; 10363 input i;
9627 /*AUTOOUTPUTEVERY*/ 10364 /*AUTOOUTPUTEVERY*/
9628 // Beginning of automatic outputs (every signal) 10365 // Beginning of automatic outputs (every signal)
9629 output tempb; 10366 output tempb;
9671 10408
9672 Signals matching `verilog-auto-input-ignore-regexp' are not included. 10409 Signals matching `verilog-auto-input-ignore-regexp' are not included.
9673 10410
9674 An example (see `verilog-auto-inst' for what else is going on here): 10411 An example (see `verilog-auto-inst' for what else is going on here):
9675 10412
9676 module ExampInput (ov,i) 10413 module ExampInput (ov,i);
9677 output [31:0] ov; 10414 output [31:0] ov;
9678 /*AUTOINPUT*/ 10415 /*AUTOINPUT*/
9679 InstModule instName 10416 InstModule instName
9680 (/*AUTOINST*/); 10417 (/*AUTOINST*/);
9681 endmodule 10418 endmodule
9682 10419
9683 Typing \\[verilog-auto] will make this into: 10420 Typing \\[verilog-auto] will make this into:
9684 10421
9685 module ExampInput (ov,i) 10422 module ExampInput (ov,i);
9686 output [31:0] ov; 10423 output [31:0] ov;
9687 /*AUTOINPUT*/ 10424 /*AUTOINPUT*/
9688 // Beginning of automatic inputs (from unused autoinst inputs) 10425 // Beginning of automatic inputs (from unused autoinst inputs)
9689 input i; // From inst of inst.v 10426 input i; // From inst of inst.v
9690 // End of automatics 10427 // End of automatics
9715 (verilog-decls-get-inouts moddecls) 10452 (verilog-decls-get-inouts moddecls)
9716 (verilog-decls-get-wires moddecls) 10453 (verilog-decls-get-wires moddecls)
9717 (verilog-decls-get-regs moddecls) 10454 (verilog-decls-get-regs moddecls)
9718 (verilog-decls-get-consts moddecls) 10455 (verilog-decls-get-consts moddecls)
9719 (verilog-decls-get-gparams moddecls) 10456 (verilog-decls-get-gparams moddecls)
10457 (verilog-subdecls-get-interfaced modsubdecls)
9720 (verilog-subdecls-get-outputs modsubdecls) 10458 (verilog-subdecls-get-outputs modsubdecls)
9721 (verilog-subdecls-get-inouts modsubdecls))))) 10459 (verilog-subdecls-get-inouts modsubdecls)))))
9722 (when regexp 10460 (when regexp
9723 (setq sig-list (verilog-signals-matching-regexp 10461 (setq sig-list (verilog-signals-matching-regexp
9724 sig-list regexp))) 10462 sig-list regexp)))
9751 10489
9752 Signals matching `verilog-auto-inout-ignore-regexp' are not included. 10490 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
9753 10491
9754 An example (see `verilog-auto-inst' for what else is going on here): 10492 An example (see `verilog-auto-inst' for what else is going on here):
9755 10493
9756 module ExampInout (ov,i) 10494 module ExampInout (ov,i);
9757 input i; 10495 input i;
9758 /*AUTOINOUT*/ 10496 /*AUTOINOUT*/
9759 InstModule instName 10497 InstModule instName
9760 (/*AUTOINST*/); 10498 (/*AUTOINST*/);
9761 endmodule 10499 endmodule
9762 10500
9763 Typing \\[verilog-auto] will make this into: 10501 Typing \\[verilog-auto] will make this into:
9764 10502
9765 module ExampInout (ov,i) 10503 module ExampInout (ov,i);
9766 input i; 10504 input i;
9767 /*AUTOINOUT*/ 10505 /*AUTOINOUT*/
9768 // Beginning of automatic inouts (from unused autoinst inouts) 10506 // Beginning of automatic inouts (from unused autoinst inouts)
9769 inout [31:0] ov; // From inst of inst.v 10507 inout [31:0] ov; // From inst of inst.v
9770 // End of automatics 10508 // End of automatics
9815 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto]. 10553 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
9816 Take input/output/inout statements from the specified module and insert 10554 Take input/output/inout statements from the specified module and insert
9817 into the current module. This is useful for making null templates and 10555 into the current module. This is useful for making null templates and
9818 shell modules which need to have identical I/O with another module. 10556 shell modules which need to have identical I/O with another module.
9819 Any I/O which are already defined in this module will not be redefined. 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'.
9820 10559
9821 Limitations: 10560 Limitations:
9822 If placed inside the parenthesis of a module declaration, it creates 10561 If placed inside the parenthesis of a module declaration, it creates
9823 Verilog 2001 style, else uses Verilog 1995 style. 10562 Verilog 2001 style, else uses Verilog 1995 style.
9824 10563
9830 though they will appear to be in the same order to a AUTOINST 10569 though they will appear to be in the same order to a AUTOINST
9831 instantiating either module. 10570 instantiating either module.
9832 10571
9833 An example: 10572 An example:
9834 10573
9835 module ExampShell (/*AUTOARG*/) 10574 module ExampShell (/*AUTOARG*/);
9836 /*AUTOINOUTMODULE(\"ExampMain\")*/ 10575 /*AUTOINOUTMODULE(\"ExampMain\")*/
9837 endmodule 10576 endmodule
9838 10577
9839 module ExampMain (i,o,io) 10578 module ExampMain (i,o,io);
9840 input i; 10579 input i;
9841 output o; 10580 output o;
9842 inout io; 10581 inout io;
9843 endmodule 10582 endmodule
9844 10583
9845 Typing \\[verilog-auto] will make this into: 10584 Typing \\[verilog-auto] will make this into:
9846 10585
9847 module ExampShell (/*AUTOARG*/i,o,io) 10586 module ExampShell (/*AUTOARG*/i,o,io);
9848 /*AUTOINOUTMODULE(\"ExampMain\")*/ 10587 /*AUTOINOUTMODULE(\"ExampMain\")*/
9849 // Beginning of automatic in/out/inouts (from specific module) 10588 // Beginning of automatic in/out/inouts (from specific module)
9850 output o; 10589 output o;
9851 inout io; 10590 inout io;
9852 input i; 10591 input i;
9933 Take input/output/inout statements from the specified module and 10672 Take input/output/inout statements from the specified module and
9934 insert the inverse into the current module (inputs become outputs 10673 insert the inverse into the current module (inputs become outputs
9935 and vice-versa.) This is useful for making test and stimulus 10674 and vice-versa.) This is useful for making test and stimulus
9936 modules which need to have complementing I/O with another module. 10675 modules which need to have complementing I/O with another module.
9937 Any I/O which are already defined in this module will not be 10676 Any I/O which are already defined in this module will not be
9938 redefined. 10677 redefined. For the complement of this function, see
10678 `verilog-auto-inout-module'.
9939 10679
9940 Limitations: 10680 Limitations:
9941 If placed inside the parenthesis of a module declaration, it creates 10681 If placed inside the parenthesis of a module declaration, it creates
9942 Verilog 2001 style, else uses Verilog 1995 style. 10682 Verilog 2001 style, else uses Verilog 1995 style.
9943 10683
9949 though they will appear to be in the same order to a AUTOINST 10689 though they will appear to be in the same order to a AUTOINST
9950 instantiating either module. 10690 instantiating either module.
9951 10691
9952 An example: 10692 An example:
9953 10693
9954 module ExampShell (/*AUTOARG*/) 10694 module ExampShell (/*AUTOARG*/);
9955 /*AUTOINOUTCOMP(\"ExampMain\")*/ 10695 /*AUTOINOUTCOMP(\"ExampMain\")*/
9956 endmodule 10696 endmodule
9957 10697
9958 module ExampMain (i,o,io) 10698 module ExampMain (i,o,io);
9959 input i; 10699 input i;
9960 output o; 10700 output o;
9961 inout io; 10701 inout io;
9962 endmodule 10702 endmodule
9963 10703
9964 Typing \\[verilog-auto] will make this into: 10704 Typing \\[verilog-auto] will make this into:
9965 10705
9966 module ExampShell (/*AUTOARG*/i,o,io) 10706 module ExampShell (/*AUTOARG*/i,o,io);
9967 /*AUTOINOUTCOMP(\"ExampMain\")*/ 10707 /*AUTOINOUTCOMP(\"ExampMain\")*/
9968 // Beginning of automatic in/out/inouts (from specific module) 10708 // Beginning of automatic in/out/inouts (from specific module)
9969 output i; 10709 output i;
9970 inout io; 10710 inout io;
9971 input o; 10711 input o;
10035 (verilog-insert-indent "// Beginning of automatic insert lisp\n") 10775 (verilog-insert-indent "// Beginning of automatic insert lisp\n")
10036 (verilog-insert-indent "// End of automatics\n") 10776 (verilog-insert-indent "// End of automatics\n")
10037 (forward-line -1) 10777 (forward-line -1)
10038 (eval (read cmd)) 10778 (eval (read cmd))
10039 (forward-line -1) 10779 (forward-line -1)
10780 (setq verilog-scan-cache-tick nil) ;; Clear cache; inserted unknown text
10040 (verilog-delete-empty-auto-pair)))) 10781 (verilog-delete-empty-auto-pair))))
10041 10782
10042 (defun verilog-auto-sense-sigs (moddecls presense-sigs) 10783 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
10043 "Return list of signals for current AUTOSENSE block." 10784 "Return list of signals for current AUTOSENSE block."
10044 (let* ((sigss (verilog-read-always-signals)) 10785 (let* ((sigss (verilog-read-always-signals))
10045 (sig-list (verilog-signals-not-params 10786 (sig-list (verilog-signals-not-params
10046 (verilog-signals-not-in (verilog-alw-get-inputs sigss) 10787 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
10047 (append (and (not verilog-auto-sense-include-inputs) 10788 (append (and (not verilog-auto-sense-include-inputs)
10048 (verilog-alw-get-outputs sigss)) 10789 (verilog-alw-get-outputs sigss))
10790 (verilog-alw-get-temps sigss)
10049 (verilog-decls-get-consts moddecls) 10791 (verilog-decls-get-consts moddecls)
10050 (verilog-decls-get-gparams moddecls) 10792 (verilog-decls-get-gparams moddecls)
10051 presense-sigs))))) 10793 presense-sigs)))))
10052 sig-list)) 10794 sig-list))
10053 10795
10126 (verilog-read-signals start-pt (point))))) 10868 (verilog-read-signals start-pt (point)))))
10127 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs)) 10869 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
10128 (when sig-memories 10870 (when sig-memories
10129 (let ((tlen (length sig-list))) 10871 (let ((tlen (length sig-list)))
10130 (setq sig-list (verilog-signals-not-in sig-list sig-memories)) 10872 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
10131 (if (not (eq tlen (length sig-list))) (insert " /*memory or*/ ")))) 10873 (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
10132 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/" 10874 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/"
10133 (save-excursion (goto-char (point)) 10875 (save-excursion (goto-char (point))
10134 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t) 10876 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t)
10135 (verilog-re-search-backward "\\s-" start-pt t) 10877 (verilog-re-search-backward "\\s-" start-pt t)
10136 (while (looking-at "\\s-`endif") 10878 (while (looking-at "\\s-`endif")
10226 (setq sigss (verilog-read-always-signals))) 10968 (setq sigss (verilog-read-always-signals)))
10227 (setq assignment-str (if (verilog-alw-get-uses-delayed sigss) 10969 (setq assignment-str (if (verilog-alw-get-uses-delayed sigss)
10228 (concat " <= " verilog-assignment-delay) 10970 (concat " <= " verilog-assignment-delay)
10229 " = ")) 10971 " = "))
10230 (setq sig-list (verilog-signals-not-in (verilog-alw-get-outputs sigss) 10972 (setq sig-list (verilog-signals-not-in (verilog-alw-get-outputs sigss)
10231 prereset-sigs)) 10973 (append
10974 (verilog-alw-get-temps sigss)
10975 prereset-sigs)))
10232 (setq sig-list (sort sig-list `verilog-signals-sort-compare)) 10976 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
10233 (when sig-list 10977 (when sig-list
10234 (insert "\n"); 10978 (insert "\n");
10235 (indent-to indent-pt) 10979 (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
10236 (insert "// Beginning of autoreset for uninitialized flops\n");
10237 (indent-to indent-pt) 10980 (indent-to indent-pt)
10238 (while sig-list 10981 (while sig-list
10239 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths 10982 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths
10240 (car sig-list)))) 10983 (car sig-list))))
10241 (insert (verilog-sig-name sig) 10984 (insert (verilog-sig-name sig)
10242 assignment-str 10985 assignment-str
10243 (verilog-sig-tieoff sig (not verilog-auto-reset-widths)) 10986 (verilog-sig-tieoff sig (not verilog-auto-reset-widths))
10244 ";\n") 10987 ";\n")
10245 (indent-to indent-pt) 10988 (indent-to indent-pt)
10246 (setq sig-list (cdr sig-list)))) 10989 (setq sig-list (cdr sig-list))))
10247 (insert "// End of automatics"))))) 10990 (verilog-insert "// End of automatics")))))
10248 10991
10249 (defun verilog-auto-tieoff () 10992 (defun verilog-auto-tieoff ()
10250 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto]. 10993 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
10251 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output 10994 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
10252 signals to deasserted. 10995 signals to deasserted.
10257 as a register or wire, creates a tieoff. 11000 as a register or wire, creates a tieoff.
10258 11001
10259 AUTORESET ties signals to deasserted, which is presumed to be zero. 11002 AUTORESET ties signals to deasserted, which is presumed to be zero.
10260 Signals that match `verilog-active-low-regexp' will be deasserted by tieing 11003 Signals that match `verilog-active-low-regexp' will be deasserted by tieing
10261 them to a one. 11004 them to a one.
11005
11006 You can add signals you do not want included in AUTOTIEOFF with
11007 `verilog-auto-tieoff-ignore-regexp'.
10262 11008
10263 An example of making a stub for another module: 11009 An example of making a stub for another module:
10264 11010
10265 module ExampStub (/*AUTOINST*/); 11011 module ExampStub (/*AUTOINST*/);
10266 /*AUTOINOUTMODULE(\"Foo\")*/ 11012 /*AUTOINOUTMODULE(\"Foo\")*/
10298 (append (verilog-decls-get-wires moddecls) 11044 (append (verilog-decls-get-wires moddecls)
10299 (verilog-decls-get-regs moddecls) 11045 (verilog-decls-get-regs moddecls)
10300 (verilog-decls-get-assigns moddecls) 11046 (verilog-decls-get-assigns moddecls)
10301 (verilog-decls-get-consts moddecls) 11047 (verilog-decls-get-consts moddecls)
10302 (verilog-decls-get-gparams moddecls) 11048 (verilog-decls-get-gparams moddecls)
11049 (verilog-subdecls-get-interfaced modsubdecls)
10303 (verilog-subdecls-get-outputs modsubdecls) 11050 (verilog-subdecls-get-outputs modsubdecls)
10304 (verilog-subdecls-get-inouts modsubdecls))))) 11051 (verilog-subdecls-get-inouts modsubdecls)))))
11052 (setq sig-list (verilog-signals-not-matching-regexp
11053 sig-list verilog-auto-tieoff-ignore-regexp))
10305 (when sig-list 11054 (when sig-list
10306 (forward-line 1) 11055 (forward-line 1)
10307 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n") 11056 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
10308 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)) 11057 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
10309 (verilog-modi-cache-add-wires modi sig-list) ; Before we trash list 11058 (verilog-modi-cache-add-wires modi sig-list) ; Before we trash list
10551 11300
10552 (defun verilog-auto-templated-rel () 11301 (defun verilog-auto-templated-rel ()
10553 "Replace Templated relative line numbers with absolute line numbers. 11302 "Replace Templated relative line numbers with absolute line numbers.
10554 Internal use only. This hacks around the line numbers in AUTOINST Templates 11303 Internal use only. This hacks around the line numbers in AUTOINST Templates
10555 being different from the final output's line numbering." 11304 being different from the final output's line numbering."
10556 (let ((templateno 0) (template-line (list 0))) 11305 (let ((templateno 0) (template-line (list 0)) (buf-line 1))
10557 ;; Find line number each template is on 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
10558 (goto-char (point-min)) 11308 (goto-char (point-min))
10559 (while (search-forward "AUTO_TEMPLATE" nil t) 11309 (while (not (eobp))
10560 (setq templateno (1+ templateno)) 11310 (when (looking-at ".*AUTO_TEMPLATE")
10561 (setq template-line 11311 (setq templateno (1+ templateno))
10562 (cons (count-lines (point-min) (point)) template-line))) 11312 (setq template-line (cons buf-line template-line)))
11313 (setq buf-line (1+ buf-line))
11314 (forward-line 1))
10563 (setq template-line (nreverse template-line)) 11315 (setq template-line (nreverse template-line))
10564 ;; Replace T# L# with absolute line number 11316 ;; Replace T# L# with absolute line number
10565 (goto-char (point-min)) 11317 (goto-char (point-min))
10566 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t) 11318 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
10567 (replace-match 11319 (replace-match
10590 11342
10591 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are 11343 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
10592 called before and after this function, respectively. 11344 called before and after this function, respectively.
10593 11345
10594 For example: 11346 For example:
10595 module ModuleName (/*AUTOARG*/) 11347 module ModuleName (/*AUTOARG*/);
10596 /*AUTOINPUT*/ 11348 /*AUTOINPUT*/
10597 /*AUTOOUTPUT*/ 11349 /*AUTOOUTPUT*/
10598 /*AUTOWIRE*/ 11350 /*AUTOWIRE*/
10599 /*AUTOREG*/ 11351 /*AUTOREG*/
10600 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/); 11352 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
10646 (fontlocked (when (and (boundp 'font-lock-mode) 11398 (fontlocked (when (and (boundp 'font-lock-mode)
10647 font-lock-mode) 11399 font-lock-mode)
10648 (font-lock-mode 0) 11400 (font-lock-mode 0)
10649 t)) 11401 t))
10650 ;; Cache directories; we don't write new files, so can't change 11402 ;; Cache directories; we don't write new files, so can't change
10651 (verilog-dir-cache-preserving t)) 11403 (verilog-dir-cache-preserving t)
10652 (unwind-protect 11404 ;; Cache current module
10653 (save-excursion 11405 (verilog-modi-cache-current-enable t)
10654 ;; If we're not in verilog-mode, change syntax table so parsing works right 11406 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
10655 (unless (eq major-mode `verilog-mode) (verilog-mode)) 11407 verilog-modi-cache-current)
10656 ;; Allow user to customize 11408 (unwind-protect
10657 (run-hooks 'verilog-before-auto-hook) 11409 ;; Disable change hooks for speed
10658 ;; Try to save the user from needing to revert-file to reread file local-variables 11410 ;; This let can't be part of above let; must restore
10659 (verilog-auto-reeval-locals) 11411 ;; after-change-functions before font-lock resumes
10660 (verilog-read-auto-lisp (point-min) (point-max)) 11412 (verilog-save-no-change-functions
10661 (verilog-getopt-flags) 11413 (verilog-save-scan-cache
10662 ;; From here on out, we can cache anything we read from disk 11414 (save-excursion
10663 (verilog-preserve-dir-cache 11415 ;; If we're not in verilog-mode, change syntax table so parsing works right
10664 ;; These two may seem obvious to do always, but on large includes it can be way too slow 11416 (unless (eq major-mode `verilog-mode) (verilog-mode))
10665 (when verilog-auto-read-includes 11417 ;; Allow user to customize
10666 (verilog-read-includes) 11418 (run-hooks 'verilog-before-auto-hook)
10667 (verilog-read-defines nil nil t)) 11419 ;; Try to save the user from needing to revert-file to reread file local-variables
10668 ;; This particular ordering is important 11420 (verilog-auto-reeval-locals)
10669 ;; INST: Lower modules correct, no internal dependencies, FIRST 11421 (verilog-read-auto-lisp-present)
10670 (verilog-preserve-modi-cache 11422 (verilog-read-auto-lisp (point-min) (point-max))
10671 ;; Clear existing autos else we'll be screwed by existing ones 11423 (verilog-getopt-flags)
10672 (verilog-delete-auto) 11424 ;; From here on out, we can cache anything we read from disk
10673 ;; Injection if appropriate 11425 (verilog-preserve-dir-cache
10674 (when inject 11426 ;; These two may seem obvious to do always, but on large includes it can be way too slow
10675 (verilog-inject-inst) 11427 (when verilog-auto-read-includes
10676 (verilog-inject-sense) 11428 (verilog-read-includes)
10677 (verilog-inject-arg)) 11429 (verilog-read-defines nil nil t))
10678 ;; 11430 ;; This particular ordering is important
10679 ;; Do user inserts first, so their code can insert AUTOs 11431 ;; INST: Lower modules correct, no internal dependencies, FIRST
10680 ;; We may provide a AUTOINSERTLISPLAST if another cleanup pass is needed 11432 (verilog-preserve-modi-cache
10681 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/" 11433 ;; Clear existing autos else we'll be screwed by existing ones
10682 'verilog-auto-insert-lisp) 11434 (verilog-delete-auto)
10683 ;; Expand instances before need the signals the instances input/output 11435 ;; Injection if appropriate
10684 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param) 11436 (when inject
10685 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst) 11437 (verilog-inject-inst)
10686 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star) 11438 (verilog-inject-sense)
10687 ;; Doesn't matter when done, but combine it with a common changer 11439 (verilog-inject-arg))
10688 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense) 11440 ;;
10689 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset) 11441 ;; Do user inserts first, so their code can insert AUTOs
10690 ;; Must be done before autoin/out as creates a reg 11442 ;; We may provide a AUTOINSERTLISPLAST if another cleanup pass is needed
10691 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM([^)]*)\\*/" 'verilog-auto-ascii-enum) 11443 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
10692 ;; 11444 'verilog-auto-insert-lisp)
10693 ;; first in/outs from other files 11445 ;; Expand instances before need the signals the instances input/output
10694 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE([^)]*)\\*/" 'verilog-auto-inout-module) 11446 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
10695 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP([^)]*)\\*/" 'verilog-auto-inout-comp) 11447 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
10696 ;; next in/outs which need previous sucked inputs first 11448 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
10697 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((\"[^\"]*\")\\)\\*/" 11449 ;; Doesn't matter when done, but combine it with a common changer
10698 '(lambda () (verilog-auto-output t))) 11450 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
10699 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\*/" 'verilog-auto-output) 11451 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
10700 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((\"[^\"]*\")\\)\\*/" 11452 ;; Must be done before autoin/out as creates a reg
10701 '(lambda () (verilog-auto-input t))) 11453 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM([^)]*)\\*/" 'verilog-auto-ascii-enum)
10702 (verilog-auto-re-search-do "/\\*AUTOINPUT\\*/" 'verilog-auto-input) 11454 ;;
10703 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((\"[^\"]*\")\\)\\*/" 11455 ;; first in/outs from other files
10704 '(lambda () (verilog-auto-inout t))) 11456 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE([^)]*)\\*/" 'verilog-auto-inout-module)
10705 (verilog-auto-re-search-do "/\\*AUTOINOUT\\*/" 'verilog-auto-inout) 11457 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP([^)]*)\\*/" 'verilog-auto-inout-comp)
10706 ;; Then tie off those in/outs 11458 ;; next in/outs which need previous sucked inputs first
10707 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff) 11459 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((\"[^\"]*\")\\)\\*/"
10708 ;; Wires/regs must be after inputs/outputs 11460 '(lambda () (verilog-auto-output t)))
10709 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire) 11461 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\*/" 'verilog-auto-output)
10710 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg) 11462 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((\"[^\"]*\")\\)\\*/"
10711 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input) 11463 '(lambda () (verilog-auto-input t)))
10712 ;; outputevery needs AUTOOUTPUTs done first 11464 (verilog-auto-re-search-do "/\\*AUTOINPUT\\*/" 'verilog-auto-input)
10713 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\*/" 'verilog-auto-output-every) 11465 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((\"[^\"]*\")\\)\\*/"
10714 ;; After we've created all new variables 11466 '(lambda () (verilog-auto-inout t)))
10715 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused) 11467 (verilog-auto-re-search-do "/\\*AUTOINOUT\\*/" 'verilog-auto-inout)
10716 ;; Must be after all inputs outputs are generated 11468 ;; Then tie off those in/outs
10717 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg) 11469 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
10718 ;; Fix line numbers (comments only) 11470 ;; Wires/regs must be after inputs/outputs
10719 (verilog-auto-templated-rel))) 11471 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
10720 ;; 11472 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
10721 (run-hooks 'verilog-auto-hook) 11473 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
10722 ;; 11474 ;; outputevery needs AUTOOUTPUTs done first
10723 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick)) 11475 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\*/" 'verilog-auto-output-every)
10724 ;; 11476 ;; After we've created all new variables
10725 ;; If end result is same as when started, clear modified flag 11477 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
10726 (cond ((and oldbuf (equal oldbuf (buffer-string))) 11478 ;; Must be after all inputs outputs are generated
10727 (set-buffer-modified-p nil) 11479 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
10728 (unless noninteractive (message "Updating AUTOs...done (no changes)"))) 11480 ;; Fix line numbers (comments only)
10729 (t (unless noninteractive (message "Updating AUTOs...done"))))) 11481 (when verilog-auto-inst-template-numbers
10730 ;; Unwind forms 11482 (verilog-auto-templated-rel))))
10731 (progn 11483 ;;
10732 ;; Restore font-lock 11484 (run-hooks 'verilog-auto-hook)
10733 (when fontlocked (font-lock-mode t)))))) 11485 ;;
11486 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
11487 ;;
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
11494 )))
11495 ;; Unwind forms
11496 (progn
11497 ;; Restore font-lock
11498 (when fontlocked (font-lock-mode t))))))
10734 11499
10735 11500
10736 ;; 11501 ;;
10737 ;; Skeleton based code insertion 11502 ;; Skeleton based code insertion
10738 ;; 11503 ;;
11120 (define-key map [S-mouse-2] 'mouse-yank-at-click)) 11885 (define-key map [S-mouse-2] 'mouse-yank-at-click))
11121 map) 11886 map)
11122 "Map containing mouse bindings for `verilog-mode'.") 11887 "Map containing mouse bindings for `verilog-mode'.")
11123 11888
11124 11889
11125 (defun verilog-colorize-include-files (beg end old-len) 11890 (defun verilog-highlight-region (beg end old-len)
11126 "This function colorizes included files when the mouse passes over them. 11891 "Colorize included files and modules in the (changed?) region.
11127 Clicking on the middle-mouse button loads them in a buffer (as in dired)." 11892 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
11128 (save-excursion 11893 (when (or verilog-highlight-includes
11129 (save-match-data 11894 verilog-highlight-modules)
11130 (let (end-point) 11895 (save-excursion
11131 (goto-char end) 11896 (save-match-data ;; A query-replace may call this function - do not disturb
11132 (setq end-point (verilog-get-end-of-line)) 11897 (verilog-save-buffer-state
11133 (goto-char beg) 11898 (verilog-save-scan-cache
11134 (beginning-of-line) ; scan entire line ! 11899 (let (end-point)
11135 ;; delete overlays existing on this line 11900 (goto-char end)
11136 (let ((overlays (overlays-in (point) end-point))) 11901 (setq end-point (verilog-get-end-of-line))
11137 (while overlays 11902 (goto-char beg)
11138 (if (and 11903 (beginning-of-line) ; scan entire line
11139 (overlay-get (car overlays) 'detachable) 11904 ;; delete overlays existing on this line
11140 (overlay-get (car overlays) 'verilog-include-file)) 11905 (let ((overlays (overlays-in (point) end-point)))
11141 (delete-overlay (car overlays))) 11906 (while overlays
11142 (setq overlays (cdr overlays)))) ; let 11907 (if (and
11143 ;; make new ones, could reuse deleted one ? 11908 (overlay-get (car overlays) 'detachable)
11144 (while (search-forward-regexp verilog-include-file-regexp end-point t) 11909 (or (overlay-get (car overlays) 'verilog-include-file)
11145 (let (ov) 11910 (overlay-get (car overlays) 'verilog-inst-module)))
11146 (goto-char (match-beginning 1)) 11911 (delete-overlay (car overlays)))
11147 (setq ov (make-overlay (match-beginning 1) (match-end 1))) 11912 (setq overlays (cdr overlays))))
11148 (overlay-put ov 'start-closed 't) 11913 ;;
11149 (overlay-put ov 'end-closed 't) 11914 ;; make new include overlays
11150 (overlay-put ov 'evaporate 't) 11915 (when verilog-highlight-includes
11151 (overlay-put ov 'verilog-include-file 't) 11916 (while (search-forward-regexp verilog-include-file-regexp end-point t)
11152 (overlay-put ov 'mouse-face 'highlight) 11917 (goto-char (match-beginning 1))
11153 (overlay-put ov 'local-map verilog-mode-mouse-map))))))) 11918 (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
11154 11919 (overlay-put ov 'start-closed 't)
11155 11920 (overlay-put ov 'end-closed 't)
11156 (defun verilog-colorize-include-files-buffer () 11921 (overlay-put ov 'evaporate 't)
11157 "Colorize an include file." 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))))
11925 ;;
11926 ;; make new module overlays
11927 (goto-char beg)
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)
11932 (save-excursion
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)))))
11943 (error nil)))
11944 ;;
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
11948 )))))))
11949
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'
11158 (interactive) 11953 (interactive)
11159 ;; delete overlays 11954 ;; delete and remake overlays
11160 (let ((overlays (overlays-in (point-min) (point-max)))) 11955 (verilog-highlight-region (point-min) (point-max) nil))
11161 (while overlays 11956
11162 (if (and 11957 ;; Deprecated, but was interactive, so we'll keep it around
11163 (overlay-get (car overlays) 'detachable) 11958 (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
11164 (overlay-get (car overlays) 'verilog-include-file))
11165 (delete-overlay (car overlays)))
11166 (setq overlays (cdr overlays)))) ; let
11167 ;; remake overlays
11168 (verilog-colorize-include-files (point-min) (point-max) nil))
11169 11959
11170 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths. 11960 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
11171 ;; so define this function to do more or less the same as ffap-at-mouse 11961 ;; so define this function to do more or less the same as ffap-at-mouse
11172 ;; but first resolve filename... 11962 ;; but first resolve filename...
11173 (defun verilog-load-file-at-mouse (event) 11963 (defun verilog-load-file-at-mouse (event)
11174 "Load file under button 2 click's EVENT. 11964 "Load file under button 2 click's EVENT.
11175 Files are checked based on `verilog-library-directories'." 11965 Files are checked based on `verilog-library-flags'."
11176 (interactive "@e") 11966 (interactive "@e")
11177 (save-excursion ;; implement a Verilog specific ffap-at-mouse 11967 (save-excursion ;; implement a Verilog specific ffap-at-mouse
11178 (mouse-set-point event) 11968 (mouse-set-point event)
11179 (beginning-of-line) 11969 (verilog-load-file-at-point t)))
11180 (if (looking-at verilog-include-file-regexp) 11970
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'."
11978 (interactive)
11979 (save-excursion ;; implement a Verilog specific ffap
11980 (let ((overlays (overlays-in (point) (point)))
11981 hit)
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))))
11987 (setq hit t))
11988 (setq overlays (cdr overlays)))
11989 ;; Include?
11990 (beginning-of-line)
11991 (when (and (not hit)
11992 (looking-at verilog-include-file-regexp))
11181 (if (and (car (verilog-library-filenames 11993 (if (and (car (verilog-library-filenames
11182 (match-string 1) (buffer-file-name))) 11994 (match-string 1) (buffer-file-name)))
11183 (file-readable-p (car (verilog-library-filenames 11995 (file-readable-p (car (verilog-library-filenames
11184 (match-string 1) (buffer-file-name))))) 11996 (match-string 1) (buffer-file-name)))))
11185 (find-file (car (verilog-library-filenames 11997 (find-file (car (verilog-library-filenames
11186 (match-string 1) (buffer-file-name)))) 11998 (match-string 1) (buffer-file-name))))
11187 (progn 11999 (when warn
11188 (message 12000 (message
11189 "File '%s' isn't readable, use shift-mouse2 to paste in this field" 12001 "File '%s' isn't readable, use shift-mouse2 to paste in this field"
11190 (match-string 1))))))) 12002 (match-string 1))))))))
11191
11192 ;; ffap isn't useable for Verilog mode. It uses library paths.
11193 ;; so define this function to do more or less the same as ffap
11194 ;; but first resolve filename...
11195 (defun verilog-load-file-at-point ()
11196 "Load file under point.
11197 Files are checked based on `verilog-library-directories'."
11198 (interactive)
11199 (save-excursion ;; implement a Verilog specific ffap
11200 (beginning-of-line)
11201 (if (looking-at verilog-include-file-regexp)
11202 (if (and
11203 (car (verilog-library-filenames
11204 (match-string 1) (buffer-file-name)))
11205 (file-readable-p (car (verilog-library-filenames
11206 (match-string 1) (buffer-file-name)))))
11207 (find-file (car (verilog-library-filenames
11208 (match-string 1) (buffer-file-name))))))))
11209
11210 12003
11211 ;; 12004 ;;
11212 ;; Bug reporting 12005 ;; Bug reporting
11213 ;; 12006 ;;
11214 12007
11234 (let ((reporter-prompt-for-summary-p t)) 12027 (let ((reporter-prompt-for-summary-p t))
11235 (reporter-submit-bug-report 12028 (reporter-submit-bug-report
11236 "mac@verilog.com, wsnyder@wsnyder.org" 12029 "mac@verilog.com, wsnyder@wsnyder.org"
11237 (concat "verilog-mode v" verilog-mode-version) 12030 (concat "verilog-mode v" verilog-mode-version)
11238 '( 12031 '(
12032 verilog-active-low-regexp
11239 verilog-align-ifelse 12033 verilog-align-ifelse
12034 verilog-assignment-delay
12035 verilog-auto-arg-sort
11240 verilog-auto-endcomments 12036 verilog-auto-endcomments
11241 verilog-auto-hook 12037 verilog-auto-hook
12038 verilog-auto-ignore-concat
11242 verilog-auto-indent-on-newline 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
11243 verilog-auto-inst-vector 12046 verilog-auto-inst-vector
11244 verilog-auto-inst-template-numbers
11245 verilog-auto-lineup 12047 verilog-auto-lineup
11246 verilog-auto-newline 12048 verilog-auto-newline
12049 verilog-auto-output-ignore-regexp
12050 verilog-auto-read-includes
12051 verilog-auto-reset-widths
11247 verilog-auto-save-policy 12052 verilog-auto-save-policy
11248 verilog-auto-sense-defines-constant 12053 verilog-auto-sense-defines-constant
11249 verilog-auto-sense-include-inputs 12054 verilog-auto-sense-include-inputs
12055 verilog-auto-star-expand
12056 verilog-auto-star-save
12057 verilog-auto-unused-ignore-regexp
11250 verilog-before-auto-hook 12058 verilog-before-auto-hook
12059 verilog-before-delete-auto-hook
12060 verilog-before-getopt-flags-hook
11251 verilog-case-indent 12061 verilog-case-indent
11252 verilog-cexp-indent 12062 verilog-cexp-indent
11253 verilog-compiler 12063 verilog-compiler
11254 verilog-coverage 12064 verilog-coverage
12065 verilog-delete-auto-hook
12066 verilog-getopt-flags-hook
12067 verilog-highlight-grouping-keywords
12068 verilog-highlight-p1800-keywords
11255 verilog-highlight-translate-off 12069 verilog-highlight-translate-off
11256 verilog-indent-begin-after-if 12070 verilog-indent-begin-after-if
11257 verilog-indent-declaration-macros 12071 verilog-indent-declaration-macros
11258 verilog-indent-level 12072 verilog-indent-level
11259 verilog-indent-level-behavioral 12073 verilog-indent-level-behavioral
11260 verilog-indent-level-declaration 12074 verilog-indent-level-declaration
11261 verilog-indent-level-directive 12075 verilog-indent-level-directive
11262 verilog-indent-level-module 12076 verilog-indent-level-module
11263 verilog-indent-lists 12077 verilog-indent-lists
11264 verilog-library-flags
11265 verilog-library-directories 12078 verilog-library-directories
11266 verilog-library-extensions 12079 verilog-library-extensions
11267 verilog-library-files 12080 verilog-library-files
12081 verilog-library-flags
11268 verilog-linter 12082 verilog-linter
11269 verilog-minimum-comment-distance 12083 verilog-minimum-comment-distance
11270 verilog-mode-hook 12084 verilog-mode-hook
12085 verilog-preprocessor
11271 verilog-simulator 12086 verilog-simulator
11272 verilog-tab-always-indent 12087 verilog-tab-always-indent
11273 verilog-tab-to-comment 12088 verilog-tab-to-comment
12089 verilog-typedef-regexp
11274 ) 12090 )
11275 nil nil 12091 nil nil
11276 (concat "Hi Mac, 12092 (concat "Hi Mac,
11277 12093
11278 I want to report a bug. 12094 I want to report a bug.