Fix last change in verilog-mode.el.
[emacs.git] / lisp / progmodes / verilog-mode.el
blob9173aa61b293743fbb544210552f67569c9f1397
1 ;; verilog-mode.el --- major mode for editing verilog source in Emacs
3 ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
5 ;; Author: Michael McNamara (mac@verilog.com),
6 ;; Wilson Snyder (wsnyder@wsnyder.org)
7 ;; Please see our web sites:
8 ;; http://www.verilog.com
9 ;; http://www.veripool.org
11 ;; Keywords: languages
13 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
14 ;; file on 19/3/2008, and the maintainer agreed that when a bug is
15 ;; filed in the Emacs bug reporting system against this file, a copy
16 ;; of the bug report be sent to the maintainer's email address.
18 ;; This code supports Emacs 21.1 and later
19 ;; And XEmacs 21.1 and later
20 ;; Please do not make changes that break Emacs 21. Thanks!
24 ;; This file is part of GNU Emacs.
26 ;; GNU Emacs is free software: you can redistribute it and/or modify
27 ;; it under the terms of the GNU General Public License as published by
28 ;; the Free Software Foundation, either version 3 of the License, or
29 ;; (at your option) any later version.
31 ;; GNU Emacs is distributed in the hope that it will be useful,
32 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
33 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ;; GNU General Public License for more details.
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
39 ;;; Commentary:
41 ;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs
43 ;; USAGE
44 ;; =====
46 ;; A major mode for editing Verilog HDL source code. When you have
47 ;; entered Verilog mode, you may get more info by pressing C-h m. You
48 ;; may also get online help describing various functions by: C-h f
49 ;; <Name of function you want described>
51 ;; KNOWN BUGS / BUG REPORTS
52 ;; =======================
54 ;; Verilog is a rapidly evolving language, and hence this mode is
55 ;; under continuous development. Hence this is beta code, and likely
56 ;; has bugs. Please report any issues to the issue tracker at
57 ;; http://www.veripool.org/verilog-mode
58 ;; Please use verilog-submit-bug-report to submit a report; type C-c
59 ;; C-b to invoke this and as a result I will have a much easier time
60 ;; of reproducing the bug you find, and hence fixing it.
62 ;; INSTALLING THE MODE
63 ;; ===================
65 ;; An older version of this mode may be already installed as a part of
66 ;; your environment, and one method of updating would be to update
67 ;; your Emacs environment. Sometimes this is difficult for local
68 ;; political/control reasons, and hence you can always install a
69 ;; private copy (or even a shared copy) which overrides the system
70 ;; default.
72 ;; You can get step by step help in installing this file by going to
73 ;; <http://www.verilog.com/emacs_install.html>
75 ;; The short list of installation instructions are: To set up
76 ;; automatic Verilog mode, put this file in your load path, and put
77 ;; the following in code (please un comment it first!) in your
78 ;; .emacs, or in your site's site-load.el
80 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
81 ; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
83 ;; Be sure to examine at the help for verilog-auto, and the other
84 ;; verilog-auto-* functions for some major coding time savers.
86 ;; If you want to customize Verilog mode to fit your needs better,
87 ;; you may add the below lines (the values of the variables presented
88 ;; here are the defaults). Note also that if you use an Emacs that
89 ;; supports custom, it's probably better to use the custom menu to
90 ;; edit these. If working as a member of a large team these settings
91 ;; should be common across all users (in a site-start file), or set
92 ;; in Local Variables in every file. Otherwise, different people's
93 ;; AUTO expansion may result different whitespace changes.
95 ; ;; Enable syntax highlighting of **all** languages
96 ; (global-font-lock-mode t)
98 ; ;; User customization for Verilog mode
99 ; (setq verilog-indent-level 3
100 ; verilog-indent-level-module 3
101 ; verilog-indent-level-declaration 3
102 ; verilog-indent-level-behavioral 3
103 ; verilog-indent-level-directive 1
104 ; verilog-case-indent 2
105 ; verilog-auto-newline t
106 ; verilog-auto-indent-on-newline t
107 ; verilog-tab-always-indent t
108 ; verilog-auto-endcomments t
109 ; verilog-minimum-comment-distance 40
110 ; verilog-indent-begin-after-if t
111 ; verilog-auto-lineup 'declarations
112 ; verilog-highlight-p1800-keywords nil
113 ; verilog-linter "my_lint_shell_command"
116 ;; \f
118 ;;; History:
120 ;; See commit history at http://www.veripool.org/verilog-mode.html
121 ;; (This section is required to appease checkdoc.)
123 ;;; Code:
125 ;; This variable will always hold the version number of the mode
126 (defconst verilog-mode-version (substring "$$Revision: 820 $$" 12 -3)
127 "Version of this Verilog mode.")
128 (defconst verilog-mode-release-date (substring "$$Date: 2012-09-17 20:43:10 -0400 (Mon, 17 Sep 2012) $$" 8 -3)
129 "Release date of this Verilog mode.")
130 (defconst verilog-mode-release-emacs t
131 "If non-nil, this version of Verilog mode was released with Emacs itself.")
133 (defun verilog-version ()
134 "Inform caller of the version of this file."
135 (interactive)
136 (message "Using verilog-mode version %s" verilog-mode-version))
138 ;; Insure we have certain packages, and deal with it if we don't
139 ;; Be sure to note which Emacs flavor and version added each feature.
140 (eval-when-compile
141 ;; Provide stuff if we are XEmacs
142 (when (featurep 'xemacs)
143 (condition-case nil
144 (require 'easymenu)
145 (error nil))
146 (condition-case nil
147 (require 'regexp-opt)
148 (error nil))
149 ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
150 (condition-case nil
151 (load "skeleton")
152 (error nil))
153 (condition-case nil
154 (if (fboundp 'when)
155 nil ;; fab
156 (defmacro when (cond &rest body)
157 (list 'if cond (cons 'progn body))))
158 (error nil))
159 (condition-case nil
160 (if (fboundp 'unless)
161 nil ;; fab
162 (defmacro unless (cond &rest body)
163 (cons 'if (cons cond (cons nil body)))))
164 (error nil))
165 (condition-case nil
166 (if (fboundp 'store-match-data)
167 nil ;; fab
168 (defmacro store-match-data (&rest args) nil))
169 (error nil))
170 (condition-case nil
171 (if (fboundp 'char-before)
172 nil ;; great
173 (defmacro char-before (&rest body)
174 (char-after (1- (point)))))
175 (error nil))
176 (condition-case nil
177 (if (fboundp 'when)
178 nil ;; fab
179 (defsubst point-at-bol (&optional N)
180 (save-excursion (beginning-of-line N) (point))))
181 (error nil))
182 (condition-case nil
183 (if (fboundp 'when)
184 nil ;; fab
185 (defsubst point-at-eol (&optional N)
186 (save-excursion (end-of-line N) (point))))
187 (error nil))
188 (condition-case nil
189 (require 'custom)
190 (error nil))
191 (condition-case nil
192 (if (fboundp 'match-string-no-properties)
193 nil ;; great
194 (defsubst match-string-no-properties (num &optional string)
195 "Return string of text matched by last search, without text properties.
196 NUM specifies which parenthesized expression in the last regexp.
197 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
198 Zero means the entire text matched by the whole regexp or whole string.
199 STRING should be given if the last search was by `string-match' on STRING."
200 (if (match-beginning num)
201 (if string
202 (let ((result
203 (substring string
204 (match-beginning num) (match-end num))))
205 (set-text-properties 0 (length result) nil result)
206 result)
207 (buffer-substring-no-properties (match-beginning num)
208 (match-end num)
209 (current-buffer)))))
211 (error nil))
212 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
213 nil ;; We've got what we needed
214 ;; We have the old custom-library, hack around it!
215 (defmacro defgroup (&rest args) nil)
216 (defmacro customize (&rest args)
217 (message
218 "Sorry, Customize is not available with this version of Emacs"))
219 (defmacro defcustom (var value doc &rest args)
220 `(defvar ,var ,value ,doc))
222 (if (fboundp 'defface)
223 nil ; great!
224 (defmacro defface (var values doc &rest args)
225 `(make-face ,var))
228 (if (and (featurep 'custom) (fboundp 'customize-group))
229 nil ;; We've got what we needed
230 ;; We have an intermediate custom-library, hack around it!
231 (defmacro customize-group (var &rest args)
232 `(customize ,var))
235 (unless (boundp 'inhibit-point-motion-hooks)
236 (defvar inhibit-point-motion-hooks nil))
237 (unless (boundp 'deactivate-mark)
238 (defvar deactivate-mark nil))
241 ;; OK, do this stuff if we are NOT XEmacs:
242 (unless (featurep 'xemacs)
243 (unless (fboundp 'region-active-p)
244 (defmacro region-active-p ()
245 `(and transient-mark-mode mark-active))))
248 ;; Provide a regular expression optimization routine, using regexp-opt
249 ;; if provided by the user's elisp libraries
250 (eval-and-compile
251 ;; The below were disabled when GNU Emacs 22 was released;
252 ;; perhaps some still need to be there to support Emacs 21.
253 (if (featurep 'xemacs)
254 (if (fboundp 'regexp-opt)
255 ;; regexp-opt is defined, does it take 3 or 2 arguments?
256 (if (fboundp 'function-max-args)
257 (let ((args (function-max-args `regexp-opt)))
258 (cond
259 ((eq args 3) ;; It takes 3
260 (condition-case nil ; Hide this defun from emacses
261 ;with just a two input regexp
262 (defun verilog-regexp-opt (a b)
263 "Deal with differing number of required arguments for `regexp-opt'.
264 Call 'regexp-opt' on A and B."
265 (regexp-opt a b 't))
266 (error nil))
268 ((eq args 2) ;; It takes 2
269 (defun verilog-regexp-opt (a b)
270 "Call 'regexp-opt' on A and B."
271 (regexp-opt a b))
273 (t nil)))
274 ;; We can't tell; assume it takes 2
275 (defun verilog-regexp-opt (a b)
276 "Call 'regexp-opt' on A and B."
277 (regexp-opt a b))
279 ;; There is no regexp-opt, provide our own
280 (defun verilog-regexp-opt (strings &optional paren shy)
281 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
282 (concat open (mapconcat 'regexp-quote strings "\\|") close)))
284 ;; Emacs.
285 (defalias 'verilog-regexp-opt 'regexp-opt)))
287 (eval-and-compile
288 ;; Both xemacs and emacs
289 (condition-case nil
290 (require 'diff) ;; diff-command and diff-switches
291 (error nil))
292 (condition-case nil
293 (require 'compile) ;; compilation-error-regexp-alist-alist
294 (error nil))
295 (condition-case nil
296 (unless (fboundp 'buffer-chars-modified-tick) ;; Emacs 22 added
297 (defmacro buffer-chars-modified-tick () (buffer-modified-tick)))
298 (error nil))
299 ;; Added in Emacs 24.1
300 (condition-case nil
301 (unless (fboundp 'prog-mode)
302 (define-derived-mode prog-mode fundamental-mode "Prog"))
303 (error nil)))
305 (eval-when-compile
306 (defun verilog-regexp-words (a)
307 "Call 'regexp-opt' with word delimiters for the words A."
308 (concat "\\<" (verilog-regexp-opt a t) "\\>")))
309 (defun verilog-regexp-words (a)
310 "Call 'regexp-opt' with word delimiters for the words A."
311 ;; The FAQ references this function, so user LISP sometimes calls it
312 (concat "\\<" (verilog-regexp-opt a t) "\\>"))
314 (defun verilog-easy-menu-filter (menu)
315 "Filter `easy-menu-define' MENU to support new features."
316 (cond ((not (featurep 'xemacs))
317 menu) ;; GNU Emacs - passthru
318 ;; XEmacs doesn't support :help. Strip it.
319 ;; Recursively filter the a submenu
320 ((listp menu)
321 (mapcar 'verilog-easy-menu-filter menu))
322 ;; Look for [:help "blah"] and remove
323 ((vectorp menu)
324 (let ((i 0) (out []))
325 (while (< i (length menu))
326 (if (equal `:help (aref menu i))
327 (setq i (+ 2 i))
328 (setq out (vconcat out (vector (aref menu i)))
329 i (1+ i))))
330 out))
331 (t menu))) ;; Default - ok
332 ;;(verilog-easy-menu-filter
333 ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
334 ;; "----" ["MB" nil :help "Help MB"]))
336 (defun verilog-define-abbrev (table name expansion &optional hook)
337 "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
338 Provides SYSTEM-FLAG in newer Emacs."
339 (condition-case nil
340 (define-abbrev table name expansion hook 0 t)
341 (error
342 (define-abbrev table name expansion hook))))
344 (defun verilog-customize ()
345 "Customize variables and other settings used by Verilog-Mode."
346 (interactive)
347 (customize-group 'verilog-mode))
349 (defun verilog-font-customize ()
350 "Customize fonts used by Verilog-Mode."
351 (interactive)
352 (if (fboundp 'customize-apropos)
353 (customize-apropos "font-lock-*" 'faces)))
355 (defun verilog-booleanp (value)
356 "Return t if VALUE is boolean.
357 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
358 This function may be removed when Emacs 21 is no longer supported."
359 (or (equal value t) (equal value nil)))
361 (defun verilog-insert-last-command-event ()
362 "Insert the `last-command-event'."
363 (insert (if (featurep 'xemacs)
364 ;; XEmacs 21.5 doesn't like last-command-event
365 last-command-char
366 ;; And GNU Emacs 22 has obsoleted last-command-char
367 last-command-event)))
369 (defvar verilog-no-change-functions nil
370 "True if `after-change-functions' is disabled.
371 Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")
373 (defvar verilog-in-hooks nil
374 "True when within a `verilog-run-hooks' block.")
376 (defmacro verilog-run-hooks (&rest hooks)
377 "Run each hook in HOOKS using `run-hooks'.
378 Set `verilog-in-hooks' during this time, to assist AUTO caches."
379 `(let ((verilog-in-hooks t))
380 (run-hooks ,@hooks)))
382 (defun verilog-syntax-ppss (&optional pos)
383 (when verilog-no-change-functions
384 (if verilog-in-hooks
385 (verilog-scan-cache-flush)
386 ;; else don't let the AUTO code itself get away with flushing the cache,
387 ;; as that'll make things very slow
388 (backtrace)
389 (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
390 (verilog-point-text))))
391 (if (fboundp 'syntax-ppss)
392 (syntax-ppss pos)
393 (parse-partial-sexp (point-min) (or pos (point)))))
395 (defgroup verilog-mode nil
396 "Major mode for Verilog source code."
397 :version "22.2"
398 :group 'languages)
400 ; (defgroup verilog-mode-fonts nil
401 ; "Facilitates easy customization fonts used in Verilog source text"
402 ; :link '(customize-apropos "font-lock-*" 'faces)
403 ; :group 'verilog-mode)
405 (defgroup verilog-mode-indent nil
406 "Customize indentation and highlighting of Verilog source text."
407 :group 'verilog-mode)
409 (defgroup verilog-mode-actions nil
410 "Customize actions on Verilog source text."
411 :group 'verilog-mode)
413 (defgroup verilog-mode-auto nil
414 "Customize AUTO actions when expanding Verilog source text."
415 :group 'verilog-mode)
417 (defvar verilog-debug nil
418 "Non-nil means enable debug messages for `verilog-mode' internals.")
420 (defvar verilog-warn-fatal nil
421 "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
423 (defcustom verilog-linter
424 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
425 "Unix program and arguments to call to run a lint checker on Verilog source.
426 Depending on the `verilog-set-compile-command', this may be invoked when
427 you type \\[compile]. When the compile completes, \\[next-error] will take
428 you to the next lint error."
429 :type 'string
430 :group 'verilog-mode-actions)
431 ;; We don't mark it safe, as it's used as a shell command
433 (defcustom verilog-coverage
434 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
435 "Program and arguments to use to annotate for coverage Verilog source.
436 Depending on the `verilog-set-compile-command', this may be invoked when
437 you type \\[compile]. When the compile completes, \\[next-error] will take
438 you to the next lint error."
439 :type 'string
440 :group 'verilog-mode-actions)
441 ;; We don't mark it safe, as it's used as a shell command
443 (defcustom verilog-simulator
444 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
445 "Program and arguments to use to interpret Verilog source.
446 Depending on the `verilog-set-compile-command', this may be invoked when
447 you type \\[compile]. When the compile completes, \\[next-error] will take
448 you to the next lint error."
449 :type 'string
450 :group 'verilog-mode-actions)
451 ;; We don't mark it safe, as it's used as a shell command
453 (defcustom verilog-compiler
454 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
455 "Program and arguments to use to compile Verilog source.
456 Depending on the `verilog-set-compile-command', this may be invoked when
457 you type \\[compile]. When the compile completes, \\[next-error] will take
458 you to the next lint error."
459 :type 'string
460 :group 'verilog-mode-actions)
461 ;; We don't mark it safe, as it's used as a shell command
463 (defcustom verilog-preprocessor
464 ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
465 "vppreproc __FLAGS__ __FILE__"
466 "Program and arguments to use to preprocess Verilog source.
467 This is invoked with `verilog-preprocess', and depending on the
468 `verilog-set-compile-command', may also be invoked when you type
469 \\[compile]. When the compile completes, \\[next-error] will
470 take you to the next lint error."
471 :type 'string
472 :group 'verilog-mode-actions)
473 ;; We don't mark it safe, as it's used as a shell command
475 (defvar verilog-preprocess-history nil
476 "History for `verilog-preprocess'.")
478 (defvar verilog-tool 'verilog-linter
479 "Which tool to use for building compiler-command.
480 Either nil, `verilog-linter, `verilog-compiler,
481 `verilog-coverage, `verilog-preprocessor, or `verilog-simulator.
482 Alternatively use the \"Choose Compilation Action\" menu. See
483 `verilog-set-compile-command' for more information.")
485 (defcustom verilog-highlight-translate-off nil
486 "Non-nil means background-highlight code excluded from translation.
487 That is, all code between \"// synopsys translate_off\" and
488 \"// synopsys translate_on\" is highlighted using a different background color
489 \(face `verilog-font-lock-translate-off-face').
491 Note: This will slow down on-the-fly fontification (and thus editing).
493 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
494 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
495 :type 'boolean
496 :group 'verilog-mode-indent)
497 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
498 (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
500 (defcustom verilog-auto-lineup 'declarations
501 "Type of statements to lineup across multiple lines.
502 If 'all' is selected, then all line ups described below are done.
504 If 'declaration', then just declarations are lined up with any
505 preceding declarations, taking into account widths and the like,
506 so or example the code:
507 reg [31:0] a;
508 reg b;
509 would become
510 reg [31:0] a;
511 reg b;
513 If 'assignment', then assignments are lined up with any preceding
514 assignments, so for example the code
515 a_long_variable <= b + c;
516 d = e + f;
517 would become
518 a_long_variable <= b + c;
519 d = e + f;
521 In order to speed up editing, large blocks of statements are lined up
522 only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
523 are lineup only when \\[verilog-pretty-declarations] is typed."
525 :type '(radio (const :tag "Line up Assignments and Declarations" all)
526 (const :tag "Line up Assignment statements" assignments )
527 (const :tag "Line up Declarations" declarations)
528 (function :tag "Other"))
529 :group 'verilog-mode-indent )
530 (put 'verilog-auto-lineup 'safe-local-variable
531 '(lambda (x) (memq x '(nil all assignments declarations))))
533 (defcustom verilog-indent-level 3
534 "Indentation of Verilog statements with respect to containing block."
535 :group 'verilog-mode-indent
536 :type 'integer)
537 (put 'verilog-indent-level 'safe-local-variable 'integerp)
539 (defcustom verilog-indent-level-module 3
540 "Indentation of Module level Verilog statements (eg always, initial).
541 Set to 0 to get initial and always statements lined up on the left side of
542 your screen."
543 :group 'verilog-mode-indent
544 :type 'integer)
545 (put 'verilog-indent-level-module 'safe-local-variable 'integerp)
547 (defcustom verilog-indent-level-declaration 3
548 "Indentation of declarations with respect to containing block.
549 Set to 0 to get them list right under containing block."
550 :group 'verilog-mode-indent
551 :type 'integer)
552 (put 'verilog-indent-level-declaration 'safe-local-variable 'integerp)
554 (defcustom verilog-indent-declaration-macros nil
555 "How to treat macro expansions in a declaration.
556 If nil, indent as:
557 input [31:0] a;
558 input `CP;
559 output c;
560 If non nil, treat as:
561 input [31:0] a;
562 input `CP ;
563 output c;"
564 :group 'verilog-mode-indent
565 :type 'boolean)
566 (put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp)
568 (defcustom verilog-indent-lists t
569 "How to treat indenting items in a list.
570 If t (the default), indent as:
571 always @( posedge a or
572 reset ) begin
574 If nil, treat as:
575 always @( posedge a or
576 reset ) begin"
577 :group 'verilog-mode-indent
578 :type 'boolean)
579 (put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp)
581 (defcustom verilog-indent-level-behavioral 3
582 "Absolute indentation of first begin in a task or function block.
583 Set to 0 to get such code to start at the left side of the screen."
584 :group 'verilog-mode-indent
585 :type 'integer)
586 (put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp)
588 (defcustom verilog-indent-level-directive 1
589 "Indentation to add to each level of `ifdef declarations.
590 Set to 0 to have all directives start at the left side of the screen."
591 :group 'verilog-mode-indent
592 :type 'integer)
593 (put 'verilog-indent-level-directive 'safe-local-variable 'integerp)
595 (defcustom verilog-cexp-indent 2
596 "Indentation of Verilog statements split across lines."
597 :group 'verilog-mode-indent
598 :type 'integer)
599 (put 'verilog-cexp-indent 'safe-local-variable 'integerp)
601 (defcustom verilog-case-indent 2
602 "Indentation for case statements."
603 :group 'verilog-mode-indent
604 :type 'integer)
605 (put 'verilog-case-indent 'safe-local-variable 'integerp)
607 (defcustom verilog-auto-newline t
608 "Non-nil means automatically newline after semicolons."
609 :group 'verilog-mode-indent
610 :type 'boolean)
611 (put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
613 (defcustom verilog-auto-indent-on-newline t
614 "Non-nil means automatically indent line after newline."
615 :group 'verilog-mode-indent
616 :type 'boolean)
617 (put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp)
619 (defcustom verilog-tab-always-indent t
620 "Non-nil means TAB should always re-indent the current line.
621 A nil value means TAB will only reindent when at the beginning of the line."
622 :group 'verilog-mode-indent
623 :type 'boolean)
624 (put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
626 (defcustom verilog-tab-to-comment nil
627 "Non-nil means TAB moves to the right hand column in preparation for a comment."
628 :group 'verilog-mode-actions
629 :type 'boolean)
630 (put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
632 (defcustom verilog-indent-begin-after-if t
633 "Non-nil means indent begin statements following if, else, while, etc.
634 Otherwise, line them up."
635 :group 'verilog-mode-indent
636 :type 'boolean)
637 (put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
639 (defcustom verilog-align-ifelse nil
640 "Non-nil means align `else' under matching `if'.
641 Otherwise else is lined up with first character on line holding matching if."
642 :group 'verilog-mode-indent
643 :type 'boolean)
644 (put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp)
646 (defcustom verilog-minimum-comment-distance 10
647 "Minimum distance (in lines) between begin and end required before a comment.
648 Setting this variable to zero results in every end acquiring a comment; the
649 default avoids too many redundant comments in tight quarters."
650 :group 'verilog-mode-indent
651 :type 'integer)
652 (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
654 (defcustom verilog-highlight-p1800-keywords nil
655 "Non-nil means highlight words newly reserved by IEEE-1800.
656 These will appear in `verilog-font-lock-p1800-face' in order to gently
657 suggest changing where these words are used as variables to something else.
658 A nil value means highlight these words as appropriate for the SystemVerilog
659 IEEE-1800 standard. Note that changing this will require restarting Emacs
660 to see the effect as font color choices are cached by Emacs."
661 :group 'verilog-mode-indent
662 :type 'boolean)
663 (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
665 (defcustom verilog-highlight-grouping-keywords nil
666 "Non-nil means highlight grouping keywords 'begin' and 'end' more dramatically.
667 If false, these words are in the `font-lock-type-face'; if True then they are in
668 `verilog-font-lock-ams-face'. Some find that special highlighting on these
669 grouping constructs allow the structure of the code to be understood at a glance."
670 :group 'verilog-mode-indent
671 :type 'boolean)
672 (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
674 (defcustom verilog-highlight-modules nil
675 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
676 When true, mousing over module names will allow jumping to the
677 module definition. If false, this is not supported. Setting
678 this is experimental, and may lead to bad performance."
679 :group 'verilog-mode-indent
680 :type 'boolean)
681 (put 'verilog-highlight-modules 'safe-local-variable 'verilog-booleanp)
683 (defcustom verilog-highlight-includes t
684 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
685 When true, mousing over include file names will allow jumping to the
686 file referenced. If false, this is not supported."
687 :group 'verilog-mode-indent
688 :type 'boolean)
689 (put 'verilog-highlight-includes 'safe-local-variable 'verilog-booleanp)
691 (defcustom verilog-auto-declare-nettype nil
692 "Non-nil specifies the data type to use with `verilog-auto-input' etc.
693 Set this to \"wire\" if the Verilog code uses \"`default_nettype
694 none\". Note using `default_nettype none isn't recommended practice; this
695 mode is experimental."
696 :version "24.1" ;; rev670
697 :group 'verilog-mode-actions
698 :type 'boolean)
699 (put 'verilog-auto-declare-nettype 'safe-local-variable `stringp)
701 (defcustom verilog-auto-wire-type nil
702 "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
703 Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'."
704 :version "24.1" ;; rev673
705 :group 'verilog-mode-actions
706 :type 'boolean)
707 (put 'verilog-auto-wire-type 'safe-local-variable `stringp)
709 (defcustom verilog-auto-endcomments t
710 "Non-nil means insert a comment /* ... */ after 'end's.
711 The name of the function or case will be set between the braces."
712 :group 'verilog-mode-actions
713 :type 'boolean)
714 (put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
716 (defcustom verilog-auto-delete-trailing-whitespace nil
717 "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
718 :version "24.1" ;; rev703
719 :group 'verilog-mode-actions
720 :type 'boolean)
721 (put 'verilog-auto-delete-trailing-whitespace 'safe-local-variable 'verilog-booleanp)
723 (defcustom verilog-auto-ignore-concat nil
724 "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
725 This will exclude signals referenced as pin connections in {...}
726 from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
727 for backward compatibility only and not set in new designs; it
728 may be removed in future versions."
729 :group 'verilog-mode-actions
730 :type 'boolean)
731 (put 'verilog-auto-ignore-concat 'safe-local-variable 'verilog-booleanp)
733 (defcustom verilog-auto-read-includes nil
734 "Non-nil means to automatically read includes before AUTOs.
735 This will do a `verilog-read-defines' and `verilog-read-includes' before
736 each AUTO expansion. This makes it easier to embed defines and includes,
737 but can result in very slow reading times if there are many or large
738 include files."
739 :group 'verilog-mode-actions
740 :type 'boolean)
741 (put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp)
743 (defcustom verilog-auto-save-policy nil
744 "Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
745 A value of `force' will always do a \\[verilog-auto] automatically if
746 needed on every save. A value of `detect' will do \\[verilog-auto]
747 automatically when it thinks necessary. A value of `ask' will query the
748 user when it thinks updating is needed.
750 You should not rely on the 'ask or 'detect policies, they are safeguards
751 only. They do not detect when AUTOINSTs need to be updated because a
752 sub-module's port list has changed."
753 :group 'verilog-mode-actions
754 :type '(choice (const nil) (const ask) (const detect) (const force)))
756 (defcustom verilog-auto-star-expand t
757 "Non-nil means to expand SystemVerilog .* instance ports.
758 They will be expanded in the same way as if there was an AUTOINST in the
759 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
760 :group 'verilog-mode-actions
761 :type 'boolean)
762 (put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
764 (defcustom verilog-auto-star-save nil
765 "Non-nil means save to disk SystemVerilog .* instance expansions.
766 A nil value indicates direct connections will be removed before saving.
767 Only meaningful to those created due to `verilog-auto-star-expand' being set.
769 Instead of setting this, you may want to use /*AUTOINST*/, which will
770 always be saved."
771 :group 'verilog-mode-actions
772 :type 'boolean)
773 (put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp)
775 (defvar verilog-auto-update-tick nil
776 "Modification tick at which autos were last performed.")
778 (defvar verilog-auto-last-file-locals nil
779 "Text from file-local-variables during last evaluation.")
781 (defvar verilog-diff-function 'verilog-diff-report
782 "Function to run when `verilog-diff-auto' detects differences.
783 Function takes three arguments, the original buffer, the
784 difference buffer, and the point in original buffer with the
785 first difference.")
787 ;;; Compile support
788 (require 'compile)
789 (defvar verilog-error-regexp-added nil)
791 (defvar verilog-error-regexp-emacs-alist
793 (verilog-xl-1
794 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
795 (verilog-xl-2
796 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
797 (verilog-IES
798 ".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
799 (verilog-surefire-1
800 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
801 (verilog-surefire-2
802 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
803 (verilog-verbose
805 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
806 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
807 (verilog-xsim
808 "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
809 (verilog-vcs-1
810 "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
811 (verilog-vcs-2
812 "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
813 (verilog-vcs-3
814 "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
815 (verilog-vcs-4
816 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
817 (verilog-verilator
818 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
819 (verilog-leda
820 "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
822 "List of regexps for Verilog compilers.
823 See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
825 (defvar verilog-error-regexp-xemacs-alist
826 ;; Emacs form is '((v-tool "re" 1 2) ...)
827 ;; XEmacs form is '(verilog ("re" 1 2) ...)
828 ;; So we can just map from Emacs to XEmacs
829 (cons 'verilog (mapcar 'cdr verilog-error-regexp-emacs-alist))
830 "List of regexps for Verilog compilers.
831 See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
833 (defvar verilog-error-font-lock-keywords
835 ;; verilog-xl-1
836 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
837 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
838 ;; verilog-xl-2
839 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t)
840 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t)
841 ;; verilog-IES (nc-verilog)
842 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t)
843 (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t)
844 ;; verilog-surefire-1
845 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
846 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
847 ;; verilog-surefire-2
848 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t)
849 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t)
850 ;; verilog-verbose
852 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
853 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
855 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
856 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
857 ;; verilog-vcs-1
858 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t)
859 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t)
860 ;; verilog-vcs-2
861 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
862 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
863 ;; verilog-vcs-3
864 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
865 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t)
866 ;; verilog-vcs-4
867 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t)
868 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
869 ;; verilog-verilator
870 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
871 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)
872 ;; verilog-leda
873 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t)
874 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t)
876 "Keywords to also highlight in Verilog *compilation* buffers.
877 Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
879 (defcustom verilog-library-flags '("")
880 "List of standard Verilog arguments to use for /*AUTOINST*/.
881 These arguments are used to find files for `verilog-auto', and match
882 the flags accepted by a standard Verilog-XL simulator.
884 -f filename Reads more `verilog-library-flags' from the filename.
885 +incdir+dir Adds the directory to `verilog-library-directories'.
886 -Idir Adds the directory to `verilog-library-directories'.
887 -y dir Adds the directory to `verilog-library-directories'.
888 +libext+.v Adds the extensions to `verilog-library-extensions'.
889 -v filename Adds the filename to `verilog-library-files'.
891 filename Adds the filename to `verilog-library-files'.
892 This is not recommended, -v is a better choice.
894 You might want these defined in each file; put at the *END* of your file
895 something like:
897 // Local Variables:
898 // verilog-library-flags:(\"-y dir -y otherdir\")
899 // End:
901 Verilog-mode attempts to detect changes to this local variable, but they
902 are only insured to be correct when the file is first visited. Thus if you
903 have problems, use \\[find-alternate-file] RET to have these take effect.
905 See also the variables mentioned above."
906 :group 'verilog-mode-auto
907 :type '(repeat string))
908 (put 'verilog-library-flags 'safe-local-variable 'listp)
910 (defcustom verilog-library-directories '(".")
911 "List of directories when looking for files for /*AUTOINST*/.
912 The directory may be relative to the current file, or absolute.
913 Environment variables are also expanded in the directory names.
914 Having at least the current directory is a good idea.
916 You might want these defined in each file; put at the *END* of your file
917 something like:
919 // Local Variables:
920 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
921 // End:
923 Verilog-mode attempts to detect changes to this local variable, but they
924 are only insured to be correct when the file is first visited. Thus if you
925 have problems, use \\[find-alternate-file] RET to have these take effect.
927 See also `verilog-library-flags', `verilog-library-files'
928 and `verilog-library-extensions'."
929 :group 'verilog-mode-auto
930 :type '(repeat file))
931 (put 'verilog-library-directories 'safe-local-variable 'listp)
933 (defcustom verilog-library-files '()
934 "List of files to search for modules.
935 AUTOINST will use this when it needs to resolve a module name.
936 This is a complete path, usually to a technology file with many standard
937 cells defined in it.
939 You might want these defined in each file; put at the *END* of your file
940 something like:
942 // Local Variables:
943 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
944 // End:
946 Verilog-mode attempts to detect changes to this local variable, but they
947 are only insured to be correct when the file is first visited. Thus if you
948 have problems, use \\[find-alternate-file] RET to have these take effect.
950 See also `verilog-library-flags', `verilog-library-directories'."
951 :group 'verilog-mode-auto
952 :type '(repeat directory))
953 (put 'verilog-library-files 'safe-local-variable 'listp)
955 (defcustom verilog-library-extensions '(".v" ".sv")
956 "List of extensions to use when looking for files for /*AUTOINST*/.
957 See also `verilog-library-flags', `verilog-library-directories'."
958 :type '(repeat string)
959 :group 'verilog-mode-auto)
960 (put 'verilog-library-extensions 'safe-local-variable 'listp)
962 (defcustom verilog-active-low-regexp nil
963 "If set, treat signals matching this regexp as active low.
964 This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
965 you will probably also need `verilog-auto-reset-widths' set."
966 :group 'verilog-mode-auto
967 :type 'string)
968 (put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
970 (defcustom verilog-auto-sense-include-inputs nil
971 "Non-nil means AUTOSENSE should include all inputs.
972 If nil, only inputs that are NOT output signals in the same block are
973 included."
974 :group 'verilog-mode-auto
975 :type 'boolean)
976 (put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
978 (defcustom verilog-auto-sense-defines-constant nil
979 "Non-nil means AUTOSENSE should assume all defines represent constants.
980 When true, the defines will not be included in sensitivity lists. To
981 maintain compatibility with other sites, this should be set at the bottom
982 of each Verilog file that requires it, rather than being set globally."
983 :group 'verilog-mode-auto
984 :type 'boolean)
985 (put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
987 (defcustom verilog-auto-reset-blocking-in-non t
988 "Non-nil means AUTORESET will reset blocking statements.
989 When true, AUTORESET will reset in blocking statements those
990 signals which were assigned with blocking assignments (=) even in
991 a block with non-blocking assignments (<=).
993 If nil, all blocking assigned signals are ignored when any
994 non-blocking assignment is in the AUTORESET block. This allows
995 blocking assignments to be used for temporary values and not have
996 those temporaries reset. See example in `verilog-auto-reset'."
997 :version "24.1" ;; rev718
998 :type 'boolean
999 :group 'verilog-mode-auto)
1000 (put 'verilog-auto-reset-blocking-in-non 'safe-local-variable 'verilog-booleanp)
1002 (defcustom verilog-auto-reset-widths t
1003 "True means AUTORESET should determine the width of signals.
1004 This is then used to set the width of the zero (32'h0 for example). This
1005 is required by some lint tools that aren't smart enough to ignore widths of
1006 the constant zero. This may result in ugly code when parameters determine
1007 the MSB or LSB of a signal inside an AUTORESET.
1009 If nil, AUTORESET uses \"0\" as the constant.
1011 If 'unbased', AUTORESET used the unbased unsized literal \"'0\"
1012 as the constant. This setting is strongly recommended for
1013 SystemVerilog designs."
1014 :type 'boolean
1015 :group 'verilog-mode-auto)
1016 (put 'verilog-auto-reset-widths 'safe-local-variable
1017 '(lambda (x) (memq x '(nil t unbased))))
1019 (defcustom verilog-assignment-delay ""
1020 "Text used for delays in delayed assignments. Add a trailing space if set."
1021 :group 'verilog-mode-auto
1022 :type 'string)
1023 (put 'verilog-assignment-delay 'safe-local-variable 'stringp)
1025 (defcustom verilog-auto-arg-sort nil
1026 "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
1027 Declaration order is advantageous with order based instantiations
1028 and is the default for backward compatibility. Sorted order
1029 reduces changes when declarations are moved around in a file, and
1030 it's bad practice to rely on order based instantiations anyhow.
1032 See also `verilog-auto-inst-sort'."
1033 :group 'verilog-mode-auto
1034 :type 'boolean)
1035 (put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)
1037 (defcustom verilog-auto-inst-dot-name nil
1038 "Non-nil means when creating ports with AUTOINST, use .name syntax.
1039 This will use \".port\" instead of \".port(port)\" when possible.
1040 This is only legal in SystemVerilog files, and will confuse older
1041 simulators. Setting `verilog-auto-inst-vector' to nil may also
1042 be desirable to increase how often .name will be used."
1043 :group 'verilog-mode-auto
1044 :type 'boolean)
1045 (put 'verilog-auto-inst-dot-name 'safe-local-variable 'verilog-booleanp)
1047 (defcustom verilog-auto-inst-param-value nil
1048 "Non-nil means AUTOINST will replace parameters with the parameter value.
1049 If nil, leave parameters as symbolic names.
1051 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
1052 listed as such there (as when the default value is acceptable), it will not
1053 be replaced, and will remain symbolic.
1055 For example, imagine a submodule uses parameters to declare the size of its
1056 inputs. This is then used by an upper module:
1058 module InstModule (o,i);
1059 parameter WIDTH;
1060 input [WIDTH-1:0] i;
1061 endmodule
1063 module ExampInst;
1064 InstModule
1065 #(PARAM(10))
1066 instName
1067 (/*AUTOINST*/
1068 .i (i[PARAM-1:0]));
1070 Note even though PARAM=10, the AUTOINST has left the parameter as a
1071 symbolic name. If `verilog-auto-inst-param-value' is set, this will
1072 instead expand to:
1074 module ExampInst;
1075 InstModule
1076 #(PARAM(10))
1077 instName
1078 (/*AUTOINST*/
1079 .i (i[9:0]));"
1080 :group 'verilog-mode-auto
1081 :type 'boolean)
1082 (put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
1084 (defcustom verilog-auto-inst-sort nil
1085 "Non-nil means AUTOINST signals will be sorted, not in declaration order.
1086 Also affects AUTOINSTPARAM. Declaration order is the default for
1087 backward compatibility, and as some teams prefer signals that are
1088 declared together to remain together. Sorted order reduces
1089 changes when declarations are moved around in a file.
1091 See also `verilog-auto-arg-sort'."
1092 :version "24.1" ;; rev688
1093 :group 'verilog-mode-auto
1094 :type 'boolean)
1095 (put 'verilog-auto-inst-sort 'safe-local-variable 'verilog-booleanp)
1097 (defcustom verilog-auto-inst-vector t
1098 "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
1099 If nil, skip the subscript when it matches the entire bus as declared in
1100 the module (AUTOWIRE signals always are subscripted, you must manually
1101 declare the wire to have the subscripts removed.) Setting this to nil may
1102 speed up some simulators, but is less general and harder to read, so avoid."
1103 :group 'verilog-mode-auto
1104 :type 'boolean)
1105 (put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp)
1107 (defcustom verilog-auto-inst-template-numbers nil
1108 "If true, when creating templated ports with AUTOINST, add a comment.
1110 If t, the comment will add the line number of the template that
1111 was used for that port declaration. This setting is suggested
1112 only for debugging use, as regular use may cause a large numbers
1113 of merge conflicts.
1115 If 'lhs', the comment will show the left hand side of the
1116 AUTO_TEMPLATE rule that is matched. This is less precise than
1117 numbering (t) when multiple rules have the same pin name, but
1118 won't merge conflict."
1119 :group 'verilog-mode-auto
1120 :type '(choice (const nil) (const t) (const lhs)))
1121 (put 'verilog-auto-inst-template-numbers 'safe-local-variable
1122 '(lambda (x) (memq x '(nil t lhs))))
1124 (defcustom verilog-auto-inst-column 40
1125 "Indent-to column number for net name part of AUTOINST created pin."
1126 :group 'verilog-mode-indent
1127 :type 'integer)
1128 (put 'verilog-auto-inst-column 'safe-local-variable 'integerp)
1130 (defcustom verilog-auto-inst-interfaced-ports nil
1131 "Non-nil means include interfaced ports in AUTOINST expansions."
1132 :group 'verilog-mode-auto
1133 :type 'boolean)
1134 (put 'verilog-auto-inst-interfaced-ports 'safe-local-variable 'verilog-booleanp)
1136 (defcustom verilog-auto-input-ignore-regexp nil
1137 "If set, when creating AUTOINPUT list, ignore signals matching this regexp.
1138 See the \\[verilog-faq] for examples on using this."
1139 :group 'verilog-mode-auto
1140 :type 'string)
1141 (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp)
1143 (defcustom verilog-auto-inout-ignore-regexp nil
1144 "If set, when creating AUTOINOUT list, ignore signals matching this regexp.
1145 See the \\[verilog-faq] for examples on using this."
1146 :group 'verilog-mode-auto
1147 :type 'string)
1148 (put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp)
1150 (defcustom verilog-auto-output-ignore-regexp nil
1151 "If set, when creating AUTOOUTPUT list, ignore signals matching this regexp.
1152 See the \\[verilog-faq] for examples on using this."
1153 :group 'verilog-mode-auto
1154 :type 'string)
1155 (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
1157 (defcustom verilog-auto-template-warn-unused nil
1158 "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
1159 This feature is not supported before Emacs 21.1 or XEmacs 21.4."
1160 :group 'verilog-mode-auto
1161 :type 'boolean)
1162 (put 'verilog-auto-template-warn-unused 'safe-local-variable 'verilog-booleanp)
1164 (defcustom verilog-auto-tieoff-declaration "wire"
1165 "Data type used for the declaration for AUTOTIEOFF.
1166 If \"wire\" then create a wire, if \"assign\" create an
1167 assignment, else the data type for variable creation."
1168 :version "24.1" ;; rev713
1169 :group 'verilog-mode-auto
1170 :type 'string)
1171 (put 'verilog-auto-tieoff-declaration 'safe-local-variable 'stringp)
1173 (defcustom verilog-auto-tieoff-ignore-regexp nil
1174 "If set, when creating AUTOTIEOFF list, ignore signals matching this regexp.
1175 See the \\[verilog-faq] for examples on using this."
1176 :group 'verilog-mode-auto
1177 :type 'string)
1178 (put 'verilog-auto-tieoff-ignore-regexp 'safe-local-variable 'stringp)
1180 (defcustom verilog-auto-unused-ignore-regexp nil
1181 "If set, when creating AUTOUNUSED list, ignore signals matching this regexp.
1182 See the \\[verilog-faq] for examples on using this."
1183 :group 'verilog-mode-auto
1184 :type 'string)
1185 (put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp)
1187 (defcustom verilog-typedef-regexp nil
1188 "If non-nil, regular expression that matches Verilog-2001 typedef names.
1189 For example, \"_t$\" matches typedefs named with _t, as in the C language."
1190 :group 'verilog-mode-auto
1191 :type 'string)
1192 (put 'verilog-typedef-regexp 'safe-local-variable 'stringp)
1194 (defcustom verilog-mode-hook 'verilog-set-compile-command
1195 "Hook run after Verilog mode is loaded."
1196 :type 'hook
1197 :group 'verilog-mode)
1199 (defcustom verilog-auto-hook nil
1200 "Hook run after `verilog-mode' updates AUTOs."
1201 :group 'verilog-mode-auto
1202 :type 'hook)
1204 (defcustom verilog-before-auto-hook nil
1205 "Hook run before `verilog-mode' updates AUTOs."
1206 :group 'verilog-mode-auto
1207 :type 'hook)
1209 (defcustom verilog-delete-auto-hook nil
1210 "Hook run after `verilog-mode' deletes AUTOs."
1211 :group 'verilog-mode-auto
1212 :type 'hook)
1214 (defcustom verilog-before-delete-auto-hook nil
1215 "Hook run before `verilog-mode' deletes AUTOs."
1216 :group 'verilog-mode-auto
1217 :type 'hook)
1219 (defcustom verilog-getopt-flags-hook nil
1220 "Hook run after `verilog-getopt-flags' determines the Verilog option lists."
1221 :group 'verilog-mode-auto
1222 :type 'hook)
1224 (defcustom verilog-before-getopt-flags-hook nil
1225 "Hook run before `verilog-getopt-flags' determines the Verilog option lists."
1226 :group 'verilog-mode-auto
1227 :type 'hook)
1229 (defcustom verilog-before-save-font-hook nil
1230 "Hook run before `verilog-save-font-mods' removes highlighting."
1231 :group 'verilog-mode-auto
1232 :type 'hook)
1234 (defcustom verilog-after-save-font-hook nil
1235 "Hook run after `verilog-save-font-mods' restores highlighting."
1236 :group 'verilog-mode-auto
1237 :type 'hook)
1239 (defvar verilog-imenu-generic-expression
1240 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
1241 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
1242 "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
1245 ;; provide a verilog-header function.
1246 ;; Customization variables:
1248 (defvar verilog-date-scientific-format nil
1249 "If non-nil, dates are written in scientific format (e.g. 1997/09/17).
1250 If nil, in European format (e.g. 17.09.1997). The brain-dead American
1251 format (e.g. 09/17/1997) is not supported.")
1253 (defvar verilog-company nil
1254 "Default name of Company for Verilog header.
1255 If set will become buffer local.")
1256 (make-variable-buffer-local 'verilog-company)
1258 (defvar verilog-project nil
1259 "Default name of Project for Verilog header.
1260 If set will become buffer local.")
1261 (make-variable-buffer-local 'verilog-project)
1263 (defvar verilog-mode-map
1264 (let ((map (make-sparse-keymap)))
1265 (define-key map ";" 'electric-verilog-semi)
1266 (define-key map [(control 59)] 'electric-verilog-semi-with-comment)
1267 (define-key map ":" 'electric-verilog-colon)
1268 ;;(define-key map "=" 'electric-verilog-equal)
1269 (define-key map "\`" 'electric-verilog-tick)
1270 (define-key map "\t" 'electric-verilog-tab)
1271 (define-key map "\r" 'electric-verilog-terminate-line)
1272 ;; backspace/delete key bindings
1273 (define-key map [backspace] 'backward-delete-char-untabify)
1274 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
1275 (define-key map [delete] 'delete-char)
1276 (define-key map [(meta delete)] 'kill-word))
1277 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
1278 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
1279 (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
1280 (define-key map "\M-\t" 'verilog-complete-word)
1281 (define-key map "\M-?" 'verilog-show-completions)
1282 ;; Note \C-c and letter are reserved for users
1283 (define-key map "\C-c\`" 'verilog-lint-off)
1284 (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit)
1285 (define-key map "\C-c\?" 'verilog-diff-auto)
1286 (define-key map "\C-c\C-r" 'verilog-label-be)
1287 (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
1288 (define-key map "\C-c=" 'verilog-pretty-expr)
1289 (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
1290 (define-key map "\M-*" 'verilog-star-comment)
1291 (define-key map "\C-c\C-c" 'verilog-comment-region)
1292 (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1293 (when (featurep 'xemacs)
1294 (define-key map [(meta control h)] 'verilog-mark-defun)
1295 (define-key map "\M-\C-a" 'verilog-beg-of-defun)
1296 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1297 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1298 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1299 (define-key map "\C-c\C-a" 'verilog-auto)
1300 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1301 (define-key map "\C-c\C-p" 'verilog-preprocess)
1302 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1303 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1304 (define-key map "\C-c\C-h" 'verilog-header)
1305 map)
1306 "Keymap used in Verilog mode.")
1308 ;; menus
1309 (easy-menu-define
1310 verilog-menu verilog-mode-map "Menu for Verilog mode"
1311 (verilog-easy-menu-filter
1312 '("Verilog"
1313 ("Choose Compilation Action"
1314 ["None"
1315 (progn
1316 (setq verilog-tool nil)
1317 (verilog-set-compile-command))
1318 :style radio
1319 :selected (equal verilog-tool nil)
1320 :help "When invoking compilation, use compile-command"]
1321 ["Lint"
1322 (progn
1323 (setq verilog-tool 'verilog-linter)
1324 (verilog-set-compile-command))
1325 :style radio
1326 :selected (equal verilog-tool `verilog-linter)
1327 :help "When invoking compilation, use lint checker"]
1328 ["Coverage"
1329 (progn
1330 (setq verilog-tool 'verilog-coverage)
1331 (verilog-set-compile-command))
1332 :style radio
1333 :selected (equal verilog-tool `verilog-coverage)
1334 :help "When invoking compilation, annotate for coverage"]
1335 ["Simulator"
1336 (progn
1337 (setq verilog-tool 'verilog-simulator)
1338 (verilog-set-compile-command))
1339 :style radio
1340 :selected (equal verilog-tool `verilog-simulator)
1341 :help "When invoking compilation, interpret Verilog source"]
1342 ["Compiler"
1343 (progn
1344 (setq verilog-tool 'verilog-compiler)
1345 (verilog-set-compile-command))
1346 :style radio
1347 :selected (equal verilog-tool `verilog-compiler)
1348 :help "When invoking compilation, compile Verilog source"]
1349 ["Preprocessor"
1350 (progn
1351 (setq verilog-tool 'verilog-preprocessor)
1352 (verilog-set-compile-command))
1353 :style radio
1354 :selected (equal verilog-tool `verilog-preprocessor)
1355 :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1357 ("Move"
1358 ["Beginning of function" verilog-beg-of-defun
1359 :keys "C-M-a"
1360 :help "Move backward to the beginning of the current function or procedure"]
1361 ["End of function" verilog-end-of-defun
1362 :keys "C-M-e"
1363 :help "Move forward to the end of the current function or procedure"]
1364 ["Mark function" verilog-mark-defun
1365 :keys "C-M-h"
1366 :help "Mark the current Verilog function or procedure"]
1367 ["Goto function/module" verilog-goto-defun
1368 :help "Move to specified Verilog module/task/function"]
1369 ["Move to beginning of block" electric-verilog-backward-sexp
1370 :help "Move backward over one balanced expression"]
1371 ["Move to end of block" electric-verilog-forward-sexp
1372 :help "Move forward over one balanced expression"]
1374 ("Comments"
1375 ["Comment Region" verilog-comment-region
1376 :help "Put marked area into a comment"]
1377 ["UnComment Region" verilog-uncomment-region
1378 :help "Uncomment an area commented with Comment Region"]
1379 ["Multi-line comment insert" verilog-star-comment
1380 :help "Insert Verilog /* */ comment at point"]
1381 ["Lint error to comment" verilog-lint-off
1382 :help "Convert a Verilog linter warning line into a disable statement"]
1384 "----"
1385 ["Compile" compile
1386 :help "Perform compilation-action (above) on the current buffer"]
1387 ["AUTO, Save, Compile" verilog-auto-save-compile
1388 :help "Recompute AUTOs, save buffer, and compile"]
1389 ["Next Compile Error" next-error
1390 :help "Visit next compilation error message and corresponding source code"]
1391 ["Ignore Lint Warning at point" verilog-lint-off
1392 :help "Convert a Verilog linter warning line into a disable statement"]
1393 "----"
1394 ["Line up declarations around point" verilog-pretty-declarations
1395 :help "Line up declarations around point"]
1396 ["Line up equations around point" verilog-pretty-expr
1397 :help "Line up expressions around point"]
1398 ["Redo/insert comments on every end" verilog-label-be
1399 :help "Label matching begin ... end statements"]
1400 ["Expand [x:y] vector line" verilog-expand-vector
1401 :help "Take a signal vector on the current line and expand it to multiple lines"]
1402 ["Insert begin-end block" verilog-insert-block
1403 :help "Insert begin ... end"]
1404 ["Complete word" verilog-complete-word
1405 :help "Complete word at point"]
1406 "----"
1407 ["Recompute AUTOs" verilog-auto
1408 :help "Expand AUTO meta-comment statements"]
1409 ["Kill AUTOs" verilog-delete-auto
1410 :help "Remove AUTO expansions"]
1411 ["Diff AUTOs" verilog-diff-auto
1412 :help "Show differences in AUTO expansions"]
1413 ["Inject AUTOs" verilog-inject-auto
1414 :help "Inject AUTOs into legacy non-AUTO buffer"]
1415 ("AUTO Help..."
1416 ["AUTO General" (describe-function 'verilog-auto)
1417 :help "Help introduction on AUTOs"]
1418 ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
1419 :help "Help on verilog-library-flags"]
1420 ["AUTO Library Path" (describe-variable 'verilog-library-directories)
1421 :help "Help on verilog-library-directories"]
1422 ["AUTO Library Files" (describe-variable 'verilog-library-files)
1423 :help "Help on verilog-library-files"]
1424 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
1425 :help "Help on verilog-library-extensions"]
1426 ["AUTO `define Reading" (describe-function 'verilog-read-defines)
1427 :help "Help on reading `defines"]
1428 ["AUTO `include Reading" (describe-function 'verilog-read-includes)
1429 :help "Help on parsing `includes"]
1430 ["AUTOARG" (describe-function 'verilog-auto-arg)
1431 :help "Help on AUTOARG - declaring module port list"]
1432 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
1433 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1434 ["AUTOASSIGNMODPORT" (describe-function 'verilog-auto-assign-modport)
1435 :help "Help on AUTOASSIGNMODPORT - creating assignments to/from modports"]
1436 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
1437 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1438 ["AUTOINOUTIN" (describe-function 'verilog-auto-inout-in)
1439 :help "Help on AUTOINOUTIN - copying i/o from another file as all inputs"]
1440 ["AUTOINOUTMODPORT" (describe-function 'verilog-auto-inout-modport)
1441 :help "Help on AUTOINOUTMODPORT - copying i/o from an interface modport"]
1442 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1443 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1444 ["AUTOINOUTPARAM" (describe-function 'verilog-auto-inout-param)
1445 :help "Help on AUTOINOUTPARAM - copying parameters from another file"]
1446 ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
1447 :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
1448 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1449 :help "Help on AUTOINOUT - adding inouts from cells"]
1450 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1451 :help "Help on AUTOINPUT - adding inputs from cells"]
1452 ["AUTOINST" (describe-function 'verilog-auto-inst)
1453 :help "Help on AUTOINST - adding pins for cells"]
1454 ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
1455 :help "Help on expanding Verilog-2001 .* pins"]
1456 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
1457 :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
1458 ["AUTOLOGIC" (describe-function 'verilog-auto-logic)
1459 :help "Help on AUTOLOGIC - declaring logic signals"]
1460 ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
1461 :help "Help on AUTOOUTPUT - adding outputs from cells"]
1462 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
1463 :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
1464 ["AUTOREG" (describe-function 'verilog-auto-reg)
1465 :help "Help on AUTOREG - declaring registers for non-wires"]
1466 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
1467 :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
1468 ["AUTORESET" (describe-function 'verilog-auto-reset)
1469 :help "Help on AUTORESET - resetting always blocks"]
1470 ["AUTOSENSE" (describe-function 'verilog-auto-sense)
1471 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1472 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1473 :help "Help on AUTOTIEOFF - tying off unused outputs"]
1474 ["AUTOUNDEF" (describe-function 'verilog-auto-undef)
1475 :help "Help on AUTOUNDEF - undefine all local defines"]
1476 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1477 :help "Help on AUTOUNUSED - terminating unused inputs"]
1478 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
1479 :help "Help on AUTOWIRE - declaring wires for cells"]
1481 "----"
1482 ["Submit bug report" verilog-submit-bug-report
1483 :help "Submit via mail a bug report on verilog-mode.el"]
1484 ["Version and FAQ" verilog-faq
1485 :help "Show the current version, and where to get the FAQ etc"]
1486 ["Customize Verilog Mode..." verilog-customize
1487 :help "Customize variables and other settings used by Verilog-Mode"]
1488 ["Customize Verilog Fonts & Colors" verilog-font-customize
1489 :help "Customize fonts used by Verilog-Mode."])))
1491 (easy-menu-define
1492 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1493 (verilog-easy-menu-filter
1494 '("Statements"
1495 ["Header" verilog-sk-header
1496 :help "Insert a header block at the top of file"]
1497 ["Comment" verilog-sk-comment
1498 :help "Insert a comment block"]
1499 "----"
1500 ["Module" verilog-sk-module
1501 :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
1502 ["OVM Class" verilog-sk-ovm-class
1503 :help "Insert an OVM class block"]
1504 ["UVM Class" verilog-sk-uvm-class
1505 :help "Insert an UVM class block"]
1506 ["Primitive" verilog-sk-primitive
1507 :help "Insert a primitive .. (.. );.. endprimitive block"]
1508 "----"
1509 ["Input" verilog-sk-input
1510 :help "Insert an input declaration"]
1511 ["Output" verilog-sk-output
1512 :help "Insert an output declaration"]
1513 ["Inout" verilog-sk-inout
1514 :help "Insert an inout declaration"]
1515 ["Wire" verilog-sk-wire
1516 :help "Insert a wire declaration"]
1517 ["Reg" verilog-sk-reg
1518 :help "Insert a register declaration"]
1519 ["Define thing under point as a register" verilog-sk-define-signal
1520 :help "Define signal under point as a register at the top of the module"]
1521 "----"
1522 ["Initial" verilog-sk-initial
1523 :help "Insert an initial begin .. end block"]
1524 ["Always" verilog-sk-always
1525 :help "Insert an always @(AS) begin .. end block"]
1526 ["Function" verilog-sk-function
1527 :help "Insert a function .. begin .. end endfunction block"]
1528 ["Task" verilog-sk-task
1529 :help "Insert a task .. begin .. end endtask block"]
1530 ["Specify" verilog-sk-specify
1531 :help "Insert a specify .. endspecify block"]
1532 ["Generate" verilog-sk-generate
1533 :help "Insert a generate .. endgenerate block"]
1534 "----"
1535 ["Begin" verilog-sk-begin
1536 :help "Insert a begin .. end block"]
1537 ["If" verilog-sk-if
1538 :help "Insert an if (..) begin .. end block"]
1539 ["(if) else" verilog-sk-else-if
1540 :help "Insert an else if (..) begin .. end block"]
1541 ["For" verilog-sk-for
1542 :help "Insert a for (...) begin .. end block"]
1543 ["While" verilog-sk-while
1544 :help "Insert a while (...) begin .. end block"]
1545 ["Fork" verilog-sk-fork
1546 :help "Insert a fork begin .. end .. join block"]
1547 ["Repeat" verilog-sk-repeat
1548 :help "Insert a repeat (..) begin .. end block"]
1549 ["Case" verilog-sk-case
1550 :help "Insert a case block, prompting for details"]
1551 ["Casex" verilog-sk-casex
1552 :help "Insert a casex (...) item: begin.. end endcase block"]
1553 ["Casez" verilog-sk-casez
1554 :help "Insert a casez (...) item: begin.. end endcase block"])))
1556 (defvar verilog-mode-abbrev-table nil
1557 "Abbrev table in use in Verilog-mode buffers.")
1559 (define-abbrev-table 'verilog-mode-abbrev-table ())
1560 (verilog-define-abbrev verilog-mode-abbrev-table "class" "" 'verilog-sk-ovm-class)
1561 (verilog-define-abbrev verilog-mode-abbrev-table "always" "" 'verilog-sk-always)
1562 (verilog-define-abbrev verilog-mode-abbrev-table "begin" nil `verilog-sk-begin)
1563 (verilog-define-abbrev verilog-mode-abbrev-table "case" "" `verilog-sk-case)
1564 (verilog-define-abbrev verilog-mode-abbrev-table "for" "" `verilog-sk-for)
1565 (verilog-define-abbrev verilog-mode-abbrev-table "generate" "" `verilog-sk-generate)
1566 (verilog-define-abbrev verilog-mode-abbrev-table "initial" "" `verilog-sk-initial)
1567 (verilog-define-abbrev verilog-mode-abbrev-table "fork" "" `verilog-sk-fork)
1568 (verilog-define-abbrev verilog-mode-abbrev-table "module" "" `verilog-sk-module)
1569 (verilog-define-abbrev verilog-mode-abbrev-table "primitive" "" `verilog-sk-primitive)
1570 (verilog-define-abbrev verilog-mode-abbrev-table "repeat" "" `verilog-sk-repeat)
1571 (verilog-define-abbrev verilog-mode-abbrev-table "specify" "" `verilog-sk-specify)
1572 (verilog-define-abbrev verilog-mode-abbrev-table "task" "" `verilog-sk-task)
1573 (verilog-define-abbrev verilog-mode-abbrev-table "while" "" `verilog-sk-while)
1574 (verilog-define-abbrev verilog-mode-abbrev-table "casex" "" `verilog-sk-casex)
1575 (verilog-define-abbrev verilog-mode-abbrev-table "casez" "" `verilog-sk-casez)
1576 (verilog-define-abbrev verilog-mode-abbrev-table "if" "" `verilog-sk-if)
1577 (verilog-define-abbrev verilog-mode-abbrev-table "else if" "" `verilog-sk-else-if)
1578 (verilog-define-abbrev verilog-mode-abbrev-table "assign" "" `verilog-sk-assign)
1579 (verilog-define-abbrev verilog-mode-abbrev-table "function" "" `verilog-sk-function)
1580 (verilog-define-abbrev verilog-mode-abbrev-table "input" "" `verilog-sk-input)
1581 (verilog-define-abbrev verilog-mode-abbrev-table "output" "" `verilog-sk-output)
1582 (verilog-define-abbrev verilog-mode-abbrev-table "inout" "" `verilog-sk-inout)
1583 (verilog-define-abbrev verilog-mode-abbrev-table "wire" "" `verilog-sk-wire)
1584 (verilog-define-abbrev verilog-mode-abbrev-table "reg" "" `verilog-sk-reg)
1587 ;; Macros
1590 (defsubst verilog-within-string ()
1591 (nth 3 (parse-partial-sexp (point-at-bol) (point))))
1593 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1594 "Replace occurrences of FROM-STRING with TO-STRING.
1595 FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace.
1596 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1597 will break, as the o's continuously replace. xa -> x works ok though."
1598 ;; Hopefully soon to an Emacs built-in
1599 ;; Also note \ in the replacement prevent multiple replacements; IE
1600 ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
1601 ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
1602 (let ((start 0))
1603 (while (string-match from-string string start)
1604 (setq string (replace-match to-string fixedcase literal string)
1605 start (min (length string) (+ (match-beginning 0) (length to-string)))))
1606 string))
1608 (defsubst verilog-string-remove-spaces (string)
1609 "Remove spaces surrounding STRING."
1610 (save-match-data
1611 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
1612 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
1613 string))
1615 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
1616 ; checkdoc-params: (REGEXP BOUND NOERROR)
1617 "Like `re-search-forward', but skips over match in comments or strings."
1618 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1619 (while (and
1620 (re-search-forward REGEXP BOUND NOERROR)
1621 (setq mdata (match-data))
1622 (and (verilog-skip-forward-comment-or-string)
1623 (progn
1624 (setq mdata '(nil nil))
1625 (if BOUND
1626 (< (point) BOUND)
1627 t)))))
1628 (store-match-data mdata)
1629 (match-end 0)))
1631 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
1632 ; checkdoc-params: (REGEXP BOUND NOERROR)
1633 "Like `re-search-backward', but skips over match in comments or strings."
1634 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1635 (while (and
1636 (re-search-backward REGEXP BOUND NOERROR)
1637 (setq mdata (match-data))
1638 (and (verilog-skip-backward-comment-or-string)
1639 (progn
1640 (setq mdata '(nil nil))
1641 (if BOUND
1642 (> (point) BOUND)
1643 t)))))
1644 (store-match-data mdata)
1645 (match-end 0)))
1647 (defsubst verilog-re-search-forward-quick (regexp bound noerror)
1648 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
1649 but trashes match data and is faster for REGEXP that doesn't match often.
1650 This uses `verilog-scan' and text properties to ignore comments,
1651 so there may be a large up front penalty for the first search."
1652 (let (pt)
1653 (while (and (not pt)
1654 (re-search-forward regexp bound noerror))
1655 (if (verilog-inside-comment-or-string-p)
1656 (re-search-forward "[/\"\n]" nil t) ;; Only way a comment or quote can end
1657 (setq pt (match-end 0))))
1658 pt))
1660 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
1661 ; checkdoc-params: (REGEXP BOUND NOERROR)
1662 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
1663 but trashes match data and is faster for REGEXP that doesn't match often.
1664 This uses `verilog-scan' and text properties to ignore comments,
1665 so there may be a large up front penalty for the first search."
1666 (let (pt)
1667 (while (and (not pt)
1668 (re-search-backward regexp bound noerror))
1669 (if (verilog-inside-comment-or-string-p)
1670 (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
1671 (setq pt (match-beginning 0))))
1672 pt))
1674 (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
1675 "Like `re-search-forward', but first search for SUBSTR constant.
1676 Then searched for the normal REGEXP (which contains SUBSTR), with given
1677 BOUND and NOERROR. The REGEXP must fit within a single line.
1678 This speeds up complicated regexp matches."
1679 ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
1680 ;; thus require matches to be on one line, and use beginning-of-line.
1681 (let (done)
1682 (while (and (not done)
1683 (search-forward substr bound noerror))
1684 (save-excursion
1685 (beginning-of-line)
1686 (setq done (re-search-forward regexp (point-at-eol) noerror)))
1687 (unless (and (<= (match-beginning 0) (point))
1688 (>= (match-end 0) (point)))
1689 (setq done nil)))
1690 (when done (goto-char done))
1691 done))
1692 ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1694 (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
1695 "Like `re-search-backward', but first search for SUBSTR constant.
1696 Then searched for the normal REGEXP (which contains SUBSTR), with given
1697 BOUND and NOERROR. The REGEXP must fit within a single line.
1698 This speeds up complicated regexp matches."
1699 ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
1700 ;; thus require matches to be on one line, and use beginning-of-line.
1701 (let (done)
1702 (while (and (not done)
1703 (search-backward substr bound noerror))
1704 (save-excursion
1705 (end-of-line)
1706 (setq done (re-search-backward regexp (point-at-bol) noerror)))
1707 (unless (and (<= (match-beginning 0) (point))
1708 (>= (match-end 0) (point)))
1709 (setq done nil)))
1710 (when done (goto-char done))
1711 done))
1712 ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1714 (defun verilog-delete-trailing-whitespace ()
1715 "Delete trailing spaces or tabs, but not newlines nor linefeeds.
1716 Also add missing final newline.
1718 To call this from the command line, see \\[verilog-batch-diff-auto].
1720 To call on \\[verilog-auto], set `verilog-auto-delete-trailing-whitespace'."
1721 ;; Similar to `delete-trailing-whitespace' but that's not present in XEmacs
1722 (save-excursion
1723 (goto-char (point-min))
1724 (while (re-search-forward "[ \t]+$" nil t) ;; Not syntactic WS as no formfeed
1725 (replace-match "" nil nil))
1726 (goto-char (point-max))
1727 (unless (bolp) (insert "\n"))))
1729 (defvar compile-command)
1731 ;; compilation program
1732 (defun verilog-set-compile-command ()
1733 "Function to compute shell command to compile Verilog.
1735 This reads `verilog-tool' and sets `compile-command'. This specifies the
1736 program that executes when you type \\[compile] or
1737 \\[verilog-auto-save-compile].
1739 By default `verilog-tool' uses a Makefile if one exists in the
1740 current directory. If not, it is set to the `verilog-linter',
1741 `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
1742 or `verilog-simulator' variables, as selected with the Verilog ->
1743 \"Choose Compilation Action\" menu.
1745 You should set `verilog-tool' or the other variables to the path and
1746 arguments for your Verilog simulator. For example:
1747 \"vcs -p123 -O\"
1748 or a string like:
1749 \"(cd /tmp; surecov %s)\".
1751 In the former case, the path to the current buffer is concat'ed to the
1752 value of `verilog-tool'; in the later, the path to the current buffer is
1753 substituted for the %s.
1755 Where __FLAGS__ appears in the string `verilog-current-flags'
1756 will be substituted.
1758 Where __FILE__ appears in the string, the variable
1759 `buffer-file-name' of the current buffer, without the directory
1760 portion, will be substituted."
1761 (interactive)
1762 (cond
1763 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1764 (file-exists-p "Makefile"))
1765 (set (make-local-variable 'compile-command) "make "))
1767 (set (make-local-variable 'compile-command)
1768 (if verilog-tool
1769 (if (string-match "%s" (eval verilog-tool))
1770 (format (eval verilog-tool) (or buffer-file-name ""))
1771 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1772 ""))))
1773 (verilog-modify-compile-command))
1775 (defun verilog-expand-command (command)
1776 "Replace meta-information in COMMAND and return it.
1777 Where __FLAGS__ appears in the string `verilog-current-flags'
1778 will be substituted. Where __FILE__ appears in the string, the
1779 current buffer's file-name, without the directory portion, will
1780 be substituted."
1781 (setq command (verilog-string-replace-matches
1782 ;; Note \\b only works if under verilog syntax table
1783 "\\b__FLAGS__\\b" (verilog-current-flags)
1784 t t command))
1785 (setq command (verilog-string-replace-matches
1786 "\\b__FILE__\\b" (file-name-nondirectory
1787 (or (buffer-file-name) ""))
1788 t t command))
1789 command)
1791 (defun verilog-modify-compile-command ()
1792 "Update `compile-command' using `verilog-expand-command'."
1793 (when (and
1794 (stringp compile-command)
1795 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1796 (set (make-local-variable 'compile-command)
1797 (verilog-expand-command compile-command))))
1799 (if (featurep 'xemacs)
1800 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1801 (defun verilog-error-regexp-add-xemacs ()
1802 "Teach XEmacs about verilog errors.
1803 Called by `compilation-mode-hook'. This allows \\[next-error] to
1804 find the errors."
1805 (interactive)
1806 (if (boundp 'compilation-error-regexp-systems-alist)
1807 (if (and
1808 (not (equal compilation-error-regexp-systems-list 'all))
1809 (not (member compilation-error-regexp-systems-list 'verilog)))
1810 (push 'verilog compilation-error-regexp-systems-list)))
1811 (if (boundp 'compilation-error-regexp-alist-alist)
1812 (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
1813 (setcdr compilation-error-regexp-alist-alist
1814 (cons verilog-error-regexp-xemacs-alist
1815 (cdr compilation-error-regexp-alist-alist)))))
1816 (if (boundp 'compilation-font-lock-keywords)
1817 (progn
1818 (set (make-local-variable 'compilation-font-lock-keywords)
1819 verilog-error-font-lock-keywords)
1820 (font-lock-set-defaults)))
1821 ;; Need to re-run compilation-error-regexp builder
1822 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
1823 (compilation-build-compilation-error-regexp-alist))
1826 ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
1827 (defun verilog-error-regexp-add-emacs ()
1828 "Tell Emacs compile that we are Verilog.
1829 Called by `compilation-mode-hook'. This allows \\[next-error] to
1830 find the errors."
1831 (interactive)
1832 (if (boundp 'compilation-error-regexp-alist-alist)
1833 (progn
1834 (if (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
1835 (mapcar
1836 (lambda (item)
1837 (push (car item) compilation-error-regexp-alist)
1838 (push item compilation-error-regexp-alist-alist)
1840 verilog-error-regexp-emacs-alist)))))
1842 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
1843 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
1845 (defconst verilog-directive-re
1846 (eval-when-compile
1847 (verilog-regexp-words
1849 "`case" "`default" "`define" "`else" "`elsif" "`endfor" "`endif"
1850 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
1851 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
1852 "`time_scale" "`undef" "`while" ))))
1854 (defconst verilog-directive-re-1
1855 (concat "[ \t]*" verilog-directive-re))
1857 (defconst verilog-directive-begin
1858 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
1860 (defconst verilog-directive-middle
1861 "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
1863 (defconst verilog-directive-end
1864 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
1866 (defconst verilog-ovm-begin-re
1867 (eval-when-compile
1868 (verilog-regexp-opt
1870 "`ovm_component_utils_begin"
1871 "`ovm_component_param_utils_begin"
1872 "`ovm_field_utils_begin"
1873 "`ovm_object_utils_begin"
1874 "`ovm_object_param_utils_begin"
1875 "`ovm_sequence_utils_begin"
1876 "`ovm_sequencer_utils_begin"
1877 ) nil )))
1879 (defconst verilog-ovm-end-re
1880 (eval-when-compile
1881 (verilog-regexp-opt
1883 "`ovm_component_utils_end"
1884 "`ovm_field_utils_end"
1885 "`ovm_object_utils_end"
1886 "`ovm_sequence_utils_end"
1887 "`ovm_sequencer_utils_end"
1888 ) nil )))
1890 (defconst verilog-uvm-begin-re
1891 (eval-when-compile
1892 (verilog-regexp-opt
1894 "`uvm_component_utils_begin"
1895 "`uvm_component_param_utils_begin"
1896 "`uvm_field_utils_begin"
1897 "`uvm_object_utils_begin"
1898 "`uvm_object_param_utils_begin"
1899 "`uvm_sequence_utils_begin"
1900 "`uvm_sequencer_utils_begin"
1901 ) nil )))
1903 (defconst verilog-uvm-end-re
1904 (eval-when-compile
1905 (verilog-regexp-opt
1907 "`uvm_component_utils_end"
1908 "`uvm_field_utils_end"
1909 "`uvm_object_utils_end"
1910 "`uvm_sequence_utils_end"
1911 "`uvm_sequencer_utils_end"
1912 ) nil )))
1914 (defconst verilog-vmm-begin-re
1915 (eval-when-compile
1916 (verilog-regexp-opt
1918 "`vmm_data_member_begin"
1919 "`vmm_env_member_begin"
1920 "`vmm_scenario_member_begin"
1921 "`vmm_subenv_member_begin"
1922 "`vmm_xactor_member_begin"
1923 ) nil ) ) )
1925 (defconst verilog-vmm-end-re
1926 (eval-when-compile
1927 (verilog-regexp-opt
1929 "`vmm_data_member_end"
1930 "`vmm_env_member_end"
1931 "`vmm_scenario_member_end"
1932 "`vmm_subenv_member_end"
1933 "`vmm_xactor_member_end"
1934 ) nil ) ) )
1936 (defconst verilog-vmm-statement-re
1937 (eval-when-compile
1938 (verilog-regexp-opt
1940 ;; "`vmm_xactor_member_enum_array"
1941 "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
1942 ;; "`vmm_xactor_member_scalar_array"
1943 ;; "`vmm_xactor_member_scalar"
1944 ) nil )))
1946 (defconst verilog-ovm-statement-re
1947 (eval-when-compile
1948 (verilog-regexp-opt
1950 ;; Statements
1951 "`DUT_ERROR"
1952 "`MESSAGE"
1953 "`dut_error"
1954 "`message"
1955 "`ovm_analysis_imp_decl"
1956 "`ovm_blocking_get_imp_decl"
1957 "`ovm_blocking_get_peek_imp_decl"
1958 "`ovm_blocking_master_imp_decl"
1959 "`ovm_blocking_peek_imp_decl"
1960 "`ovm_blocking_put_imp_decl"
1961 "`ovm_blocking_slave_imp_decl"
1962 "`ovm_blocking_transport_imp_decl"
1963 "`ovm_component_registry"
1964 "`ovm_component_registry_param"
1965 "`ovm_component_utils"
1966 "`ovm_create"
1967 "`ovm_create_seq"
1968 "`ovm_declare_sequence_lib"
1969 "`ovm_do"
1970 "`ovm_do_seq"
1971 "`ovm_do_seq_with"
1972 "`ovm_do_with"
1973 "`ovm_error"
1974 "`ovm_fatal"
1975 "`ovm_field_aa_int_byte"
1976 "`ovm_field_aa_int_byte_unsigned"
1977 "`ovm_field_aa_int_int"
1978 "`ovm_field_aa_int_int_unsigned"
1979 "`ovm_field_aa_int_integer"
1980 "`ovm_field_aa_int_integer_unsigned"
1981 "`ovm_field_aa_int_key"
1982 "`ovm_field_aa_int_longint"
1983 "`ovm_field_aa_int_longint_unsigned"
1984 "`ovm_field_aa_int_shortint"
1985 "`ovm_field_aa_int_shortint_unsigned"
1986 "`ovm_field_aa_int_string"
1987 "`ovm_field_aa_object_int"
1988 "`ovm_field_aa_object_string"
1989 "`ovm_field_aa_string_int"
1990 "`ovm_field_aa_string_string"
1991 "`ovm_field_array_int"
1992 "`ovm_field_array_object"
1993 "`ovm_field_array_string"
1994 "`ovm_field_enum"
1995 "`ovm_field_event"
1996 "`ovm_field_int"
1997 "`ovm_field_object"
1998 "`ovm_field_queue_int"
1999 "`ovm_field_queue_object"
2000 "`ovm_field_queue_string"
2001 "`ovm_field_sarray_int"
2002 "`ovm_field_string"
2003 "`ovm_field_utils"
2004 "`ovm_file"
2005 "`ovm_get_imp_decl"
2006 "`ovm_get_peek_imp_decl"
2007 "`ovm_info"
2008 "`ovm_info1"
2009 "`ovm_info2"
2010 "`ovm_info3"
2011 "`ovm_info4"
2012 "`ovm_line"
2013 "`ovm_master_imp_decl"
2014 "`ovm_msg_detail"
2015 "`ovm_non_blocking_transport_imp_decl"
2016 "`ovm_nonblocking_get_imp_decl"
2017 "`ovm_nonblocking_get_peek_imp_decl"
2018 "`ovm_nonblocking_master_imp_decl"
2019 "`ovm_nonblocking_peek_imp_decl"
2020 "`ovm_nonblocking_put_imp_decl"
2021 "`ovm_nonblocking_slave_imp_decl"
2022 "`ovm_object_registry"
2023 "`ovm_object_registry_param"
2024 "`ovm_object_utils"
2025 "`ovm_peek_imp_decl"
2026 "`ovm_phase_func_decl"
2027 "`ovm_phase_task_decl"
2028 "`ovm_print_aa_int_object"
2029 "`ovm_print_aa_string_int"
2030 "`ovm_print_aa_string_object"
2031 "`ovm_print_aa_string_string"
2032 "`ovm_print_array_int"
2033 "`ovm_print_array_object"
2034 "`ovm_print_array_string"
2035 "`ovm_print_object_queue"
2036 "`ovm_print_queue_int"
2037 "`ovm_print_string_queue"
2038 "`ovm_put_imp_decl"
2039 "`ovm_rand_send"
2040 "`ovm_rand_send_with"
2041 "`ovm_send"
2042 "`ovm_sequence_utils"
2043 "`ovm_slave_imp_decl"
2044 "`ovm_transport_imp_decl"
2045 "`ovm_update_sequence_lib"
2046 "`ovm_update_sequence_lib_and_item"
2047 "`ovm_warning"
2048 "`static_dut_error"
2049 "`static_message") nil )))
2051 (defconst verilog-uvm-statement-re
2052 (eval-when-compile
2053 (verilog-regexp-opt
2055 ;; Statements
2056 "`uvm_analysis_imp_decl"
2057 "`uvm_blocking_get_imp_decl"
2058 "`uvm_blocking_get_peek_imp_decl"
2059 "`uvm_blocking_master_imp_decl"
2060 "`uvm_blocking_peek_imp_decl"
2061 "`uvm_blocking_put_imp_decl"
2062 "`uvm_blocking_slave_imp_decl"
2063 "`uvm_blocking_transport_imp_decl"
2064 "`uvm_component_param_utils"
2065 "`uvm_component_registry"
2066 "`uvm_component_registry_param"
2067 "`uvm_component_utils"
2068 "`uvm_create"
2069 "`uvm_create_on"
2070 "`uvm_create_seq" ;; Undocumented in 1.1
2071 "`uvm_declare_p_sequencer"
2072 "`uvm_declare_sequence_lib" ;; Deprecated in 1.1
2073 "`uvm_do"
2074 "`uvm_do_callbacks"
2075 "`uvm_do_callbacks_exit_on"
2076 "`uvm_do_obj_callbacks"
2077 "`uvm_do_obj_callbacks_exit_on"
2078 "`uvm_do_on"
2079 "`uvm_do_on_pri"
2080 "`uvm_do_on_pri_with"
2081 "`uvm_do_on_with"
2082 "`uvm_do_pri"
2083 "`uvm_do_pri_with"
2084 "`uvm_do_seq" ;; Undocumented in 1.1
2085 "`uvm_do_seq_with" ;; Undocumented in 1.1
2086 "`uvm_do_with"
2087 "`uvm_error"
2088 "`uvm_error_context"
2089 "`uvm_fatal"
2090 "`uvm_fatal_context"
2091 "`uvm_field_aa_int_byte"
2092 "`uvm_field_aa_int_byte_unsigned"
2093 "`uvm_field_aa_int_enum"
2094 "`uvm_field_aa_int_int"
2095 "`uvm_field_aa_int_int_unsigned"
2096 "`uvm_field_aa_int_integer"
2097 "`uvm_field_aa_int_integer_unsigned"
2098 "`uvm_field_aa_int_key"
2099 "`uvm_field_aa_int_longint"
2100 "`uvm_field_aa_int_longint_unsigned"
2101 "`uvm_field_aa_int_shortint"
2102 "`uvm_field_aa_int_shortint_unsigned"
2103 "`uvm_field_aa_int_string"
2104 "`uvm_field_aa_object_int"
2105 "`uvm_field_aa_object_string"
2106 "`uvm_field_aa_string_int"
2107 "`uvm_field_aa_string_string"
2108 "`uvm_field_array_enum"
2109 "`uvm_field_array_int"
2110 "`uvm_field_array_object"
2111 "`uvm_field_array_string"
2112 "`uvm_field_enum"
2113 "`uvm_field_event"
2114 "`uvm_field_int"
2115 "`uvm_field_object"
2116 "`uvm_field_queue_enum"
2117 "`uvm_field_queue_int"
2118 "`uvm_field_queue_object"
2119 "`uvm_field_queue_string"
2120 "`uvm_field_real"
2121 "`uvm_field_sarray_enum"
2122 "`uvm_field_sarray_int"
2123 "`uvm_field_sarray_object"
2124 "`uvm_field_sarray_string"
2125 "`uvm_field_string"
2126 "`uvm_field_utils"
2127 "`uvm_file" ;; Undocumented in 1.1, use `__FILE__
2128 "`uvm_get_imp_decl"
2129 "`uvm_get_peek_imp_decl"
2130 "`uvm_info"
2131 "`uvm_info_context"
2132 "`uvm_line" ;; Undocumented in 1.1, use `__LINE__
2133 "`uvm_master_imp_decl"
2134 "`uvm_non_blocking_transport_imp_decl" ;; Deprecated in 1.1
2135 "`uvm_nonblocking_get_imp_decl"
2136 "`uvm_nonblocking_get_peek_imp_decl"
2137 "`uvm_nonblocking_master_imp_decl"
2138 "`uvm_nonblocking_peek_imp_decl"
2139 "`uvm_nonblocking_put_imp_decl"
2140 "`uvm_nonblocking_slave_imp_decl"
2141 "`uvm_nonblocking_transport_imp_decl"
2142 "`uvm_object_param_utils"
2143 "`uvm_object_registry"
2144 "`uvm_object_registry_param" ;; Undocumented in 1.1
2145 "`uvm_object_utils"
2146 "`uvm_pack_array"
2147 "`uvm_pack_arrayN"
2148 "`uvm_pack_enum"
2149 "`uvm_pack_enumN"
2150 "`uvm_pack_int"
2151 "`uvm_pack_intN"
2152 "`uvm_pack_queue"
2153 "`uvm_pack_queueN"
2154 "`uvm_pack_real"
2155 "`uvm_pack_sarray"
2156 "`uvm_pack_sarrayN"
2157 "`uvm_pack_string"
2158 "`uvm_peek_imp_decl"
2159 "`uvm_put_imp_decl"
2160 "`uvm_rand_send"
2161 "`uvm_rand_send_pri"
2162 "`uvm_rand_send_pri_with"
2163 "`uvm_rand_send_with"
2164 "`uvm_record_attribute"
2165 "`uvm_record_field"
2166 "`uvm_register_cb"
2167 "`uvm_send"
2168 "`uvm_send_pri"
2169 "`uvm_sequence_utils" ;; Deprecated in 1.1
2170 "`uvm_set_super_type"
2171 "`uvm_slave_imp_decl"
2172 "`uvm_transport_imp_decl"
2173 "`uvm_unpack_array"
2174 "`uvm_unpack_arrayN"
2175 "`uvm_unpack_enum"
2176 "`uvm_unpack_enumN"
2177 "`uvm_unpack_int"
2178 "`uvm_unpack_intN"
2179 "`uvm_unpack_queue"
2180 "`uvm_unpack_queueN"
2181 "`uvm_unpack_real"
2182 "`uvm_unpack_sarray"
2183 "`uvm_unpack_sarrayN"
2184 "`uvm_unpack_string"
2185 "`uvm_update_sequence_lib" ;; Deprecated in 1.1
2186 "`uvm_update_sequence_lib_and_item" ;; Deprecated in 1.1
2187 "`uvm_warning"
2188 "`uvm_warning_context") nil )))
2192 ;; Regular expressions used to calculate indent, etc.
2194 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
2195 ;; Want to match
2196 ;; aa :
2197 ;; aa,bb :
2198 ;; a[34:32] :
2199 ;; a,
2200 ;; b :
2201 (defconst verilog-assignment-operator-re
2202 (eval-when-compile
2203 (verilog-regexp-opt
2205 ;; blocking assignment_operator
2206 "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
2207 ;; non blocking assignment operator
2208 "<="
2209 ;; comparison
2210 "==" "!=" "===" "!===" "<=" ">=" "==\?" "!=\?"
2211 ;; event_trigger
2212 "->" "->>"
2213 ;; property_expr
2214 "|->" "|=>"
2215 ;; Is this a legal verilog operator?
2216 ":="
2217 ) 't
2219 (defconst verilog-assignment-operation-re
2220 (concat
2221 ; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)"
2222 ; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)"
2223 "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" ))
2225 (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
2226 (defconst verilog-property-re
2227 (concat "\\(" verilog-label-re "\\)?"
2228 "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
2229 ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
2231 (defconst verilog-no-indent-begin-re
2232 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>")
2234 (defconst verilog-ends-re
2235 ;; Parenthesis indicate type of keyword found
2236 (concat
2237 "\\(\\<else\\>\\)\\|" ; 1
2238 "\\(\\<if\\>\\)\\|" ; 2
2239 "\\(\\<assert\\>\\)\\|" ; 3
2240 "\\(\\<end\\>\\)\\|" ; 3.1
2241 "\\(\\<endcase\\>\\)\\|" ; 4
2242 "\\(\\<endfunction\\>\\)\\|" ; 5
2243 "\\(\\<endtask\\>\\)\\|" ; 6
2244 "\\(\\<endspecify\\>\\)\\|" ; 7
2245 "\\(\\<endtable\\>\\)\\|" ; 8
2246 "\\(\\<endgenerate\\>\\)\\|" ; 9
2247 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
2248 "\\(\\<endclass\\>\\)\\|" ; 11
2249 "\\(\\<endgroup\\>\\)\\|" ; 12
2250 ;; VMM
2251 "\\(\\<`vmm_data_member_end\\>\\)\\|"
2252 "\\(\\<`vmm_env_member_end\\>\\)\\|"
2253 "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
2254 "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
2255 "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
2256 ;; OVM
2257 "\\(\\<`ovm_component_utils_end\\>\\)\\|"
2258 "\\(\\<`ovm_field_utils_end\\>\\)\\|"
2259 "\\(\\<`ovm_object_utils_end\\>\\)\\|"
2260 "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
2261 "\\(\\<`ovm_sequencer_utils_end\\>\\)"
2262 ;; UVM
2263 "\\(\\<`uvm_component_utils_end\\>\\)\\|"
2264 "\\(\\<`uvm_field_utils_end\\>\\)\\|"
2265 "\\(\\<`uvm_object_utils_end\\>\\)\\|"
2266 "\\(\\<`uvm_sequence_utils_end\\>\\)\\|"
2267 "\\(\\<`uvm_sequencer_utils_end\\>\\)"
2270 (defconst verilog-auto-end-comment-lines-re
2271 ;; Matches to names in this list cause auto-end-commenting
2272 (concat "\\("
2273 verilog-directive-re "\\)\\|\\("
2274 (eval-when-compile
2275 (verilog-regexp-words
2276 `( "begin"
2277 "else"
2278 "end"
2279 "endcase"
2280 "endclass"
2281 "endclocking"
2282 "endgroup"
2283 "endfunction"
2284 "endmodule"
2285 "endprogram"
2286 "endprimitive"
2287 "endinterface"
2288 "endpackage"
2289 "endsequence"
2290 "endspecify"
2291 "endtable"
2292 "endtask"
2293 "join"
2294 "join_any"
2295 "join_none"
2296 "module"
2297 "macromodule"
2298 "primitive"
2299 "interface"
2300 "package")))
2301 "\\)"))
2303 ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
2304 ;;; verilog-end-block-ordered-re matches exactly the same strings.
2305 (defconst verilog-end-block-ordered-re
2306 ;; Parenthesis indicate type of keyword found
2307 (concat "\\(\\<endcase\\>\\)\\|" ; 1
2308 "\\(\\<end\\>\\)\\|" ; 2
2309 "\\(\\<end" ; 3, but not used
2310 "\\(" ; 4, but not used
2311 "\\(function\\)\\|" ; 5
2312 "\\(task\\)\\|" ; 6
2313 "\\(module\\)\\|" ; 7
2314 "\\(primitive\\)\\|" ; 8
2315 "\\(interface\\)\\|" ; 9
2316 "\\(package\\)\\|" ; 10
2317 "\\(class\\)\\|" ; 11
2318 "\\(group\\)\\|" ; 12
2319 "\\(program\\)\\|" ; 13
2320 "\\(sequence\\)\\|" ; 14
2321 "\\(clocking\\)\\|" ; 15
2322 "\\)\\>\\)"))
2323 (defconst verilog-end-block-re
2324 (eval-when-compile
2325 (verilog-regexp-words
2327 `("end" ;; closes begin
2328 "endcase" ;; closes any of case, casex casez or randcase
2329 "join" "join_any" "join_none" ;; closes fork
2330 "endclass"
2331 "endtable"
2332 "endspecify"
2333 "endfunction"
2334 "endgenerate"
2335 "endtask"
2336 "endgroup"
2337 "endproperty"
2338 "endinterface"
2339 "endpackage"
2340 "endprogram"
2341 "endsequence"
2342 "endclocking"
2343 ;; OVM
2344 "`ovm_component_utils_end"
2345 "`ovm_field_utils_end"
2346 "`ovm_object_utils_end"
2347 "`ovm_sequence_utils_end"
2348 "`ovm_sequencer_utils_end"
2349 ;; UVM
2350 "`uvm_component_utils_end"
2351 "`uvm_field_utils_end"
2352 "`uvm_object_utils_end"
2353 "`uvm_sequence_utils_end"
2354 "`uvm_sequencer_utils_end"
2355 ;; VMM
2356 "`vmm_data_member_end"
2357 "`vmm_env_member_end"
2358 "`vmm_scenario_member_end"
2359 "`vmm_subenv_member_end"
2360 "`vmm_xactor_member_end"
2361 ))))
2364 (defconst verilog-endcomment-reason-re
2365 ;; Parenthesis indicate type of keyword found
2366 (concat
2367 "\\(\\<begin\\>\\)\\|" ; 1
2368 "\\(\\<else\\>\\)\\|" ; 2
2369 "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
2370 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" ; 4
2371 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" ; 5
2372 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" ; 6
2373 "\\(\\<fork\\>\\)\\|" ; 7
2374 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
2375 "\\(\\<if\\>\\)\\|"
2376 verilog-property-re "\\|"
2377 "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
2378 "\\(\\<clocking\\>\\)\\|"
2379 "\\(\\<task\\>\\)\\|"
2380 "\\(\\<function\\>\\)\\|"
2381 "\\(\\<initial\\>\\)\\|"
2382 "\\(\\<interface\\>\\)\\|"
2383 "\\(\\<package\\>\\)\\|"
2384 "\\(\\<final\\>\\)\\|"
2385 "\\(@\\)\\|"
2386 "\\(\\<while\\>\\)\\|"
2387 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
2388 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
2389 "#"))
2391 (defconst verilog-named-block-re "begin[ \t]*:")
2393 ;; These words begin a block which can occur inside a module which should be indented,
2394 ;; and closed with the respective word from the end-block list
2396 (defconst verilog-beg-block-re
2397 (eval-when-compile
2398 (verilog-regexp-words
2399 `("begin"
2400 "case" "casex" "casez" "randcase"
2401 "clocking"
2402 "generate"
2403 "fork"
2404 "function"
2405 "property"
2406 "specify"
2407 "table"
2408 "task"
2409 ;; OVM
2410 "`ovm_component_utils_begin"
2411 "`ovm_component_param_utils_begin"
2412 "`ovm_field_utils_begin"
2413 "`ovm_object_utils_begin"
2414 "`ovm_object_param_utils_begin"
2415 "`ovm_sequence_utils_begin"
2416 "`ovm_sequencer_utils_begin"
2417 ;; UVM
2418 "`uvm_component_utils_begin"
2419 "`uvm_component_param_utils_begin"
2420 "`uvm_field_utils_begin"
2421 "`uvm_object_utils_begin"
2422 "`uvm_object_param_utils_begin"
2423 "`uvm_sequence_utils_begin"
2424 "`uvm_sequencer_utils_begin"
2425 ;; VMM
2426 "`vmm_data_member_begin"
2427 "`vmm_env_member_begin"
2428 "`vmm_scenario_member_begin"
2429 "`vmm_subenv_member_begin"
2430 "`vmm_xactor_member_begin"
2431 ))))
2432 ;; These are the same words, in a specific order in the regular
2433 ;; expression so that matching will work nicely for
2434 ;; verilog-forward-sexp and verilog-calc-indent
2435 (defconst verilog-beg-block-re-ordered
2436 ( concat "\\(\\<begin\\>\\)" ;1
2437 "\\|\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
2438 "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
2439 "\\|\\(\\<class\\>\\)" ;6
2440 "\\|\\(\\<table\\>\\)" ;7
2441 "\\|\\(\\<specify\\>\\)" ;8
2442 "\\|\\(\\<function\\>\\)" ;9
2443 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<function\\>\\)" ;10
2444 "\\|\\(\\<task\\>\\)" ;14
2445 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;15
2446 "\\|\\(\\<generate\\>\\)" ;18
2447 "\\|\\(\\<covergroup\\>\\)" ;16 20
2448 "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17 21
2449 "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25
2450 "\\|\\(\\<clocking\\>\\)" ;22 27
2451 "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;28
2452 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
2456 (defconst verilog-end-block-ordered-rry
2457 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2458 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
2459 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2460 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
2461 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
2462 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
2463 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
2464 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
2465 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
2466 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
2467 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
2468 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
2469 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
2472 (defconst verilog-nameable-item-re
2473 (eval-when-compile
2474 (verilog-regexp-words
2475 `("begin"
2476 "fork"
2477 "join" "join_any" "join_none"
2478 "end"
2479 "endcase"
2480 "endconfig"
2481 "endclass"
2482 "endclocking"
2483 "endfunction"
2484 "endgenerate"
2485 "endmodule"
2486 "endprimitive"
2487 "endinterface"
2488 "endpackage"
2489 "endspecify"
2490 "endtable"
2491 "endtask" )
2494 (defconst verilog-declaration-opener
2495 (eval-when-compile
2496 (verilog-regexp-words
2497 `("module" "begin" "task" "function"))))
2499 (defconst verilog-declaration-prefix-re
2500 (eval-when-compile
2501 (verilog-regexp-words
2503 ;; port direction
2504 "inout" "input" "output" "ref"
2505 ;; changeableness
2506 "const" "static" "protected" "local"
2507 ;; parameters
2508 "localparam" "parameter" "var"
2509 ;; type creation
2510 "typedef"
2511 ))))
2512 (defconst verilog-declaration-core-re
2513 (eval-when-compile
2514 (verilog-regexp-words
2516 ;; port direction (by themselves)
2517 "inout" "input" "output"
2518 ;; integer_atom_type
2519 "byte" "shortint" "int" "longint" "integer" "time"
2520 ;; integer_vector_type
2521 "bit" "logic" "reg"
2522 ;; non_integer_type
2523 "shortreal" "real" "realtime"
2524 ;; net_type
2525 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
2526 ;; misc
2527 "string" "event" "chandle" "virtual" "enum" "genvar"
2528 "struct" "union"
2529 ;; builtin classes
2530 "mailbox" "semaphore"
2531 ))))
2532 (defconst verilog-declaration-re
2533 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
2534 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
2535 (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?")
2536 (defconst verilog-optional-signed-range-re
2537 (concat
2538 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
2539 (defconst verilog-macroexp-re "`\\sw+")
2541 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
2542 (defconst verilog-declaration-re-2-no-macro
2543 (concat "\\s-*" verilog-declaration-re
2544 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2545 "\\)?"))
2546 (defconst verilog-declaration-re-2-macro
2547 (concat "\\s-*" verilog-declaration-re
2548 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2549 "\\|\\(" verilog-macroexp-re "\\)"
2550 "\\)?"))
2551 (defconst verilog-declaration-re-1-macro
2552 (concat "^" verilog-declaration-re-2-macro))
2554 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
2556 (defconst verilog-defun-re
2557 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
2558 (defconst verilog-end-defun-re
2559 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
2560 (defconst verilog-zero-indent-re
2561 (concat verilog-defun-re "\\|" verilog-end-defun-re))
2562 (defconst verilog-inst-comment-re
2563 (eval-when-compile (verilog-regexp-words `("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced"))))
2565 (defconst verilog-behavioral-block-beg-re
2566 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
2567 "function" "task"))))
2568 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
2569 (defconst verilog-indent-re
2570 (eval-when-compile
2571 (verilog-regexp-words
2574 "always" "always_latch" "always_ff" "always_comb"
2575 "begin" "end"
2576 ; "unique" "priority"
2577 "case" "casex" "casez" "randcase" "endcase"
2578 "class" "endclass"
2579 "clocking" "endclocking"
2580 "config" "endconfig"
2581 "covergroup" "endgroup"
2582 "fork" "join" "join_any" "join_none"
2583 "function" "endfunction"
2584 "final"
2585 "generate" "endgenerate"
2586 "initial"
2587 "interface" "endinterface"
2588 "module" "macromodule" "endmodule"
2589 "package" "endpackage"
2590 "primitive" "endprimitive"
2591 "program" "endprogram"
2592 "property" "endproperty"
2593 "sequence" "randsequence" "endsequence"
2594 "specify" "endspecify"
2595 "table" "endtable"
2596 "task" "endtask"
2597 "virtual"
2598 "`case"
2599 "`default"
2600 "`define" "`undef"
2601 "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
2602 "`while" "`endwhile"
2603 "`for" "`endfor"
2604 "`format"
2605 "`include"
2606 "`let"
2607 "`protect" "`endprotect"
2608 "`switch" "`endswitch"
2609 "`timescale"
2610 "`time_scale"
2611 ;; OVM Begin tokens
2612 "`ovm_component_utils_begin"
2613 "`ovm_component_param_utils_begin"
2614 "`ovm_field_utils_begin"
2615 "`ovm_object_utils_begin"
2616 "`ovm_object_param_utils_begin"
2617 "`ovm_sequence_utils_begin"
2618 "`ovm_sequencer_utils_begin"
2619 ;; OVM End tokens
2620 "`ovm_component_utils_end"
2621 "`ovm_field_utils_end"
2622 "`ovm_object_utils_end"
2623 "`ovm_sequence_utils_end"
2624 "`ovm_sequencer_utils_end"
2625 ;; UVM Begin tokens
2626 "`uvm_component_utils_begin"
2627 "`uvm_component_param_utils_begin"
2628 "`uvm_field_utils_begin"
2629 "`uvm_object_utils_begin"
2630 "`uvm_object_param_utils_begin"
2631 "`uvm_sequence_utils_begin"
2632 "`uvm_sequencer_utils_begin"
2633 ;; UVM End tokens
2634 "`uvm_component_utils_end" ;; Typo in spec, it's not uvm_component_end
2635 "`uvm_field_utils_end"
2636 "`uvm_object_utils_end"
2637 "`uvm_sequence_utils_end"
2638 "`uvm_sequencer_utils_end"
2639 ;; VMM Begin tokens
2640 "`vmm_data_member_begin"
2641 "`vmm_env_member_begin"
2642 "`vmm_scenario_member_begin"
2643 "`vmm_subenv_member_begin"
2644 "`vmm_xactor_member_begin"
2645 ;; VMM End tokens
2646 "`vmm_data_member_end"
2647 "`vmm_env_member_end"
2648 "`vmm_scenario_member_end"
2649 "`vmm_subenv_member_end"
2650 "`vmm_xactor_member_end"
2651 ))))
2653 (defconst verilog-defun-level-not-generate-re
2654 (eval-when-compile
2655 (verilog-regexp-words
2656 `( "module" "macromodule" "primitive" "class" "program"
2657 "interface" "package" "config"))))
2659 (defconst verilog-defun-level-re
2660 (eval-when-compile
2661 (verilog-regexp-words
2662 (append
2663 `( "module" "macromodule" "primitive" "class" "program"
2664 "interface" "package" "config")
2665 `( "initial" "final" "always" "always_comb" "always_ff"
2666 "always_latch" "endtask" "endfunction" )))))
2668 (defconst verilog-defun-level-generate-only-re
2669 (eval-when-compile
2670 (verilog-regexp-words
2671 `( "initial" "final" "always" "always_comb" "always_ff"
2672 "always_latch" "endtask" "endfunction" ))))
2674 (defconst verilog-cpp-level-re
2675 (eval-when-compile
2676 (verilog-regexp-words
2678 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2679 ))))
2680 (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
2681 (defconst verilog-extended-case-re "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
2682 (defconst verilog-extended-complete-re
2683 (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
2684 "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
2685 "\\|\\(\\(\\<import\\>\\s-+\\)?\\(\"DPI-C\"\\s-+\\)?\\(\\<pure\\>\\s-+\\)?\\(function\\>\\|task\\>\\)\\)"
2686 "\\|" verilog-extended-case-re ))
2687 (defconst verilog-basic-complete-re
2688 (eval-when-compile
2689 (verilog-regexp-words
2691 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
2692 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
2693 "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
2694 ))))
2695 (defconst verilog-complete-reg
2696 (concat
2697 verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)"))
2699 (defconst verilog-end-statement-re
2700 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
2701 verilog-end-block-re "\\)"))
2703 (defconst verilog-endcase-re
2704 (concat verilog-extended-case-re "\\|"
2705 "\\(endcase\\)\\|"
2706 verilog-defun-re
2709 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
2710 "String used to mark beginning of excluded text.")
2711 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
2712 "String used to mark end of excluded text.")
2713 (defconst verilog-preprocessor-re
2714 (eval-when-compile
2715 (verilog-regexp-words
2717 "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else"
2718 ))))
2720 (defconst verilog-keywords
2721 '( "`case" "`default" "`define" "`else" "`endfor" "`endif"
2722 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
2723 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
2724 "`time_scale" "`undef" "`while"
2726 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
2727 "assert" "assign" "assume" "automatic" "before" "begin" "bind"
2728 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
2729 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
2730 "config" "const" "constraint" "context" "continue" "cover"
2731 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
2732 "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
2733 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
2734 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
2735 "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
2736 "endtask" "enum" "event" "expect" "export" "extends" "extern"
2737 "final" "first_match" "for" "force" "foreach" "forever" "fork"
2738 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
2739 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
2740 "include" "initial" "inout" "input" "inside" "instance" "int"
2741 "integer" "interface" "intersect" "join" "join_any" "join_none"
2742 "large" "liblist" "library" "local" "localparam" "logic"
2743 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
2744 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
2745 "notif0" "notif1" "null" "or" "output" "package" "packed"
2746 "parameter" "pmos" "posedge" "primitive" "priority" "program"
2747 "property" "protected" "pull0" "pull1" "pulldown" "pullup"
2748 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2749 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
2750 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
2751 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
2752 "showcancelled" "signed" "small" "solve" "specify" "specparam"
2753 "static" "string" "strong0" "strong1" "struct" "super" "supply0"
2754 "supply1" "table" "tagged" "task" "this" "throughout" "time"
2755 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
2756 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
2757 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
2758 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
2759 "wire" "with" "within" "wor" "xnor" "xor"
2760 ;; 1800-2009
2761 "accept_on" "checker" "endchecker" "eventually" "global" "implies"
2762 "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
2763 "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
2764 "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
2766 "List of Verilog keywords.")
2768 (defconst verilog-comment-start-regexp "//\\|/\\*"
2769 "Dual comment value for `comment-start-regexp'.")
2771 (defvar verilog-mode-syntax-table
2772 (let ((table (make-syntax-table)))
2773 ;; Populate the syntax TABLE.
2774 (modify-syntax-entry ?\\ "\\" table)
2775 (modify-syntax-entry ?+ "." table)
2776 (modify-syntax-entry ?- "." table)
2777 (modify-syntax-entry ?= "." table)
2778 (modify-syntax-entry ?% "." table)
2779 (modify-syntax-entry ?< "." table)
2780 (modify-syntax-entry ?> "." table)
2781 (modify-syntax-entry ?& "." table)
2782 (modify-syntax-entry ?| "." table)
2783 (modify-syntax-entry ?` "w" table)
2784 (modify-syntax-entry ?_ "w" table)
2785 (modify-syntax-entry ?\' "." table)
2787 ;; Set up TABLE to handle block and line style comments.
2788 (if (featurep 'xemacs)
2789 (progn
2790 ;; XEmacs (formerly Lucid) has the best implementation
2791 (modify-syntax-entry ?/ ". 1456" table)
2792 (modify-syntax-entry ?* ". 23" table)
2793 (modify-syntax-entry ?\n "> b" table))
2794 ;; Emacs does things differently, but we can work with it
2795 (modify-syntax-entry ?/ ". 124b" table)
2796 (modify-syntax-entry ?* ". 23" table)
2797 (modify-syntax-entry ?\n "> b" table))
2798 table)
2799 "Syntax table used in Verilog mode buffers.")
2801 (defvar verilog-font-lock-keywords nil
2802 "Default highlighting for Verilog mode.")
2804 (defvar verilog-font-lock-keywords-1 nil
2805 "Subdued level highlighting for Verilog mode.")
2807 (defvar verilog-font-lock-keywords-2 nil
2808 "Medium level highlighting for Verilog mode.
2809 See also `verilog-font-lock-extra-types'.")
2811 (defvar verilog-font-lock-keywords-3 nil
2812 "Gaudy level highlighting for Verilog mode.
2813 See also `verilog-font-lock-extra-types'.")
2815 (defvar verilog-font-lock-translate-off-face
2816 'verilog-font-lock-translate-off-face
2817 "Font to use for translated off regions.")
2818 (defface verilog-font-lock-translate-off-face
2819 '((((class color)
2820 (background light))
2821 (:background "gray90" :italic t ))
2822 (((class color)
2823 (background dark))
2824 (:background "gray10" :italic t ))
2825 (((class grayscale) (background light))
2826 (:foreground "DimGray" :italic t))
2827 (((class grayscale) (background dark))
2828 (:foreground "LightGray" :italic t))
2829 (t (:italis t)))
2830 "Font lock mode face used to background highlight translate-off regions."
2831 :group 'font-lock-highlighting-faces)
2833 (defvar verilog-font-lock-p1800-face
2834 'verilog-font-lock-p1800-face
2835 "Font to use for p1800 keywords.")
2836 (defface verilog-font-lock-p1800-face
2837 '((((class color)
2838 (background light))
2839 (:foreground "DarkOrange3" :bold t ))
2840 (((class color)
2841 (background dark))
2842 (:foreground "orange1" :bold t ))
2843 (t (:italic t)))
2844 "Font lock mode face used to highlight P1800 keywords."
2845 :group 'font-lock-highlighting-faces)
2847 (defvar verilog-font-lock-ams-face
2848 'verilog-font-lock-ams-face
2849 "Font to use for Analog/Mixed Signal keywords.")
2850 (defface verilog-font-lock-ams-face
2851 '((((class color)
2852 (background light))
2853 (:foreground "Purple" :bold t ))
2854 (((class color)
2855 (background dark))
2856 (:foreground "orange1" :bold t ))
2857 (t (:italic t)))
2858 "Font lock mode face used to highlight AMS keywords."
2859 :group 'font-lock-highlighting-faces)
2861 (defvar verilog-font-grouping-keywords-face
2862 'verilog-font-lock-grouping-keywords-face
2863 "Font to use for Verilog Grouping Keywords (such as begin..end).")
2864 (defface verilog-font-lock-grouping-keywords-face
2865 '((((class color)
2866 (background light))
2867 (:foreground "red4" :bold t ))
2868 (((class color)
2869 (background dark))
2870 (:foreground "red4" :bold t ))
2871 (t (:italic t)))
2872 "Font lock mode face used to highlight verilog grouping keywords."
2873 :group 'font-lock-highlighting-faces)
2875 (let* ((verilog-type-font-keywords
2876 (eval-when-compile
2877 (verilog-regexp-opt
2879 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
2880 "event" "genvar" "inout" "input" "integer" "localparam"
2881 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or"
2882 "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
2883 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
2884 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
2885 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
2886 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
2887 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
2888 ) nil )))
2890 (verilog-pragma-keywords
2891 (eval-when-compile
2892 (verilog-regexp-opt
2893 '("surefire" "auto" "synopsys" "rtl_synthesis" "verilint" "leda" "0in"
2894 ) nil )))
2896 (verilog-1800-2005-keywords
2897 (eval-when-compile
2898 (verilog-regexp-opt
2899 '("alias" "assert" "assume" "automatic" "before" "bind"
2900 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
2901 "clocking" "config" "const" "constraint" "context" "continue"
2902 "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
2903 "dist" "do" "edge" "endclass" "endclocking" "endconfig"
2904 "endgroup" "endprogram" "endproperty" "endsequence" "enum"
2905 "expect" "export" "extends" "extern" "first_match" "foreach"
2906 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
2907 "illegal_bins" "import" "incdir" "include" "inside" "instance"
2908 "int" "intersect" "large" "liblist" "library" "local" "longint"
2909 "matches" "medium" "modport" "new" "noshowcancelled" "null"
2910 "packed" "program" "property" "protected" "pull0" "pull1"
2911 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2912 "randcase" "randsequence" "ref" "release" "return" "scalared"
2913 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
2914 "specparam" "static" "string" "strong0" "strong1" "struct"
2915 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
2916 "type" "union" "unsigned" "use" "var" "virtual" "void"
2917 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
2918 ) nil )))
2920 (verilog-1800-2009-keywords
2921 (eval-when-compile
2922 (verilog-regexp-opt
2923 '("accept_on" "checker" "endchecker" "eventually" "global"
2924 "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
2925 "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
2926 "sync_accept_on" "sync_reject_on" "unique0" "until"
2927 "until_with" "untyped" "weak" ) nil )))
2929 (verilog-ams-keywords
2930 (eval-when-compile
2931 (verilog-regexp-opt
2932 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
2933 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
2934 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
2935 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
2936 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
2937 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
2938 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
2939 "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
2940 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
2941 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
2942 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
2944 (verilog-font-keywords
2945 (eval-when-compile
2946 (verilog-regexp-opt
2948 "assign" "case" "casex" "casez" "randcase" "deassign"
2949 "default" "disable" "else" "endcase" "endfunction"
2950 "endgenerate" "endinterface" "endmodule" "endprimitive"
2951 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
2952 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
2953 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
2954 "package" "endpackage" "always" "always_comb" "always_ff"
2955 "always_latch" "posedge" "primitive" "priority" "release"
2956 "repeat" "specify" "table" "task" "unique" "wait" "while"
2957 "class" "program" "endclass" "endprogram"
2958 ) nil )))
2960 (verilog-font-grouping-keywords
2961 (eval-when-compile
2962 (verilog-regexp-opt
2963 '( "begin" "end" ) nil ))))
2965 (setq verilog-font-lock-keywords
2966 (list
2967 ;; Fontify all builtin keywords
2968 (concat "\\<\\(" verilog-font-keywords "\\|"
2969 ;; And user/system tasks and functions
2970 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
2971 "\\)\\>")
2972 ;; Fontify all types
2973 (if verilog-highlight-grouping-keywords
2974 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2975 'verilog-font-lock-ams-face)
2976 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2977 'font-lock-type-face))
2978 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
2979 'font-lock-type-face)
2980 ;; Fontify IEEE-1800-2005 keywords appropriately
2981 (if verilog-highlight-p1800-keywords
2982 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
2983 'verilog-font-lock-p1800-face)
2984 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
2985 'font-lock-type-face))
2986 ;; Fontify IEEE-1800-2009 keywords appropriately
2987 (if verilog-highlight-p1800-keywords
2988 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
2989 'verilog-font-lock-p1800-face)
2990 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
2991 'font-lock-type-face))
2992 ;; Fontify Verilog-AMS keywords
2993 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
2994 'verilog-font-lock-ams-face)))
2996 (setq verilog-font-lock-keywords-1
2997 (append verilog-font-lock-keywords
2998 (list
2999 ;; Fontify module definitions
3000 (list
3001 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
3002 '(1 font-lock-keyword-face)
3003 '(3 font-lock-function-name-face 'prepend))
3004 ;; Fontify function definitions
3005 (list
3006 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
3007 '(1 font-lock-keyword-face)
3008 '(3 font-lock-constant-face prepend))
3009 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
3010 (1 font-lock-keyword-face)
3011 (2 font-lock-constant-face append))
3012 '("\\<function\\>\\s-+\\(\\sw+\\)"
3013 1 'font-lock-constant-face append))))
3015 (setq verilog-font-lock-keywords-2
3016 (append verilog-font-lock-keywords-1
3017 (list
3018 ;; Fontify pragmas
3019 (concat "\\(//\\s-*\\(" verilog-pragma-keywords "\\)\\s-.*\\)")
3020 ;; Fontify escaped names
3021 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
3022 ;; Fontify macro definitions/ uses
3023 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
3024 'font-lock-preprocessor-face
3025 'font-lock-type-face))
3026 ;; Fontify delays/numbers
3027 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
3028 0 font-lock-type-face append)
3029 ;; Fontify instantiation names
3030 '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
3033 (setq verilog-font-lock-keywords-3
3034 (append verilog-font-lock-keywords-2
3035 (when verilog-highlight-translate-off
3036 (list
3037 ;; Fontify things in translate off regions
3038 '(verilog-match-translate-off
3039 (0 'verilog-font-lock-translate-off-face prepend))
3040 )))))
3043 ;; Buffer state preservation
3045 (defmacro verilog-save-buffer-state (&rest body)
3046 "Execute BODY forms, saving state around insignificant change.
3047 Changes in text properties like `face' or `syntax-table' are
3048 considered insignificant. This macro allows text properties to
3049 be changed, even in a read-only buffer.
3051 A change is considered significant if it affects the buffer text
3052 in any way that isn't completely restored again. Any
3053 user-visible changes to the buffer must not be within a
3054 `verilog-save-buffer-state'."
3055 ;; From c-save-buffer-state
3056 `(let* ((modified (buffer-modified-p))
3057 (buffer-undo-list t)
3058 (inhibit-read-only t)
3059 (inhibit-point-motion-hooks t)
3060 (verilog-no-change-functions t)
3061 before-change-functions
3062 after-change-functions
3063 deactivate-mark
3064 buffer-file-name ; Prevent primitives checking
3065 buffer-file-truename) ; for file modification
3066 (unwind-protect
3067 (progn ,@body)
3068 (and (not modified)
3069 (buffer-modified-p)
3070 (set-buffer-modified-p nil)))))
3072 (defmacro verilog-save-no-change-functions (&rest body)
3073 "Execute BODY forms, disabling all change hooks in BODY.
3074 For insignificant changes, see instead `verilog-save-buffer-state'."
3075 `(let* ((inhibit-point-motion-hooks t)
3076 (verilog-no-change-functions t)
3077 before-change-functions
3078 after-change-functions)
3079 (progn ,@body)))
3081 (defvar verilog-save-font-mod-hooked nil
3082 "Local variable when inside a `verilog-save-font-mods' block.")
3083 (make-variable-buffer-local 'verilog-save-font-mod-hooked)
3085 (defmacro verilog-save-font-mods (&rest body)
3086 "Execute BODY forms, disabling text modifications to allow performing BODY.
3087 Includes temporary disabling of `font-lock' to restore the buffer
3088 to full text form for parsing. Additional actions may be specified with
3089 `verilog-before-save-font-hook' and `verilog-after-save-font-hook'."
3090 ;; Before version 20, match-string with font-lock returns a
3091 ;; vector that is not equal to the string. IE if on "input"
3092 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
3093 `(let* ((hooked (unless verilog-save-font-mod-hooked
3094 (verilog-run-hooks 'verilog-before-save-font-hook)
3096 (verilog-save-font-mod-hooked t)
3097 (fontlocked (when (and (boundp 'font-lock-mode) font-lock-mode)
3098 (font-lock-mode 0)
3099 t)))
3100 (unwind-protect
3101 (progn ,@body)
3102 ;; Unwind forms
3103 (when fontlocked (font-lock-mode t))
3104 (when hooked (verilog-run-hooks 'verilog-after-save-font-hook)))))
3107 ;; Comment detection and caching
3109 (defvar verilog-scan-cache-preserving nil
3110 "If set, the specified buffer's comment properties are static.
3111 Buffer changes will be ignored. See `verilog-inside-comment-or-string-p'
3112 and `verilog-scan'.")
3114 (defvar verilog-scan-cache-tick nil
3115 "Modification tick at which `verilog-scan' was last completed.")
3116 (make-variable-buffer-local 'verilog-scan-cache-tick)
3118 (defun verilog-scan-cache-flush ()
3119 "Flush the `verilog-scan' cache."
3120 (setq verilog-scan-cache-tick nil))
3122 (defun verilog-scan-cache-ok-p ()
3123 "Return t iff the scan cache is up to date."
3124 (or (and verilog-scan-cache-preserving
3125 (eq verilog-scan-cache-preserving (current-buffer))
3126 verilog-scan-cache-tick)
3127 (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
3129 (defmacro verilog-save-scan-cache (&rest body)
3130 "Execute the BODY forms, allowing scan cache preservation within BODY.
3131 This requires that insertions must use `verilog-insert'."
3132 ;; If the buffer is out of date, trash it, as we'll not check later the tick
3133 ;; Note this must work properly if there's multiple layers of calls
3134 ;; to verilog-save-scan-cache even with differing ticks.
3135 `(progn
3136 (unless (verilog-scan-cache-ok-p) ;; Must be before let
3137 (setq verilog-scan-cache-tick nil))
3138 (let* ((verilog-scan-cache-preserving (current-buffer)))
3139 (progn ,@body))))
3141 (defun verilog-scan-region (beg end)
3142 "Parse between BEG and END for `verilog-inside-comment-or-string-p'.
3143 This creates v-cmts properties where comments are in force."
3144 ;; Why properties and not overlays? Overlays have much slower non O(1)
3145 ;; lookup times.
3146 ;; This function is warm - called on every verilog-insert
3147 (save-excursion
3148 (save-match-data
3149 (verilog-save-buffer-state
3150 (let (pt)
3151 (goto-char beg)
3152 (while (< (point) end)
3153 (cond ((looking-at "//")
3154 (setq pt (point))
3155 (or (search-forward "\n" end t)
3156 (goto-char end))
3157 ;; "1+": The leading // or /* itself isn't considered as
3158 ;; being "inside" the comment, so that a (search-backward)
3159 ;; that lands at the start of the // won't mis-indicate
3160 ;; it's inside a comment. Also otherwise it would be
3161 ;; hard to find a commented out /*AS*/ vs one that isn't
3162 (put-text-property (1+ pt) (point) 'v-cmts t))
3163 ((looking-at "/\\*")
3164 (setq pt (point))
3165 (or (search-forward "*/" end t)
3166 ;; No error - let later code indicate it so we can
3167 ;; use inside functions on-the-fly
3168 ;;(error "%s: Unmatched /* */, at char %d"
3169 ;; (verilog-point-text) (point))
3170 (goto-char end))
3171 (put-text-property (1+ pt) (point) 'v-cmts t))
3172 ((looking-at "\"")
3173 (setq pt (point))
3174 (or (re-search-forward "[^\\]\"" end t) ;; don't forward-char first, since we look for a non backslash first
3175 ;; No error - let later code indicate it so we can
3176 (goto-char end))
3177 (put-text-property (1+ pt) (point) 'v-cmts t))
3179 (forward-char 1)
3180 (if (re-search-forward "[/\"]" end t)
3181 (backward-char 1)
3182 (goto-char end))))))))))
3184 (defun verilog-scan ()
3185 "Parse the buffer, marking all comments with properties.
3186 Also assumes any text inserted since `verilog-scan-cache-tick'
3187 either is ok to parse as a non-comment, or `verilog-insert' was used."
3188 ;; See also `verilog-scan-debug' and `verilog-scan-and-debug'
3189 (unless (verilog-scan-cache-ok-p)
3190 (save-excursion
3191 (verilog-save-buffer-state
3192 (when verilog-debug
3193 (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
3194 verilog-scan-cache-preserving verilog-scan-cache-tick
3195 (buffer-chars-modified-tick)))
3196 (remove-text-properties (point-min) (point-max) '(v-cmts nil))
3197 (verilog-scan-region (point-min) (point-max))
3198 (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
3199 (when verilog-debug (message "Scanning... done"))))))
3201 (defun verilog-scan-debug ()
3202 "For debugging, show with display face results of `verilog-scan'."
3203 (font-lock-mode 0)
3204 ;;(if dbg (setq dbg (concat dbg (format "verilog-scan-debug\n"))))
3205 (save-excursion
3206 (goto-char (point-min))
3207 (remove-text-properties (point-min) (point-max) '(face nil))
3208 (while (not (eobp))
3209 (cond ((get-text-property (point) 'v-cmts)
3210 (put-text-property (point) (1+ (point)) `face 'underline)
3211 ;;(if dbg (setq dbg (concat dbg (format " v-cmts at %S\n" (point)))))
3212 (forward-char 1))
3214 (goto-char (or (next-property-change (point)) (point-max))))))))
3216 (defun verilog-scan-and-debug ()
3217 "For debugging, run `verilog-scan' and `verilog-scan-debug'."
3218 (let (verilog-scan-cache-preserving
3219 verilog-scan-cache-tick)
3220 (goto-char (point-min))
3221 (verilog-scan)
3222 (verilog-scan-debug)))
3224 (defun verilog-inside-comment-or-string-p (&optional pos)
3225 "Check if optional point POS is inside a comment.
3226 This may require a slow pre-parse of the buffer with `verilog-scan'
3227 to establish comment properties on all text."
3228 ;; This function is very hot
3229 (verilog-scan)
3230 (if pos
3231 (and (>= pos (point-min))
3232 (get-text-property pos 'v-cmts))
3233 (get-text-property (point) 'v-cmts)))
3235 (defun verilog-insert (&rest stuff)
3236 "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
3237 Any insert that includes a comment must have the entire comment
3238 inserted using a single call to `verilog-insert'."
3239 (let ((pt (point)))
3240 (while stuff
3241 (insert (car stuff))
3242 (setq stuff (cdr stuff)))
3243 (verilog-scan-region pt (point))))
3245 ;; More searching
3247 (defun verilog-declaration-end ()
3248 (search-forward ";"))
3250 (defun verilog-point-text (&optional pointnum)
3251 "Return text describing where POINTNUM or current point is (for errors).
3252 Use filename, if current buffer being edited shorten to just buffer name."
3253 (concat (or (and (equal (window-buffer (selected-window)) (current-buffer))
3254 (buffer-name))
3255 buffer-file-name
3256 (buffer-name))
3257 ":" (int-to-string (1+ (count-lines (point-min) (or pointnum (point)))))))
3259 (defun electric-verilog-backward-sexp ()
3260 "Move backward over one balanced expression."
3261 (interactive)
3262 ;; before that see if we are in a comment
3263 (verilog-backward-sexp))
3265 (defun electric-verilog-forward-sexp ()
3266 "Move forward over one balanced expression."
3267 (interactive)
3268 ;; before that see if we are in a comment
3269 (verilog-forward-sexp))
3271 ;;;used by hs-minor-mode
3272 (defun verilog-forward-sexp-function (arg)
3273 (if (< arg 0)
3274 (verilog-backward-sexp)
3275 (verilog-forward-sexp)))
3278 (defun verilog-backward-sexp ()
3279 (let ((reg)
3280 (elsec 1)
3281 (found nil)
3282 (st (point)))
3283 (if (not (looking-at "\\<"))
3284 (forward-word -1))
3285 (cond
3286 ((verilog-skip-backward-comment-or-string))
3287 ((looking-at "\\<else\\>")
3288 (setq reg (concat
3289 verilog-end-block-re
3290 "\\|\\(\\<else\\>\\)"
3291 "\\|\\(\\<if\\>\\)"))
3292 (while (and (not found)
3293 (verilog-re-search-backward reg nil 'move))
3294 (cond
3295 ((match-end 1) ; matched verilog-end-block-re
3296 ; try to leap back to matching outward block by striding across
3297 ; indent level changing tokens then immediately
3298 ; previous line governs indentation.
3299 (verilog-leap-to-head))
3300 ((match-end 2) ; else, we're in deep
3301 (setq elsec (1+ elsec)))
3302 ((match-end 3) ; found it
3303 (setq elsec (1- elsec))
3304 (if (= 0 elsec)
3305 ;; Now previous line describes syntax
3306 (setq found 't))))))
3307 ((looking-at verilog-end-block-re)
3308 (verilog-leap-to-head))
3309 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
3310 (cond
3311 ((match-end 1)
3312 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
3313 ((match-end 2)
3314 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
3315 ((match-end 3)
3316 (verilog-re-search-backward "\\<class\\>" nil 'move))
3317 ((match-end 4)
3318 (verilog-re-search-backward "\\<program\\>" nil 'move))
3319 ((match-end 5)
3320 (verilog-re-search-backward "\\<interface\\>" nil 'move))
3321 ((match-end 6)
3322 (verilog-re-search-backward "\\<package\\>" nil 'move))
3324 (goto-char st)
3325 (backward-sexp 1))))
3327 (goto-char st)
3328 (backward-sexp)))))
3330 (defun verilog-forward-sexp ()
3331 (let ((reg)
3332 (md 2)
3333 (st (point))
3334 (nest 'yes))
3335 (if (not (looking-at "\\<"))
3336 (forward-word -1))
3337 (cond
3338 ((verilog-skip-forward-comment-or-string)
3339 (verilog-forward-syntactic-ws))
3340 ((looking-at verilog-beg-block-re-ordered)
3341 (cond
3342 ((match-end 1);
3343 ;; Search forward for matching end
3344 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
3345 ((match-end 2)
3346 ;; Search forward for matching endcase
3347 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
3348 (setq md 3) ;; ender is third item in regexp
3350 ((match-end 4)
3351 ;; might be "disable fork" or "wait fork"
3352 (let
3353 (here)
3354 (if (or
3355 (looking-at verilog-disable-fork-re)
3356 (and (looking-at "fork")
3357 (progn
3358 (setq here (point)) ;; sometimes a fork is just a fork
3359 (forward-word -1)
3360 (looking-at verilog-disable-fork-re))))
3361 (progn ;; it is a disable fork; ignore it
3362 (goto-char (match-end 0))
3363 (forward-word 1)
3364 (setq reg nil))
3365 (progn ;; it is a nice simple fork
3366 (goto-char here) ;; return from looking for "disable fork"
3367 ;; Search forward for matching join
3368 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))))
3369 ((match-end 6)
3370 ;; Search forward for matching endclass
3371 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
3373 ((match-end 7)
3374 ;; Search forward for matching endtable
3375 (setq reg "\\<endtable\\>" )
3376 (setq nest 'no))
3377 ((match-end 8)
3378 ;; Search forward for matching endspecify
3379 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
3380 ((match-end 9)
3381 ;; Search forward for matching endfunction
3382 (setq reg "\\<endfunction\\>" )
3383 (setq nest 'no))
3384 ((match-end 10)
3385 ;; Search forward for matching endfunction
3386 (setq reg "\\<endfunction\\>" )
3387 (setq nest 'no))
3388 ((match-end 14)
3389 ;; Search forward for matching endtask
3390 (setq reg "\\<endtask\\>" )
3391 (setq nest 'no))
3392 ((match-end 15)
3393 ;; Search forward for matching endtask
3394 (setq reg "\\<endtask\\>" )
3395 (setq nest 'no))
3396 ((match-end 19)
3397 ;; Search forward for matching endgenerate
3398 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
3399 ((match-end 20)
3400 ;; Search forward for matching endgroup
3401 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
3402 ((match-end 21)
3403 ;; Search forward for matching endproperty
3404 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
3405 ((match-end 25)
3406 ;; Search forward for matching endsequence
3407 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
3408 (setq md 3)) ; 3 to get to endsequence in the reg above
3409 ((match-end 27)
3410 ;; Search forward for matching endclocking
3411 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
3412 (if (and reg
3413 (forward-word 1))
3414 (catch 'skip
3415 (if (eq nest 'yes)
3416 (let ((depth 1)
3417 here)
3418 (while (verilog-re-search-forward reg nil 'move)
3419 (cond
3420 ((match-end md) ; a closer in regular expression, so we are climbing out
3421 (setq depth (1- depth))
3422 (if (= 0 depth) ; we are out!
3423 (throw 'skip 1)))
3424 ((match-end 1) ; an opener in the r-e, so we are in deeper now
3425 (setq here (point)) ; remember where we started
3426 (goto-char (match-beginning 1))
3427 (cond
3428 ((if (or
3429 (looking-at verilog-disable-fork-re)
3430 (and (looking-at "fork")
3431 (progn
3432 (forward-word -1)
3433 (looking-at verilog-disable-fork-re))))
3434 (progn ;; it is a disable fork; another false alarm
3435 (goto-char (match-end 0)))
3436 (progn ;; it is a simple fork (or has nothing to do with fork)
3437 (goto-char here)
3438 (setq depth (1+ depth))))))))))
3439 (if (verilog-re-search-forward reg nil 'move)
3440 (throw 'skip 1))))))
3442 ((looking-at (concat
3443 "\\(\\<\\(macro\\)?module\\>\\)\\|"
3444 "\\(\\<primitive\\>\\)\\|"
3445 "\\(\\<class\\>\\)\\|"
3446 "\\(\\<program\\>\\)\\|"
3447 "\\(\\<interface\\>\\)\\|"
3448 "\\(\\<package\\>\\)"))
3449 (cond
3450 ((match-end 1)
3451 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
3452 ((match-end 2)
3453 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
3454 ((match-end 3)
3455 (verilog-re-search-forward "\\<endclass\\>" nil 'move))
3456 ((match-end 4)
3457 (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
3458 ((match-end 5)
3459 (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
3460 ((match-end 6)
3461 (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
3463 (goto-char st)
3464 (if (= (following-char) ?\) )
3465 (forward-char 1)
3466 (forward-sexp 1)))))
3468 (goto-char st)
3469 (if (= (following-char) ?\) )
3470 (forward-char 1)
3471 (forward-sexp 1))))))
3473 (defun verilog-declaration-beg ()
3474 (verilog-re-search-backward verilog-declaration-re (bobp) t))
3478 ;; Mode
3480 (defvar verilog-which-tool 1)
3481 ;;;###autoload
3482 (define-derived-mode verilog-mode prog-mode "Verilog"
3483 "Major mode for editing Verilog code.
3484 \\<verilog-mode-map>
3485 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
3486 AUTOs can improve coding efficiency.
3488 Use \\[verilog-faq] for a pointer to frequently asked questions.
3490 NEWLINE, TAB indents for Verilog code.
3491 Delete converts tabs to spaces as it moves back.
3493 Supports highlighting.
3495 Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
3496 with no args, if that value is non-nil.
3498 Variables controlling indentation/edit style:
3500 variable `verilog-indent-level' (default 3)
3501 Indentation of Verilog statements with respect to containing block.
3502 `verilog-indent-level-module' (default 3)
3503 Absolute indentation of Module level Verilog statements.
3504 Set to 0 to get initial and always statements lined up
3505 on the left side of your screen.
3506 `verilog-indent-level-declaration' (default 3)
3507 Indentation of declarations with respect to containing block.
3508 Set to 0 to get them list right under containing block.
3509 `verilog-indent-level-behavioral' (default 3)
3510 Indentation of first begin in a task or function block
3511 Set to 0 to get such code to lined up underneath the task or
3512 function keyword.
3513 `verilog-indent-level-directive' (default 1)
3514 Indentation of `ifdef/`endif blocks.
3515 `verilog-cexp-indent' (default 1)
3516 Indentation of Verilog statements broken across lines i.e.:
3517 if (a)
3518 begin
3519 `verilog-case-indent' (default 2)
3520 Indentation for case statements.
3521 `verilog-auto-newline' (default nil)
3522 Non-nil means automatically newline after semicolons and the punctuation
3523 mark after an end.
3524 `verilog-auto-indent-on-newline' (default t)
3525 Non-nil means automatically indent line after newline.
3526 `verilog-tab-always-indent' (default t)
3527 Non-nil means TAB in Verilog mode should always reindent the current line,
3528 regardless of where in the line point is when the TAB command is used.
3529 `verilog-indent-begin-after-if' (default t)
3530 Non-nil means to indent begin statements following a preceding
3531 if, else, while, for and repeat statements, if any. Otherwise,
3532 the begin is lined up with the preceding token. If t, you get:
3533 if (a)
3534 begin // amount of indent based on `verilog-cexp-indent'
3535 otherwise you get:
3536 if (a)
3537 begin
3538 `verilog-auto-endcomments' (default t)
3539 Non-nil means a comment /* ... */ is set after the ends which ends
3540 cases, tasks, functions and modules.
3541 The type and name of the object will be set between the braces.
3542 `verilog-minimum-comment-distance' (default 10)
3543 Minimum distance (in lines) between begin and end required before a comment
3544 will be inserted. Setting this variable to zero results in every
3545 end acquiring a comment; the default avoids too many redundant
3546 comments in tight quarters.
3547 `verilog-auto-lineup' (default 'declarations)
3548 List of contexts where auto lineup of code should be done.
3550 Variables controlling other actions:
3552 `verilog-linter' (default surelint)
3553 Unix program to call to run the lint checker. This is the default
3554 command for \\[compile-command] and \\[verilog-auto-save-compile].
3556 See \\[customize] for the complete list of variables.
3558 AUTO expansion functions are, in part:
3560 \\[verilog-auto] Expand AUTO statements.
3561 \\[verilog-delete-auto] Remove the AUTOs.
3562 \\[verilog-inject-auto] Insert AUTOs for the first time.
3564 Some other functions are:
3566 \\[verilog-complete-word] Complete word with appropriate possibilities.
3567 \\[verilog-mark-defun] Mark function.
3568 \\[verilog-beg-of-defun] Move to beginning of current function.
3569 \\[verilog-end-of-defun] Move to end of current function.
3570 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
3572 \\[verilog-comment-region] Put marked area in a comment.
3573 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
3574 \\[verilog-insert-block] Insert begin ... end.
3575 \\[verilog-star-comment] Insert /* ... */.
3577 \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
3578 \\[verilog-sk-begin] Insert a begin .. end block.
3579 \\[verilog-sk-case] Insert a case block, prompting for details.
3580 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
3581 \\[verilog-sk-generate] Insert a generate .. endgenerate block.
3582 \\[verilog-sk-header] Insert a header block at the top of file.
3583 \\[verilog-sk-initial] Insert an initial begin .. end block.
3584 \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
3585 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
3586 \\[verilog-sk-ovm-class] Insert an OVM Class block.
3587 \\[verilog-sk-uvm-class] Insert an UVM Class block.
3588 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
3589 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
3590 \\[verilog-sk-specify] Insert a specify .. endspecify block.
3591 \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
3592 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
3593 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
3594 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
3595 \\[verilog-sk-if] Insert an if (..) begin .. end block.
3596 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
3597 \\[verilog-sk-comment] Insert a comment block.
3598 \\[verilog-sk-assign] Insert an assign .. = ..; statement.
3599 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
3600 \\[verilog-sk-input] Insert an input declaration, prompting for details.
3601 \\[verilog-sk-output] Insert an output declaration, prompting for details.
3602 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
3603 \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
3604 \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
3605 \\[verilog-sk-reg] Insert a register declaration, prompting for details.
3606 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
3608 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
3609 Key bindings specific to `verilog-mode-map' are:
3611 \\{verilog-mode-map}"
3612 :abbrev-table verilog-mode-abbrev-table
3613 (set (make-local-variable 'beginning-of-defun-function)
3614 'verilog-beg-of-defun)
3615 (set (make-local-variable 'end-of-defun-function)
3616 'verilog-end-of-defun)
3617 (set-syntax-table verilog-mode-syntax-table)
3618 (set (make-local-variable 'indent-line-function)
3619 #'verilog-indent-line-relative)
3620 (setq comment-indent-function 'verilog-comment-indent)
3621 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
3622 (set (make-local-variable 'comment-start) "// ")
3623 (set (make-local-variable 'comment-end) "")
3624 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
3625 (set (make-local-variable 'comment-multi-line) nil)
3626 ;; Set up for compilation
3627 (setq verilog-which-tool 1)
3628 (setq verilog-tool 'verilog-linter)
3629 (verilog-set-compile-command)
3630 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables
3631 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
3633 ;; Setting up menus
3634 (when (featurep 'xemacs)
3635 (easy-menu-add verilog-stmt-menu)
3636 (easy-menu-add verilog-menu)
3637 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
3639 ;; Stuff for GNU Emacs
3640 (set (make-local-variable 'font-lock-defaults)
3641 `((verilog-font-lock-keywords
3642 verilog-font-lock-keywords-1
3643 verilog-font-lock-keywords-2
3644 verilog-font-lock-keywords-3)
3645 nil nil nil
3646 ,(if (functionp 'syntax-ppss)
3647 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
3648 ;; font-lock-beginning-of-syntax-function, so
3649 ;; font-lock-beginning-of-syntax-function, can't use
3650 ;; verilog-beg-of-defun.
3652 'verilog-beg-of-defun)))
3653 ;;------------------------------------------------------------
3654 ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
3655 ;; all buffer local:
3656 (unless noninteractive ;; Else can't see the result, and change hooks are slow
3657 (when (featurep 'xemacs)
3658 (make-local-hook 'font-lock-mode-hook)
3659 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
3660 (make-local-hook 'after-change-functions))
3661 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
3662 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
3663 (add-hook 'after-change-functions 'verilog-highlight-region t t))
3665 ;; Tell imenu how to handle Verilog.
3666 (set (make-local-variable 'imenu-generic-expression)
3667 verilog-imenu-generic-expression)
3668 ;; Tell which-func-modes that imenu knows about verilog
3669 (when (and (boundp 'which-func-modes) (listp which-func-modes))
3670 (add-to-list 'which-func-modes 'verilog-mode))
3671 ;; hideshow support
3672 (when (boundp 'hs-special-modes-alist)
3673 (unless (assq 'verilog-mode hs-special-modes-alist)
3674 (setq hs-special-modes-alist
3675 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
3676 verilog-forward-sexp-function)
3677 hs-special-modes-alist))))
3679 ;; Stuff for autos
3680 (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local)
3681 ;; verilog-mode-hook call added by define-derived-mode
3686 ;; Electric functions
3688 (defun electric-verilog-terminate-line (&optional arg)
3689 "Terminate line and indent next line.
3690 With optional ARG, remove existing end of line comments."
3691 (interactive)
3692 ;; before that see if we are in a comment
3693 (let ((state (save-excursion (verilog-syntax-ppss))))
3694 (cond
3695 ((nth 7 state) ; Inside // comment
3696 (if (eolp)
3697 (progn
3698 (delete-horizontal-space)
3699 (newline))
3700 (progn
3701 (newline)
3702 (insert "// ")
3703 (beginning-of-line)))
3704 (verilog-indent-line))
3705 ((nth 4 state) ; Inside any comment (hence /**/)
3706 (newline)
3707 (verilog-more-comment))
3708 ((eolp)
3709 ;; First, check if current line should be indented
3710 (if (save-excursion
3711 (delete-horizontal-space)
3712 (beginning-of-line)
3713 (skip-chars-forward " \t")
3714 (if (looking-at verilog-auto-end-comment-lines-re)
3715 (let ((indent-str (verilog-indent-line)))
3716 ;; Maybe we should set some endcomments
3717 (if verilog-auto-endcomments
3718 (verilog-set-auto-endcomments indent-str arg))
3719 (end-of-line)
3720 (delete-horizontal-space)
3721 (if arg
3723 (newline))
3724 nil)
3725 (progn
3726 (end-of-line)
3727 (delete-horizontal-space)
3728 't)))
3729 ;; see if we should line up assignments
3730 (progn
3731 (if (or (eq 'all verilog-auto-lineup)
3732 (eq 'assignments verilog-auto-lineup))
3733 (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
3734 (newline))
3735 (forward-line 1))
3736 ;; Indent next line
3737 (if verilog-auto-indent-on-newline
3738 (verilog-indent-line)))
3740 (newline)))))
3742 (defun electric-verilog-terminate-and-indent ()
3743 "Insert a newline and indent for the next statement."
3744 (interactive)
3745 (electric-verilog-terminate-line 1))
3747 (defun electric-verilog-semi ()
3748 "Insert `;' character and reindent the line."
3749 (interactive)
3750 (verilog-insert-last-command-event)
3752 (if (or (verilog-in-comment-or-string-p)
3753 (verilog-in-escaped-name-p))
3755 (save-excursion
3756 (beginning-of-line)
3757 (verilog-forward-ws&directives)
3758 (verilog-indent-line))
3759 (if (and verilog-auto-newline
3760 (not (verilog-parenthesis-depth)))
3761 (electric-verilog-terminate-line))))
3763 (defun electric-verilog-semi-with-comment ()
3764 "Insert `;' character, reindent the line and indent for comment."
3765 (interactive)
3766 (insert "\;")
3767 (save-excursion
3768 (beginning-of-line)
3769 (verilog-indent-line))
3770 (indent-for-comment))
3772 (defun electric-verilog-colon ()
3773 "Insert `:' and do all indentations except line indent on this line."
3774 (interactive)
3775 (verilog-insert-last-command-event)
3776 ;; Do nothing if within string.
3777 (if (or
3778 (verilog-within-string)
3779 (not (verilog-in-case-region-p)))
3781 (save-excursion
3782 (let ((p (point))
3783 (lim (progn (verilog-beg-of-statement) (point))))
3784 (goto-char p)
3785 (verilog-backward-case-item lim)
3786 (verilog-indent-line)))
3787 ;; (let ((verilog-tab-always-indent nil))
3788 ;; (verilog-indent-line))
3791 ;;(defun electric-verilog-equal ()
3792 ;; "Insert `=', and do indentation if within block."
3793 ;; (interactive)
3794 ;; (verilog-insert-last-command-event)
3795 ;; Could auto line up expressions, but not yet
3796 ;; (if (eq (car (verilog-calculate-indent)) 'block)
3797 ;; (let ((verilog-tab-always-indent nil))
3798 ;; (verilog-indent-command)))
3799 ;; )
3801 (defun electric-verilog-tick ()
3802 "Insert back-tick, and indent to column 0 if this is a CPP directive."
3803 (interactive)
3804 (verilog-insert-last-command-event)
3805 (save-excursion
3806 (if (verilog-in-directive-p)
3807 (verilog-indent-line))))
3809 (defun electric-verilog-tab ()
3810 "Function called when TAB is pressed in Verilog mode."
3811 (interactive)
3812 ;; If verilog-tab-always-indent, indent the beginning of the line.
3813 (cond
3814 ;; The region is active, indent it.
3815 ((and (region-active-p)
3816 (not (eq (region-beginning) (region-end))))
3817 (indent-region (region-beginning) (region-end) nil))
3818 ((or verilog-tab-always-indent
3819 (save-excursion
3820 (skip-chars-backward " \t")
3821 (bolp)))
3822 (let* ((oldpnt (point))
3823 (boi-point
3824 (save-excursion
3825 (beginning-of-line)
3826 (skip-chars-forward " \t")
3827 (verilog-indent-line)
3828 (back-to-indentation)
3829 (point))))
3830 (if (< (point) boi-point)
3831 (back-to-indentation)
3832 (cond ((not verilog-tab-to-comment))
3833 ((not (eolp))
3834 (end-of-line))
3836 (indent-for-comment)
3837 (when (and (eolp) (= oldpnt (point)))
3838 ; kill existing comment
3839 (beginning-of-line)
3840 (re-search-forward comment-start-skip oldpnt 'move)
3841 (goto-char (match-beginning 0))
3842 (skip-chars-backward " \t")
3843 (kill-region (point) oldpnt)))))))
3844 (t (progn (insert "\t")))))
3849 ;; Interactive functions
3852 (defun verilog-indent-buffer ()
3853 "Indent-region the entire buffer as Verilog code.
3854 To call this from the command line, see \\[verilog-batch-indent]."
3855 (interactive)
3856 (verilog-mode)
3857 (indent-region (point-min) (point-max) nil))
3859 (defun verilog-insert-block ()
3860 "Insert Verilog begin ... end; block in the code with right indentation."
3861 (interactive)
3862 (verilog-indent-line)
3863 (insert "begin")
3864 (electric-verilog-terminate-line)
3865 (save-excursion
3866 (electric-verilog-terminate-line)
3867 (insert "end")
3868 (beginning-of-line)
3869 (verilog-indent-line)))
3871 (defun verilog-star-comment ()
3872 "Insert Verilog star comment at point."
3873 (interactive)
3874 (verilog-indent-line)
3875 (insert "/*")
3876 (save-excursion
3877 (newline)
3878 (insert " */"))
3879 (newline)
3880 (insert " * "))
3882 (defun verilog-insert-1 (fmt max)
3883 "Use format string FMT to insert integers 0 to MAX - 1.
3884 Inserts one integer per line, at the current column. Stops early
3885 if it reaches the end of the buffer."
3886 (let ((col (current-column))
3887 (n 0))
3888 (save-excursion
3889 (while (< n max)
3890 (insert (format fmt n))
3891 (forward-line 1)
3892 ;; Note that this function does not bother to check for lines
3893 ;; shorter than col.
3894 (if (eobp)
3895 (setq n max)
3896 (setq n (1+ n))
3897 (move-to-column col))))))
3899 (defun verilog-insert-indices (max)
3900 "Insert a set of indices into a rectangle.
3901 The upper left corner is defined by point. Indices begin with 0
3902 and extend to the MAX - 1. If no prefix arg is given, the user
3903 is prompted for a value. The indices are surrounded by square
3904 brackets \[]. For example, the following code with the point
3905 located after the first 'a' gives:
3907 a = b a[ 0] = b
3908 a = b a[ 1] = b
3909 a = b a[ 2] = b
3910 a = b a[ 3] = b
3911 a = b ==> insert-indices ==> a[ 4] = b
3912 a = b a[ 5] = b
3913 a = b a[ 6] = b
3914 a = b a[ 7] = b
3915 a = b a[ 8] = b"
3917 (interactive "NMAX: ")
3918 (verilog-insert-1 "[%3d]" max))
3920 (defun verilog-generate-numbers (max)
3921 "Insert a set of generated numbers into a rectangle.
3922 The upper left corner is defined by point. The numbers are padded to three
3923 digits, starting with 000 and extending to (MAX - 1). If no prefix argument
3924 is supplied, then the user is prompted for the MAX number. Consider the
3925 following code fragment:
3927 buf buf buf buf000
3928 buf buf buf buf001
3929 buf buf buf buf002
3930 buf buf buf buf003
3931 buf buf ==> generate-numbers ==> buf buf004
3932 buf buf buf buf005
3933 buf buf buf buf006
3934 buf buf buf buf007
3935 buf buf buf buf008"
3937 (interactive "NMAX: ")
3938 (verilog-insert-1 "%3.3d" max))
3940 (defun verilog-mark-defun ()
3941 "Mark the current Verilog function (or procedure).
3942 This puts the mark at the end, and point at the beginning."
3943 (interactive)
3944 (if (featurep 'xemacs)
3945 (progn
3946 (push-mark (point))
3947 (verilog-end-of-defun)
3948 (push-mark (point))
3949 (verilog-beg-of-defun)
3950 (if (fboundp 'zmacs-activate-region)
3951 (zmacs-activate-region)))
3952 (mark-defun)))
3954 (defun verilog-comment-region (start end)
3955 ; checkdoc-params: (start end)
3956 "Put the region into a Verilog comment.
3957 The comments that are in this area are \"deformed\":
3958 `*)' becomes `!(*' and `}' becomes `!{'.
3959 These deformed comments are returned to normal if you use
3960 \\[verilog-uncomment-region] to undo the commenting.
3962 The commented area starts with `verilog-exclude-str-start', and ends with
3963 `verilog-exclude-str-end'. But if you change these variables,
3964 \\[verilog-uncomment-region] won't recognize the comments."
3965 (interactive "r")
3966 (save-excursion
3967 ;; Insert start and endcomments
3968 (goto-char end)
3969 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
3970 (not (save-excursion (skip-chars-backward " \t") (bolp))))
3971 (forward-line 1)
3972 (beginning-of-line))
3973 (insert verilog-exclude-str-end)
3974 (setq end (point))
3975 (newline)
3976 (goto-char start)
3977 (beginning-of-line)
3978 (insert verilog-exclude-str-start)
3979 (newline)
3980 ;; Replace end-comments within commented area
3981 (goto-char end)
3982 (save-excursion
3983 (while (re-search-backward "\\*/" start t)
3984 (replace-match "*-/" t t)))
3985 (save-excursion
3986 (let ((s+1 (1+ start)))
3987 (while (re-search-backward "/\\*" s+1 t)
3988 (replace-match "/-*" t t))))))
3990 (defun verilog-uncomment-region ()
3991 "Uncomment a commented area; change deformed comments back to normal.
3992 This command does nothing if the pointer is not in a commented
3993 area. See also `verilog-comment-region'."
3994 (interactive)
3995 (save-excursion
3996 (let ((start (point))
3997 (end (point)))
3998 ;; Find the boundaries of the comment
3999 (save-excursion
4000 (setq start (progn (search-backward verilog-exclude-str-start nil t)
4001 (point)))
4002 (setq end (progn (search-forward verilog-exclude-str-end nil t)
4003 (point))))
4004 ;; Check if we're really inside a comment
4005 (if (or (equal start (point)) (<= end (point)))
4006 (message "Not standing within commented area.")
4007 (progn
4008 ;; Remove endcomment
4009 (goto-char end)
4010 (beginning-of-line)
4011 (let ((pos (point)))
4012 (end-of-line)
4013 (delete-region pos (1+ (point))))
4014 ;; Change comments back to normal
4015 (save-excursion
4016 (while (re-search-backward "\\*-/" start t)
4017 (replace-match "*/" t t)))
4018 (save-excursion
4019 (while (re-search-backward "/-\\*" start t)
4020 (replace-match "/*" t t)))
4021 ;; Remove start comment
4022 (goto-char start)
4023 (beginning-of-line)
4024 (let ((pos (point)))
4025 (end-of-line)
4026 (delete-region pos (1+ (point)))))))))
4028 (defun verilog-beg-of-defun ()
4029 "Move backward to the beginning of the current function or procedure."
4030 (interactive)
4031 (verilog-re-search-backward verilog-defun-re nil 'move))
4033 (defun verilog-beg-of-defun-quick ()
4034 "Move backward to the beginning of the current function or procedure.
4035 Uses `verilog-scan' cache."
4036 (interactive)
4037 (verilog-re-search-backward-quick verilog-defun-re nil 'move))
4039 (defun verilog-end-of-defun ()
4040 "Move forward to the end of the current function or procedure."
4041 (interactive)
4042 (verilog-re-search-forward verilog-end-defun-re nil 'move))
4044 (defun verilog-get-beg-of-defun (&optional warn)
4045 (save-excursion
4046 (cond ((verilog-re-search-forward-quick verilog-defun-re nil t)
4047 (point))
4049 (error "%s: Can't find module beginning" (verilog-point-text))
4050 (point-max)))))
4051 (defun verilog-get-end-of-defun (&optional warn)
4052 (save-excursion
4053 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
4054 (point))
4056 (error "%s: Can't find endmodule" (verilog-point-text))
4057 (point-max)))))
4059 (defun verilog-label-be (&optional arg)
4060 "Label matching begin ... end, fork ... join and case ... endcase statements.
4061 With ARG, first kill any existing labels."
4062 (interactive)
4063 (let ((cnt 0)
4064 (oldpos (point))
4065 (b (progn
4066 (verilog-beg-of-defun)
4067 (point-marker)))
4068 (e (progn
4069 (verilog-end-of-defun)
4070 (point-marker))))
4071 (goto-char (marker-position b))
4072 (if (> (- e b) 200)
4073 (message "Relabeling module..."))
4074 (while (and
4075 (> (marker-position e) (point))
4076 (verilog-re-search-forward
4077 (concat
4078 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>"
4079 "\\|\\(`endif\\)\\|\\(`else\\)")
4080 nil 'move))
4081 (goto-char (match-beginning 0))
4082 (let ((indent-str (verilog-indent-line)))
4083 (verilog-set-auto-endcomments indent-str 't)
4084 (end-of-line)
4085 (delete-horizontal-space))
4086 (setq cnt (1+ cnt))
4087 (if (= 9 (% cnt 10))
4088 (message "%d..." cnt)))
4089 (goto-char oldpos)
4090 (if (or
4091 (> (- e b) 200)
4092 (> cnt 20))
4093 (message "%d lines auto commented" cnt))))
4095 (defun verilog-beg-of-statement ()
4096 "Move backward to beginning of statement."
4097 (interactive)
4098 ;; Move back token by token until we see the end
4099 ;; of some earlier line.
4100 (let (h)
4101 (while
4102 ;; If the current point does not begin a new
4103 ;; statement, as in the character ahead of us is a ';', or SOF
4104 ;; or the string after us unambiguously starts a statement,
4105 ;; or the token before us unambiguously ends a statement,
4106 ;; then move back a token and test again.
4107 (not (or
4108 ;; stop if beginning of buffer
4109 (bolp)
4110 ;; stop if we find a ;
4111 (= (preceding-char) ?\;)
4112 ;; stop if we see a named coverpoint
4113 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
4114 ;; keep going if we are in the middle of a word
4115 (not (or (looking-at "\\<") (forward-word -1)))
4116 ;; stop if we see an assertion (perhaps labeled)
4117 (and
4118 (looking-at "\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
4119 (progn
4120 (setq h (point))
4121 (save-excursion
4122 (verilog-backward-token)
4123 (if (looking-at verilog-label-re)
4124 (setq h (point))))
4125 (goto-char h)))
4126 ;; stop if we see an extended complete reg, perhaps a complete one
4127 (and
4128 (looking-at verilog-complete-reg)
4129 (let* ((p (point)))
4130 (while (and (looking-at verilog-extended-complete-re)
4131 (progn (setq p (point))
4132 (verilog-backward-token)
4133 (/= p (point)))))
4134 (goto-char p)))
4135 ;; stop if we see a complete reg (previous found extended ones)
4136 (looking-at verilog-basic-complete-re)
4137 ;; stop if previous token is an ender
4138 (save-excursion
4139 (verilog-backward-token)
4141 (looking-at verilog-end-block-re)
4142 (looking-at verilog-preprocessor-re))))) ;; end of test
4143 (verilog-backward-syntactic-ws)
4144 (verilog-backward-token))
4145 ;; Now point is where the previous line ended.
4146 (verilog-forward-syntactic-ws)))
4148 (defun verilog-beg-of-statement-1 ()
4149 "Move backward to beginning of statement."
4150 (interactive)
4151 (if (verilog-in-comment-p)
4152 (verilog-backward-syntactic-ws))
4153 (let ((pt (point)))
4154 (catch 'done
4155 (while (not (looking-at verilog-complete-reg))
4156 (setq pt (point))
4157 (verilog-backward-syntactic-ws)
4158 (if (or (bolp)
4159 (= (preceding-char) ?\;)
4160 (save-excursion
4161 (verilog-backward-token)
4162 (looking-at verilog-ends-re)))
4163 (progn
4164 (goto-char pt)
4165 (throw 'done t))
4166 (verilog-backward-token))))
4167 (verilog-forward-syntactic-ws)))
4169 ; (while (and
4170 ; (not (looking-at verilog-complete-reg))
4171 ; (not (bolp))
4172 ; (not (= (preceding-char) ?\;)))
4173 ; (verilog-backward-token)
4174 ; (verilog-backward-syntactic-ws)
4175 ; (setq pt (point)))
4176 ; (goto-char pt)
4177 ; ;(verilog-forward-syntactic-ws)
4179 (defun verilog-end-of-statement ()
4180 "Move forward to end of current statement."
4181 (interactive)
4182 (let ((nest 0) pos)
4183 (cond
4184 ((verilog-in-directive-p)
4185 (forward-line 1)
4186 (backward-char 1))
4188 ((looking-at verilog-beg-block-re)
4189 (verilog-forward-sexp))
4191 ((equal (char-after) ?\})
4192 (forward-char))
4194 ;; Skip to end of statement
4195 ((condition-case nil
4196 (setq pos
4197 (catch 'found
4198 (while t
4199 (forward-sexp 1)
4200 (verilog-skip-forward-comment-or-string)
4201 (if (eolp)
4202 (forward-line 1))
4203 (cond ((looking-at "[ \t]*;")
4204 (skip-chars-forward "^;")
4205 (forward-char 1)
4206 (throw 'found (point)))
4207 ((save-excursion
4208 (forward-sexp -1)
4209 (looking-at verilog-beg-block-re))
4210 (goto-char (match-beginning 0))
4211 (throw 'found nil))
4212 ((looking-at "[ \t]*)")
4213 (throw 'found (point)))
4214 ((eobp)
4215 (throw 'found (point)))
4219 (error nil))
4220 (if (not pos)
4221 ;; Skip a whole block
4222 (catch 'found
4223 (while t
4224 (verilog-re-search-forward verilog-end-statement-re nil 'move)
4225 (setq nest (if (match-end 1)
4226 (1+ nest)
4227 (1- nest)))
4228 (cond ((eobp)
4229 (throw 'found (point)))
4230 ((= 0 nest)
4231 (throw 'found (verilog-end-of-statement))))))
4232 pos)))))
4234 (defun verilog-in-case-region-p ()
4235 "Return true if in a case region.
4236 More specifically, point @ in the line foo : @ begin"
4237 (interactive)
4238 (save-excursion
4239 (if (and
4240 (progn (verilog-forward-syntactic-ws)
4241 (looking-at "\\<begin\\>"))
4242 (progn (verilog-backward-syntactic-ws)
4243 (= (preceding-char) ?\:)))
4244 (catch 'found
4245 (let ((nest 1))
4246 (while t
4247 (verilog-re-search-backward
4248 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
4249 "\\(\\<endcase\\>\\)\\>")
4250 nil 'move)
4251 (cond
4252 ((match-end 3)
4253 (setq nest (1+ nest)))
4254 ((match-end 2)
4255 (if (= nest 1)
4256 (throw 'found 1))
4257 (setq nest (1- nest)))
4259 (throw 'found (= nest 0)))))))
4260 nil)))
4262 (defun verilog-backward-up-list (arg)
4263 "Call `backward-up-list' ARG, ignoring comments."
4264 (let ((parse-sexp-ignore-comments t))
4265 (backward-up-list arg)))
4267 (defun verilog-forward-sexp-cmt (arg)
4268 "Call `forward-sexp' ARG, inside comments."
4269 (let ((parse-sexp-ignore-comments nil))
4270 (forward-sexp arg)))
4272 (defun verilog-forward-sexp-ign-cmt (arg)
4273 "Call `forward-sexp' ARG, ignoring comments."
4274 (let ((parse-sexp-ignore-comments t))
4275 (forward-sexp arg)))
4277 (defun verilog-in-generate-region-p ()
4278 "Return true if in a generate region.
4279 More specifically, after a generate and before an endgenerate."
4280 (interactive)
4281 (let ((nest 1))
4282 (save-excursion
4283 (catch 'done
4284 (while (and
4285 (/= nest 0)
4286 (verilog-re-search-backward
4287 "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
4288 (cond
4289 ((match-end 1) ; module - we have crawled out
4290 (throw 'done 1))
4291 ((match-end 2) ; generate
4292 (setq nest (1- nest)))
4293 ((match-end 3) ; endgenerate
4294 (setq nest (1+ nest))))))))
4295 (= nest 0) )) ; return nest
4297 (defun verilog-in-fork-region-p ()
4298 "Return true if between a fork and join."
4299 (interactive)
4300 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
4301 (nest 1))
4302 (save-excursion
4303 (while (and
4304 (/= nest 0)
4305 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
4306 (cond
4307 ((match-end 1) ; fork
4308 (setq nest (1- nest)))
4309 ((match-end 2) ; join
4310 (setq nest (1+ nest)))))))
4311 (= nest 0) )) ; return nest
4313 (defun verilog-backward-case-item (lim)
4314 "Skip backward to nearest enclosing case item.
4315 Limit search to point LIM."
4316 (interactive)
4317 (let ((str 'nil)
4318 (lim1
4319 (progn
4320 (save-excursion
4321 (verilog-re-search-backward verilog-endcomment-reason-re
4322 lim 'move)
4323 (point)))))
4324 ;; Try to find the real :
4325 (if (save-excursion (search-backward ":" lim1 t))
4326 (let ((colon 0)
4327 b e )
4328 (while
4329 (and
4330 (< colon 1)
4331 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
4332 lim1 'move))
4333 (cond
4334 ((match-end 1) ;; [
4335 (setq colon (1+ colon))
4336 (if (>= colon 0)
4337 (error "%s: unbalanced [" (verilog-point-text))))
4338 ((match-end 2) ;; ]
4339 (setq colon (1- colon)))
4341 ((match-end 3) ;; :
4342 (setq colon (1+ colon)))))
4343 ;; Skip back to beginning of case item
4344 (skip-chars-backward "\t ")
4345 (verilog-skip-backward-comment-or-string)
4346 (setq e (point))
4347 (setq b
4348 (progn
4350 (verilog-re-search-backward
4351 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
4352 (progn
4353 (cond
4354 ((match-end 1)
4355 (goto-char (match-end 1))
4356 (verilog-forward-ws&directives)
4357 (if (looking-at "(")
4358 (progn
4359 (forward-sexp)
4360 (verilog-forward-ws&directives)))
4361 (point))
4363 (goto-char (match-end 0))
4364 (verilog-forward-ws&directives)
4365 (point))))
4366 (error "Malformed case item"))))
4367 (setq str (buffer-substring b e))
4369 (setq e
4370 (string-match
4371 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4372 (setq str (concat (substring str 0 e) "...")))
4373 str)
4374 'nil)))
4378 ;; Other functions
4381 (defun verilog-kill-existing-comment ()
4382 "Kill auto comment on this line."
4383 (save-excursion
4384 (let* (
4385 (e (progn
4386 (end-of-line)
4387 (point)))
4388 (b (progn
4389 (beginning-of-line)
4390 (search-forward "//" e t))))
4391 (if b
4392 (delete-region (- b 2) e)))))
4394 (defconst verilog-directive-nest-re
4395 (concat "\\(`else\\>\\)\\|"
4396 "\\(`endif\\>\\)\\|"
4397 "\\(`if\\>\\)\\|"
4398 "\\(`ifdef\\>\\)\\|"
4399 "\\(`ifndef\\>\\)\\|"
4400 "\\(`elsif\\>\\)"))
4401 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
4402 "Add ending comment with given INDENT-STR.
4403 With KILL-EXISTING-COMMENT, remove what was there before.
4404 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
4405 Insert `// case expr ' if this line ends a case block.
4406 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
4407 Insert `// NAME ' if this line ends a function, task, module,
4408 primitive or interface named NAME."
4409 (save-excursion
4410 (cond
4411 (; Comment close preprocessor directives
4412 (and
4413 (looking-at "\\(`endif\\)\\|\\(`else\\)")
4414 (or kill-existing-comment
4415 (not (save-excursion
4416 (end-of-line)
4417 (search-backward "//" (point-at-bol) t)))))
4418 (let ((nest 1) b e
4420 (else (if (match-end 2) "!" " ")))
4421 (end-of-line)
4422 (if kill-existing-comment
4423 (verilog-kill-existing-comment))
4424 (delete-horizontal-space)
4425 (save-excursion
4426 (backward-sexp 1)
4427 (while (and (/= nest 0)
4428 (verilog-re-search-backward verilog-directive-nest-re nil 'move))
4429 (cond
4430 ((match-end 1) ; `else
4431 (if (= nest 1)
4432 (setq else "!")))
4433 ((match-end 2) ; `endif
4434 (setq nest (1+ nest)))
4435 ((match-end 3) ; `if
4436 (setq nest (1- nest)))
4437 ((match-end 4) ; `ifdef
4438 (setq nest (1- nest)))
4439 ((match-end 5) ; `ifndef
4440 (setq nest (1- nest)))
4441 ((match-end 6) ; `elsif
4442 (if (= nest 1)
4443 (progn
4444 (setq else "!")
4445 (setq nest 0))))))
4446 (if (match-end 0)
4447 (setq
4448 m (buffer-substring
4449 (match-beginning 0)
4450 (match-end 0))
4451 b (progn
4452 (skip-chars-forward "^ \t")
4453 (verilog-forward-syntactic-ws)
4454 (point))
4455 e (progn
4456 (skip-chars-forward "a-zA-Z0-9_")
4457 (point)))))
4458 (if b
4459 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
4460 (insert (concat " // " else m " " (buffer-substring b e))))
4461 (progn
4462 (insert " // unmatched `else, `elsif or `endif")
4463 (ding 't)))))
4465 (; Comment close case/class/function/task/module and named block
4466 (and (looking-at "\\<end")
4467 (or kill-existing-comment
4468 (not (save-excursion
4469 (end-of-line)
4470 (search-backward "//" (point-at-bol) t)))))
4471 (let ((type (car indent-str)))
4472 (unless (eq type 'declaration)
4473 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends
4474 (if (looking-at verilog-end-block-ordered-re)
4475 (cond
4476 (;- This is a case block; search back for the start of this case
4477 (match-end 1) ;; of verilog-end-block-ordered-re
4479 (let ((err 't)
4480 (str "UNMATCHED!!"))
4481 (save-excursion
4482 (verilog-leap-to-head)
4483 (cond
4484 ((looking-at "\\<randcase\\>")
4485 (setq str "randcase")
4486 (setq err nil))
4487 ((looking-at "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
4488 (goto-char (match-end 0))
4489 (setq str (concat (match-string 0) " " (verilog-get-expr)))
4490 (setq err nil))
4492 (end-of-line)
4493 (if kill-existing-comment
4494 (verilog-kill-existing-comment))
4495 (delete-horizontal-space)
4496 (insert (concat " // " str ))
4497 (if err (ding 't))))
4499 (;- This is a begin..end block
4500 (match-end 2) ;; of verilog-end-block-ordered-re
4501 (let ((str " // UNMATCHED !!")
4502 (err 't)
4503 (here (point))
4504 there
4505 cntx)
4506 (save-excursion
4507 (verilog-leap-to-head)
4508 (setq there (point))
4509 (if (not (match-end 0))
4510 (progn
4511 (goto-char here)
4512 (end-of-line)
4513 (if kill-existing-comment
4514 (verilog-kill-existing-comment))
4515 (delete-horizontal-space)
4516 (insert str)
4517 (ding 't))
4518 (let ((lim
4519 (save-excursion (verilog-beg-of-defun) (point)))
4520 (here (point)))
4521 (cond
4522 (;-- handle named block differently
4523 (looking-at verilog-named-block-re)
4524 (search-forward ":")
4525 (setq there (point))
4526 (setq str (verilog-get-expr))
4527 (setq err nil)
4528 (setq str (concat " // block: " str )))
4530 ((verilog-in-case-region-p) ;-- handle case item differently
4531 (goto-char here)
4532 (setq str (verilog-backward-case-item lim))
4533 (setq there (point))
4534 (setq err nil)
4535 (setq str (concat " // case: " str )))
4537 (;- try to find "reason" for this begin
4538 (cond
4540 (eq here (progn
4541 ;; (verilog-backward-token)
4542 (verilog-beg-of-statement)
4543 (point)))
4544 (setq err nil)
4545 (setq str ""))
4546 ((looking-at verilog-endcomment-reason-re)
4547 (setq there (match-end 0))
4548 (setq cntx (concat (match-string 0) " "))
4549 (cond
4550 (;- begin
4551 (match-end 1)
4552 (setq err nil)
4553 (save-excursion
4554 (if (and (verilog-continued-line)
4555 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
4556 (progn
4557 (goto-char (match-end 0))
4558 (setq there (point))
4559 (setq str
4560 (concat " // " (match-string 0) " " (verilog-get-expr))))
4561 (setq str ""))))
4563 (;- else
4564 (match-end 2)
4565 (let ((nest 0)
4566 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4567 (catch 'skip
4568 (while (verilog-re-search-backward reg nil 'move)
4569 (cond
4570 ((match-end 1) ; begin
4571 (setq nest (1- nest)))
4572 ((match-end 2) ; end
4573 (setq nest (1+ nest)))
4574 ((match-end 3)
4575 (if (= 0 nest)
4576 (progn
4577 (goto-char (match-end 0))
4578 (setq there (point))
4579 (setq err nil)
4580 (setq str (verilog-get-expr))
4581 (setq str (concat " // else: !if" str ))
4582 (throw 'skip 1))))
4583 ((match-end 4)
4584 (if (= 0 nest)
4585 (progn
4586 (goto-char (match-end 0))
4587 (setq there (point))
4588 (setq err nil)
4589 (setq str (verilog-get-expr))
4590 (setq str (concat " // else: !assert " str ))
4591 (throw 'skip 1)))))))))
4592 (;- end else
4593 (match-end 3)
4594 (goto-char there)
4595 (let ((nest 0)
4596 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4597 (catch 'skip
4598 (while (verilog-re-search-backward reg nil 'move)
4599 (cond
4600 ((match-end 1) ; begin
4601 (setq nest (1- nest)))
4602 ((match-end 2) ; end
4603 (setq nest (1+ nest)))
4604 ((match-end 3)
4605 (if (= 0 nest)
4606 (progn
4607 (goto-char (match-end 0))
4608 (setq there (point))
4609 (setq err nil)
4610 (setq str (verilog-get-expr))
4611 (setq str (concat " // else: !if" str ))
4612 (throw 'skip 1))))
4613 ((match-end 4)
4614 (if (= 0 nest)
4615 (progn
4616 (goto-char (match-end 0))
4617 (setq there (point))
4618 (setq err nil)
4619 (setq str (verilog-get-expr))
4620 (setq str (concat " // else: !assert " str ))
4621 (throw 'skip 1)))))))))
4623 (; always_comb, always_ff, always_latch
4624 (or (match-end 4) (match-end 5) (match-end 6))
4625 (goto-char (match-end 0))
4626 (setq there (point))
4627 (setq err nil)
4628 (setq str (concat " // " cntx )))
4630 (;- task/function/initial et cetera
4632 (match-end 0)
4633 (goto-char (match-end 0))
4634 (setq there (point))
4635 (setq err nil)
4636 (setq str (concat " // " cntx (verilog-get-expr))))
4638 (;-- otherwise...
4639 (setq str " // auto-endcomment confused "))))
4641 ((and
4642 (verilog-in-case-region-p) ;-- handle case item differently
4643 (progn
4644 (setq there (point))
4645 (goto-char here)
4646 (setq str (verilog-backward-case-item lim))))
4647 (setq err nil)
4648 (setq str (concat " // case: " str )))
4650 ((verilog-in-fork-region-p)
4651 (setq err nil)
4652 (setq str " // fork branch" ))
4654 ((looking-at "\\<end\\>")
4655 ;; HERE
4656 (forward-word 1)
4657 (verilog-forward-syntactic-ws)
4658 (setq err nil)
4659 (setq str (verilog-get-expr))
4660 (setq str (concat " // " cntx str )))
4662 ))))
4663 (goto-char here)
4664 (end-of-line)
4665 (if kill-existing-comment
4666 (verilog-kill-existing-comment))
4667 (delete-horizontal-space)
4668 (if (or err
4669 (> (count-lines here there) verilog-minimum-comment-distance))
4670 (insert str))
4671 (if err (ding 't))
4672 ))))
4673 (;- this is endclass, which can be nested
4674 (match-end 11) ;; of verilog-end-block-ordered-re
4675 ;;(goto-char there)
4676 (let ((nest 0)
4677 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
4678 string)
4679 (save-excursion
4680 (catch 'skip
4681 (while (verilog-re-search-backward reg nil 'move)
4682 (cond
4683 ((match-end 3) ; endclass
4684 (ding 't)
4685 (setq string "unmatched endclass")
4686 (throw 'skip 1))
4688 ((match-end 2) ; endclass
4689 (setq nest (1+ nest)))
4691 ((match-end 1) ; class
4692 (setq nest (1- nest))
4693 (if (< nest 0)
4694 (progn
4695 (goto-char (match-end 0))
4696 (let (b e)
4697 (setq b (progn
4698 (skip-chars-forward "^ \t")
4699 (verilog-forward-ws&directives)
4700 (point))
4701 e (progn
4702 (skip-chars-forward "a-zA-Z0-9_")
4703 (point)))
4704 (setq string (buffer-substring b e)))
4705 (throw 'skip 1))))
4706 ))))
4707 (end-of-line)
4708 (insert (concat " // " string ))))
4710 (;- this is end{function,generate,task,module,primitive,table,generate}
4711 ;- which can not be nested.
4713 (let (string reg (name-re nil))
4714 (end-of-line)
4715 (if kill-existing-comment
4716 (save-match-data
4717 (verilog-kill-existing-comment)))
4718 (delete-horizontal-space)
4719 (backward-sexp)
4720 (cond
4721 ((match-end 5) ;; of verilog-end-block-ordered-re
4722 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4723 (setq name-re "\\w+\\s-*("))
4724 ((match-end 6) ;; of verilog-end-block-ordered-re
4725 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4726 (setq name-re "\\w+\\s-*("))
4727 ((match-end 7) ;; of verilog-end-block-ordered-re
4728 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
4729 ((match-end 8) ;; of verilog-end-block-ordered-re
4730 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4731 ((match-end 9) ;; of verilog-end-block-ordered-re
4732 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
4733 ((match-end 10) ;; of verilog-end-block-ordered-re
4734 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4735 ((match-end 11) ;; of verilog-end-block-ordered-re
4736 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4737 ((match-end 12) ;; of verilog-end-block-ordered-re
4738 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4739 ((match-end 13) ;; of verilog-end-block-ordered-re
4740 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4741 ((match-end 14) ;; of verilog-end-block-ordered-re
4742 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
4743 ((match-end 15) ;; of verilog-end-block-ordered-re
4744 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
4746 (t (error "Problem in verilog-set-auto-endcomments")))
4747 (let (b e)
4748 (save-excursion
4749 (verilog-re-search-backward reg nil 'move)
4750 (cond
4751 ((match-end 1)
4752 (setq b (progn
4753 (skip-chars-forward "^ \t")
4754 (verilog-forward-ws&directives)
4755 (if (looking-at "static\\|automatic")
4756 (progn
4757 (goto-char (match-end 0))
4758 (verilog-forward-ws&directives)))
4759 (if (and name-re (verilog-re-search-forward name-re nil 'move))
4760 (progn
4761 (goto-char (match-beginning 0))
4762 (verilog-forward-ws&directives)))
4763 (point))
4764 e (progn
4765 (skip-chars-forward "a-zA-Z0-9_")
4766 (point)))
4767 (setq string (buffer-substring b e)))
4769 (ding 't)
4770 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
4771 (end-of-line)
4772 (insert (concat " // " string )))
4773 ))))))))))
4775 (defun verilog-get-expr()
4776 "Grab expression at point, e.g, case ( a | b & (c ^d))."
4777 (let* ((b (progn
4778 (verilog-forward-syntactic-ws)
4779 (skip-chars-forward " \t")
4780 (point)))
4781 (e (let ((par 1))
4782 (cond
4783 ((looking-at "@")
4784 (forward-char 1)
4785 (verilog-forward-syntactic-ws)
4786 (if (looking-at "(")
4787 (progn
4788 (forward-char 1)
4789 (while (and (/= par 0)
4790 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4791 (cond
4792 ((match-end 1)
4793 (setq par (1+ par)))
4794 ((match-end 2)
4795 (setq par (1- par)))))))
4796 (point))
4797 ((looking-at "(")
4798 (forward-char 1)
4799 (while (and (/= par 0)
4800 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
4801 (cond
4802 ((match-end 1)
4803 (setq par (1+ par)))
4804 ((match-end 2)
4805 (setq par (1- par)))))
4806 (point))
4807 ((looking-at "\\[")
4808 (forward-char 1)
4809 (while (and (/= par 0)
4810 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
4811 (cond
4812 ((match-end 1)
4813 (setq par (1+ par)))
4814 ((match-end 2)
4815 (setq par (1- par)))))
4816 (verilog-forward-syntactic-ws)
4817 (skip-chars-forward "^ \t\n\f")
4818 (point))
4819 ((looking-at "/[/\\*]")
4822 (skip-chars-forward "^: \t\n\f")
4823 (point)))))
4824 (str (buffer-substring b e)))
4825 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4826 (setq str (concat (substring str 0 e) "...")))
4827 str))
4829 (defun verilog-expand-vector ()
4830 "Take a signal vector on the current line and expand it to multiple lines.
4831 Useful for creating tri's and other expanded fields."
4832 (interactive)
4833 (verilog-expand-vector-internal "[" "]"))
4835 (defun verilog-expand-vector-internal (bra ket)
4836 "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
4837 (save-excursion
4838 (forward-line 0)
4839 (let ((signal-string (buffer-substring (point)
4840 (progn
4841 (end-of-line) (point)))))
4842 (if (string-match
4843 (concat "\\(.*\\)"
4844 (regexp-quote bra)
4845 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
4846 (regexp-quote ket)
4847 "\\(.*\\)$") signal-string)
4848 (let* ((sig-head (match-string 1 signal-string))
4849 (vec-start (string-to-number (match-string 2 signal-string)))
4850 (vec-end (if (= (match-beginning 3) (match-end 3))
4851 vec-start
4852 (string-to-number
4853 (substring signal-string (1+ (match-beginning 3))
4854 (match-end 3)))))
4855 (vec-range
4856 (if (= (match-beginning 4) (match-end 4))
4858 (string-to-number
4859 (substring signal-string (+ 2 (match-beginning 4))
4860 (match-end 4)))))
4861 (sig-tail (match-string 5 signal-string))
4862 vec)
4863 ;; Decode vectors
4864 (setq vec nil)
4865 (if (< vec-range 0)
4866 (let ((tmp vec-start))
4867 (setq vec-start vec-end
4868 vec-end tmp
4869 vec-range (- vec-range))))
4870 (if (< vec-end vec-start)
4871 (while (<= vec-end vec-start)
4872 (setq vec (append vec (list vec-start)))
4873 (setq vec-start (- vec-start vec-range)))
4874 (while (<= vec-start vec-end)
4875 (setq vec (append vec (list vec-start)))
4876 (setq vec-start (+ vec-start vec-range))))
4878 ;; Delete current line
4879 (delete-region (point) (progn (forward-line 0) (point)))
4881 ;; Expand vector
4882 (while vec
4883 (insert (concat sig-head bra
4884 (int-to-string (car vec)) ket sig-tail "\n"))
4885 (setq vec (cdr vec)))
4886 (delete-char -1)
4888 )))))
4890 (defun verilog-strip-comments ()
4891 "Strip all comments from the Verilog code."
4892 (interactive)
4893 (goto-char (point-min))
4894 (while (re-search-forward "//" nil t)
4895 (if (verilog-within-string)
4896 (re-search-forward "\"" nil t)
4897 (if (verilog-in-star-comment-p)
4898 (re-search-forward "\*/" nil t)
4899 (let ((bpt (- (point) 2)))
4900 (end-of-line)
4901 (delete-region bpt (point))))))
4903 (goto-char (point-min))
4904 (while (re-search-forward "/\\*" nil t)
4905 (if (verilog-within-string)
4906 (re-search-forward "\"" nil t)
4907 (let ((bpt (- (point) 2)))
4908 (re-search-forward "\\*/")
4909 (delete-region bpt (point))))))
4911 (defun verilog-one-line ()
4912 "Convert structural Verilog instances to occupy one line."
4913 (interactive)
4914 (goto-char (point-min))
4915 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
4916 (replace-match "\\1 " nil nil)))
4918 (defun verilog-linter-name ()
4919 "Return name of linter, either surelint or verilint."
4920 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4921 compile-command))
4922 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
4923 verilog-linter)))
4924 (cond ((equal compile-word1 "surelint") `surelint)
4925 ((equal compile-word1 "verilint") `verilint)
4926 ((equal lint-word1 "surelint") `surelint)
4927 ((equal lint-word1 "verilint") `verilint)
4928 (t `surelint)))) ;; back compatibility
4930 (defun verilog-lint-off ()
4931 "Convert a Verilog linter warning line into a disable statement.
4932 For example:
4933 pci_bfm_null.v, line 46: Unused input: pci_rst_
4934 becomes a comment for the appropriate tool.
4936 The first word of the `compile-command' or `verilog-linter'
4937 variables is used to determine which product is being used.
4939 See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
4940 (interactive)
4941 (let ((linter (verilog-linter-name)))
4942 (cond ((equal linter `surelint)
4943 (verilog-surelint-off))
4944 ((equal linter `verilint)
4945 (verilog-verilint-off))
4946 (t (error "Linter name not set")))))
4948 (defvar compilation-last-buffer)
4949 (defvar next-error-last-buffer)
4951 (defun verilog-surelint-off ()
4952 "Convert a SureLint warning line into a disable statement.
4953 Run from Verilog source window; assumes there is a *compile* buffer
4954 with point set appropriately.
4956 For example:
4957 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
4958 becomes:
4959 // surefire lint_line_off UDDONX"
4960 (interactive)
4961 (let ((buff (if (boundp 'next-error-last-buffer)
4962 next-error-last-buffer
4963 compilation-last-buffer)))
4964 (when (buffer-live-p buff)
4965 (save-excursion
4966 (switch-to-buffer buff)
4967 (beginning-of-line)
4968 (when
4969 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
4970 (let* ((code (match-string 2))
4971 (file (match-string 3))
4972 (line (match-string 4))
4973 (buffer (get-file-buffer file))
4974 dir filename)
4975 (unless buffer
4976 (progn
4977 (setq buffer
4978 (and (file-exists-p file)
4979 (find-file-noselect file)))
4980 (or buffer
4981 (let* ((pop-up-windows t))
4982 (let ((name (expand-file-name
4983 (read-file-name
4984 (format "Find this error in: (default %s) "
4985 file)
4986 dir file t))))
4987 (if (file-directory-p name)
4988 (setq name (expand-file-name filename name)))
4989 (setq buffer
4990 (and (file-exists-p name)
4991 (find-file-noselect name))))))))
4992 (switch-to-buffer buffer)
4993 (goto-char (point-min))
4994 (forward-line (- (string-to-number line)))
4995 (end-of-line)
4996 (catch 'already
4997 (cond
4998 ((verilog-in-slash-comment-p)
4999 (re-search-backward "//")
5000 (cond
5001 ((looking-at "// surefire lint_off_line ")
5002 (goto-char (match-end 0))
5003 (let ((lim (point-at-eol)))
5004 (if (re-search-forward code lim 'move)
5005 (throw 'already t)
5006 (insert (concat " " code)))))
5009 ((verilog-in-star-comment-p)
5010 (re-search-backward "/\*")
5011 (insert (format " // surefire lint_off_line %6s" code )))
5013 (insert (format " // surefire lint_off_line %6s" code ))
5014 )))))))))
5016 (defun verilog-verilint-off ()
5017 "Convert a Verilint warning line into a disable statement.
5019 For example:
5020 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
5021 becomes:
5022 //Verilint 240 off // WARNING: Unused input"
5023 (interactive)
5024 (save-excursion
5025 (beginning-of-line)
5026 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
5027 (replace-match (format
5028 ;; %3s makes numbers 1-999 line up nicely
5029 "\\1//Verilint %3s off // WARNING: \\3"
5030 (match-string 2)))
5031 (beginning-of-line)
5032 (verilog-indent-line))))
5034 (defun verilog-auto-save-compile ()
5035 "Update automatics with \\[verilog-auto], save the buffer, and compile."
5036 (interactive)
5037 (verilog-auto) ; Always do it for safety
5038 (save-buffer)
5039 (compile compile-command))
5041 (defun verilog-preprocess (&optional command filename)
5042 "Preprocess the buffer, similar to `compile', but put output in Verilog-Mode.
5043 Takes optional COMMAND or defaults to `verilog-preprocessor', and
5044 FILENAME to find directory to run in, or defaults to `buffer-file-name`."
5045 (interactive
5046 (list
5047 (let ((default (verilog-expand-command verilog-preprocessor)))
5048 (set (make-local-variable `verilog-preprocessor)
5049 (read-from-minibuffer "Run Preprocessor (like this): "
5050 default nil nil
5051 'verilog-preprocess-history default)))))
5052 (unless command (setq command (verilog-expand-command verilog-preprocessor)))
5053 (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
5054 (dir (file-name-directory (or filename buffer-file-name)))
5055 (cmd (concat "cd " dir "; " command)))
5056 (with-output-to-temp-buffer "*Verilog-Preprocessed*"
5057 (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
5058 (insert (concat "// " cmd "\n"))
5059 (call-process shell-file-name nil t nil shell-command-switch cmd)
5060 (verilog-mode)
5061 ;; Without this force, it takes a few idle seconds
5062 ;; to get the color, which is very jarring
5063 (when fontlocked (font-lock-fontify-buffer))))))
5067 ;; Batch
5070 (defun verilog-warn (string &rest args)
5071 "Print a warning with `format' using STRING and optional ARGS."
5072 (apply 'message (concat "%%Warning: " string) args))
5074 (defun verilog-warn-error (string &rest args)
5075 "Call `error' using STRING and optional ARGS.
5076 If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead."
5077 (if verilog-warn-fatal
5078 (apply 'error string args)
5079 (apply 'verilog-warn string args)))
5081 (defmacro verilog-batch-error-wrapper (&rest body)
5082 "Execute BODY and add error prefix to any errors found.
5083 This lets programs calling batch mode to easily extract error messages."
5084 `(let ((verilog-warn-fatal nil))
5085 (condition-case err
5086 (progn ,@body)
5087 (error
5088 (error "%%Error: %s%s" (error-message-string err)
5089 (if (featurep 'xemacs) "\n" "")))))) ;; XEmacs forgets to add a newline
5091 (defun verilog-batch-execute-func (funref &optional no-save)
5092 "Internal processing of a batch command.
5093 Runs FUNREF on all command arguments.
5094 Save the result unless optional NO-SAVE is t."
5095 (verilog-batch-error-wrapper
5096 ;; Setting global variables like that is *VERY NASTY* !!! --Stef
5097 ;; However, this function is called only when Emacs is being used as
5098 ;; a standalone language instead of as an editor, so we'll live.
5100 ;; General globals needed
5101 (setq make-backup-files nil)
5102 (setq-default make-backup-files nil)
5103 (setq enable-local-variables t)
5104 (setq enable-local-eval t)
5105 ;; Make sure any sub-files we read get proper mode
5106 (setq-default major-mode 'verilog-mode)
5107 ;; Ditto files already read in
5108 (mapc (lambda (buf)
5109 (when (buffer-file-name buf)
5110 (with-current-buffer buf
5111 (verilog-mode))))
5112 (buffer-list))
5113 ;; Process the files
5114 (mapcar (lambda (buf)
5115 (when (buffer-file-name buf)
5116 (save-excursion
5117 (if (not (file-exists-p (buffer-file-name buf)))
5118 (error
5119 (concat "File not found: " (buffer-file-name buf))))
5120 (message (concat "Processing " (buffer-file-name buf)))
5121 (set-buffer buf)
5122 (funcall funref)
5123 (unless no-save (save-buffer)))))
5124 (buffer-list))))
5126 (defun verilog-batch-auto ()
5127 "For use with --batch, perform automatic expansions as a stand-alone tool.
5128 This sets up the appropriate Verilog mode environment, updates automatics
5129 with \\[verilog-auto] on all command-line files, and saves the buffers.
5130 For proper results, multiple filenames need to be passed on the command
5131 line in bottom-up order."
5132 (unless noninteractive
5133 (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5134 (verilog-batch-execute-func `verilog-auto))
5136 (defun verilog-batch-delete-auto ()
5137 "For use with --batch, perform automatic deletion as a stand-alone tool.
5138 This sets up the appropriate Verilog mode environment, deletes automatics
5139 with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
5140 (unless noninteractive
5141 (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5142 (verilog-batch-execute-func `verilog-delete-auto))
5144 (defun verilog-batch-delete-trailing-whitespace ()
5145 "For use with --batch, perform whitespace deletion as a stand-alone tool.
5146 This sets up the appropriate Verilog mode environment, removes
5147 whitespace with \\[verilog-delete-trailing-whitespace] on all
5148 command-line files, and saves the buffers."
5149 (unless noninteractive
5150 (error "Use verilog-batch-delete-trailing-whitepace only with --batch")) ;; Otherwise we'd mess up buffer modes
5151 (verilog-batch-execute-func `verilog-delete-trailing-whitespace))
5153 (defun verilog-batch-diff-auto ()
5154 "For use with --batch, perform automatic differences as a stand-alone tool.
5155 This sets up the appropriate Verilog mode environment, expand automatics
5156 with \\[verilog-diff-auto] on all command-line files, and reports an error
5157 if any differences are observed. This is appropriate for adding to regressions
5158 to insure automatics are always properly maintained."
5159 (unless noninteractive
5160 (error "Use verilog-batch-diff-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5161 (verilog-batch-execute-func `verilog-diff-auto t))
5163 (defun verilog-batch-inject-auto ()
5164 "For use with --batch, perform automatic injection as a stand-alone tool.
5165 This sets up the appropriate Verilog mode environment, injects new automatics
5166 with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
5167 For proper results, multiple filenames need to be passed on the command
5168 line in bottom-up order."
5169 (unless noninteractive
5170 (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
5171 (verilog-batch-execute-func `verilog-inject-auto))
5173 (defun verilog-batch-indent ()
5174 "For use with --batch, reindent an entire file as a stand-alone tool.
5175 This sets up the appropriate Verilog mode environment, calls
5176 \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
5177 (unless noninteractive
5178 (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes
5179 (verilog-batch-execute-func `verilog-indent-buffer))
5183 ;; Indentation
5185 (defconst verilog-indent-alist
5186 '((block . (+ ind verilog-indent-level))
5187 (case . (+ ind verilog-case-indent))
5188 (cparenexp . (+ ind verilog-indent-level))
5189 (cexp . (+ ind verilog-cexp-indent))
5190 (defun . verilog-indent-level-module)
5191 (declaration . verilog-indent-level-declaration)
5192 (directive . (verilog-calculate-indent-directive))
5193 (tf . verilog-indent-level)
5194 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
5195 (statement . ind)
5196 (cpp . 0)
5197 (comment . (verilog-comment-indent))
5198 (unknown . 3)
5199 (string . 0)))
5201 (defun verilog-continued-line-1 (lim)
5202 "Return true if this is a continued line.
5203 Set point to where line starts. Limit search to point LIM."
5204 (let ((continued 't))
5205 (if (eq 0 (forward-line -1))
5206 (progn
5207 (end-of-line)
5208 (verilog-backward-ws&directives lim)
5209 (if (bobp)
5210 (setq continued nil)
5211 (setq continued (verilog-backward-token))))
5212 (setq continued nil))
5213 continued))
5215 (defun verilog-calculate-indent ()
5216 "Calculate the indent of the current Verilog line.
5217 Examine previous lines. Once a line is found that is definitive as to the
5218 type of the current line, return that lines' indent level and its type.
5219 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5220 (save-excursion
5221 (let* ((starting_position (point))
5222 (par 0)
5223 (begin (looking-at "[ \t]*begin\\>"))
5224 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
5225 (type (catch 'nesting
5226 ;; Keep working backwards until we can figure out
5227 ;; what type of statement this is.
5228 ;; Basically we need to figure out
5229 ;; 1) if this is a continuation of the previous line;
5230 ;; 2) are we in a block scope (begin..end)
5232 ;; if we are in a comment, done.
5233 (if (verilog-in-star-comment-p)
5234 (throw 'nesting 'comment))
5236 ;; if we have a directive, done.
5237 (if (save-excursion (beginning-of-line)
5238 (and (looking-at verilog-directive-re-1)
5239 (not (or (looking-at "[ \t]*`[ou]vm_")
5240 (looking-at "[ \t]*`vmm_")))))
5241 (throw 'nesting 'directive))
5242 ;; indent structs as if there were module level
5243 (if (verilog-in-struct-p)
5244 (throw 'nesting 'block))
5246 ;; if we are in a parenthesized list, and the user likes to indent these, return.
5247 ;; unless we are in the newfangled coverpoint or constraint blocks
5248 (if (and
5249 verilog-indent-lists
5250 (verilog-in-paren)
5251 (not (verilog-in-coverage-p))
5253 (progn (setq par 1)
5254 (throw 'nesting 'block)))
5256 ;; See if we are continuing a previous line
5257 (while t
5258 ;; trap out if we crawl off the top of the buffer
5259 (if (bobp) (throw 'nesting 'cpp))
5261 (if (verilog-continued-line-1 lim)
5262 (let ((sp (point)))
5263 (if (and
5264 (not (looking-at verilog-complete-reg))
5265 (verilog-continued-line-1 lim))
5266 (progn (goto-char sp)
5267 (throw 'nesting 'cexp))
5269 (goto-char sp))
5271 (if (and begin
5272 (not verilog-indent-begin-after-if)
5273 (looking-at verilog-no-indent-begin-re))
5274 (progn
5275 (beginning-of-line)
5276 (skip-chars-forward " \t")
5277 (throw 'nesting 'statement))
5278 (progn
5279 (throw 'nesting 'cexp))))
5280 ;; not a continued line
5281 (goto-char starting_position))
5283 (if (looking-at "\\<else\\>")
5284 ;; search back for governing if, striding across begin..end pairs
5285 ;; appropriately
5286 (let ((elsec 1))
5287 (while (verilog-re-search-backward verilog-ends-re nil 'move)
5288 (cond
5289 ((match-end 1) ; else, we're in deep
5290 (setq elsec (1+ elsec)))
5291 ((match-end 2) ; if
5292 (setq elsec (1- elsec))
5293 (if (= 0 elsec)
5294 (if verilog-align-ifelse
5295 (throw 'nesting 'statement)
5296 (progn ;; back up to first word on this line
5297 (beginning-of-line)
5298 (verilog-forward-syntactic-ws)
5299 (throw 'nesting 'statement)))))
5300 ((match-end 3) ; assert block
5301 (setq elsec (1- elsec))
5302 (verilog-beg-of-statement) ;; doesn't get to beginning
5303 (if (looking-at verilog-property-re)
5304 (throw 'nesting 'statement) ; We don't need an endproperty for these
5305 (throw 'nesting 'block) ;We still need an endproperty
5307 (t ; endblock
5308 ; try to leap back to matching outward block by striding across
5309 ; indent level changing tokens then immediately
5310 ; previous line governs indentation.
5311 (let (( reg) (nest 1))
5312 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
5313 (cond
5314 ((match-end 4) ; end
5315 ;; Search back for matching begin
5316 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
5317 ((match-end 5) ; endcase
5318 ;; Search back for matching case
5319 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5320 ((match-end 6) ; endfunction
5321 ;; Search back for matching function
5322 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5323 ((match-end 7) ; endtask
5324 ;; Search back for matching task
5325 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
5326 ((match-end 8) ; endspecify
5327 ;; Search back for matching specify
5328 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5329 ((match-end 9) ; endtable
5330 ;; Search back for matching table
5331 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5332 ((match-end 10) ; endgenerate
5333 ;; Search back for matching generate
5334 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5335 ((match-end 11) ; joins
5336 ;; Search back for matching fork
5337 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
5338 ((match-end 12) ; class
5339 ;; Search back for matching class
5340 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5341 ((match-end 13) ; covergroup
5342 ;; Search back for matching covergroup
5343 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
5344 (catch 'skip
5345 (while (verilog-re-search-backward reg nil 'move)
5346 (cond
5347 ((match-end 1) ; begin
5348 (setq nest (1- nest))
5349 (if (= 0 nest)
5350 (throw 'skip 1)))
5351 ((match-end 2) ; end
5352 (setq nest (1+ nest)))))
5353 )))))))
5354 (throw 'nesting (verilog-calc-1)))
5355 );; catch nesting
5356 );; type
5358 ;; Return type of block and indent level.
5359 (if (not type)
5360 (setq type 'cpp))
5361 (if (> par 0) ; Unclosed Parenthesis
5362 (list 'cparenexp par)
5363 (cond
5364 ((eq type 'case)
5365 (list type (verilog-case-indent-level)))
5366 ((eq type 'statement)
5367 (list type (current-column)))
5368 ((eq type 'defun)
5369 (list type 0))
5371 (list type (verilog-current-indent-level))))))))
5373 (defun verilog-wai ()
5374 "Show matching nesting block for debugging."
5375 (interactive)
5376 (save-excursion
5377 (let* ((type (verilog-calc-1))
5378 depth)
5379 ;; Return type of block and indent level.
5380 (if (not type)
5381 (setq type 'cpp))
5382 (if (and
5383 verilog-indent-lists
5384 (not(or (verilog-in-coverage-p)
5385 (verilog-in-struct-p)))
5386 (verilog-in-paren))
5387 (setq depth 1)
5388 (cond
5389 ((eq type 'case)
5390 (setq depth (verilog-case-indent-level)))
5391 ((eq type 'statement)
5392 (setq depth (current-column)))
5393 ((eq type 'defun)
5394 (setq depth 0))
5396 (setq depth (verilog-current-indent-level)))))
5397 (message "You are at nesting %s depth %d" type depth))))
5398 (defun verilog-calc-1 ()
5399 (catch 'nesting
5400 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)")))
5401 (while (verilog-re-search-backward re nil 'move)
5402 (catch 'continue
5403 (cond
5404 ((equal (char-after) ?\{)
5405 (if (verilog-at-constraint-p)
5406 (throw 'nesting 'block)))
5408 ((equal (char-after) ?\})
5409 (let ((there (verilog-at-close-constraint-p)))
5410 (if there ;; we are at the } that closes a constraint. Find the { that opens it
5411 (progn
5412 (forward-char 1)
5413 (backward-list 1)
5414 (verilog-beg-of-statement)))))
5416 ((looking-at verilog-beg-block-re-ordered)
5417 (cond
5418 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
5419 (let ((here (point)))
5420 (verilog-beg-of-statement)
5421 (if (looking-at verilog-extended-case-re)
5422 (throw 'nesting 'case)
5423 (goto-char here)))
5424 (throw 'nesting 'case))
5426 ((match-end 4) ; *sigh* could be "disable fork"
5427 (let ((here (point)))
5428 (verilog-beg-of-statement)
5429 (if (looking-at verilog-disable-fork-re)
5430 t ; this is a normal statement
5431 (progn ; or is fork, starts a new block
5432 (goto-char here)
5433 (throw 'nesting 'block)))))
5435 ((match-end 27) ; *sigh* might be a clocking declaration
5436 (let ((here (point)))
5437 (if (verilog-in-paren)
5438 t ; this is a normal statement
5439 (progn ; or is fork, starts a new block
5440 (goto-char here)
5441 (throw 'nesting 'block)))))
5443 ;; need to consider typedef struct here...
5444 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
5445 ; *sigh* These words have an optional prefix:
5446 ; extern {virtual|protected}? function a();
5447 ; typedef class foo;
5448 ; and we don't want to confuse this with
5449 ; function a();
5450 ; property
5451 ; ...
5452 ; endfunction
5453 (verilog-beg-of-statement)
5454 (if (looking-at verilog-beg-block-re-ordered)
5455 (throw 'nesting 'block)
5456 (throw 'nesting 'defun)))
5459 ((looking-at "\\<property\\>")
5460 ; *sigh*
5461 ; {assert|assume|cover} property (); are complete
5462 ; and could also be labeled: - foo: assert property
5463 ; but
5464 ; property ID () ... needs end_property
5465 (verilog-beg-of-statement)
5466 (if (looking-at verilog-property-re)
5467 (throw 'continue 'statement) ; We don't need an endproperty for these
5468 (throw 'nesting 'block) ;We still need an endproperty
5471 (t (throw 'nesting 'block))))
5473 ((looking-at verilog-end-block-re)
5474 (verilog-leap-to-head)
5475 (if (verilog-in-case-region-p)
5476 (progn
5477 (verilog-leap-to-case-head)
5478 (if (looking-at verilog-extended-case-re)
5479 (throw 'nesting 'case)))))
5481 ((looking-at verilog-defun-level-re)
5482 (if (looking-at verilog-defun-level-generate-only-re)
5483 (if (verilog-in-generate-region-p)
5484 (throw 'continue 'foo) ; always block in a generate - keep looking
5485 (throw 'nesting 'defun))
5486 (throw 'nesting 'defun)))
5488 ((looking-at verilog-cpp-level-re)
5489 (throw 'nesting 'cpp))
5491 ((bobp)
5492 (throw 'nesting 'cpp)))))
5494 (throw 'nesting 'cpp))))
5496 (defun verilog-calculate-indent-directive ()
5497 "Return indentation level for directive.
5498 For speed, the searcher looks at the last directive, not the indent
5499 of the appropriate enclosing block."
5500 (let ((base -1) ;; Indent of the line that determines our indentation
5501 (ind 0)) ;; Relative offset caused by other directives (like `endif on same line as `else)
5502 ;; Start at current location, scan back for another directive
5504 (save-excursion
5505 (beginning-of-line)
5506 (while (and (< base 0)
5507 (verilog-re-search-backward verilog-directive-re nil t))
5508 (cond ((save-excursion (skip-chars-backward " \t") (bolp))
5509 (setq base (current-indentation))))
5510 (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL
5511 (setq ind (- ind verilog-indent-level-directive)))
5512 ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL
5513 (setq ind (+ ind verilog-indent-level-directive)))
5514 ((looking-at verilog-directive-begin)
5515 (setq ind (+ ind verilog-indent-level-directive)))))
5516 ;; Adjust indent to starting indent of critical line
5517 (setq ind (max 0 (+ ind base))))
5519 (save-excursion
5520 (beginning-of-line)
5521 (skip-chars-forward " \t")
5522 (cond ((or (looking-at verilog-directive-middle)
5523 (looking-at verilog-directive-end))
5524 (setq ind (max 0 (- ind verilog-indent-level-directive))))))
5525 ind))
5527 (defun verilog-leap-to-case-head ()
5528 (let ((nest 1))
5529 (while (/= 0 nest)
5530 (verilog-re-search-backward
5531 (concat
5532 "\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
5533 "\\|\\(\\<endcase\\>\\)" )
5534 nil 'move)
5535 (cond
5536 ((match-end 1)
5537 (let ((here (point)))
5538 (verilog-beg-of-statement)
5539 (unless (looking-at verilog-extended-case-re)
5540 (goto-char here)))
5541 (setq nest (1- nest)))
5542 ((match-end 3)
5543 (setq nest (1+ nest)))
5544 ((bobp)
5545 (ding 't)
5546 (setq nest 0))))))
5548 (defun verilog-leap-to-head ()
5549 "Move point to the head of this block.
5550 Jump from end to matching begin, from endcase to matching case, and so on."
5551 (let ((reg nil)
5552 snest
5553 (nesting 'yes)
5554 (nest 1))
5555 (cond
5556 ((looking-at "\\<end\\>")
5557 ;; 1: Search back for matching begin
5558 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
5559 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
5560 ((looking-at "\\<endtask\\>")
5561 ;; 2: Search back for matching task
5562 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)")
5563 (setq nesting 'no))
5564 ((looking-at "\\<endcase\\>")
5565 (catch 'nesting
5566 (verilog-leap-to-case-head) )
5567 (setq reg nil) ; to force skip
5570 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
5571 ;; 4: Search back for matching fork
5572 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5573 ((looking-at "\\<endclass\\>")
5574 ;; 5: Search back for matching class
5575 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5576 ((looking-at "\\<endtable\\>")
5577 ;; 6: Search back for matching table
5578 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5579 ((looking-at "\\<endspecify\\>")
5580 ;; 7: Search back for matching specify
5581 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5582 ((looking-at "\\<endfunction\\>")
5583 ;; 8: Search back for matching function
5584 (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<function\\>\\)")
5585 (setq nesting 'no))
5586 ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5587 ((looking-at "\\<endgenerate\\>")
5588 ;; 8: Search back for matching generate
5589 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5590 ((looking-at "\\<endgroup\\>")
5591 ;; 10: Search back for matching covergroup
5592 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
5593 ((looking-at "\\<endproperty\\>")
5594 ;; 11: Search back for matching property
5595 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
5596 ((looking-at verilog-uvm-end-re)
5597 ;; 12: Search back for matching sequence
5598 (setq reg (concat "\\(" verilog-uvm-begin-re "\\|" verilog-uvm-end-re "\\)")))
5599 ((looking-at verilog-ovm-end-re)
5600 ;; 12: Search back for matching sequence
5601 (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
5602 ((looking-at verilog-vmm-end-re)
5603 ;; 12: Search back for matching sequence
5604 (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
5605 ((looking-at "\\<endinterface\\>")
5606 ;; 12: Search back for matching interface
5607 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
5608 ((looking-at "\\<endsequence\\>")
5609 ;; 12: Search back for matching sequence
5610 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
5611 ((looking-at "\\<endclocking\\>")
5612 ;; 12: Search back for matching clocking
5613 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
5614 (if reg
5615 (catch 'skip
5616 (if (eq nesting 'yes)
5617 (let (sreg)
5618 (while (verilog-re-search-backward reg nil 'move)
5619 (cond
5620 ((match-end 1) ; begin
5621 (if (looking-at "fork")
5622 (let ((here (point)))
5623 (verilog-beg-of-statement)
5624 (unless (looking-at verilog-disable-fork-re)
5625 (goto-char here)
5626 (setq nest (1- nest))))
5627 (setq nest (1- nest)))
5628 (if (= 0 nest)
5629 ;; Now previous line describes syntax
5630 (throw 'skip 1))
5631 (if (and snest
5632 (= snest nest))
5633 (setq reg sreg)))
5634 ((match-end 2) ; end
5635 (setq nest (1+ nest)))
5636 ((match-end 3)
5637 ;; endcase, jump to case
5638 (setq snest nest)
5639 (setq nest (1+ nest))
5640 (setq sreg reg)
5641 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5642 ((match-end 4)
5643 ;; join, jump to fork
5644 (setq snest nest)
5645 (setq nest (1+ nest))
5646 (setq sreg reg)
5647 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5649 ;no nesting
5650 (if (and
5651 (verilog-re-search-backward reg nil 'move)
5652 (match-end 1)) ; task -> could be virtual and/or protected
5653 (progn
5654 (verilog-beg-of-statement)
5655 (throw 'skip 1))
5656 (throw 'skip 1)))))))
5658 (defun verilog-continued-line ()
5659 "Return true if this is a continued line.
5660 Set point to where line starts."
5661 (let ((continued 't))
5662 (if (eq 0 (forward-line -1))
5663 (progn
5664 (end-of-line)
5665 (verilog-backward-ws&directives)
5666 (if (bobp)
5667 (setq continued nil)
5668 (while (and continued
5669 (save-excursion
5670 (skip-chars-backward " \t")
5671 (not (bolp))))
5672 (setq continued (verilog-backward-token)))))
5673 (setq continued nil))
5674 continued))
5676 (defun verilog-backward-token ()
5677 "Step backward token, returning true if this is a continued line."
5678 (interactive)
5679 (verilog-backward-syntactic-ws)
5680 (cond
5681 ((bolp)
5682 nil)
5683 (;-- Anything ending in a ; is complete
5684 (= (preceding-char) ?\;)
5685 nil)
5686 (; If a "}" is prefixed by a ";", then this is a complete statement
5687 ; i.e.: constraint foo { a = b; }
5688 (= (preceding-char) ?\})
5689 (progn
5690 (backward-char)
5691 (not(verilog-at-close-constraint-p))))
5692 (;-- constraint foo { a = b }
5693 ; is a complete statement. *sigh*
5694 (= (preceding-char) ?\{)
5695 (progn
5696 (backward-char)
5697 (not (verilog-at-constraint-p))))
5698 (;" string "
5699 (= (preceding-char) ?\")
5700 (backward-char)
5701 (verilog-skip-backward-comment-or-string)
5702 nil)
5704 (; [3:4]
5705 (= (preceding-char) ?\])
5706 (backward-char)
5707 (verilog-backward-open-bracket)
5710 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
5711 ; also could be simply '@(foo)'
5712 ; or foo u1 #(a=8)
5713 ; (b, ... which ISN'T complete
5714 ;;;; Do we need this???
5715 (= (preceding-char) ?\))
5716 (progn
5717 (backward-char)
5718 (verilog-backward-up-list 1)
5719 (verilog-backward-syntactic-ws)
5720 (let ((back (point)))
5721 (forward-word -1)
5722 (cond
5723 ;;XX
5724 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
5725 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
5726 ((looking-at verilog-uvm-statement-re)
5727 nil)
5728 ((looking-at verilog-uvm-begin-re)
5730 ((looking-at verilog-uvm-end-re)
5732 ((looking-at verilog-ovm-statement-re)
5733 nil)
5734 ((looking-at verilog-ovm-begin-re)
5736 ((looking-at verilog-ovm-end-re)
5738 ;; JBA find VMM macros
5739 ((looking-at verilog-vmm-statement-re)
5740 nil )
5741 ((looking-at verilog-vmm-begin-re)
5743 ((looking-at verilog-vmm-end-re)
5744 nil)
5745 ;; JBA trying to catch macro lines with no ; at end
5746 ((looking-at "\\<`")
5747 nil)
5749 (goto-char back)
5750 (cond
5751 ((= (preceding-char) ?\@)
5752 (backward-char)
5753 (save-excursion
5754 (verilog-backward-token)
5755 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
5756 ((= (preceding-char) ?\#)
5757 (backward-char))
5758 (t t)))))))
5760 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
5762 (forward-word -1)
5763 (while (= (preceding-char) ?\_)
5764 (forward-word -1))
5765 (cond
5766 ((looking-at "\\<else\\>")
5768 ((looking-at verilog-behavioral-block-beg-re)
5770 ((looking-at verilog-indent-re)
5771 nil)
5773 (let
5774 ((back (point)))
5775 (verilog-backward-syntactic-ws)
5776 (cond
5777 ((= (preceding-char) ?\:)
5778 (backward-char)
5779 (verilog-backward-syntactic-ws)
5780 (backward-sexp)
5781 (if (looking-at verilog-nameable-item-re )
5784 ((= (preceding-char) ?\#)
5785 (backward-char)
5787 ((= (preceding-char) ?\`)
5788 (backward-char)
5792 (goto-char back)
5793 t))))))))
5795 (defun verilog-backward-syntactic-ws ()
5796 "Move backwards putting point after first non-whitespace non-comment."
5797 (verilog-skip-backward-comments)
5798 (forward-comment (- (buffer-size))))
5800 (defun verilog-backward-syntactic-ws-quick ()
5801 "As with `verilog-backward-syntactic-ws' but use `verilog-scan' cache."
5802 (while (cond ((bobp)
5803 nil) ; Done
5804 ((> (skip-syntax-backward " ") 0)
5806 ((eq (preceding-char) ?\n) ;; \n's terminate // so aren't space syntax
5807 (forward-char -1)
5809 ((or (verilog-inside-comment-or-string-p (1- (point)))
5810 (verilog-inside-comment-or-string-p (point)))
5811 (re-search-backward "[/\"]" nil t) ;; Only way a comment or quote can begin
5812 t))))
5814 (defun verilog-forward-syntactic-ws ()
5815 (verilog-skip-forward-comment-p)
5816 (forward-comment (buffer-size)))
5818 (defun verilog-backward-ws&directives (&optional bound)
5819 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
5820 Optional BOUND limits search."
5821 (save-restriction
5822 (let* ((bound (or bound (point-min)))
5823 (here bound)
5824 (p nil) )
5825 (if (< bound (point))
5826 (progn
5827 (let ((state (save-excursion (verilog-syntax-ppss))))
5828 (cond
5829 ((nth 7 state) ;; in // comment
5830 (verilog-re-search-backward "//" nil 'move)
5831 (skip-chars-backward "/"))
5832 ((nth 4 state) ;; in /* */ comment
5833 (verilog-re-search-backward "/\*" nil 'move))))
5834 (narrow-to-region bound (point))
5835 (while (/= here (point))
5836 (setq here (point))
5837 (verilog-skip-backward-comments)
5838 (setq p
5839 (save-excursion
5840 (beginning-of-line)
5841 (cond
5842 ((and verilog-highlight-translate-off
5843 (verilog-within-translate-off))
5844 (verilog-back-to-start-translate-off (point-min)))
5845 ((looking-at verilog-directive-re-1)
5846 (point))
5848 nil))))
5849 (if p (goto-char p))))))))
5851 (defun verilog-forward-ws&directives (&optional bound)
5852 "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
5853 Optional BOUND limits search."
5854 (save-restriction
5855 (let* ((bound (or bound (point-max)))
5856 (here bound)
5857 jump)
5858 (if (> bound (point))
5859 (progn
5860 (let ((state (save-excursion (verilog-syntax-ppss))))
5861 (cond
5862 ((nth 7 state) ;; in // comment
5863 (end-of-line)
5864 (forward-char 1)
5865 (skip-chars-forward " \t\n\f")
5867 ((nth 4 state) ;; in /* */ comment
5868 (verilog-re-search-forward "\*\/\\s-*" nil 'move))))
5869 (narrow-to-region (point) bound)
5870 (while (/= here (point))
5871 (setq here (point)
5872 jump nil)
5873 (forward-comment (buffer-size))
5874 (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ;; Attribute
5875 (goto-char (match-end 0)))
5876 (save-excursion
5877 (beginning-of-line)
5878 (if (looking-at verilog-directive-re-1)
5879 (setq jump t)))
5880 (if jump
5881 (beginning-of-line 2))))))))
5883 (defun verilog-in-comment-p ()
5884 "Return true if in a star or // comment."
5885 (let ((state (save-excursion (verilog-syntax-ppss))))
5886 (or (nth 4 state) (nth 7 state))))
5888 (defun verilog-in-star-comment-p ()
5889 "Return true if in a star comment."
5890 (let ((state (save-excursion (verilog-syntax-ppss))))
5891 (and
5892 (nth 4 state) ; t if in a comment of style a // or b /**/
5893 (not
5894 (nth 7 state) ; t if in a comment of style b /**/
5895 ))))
5897 (defun verilog-in-slash-comment-p ()
5898 "Return true if in a slash comment."
5899 (let ((state (save-excursion (verilog-syntax-ppss))))
5900 (nth 7 state)))
5902 (defun verilog-in-comment-or-string-p ()
5903 "Return true if in a string or comment."
5904 (let ((state (save-excursion (verilog-syntax-ppss))))
5905 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
5907 (defun verilog-in-attribute-p ()
5908 "Return true if point is in an attribute (* [] attribute *)."
5909 (save-match-data
5910 (save-excursion
5911 (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
5912 (numberp (match-beginning 1)))))
5914 (defun verilog-in-parameter-p ()
5915 "Return true if point is in a parameter assignment #( p1=1, p2=5)."
5916 (save-match-data
5917 (save-excursion
5918 (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move)
5919 (numberp (match-beginning 1)))))
5921 (defun verilog-in-escaped-name-p ()
5922 "Return true if in an escaped name."
5923 (save-excursion
5924 (backward-char)
5925 (skip-chars-backward "^ \t\n\f")
5926 (if (equal (char-after (point) ) ?\\ )
5928 nil)))
5929 (defun verilog-in-directive-p ()
5930 "Return true if in a directive."
5931 (save-excursion
5932 (beginning-of-line)
5933 (looking-at verilog-directive-re-1)))
5935 (defun verilog-in-parenthesis-p ()
5936 "Return true if in a ( ) expression (but not { } or [ ])."
5937 (save-match-data
5938 (save-excursion
5939 (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move)
5940 (numberp (match-beginning 1)))))
5942 (defun verilog-in-paren ()
5943 "Return true if in a parenthetical expression.
5944 May cache result using `verilog-syntax-ppss'."
5945 (let ((state (save-excursion (verilog-syntax-ppss))))
5946 (> (nth 0 state) 0 )))
5948 (defun verilog-in-paren-quick ()
5949 "Return true if in a parenthetical expression.
5950 Always starts from `point-min', to allow inserts with hooks disabled."
5951 ;; The -quick refers to its use alongside the other -quick functions,
5952 ;; not that it's likely to be faster than verilog-in-paren.
5953 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
5954 (> (nth 0 state) 0 )))
5956 (defun verilog-in-struct-p ()
5957 "Return true if in a struct declaration."
5958 (interactive)
5959 (save-excursion
5960 (if (verilog-in-paren)
5961 (progn
5962 (verilog-backward-up-list 1)
5963 (verilog-at-struct-p)
5965 nil)))
5967 (defun verilog-in-coverage-p ()
5968 "Return true if in a constraint or coverpoint expression."
5969 (interactive)
5970 (save-excursion
5971 (if (verilog-in-paren)
5972 (progn
5973 (verilog-backward-up-list 1)
5974 (verilog-at-constraint-p)
5976 nil)))
5977 (defun verilog-at-close-constraint-p ()
5978 "If at the } that closes a constraint or covergroup, return true."
5979 (if (and
5980 (equal (char-after) ?\})
5981 (verilog-in-paren))
5983 (save-excursion
5984 (verilog-backward-ws&directives)
5985 (if (equal (char-before) ?\;)
5986 (point)
5987 nil))))
5989 (defun verilog-at-constraint-p ()
5990 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
5991 (if (save-excursion
5992 (and
5993 (equal (char-after) ?\{)
5994 (forward-list)
5995 (progn (backward-char 1)
5996 (verilog-backward-ws&directives)
5997 (equal (char-before) ?\;))))
5998 ;; maybe
5999 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move)
6000 ;; not
6001 nil))
6003 (defun verilog-at-struct-p ()
6004 "If at the { of a struct, return true, moving point to struct."
6005 (save-excursion
6006 (if (and (equal (char-after) ?\{)
6007 (verilog-backward-token))
6008 (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6009 nil)))
6011 (defun verilog-parenthesis-depth ()
6012 "Return non zero if in parenthetical-expression."
6013 (save-excursion (nth 1 (verilog-syntax-ppss))))
6016 (defun verilog-skip-forward-comment-or-string ()
6017 "Return true if in a string or comment."
6018 (let ((state (save-excursion (verilog-syntax-ppss))))
6019 (cond
6020 ((nth 3 state) ;Inside string
6021 (search-forward "\"")
6023 ((nth 7 state) ;Inside // comment
6024 (forward-line 1)
6026 ((nth 4 state) ;Inside any comment (hence /**/)
6027 (search-forward "*/"))
6029 nil))))
6031 (defun verilog-skip-backward-comment-or-string ()
6032 "Return true if in a string or comment."
6033 (let ((state (save-excursion (verilog-syntax-ppss))))
6034 (cond
6035 ((nth 3 state) ;Inside string
6036 (search-backward "\"")
6038 ((nth 7 state) ;Inside // comment
6039 (search-backward "//")
6040 (skip-chars-backward "/")
6042 ((nth 4 state) ;Inside /* */ comment
6043 (search-backward "/*")
6046 nil))))
6048 (defun verilog-skip-backward-comments ()
6049 "Return true if a comment was skipped."
6050 (let ((more t))
6051 (while more
6052 (setq more
6053 (let ((state (save-excursion (verilog-syntax-ppss))))
6054 (cond
6055 ((nth 7 state) ;Inside // comment
6056 (search-backward "//")
6057 (skip-chars-backward "/")
6058 (skip-chars-backward " \t\n\f")
6060 ((nth 4 state) ;Inside /* */ comment
6061 (search-backward "/*")
6062 (skip-chars-backward " \t\n\f")
6064 ((and (not (bobp))
6065 (= (char-before) ?\/)
6066 (= (char-before (1- (point))) ?\*))
6067 (goto-char (- (point) 2))
6068 t) ;; Let nth 4 state handle the rest
6069 ((and (not (bobp))
6070 (= (char-before) ?\))
6071 (= (char-before (1- (point))) ?\*))
6072 (goto-char (- (point) 2))
6073 (if (search-backward "(*" nil t)
6074 (progn
6075 (skip-chars-backward " \t\n\f")
6077 (progn
6078 (goto-char (+ (point) 2))
6079 nil)))
6081 (/= (skip-chars-backward " \t\n\f") 0))))))))
6083 (defun verilog-skip-forward-comment-p ()
6084 "If in comment, move to end and return true."
6085 (let* (h
6086 (state (save-excursion (verilog-syntax-ppss)))
6087 (skip (cond
6088 ((nth 3 state) ;Inside string
6090 ((nth 7 state) ;Inside // comment
6091 (end-of-line)
6092 (forward-char 1)
6094 ((nth 4 state) ;Inside /* comment
6095 (search-forward "*/")
6097 ((verilog-in-attribute-p) ;Inside (* attribute
6098 (search-forward "*)" nil t)
6100 (t nil))))
6101 (skip-chars-forward " \t\n\f")
6102 (while
6103 (cond
6104 ((looking-at "\\/\\*")
6105 (progn
6106 (setq h (point))
6107 (goto-char (match-end 0))
6108 (if (search-forward "*/" nil t)
6109 (progn
6110 (skip-chars-forward " \t\n\f")
6111 (setq skip 't))
6112 (progn
6113 (goto-char h)
6114 nil))))
6115 ((looking-at "(\\*")
6116 (progn
6117 (setq h (point))
6118 (goto-char (match-end 0))
6119 (if (search-forward "*)" nil t)
6120 (progn
6121 (skip-chars-forward " \t\n\f")
6122 (setq skip 't))
6123 (progn
6124 (goto-char h)
6125 nil))))
6126 (t nil)))
6127 skip))
6129 (defun verilog-indent-line-relative ()
6130 "Cheap version of indent line.
6131 Only look at a few lines to determine indent level."
6132 (interactive)
6133 (let ((indent-str)
6134 (sp (point)))
6135 (if (looking-at "^[ \t]*$")
6136 (cond ;- A blank line; No need to be too smart.
6137 ((bobp)
6138 (setq indent-str (list 'cpp 0)))
6139 ((verilog-continued-line)
6140 (let ((sp1 (point)))
6141 (if (verilog-continued-line)
6142 (progn
6143 (goto-char sp)
6144 (setq indent-str
6145 (list 'statement (verilog-current-indent-level))))
6146 (goto-char sp1)
6147 (setq indent-str (list 'block (verilog-current-indent-level)))))
6148 (goto-char sp))
6149 ((goto-char sp)
6150 (setq indent-str (verilog-calculate-indent))))
6151 (progn (skip-chars-forward " \t")
6152 (setq indent-str (verilog-calculate-indent))))
6153 (verilog-do-indent indent-str)))
6155 (defun verilog-indent-line ()
6156 "Indent for special part of code."
6157 (verilog-do-indent (verilog-calculate-indent)))
6159 (defun verilog-do-indent (indent-str)
6160 (let ((type (car indent-str))
6161 (ind (car (cdr indent-str))))
6162 (cond
6163 (; handle continued exp
6164 (eq type 'cexp)
6165 (let ((here (point)))
6166 (verilog-backward-syntactic-ws)
6167 (cond
6168 ((or
6169 (= (preceding-char) ?\,)
6170 (= (preceding-char) ?\])
6171 (save-excursion
6172 (verilog-beg-of-statement-1)
6173 (looking-at verilog-declaration-re)))
6174 (let* ( fst
6175 (val
6176 (save-excursion
6177 (backward-char 1)
6178 (verilog-beg-of-statement-1)
6179 (setq fst (point))
6180 (if (looking-at verilog-declaration-re)
6181 (progn ;; we have multiple words
6182 (goto-char (match-end 0))
6183 (skip-chars-forward " \t")
6184 (cond
6185 ((and verilog-indent-declaration-macros
6186 (= (following-char) ?\`))
6187 (progn
6188 (forward-char 1)
6189 (forward-word 1)
6190 (skip-chars-forward " \t")))
6191 ((= (following-char) ?\[)
6192 (progn
6193 (forward-char 1)
6194 (verilog-backward-up-list -1)
6195 (skip-chars-forward " \t"))))
6196 (current-column))
6197 (progn
6198 (goto-char fst)
6199 (+ (current-column) verilog-cexp-indent))))))
6200 (goto-char here)
6201 (indent-line-to val)
6202 (if (and (not verilog-indent-lists)
6203 (verilog-in-paren))
6204 (verilog-pretty-declarations-auto))
6206 ((= (preceding-char) ?\) )
6207 (goto-char here)
6208 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6209 (indent-line-to val)))
6211 (goto-char here)
6212 (let ((val))
6213 (verilog-beg-of-statement-1)
6214 (if (and (< (point) here)
6215 (verilog-re-search-forward "=[ \\t]*" here 'move))
6216 (setq val (current-column))
6217 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
6218 (goto-char here)
6219 (indent-line-to val))))))
6221 (; handle inside parenthetical expressions
6222 (eq type 'cparenexp)
6223 (let* ( here
6224 (val (save-excursion
6225 (verilog-backward-up-list 1)
6226 (forward-char 1)
6227 (if verilog-indent-lists
6228 (skip-chars-forward " \t")
6229 (verilog-forward-syntactic-ws))
6230 (setq here (point))
6231 (current-column)))
6233 (decl (save-excursion
6234 (goto-char here)
6235 (verilog-forward-syntactic-ws)
6236 (setq here (point))
6237 (looking-at verilog-declaration-re))))
6238 (indent-line-to val)
6239 (if decl
6240 (verilog-pretty-declarations-auto))))
6242 (;-- Handle the ends
6244 (looking-at verilog-end-block-re )
6245 (verilog-at-close-constraint-p))
6246 (let ((val (if (eq type 'statement)
6247 (- ind verilog-indent-level)
6248 ind)))
6249 (indent-line-to val)))
6251 (;-- Case -- maybe line 'em up
6252 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
6253 (progn
6254 (cond
6255 ((looking-at "\\<endcase\\>")
6256 (indent-line-to ind))
6258 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6259 (indent-line-to val))))))
6261 (;-- defun
6262 (and (eq type 'defun)
6263 (looking-at verilog-zero-indent-re))
6264 (indent-line-to 0))
6266 (;-- declaration
6267 (and (or
6268 (eq type 'defun)
6269 (eq type 'block))
6270 (looking-at verilog-declaration-re))
6271 (verilog-indent-declaration ind))
6273 (;-- Everything else
6275 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6276 (indent-line-to val))))
6278 (if (looking-at "[ \t]+$")
6279 (skip-chars-forward " \t"))
6280 indent-str ; Return indent data
6283 (defun verilog-current-indent-level ()
6284 "Return the indent-level of the current statement."
6285 (save-excursion
6286 (let (par-pos)
6287 (beginning-of-line)
6288 (setq par-pos (verilog-parenthesis-depth))
6289 (while par-pos
6290 (goto-char par-pos)
6291 (beginning-of-line)
6292 (setq par-pos (verilog-parenthesis-depth)))
6293 (skip-chars-forward " \t")
6294 (current-column))))
6296 (defun verilog-case-indent-level ()
6297 "Return the indent-level of the current statement.
6298 Do not count named blocks or case-statements."
6299 (save-excursion
6300 (skip-chars-forward " \t")
6301 (cond
6302 ((looking-at verilog-named-block-re)
6303 (current-column))
6304 ((and (not (looking-at verilog-extended-case-re))
6305 (looking-at "^[^:;]+[ \t]*:"))
6306 (verilog-re-search-forward ":" nil t)
6307 (skip-chars-forward " \t")
6308 (current-column))
6310 (current-column)))))
6312 (defun verilog-indent-comment ()
6313 "Indent current line as comment."
6314 (let* ((stcol
6315 (cond
6316 ((verilog-in-star-comment-p)
6317 (save-excursion
6318 (re-search-backward "/\\*" nil t)
6319 (1+(current-column))))
6320 (comment-column
6321 comment-column )
6323 (save-excursion
6324 (re-search-backward "//" nil t)
6325 (current-column))))))
6326 (indent-line-to stcol)
6327 stcol))
6329 (defun verilog-more-comment ()
6330 "Make more comment lines like the previous."
6331 (let* ((star 0)
6332 (stcol
6333 (cond
6334 ((verilog-in-star-comment-p)
6335 (save-excursion
6336 (setq star 1)
6337 (re-search-backward "/\\*" nil t)
6338 (1+(current-column))))
6339 (comment-column
6340 comment-column )
6342 (save-excursion
6343 (re-search-backward "//" nil t)
6344 (current-column))))))
6345 (progn
6346 (indent-to stcol)
6347 (if (and star
6348 (save-excursion
6349 (forward-line -1)
6350 (skip-chars-forward " \t")
6351 (looking-at "\*")))
6352 (insert "* ")))))
6354 (defun verilog-comment-indent (&optional arg)
6355 "Return the column number the line should be indented to.
6356 ARG is ignored, for `comment-indent-function' compatibility."
6357 (cond
6358 ((verilog-in-star-comment-p)
6359 (save-excursion
6360 (re-search-backward "/\\*" nil t)
6361 (1+(current-column))))
6362 ( comment-column
6363 comment-column )
6365 (save-excursion
6366 (re-search-backward "//" nil t)
6367 (current-column)))))
6371 (defun verilog-pretty-declarations-auto (&optional quiet)
6372 "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'."
6373 (when (or (eq 'all verilog-auto-lineup)
6374 (eq 'declarations verilog-auto-lineup))
6375 (verilog-pretty-declarations quiet)))
6377 (defun verilog-pretty-declarations (&optional quiet)
6378 "Line up declarations around point.
6379 Be verbose about progress unless optional QUIET set."
6380 (interactive)
6381 (let* ((m1 (make-marker))
6382 (e (point))
6385 (here (point))
6387 start
6388 startpos
6390 endpos
6391 base-ind
6393 (save-excursion
6394 (if (progn
6395 ; (verilog-beg-of-statement-1)
6396 (beginning-of-line)
6397 (verilog-forward-syntactic-ws)
6398 (and (not (verilog-in-directive-p)) ;; could have `define input foo
6399 (looking-at verilog-declaration-re)))
6400 (progn
6401 (if (verilog-parenthesis-depth)
6402 ;; in an argument list or parameter block
6403 (setq el (verilog-backward-up-list -1)
6404 start (progn
6405 (goto-char e)
6406 (verilog-backward-up-list 1)
6407 (forward-line) ;; ignore ( input foo,
6408 (verilog-re-search-forward verilog-declaration-re el 'move)
6409 (goto-char (match-beginning 0))
6410 (skip-chars-backward " \t")
6411 (point))
6412 startpos (set-marker (make-marker) start)
6413 end (progn
6414 (goto-char start)
6415 (verilog-backward-up-list -1)
6416 (forward-char -1)
6417 (verilog-backward-syntactic-ws)
6418 (point))
6419 endpos (set-marker (make-marker) end)
6420 base-ind (progn
6421 (goto-char start)
6422 (forward-char 1)
6423 (skip-chars-forward " \t")
6424 (current-column))
6426 ;; in a declaration block (not in argument list)
6427 (setq
6428 start (progn
6429 (verilog-beg-of-statement-1)
6430 (while (and (looking-at verilog-declaration-re)
6431 (not (bobp)))
6432 (skip-chars-backward " \t")
6433 (setq e (point))
6434 (beginning-of-line)
6435 (verilog-backward-syntactic-ws)
6436 (backward-char)
6437 (verilog-beg-of-statement-1))
6439 startpos (set-marker (make-marker) start)
6440 end (progn
6441 (goto-char here)
6442 (verilog-end-of-statement)
6443 (setq e (point)) ;Might be on last line
6444 (verilog-forward-syntactic-ws)
6445 (while (looking-at verilog-declaration-re)
6446 (verilog-end-of-statement)
6447 (setq e (point))
6448 (verilog-forward-syntactic-ws))
6450 endpos (set-marker (make-marker) end)
6451 base-ind (progn
6452 (goto-char start)
6453 (verilog-do-indent (verilog-calculate-indent))
6454 (verilog-forward-ws&directives)
6455 (current-column))))
6456 ;; OK, start and end are set
6457 (goto-char (marker-position startpos))
6458 (if (and (not quiet)
6459 (> (- end start) 100))
6460 (message "Lining up declarations..(please stand by)"))
6461 ;; Get the beginning of line indent first
6462 (while (progn (setq e (marker-position endpos))
6463 (< (point) e))
6464 (cond
6465 ((save-excursion (skip-chars-backward " \t")
6466 (bolp))
6467 (verilog-forward-ws&directives)
6468 (indent-line-to base-ind)
6469 (verilog-forward-ws&directives)
6470 (if (< (point) e)
6471 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6473 (just-one-space)
6474 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6475 ;;(forward-line)
6477 ;; Now find biggest prefix
6478 (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
6479 ;; Now indent each line.
6480 (goto-char (marker-position startpos))
6481 (while (progn (setq e (marker-position endpos))
6482 (setq r (- e (point)))
6483 (> r 0))
6484 (setq e (point))
6485 (unless quiet (message "%d" r))
6486 ;;(verilog-do-indent (verilog-calculate-indent)))
6487 (verilog-forward-ws&directives)
6488 (cond
6489 ((or (and verilog-indent-declaration-macros
6490 (looking-at verilog-declaration-re-2-macro))
6491 (looking-at verilog-declaration-re-2-no-macro))
6492 (let ((p (match-end 0)))
6493 (set-marker m1 p)
6494 (if (verilog-re-search-forward "[[#`]" p 'move)
6495 (progn
6496 (forward-char -1)
6497 (just-one-space)
6498 (goto-char (marker-position m1))
6499 (just-one-space)
6500 (indent-to ind))
6501 (progn
6502 (just-one-space)
6503 (indent-to ind)))))
6504 ((verilog-continued-line-1 (marker-position startpos))
6505 (goto-char e)
6506 (indent-line-to ind))
6507 ((verilog-in-struct-p)
6508 ;; could have a declaration of a user defined item
6509 (goto-char e)
6510 (verilog-end-of-statement))
6511 (t ; Must be comment or white space
6512 (goto-char e)
6513 (verilog-forward-ws&directives)
6514 (forward-line -1)))
6515 (forward-line 1))
6516 (unless quiet (message "")))))))
6518 (defun verilog-pretty-expr (&optional quiet myre)
6519 "Line up expressions around point, optionally QUIET with regexp MYRE ignored."
6520 (interactive)
6521 (if (not (verilog-in-comment-or-string-p))
6522 (save-excursion
6523 (let ( (rexp (concat "^\\s-*" verilog-complete-reg))
6524 (rexp1 (concat "^\\s-*" verilog-basic-complete-re)))
6525 (beginning-of-line)
6526 (if (and (not (looking-at rexp ))
6527 (looking-at verilog-assignment-operation-re)
6528 (save-excursion
6529 (goto-char (match-end 2))
6530 (and (not (verilog-in-attribute-p))
6531 (not (verilog-in-parameter-p))
6532 (not (verilog-in-comment-or-string-p)))))
6533 (let* ((here (point))
6534 (e) (r)
6535 (start
6536 (progn
6537 (beginning-of-line)
6538 (setq e (point))
6539 (verilog-backward-syntactic-ws)
6540 (beginning-of-line)
6541 (while (and (not (looking-at rexp1))
6542 (looking-at verilog-assignment-operation-re)
6543 (not (bobp))
6545 (setq e (point))
6546 (verilog-backward-syntactic-ws)
6547 (beginning-of-line)
6548 ) ;Ack, need to grok `define
6550 (end
6551 (progn
6552 (goto-char here)
6553 (end-of-line)
6554 (setq e (point)) ;Might be on last line
6555 (verilog-forward-syntactic-ws)
6556 (beginning-of-line)
6557 (while (and
6558 (not (looking-at rexp1 ))
6559 (looking-at verilog-assignment-operation-re)
6560 (progn
6561 (end-of-line)
6562 (not (eq e (point)))))
6563 (setq e (point))
6564 (verilog-forward-syntactic-ws)
6565 (beginning-of-line)
6568 (endpos (set-marker (make-marker) end))
6569 (ind)
6571 (goto-char start)
6572 (verilog-do-indent (verilog-calculate-indent))
6573 (if (and (not quiet)
6574 (> (- end start) 100))
6575 (message "Lining up expressions..(please stand by)"))
6577 ;; Set indent to minimum throughout region
6578 (while (< (point) (marker-position endpos))
6579 (beginning-of-line)
6580 (verilog-just-one-space verilog-assignment-operation-re)
6581 (beginning-of-line)
6582 (verilog-do-indent (verilog-calculate-indent))
6583 (end-of-line)
6584 (verilog-forward-syntactic-ws)
6587 ;; Now find biggest prefix
6588 (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))
6590 ;; Now indent each line.
6591 (goto-char start)
6592 (while (progn (setq e (marker-position endpos))
6593 (setq r (- e (point)))
6594 (> r 0))
6595 (setq e (point))
6596 (if (not quiet) (message "%d" r))
6597 (cond
6598 ((looking-at verilog-assignment-operation-re)
6599 (goto-char (match-beginning 2))
6600 (if (not (or (verilog-in-parenthesis-p) ;; leave attributes and comparisons alone
6601 (verilog-in-coverage-p)))
6602 (if (eq (char-after) ?=)
6603 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
6604 (indent-to ind)
6607 ((verilog-continued-line-1 start)
6608 (goto-char e)
6609 (indent-line-to ind))
6610 (t ; Must be comment or white space
6611 (goto-char e)
6612 (verilog-forward-ws&directives)
6613 (forward-line -1))
6615 (forward-line 1))
6616 (unless quiet (message ""))
6617 ))))))
6619 (defun verilog-just-one-space (myre)
6620 "Remove extra spaces around regular expression MYRE."
6621 (interactive)
6622 (if (and (not(looking-at verilog-complete-reg))
6623 (looking-at myre))
6624 (let ((p1 (match-end 1))
6625 (p2 (match-end 2)))
6626 (progn
6627 (goto-char p2)
6628 (just-one-space)
6629 (goto-char p1)
6630 (just-one-space)))))
6632 (defun verilog-indent-declaration (baseind)
6633 "Indent current lines as declaration.
6634 Line up the variable names based on previous declaration's indentation.
6635 BASEIND is the base indent to offset everything."
6636 (interactive)
6637 (let ((pos (point-marker))
6638 (lim (save-excursion
6639 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
6640 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
6641 (point)))
6642 (ind)
6643 (val)
6644 (m1 (make-marker)))
6645 (setq val
6646 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6647 (indent-line-to val)
6649 ;; Use previous declaration (in this module) as template.
6650 (if (or (eq 'all verilog-auto-lineup)
6651 (eq 'declarations verilog-auto-lineup))
6652 (if (verilog-re-search-backward
6653 (or (and verilog-indent-declaration-macros
6654 verilog-declaration-re-1-macro)
6655 verilog-declaration-re-1-no-macro) lim t)
6656 (progn
6657 (goto-char (match-end 0))
6658 (skip-chars-forward " \t")
6659 (setq ind (current-column))
6660 (goto-char pos)
6661 (setq val
6662 (+ baseind
6663 (eval (cdr (assoc 'declaration verilog-indent-alist)))))
6664 (indent-line-to val)
6665 (if (and verilog-indent-declaration-macros
6666 (looking-at verilog-declaration-re-2-macro))
6667 (let ((p (match-end 0)))
6668 (set-marker m1 p)
6669 (if (verilog-re-search-forward "[[#`]" p 'move)
6670 (progn
6671 (forward-char -1)
6672 (just-one-space)
6673 (goto-char (marker-position m1))
6674 (just-one-space)
6675 (indent-to ind))
6676 (if (/= (current-column) ind)
6677 (progn
6678 (just-one-space)
6679 (indent-to ind)))))
6680 (if (looking-at verilog-declaration-re-2-no-macro)
6681 (let ((p (match-end 0)))
6682 (set-marker m1 p)
6683 (if (verilog-re-search-forward "[[`#]" p 'move)
6684 (progn
6685 (forward-char -1)
6686 (just-one-space)
6687 (goto-char (marker-position m1))
6688 (just-one-space)
6689 (indent-to ind))
6690 (if (/= (current-column) ind)
6691 (progn
6692 (just-one-space)
6693 (indent-to ind))))))))))
6694 (goto-char pos)))
6696 (defun verilog-get-lineup-indent (b edpos)
6697 "Return the indent level that will line up several lines within the region.
6698 Region is defined by B and EDPOS."
6699 (save-excursion
6700 (let ((ind 0) e)
6701 (goto-char b)
6702 ;; Get rightmost position
6703 (while (progn (setq e (marker-position edpos))
6704 (< (point) e))
6705 (if (verilog-re-search-forward
6706 (or (and verilog-indent-declaration-macros
6707 verilog-declaration-re-1-macro)
6708 verilog-declaration-re-1-no-macro) e 'move)
6709 (progn
6710 (goto-char (match-end 0))
6711 (verilog-backward-syntactic-ws)
6712 (if (> (current-column) ind)
6713 (setq ind (current-column)))
6714 (goto-char (match-end 0)))))
6715 (if (> ind 0)
6716 (1+ ind)
6717 ;; No lineup-string found
6718 (goto-char b)
6719 (end-of-line)
6720 (verilog-backward-syntactic-ws)
6721 ;;(skip-chars-backward " \t")
6722 (1+ (current-column))))))
6724 (defun verilog-get-lineup-indent-2 (myre b edpos)
6725 "Return the indent level that will line up several lines within the region."
6726 (save-excursion
6727 (let ((ind 0) e)
6728 (goto-char b)
6729 ;; Get rightmost position
6730 (while (progn (setq e (marker-position edpos))
6731 (< (point) e))
6732 (if (and (verilog-re-search-forward myre e 'move)
6733 (not (verilog-in-attribute-p))) ;; skip attribute exprs
6734 (progn
6735 (goto-char (match-beginning 2))
6736 (verilog-backward-syntactic-ws)
6737 (if (> (current-column) ind)
6738 (setq ind (current-column)))
6739 (goto-char (match-end 0)))
6741 (if (> ind 0)
6742 (1+ ind)
6743 ;; No lineup-string found
6744 (goto-char b)
6745 (end-of-line)
6746 (skip-chars-backward " \t")
6747 (1+ (current-column))))))
6749 (defun verilog-comment-depth (type val)
6750 "A useful mode debugging aide. TYPE and VAL are comments for insertion."
6751 (save-excursion
6752 (let
6753 ((b (prog2
6754 (beginning-of-line)
6755 (point-marker)
6756 (end-of-line)))
6757 (e (point-marker)))
6758 (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t)
6759 (progn
6760 (replace-match " /* -# ## */")
6761 (end-of-line))
6762 (progn
6763 (end-of-line)
6764 (insert " /* ## ## */"))))
6765 (backward-char 6)
6766 (insert
6767 (format "%s %d" type val))))
6769 ;; \f
6771 ;; Completion
6773 (defvar verilog-str nil)
6774 (defvar verilog-all nil)
6775 (defvar verilog-pred nil)
6776 (defvar verilog-buffer-to-use nil)
6777 (defvar verilog-flag nil)
6778 (defvar verilog-toggle-completions nil
6779 "True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
6780 Repeated use of \\[verilog-complete-word] will show you all of them.
6781 Normally, when there is more than one possible completion,
6782 it displays a list of all possible completions.")
6785 (defvar verilog-type-keywords
6787 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
6788 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
6789 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
6790 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
6791 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
6792 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
6794 "Keywords for types used when completing a word in a declaration or parmlist.
6795 \(integer, real, reg...)")
6797 (defvar verilog-cpp-keywords
6798 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
6799 "endif")
6800 "Keywords to complete when at first word of a line in declarative scope.
6801 \(initial, always, begin, assign...)
6802 The procedures and variables defined within the Verilog program
6803 will be completed at runtime and should not be added to this list.")
6805 (defvar verilog-defun-keywords
6806 (append
6808 "always" "always_comb" "always_ff" "always_latch" "assign"
6809 "begin" "end" "generate" "endgenerate" "module" "endmodule"
6810 "specify" "endspecify" "function" "endfunction" "initial" "final"
6811 "task" "endtask" "primitive" "endprimitive"
6813 verilog-type-keywords)
6814 "Keywords to complete when at first word of a line in declarative scope.
6815 \(initial, always, begin, assign...)
6816 The procedures and variables defined within the Verilog program
6817 will be completed at runtime and should not be added to this list.")
6819 (defvar verilog-block-keywords
6821 "begin" "break" "case" "continue" "else" "end" "endfunction"
6822 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
6823 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
6824 "while")
6825 "Keywords to complete when at first word of a line in behavioral scope.
6826 \(begin, if, then, else, for, fork...)
6827 The procedures and variables defined within the Verilog program
6828 will be completed at runtime and should not be added to this list.")
6830 (defvar verilog-tf-keywords
6831 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
6832 "Keywords to complete when at first word of a line in a task or function.
6833 \(begin, if, then, else, for, fork.)
6834 The procedures and variables defined within the Verilog program
6835 will be completed at runtime and should not be added to this list.")
6837 (defvar verilog-case-keywords
6838 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
6839 "Keywords to complete when at first word of a line in case scope.
6840 \(begin, if, then, else, for, fork...)
6841 The procedures and variables defined within the Verilog program
6842 will be completed at runtime and should not be added to this list.")
6844 (defvar verilog-separator-keywords
6845 '("else" "then" "begin")
6846 "Keywords to complete when NOT standing at the first word of a statement.
6847 \(else, then, begin...)
6848 Variables and function names defined within the Verilog program
6849 will be completed at runtime and should not be added to this list.")
6851 (defvar verilog-gate-ios
6852 ;; All these have an implied {"input"...} at the end
6853 '(("and" "output")
6854 ("buf" "output")
6855 ("bufif0" "output")
6856 ("bufif1" "output")
6857 ("cmos" "output")
6858 ("nand" "output")
6859 ("nmos" "output")
6860 ("nor" "output")
6861 ("not" "output")
6862 ("notif0" "output")
6863 ("notif1" "output")
6864 ("or" "output")
6865 ("pmos" "output")
6866 ("pulldown" "output")
6867 ("pullup" "output")
6868 ("rcmos" "output")
6869 ("rnmos" "output")
6870 ("rpmos" "output")
6871 ("rtran" "inout" "inout")
6872 ("rtranif0" "inout" "inout")
6873 ("rtranif1" "inout" "inout")
6874 ("tran" "inout" "inout")
6875 ("tranif0" "inout" "inout")
6876 ("tranif1" "inout" "inout")
6877 ("xnor" "output")
6878 ("xor" "output"))
6879 "Map of direction for each positional argument to each gate primitive.")
6881 (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
6882 "Keywords for gate primitives.")
6884 (defun verilog-string-diff (str1 str2)
6885 "Return index of first letter where STR1 and STR2 differs."
6886 (catch 'done
6887 (let ((diff 0))
6888 (while t
6889 (if (or (> (1+ diff) (length str1))
6890 (> (1+ diff) (length str2)))
6891 (throw 'done diff))
6892 (or (equal (aref str1 diff) (aref str2 diff))
6893 (throw 'done diff))
6894 (setq diff (1+ diff))))))
6896 ;; Calculate all possible completions for functions if argument is `function',
6897 ;; completions for procedures if argument is `procedure' or both functions and
6898 ;; procedures otherwise.
6900 (defun verilog-func-completion (type)
6901 "Build regular expression for module/task/function names.
6902 TYPE is 'module, 'tf for task or function, or t if unknown."
6903 (if (string= verilog-str "")
6904 (setq verilog-str "[a-zA-Z_]"))
6905 (let ((verilog-str (concat (cond
6906 ((eq type 'module) "\\<\\(module\\)\\s +")
6907 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
6908 (t "\\<\\(task\\|function\\|module\\)\\s +"))
6909 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
6910 match)
6912 (if (not (looking-at verilog-defun-re))
6913 (verilog-re-search-backward verilog-defun-re nil t))
6914 (forward-char 1)
6916 ;; Search through all reachable functions
6917 (goto-char (point-min))
6918 (while (verilog-re-search-forward verilog-str (point-max) t)
6919 (progn (setq match (buffer-substring (match-beginning 2)
6920 (match-end 2)))
6921 (if (or (null verilog-pred)
6922 (funcall verilog-pred match))
6923 (setq verilog-all (cons match verilog-all)))))
6924 (if (match-beginning 0)
6925 (goto-char (match-beginning 0)))))
6927 (defun verilog-get-completion-decl (end)
6928 "Macro for searching through current declaration (var, type or const)
6929 for matches of `str' and adding the occurrence tp `all' through point END."
6930 (let ((re (or (and verilog-indent-declaration-macros
6931 verilog-declaration-re-2-macro)
6932 verilog-declaration-re-2-no-macro))
6933 decl-end match)
6934 ;; Traverse lines
6935 (while (and (< (point) end)
6936 (verilog-re-search-forward re end t))
6937 ;; Traverse current line
6938 (setq decl-end (save-excursion (verilog-declaration-end)))
6939 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
6940 (not (match-end 1)))
6941 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
6942 (if (string-match (concat "\\<" verilog-str) match)
6943 (if (or (null verilog-pred)
6944 (funcall verilog-pred match))
6945 (setq verilog-all (cons match verilog-all)))))
6946 (forward-line 1)))
6947 verilog-all)
6949 (defun verilog-type-completion ()
6950 "Calculate all possible completions for types."
6951 (let ((start (point))
6952 goon)
6953 ;; Search for all reachable type declarations
6954 (while (or (verilog-beg-of-defun)
6955 (setq goon (not goon)))
6956 (save-excursion
6957 (if (and (< start (prog1 (save-excursion (verilog-end-of-defun)
6958 (point))
6959 (forward-char 1)))
6960 (verilog-re-search-forward
6961 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
6962 start t)
6963 (not (match-end 1)))
6964 ;; Check current type declaration
6965 (verilog-get-completion-decl start))))))
6967 (defun verilog-var-completion ()
6968 "Calculate all possible completions for variables (or constants)."
6969 (let ((start (point)))
6970 ;; Search for all reachable var declarations
6971 (verilog-beg-of-defun)
6972 (save-excursion
6973 ;; Check var declarations
6974 (verilog-get-completion-decl start))))
6976 (defun verilog-keyword-completion (keyword-list)
6977 "Give list of all possible completions of keywords in KEYWORD-LIST."
6978 (mapcar (lambda (s)
6979 (if (string-match (concat "\\<" verilog-str) s)
6980 (if (or (null verilog-pred)
6981 (funcall verilog-pred s))
6982 (setq verilog-all (cons s verilog-all)))))
6983 keyword-list))
6986 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
6987 "Function passed to `completing-read', `try-completion' or `all-completions'.
6988 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
6989 must be a function to be called for every match to check if this should
6990 really be a match. If VERILOG-FLAG is t, the function returns a list of
6991 all possible completions. If VERILOG-FLAG is nil it returns a string,
6992 the longest possible completion, or t if VERILOG-STR is an exact match.
6993 If VERILOG-FLAG is 'lambda, the function returns t if VERILOG-STR is an
6994 exact match, nil otherwise."
6995 (save-excursion
6996 (let ((verilog-all nil))
6997 ;; Set buffer to use for searching labels. This should be set
6998 ;; within functions which use verilog-completions
6999 (set-buffer verilog-buffer-to-use)
7001 ;; Determine what should be completed
7002 (let ((state (car (verilog-calculate-indent))))
7003 (cond ((eq state 'defun)
7004 (save-excursion (verilog-var-completion))
7005 (verilog-func-completion 'module)
7006 (verilog-keyword-completion verilog-defun-keywords))
7008 ((eq state 'behavioral)
7009 (save-excursion (verilog-var-completion))
7010 (verilog-func-completion 'module)
7011 (verilog-keyword-completion verilog-defun-keywords))
7013 ((eq state 'block)
7014 (save-excursion (verilog-var-completion))
7015 (verilog-func-completion 'tf)
7016 (verilog-keyword-completion verilog-block-keywords))
7018 ((eq state 'case)
7019 (save-excursion (verilog-var-completion))
7020 (verilog-func-completion 'tf)
7021 (verilog-keyword-completion verilog-case-keywords))
7023 ((eq state 'tf)
7024 (save-excursion (verilog-var-completion))
7025 (verilog-func-completion 'tf)
7026 (verilog-keyword-completion verilog-tf-keywords))
7028 ((eq state 'cpp)
7029 (save-excursion (verilog-var-completion))
7030 (verilog-keyword-completion verilog-cpp-keywords))
7032 ((eq state 'cparenexp)
7033 (save-excursion (verilog-var-completion)))
7035 (t;--Anywhere else
7036 (save-excursion (verilog-var-completion))
7037 (verilog-func-completion 'both)
7038 (verilog-keyword-completion verilog-separator-keywords))))
7040 ;; Now we have built a list of all matches. Give response to caller
7041 (verilog-completion-response))))
7043 (defun verilog-completion-response ()
7044 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
7045 ;; This was not called by all-completions
7046 (if (null verilog-all)
7047 ;; Return nil if there was no matching label
7049 ;; Get longest string common in the labels
7050 (let* ((elm (cdr verilog-all))
7051 (match (car verilog-all))
7052 (min (length match))
7053 tmp)
7054 (if (string= match verilog-str)
7055 ;; Return t if first match was an exact match
7056 (setq match t)
7057 (while (not (null elm))
7058 ;; Find longest common string
7059 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
7060 (progn
7061 (setq min tmp)
7062 (setq match (substring match 0 min))))
7063 ;; Terminate with match=t if this is an exact match
7064 (if (string= (car elm) verilog-str)
7065 (progn
7066 (setq match t)
7067 (setq elm nil))
7068 (setq elm (cdr elm)))))
7069 ;; If this is a test just for exact match, return nil ot t
7070 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
7072 match))))
7073 ;; If flag is t, this was called by all-completions. Return
7074 ;; list of all possible completions
7075 (verilog-flag
7076 verilog-all)))
7078 (defvar verilog-last-word-numb 0)
7079 (defvar verilog-last-word-shown nil)
7080 (defvar verilog-last-completions nil)
7082 (defun verilog-complete-word ()
7083 "Complete word at current point.
7084 \(See also `verilog-toggle-completions', `verilog-type-keywords',
7085 and `verilog-separator-keywords'.)"
7086 (interactive)
7087 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7088 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7089 (verilog-str (buffer-substring b e))
7090 ;; The following variable is used in verilog-completion
7091 (verilog-buffer-to-use (current-buffer))
7092 (allcomp (if (and verilog-toggle-completions
7093 (string= verilog-last-word-shown verilog-str))
7094 verilog-last-completions
7095 (all-completions verilog-str 'verilog-completion)))
7096 (match (if verilog-toggle-completions
7097 "" (try-completion
7098 verilog-str (mapcar (lambda (elm)
7099 (cons elm 0)) allcomp)))))
7100 ;; Delete old string
7101 (delete-region b e)
7103 ;; Toggle-completions inserts whole labels
7104 (if verilog-toggle-completions
7105 (progn
7106 ;; Update entry number in list
7107 (setq verilog-last-completions allcomp
7108 verilog-last-word-numb
7109 (if (>= verilog-last-word-numb (1- (length allcomp)))
7111 (1+ verilog-last-word-numb)))
7112 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
7113 ;; Display next match or same string if no match was found
7114 (if (not (null allcomp))
7115 (insert "" verilog-last-word-shown)
7116 (insert "" verilog-str)
7117 (message "(No match)")))
7118 ;; The other form of completion does not necessarily do that.
7120 ;; Insert match if found, or the original string if no match
7121 (if (or (null match) (equal match 't))
7122 (progn (insert "" verilog-str)
7123 (message "(No match)"))
7124 (insert "" match))
7125 ;; Give message about current status of completion
7126 (cond ((equal match 't)
7127 (if (not (null (cdr allcomp)))
7128 (message "(Complete but not unique)")
7129 (message "(Sole completion)")))
7130 ;; Display buffer if the current completion didn't help
7131 ;; on completing the label.
7132 ((and (not (null (cdr allcomp))) (= (length verilog-str)
7133 (length match)))
7134 (with-output-to-temp-buffer "*Completions*"
7135 (display-completion-list allcomp))
7136 ;; Wait for a key press. Then delete *Completion* window
7137 (momentary-string-display "" (point))
7138 (delete-window (get-buffer-window (get-buffer "*Completions*")))
7139 )))))
7141 (defun verilog-show-completions ()
7142 "Show all possible completions at current point."
7143 (interactive)
7144 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7145 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7146 (verilog-str (buffer-substring b e))
7147 ;; The following variable is used in verilog-completion
7148 (verilog-buffer-to-use (current-buffer))
7149 (allcomp (if (and verilog-toggle-completions
7150 (string= verilog-last-word-shown verilog-str))
7151 verilog-last-completions
7152 (all-completions verilog-str 'verilog-completion))))
7153 ;; Show possible completions in a temporary buffer.
7154 (with-output-to-temp-buffer "*Completions*"
7155 (display-completion-list allcomp))
7156 ;; Wait for a key press. Then delete *Completion* window
7157 (momentary-string-display "" (point))
7158 (delete-window (get-buffer-window (get-buffer "*Completions*")))))
7161 (defun verilog-get-default-symbol ()
7162 "Return symbol around current point as a string."
7163 (save-excursion
7164 (buffer-substring (progn
7165 (skip-chars-backward " \t")
7166 (skip-chars-backward "a-zA-Z0-9_")
7167 (point))
7168 (progn
7169 (skip-chars-forward "a-zA-Z0-9_")
7170 (point)))))
7172 (defun verilog-build-defun-re (str &optional arg)
7173 "Return function/task/module starting with STR as regular expression.
7174 With optional second ARG non-nil, STR is the complete name of the instruction."
7175 (if arg
7176 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
7177 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
7179 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
7180 "Function passed to `completing-read', `try-completion' or `all-completions'.
7181 Returns a completion on any function name based on VERILOG-STR prefix. If
7182 VERILOG-PRED is non-nil, it must be a function to be called for every match
7183 to check if this should really be a match. If VERILOG-FLAG is t, the
7184 function returns a list of all possible completions. If it is nil it
7185 returns a string, the longest possible completion, or t if VERILOG-STR is
7186 an exact match. If VERILOG-FLAG is 'lambda, the function returns t if
7187 VERILOG-STR is an exact match, nil otherwise."
7188 (save-excursion
7189 (let ((verilog-all nil)
7190 match)
7192 ;; Set buffer to use for searching labels. This should be set
7193 ;; within functions which use verilog-completions
7194 (set-buffer verilog-buffer-to-use)
7196 (let ((verilog-str verilog-str))
7197 ;; Build regular expression for functions
7198 (if (string= verilog-str "")
7199 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
7200 (setq verilog-str (verilog-build-defun-re verilog-str)))
7201 (goto-char (point-min))
7203 ;; Build a list of all possible completions
7204 (while (verilog-re-search-forward verilog-str nil t)
7205 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
7206 (if (or (null verilog-pred)
7207 (funcall verilog-pred match))
7208 (setq verilog-all (cons match verilog-all)))))
7210 ;; Now we have built a list of all matches. Give response to caller
7211 (verilog-completion-response))))
7213 (defun verilog-goto-defun ()
7214 "Move to specified Verilog module/interface/task/function.
7215 The default is a name found in the buffer around point.
7216 If search fails, other files are checked based on
7217 `verilog-library-flags'."
7218 (interactive)
7219 (let* ((default (verilog-get-default-symbol))
7220 ;; The following variable is used in verilog-comp-function
7221 (verilog-buffer-to-use (current-buffer))
7222 (label (if (not (string= default ""))
7223 ;; Do completion with default
7224 (completing-read (concat "Goto-Label: (default "
7225 default ") ")
7226 'verilog-comp-defun nil nil "")
7227 ;; There is no default value. Complete without it
7228 (completing-read "Goto-Label: "
7229 'verilog-comp-defun nil nil "")))
7231 ;; Make sure library paths are correct, in case need to resolve module
7232 (verilog-auto-reeval-locals)
7233 (verilog-getopt-flags)
7234 ;; If there was no response on prompt, use default value
7235 (if (string= label "")
7236 (setq label default))
7237 ;; Goto right place in buffer if label is not an empty string
7238 (or (string= label "")
7239 (progn
7240 (save-excursion
7241 (goto-char (point-min))
7242 (setq pt
7243 (re-search-forward (verilog-build-defun-re label t) nil t)))
7244 (when pt
7245 (goto-char pt)
7246 (beginning-of-line))
7248 (verilog-goto-defun-file label))))
7250 ;; Eliminate compile warning
7251 (defvar occur-pos-list)
7253 (defun verilog-showscopes ()
7254 "List all scopes in this module."
7255 (interactive)
7256 (let ((buffer (current-buffer))
7257 (linenum 1)
7258 (nlines 0)
7259 (first 1)
7260 (prevpos (point-min))
7261 (final-context-start (make-marker))
7262 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
7263 (with-output-to-temp-buffer "*Occur*"
7264 (save-excursion
7265 (message (format "Searching for %s ..." regexp))
7266 ;; Find next match, but give up if prev match was at end of buffer.
7267 (while (and (not (= prevpos (point-max)))
7268 (verilog-re-search-forward regexp nil t))
7269 (goto-char (match-beginning 0))
7270 (beginning-of-line)
7271 (save-match-data
7272 (setq linenum (+ linenum (count-lines prevpos (point)))))
7273 (setq prevpos (point))
7274 (goto-char (match-end 0))
7275 (let* ((start (save-excursion
7276 (goto-char (match-beginning 0))
7277 (forward-line (if (< nlines 0) nlines (- nlines)))
7278 (point)))
7279 (end (save-excursion
7280 (goto-char (match-end 0))
7281 (if (> nlines 0)
7282 (forward-line (1+ nlines))
7283 (forward-line 1))
7284 (point)))
7285 (tag (format "%3d" linenum))
7286 (empty (make-string (length tag) ?\ ))
7287 tem)
7288 (save-excursion
7289 (setq tem (make-marker))
7290 (set-marker tem (point))
7291 (set-buffer standard-output)
7292 (setq occur-pos-list (cons tem occur-pos-list))
7293 (or first (zerop nlines)
7294 (insert "--------\n"))
7295 (setq first nil)
7296 (insert-buffer-substring buffer start end)
7297 (backward-char (- end start))
7298 (setq tem (if (< nlines 0) (- nlines) nlines))
7299 (while (> tem 0)
7300 (insert empty ?:)
7301 (forward-line 1)
7302 (setq tem (1- tem)))
7303 (let ((this-linenum linenum))
7304 (set-marker final-context-start
7305 (+ (point) (- (match-end 0) (match-beginning 0))))
7306 (while (< (point) final-context-start)
7307 (if (null tag)
7308 (setq tag (format "%3d" this-linenum)))
7309 (insert tag ?:)))))))
7310 (set-buffer-modified-p nil))))
7313 ;; Highlight helper functions
7314 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
7315 (defun verilog-within-translate-off ()
7316 "Return point if within translate-off region, else nil."
7317 (and (save-excursion
7318 (re-search-backward
7319 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
7320 nil t))
7321 (equal "off" (match-string 2))
7322 (point)))
7324 (defun verilog-start-translate-off (limit)
7325 "Return point before translate-off directive if before LIMIT, else nil."
7326 (when (re-search-forward
7327 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7328 limit t)
7329 (match-beginning 0)))
7331 (defun verilog-back-to-start-translate-off (limit)
7332 "Return point before translate-off directive if before LIMIT, else nil."
7333 (when (re-search-backward
7334 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7335 limit t)
7336 (match-beginning 0)))
7338 (defun verilog-end-translate-off (limit)
7339 "Return point after translate-on directive if before LIMIT, else nil."
7341 (re-search-forward (concat
7342 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
7344 (defun verilog-match-translate-off (limit)
7345 "Match a translate-off block, setting `match-data' and returning t, else nil.
7346 Bound search by LIMIT."
7347 (when (< (point) limit)
7348 (let ((start (or (verilog-within-translate-off)
7349 (verilog-start-translate-off limit)))
7350 (case-fold-search t))
7351 (when start
7352 (let ((end (or (verilog-end-translate-off limit) limit)))
7353 (set-match-data (list start end))
7354 (goto-char end))))))
7356 (defun verilog-font-lock-match-item (limit)
7357 "Match, and move over, any declaration item after point.
7358 Bound search by LIMIT. Adapted from
7359 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
7360 (condition-case nil
7361 (save-restriction
7362 (narrow-to-region (point-min) limit)
7363 ;; match item
7364 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
7365 (save-match-data
7366 (goto-char (match-end 1))
7367 ;; move to next item
7368 (if (looking-at "\\(\\s-*,\\)")
7369 (goto-char (match-end 1))
7370 (end-of-line) t))))
7371 (error nil)))
7374 ;; Added by Subbu Meiyappan for Header
7376 (defun verilog-header ()
7377 "Insert a standard Verilog file header.
7378 See also `verilog-sk-header' for an alternative format."
7379 (interactive)
7380 (let ((start (point)))
7381 (insert "\
7382 //-----------------------------------------------------------------------------
7383 // Title : <title>
7384 // Project : <project>
7385 //-----------------------------------------------------------------------------
7386 // File : <filename>
7387 // Author : <author>
7388 // Created : <credate>
7389 // Last modified : <moddate>
7390 //-----------------------------------------------------------------------------
7391 // Description :
7392 // <description>
7393 //-----------------------------------------------------------------------------
7394 // Copyright (c) <copydate> by <company> This model is the confidential and
7395 // proprietary property of <company> and the possession or use of this
7396 // file requires a written license from <company>.
7397 //------------------------------------------------------------------------------
7398 // Modification history :
7399 // <modhist>
7400 //-----------------------------------------------------------------------------
7403 (goto-char start)
7404 (search-forward "<filename>")
7405 (replace-match (buffer-name) t t)
7406 (search-forward "<author>") (replace-match "" t t)
7407 (insert (user-full-name))
7408 (insert " <" (user-login-name) "@" (system-name) ">")
7409 (search-forward "<credate>") (replace-match "" t t)
7410 (verilog-insert-date)
7411 (search-forward "<moddate>") (replace-match "" t t)
7412 (verilog-insert-date)
7413 (search-forward "<copydate>") (replace-match "" t t)
7414 (verilog-insert-year)
7415 (search-forward "<modhist>") (replace-match "" t t)
7416 (verilog-insert-date)
7417 (insert " : created")
7418 (goto-char start)
7419 (let (string)
7420 (setq string (read-string "title: "))
7421 (search-forward "<title>")
7422 (replace-match string t t)
7423 (setq string (read-string "project: " verilog-project))
7424 (setq verilog-project string)
7425 (search-forward "<project>")
7426 (replace-match string t t)
7427 (setq string (read-string "Company: " verilog-company))
7428 (setq verilog-company string)
7429 (search-forward "<company>")
7430 (replace-match string t t)
7431 (search-forward "<company>")
7432 (replace-match string t t)
7433 (search-forward "<company>")
7434 (replace-match string t t)
7435 (search-backward "<description>")
7436 (replace-match "" t t))))
7438 ;; verilog-header Uses the verilog-insert-date function
7440 (defun verilog-insert-date ()
7441 "Insert date from the system."
7442 (interactive)
7443 (if verilog-date-scientific-format
7444 (insert (format-time-string "%Y/%m/%d"))
7445 (insert (format-time-string "%d.%m.%Y"))))
7447 (defun verilog-insert-year ()
7448 "Insert year from the system."
7449 (interactive)
7450 (insert (format-time-string "%Y")))
7454 ;; Signal list parsing
7457 ;; Elements of a signal list
7458 ;; Unfortunately we use 'assoc' on this, so can't be a vector
7459 (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
7460 (list name bits comment mem enum signed type multidim modport))
7461 (defsubst verilog-sig-name (sig)
7462 (car sig))
7463 (defsubst verilog-sig-bits (sig)
7464 (nth 1 sig))
7465 (defsubst verilog-sig-comment (sig)
7466 (nth 2 sig))
7467 (defsubst verilog-sig-memory (sig)
7468 (nth 3 sig))
7469 (defsubst verilog-sig-enum (sig)
7470 (nth 4 sig))
7471 (defsubst verilog-sig-signed (sig)
7472 (nth 5 sig))
7473 (defsubst verilog-sig-type (sig)
7474 (nth 6 sig))
7475 (defsubst verilog-sig-type-set (sig type)
7476 (setcar (nthcdr 6 sig) type))
7477 (defsubst verilog-sig-multidim (sig)
7478 (nth 7 sig))
7479 (defsubst verilog-sig-multidim-string (sig)
7480 (if (verilog-sig-multidim sig)
7481 (let ((str "") (args (verilog-sig-multidim sig)))
7482 (while args
7483 (setq str (concat str (car args)))
7484 (setq args (cdr args)))
7485 str)))
7486 (defsubst verilog-sig-modport (sig)
7487 (nth 8 sig))
7488 (defsubst verilog-sig-width (sig)
7489 (verilog-make-width-expression (verilog-sig-bits sig)))
7491 (defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
7492 (vector outputs-del outputs-imm temps inputs))
7493 (defsubst verilog-alw-get-outputs-delayed (sigs)
7494 (aref sigs 0))
7495 (defsubst verilog-alw-get-outputs-immediate (sigs)
7496 (aref sigs 1))
7497 (defsubst verilog-alw-get-temps (sigs)
7498 (aref sigs 2))
7499 (defsubst verilog-alw-get-inputs (sigs)
7500 (aref sigs 3))
7501 (defsubst verilog-alw-get-uses-delayed (sigs)
7502 (aref sigs 0))
7504 (defsubst verilog-modport-new (name clockings decls)
7505 (list name clockings decls))
7506 (defsubst verilog-modport-name (sig)
7507 (car sig))
7508 (defsubst verilog-modport-clockings (sig)
7509 (nth 1 sig)) ;; Returns list of names
7510 (defsubst verilog-modport-clockings-add (sig val)
7511 (setcar (nthcdr 1 sig) (cons val (nth 1 sig))))
7512 (defsubst verilog-modport-decls (sig)
7513 (nth 2 sig)) ;; Returns verilog-decls-* structure
7514 (defsubst verilog-modport-decls-set (sig val)
7515 (setcar (nthcdr 2 sig) val))
7517 (defsubst verilog-modi-new (name fob pt type)
7518 (vector name fob pt type))
7519 (defsubst verilog-modi-name (modi)
7520 (aref modi 0))
7521 (defsubst verilog-modi-file-or-buffer (modi)
7522 (aref modi 1))
7523 (defsubst verilog-modi-get-point (modi)
7524 (aref modi 2))
7525 (defsubst verilog-modi-get-type (modi) ;; "module" or "interface"
7526 (aref modi 3))
7527 (defsubst verilog-modi-get-decls (modi)
7528 (verilog-modi-cache-results modi 'verilog-read-decls))
7529 (defsubst verilog-modi-get-sub-decls (modi)
7530 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
7532 ;; Signal reading for given module
7533 ;; Note these all take modi's - as returned from verilog-modi-current
7534 (defsubst verilog-decls-new (out inout in vars modports assigns consts gparams interfaces)
7535 (vector out inout in vars modports assigns consts gparams interfaces))
7536 (defsubst verilog-decls-append (a b)
7537 (cond ((not a) b) ((not b) a)
7538 (t (vector (append (aref a 0) (aref b 0)) (append (aref a 1) (aref b 1))
7539 (append (aref a 2) (aref b 2)) (append (aref a 3) (aref b 3))
7540 (append (aref a 4) (aref b 4)) (append (aref a 5) (aref b 5))
7541 (append (aref a 6) (aref b 6)) (append (aref a 7) (aref b 7))
7542 (append (aref a 8) (aref b 8))))))
7543 (defsubst verilog-decls-get-outputs (decls)
7544 (aref decls 0))
7545 (defsubst verilog-decls-get-inouts (decls)
7546 (aref decls 1))
7547 (defsubst verilog-decls-get-inputs (decls)
7548 (aref decls 2))
7549 (defsubst verilog-decls-get-vars (decls)
7550 (aref decls 3))
7551 (defsubst verilog-decls-get-modports (decls) ;; Also for clocking blocks; contains another verilog-decls struct
7552 (aref decls 4)) ;; Returns verilog-modport* structure
7553 (defsubst verilog-decls-get-assigns (decls)
7554 (aref decls 5))
7555 (defsubst verilog-decls-get-consts (decls)
7556 (aref decls 6))
7557 (defsubst verilog-decls-get-gparams (decls)
7558 (aref decls 7))
7559 (defsubst verilog-decls-get-interfaces (decls)
7560 (aref decls 8))
7563 (defsubst verilog-subdecls-new (out inout in intf intfd)
7564 (vector out inout in intf intfd))
7565 (defsubst verilog-subdecls-get-outputs (subdecls)
7566 (aref subdecls 0))
7567 (defsubst verilog-subdecls-get-inouts (subdecls)
7568 (aref subdecls 1))
7569 (defsubst verilog-subdecls-get-inputs (subdecls)
7570 (aref subdecls 2))
7571 (defsubst verilog-subdecls-get-interfaces (subdecls)
7572 (aref subdecls 3))
7573 (defsubst verilog-subdecls-get-interfaced (subdecls)
7574 (aref subdecls 4))
7576 (defun verilog-signals-from-signame (signame-list)
7577 "Return signals in standard form from SIGNAME-LIST, a simple list of names."
7578 (mapcar (lambda (name) (verilog-sig-new name nil nil nil nil nil nil nil nil))
7579 signame-list))
7581 (defun verilog-signals-in (in-list not-list)
7582 "Return list of signals in IN-LIST that are also in NOT-LIST.
7583 Also remove any duplicates in IN-LIST.
7584 Signals must be in standard (base vector) form."
7585 ;; This function is hot, so implemented as O(1)
7586 (cond ((eval-when-compile (fboundp 'make-hash-table))
7587 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
7588 (ht-not (make-hash-table :test 'equal :rehash-size 4.0))
7589 out-list)
7590 (while not-list
7591 (puthash (car (car not-list)) t ht-not)
7592 (setq not-list (cdr not-list)))
7593 (while in-list
7594 (when (and (gethash (verilog-sig-name (car in-list)) ht-not)
7595 (not (gethash (verilog-sig-name (car in-list)) ht)))
7596 (setq out-list (cons (car in-list) out-list))
7597 (puthash (verilog-sig-name (car in-list)) t ht))
7598 (setq in-list (cdr in-list)))
7599 (nreverse out-list)))
7600 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
7602 (let (out-list)
7603 (while in-list
7604 (if (and (assoc (verilog-sig-name (car in-list)) not-list)
7605 (not (assoc (verilog-sig-name (car in-list)) out-list)))
7606 (setq out-list (cons (car in-list) out-list)))
7607 (setq in-list (cdr in-list)))
7608 (nreverse out-list)))))
7609 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("C" "")))
7611 (defun verilog-signals-not-in (in-list not-list)
7612 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
7613 Also remove any duplicates in IN-LIST.
7614 Signals must be in standard (base vector) form."
7615 ;; This function is hot, so implemented as O(1)
7616 (cond ((eval-when-compile (fboundp 'make-hash-table))
7617 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
7618 out-list)
7619 (while not-list
7620 (puthash (car (car not-list)) t ht)
7621 (setq not-list (cdr not-list)))
7622 (while in-list
7623 (when (not (gethash (verilog-sig-name (car in-list)) ht))
7624 (setq out-list (cons (car in-list) out-list))
7625 (puthash (verilog-sig-name (car in-list)) t ht))
7626 (setq in-list (cdr in-list)))
7627 (nreverse out-list)))
7628 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
7630 (let (out-list)
7631 (while in-list
7632 (if (and (not (assoc (verilog-sig-name (car in-list)) not-list))
7633 (not (assoc (verilog-sig-name (car in-list)) out-list)))
7634 (setq out-list (cons (car in-list) out-list)))
7635 (setq in-list (cdr in-list)))
7636 (nreverse out-list)))))
7637 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
7639 (defun verilog-signals-memory (in-list)
7640 "Return list of signals in IN-LIST that are memorized (multidimensional)."
7641 (let (out-list)
7642 (while in-list
7643 (if (nth 3 (car in-list))
7644 (setq out-list (cons (car in-list) out-list)))
7645 (setq in-list (cdr in-list)))
7646 out-list))
7647 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
7649 (defun verilog-signals-sort-compare (a b)
7650 "Compare signal A and B for sorting."
7651 (string< (verilog-sig-name a) (verilog-sig-name b)))
7653 (defun verilog-signals-not-params (in-list)
7654 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
7655 (let (out-list)
7656 (while in-list
7657 (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
7658 (setq out-list (cons (car in-list) out-list)))
7659 (setq in-list (cdr in-list)))
7660 (nreverse out-list)))
7662 (defun verilog-signals-with (func in-list)
7663 "Return IN-LIST with only signals where FUNC passed each signal is true."
7664 (let (out-list)
7665 (while in-list
7666 (when (funcall func (car in-list))
7667 (setq out-list (cons (car in-list) out-list)))
7668 (setq in-list (cdr in-list)))
7669 (nreverse out-list)))
7671 (defun verilog-signals-combine-bus (in-list)
7672 "Return a list of signals in IN-LIST, with buses combined.
7673 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
7674 (let (combo buswarn
7675 out-list
7676 sig highbit lowbit ; Temp information about current signal
7677 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
7678 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
7679 sv-modport
7680 bus)
7681 ;; Shove signals so duplicated signals will be adjacent
7682 (setq in-list (sort in-list `verilog-signals-sort-compare))
7683 (while in-list
7684 (setq sig (car in-list))
7685 ;; No current signal; form from existing details
7686 (unless sv-name
7687 (setq sv-name (verilog-sig-name sig)
7688 sv-highbit nil
7689 sv-busstring nil
7690 sv-comment (verilog-sig-comment sig)
7691 sv-memory (verilog-sig-memory sig)
7692 sv-enum (verilog-sig-enum sig)
7693 sv-signed (verilog-sig-signed sig)
7694 sv-type (verilog-sig-type sig)
7695 sv-multidim (verilog-sig-multidim sig)
7696 sv-modport (verilog-sig-modport sig)
7697 combo ""
7698 buswarn ""))
7699 ;; Extract bus details
7700 (setq bus (verilog-sig-bits sig))
7701 (setq bus (and bus (verilog-simplify-range-expression bus)))
7702 (cond ((and bus
7703 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
7704 (setq highbit (string-to-number (match-string 1 bus))
7705 lowbit (string-to-number
7706 (match-string 2 bus))))
7707 (and (string-match "\\[\\([0-9]+\\)\\]" bus)
7708 (setq highbit (string-to-number (match-string 1 bus))
7709 lowbit highbit))))
7710 ;; Combine bits in bus
7711 (if sv-highbit
7712 (setq sv-highbit (max highbit sv-highbit)
7713 sv-lowbit (min lowbit sv-lowbit))
7714 (setq sv-highbit highbit
7715 sv-lowbit lowbit)))
7716 (bus
7717 ;; String, probably something like `preproc:0
7718 (setq sv-busstring bus)))
7719 ;; Peek ahead to next signal
7720 (setq in-list (cdr in-list))
7721 (setq sig (car in-list))
7722 (cond ((and sig (equal sv-name (verilog-sig-name sig)))
7723 ;; Combine with this signal
7724 (when (and sv-busstring
7725 (not (equal sv-busstring (verilog-sig-bits sig))))
7726 (when nil ;; Debugging
7727 (message (concat "Warning, can't merge into single bus "
7728 sv-name bus
7729 ", the AUTOs may be wrong")))
7730 (setq buswarn ", Couldn't Merge"))
7731 (if (verilog-sig-comment sig) (setq combo ", ..."))
7732 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
7733 sv-enum (or sv-enum (verilog-sig-enum sig))
7734 sv-signed (or sv-signed (verilog-sig-signed sig))
7735 sv-type (or sv-type (verilog-sig-type sig))
7736 sv-multidim (or sv-multidim (verilog-sig-multidim sig))
7737 sv-modport (or sv-modport (verilog-sig-modport sig))))
7738 ;; Doesn't match next signal, add to queue, zero in prep for next
7739 ;; Note sig may also be nil for the last signal in the list
7741 (setq out-list
7742 (cons (verilog-sig-new
7743 sv-name
7744 (or sv-busstring
7745 (if sv-highbit
7746 (concat "[" (int-to-string sv-highbit) ":"
7747 (int-to-string sv-lowbit) "]")))
7748 (concat sv-comment combo buswarn)
7749 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
7750 out-list)
7751 sv-name nil))))
7753 out-list))
7755 (defun verilog-sig-tieoff (sig)
7756 "Return tieoff expression for given SIG, with appropriate width.
7757 Tieoff value uses `verilog-active-low-regexp' and
7758 `verilog-auto-reset-widths'."
7759 (concat
7760 (if (and verilog-active-low-regexp
7761 (string-match verilog-active-low-regexp (verilog-sig-name sig)))
7762 "~" "")
7763 (cond ((not verilog-auto-reset-widths)
7764 "0")
7765 ((equal verilog-auto-reset-widths 'unbased)
7766 "'0")
7767 ;; Else presume verilog-auto-reset-widths is true
7769 (let* ((width (verilog-sig-width sig)))
7770 (if (string-match "^[0-9]+$" width)
7771 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0"))
7772 (concat "{" width "{1'b0}}")))))))
7775 ;; Dumping
7778 (defun verilog-decls-princ (decls &optional header prefix)
7779 "For debug, dump the `verilog-read-decls' structure DECLS."
7780 (when decls
7781 (if header (princ header))
7782 (setq prefix (or prefix ""))
7783 (verilog-signals-princ (verilog-decls-get-outputs decls)
7784 (concat prefix "Outputs:\n") (concat prefix " "))
7785 (verilog-signals-princ (verilog-decls-get-inouts decls)
7786 (concat prefix "Inout:\n") (concat prefix " "))
7787 (verilog-signals-princ (verilog-decls-get-inputs decls)
7788 (concat prefix "Inputs:\n") (concat prefix " "))
7789 (verilog-signals-princ (verilog-decls-get-vars decls)
7790 (concat prefix "Vars:\n") (concat prefix " "))
7791 (verilog-signals-princ (verilog-decls-get-assigns decls)
7792 (concat prefix "Assigns:\n") (concat prefix " "))
7793 (verilog-signals-princ (verilog-decls-get-consts decls)
7794 (concat prefix "Consts:\n") (concat prefix " "))
7795 (verilog-signals-princ (verilog-decls-get-gparams decls)
7796 (concat prefix "Gparams:\n") (concat prefix " "))
7797 (verilog-signals-princ (verilog-decls-get-interfaces decls)
7798 (concat prefix "Interfaces:\n") (concat prefix " "))
7799 (verilog-modport-princ (verilog-decls-get-modports decls)
7800 (concat prefix "Modports:\n") (concat prefix " "))
7801 (princ "\n")))
7803 (defun verilog-signals-princ (signals &optional header prefix)
7804 "For debug, dump internal SIGNALS structures, with HEADER and PREFIX."
7805 (when signals
7806 (if header (princ header))
7807 (while signals
7808 (let ((sig (car signals)))
7809 (setq signals (cdr signals))
7810 (princ prefix)
7811 (princ "\"") (princ (verilog-sig-name sig)) (princ "\"")
7812 (princ " bits=") (princ (verilog-sig-bits sig))
7813 (princ " cmt=") (princ (verilog-sig-comment sig))
7814 (princ " mem=") (princ (verilog-sig-memory sig))
7815 (princ " enum=") (princ (verilog-sig-enum sig))
7816 (princ " sign=") (princ (verilog-sig-signed sig))
7817 (princ " type=") (princ (verilog-sig-type sig))
7818 (princ " dim=") (princ (verilog-sig-multidim sig))
7819 (princ " modp=") (princ (verilog-sig-modport sig))
7820 (princ "\n")))))
7822 (defun verilog-modport-princ (modports &optional header prefix)
7823 "For debug, dump internal MODPORT structures, with HEADER and PREFIX."
7824 (when modports
7825 (if header (princ header))
7826 (while modports
7827 (let ((sig (car modports)))
7828 (setq modports (cdr modports))
7829 (princ prefix)
7830 (princ "\"") (princ (verilog-modport-name sig)) (princ "\"")
7831 (princ " clockings=") (princ (verilog-modport-clockings sig))
7832 (princ "\n")
7833 (verilog-decls-princ (verilog-modport-decls sig)
7834 (concat prefix " syms:\n")
7835 (concat prefix " "))))))
7838 ;; Port/Wire/Etc Reading
7841 (defun verilog-read-inst-backward-name ()
7842 "Internal. Move point back to beginning of inst-name."
7843 (verilog-backward-open-paren)
7844 (let (done)
7845 (while (not done)
7846 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary
7847 (cond ((looking-at ")")
7848 (verilog-backward-open-paren))
7849 (t (setq done t)))))
7850 (while (looking-at "\\]")
7851 (verilog-backward-open-bracket)
7852 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil))
7853 (skip-chars-backward "a-zA-Z0-9`_$"))
7855 (defun verilog-read-inst-module-matcher ()
7856 "Set match data 0 with module_name when point is inside instantiation."
7857 (verilog-read-inst-backward-name)
7858 ;; Skip over instantiation name
7859 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
7860 ;; Check for parameterized instantiations
7861 (when (looking-at ")")
7862 (verilog-backward-open-paren)
7863 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil))
7864 (skip-chars-backward "a-zA-Z0-9'_$")
7865 (looking-at "[a-zA-Z0-9`_\$]+")
7866 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7867 (buffer-substring-no-properties (match-beginning 0) (match-end 0))
7868 ;; Caller assumes match-beginning/match-end is still set
7871 (defun verilog-read-inst-module ()
7872 "Return module_name when point is inside instantiation."
7873 (save-excursion
7874 (verilog-read-inst-module-matcher)))
7876 (defun verilog-read-inst-name ()
7877 "Return instance_name when point is inside instantiation."
7878 (save-excursion
7879 (verilog-read-inst-backward-name)
7880 (looking-at "[a-zA-Z0-9`_\$]+")
7881 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7882 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
7884 (defun verilog-read-module-name ()
7885 "Return module name when after its ( or ;."
7886 (save-excursion
7887 (re-search-backward "[(;]")
7888 ;; Due to "module x import y (" we must search for declaration begin
7889 (verilog-re-search-backward-quick verilog-defun-re nil nil)
7890 (goto-char (match-end 0))
7891 (verilog-re-search-forward-quick "\\b[a-zA-Z0-9`_\$]+" nil nil)
7892 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
7893 (verilog-symbol-detick
7894 (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
7896 (defun verilog-read-inst-param-value ()
7897 "Return list of parameters and values when point is inside instantiation."
7898 (save-excursion
7899 (verilog-read-inst-backward-name)
7900 ;; Skip over instantiation name
7901 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
7902 ;; If there are parameterized instantiations
7903 (when (looking-at ")")
7904 (let ((end-pt (point))
7905 params
7906 param-name paren-beg-pt param-value)
7907 (verilog-backward-open-paren)
7908 (while (verilog-re-search-forward-quick "\\." end-pt t)
7909 (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_\$]\\)" nil nil)
7910 (skip-chars-backward "a-zA-Z0-9'_$")
7911 (looking-at "[a-zA-Z0-9`_\$]+")
7912 (setq param-name (buffer-substring-no-properties
7913 (match-beginning 0) (match-end 0)))
7914 (verilog-re-search-forward-quick "(" nil nil)
7915 (setq paren-beg-pt (point))
7916 (verilog-forward-close-paren)
7917 (setq param-value (verilog-string-remove-spaces
7918 (buffer-substring-no-properties
7919 paren-beg-pt (1- (point)))))
7920 (setq params (cons (list param-name param-value) params)))
7921 params))))
7923 (defun verilog-read-auto-params (num-param &optional max-param)
7924 "Return parameter list inside auto.
7925 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
7926 (let ((olist))
7927 (save-excursion
7928 ;; /*AUTOPUNT("parameter", "parameter")*/
7929 (backward-sexp 1)
7930 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
7931 (setq olist (cons (match-string 1) olist))
7932 (goto-char (match-end 0))))
7933 (or (eq nil num-param)
7934 (<= num-param (length olist))
7935 (error "%s: Expected %d parameters" (verilog-point-text) num-param))
7936 (if (eq max-param nil) (setq max-param num-param))
7937 (or (eq nil max-param)
7938 (>= max-param (length olist))
7939 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
7940 (nreverse olist)))
7942 (defun verilog-read-decls ()
7943 "Compute signal declaration information for the current module at point.
7944 Return an array of [outputs inouts inputs wire reg assign const]."
7945 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
7946 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
7947 in-modport in-clocking ptype ign-prop
7948 sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
7949 sigs-gparam sigs-intf sigs-modports
7950 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
7951 modport
7952 varstack tmp)
7953 (save-excursion
7954 (verilog-beg-of-defun-quick)
7955 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
7956 (while (< (point) end-mod-point)
7957 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
7958 (cond
7959 ((looking-at "//")
7960 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7961 (setq enum (match-string 2)))
7962 (search-forward "\n"))
7963 ((looking-at "/\\*")
7964 (forward-char 2)
7965 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7966 (setq enum (match-string 2)))
7967 (or (search-forward "*/")
7968 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
7969 ((looking-at "(\\*")
7970 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
7971 (forward-char 1)
7972 (or (search-forward "*)")
7973 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
7974 ((eq ?\" (following-char))
7975 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first
7976 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
7977 ((eq ?\; (following-char))
7978 (when (and in-modport (not (eq in-modport t))) ;; end of a modport declaration
7979 (verilog-modport-decls-set
7980 in-modport
7981 (verilog-decls-new sigs-out sigs-inout sigs-in
7982 nil nil nil nil nil nil))
7983 ;; Pop from varstack to restore state to pre-clocking
7984 (setq tmp (car varstack)
7985 varstack (cdr varstack)
7986 sigs-out (aref tmp 0)
7987 sigs-inout (aref tmp 1)
7988 sigs-in (aref tmp 2)))
7989 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
7990 v2kargs-ok nil in-modport nil ign-prop nil)
7991 (forward-char 1))
7992 ((eq ?= (following-char))
7993 (setq rvalue t newsig nil)
7994 (forward-char 1))
7995 ((and (eq ?, (following-char))
7996 (eq paren sig-paren))
7997 (setq rvalue nil)
7998 (forward-char 1))
7999 ;; ,'s can occur inside {} & funcs
8000 ((looking-at "[{(]")
8001 (setq paren (1+ paren))
8002 (forward-char 1))
8003 ((looking-at "[})]")
8004 (setq paren (1- paren))
8005 (forward-char 1)
8006 (when (< paren sig-paren)
8007 (setq expect-signal nil))) ; ) that ends variables inside v2k arg list
8008 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
8009 (goto-char (match-end 0))
8010 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
8011 (setcar (cdr (cdr (cdr newsig)))
8012 (if (verilog-sig-memory newsig)
8013 (concat (verilog-sig-memory newsig) (match-string 1))
8014 (match-string 1))))
8015 (vec ;; Multidimensional
8016 (setq multidim (cons vec multidim))
8017 (setq vec (verilog-string-replace-matches
8018 "\\s-+" "" nil nil (match-string 1))))
8019 (t ;; Bit width
8020 (setq vec (verilog-string-replace-matches
8021 "\\s-+" "" nil nil (match-string 1))))))
8022 ;; Normal or escaped identifier -- note we remember the \ if escaped
8023 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8024 (goto-char (match-end 0))
8025 (setq keywd (match-string 1))
8026 (when (string-match "^\\\\" (match-string 1))
8027 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end
8028 ;; Add any :: package names to same identifier
8029 (while (looking-at "\\s-*::\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8030 (goto-char (match-end 0))
8031 (setq keywd (concat keywd "::" (match-string 1)))
8032 (when (string-match "^\\\\" (match-string 1))
8033 (setq keywd (concat keywd " ")))) ;; Escaped ID needs space at end
8034 (cond ((equal keywd "input")
8035 (setq vec nil enum nil rvalue nil newsig nil signed nil
8036 typedefed nil multidim nil ptype nil modport nil
8037 expect-signal 'sigs-in io t sig-paren paren))
8038 ((equal keywd "output")
8039 (setq vec nil enum nil rvalue nil newsig nil signed nil
8040 typedefed nil multidim nil ptype nil modport nil
8041 expect-signal 'sigs-out io t sig-paren paren))
8042 ((equal keywd "inout")
8043 (setq vec nil enum nil rvalue nil newsig nil signed nil
8044 typedefed nil multidim nil ptype nil modport nil
8045 expect-signal 'sigs-inout io t sig-paren paren))
8046 ((equal keywd "parameter")
8047 (setq vec nil enum nil rvalue nil signed nil
8048 typedefed nil multidim nil ptype nil modport nil
8049 expect-signal 'sigs-gparam io t sig-paren paren))
8050 ((member keywd '("wire" "reg" ; Fast
8051 ;; net_type
8052 "tri" "tri0" "tri1" "triand" "trior" "trireg"
8053 "uwire" "wand" "wor"
8054 ;; integer_atom_type
8055 "byte" "shortint" "int" "longint" "integer" "time"
8056 "supply0" "supply1"
8057 ;; integer_vector_type - "reg" above
8058 "bit" "logic"
8059 ;; non_integer_type
8060 "shortreal" "real" "realtime"
8061 ;; data_type
8062 "string" "event" "chandle"))
8063 (cond (io
8064 (setq typedefed
8065 (if typedefed (concat typedefed " " keywd) keywd)))
8066 (t (setq vec nil enum nil rvalue nil signed nil
8067 typedefed nil multidim nil sig-paren paren
8068 expect-signal 'sigs-var modport nil))))
8069 ((equal keywd "assign")
8070 (setq vec nil enum nil rvalue nil signed nil
8071 typedefed nil multidim nil ptype nil modport nil
8072 expect-signal 'sigs-assign sig-paren paren))
8073 ((member keywd '("localparam" "genvar"))
8074 (unless io
8075 (setq vec nil enum nil rvalue nil signed nil
8076 typedefed nil multidim nil ptype nil modport nil
8077 expect-signal 'sigs-const sig-paren paren)))
8078 ((member keywd '("signed" "unsigned"))
8079 (setq signed keywd))
8080 ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
8081 (setq ign-prop t))
8082 ((member keywd '("class" "covergroup" "function"
8083 "property" "randsequence" "sequence" "task"))
8084 (unless ign-prop
8085 (setq functask (1+ functask))))
8086 ((member keywd '("endclass" "endgroup" "endfunction"
8087 "endproperty" "endsequence" "endtask"))
8088 (setq functask (1- functask)))
8089 ((equal keywd "modport")
8090 (setq in-modport t))
8091 ((equal keywd "clocking")
8092 (setq in-clocking t))
8093 ((equal keywd "type")
8094 (setq ptype t))
8095 ;; Ifdef? Ignore name of define
8096 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8097 (setq rvalue t))
8098 ;; Type?
8099 ((unless ptype
8100 (verilog-typedef-name-p keywd))
8101 (setq typedefed keywd))
8102 ;; Interface with optional modport in v2k arglist?
8103 ;; Skip over parsing modport, and take the interface name as the type
8104 ((and v2kargs-ok
8105 (eq paren 1)
8106 (not rvalue)
8107 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
8108 (when (match-end 2) (goto-char (match-end 2)))
8109 (setq vec nil enum nil rvalue nil signed nil
8110 typedefed keywd multidim nil ptype nil modport (match-string 2)
8111 newsig nil sig-paren paren
8112 expect-signal 'sigs-intf io t ))
8113 ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
8114 ((looking-at "\\s-*\\.")
8115 (goto-char (match-end 0))
8116 (when (not rvalue)
8117 (setq expect-signal nil)))
8118 ;; "modport <keywd>"
8119 ((and (eq in-modport t)
8120 (not (member keywd verilog-keywords)))
8121 (setq in-modport (verilog-modport-new keywd nil nil))
8122 (setq sigs-modports (cons in-modport sigs-modports))
8123 ;; Push old sig values to stack and point to new signal list
8124 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8125 varstack))
8126 (setq sigs-in nil sigs-inout nil sigs-out nil))
8127 ;; "modport x (clocking <keywd>)"
8128 ((and in-modport in-clocking)
8129 (verilog-modport-clockings-add in-modport keywd)
8130 (setq in-clocking nil))
8131 ;; endclocking
8132 ((and in-clocking
8133 (equal keywd "endclocking"))
8134 (unless (eq in-clocking t)
8135 (verilog-modport-decls-set
8136 in-clocking
8137 (verilog-decls-new sigs-out sigs-inout sigs-in
8138 nil nil nil nil nil nil))
8139 ;; Pop from varstack to restore state to pre-clocking
8140 (setq tmp (car varstack)
8141 varstack (cdr varstack)
8142 sigs-out (aref tmp 0)
8143 sigs-inout (aref tmp 1)
8144 sigs-in (aref tmp 2)))
8145 (setq in-clocking nil))
8146 ;; "clocking <keywd>"
8147 ((and (eq in-clocking t)
8148 (not (member keywd verilog-keywords)))
8149 (setq in-clocking (verilog-modport-new keywd nil nil))
8150 (setq sigs-modports (cons in-clocking sigs-modports))
8151 ;; Push old sig values to stack and point to new signal list
8152 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8153 varstack))
8154 (setq sigs-in nil sigs-inout nil sigs-out nil))
8155 ;; New signal, maybe?
8156 ((and expect-signal
8157 (not rvalue)
8158 (eq functask 0)
8159 (not (member keywd verilog-keywords)))
8160 ;; Add new signal to expect-signal's variable
8161 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
8162 (set expect-signal (cons newsig
8163 (symbol-value expect-signal))))))
8165 (forward-char 1)))
8166 (skip-syntax-forward " "))
8167 ;; Return arguments
8168 (setq tmp (verilog-decls-new (nreverse sigs-out)
8169 (nreverse sigs-inout)
8170 (nreverse sigs-in)
8171 (nreverse sigs-var)
8172 (nreverse sigs-modports)
8173 (nreverse sigs-assign)
8174 (nreverse sigs-const)
8175 (nreverse sigs-gparam)
8176 (nreverse sigs-intf)))
8177 ;;(if dbg (verilog-decls-princ tmp))
8178 tmp)))
8180 (defvar verilog-read-sub-decls-in-interfaced nil
8181 "For `verilog-read-sub-decls', process next signal as under interfaced block.")
8183 (defvar verilog-read-sub-decls-gate-ios nil
8184 "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
8186 (eval-when-compile
8187 ;; Prevent compile warnings; these are let's, not globals
8188 ;; Do not remove the eval-when-compile
8189 ;; - we want an error when we are debugging this code if they are refed.
8190 (defvar sigs-in)
8191 (defvar sigs-inout)
8192 (defvar sigs-out)
8193 (defvar sigs-intf)
8194 (defvar sigs-intfd))
8196 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
8197 "For `verilog-read-sub-decls-line', add a signal."
8198 ;; sig eq t to indicate .name syntax
8199 ;;(message "vrsds: %s(%S)" port sig)
8200 (let ((dotname (eq sig t))
8201 portdata)
8202 (when sig
8203 (setq port (verilog-symbol-detick-denumber port))
8204 (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
8205 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
8206 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
8207 (unless (or (not sig)
8208 (equal sig "")) ;; Ignore .foo(1'b1) assignments
8209 (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
8210 (equal "inout" verilog-read-sub-decls-gate-ios))
8211 (setq sigs-inout
8212 (cons (verilog-sig-new
8214 (if dotname (verilog-sig-bits portdata) vec)
8215 (concat "To/From " comment)
8216 (verilog-sig-memory portdata)
8218 (verilog-sig-signed portdata)
8219 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8220 (verilog-sig-type portdata))
8221 multidim nil)
8222 sigs-inout)))
8223 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
8224 (equal "output" verilog-read-sub-decls-gate-ios))
8225 (setq sigs-out
8226 (cons (verilog-sig-new
8228 (if dotname (verilog-sig-bits portdata) vec)
8229 (concat "From " comment)
8230 (verilog-sig-memory portdata)
8232 (verilog-sig-signed portdata)
8233 ;; Though ok in SV, in V2K code, propagating the
8234 ;; "reg" in "output reg" upwards isn't legal.
8235 ;; Also for backwards compatibility we don't propagate
8236 ;; "input wire" upwards.
8237 ;; See also `verilog-signals-edit-wire-reg'.
8238 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8239 (verilog-sig-type portdata))
8240 multidim nil)
8241 sigs-out)))
8242 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
8243 (equal "input" verilog-read-sub-decls-gate-ios))
8244 (setq sigs-in
8245 (cons (verilog-sig-new
8247 (if dotname (verilog-sig-bits portdata) vec)
8248 (concat "To " comment)
8249 (verilog-sig-memory portdata)
8251 (verilog-sig-signed portdata)
8252 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8253 (verilog-sig-type portdata))
8254 multidim nil)
8255 sigs-in)))
8256 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
8257 (setq sigs-intf
8258 (cons (verilog-sig-new
8260 (if dotname (verilog-sig-bits portdata) vec)
8261 (concat "To/From " comment)
8262 (verilog-sig-memory portdata)
8264 (verilog-sig-signed portdata)
8265 (verilog-sig-type portdata)
8266 multidim nil)
8267 sigs-intf)))
8268 ((setq portdata (and verilog-read-sub-decls-in-interfaced
8269 (assoc port (verilog-decls-get-vars submoddecls))))
8270 (setq sigs-intfd
8271 (cons (verilog-sig-new
8273 (if dotname (verilog-sig-bits portdata) vec)
8274 (concat "To/From " comment)
8275 (verilog-sig-memory portdata)
8277 (verilog-sig-signed portdata)
8278 (verilog-sig-type portdata)
8279 multidim nil)
8280 sigs-intf)))
8281 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
8282 )))))
8284 (defun verilog-read-sub-decls-expr (submoddecls comment port expr)
8285 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
8286 ;;(message "vrsde: '%s'" expr)
8287 ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
8288 (setq expr (verilog-string-replace-matches "/\\*\\(\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
8289 ;; Remove front operators
8290 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8292 (cond
8293 ;; {..., a, b} requires us to recurse on a,b
8294 ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
8295 ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
8296 (unless verilog-auto-ignore-concat
8297 (let ((mlst (split-string (match-string 1 expr) "[{},]"))
8298 mstr)
8299 (while (setq mstr (pop mlst))
8300 (verilog-read-sub-decls-expr submoddecls comment port mstr)))))
8302 (let (sig vec multidim)
8303 ;; Remove leading reduction operators, etc
8304 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8305 ;;(message "vrsde-ptop: '%s'" expr)
8306 (cond ;; Find \signal. Final space is part of escaped signal name
8307 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
8308 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
8309 (setq sig (match-string 1 expr)
8310 expr (substring expr (match-end 0))))
8311 ;; Find signal
8312 ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
8313 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
8314 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
8315 expr (substring expr (match-end 0)))))
8316 ;; Find [vector] or [multi][multi][multi][vector]
8317 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
8318 ;;(message "vrsde-v: '%s'" (match-string 1 expr))
8319 (when vec (setq multidim (cons vec multidim)))
8320 (setq vec (match-string 1 expr)
8321 expr (substring expr (match-end 0))))
8322 ;; If found signal, and nothing unrecognized, add the signal
8323 ;;(message "vrsde-rem: '%s'" expr)
8324 (when (and sig (string-match "^\\s-*$" expr))
8325 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))))
8327 (defun verilog-read-sub-decls-line (submoddecls comment)
8328 "For `verilog-read-sub-decls', read lines of port defs until none match.
8329 Inserts the list of signals found, using submodi to look up each port."
8330 (let (done port)
8331 (save-excursion
8332 (forward-line 1)
8333 (while (not done)
8334 ;; Get port name
8335 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
8336 (setq port (match-string 1))
8337 (goto-char (match-end 0)))
8338 ;; .\escaped (
8339 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
8340 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space
8341 (goto-char (match-end 0)))
8342 ;; .name
8343 ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
8344 (verilog-read-sub-decls-sig
8345 submoddecls comment (match-string 1) t ; sig==t for .name
8346 nil nil) ; vec multidim
8347 (setq port nil))
8348 ;; .\escaped_name
8349 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
8350 (verilog-read-sub-decls-sig
8351 submoddecls comment (concat (match-string 1) " ") t ; sig==t for .name
8352 nil nil) ; vec multidim
8353 (setq port nil))
8354 ;; random
8355 ((looking-at "\\s-*\\.[^(]*(")
8356 (setq port nil) ;; skip this line
8357 (goto-char (match-end 0)))
8359 (setq port nil done t))) ;; Unknown, ignore rest of line
8360 ;; Get signal name. Point is at the first-non-space after (
8361 ;; We intentionally ignore (non-escaped) signals with .s in them
8362 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
8363 (when port
8364 (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
8365 (verilog-read-sub-decls-sig
8366 submoddecls comment port
8367 (verilog-string-remove-spaces (match-string 1)) ; sig
8368 nil nil)) ; vec multidim
8370 ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
8371 (verilog-read-sub-decls-sig
8372 submoddecls comment port
8373 (verilog-string-remove-spaces (match-string 1)) ; sig
8374 (match-string 2) nil)) ; vec multidim
8375 ;; Fastpath was above looking-at's.
8376 ;; For something more complicated invoke a parser
8377 ((looking-at "[^)]+")
8378 (verilog-read-sub-decls-expr
8379 submoddecls comment port
8380 (buffer-substring
8381 (point) (1- (progn (search-backward "(") ; start at (
8382 (verilog-forward-sexp-ign-cmt 1)
8383 (point)))))))) ; expr
8385 (forward-line 1)))))
8387 (defun verilog-read-sub-decls-gate (submoddecls comment submod end-inst-point)
8388 "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
8389 Inserts the list of signals found."
8390 (save-excursion
8391 (let ((iolist (cdr (assoc submod verilog-gate-ios))))
8392 (while (< (point) end-inst-point)
8393 ;; Get primitive's signal name, as will never have port, and no trailing )
8394 (cond ((looking-at "//")
8395 (search-forward "\n"))
8396 ((looking-at "/\\*")
8397 (or (search-forward "*/")
8398 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8399 ((looking-at "(\\*")
8400 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8401 (forward-char 1)
8402 (or (search-forward "*)")
8403 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8404 ;; On pins, parse and advance to next pin
8405 ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
8406 ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
8407 (goto-char (match-end 0))
8408 (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
8409 iolist (cdr iolist))
8410 (verilog-read-sub-decls-expr
8411 submoddecls comment "primitive_port"
8412 (match-string 0)))
8414 (forward-char 1)
8415 (skip-syntax-forward " ")))))))
8417 (defun verilog-read-sub-decls ()
8418 "Internally parse signals going to modules under this module.
8419 Return an array of [ outputs inouts inputs ] signals for modules that are
8420 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
8421 is an output, then SIG will be included in the list.
8423 This only works on instantiations created with /*AUTOINST*/ converted by
8424 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
8425 component library to determine connectivity of the design.
8427 One work around for this problem is to manually create // Inputs and //
8428 Outputs comments above subcell signals, for example:
8430 module ModuleName (
8431 // Outputs
8432 .out (out),
8433 // Inputs
8434 .in (in));"
8435 (save-excursion
8436 (let ((end-mod-point (verilog-get-end-of-defun t))
8437 st-point end-inst-point
8438 ;; below 3 modified by verilog-read-sub-decls-line
8439 sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
8440 (verilog-beg-of-defun-quick)
8441 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
8442 (save-excursion
8443 (goto-char (match-beginning 0))
8444 (unless (verilog-inside-comment-or-string-p)
8445 ;; Attempt to snarf a comment
8446 (let* ((submod (verilog-read-inst-module))
8447 (inst (verilog-read-inst-name))
8448 (subprim (member submod verilog-gate-keywords))
8449 (comment (concat inst " of " submod ".v"))
8450 submodi submoddecls)
8451 (cond
8452 (subprim
8453 (setq submodi `primitive
8454 submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
8455 comment (concat inst " of " submod))
8456 (verilog-backward-open-paren)
8457 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
8458 (point))
8459 st-point (point))
8460 (forward-char 1)
8461 (verilog-read-sub-decls-gate submoddecls comment submod end-inst-point))
8462 ;; Non-primitive
8464 (when (setq submodi (verilog-modi-lookup submod t))
8465 (setq submoddecls (verilog-modi-get-decls submodi)
8466 verilog-read-sub-decls-gate-ios nil)
8467 (verilog-backward-open-paren)
8468 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
8469 (point))
8470 st-point (point))
8471 ;; This could have used a list created by verilog-auto-inst
8472 ;; However I want it to be runnable even on user's manually added signals
8473 (let ((verilog-read-sub-decls-in-interfaced t))
8474 (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
8475 (verilog-read-sub-decls-line submoddecls comment))) ;; Modifies sigs-ifd
8476 (goto-char st-point)
8477 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
8478 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
8479 (goto-char st-point)
8480 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
8481 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
8482 (goto-char st-point)
8483 (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
8484 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout
8485 (goto-char st-point)
8486 (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
8487 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-in
8488 )))))))
8489 ;; Combine duplicate bits
8490 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
8491 (verilog-subdecls-new
8492 (verilog-signals-combine-bus (nreverse sigs-out))
8493 (verilog-signals-combine-bus (nreverse sigs-inout))
8494 (verilog-signals-combine-bus (nreverse sigs-in))
8495 (verilog-signals-combine-bus (nreverse sigs-intf))
8496 (verilog-signals-combine-bus (nreverse sigs-intfd))))))
8498 (defun verilog-read-inst-pins ()
8499 "Return an array of [ pins ] for the current instantiation at point.
8500 For example if declare A A (.B(SIG)) then B will be included in the list."
8501 (save-excursion
8502 (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point
8503 pins pin)
8504 (verilog-backward-open-paren)
8505 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
8506 (setq pin (match-string 1))
8507 (unless (verilog-inside-comment-or-string-p)
8508 (setq pins (cons (list pin) pins))
8509 (when (looking-at "(")
8510 (verilog-forward-sexp-ign-cmt 1))))
8511 (vector pins))))
8513 (defun verilog-read-arg-pins ()
8514 "Return an array of [ pins ] for the current argument declaration at point."
8515 (save-excursion
8516 (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point
8517 pins pin)
8518 (verilog-backward-open-paren)
8519 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
8520 (setq pin (match-string 1))
8521 (unless (verilog-inside-comment-or-string-p)
8522 (setq pins (cons (list pin) pins))))
8523 (vector pins))))
8525 (defun verilog-read-auto-constants (beg end-mod-point)
8526 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
8527 ;; Insert new
8528 (save-excursion
8529 (let (sig-list tpl-end-pt)
8530 (goto-char beg)
8531 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
8532 (if (not (looking-at "\\s *("))
8533 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
8534 (search-forward "(" end-mod-point)
8535 (setq tpl-end-pt (save-excursion
8536 (backward-char 1)
8537 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8538 (backward-char 1)
8539 (point)))
8540 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
8541 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
8542 sig-list)))
8544 (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
8545 (make-variable-buffer-local 'verilog-cache-has-lisp)
8547 (defun verilog-read-auto-lisp-present ()
8548 "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
8549 (save-excursion
8550 (goto-char (point-min))
8551 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
8553 (defun verilog-read-auto-lisp (start end)
8554 "Look for and evaluate an AUTO_LISP between START and END.
8555 Must call `verilog-read-auto-lisp-present' before this function."
8556 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
8557 (when verilog-cache-has-lisp
8558 (save-excursion
8559 (goto-char start)
8560 (while (re-search-forward "\\<AUTO_LISP(" end t)
8561 (backward-char)
8562 (let* ((beg-pt (prog1 (point)
8563 (verilog-forward-sexp-cmt 1))) ;; Closing paren
8564 (end-pt (point))
8565 (verilog-in-hooks t))
8566 (eval-region beg-pt end-pt nil))))))
8568 (eval-when-compile
8569 ;; Prevent compile warnings; these are let's, not globals
8570 ;; Do not remove the eval-when-compile
8571 ;; - we want an error when we are debugging this code if they are refed.
8572 (defvar sigs-in)
8573 (defvar sigs-out-d)
8574 (defvar sigs-out-i)
8575 (defvar sigs-out-unk)
8576 (defvar sigs-temp)
8577 (defvar vector-skip-list))
8579 (defun verilog-read-always-signals-recurse
8580 (exit-keywd rvalue temp-next)
8581 "Recursive routine for parentheses/bracket matching.
8582 EXIT-KEYWD is expression to stop at, nil if top level.
8583 RVALUE is true if at right hand side of equal.
8584 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
8585 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue
8586 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
8587 ignore-next)
8588 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
8589 (while (not (or (eobp) gotend))
8590 (cond
8591 ((looking-at "//")
8592 (search-forward "\n"))
8593 ((looking-at "/\\*")
8594 (or (search-forward "*/")
8595 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8596 ((looking-at "(\\*")
8597 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8598 (forward-char 1)
8599 (or (search-forward "*)")
8600 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8601 (t (setq keywd (buffer-substring-no-properties
8602 (point)
8603 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
8604 (forward-char 1))
8605 (point)))
8606 sig-last-tolk sig-tolk
8607 sig-tolk nil)
8608 ;;(if dbg (setq dbg (concat dbg (format "\tPt=%S %S\trv=%S in=%S ee=%S gs=%S\n" (point) keywd rvalue ignore-next end-else-check got-sig))))
8609 (cond
8610 ((equal keywd "\"")
8611 (or (re-search-forward "[^\\]\"" nil t)
8612 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
8613 ;; else at top level loop, keep parsing
8614 ((and end-else-check (equal keywd "else"))
8615 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
8616 ;; no forward movement, want to see else in lower loop
8617 (setq end-else-check nil))
8618 ;; End at top level loop
8619 ((and end-else-check (looking-at "[^ \t\n\f]"))
8620 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
8621 (setq gotend t))
8622 ;; Final statement?
8623 ((and exit-keywd (equal keywd exit-keywd))
8624 (setq gotend t)
8625 (forward-char (length keywd)))
8626 ;; Standard tokens...
8627 ((equal keywd ";")
8628 (setq ignore-next nil rvalue semi-rvalue)
8629 ;; Final statement at top level loop?
8630 (when (not exit-keywd)
8631 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
8632 (setq end-else-check t))
8633 (forward-char 1))
8634 ((equal keywd "'")
8635 (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
8636 (goto-char (match-end 0))
8637 (forward-char 1)))
8638 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z
8639 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next
8640 (setq ignore-next nil rvalue nil))
8641 ((equal "?" exit-keywd) ;; x?y:z rvalue
8642 ) ;; NOP
8643 ((equal "]" exit-keywd) ;; [x:y] rvalue
8644 ) ;; NOP
8645 (got-sig ;; label: statement
8646 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
8647 ((not rvalue) ;; begin label
8648 (setq ignore-next t rvalue nil)))
8649 (forward-char 1))
8650 ((equal keywd "=")
8651 (when got-sig
8652 ;;(if dbg (setq dbg (concat dbg (format "\t\tequal got-sig=%S got-list=%s\n" got-sig got-list))))
8653 (set got-list (cons got-sig (symbol-value got-list)))
8654 (setq got-sig nil))
8655 (when (not rvalue)
8656 (if (eq (char-before) ?< )
8657 (setq sigs-out-d (append sigs-out-d sigs-out-unk)
8658 sigs-out-unk nil)
8659 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
8660 sigs-out-unk nil)))
8661 (setq ignore-next nil rvalue t)
8662 (forward-char 1))
8663 ((equal keywd "?")
8664 (forward-char 1)
8665 (verilog-read-always-signals-recurse ":" rvalue nil))
8666 ((equal keywd "[")
8667 (forward-char 1)
8668 (verilog-read-always-signals-recurse "]" t nil))
8669 ((equal keywd "(")
8670 (forward-char 1)
8671 (cond (sig-last-tolk ;; Function call; zap last signal
8672 (setq got-sig nil)))
8673 (cond ((equal last-keywd "for")
8674 ;; temp-next: Variables on LHS are lvalues, but generally we want
8675 ;; to ignore them, assuming they are loop increments
8676 (verilog-read-always-signals-recurse ";" nil t)
8677 (verilog-read-always-signals-recurse ";" t nil)
8678 (verilog-read-always-signals-recurse ")" nil nil))
8679 (t (verilog-read-always-signals-recurse ")" t nil))))
8680 ((equal keywd "begin")
8681 (skip-syntax-forward "w_")
8682 (verilog-read-always-signals-recurse "end" nil nil)
8683 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
8684 (setq ignore-next nil rvalue semi-rvalue)
8685 (if (not exit-keywd) (setq end-else-check t)))
8686 ((member keywd '("case" "casex" "casez"))
8687 (skip-syntax-forward "w_")
8688 (verilog-read-always-signals-recurse "endcase" t nil)
8689 (setq ignore-next nil rvalue semi-rvalue)
8690 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end
8691 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent
8692 (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8693 (setq ignore-next t))
8694 ((or ignore-next
8695 (member keywd verilog-keywords)
8696 (string-match "^\\$" keywd)) ;; PLI task
8697 (setq ignore-next nil))
8699 (setq keywd (verilog-symbol-detick-denumber keywd))
8700 (when got-sig
8701 (set got-list (cons got-sig (symbol-value got-list)))
8702 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
8704 (setq got-list (cond (temp-next 'sigs-temp)
8705 (rvalue 'sigs-in)
8706 (t 'sigs-out-unk))
8707 got-sig (if (or (not keywd)
8708 (assoc keywd (symbol-value got-list)))
8709 nil (list keywd nil nil))
8710 temp-next nil
8711 sig-tolk t)))
8712 (skip-chars-forward "a-zA-Z0-9$_.%`"))
8714 (forward-char 1)))
8715 ;; End of non-comment token
8716 (setq last-keywd keywd)))
8717 (skip-syntax-forward " "))
8718 ;; Append the final pending signal
8719 (when got-sig
8720 ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
8721 (set got-list (cons got-sig (symbol-value got-list)))
8722 (setq got-sig nil))
8723 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
8726 (defun verilog-read-always-signals ()
8727 "Parse always block at point and return list of (outputs inout inputs)."
8728 (save-excursion
8729 (let* (;;(dbg "")
8730 sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
8731 (search-forward ")")
8732 (verilog-read-always-signals-recurse nil nil nil)
8733 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
8734 sigs-out-unk nil)
8735 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))
8736 ;; Return what was found
8737 (verilog-alw-new sigs-out-d sigs-out-i sigs-temp sigs-in))))
8739 (defun verilog-read-instants ()
8740 "Parse module at point and return list of ( ( file instance ) ... )."
8741 (verilog-beg-of-defun-quick)
8742 (let* ((end-mod-point (verilog-get-end-of-defun t))
8743 (state nil)
8744 (instants-list nil))
8745 (save-excursion
8746 (while (< (point) end-mod-point)
8747 ;; Stay at level 0, no comments
8748 (while (progn
8749 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
8750 (or (> (car state) 0) ; in parens
8751 (nth 5 state) ; comment
8753 (forward-line 1))
8754 (beginning-of-line)
8755 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
8756 ;;(if (looking-at "^\\(.+\\)$")
8757 (let ((module (match-string 1))
8758 (instant (match-string 2)))
8759 (if (not (member module verilog-keywords))
8760 (setq instants-list (cons (list module instant) instants-list)))))
8761 (forward-line 1)))
8762 instants-list))
8765 (defun verilog-read-auto-template-middle ()
8766 "With point in middle of an AUTO_TEMPLATE, parse it.
8767 Returns REGEXP and list of ( (signal_name connection_name)... )."
8768 (save-excursion
8769 ;; Find beginning
8770 (let ((tpl-regexp "\\([0-9]+\\)")
8771 (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
8772 (templateno 0)
8773 tpl-sig-list tpl-wild-list tpl-end-pt rep)
8774 ;; Parse "REGEXP"
8775 ;; We reserve @"..." for future lisp expressions that evaluate
8776 ;; once-per-AUTOINST
8777 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
8778 (setq tpl-regexp (match-string 1))
8779 (goto-char (match-end 0)))
8780 (search-forward "(")
8781 ;; Parse lines in the template
8782 (when (or verilog-auto-inst-template-numbers
8783 verilog-auto-template-warn-unused)
8784 (save-excursion
8785 (let ((pre-pt (point)))
8786 (goto-char (point-min))
8787 (while (search-forward "AUTO_TEMPLATE" pre-pt t)
8788 (setq templateno (1+ templateno)))
8789 (while (< (point) pre-pt)
8790 (forward-line 1)
8791 (setq lineno (1+ lineno))))))
8792 (setq tpl-end-pt (save-excursion
8793 (backward-char 1)
8794 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8795 (backward-char 1)
8796 (point)))
8798 (while (< (point) tpl-end-pt)
8799 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8800 (setq tpl-sig-list
8801 (cons (list
8802 (match-string-no-properties 1)
8803 (match-string-no-properties 2)
8804 templateno lineno)
8805 tpl-sig-list))
8806 (goto-char (match-end 0)))
8807 ;; Regexp form??
8808 ((looking-at
8809 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
8810 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8811 (setq rep (match-string-no-properties 3))
8812 (goto-char (match-end 0))
8813 (setq tpl-wild-list
8814 (cons (list
8815 (concat "^"
8816 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
8817 (match-string 1))
8818 "$")
8820 templateno lineno)
8821 tpl-wild-list)))
8822 ((looking-at "[ \t\f]+")
8823 (goto-char (match-end 0)))
8824 ((looking-at "\n")
8825 (setq lineno (1+ lineno))
8826 (goto-char (match-end 0)))
8827 ((looking-at "//")
8828 (search-forward "\n")
8829 (setq lineno (1+ lineno)))
8830 ((looking-at "/\\*")
8831 (forward-char 2)
8832 (or (search-forward "*/")
8833 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8835 (error "%s: AUTO_TEMPLATE parsing error: %s"
8836 (verilog-point-text)
8837 (progn (looking-at ".*$") (match-string 0))))))
8838 ;; Return
8839 (vector tpl-regexp
8840 (list tpl-sig-list tpl-wild-list)))))
8842 (defun verilog-read-auto-template (module)
8843 "Look for an auto_template for the instantiation of the given MODULE.
8844 If found returns `verilog-read-auto-template-inside' structure."
8845 (save-excursion
8846 ;; Find beginning
8847 (let ((pt (point)))
8848 ;; Note this search is expensive, as we hunt from mod-begin to point
8849 ;; for every instantiation. Likewise in verilog-read-auto-lisp.
8850 ;; So, we look first for an exact string rather than a slow regexp.
8851 ;; Someday we may keep a cache of every template, but this would also
8852 ;; need to record the relative position of each AUTOINST, as multiple
8853 ;; templates exist for each module, and we're inserting lines.
8854 (cond ((or
8855 ;; See also regexp in `verilog-auto-template-lint'
8856 (verilog-re-search-backward-substr
8857 "AUTO_TEMPLATE"
8858 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
8859 ;; Also try forward of this AUTOINST
8860 ;; This is for historical support; this isn't speced as working
8861 (progn
8862 (goto-char pt)
8863 (verilog-re-search-forward-substr
8864 "AUTO_TEMPLATE"
8865 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
8866 (goto-char (match-end 0))
8867 (verilog-read-auto-template-middle))
8868 ;; If no template found
8869 (t (vector "" nil))))))
8870 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
8872 (defvar verilog-auto-template-hits nil "Successful lookups with `verilog-read-auto-template-hit'.")
8873 (make-variable-buffer-local 'verilog-auto-template-hits)
8875 (defun verilog-read-auto-template-hit (tpl-ass)
8876 "Record that TPL-ASS template from `verilog-read-auto-template' was used."
8877 (when (eval-when-compile (fboundp 'make-hash-table)) ;; else feature not allowed
8878 (when verilog-auto-template-warn-unused
8879 (unless verilog-auto-template-hits
8880 (setq verilog-auto-template-hits
8881 (make-hash-table :test 'equal :rehash-size 4.0)))
8882 (puthash (vector (nth 2 tpl-ass) (nth 3 tpl-ass)) t
8883 verilog-auto-template-hits))))
8885 (defun verilog-set-define (defname defvalue &optional buffer enumname)
8886 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
8887 Optionally associate it with the specified enumeration ENUMNAME."
8888 (with-current-buffer (or buffer (current-buffer))
8889 (let ((mac (intern (concat "vh-" defname))))
8890 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
8891 ;; Need to define to a constant if no value given
8892 (set (make-local-variable mac)
8893 (if (equal defvalue "") "1" defvalue)))
8894 (if enumname
8895 (let ((enumvar (intern (concat "venum-" enumname))))
8896 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
8897 (unless (boundp enumvar) (set enumvar nil))
8898 (add-to-list (make-local-variable enumvar) defname)))))
8900 (defun verilog-read-defines (&optional filename recurse subcall)
8901 "Read `defines and parameters for the current file, or optional FILENAME.
8902 If the filename is provided, `verilog-library-flags' will be used to
8903 resolve it. If optional RECURSE is non-nil, recurse through `includes.
8905 Parameters must be simple assignments to constants, or have their own
8906 \"parameter\" label rather than a list of parameters. Thus:
8908 parameter X = 5, Y = 10; // Ok
8909 parameter X = {1'b1, 2'h2}; // Ok
8910 parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines
8912 Defines must be simple text substitutions, one on a line, starting
8913 at the beginning of the line. Any ifdefs or multiline comments around the
8914 define are ignored.
8916 Defines are stored inside Emacs variables using the name vh-{definename}.
8918 This function is useful for setting vh-* variables. The file variables
8919 feature can be used to set defines that `verilog-mode' can see; put at the
8920 *END* of your file something like:
8922 // Local Variables:
8923 // vh-macro:\"macro_definition\"
8924 // End:
8926 If macros are defined earlier in the same file and you want their values,
8927 you can read them automatically (provided `enable-local-eval' is on):
8929 // Local Variables:
8930 // eval:(verilog-read-defines)
8931 // eval:(verilog-read-defines \"group_standard_includes.v\")
8932 // End:
8934 Note these are only read when the file is first visited, you must use
8935 \\[find-alternate-file] RET to have these take effect after editing them!
8937 If you want to disable the \"Process `eval' or hook local variables\"
8938 warning message, you need to add to your init file:
8940 (setq enable-local-eval t)"
8941 (let ((origbuf (current-buffer)))
8942 (save-excursion
8943 (unless subcall (verilog-getopt-flags))
8944 (when filename
8945 (let ((fns (verilog-library-filenames filename (buffer-file-name))))
8946 (if fns
8947 (set-buffer (find-file-noselect (car fns)))
8948 (error (concat (verilog-point-text)
8949 ": Can't find verilog-read-defines file: " filename)))))
8950 (when recurse
8951 (goto-char (point-min))
8952 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
8953 (let ((inc (verilog-string-replace-matches
8954 "\"" "" nil nil (match-string-no-properties 1))))
8955 (unless (verilog-inside-comment-or-string-p)
8956 (verilog-read-defines inc recurse t)))))
8957 ;; Read `defines
8958 ;; note we don't use verilog-re... it's faster this way, and that
8959 ;; function has problems when comments are at the end of the define
8960 (goto-char (point-min))
8961 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
8962 (let ((defname (match-string-no-properties 1))
8963 (defvalue (match-string-no-properties 2)))
8964 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
8965 (verilog-set-define defname defvalue origbuf)))
8966 ;; Hack: Read parameters
8967 (goto-char (point-min))
8968 (while (re-search-forward
8969 "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
8970 (let (enumname)
8971 ;; The primary way of getting defines is verilog-read-decls
8972 ;; However, that isn't called yet for included files, so we'll add another scheme
8973 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8974 (setq enumname (match-string-no-properties 2)))
8975 (forward-comment 99999)
8976 (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
8977 "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
8978 (verilog-set-define (match-string-no-properties 1)
8979 (match-string-no-properties 2) origbuf enumname)
8980 (goto-char (match-end 0))
8981 (forward-comment 99999)))))))
8983 (defun verilog-read-includes ()
8984 "Read `includes for the current file.
8985 This will find all of the `includes which are at the beginning of lines,
8986 ignoring any ifdefs or multiline comments around them.
8987 `verilog-read-defines' is then performed on the current and each included
8988 file.
8990 It is often useful put at the *END* of your file something like:
8992 // Local Variables:
8993 // eval:(verilog-read-defines)
8994 // eval:(verilog-read-includes)
8995 // End:
8997 Note includes are only read when the file is first visited, you must use
8998 \\[find-alternate-file] RET to have these take effect after editing them!
9000 It is good to get in the habit of including all needed files in each .v
9001 file that needs it, rather than waiting for compile time. This will aid
9002 this process, Verilint, and readability. To prevent defining the same
9003 variable over and over when many modules are compiled together, put a test
9004 around the inside each include file:
9006 foo.v (an include file):
9007 `ifdef _FOO_V // include if not already included
9008 `else
9009 `define _FOO_V
9010 ... contents of file
9011 `endif // _FOO_V"
9012 ;;slow: (verilog-read-defines nil t))
9013 (save-excursion
9014 (verilog-getopt-flags)
9015 (goto-char (point-min))
9016 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9017 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
9018 (verilog-read-defines inc nil t)))))
9020 (defun verilog-read-signals (&optional start end)
9021 "Return a simple list of all possible signals in the file.
9022 Bounded by optional region from START to END. Overly aggressive but fast.
9023 Some macros and such are also found and included. For dinotrace.el."
9024 (let (sigs-all keywd)
9025 (progn;save-excursion
9026 (goto-char (or start (point-min)))
9027 (setq end (or end (point-max)))
9028 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
9029 (forward-char -1)
9030 (cond
9031 ((looking-at "//")
9032 (search-forward "\n"))
9033 ((looking-at "/\\*")
9034 (search-forward "*/"))
9035 ((looking-at "(\\*")
9036 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
9037 (search-forward "*)")))
9038 ((eq ?\" (following-char))
9039 (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first
9040 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
9041 (goto-char (match-end 0))
9042 (setq keywd (match-string-no-properties 1))
9043 (or (member keywd verilog-keywords)
9044 (member keywd sigs-all)
9045 (setq sigs-all (cons keywd sigs-all))))
9046 (t (forward-char 1))))
9047 ;; Return list
9048 sigs-all)))
9051 ;; Argument file parsing
9054 (defun verilog-getopt (arglist)
9055 "Parse -f, -v etc arguments in ARGLIST list or string."
9056 (unless (listp arglist) (setq arglist (list arglist)))
9057 (let ((space-args '())
9058 arg next-param)
9059 ;; Split on spaces, so users can pass whole command lines
9060 (while arglist
9061 (setq arg (car arglist)
9062 arglist (cdr arglist))
9063 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
9064 (setq space-args (append space-args
9065 (list (match-string-no-properties 1 arg))))
9066 (setq arg (match-string 2 arg))))
9067 ;; Parse arguments
9068 (while space-args
9069 (setq arg (car space-args)
9070 space-args (cdr space-args))
9071 (cond
9072 ;; Need another arg
9073 ((equal arg "-f")
9074 (setq next-param arg))
9075 ((equal arg "-v")
9076 (setq next-param arg))
9077 ((equal arg "-y")
9078 (setq next-param arg))
9079 ;; +libext+(ext1)+(ext2)...
9080 ((string-match "^\\+libext\\+\\(.*\\)" arg)
9081 (setq arg (match-string 1 arg))
9082 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
9083 (verilog-add-list-unique `verilog-library-extensions
9084 (match-string 1 arg))
9085 (setq arg (match-string 2 arg))))
9087 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val
9088 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine
9089 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val
9090 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define
9091 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
9093 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir
9094 (string-match "^-I\\(.*\\)" arg)) ;; -Idir
9095 (verilog-add-list-unique `verilog-library-directories
9096 (match-string 1 (substitute-in-file-name arg))))
9097 ;; Ignore
9098 ((equal "+librescan" arg))
9099 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine
9100 ;; Second parameters
9101 ((equal next-param "-f")
9102 (setq next-param nil)
9103 (verilog-getopt-file (substitute-in-file-name arg)))
9104 ((equal next-param "-v")
9105 (setq next-param nil)
9106 (verilog-add-list-unique `verilog-library-files
9107 (substitute-in-file-name arg)))
9108 ((equal next-param "-y")
9109 (setq next-param nil)
9110 (verilog-add-list-unique `verilog-library-directories
9111 (substitute-in-file-name arg)))
9112 ;; Filename
9113 ((string-match "^[^-+]" arg)
9114 (verilog-add-list-unique `verilog-library-files
9115 (substitute-in-file-name arg)))
9116 ;; Default - ignore; no warning
9117 ))))
9118 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
9120 (defun verilog-getopt-file (filename)
9121 "Read Verilog options from the specified FILENAME."
9122 (save-excursion
9123 (let ((fns (verilog-library-filenames filename (buffer-file-name)))
9124 (orig-buffer (current-buffer))
9125 line)
9126 (if fns
9127 (set-buffer (find-file-noselect (car fns)))
9128 (error (concat (verilog-point-text)
9129 ": Can't find verilog-getopt-file -f file: " filename)))
9130 (goto-char (point-min))
9131 (while (not (eobp))
9132 (setq line (buffer-substring (point) (point-at-eol)))
9133 (forward-line 1)
9134 (when (string-match "//" line)
9135 (setq line (substring line 0 (match-beginning 0))))
9136 (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
9137 (verilog-getopt line))))))
9139 (defun verilog-getopt-flags ()
9140 "Convert `verilog-library-flags' into standard library variables."
9141 ;; If the flags are local, then all the outputs should be local also
9142 (when (local-variable-p `verilog-library-flags (current-buffer))
9143 (mapc 'make-local-variable '(verilog-library-extensions
9144 verilog-library-directories
9145 verilog-library-files
9146 verilog-library-flags)))
9147 ;; Allow user to customize
9148 (verilog-run-hooks 'verilog-before-getopt-flags-hook)
9149 ;; Process arguments
9150 (verilog-getopt verilog-library-flags)
9151 ;; Allow user to customize
9152 (verilog-run-hooks 'verilog-getopt-flags-hook))
9154 (defun verilog-add-list-unique (varref object)
9155 "Append to VARREF list the given OBJECT,
9156 unless it is already a member of the variable's list."
9157 (unless (member object (symbol-value varref))
9158 (set varref (append (symbol-value varref) (list object))))
9159 varref)
9160 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
9162 (defun verilog-current-flags ()
9163 "Convert `verilog-library-flags' and similar variables to command line.
9164 Used for __FLAGS__ in `verilog-expand-command'."
9165 (let ((cmd (mapconcat `concat verilog-library-flags " ")))
9166 (when (equal cmd "")
9167 (setq cmd (concat
9168 "+libext+" (mapconcat `concat verilog-library-extensions "+")
9169 (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
9170 verilog-library-directories "")
9171 (mapconcat (lambda (i) (concat " -v " i))
9172 verilog-library-files ""))))
9173 cmd))
9174 ;;(verilog-current-flags)
9178 ;; Cached directory support
9181 (defvar verilog-dir-cache-preserving nil
9182 "If set, the directory cache is enabled, and file system changes are ignored.
9183 See `verilog-dir-exists-p' and `verilog-dir-files'.")
9185 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
9186 (defvar verilog-dir-cache-list nil
9187 "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
9188 (defvar verilog-dir-cache-lib-filenames nil
9189 "Cached data for `verilog-library-filenames'.")
9191 (defmacro verilog-preserve-dir-cache (&rest body)
9192 "Execute the BODY forms, allowing directory cache preservation within BODY.
9193 This means that changes inside BODY made to the file system will not be
9194 seen by the `verilog-dir-files' and related functions."
9195 `(let ((verilog-dir-cache-preserving (current-buffer))
9196 verilog-dir-cache-list
9197 verilog-dir-cache-lib-filenames)
9198 (progn ,@body)))
9200 (defun verilog-dir-files (dirname)
9201 "Return all filenames in the DIRNAME directory.
9202 Relative paths depend on the `default-directory'.
9203 Results are cached if inside `verilog-preserve-dir-cache'."
9204 (unless verilog-dir-cache-preserving
9205 (setq verilog-dir-cache-list nil)) ;; Cache disabled
9206 ;; We don't use expand-file-name on the dirname to make key, as it's slow
9207 (let* ((cache-key (list dirname default-directory))
9208 (fass (assoc cache-key verilog-dir-cache-list))
9209 exp-dirname data)
9210 (cond (fass ;; Return data from cache hit
9211 (nth 1 fass))
9213 (setq exp-dirname (expand-file-name dirname)
9214 data (and (file-directory-p exp-dirname)
9215 (directory-files exp-dirname nil nil nil)))
9216 ;; Note we also encache nil for non-existing dirs.
9217 (setq verilog-dir-cache-list (cons (list cache-key data)
9218 verilog-dir-cache-list))
9219 data))))
9220 ;; Miss-and-hit test:
9221 ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
9222 ;; (prin1 (verilog-dir-files ".")) nil)
9224 (defun verilog-dir-file-exists-p (filename)
9225 "Return true if FILENAME exists.
9226 Like `file-exists-p' but results are cached if inside
9227 `verilog-preserve-dir-cache'."
9228 (let* ((dirname (file-name-directory filename))
9229 ;; Correct for file-name-nondirectory returning same if no slash.
9230 (dirnamed (if (or (not dirname) (equal dirname filename))
9231 default-directory dirname))
9232 (flist (verilog-dir-files dirnamed)))
9233 (and flist
9234 (member (file-name-nondirectory filename) flist)
9235 t)))
9236 ;;(verilog-dir-file-exists-p "verilog-mode.el")
9237 ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
9241 ;; Module name lookup
9244 (defun verilog-module-inside-filename-p (module filename)
9245 "Return modi if MODULE is specified inside FILENAME, else nil.
9246 Allows version control to check out the file if need be."
9247 (and (or (file-exists-p filename)
9248 (and (fboundp 'vc-backend)
9249 (vc-backend filename)))
9250 (let (modi type)
9251 (with-current-buffer (find-file-noselect filename)
9252 (save-excursion
9253 (goto-char (point-min))
9254 (while (and
9255 ;; It may be tempting to look for verilog-defun-re,
9256 ;; don't, it slows things down a lot!
9257 (verilog-re-search-forward-quick "\\<\\(module\\|interface\\|program\\)\\>" nil t)
9258 (setq type (match-string-no-properties 0))
9259 (verilog-re-search-forward-quick "[(;]" nil t))
9260 (if (equal module (verilog-read-module-name))
9261 (setq modi (verilog-modi-new module filename (point) type))))
9262 modi)))))
9264 (defun verilog-is-number (symbol)
9265 "Return true if SYMBOL is number-like."
9266 (or (string-match "^[0-9 \t:]+$" symbol)
9267 (string-match "^[---]*[0-9]+$" symbol)
9268 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
9270 (defun verilog-symbol-detick (symbol wing-it)
9271 "Return an expanded SYMBOL name without any defines.
9272 If the variable vh-{symbol} is defined, return that value.
9273 If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
9274 (while (and symbol (string-match "^`" symbol))
9275 (setq symbol (substring symbol 1))
9276 (setq symbol
9277 (if (boundp (intern (concat "vh-" symbol)))
9278 ;; Emacs has a bug where boundp on a buffer-local
9279 ;; variable in only one buffer returns t in another.
9280 ;; This can confuse, so check for nil.
9281 (let ((val (eval (intern (concat "vh-" symbol)))))
9282 (if (eq val nil)
9283 (if wing-it symbol nil)
9284 val))
9285 (if wing-it symbol nil))))
9286 symbol)
9287 ;;(verilog-symbol-detick "`mod" nil)
9289 (defun verilog-symbol-detick-denumber (symbol)
9290 "Return SYMBOL with defines converted and any numbers dropped to nil."
9291 (when (string-match "^`" symbol)
9292 ;; This only will work if the define is a simple signal, not
9293 ;; something like a[b]. Sorry, it should be substituted into the parser
9294 (setq symbol
9295 (verilog-string-replace-matches
9296 "\[[^0-9: \t]+\]" "" nil nil
9297 (or (verilog-symbol-detick symbol nil)
9298 (if verilog-auto-sense-defines-constant
9300 symbol)))))
9301 (if (verilog-is-number symbol)
9303 symbol))
9305 (defun verilog-symbol-detick-text (text)
9306 "Return TEXT without any known defines.
9307 If the variable vh-{symbol} is defined, substitute that value."
9308 (let ((ok t) symbol val)
9309 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
9310 (setq symbol (match-string 1 text))
9311 ;;(message symbol)
9312 (cond ((and
9313 (boundp (intern (concat "vh-" symbol)))
9314 ;; Emacs has a bug where boundp on a buffer-local
9315 ;; variable in only one buffer returns t in another.
9316 ;; This can confuse, so check for nil.
9317 (setq val (eval (intern (concat "vh-" symbol)))))
9318 (setq text (replace-match val nil nil text)))
9319 (t (setq ok nil)))))
9320 text)
9321 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
9323 (defun verilog-expand-dirnames (&optional dirnames)
9324 "Return a list of existing directories given a list of wildcarded DIRNAMES.
9325 Or, just the existing dirnames themselves if there are no wildcards."
9326 ;; Note this function is performance critical.
9327 ;; Do not call anything that requires disk access that cannot be cached.
9328 (interactive)
9329 (unless dirnames (error "`verilog-library-directories' should include at least '.'"))
9330 (setq dirnames (reverse dirnames)) ; not nreverse
9331 (let ((dirlist nil)
9332 pattern dirfile dirfiles dirname root filename rest basefile)
9333 (while dirnames
9334 (setq dirname (substitute-in-file-name (car dirnames))
9335 dirnames (cdr dirnames))
9336 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root
9337 "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *?
9338 "\\(.*\\)") ;; rest
9339 dirname)
9340 (setq root (match-string 1 dirname)
9341 filename (match-string 2 dirname)
9342 rest (match-string 3 dirname)
9343 pattern filename)
9344 ;; now replace those * and ? with .+ and .
9345 ;; use ^ and /> to get only whole file names
9346 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
9347 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
9348 pattern (concat "^" pattern "$")
9349 dirfiles (verilog-dir-files root))
9350 (while dirfiles
9351 (setq basefile (car dirfiles)
9352 dirfile (expand-file-name (concat root basefile rest))
9353 dirfiles (cdr dirfiles))
9354 (if (and (string-match pattern basefile)
9355 ;; Don't allow abc/*/rtl to match abc/rtl via ..
9356 (not (equal basefile "."))
9357 (not (equal basefile ".."))
9358 (file-directory-p dirfile))
9359 (setq dirlist (cons dirfile dirlist)))))
9360 ;; Defaults
9362 (if (file-directory-p dirname)
9363 (setq dirlist (cons dirname dirlist))))))
9364 dirlist))
9365 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
9367 (defun verilog-library-filenames (filename &optional current check-ext)
9368 "Return a search path to find the given FILENAME or module name.
9369 Uses the optional CURRENT filename or variable `buffer-file-name', plus
9370 `verilog-library-directories' and `verilog-library-extensions'
9371 variables to build the path. With optional CHECK-EXT also check
9372 `verilog-library-extensions'."
9373 (unless current (setq current (buffer-file-name)))
9374 (unless verilog-dir-cache-preserving
9375 (setq verilog-dir-cache-lib-filenames nil))
9376 (let* ((cache-key (list filename current check-ext))
9377 (fass (assoc cache-key verilog-dir-cache-lib-filenames))
9378 chkdirs chkdir chkexts fn outlist)
9379 (cond (fass ;; Return data from cache hit
9380 (nth 1 fass))
9382 ;; Note this expand can't be easily cached, as we need to
9383 ;; pick up buffer-local variables for newly read sub-module files
9384 (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
9385 (while chkdirs
9386 (setq chkdir (expand-file-name (car chkdirs)
9387 (file-name-directory current))
9388 chkexts (if check-ext verilog-library-extensions `("")))
9389 (while chkexts
9390 (setq fn (expand-file-name (concat filename (car chkexts))
9391 chkdir))
9392 ;;(message "Check for %s" fn)
9393 (if (verilog-dir-file-exists-p fn)
9394 (setq outlist (cons (expand-file-name
9395 fn (file-name-directory current))
9396 outlist)))
9397 (setq chkexts (cdr chkexts)))
9398 (setq chkdirs (cdr chkdirs)))
9399 (setq outlist (nreverse outlist))
9400 (setq verilog-dir-cache-lib-filenames
9401 (cons (list cache-key outlist)
9402 verilog-dir-cache-lib-filenames))
9403 outlist))))
9405 (defun verilog-module-filenames (module current)
9406 "Return a search path to find the given MODULE name.
9407 Uses the CURRENT filename, `verilog-library-extensions',
9408 `verilog-library-directories' and `verilog-library-files'
9409 variables to build the path."
9410 ;; Return search locations for it
9411 (append (list current) ; first, current buffer
9412 (verilog-library-filenames module current t)
9413 verilog-library-files)) ; finally, any libraries
9416 ;; Module Information
9418 ;; Many of these functions work on "modi" a module information structure
9419 ;; A modi is: [module-name-string file-name begin-point]
9421 (defvar verilog-cache-enabled t
9422 "Non-nil enables caching of signals, etc. Set to nil for debugging to make things SLOW!")
9424 (defvar verilog-modi-cache-list nil
9425 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
9426 For speeding up verilog-modi-get-* commands.
9427 Buffer-local.")
9428 (make-variable-buffer-local 'verilog-modi-cache-list)
9430 (defvar verilog-modi-cache-preserve-tick nil
9431 "Modification tick after which the cache is still considered valid.
9432 Use `verilog-preserve-modi-cache' to set it.")
9433 (defvar verilog-modi-cache-preserve-buffer nil
9434 "Modification tick after which the cache is still considered valid.
9435 Use `verilog-preserve-modi-cache' to set it.")
9436 (defvar verilog-modi-cache-current-enable nil
9437 "Non-nil means allow caching `verilog-modi-current', set by let().")
9438 (defvar verilog-modi-cache-current nil
9439 "Currently active `verilog-modi-current', if any, set by let().")
9440 (defvar verilog-modi-cache-current-max nil
9441 "Current endmodule point for `verilog-modi-cache-current', if any.")
9443 (defun verilog-modi-current ()
9444 "Return the modi structure for the module currently at point, possibly cached."
9445 (cond ((and verilog-modi-cache-current
9446 (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
9447 (<= (point) verilog-modi-cache-current-max))
9448 ;; Slow assertion, for debugging the cache:
9449 ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
9450 verilog-modi-cache-current)
9451 (verilog-modi-cache-current-enable
9452 (setq verilog-modi-cache-current (verilog-modi-current-get)
9453 verilog-modi-cache-current-max
9454 ;; The cache expires when we pass "endmodule" as then the
9455 ;; current modi may change to the next module
9456 ;; This relies on the AUTOs generally inserting, not deleting text
9457 (save-excursion
9458 (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
9459 verilog-modi-cache-current)
9461 (verilog-modi-current-get))))
9463 (defun verilog-modi-current-get ()
9464 "Return the modi structure for the module currently at point."
9465 (let* (name type pt)
9466 ;; read current module's name
9467 (save-excursion
9468 (verilog-re-search-backward-quick verilog-defun-re nil nil)
9469 (setq type (match-string-no-properties 0))
9470 (verilog-re-search-forward-quick "(" nil nil)
9471 (setq name (verilog-read-module-name))
9472 (setq pt (point)))
9473 ;; return modi - note this vector built two places
9474 (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
9476 (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
9477 (make-variable-buffer-local 'verilog-modi-lookup-cache)
9478 (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
9479 (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
9481 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
9482 "Find the file and point at which MODULE is defined.
9483 If ALLOW-CACHE is set, check and remember cache of previous lookups.
9484 Return modi if successful, else print message unless IGNORE-ERROR is true."
9485 (let* ((current (or (buffer-file-name) (current-buffer)))
9486 modi)
9487 ;; Check cache
9488 ;;(message "verilog-modi-lookup: %s" module)
9489 (cond ((and verilog-modi-lookup-cache
9490 verilog-cache-enabled
9491 allow-cache
9492 (setq modi (gethash module verilog-modi-lookup-cache))
9493 (equal verilog-modi-lookup-last-current current)
9494 ;; Iff hit is in current buffer, then tick must match
9495 (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
9496 (not (equal current (verilog-modi-file-or-buffer modi)))))
9497 ;;(message "verilog-modi-lookup: HIT %S" modi)
9498 modi)
9499 ;; Miss
9500 (t (let* ((realname (verilog-symbol-detick module t))
9501 (orig-filenames (verilog-module-filenames realname current))
9502 (filenames orig-filenames)
9503 mif)
9504 (while (and filenames (not mif))
9505 (if (not (setq mif (verilog-module-inside-filename-p realname (car filenames))))
9506 (setq filenames (cdr filenames))))
9507 ;; mif has correct form to become later elements of modi
9508 (cond (mif (setq modi mif))
9509 (t (setq modi nil)
9510 (or ignore-error
9511 (error (concat (verilog-point-text)
9512 ": Can't locate " module " module definition"
9513 (if (not (equal module realname))
9514 (concat " (Expanded macro to " realname ")")
9516 "\n Check the verilog-library-directories variable."
9517 "\n I looked in (if not listed, doesn't exist):\n\t"
9518 (mapconcat 'concat orig-filenames "\n\t"))))))
9519 (when (eval-when-compile (fboundp 'make-hash-table))
9520 (unless verilog-modi-lookup-cache
9521 (setq verilog-modi-lookup-cache
9522 (make-hash-table :test 'equal :rehash-size 4.0)))
9523 (puthash module modi verilog-modi-lookup-cache))
9524 (setq verilog-modi-lookup-last-current current
9525 verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
9526 modi))
9528 (defun verilog-modi-filename (modi)
9529 "Filename of MODI, or name of buffer if it's never been saved."
9530 (if (bufferp (verilog-modi-file-or-buffer modi))
9531 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
9532 (buffer-name (verilog-modi-file-or-buffer modi)))
9533 (verilog-modi-file-or-buffer modi)))
9535 (defun verilog-modi-goto (modi)
9536 "Move point/buffer to specified MODI."
9537 (or modi (error "Passed unfound modi to goto, check earlier"))
9538 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
9539 (verilog-modi-file-or-buffer modi)
9540 (find-file-noselect (verilog-modi-file-or-buffer modi))))
9541 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax
9542 (verilog-mode))
9543 (goto-char (verilog-modi-get-point modi)))
9545 (defun verilog-goto-defun-file (module)
9546 "Move point to the file at which a given MODULE is defined."
9547 (interactive "sGoto File for Module: ")
9548 (let* ((modi (verilog-modi-lookup module nil)))
9549 (when modi
9550 (verilog-modi-goto modi)
9551 (switch-to-buffer (current-buffer)))))
9553 (defun verilog-modi-cache-results (modi function)
9554 "Run on MODI the given FUNCTION. Locate the module in a file.
9555 Cache the output of function so next call may have faster access."
9556 (let (fass)
9557 (save-excursion ;; Cache is buffer-local so can't avoid this.
9558 (verilog-modi-goto modi)
9559 (if (and (setq fass (assoc (list modi function)
9560 verilog-modi-cache-list))
9561 ;; Destroy caching when incorrect; Modified or file changed
9562 (not (and verilog-cache-enabled
9563 (or (equal (buffer-chars-modified-tick) (nth 1 fass))
9564 (and verilog-modi-cache-preserve-tick
9565 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
9566 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
9567 (equal (visited-file-modtime) (nth 2 fass)))))
9568 (setq verilog-modi-cache-list nil
9569 fass nil))
9570 (cond (fass
9571 ;; Return data from cache hit
9572 (nth 3 fass))
9574 ;; Read from file
9575 ;; Clear then restore any highlighting to make emacs19 happy
9576 (let (func-returns)
9577 (verilog-save-font-mods
9578 (setq func-returns (funcall function)))
9579 ;; Cache for next time
9580 (setq verilog-modi-cache-list
9581 (cons (list (list modi function)
9582 (buffer-chars-modified-tick)
9583 (visited-file-modtime)
9584 func-returns)
9585 verilog-modi-cache-list))
9586 func-returns))))))
9588 (defun verilog-modi-cache-add (modi function element sig-list)
9589 "Add function return results to the module cache.
9590 Update MODI's cache for given FUNCTION so that the return ELEMENT of that
9591 function now contains the additional SIG-LIST parameters."
9592 (let (fass)
9593 (save-excursion
9594 (verilog-modi-goto modi)
9595 (if (setq fass (assoc (list modi function)
9596 verilog-modi-cache-list))
9597 (let ((func-returns (nth 3 fass)))
9598 (aset func-returns element
9599 (append sig-list (aref func-returns element))))))))
9601 (defmacro verilog-preserve-modi-cache (&rest body)
9602 "Execute the BODY forms, allowing cache preservation within BODY.
9603 This means that changes to the buffer will not result in the cache being
9604 flushed. If the changes affect the modsig state, they must call the
9605 modsig-cache-add-* function, else the results of later calls may be
9606 incorrect. Without this, changes are assumed to be adding/removing signals
9607 and invalidating the cache."
9608 `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
9609 (verilog-modi-cache-preserve-buffer (current-buffer)))
9610 (progn ,@body)))
9613 (defun verilog-modi-modport-lookup-one (modi name &optional ignore-error)
9614 "Given a MODI, return the declarations related to the given modport NAME."
9615 ;; Recursive routine - see below
9616 (let* ((realname (verilog-symbol-detick name t))
9617 (modport (assoc name (verilog-decls-get-modports (verilog-modi-get-decls modi)))))
9618 (or modport ignore-error
9619 (error (concat (verilog-point-text)
9620 ": Can't locate " name " modport definition"
9621 (if (not (equal name realname))
9622 (concat " (Expanded macro to " realname ")")
9623 ""))))
9624 (let* ((decls (verilog-modport-decls modport))
9625 (clks (verilog-modport-clockings modport)))
9626 ;; Now expand any clocking's
9627 (while clks
9628 (setq decls (verilog-decls-append
9629 decls
9630 (verilog-modi-modport-lookup-one modi (car clks) ignore-error)))
9631 (setq clks (cdr clks)))
9632 decls)))
9634 (defun verilog-modi-modport-lookup (modi name-re &optional ignore-error)
9635 "Given a MODI, return the declarations related to the given modport NAME-RE.
9636 If the modport points to any clocking blocks, expand the signals to include
9637 those clocking block's signals."
9638 ;; Recursive routine - see below
9639 (let* ((mod-decls (verilog-modi-get-decls modi))
9640 (clks (verilog-decls-get-modports mod-decls))
9641 (name-re (concat "^" name-re "$"))
9642 (decls (verilog-decls-new nil nil nil nil nil nil nil nil nil)))
9643 ;; Pull in all modports
9644 (while clks
9645 (when (string-match name-re (verilog-modport-name (car clks)))
9646 (setq decls (verilog-decls-append
9647 decls
9648 (verilog-modi-modport-lookup-one modi (verilog-modport-name (car clks)) ignore-error))))
9649 (setq clks (cdr clks)))
9650 decls))
9652 (defun verilog-signals-matching-enum (in-list enum)
9653 "Return all signals in IN-LIST matching the given ENUM."
9654 (let (out-list)
9655 (while in-list
9656 (if (equal (verilog-sig-enum (car in-list)) enum)
9657 (setq out-list (cons (car in-list) out-list)))
9658 (setq in-list (cdr in-list)))
9659 ;; New scheme
9660 (let* ((enumvar (intern (concat "venum-" enum)))
9661 (enumlist (and (boundp enumvar) (eval enumvar))))
9662 (while enumlist
9663 (add-to-list 'out-list (list (car enumlist)))
9664 (setq enumlist (cdr enumlist))))
9665 (nreverse out-list)))
9667 (defun verilog-signals-matching-regexp (in-list regexp)
9668 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
9669 (if (or (not regexp) (equal regexp ""))
9670 in-list
9671 (let (out-list)
9672 (while in-list
9673 (if (string-match regexp (verilog-sig-name (car in-list)))
9674 (setq out-list (cons (car in-list) out-list)))
9675 (setq in-list (cdr in-list)))
9676 (nreverse out-list))))
9678 (defun verilog-signals-not-matching-regexp (in-list regexp)
9679 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
9680 (if (or (not regexp) (equal regexp ""))
9681 in-list
9682 (let (out-list)
9683 (while in-list
9684 (if (not (string-match regexp (verilog-sig-name (car in-list))))
9685 (setq out-list (cons (car in-list) out-list)))
9686 (setq in-list (cdr in-list)))
9687 (nreverse out-list))))
9689 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
9690 "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
9691 if non-nil."
9692 (if (or (not regexp) (equal regexp ""))
9693 in-list
9694 (let (out-list to-match)
9695 (while in-list
9696 ;; Note verilog-insert-one-definition matches on this order
9697 (setq to-match (concat
9698 decl-type
9699 " " (verilog-sig-signed (car in-list))
9700 " " (verilog-sig-multidim (car in-list))
9701 (verilog-sig-bits (car in-list))))
9702 (if (string-match regexp to-match)
9703 (setq out-list (cons (car in-list) out-list)))
9704 (setq in-list (cdr in-list)))
9705 (nreverse out-list))))
9707 (defun verilog-signals-edit-wire-reg (in-list)
9708 "Return all signals in IN-LIST with wire/reg data types made blank."
9709 (mapcar (lambda (sig)
9710 (when (member (verilog-sig-type sig) '("wire" "reg"))
9711 (verilog-sig-type-set sig nil))
9712 sig) in-list))
9714 ;; Combined
9715 (defun verilog-decls-get-signals (decls)
9716 "Return all declared signals in DECLS, excluding 'assign' statements."
9717 (append
9718 (verilog-decls-get-outputs decls)
9719 (verilog-decls-get-inouts decls)
9720 (verilog-decls-get-inputs decls)
9721 (verilog-decls-get-vars decls)
9722 (verilog-decls-get-consts decls)
9723 (verilog-decls-get-gparams decls)))
9725 (defun verilog-decls-get-ports (decls)
9726 (append
9727 (verilog-decls-get-outputs decls)
9728 (verilog-decls-get-inouts decls)
9729 (verilog-decls-get-inputs decls)))
9731 (defun verilog-decls-get-iovars (decls)
9732 (append
9733 (verilog-decls-get-vars decls)
9734 (verilog-decls-get-outputs decls)
9735 (verilog-decls-get-inouts decls)
9736 (verilog-decls-get-inputs decls)))
9738 (defsubst verilog-modi-cache-add-outputs (modi sig-list)
9739 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
9740 (defsubst verilog-modi-cache-add-inouts (modi sig-list)
9741 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
9742 (defsubst verilog-modi-cache-add-inputs (modi sig-list)
9743 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
9744 (defsubst verilog-modi-cache-add-vars (modi sig-list)
9745 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
9746 (defsubst verilog-modi-cache-add-gparams (modi sig-list)
9747 (verilog-modi-cache-add modi 'verilog-read-decls 7 sig-list))
9751 ;; Auto creation utilities
9754 (defun verilog-auto-re-search-do (search-for func)
9755 "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
9756 (goto-char (point-min))
9757 (while (verilog-re-search-forward-quick search-for nil t)
9758 (funcall func)))
9760 (defun verilog-insert-one-definition (sig type indent-pt)
9761 "Print out a definition for SIG of the given TYPE,
9762 with appropriate INDENT-PT indentation."
9763 (indent-to indent-pt)
9764 ;; Note verilog-signals-matching-dir-re matches on this order
9765 (insert type)
9766 (when (verilog-sig-modport sig)
9767 (insert "." (verilog-sig-modport sig)))
9768 (when (verilog-sig-signed sig)
9769 (insert " " (verilog-sig-signed sig)))
9770 (when (verilog-sig-multidim sig)
9771 (insert " " (verilog-sig-multidim-string sig)))
9772 (when (verilog-sig-bits sig)
9773 (insert " " (verilog-sig-bits sig)))
9774 (indent-to (max 24 (+ indent-pt 16)))
9775 (unless (= (char-syntax (preceding-char)) ?\ )
9776 (insert " ")) ; Need space between "]name" if indent-to did nothing
9777 (insert (verilog-sig-name sig))
9778 (when (verilog-sig-memory sig)
9779 (insert " " (verilog-sig-memory sig))))
9781 (defun verilog-insert-definition (modi sigs direction indent-pt v2k &optional dont-sort)
9782 "Print out a definition for MODI's list of SIGS of the given DIRECTION,
9783 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
9784 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output.
9785 When MODI is non-null, also add to modi-cache, for tracking."
9786 (when modi
9787 (cond ((equal direction "wire")
9788 (verilog-modi-cache-add-vars modi sigs))
9789 ((equal direction "reg")
9790 (verilog-modi-cache-add-vars modi sigs))
9791 ((equal direction "output")
9792 (verilog-modi-cache-add-outputs modi sigs)
9793 (when verilog-auto-declare-nettype
9794 (verilog-modi-cache-add-vars modi sigs)))
9795 ((equal direction "input")
9796 (verilog-modi-cache-add-inputs modi sigs)
9797 (when verilog-auto-declare-nettype
9798 (verilog-modi-cache-add-vars modi sigs)))
9799 ((equal direction "inout")
9800 (verilog-modi-cache-add-inouts modi sigs)
9801 (when verilog-auto-declare-nettype
9802 (verilog-modi-cache-add-vars modi sigs)))
9803 ((equal direction "interface"))
9804 ((equal direction "parameter")
9805 (verilog-modi-cache-add-gparams modi sigs))
9807 (error "Unsupported verilog-insert-definition direction: %s" direction))))
9808 (or dont-sort
9809 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
9810 (while sigs
9811 (let ((sig (car sigs)))
9812 (verilog-insert-one-definition
9814 ;; Want "type x" or "output type x", not "wire type x"
9815 (cond ((or (verilog-sig-type sig)
9816 verilog-auto-wire-type)
9817 (concat
9818 (when (member direction '("input" "output" "inout"))
9819 (concat direction " "))
9820 (or (verilog-sig-type sig)
9821 verilog-auto-wire-type)))
9822 ((and verilog-auto-declare-nettype
9823 (member direction '("input" "output" "inout")))
9824 (concat direction " " verilog-auto-declare-nettype))
9826 direction))
9827 indent-pt)
9828 (insert (if v2k "," ";"))
9829 (if (or (not (verilog-sig-comment sig))
9830 (equal "" (verilog-sig-comment sig)))
9831 (insert "\n")
9832 (indent-to (max 48 (+ indent-pt 40)))
9833 (verilog-insert "// " (verilog-sig-comment sig) "\n"))
9834 (setq sigs (cdr sigs)))))
9836 (eval-when-compile
9837 (if (not (boundp 'indent-pt))
9838 (defvar indent-pt nil "Local used by insert-indent")))
9840 (defun verilog-insert-indent (&rest stuff)
9841 "Indent to position stored in local `indent-pt' variable, then insert STUFF.
9842 Presumes that any newlines end a list element."
9843 (let ((need-indent t))
9844 (while stuff
9845 (if need-indent (indent-to indent-pt))
9846 (setq need-indent nil)
9847 (verilog-insert (car stuff))
9848 (setq need-indent (string-match "\n$" (car stuff))
9849 stuff (cdr stuff)))))
9850 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
9852 (defun verilog-forward-or-insert-line ()
9853 "Move forward a line, unless at EOB, then insert a newline."
9854 (if (eobp) (insert "\n")
9855 (forward-line)))
9857 (defun verilog-repair-open-comma ()
9858 "Insert comma if previous argument is other than an open parenthesis or endif."
9859 ;; We can't just search backward for ) as it might be inside another expression.
9860 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
9861 (save-excursion
9862 (verilog-backward-syntactic-ws-quick)
9863 (when (and (not (save-excursion ;; Not beginning (, or existing ,
9864 (backward-char 1)
9865 (looking-at "[(,]")))
9866 (not (save-excursion ;; Not `endif, or user define
9867 (backward-char 1)
9868 (skip-chars-backward "[a-zA-Z0-9_`]")
9869 (looking-at "`"))))
9870 (insert ","))))
9872 (defun verilog-repair-close-comma ()
9873 "If point is at a comma followed by a close parenthesis, fix it.
9874 This repairs those mis-inserted by an AUTOARG."
9875 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
9876 (save-excursion
9877 (verilog-forward-close-paren)
9878 (backward-char 1)
9879 (verilog-backward-syntactic-ws-quick)
9880 (backward-char 1)
9881 (when (looking-at ",")
9882 (delete-char 1))))
9884 (defun verilog-get-list (start end)
9885 "Return the elements of a comma separated list between START and END."
9886 (interactive)
9887 (let ((my-list (list))
9888 my-string)
9889 (save-excursion
9890 (while (< (point) end)
9891 (when (re-search-forward "\\([^,{]+\\)" end t)
9892 (setq my-string (verilog-string-remove-spaces (match-string 1)))
9893 (setq my-list (nconc my-list (list my-string) ))
9894 (goto-char (match-end 0))))
9895 my-list)))
9897 (defun verilog-make-width-expression (range-exp)
9898 "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
9899 ;; strip off the []
9900 (cond ((not range-exp)
9901 "1")
9903 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
9904 (setq range-exp (match-string 1 range-exp)))
9905 (cond ((not range-exp)
9906 "1")
9907 ;; [#:#] We can compute a numeric result
9908 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
9909 range-exp)
9910 (int-to-string
9911 (1+ (abs (- (string-to-number (match-string 1 range-exp))
9912 (string-to-number (match-string 2 range-exp)))))))
9913 ;; [PARAM-1:0] can just return PARAM
9914 ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
9915 (match-string 1 range-exp))
9916 ;; [arbitrary] need math
9917 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
9918 (concat "(1+(" (match-string 1 range-exp) ")"
9919 (if (equal "0" (match-string 2 range-exp))
9920 "" ;; Don't bother with -(0)
9921 (concat "-(" (match-string 2 range-exp) ")"))
9922 ")"))
9923 (t nil)))))
9924 ;;(verilog-make-width-expression "`A:`B")
9926 (defun verilog-simplify-range-expression (expr)
9927 "Return a simplified range expression with constants eliminated from EXPR."
9928 ;; Note this is always called with brackets; ie [z] or [z:z]
9929 (if (not (string-match "[---+*()]" expr))
9930 expr ;; short-circuit
9931 (let ((out expr)
9932 (last-pass ""))
9933 (while (not (equal last-pass out))
9934 (setq last-pass out)
9935 ;; Prefix regexp needs beginning of match, or some symbol of
9936 ;; lesser or equal precedence. We assume the [:]'s exist in expr.
9937 ;; Ditto the end.
9938 (while (string-match
9939 (concat "\\([[({:*+-]\\)" ; - must be last
9940 "(\\<\\([0-9A-Za-z_]+\\))"
9941 "\\([])}:*+-]\\)")
9942 out)
9943 (setq out (replace-match "\\1\\2\\3" nil nil out)))
9944 (while (string-match
9945 (concat "\\([[({:*+-]\\)" ; - must be last
9946 "\\$clog2\\s *(\\<\\([0-9]+\\))"
9947 "\\([])}:*+-]\\)")
9948 out)
9949 (setq out (replace-match
9950 (concat
9951 (match-string 1 out)
9952 (int-to-string (verilog-clog2 (string-to-number (match-string 2 out))))
9953 (match-string 3 out))
9954 nil nil out)))
9955 ;; For precedence do * before +/-
9956 (while (string-match
9957 (concat "\\([[({:*+-]\\)"
9958 "\\([0-9]+\\)\\s *\\([*]\\)\\s *\\([0-9]+\\)"
9959 "\\([])}:*+-]\\)")
9960 out)
9961 (setq out (replace-match
9962 (concat (match-string 1 out)
9963 (int-to-string (* (string-to-number (match-string 2 out))
9964 (string-to-number (match-string 4 out))))
9965 (match-string 5 out))
9966 nil nil out)))
9967 (while (string-match
9968 (concat "\\([[({:+-]\\)" ; No * here as higher prec
9969 "\\([0-9]+\\)\\s *\\([---+]\\)\\s *\\([0-9]+\\)"
9970 "\\([])}:+-]\\)")
9971 out)
9972 (let ((pre (match-string 1 out))
9973 (lhs (string-to-number (match-string 2 out)))
9974 (rhs (string-to-number (match-string 4 out)))
9975 (post (match-string 5 out))
9976 val)
9977 (when (equal pre "-")
9978 (setq lhs (- lhs)))
9979 (setq val (if (equal (match-string 3 out) "-")
9980 (- lhs rhs)
9981 (+ lhs rhs))
9982 out (replace-match
9983 (concat (if (and (equal pre "-")
9984 (< val 0))
9985 "" ;; Not "--20" but just "-20"
9986 pre)
9987 (int-to-string val)
9988 post)
9989 nil nil out)) )))
9990 out)))
9992 ;;(verilog-simplify-range-expression "[1:3]") ;; 1
9993 ;;(verilog-simplify-range-expression "[(1):3]") ;; 1
9994 ;;(verilog-simplify-range-expression "[(((16)+1)+1+(1+1))]") ;;20
9995 ;;(verilog-simplify-range-expression "[(2*3+6*7)]") ;; 48
9996 ;;(verilog-simplify-range-expression "[(FOO*4-1*2)]") ;; FOO*4-2
9997 ;;(verilog-simplify-range-expression "[(FOO*4+1-1)]") ;; FOO*4+0
9998 ;;(verilog-simplify-range-expression "[(func(BAR))]") ;; func(BAR)
9999 ;;(verilog-simplify-range-expression "[FOO-1+1-1+1]") ;; FOO-0
10000 ;;(verilog-simplify-range-expression "[$clog2(2)]") ;; 1
10001 ;;(verilog-simplify-range-expression "[$clog2(7)]") ;; 3
10003 (defun verilog-clog2 (value)
10004 "Compute $clog2 - ceiling log2 of VALUE."
10005 (if (< value 1)
10007 (ceiling (/ (log value) (log 2)))))
10009 (defun verilog-typedef-name-p (variable-name)
10010 "Return true if the VARIABLE-NAME is a type definition."
10011 (when verilog-typedef-regexp
10012 (string-match verilog-typedef-regexp variable-name)))
10015 ;; Auto deletion
10018 (defun verilog-delete-autos-lined ()
10019 "Delete autos that occupy multiple lines, between begin and end comments."
10020 ;; The newline must not have a comment property, so we must
10021 ;; delete the end auto's newline, not the first newline
10022 (forward-line 1)
10023 (let ((pt (point)))
10024 (when (and
10025 (looking-at "\\s-*// Beginning")
10026 (search-forward "// End of automatic" nil t))
10027 ;; End exists
10028 (end-of-line)
10029 (forward-line 1)
10030 (delete-region pt (point)))))
10032 (defun verilog-delete-empty-auto-pair ()
10033 "Delete begin/end auto pair at point, if empty."
10034 (forward-line 0)
10035 (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
10036 "\\s-*// End of automatics\n"))
10037 (delete-region (point) (save-excursion (forward-line 2) (point)))))
10039 (defun verilog-forward-close-paren ()
10040 "Find the close parenthesis that match the current point.
10041 Ignore other close parenthesis with matching open parens."
10042 (let ((parens 1))
10043 (while (> parens 0)
10044 (unless (verilog-re-search-forward-quick "[()]" nil t)
10045 (error "%s: Mismatching ()" (verilog-point-text)))
10046 (cond ((= (preceding-char) ?\( )
10047 (setq parens (1+ parens)))
10048 ((= (preceding-char) ?\) )
10049 (setq parens (1- parens)))))))
10051 (defun verilog-backward-open-paren ()
10052 "Find the open parenthesis that match the current point.
10053 Ignore other open parenthesis with matching close parens."
10054 (let ((parens 1))
10055 (while (> parens 0)
10056 (unless (verilog-re-search-backward-quick "[()]" nil t)
10057 (error "%s: Mismatching ()" (verilog-point-text)))
10058 (cond ((= (following-char) ?\) )
10059 (setq parens (1+ parens)))
10060 ((= (following-char) ?\( )
10061 (setq parens (1- parens)))))))
10063 (defun verilog-backward-open-bracket ()
10064 "Find the open bracket that match the current point.
10065 Ignore other open bracket with matching close bracket."
10066 (let ((parens 1))
10067 (while (> parens 0)
10068 (unless (verilog-re-search-backward-quick "[][]" nil t)
10069 (error "%s: Mismatching []" (verilog-point-text)))
10070 (cond ((= (following-char) ?\] )
10071 (setq parens (1+ parens)))
10072 ((= (following-char) ?\[ )
10073 (setq parens (1- parens)))))))
10075 (defun verilog-delete-to-paren ()
10076 "Delete the automatic inst/sense/arg created by autos.
10077 Deletion stops at the matching end parenthesis, outside comments."
10078 (delete-region (point)
10079 (save-excursion
10080 (verilog-backward-open-paren)
10081 (verilog-forward-sexp-ign-cmt 1) ;; Moves to paren that closes argdecl's
10082 (backward-char 1)
10083 (point))))
10085 (defun verilog-auto-star-safe ()
10086 "Return if a .* AUTOINST is safe to delete or expand.
10087 It was created by the AUTOS themselves, or by the user."
10088 (and verilog-auto-star-expand
10089 (looking-at
10090 (concat "[ \t\n\f,]*\\([)]\\|// " verilog-inst-comment-re "\\)"))))
10092 (defun verilog-delete-auto-star-all ()
10093 "Delete a .* AUTOINST, if it is safe."
10094 (when (verilog-auto-star-safe)
10095 (verilog-delete-to-paren)))
10097 (defun verilog-delete-auto-star-implicit ()
10098 "Delete all .* implicit connections created by `verilog-auto-star'.
10099 This function will be called automatically at save unless
10100 `verilog-auto-star-save' is set, any non-templated expanded pins will be
10101 removed."
10102 (interactive)
10103 (let (paren-pt indent have-close-paren)
10104 (save-excursion
10105 (goto-char (point-min))
10106 ;; We need to match these even outside of comments.
10107 ;; For reasonable performance, we don't check if inside comments, sorry.
10108 (while (re-search-forward "// Implicit \\.\\*" nil t)
10109 (setq paren-pt (point))
10110 (beginning-of-line)
10111 (setq have-close-paren
10112 (save-excursion
10113 (when (search-forward ");" paren-pt t)
10114 (setq indent (current-indentation))
10115 t)))
10116 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
10117 (when have-close-paren
10118 ;; Delete extra commentary
10119 (save-excursion
10120 (while (progn
10121 (forward-line -1)
10122 (looking-at (concat "\\s *//\\s *" verilog-inst-comment-re "\n")))
10123 (delete-region (match-beginning 0) (match-end 0))))
10124 ;; If it is simple, we can put the ); on the same line as the last text
10125 (let ((rtn-pt (point)))
10126 (save-excursion
10127 (while (progn (backward-char 1)
10128 (looking-at "[ \t\n\f]")))
10129 (when (looking-at ",")
10130 (delete-region (+ 1 (point)) rtn-pt))))
10131 (when (bolp)
10132 (indent-to indent))
10133 (insert ");\n")
10134 ;; Still need to kill final comma - always is one as we put one after the .*
10135 (re-search-backward ",")
10136 (delete-char 1))))))
10138 (defun verilog-delete-auto ()
10139 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
10140 Use \\[verilog-auto] to re-insert the updated AUTOs.
10142 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
10143 called before and after this function, respectively."
10144 (interactive)
10145 (save-excursion
10146 (if (buffer-file-name)
10147 (find-file-noselect (buffer-file-name))) ;; To check we have latest version
10148 (verilog-save-no-change-functions
10149 (verilog-save-scan-cache
10150 ;; Allow user to customize
10151 (verilog-run-hooks 'verilog-before-delete-auto-hook)
10153 ;; Remove those that have multi-line insertions, possibly with parameters
10154 ;; We allow anything beginning with AUTO, so that users can add their own
10155 ;; patterns
10156 (verilog-auto-re-search-do
10157 (concat "/\\*AUTO[A-Za-z0-9_]+"
10158 ;; Optional parens or quoted parameter or .* for (((...)))
10159 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
10160 "\\*/")
10161 'verilog-delete-autos-lined)
10162 ;; Remove those that are in parenthesis
10163 (verilog-auto-re-search-do
10164 (concat "/\\*"
10165 (eval-when-compile
10166 (verilog-regexp-words
10167 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
10168 "AUTOSENSE")))
10169 "\\*/")
10170 'verilog-delete-to-paren)
10171 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
10172 (verilog-auto-re-search-do "\\.\\*"
10173 'verilog-delete-auto-star-all)
10174 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
10175 (goto-char (point-min))
10176 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
10177 (replace-match ""))
10179 ;; Final customize
10180 (verilog-run-hooks 'verilog-delete-auto-hook)))))
10183 ;; Auto inject
10186 (defun verilog-inject-auto ()
10187 "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
10189 Any always @ blocks with sensitivity lists that match computed lists will
10190 be replaced with /*AS*/ comments.
10192 Any cells will get /*AUTOINST*/ added to the end of the pin list.
10193 Pins with have identical names will be deleted.
10195 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
10196 support adding new ports. You may wish to delete older ports yourself.
10198 For example:
10200 module ExampInject (i, o);
10201 input i;
10202 input j;
10203 output o;
10204 always @ (i or j)
10205 o = i | j;
10206 InstModule instName
10207 (.foobar(baz),
10208 j(j));
10209 endmodule
10211 Typing \\[verilog-inject-auto] will make this into:
10213 module ExampInject (i, o/*AUTOARG*/
10214 // Inputs
10216 input i;
10217 output o;
10218 always @ (/*AS*/i or j)
10219 o = i | j;
10220 InstModule instName
10221 (.foobar(baz),
10222 /*AUTOINST*/
10223 // Outputs
10224 j(j));
10225 endmodule"
10226 (interactive)
10227 (verilog-auto t))
10229 (defun verilog-inject-arg ()
10230 "Inject AUTOARG into new code. See `verilog-inject-auto'."
10231 ;; Presume one module per file.
10232 (save-excursion
10233 (goto-char (point-min))
10234 (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
10235 (let ((endmodp (save-excursion
10236 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
10237 (point))))
10238 ;; See if there's already a comment .. inside a comment so not verilog-re-search
10239 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
10240 (verilog-re-search-forward-quick ";" nil t)
10241 (backward-char 1)
10242 (verilog-backward-syntactic-ws-quick)
10243 (backward-char 1) ; Moves to paren that closes argdecl's
10244 (when (looking-at ")")
10245 (verilog-insert "/*AUTOARG*/")))))))
10247 (defun verilog-inject-sense ()
10248 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
10249 (save-excursion
10250 (goto-char (point-min))
10251 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
10252 (let* ((start-pt (point))
10253 (modi (verilog-modi-current))
10254 (moddecls (verilog-modi-get-decls modi))
10255 pre-sigs
10256 got-sigs)
10257 (backward-char 1)
10258 (verilog-forward-sexp-ign-cmt 1)
10259 (backward-char 1) ;; End )
10260 (when (not (verilog-re-search-backward-quick "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
10261 (setq pre-sigs (verilog-signals-from-signame
10262 (verilog-read-signals start-pt (point)))
10263 got-sigs (verilog-auto-sense-sigs moddecls nil))
10264 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
10265 (verilog-signals-not-in got-sigs pre-sigs)))
10266 (delete-region start-pt (point))
10267 (verilog-insert "/*AS*/")))))))
10269 (defun verilog-inject-inst ()
10270 "Inject AUTOINST into new code. See `verilog-inject-auto'."
10271 (save-excursion
10272 (goto-char (point-min))
10273 ;; It's hard to distinguish modules; we'll instead search for pins.
10274 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t)
10275 (verilog-backward-open-paren) ;; Inst start
10276 (cond
10277 ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip.
10278 (forward-char 1)
10279 (verilog-forward-close-paren)) ;; Parameters done
10281 (forward-char 1)
10282 (let ((indent-pt (+ (current-column)))
10283 (end-pt (save-excursion (verilog-forward-close-paren) (point))))
10284 (cond ((verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
10285 (goto-char end-pt)) ;; Already there, continue search with next instance
10287 ;; Delete identical interconnect
10288 (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc
10289 (while (verilog-re-search-forward-quick "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
10290 (delete-region (match-beginning 0) (match-end 0))
10291 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct
10292 (while (or (looking-at "[ \t\n\f,]+")
10293 (looking-at "//[^\n]*"))
10294 (delete-region (match-beginning 0) (match-end 0))
10295 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
10296 (verilog-forward-close-paren)
10297 (backward-char 1)
10298 ;; Not verilog-re-search, as we don't want to strip comments
10299 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
10300 (delete-region (match-beginning 0) (match-end 0)))
10301 (verilog-insert "\n")
10302 (verilog-insert-indent "/*AUTOINST*/")))))))))
10305 ;; Auto diff
10308 (defun verilog-diff-buffers-p (b1 b2 &optional whitespace)
10309 "Return nil if buffers B1 and B2 have same contents.
10310 Else, return point in B1 that first mismatches.
10311 If optional WHITESPACE true, ignore whitespace."
10312 (save-excursion
10313 (let* ((case-fold-search nil) ;; compare-buffer-substrings cares
10314 (p1 (with-current-buffer b1 (goto-char (point-min))))
10315 (p2 (with-current-buffer b2 (goto-char (point-min))))
10316 (maxp1 (with-current-buffer b1 (point-max)))
10317 (maxp2 (with-current-buffer b2 (point-max)))
10318 (op1 -1) (op2 -1)
10319 progress size)
10320 (while (not (and (eq p1 op1) (eq p2 op2)))
10321 ;; If both windows have whitespace optionally skip over it.
10322 (when whitespace
10323 ;; skip-syntax-* doesn't count \n
10324 (with-current-buffer b1
10325 (goto-char p1)
10326 (skip-chars-forward " \t\n\r\f\v")
10327 (setq p1 (point)))
10328 (with-current-buffer b2
10329 (goto-char p2)
10330 (skip-chars-forward " \t\n\r\f\v")
10331 (setq p2 (point))))
10332 (setq size (min (- maxp1 p1) (- maxp2 p2)))
10333 (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
10334 b1 p1 (+ size p1)))
10335 (setq progress (if (zerop progress) size (1- (abs progress))))
10336 (setq op1 p1 op2 p2
10337 p1 (+ p1 progress)
10338 p2 (+ p2 progress)))
10339 ;; Return value
10340 (if (and (eq p1 maxp1) (eq p2 maxp2))
10341 nil p1))))
10343 (defun verilog-diff-file-with-buffer (f1 b2 &optional whitespace show)
10344 "View the differences between file F1 and buffer B2.
10345 This requires the external program `diff-command' to be in your `exec-path',
10346 and uses `diff-switches' in which you may want to have \"-u\" flag.
10347 Ignores WHITESPACE if t, and writes output to stdout if SHOW."
10348 ;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
10349 ;; call `diff' as `diff' has different calling semantics on different
10350 ;; versions of Emacs.
10351 (if (not (file-exists-p f1))
10352 (message "Buffer %s has no associated file on disc" (buffer-name b2))
10353 (with-temp-buffer "*Verilog-Diff*"
10354 (let ((outbuf (current-buffer))
10355 (f2 (make-temp-file "vm-diff-auto-")))
10356 (unwind-protect
10357 (progn
10358 (with-current-buffer b2
10359 (save-restriction
10360 (widen)
10361 (write-region (point-min) (point-max) f2 nil 'nomessage)))
10362 (call-process diff-command nil outbuf t
10363 diff-switches ;; User may want -u in diff-switches
10364 (if whitespace "-b" "")
10365 f1 f2)
10366 ;; Print out results. Alternatively we could have call-processed
10367 ;; ourself, but this way we can reuse diff switches
10368 (when show
10369 (with-current-buffer outbuf (message "%s" (buffer-string))))))
10370 (sit-for 0)
10371 (when (file-exists-p f2)
10372 (delete-file f2))))))
10374 (defun verilog-diff-report (b1 b2 diffpt)
10375 "Report differences detected with `verilog-diff-auto'.
10376 Differences are between buffers B1 and B2, starting at point
10377 DIFFPT. This function is called via `verilog-diff-function'."
10378 (let ((name1 (with-current-buffer b1 (buffer-file-name))))
10379 (verilog-warn "%s:%d: Difference in AUTO expansion found"
10380 name1 (with-current-buffer b1
10381 (1+ (count-lines (point-min) (point)))))
10382 (cond (noninteractive
10383 (verilog-diff-file-with-buffer name1 b2 t t))
10385 (ediff-buffers b1 b2)))))
10387 (defun verilog-diff-auto ()
10388 "Expand AUTOs in a temporary buffer and indicate any change.
10389 Whitespace differences are ignored to determine identicalness, but
10390 once a difference is detected, whitespace differences may be shown.
10392 To call this from the command line, see \\[verilog-batch-diff-auto].
10394 The action on differences is selected with
10395 `verilog-diff-function'. The default is `verilog-diff-report'
10396 which will report an error and run `ediff' in interactive mode,
10397 or `diff' in batch mode."
10398 (interactive)
10399 (let ((b1 (current-buffer)) b2 diffpt
10400 (name1 (buffer-file-name))
10401 (newname "*Verilog-Diff*"))
10402 (save-excursion
10403 (when (get-buffer newname)
10404 (kill-buffer newname))
10405 (setq b2 (let (buffer-file-name) ;; Else clone is upset
10406 (clone-buffer newname)))
10407 (with-current-buffer b2
10408 ;; auto requires the filename, but can't have same filename in two
10409 ;; buffers; so override both b1 and b2's names
10410 (let ((buffer-file-name name1))
10411 (unwind-protect
10412 (progn
10413 (with-current-buffer b1 (setq buffer-file-name nil))
10414 (verilog-auto)
10415 (when (not verilog-auto-star-save)
10416 (verilog-delete-auto-star-implicit)))
10417 ;; Restore name if unwind
10418 (with-current-buffer b1 (setq buffer-file-name name1)))))
10420 (setq diffpt (verilog-diff-buffers-p b1 b2 t))
10421 (cond ((not diffpt)
10422 (unless noninteractive (message "AUTO expansion identical"))
10423 (kill-buffer newname)) ;; Nice to cleanup after oneself
10425 (funcall verilog-diff-function b1 b2 diffpt)))
10426 ;; Return result of compare
10427 diffpt)))
10431 ;; Auto save
10434 (defun verilog-auto-save-check ()
10435 "On saving see if we need auto update."
10436 (cond ((not verilog-auto-save-policy)) ; disabled
10437 ((not (save-excursion
10438 (save-match-data
10439 (let ((case-fold-search nil))
10440 (goto-char (point-min))
10441 (re-search-forward "AUTO" nil t))))))
10442 ((eq verilog-auto-save-policy 'force)
10443 (verilog-auto))
10444 ((not (buffer-modified-p)))
10445 ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
10446 ((eq verilog-auto-save-policy 'detect)
10447 (verilog-auto))
10449 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
10450 (verilog-auto))
10451 ;; Don't ask again if didn't update
10452 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
10453 (when (not verilog-auto-star-save)
10454 (verilog-delete-auto-star-implicit))
10455 nil) ;; Always return nil -- we don't write the file ourselves
10457 (defun verilog-auto-read-locals ()
10458 "Return file local variable segment at bottom of file."
10459 (save-excursion
10460 (goto-char (point-max))
10461 (if (re-search-backward "Local Variables:" nil t)
10462 (buffer-substring-no-properties (point) (point-max))
10463 "")))
10465 (defun verilog-auto-reeval-locals (&optional force)
10466 "Read file local variable segment at bottom of file if it has changed.
10467 If FORCE, always reread it."
10468 (let ((curlocal (verilog-auto-read-locals)))
10469 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
10470 (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
10471 ;; Note this may cause this function to be recursively invoked,
10472 ;; because hack-local-variables may call (verilog-mode)
10473 ;; The above when statement will prevent it from recursing forever.
10474 (hack-local-variables)
10475 t)))
10478 ;; Auto creation
10481 (defun verilog-auto-arg-ports (sigs message indent-pt)
10482 "Print a list of ports for an AUTOINST.
10483 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
10484 (when sigs
10485 (when verilog-auto-arg-sort
10486 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
10487 (insert "\n")
10488 (indent-to indent-pt)
10489 (insert message)
10490 (insert "\n")
10491 (let ((space ""))
10492 (indent-to indent-pt)
10493 (while sigs
10494 (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
10495 (insert "\n")
10496 (indent-to indent-pt))
10497 (t (insert space)))
10498 (insert (verilog-sig-name (car sigs)) ",")
10499 (setq sigs (cdr sigs)
10500 space " ")))))
10502 (defun verilog-auto-arg ()
10503 "Expand AUTOARG statements.
10504 Replace the argument declarations at the beginning of the
10505 module with ones automatically derived from input and output
10506 statements. This can be dangerous if the module is instantiated
10507 using position-based connections, so use only name-based when
10508 instantiating the resulting module. Long lines are split based
10509 on the `fill-column', see \\[set-fill-column].
10511 Limitations:
10512 Concatenation and outputting partial buses is not supported.
10514 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10516 For example:
10518 module ExampArg (/*AUTOARG*/);
10519 input i;
10520 output o;
10521 endmodule
10523 Typing \\[verilog-auto] will make this into:
10525 module ExampArg (/*AUTOARG*/
10526 // Outputs
10528 // Inputs
10531 input i;
10532 output o;
10533 endmodule
10535 The argument declarations may be printed in declaration order to best suit
10536 order based instantiations, or alphabetically, based on the
10537 `verilog-auto-arg-sort' variable.
10539 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
10540 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
10541 conservative guess on adding a comma for the first signal, if you have
10542 any ifdefs or complicated expressions before the AUTOARG you will need
10543 to choose the comma yourself.
10545 Avoid declaring ports manually, as it makes code harder to maintain."
10546 (save-excursion
10547 (let* ((modi (verilog-modi-current))
10548 (moddecls (verilog-modi-get-decls modi))
10549 (skip-pins (aref (verilog-read-arg-pins) 0)))
10550 (verilog-repair-open-comma)
10551 (verilog-auto-arg-ports (verilog-signals-not-in
10552 (verilog-decls-get-outputs moddecls)
10553 skip-pins)
10554 "// Outputs"
10555 verilog-indent-level-declaration)
10556 (verilog-auto-arg-ports (verilog-signals-not-in
10557 (verilog-decls-get-inouts moddecls)
10558 skip-pins)
10559 "// Inouts"
10560 verilog-indent-level-declaration)
10561 (verilog-auto-arg-ports (verilog-signals-not-in
10562 (verilog-decls-get-inputs moddecls)
10563 skip-pins)
10564 "// Inputs"
10565 verilog-indent-level-declaration)
10566 (verilog-repair-close-comma)
10567 (unless (eq (char-before) ?/ )
10568 (insert "\n"))
10569 (indent-to verilog-indent-level-declaration))))
10571 (defun verilog-auto-assign-modport ()
10572 "Expand AUTOASSIGNMODPORT statements, as part of \\[verilog-auto].
10573 Take input/output/inout statements from the specified interface
10574 and modport and use to build assignments into the modport, for
10575 making verification modules that connect to UVM interfaces.
10577 The first parameter is the name of an interface.
10579 The second parameter is a regexp of modports to read from in
10580 that interface.
10582 The third parameter is the instance name to use to dot reference into.
10584 The optional fourth parameter is a regular expression, and only
10585 signals matching the regular expression will be included.
10587 Limitations:
10589 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
10591 Inouts are not supported, as assignments must be unidirectional.
10593 If a signal is part of the interface header and in both a
10594 modport and the interface itself, it will not be listed. (As
10595 this would result in a syntax error when the connections are
10596 made.)
10598 See the example in `verilog-auto-inout-modport'."
10599 (save-excursion
10600 (let* ((params (verilog-read-auto-params 3 4))
10601 (submod (nth 0 params))
10602 (modport-re (nth 1 params))
10603 (inst-name (nth 2 params))
10604 (regexp (nth 3 params))
10605 direction-re submodi) ;; direction argument not supported until requested
10606 ;; Lookup position, etc of co-module
10607 ;; Note this may raise an error
10608 (when (setq submodi (verilog-modi-lookup submod t))
10609 (let* ((indent-pt (current-indentation))
10610 (modi (verilog-modi-current))
10611 (submoddecls (verilog-modi-get-decls submodi))
10612 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
10613 (sig-list-i (verilog-signals-in ;; Decls doesn't have data types, must resolve
10614 (verilog-decls-get-vars submoddecls)
10615 (verilog-signals-not-in
10616 (verilog-decls-get-inputs submodportdecls)
10617 (verilog-decls-get-ports submoddecls))))
10618 (sig-list-o (verilog-signals-in ;; Decls doesn't have data types, must resolve
10619 (verilog-decls-get-vars submoddecls)
10620 (verilog-signals-not-in
10621 (verilog-decls-get-outputs submodportdecls)
10622 (verilog-decls-get-ports submoddecls)))))
10623 (forward-line 1)
10624 (setq sig-list-i (verilog-signals-edit-wire-reg
10625 (verilog-signals-matching-dir-re
10626 (verilog-signals-matching-regexp sig-list-i regexp)
10627 "input" direction-re))
10628 sig-list-o (verilog-signals-edit-wire-reg
10629 (verilog-signals-matching-dir-re
10630 (verilog-signals-matching-regexp sig-list-o regexp)
10631 "output" direction-re)))
10632 (setq sig-list-i (sort (copy-alist sig-list-i) `verilog-signals-sort-compare))
10633 (setq sig-list-o (sort (copy-alist sig-list-o) `verilog-signals-sort-compare))
10634 (when (or sig-list-i sig-list-o)
10635 (verilog-insert-indent "// Beginning of automatic assignments from modport\n")
10636 ;; Don't sort them so an upper AUTOINST will match the main module
10637 (let ((sigs sig-list-o))
10638 (while sigs
10639 (verilog-insert-indent "assign " (verilog-sig-name (car sigs))
10640 " = " inst-name
10641 "." (verilog-sig-name (car sigs)) ";\n")
10642 (setq sigs (cdr sigs))))
10643 (let ((sigs sig-list-i))
10644 (while sigs
10645 (verilog-insert-indent "assign " inst-name
10646 "." (verilog-sig-name (car sigs))
10647 " = " (verilog-sig-name (car sigs)) ";\n")
10648 (setq sigs (cdr sigs))))
10649 (verilog-insert-indent "// End of automatics\n")))))))
10651 (defun verilog-auto-inst-port-map (port-st)
10652 nil)
10654 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
10655 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
10656 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
10657 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
10658 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
10659 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
10660 (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
10661 (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
10663 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
10664 "Print out an instantiation connection for this PORT-ST.
10665 Insert to INDENT-PT, use template TPL-LIST.
10666 @ are instantiation numbers, replaced with TPL-NUM.
10667 @\"(expression @)\" are evaluated, with @ as a variable.
10668 If FOR-STAR add comment it is a .* expansion.
10669 If PAR-VALUES replace final strings with these parameter values."
10670 (let* ((port (verilog-sig-name port-st))
10671 (tpl-ass (or (assoc port (car tpl-list))
10672 (verilog-auto-inst-port-map port-st)))
10673 ;; vl-* are documented for user use
10674 (vl-name (verilog-sig-name port-st))
10675 (vl-width (verilog-sig-width port-st))
10676 (vl-modport (verilog-sig-modport port-st))
10677 (vl-mbits (if (verilog-sig-multidim port-st)
10678 (verilog-sig-multidim-string port-st) ""))
10679 (vl-bits (if (or verilog-auto-inst-vector
10680 (not (assoc port vector-skip-list))
10681 (not (equal (verilog-sig-bits port-st)
10682 (verilog-sig-bits (assoc port vector-skip-list)))))
10683 (or (verilog-sig-bits port-st) "")
10684 ""))
10685 (case-fold-search nil)
10686 (check-values par-values)
10687 tpl-net)
10688 ;; Replace parameters in bit-width
10689 (when (and check-values
10690 (not (equal vl-bits "")))
10691 (while check-values
10692 (setq vl-bits (verilog-string-replace-matches
10693 (concat "\\<" (nth 0 (car check-values)) "\\>")
10694 (concat "(" (nth 1 (car check-values)) ")")
10695 t t vl-bits)
10696 vl-mbits (verilog-string-replace-matches
10697 (concat "\\<" (nth 0 (car check-values)) "\\>")
10698 (concat "(" (nth 1 (car check-values)) ")")
10699 t t vl-mbits)
10700 check-values (cdr check-values)))
10701 (setq vl-bits (verilog-simplify-range-expression vl-bits)
10702 vl-mbits (verilog-simplify-range-expression vl-mbits)
10703 vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
10704 ;; Default net value if not found
10705 (setq tpl-net (concat port
10706 (if vl-modport (concat "." vl-modport) "")
10707 (if (verilog-sig-multidim port-st)
10708 (concat "/*" vl-mbits vl-bits "*/")
10709 (concat vl-bits))))
10710 ;; Find template
10711 (cond (tpl-ass ; Template of exact port name
10712 (setq tpl-net (nth 1 tpl-ass)))
10713 ((nth 1 tpl-list) ; Wildcards in template, search them
10714 (let ((wildcards (nth 1 tpl-list)))
10715 (while wildcards
10716 (when (string-match (nth 0 (car wildcards)) port)
10717 (setq tpl-ass (car wildcards) ; so allow @ parsing
10718 tpl-net (replace-match (nth 1 (car wildcards))
10719 t nil port)))
10720 (setq wildcards (cdr wildcards))))))
10721 ;; Parse Templated variable
10722 (when tpl-ass
10723 ;; Evaluate @"(lispcode)"
10724 (when (string-match "@\".*[^\\]\"" tpl-net)
10725 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
10726 (setq tpl-net
10727 (concat
10728 (substring tpl-net 0 (match-beginning 0))
10729 (save-match-data
10730 (let* ((expr (match-string 1 tpl-net))
10731 (value
10732 (progn
10733 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
10734 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
10735 (prin1 (eval (car (read-from-string expr)))
10736 (lambda (ch) ())))))
10737 (if (numberp value) (setq value (number-to-string value)))
10738 value))
10739 (substring tpl-net (match-end 0))))))
10740 ;; Replace @ and [] magic variables in final output
10741 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
10742 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
10743 ;; Insert it
10744 (indent-to indent-pt)
10745 (insert "." port)
10746 (unless (and verilog-auto-inst-dot-name
10747 (equal port tpl-net))
10748 (indent-to verilog-auto-inst-column)
10749 (insert "(" tpl-net ")"))
10750 (insert ",")
10751 (cond (tpl-ass
10752 (verilog-read-auto-template-hit tpl-ass)
10753 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
10754 verilog-auto-inst-column))
10755 ;; verilog-insert requires the complete comment in one call - including the newline
10756 (cond ((equal verilog-auto-inst-template-numbers `lhs)
10757 (verilog-insert " // Templated"
10758 " LHS: " (nth 0 tpl-ass)
10759 "\n"))
10760 (verilog-auto-inst-template-numbers
10761 (verilog-insert " // Templated"
10762 " T" (int-to-string (nth 2 tpl-ass))
10763 " L" (int-to-string (nth 3 tpl-ass))
10764 "\n"))
10766 (verilog-insert " // Templated\n"))))
10767 (for-star
10768 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
10769 verilog-auto-inst-column))
10770 (verilog-insert " // Implicit .\*\n")) ;For some reason the . or * must be escaped...
10772 (insert "\n")))))
10773 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
10774 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
10775 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
10777 (defun verilog-auto-inst-port-list (sig-list indent-pt tpl-list tpl-num for-star par-values)
10778 "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
10779 (when verilog-auto-inst-sort
10780 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)))
10781 (mapc (lambda (port)
10782 (verilog-auto-inst-port port indent-pt
10783 tpl-list tpl-num for-star par-values))
10784 sig-list))
10786 (defun verilog-auto-inst-first ()
10787 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
10788 ;; Do we need a trailing comma?
10789 ;; There maybe an ifdef or something similar before us. What a mess. Thus
10790 ;; to avoid trouble we only insert on preceding ) or *.
10791 ;; Insert first port on new line
10792 (insert "\n") ;; Must insert before search, so point will move forward if insert comma
10793 (save-excursion
10794 (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
10795 (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure
10796 (forward-char 1)
10797 (insert ","))))
10799 (defun verilog-auto-star ()
10800 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
10802 If `verilog-auto-star-expand' is set, .* pins are treated if they were
10803 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
10804 will also ignore any .* that are not last in your pin list (this prevents
10805 it from deleting pins following the .* when it expands the AUTOINST.)
10807 On writing your file, unless `verilog-auto-star-save' is set, any
10808 non-templated expanded pins will be removed. You may do this at any time
10809 with \\[verilog-delete-auto-star-implicit].
10811 If you are converting a module to use .* for the first time, you may wish
10812 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
10814 See `verilog-auto-inst' for examples, templates, and more information."
10815 (when (verilog-auto-star-safe)
10816 (verilog-auto-inst)))
10818 (defun verilog-auto-inst ()
10819 "Expand AUTOINST statements, as part of \\[verilog-auto].
10820 Replace the pin connections to an instantiation or interface
10821 declaration with ones automatically derived from the module or
10822 interface header of the instantiated item.
10824 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
10825 and delete them before saving unless `verilog-auto-star-save' is set.
10826 See `verilog-auto-star' for more information.
10828 The pins are printed in declaration order or alphabetically,
10829 based on the `verilog-auto-inst-sort' variable.
10831 Limitations:
10832 Module names must be resolvable to filenames by adding a
10833 `verilog-library-extensions', and being found in the same directory, or
10834 by changing the variable `verilog-library-flags' or
10835 `verilog-library-directories'. Macros `modname are translated through the
10836 vh-{name} Emacs variable, if that is not found, it just ignores the `.
10838 In templates you must have one signal per line, ending in a ), or ));,
10839 and have proper () nesting, including a final ); to end the template.
10841 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
10843 SystemVerilog multidimensional input/output has only experimental support.
10845 SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
10847 Parameters referenced by the instantiation will remain symbolic, unless
10848 `verilog-auto-inst-param-value' is set.
10850 Gate primitives (and/or) may have AUTOINST for the purpose of
10851 AUTOWIRE declarations, etc. Gates are the only case when
10852 position based connections are passed.
10854 For example, first take the submodule InstModule.v:
10856 module InstModule (o,i);
10857 output [31:0] o;
10858 input i;
10859 wire [31:0] o = {32{i}};
10860 endmodule
10862 This is then used in an upper level module:
10864 module ExampInst (o,i);
10865 output o;
10866 input i;
10867 InstModule instName
10868 (/*AUTOINST*/);
10869 endmodule
10871 Typing \\[verilog-auto] will make this into:
10873 module ExampInst (o,i);
10874 output o;
10875 input i;
10876 InstModule instName
10877 (/*AUTOINST*/
10878 // Outputs
10879 .ov (ov[31:0]),
10880 // Inputs
10881 .i (i));
10882 endmodule
10884 Where the list of inputs and outputs came from the inst module.
10886 Exceptions:
10888 Unless you are instantiating a module multiple times, or the module is
10889 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
10890 It just makes for unmaintainable code. To sanitize signal names, try
10891 vrename from URL `http://www.veripool.org'.
10893 When you need to violate this suggestion there are two ways to list
10894 exceptions, placing them before the AUTOINST, or using templates.
10896 Any ports defined before the /*AUTOINST*/ are not included in the list of
10897 automatics. This is similar to making a template as described below, but
10898 is restricted to simple connections just like you normally make. Also note
10899 that any signals before the AUTOINST will only be picked up by AUTOWIRE if
10900 you have the appropriate // Input or // Output comment, and exactly the
10901 same line formatting as AUTOINST itself uses.
10903 InstModule instName
10904 (// Inputs
10905 .i (my_i_dont_mess_with_it),
10906 /*AUTOINST*/
10907 // Outputs
10908 .ov (ov[31:0]));
10911 Templates:
10913 For multiple instantiations based upon a single template, create a
10914 commented out template:
10916 /* InstModule AUTO_TEMPLATE (
10917 .sig3 (sigz[]),
10921 Templates go ABOVE the instantiation(s). When an instantiation is
10922 expanded `verilog-mode' simply searches up for the closest template.
10923 Thus you can have multiple templates for the same module, just alternate
10924 between the template for an instantiation and the instantiation itself.
10925 (For backward compatibility if no template is found above, it
10926 will also look below, but do not use this behavior in new designs.)
10928 The module name must be the same as the name of the module in the
10929 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
10930 words and capitalized. Only signals that must be different for each
10931 instantiation need to be listed.
10933 Inside a template, a [] in a connection name (with nothing else inside
10934 the brackets) will be replaced by the same bus subscript as it is being
10935 connected to, or the [] will be removed if it is a single bit signal.
10936 Generally it is a good idea to do this for all connections in a template,
10937 as then they will work for any width signal, and with AUTOWIRE. See
10938 PTL_BUS becoming PTL_BUSNEW below.
10940 If you have a complicated template, set `verilog-auto-inst-template-numbers'
10941 to see which regexps are matching. Don't leave that mode set after
10942 debugging is completed though, it will result in lots of extra differences
10943 and merge conflicts.
10945 Setting `verilog-auto-template-warn-unused' will report errors
10946 if any template lines are unused.
10948 For example:
10950 /* InstModule AUTO_TEMPLATE (
10951 .ptl_bus (ptl_busnew[]),
10954 InstModule ms2m (/*AUTOINST*/);
10956 Typing \\[verilog-auto] will make this into:
10958 InstModule ms2m (/*AUTOINST*/
10959 // Outputs
10960 .NotInTemplate (NotInTemplate),
10961 .ptl_bus (ptl_busnew[3:0]), // Templated
10962 ....
10965 Multiple Module Templates:
10967 The same template lines can be applied to multiple modules with
10968 the syntax as follows:
10970 /* InstModuleA AUTO_TEMPLATE
10971 InstModuleB AUTO_TEMPLATE
10972 InstModuleC AUTO_TEMPLATE
10973 InstModuleD AUTO_TEMPLATE (
10974 .ptl_bus (ptl_busnew[]),
10978 Note there is only one AUTO_TEMPLATE opening parenthesis.
10980 @ Templates:
10982 It is common to instantiate a cell multiple times, so templates make it
10983 trivial to substitute part of the cell name into the connection name.
10985 /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
10986 .sig1 (sigx[@]),
10987 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
10991 If no regular expression is provided immediately after the AUTO_TEMPLATE
10992 keyword, then the @ character in any connection names will be replaced
10993 with the instantiation number; the first digits found in the cell's
10994 instantiation name.
10996 If a regular expression is provided, the @ character will be replaced
10997 with the first \(\) grouping that matches against the cell name. Using a
10998 regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no
10999 regexp is provided. If you use multiple layers of parenthesis,
11000 \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number
11001 characters after test and before _, whereas
11002 \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire
11003 match.
11005 For example:
11007 /* InstModule AUTO_TEMPLATE (
11008 .ptl_mapvalidx (ptl_mapvalid[@]),
11009 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
11012 InstModule ms2m (/*AUTOINST*/);
11014 Typing \\[verilog-auto] will make this into:
11016 InstModule ms2m (/*AUTOINST*/
11017 // Outputs
11018 .ptl_mapvalidx (ptl_mapvalid[2]),
11019 .ptl_mapvalidp1x (ptl_mapvalid[3]));
11021 Note the @ character was replaced with the 2 from \"ms2m\".
11023 Alternatively, using a regular expression for @:
11025 /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
11026 .ptl_mapvalidx (@_ptl_mapvalid),
11027 .ptl_mapvalidp1x (ptl_mapvalid_@),
11030 InstModule ms2_FOO (/*AUTOINST*/);
11031 InstModule ms2_BAR (/*AUTOINST*/);
11033 Typing \\[verilog-auto] will make this into:
11035 InstModule ms2_FOO (/*AUTOINST*/
11036 // Outputs
11037 .ptl_mapvalidx (FOO_ptl_mapvalid),
11038 .ptl_mapvalidp1x (ptl_mapvalid_FOO));
11039 InstModule ms2_BAR (/*AUTOINST*/
11040 // Outputs
11041 .ptl_mapvalidx (BAR_ptl_mapvalid),
11042 .ptl_mapvalidp1x (ptl_mapvalid_BAR));
11045 Regexp Templates:
11047 A template entry of the form
11049 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
11051 will apply an Emacs style regular expression search for any port beginning
11052 in pci_req followed by numbers and ending in _l and connecting that to
11053 the pci_req_jtag_[] net, with the bus subscript coming from what matches
11054 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
11056 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
11057 does the same thing. (Note a @ in the connection/replacement text is
11058 completely different -- still use \\1 there!) Thus this is the same as
11059 the above template:
11061 .pci_req@_l (pci_req_jtag_[\\1]),
11063 Here's another example to remove the _l, useful when naming conventions
11064 specify _ alone to mean active low. Note the use of [] to keep the bus
11065 subscript:
11067 .\\(.*\\)_l (\\1_[]),
11069 Lisp Templates:
11071 First any regular expression template is expanded.
11073 If the syntax @\"( ... )\" is found in a connection, the expression in
11074 quotes will be evaluated as a Lisp expression, with @ replaced by the
11075 instantiation number. The MAPVALIDP1X example above would put @+1 modulo
11076 4 into the brackets. Quote all double-quotes inside the expression with
11077 a leading backslash (\\\"...\\\"); or if the Lisp template is also a
11078 regexp template backslash the backslash quote (\\\\\"...\\\\\").
11080 There are special variables defined that are useful in these
11081 Lisp functions:
11083 vl-name Name portion of the input/output port.
11084 vl-bits Bus bits portion of the input/output port ('[2:0]').
11085 vl-mbits Multidimensional array bits for port ('[2:0][3:0]').
11086 vl-width Width of the input/output port ('3' for [2:0]).
11087 May be a (...) expression if bits isn't a constant.
11088 vl-dir Direction of the pin input/output/inout/interface.
11089 vl-modport The modport, if an interface with a modport.
11090 vl-cell-type Module name/type of the cell ('InstModule').
11091 vl-cell-name Instance name of the cell ('instName').
11093 Normal Lisp variables may be used in expressions. See
11094 `verilog-read-defines' which can set vh-{definename} variables for use
11095 here. Also, any comments of the form:
11097 /*AUTO_LISP(setq foo 1)*/
11099 will evaluate any Lisp expression inside the parenthesis between the
11100 beginning of the buffer and the point of the AUTOINST. This allows
11101 functions to be defined or variables to be changed between instantiations.
11102 (See also `verilog-auto-insert-lisp' if you want the output from your
11103 lisp function to be inserted.)
11105 Note that when using lisp expressions errors may occur when @ is not a
11106 number; you may need to use the standard Emacs Lisp functions
11107 `number-to-string' and `string-to-number'.
11109 After the evaluation is completed, @ substitution and [] substitution
11110 occur.
11112 For more information see the \\[verilog-faq] and forums at URL
11113 `http://www.veripool.org'."
11114 (save-excursion
11115 ;; Find beginning
11116 (let* ((pt (point))
11117 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
11118 (indent-pt (save-excursion (verilog-backward-open-paren)
11119 (1+ (current-column))))
11120 (verilog-auto-inst-column (max verilog-auto-inst-column
11121 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11122 (modi (verilog-modi-current))
11123 (moddecls (verilog-modi-get-decls modi))
11124 (vector-skip-list (unless verilog-auto-inst-vector
11125 (verilog-decls-get-signals moddecls)))
11126 submod submodi submoddecls
11127 inst skip-pins tpl-list tpl-num did-first par-values)
11129 ;; Find module name that is instantiated
11130 (setq submod (verilog-read-inst-module)
11131 inst (verilog-read-inst-name)
11132 vl-cell-type submod
11133 vl-cell-name inst
11134 skip-pins (aref (verilog-read-inst-pins) 0))
11136 ;; Parse any AUTO_LISP() before here
11137 (verilog-read-auto-lisp (point-min) pt)
11139 ;; Read parameters (after AUTO_LISP)
11140 (setq par-values (and verilog-auto-inst-param-value
11141 (verilog-read-inst-param-value)))
11143 ;; Lookup position, etc of submodule
11144 ;; Note this may raise an error
11145 (when (and (not (member submod verilog-gate-keywords))
11146 (setq submodi (verilog-modi-lookup submod t)))
11147 (setq submoddecls (verilog-modi-get-decls submodi))
11148 ;; If there's a number in the instantiation, it may be an argument to the
11149 ;; automatic variable instantiation program.
11150 (let* ((tpl-info (verilog-read-auto-template submod))
11151 (tpl-regexp (aref tpl-info 0)))
11152 (setq tpl-num (if (string-match tpl-regexp inst)
11153 (match-string 1 inst)
11155 tpl-list (aref tpl-info 1)))
11156 ;; Find submodule's signals and dump
11157 (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
11158 (verilog-signals-not-in
11159 (verilog-decls-get-vars submoddecls)
11160 skip-pins)))
11161 (vl-dir "interfaced"))
11162 (when (and sig-list
11163 verilog-auto-inst-interfaced-ports)
11164 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11165 ;; Note these are searched for in verilog-read-sub-decls.
11166 (verilog-insert-indent "// Interfaced\n")
11167 (verilog-auto-inst-port-list sig-list indent-pt
11168 tpl-list tpl-num for-star par-values)))
11169 (let ((sig-list (verilog-signals-not-in
11170 (verilog-decls-get-interfaces submoddecls)
11171 skip-pins))
11172 (vl-dir "interface"))
11173 (when sig-list
11174 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11175 ;; Note these are searched for in verilog-read-sub-decls.
11176 (verilog-insert-indent "// Interfaces\n")
11177 (verilog-auto-inst-port-list sig-list indent-pt
11178 tpl-list tpl-num for-star par-values)))
11179 (let ((sig-list (verilog-signals-not-in
11180 (verilog-decls-get-outputs submoddecls)
11181 skip-pins))
11182 (vl-dir "output"))
11183 (when sig-list
11184 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11185 (verilog-insert-indent "// Outputs\n")
11186 (verilog-auto-inst-port-list sig-list indent-pt
11187 tpl-list tpl-num for-star par-values)))
11188 (let ((sig-list (verilog-signals-not-in
11189 (verilog-decls-get-inouts submoddecls)
11190 skip-pins))
11191 (vl-dir "inout"))
11192 (when sig-list
11193 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11194 (verilog-insert-indent "// Inouts\n")
11195 (verilog-auto-inst-port-list sig-list indent-pt
11196 tpl-list tpl-num for-star par-values)))
11197 (let ((sig-list (verilog-signals-not-in
11198 (verilog-decls-get-inputs submoddecls)
11199 skip-pins))
11200 (vl-dir "input"))
11201 (when sig-list
11202 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11203 (verilog-insert-indent "// Inputs\n")
11204 (verilog-auto-inst-port-list sig-list indent-pt
11205 tpl-list tpl-num for-star par-values)))
11206 ;; Kill extra semi
11207 (save-excursion
11208 (cond (did-first
11209 (re-search-backward "," pt t)
11210 (delete-char 1)
11211 (insert ");")
11212 (search-forward "\n") ;; Added by inst-port
11213 (delete-char -1)
11214 (if (search-forward ")" nil t) ;; From user, moved up a line
11215 (delete-char -1))
11216 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it
11217 (delete-char -1)))))))))
11219 (defun verilog-auto-inst-param ()
11220 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
11221 Replace the parameter connections to an instantiation with ones
11222 automatically derived from the module header of the instantiated netlist.
11224 See \\[verilog-auto-inst] for limitations, and templates to customize the
11225 output.
11227 For example, first take the submodule InstModule.v:
11229 module InstModule (o,i);
11230 parameter PAR;
11231 endmodule
11233 This is then used in an upper level module:
11235 module ExampInst (o,i);
11236 parameter PAR;
11237 InstModule #(/*AUTOINSTPARAM*/)
11238 instName (/*AUTOINST*/);
11239 endmodule
11241 Typing \\[verilog-auto] will make this into:
11243 module ExampInst (o,i);
11244 output o;
11245 input i;
11246 InstModule #(/*AUTOINSTPARAM*/
11247 // Parameters
11248 .PAR (PAR));
11249 instName (/*AUTOINST*/);
11250 endmodule
11252 Where the list of parameter connections come from the inst module.
11254 Templates:
11256 You can customize the parameter connections using AUTO_TEMPLATEs,
11257 just as you would with \\[verilog-auto-inst]."
11258 (save-excursion
11259 ;; Find beginning
11260 (let* ((pt (point))
11261 (indent-pt (save-excursion (verilog-backward-open-paren)
11262 (1+ (current-column))))
11263 (verilog-auto-inst-column (max verilog-auto-inst-column
11264 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11265 (modi (verilog-modi-current))
11266 (moddecls (verilog-modi-get-decls modi))
11267 (vector-skip-list (unless verilog-auto-inst-vector
11268 (verilog-decls-get-signals moddecls)))
11269 submod submodi submoddecls
11270 inst skip-pins tpl-list tpl-num did-first)
11271 ;; Find module name that is instantiated
11272 (setq submod (save-excursion
11273 ;; Get to the point where AUTOINST normally is to read the module
11274 (verilog-re-search-forward-quick "[(;]" nil nil)
11275 (verilog-read-inst-module))
11276 inst (save-excursion
11277 ;; Get to the point where AUTOINST normally is to read the module
11278 (verilog-re-search-forward-quick "[(;]" nil nil)
11279 (verilog-read-inst-name))
11280 vl-cell-type submod
11281 vl-cell-name inst
11282 skip-pins (aref (verilog-read-inst-pins) 0))
11284 ;; Parse any AUTO_LISP() before here
11285 (verilog-read-auto-lisp (point-min) pt)
11287 ;; Lookup position, etc of submodule
11288 ;; Note this may raise an error
11289 (when (setq submodi (verilog-modi-lookup submod t))
11290 (setq submoddecls (verilog-modi-get-decls submodi))
11291 ;; If there's a number in the instantiation, it may be an argument to the
11292 ;; automatic variable instantiation program.
11293 (let* ((tpl-info (verilog-read-auto-template submod))
11294 (tpl-regexp (aref tpl-info 0)))
11295 (setq tpl-num (if (string-match tpl-regexp inst)
11296 (match-string 1 inst)
11298 tpl-list (aref tpl-info 1)))
11299 ;; Find submodule's signals and dump
11300 (let ((sig-list (verilog-signals-not-in
11301 (verilog-decls-get-gparams submoddecls)
11302 skip-pins))
11303 (vl-dir "parameter"))
11304 (when sig-list
11305 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11306 ;; Note these are searched for in verilog-read-sub-decls.
11307 (verilog-insert-indent "// Parameters\n")
11308 (verilog-auto-inst-port-list sig-list indent-pt
11309 tpl-list tpl-num nil nil)))
11310 ;; Kill extra semi
11311 (save-excursion
11312 (cond (did-first
11313 (re-search-backward "," pt t)
11314 (delete-char 1)
11315 (insert ")")
11316 (search-forward "\n") ;; Added by inst-port
11317 (delete-char -1)
11318 (if (search-forward ")" nil t) ;; From user, moved up a line
11319 (delete-char -1)))))))))
11321 (defun verilog-auto-reg ()
11322 "Expand AUTOREG statements, as part of \\[verilog-auto].
11323 Make reg statements for any output that isn't already declared,
11324 and isn't a wire output from a block. `verilog-auto-wire-type'
11325 may be used to change the datatype of the declarations.
11327 Limitations:
11328 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11330 This does NOT work on memories, declare those yourself.
11332 An example:
11334 module ExampReg (o,i);
11335 output o;
11336 input i;
11337 /*AUTOREG*/
11338 always o = i;
11339 endmodule
11341 Typing \\[verilog-auto] will make this into:
11343 module ExampReg (o,i);
11344 output o;
11345 input i;
11346 /*AUTOREG*/
11347 // Beginning of automatic regs (for this module's undeclared outputs)
11348 reg o;
11349 // End of automatics
11350 always o = i;
11351 endmodule"
11352 (save-excursion
11353 ;; Point must be at insertion point.
11354 (let* ((indent-pt (current-indentation))
11355 (modi (verilog-modi-current))
11356 (moddecls (verilog-modi-get-decls modi))
11357 (modsubdecls (verilog-modi-get-sub-decls modi))
11358 (sig-list (verilog-signals-not-in
11359 (verilog-decls-get-outputs moddecls)
11360 (append (verilog-signals-with ;; ignore typed signals
11361 'verilog-sig-type
11362 (verilog-decls-get-outputs moddecls))
11363 (verilog-decls-get-vars moddecls)
11364 (verilog-decls-get-assigns moddecls)
11365 (verilog-decls-get-consts moddecls)
11366 (verilog-decls-get-gparams moddecls)
11367 (verilog-subdecls-get-interfaced modsubdecls)
11368 (verilog-subdecls-get-outputs modsubdecls)
11369 (verilog-subdecls-get-inouts modsubdecls)))))
11370 (when sig-list
11371 (verilog-forward-or-insert-line)
11372 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
11373 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
11374 (verilog-insert-indent "// End of automatics\n")))))
11376 (defun verilog-auto-reg-input ()
11377 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
11378 Make reg statements instantiation inputs that aren't already declared.
11379 This is useful for making a top level shell for testing the module that is
11380 to be instantiated.
11382 Limitations:
11383 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
11385 This does NOT work on memories, declare those yourself.
11387 An example (see `verilog-auto-inst' for what else is going on here):
11389 module ExampRegInput (o,i);
11390 output o;
11391 input i;
11392 /*AUTOREGINPUT*/
11393 InstModule instName
11394 (/*AUTOINST*/);
11395 endmodule
11397 Typing \\[verilog-auto] will make this into:
11399 module ExampRegInput (o,i);
11400 output o;
11401 input i;
11402 /*AUTOREGINPUT*/
11403 // Beginning of automatic reg inputs (for undeclared ...
11404 reg [31:0] iv; // From inst of inst.v
11405 // End of automatics
11406 InstModule instName
11407 (/*AUTOINST*/
11408 // Outputs
11409 .o (o[31:0]),
11410 // Inputs
11411 .iv (iv));
11412 endmodule"
11413 (save-excursion
11414 ;; Point must be at insertion point.
11415 (let* ((indent-pt (current-indentation))
11416 (modi (verilog-modi-current))
11417 (moddecls (verilog-modi-get-decls modi))
11418 (modsubdecls (verilog-modi-get-sub-decls modi))
11419 (sig-list (verilog-signals-combine-bus
11420 (verilog-signals-not-in
11421 (append (verilog-subdecls-get-inputs modsubdecls)
11422 (verilog-subdecls-get-inouts modsubdecls))
11423 (append (verilog-decls-get-signals moddecls)
11424 (verilog-decls-get-assigns moddecls))))))
11425 (when sig-list
11426 (verilog-forward-or-insert-line)
11427 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
11428 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
11429 (verilog-insert-indent "// End of automatics\n")))))
11431 (defun verilog-auto-logic-setup ()
11432 "Prepare variables due to AUTOLOGIC."
11433 (unless verilog-auto-wire-type
11434 (set (make-local-variable 'verilog-auto-wire-type)
11435 "logic")))
11437 (defun verilog-auto-logic ()
11438 "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
11439 Make wire statements using the SystemVerilog logic keyword.
11440 This is currently equivalent to:
11442 /*AUTOWIRE*/
11444 with the below at the bottom of the file
11446 // Local Variables:
11447 // verilog-auto-logic-type:\"logic\"
11448 // End:
11450 In the future AUTOLOGIC may declare additional identifiers,
11451 while AUTOWIRE will not."
11452 (save-excursion
11453 (verilog-auto-logic-setup)
11454 (verilog-auto-wire)))
11456 (defun verilog-auto-wire ()
11457 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
11458 Make wire statements for instantiations outputs that aren't
11459 already declared. `verilog-auto-wire-type' may be used to change
11460 the datatype of the declarations.
11462 Limitations:
11463 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
11464 and all buses must have widths, such as those from AUTOINST, or using []
11465 in AUTO_TEMPLATEs.
11467 This does NOT work on memories or SystemVerilog .name connections,
11468 declare those yourself.
11470 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
11471 determine how to bus together. This occurs when you have ports with
11472 non-numeric or non-sequential bus subscripts. If Verilog mode
11473 mis-guessed, you'll have to declare them yourself.
11475 An example (see `verilog-auto-inst' for what else is going on here):
11477 module ExampWire (o,i);
11478 output o;
11479 input i;
11480 /*AUTOWIRE*/
11481 InstModule instName
11482 (/*AUTOINST*/);
11483 endmodule
11485 Typing \\[verilog-auto] will make this into:
11487 module ExampWire (o,i);
11488 output o;
11489 input i;
11490 /*AUTOWIRE*/
11491 // Beginning of automatic wires
11492 wire [31:0] ov; // From inst of inst.v
11493 // End of automatics
11494 InstModule instName
11495 (/*AUTOINST*/
11496 // Outputs
11497 .ov (ov[31:0]),
11498 // Inputs
11499 .i (i));
11500 wire o = | ov;
11501 endmodule"
11502 (save-excursion
11503 ;; Point must be at insertion point.
11504 (let* ((indent-pt (current-indentation))
11505 (modi (verilog-modi-current))
11506 (moddecls (verilog-modi-get-decls modi))
11507 (modsubdecls (verilog-modi-get-sub-decls modi))
11508 (sig-list (verilog-signals-combine-bus
11509 (verilog-signals-not-in
11510 (append (verilog-subdecls-get-outputs modsubdecls)
11511 (verilog-subdecls-get-inouts modsubdecls))
11512 (verilog-decls-get-signals moddecls)))))
11513 (when sig-list
11514 (verilog-forward-or-insert-line)
11515 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
11516 (verilog-insert-definition modi sig-list "wire" indent-pt nil)
11517 (verilog-insert-indent "// End of automatics\n")
11518 ;; We used to optionally call verilog-pretty-declarations and
11519 ;; verilog-pretty-expr here, but it's too slow on huge modules,
11520 ;; plus makes everyone's module change. Finally those call
11521 ;; syntax-ppss which is broken when change hooks are disabled.
11522 ))))
11524 (defun verilog-auto-output ()
11525 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
11526 Make output statements for any output signal from an /*AUTOINST*/ that
11527 isn't an input to another AUTOINST. This is useful for modules which
11528 only instantiate other modules.
11530 Limitations:
11531 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11533 If placed inside the parenthesis of a module declaration, it creates
11534 Verilog 2001 style, else uses Verilog 1995 style.
11536 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11537 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11539 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11541 Signals matching `verilog-auto-output-ignore-regexp' are not included.
11543 An example (see `verilog-auto-inst' for what else is going on here):
11545 module ExampOutput (ov,i);
11546 input i;
11547 /*AUTOOUTPUT*/
11548 InstModule instName
11549 (/*AUTOINST*/);
11550 endmodule
11552 Typing \\[verilog-auto] will make this into:
11554 module ExampOutput (ov,i);
11555 input i;
11556 /*AUTOOUTPUT*/
11557 // Beginning of automatic outputs (from unused autoinst outputs)
11558 output [31:0] ov; // From inst of inst.v
11559 // End of automatics
11560 InstModule instName
11561 (/*AUTOINST*/
11562 // Outputs
11563 .ov (ov[31:0]),
11564 // Inputs
11565 .i (i));
11566 endmodule
11568 You may also provide an optional regular expression, in which case only
11569 signals matching the regular expression will be included. For example the
11570 same expansion will result from only extracting outputs starting with ov:
11572 /*AUTOOUTPUT(\"^ov\")*/"
11573 (save-excursion
11574 ;; Point must be at insertion point.
11575 (let* ((indent-pt (current-indentation))
11576 (params (verilog-read-auto-params 0 1))
11577 (regexp (nth 0 params))
11578 (v2k (verilog-in-paren-quick))
11579 (modi (verilog-modi-current))
11580 (moddecls (verilog-modi-get-decls modi))
11581 (modsubdecls (verilog-modi-get-sub-decls modi))
11582 (sig-list (verilog-signals-not-in
11583 (verilog-subdecls-get-outputs modsubdecls)
11584 (append (verilog-decls-get-outputs moddecls)
11585 (verilog-decls-get-inouts moddecls)
11586 (verilog-subdecls-get-inputs modsubdecls)
11587 (verilog-subdecls-get-inouts modsubdecls)))))
11588 (when regexp
11589 (setq sig-list (verilog-signals-matching-regexp
11590 sig-list regexp)))
11591 (setq sig-list (verilog-signals-not-matching-regexp
11592 sig-list verilog-auto-output-ignore-regexp))
11593 (verilog-forward-or-insert-line)
11594 (when v2k (verilog-repair-open-comma))
11595 (when sig-list
11596 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
11597 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
11598 (verilog-insert-indent "// End of automatics\n"))
11599 (when v2k (verilog-repair-close-comma)))))
11601 (defun verilog-auto-output-every ()
11602 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
11603 Make output statements for any signals that aren't primary inputs or
11604 outputs already. This makes every signal in the design an output. This is
11605 useful to get Synopsys to preserve every signal in the design, since it
11606 won't optimize away the outputs.
11608 An example:
11610 module ExampOutputEvery (o,i,tempa,tempb);
11611 output o;
11612 input i;
11613 /*AUTOOUTPUTEVERY*/
11614 wire tempa = i;
11615 wire tempb = tempa;
11616 wire o = tempb;
11617 endmodule
11619 Typing \\[verilog-auto] will make this into:
11621 module ExampOutputEvery (o,i,tempa,tempb);
11622 output o;
11623 input i;
11624 /*AUTOOUTPUTEVERY*/
11625 // Beginning of automatic outputs (every signal)
11626 output tempb;
11627 output tempa;
11628 // End of automatics
11629 wire tempa = i;
11630 wire tempb = tempa;
11631 wire o = tempb;
11632 endmodule"
11633 (save-excursion
11634 ;;Point must be at insertion point
11635 (let* ((indent-pt (current-indentation))
11636 (v2k (verilog-in-paren-quick))
11637 (modi (verilog-modi-current))
11638 (moddecls (verilog-modi-get-decls modi))
11639 (sig-list (verilog-signals-combine-bus
11640 (verilog-signals-not-in
11641 (verilog-decls-get-signals moddecls)
11642 (verilog-decls-get-ports moddecls)))))
11643 (verilog-forward-or-insert-line)
11644 (when v2k (verilog-repair-open-comma))
11645 (when sig-list
11646 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
11647 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
11648 (verilog-insert-indent "// End of automatics\n"))
11649 (when v2k (verilog-repair-close-comma)))))
11651 (defun verilog-auto-input ()
11652 "Expand AUTOINPUT statements, as part of \\[verilog-auto].
11653 Make input statements for any input signal into an /*AUTOINST*/ that
11654 isn't declared elsewhere inside the module. This is useful for modules which
11655 only instantiate other modules.
11657 Limitations:
11658 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11660 If placed inside the parenthesis of a module declaration, it creates
11661 Verilog 2001 style, else uses Verilog 1995 style.
11663 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11664 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11666 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11668 Signals matching `verilog-auto-input-ignore-regexp' are not included.
11670 An example (see `verilog-auto-inst' for what else is going on here):
11672 module ExampInput (ov,i);
11673 output [31:0] ov;
11674 /*AUTOINPUT*/
11675 InstModule instName
11676 (/*AUTOINST*/);
11677 endmodule
11679 Typing \\[verilog-auto] will make this into:
11681 module ExampInput (ov,i);
11682 output [31:0] ov;
11683 /*AUTOINPUT*/
11684 // Beginning of automatic inputs (from unused autoinst inputs)
11685 input i; // From inst of inst.v
11686 // End of automatics
11687 InstModule instName
11688 (/*AUTOINST*/
11689 // Outputs
11690 .ov (ov[31:0]),
11691 // Inputs
11692 .i (i));
11693 endmodule
11695 You may also provide an optional regular expression, in which case only
11696 signals matching the regular expression will be included. For example the
11697 same expansion will result from only extracting inputs starting with i:
11699 /*AUTOINPUT(\"^i\")*/"
11700 (save-excursion
11701 (let* ((indent-pt (current-indentation))
11702 (params (verilog-read-auto-params 0 1))
11703 (regexp (nth 0 params))
11704 (v2k (verilog-in-paren-quick))
11705 (modi (verilog-modi-current))
11706 (moddecls (verilog-modi-get-decls modi))
11707 (modsubdecls (verilog-modi-get-sub-decls modi))
11708 (sig-list (verilog-signals-not-in
11709 (verilog-subdecls-get-inputs modsubdecls)
11710 (append (verilog-decls-get-inputs moddecls)
11711 (verilog-decls-get-inouts moddecls)
11712 (verilog-decls-get-vars moddecls)
11713 (verilog-decls-get-consts moddecls)
11714 (verilog-decls-get-gparams moddecls)
11715 (verilog-subdecls-get-interfaced modsubdecls)
11716 (verilog-subdecls-get-outputs modsubdecls)
11717 (verilog-subdecls-get-inouts modsubdecls)))))
11718 (when regexp
11719 (setq sig-list (verilog-signals-matching-regexp
11720 sig-list regexp)))
11721 (setq sig-list (verilog-signals-not-matching-regexp
11722 sig-list verilog-auto-input-ignore-regexp))
11723 (verilog-forward-or-insert-line)
11724 (when v2k (verilog-repair-open-comma))
11725 (when sig-list
11726 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
11727 (verilog-insert-definition modi sig-list "input" indent-pt v2k)
11728 (verilog-insert-indent "// End of automatics\n"))
11729 (when v2k (verilog-repair-close-comma)))))
11731 (defun verilog-auto-inout ()
11732 "Expand AUTOINOUT statements, as part of \\[verilog-auto].
11733 Make inout statements for any inout signal in an /*AUTOINST*/ that
11734 isn't declared elsewhere inside the module.
11736 Limitations:
11737 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11739 If placed inside the parenthesis of a module declaration, it creates
11740 Verilog 2001 style, else uses Verilog 1995 style.
11742 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11743 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11745 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11747 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
11749 An example (see `verilog-auto-inst' for what else is going on here):
11751 module ExampInout (ov,i);
11752 input i;
11753 /*AUTOINOUT*/
11754 InstModule instName
11755 (/*AUTOINST*/);
11756 endmodule
11758 Typing \\[verilog-auto] will make this into:
11760 module ExampInout (ov,i);
11761 input i;
11762 /*AUTOINOUT*/
11763 // Beginning of automatic inouts (from unused autoinst inouts)
11764 inout [31:0] ov; // From inst of inst.v
11765 // End of automatics
11766 InstModule instName
11767 (/*AUTOINST*/
11768 // Inouts
11769 .ov (ov[31:0]),
11770 // Inputs
11771 .i (i));
11772 endmodule
11774 You may also provide an optional regular expression, in which case only
11775 signals matching the regular expression will be included. For example the
11776 same expansion will result from only extracting inouts starting with i:
11778 /*AUTOINOUT(\"^i\")*/"
11779 (save-excursion
11780 ;; Point must be at insertion point.
11781 (let* ((indent-pt (current-indentation))
11782 (params (verilog-read-auto-params 0 1))
11783 (regexp (nth 0 params))
11784 (v2k (verilog-in-paren-quick))
11785 (modi (verilog-modi-current))
11786 (moddecls (verilog-modi-get-decls modi))
11787 (modsubdecls (verilog-modi-get-sub-decls modi))
11788 (sig-list (verilog-signals-not-in
11789 (verilog-subdecls-get-inouts modsubdecls)
11790 (append (verilog-decls-get-outputs moddecls)
11791 (verilog-decls-get-inouts moddecls)
11792 (verilog-decls-get-inputs moddecls)
11793 (verilog-subdecls-get-inputs modsubdecls)
11794 (verilog-subdecls-get-outputs modsubdecls)))))
11795 (when regexp
11796 (setq sig-list (verilog-signals-matching-regexp
11797 sig-list regexp)))
11798 (setq sig-list (verilog-signals-not-matching-regexp
11799 sig-list verilog-auto-inout-ignore-regexp))
11800 (verilog-forward-or-insert-line)
11801 (when v2k (verilog-repair-open-comma))
11802 (when sig-list
11803 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
11804 (verilog-insert-definition modi sig-list "inout" indent-pt v2k)
11805 (verilog-insert-indent "// End of automatics\n"))
11806 (when v2k (verilog-repair-close-comma)))))
11808 (defun verilog-auto-inout-module (&optional complement all-in)
11809 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
11810 Take input/output/inout statements from the specified module and insert
11811 into the current module. This is useful for making null templates and
11812 shell modules which need to have identical I/O with another module.
11813 Any I/O which are already defined in this module will not be redefined.
11814 For the complement of this function, see `verilog-auto-inout-comp',
11815 and to make monitors with all inputs, see `verilog-auto-inout-in'.
11817 Limitations:
11818 If placed inside the parenthesis of a module declaration, it creates
11819 Verilog 2001 style, else uses Verilog 1995 style.
11821 Concatenation and outputting partial buses is not supported.
11823 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11825 Signals are not inserted in the same order as in the original module,
11826 though they will appear to be in the same order to an AUTOINST
11827 instantiating either module.
11829 Signals declared as \"output reg\" or \"output wire\" etc will
11830 lose the wire/reg declaration so that shell modules may
11831 generate those outputs differently. However, \"output logic\"
11832 is propagated.
11834 An example:
11836 module ExampShell (/*AUTOARG*/);
11837 /*AUTOINOUTMODULE(\"ExampMain\")*/
11838 endmodule
11840 module ExampMain (i,o,io);
11841 input i;
11842 output o;
11843 inout io;
11844 endmodule
11846 Typing \\[verilog-auto] will make this into:
11848 module ExampShell (/*AUTOARG*/i,o,io);
11849 /*AUTOINOUTMODULE(\"ExampMain\")*/
11850 // Beginning of automatic in/out/inouts (from specific module)
11851 output o;
11852 inout io;
11853 input i;
11854 // End of automatics
11855 endmodule
11857 You may also provide an optional regular expression, in which case only
11858 signals matching the regular expression will be included. For example the
11859 same expansion will result from only extracting signals starting with i:
11861 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
11863 You may also provide an optional second regular expression, in
11864 which case only signals which have that pin direction and data
11865 type will be included. This matches against everything before
11866 the signal name in the declaration, for example against
11867 \"input\" (single bit), \"output logic\" (direction and type) or
11868 \"output [1:0]\" (direction and implicit type). You also
11869 probably want to skip spaces in your regexp.
11871 For example, the below will result in matching the output \"o\"
11872 against the previous example's module:
11874 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/"
11875 (save-excursion
11876 (let* ((params (verilog-read-auto-params 1 3))
11877 (submod (nth 0 params))
11878 (regexp (nth 1 params))
11879 (direction-re (nth 2 params))
11880 submodi)
11881 ;; Lookup position, etc of co-module
11882 ;; Note this may raise an error
11883 (when (setq submodi (verilog-modi-lookup submod t))
11884 (let* ((indent-pt (current-indentation))
11885 (v2k (verilog-in-paren-quick))
11886 (modi (verilog-modi-current))
11887 (moddecls (verilog-modi-get-decls modi))
11888 (submoddecls (verilog-modi-get-decls submodi))
11889 (sig-list-i (verilog-signals-not-in
11890 (cond (all-in
11891 (append
11892 (verilog-decls-get-inputs submoddecls)
11893 (verilog-decls-get-inouts submoddecls)
11894 (verilog-decls-get-outputs submoddecls)))
11895 (complement
11896 (verilog-decls-get-outputs submoddecls))
11897 (t (verilog-decls-get-inputs submoddecls)))
11898 (append (verilog-decls-get-inputs moddecls))))
11899 (sig-list-o (verilog-signals-not-in
11900 (cond (all-in nil)
11901 (complement
11902 (verilog-decls-get-inputs submoddecls))
11903 (t (verilog-decls-get-outputs submoddecls)))
11904 (append (verilog-decls-get-outputs moddecls))))
11905 (sig-list-io (verilog-signals-not-in
11906 (cond (all-in nil)
11907 (t (verilog-decls-get-inouts submoddecls)))
11908 (append (verilog-decls-get-inouts moddecls))))
11909 (sig-list-if (verilog-signals-not-in
11910 (verilog-decls-get-interfaces submoddecls)
11911 (append (verilog-decls-get-interfaces moddecls)))))
11912 (forward-line 1)
11913 (setq sig-list-i (verilog-signals-edit-wire-reg
11914 (verilog-signals-matching-dir-re
11915 (verilog-signals-matching-regexp sig-list-i regexp)
11916 "input" direction-re))
11917 sig-list-o (verilog-signals-edit-wire-reg
11918 (verilog-signals-matching-dir-re
11919 (verilog-signals-matching-regexp sig-list-o regexp)
11920 "output" direction-re))
11921 sig-list-io (verilog-signals-edit-wire-reg
11922 (verilog-signals-matching-dir-re
11923 (verilog-signals-matching-regexp sig-list-io regexp)
11924 "inout" direction-re))
11925 sig-list-if (verilog-signals-matching-dir-re
11926 (verilog-signals-matching-regexp sig-list-if regexp)
11927 "interface" direction-re))
11928 (when v2k (verilog-repair-open-comma))
11929 (when (or sig-list-i sig-list-o sig-list-io)
11930 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
11931 ;; Don't sort them so an upper AUTOINST will match the main module
11932 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
11933 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
11934 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
11935 (verilog-insert-definition modi sig-list-if "interface" indent-pt v2k t)
11936 (verilog-insert-indent "// End of automatics\n"))
11937 (when v2k (verilog-repair-close-comma)))))))
11939 (defun verilog-auto-inout-comp ()
11940 "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
11941 Take input/output/inout statements from the specified module and
11942 insert the inverse into the current module (inputs become outputs
11943 and vice-versa.) This is useful for making test and stimulus
11944 modules which need to have complementing I/O with another module.
11945 Any I/O which are already defined in this module will not be
11946 redefined. For the complement of this function, see
11947 `verilog-auto-inout-module'.
11949 Limitations:
11950 If placed inside the parenthesis of a module declaration, it creates
11951 Verilog 2001 style, else uses Verilog 1995 style.
11953 Concatenation and outputting partial buses is not supported.
11955 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11957 Signals are not inserted in the same order as in the original module,
11958 though they will appear to be in the same order to an AUTOINST
11959 instantiating either module.
11961 An example:
11963 module ExampShell (/*AUTOARG*/);
11964 /*AUTOINOUTCOMP(\"ExampMain\")*/
11965 endmodule
11967 module ExampMain (i,o,io);
11968 input i;
11969 output o;
11970 inout io;
11971 endmodule
11973 Typing \\[verilog-auto] will make this into:
11975 module ExampShell (/*AUTOARG*/i,o,io);
11976 /*AUTOINOUTCOMP(\"ExampMain\")*/
11977 // Beginning of automatic in/out/inouts (from specific module)
11978 output i;
11979 inout io;
11980 input o;
11981 // End of automatics
11982 endmodule
11984 You may also provide an optional regular expression, in which case only
11985 signals matching the regular expression will be included. For example the
11986 same expansion will result from only extracting signals starting with i:
11988 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
11989 (verilog-auto-inout-module t nil))
11991 (defun verilog-auto-inout-in ()
11992 "Expand AUTOINOUTIN statements, as part of \\[verilog-auto].
11993 Take input/output/inout statements from the specified module and
11994 insert them as all inputs into the current module. This is
11995 useful for making monitor modules which need to see all signals
11996 as inputs based on another module. Any I/O which are already
11997 defined in this module will not be redefined. See also
11998 `verilog-auto-inout-module'.
12000 Limitations:
12001 If placed inside the parenthesis of a module declaration, it creates
12002 Verilog 2001 style, else uses Verilog 1995 style.
12004 Concatenation and outputting partial buses is not supported.
12006 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12008 Signals are not inserted in the same order as in the original module,
12009 though they will appear to be in the same order to an AUTOINST
12010 instantiating either module.
12012 An example:
12014 module ExampShell (/*AUTOARG*/);
12015 /*AUTOINOUTIN(\"ExampMain\")*/
12016 endmodule
12018 module ExampMain (i,o,io);
12019 input i;
12020 output o;
12021 inout io;
12022 endmodule
12024 Typing \\[verilog-auto] will make this into:
12026 module ExampShell (/*AUTOARG*/i,o,io);
12027 /*AUTOINOUTIN(\"ExampMain\")*/
12028 // Beginning of automatic in/out/inouts (from specific module)
12029 input i;
12030 input io;
12031 input o;
12032 // End of automatics
12033 endmodule
12035 You may also provide an optional regular expression, in which case only
12036 signals matching the regular expression will be included. For example the
12037 same expansion will result from only extracting signals starting with i:
12039 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
12040 (verilog-auto-inout-module nil t))
12042 (defun verilog-auto-inout-param ()
12043 "Expand AUTOINOUTPARAM statements, as part of \\[verilog-auto].
12044 Take input/output/inout statements from the specified module and insert
12045 into the current module. This is useful for making null templates and
12046 shell modules which need to have identical I/O with another module.
12047 Any I/O which are already defined in this module will not be redefined.
12048 For the complement of this function, see `verilog-auto-inout-comp',
12049 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12051 Limitations:
12052 If placed inside the parenthesis of a module declaration, it creates
12053 Verilog 2001 style, else uses Verilog 1995 style.
12055 Concatenation and outputting partial buses is not supported.
12057 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12059 Signals are not inserted in the same order as in the original module,
12060 though they will appear to be in the same order to an AUTOINST
12061 instantiating either module.
12063 Signals declared as \"output reg\" or \"output wire\" etc will
12064 lose the wire/reg declaration so that shell modules may
12065 generate those outputs differently. However, \"output logic\"
12066 is propagated.
12068 An example:
12070 module ExampShell (/*AUTOARG*/);
12071 /*AUTOINOUTMODULE(\"ExampMain\")*/
12072 endmodule
12074 module ExampMain (i,o,io);
12075 input i;
12076 output o;
12077 inout io;
12078 endmodule
12080 Typing \\[verilog-auto] will make this into:
12082 module ExampShell (/*AUTOARG*/i,o,io);
12083 /*AUTOINOUTMODULE(\"ExampMain\")*/
12084 // Beginning of automatic in/out/inouts (from specific module)
12085 output o;
12086 inout io;
12087 input i;
12088 // End of automatics
12089 endmodule
12091 You may also provide an optional regular expression, in which case only
12092 signals matching the regular expression will be included. For example the
12093 same expansion will result from only extracting signals starting with i:
12095 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
12097 You may also provide an optional second regular expression, in
12098 which case only signals which have that pin direction and data
12099 type will be included. This matches against everything before
12100 the signal name in the declaration, for example against
12101 \"input\" (single bit), \"output logic\" (direction and type) or
12102 \"output [1:0]\" (direction and implicit type). You also
12103 probably want to skip spaces in your regexp.
12105 For example, the below will result in matching the output \"o\"
12106 against the previous example's module:
12108 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/
12110 You may also provide an optional third regular expression, in
12111 which case any parameter names that match the given regexp will
12112 be included. Including parameters is off by default. To include
12113 all signals and parameters, use:
12115 /*AUTOINOUTMODULE(\"ExampMain\",\".*\",\".*\",\".*\")*/"
12116 (save-excursion
12117 (let* ((params (verilog-read-auto-params 1 2))
12118 (submod (nth 0 params))
12119 (regexp (nth 1 params))
12120 submodi)
12121 ;; Lookup position, etc of co-module
12122 ;; Note this may raise an error
12123 (when (setq submodi (verilog-modi-lookup submod t))
12124 (let* ((indent-pt (current-indentation))
12125 (v2k (verilog-in-paren-quick))
12126 (modi (verilog-modi-current))
12127 (moddecls (verilog-modi-get-decls modi))
12128 (submoddecls (verilog-modi-get-decls submodi))
12129 (sig-list-p (verilog-signals-not-in
12130 (verilog-decls-get-gparams submoddecls)
12131 (append (verilog-decls-get-gparams moddecls)))))
12132 (forward-line 1)
12133 (setq sig-list-p (verilog-signals-matching-regexp sig-list-p regexp))
12134 (when v2k (verilog-repair-open-comma))
12135 (when sig-list-p
12136 (verilog-insert-indent "// Beginning of automatic parameters (from specific module)\n")
12137 ;; Don't sort them so an upper AUTOINST will match the main module
12138 (verilog-insert-definition modi sig-list-p "parameter" indent-pt v2k t)
12139 (verilog-insert-indent "// End of automatics\n"))
12140 (when v2k (verilog-repair-close-comma)))))))
12142 (defun verilog-auto-inout-modport ()
12143 "Expand AUTOINOUTMODPORT statements, as part of \\[verilog-auto].
12144 Take input/output/inout statements from the specified interface
12145 and modport and insert into the current module. This is useful
12146 for making verification modules that connect to UVM interfaces.
12148 The first parameter is the name of an interface.
12150 The second parameter is a regexp of modports to read from in
12151 that interface.
12153 The optional third parameter is a regular expression, and only
12154 signals matching the regular expression will be included.
12156 Limitations:
12157 If placed inside the parenthesis of a module declaration, it creates
12158 Verilog 2001 style, else uses Verilog 1995 style.
12160 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
12162 As with other autos, any inputs/outputs declared in the module
12163 will suppress the AUTO from redeclarating an inputs/outputs by
12164 the same name.
12166 An example:
12168 interface ExampIf
12169 ( input logic clk );
12170 logic req_val;
12171 logic [7:0] req_dat;
12172 clocking mon_clkblk @(posedge clk);
12173 input req_val;
12174 input req_dat;
12175 endclocking
12176 modport mp(clocking mon_clkblk);
12177 endinterface
12179 module ExampMain
12180 ( input clk,
12181 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12182 // Beginning of automatic in/out/inouts (from modport)
12183 input [7:0] req_dat,
12184 input req_val
12185 // End of automatics
12187 /*AUTOASSIGNMODPORT(\"ExampIf\" \"mp\")*/
12188 endmodule
12190 Typing \\[verilog-auto] will make this into:
12193 module ExampMain
12194 ( input clk,
12195 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12196 // Beginning of automatic in/out/inouts (from modport)
12197 input req_dat,
12198 input req_val
12199 // End of automatics
12202 If the modport is part of a UVM monitor/driver class, this
12203 creates a wrapper module that may be used to instantiate the
12204 driver/monitor using AUTOINST in the testbench."
12205 (save-excursion
12206 (let* ((params (verilog-read-auto-params 2 3))
12207 (submod (nth 0 params))
12208 (modport-re (nth 1 params))
12209 (regexp (nth 2 params))
12210 direction-re submodi) ;; direction argument not supported until requested
12211 ;; Lookup position, etc of co-module
12212 ;; Note this may raise an error
12213 (when (setq submodi (verilog-modi-lookup submod t))
12214 (let* ((indent-pt (current-indentation))
12215 (v2k (verilog-in-paren-quick))
12216 (modi (verilog-modi-current))
12217 (moddecls (verilog-modi-get-decls modi))
12218 (submoddecls (verilog-modi-get-decls submodi))
12219 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
12220 (sig-list-i (verilog-signals-in ;; Decls doesn't have data types, must resolve
12221 (verilog-decls-get-vars submoddecls)
12222 (verilog-signals-not-in
12223 (verilog-decls-get-inputs submodportdecls)
12224 (append (verilog-decls-get-ports submoddecls)
12225 (verilog-decls-get-ports moddecls)))))
12226 (sig-list-o (verilog-signals-in ;; Decls doesn't have data types, must resolve
12227 (verilog-decls-get-vars submoddecls)
12228 (verilog-signals-not-in
12229 (verilog-decls-get-outputs submodportdecls)
12230 (append (verilog-decls-get-ports submoddecls)
12231 (verilog-decls-get-ports moddecls)))))
12232 (sig-list-io (verilog-signals-in ;; Decls doesn't have data types, must resolve
12233 (verilog-decls-get-vars submoddecls)
12234 (verilog-signals-not-in
12235 (verilog-decls-get-inouts submodportdecls)
12236 (append (verilog-decls-get-ports submoddecls)
12237 (verilog-decls-get-ports moddecls))))))
12238 (forward-line 1)
12239 (setq sig-list-i (verilog-signals-edit-wire-reg
12240 (verilog-signals-matching-dir-re
12241 (verilog-signals-matching-regexp sig-list-i regexp)
12242 "input" direction-re))
12243 sig-list-o (verilog-signals-edit-wire-reg
12244 (verilog-signals-matching-dir-re
12245 (verilog-signals-matching-regexp sig-list-o regexp)
12246 "output" direction-re))
12247 sig-list-io (verilog-signals-edit-wire-reg
12248 (verilog-signals-matching-dir-re
12249 (verilog-signals-matching-regexp sig-list-io regexp)
12250 "inout" direction-re)))
12251 (when v2k (verilog-repair-open-comma))
12252 (when (or sig-list-i sig-list-o sig-list-io)
12253 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from modport)\n")
12254 ;; Don't sort them so an upper AUTOINST will match the main module
12255 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12256 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12257 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12258 (verilog-insert-indent "// End of automatics\n"))
12259 (when v2k (verilog-repair-close-comma)))))))
12261 (defun verilog-auto-insert-lisp ()
12262 "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
12263 The Lisp code provided is called, and the Lisp code calls
12264 `insert` to insert text into the current file beginning on the
12265 line after the AUTOINSERTLISP.
12267 See also AUTO_LISP, which takes a Lisp expression and evaluates
12268 it during `verilog-auto-inst' but does not insert any text.
12270 An example:
12272 module ExampInsertLisp;
12273 /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
12274 endmodule
12276 // For this example we declare the function in the
12277 // module's file itself. Often you'd define it instead
12278 // in a site-start.el or init file.
12280 Local Variables:
12281 eval:
12282 (defun my-verilog-insert-hello (who)
12283 (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
12284 End:
12287 Typing \\[verilog-auto] will call my-verilog-insert-hello and
12288 expand the above into:
12290 // Beginning of automatic insert lisp
12291 initial $write(\"hello world\");
12292 // End of automatics
12294 You can also call an external program and insert the returned
12295 text:
12297 /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
12298 // Beginning of automatic insert lisp
12299 //hello
12300 // End of automatics"
12301 (save-excursion
12302 ;; Point is at end of /*AUTO...*/
12303 (let* ((indent-pt (current-indentation))
12304 (cmd-end-pt (save-excursion (search-backward ")")
12305 (forward-char)
12306 (point))) ;; Closing paren
12307 (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
12308 (backward-sexp 1) ;; Inside comment
12309 (point))) ;; Beginning paren
12310 (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
12311 (verilog-forward-or-insert-line)
12312 ;; Some commands don't move point (like insert-file) so we always
12313 ;; add the begin/end comments, then delete it if not needed
12314 (verilog-insert-indent "// Beginning of automatic insert lisp\n")
12315 (verilog-insert-indent "// End of automatics\n")
12316 (forward-line -1)
12317 (eval (read cmd))
12318 (forward-line -1)
12319 (setq verilog-scan-cache-tick nil) ;; Clear cache; inserted unknown text
12320 (verilog-delete-empty-auto-pair))))
12322 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
12323 "Return list of signals for current AUTOSENSE block."
12324 (let* ((sigss (verilog-read-always-signals))
12325 (sig-list (verilog-signals-not-params
12326 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
12327 (append (and (not verilog-auto-sense-include-inputs)
12328 (verilog-alw-get-outputs-delayed sigss))
12329 (and (not verilog-auto-sense-include-inputs)
12330 (verilog-alw-get-outputs-immediate sigss))
12331 (verilog-alw-get-temps sigss)
12332 (verilog-decls-get-consts moddecls)
12333 (verilog-decls-get-gparams moddecls)
12334 presense-sigs)))))
12335 sig-list))
12337 (defun verilog-auto-sense ()
12338 "Expand AUTOSENSE statements, as part of \\[verilog-auto].
12339 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
12340 with one automatically derived from all inputs declared in the always
12341 statement. Signals that are generated within the same always block are NOT
12342 placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
12343 Long lines are split based on the `fill-column', see \\[set-fill-column].
12345 Limitations:
12346 Verilog does not allow memories (multidimensional arrays) in sensitivity
12347 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
12349 Constant signals:
12350 AUTOSENSE cannot always determine if a `define is a constant or a signal
12351 (it could be in an include file for example). If a `define or other signal
12352 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
12353 declaration anywhere in the module (parenthesis are required):
12355 /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */
12357 Better yet, use a parameter, which will be understood to be constant
12358 automatically.
12360 OOps!
12361 If AUTOSENSE makes a mistake, please report it. (First try putting
12362 a begin/end after your always!) As a workaround, if a signal that
12363 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
12364 If a signal should be in the sensitivity list wasn't, placing it before
12365 the /*AUTOSENSE*/ comment will prevent it from being deleted when the
12366 autos are updated (or added if it occurs there already).
12368 An example:
12370 always @ (/*AS*/) begin
12371 /* AUTO_CONSTANT (`constant) */
12372 outin = ina | inb | `constant;
12373 out = outin;
12376 Typing \\[verilog-auto] will make this into:
12378 always @ (/*AS*/ina or inb) begin
12379 /* AUTO_CONSTANT (`constant) */
12380 outin = ina | inb | `constant;
12381 out = outin;
12384 Note in Verilog 2001, you can often get the same result from the new @*
12385 operator. (This was added to the language in part due to AUTOSENSE!)
12387 always @* begin
12388 outin = ina | inb | `constant;
12389 out = outin;
12390 end"
12391 (save-excursion
12392 ;; Find beginning
12393 (let* ((start-pt (save-excursion
12394 (verilog-re-search-backward-quick "(" nil t)
12395 (point)))
12396 (indent-pt (save-excursion
12397 (or (and (goto-char start-pt) (1+ (current-column)))
12398 (current-indentation))))
12399 (modi (verilog-modi-current))
12400 (moddecls (verilog-modi-get-decls modi))
12401 (sig-memories (verilog-signals-memory
12402 (verilog-decls-get-vars moddecls)))
12403 sig-list not-first presense-sigs)
12404 ;; Read signals in always, eliminate outputs from sense list
12405 (setq presense-sigs (verilog-signals-from-signame
12406 (save-excursion
12407 (verilog-read-signals start-pt (point)))))
12408 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
12409 (when sig-memories
12410 (let ((tlen (length sig-list)))
12411 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
12412 (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
12413 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/"
12414 (save-excursion (goto-char (point))
12415 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
12416 (verilog-re-search-backward-quick "\\s-" start-pt t)
12417 (while (looking-at "\\s-`endif")
12418 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
12419 (verilog-re-search-backward-quick "\\s-" start-pt t))
12420 (not (looking-at "\\s-or\\b"))))
12421 (setq not-first t))
12422 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
12423 (while sig-list
12424 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
12425 (insert "\n")
12426 (indent-to indent-pt)
12427 (if not-first (insert "or ")))
12428 (not-first (insert " or ")))
12429 (insert (verilog-sig-name (car sig-list)))
12430 (setq sig-list (cdr sig-list)
12431 not-first t)))))
12433 (defun verilog-auto-reset ()
12434 "Expand AUTORESET statements, as part of \\[verilog-auto].
12435 Replace the /*AUTORESET*/ comment with code to initialize all
12436 registers set elsewhere in the always block.
12438 Limitations:
12439 AUTORESET will not clear memories.
12441 AUTORESET uses <= if the signal has a <= assignment in the block,
12442 else it uses =.
12444 If <= is used, all = assigned variables are ignored if
12445 `verilog-auto-reset-blocking-in-non' is nil; they are presumed
12446 to be temporaries.
12448 /*AUTORESET*/ presumes that any signals mentioned between the previous
12449 begin/case/if statement and the AUTORESET comment are being reset manually
12450 and should not be automatically reset. This includes omitting any signals
12451 used on the right hand side of assignments.
12453 By default, AUTORESET will include the width of the signal in the
12454 autos, SystemVerilog designs may want to change this. To control
12455 this behavior, see `verilog-auto-reset-widths'.
12457 AUTORESET ties signals to deasserted, which is presumed to be zero.
12458 Signals that match `verilog-active-low-regexp' will be deasserted by tying
12459 them to a one.
12461 An example:
12463 always @(posedge clk or negedge reset_l) begin
12464 if (!reset_l) begin
12465 c <= 1;
12466 /*AUTORESET*/
12468 else begin
12469 a <= in_a;
12470 b <= in_b;
12471 c <= in_c;
12475 Typing \\[verilog-auto] will make this into:
12477 always @(posedge core_clk or negedge reset_l) begin
12478 if (!reset_l) begin
12479 c <= 1;
12480 /*AUTORESET*/
12481 // Beginning of autoreset for uninitialized flops
12482 a <= 0;
12483 b = 0; // if `verilog-auto-reset-blocking-in-non' true
12484 // End of automatics
12486 else begin
12487 a <= in_a;
12488 b = in_b;
12489 c <= in_c;
12491 end"
12493 (interactive)
12494 (save-excursion
12495 ;; Find beginning
12496 (let* ((indent-pt (current-indentation))
12497 (modi (verilog-modi-current))
12498 (moddecls (verilog-modi-get-decls modi))
12499 (all-list (verilog-decls-get-signals moddecls))
12500 sigss sig-list dly-list prereset-sigs)
12501 ;; Read signals in always, eliminate outputs from reset list
12502 (setq prereset-sigs (verilog-signals-from-signame
12503 (save-excursion
12504 (verilog-read-signals
12505 (save-excursion
12506 (verilog-re-search-backward-quick "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t)
12507 (point))
12508 (point)))))
12509 (save-excursion
12510 (verilog-re-search-backward-quick "@" nil t)
12511 (setq sigss (verilog-read-always-signals)))
12512 (setq dly-list (verilog-alw-get-outputs-delayed sigss))
12513 (setq sig-list (verilog-signals-not-in (append
12514 (verilog-alw-get-outputs-delayed sigss)
12515 (when (or (not (verilog-alw-get-uses-delayed sigss))
12516 verilog-auto-reset-blocking-in-non)
12517 (verilog-alw-get-outputs-immediate sigss)))
12518 (append
12519 (verilog-alw-get-temps sigss)
12520 prereset-sigs)))
12521 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
12522 (when sig-list
12523 (insert "\n");
12524 (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
12525 (while sig-list
12526 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths
12527 (car sig-list))))
12528 (indent-to indent-pt)
12529 (insert (verilog-sig-name sig)
12530 (if (assoc (verilog-sig-name sig) dly-list)
12531 (concat " <= " verilog-assignment-delay)
12532 " = ")
12533 (verilog-sig-tieoff sig)
12534 ";\n")
12535 (setq sig-list (cdr sig-list))))
12536 (verilog-insert-indent "// End of automatics")))))
12538 (defun verilog-auto-tieoff ()
12539 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
12540 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
12541 signals to deasserted.
12543 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
12544 input/output list as another module, but no internals. Specifically, it
12545 finds all outputs in the module, and if that input is not otherwise declared
12546 as a register or wire, creates a tieoff.
12548 AUTORESET ties signals to deasserted, which is presumed to be zero.
12549 Signals that match `verilog-active-low-regexp' will be deasserted by tying
12550 them to a one.
12552 You can add signals you do not want included in AUTOTIEOFF with
12553 `verilog-auto-tieoff-ignore-regexp'.
12555 `verilog-auto-wire-type' may be used to change the datatype of
12556 the declarations.
12558 `verilog-auto-reset-widths' may be used to change how the tieoff
12559 value's width is generated.
12561 An example of making a stub for another module:
12563 module ExampStub (/*AUTOINST*/);
12564 /*AUTOINOUTPARAM(\"Foo\")*/
12565 /*AUTOINOUTMODULE(\"Foo\")*/
12566 /*AUTOTIEOFF*/
12567 // verilator lint_off UNUSED
12568 wire _unused_ok = &{1'b0,
12569 /*AUTOUNUSED*/
12570 1'b0};
12571 // verilator lint_on UNUSED
12572 endmodule
12574 Typing \\[verilog-auto] will make this into:
12576 module ExampStub (/*AUTOINST*/...);
12577 /*AUTOINOUTPARAM(\"Foo\")*/
12578 /*AUTOINOUTMODULE(\"Foo\")*/
12579 // Beginning of autotieoff
12580 output [2:0] foo;
12581 // End of automatics
12583 /*AUTOTIEOFF*/
12584 // Beginning of autotieoff
12585 wire [2:0] foo = 3'b0;
12586 // End of automatics
12588 endmodule"
12589 (interactive)
12590 (save-excursion
12591 ;; Find beginning
12592 (let* ((indent-pt (current-indentation))
12593 (modi (verilog-modi-current))
12594 (moddecls (verilog-modi-get-decls modi))
12595 (modsubdecls (verilog-modi-get-sub-decls modi))
12596 (sig-list (verilog-signals-not-in
12597 (verilog-decls-get-outputs moddecls)
12598 (append (verilog-decls-get-vars moddecls)
12599 (verilog-decls-get-assigns moddecls)
12600 (verilog-decls-get-consts moddecls)
12601 (verilog-decls-get-gparams moddecls)
12602 (verilog-subdecls-get-interfaced modsubdecls)
12603 (verilog-subdecls-get-outputs modsubdecls)
12604 (verilog-subdecls-get-inouts modsubdecls)))))
12605 (setq sig-list (verilog-signals-not-matching-regexp
12606 sig-list verilog-auto-tieoff-ignore-regexp))
12607 (when sig-list
12608 (verilog-forward-or-insert-line)
12609 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
12610 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
12611 (verilog-modi-cache-add-vars modi sig-list) ; Before we trash list
12612 (while sig-list
12613 (let ((sig (car sig-list)))
12614 (cond ((equal verilog-auto-tieoff-declaration "assign")
12615 (indent-to indent-pt)
12616 (insert "assign " (verilog-sig-name sig)))
12618 (verilog-insert-one-definition sig verilog-auto-tieoff-declaration indent-pt)))
12619 (indent-to (max 48 (+ indent-pt 40)))
12620 (insert "= " (verilog-sig-tieoff sig)
12621 ";\n")
12622 (setq sig-list (cdr sig-list))))
12623 (verilog-insert-indent "// End of automatics\n")))))
12625 (defun verilog-auto-undef ()
12626 "Expand AUTOUNDEF statements, as part of \\[verilog-auto].
12627 Take any `defines since the last AUTOUNDEF in the current file
12628 and create `undefs for them. This is used to insure that
12629 file-local defines do not pollute the global `define name space.
12631 Limitations:
12632 AUTOUNDEF presumes any identifier following `define is the
12633 name of a define. Any `ifdefs are ignored.
12635 AUTOUNDEF suppresses creating an `undef for any define that was
12636 `undefed before the AUTOUNDEF. This may be used to work around
12637 the ignoring of `ifdefs as shown below.
12639 An example:
12641 `define XX_FOO
12642 `define M_BAR(x)
12643 `define M_BAZ
12645 `ifdef NEVER
12646 `undef M_BAZ // Emacs will see this and not `undef M_BAZ
12647 `endif
12649 /*AUTOUNDEF*/
12651 Typing \\[verilog-auto] will make this into:
12654 /*AUTOUNDEF*/
12655 // Beginning of automatic undefs
12656 `undef XX_FOO
12657 `undef M_BAR
12658 // End of automatics
12660 You may also provide an optional regular expression, in which case only
12661 defines the regular expression will be undefed."
12662 (save-excursion
12663 (let* ((params (verilog-read-auto-params 0 1))
12664 (regexp (nth 0 params))
12665 (indent-pt (current-indentation))
12666 (end-pt (point))
12667 defs def)
12668 (save-excursion
12669 ;; Scan from start of file, or last AUTOUNDEF
12670 (or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
12671 (goto-char (point-min)))
12672 (while (verilog-re-search-forward-quick
12673 "`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
12674 (cond ((equal (match-string-no-properties 1) "define")
12675 (setq def (match-string-no-properties 2))
12676 (when (and (or (not regexp)
12677 (string-match regexp def))
12678 (not (member def defs))) ;; delete-dups not in 21.1
12679 (setq defs (cons def defs))))
12681 (setq defs (delete (match-string-no-properties 2) defs))))))
12682 ;; Insert
12683 (setq defs (sort defs 'string<))
12684 (when defs
12685 (verilog-forward-or-insert-line)
12686 (verilog-insert-indent "// Beginning of automatic undefs\n")
12687 (while defs
12688 (verilog-insert-indent "`undef " (car defs) "\n")
12689 (setq defs (cdr defs)))
12690 (verilog-insert-indent "// End of automatics\n")))))
12692 (defun verilog-auto-unused ()
12693 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
12694 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
12695 input and inout signals.
12697 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
12698 input/output list as another module, but no internals. Specifically, it
12699 finds all inputs and inouts in the module, and if that input is not otherwise
12700 used, adds it to a comma separated list.
12702 The comma separated list is intended to be used to create a _unused_ok
12703 signal. Using the exact name \"_unused_ok\" for name of the temporary
12704 signal is recommended as it will insure maximum forward compatibility, it
12705 also makes lint warnings easy to understand; ignore any unused warnings
12706 with \"unused\" in the signal name.
12708 To reduce simulation time, the _unused_ok signal should be forced to a
12709 constant to prevent wiggling. The easiest thing to do is use a
12710 reduction-and with 1'b0 as shown.
12712 This way all unused signals are in one place, making it convenient to add
12713 your tool's specific pragmas around the assignment to disable any unused
12714 warnings.
12716 You can add signals you do not want included in AUTOUNUSED with
12717 `verilog-auto-unused-ignore-regexp'.
12719 An example of making a stub for another module:
12721 module ExampStub (/*AUTOINST*/);
12722 /*AUTOINOUTPARAM(\"Examp\")*/
12723 /*AUTOINOUTMODULE(\"Examp\")*/
12724 /*AUTOTIEOFF*/
12725 // verilator lint_off UNUSED
12726 wire _unused_ok = &{1'b0,
12727 /*AUTOUNUSED*/
12728 1'b0};
12729 // verilator lint_on UNUSED
12730 endmodule
12732 Typing \\[verilog-auto] will make this into:
12735 // verilator lint_off UNUSED
12736 wire _unused_ok = &{1'b0,
12737 /*AUTOUNUSED*/
12738 // Beginning of automatics
12739 unused_input_a,
12740 unused_input_b,
12741 unused_input_c,
12742 // End of automatics
12743 1'b0};
12744 // verilator lint_on UNUSED
12745 endmodule"
12746 (interactive)
12747 (save-excursion
12748 ;; Find beginning
12749 (let* ((indent-pt (progn (search-backward "/*") (current-column)))
12750 (modi (verilog-modi-current))
12751 (moddecls (verilog-modi-get-decls modi))
12752 (modsubdecls (verilog-modi-get-sub-decls modi))
12753 (sig-list (verilog-signals-not-in
12754 (append (verilog-decls-get-inputs moddecls)
12755 (verilog-decls-get-inouts moddecls))
12756 (append (verilog-subdecls-get-inputs modsubdecls)
12757 (verilog-subdecls-get-inouts modsubdecls)))))
12758 (setq sig-list (verilog-signals-not-matching-regexp
12759 sig-list verilog-auto-unused-ignore-regexp))
12760 (when sig-list
12761 (verilog-forward-or-insert-line)
12762 (verilog-insert-indent "// Beginning of automatic unused inputs\n")
12763 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
12764 (while sig-list
12765 (let ((sig (car sig-list)))
12766 (indent-to indent-pt)
12767 (insert (verilog-sig-name sig) ",\n")
12768 (setq sig-list (cdr sig-list))))
12769 (verilog-insert-indent "// End of automatics\n")))))
12771 (defun verilog-enum-ascii (signm elim-regexp)
12772 "Convert an enum name SIGNM to an ascii string for insertion.
12773 Remove user provided prefix ELIM-REGEXP."
12774 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
12775 (let ((case-fold-search t))
12776 ;; All upper becomes all lower for readability
12777 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
12779 (defun verilog-auto-ascii-enum ()
12780 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
12781 Create a register to contain the ASCII decode of an enumerated signal type.
12782 This will allow trace viewers to show the ASCII name of states.
12784 First, parameters are built into an enumeration using the synopsys enum
12785 comment. The comment must be between the keyword and the symbol.
12786 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
12788 Next, registers which that enum applies to are also tagged with the same
12789 enum.
12791 Finally, an AUTOASCIIENUM command is used.
12793 The first parameter is the name of the signal to be decoded.
12795 The second parameter is the name to store the ASCII code into. For the
12796 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
12797 a signal that is just for simulation, and the magic characters _ascii
12798 tell viewers like Dinotrace to display in ASCII format.
12800 The third optional parameter is a string which will be removed
12801 from the state names. It defaults to \"\" which removes nothing.
12803 The fourth optional parameter is \"onehot\" to force one-hot
12804 decoding. If unspecified, if and only if the first parameter
12805 width is 2^(number of states in enum) and does NOT match the
12806 width of the enum, the signal is assumed to be a one-hot
12807 decode. Otherwise, it's a normal encoded state vector.
12809 `verilog-auto-wire-type' may be used to change the datatype of
12810 the declarations.
12812 \"auto enum\" may be used in place of \"synopsys enum\".
12814 An example:
12816 //== State enumeration
12817 parameter [2:0] // synopsys enum state_info
12818 SM_IDLE = 3'b000,
12819 SM_SEND = 3'b001,
12820 SM_WAIT1 = 3'b010;
12821 //== State variables
12822 reg [2:0] /* synopsys enum state_info */
12823 state_r; /* synopsys state_vector state_r */
12824 reg [2:0] /* synopsys enum state_info */
12825 state_e1;
12827 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
12829 Typing \\[verilog-auto] will make this into:
12831 ... same front matter ...
12833 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
12834 // Beginning of automatic ASCII enum decoding
12835 reg [39:0] state_ascii_r; // Decode of state_r
12836 always @(state_r) begin
12837 case ({state_r})
12838 SM_IDLE: state_ascii_r = \"idle \";
12839 SM_SEND: state_ascii_r = \"send \";
12840 SM_WAIT1: state_ascii_r = \"wait1\";
12841 default: state_ascii_r = \"%Erro\";
12842 endcase
12844 // End of automatics"
12845 (save-excursion
12846 (let* ((params (verilog-read-auto-params 2 4))
12847 (undecode-name (nth 0 params))
12848 (ascii-name (nth 1 params))
12849 (elim-regexp (and (nth 2 params)
12850 (not (equal (nth 2 params) ""))
12851 (nth 2 params)))
12852 (one-hot-flag (nth 3 params))
12854 (indent-pt (current-indentation))
12855 (modi (verilog-modi-current))
12856 (moddecls (verilog-modi-get-decls modi))
12858 (sig-list-consts (append (verilog-decls-get-consts moddecls)
12859 (verilog-decls-get-gparams moddecls)))
12860 (sig-list-all (verilog-decls-get-iovars moddecls))
12862 (undecode-sig (or (assoc undecode-name sig-list-all)
12863 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
12864 (undecode-enum (or (verilog-sig-enum undecode-sig)
12865 (error "%s: Signal %s does not have an enum tag" (verilog-point-text) undecode-name)))
12867 (enum-sigs (verilog-signals-not-in
12868 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
12869 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))
12870 nil))
12872 (one-hot (or
12873 (string-match "onehot" (or one-hot-flag ""))
12874 (and ;; width(enum) != width(sig)
12875 (or (not (verilog-sig-bits (car enum-sigs)))
12876 (not (equal (verilog-sig-width (car enum-sigs))
12877 (verilog-sig-width undecode-sig))))
12878 ;; count(enums) == width(sig)
12879 (equal (number-to-string (length enum-sigs))
12880 (verilog-sig-width undecode-sig)))))
12881 (enum-chars 0)
12882 (ascii-chars 0))
12884 ;; Find number of ascii chars needed
12885 (let ((tmp-sigs enum-sigs))
12886 (while tmp-sigs
12887 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
12888 ascii-chars (max ascii-chars (length (verilog-enum-ascii
12889 (verilog-sig-name (car tmp-sigs))
12890 elim-regexp)))
12891 tmp-sigs (cdr tmp-sigs))))
12893 (verilog-forward-or-insert-line)
12894 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
12895 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
12896 (concat "Decode of " undecode-name) nil nil))))
12897 (verilog-insert-definition modi decode-sig-list "reg" indent-pt nil))
12899 (verilog-insert-indent "always @(" undecode-name ") begin\n")
12900 (setq indent-pt (+ indent-pt verilog-indent-level))
12901 (verilog-insert-indent "case ({" undecode-name "})\n")
12902 (setq indent-pt (+ indent-pt verilog-case-indent))
12904 (let ((tmp-sigs enum-sigs)
12905 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
12906 (+ (if one-hot 9 1) (max 8 enum-chars))
12907 ascii-name ascii-chars))
12908 (errname (substring "%Error" 0 (min 6 ascii-chars))))
12909 (while tmp-sigs
12910 (verilog-insert-indent
12911 (concat
12912 (format chrfmt
12913 (concat (if one-hot "(")
12914 ;; Use enum-sigs length as that's numeric
12915 ;; verilog-sig-width undecode-sig might not be.
12916 (if one-hot (number-to-string (length enum-sigs)))
12917 ;; We use a shift instead of var[index]
12918 ;; so that a non-one hot value will show as error.
12919 (if one-hot "'b1<<")
12920 (verilog-sig-name (car tmp-sigs))
12921 (if one-hot ")") ":")
12922 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
12923 elim-regexp))))
12924 (setq tmp-sigs (cdr tmp-sigs)))
12925 (verilog-insert-indent (format chrfmt "default:" errname)))
12927 (setq indent-pt (- indent-pt verilog-case-indent))
12928 (verilog-insert-indent "endcase\n")
12929 (setq indent-pt (- indent-pt verilog-indent-level))
12930 (verilog-insert-indent "end\n"
12931 "// End of automatics\n"))))
12933 (defun verilog-auto-templated-rel ()
12934 "Replace Templated relative line numbers with absolute line numbers.
12935 Internal use only. This hacks around the line numbers in AUTOINST Templates
12936 being different from the final output's line numbering."
12937 (let ((templateno 0) (template-line (list 0)) (buf-line 1))
12938 ;; Find line number each template is on
12939 ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
12940 (goto-char (point-min))
12941 (while (not (eobp))
12942 (when (looking-at ".*AUTO_TEMPLATE")
12943 (setq templateno (1+ templateno))
12944 (setq template-line (cons buf-line template-line)))
12945 (setq buf-line (1+ buf-line))
12946 (forward-line 1))
12947 (setq template-line (nreverse template-line))
12948 ;; Replace T# L# with absolute line number
12949 (goto-char (point-min))
12950 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
12951 (replace-match
12952 (concat " Templated "
12953 (int-to-string (+ (nth (string-to-number (match-string 1))
12954 template-line)
12955 (string-to-number (match-string 2)))))
12956 t t))))
12958 (defun verilog-auto-template-lint ()
12959 "Check AUTO_TEMPLATEs for unused lines.
12960 Enable with `verilog-auto-template-warn-unused'."
12961 (let ((name1 (or (buffer-file-name) (buffer-name))))
12962 (save-excursion
12963 (goto-char (point-min))
12964 (while (re-search-forward
12965 "^\\s-*/?\\*?\\s-*[a-zA-Z0-9`_$]+\\s-+AUTO_TEMPLATE" nil t)
12966 (let* ((tpl-info (verilog-read-auto-template-middle))
12967 (tpl-list (aref tpl-info 1))
12968 (tlines (append (nth 0 tpl-list) (nth 1 tpl-list)))
12969 tpl-ass)
12970 (while tlines
12971 (setq tpl-ass (car tlines)
12972 tlines (cdr tlines))
12974 (unless (or (not (eval-when-compile (fboundp 'make-hash-table))) ;; Not supported, no warning
12975 (not verilog-auto-template-hits)
12976 (gethash (vector (nth 2 tpl-ass) (nth 3 tpl-ass))
12977 verilog-auto-template-hits))
12978 (verilog-warn-error "%s:%d: AUTO_TEMPLATE line unused: \".%s (%s)\""
12979 name1
12980 (+ (elt tpl-ass 3) ;; Template line number
12981 (count-lines (point-min) (point)))
12982 (elt tpl-ass 0) (elt tpl-ass 1))
12983 )))))))
12987 ;; Auto top level
12990 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing an arg
12991 "Expand AUTO statements.
12992 Look for any /*AUTO...*/ commands in the code, as used in
12993 instantiations or argument headers. Update the list of signals
12994 following the /*AUTO...*/ command.
12996 Use \\[verilog-delete-auto] to remove the AUTOs.
12998 Use \\[verilog-diff-auto] to see differences in AUTO expansion.
13000 Use \\[verilog-inject-auto] to insert AUTOs for the first time.
13002 Use \\[verilog-faq] for a pointer to frequently asked questions.
13004 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
13005 called before and after this function, respectively.
13007 For example:
13008 module ModuleName (/*AUTOARG*/);
13009 /*AUTOINPUT*/
13010 /*AUTOOUTPUT*/
13011 /*AUTOWIRE*/
13012 /*AUTOREG*/
13013 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
13015 You can also update the AUTOs from the shell using:
13016 emacs --batch <filenames.v> -f verilog-batch-auto
13017 Or fix indentation with:
13018 emacs --batch <filenames.v> -f verilog-batch-indent
13019 Likewise, you can delete or inject AUTOs with:
13020 emacs --batch <filenames.v> -f verilog-batch-delete-auto
13021 emacs --batch <filenames.v> -f verilog-batch-inject-auto
13022 Or check if AUTOs have the same expansion
13023 emacs --batch <filenames.v> -f verilog-batch-diff-auto
13025 Using \\[describe-function], see also:
13026 `verilog-auto-arg' for AUTOARG module instantiations
13027 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
13028 `verilog-auto-assign-modport' for AUTOASSIGNMODPORT assignment to/from modport
13029 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
13030 `verilog-auto-inout-in' for AUTOINOUTIN inputs for all i/o
13031 `verilog-auto-inout-modport' for AUTOINOUTMODPORT i/o from an interface modport
13032 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
13033 `verilog-auto-inout-param' for AUTOINOUTPARAM copying params from elsewhere
13034 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
13035 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
13036 `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
13037 `verilog-auto-inst' for AUTOINST instantiation pins
13038 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
13039 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
13040 `verilog-auto-logic' for AUTOLOGIC declaring logic signals
13041 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
13042 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
13043 `verilog-auto-reg' for AUTOREG registers
13044 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
13045 `verilog-auto-reset' for AUTORESET flop resets
13046 `verilog-auto-sense' for AUTOSENSE always sensitivity lists
13047 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
13048 `verilog-auto-undef' for AUTOUNDEF `undef of local `defines
13049 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
13050 `verilog-auto-wire' for AUTOWIRE instantiation wires
13052 `verilog-read-defines' for reading `define values
13053 `verilog-read-includes' for reading `includes
13055 If you have bugs with these autos, please file an issue at
13056 URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
13057 Wilson Snyder (wsnyder@wsnyder.org)."
13058 (interactive)
13059 (unless noninteractive (message "Updating AUTOs..."))
13060 (if (fboundp 'dinotrace-unannotate-all)
13061 (dinotrace-unannotate-all))
13062 (verilog-save-font-mods
13063 (let ((oldbuf (if (not (buffer-modified-p))
13064 (buffer-string)))
13065 ;; Cache directories; we don't write new files, so can't change
13066 (verilog-dir-cache-preserving t)
13067 ;; Cache current module
13068 (verilog-modi-cache-current-enable t)
13069 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
13070 verilog-modi-cache-current)
13071 (unwind-protect
13072 ;; Disable change hooks for speed
13073 ;; This let can't be part of above let; must restore
13074 ;; after-change-functions before font-lock resumes
13075 (verilog-save-no-change-functions
13076 (verilog-save-scan-cache
13077 (save-excursion
13078 ;; Wipe cache; otherwise if we AUTOed a block above this one,
13079 ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
13080 (setq verilog-modi-cache-list nil)
13081 ;; Local state
13082 (setq verilog-auto-template-hits nil)
13083 ;; If we're not in verilog-mode, change syntax table so parsing works right
13084 (unless (eq major-mode `verilog-mode) (verilog-mode))
13085 ;; Allow user to customize
13086 (verilog-run-hooks 'verilog-before-auto-hook)
13087 ;; Try to save the user from needing to revert-file to reread file local-variables
13088 (verilog-auto-reeval-locals)
13089 (verilog-read-auto-lisp-present)
13090 (verilog-read-auto-lisp (point-min) (point-max))
13091 (verilog-getopt-flags)
13092 ;; From here on out, we can cache anything we read from disk
13093 (verilog-preserve-dir-cache
13094 ;; These two may seem obvious to do always, but on large includes it can be way too slow
13095 (when verilog-auto-read-includes
13096 (verilog-read-includes)
13097 (verilog-read-defines nil nil t))
13098 ;; Setup variables due to SystemVerilog expansion
13099 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic-setup)
13100 ;; This particular ordering is important
13101 ;; INST: Lower modules correct, no internal dependencies, FIRST
13102 (verilog-preserve-modi-cache
13103 ;; Clear existing autos else we'll be screwed by existing ones
13104 (verilog-delete-auto)
13105 ;; Injection if appropriate
13106 (when inject
13107 (verilog-inject-inst)
13108 (verilog-inject-sense)
13109 (verilog-inject-arg))
13111 ;; Do user inserts first, so their code can insert AUTOs
13112 ;; We may provide an AUTOINSERTLISPLAST if another cleanup pass is needed
13113 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
13114 'verilog-auto-insert-lisp)
13115 ;; Expand instances before need the signals the instances input/output
13116 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
13117 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
13118 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
13119 ;; Doesn't matter when done, but combine it with a common changer
13120 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
13121 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
13122 ;; Must be done before autoin/out as creates a reg
13123 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM(.*?)\\*/" 'verilog-auto-ascii-enum)
13125 ;; first in/outs from other files
13126 (verilog-auto-re-search-do "/\\*AUTOINOUTMODPORT(.*?)\\*/" 'verilog-auto-inout-modport)
13127 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE(.*?)\\*/" 'verilog-auto-inout-module)
13128 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP(.*?)\\*/" 'verilog-auto-inout-comp)
13129 (verilog-auto-re-search-do "/\\*AUTOINOUTIN(.*?)\\*/" 'verilog-auto-inout-in)
13130 (verilog-auto-re-search-do "/\\*AUTOINOUTPARAM(.*?)\\*/" 'verilog-auto-inout-param)
13131 ;; next in/outs which need previous sucked inputs first
13132 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((.*?)\\)?\\*/" 'verilog-auto-output)
13133 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((.*?)\\)?\\*/" 'verilog-auto-input)
13134 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((.*?)\\)?\\*/" 'verilog-auto-inout)
13135 ;; Then tie off those in/outs
13136 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
13137 ;; These can be anywhere after AUTOINSERTLISP
13138 (verilog-auto-re-search-do "/\\*AUTOUNDEF\\((.*?)\\)?\\*/" 'verilog-auto-undef)
13139 ;; Wires/regs must be after inputs/outputs
13140 (verilog-auto-re-search-do "/\\*AUTOASSIGNMODPORT(.*?)\\*/" 'verilog-auto-assign-modport)
13141 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
13142 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
13143 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
13144 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
13145 ;; outputevery needs AUTOOUTPUTs done first
13146 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\*/" 'verilog-auto-output-every)
13147 ;; After we've created all new variables
13148 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
13149 ;; Must be after all inputs outputs are generated
13150 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
13151 ;; Fix line numbers (comments only)
13152 (when verilog-auto-inst-template-numbers
13153 (verilog-auto-templated-rel))
13154 (when verilog-auto-template-warn-unused
13155 (verilog-auto-template-lint))))
13157 (verilog-run-hooks 'verilog-auto-hook)
13159 (when verilog-auto-delete-trailing-whitespace
13160 (verilog-delete-trailing-whitespace))
13162 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
13164 ;; If end result is same as when started, clear modified flag
13165 (cond ((and oldbuf (equal oldbuf (buffer-string)))
13166 (set-buffer-modified-p nil)
13167 (unless noninteractive (message "Updating AUTOs...done (no changes)")))
13168 (t (unless noninteractive (message "Updating AUTOs...done"))))
13169 ;; End of after-change protection
13171 ;; Unwind forms
13172 ;; Currently handled in verilog-save-font-mods
13173 ))))
13177 ;; Skeleton based code insertion
13179 (defvar verilog-template-map
13180 (let ((map (make-sparse-keymap)))
13181 (define-key map "a" 'verilog-sk-always)
13182 (define-key map "b" 'verilog-sk-begin)
13183 (define-key map "c" 'verilog-sk-case)
13184 (define-key map "f" 'verilog-sk-for)
13185 (define-key map "g" 'verilog-sk-generate)
13186 (define-key map "h" 'verilog-sk-header)
13187 (define-key map "i" 'verilog-sk-initial)
13188 (define-key map "j" 'verilog-sk-fork)
13189 (define-key map "m" 'verilog-sk-module)
13190 (define-key map "o" 'verilog-sk-ovm-class)
13191 (define-key map "p" 'verilog-sk-primitive)
13192 (define-key map "r" 'verilog-sk-repeat)
13193 (define-key map "s" 'verilog-sk-specify)
13194 (define-key map "t" 'verilog-sk-task)
13195 (define-key map "u" 'verilog-sk-uvm-class)
13196 (define-key map "w" 'verilog-sk-while)
13197 (define-key map "x" 'verilog-sk-casex)
13198 (define-key map "z" 'verilog-sk-casez)
13199 (define-key map "?" 'verilog-sk-if)
13200 (define-key map ":" 'verilog-sk-else-if)
13201 (define-key map "/" 'verilog-sk-comment)
13202 (define-key map "A" 'verilog-sk-assign)
13203 (define-key map "F" 'verilog-sk-function)
13204 (define-key map "I" 'verilog-sk-input)
13205 (define-key map "O" 'verilog-sk-output)
13206 (define-key map "S" 'verilog-sk-state-machine)
13207 (define-key map "=" 'verilog-sk-inout)
13208 (define-key map "W" 'verilog-sk-wire)
13209 (define-key map "R" 'verilog-sk-reg)
13210 (define-key map "D" 'verilog-sk-define-signal)
13211 map)
13212 "Keymap used in Verilog mode for smart template operations.")
13216 ;; Place the templates into Verilog Mode. They may be inserted under any key.
13217 ;; C-c C-t will be the default. If you use templates a lot, you
13218 ;; may want to consider moving the binding to another key in your init
13219 ;; file.
13221 ;; Note \C-c and letter are reserved for users
13222 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
13224 ;;; ---- statement skeletons ------------------------------------------
13226 (define-skeleton verilog-sk-prompt-condition
13227 "Prompt for the loop condition."
13228 "[condition]: " str )
13230 (define-skeleton verilog-sk-prompt-init
13231 "Prompt for the loop init statement."
13232 "[initial statement]: " str )
13234 (define-skeleton verilog-sk-prompt-inc
13235 "Prompt for the loop increment statement."
13236 "[increment statement]: " str )
13238 (define-skeleton verilog-sk-prompt-name
13239 "Prompt for the name of something."
13240 "[name]: " str)
13242 (define-skeleton verilog-sk-prompt-clock
13243 "Prompt for the name of something."
13244 "name and edge of clock(s): " str)
13246 (defvar verilog-sk-reset nil)
13247 (defun verilog-sk-prompt-reset ()
13248 "Prompt for the name of a state machine reset."
13249 (setq verilog-sk-reset (read-string "name of reset: " "rst")))
13252 (define-skeleton verilog-sk-prompt-state-selector
13253 "Prompt for the name of a state machine selector."
13254 "name of selector (eg {a,b,c,d}): " str )
13256 (define-skeleton verilog-sk-prompt-output
13257 "Prompt for the name of something."
13258 "output: " str)
13260 (define-skeleton verilog-sk-prompt-msb
13261 "Prompt for most significant bit specification."
13262 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
13264 (define-skeleton verilog-sk-prompt-lsb
13265 "Prompt for least significant bit specification."
13266 "lsb:" str )
13268 (defvar verilog-sk-p nil)
13269 (define-skeleton verilog-sk-prompt-width
13270 "Prompt for a width specification."
13272 (progn
13273 (setq verilog-sk-p (point))
13274 (verilog-sk-prompt-msb)
13275 (if (> (point) verilog-sk-p) "] " " ")))
13277 (defun verilog-sk-header ()
13278 "Insert a descriptive header at the top of the file.
13279 See also `verilog-header' for an alternative format."
13280 (interactive "*")
13281 (save-excursion
13282 (goto-char (point-min))
13283 (verilog-sk-header-tmpl)))
13285 (define-skeleton verilog-sk-header-tmpl
13286 "Insert a comment block containing the module title, author, etc."
13287 "[Description]: "
13288 "// -*- Mode: Verilog -*-"
13289 "\n// Filename : " (buffer-name)
13290 "\n// Description : " str
13291 "\n// Author : " (user-full-name)
13292 "\n// Created On : " (current-time-string)
13293 "\n// Last Modified By: " (user-full-name)
13294 "\n// Last Modified On: " (current-time-string)
13295 "\n// Update Count : 0"
13296 "\n// Status : Unknown, Use with caution!"
13297 "\n")
13299 (define-skeleton verilog-sk-module
13300 "Insert a module definition."
13302 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
13303 > _ \n
13304 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
13306 ;;; ------------------------------------------------------------------------
13307 ;;; Define a default OVM class, with macros and new()
13308 ;;; ------------------------------------------------------------------------
13310 (define-skeleton verilog-sk-ovm-class
13311 "Insert a class definition"
13313 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
13314 > _ \n
13315 > "`ovm_object_utils_begin(" name ")" \n
13316 > (- verilog-indent-level) " `ovm_object_utils_end" \n
13317 > _ \n
13318 > "function new(name=\"" name "\");" \n
13319 > "super.new(name);" \n
13320 > (- verilog-indent-level) "endfunction" \n
13321 > _ \n
13322 > "endclass" (progn (electric-verilog-terminate-line) nil))
13324 (define-skeleton verilog-sk-uvm-class
13325 "Insert a class definition"
13327 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
13328 > _ \n
13329 > "`uvm_object_utils_begin(" name ")" \n
13330 > (- verilog-indent-level) " `uvm_object_utils_end" \n
13331 > _ \n
13332 > "function new(name=\"" name "\");" \n
13333 > "super.new(name);" \n
13334 > (- verilog-indent-level) "endfunction" \n
13335 > _ \n
13336 > "endclass" (progn (electric-verilog-terminate-line) nil))
13338 (define-skeleton verilog-sk-primitive
13339 "Insert a task definition."
13341 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
13342 > _ \n
13343 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
13345 (define-skeleton verilog-sk-task
13346 "Insert a task definition."
13348 > "task " '(verilog-sk-prompt-name) & ?; \n
13349 > _ \n
13350 > "begin" \n
13351 > \n
13352 > (- verilog-indent-level-behavioral) "end" \n
13353 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
13355 (define-skeleton verilog-sk-function
13356 "Insert a function definition."
13358 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n
13359 > _ \n
13360 > "begin" \n
13361 > \n
13362 > (- verilog-indent-level-behavioral) "end" \n
13363 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
13365 (define-skeleton verilog-sk-always
13366 "Insert always block. Uses the minibuffer to prompt
13367 for sensitivity list."
13369 > "always @ ( /*AUTOSENSE*/ ) begin\n"
13370 > _ \n
13371 > (- verilog-indent-level-behavioral) "end" \n >
13374 (define-skeleton verilog-sk-initial
13375 "Insert an initial block."
13377 > "initial begin\n"
13378 > _ \n
13379 > (- verilog-indent-level-behavioral) "end" \n > )
13381 (define-skeleton verilog-sk-specify
13382 "Insert specify block. "
13384 > "specify\n"
13385 > _ \n
13386 > (- verilog-indent-level-behavioral) "endspecify" \n > )
13388 (define-skeleton verilog-sk-generate
13389 "Insert generate block. "
13391 > "generate\n"
13392 > _ \n
13393 > (- verilog-indent-level-behavioral) "endgenerate" \n > )
13395 (define-skeleton verilog-sk-begin
13396 "Insert begin end block. Uses the minibuffer to prompt for name."
13398 > "begin" '(verilog-sk-prompt-name) \n
13399 > _ \n
13400 > (- verilog-indent-level-behavioral) "end"
13403 (define-skeleton verilog-sk-fork
13404 "Insert a fork join block."
13406 > "fork\n"
13407 > "begin" \n
13408 > _ \n
13409 > (- verilog-indent-level-behavioral) "end" \n
13410 > "begin" \n
13411 > \n
13412 > (- verilog-indent-level-behavioral) "end" \n
13413 > (- verilog-indent-level-behavioral) "join" \n
13417 (define-skeleton verilog-sk-case
13418 "Build skeleton case statement, prompting for the selector expression,
13419 and the case items."
13420 "[selector expression]: "
13421 > "case (" str ") " \n
13422 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
13423 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
13425 (define-skeleton verilog-sk-casex
13426 "Build skeleton casex statement, prompting for the selector expression,
13427 and the case items."
13428 "[selector expression]: "
13429 > "casex (" str ") " \n
13430 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
13431 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
13433 (define-skeleton verilog-sk-casez
13434 "Build skeleton casez statement, prompting for the selector expression,
13435 and the case items."
13436 "[selector expression]: "
13437 > "casez (" str ") " \n
13438 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
13439 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
13441 (define-skeleton verilog-sk-if
13442 "Insert a skeleton if statement."
13443 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
13444 > _ \n
13445 > (- verilog-indent-level-behavioral) "end " \n )
13447 (define-skeleton verilog-sk-else-if
13448 "Insert a skeleton else if statement."
13449 > (verilog-indent-line) "else if ("
13450 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
13451 > _ \n
13452 > "end" (progn (electric-verilog-terminate-line) nil))
13454 (define-skeleton verilog-sk-datadef
13455 "Common routine to get data definition."
13457 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
13459 (define-skeleton verilog-sk-input
13460 "Insert an input definition."
13462 > "input [" '(verilog-sk-datadef))
13464 (define-skeleton verilog-sk-output
13465 "Insert an output definition."
13467 > "output [" '(verilog-sk-datadef))
13469 (define-skeleton verilog-sk-inout
13470 "Insert an inout definition."
13472 > "inout [" '(verilog-sk-datadef))
13474 (defvar verilog-sk-signal nil)
13475 (define-skeleton verilog-sk-def-reg
13476 "Insert a reg definition."
13478 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations-auto) )
13480 (defun verilog-sk-define-signal ()
13481 "Insert a definition of signal under point at top of module."
13482 (interactive "*")
13483 (let* ((sig-re "[a-zA-Z0-9_]*")
13484 (v1 (buffer-substring
13485 (save-excursion
13486 (skip-chars-backward sig-re)
13487 (point))
13488 (save-excursion
13489 (skip-chars-forward sig-re)
13490 (point)))))
13491 (if (not (member v1 verilog-keywords))
13492 (save-excursion
13493 (setq verilog-sk-signal v1)
13494 (verilog-beg-of-defun)
13495 (verilog-end-of-statement)
13496 (verilog-forward-syntactic-ws)
13497 (verilog-sk-def-reg)
13498 (message "signal at point is %s" v1))
13499 (message "object at point (%s) is a keyword" v1))))
13501 (define-skeleton verilog-sk-wire
13502 "Insert a wire definition."
13504 > "wire [" '(verilog-sk-datadef))
13506 (define-skeleton verilog-sk-reg
13507 "Insert a reg definition."
13509 > "reg [" '(verilog-sk-datadef))
13511 (define-skeleton verilog-sk-assign
13512 "Insert a skeleton assign statement."
13514 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
13516 (define-skeleton verilog-sk-while
13517 "Insert a skeleton while loop statement."
13519 > "while (" '(verilog-sk-prompt-condition) ") begin" \n
13520 > _ \n
13521 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13523 (define-skeleton verilog-sk-repeat
13524 "Insert a skeleton repeat loop statement."
13526 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
13527 > _ \n
13528 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13530 (define-skeleton verilog-sk-for
13531 "Insert a skeleton while loop statement."
13533 > "for ("
13534 '(verilog-sk-prompt-init) "; "
13535 '(verilog-sk-prompt-condition) "; "
13536 '(verilog-sk-prompt-inc)
13537 ") begin" \n
13538 > _ \n
13539 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
13541 (define-skeleton verilog-sk-comment
13542 "Inserts three comment lines, making a display comment."
13544 > "/*\n"
13545 > "* " _ \n
13546 > "*/")
13548 (define-skeleton verilog-sk-state-machine
13549 "Insert a state machine definition."
13550 "Name of state variable: "
13551 '(setq input "state")
13552 > "// State registers for " str | -23 \n
13553 '(setq verilog-sk-state str)
13554 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n
13555 '(setq input nil)
13556 > \n
13557 > "// State FF for " verilog-sk-state \n
13558 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
13559 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
13560 > verilog-sk-state " = next_" verilog-sk-state ?; \n
13561 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
13562 > \n
13563 > "// Next State Logic for " verilog-sk-state \n
13564 > "always @ ( /*AUTOSENSE*/ ) begin\n"
13565 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
13566 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
13567 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
13568 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
13572 ;; Include file loading with mouse/return event
13574 ;; idea & first impl.: M. Rouat (eldo-mode.el)
13575 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
13577 (if (featurep 'xemacs)
13578 (require 'overlay))
13580 (defconst verilog-include-file-regexp
13581 "^`include\\s-+\"\\([^\n\"]*\\)\""
13582 "Regexp that matches the include file.")
13584 (defvar verilog-mode-mouse-map
13585 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
13586 (set-keymap-parent map verilog-mode-map)
13587 ;; mouse button bindings
13588 (define-key map "\r" 'verilog-load-file-at-point)
13589 (if (featurep 'xemacs)
13590 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
13591 (define-key map [mouse-2] 'verilog-load-file-at-mouse))
13592 (if (featurep 'xemacs)
13593 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
13594 (define-key map [S-mouse-2] 'mouse-yank-at-click))
13595 map)
13596 "Map containing mouse bindings for `verilog-mode'.")
13599 (defun verilog-highlight-region (beg end old-len)
13600 "Colorize included files and modules in the (changed?) region.
13601 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
13602 (when (or verilog-highlight-includes
13603 verilog-highlight-modules)
13604 (save-excursion
13605 (save-match-data ;; A query-replace may call this function - do not disturb
13606 (verilog-save-buffer-state
13607 (verilog-save-scan-cache
13608 (let (end-point)
13609 (goto-char end)
13610 (setq end-point (point-at-eol))
13611 (goto-char beg)
13612 (beginning-of-line) ; scan entire line
13613 ;; delete overlays existing on this line
13614 (let ((overlays (overlays-in (point) end-point)))
13615 (while overlays
13616 (if (and
13617 (overlay-get (car overlays) 'detachable)
13618 (or (overlay-get (car overlays) 'verilog-include-file)
13619 (overlay-get (car overlays) 'verilog-inst-module)))
13620 (delete-overlay (car overlays)))
13621 (setq overlays (cdr overlays))))
13623 ;; make new include overlays
13624 (when verilog-highlight-includes
13625 (while (search-forward-regexp verilog-include-file-regexp end-point t)
13626 (goto-char (match-beginning 1))
13627 (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
13628 (overlay-put ov 'start-closed 't)
13629 (overlay-put ov 'end-closed 't)
13630 (overlay-put ov 'evaporate 't)
13631 (overlay-put ov 'verilog-include-file 't)
13632 (overlay-put ov 'mouse-face 'highlight)
13633 (overlay-put ov 'local-map verilog-mode-mouse-map))))
13635 ;; make new module overlays
13636 (goto-char beg)
13637 ;; This scanner is syntax-fragile, so don't get bent
13638 (when verilog-highlight-modules
13639 (condition-case nil
13640 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
13641 (save-excursion
13642 (goto-char (match-beginning 0))
13643 (unless (verilog-inside-comment-or-string-p)
13644 (verilog-read-inst-module-matcher) ;; sets match 0
13645 (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
13646 (overlay-put ov 'start-closed 't)
13647 (overlay-put ov 'end-closed 't)
13648 (overlay-put ov 'evaporate 't)
13649 (overlay-put ov 'verilog-inst-module 't)
13650 (overlay-put ov 'mouse-face 'highlight)
13651 (overlay-put ov 'local-map verilog-mode-mouse-map)))))
13652 (error nil)))
13654 ;; Future highlights:
13655 ;; variables - make an Occur buffer of where referenced
13656 ;; pins - make an Occur buffer of the sig in the declaration module
13657 )))))))
13659 (defun verilog-highlight-buffer ()
13660 "Colorize included files and modules across the whole buffer."
13661 ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
13662 (interactive)
13663 ;; delete and remake overlays
13664 (verilog-highlight-region (point-min) (point-max) nil))
13666 ;; Deprecated, but was interactive, so we'll keep it around
13667 (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
13669 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
13670 ;; so define this function to do more or less the same as ffap-at-mouse
13671 ;; but first resolve filename...
13672 (defun verilog-load-file-at-mouse (event)
13673 "Load file under button 2 click's EVENT.
13674 Files are checked based on `verilog-library-flags'."
13675 (interactive "@e")
13676 (save-excursion ;; implement a Verilog specific ffap-at-mouse
13677 (mouse-set-point event)
13678 (verilog-load-file-at-point t)))
13680 ;; ffap isn't usable for Verilog mode. It uses library paths.
13681 ;; so define this function to do more or less the same as ffap
13682 ;; but first resolve filename...
13683 (defun verilog-load-file-at-point (&optional warn)
13684 "Load file under point.
13685 If WARN, throw warning if not found.
13686 Files are checked based on `verilog-library-flags'."
13687 (interactive)
13688 (save-excursion ;; implement a Verilog specific ffap
13689 (let ((overlays (overlays-in (point) (point)))
13690 hit)
13691 (while (and overlays (not hit))
13692 (when (overlay-get (car overlays) 'verilog-inst-module)
13693 (verilog-goto-defun-file (buffer-substring
13694 (overlay-start (car overlays))
13695 (overlay-end (car overlays))))
13696 (setq hit t))
13697 (setq overlays (cdr overlays)))
13698 ;; Include?
13699 (beginning-of-line)
13700 (when (and (not hit)
13701 (looking-at verilog-include-file-regexp))
13702 (if (and (car (verilog-library-filenames
13703 (match-string 1) (buffer-file-name)))
13704 (file-readable-p (car (verilog-library-filenames
13705 (match-string 1) (buffer-file-name)))))
13706 (find-file (car (verilog-library-filenames
13707 (match-string 1) (buffer-file-name))))
13708 (when warn
13709 (message
13710 "File '%s' isn't readable, use shift-mouse2 to paste in this field"
13711 (match-string 1))))))))
13714 ;; Bug reporting
13717 (defun verilog-faq ()
13718 "Tell the user their current version, and where to get the FAQ etc."
13719 (interactive)
13720 (with-output-to-temp-buffer "*verilog-mode help*"
13721 (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
13722 (princ "\n")
13723 (princ "For new releases, see http://www.verilog.com\n")
13724 (princ "\n")
13725 (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
13726 (princ "\n")
13727 (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
13728 (princ "\n")))
13730 (autoload 'reporter-submit-bug-report "reporter")
13731 (defvar reporter-prompt-for-summary-p)
13733 (defun verilog-submit-bug-report ()
13734 "Submit via mail a bug report on verilog-mode.el."
13735 (interactive)
13736 (let ((reporter-prompt-for-summary-p t))
13737 (reporter-submit-bug-report
13738 "mac@verilog.com, wsnyder@wsnyder.org"
13739 (concat "verilog-mode v" verilog-mode-version)
13741 verilog-active-low-regexp
13742 verilog-after-save-font-hook
13743 verilog-align-ifelse
13744 verilog-assignment-delay
13745 verilog-auto-arg-sort
13746 verilog-auto-declare-nettype
13747 verilog-auto-delete-trailing-whitespace
13748 verilog-auto-endcomments
13749 verilog-auto-hook
13750 verilog-auto-ignore-concat
13751 verilog-auto-indent-on-newline
13752 verilog-auto-inout-ignore-regexp
13753 verilog-auto-input-ignore-regexp
13754 verilog-auto-inst-column
13755 verilog-auto-inst-dot-name
13756 verilog-auto-inst-interfaced-ports
13757 verilog-auto-inst-param-value
13758 verilog-auto-inst-sort
13759 verilog-auto-inst-template-numbers
13760 verilog-auto-inst-vector
13761 verilog-auto-lineup
13762 verilog-auto-newline
13763 verilog-auto-output-ignore-regexp
13764 verilog-auto-read-includes
13765 verilog-auto-reset-blocking-in-non
13766 verilog-auto-reset-widths
13767 verilog-auto-save-policy
13768 verilog-auto-sense-defines-constant
13769 verilog-auto-sense-include-inputs
13770 verilog-auto-star-expand
13771 verilog-auto-star-save
13772 verilog-auto-template-warn-unused
13773 verilog-auto-tieoff-declaration
13774 verilog-auto-tieoff-ignore-regexp
13775 verilog-auto-unused-ignore-regexp
13776 verilog-auto-wire-type
13777 verilog-before-auto-hook
13778 verilog-before-delete-auto-hook
13779 verilog-before-getopt-flags-hook
13780 verilog-before-save-font-hook
13781 verilog-cache-enabled
13782 verilog-case-indent
13783 verilog-cexp-indent
13784 verilog-compiler
13785 verilog-coverage
13786 verilog-delete-auto-hook
13787 verilog-getopt-flags-hook
13788 verilog-highlight-grouping-keywords
13789 verilog-highlight-includes
13790 verilog-highlight-modules
13791 verilog-highlight-p1800-keywords
13792 verilog-highlight-translate-off
13793 verilog-indent-begin-after-if
13794 verilog-indent-declaration-macros
13795 verilog-indent-level
13796 verilog-indent-level-behavioral
13797 verilog-indent-level-declaration
13798 verilog-indent-level-directive
13799 verilog-indent-level-module
13800 verilog-indent-lists
13801 verilog-library-directories
13802 verilog-library-extensions
13803 verilog-library-files
13804 verilog-library-flags
13805 verilog-linter
13806 verilog-minimum-comment-distance
13807 verilog-mode-hook
13808 verilog-mode-release-date
13809 verilog-mode-release-emacs
13810 verilog-mode-version
13811 verilog-preprocessor
13812 verilog-simulator
13813 verilog-tab-always-indent
13814 verilog-tab-to-comment
13815 verilog-typedef-regexp
13816 verilog-warn-fatal
13818 nil nil
13819 (concat "Hi Mac,
13821 I want to report a bug.
13823 Before I go further, I want to say that Verilog mode has changed my life.
13824 I save so much time, my files are colored nicely, my co workers respect
13825 my coding ability... until now. I'd really appreciate anything you
13826 could do to help me out with this minor deficiency in the product.
13828 I've taken a look at the Verilog-Mode FAQ at
13829 http://www.veripool.org/verilog-mode-faq.html.
13831 And, I've considered filing the bug on the issue tracker at
13832 http://www.veripool.org/verilog-mode-bugs
13833 since I realize that public bugs are easier for you to track,
13834 and for others to search, but would prefer to email.
13836 So, to reproduce the bug, start a fresh Emacs via " invocation-name "
13837 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
13838 the code included below.
13840 Given those lines, I expected [[Fill in here]] to happen;
13841 but instead, [[Fill in here]] happens!.
13843 == The code: =="))))
13845 (provide 'verilog-mode)
13847 ;; Local Variables:
13848 ;; checkdoc-permit-comma-termination-flag:t
13849 ;; checkdoc-force-docstrings-flag:nil
13850 ;; End:
13852 ;;; verilog-mode.el ends here